/** * @return bool */ public function RawIframe() { $sEncodedUrl = $this->getParamValue('RawKey', ''); $sUrl = urldecode($sEncodedUrl); $sUrl = trim(trim($sUrl), '/\\?'); $aParts = null; if (!empty($sUrl)) { $aParts = explode('/', $sUrl); } if (is_array($aParts) && isset($aParts[0], $aParts[1], $aParts[2], $aParts[3])) { $aValues = \CApi::DecodeKeyValues($aParts[3]); if (isset($aValues['Iframed'], $aValues['Name'], $aValues['AccountID']) && (!isset($aValues['MimeType']) || !isset($aValues['FileName']))) { $aValues['FileName'] = $aValues['Name']; $aValues['MimeType'] = \api_Utils::MimeContentType($aValues['FileName']); } if (isset($aValues['Iframed'], $aValues['MimeType'], $aValues['FileName']) && $aValues['Iframed'] && \CApi::isIframedMimeTypeSupported($aValues['MimeType'], $aValues['FileName'])) { $oAccount = $this->getAccountFromParam(false); if ($oAccount) { $sNewUrl = ''; $sNewHash = ''; $sResultUrl = ''; $aSubParts = \CApi::DecodeKeyValues($aParts[3]); if (isset($aSubParts['Iframed']) && (int) $aParts[2] === (int) $oAccount->IdAccount && 0 < $oAccount->IdAccount) { $aSubParts['Time'] = \time(); $sNewHash = \CApi::EncodeKeyValues($aSubParts); } if (!empty($sNewHash)) { $aParts[3] = $sNewHash; $sNewUrl = rtrim(trim($this->oHttp->GetFullUrl()), '/') . '/?/' . implode('/', $aParts); \CApi::Plugin()->RunHook('webmail.filter.iframed-attachments-url', array(&$sResultUrl, $sNewUrl, $aValues['MimeType'], $aValues['FileName'])); if (empty($sResultUrl) && \CApi::GetConf('labs.allow-officeapps-viewer', true)) { $sResultUrl = 'https://view.officeapps.live.com/op/view.aspx?src=' . urlencode($sNewUrl); } } if (!empty($sResultUrl)) { header('Content-Type: text/html', true); echo '<html style="height: 100%; width: 100%; margin: 0; padding: 0"><head></head><body' . ' style="height: 100%; width: 100%; margin: 0; padding: 0">' . '<iframe style="height: 100%; width: 100%; margin: 0; padding: 0; border: 0" src="' . $sResultUrl . '"></iframe></body></html>'; return true; } } } } return false; }
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); } } $aResult[] = $oItem; } } } return $aResult; }