コード例 #1
0
ファイル: Actions.php プロジェクト: nsine/webmail-lite
 /**
  * @return array
  */
 public function AjaxFilesCheckUrl()
 {
     $oAccount = $this->GetDefaultAccount();
     $mResult = false;
     if ($oAccount) {
         $sUrl = trim($this->getParamValue('Url', ''));
         if (!empty($sUrl)) {
             $iLinkType = \api_Utils::GetLinkType($sUrl);
             if ($iLinkType === \EFileStorageLinkType::GoogleDrive) {
                 if ($this->oApiTenants) {
                     $oTenant = 0 < $oAccount->IdTenant ? $this->oApiTenants->getTenantById($oAccount->IdTenant) : $this->oApiTenants->getDefaultGlobalTenant();
                 }
                 $oSocial = $oTenant->getSocialByName('google');
                 if ($oSocial) {
                     $oInfo = \api_Utils::GetGoogleDriveFileInfo($sUrl, $oSocial->SocialApiKey);
                     if ($oInfo) {
                         $mResult['Size'] = 0;
                         if (isset($oInfo->fileSize)) {
                             $mResult['Size'] = $oInfo->fileSize;
                         } else {
                             $aRemoteFileInfo = \api_Utils::GetRemoteFileInfo($sUrl);
                             $mResult['Size'] = $aRemoteFileInfo['size'];
                         }
                         $mResult['Name'] = isset($oInfo->title) ? $oInfo->title : '';
                         $mResult['Thumb'] = isset($oInfo->thumbnailLink) ? $oInfo->thumbnailLink : null;
                     }
                 }
             } else {
                 //$sUrl = \api_Utils::GetRemoteFileRealUrl($sUrl);
                 $oInfo = \api_Utils::GetOembedFileInfo($sUrl);
                 if ($oInfo) {
                     $mResult['Size'] = isset($oInfo->fileSize) ? $oInfo->fileSize : '';
                     $mResult['Name'] = isset($oInfo->title) ? $oInfo->title : '';
                     $mResult['LinkType'] = $iLinkType;
                     $mResult['Thumb'] = isset($oInfo->thumbnail_url) ? $oInfo->thumbnail_url : null;
                 } else {
                     if (\api_Utils::GetLinkType($sUrl) === \EFileStorageLinkType::DropBox) {
                         $sUrl = str_replace('?dl=0', '', $sUrl);
                     }
                     $sUrl = \api_Utils::GetRemoteFileRealUrl($sUrl);
                     if ($sUrl) {
                         $aRemoteFileInfo = \api_Utils::GetRemoteFileInfo($sUrl);
                         $sFileName = basename($sUrl);
                         $sFileExtension = \api_Utils::GetFileExtension($sFileName);
                         if (empty($sFileExtension)) {
                             $sFileExtension = \api_Utils::GetFileExtensionFromMimeContentType($aRemoteFileInfo['content-type']);
                             $sFileName .= '.' . $sFileExtension;
                         }
                         if ($sFileExtension === 'htm') {
                             $oCurl = curl_init();
                             \curl_setopt_array($oCurl, array(CURLOPT_URL => $sUrl, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => '', CURLOPT_RETURNTRANSFER => true, CURLOPT_AUTOREFERER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 5, CURLOPT_MAXREDIRS => 5));
                             $sContent = curl_exec($oCurl);
                             //$aInfo = curl_getinfo($oCurl);
                             curl_close($oCurl);
                             preg_match('/<title>(.*?)<\\/title>/s', $sContent, $aTitle);
                             $sTitle = isset($aTitle['1']) ? trim($aTitle['1']) : '';
                         }
                         $mResult['Name'] = isset($sTitle) && strlen($sTitle) > 0 ? $sTitle : urldecode($sFileName);
                         $mResult['Size'] = $aRemoteFileInfo['size'];
                     }
                 }
             }
         }
     }
     return $this->DefaultResponse(null, __FUNCTION__, $mResult);
 }
コード例 #2
0
ファイル: utils.php プロジェクト: pkdevboxy/webmail-lite
 /**
  * @param string $sLink
  * @return int
  */
 public static function GetLinkType($sLink)
 {
     $iResult = \EFileStorageLinkType::Unknown;
     if (false !== strpos($sLink, 'drive.google.com')) {
         $iResult = \EFileStorageLinkType::GoogleDrive;
     } else {
         if (false !== strpos($sLink, 'dl.dropboxusercontent.com') || false !== strpos($sLink, 'dropbox.com')) {
             $iResult = \EFileStorageLinkType::DropBox;
         } else {
             if (preg_match('/(youtube.com|youtu.be|vimeo.com|soundcloud.com)/i', $sLink)) {
                 $oInfo = \api_Utils::GetOembedFileInfo($sLink);
                 if ($oInfo) {
                     $iResult = constant('\\EFileStorageLinkType::' . $oInfo->provider_name);
                 }
             }
         }
     }
     return $iResult;
 }
コード例 #3
0
ファイル: storage.php プロジェクト: nsine/webmail-lite
 /**
  * @param CAccount $oAccount
  * @param string $sType
  * @param string $sPath
  * @param string $sPattern
  *
  * @return array
  */
 public function getFiles($oAccount, $sType = \EFileStorageTypeStr::Personal, $sPath = '', $sPattern = '')
 {
     $oDirectory = null;
     $aItems = array();
     $aResult = array();
     $oMin = $this->getApiMinManager();
     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;
                     $oEmbedFileInfo = 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) {
                             $oEmbedFileInfo = \api_Utils::GetOembedFileInfo($oItem->LinkUrl);
                             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 ($oEmbedFileInfo) {
                                     $oFileInfo = $oEmbedFileInfo;
                                     $oItem->Name = isset($oFileInfo->title) ? $oFileInfo->title : $oItem->Name;
                                     $oItem->Size = isset($oFileInfo->fileSize) ? $oFileInfo->fileSize : $oItem->Size;
                                     $oItem->OembedHtml = isset($oFileInfo->html) ? $oFileInfo->html : $oItem->OembedHtml;
                                 } 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)) {
                         $iItemLinkType = $oItem->LinkType;
                         if ($oItem->IsLink && $iItemLinkType === \EFileStorageLinkType::GoogleDrive && isset($oFileInfo) && isset($oFileInfo->thumbnailLink)) {
                             $oItem->Thumb = true;
                             $oItem->ThumbnailLink = $oFileInfo->thumbnailLink;
                         } else {
                             if ($oItem->IsLink && $oEmbedFileInfo) {
                                 $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);
                     }
                 }
                 $aResult[] = $oItem;
             }
         }
     }
     return $aResult;
 }