You are here

function page_manager_http_response_render in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 page_manager/plugins/task_handlers/http_response.inc \page_manager_http_response_render()
1 string reference to 'page_manager_http_response_render'
http_response.inc in page_manager/plugins/task_handlers/http_response.inc
This is the task handler plugin to handle generating 403, 404 and 301 response codes.

File

page_manager/plugins/task_handlers/http_response.inc, line 250
This is the task handler plugin to handle generating 403, 404 and 301 response codes.

Code

function page_manager_http_response_render($handler, $base_contexts, $args, $test = TRUE) {

  // Go through arguments and see if they match.
  ctools_include('context');
  ctools_include('context-task-handler');

  // Add my contexts
  $contexts = ctools_context_handler_get_handler_contexts($base_contexts, $handler);

  // Test.
  if ($test && !ctools_context_handler_select($handler, $contexts)) {
    return;
  }
  if (isset($handler->handler)) {
    ctools_context_handler_pre_render($handler, $contexts, $args);
  }
  $info['response code'] = $handler->conf['code'];
  if ($info['response code'] == 301) {
    $path = ctools_context_keyword_substitute($handler->conf['destination'], array(), $contexts);
    $url = parse_url($path);
    if (isset($url['query'])) {
      $path = strtr($path, array(
        '?' . $url['query'] => '',
      ));
      $info['query'] = array();
      foreach (explode('&', $url['query']) as $query_part) {
        list($key, $value) = explode('=', $query_part);
        $info['query'][$key] = $value;
      }
    }
    if (isset($url['fragment'])) {
      $path = strtr($path, array(
        '#' . $url['fragment'] => '',
      ));
      $info['fragment'] = $url['fragment'];
    }
    $info['destination'] = rtrim($path, '?');
  }
  return $info;
}