function action_init() { if (!empty($_GET['theme_dir']) || !empty($_POST['theme_dir'])) { $new_theme_dir = empty($_GET['theme_dir']) ? $_POST['theme_dir'] : $_GET['theme_dir']; $all_themes = Themes::get_all(); if (array_key_exists($new_theme_dir, $all_themes)) { if (!isset($_COOKIE['theme_dir']) || isset($_COOKIE['theme_dir']) && $_COOKIE['theme_dir'] != $new_theme_dir) { $_COOKIE['theme_dir'] = $new_theme_dir; // Without this, the cookie isn't get in time to change the theme NOW. setcookie('theme_dir', $new_theme_dir); } } } $this->add_template('switcher', dirname(__FILE__) . '/themeswitcher.php'); }
/** * Returns the active theme's full directory path. * @params boolean $nopreview If true, return the real active theme, not the preview * @return string The full path to the active theme directory */ private static function get_active_theme_dir($nopreview = false) { $theme_dir = self::get_theme_dir($nopreview); $themes = Themes::get_all(); if (!isset($themes[$theme_dir])) { $theme_exists = false; foreach ($themes as $themedir) { if (file_exists(Utils::end_in_slash($themedir) . 'theme.xml')) { $theme_dir = basename($themedir); Options::set('theme_dir', basename($themedir)); $theme_exists = true; break; } } if (!$theme_exists) { die(_t('There is no valid theme currently installed.')); } } return $themes[$theme_dir]; }
/** * Determines if an option is for a theme * * @param $option Name of the option being checked * @return mixed Returns the theme name on success, or FALSE if not found */ public function is_theme_option($option) { if ($all_themes = Themes::get_all()) { foreach ($all_themes as $theme_name => $theme_file) { if (0 === strpos($option, strtolower($theme_name) . '_')) { return $theme_name; } } } return FALSE; }
/** * Returns the active theme's full directory path. * @params boolean $nopreview If true, return the real active theme, not the preview * @return string The full path to the active theme directory */ private static function get_active_theme_dir( $nopreview = false ) { $theme_dir = self::get_theme_dir( $nopreview ); $themes = Themes::get_all(); // If our active theme directory has gone missing, iterate through the others until we find one we can use and activate it. if ( !isset( $themes[$theme_dir] ) ) { $theme_exists = false; foreach ( $themes as $themedir ) { if ( file_exists( Utils::end_in_slash( $themedir ) . 'theme.xml' ) ) { $theme_dir = basename( $themedir ); EventLog::log( _t( "Active theme directory no longer available. Falling back to '{$theme_dir}'" ), 'err', 'theme', 'habari' ); Options::set( 'theme_dir', basename( $themedir ) ); $fallback_theme = Themes::create(); Plugins::act_id( 'theme_activated', $fallback_theme->plugin_id(), $theme_dir, $fallback_theme ); $theme_exists = true; // Refresh to the newly "activated" theme to ensure it takes the options that have just been set above and doesn't produce any errors. Utils::redirect(); break; } } if ( !$theme_exists ) { die( _t( 'There is no valid theme currently installed.' ) ); } } return $themes[$theme_dir]; }