FINAL suepr merge step : added all modules to this super repos

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-19 16:46:59 +02:00
7585 changed files with 1723356 additions and 18 deletions

View File

@@ -0,0 +1,16 @@
; $Id: xmlsitemap_menu.info,v 1.3 2009/12/22 23:56:59 davereid Exp $
name = XML sitemap menu
description = Adds menu item links to the sitemap.
package = XML sitemap
core = 7.x
dependencies[] = xmlsitemap
dependencies[] = menu
files[] = xmlsitemap_menu.module
files[] = xmlsitemap_menu.install
; Information added by drupal.org packaging script on 2010-01-24
version = "7.x-2.x-dev"
core = "7.x"
project = "xmlsitemap"
datestamp = "1264335489"

View File

@@ -0,0 +1,69 @@
<?php
// $Id: xmlsitemap_menu.install,v 1.3 2010/01/18 07:46:28 davereid Exp $
/**
* @file
* Install and uninstall schema and functions for the xmlsitemap_menu module.
*/
/**
* Implements hook_uninstall().
*/
function xmlsitemap_menu_uninstall() {
// Remove variables.
drupal_load('module', 'xmlsitemap_menu');
$variables = array_keys(xmlsitemap_menu_variables());
foreach ($variables as $variable) {
variable_del($variable);
}
}
// @todo Remove these update functions before alpha.
function xmlsitemap_menu_update_1() {
$value = xmlsitemap_menu_var('menus');
variable_set('xmlsitemap_menu_menus', array_filter($value));
}
function xmlsitemap_menu_update_2() {
$field = array(
'description' => 'The {menu_links}.menu_name of this menu link.',
'type' => 'varchar',
'length' => 32,
'default' => NULL,
);
db_add_field('xmlsitemap', 'menu_name', $field);
db_add_index('xmlsitemap', 'menu_name', array('menu_name'));
db_query("UPDATE {xmlsitemap} SET menu_name = (SELECT menu_name FROM {menu_links} WHERE mlid = {xmlsitemap}.id) WHERE type = 'menu'");
}
function xmlsitemap_menu_update_3() {
$menus = variable_get('xmlsitemap_menu_menus', array());
foreach ($menus as $menu) {
variable_set('xmlsitemap_menu_status_' . $menu, TRUE);
}
variable_del('xmlsitemap_menu_menus');
}
function xmlsitemap_menu_update_4() {
}
function xmlsitemap_menu_update_5() {
}
// Skip to 6 since I was stupid and had xmlsitemap_menu_update_5() in xmlsitemap_node.install
function xmlsitemap_menu_update_6() {
db_update('system')
->fields(array('weight' => 0))
->condition('type', 'module')
->condition('name', 'xmlsitemap_menu')
->execute();
}
function xmlsitemap_menu_update_7() {
$menus = array_keys(menu_get_menus());
foreach ($menus as $menu) {
if (variable_get('xmlsitemap_menu_priority_' . $menu, 'default') === 'default') {
variable_set('xmlsitemap_menu_priority_' . $menu, 0.5);
}
}
}

View File

@@ -0,0 +1,339 @@
<?php
// $Id: xmlsitemap_menu.module,v 1.7 2010/01/20 03:34:33 davereid Exp $
/**
* Implements hook_cron().
*
* Process old menu links not found in the {xmlsitemap} table.
*/
function xmlsitemap_menu_cron() {
xmlsitemap_menu_xmlsitemap_index_links(xmlsitemap_var('batch_limit'));
}
/**
* Implements hook_xmlsitemap_index_links().
*/
function xmlsitemap_menu_xmlsitemap_index_links($limit) {
if ($menus = xmlsitemap_menu_get_menus()) {
// Set the global user variable to the anonymous user.
xmlsitemap_switch_user(0);
$sql = "SELECT ml.mlid FROM {menu_links} ml LEFT JOIN {xmlsitemap} x ON x.type = 'menu' AND ml.mlid = x.id WHERE x.id IS NULL AND ml.menu_name IN (:menus) ORDER BY ml.mlid DESC";
$mlids = db_query_range($sql, 0, $limit, array(':menus' => $menus));
foreach ($mlids as $mlid) {
$menu_item = xmlsitemap_menu_menu_link_load($mlid);
$link = xmlsitemap_menu_create_link($menu_item);
xmlsitemap_save_link($link);
}
// Set the global user variable back to the original user.
xmlsitemap_restore_user();
}
}
/**
* Implements hook_xmlsitemap_links().
*/
function xmlsitemap_menu_xmlsitemap_links($offset = 0, $limit = 0) {
$links = array();
if ($menus = xmlsitemap_menu_get_menus()) {
// Set the global user variable to the anonymous user.
xmlsitemap_switch_user(0);
$sql = "SELECT ml.mlid FROM {menu_links} ml WHERE ml.mlid > :mlid AND ml.menu_name IN (:menus) ORDER BY ml.mlid";
$args = array(':mlid' => $offset, ':menus' => $menus);
$mlids = ($limit ? db_query_range($sql, 0, $limit, $args) : db_query($sql, $args));
foreach ($mlids as $mlid) {
$menu_item = xmlsitemap_menu_menu_link_load($mlid);
$links[] = xmlsitemap_menu_create_link($menu_item);
}
// Set the global user variable back to the original user.
xmlsitemap_restore_user();
}
return $links;
}
/**
* Implements hook_xmlsitemap_links_batch_info().
*/
function xmlsitemap_menu_xmlsitemap_links_batch_info() {
$menus = xmlsitemap_menu_get_menus();
return array(
'max' => $menus ? db_query("SELECT COUNT(ml.mlid) FROM {menu_links} ml WHERE ml.menu_name IN (:menus)", array(':menus' => $menus))->fetchField() : 0,
);
}
/**
* Implements hook_xmlsitemap_link_info().
*/
function xmlsitemap_menu_xmlsitemap_link_info() {
return array(
'menu' => array(
'purge' => TRUE,
'table' => 'menu_links',
'id' => 'mlid',
'subtype' => 'menu_name',
'subtypes' => xmlsitemap_menu_get_menus(),
),
);
}
/**
* Load a menu link and its associated sitemap link data.
*/
function xmlsitemap_menu_menu_link_load($mlid) {
$menu_item = menu_link_load($mlid);
if ($data = xmlsitemap_load_link(array('type' => 'menu', 'id' => $mlid))) {
$menu_item['xmlsitemap'] = $data;
}
return $menu_item;
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Show a summary of menus on the XML sitemap settings page.
*/
function xmlsitemap_menu_form_xmlsitemap_settings_form_alter(&$form, $form_state) {
$type = array(
'type' => 'menu',
'title' => t('Menus'),
'item_title' => t('Menu'),
'access' => user_access('administer menu'),
);
$menus = menu_get_menus();
foreach ($menus as $menu => $name) {
$menus[$menu] = array(
'name' => $name,
'link' => 'admin/build/menu-customize/' . $menu . '/edit',
'status' => variable_get('xmlsitemap_menu_status_' . $menu, 0),
'priority' => variable_get('xmlsitemap_menu_priority_' . $menu, 0.5),
);
}
xmlsitemap_add_form_type_summary($form, $type, $menus);
$form['menu']['#weight'] = 40;
}
/**
* Implements hook_form_FORM_ID_alter().
*
* @see menu_edit_menu()
* @see xmlsitemap_menu_menu_edit_menu_submit()
*/
function xmlsitemap_menu_form_menu_edit_menu_alter(&$form, $form_state) {
$menu = isset($form['menu_name']['#value']) ? $form['menu_name']['#value'] : '';
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
$options = array(
'status' => variable_get('xmlsitemap_menu_status_' . $menu, 0),
'priority' => variable_get('xmlsitemap_menu_priority_' . $menu, 0.5),
);
xmlsitemap_add_form_type_options($form, 'menu', $options);
// @todo Enable this feature:
//$form['xmlsitemap']['xmlsitemap_menu_calculate_priority'] = array(
// '#type' => 'checkbox',
// '#title' => t('Calculate priority based on menu item depth and weight.'),
// '#default_value' => variable_get('xmlsitemap_menu_calculate_priority_' . $menu, FALSE),
//);
$form['submit'] += array('#weight' => 50);
if (isset($form['delete'])) {
$form['delete'] += array('#weight' => 51);
}
$form['#submit'][] = 'xmlsitemap_menu_menu_edit_menu_submit';
}
/**
* Form submit handler; update settings when a menu is saved.
*/
function xmlsitemap_menu_menu_edit_menu_submit($form, $form_state) {
$menu = $form_state['values']['menu_name'];
$new_priority = $form_state['values']['xmlsitemap_menu_priority'];
$new_status = $form_state['values']['xmlsitemap_menu_status'];
if ($new_status != variable_get('xmlsitemap_menu_status_' . $menu, 0)) {
xmlsitemap_update_links(array('status' => $new_status), array('type' => 'menu', 'subtype' => $menu, 'status_override' => 0));
}
if ($new_priority != variable_get('xmlsitemap_menu_priority_' . $menu, 0.5)) {
xmlsitemap_update_links(array('priority' => $new_priority), array('type' => 'menu', 'subtype' => $menu, 'priority_override' => 0));
}
variable_set('xmlsitemap_menu_priority_' . $menu, $new_priority);
variable_set('xmlsitemap_menu_status_' . $menu, $new_status);
}
/**
* Implements hook_form_FORM_ID_alter().
*
* @see menu_delete_menu_confirm()
* @see xmlsitemap_menu_form_menu_delete_menu_confirm_submit()
*/
function xmlsitemap_menu_form_menu_delete_menu_confirm_alter(&$form, $form_state) {
$form['#submit'][] = 'xmlsitemap_menu_form_menu_delete_menu_confirm_submit';
}
/**
* Form submit handler; delete sitemap links when a menu is deleted.
*/
function xmlsitemap_menu_form_menu_delete_menu_confirm_submit($form, $form_state) {
$menu = $form['#menu']['menu_name'];
xmlsitemap_delete_link(array('type' => 'menu', 'subtype' => $menu));
variable_del('xmlsitemap_menu_status_' . $menu);
variable_del('xmlsitemap_menu_priority_ ' . $menu);
}
//function xmlsitemap_menu_form_menu_overview_form_alter(&$form, $form_state) {
// $form['#submit'][] = 'xmlsitemap_menu_menu_overview_form_submit';
//}
//
//function xmlsitemap_menu_menu_overview_form_submit($form, $form_state) {
// foreach (element_children($form) as $mlid) {
// if (isset($form[$mlid]['#item'])) {
// $menu_item = menu_link_load($form[$mlid]['#item']['mlid'], TRUE);
// xmlsitemap_menu_item_update($menu_item);
// }
// }
//}
/**
* Implements hook_form_FORM_ID_alter().
*
* @see menu_item_delete_form()
*/
function xmlsitemap_menu_form_menu_item_delete_form_alter(&$form, $form_state) {
$form['#submit'][] = 'xmlsitemap_menu_menu_item_delete_form_submit';
}
/**
* Form submit callback; delete the sitemap link when a menu item is deleted.
*/
function xmlsitemap_menu_menu_item_delete_form_submit($form, $form_state) {
xmlsitemap_menu_item_delete($form['#item']);
}
/**
* Implements hook_form_FORM_ID_alter().
*
* @see menu_edit_item()
*/
function xmlsitemap_menu_form_menu_edit_item_alter(&$form, $form_state) {
$form['#submit'][] = 'xmlsitemap_menu_menu_edit_item_submit';
}
/**
* Form submit callback; update the sitemap link when a menu item is updated.
*/
function xmlsitemap_menu_menu_edit_item_submit($form, $form_state) {
xmlsitemap_switch_user(0);
$menu_item = xmlsitemap_menu_menu_link_load($form_state['values']['menu']['mlid']);
xmlsitemap_restore_user();
xmlsitemap_menu_item_update($menu_item);
}
function xmlsitemap_menu_item_update(array $menu_item) {
$link = xmlsitemap_menu_create_link($menu_item);
xmlsitemap_save_link($link);
}
function xmlsitemap_menu_item_delete(array $menu_item) {
xmlsitemap_delete_link(array('type' => 'menu', 'id' => $menu_item['mlid']));
}
/**
* Fetch an array of menus to be included in the sitemap.
*/
function xmlsitemap_menu_get_menus() {
$menus = array_keys(menu_get_menus());
foreach ($menus as $index => $menu) {
if (!variable_get('xmlsitemap_menu_status_' . $menu, 0)) {
unset($menus[$index]);
}
}
return $menus;
}
/**
* Create a sitemap link from a menu item.
*
* @param $menu_item
* A loaded menu item.
*/
function xmlsitemap_menu_create_link(array $menu_item) {
if (!isset($menu_item['xmlsitemap'])) {
$menu_item['xmlsitemap'] = array();
}
$menu_item['xmlsitemap'] += array(
'type' => 'menu',
'id' => $menu_item['mlid'],
'loc' => $menu_item['link_path'],
'status' => variable_get('xmlsitemap_menu_status_' . $menu_item['menu_name'], 0),
'status_default' => variable_get('xmlsitemap_menu_status_' . $menu_item['menu_name'], 0),
'status_override' => 0,
'priority' => variable_get('xmlsitemap_menu_priority_' . $menu_item['menu_name'], 0.5),
'priority_default' => variable_get('xmlsitemap_menu_priority_' . $menu_item['menu_name'], 0.5),
'priority_override' => 0,
);
// The following values must always be checked because they are volatile.
$menu_item['xmlsitemap']['subtype'] = $menu_item['menu_name'];
$menu_item['xmlsitemap']['access'] = $menu_item['access'] && !$menu_item['external'] && !$menu_item['hidden'];
$menu_item['xmlsitemap']['language'] = isset($menu_item['options']['langcode']) ? $menu_item['options']['langcode'] : LANGUAGE_NONE;
return $menu_item['xmlsitemap'];
}
/**
* Calculate the priority of a menu link based on depth and weight.
*/
function xmlsitemap_menu_calculate_priority(array $menu_item) {
$priority = (MENU_MAX_DEPTH - $menu_item['depth'] + 1) / MENU_MAX_DEPTH;
$priority -= (50 + $menu_item['weight']) / (100 * (MENU_MAX_DEPTH + 1));
return $priority;
}
/**
* Internal default variables for template_var().
*/
function xmlsitemap_menu_variables() {
$defaults = array(
// Deprecated variables set to NULL so they are still removed on uninstall.
'xmlsitemap_menu_menus' => NULL,
'xmlsitemap_menu_calculate_priority' => NULL,
);
$menus = array_keys(menu_get_menus());
foreach ($menus as $menu) {
$defaults['xmlsitemap_menu_status_' . $menu] = 0;
$defaults['xmlsitemap_menu_priority_' . $menu] = 0.5;
$defaults['xmlsitemap_menu_calculate_priority_' . $menu] = FALSE;
}
return $defaults;
}
/**
* Internal implementation of variable_get().
*/
function xmlsitemap_menu_var($name, $default = NULL) {
static $defaults = NULL;
if (!isset($defaults)) {
$defaults = xmlsitemap_menu_variables();
}
$name = 'xmlsitemap_menu_' . $name;
// @todo Remove when stable.
if (!isset($defaults[$name])) {
trigger_error(t('Default variable for %variable not found.', array('%variable' => $name)));
}
return variable_get($name, isset($default) || !isset($defaults[$name]) ? $default : $defaults[$name]);
}