Beispiel #1
0
 /**
  * Returns the edit theme.
  * By default the edit theme is loaded from the cms.editTheme parameter,
  * but this behavior can be overridden by the cms.editTheme event listeners.
  * If the edit theme is not defined in the configuration file, the active theme
  * is returned.
  * @return \Cms\Classes\Theme Returns the loaded theme object.
  * If the theme doesn't exist, returns null.
  */
 public static function getEditTheme()
 {
     if (self::$editThemeCache !== false) {
         return self::$editThemeCache;
     }
     $editTheme = Config::get('cms.editTheme');
     if (!$editTheme) {
         $editTheme = static::getActiveTheme()->getDirName();
     }
     $apiResult = Event::fire('cms.editTheme', [], true);
     if ($apiResult !== null) {
         $editTheme = $apiResult;
     }
     if (!strlen($editTheme)) {
         throw new SystemException(Lang::get('cms::lang.theme.edit.not_set'));
     }
     $theme = new static();
     $theme->load($editTheme);
     if (!File::isDirectory($theme->getPath())) {
         return self::$editThemeCache = null;
     }
     return self::$editThemeCache = $theme;
 }
Beispiel #2
0
 /**
  * Resets any memory or cache involved with the active or edit theme.
  * @return void
  */
 public static function resetCache()
 {
     self::$activeThemeCache = false;
     self::$editThemeCache = false;
     Cache::forget(self::ACTIVE_KEY);
     Cache::forget(self::EDIT_KEY);
 }
 /**
  * Returns the active theme.
  * By default the active theme is loaded from the cms.activeTheme parameter,
  * but this behavior can be overridden by the cms.activeTheme event listeners.
  * @return \Cms\Classes\Theme Returns the loaded theme object.
  * If the theme doesn't exist, returns null.
  */
 public static function getActiveTheme()
 {
     if (self::$activeThemeCache !== false) {
         return self::$activeThemeCache;
     }
     $activeTheme = Config::get('cms.activeTheme');
     if (DbDongle::hasDatabase()) {
         $dbResult = Cache::remember(self::ACTIVE_KEY, 1440, function () {
             return Parameters::applyKey(self::ACTIVE_KEY)->pluck('value');
         });
         if ($dbResult !== null && static::exists($dbResult)) {
             $activeTheme = $dbResult;
         }
     }
     $apiResult = Event::fire('cms.activeTheme', [], true);
     if ($apiResult !== null) {
         $activeTheme = $apiResult;
     }
     if (!strlen($activeTheme)) {
         throw new SystemException(Lang::get('cms::lang.theme.active.not_set'));
     }
     $theme = static::load($activeTheme);
     if (!File::isDirectory($theme->getPath())) {
         return self::$activeThemeCache = null;
     }
     return self::$activeThemeCache = $theme;
 }