本文整理汇总了PHP中api_Utils::GetRemoteFileInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP api_Utils::GetRemoteFileInfo方法的具体用法?PHP api_Utils::GetRemoteFileInfo怎么用?PHP api_Utils::GetRemoteFileInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api_Utils
的用法示例。
在下文中一共展示了api_Utils::GetRemoteFileInfo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetOembedFileInfo
public static function GetOembedFileInfo($sUrl)
{
$mResult = false;
$sOembedUrl = '';
if (false !== strpos($sUrl, 'youtube.com') || false !== strpos($sUrl, 'youtu.be')) {
$sOembedUrl = 'https://youtube.com/oembed?format=json&url=' . $sUrl;
} else {
if (false !== strpos($sUrl, 'vimeo.com')) {
$sOembedUrl = 'https://vimeo.com/api/oembed.json?format=json&url=' . $sUrl;
} else {
if (false !== strpos($sUrl, 'soundcloud.com')) {
$sOembedUrl = 'https://soundcloud.com/oembed?format=json&url=' . $sUrl;
}
}
}
if (strlen($sOembedUrl) > 0) {
$oCurl = curl_init();
\curl_setopt_array($oCurl, array(CURLOPT_URL => $sOembedUrl, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => '', CURLOPT_AUTOREFERER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 5, CURLOPT_MAXREDIRS => 5));
$sResult = curl_exec($oCurl);
curl_close($oCurl);
$oResult = json_decode($sResult);
if ($oResult) {
$sSearch = $oResult->html;
$aPatterns = array('/ width="\\d+."/', '/ height="\\d+."/', '/(src="[^\\"]+)/');
$aResults = array(' width="896"', ' height="504"', '$1?&autoplay=1&auto_play=true');
$oResult->html = preg_replace($aPatterns, $aResults, $sSearch);
$aRemoteFileInfo = \api_Utils::GetRemoteFileInfo($sUrl);
$oResult->fileSize = $aRemoteFileInfo['size'];
$oResult->thumbnailLink = $oResult->thumbnail_url;
$mResult = $oResult;
}
}
return $mResult;
}
示例2: GetFiles
public function GetFiles($oAccount, $sType = \EFileStorageTypeStr::Personal, $sPath = '', $sPattern = '')
{
$oDirectory = null;
$aItems = array();
$aResult = array();
$oMin = $this->GetMinManager();
if ($oAccount && $this->Init($oAccount)) {
$oTenant = null;
$oApiTenants = \CApi::Manager('tenants');
if ($oApiTenants) {
$oTenant = 0 < $oAccount->IdTenant ? $oApiTenants->GetTenantById($oAccount->IdTenant) : $oApiTenants->GetDefaultGlobalTenant();
}
$sRootPath = $this->getRootPath($oAccount, $sType, true);
$oDirectory = $this->getDirectory($oAccount, $sType, $sPath);
if ($oDirectory !== null) {
if (!empty($sPattern) || is_numeric($sPattern)) {
$aItems = $oDirectory->Search($sPattern);
$aDirectoryInfo = $oDirectory->getChildrenProperties();
foreach ($aDirectoryInfo as $oDirectoryInfo) {
if (isset($oDirectoryInfo['Link']) && strpos($oDirectoryInfo['Name'], $sPattern) !== false) {
$aItems[] = new \afterlogic\DAV\FS\File($oDirectory->getPath() . '/' . $oDirectoryInfo['@Name']);
}
}
} else {
$aItems = $oDirectory->getChildren();
}
$iThumbnailLimit = 1024 * 1024 * 2;
// 2MB
foreach ($aItems as $oValue) {
$sFilePath = str_replace($sRootPath, '', dirname($oValue->getPath()));
$aProps = $oValue->getProperties(array('Owner', 'Shared', 'Name', 'Link', 'LinkType'));
$oItem = new \CFileStorageItem();
$oItem->Type = $sType;
$oItem->TypeStr = $sType;
$oItem->Path = $sFilePath;
$oItem->Name = $oValue->getName();
$oItem->Id = $oValue->getName();
$oItem->FullPath = $oItem->Name !== '' ? $oItem->Path . '/' . $oItem->Name : $oItem->Path;
$sID = '';
if ($oValue instanceof \afterlogic\DAV\FS\Directory) {
$sID = $this->GenerateShareHash($oAccount, $sType, $sFilePath, $oValue->getName());
$oItem->IsFolder = true;
}
if ($oValue instanceof \afterlogic\DAV\FS\File) {
$sID = $this->GenerateShareHash($oAccount, $sType, $sFilePath, $oValue->getName());
$oItem->IsFolder = false;
$oItem->Size = $oValue->getSize();
$oFileInfo = null;
if (isset($aProps['Link'])) {
$oItem->IsLink = true;
$iLinkType = api_Utils::GetLinkType($aProps['Link']);
$oItem->LinkType = $iLinkType;
$oItem->LinkUrl = $aProps['Link'];
if (isset($iLinkType) && $oTenant) {
if (\EFileStorageLinkType::GoogleDrive === $iLinkType) {
$oSocial = $oTenant->GetSocialByName('google');
if ($oSocial) {
$oFileInfo = \api_Utils::GetGoogleDriveFileInfo($aProps['Link'], $oSocial->SocialApiKey);
if ($oFileInfo) {
$oItem->Name = isset($oFileInfo->title) ? $oFileInfo->title : $oItem->Name;
$oItem->Size = isset($oFileInfo->fileSize) ? $oFileInfo->fileSize : $oItem->Size;
}
}
} else {
if (\EFileStorageLinkType::DropBox === $iLinkType) {
$aProps['Link'] = str_replace('www.dropbox.com', 'dl.dropboxusercontent.com', $aProps['Link']);
}
$oItem->Name = isset($aProps['Name']) ? $aProps['Name'] : basename($aProps['Link']);
$aRemoteFileInfo = \api_Utils::GetRemoteFileInfo($aProps['Link']);
$oItem->Size = $aRemoteFileInfo['size'];
}
}
} else {
$oItem->IsLink = false;
}
$oItem->LastModified = $oValue->getLastModified();
$oItem->ContentType = $oValue->getContentType();
if (!$oItem->ContentType) {
$oItem->ContentType = \api_Utils::MimeContentType($oItem->Name);
}
if (\CApi::GetConf('labs.allow-thumbnail', true)) {
if ($oItem->IsLink && $oItem->LinkType === \EFileStorageLinkType::GoogleDrive && isset($oFileInfo) && isset($oFileInfo->thumbnailLink)) {
$oItem->Thumb = true;
$oItem->ThumbnailLink = $oFileInfo->thumbnailLink;
} else {
$oItem->Thumb = $oItem->Size < $iThumbnailLimit && \api_Utils::IsGDImageMimeTypeSuppoted($oItem->ContentType, $oItem->Name);
}
}
$oItem->Iframed = !$oItem->IsFolder && !$oItem->IsLink && \CApi::isIframedMimeTypeSupported($oItem->ContentType, $oItem->Name);
$oItem->Hash = \CApi::EncodeKeyValues(array('Type' => $sType, 'Path' => $sFilePath, 'Name' => $oValue->getName(), 'FileName' => $oValue->getName(), 'MimeType' => $oItem->ContentType, 'Size' => $oValue->getSize(), 'Iframed' => $oItem->Iframed));
}
$mMin = $oMin->GetMinByID($sID);
$oItem->Shared = isset($aProps['Shared']) ? $aProps['Shared'] : empty($mMin['__hash__']) ? false : true;
$oItem->Owner = isset($aProps['Owner']) ? $aProps['Owner'] : $oAccount->Email;
if ($oItem && '.asc' === \strtolower(\substr(\trim($oItem->Name), -4))) {
$mResult = $this->GetFile($oAccount, $oItem->Type, $oItem->Path, $oItem->Name);
if (is_resource($mResult)) {
$oItem->Content = stream_get_contents($mResult);
}
}
//.........这里部分代码省略.........
示例3: AjaxFilesUpload
/**
* @return array
*/
public function AjaxFilesUpload()
{
$oAccount = $this->getDefaultAccountFromParam();
$oTenant = null;
if ($this->oApiTenants) {
$oTenant = 0 < $oAccount->IdTenant ? $this->oApiTenants->getTenantById($oAccount->IdTenant) : $this->oApiTenants->getDefaultGlobalTenant();
}
$mResult = false;
if ($this->oApiCapability->isFilesSupported($oAccount) && $oTenant) {
$aFiles = $this->getParamValue('Hashes', null);
if (is_array($aFiles) && 0 < count($aFiles)) {
$mResult = array();
foreach ($aFiles as $sHash) {
$aData = \CApi::DecodeKeyValues($sHash);
if (\is_array($aData) && 0 < \count($aData)) {
$oFileInfo = $this->oApiFilestorage->getFileInfo($oAccount, $aData['Type'], $aData['Path'], $aData['Name']);
$rFile = null;
if ($oFileInfo->IsLink) {
if (\EFileStorageLinkType::GoogleDrive === $oFileInfo->LinkType) {
$oSocial = $oTenant->getSocialByName('google');
if ($oSocial) {
$oInfo = \api_Utils::GetGoogleDriveFileInfo($oFileInfo->LinkUrl, $oSocial->SocialApiKey);
$aData['Name'] = isset($oInfo->title) ? $oInfo->title : $aData['Name'];
$aData['Size'] = isset($oInfo->fileSize) ? $oInfo->fileSize : $aData['Size'];
if (isset($oInfo->downloadUrl)) {
$rFile = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
$this->oHttp->SaveUrlToFile($oInfo->downloadUrl, $rFile);
rewind($rFile);
}
}
} else {
$rFile = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
$aData['Name'] = basename($oFileInfo->LinkUrl);
$aRemoteFileInfo = \api_Utils::GetRemoteFileInfo($oFileInfo->LinkUrl);
$aData['Size'] = $aRemoteFileInfo['size'];
$this->oHttp->SaveUrlToFile($oFileInfo->LinkUrl, $rFile);
rewind($rFile);
}
} else {
$rFile = $this->oApiFilestorage->getFile($oAccount, $aData['Type'], $aData['Path'], $aData['Name']);
}
$sTempName = md5('Files/Tmp/' . $aData['Type'] . $aData['Path'] . $aData['Name'] . microtime(true) . rand(1000, 9999));
if (is_resource($rFile) && $this->ApiFileCache()->putFile($oAccount, $sTempName, $rFile)) {
$aItem = array('Name' => $oFileInfo->Name, 'TempName' => $sTempName, 'Size' => (int) $aData['Size'], 'Hash' => $sHash, 'MimeType' => '');
$aItem['MimeType'] = \MailSo\Base\Utils::MimeContentType($aItem['Name']);
$aItem['NewHash'] = \CApi::EncodeKeyValues(array('TempFile' => true, 'AccountID' => $oAccount->IdAccount, 'Name' => $aItem['Name'], 'TempName' => $sTempName));
$mResult[] = $aItem;
if (is_resource($rFile)) {
@fclose($rFile);
}
}
}
}
} else {
throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::InvalidInputParameter);
}
} else {
throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::FilesNotAllowed);
}
return $this->DefaultResponse($oAccount, __FUNCTION__, $mResult);
}
示例4: PopulateGoogleDriveFileInfo
public static function PopulateGoogleDriveFileInfo(&$oFileInfo)
{
if (!isset($oFileInfo->downloadUrl)) {
switch ($oFileInfo->mimeType) {
case 'application/vnd.google-apps.document':
$oFileInfo->downloadUrl = $oFileInfo->exportLinks->{'application/vnd.openxmlformats-officedocument.wordprocessingml.document'};
$oFileInfo->title = $oFileInfo->title . '.docx';
break;
case 'application/vnd.google-apps.spreadsheet':
$oFileInfo->downloadUrl = $oFileInfo->exportLinks->{'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'};
$oFileInfo->title = $oFileInfo->title . '.xlsx';
break;
case 'application/vnd.google-apps.drawing':
$oFileInfo->downloadUrl = $oFileInfo->exportLinks->{'image/png'};
$oFileInfo->title = $oFileInfo->title . '.png';
break;
case 'application/vnd.google-apps.presentation':
$oFileInfo->downloadUrl = $oFileInfo->exportLinks->{'application/vnd.openxmlformats-officedocument.presentationml.presentation'};
$oFileInfo->title = $oFileInfo->title . '.pptx';
break;
default:
$oFileInfo->downloadUrl = $oFileInfo->exportLinks->{'application/pdf'};
$oFileInfo->title = $oFileInfo->title . '.pdf';
break;
}
if (!isset($oFileInfo->fileSize)) {
$aRemoteFileInfo = \api_Utils::GetRemoteFileInfo($oFileInfo->downloadUrl);
$oFileInfo->fileSize = $aRemoteFileInfo['size'];
}
}
}