function _smarty_prefilter_tplhook_mark($sSource, Smarty_Internal_Template $oTemplate) { $sTemplateFile = ACE::FilePath($oTemplate->smarty->_current_file); $nLevel = intval(Config::Get('plugin.aceadminpanel.smarty.options.mark_template_lvl')); $sSource = ($nLevel ? "\n\n" : "") . "<!-- TEMPLATE BEGIN ({$nLevel} " . $sTemplateFile . ") -->" . ($nLevel ? "\n" : "") . $sSource . ($nLevel ? "\n" : "") . "<!-- TEMPLATE END ({$nLevel} " . $sTemplateFile . ") -->" . ($nLevel ? "\n" : ""); Config::Set('plugin.aceadminpanel.smarty.options.mark_template_lvl', ++$nLevel); return $sSource; }
public function EventExec() { $sFile = ''; $sSourceFile = implode('/', $this->GetParams()); $sSourceFile = str_replace('[skin]', HelperPlugin::GetTemplatePath(), $sSourceFile); $sSourceFile = str_replace('[admin_skin]', HelperPlugin::GetPluginPath('aceadminpanel') . '/templates/skin/' . $this->Admin_GetAdminSkin(), $sSourceFile); if (isset($_SERVER['QUERY_STRING']) and $_SERVER['QUERY_STRING']) { $sSourceFile .= '?' . $_SERVER['QUERY_STRING']; } $sCachePath = Config::Get('path.smarty.cache') . '/' . $this->Admin_GetAdminSkin(); $aFileParts = ACE::PathInfo($sSourceFile); if (strtolower($aFileParts['extension']) == 'css' and getRequest('from', '', 'get') == 'less') { $sSourceFile = $aFileParts['dirname'] . '/' . $aFileParts['filename'] . '.less'; $sFileType = 'less'; } elseif (strtolower($aFileParts['extension']) == 'less') { $sFileType = 'less'; } else { $sFileType = 'other'; } if ($sFileType == 'less') { $sCachePath .= '/css/'; if (!is_dir($sCachePath)) { ACE::MakeDir($sCachePath); } $aLessParams = array('file' => $sSourceFile, 'config' => array('formatter' => 'compressed'), 'variables' => array('gridColumns' => 16, 'gridColumnWidth' => '65px', 'gridGutterWidth' => '12px', 'baseFontSize' => '12px', 'baseLineHeight' => '18px')); // определяем целевой CSS-файл $sFile = ACE::FilePath($sCachePath . '/' . md5(serialize($aLessParams)) . '.css'); // если целевого файла нет - компилируем его из исходного LESS-файла if (!is_file($sFile)) { $oLess = $this->PluginAceadminpanel_Aceless_GetLessCompiler(); $oLess->setVariables($aLessParams['variables'], true); $oLess->setFormatter('compressed'); $oLess->checkedCompile($sSourceFile, $sFile); $this->aFiles[] = array('source' => $sSourceFile, 'target' => $sFile); } $sContentType = 'text/css'; } else { $sCachePath .= '/' . basename($aFileParts['dirname']) . '/'; if (!is_dir($sCachePath)) { ACE::MakeDir($sCachePath); } $sFile = $sCachePath . $aFileParts['basename']; copy($sSourceFile, $sFile); $sContentType = 'image/' . strtolower($aFileParts['extension']); } if ($sFile and is_file($sFile)) { $sCssContent = file_get_contents($sFile); header('Content-type: ' . $sContentType); echo $sCssContent; } /* */ exit; }
/** * Проверка, можем ли писать в текущий лог-файл */ protected function _checkLogFile() { if ($this->bCheckLogFiles and $this->sFileName and $this->sFileName != '-') { $sFile = ACE::FilePath($this->sPathLogs . $this->sFileName); if (!isset($this->aCheckedFiles[$sFile])) { // Проверяем, можем ли писать в лог-файл if ($fp = @fopen($sFile, 'a')) { fclose($fp); $this->aCheckedFiles[$sFile] = true; } else { if (($this->oUserCurrent or $this->oUserCurrent = $this->User_GetUserCurrent()) and $this->oUserCurrent->isAdministrator()) { $this->Message_AddError('Cannot write to log file "' . $sFile . '"', $this->Lang_Get('error')); //$this->Message_AddError('Cannot write to log file "' . $sFile . '"', $this->Lang_Get('error'), true); } $this->aCheckedFiles[$sFile] = false; } } return $this->aCheckedFiles[$sFile]; } return true; }
protected function ClearCache() { if (!ACE::ClearDir(Config::Get('path.smarty.compiled'))) { $this->Message_AddErrorSingle('Unable to remove content of dir <b>' . ACE::FilePath(Config::Get('path.smarty.compiled')) . '</b>. It is recommended to do it manually', $this->Lang_Get('attention'), true); } if (!ACE::ClearDir(Config::Get('path.smarty.cache'))) { $this->Message_AddErrorSingle('Unable to remove content of dir <b>' . ACE::FilePath(Config::Get('path.smarty.cache')) . '</b>. It is recommended to do it manually', $this->Lang_Get('attention'), true); } $result = ACE::ClearAllCache(); return $result; }
public function GetPluginDir($sPlugin = null) { $sResult = ACE::FilePath(Config::Get('path.root.server') . '/plugins', '/'); if ($sPlugin) { $sResult .= '/' . strtolower($sPlugin); } return $sResult; }
/** * Определяет тип блока * * @param string $sName - Название блока * @param string|null $sDir - Путь до блока (определяется само для плагинов, если передать параметр 'plugin'=>'myplugin') * @return string ('block','template','undefined') * @throws Exception */ protected function DefineTypeBlock($sName, $sDir = null) { if ($sDir) { // * Если найден шаблон вида block.name.tpl то считаем что тип 'block' if (is_file(ACE::FilePath($sDir . '/blocks/block.' . $sName . '.tpl'))) { return 'block'; } // * Если найден шаблон по имени блока то считаем его простым шаблоном if (is_file(ACE::FilePath($sDir . '/' . $sName))) { return 'template'; } } return parent::DefineTypeBlock($sName, $sDir); }
public function LoadFile($sFileName) { if (strpos($sFileName, '%%language%%') !== false) { $this->LoadFile(ACE::FilePath(str_replace('%%language%%', $this->GetLangDefault(), $sFileName))); $this->LoadFile(ACE::FilePath(str_replace('%%language%%', $this->GetLang(), $sFileName))); } else { if (is_file($sFileName)) { $aLangMessages = (array) (include $sFileName); $this->aLangMsg = array_merge($this->aLangMsg, $aLangMessages); } } }
/** * Возвращает путь к шаблону скина плагина * * @param string $sFile * @param string $sPlugin * * @return string */ public static function GetTemplatePath($sFile = '', $sPlugin = '') { if ($sPath = self::GetPluginSkinPath($sPlugin)) { if ($sFile) { if (substr($sFile, 0, 1) != '/') { $sFile = '/' . $sFile; } $sPath .= $sFile; } else { $sPath .= '/'; } } return ACE::FilePath($sPath, '/'); }
public function GetCustomConfigFile() { return ACE::FilePath(Config::Get('sys.cache.dir') . CUSTOM_CFG); }
public function PluginConfigSave($sPlugin = null) { if (!$this->sPluginAddon) { $this->sPluginAddon = HelperPlugin::GetPluginName($this, true); } if (!$sPlugin) { $sPlugin = $this->sPluginAddon; } $sFile = ACE::FilePath(Config::Get('sys.cache.dir') . 'adm.' . $sPlugin . '.cfg'); if (@file_put_contents($sFile, serialize(Config::Get('plugin.' . $sPlugin)))) { $this->Message('notice', $this->Lang_Get('adm_saved_ok')); } else { $this->Message('error', $this->Lang_Get('adm_saved_err')); } }
/** * Рекурсивное создание папки (если ее нет) * * @static * * @param $sNewDir * @param int $nMode * @param bool $bQuiet * * @return bool|string */ static function MakeDir($sNewDir, $nMode = 0755, $bQuiet = false) { $sBasePath = ACE::FilePath(self::GetRootDir() . '/'); if (substr($sNewDir, 0, 2) == '//') { $sNewDir = substr($sNewDir, 2); } else { $sNewDir = ACE::LocalPath($sNewDir, $sBasePath); } $sTempPath = $sBasePath; $aNewDir = explode('/', $sNewDir); foreach ($aNewDir as $sDir) { if ($sDir != '.' and $sDir != '') { $sCheckPath = $sTempPath . $sDir . '/'; if (!is_dir($sCheckPath)) { if ($bQuiet) { $bResult = @mkdir($sCheckPath, $nMode, true); } else { $bResult = mkdir($sCheckPath, $nMode, true); } if ($bResult) { //; } else { //die('Cannot make dir "' . $sCheckPath . '"'); return false; } if ($bQuiet) { @chmod($sCheckPath, $nMode); } else { chmod($sCheckPath, $nMode); } } $sTempPath = $sCheckPath; } } return $sTempPath; }
/** * Определяет тип блока * * @param string $sName - Название блока * @param string|null $sDir - Путь до блока (определяется само для плагинов, если передать параметр 'plugin'=>'myplugin') * @return string ('block','template','undefined') * @throws Exception */ protected function DefineTypeBlock($sName, $sDir = null) { if ($sDir) { // * Если найден шаблон вида block.name.tpl то считаем что тип 'block' if (is_file(ACE::FilePath($sDir . '/blocks/block.' . $sName . '.tpl'))) { return 'block'; } // * Если найден шаблон по имени блока то считаем его простым шаблоном if (is_file(ACE::FilePath($sDir . '/' . $sName))) { return 'template'; } } /* try { $xResult = parent::DefineTypeBlock($sName, $sDir); } catch (Exception $e) { // если ищется шаблон плагина, и его скин не default, и он не найден, то делается попытка найти шаблон в default if (substr($e->getMessage(), 0, 22) == 'Can not find the block' AND ($s = ACE::InPath($sDir, ACE::GetRootDir() . '/plugins/*'))) { $n = strrpos($sDir, '/', -2); $sSkin = trim(substr($sDir, $n), '/'); if ($sSkin !== 'default') $sDir = substr($sDir, 0, $n) . '/default/'; $xResult = parent::DefineTypeBlock($sName, $sDir); } } */ $xResult = parent::DefineTypeBlock($sName, $sDir); return $xResult; }
public function Call() { if ($this->SourceTypeIsTemplate()) { // получаем пути к шаблонам $aTplDirs = $this->GetSmarty()->getTemplateDir(); $sTemplate = $this->GetContentSource(); $sFile = ''; // лежит ли подгружаемый шаблон по одному из путей foreach ($aTplDirs as $sDir) { if (ACE::LocalPath(dirname($sTemplate), $sDir) and ACE::FileExists($sTemplate)) { $sFile = $sTemplate; break; } } if (!$sFile) { // варианты расположения шаблона foreach ($aTplDirs as $sDir) { if (ACE::FileExists($sDir . '/' . $sTemplate)) { $sFile = ACE::FilePath($sDir . '/' . $sTemplate); } } } if (!$sFile) { $sFile = $sTemplate; } $sResult = file_get_contents($sFile); } elseif ($this->SourceTypeIsCallback()) { $sResult = call_user_func_array($this->GetContentSource(), array()); } else { $sResult = $this->GetContentSource(); } return $sResult; }
static function CheckTmpDirs() { if (self::_getVal('tmp.path.use')) { $sTmpPath = ACE::FilePath(self::_getVal('tmp.path.root')); if (!$sTmpPath) { $sTmpPath = Config::Get('sys.cache.dir'); } if (!is_dir($sTmpPath)) { $bOk = false; $sContent = 'Order Deny,Allow' . PHP_EOL . 'Deny from all'; if (ACE::MakeDir($sTmpPath, 0777, true) and file_put_contents($sTmpPath . '.htaccess', $sContent)) { $bOk = chmod($sTmpPath . '.htaccess', 0644); } } else { $bOk = true; } if ($bOk) { self::_makeTmpDir($sTmpPath, 'tmp.dir.sys', 'sys.cache.dir'); self::_makeTmpDir($sTmpPath, 'tmp.dir.tpl.compiled', 'path.smarty.compiled'); self::_makeTmpDir($sTmpPath, 'tmp.dir.tpl.cache', 'path.smarty.cache'); self::_makeTmpDir($sTmpPath, 'tmp.dir.log', 'sys.logs.path'); } } }