/** * Плагин для смарти * Позволяет получать данные из конфига * * @param array $aParams * @param Smarty $oSmarty * @return string */ function smarty_function_cfg($aParams, &$oSmarty) { if (isset($aParams['_default_short'])) { $aParams['name'] = $aParams['_default_short']; } if (empty($aParams['name'])) { trigger_error("Config: missing 'name' parametr", E_USER_WARNING); return; } if (!isset($aParams['instance'])) { $aParams['instance'] = Config::DEFAULT_CONFIG_INSTANCE; } $mReturn = Config::Get($aParams['name'], $aParams['instance']); /** * Небольшой хак для замены http на https */ $aHttpsKeys = array('path.skin.web', 'path.framework.frontend.web', 'path.framework.libs_vendor.web', 'path.root.web', 'path.skin.assets.web', 'path.framework.web'); if (in_array($aParams['name'], $aHttpsKeys) and is_string($mReturn) and Router::GetIsSecureConnection()) { $mReturn = preg_replace('#^http://#i', 'https://', $mReturn); } /** * Возвращаем значение из конфигурации */ return $mReturn; }
/** * Производит объединение и сжатие файлов * * @param $aAssetItems * @param $sType * @param bool $bCompress * * @return string|bool Web путь до нового файла */ protected function Merge($aAssetItems, $sType, $bCompress = false) { $sCacheDir = Config::Get('path.cache_assets.server') . "/" . Config::Get('view.skin'); $sCacheFile = $sCacheDir . "/" . md5(serialize(array_keys($aAssetItems)) . '_head') . '.' . $sType; /** * Если файла еще нет, то создаем его */ if (!file_exists($sCacheFile)) { /** * Но только в том случае, если еще другой процесс не начал его создавать - проверка на блокировку */ if ($this->IsLockMerge()) { return false; } /** * Создаем директорию для кеша текущего скина, * если таковая отсутствует */ if (!is_dir($sCacheDir)) { @mkdir($sCacheDir, 0777, true); } $sContent = ''; foreach ($aAssetItems as $sFile => $aParams) { $sFile = isset($aParams['file']) ? $aParams['file'] : $aParams['file']; if (strpos($sFile, '//') === 0) { /** * Добавляем текущий протокол */ $sFile = (Router::GetIsSecureConnection() ? 'https' : 'http') . ':' . $sFile; } $sFile = $this->Fs_GetPathServerFromWeb($sFile); /** * Считываем содержимое файла */ if ($sFileContent = @file_get_contents($sFile)) { /** * Создаем объект */ if ($oType = $this->CreateObjectType($sType)) { $oType->setContent($sFileContent); $oType->setFile($sFile); unset($sFileContent); $oType->prepare(); if ($bCompress and (!isset($aParams['compress']) or $aParams['compress'])) { $oType->compress(); } $sContent .= $oType->getContent(); unset($oType); } else { $sContent .= $sFileContent; } } } /** * Создаем файл и сливаем туда содержимое */ @file_put_contents($sCacheFile, $sContent); @chmod($sCacheFile, 0766); /** * Удаляем блокировку */ $this->RemoveLockMerge(); } return $this->Fs_GetPathWebFromServer($sCacheFile); }