context_redirect.module in Context Redirect 7
Same filename and directory in other branches
Provides a context reaction that redirects the user.
File
context_redirect.moduleView source
<?php
/**
* @file
* Provides a context reaction that redirects the user.
*/
/**
* Implements hook_ctools_plugin_api().
*/
function context_redirect_ctools_plugin_api($module, $api) {
if ($module == 'context' && $api == 'plugins') {
return array(
'version' => 3,
);
}
}
/**
* Implements hook_context_plugins().
*/
function context_redirect_context_plugins() {
$plugins = array();
$plugins['context_redirect_reaction'] = array(
'handler' => array(
'path' => drupal_get_path('module', 'context_redirect'),
'file' => 'context_redirect_reaction.inc',
'class' => 'context_redirect_reaction',
'parent' => 'context_reaction',
),
);
return $plugins;
}
/**
* Implements hook_context_registry().
*/
function context_redirect_context_registry() {
$registry['reactions'] = array(
'context_redirect' => array(
'title' => t('Context redirect'),
'plugin' => 'context_redirect_reaction',
),
);
return $registry;
}
/**
* Implements hook_context_page_reaction().
*/
function context_redirect_context_page_reaction() {
if ($plugin = context_get_plugin('reaction', 'context_redirect')) {
$plugin
->execute();
}
}
/**
* Backport of _external_url_is_local from Drupal 8.
* @param $url
* @return bool
*/
function context_redirect_external_url_is_local($url) {
$url_parts = parse_url($url);
$base_host = parse_url($GLOBALS['base_url'], PHP_URL_HOST);
// When comparing base paths, we need a trailing slash to make sure a
// partial URL match isn't occuring. Since base_path() always returns with
// a trailing slash, we don't need to add the trailing slash here.
return $url_parts['host'] == $base_host && stripos($url_parts['path'], base_path()) === 0;
}
Functions
Name | Description |
---|---|
context_redirect_context_page_reaction | Implements hook_context_page_reaction(). |
context_redirect_context_plugins | Implements hook_context_plugins(). |
context_redirect_context_registry | Implements hook_context_registry(). |
context_redirect_ctools_plugin_api | Implements hook_ctools_plugin_api(). |
context_redirect_external_url_is_local | Backport of _external_url_is_local from Drupal 8. |