/** * @return bool */ private function rawFiles($bDownload = true, $bThumbnail = false) { $sRawKey = (string) $this->getParamValue('RawKey', ''); $aValues = \CApi::DecodeKeyValues($sRawKey); if ($bThumbnail) { $this->verifyCacheByKey($sRawKey); } $sHash = (string) $this->getParamValue('TenantHash', ''); $oMin = \CApi::Manager('min'); $mMin = $oMin->getMinByHash($sHash); $oAccount = null; if (!empty($mMin['__hash__'])) { $oAccount = $this->oApiUsers->getAccountById($mMin['Account']); } else { if (isset($aValues['Iframed'], $aValues['Time']) && $aValues['Iframed'] && $aValues['Time']) { $oAccount = $this->getAccountFromParam(true, !($aValues['Time'] > \ProjectCore\Base\Utils::iframedTimestamp())); if (!$oAccount->IsDefaultAccount) { $iAccountId = $this->oApiUsers->getDefaultAccountId($oAccount->IdUser); if (0 < $iAccountId) { $oAccount = $this->oApiUsers->getAccountById($iAccountId); } else { throw new \ProjectCore\Exceptions\ClientException(\ProjectCore\Notifications::AuthError); } } } else { $oAccount = $this->getDefaultAccountFromParam(); } } $oTenant = null; if ($oAccount && $this->oApiTenants) { $oTenant = 0 < $oAccount->IdTenant ? $this->oApiTenants->getTenantById($oAccount->IdTenant) : $this->oApiTenants->getDefaultGlobalTenant(); } if ($this->oApiCapability->isFilesSupported($oAccount) && $oTenant && isset($aValues['Type'], $aValues['Path'], $aValues['Name'])) { $mResult = false; $sFileName = $aValues['Name']; $sContentType = empty($sFileName) ? 'text/plain' : \MailSo\Base\Utils::MimeContentType($sFileName); $oFileInfo = $this->oApiFilestorage->getFileInfo($oAccount, $aValues['Type'], $aValues['Path'], $aValues['Name']); if ($oFileInfo->IsLink) { $iLinkType = \api_Utils::GetLinkType($oFileInfo->LinkUrl); if (isset($iLinkType)) { if (\EFileStorageLinkType::GoogleDrive === $iLinkType) { $oSocial = $oTenant->getSocialByName('google'); if ($oSocial) { $oInfo = \api_Utils::GetGoogleDriveFileInfo($oFileInfo->LinkUrl, $oSocial->SocialApiKey); $sFileName = isset($oInfo->title) ? $oInfo->title : $sFileName; $sContentType = \MailSo\Base\Utils::MimeContentType($sFileName); if (isset($oInfo->downloadUrl)) { $mResult = \MailSo\Base\ResourceRegistry::CreateMemoryResource(); $this->oHttp->SaveUrlToFile($oInfo->downloadUrl, $mResult); rewind($mResult); } } } else { if (\EFileStorageLinkType::DropBox === $iLinkType) { $oFileInfo->LinkUrl = str_replace('www.dropbox.com', 'dl.dropboxusercontent.com', $oFileInfo->LinkUrl); } $mResult = \MailSo\Base\ResourceRegistry::CreateMemoryResource(); $sFileName = basename($oFileInfo->LinkUrl); $sContentType = \MailSo\Base\Utils::MimeContentType($sFileName); $this->oHttp->SaveUrlToFile($oFileInfo->LinkUrl, $mResult); rewind($mResult); } } } else { $mResult = $this->oApiFilestorage->getFile($oAccount, $aValues['Type'], $aValues['Path'], $aValues['Name']); } if (false !== $mResult) { if (is_resource($mResult)) { $sFileName = $this->clearFileName($oFileInfo->Name, $sContentType); $sContentType = \MailSo\Base\Utils::MimeContentType($sFileName); $this->RawOutputHeaders($bDownload, $sContentType, $sFileName); if ($bThumbnail) { $this->cacheByKey($sRawKey); $this->thumbResource($oAccount, $mResult, $sFileName); } else { \MailSo\Base\Utils::FpassthruWithTimeLimitReset($mResult); } @fclose($mResult); } return true; } } return false; }