You are here

class sweaver_plugin_themeswitch in Sweaver 6

Same name and namespace in other branches
  1. 7 plugins/sweaver_plugin_themeswitch/sweaver_plugin_themeswitch.inc \sweaver_plugin_themeswitch

@file Themeswitch plugin.

Hierarchy

Expanded class hierarchy of sweaver_plugin_themeswitch

1 string reference to 'sweaver_plugin_themeswitch'
_sweaver_sweaver_plugins in ./sweaver.registry.inc
Sweaver plugins.

File

plugins/sweaver_plugin_themeswitch/sweaver_plugin_themeswitch.inc, line 7
Themeswitch plugin.

View source
class sweaver_plugin_themeswitch extends sweaver_plugin {

  /**
   * Menu registry.
   */
  public function sweaver_menu(&$weight, $page_arguments, $base) {
    $items = array();

    // Theme classes groups administration.
    $base['access arguments'] = array(
      'use editor',
    );
    $items['sweaver_themeswitch'] = $base + array(
      'title' => 'Theme switch',
      'page arguments' => array(
        $page_arguments,
      ),
      'type' => MENU_CALLBACK,
      'weight' => $weight++,
    );
    return $items;
  }

  /**
   * Init
   */
  public function sweaver_init() {
    global $custom_theme;
    $custom_theme = Sweaver::get_instance()
      ->get_theme_key();
  }

  /**
   * Frontend form.
   */
  public function sweaver_form() {
    $form = array();
    $content = '';
    $no_image = drupal_get_path('module', 'sweaver') . '/plugins/sweaver_plugin_themeswitch/no_screenshot.png';
    $theme_key = Sweaver::get_instance()
      ->get_theme_key();
    $number_of_themes = 0;
    $themes = sweaver_get_all_themes();
    foreach ($themes as $theme) {
      if (isset($theme->info['screenshot']) && file_exists($theme->info['screenshot'])) {
        $image_file = $theme->info['screenshot'];
      }
      else {
        $image_file = $no_image;
      }
      if ($theme_key != $theme->name) {
        $switch_description = t('Switch to @theme', array(
          '@theme' => $theme->info['name'],
        ));
        $image = sweaver_theme_image($image_file, $switch_description, $switch_description, array(
          'width' => '150',
          'height' => '90',
        ), FALSE);
        $image = l($image, 'sweaver_themeswitch/' . $theme->name, array(
          'alias' => TRUE,
          'html' => TRUE,
          'query' => drupal_get_destination(),
        ));
        $content .= '<div class="selected-image">' . $image;
      }
      else {
        $switch_description = t('This theme is currently selected');
        $image = sweaver_theme_image($image_file, $switch_description, $switch_description, array(
          'width' => '150',
          'height' => '90',
        ), FALSE);
        $content .= '<div class="selected-image selected-image-default">' . $image;
      }
      $number_of_themes++;
      $content .= '<br />' . check_plain($theme->info['name']);
      $content .= '</div>';
    }
    $form['markup'] = array(
      '#type' => 'markup',
      '#value' => '<div id="themeswitch-pane"><div id="themeswitch-content">' . $content . '</div><div class="scroll-bar-wrap"><div class="scroll-bar"></div></div></div>',
    );
    return $form;
  }

  /**
   * Frontend form submit handler.
   */
  public function sweaver_form_submit($form, &$form_state) {
    if ($form_state['clicked_button']['#value'] == t('Publish style') && isset($form_state['style_id'])) {
      $theme_key = $form['#current_theme'];
      variable_set('theme_default', $theme_key);
    }
  }

  /**
   * Frontend css and js.
   */
  public function sweaver_form_css_js(&$inline_settings) {
    drupal_add_js(drupal_get_path('module', 'sweaver') . '/plugins/sweaver_plugin_themeswitch/sweaver_plugin_themeswitch.js', 'module');
  }

  /**
   * Frontend themeswitch.
   */
  public function sweaver_menu_callback() {
    $theme = arg(1);
    $theme_default = variable_get('theme_default', 'garland');
    $all_themes = sweaver_get_all_themes();
    if (!empty($theme) && isset($all_themes[$theme]) && $all_themes[$theme]->status == 1) {
      if ($theme != $theme_default) {
        sweaver_session(NULL, 'sweaver_theme', TRUE);
        sweaver_session($theme, 'sweaver_theme');
      }
      else {

        // Reset session variable because it's the default.
        sweaver_session(NULL, 'sweaver_theme', TRUE);
      }

      // Let other modules act on the themeswitch.
      $arguments = array(
        'switched_theme' => $theme,
        'default_theme' => $theme_default,
      );
      module_invoke_all('sweaver_action', 'theme_switch', $arguments);
      sweaver_session(t('You have switched to @switched_theme.', array(
        '@switched_theme' => $all_themes[$theme]->info['name'],
      )));
    }

    // Go back to previous page.
    drupal_goto();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
sweaver_plugin::sweaver_dependencies public function Sweaver dependencies. 2
sweaver_plugin::sweaver_form_render public function Sweaver form render. 2
sweaver_plugin::sweaver_images_handler public function Images handler. 1
sweaver_plugin::sweaver_menu_callback_submit public function Menu callback submit. 2
sweaver_plugin::sweaver_menu_callback_validate public function Menu callback validate.
sweaver_plugin::sweaver_objects_alter public function Sweaver objects alter. 1
sweaver_plugin::sweaver_popups_render protected function Helper function render the popups.
sweaver_plugin::sweaver_preprocess_page public function Preprocess page function. 1
sweaver_plugin::sweaver_theme public function Theme registry. 1
sweaver_plugin_themeswitch::sweaver_form public function Frontend form. Overrides sweaver_plugin::sweaver_form
sweaver_plugin_themeswitch::sweaver_form_css_js public function Frontend css and js. Overrides sweaver_plugin::sweaver_form_css_js
sweaver_plugin_themeswitch::sweaver_form_submit public function Frontend form submit handler. Overrides sweaver_plugin::sweaver_form_submit
sweaver_plugin_themeswitch::sweaver_init public function Init Overrides sweaver_plugin::sweaver_init
sweaver_plugin_themeswitch::sweaver_menu public function Menu registry. Overrides sweaver_plugin::sweaver_menu
sweaver_plugin_themeswitch::sweaver_menu_callback public function Frontend themeswitch. Overrides sweaver_plugin::sweaver_menu_callback