protected function ClearCache()
 {
     if (!admClearDir(Config::Get('path.smarty.compiled'))) {
         $this->Message_AddErrorSingle('Unable to remove content of dir <b>' . admFilePath(Config::Get('path.smarty.compiled')) . '</b>. It is recommended to do it manually', $this->Lang_Get('attention'), true);
     }
     if (!admClearDir(Config::Get('path.smarty.cache'))) {
         $this->Message_AddErrorSingle('Unable to remove content of dir <b>' . admFilePath(Config::Get('path.smarty.cache')) . '</b>. It is recommended to do it manually', $this->Lang_Get('attention'), true);
     }
     $result = admClearAllCache();
     return $result;
 }
 public function PluginConfigSave($sPlugin = null)
 {
     if (!$this->sPluginAddon) {
         $this->sPluginAddon = HelperPlugin::GetPluginName($this, true);
     }
     if (!$sPlugin) {
         $sPlugin = $this->sPluginAddon;
     }
     $sFile = admFilePath(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'));
     }
 }
Example #3
0
 public function Activate($sPlugin)
 {
     $aConditions = array('<' => 'lt', 'lt' => 'lt', '<=' => 'le', 'le' => 'le', '>' => 'gt', 'gt' => 'gt', '>=' => 'ge', 'ge' => 'ge', '==' => 'eq', '=' => 'eq', 'eq' => 'eq', '!=' => 'ne', '<>' => 'ne', 'ne' => 'ne');
     $aPlugins = $this->GetList();
     if (!isset($aPlugins[$sPlugin])) {
         return null;
     }
     $sPluginName = ucfirst($sPlugin);
     $sFile = admFilePath("{$this->sPluginsDir}{$sPlugin}/Plugin{$sPluginName}.class.php");
     if (is_file($sFile)) {
         require_once $sFile;
         $sClassName = "Plugin{$sPluginName}";
         $oPlugin = new $sClassName();
         /**
          * Проверяем совместимость с версией LS
          */
         if (defined('LS_VERSION') and version_compare(LS_VERSION, $aPlugins[$sPlugin]['property']->requires->livestreet, '=<')) {
             $this->Message_AddError($this->Lang_Get('plugins_activation_version_error', array('version' => $aPlugins[$sPlugin]['property']->requires->livestreet)), $this->Lang_Get('error'), true);
             return false;
         }
         // * Проверяем наличие require-плагинов
         if ($aPlugins[$sPlugin]['property']->requires->plugins) {
             $aActivePlugins = $this->GetActivePlugins();
             $iError = 0;
             foreach ($aPlugins[$sPlugin]['property']->requires->plugins->children() as $sReqPlugin) {
                 // * Есть ли требуемый активный плагин
                 if (!in_array($sReqPlugin, $aActivePlugins)) {
                     $iError++;
                     $this->Message_AddError($this->Lang_Get('plugins_activation_requires_error', array('plugin' => ucfirst($sReqPlugin))), $this->Lang_Get('error'), true);
                 } else {
                     if (isset($sReqPlugin['name'])) {
                         $sReqPluginName = (string) $sReqPlugin['name'];
                     } else {
                         $sReqPluginName = ucfirst($sReqPlugin);
                     }
                     if (isset($sReqPlugin['version'])) {
                         $sReqVersion = $sReqPlugin['version'];
                         if (isset($sReqPlugin['condition']) && array_key_exists((string) $sReqPlugin['condition'], $aConditions)) {
                             $sReqCondition = $aConditions[(string) $sReqPlugin['condition']];
                         } else {
                             $sReqCondition = 'eq';
                         }
                         $sClassName = "Plugin{$sReqPlugin}";
                         $oReqPlugin = new $sClassName();
                         // * Версия может задавать константой
                         // * или возвращаться методом плагина GetVersion()
                         if (method_exists($oReqPlugin, 'GetVersion')) {
                             $sReqPluginVersion = $oReqPlugin->GetVersion();
                         } elseif (Config::Get('plugin.' . strtolower($sReqPlugin) . '.version')) {
                             $sReqPluginVersion = Config::Get('plugin.' . strtolower($sReqPlugin) . '.version');
                         } elseif (defined(strtoupper('VERSION_' . $sReqPluginName))) {
                             $sReqPluginVersion = constant(strtoupper('VERSION_' . $sReqPluginName));
                         } elseif (defined(strtoupper($sReqPluginName . '_VERSION'))) {
                             $sReqPluginVersion = constant(strtoupper($sReqPluginName . '_VERSION'));
                         } else {
                             $sReqPluginVersion = false;
                         }
                         if (!$sReqPluginVersion) {
                             $iError++;
                             $this->Message_AddError($this->Lang_Get('adm_plugin_havenot_getversion_method', array('plugin' => $sReqPluginName)), $this->Lang_Get('error'), true);
                         } else {
                             // * Если требуемый плагин возвращает версию, то проверяем ее
                             if (!version_compare($sReqPluginVersion, $sReqVersion, $sReqCondition)) {
                                 $sTextKey = 'adm_plugin_activation_reqversion_error_' . $sReqCondition;
                                 $iError++;
                                 $this->Message_AddError($this->Lang_Get($sTextKey, array('plugin' => $sReqPluginName, 'version' => $sReqVersion)), $this->Lang_Get('error'), true);
                             }
                         }
                     }
                 }
             }
             if ($iError) {
                 return false;
             }
         }
         // * Проверяем, не вступает ли данный плагин в конфликт с уже активированными
         // * (по поводу объявленных делегатов)
         $aPluginDelegates = $oPlugin->GetDelegates();
         $iError = 0;
         foreach ($this->aDelegates as $sGroup => $aReplaceList) {
             $iCount = 0;
             if (isset($aPluginDelegates[$sGroup]) and is_array($aPluginDelegates[$sGroup]) and $iCount = count($aOverlap = array_intersect_key($aReplaceList, $aPluginDelegates[$sGroup]))) {
                 $iError += $iCount;
                 foreach ($aOverlap as $sResource => $aConflict) {
                     $this->Message_AddError($this->Lang_Get('plugins_activation_overlap', array('resource' => $sResource, 'delegate' => $aConflict['delegate'], 'plugin' => $aConflict['sign'])), $this->Lang_Get('error'), true);
                 }
             }
             if ($iCount) {
                 return false;
             }
         }
         $bResult = $oPlugin->Activate();
     } else {
         // * Исполняемый файл плагина не найден
         $this->Message_AddError($this->Lang_Get('adm_plugin_file_not_found', array('file' => $sFile)), $this->Lang_Get('error'), true);
         return false;
     }
     if ($bResult) {
         // * Переопределяем список активированных пользователем плагинов
         $aActivePlugins = $this->GetActivePlugins();
         $aActivePlugins[] = $sPlugin;
         $bResult = $this->SetActivePlugins($aActivePlugins);
         if (!$bResult) {
             $this->Message_AddError($this->Lang_Get('adm_plugin_write_error', array('file' => $this->sPluginsDatFile)), $this->Lang_Get('error'), true);
         }
     }
     return $bResult;
 }
Example #4
0
 public function GetCustomConfigFile()
 {
     return admFilePath(Config::Get('sys.cache.dir') . CUSTOM_CFG);
 }
 protected function _callAdminAddon($aAddon, $aArgs)
 {
     if (!is_array($aAddon)) {
         if (!isset($this->aAddons[$aAddon])) {
             return;
         }
         $aAddon = $this->aAddons[$aAddon];
     }
     $sFileName = $aAddon['file'];
     $sClassName = $aAddon['class'];
     if (isset($aAddon['template']) and $aAddon['template']) {
         $sTemplate = $aAddon['template'];
     } else {
         $sTemplate = '';
     }
     if (isset($aAddon['language']) and $aAddon['language']) {
         $sLangFile = $aAddon['language'];
     } else {
         $sLangFile = '';
     }
     include_once $sFileName;
     $oEventClass = new $sClassName($this->oEngine, $this->sCurrentAction);
     // * load template
     if ($sTemplate) {
         $this->Viewer_Assign('tpl_include', $sTemplate);
     }
     // * load css
     //$sCssFile = HelperPlugin::GetTemplatePath('css/admin_site_settings.css');
     //$this->Viewer_AppendStyle($sCssFile);
     // * load language texts
     if ($sLangFile) {
         $this->Lang_LoadFile(admFilePath(str_replace('%%language%%', $this->Lang_GetLang(), $sLangFile)));
     }
     $oEventClass->SetAdminAction($this);
     $oEventClass->Init();
     $result = call_user_func_array(array($oEventClass, 'Event'), $aArgs);
     $oEventClass->EventShutdown();
     $oEventClass->Done();
     return $result;
 }
Example #6
0
/**
 * Преобразование урл в путь на сервере
 *
 * @param  $sUrl
 * @return string
 */
function admUrl2Path($sUrl)
{
    // * Delete www from path
    $sUrl = str_replace('//www.', '//', $sUrl);
    $sPathWeb = str_replace('//www.', '//', Config::Get('path.root.web'));
    // * do replace
    $sUrl = str_replace($sPathWeb, Config::Get('path.root.server'), $sUrl);
    return admFilePath($sUrl);
}
Example #7
0
 public function _CallAdminAddon($sAddon)
 {
     $sFileName = $this->aAddons[$sAddon]['file'];
     $sClassName = $this->aAddons[$sAddon]['class'];
     if (isset($this->aAddons[$sAddon]['template'])) {
         $sTemplate = $this->aAddons[$sAddon]['template'];
     } else {
         $sTemplate = '';
     }
     if (isset($this->aAddons[$sAddon]['language'])) {
         $sLangFile = $this->aAddons[$sAddon]['language'];
     } else {
         $sLangFile = '';
     }
     include_once $sFileName;
     // * load template
     if ($sTemplate) {
         $this->Viewer_Assign('tpl_content', $sTemplate);
     }
     // * load css
     //$sCssFile = HelperPlugin::GetTemplatePath('css/admin_site_settings.css');
     //$this->Viewer_AppendStyle($sCssFile);
     // * load language texts
     if ($sLangFile) {
         $this->Lang_LoadFile(admFilePath(str_replace('%%language%%', $this->Lang_GetLang(), $sLangFile)));
     }
     $oEventClass = new $sClassName($this->oEngine, $this->sCurrentAction);
     $oEventClass->SetAdminAction($this);
     $oEventClass->Init();
     $result = $oEventClass->Event();
     $oEventClass->EventShutdown();
     $oEventClass->Done();
     return $result;
 }