[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/skinr/ -> skinr.handlers.inc (source)

   1  <?php
   2  // $Id: skinr.handlers.inc,v 1.2.4.8 2010/11/10 19:21:10 jgirlygirl Exp $
   3  /**
   4   * @file
   5   * Defines the various handler objects to support Skinr.
   6   */
   7  
   8  /*
   9   * Skinr access handler.
  10   *
  11   * @param $op
  12   *   What kind of action is being performed. Possible values:
  13   *   - "access skinr": access to edit skinr's selector
  14   *   - "access skinr classes": access to edit skinr's additional classes
  15   * @param &$form
  16   *   Passes in the $form parameter from hook_form_alter().
  17   * @param $form_state
  18   *   Passes in the $form_state parameter from hook_form_alter().
  19   * @return
  20   *   TRUE if we get access, FALSE if we don't.
  21   */
  22  function skinr_access_handler($op, &$form, $form_state) {
  23    switch ($op) {
  24      case 'access skinr':
  25        return user_access('access skinr') || user_access('administer skinr');
  26      case 'access skinr classes':
  27        return user_access('access skinr classes') || user_access('administer skinr');
  28    }
  29  }
  30  
  31  /**
  32   * Skinr form index handler for ajax form.
  33   *
  34   * @param $op
  35   *   What kind of action is being performed. Possible values:
  36   *   - "form": the form elements for Skinr are being inserted in a form
  37   *   - "submit": the form has been submitted.
  38   * @param &$form
  39   *   - For "form", passes in the $form parameter from hook_form_alter().
  40   *   - For "submit", passes in the $form parameter from hook_form_submit().
  41   * @param $form_state
  42   *   - For "form", passes in the $form_state parameter from hook_form_alter().
  43   *   - For "submit", passes in the $form_state parameter from hook_form_submit().
  44   * @return
  45   *   The index where we can find our values in Skinrs data structure.
  46   */
  47  function skinr_ajax_index_handler($op, &$form, $form_state) {
  48    switch ($op) {
  49      case 'form':
  50        if (empty($form['skinr']['sid']['#value'])) {
  51          trigger_error(sprintf("The form with form_id '%s' is not a valid AJAX form.", $form['form_id']['#value']), E_USER_ERROR);
  52          return FALSE;
  53        }
  54        return $form['skinr']['sid']['#value'];
  55  
  56      case 'submit':
  57        if (empty($form_state['values']['sid'])) {
  58          trigger_error(sprintf("The form with form_id '%s' is not a valid AJAX form.", $form['form_id']['#value']), E_USER_ERROR);
  59          return FALSE;
  60        }
  61        return $form_state['values']['sid'];
  62    }
  63  }
  64  
  65  /*
  66   * Skinr data handler.
  67   *
  68   * @param &$form
  69   *   Passes in the $form parameter from hook_form_submit().
  70   * @param $form_state
  71   *   Passes in the $form_state parameter from hook_form_submit().
  72   * @param $module
  73   *   The module that is currently being processed.
  74   * @param $form_settings
  75   *   The settings from hook_skinr_config() for the form that's currently being
  76   *   processed.
  77   * @return
  78   *   TRUE if we get access, FALSE if we don't.
  79   */
  80  function skinr_data_handler(&$form, $form_state, $theme, $module, $form_settings) {
  81    // Ensure we have the required index_handler
  82    if (empty($form_settings['index_handler'])) {
  83      trigger_error(sprintf("No index_handler was found for form_id '%s' in module '%s'.", $form_id, $module), E_USER_ERROR);
  84    }
  85    $index = skinr_handler('form_index_handler', 'form', $form_settings['index_handler'], $form, $form_state);
  86  
  87    return skinr_get($theme, $module, $index);
  88  }
  89  
  90  /**
  91   * Skinr submit handler.
  92   *
  93   * @param &$form
  94   *   Passes in the $form parameter from hook_form_submit().
  95   * @param $form_state
  96   *   Passes in the $form_state parameter from hook_form_submit().
  97   * @param $module
  98   *   The module that is currently being processed.
  99   * @param $form_settings
 100   *   The settings from hook_skinr_config() for the form that's currently being
 101   *   processed.
 102   * @return
 103   *   TRUE if we get access, FALSE if we don't.
 104   */
 105  function skinr_submit_handler(&$form, $form_state, $module, $form_settings) {
 106    if (isset($form_state['values']['skinr_settings'][$module .'_group'])) {
 107      foreach ($form_state['values']['skinr_settings'][$module .'_group'] as $theme_name => $theme) {
 108        if ((!empty($theme['widgets']) && is_array($theme['widgets'])) || isset($theme['_additional'])) {
 109          $skinr = new stdClass();
 110          $skinr->theme = $theme_name;
 111          $skinr->module = $module;
 112          $skinr->sid = skinr_handler('form_index_handler', 'submit', $form_settings['index_handler'], $form, $form_state);
 113          $skinr->skins = array();
 114          
 115          $saved = skinr_get($skinr->theme, $skinr->module, $skinr->sid);
 116  
 117          if (!empty($theme['widgets']) && is_array($theme['widgets'])) {
 118            foreach ($theme['widgets'] as $skin_id => $skin_value) {
 119              $skinr->skins[$skin_id] = $skin_value;
 120            }
 121          }
 122  
 123          if (isset($theme['_additional'])) {
 124            $theme['_additional'] = trim($theme['_additional']);
 125            if (!empty($theme['_additional'])) {
 126              $skinr->skins['_additional'] = $theme['_additional'];
 127            }
 128          }
 129          else {
 130            if (!user_access('access skinr classes') && isset($saved->skins['_additional'])) {
 131              // The user didn't have access to change this. Ensure the existing
 132              // custom classes remain by populating the element with the
 133              // previously saved values.
 134              $value->skins['_additional'] = $saved->skins['_additional'];
 135            }
 136          }
 137  
 138          if (isset($theme['_template'])) {
 139            $theme['_template'] = trim($theme['_template']);
 140            if (!empty($theme['_template'])) {
 141              $skinr->skins['_template'] = $theme['_template'];
 142            }
 143          }
 144          else {
 145            if (!user_access('access skinr classes') && isset($saved->skins['_template'])) {
 146              // The user didn't have access to change this. Ensure the existing
 147              // template selection remains by populating the element with the
 148              // previously saved values.
 149              $value->skins['_template'] = $saved->skins['_template'];
 150            }
 151          }
 152  
 153          if (empty($skinr->sid)) {
 154            // We didn't receive a valid sid, so raise an error
 155            drupal_set_message(t("Skinr settings weren't saved due to an error."), 'error');
 156          }
 157  
 158          skinr_set($skinr);
 159        }
 160      }
 161    }
 162  }
 163  
 164  // Declare API compatibility on behalf of core modules:
 165  
 166  /**
 167   * Implementation of hook_skinr_api().
 168   *
 169   * This one is used as the base to reduce errors when updating.
 170   */
 171  function skinr_skinr_api() {
 172    return array(
 173      'api' => 1,
 174      'path' => drupal_get_path('module', 'skinr') .'/modules',
 175    );
 176  }
 177  
 178  function block_skinr_api() { return skinr_skinr_api(); }
 179  
 180  function content_skinr_api() { return skinr_skinr_api(); }
 181  
 182  function comment_skinr_api() { return skinr_skinr_api(); }
 183  
 184  function fieldgroup_skinr_api() { return skinr_skinr_api(); }
 185  
 186  function node_skinr_api() { return skinr_skinr_api(); }
 187  
 188  function panels_skinr_api() { return skinr_skinr_api(); }
 189  
 190  function views_skinr_api() { return skinr_skinr_api(); }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7