http_response.inc

  1. cis7 sites/all/modules/ulmus/ctools/page_manager/plugins/task_handlers/http_response.inc
  2. cle7 sites/all/modules/ulmus/ctools/page_manager/plugins/task_handlers/http_response.inc
  3. ecd7 sites/all/modules/ulmus/ctools/page_manager/plugins/task_handlers/http_response.inc
  4. elmsmedia7 sites/all/modules/ulmus/ctools/page_manager/plugins/task_handlers/http_response.inc
  5. harmony7 sites/all/modules/ulmus/ctools/page_manager/plugins/task_handlers/http_response.inc
  6. icor7 sites/all/modules/ulmus/ctools/page_manager/plugins/task_handlers/http_response.inc
  7. meedjum_blog7 sites/all/modules/ulmus/ctools/page_manager/plugins/task_handlers/http_response.inc
  8. mooc7 sites/all/modules/ulmus/ctools/page_manager/plugins/task_handlers/http_response.inc

This is the task handler plugin to handle generating 403, 404 and 301 response codes.

Functions

Namesort descending Description
page_manager_http_response_admin_summary
page_manager_http_response_codes Provide a list of the response codes we support.
page_manager_http_response_edit_settings General settings for the panel
page_manager_http_response_edit_settings_submit
page_manager_http_response_render
page_manager_http_response_title Set up a title for the panel based upon the selection rules.

File

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