security updates
have to check views and entityreference for custom patches
This commit is contained in:
@@ -9,7 +9,8 @@ class context_condition_context extends context_condition_path {
|
||||
$active_contexts = array_keys(context_active_contexts());
|
||||
foreach ($this->get_contexts() as $context) {
|
||||
if (!in_array($context->name, $active_contexts, TRUE) && $values = $this->fetch_from_context($context, 'values')) {
|
||||
if ($this->match($active_contexts, $values)) {
|
||||
// Always check against the active contexts.
|
||||
if ($this->match(array_keys(context_active_contexts()), $values)) {
|
||||
$this->condition_met($context);
|
||||
}
|
||||
}
|
||||
@@ -20,4 +21,45 @@ class context_condition_context extends context_condition_path {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all context conditions.
|
||||
*
|
||||
* This method is slightly adapted to context_condition::get_contexts() in
|
||||
* order to ensure that a context that is used as condition in another context
|
||||
* gets handled before.
|
||||
*/
|
||||
function get_contexts($value = NULL) {
|
||||
$map = context_condition_map();
|
||||
$map = isset($map[$this->plugin]) ? $map[$this->plugin] : array();
|
||||
|
||||
$contexts = array();
|
||||
|
||||
// Add the contexts that are needed for conditions in the other contexts
|
||||
// first. Start with the negated ones first, as we can not unset a met
|
||||
// condition afterwards.
|
||||
krsort($map);
|
||||
foreach ($map as $key => $submap) {
|
||||
// Negated context conditions start with a "~".
|
||||
if (substr($key, 0, 1) == "~") {
|
||||
$key = substr($key, 1);
|
||||
}
|
||||
if (!isset($contexts[$key])) {
|
||||
$context = context_load($key);
|
||||
// Check if context exists. This will fail for wildcards.
|
||||
if ($context) {
|
||||
$contexts[$context->name] = $context;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($map as $key => $submap) {
|
||||
foreach ($submap as $name) {
|
||||
if (!isset($contexts[$name])) {
|
||||
$context = context_load($name);
|
||||
$contexts[$context->name] = $context;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $contexts;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Expose active contexts as a context condition.
|
||||
*/
|
||||
class context_condition_context_all extends context_condition_path {
|
||||
function execute() {
|
||||
if ($this->condition_used()) {
|
||||
$active_contexts = array_keys(context_active_contexts());
|
||||
foreach ($this->get_contexts() as $context) {
|
||||
|
||||
// Only test contexts that haven't been activated yet,
|
||||
// and have values set.
|
||||
if (!in_array($context->name, $active_contexts, TRUE) && $values = $this->fetch_from_context($context, 'values')) {
|
||||
|
||||
// The condition is met if all contexts are active.
|
||||
if (count(array_intersect($values, $active_contexts)) == count($values)) {
|
||||
$this->condition_met($context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the list of active contexts has changed, we need to recurse.
|
||||
if ($active_contexts != array_keys(context_active_contexts())) {
|
||||
$this->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Simple condition that sets context active if no other non-default and non
|
||||
* sitewide context is active.
|
||||
*/
|
||||
class context_condition_default extends context_condition {
|
||||
function condition_values() {
|
||||
return array('context_condition_default' => t('Default context'));
|
||||
}
|
||||
|
||||
function editor_form($context = NULL) {
|
||||
$form = parent::editor_form($context);
|
||||
$form[1]['#title'] = t('Default context');
|
||||
$form['#weight'] = -10;
|
||||
return $form;
|
||||
}
|
||||
|
||||
function execute() {
|
||||
if ($this->condition_used()) {
|
||||
$active_contexts = context_active_contexts();
|
||||
|
||||
foreach ($active_contexts as $name => $context) {
|
||||
foreach (array_keys($context->conditions) as $cond) {
|
||||
if (!in_array($cond, array('default', 'sitewide'))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($this->get_contexts('context_condition_default') as $context) {
|
||||
$this->condition_met($context, 'context_condition_default');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file context_condition_query_string.inc
|
||||
*
|
||||
* Similar to context_condition_path but for entire query string.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Expose query strings as a context condition.
|
||||
*/
|
||||
class context_condition_query_string extends context_condition_path {
|
||||
|
||||
/**
|
||||
* Execute.
|
||||
*/
|
||||
function execute() {
|
||||
if ($this->condition_used()) {
|
||||
$current_query_string = $_SERVER["QUERY_STRING"];
|
||||
foreach ($this->get_contexts() as $context) {
|
||||
$query_strings = $this->fetch_from_context($context, 'values');
|
||||
if ($this->match($current_query_string, $query_strings, TRUE)) {
|
||||
$this->condition_met($context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -168,7 +168,6 @@ body.context-editing .draggable:hover a.context-block-remove {
|
||||
* Block visibility ===================================================
|
||||
*/
|
||||
#context-blockform .context-blockform-selector {
|
||||
height:20em;
|
||||
overflow:auto;
|
||||
}
|
||||
|
||||
@@ -179,6 +178,7 @@ body.context-editing .draggable:hover a.context-block-remove {
|
||||
border:1px solid #ddd;
|
||||
padding:10px;
|
||||
width:50%;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
#context-blockform td.blocks .label,
|
||||
|
@@ -42,13 +42,19 @@ class context_reaction_block extends context_reaction {
|
||||
$group = isset($block->context_group) ? $block->context_group : $block->module;
|
||||
if (!isset($form['selector'][$group])) {
|
||||
$form['selector'][$group] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#title' => isset($block->context_group) ? $block->context_group : $modules[$block->module],
|
||||
);
|
||||
$form['selector'][$group]['checkboxes'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => array(),
|
||||
);
|
||||
}
|
||||
$form['selector'][$group]['#options'][$block->bid] = check_plain($block->info);
|
||||
$form['selector'][$group]['checkboxes']['#options'][$block->bid] = check_plain($block->info);
|
||||
}
|
||||
|
||||
ksort($form['selector']);
|
||||
|
||||
/**
|
||||
@@ -58,7 +64,7 @@ class context_reaction_block extends context_reaction {
|
||||
'#tree' => TRUE,
|
||||
'#theme' => 'context_block_regions_form',
|
||||
);
|
||||
foreach (system_region_list($theme_key, REGIONS_VISIBLE) as $region => $label) {
|
||||
foreach ($this->system_region_list($theme_key, REGIONS_VISIBLE) as $region => $label) {
|
||||
$form['blocks'][$region] = array(
|
||||
'#type' => 'item',
|
||||
'#title' => $label,
|
||||
@@ -215,7 +221,7 @@ class context_reaction_block extends context_reaction {
|
||||
}
|
||||
|
||||
// Populate all block regions
|
||||
$all_regions = system_region_list($theme);
|
||||
$all_regions = $this->system_region_list($theme);
|
||||
|
||||
// Load all region content assigned via blocks.
|
||||
foreach (array_keys($all_regions) as $region) {
|
||||
@@ -255,7 +261,7 @@ class context_reaction_block extends context_reaction {
|
||||
*/
|
||||
protected function is_enabled_region($region) {
|
||||
global $theme;
|
||||
$regions = array_keys(system_region_list($theme));
|
||||
$regions = array_keys($this->system_region_list($theme));
|
||||
return in_array($region, $regions, TRUE);
|
||||
}
|
||||
|
||||
@@ -290,7 +296,7 @@ class context_reaction_block extends context_reaction {
|
||||
return FALSE;
|
||||
}
|
||||
// Check that this region is not hidden
|
||||
$visible = system_region_list($theme, REGIONS_VISIBLE);
|
||||
$visible = $this->system_region_list($theme, REGIONS_VISIBLE);
|
||||
return $requirements && $this->is_enabled_region($region) && isset($visible[$region]);
|
||||
}
|
||||
|
||||
@@ -299,15 +305,7 @@ class context_reaction_block extends context_reaction {
|
||||
*/
|
||||
protected function editable_block($block) {
|
||||
if (!empty($block->content)) {
|
||||
$block->content = array(
|
||||
'content' => $block->content,
|
||||
'context' => array('#markup' => "<a id='context-block-{$block->module}-{$block->delta}' class='context-block editable edit-{$block->context}'></a>"),
|
||||
);
|
||||
//Contextual links are in the wrong spot in the render array once we've nested them
|
||||
if (isset($block->content['content']['#contextual_links'])) {
|
||||
$block->content['#contextual_links'] = $block->content['content']['#contextual_links'];
|
||||
unset($block->content['content']['#contextual_links']);
|
||||
}
|
||||
$block->content['#theme_wrappers'][] = 'context_block_edit_wrap';
|
||||
}
|
||||
else {
|
||||
// the block alter in context.module should ensure that blocks are never
|
||||
@@ -328,7 +326,7 @@ class context_reaction_block extends context_reaction {
|
||||
context_isset('context_ui', 'context_ui_editor_present'))
|
||||
) {
|
||||
global $theme;
|
||||
$regions = system_region_list($theme);
|
||||
$regions = $this->system_region_list($theme);
|
||||
$name = isset($regions[$region]) ? $regions[$region] : $region;
|
||||
// The negative weight + sorted will push our region marker to the top of the region
|
||||
$build['context'] = array(
|
||||
@@ -388,13 +386,29 @@ class context_reaction_block extends context_reaction {
|
||||
}
|
||||
|
||||
$this->is_editable_check($context_blocks);
|
||||
foreach ($context_blocks as $r => $blocks) {
|
||||
$context_blocks[$r] = _block_render_blocks($blocks);
|
||||
global $theme;
|
||||
$active_regions = $this->system_region_list($theme);
|
||||
|
||||
// Make blocks editable if allowed.
|
||||
if ($this->is_editable_region($r)) {
|
||||
foreach ($context_blocks[$r] as $key => $block) {
|
||||
$context_blocks[$r][$key] = $this->editable_block($block);
|
||||
// Make context renders regions in the same order as core.
|
||||
$_context_blocks = array();
|
||||
foreach ($active_regions as $r => $name) {
|
||||
if (isset($context_blocks[$r])) {
|
||||
$_context_blocks[$r] = $context_blocks[$r];
|
||||
}
|
||||
}
|
||||
$context_blocks = $_context_blocks;
|
||||
unset($_context_blocks);
|
||||
|
||||
foreach ($context_blocks as $r => $blocks) {
|
||||
//only render blocks in an active region
|
||||
if (array_key_exists($r, $active_regions)) {
|
||||
$context_blocks[$r] = _block_render_blocks($blocks);
|
||||
|
||||
// Make blocks editable if allowed.
|
||||
if ($this->is_editable_region($r)) {
|
||||
foreach ($context_blocks[$r] as $key => $block) {
|
||||
$context_blocks[$r][$key] = $this->editable_block($block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,7 +528,12 @@ class context_reaction_block extends context_reaction {
|
||||
$result = db_select('block')
|
||||
->fields('block')
|
||||
->condition('theme', $theme_key)
|
||||
->execute();
|
||||
->execute()
|
||||
->fetchAllAssoc('bid');
|
||||
|
||||
drupal_alter('block_list', $result);
|
||||
drupal_alter('context_block_list', $result);
|
||||
|
||||
foreach ($result as $row) {
|
||||
if (isset($block_info["{$row->module}-{$row->delta}"])) {
|
||||
$block_info["{$row->module}-{$row->delta}"] = (object) array_merge((array) $row, (array) $block_info["{$row->module}-{$row->delta}"]);
|
||||
@@ -576,50 +595,9 @@ class context_reaction_block extends context_reaction {
|
||||
if (function_exists('json_decode')) {
|
||||
return json_decode($json, $assoc);
|
||||
}
|
||||
return context_reaction_block::_json_decode($json);
|
||||
}
|
||||
|
||||
/**
|
||||
* From http://www.php.net/manual/en/function.json-decode.php#91216
|
||||
* with modifications for consistency with output of json_decode().
|
||||
*
|
||||
* Original author: walidator.info 2009.
|
||||
*/
|
||||
static function _json_decode($json) {
|
||||
$comment = FALSE;
|
||||
$out = '$x = ';
|
||||
for ($i=0; $i < strlen($json); $i++) {
|
||||
if (!$comment) {
|
||||
switch ($json[$i]) {
|
||||
case '{':
|
||||
$out .= ' (object) array(';
|
||||
break;
|
||||
case '}':
|
||||
$out .= ')';
|
||||
break;
|
||||
case '[':
|
||||
$out .= ' array(';
|
||||
break;
|
||||
case ']':
|
||||
$out .= ')';
|
||||
break;
|
||||
case ':';
|
||||
$out .= '=>';
|
||||
break;
|
||||
default:
|
||||
$out .= $json[$i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$out .= $json[$i];
|
||||
}
|
||||
if ($json[$i] == '"') {
|
||||
$comment = !$comment;
|
||||
}
|
||||
else {
|
||||
watchdog('context', 'Please upgrade your PHP version to one that supports json_decode.');
|
||||
}
|
||||
eval($out . ';');
|
||||
return $x;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -640,7 +618,7 @@ class context_reaction_block extends context_reaction {
|
||||
list($bid, $context) = explode(',', $param);
|
||||
list($module, $delta) = explode('-', $bid, 2);
|
||||
// Check token to make sure user has access to block.
|
||||
if (empty($_GET['context_token']) || $_GET['context_token'] != drupal_get_token($bid)) {
|
||||
if (!(user_access('administer contexts') || user_access('context ajax block access') || $this->context_block_ajax_rendering_allowed($bid))) {
|
||||
echo drupal_json_encode(array('status' => 0));
|
||||
exit;
|
||||
}
|
||||
@@ -670,4 +648,34 @@ class context_reaction_block extends context_reaction {
|
||||
echo drupal_json_encode(array('status' => 0));
|
||||
drupal_exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide caching for system_region_list since it can get called
|
||||
* frequently. Evaluate for removal once https://drupal.org/node/1873450
|
||||
* lands or system_region_list is otherwise cached in core
|
||||
*/
|
||||
protected function system_region_list($theme_key, $show = REGIONS_ALL) {
|
||||
static $cache = array();
|
||||
if (!isset($cache[$theme_key])) {
|
||||
$cache[$theme_key] = array();
|
||||
}
|
||||
if (!isset($cache[$theme_key][$show])) {
|
||||
$cache[$theme_key][$show] = system_region_list($theme_key, $show);
|
||||
}
|
||||
return $cache[$theme_key][$show];
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow modules to selectively allow ajax rendering of a specific block
|
||||
*/
|
||||
private function context_block_ajax_rendering_allowed($bid) {
|
||||
$allowed = FALSE;
|
||||
foreach (module_invoke_all('context_allow_ajax_block_access', $bid) as $module_allow) {
|
||||
$allowed = $allow || $module_allow;
|
||||
if ($allowed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $allowed;
|
||||
}
|
||||
}
|
||||
|
@@ -327,11 +327,6 @@ DrupalContextBlockEditor.prototype = {
|
||||
// Construct query params for our AJAX block request.
|
||||
var params = Drupal.settings.contextBlockEditor.params;
|
||||
params.context_block = bid + ',' + context;
|
||||
if (!Drupal.settings.contextBlockEditor.block_tokens || !Drupal.settings.contextBlockEditor.block_tokens[bid]) {
|
||||
alert(Drupal.t('An error occurred trying to retrieve block content. Please contact a site administer.'));
|
||||
return;
|
||||
}
|
||||
params.context_token = Drupal.settings.contextBlockEditor.block_tokens[bid];
|
||||
|
||||
// Replace item with loading block.
|
||||
//ui.sender.append(ui.item);
|
||||
@@ -443,7 +438,7 @@ DrupalContextBlockEditor.prototype = {
|
||||
dropOnEmpty: true,
|
||||
placeholder: 'draggable-placeholder',
|
||||
forcePlaceholderSize: true,
|
||||
items: '> .block:has(a.context-block.editable)',
|
||||
items: '> *:has(a.context-block.editable)',
|
||||
handle: 'a.context-block-handle',
|
||||
start: function(event, ui) { self.scriptFix(event, ui, editor, context); },
|
||||
stop: function(event, ui) { self.addBlock(event, ui, editor, context); },
|
||||
|
@@ -5,35 +5,35 @@
|
||||
*/
|
||||
class context_reaction_breadcrumb extends context_reaction_menu {
|
||||
/**
|
||||
* Override of execute().
|
||||
* Overrides set_active_trail_from_link to set the breadcrumb instead of the menu path.
|
||||
*/
|
||||
function execute(&$vars = NULL) {
|
||||
if ($active_paths = $this->get_active_paths()) {
|
||||
$breadcrumb = array(l(t('Home'), '<front>', array('purl' => array('disabled' => TRUE))));
|
||||
foreach ($active_paths as $path) {
|
||||
$result = db_select('menu_links')
|
||||
->fields('menu_links', array('p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8'))
|
||||
->condition('hidden', 0)
|
||||
->condition('link_path', $path)
|
||||
->execute();
|
||||
while ($parents = $result->fetchAssoc()) {
|
||||
$set = FALSE;
|
||||
foreach (array_filter($parents) as $plid) {
|
||||
$parent = menu_link_load($plid);
|
||||
if ($parent && $parent['access'] && empty($parent['hidden']) && !empty($parent['title'])) {
|
||||
$set = TRUE;
|
||||
$breadcrumb[] = l($parent['title'], $parent['href']);
|
||||
}
|
||||
}
|
||||
// Only set the breadcrumb if one or more links were added to the
|
||||
// trail. If not, continue iterating through possible menu links.
|
||||
if ($set) {
|
||||
drupal_set_breadcrumb($breadcrumb);
|
||||
break;
|
||||
}
|
||||
function set_active_trail_from_link($item) {
|
||||
$result = db_select('menu_links')
|
||||
->fields('menu_links', array('p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8'))
|
||||
->condition('hidden', 0)
|
||||
->condition('link_path', $item['link_path'])
|
||||
->execute();
|
||||
while ($parents = $result->fetchAssoc()) {
|
||||
$set = FALSE;
|
||||
foreach (array_filter($parents) as $plid) {
|
||||
$parent = menu_link_load($plid);
|
||||
if ($parent && $parent['access'] && empty($parent['hidden']) && !empty($parent['title'])) {
|
||||
$set = TRUE;
|
||||
$breadcrumb[] = l($parent['title'], $parent['href']);
|
||||
}
|
||||
}
|
||||
// Only set the breadcrumb if one or more links were added to the
|
||||
// trail. If not, continue iterating through possible menu links.
|
||||
if ($set) {
|
||||
drupal_set_breadcrumb($breadcrumb);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return the title to be used for the current menu item.
|
||||
*/
|
||||
function get_link_title($item) {
|
||||
return module_exists('i18n_menu') ? _i18n_menu_link_title($item) : $item['title'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -12,13 +12,27 @@ class context_reaction_debug extends context_reaction {
|
||||
return array('debug' => 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for variables.
|
||||
*/
|
||||
function settings_form() {
|
||||
$form = array();
|
||||
$form['context_reaction_debug_enable_global'] = array(
|
||||
'#title' => t('Enable debug reaction on all contexts'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => variable_get('context_reaction_debug_enable_global', FALSE),
|
||||
'#description' => t('Enable the debug reaction on all contexts.')
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a list of active contexts.
|
||||
*/
|
||||
function execute() {
|
||||
$contexts = context_active_contexts();
|
||||
foreach ($contexts as $context) {
|
||||
if (!empty($context->reactions['debug'])) {
|
||||
if (!empty($context->reactions['debug']) || variable_get('context_reaction_debug_enable_global', FALSE)) {
|
||||
if (user_access('administer site configuration') && module_exists('context_ui')) {
|
||||
$name = l($context->name, "admin/structure/context/list/{$context->name}", array('query' => array('destination' => $_GET['q'])));
|
||||
}
|
||||
|
@@ -8,35 +8,33 @@ class context_reaction_menu extends context_reaction {
|
||||
* Provide a form element that allow the admin to chose a menu item.
|
||||
*/
|
||||
function options_form($context) {
|
||||
$options = array("-- " . t('None') . " --");
|
||||
if (module_exists('menu')) {
|
||||
$menus = menu_parent_options(menu_get_menus(), array('mlid' => 0));
|
||||
$root_menus = array();
|
||||
foreach ($menus as $key => $name) {
|
||||
$id = explode(':', $key);
|
||||
if ($id[1] == '0') {
|
||||
$root_menus[$id[0]] = check_plain($name);
|
||||
$menu_names = array();
|
||||
foreach ($menus as $id => $title) {
|
||||
list($menu_name, $mlid) = explode(':', $id);
|
||||
// Store the title each menu for reference.
|
||||
if ($mlid == '0') {
|
||||
$menu_names[$menu_name] = $title;
|
||||
}
|
||||
else {
|
||||
$link = menu_link_load($id[1]);
|
||||
$link = menu_link_load($mlid);
|
||||
$identifier = $link['link_path'];
|
||||
$root_menu = $root_menus[$id[0]];
|
||||
while (isset($menus[$root_menu][$identifier])) {
|
||||
$root_menu = $menu_names[$menu_name];
|
||||
while (isset($options[$root_menu][$identifier])) {
|
||||
$identifier .= "'";
|
||||
}
|
||||
$menus[$root_menu][$identifier] = $name;
|
||||
$options[$root_menu][$menu_name . ':' . $identifier] = $title;
|
||||
}
|
||||
unset($menus[$key]);
|
||||
}
|
||||
array_unshift($menus, "-- " . t('None') . " --");
|
||||
}
|
||||
else {
|
||||
$menus = array();
|
||||
}
|
||||
return array(
|
||||
'#title' => $this->title,
|
||||
'#description' => $this->description,
|
||||
'#options' => $menus,
|
||||
'#options' => $options,
|
||||
'#type' => 'select',
|
||||
'#multiple' => TRUE,
|
||||
'#default_value' => $this->fetch_from_context($context),
|
||||
);
|
||||
}
|
||||
@@ -46,97 +44,100 @@ class context_reaction_menu extends context_reaction {
|
||||
* Trim any identifier padding for non-unique path menu items.
|
||||
*/
|
||||
function options_form_submit($values) {
|
||||
return trim($values, "'");
|
||||
$trimmed = array();
|
||||
foreach ($values as $value) {
|
||||
$value = trim($value, "'");
|
||||
$trimmed[] = $value;
|
||||
}
|
||||
return $trimmed;
|
||||
}
|
||||
|
||||
/**
|
||||
* If primary + secondary links are pointed at the same menu, provide
|
||||
* contextual trailing by default.
|
||||
* Overrides parent function to include legacy handling for old format of just storing a single path.
|
||||
*/
|
||||
function execute(&$vars = NULL) {
|
||||
if (variable_get('menu_main_links_source', 'main-menu') == variable_get('menu_secondary_links_source', 'user-menu')) {
|
||||
$vars['main_menu'] = theme_get_setting('toggle_main_menu') ? $this->menu_navigation_links(variable_get('menu_main_links_source', 'main-menu')) : $vars['main_menu'];
|
||||
$vars['secondary_menu'] = theme_get_setting('toggle_secondary_menu') ? $this->menu_navigation_links(variable_get('menu_secondary_links_source', 'secondary-links'), 1) : $vars['secondary_menu'];
|
||||
function fetch_from_context($context) {
|
||||
$values = parent::fetch_from_context($context);
|
||||
// Legacy - convert single string value to an array with a preferred menu
|
||||
if (is_string($values)) {
|
||||
$menu = menu_link_get_preferred($values);
|
||||
if (!$menu) {
|
||||
return array();
|
||||
}
|
||||
return array($menu['menu_name'] . ':' . $menu['link_path']);
|
||||
}
|
||||
|
||||
$vars['main_menu'] = $this->menu_set_active($vars['main_menu']);
|
||||
$vars['secondary_menu'] = $this->menu_set_active($vars['secondary_menu']);
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide active trail in all menus in which our path appears.
|
||||
*/
|
||||
function execute(&$vars = NULL) {
|
||||
$menu_names = menu_get_active_menu_names();
|
||||
$active_paths = $this->get_active_paths();
|
||||
foreach ($menu_names as $menu_name) {
|
||||
if (isset($active_paths[$menu_name])) {
|
||||
foreach($active_paths[$menu_name] as $path) {
|
||||
if ($link = menu_link_get_preferred($path, $menu_name)) {
|
||||
$this->set_active_trail_from_link($link);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// None of the links can be found in their preferred menus. Instead we just try to find any of the paths in any
|
||||
// menu. Note that the preferred menu names list is still used but not always honoured.
|
||||
// We hope to not have to fall into this section as we could end up doing rather a lot of lookups.
|
||||
foreach ($active_paths as $menu_name => $paths) {
|
||||
foreach($paths as $path) {
|
||||
if ($link = menu_link_get_preferred($path)) {
|
||||
$this->set_active_trail_from_link($link);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to build and set the active trail from a menu link.
|
||||
*
|
||||
* @param $item
|
||||
* A menu link item.
|
||||
*/
|
||||
function set_active_trail_from_link($item) {
|
||||
menu_tree_set_path($item['menu_name'], $item['link_path']);
|
||||
$trail = array();
|
||||
while($item) {
|
||||
array_unshift($trail, $item);
|
||||
$item = menu_link_load($item['plid']);
|
||||
}
|
||||
array_unshift($trail, array(
|
||||
'title' => t('Home'),
|
||||
'href' => '<front>',
|
||||
'link_path' => '',
|
||||
'localized_options' => array(),
|
||||
'type' => 0,
|
||||
));
|
||||
menu_set_active_trail($trail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to return the list of currently active paths.
|
||||
*
|
||||
* The paths are grouped by menu name.
|
||||
*/
|
||||
function get_active_paths() {
|
||||
$active_paths = array();
|
||||
foreach ($this->get_contexts() as $context) {
|
||||
if (isset($context->reactions[$this->plugin])) {
|
||||
$active_paths[] = $context->reactions[$this->plugin];
|
||||
}
|
||||
}
|
||||
return $active_paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates through a provided links array for use with theme_links()
|
||||
* (e.g. from menu_primary_links()) and provides an active class for
|
||||
* any items that have a path that matches an active context.
|
||||
*
|
||||
* @param $links
|
||||
* An array of links.
|
||||
* @param $reset
|
||||
* A boolean flag for resetting the static cache.
|
||||
*
|
||||
* @return
|
||||
* A modified links array.
|
||||
*/
|
||||
function menu_set_active($links = array(), $reset = FALSE) {
|
||||
$new_links = array();
|
||||
if (!empty($links)) {
|
||||
$active_paths = $this->get_active_paths();
|
||||
|
||||
// Iterate through the provided links and build a new set of links
|
||||
// that includes active classes
|
||||
foreach ($links as $key => $link) {
|
||||
if (!empty($link['href']) && in_array($link['href'], $active_paths)) {
|
||||
$link['attributes']['class'][] = 'active';
|
||||
|
||||
if (strpos(' active', $key) === FALSE) {
|
||||
$new_links[$key . ' active'] = $link;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$new_links[$key] = $link;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $new_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around menu_navigation_links() that gives themers the option of
|
||||
* building navigation links based on an active context trail.
|
||||
*/
|
||||
function menu_navigation_links($menu_name, $level = 0) {
|
||||
// Retrieve original path so we can repair it after our hack.
|
||||
$original_path = $_GET['q'];
|
||||
$original_menu_trail = drupal_static('menu_set_active_trail');
|
||||
|
||||
// Retrieve the first active menu path found.
|
||||
if ($active_paths = $this->get_active_paths()) {
|
||||
$path = current($active_paths);
|
||||
if (menu_get_item($path)) {
|
||||
menu_set_active_item($path);
|
||||
}
|
||||
$paths = $this->fetch_from_context($context);
|
||||
$active_paths = array_merge($active_paths, $paths);
|
||||
}
|
||||
|
||||
// Build the links requested
|
||||
if (module_exists('i18n_menu')) {
|
||||
$links = i18n_menu_navigation_links($menu_name, $level);
|
||||
} else {
|
||||
$links = menu_navigation_links($menu_name, $level);
|
||||
$by_menu_name = array();
|
||||
foreach ($active_paths as $id) {
|
||||
list($menu_name, $path) = explode(':', $id);
|
||||
$by_menu_name[$menu_name][] = $path;
|
||||
}
|
||||
|
||||
// Repair and get out
|
||||
menu_set_active_item($original_path);
|
||||
$repair_menu_trail = &drupal_static('menu_set_active_trail');
|
||||
$repair_menu_trail = $original_menu_trail;
|
||||
return $links;
|
||||
return $by_menu_name;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Add template suggestions as a context reaction.
|
||||
*/
|
||||
class context_reaction_template_suggestions extends context_reaction {
|
||||
|
||||
/**
|
||||
* Display the text area field for adding new template suggestions.
|
||||
*/
|
||||
function options_form($context) {
|
||||
$default_value = $this->fetch_from_context($context);
|
||||
|
||||
return array(
|
||||
'#title' => t('Template suggestions'),
|
||||
'#type' => 'textarea',
|
||||
'#description' => t('Enter template suggestions such as "page__front", one per line, in order of preference (using underscores instead of hyphens). For more information, please visit ') . l(t('Drupal 7 Template (Theme Hook) Suggestions'), 'http://drupal.org/node/1089656', array(array('target' => '_blank'), 'html' => TRUE,)) . '.',
|
||||
'#default_value' => is_string($default_value) ? $default_value : '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any new template suggestions to the current list.
|
||||
*/
|
||||
function execute(&$vars = NULL) {
|
||||
|
||||
// Get the list of contexts associated with this reaction.
|
||||
$contexts = $this->get_contexts();
|
||||
|
||||
// Iterate through each, and process those with something set.
|
||||
foreach ($contexts as $context) {
|
||||
if (isset($context->reactions) && (!empty($context->reactions[$this->plugin]))) {
|
||||
|
||||
// Get the suggestion data entered by the user.
|
||||
$suggestions = $this->fetch_from_context($context, 'values');
|
||||
|
||||
// Convert it to an list and reverse it (as higher priority items
|
||||
// should be on the bottom).
|
||||
$suggestions = array_reverse(explode("\n", $suggestions));
|
||||
|
||||
// Append the suggested list to the existing list.
|
||||
$vars['theme_hook_suggestions'] = array_merge($vars['theme_hook_suggestions'], $suggestions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user