security update core+modules

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-26 18:38:56 +02:00
parent 2f45ea820a
commit 7c96373038
1022 changed files with 30319 additions and 11259 deletions

View File

@@ -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;
}
}