Example #1
0
 /**
  * Handles GET requests for the theme listing
  */
 public function get_themes()
 {
     $all_themes = Themes::get_all_data();
     $available_updates = Options::get('updates_available', array());
     foreach ($all_themes as $name => $theme) {
         // only themes with a guid can be checked for updates
         if (isset($theme['info']->guid)) {
             if (isset($available_updates[(string) $theme['info']->guid])) {
                 // @todo this doesn't use the URL and is therefore worthless
                 $all_themes[$name]['info']->update = $available_updates[(string) $theme['info']->guid]['latest_version'];
             }
         }
     }
     $this->theme->all_themes = $all_themes;
     $this->theme->active_theme = Themes::get_active_data(true);
     $this->theme->active_theme_dir = $this->theme->active_theme['path'];
     // If the active theme is configurable, allow it to configure
     $this->theme->active_theme_name = $this->theme->active_theme['info']->name;
     $this->theme->configurable = Plugins::filter('theme_config', false, $this->active_theme);
     $this->theme->assign('configure', Controller::get_var('configure'));
     $activedata = Themes::get_active_data(true);
     $areas = array();
     if (isset($activedata['info']->areas->area)) {
         foreach ($activedata['info']->areas->area as $area) {
             $areas[] = (string) $area;
         }
     }
     $this->theme->areas = $areas;
     $this->theme->previewed = Themes::get_theme_dir(false);
     $this->theme->blocks = Plugins::filter('block_list', array());
     $this->theme->block_instances = DB::get_results('SELECT b.* FROM {blocks} b ORDER BY b.title ASC', array(), 'Block');
     $blocks_areas_t = DB::get_results('SELECT b.*, ba.scope_id, ba.area, ba.display_order FROM {blocks} b INNER JOIN {blocks_areas} ba ON ba.block_id = b.id ORDER BY ba.scope_id ASC, ba.area ASC, ba.display_order ASC', array());
     $blocks_areas = array();
     foreach ($blocks_areas_t as $block) {
         if (!isset($blocks_areas[$block->scope_id])) {
             $blocks_areas[$block->scope_id] = array();
         }
         $blocks_areas[$block->scope_id][$block->area][$block->display_order] = $block;
     }
     $this->theme->blocks_areas = $blocks_areas;
     $scopes = DB::get_results('SELECT * FROM {scopes} ORDER BY name ASC;');
     $scopes = Plugins::filter('get_scopes', $scopes);
     $this->theme->scopes = $scopes;
     $this->theme->scopeid = 0;
     $this->theme->theme_loader = Plugins::filter('theme_loader', '', $this->theme);
     $this->theme->display('themes');
 }
Example #2
0
 /**
  * Handles GET requests for the theme listing
  */
 public function get_themes()
 {
     $all_themes = Themes::get_all_data();
     $theme_names = Utils::array_map_field($all_themes, 'name');
     $available_updates = Options::get('updates_available', array());
     foreach ($all_themes as $name => $theme) {
         // only themes with a guid can be checked for updates
         if (isset($theme['info']->guid)) {
             if (isset($available_updates[(string) $theme['info']->guid])) {
                 // @todo this doesn't use the URL and is therefore worthless
                 $all_themes[$name]['info']->update = $available_updates[(string) $theme['info']->guid]['latest_version'];
             }
         }
         // If this theme requires a parent to be present and it's not, send an error
         if (isset($theme['info']->parent) && !in_array((string) $theme['info']->parent, $theme_names)) {
             $all_themes[$name]['req_parent'] = $theme['info']->parent;
         }
     }
     $this->theme->all_themes = $all_themes;
     $this->theme->active_theme = Themes::get_active_data(true);
     $this->theme->active_theme_dir = $this->theme->active_theme['path'];
     // If the active theme is configurable, allow it to configure
     $this->theme->active_theme_name = $this->theme->active_theme['info']->name;
     $this->theme->configurable = Plugins::filter('theme_config', false, $this->active_theme);
     $this->theme->assign('configure', Controller::get_var('configure'));
     $this->theme->areas = $this->get_areas(0);
     $this->theme->previewed = Themes::get_theme_dir(false);
     $this->theme->help = isset($this->theme->active_theme['info']->help) ? $this->theme->active_theme['info']->help : false;
     $this->theme->help_active = Controller::get_var('help') == $this->theme->active_theme['dir'];
     $this->prepare_block_list();
     $blocks_areas_t = DB::get_results('SELECT b.*, ba.scope_id, ba.area, ba.display_order FROM {blocks} b INNER JOIN {blocks_areas} ba ON ba.block_id = b.id ORDER BY ba.scope_id ASC, ba.area ASC, ba.display_order ASC', array());
     $blocks_areas = array();
     foreach ($blocks_areas_t as $block) {
         if (!isset($blocks_areas[$block->scope_id])) {
             $blocks_areas[$block->scope_id] = array();
         }
         $blocks_areas[$block->scope_id][$block->area][$block->display_order] = $block;
     }
     $this->theme->blocks_areas = $blocks_areas;
     $scopes = DB::get_results('SELECT * FROM {scopes} ORDER BY name ASC;');
     $scopes = Plugins::filter('get_scopes', $scopes);
     $this->theme->scopes = $scopes;
     $this->theme->scopeid = 0;
     $this->theme->theme_loader = Plugins::filter('theme_loader', '', $this->theme);
     $this->theme->display('themes');
 }
Example #3
0
	/**
	 * Returns theme information for the active theme -- dir, path, theme.xml, screenshot url
	 * @params boolean $nopreview If true, return the real active theme, not the preview
	 * @return array An array of Theme data
	 */
	public static function get_active_data( $nopreview = false )
	{
		$all_data = Themes::get_all_data();
		$active_theme_dir = basename( Themes::get_active_theme_dir( $nopreview ) );
		$active_data = $all_data[$active_theme_dir];
		return $active_data;
	}
 /**
  * Handle calls from FormUI actions.
  * Show the form to manage the plugin's options.
  *
  * @param string $plugin_id A unique plugin ID, it needs to match ours.
  * @param string $action The menu item the user clicked.
  */
 public function action_plugin_ui($plugin_id, $action)
 {
     if ($plugin_id == $this->plugin_id) {
         switch ($action) {
             case 'Configure':
                 $themes = array_keys(Themes::get_all_data());
                 $themes = array_combine($themes, $themes);
                 $ui = new FormUI('themeswitcher');
                 $ts_s = $ui->append('select', 'selected_themes', 'themeswitcher__selected_themes', 'Select themes to offer:');
                 $ts_s->multiple = true;
                 $ts_s->options = $themes;
                 $ts_y = $ui->append('select', 'show', 'themeswitcher__show', _t('If not showing with $theme->switcher() always show in footer: '));
                 $ts_y->options = array('0' => _t('No'), '1' => _t('Yes'));
                 $ui->append('submit', 'save', 'Save');
                 $ui->out();
                 break;
         }
     }
 }
Example #5
0
 /**
  * Handles GET requests for the theme listing
  */
 public function get_themes()
 {
     $all_themes = Themes::get_all_data();
     foreach ($all_themes as $name => $theme) {
         if (isset($all_themes[$name]['info']->update) && $all_themes[$name]['info']->update != '' && isset($all_themes[$name]['info']->version) && $all_themes[$name]['info']->version != '') {
             Update::add($name, $all_themes[$name]['info']->update, $all_themes[$name]['info']->version);
         }
     }
     $updates = Update::check();
     foreach ($all_themes as $name => $theme) {
         if (isset($all_themes[$name]['info']->update) && isset($updates[$all_themes[$name]['info']->update])) {
             $all_themes[$name]['info']->update = $updates[$all_themes[$name]['info']->update]['latest_version'];
         } else {
             $all_themes[$name]['info']->update = '';
         }
     }
     $this->theme->all_themes = $all_themes;
     $this->theme->active_theme = Themes::get_active_data(true);
     $this->theme->active_theme_dir = $this->theme->active_theme['path'];
     // If the active theme is configurable, allow it to configure
     $this->theme->active_theme_name = $this->theme->active_theme['info']->name;
     $this->theme->configurable = Plugins::filter('theme_config', false, $this->active_theme);
     $this->theme->assign('configure', Controller::get_var('configure'));
     $activedata = Themes::get_active_data(true);
     $areas = array();
     if (isset($activedata['info']->areas->area)) {
         foreach ($activedata['info']->areas->area as $area) {
             $areas[] = (string) $area;
         }
     }
     $this->theme->areas = $areas;
     $this->theme->previewed = Themes::get_theme_dir(false);
     $this->theme->blocks = Plugins::filter('block_list', array());
     $this->theme->block_instances = DB::get_results('SELECT b.* FROM {blocks} b ORDER BY b.title ASC', array(), 'Block');
     $blocks_areas_t = DB::get_results('SELECT b.*, ba.scope_id, ba.area, ba.display_order FROM {blocks} b INNER JOIN {blocks_areas} ba ON ba.block_id = b.id ORDER BY ba.scope_id ASC, ba.area ASC, ba.display_order ASC', array());
     $blocks_areas = array();
     foreach ($blocks_areas_t as $block) {
         if (!isset($blocks_areas[$block->scope_id])) {
             $blocks_areas[$block->scope_id] = array();
         }
         $blocks_areas[$block->scope_id][$block->area][$block->display_order] = $block;
     }
     $this->theme->blocks_areas = $blocks_areas;
     $this->theme->scopes = DB::get_results('SELECT * FROM {scopes} ORDER BY id ASC;');
     $this->theme->theme_loader = Plugins::filter('theme_loader', '', $this->theme);
     $this->theme->display('themes');
 }
Example #6
0
 /**
  * Ensure that a theme meets requirements for activation/preview
  * @static
  * @param string $theme_dir the directory of the theme
  * @return bool True if the theme meets all requirements
  */
 public static function validate_theme($theme_dir)
 {
     $all_themes = Themes::get_all_data();
     // @todo Make this a closure in php 5.3
     $theme_names = Utils::array_map_field($all_themes, 'name');
     $theme_data = $all_themes[$theme_dir];
     $ok = true;
     if (isset($theme_data['info']->parent) && !in_array((string) $theme_data['info']->parent, $theme_names)) {
         Session::error(_t('This theme requires the parent theme named "%s" to be present prior to activation.', array($theme_data['info']->parent)));
         $ok = false;
     }
     if (isset($theme_data['info']->requires)) {
         $provided = Plugins::provided();
         foreach ($theme_data['info']->requires->feature as $requirement) {
             if (!isset($provided[(string) $requirement])) {
                 Session::error(_t('This theme requires the feature "<a href="%2$s">%1$s</a>" to be present prior to activation.', array((string) $requirement, $requirement['url'])));
                 $ok = false;
             }
         }
     }
     return $ok;
 }
Example #7
0
 public function activate_theme()
 {
     $theme_dir = $this->handler_vars['theme_dir'];
     if (!isset($theme_dir) || empty($theme_dir)) {
         return;
     }
     // set the user_id in the session in case theme activation methods need it
     if (!($u = User::get_by_name($this->handler_vars['admin_username']))) {
         // @todo die gracefully
         die(_t('No admin user found'));
     }
     $u->remember();
     $themes = Themes::get_all_data();
     $theme = $themes[$theme_dir];
     Themes::activate_theme((string) $theme['info']->name, $theme_dir);
     // unset the user_id session variable
     Session::clear_userid($_SESSION['user_id']);
     unset($_SESSION['user_id']);
 }
Example #8
0
 /**
  * Handles GET requests for the theme listing
  */
 public function get_themes()
 {
     $all_themes = Themes::get_all_data();
     foreach ($all_themes as $name => $theme) {
         if (isset($all_themes[$name]['info']->update) && $all_themes[$name]['info']->update != '' && isset($all_themes[$name]['info']->version) && $all_themes[$name]['info']->version != '') {
             Update::add($name, $all_themes[$name]['info']->update, $all_themes[$name]['info']->version);
         }
     }
     $updates = Update::check();
     foreach ($all_themes as $name => $theme) {
         if (isset($all_themes[$name]['info']->update) && isset($updates[$all_themes[$name]['info']->update])) {
             $all_themes[$name]['info']->update = $updates[$all_themes[$name]['info']->update]['latest_version'];
         } else {
             $all_themes[$name]['info']->update = '';
         }
     }
     $this->theme->all_themes = $all_themes;
     $this->theme->active_theme = Themes::get_active_data();
     $this->theme->active_theme_dir = $this->theme->active_theme['path'];
     // If the active theme is configurable, allow it to configure
     $this->theme->active_theme_name = $this->theme->active_theme['info']->name;
     $this->theme->configurable = Plugins::filter('theme_config', false, $this->active_theme);
     $this->theme->assign('configure', Controller::get_var('configure'));
     $this->theme->display('themes');
 }
Example #9
0
 /**
  * Returns theme information for the active theme -- dir, path, theme.xml, screenshot url
  * @return array An array of Theme data
  */
 public static function get_active_data()
 {
     $all_data = Themes::get_all_data();
     $active_theme_dir = basename(Themes::get_active_theme_dir());
     $active_data = $all_data[$active_theme_dir];
     return $active_data;
 }
<?php

$active_theme = Options::get('theme_dir');
$all_themes = Themes::get_all_data();
$selected_themes = Options::get('themeswitcher__selected_themes');
?>
	<div class="sb-switcher">
		<h2>Theme Switcher</h2>
		<form action="" method="post" name="themeswitcher">
			<select name="theme_dir" onChange="this.form.submit()">
				<?php 
foreach ($selected_themes as $selected_theme) {
    $theme = $all_themes[$selected_theme];
    ?>
					<option value="<?php 
    echo $theme['dir'];
    ?>
"<?php 
    echo $theme['dir'] == $active_theme ? 'selected' : '';
    ?>
><?php 
    echo $theme['info']->name;
    ?>
 <?php 
    echo $theme['info']->version;
    ?>
</option>
				<?php 
}
?>
			</select>