You are here

class sweaver_plugin_themeclasses in Sweaver 6

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

Hierarchy

Expanded class hierarchy of sweaver_plugin_themeclasses

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

File

plugins/sweaver_plugin_themeclasses/sweaver_plugin_themeclasses.inc, line 9
Theme classes plugin.

View source
class sweaver_plugin_themeclasses extends sweaver_plugin {

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

    // Theme classes groups administration.
    $items['admin/settings/sweaver/themeclasses'] = $base + array(
      'title' => 'Theme styles',
      'page arguments' => array(
        $page_arguments,
      ),
      'type' => MENU_LOCAL_TASK,
      'weight' => $weight++,
    );
    return $items;
  }

  /**
   * Frontend form.
   */
  public function sweaver_form() {
    $form = array();
    $class_groups = trim(variable_get('sweaver_themeclasses_groups', SWEAVER_PLUGIN_THEMECLASSES_DEFAULT));
    if (empty($class_groups)) {
      return $form;
    }
    $theme_key = Sweaver::get_instance()
      ->get_theme_key();
    $theme_info = sweaver_get_theme_info($theme_key);
    if (empty($theme_info)) {
      return $form;
    }
    $cache = variable_get('sweaver_plugin_themeclasses_' . $theme_key, array());
    if (!empty($cache)) {
      $styles = $cache['styles'];
    }
    else {
      $styles = array();
      $groups = explode("\n", $class_groups);
      foreach ($groups as $group) {
        $group = trim($group);
        if (isset($theme_info[$group])) {
          $this
            ->sweaver_get_styles($theme_info[$group], $styles);
        }
      }

      // Cache the stuff.
      variable_set('sweaver_plugin_themeclasses_' . $theme_key, array(
        'checked' => TRUE,
        'styles' => $styles,
      ));
    }
    if (!empty($styles)) {
      $content = t('<h2>Styles</h2>!styles', array(
        '!styles' => implode(' ', $styles),
      ));
    }
    else {
      $content = t('<p>No styles found.</p>');
    }
    $form['sweaver_plugin_themeclasses'] = array(
      '#type' => 'markup',
      '#value' => $content,
    );
    return $form;
  }

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

  /**
   * Menu callback.
   */
  public function sweaver_menu_callback() {
    $form = array();
    $form['sweaver_themeclasses_groups'] = array(
      '#type' => 'textarea',
      '#title' => t('Theme groups'),
      '#description' => t('Enter a group which is available in your theme(s) info file. This plugin will try to fetch all classes from it and make them available in a separate tab. Enter one group per line. This is inspired by the skinr way of theming, so we need to find a key called \'class\' to get a list of styles. If you have added new classes and the editor does not pick them up yet, click on submit button to reset the cache.'),
      '#default_value' => variable_get('sweaver_themeclasses_groups', SWEAVER_PLUGIN_THEMECLASSES_DEFAULT),
      '#wysiwyg' => FALSE,
    );
    $form['sweaver_themeclasses_submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save configuration'),
    );
    return $form;
  }

  /**
   * Menu callback submit.
   */
  public function sweaver_menu_callback_submit($form, &$form_state) {
    db_query("DELETE FROM {variable} where name LIKE '%s%%'", 'sweaver_plugin_themeclasses_');
    variable_set('sweaver_themeclasses_groups', $form_state['values']['sweaver_themeclasses_groups']);
    drupal_set_message(t('The configuration options have been saved.'));
  }

  /**
   * Get styles from the group. We look for a key called 'class'.
   */
  public function sweaver_get_styles($theme_info, &$styles) {
    foreach ($theme_info as $key => $value) {
      if (is_array($value) && isset($value['class'])) {
        $label = isset($value['label']) ? $value['label'] : $value['class'];
        $styles[] = '<div class="sweaver-switch-to-style " id="spt-' . $value['class'] . '"><a href="javascript:Drupal.Sweaver.ThemeClasses(\'spt-' . $value['class'] . '\', \'spt-' . strip_tags($value['label']) . '\')">' . strip_tags($value['label']) . '</a></div>';
      }
      if (is_array($value)) {
        $this
          ->sweaver_get_styles($theme_info[$key], $styles);
      }
    }
  }

}

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_form_submit public function Sweaver submit handler. 6
sweaver_plugin::sweaver_images_handler public function Images handler. 1
sweaver_plugin::sweaver_init public function Init function. 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_themeclasses::sweaver_form public function Frontend form. Overrides sweaver_plugin::sweaver_form
sweaver_plugin_themeclasses::sweaver_form_css_js public function Frontend css and js. Overrides sweaver_plugin::sweaver_form_css_js
sweaver_plugin_themeclasses::sweaver_get_styles public function Get styles from the group. We look for a key called 'class'.
sweaver_plugin_themeclasses::sweaver_menu public function Menu registry. Overrides sweaver_plugin::sweaver_menu
sweaver_plugin_themeclasses::sweaver_menu_callback public function Menu callback. Overrides sweaver_plugin::sweaver_menu_callback
sweaver_plugin_themeclasses::sweaver_menu_callback_submit public function Menu callback submit. Overrides sweaver_plugin::sweaver_menu_callback_submit