/** * 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->getName(); } $themes = array(); $defaultThemeExists = false; $xmlFiles = UTIL_File::findFiles(OW_DIR_THEME, array('xml'), 1); foreach ($xmlFiles as $themeXml) { if (basename($themeXml) === self::MANIFEST_FILE) { $xml = simplexml_load_file($themeXml); if ((string) $xml->key === self::DEFAULT_THEME) { $defaultThemeExists = true; } if (in_array((string) $xml->key, $dbThemesArray)) { unset($dbThemesArray[array_search((string) $xml->key, $dbThemesArray)]); continue; } $name = (string) $xml->key; $title = (string) $xml->name; $sidebarPosition = (string) $xml->sidebarPosition; if (!in_array(trim($sidebarPosition), array('left', 'right', 'none'))) { $sidebarPosition = 'none'; } $xmlArray = (array) $xml; unset($xmlArray['masterPages']); $description = json_encode($xmlArray); if (!trim($name) || !trim($title)) { $problemThemes[] = trim($name); } $result = OW::getEventManager()->call('admin.themes_list_theme_avail', array('name' => $name)); if ($result === false) { continue; } $newTheme = new BOL_Theme(); $newTheme->setName($name); $newTheme->setTitle($title); $newTheme->setDescription($description); $newTheme->setSidebarPosition($sidebarPosition); $this->themeDao->save($newTheme); $this->processTheme($newTheme->getId()); } } if (!empty($dbThemesArray)) { foreach ($dbThemesArray as $id => $themeName) { $this->deleteTheme($id); if (trim($themeName) === OW::getConfig()->getValue('base', 'selectedTheme')) { OW::getConfig()->saveConfig('base', 'selectedTheme', self::DEFAULT_THEME); } } } if (!$defaultThemeExists) { throw new LogicException('Cant find default theme!'); } if (!empty($problemThemes)) { throw new LogicException('Cant process themes `' . implode(',', $problemThemes) . '`!'); } }
/** * 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 . "`!"); } }