示例#1
0
 /**
  * Updates available theme list. Reads themes directory, adding new themes and removing deleted themes.
  */
 public function updateThemeList()
 {
     $dbThemes = $this->themeDao->findAll();
     $dbThemesArray = array();
     /* @var $value BOL_Theme */
     foreach ($dbThemes as $value) {
         $dbThemesArray[$value->getId()] = $value->getKey();
     }
     $themes = array();
     $defaultThemeExists = false;
     $xmlFiles = UTIL_File::findFiles(OW_DIR_THEME, array("xml"), 1);
     foreach ($xmlFiles as $themeXml) {
         if (basename($themeXml) != self::THEME_XML) {
             continue;
         }
         $xmlInfo = $this->getThemeXmlInfo($themeXml);
         if (!$xmlInfo) {
             continue;
         }
         unset($xmlInfo["masterPages"]);
         $themeKey = trim($xmlInfo["key"]);
         if ($themeKey == self::DEFAULT_THEME) {
             $defaultThemeExists = true;
         }
         if (in_array($themeKey, $dbThemesArray)) {
             unset($dbThemesArray[array_search($themeKey, $dbThemesArray)]);
             continue;
         }
         $result = OW::getEventManager()->call("admin.themes_list_theme_avail", array("name" => $themeKey));
         if ($result === false) {
             continue;
         }
         $newTheme = new BOL_Theme();
         $newTheme->setKey($themeKey);
         $newTheme->setTitle(trim($xmlInfo["name"]));
         $newTheme->setDescription(json_encode($xmlInfo));
         $newTheme->setSidebarPosition($xmlInfo["sidebarPosition"]);
         $this->themeDao->save($newTheme);
         $this->processTheme($newTheme->getId());
     }
     if (!empty($dbThemesArray)) {
         foreach ($dbThemesArray as $id => $themeName) {
             $this->deleteTheme($id);
             if (trim($themeName) === $this->getSelectedThemeName()) {
                 $this->setSelectedThemeName(self::DEFAULT_THEME);
             }
         }
     }
     if (!$defaultThemeExists) {
         throw new LogicException("Cant find default theme `" . self::DEFAULT_THEME . "`!");
     }
 }