[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/ctools/page_manager/plugins/task_handlers/ -> http_response.inc (source)

   1  <?php
   2  // $Id: http_response.inc,v 1.1.2.1 2010/08/06 18:23:11 merlinofchaos Exp $
   3  
   4  /**
   5   * @file
   6   *
   7   * This is the task handler plugin to handle generating 403, 404 and 301 response codes.
   8   */
   9  
  10  // Plugin definition
  11  $plugin = array(
  12    // is a 'context' handler type, meaning it supports the API of the
  13    // context handlers provided by ctools context plugins.
  14    'handler type' => 'context',
  15    'visible' => TRUE, // may be added up front.
  16  
  17    // Administrative fields.
  18    'title' => t('HTTP response code'),
  19    'admin summary' =>'page_manager_http_response_admin_summary',
  20    'admin title' => 'page_manager_http_response_title',
  21    'operations' => array(
  22      'settings' => array(
  23        'title' => t('General'),
  24        'description' => t('Change general settings for this variant.'),
  25        'form' => 'page_manager_http_response_edit_settings',
  26      ),
  27      'criteria' => array(
  28        'title' => t('Selection rules'),
  29        'description' => t('Control the criteria used to decide whether or not this variant is used.'),
  30        'ajax' => FALSE,
  31        'form' => array(
  32          'order' => array(
  33            'form' => t('Selection rules'),
  34          ),
  35          'forms' => array(
  36            'form' => array(
  37              'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc',
  38              'form id' => 'ctools_context_handler_edit_criteria',
  39            ),
  40          ),
  41        ),
  42      ),
  43      'context' => array(
  44        'title' => t('Contexts'),
  45        'ajax' => FALSE,
  46        'description' => t('Add additional context objects to this variant that can be used by the content.'),
  47        'form' => array(
  48          'order' => array(
  49            'form' => t('Context'),
  50          ),
  51          'forms' => array(
  52            'form' => array(
  53              'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc',
  54              'form id' => 'ctools_context_handler_edit_context',
  55            ),
  56          ),
  57        ),
  58      ),
  59    ),
  60  
  61    // Callback to render the data.
  62    'render' => 'page_manager_http_response_render',
  63  
  64    'add features' => array(
  65      'criteria' => t('Selection rules'),
  66      'context' => t('Contexts'),
  67    ),
  68    // Where to go when finished.
  69    'add finish' => 'settings',
  70  
  71    'required forms' => array(
  72      'settings' => t('Panel settings'),
  73    ),
  74  
  75    'edit forms' => array(
  76      'criteria' => t('Selection rules'),
  77      'settings' => t('General'),
  78      'context' => t('Contexts'),
  79    ),
  80    'forms' => array(
  81      'settings' => array(
  82        'form id' => 'page_manager_http_response_edit_settings',
  83      ),
  84      'context' => array(
  85        'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc',
  86        'form id' => 'ctools_context_handler_edit_context',
  87      ),
  88      'criteria' => array(
  89        'include' => drupal_get_path('module', 'ctools') . '/includes/context-task-handler.inc',
  90        'form id' => 'ctools_context_handler_edit_criteria',
  91      ),
  92    ),
  93    'default conf' => array(
  94      'title' => t('HTTP response code'),
  95      'contexts' => array(),
  96      'relationships' => array(),
  97      'code' => '404',
  98      'destination' => '',
  99    ),
 100  );
 101  
 102  /**
 103   * Provide a list of the response codes we support.
 104   *
 105   * Abstracted so it can be more readily used both on input and output.
 106   */
 107  function page_manager_http_response_codes() {
 108    return array(
 109      404 => t('404 Page not found'),
 110      403 => t('403 Access denied'),
 111      301 => t('301 Redirect'),
 112    );
 113  }
 114  
 115  function page_manager_http_response_admin_summary($handler, $task, $subtask, $page, $show_title = TRUE) {
 116    $task_name = page_manager_make_task_name($task['name'], $subtask['name']);
 117    $output = '';
 118  
 119    $display = panels_panel_context_get_display($handler);
 120  
 121    ctools_include('plugins', 'panels');
 122    ctools_include('context');
 123    ctools_include('context-task-handler');
 124  
 125    // Get the operations
 126    $operations = page_manager_get_operations($page);
 127  
 128    // Get operations for just this handler.
 129    $operations = $operations['handlers']['children'][$handler->name]['children']['actions']['children'];
 130    $args = array('handlers', $handler->name, 'actions');
 131    $rendered_operations = page_manager_render_operations($page, $operations, array(), array('class' => 'actions'), 'actions', $args);
 132  
 133    $layout = panels_get_layout($display->layout);
 134  
 135    $plugin = page_manager_get_task_handler($handler->handler);
 136  
 137    $object = ctools_context_handler_get_task_object($task, $subtask, $handler);
 138    $display->context = ctools_context_load_contexts($object, TRUE);
 139  
 140    $access = ctools_access_group_summary(!empty($handler->conf['access']) ? $handler->conf['access'] : array(), $display->context);
 141    if ($access) {
 142      $access = t('This panel will be selected if @conditions.', array('@conditions' => $access));
 143    }
 144    else {
 145      $access = t('This panel will always be selected.');
 146    }
 147  
 148    $rows = array();
 149  
 150    $type = $handler->type == t('Default') ? t('In code') : $handler->type;
 151    $rows[] = array(
 152      array('class' => t('page-summary-label'), 'data' => t('Storage')),
 153      array('class' => t('page-summary-data'), 'data' => $type),
 154      array('class' => t('page-summary-operation'), 'data' => ''),
 155    );
 156  
 157    if (!empty($handler->disabled)) {
 158      $link = l(t('Enable'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'actions', 'enable')));
 159      $text = t('Disabled');
 160    }
 161    else {
 162      $link = l(t('Disable'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'actions', 'disable')));
 163      $text = t('Enabled');
 164    }
 165  
 166    $rows[] = array(
 167      array('class' => t('page-summary-label'), 'data' => t('Status')),
 168      array('class' => t('page-summary-data'), 'data' => $text),
 169      array('class' => t('page-summary-operation'), 'data' => $link),
 170    );
 171  
 172    $link = l(t('Edit'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'criteria')));
 173    $rows[] = array(
 174      array('class' => t('page-summary-label'), 'data' => t('Selection rule')),
 175      array('class' => t('page-summary-data'), 'data' => $access),
 176      array('class' => t('page-summary-operation'), 'data' => $link),
 177    );
 178  
 179    $link = l(t('Edit'), page_manager_edit_url($task_name, array('handlers', $handler->name, 'settings')));
 180    $codes = page_manager_http_response_codes();
 181    $rows[] = array(
 182      array('class' => t('page-summary-label'), 'data' => t('Response code')),
 183      array('class' => t('page-summary-data'), 'data' => $codes[$handler->conf['code']]),
 184      array('class' => t('page-summary-operation'), 'data' => $link),
 185    );
 186  
 187    $info = theme('table', array(), $rows, array('class' => 'page-manager-handler-summary'));
 188  
 189    $title = $handler->conf['title'];
 190    if ($title != t('Panel')) {
 191      $title = t('Panel: @title', array('@title' => $title));
 192    }
 193  
 194    $output .= '<div class="clear-block">';
 195    if ($show_title) {
 196    $output .= '<div class="handler-title clear-block">';
 197      $output .= '<div class="actions handler-actions">' . $rendered_operations['actions'] . '</div>';
 198      $output .= '<span class="title-label">' . $title . '</span>';
 199    }
 200  
 201    $output .= '</div>';
 202    $output .= $info;
 203    $output .= '</div>';
 204  
 205    return $output;
 206  }
 207  
 208  /**
 209   * Set up a title for the panel based upon the selection rules.
 210   */
 211  function page_manager_http_response_title($handler, $task, $subtask) {
 212    if (isset($handler->conf['title'])) {
 213      return check_plain($handler->conf['title']);
 214    }
 215    else {
 216      return t('HTTP response code');
 217    }
 218  }
 219  
 220  /**
 221   * General settings for the panel
 222   */
 223  function page_manager_http_response_edit_settings(&$form, &$form_state) {
 224    $conf = $form_state['handler']->conf;
 225    $form['title'] = array(
 226      '#type' => 'textfield',
 227      '#default_value' => $conf['title'],
 228      '#title' => t('Administrative title'),
 229      '#description' => t('Administrative title of this variant.'),
 230    );
 231  
 232    $form['code'] = array(
 233      '#title' => t('Response code'),
 234      '#type' => 'select',
 235      '#options' => page_manager_http_response_codes(),
 236      '#default_value' => $conf['code'],
 237    );
 238  
 239    ctools_include('dependent');
 240    $form['destination'] = array(
 241      '#type' => 'textfield',
 242      '#title' => t('Redirect destination'),
 243      '#default_value' => $conf['destination'],
 244      '#process' => array('ctools_dependent_process'),
 245      '#dependency' => array('edit-code' => array(301)),
 246      '#description' => t('Enter the path to redirect to. You may use keyword substitutions from contexts. You can use external urls (http://www.example.com/foo) or internal urls (node/1).'),
 247    );
 248  }
 249  
 250  function page_manager_http_response_edit_settings_submit(&$form, &$form_state) {
 251    $form_state['handler']->conf['title'] = $form_state['values']['title'];
 252    $form_state['handler']->conf['code'] = $form_state['values']['code'];
 253    $form_state['handler']->conf['destination'] = $form_state['values']['destination'];
 254  }
 255  
 256  function page_manager_http_response_render($handler, $base_contexts, $args, $test = TRUE) {
 257    // Go through arguments and see if they match.
 258    ctools_include('context');
 259    ctools_include('context-task-handler');
 260    ctools_include('plugins', 'panels');
 261  
 262    // Add my contexts
 263    $contexts = ctools_context_handler_get_handler_contexts($base_contexts, $handler);
 264  
 265    // Test.
 266    if ($test && !ctools_context_handler_select($handler, $contexts)) {
 267      return;
 268    }
 269  
 270    if (isset($handler->handler)) {
 271      ctools_context_handler_pre_render($handler, $contexts, $args);
 272    }
 273  
 274    $info['response code'] = $handler->conf['code'];
 275    if ($info['response code'] == 301) {
 276      $path = ctools_context_keyword_substitute($handler->conf['destination'], array(), $contexts);
 277      $url = parse_url($path);
 278      if (isset($url['query'])) {
 279        $path = strtr($path, array('?' . $url['query'] => ''));
 280        $info['query'] = $url['query'];
 281      }
 282      if (isset($url['fragment'])) {
 283        $path = strtr($path, array('#' . $url['fragment'] => ''));
 284        $info['fragment'] = $url['fragment'];
 285      }
 286  
 287      $info['destination'] = $path;
 288    }
 289  
 290    return $info;
 291  }


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