上传图文素材.

@param array $info 图文素材的信息, title 标题,thumb_media_id 封面图片ID,author 作者,digest 摘要,show_cover_pic 是否显示封面,content 内容支持html少于2万字符 小于1M,content_source_url 点击 阅读原文的url

@return string.  成功返回mediaid
178909
public function addNews($info)
    {
        if (!is_array($info)) {
            $this->setError('参数错误');

            return false;
        }

        $data = ['articles' => $info];

        $res = $this->_post('add_news', $data);

        return $res;
    }
1087891
public function getMedia($media_id) {
		$data = $this->getData('/cgi-bin/media/get', [
			'access_token' => $this->getAccessToken(),
			'media_id' => $media_id,
		]);

		return $this->errcode == 0 ? $this->saveFile($data) : null;
	}
1187178
protected function extractDataFromFileInfo(FileInfo $info)
    {
        $data = [];

        if ($info instanceof UploadedFile) {
            $data['original_name']      = $info->getClientOriginalName();
            $data['original_extension'] = $info->getClientOriginalExtension();
        }

        return $data;
    }
1363599
public function withInfo($info)
    {
        Assertion::string($info);
        Assertion::notBlank($info);

        $instance = clone $this;

        $instance->info = $info;

        return $instance;
    }
1051736
public function uploadImg($data){
		if (!$this->access_token && !$this->checkAuth()) return false;
		//原先的上传多媒体文件接口使用 self::UPLOAD_MEDIA_URL 前缀
		$result = $this->http_post(self::API_URL_PREFIX.self::MEDIA_UPLOADIMG_URL.'access_token='.$this->access_token,$data,true);
		if ($result)
		{
			$json = json_decode($result,true);
			if (!$json || !empty($json['errcode'])) {
				$this->errCode = $json['errcode'];
				$this->errMsg = $json['errmsg'];
				return false;
			}
			return $json;
		}
		return false;
	}
794416
protected function _getUploadInfoString() {
        $maxFileSize = $this->getUploadMaxFilesize();
        $allowedExtensions = $this->getAllowedExtensions();
        $lastExtension = array_pop($allowedExtensions);

        $translator = $this->getTranslator();
        $uploadInfoStr = $translator->translate('Only %1$s and %2$s files with a maximum of %3$s MB are allowed');
        $uploadInfoStr = sprintf($uploadInfoStr, implode(', ', $allowedExtensions), $lastExtension, $maxFileSize);

        return $uploadInfoStr;
    }
38844
private function mediaObjectInfo(Media $media): string
    {
        $html = '<b><a href="' . e($media->url()) . '">' . $media->fullName() . '</a></b>' . '<br><i>' . e($media->getNote()) . '</i></br><br>';

        $linked = [];
        foreach ($media->linkedIndividuals('OBJE') as $link) {
            $linked[] = '<a href="' . e($link->url()) . '">' . $link->fullName() . '</a>';
        }
        foreach ($media->linkedFamilies('OBJE') as $link) {
            $linked[] = '<a href="' . e($link->url()) . '">' . $link->fullName() . '</a>';
        }
        foreach ($media->linkedSources('OBJE') as $link) {
            $linked[] = '<a href="' . e($link->url()) . '">' . $link->fullName() . '</a>';
        }
        foreach ($media->linkedNotes('OBJE') as $link) {
            // Invalid GEDCOM - you cannot link a NOTE to an OBJE
            $linked[] = '<a href="' . e($link->url()) . '">' . $link->fullName() . '</a>';
        }
        foreach ($media->linkedRepositories('OBJE') as $link) {
            // Invalid GEDCOM - you cannot link a REPO to an OBJE
            $linked[] = '<a href="' . e($link->url()) . '">' . $link->fullName() . '</a>';
        }
        if (!empty($linked)) {
            $html .= '<ul>';
            foreach ($linked as $link) {
                $html .= '<li>' . $link . '</li>';
            }
            $html .= '</ul>';
        } else {
            $html .= '<div class="alert alert-danger">' . I18N::translate('There are no links to this media object.') . '</div>';
        }

        return $html;
    }
1371282
public function upload($array)
	{
		$array['action'] = 'upload';
		$array['format'] = 'php';

		// Construct multipart body: https://www.mediawiki.org/wiki/API:Upload#Sample_Raw_Upload
		$boundary = '---Wikimate-' . md5(microtime());
		$body = '';
		foreach ($array as $fieldName => $fieldData) {
			$body .= "--{$boundary}\r\n";
			$body .= 'Content-Disposition: form-data; name="' . $fieldName . '"';
			// Process the (binary) file
			if ($fieldName == 'file') {
				$body .= '; filename="' . $array['filename'] . '"' . "\r\n";
				$body .= "Content-Type: application/octet-stream; charset=UTF-8\r\n";
				$body .= "Content-Transfer-Encoding: binary\r\n";
			// Process text parameters
			} else {
				$body .= "\r\n";
				$body .= "Content-Type: text/plain; charset=UTF-8\r\n";
				$body .= "Content-Transfer-Encoding: 8bit\r\n";
			}
			$body .= "\r\n{$fieldData}\r\n";
		}
		$body .= "--{$boundary}--\r\n";

		// Construct multipart headers
		$headers = array(
			'Content-Type' => "multipart/form-data; boundary={$boundary}",
			'Content-Length' => strlen($body),
		);

		$apiResult = $this->session->post($this->api, $headers, $body);

		return unserialize($apiResult->body);
	}
1065625
public function actionUpload()
    {
        $model = new MediaForm();
        if ($model->load(Yii::$app->request->post())) {
            $model->file = UploadedFile::getInstance($model, 'file');
            if ($model->upload()) {
                return $this->message('上传成功', 'success');
            }
        }
//        $files = static::getFiles();
//        if (!empty($files)) {
//            if (($mediaType = Yii::$app->request->post('mediaType')) === null) {
//                return $this->message('错误的媒体素材类型!', 'error');
//            }
//            foreach ($files as $name) {
//                $_model = clone $model;
//                $_model->setAttributes([
//                    'type' => $mediaType,
//                    'material' => ''
//                ]);
//                $uploadedFile = UploadedFile::getInstanceByName($name);
//                $result = $this->getWechat()->getSdk()->uploadMedia($uploadedFile->tempName, $mediaType);
//            }
//        }
        return $this->render('upload', [
            'model' => $model
        ]);
    }
392478
protected function createContent(Infoset $info) {
		$this->serverInfo($info);
		
		if (! empty($_REQUEST)) {
			$this->collectData($info, $_REQUEST, 'Request arguments');
		}
		
		if (! empty($_GET)) {
			$this->collectData($info, $_GET, 'Get arguments');
		}
		
		if (! empty($_POST)) {
			$this->collectData($info, $_POST, 'Post arguments');
		}
		
		if (! empty($_ENV)) {
			$this->collectData($info, $_ENV, 'Environment vars');
		}
		
		if (! empty($_COOKIE)) {
			$this->collectData($info, $_COOKIE, 'Cookies');
		}
	}
263380
protected function createContent(Infoset $info) {
		$this->includePathInfo($info);
		
		if (extension_loaded('apc')) {
			$apcInfo  = apc_cache_info();
			$apcFiles = [];
			
			foreach ($apcInfo['cache_list'] as $file) {
				$apcFiles[$file['filename']] = $file;
			}
			
			$this->apcInfo($info, $apcInfo);
		}
		
		$apcEnabled = ! empty($apcFiles);
		
		$groups = $this->includedFilesInfo($apcEnabled ? $apcFiles : null);
		
		foreach ($groups as $title => $group) {
			$table = $this->createTable();
			$table->setColsWidths([50, 50]);
			$table->setTitle($title);
			
			if ($apcEnabled) {
				$table->enableBbCodes();
			}
			
			foreach ($group as $file) {
				$table[] = $file;
			}
			
			$info[] = $table;
		}
	}
754379
protected function getIpFromInfo($info)
    {
        $ip = \Piwik\Network\IP::fromStringIP($info['ip']);

        if ($ip instanceof \Piwik\Network\IPv6 && $ip->isMappedIPv4()) {
            return $ip->toIPv4String();
        } else {
            return $ip->toString();
        }
    }
811280
protected function createList(Infoset $info) {
		$list = [];
		
		if ($info->hasTitle()) {
			$list[] = $info->getTitle() . ':';
		}
		
		foreach ($info as $content) {
			if ($content instanceof Infoset) {
				$content = $this->createContent($content);
			}
			
			if ($info->isContentBbCodes()) {
				$content = $this->bbCodesHandle($content);
			}
			
			$list[] = ' - ' . $content;
		}

		return implode(PHP_EOL, $list);
	}
1100918
public static function get($path, array $info = null)
    {
        $info = $info ?: self::getSize($path);

        switch ($info['mime']) {
            case self::TYPE_JPG:
                $srcImg = imagecreatefromjpeg($path);
                break;
            case self::TYPE_PNG:
                $srcImg = imagecreatefrompng($path);
                break;
            case self::TYPE_GIF:
                $srcImg = imagecreatefromgif($path);
                break;
            case self::TYPE_BMP:
                $srcImg = imagecreatefromwbmp($path);
                break;
            case self::TYPE_WEBP:
                $srcImg = imagecreatefromwebp($path);
                break;
            default:
                throw new FileInvalidTypeException('Not supported image type.');
        }

        return $srcImg;
    }
741565
public function getMetaData(MediaInformation $information)
    {
        $subdef = $information->getResource();
        $record = $subdef->get_record();
        $thumbnail = $record->get_thumbnail();
        $request = $information->getResourceRequest();
        $baseUrl = $request->getSchemeAndHttpHost() . $request->getBasePath();


        $ogMetaData = [];
        $embedMedia = [];
        $oembedMetaData = [];

        $substitutionPath = sprintf(
            '/assets/common/images/icons/substitution/%s.png',
            str_replace('/', '_', $record->getMimeType())
        );

        $resourceUrl = $information->getUrl();

        $embedMedia['title'] = $record->get_title();
        $embedMedia['url'] = $resourceUrl;

        switch ($record->getType()) {
            case 'video':
                $ogMetaData['og:type'] = 'video.other';
                $ogMetaData['og:image'] = $baseUrl . $thumbnail->get_url();
                $ogMetaData['og:image:width'] = $thumbnail->get_width();
                $ogMetaData['og:image:height'] = $thumbnail->get_height();

                $coverUrl = $baseUrl . $thumbnail->get_url();

                $embedConfig = $this->getEmbedConfiguration();

                // if user config has custom subdef specified:
                if (array_key_exists('video', $embedConfig)) {
                    if (array_key_exists('coverSubdef', $embedConfig['video'])) {
                        $customCoverName = $embedConfig['video']['coverSubdef'];
                        try {
                            $customCover = $record->get_subdef($customCoverName);
                            $coverUrl = $baseUrl.$customCover->get_url();
                        } catch (\Exception $e) {
                            // no existing custom cover
                        }
                    }
                }

                $embedMedia['coverUrl'] = $coverUrl;
                $embedMedia['source'] = [];
                $embedMedia['source'][] = [
                    'url'  => $resourceUrl,
                    'type' => $subdef->get_mime(),
                ];

                $embedMedia['track'] = $this->getAvailableVideoTextTracks($information);



                $embedMedia['dimensions'] = $this->getDimensions($subdef);

                $oembedMetaData['type'] = 'video';
                $oembedMetaData['html'] = sprintf(
                    '<iframe width="%d" height="%d" src="%s" frameborder="0" allowfullscreen></iframe>',
                    $embedMedia['dimensions']['width'],
                    $embedMedia['dimensions']['height'],
                    $this->getEmbedUrl($resourceUrl)
                );
                break;
            case 'flexpaper':
            case 'document':
                $ogMetaData['og:type'] = 'article';
                $ogMetaData['og:image'] = $baseUrl . $thumbnail->get_url();
                $ogMetaData['og:image:width'] = $thumbnail->get_width();
                $ogMetaData['og:image:height'] = $thumbnail->get_height();

                $oembedMetaData['type'] = 'link';
                $embedMedia['dimensions'] = $this->getDimensions($subdef);
                break;
            case 'audio':
                $ogMetaData['og:type'] = 'music.song';
                $ogMetaData['og:image'] = $baseUrl . $substitutionPath;
                $ogMetaData['og:image:width'] = $thumbnail->get_width();
                $ogMetaData['og:image:height'] = $thumbnail->get_height();

                $oembedMetaData['type'] = 'link';
                $embedMedia['source'] = [];
                $embedMedia['source'][] = [
                    'url'  => $resourceUrl,
                    'type' => $subdef->get_mime()
                ];
                $embedMedia['coverUrl'] = $baseUrl . $substitutionPath;
                // set default dimension for player
                $embedMedia['dimensions'] = [
                    'width'  => 320,
                    'height' => 320,
                    'top'    => 0,
                ];
                break;
            default:
                $oembedMetaData['type'] = 'photo';
                $ogMetaData['og:type'] = 'image';
                $ogMetaData['og:image'] = (string)$record->get_preview()->get_permalink()->get_url();
                $ogMetaData['og:image:width'] = $subdef->get_width();
                $ogMetaData['og:image:height'] = $subdef->get_height();

                $embedMedia['dimensions'] = $this->getDimensions($subdef);
                break;
        }

        return [
            'options'        => [
                'autoplay' => false,
            ],
            'oembedMetaData' => $oembedMetaData,
            'ogMetaData'     => $ogMetaData,
            'embedMedia'     => $embedMedia,
        ];
    }
438527
static function set_info($info)
    {
        if (!isset($info['proto']) && $info['uri'] !='/vendor/boolive/basic/object'){
            $info['proto'] = '/vendor/boolive/basic/object';
        }
        if (isset($info['properties'])){
            foreach ($info['properties'] as $name => $child){
                if (is_scalar($child) || is_null($child)){
                    $child = ['value' => $child];
                    if (isset($info['proto'])) $child['proto'] = $info['proto'].'/'.$name;
                }
                $child['name'] = $name;
                $child['is_property'] = true;
                if (!empty($child['value'])) $child['is_default_value'] = false;
                if (!empty($child['file'])) $child['is_default_file'] = false;
                if (!isset($child['is_default_logic'])) $child['is_default_logic'] = true;
                if (!isset($child['created']) && isset($info['created'])) $child['created'] = $info['created'];
                if (!isset($child['updated']) && isset($info['updated'])) $child['updated'] = $info['updated'];
                $child['is_exists'] = $info['is_exists'];
                $child['uri'] = $info['uri'].'/'.$name;
                self::$list_props[$info['uri']][$name] = $child['uri'];
                self::set_info($child);
            }
            unset($info['properties']);
        }
        self::$list_info[$info['uri']] = $info;
        return $info;
    }
189516
public function cardUpload_img($file)
    {
        if (!$file) {
            $this->setError('参数缺失');

            return false;
        }

        $node = 'uploadimg';

        $name        = 'media'; // 设置上传文件键名 固定为media
        $filename    = $file['name']; // 设置上传文件名
        $filetype    = $file['type'];
        $filecontent = file_get_contents($file['tmp_name']); // 读取临时文件里 上传文件的信息
        $key         = "name=\"{$name}\"; filename=\"{$filename}\"\r\nContent-Type: {$filetype}\r\n"; // curl设置上传文件的一种方法.

        $param       = [];
        $param[$key] = $filecontent;

        $res = $this->_post($node, $param, false);

        return $res;
    }