protected function EventSkin() { $aParams = $this->GetParams(); $sSkinName = array_shift($aParams); $sRelPath = implode('/', $aParams); $sOriginalFile = Config::Get('path.skins.dir') . $sSkinName . '/' . $sRelPath; if (F::File_Exists($sOriginalFile)) { $sAssetFile = F::File_GetAssetDir() . 'skin/' . $sSkinName . '/' . $sRelPath; if (F::File_Copy($sOriginalFile, $sAssetFile)) { if (headers_sent($sFile, $nLine)) { $sUrl = F::File_GetAssetUrl() . 'skin/' . $sSkinName . '/' . $sRelPath; if (strpos($sUrl, '?')) { $sUrl .= '&' . uniqid(); } else { $sUrl .= '?' . uniqid(); } R::Location($sUrl); } else { header_remove(); if ($sMimeType = F::File_MimeType($sAssetFile)) { header('Content-Type: ' . $sMimeType); } echo file_get_contents($sAssetFile); exit; } } } F::HttpHeader('404 Not Found'); exit; }
/** * Save uploaded image into store * * @param string $sImageFile * @param ModuleUser_EntityUser $oUser * @param string $sType * @param array $aOptions * * @return bool */ protected function _saveTopicImage($sImageFile, $oUser, $sType, $aOptions = array()) { $sExtension = F::File_GetExtension($sImageFile, true); $aConfig = E::ModuleUploader()->GetConfig($sImageFile, 'images.' . $sType); if ($aOptions) { $aConfig['transform'] = F::Array_Merge($aConfig['transform'], $aOptions); } // Check whether to save the original if (isset($aConfig['original']['save']) && $aConfig['original']['save']) { $sSuffix = isset($aConfig['original']['suffix']) ? $aConfig['original']['suffix'] : '-original'; $sOriginalFile = F::File_Copy($sImageFile, $sImageFile . $sSuffix . '.' . $sExtension); } else { $sSuffix = ''; $sOriginalFile = null; } // Transform image before saving $sFileTmp = E::ModuleImg()->TransformFile($sImageFile, $aConfig['transform']); if ($sFileTmp) { $sDirUpload = E::ModuleUploader()->GetUserImageDir($oUser->getId(), true, $sType); $sFileImage = E::ModuleUploader()->Uniqname($sDirUpload, $sExtension); if ($oStoredFile = E::ModuleUploader()->Store($sFileTmp, $sFileImage)) { if ($sOriginalFile) { E::ModuleUploader()->Move($sOriginalFile, $oStoredFile->GetFile() . $sSuffix . '.' . $sExtension); } return $oStoredFile->GetUrl(); } } return false; }
protected function _convertUrlsInCss($sContent, $sSourceDir) { // Есть ли в файле URLs if (!preg_match_all('/(?P<src>src:)?url\\((?P<url>.*?)\\)/is', $sContent, $aMatchedUrl, PREG_OFFSET_CAPTURE)) { return $sContent; } // * Обрабатываем список URLs $aUrls = array(); foreach ($aMatchedUrl['url'] as $nIdx => $aPart) { $sPath = $aPart[0]; //$nPos = $aPart[1]; // * Don't touch data URIs if (strstr($sPath, 'data:')) { continue; } $sPath = str_replace(array('\'', '"'), '', $sPath); // * Если путь является абсолютным, то не обрабатываем if (substr($sPath, 0, 1) == "/" || substr($sPath, 0, 5) == 'http:' || substr($sPath, 0, 6) == 'https:') { continue; } if (($n = strpos($sPath, '?')) || ($n = strpos($sPath, '#'))) { $sPath = substr($sPath, 0, $n); $sFileParam = substr($sPath, $n); } else { $sFileParam = ''; } if (!isset($aUrls[$sPath])) { // if url didn't prepare... $sRealPath = realpath($sSourceDir . $sPath); if ($sRealPath) { $sDestination = F::File_GetAssetDir() . F::Crc32(dirname($sRealPath), true) . '/' . basename($sRealPath); $aUrls[$sPath] = array('source' => $sRealPath, 'destination' => $sDestination, 'url' => E::ModuleViewerAsset()->AssetFileDir2Url($sDestination) . $sFileParam); F::File_Copy($sRealPath, $sDestination); } } } if ($aUrls) { $sContent = str_replace(array_keys($aUrls), F::Array_Column($aUrls, 'url'), $sContent); } return $sContent; }
/** * @param string $sLocalFile * @param string $sParentDir * * @return bool|string */ public function File2Link($sLocalFile, $sParentDir = null) { $sAssetFile = $this->AssetFileDir($sLocalFile, $sParentDir); if (F::File_Exists($sAssetFile) || F::File_Copy($sLocalFile, $sAssetFile)) { return $this->AssetFileUrl($sLocalFile, $sParentDir); } return false; }
/** * Stores uploaded image with optional cropping * * @param string $sFile - The server path to the temporary image file * @param string $sTarget - Target type * @param string $sTargetId - Target ID * @param array|int|bool $xSize - The size of the area to cut the picture: * array('x1'=>0,'y1'=>0,'x2'=>100,'y2'=>100) * 100 - crop 100x100 by center * true - crop square by min side * * @param bool $bMulti - Target has many images * @return bool|ModuleMresource_EntityMresource */ public function StoreImage($sFile, $sTarget, $sTargetId, $xSize = null, $bMulti = FALSE) { $oImg = E::ModuleImg()->Read($sFile); if (!$oImg) { // Возникла ошибка, надо обработать /** TODO Обработка ошибки */ $this->nLastError = self::ERR_TRANSFORM_IMAGE; return false; } $sExtension = strtolower(pathinfo($sFile, PATHINFO_EXTENSION)); $aConfig = $this->GetConfig($sFile, 'images.' . $sTarget); // Check whether to save the original if (isset($aConfig['original']['save']) && $aConfig['original']['save']) { $sSuffix = isset($aConfig['original']['suffix']) ? $aConfig['original']['suffix'] : '-original'; $sOriginalFile = F::File_Copy($sFile, $sFile . $sSuffix . '.' . $sExtension); } else { $sOriginalFile = null; } if (!is_null($xSize)) { if ($xSize === true) { // crop square by min side $oImg = E::ModuleImg()->CropSquare($oImg, TRUE); } elseif (is_numeric($xSize)) { // crop square in center $oImg = E::ModuleImg()->CropCenter($oImg, intval($xSize), intval($xSize)); } elseif (is_array($xSize) && !empty($xSize)) { if (!isset($xSize['w']) && isset($xSize['x1']) && isset($xSize['x2'])) { $xSize['w'] = $xSize['x2'] - $xSize['x1']; } if (!isset($xSize['h']) && isset($xSize['y1']) && isset($xSize['y2'])) { $xSize['h'] = $xSize['y2'] - $xSize['y1']; } if (isset($xSize['w']) && !isset($xSize['h'])) { $xSize['h'] = $oImg->getHeight(); } if (!isset($xSize['w']) && isset($xSize['h'])) { $xSize['w'] = $oImg->getWidth(); } if (isset($xSize['w']) && isset($xSize['h']) && !(isset($xSize['x1']) && isset($xSize['y1']))) { $oImg = E::ModuleImg()->CropCenter($oImg, $xSize['w'], $xSize['h']); } else { $oImg = E::ModuleImg()->Crop($oImg, $xSize['w'], $xSize['h'], $xSize['x1'], $xSize['y1']); } } } if ($aConfig['transform']) { E::ModuleImg()->Transform($oImg, $aConfig['transform']); } // Сохраняем изображение во временный файл if ($sTmpFile = $oImg->Save(F::File_UploadUniqname($sExtension))) { // Файл, куда будет записано изображение $sImageFile = $this->Uniqname(E::ModuleUploader()->GetUserImageDir(E::UserId(), true, false), $sExtension); // Окончательная запись файла if ($oStoredFile = $this->Store($sTmpFile, $sImageFile)) { $oResource = E::ModuleMresource()->GetMresourcesByUuid($oStoredFile->getUuid()); $aTmpTarget = array('topic_comment', 'talk_comment', 'talk'); if (!(in_array($sTarget, $aTmpTarget) && !$sTargetId)) { if (!$this->AddRelationResourceTarget($oResource, $sTarget, $sTargetId, $bMulti)) { // TODO Возможная ошибка } } return $oStoredFile; } } return false; }
/** * @param string $sLocalFile * @param string $sParentDir * * @return bool|string */ public function File2Link($sLocalFile, $sParentDir = null) { $sAssetFile = $this->AssetFileDir($sLocalFile, $sParentDir); $aInfo = F::File_PathInfo($sLocalFile); if (F::File_Exists($sAssetFile) || F::File_Copy($aInfo['dirname'] . '/' . $aInfo['basename'], $sAssetFile)) { return $this->AssetFileUrl($sLocalFile, $sParentDir); } return false; }
/** * Обработка файла * * @param string $sFile * @param string $sDestination * * @return string */ public function PrepareFile($sFile, $sDestination) { return F::File_Copy($sFile, $sDestination); }