Commit 122f48be authored by Dave Reid's avatar Dave Reid

by Dave Reid: Up-port entity usage for admin settings.

parent fcaefdfd
......@@ -104,27 +104,30 @@ function xmlsitemap_settings_form() {
'#weight' => 20,
);
$form['frontpage'] = array(
'#type' => 'fieldset',
'#title' => t('Front page'),
'#description' => t('The front page path can be changed at <a href="@url-frontpage">@url-frontpage</a>.', array('@url-frontpage' => url('admin/settings/site-information'))),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 20,
'#group' => 'xmlsitemap_settings',
);
$form['frontpage']['xmlsitemap_frontpage_priority'] = array(
'#type' => 'select',
'#title' => t('Priority'),
'#options' => xmlsitemap_get_priority_options(),
'#default_value' => xmlsitemap_var('frontpage_priority'),
);
$form['frontpage']['xmlsitemap_frontpage_changefreq'] = array(
'#type' => 'select',
'#title' => t('Change frequency'),
'#options' => xmlsitemap_get_changefreq_options(),
'#default_value' => xmlsitemap_var('frontpage_changefreq'),
);
$entites = xmlsitemap_get_link_info(NULL, TRUE);
foreach ($entites as $entity => $entity_info) {
$form[$entity] = array(
'#type' => 'fieldset',
'#title' => $entity_info['label'],
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'xmlsitemap_settings',
);
if (!empty($entity_info['bundles'])) {
// If this entity has bundles, show a bundle setting summary.
xmlsitemap_add_form_entity_summary($form[$entity], $entity, $entity_info);
}
if (!empty($entity_info['xmlsitemap']['settings callback'])) {
// Add any entity-specific settings.
$entity_info['xmlsitemap']['settings callback']($form[$entity]);
}
// Ensure that the entity fieldset is not shown if there are no accessible
// sub-elements.
$form[$entity]['#access'] = (bool) element_get_visible_children($form[$entity]);
}
$form['#pre_render'][] = 'vertical_tabs_form_pre_render';
$form['#validate'][] = 'xmlsitemap_settings_form_validate';
......@@ -243,56 +246,84 @@ function xmlsitemap_rebuild_form_submit($form, &$form_state) {
}
/**
* Create a list of items that can be included in the sitemap.
*
* @param $form
* An array with the form to add the type summary.
* @param $type
* An array of details about the type with the following key/value pairs:
* type: The {xmlsitemap}.type value
* title: The title of the type (usually plural form)
* item_title: The title of each individual item of this type (singular)
* access: An optional boolean that if TRUE will create links to each
* item's edit page as specified by the link key in $items.
* @param $items
* An array of items with the following keys:
* 'name': The translated name of the item.
* 'link': The path to edit the item. If $type['access'] is not TRUE, just
the item's name will be shown instead of a link.
* 'status': The item's default inclusion status.
* 'priority': The items default priority.
* Add a table summary for an entity and its bundles.
*/
function xmlsitemap_add_form_type_summary(&$form, $type, $items) {
$form[$type['type']] = array(
'#type' => 'fieldset',
'#title' => $type['title'],
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'xmlsitemap_settings',
);
function xmlsitemap_add_form_entity_summary(&$form, $entity, array $entity_info) {
$header = array(
$type['item_title'],
t('Type'),
t('Inclusion'),
t('Priority'),
t('Total'),
t('Indexed'),
t('Visible'),
);
$priorities = xmlsitemap_get_priority_options(NULL, FALSE);
$statuses = xmlsitemap_get_status_options(NULL);
$rows = array();
foreach ($items as $item_type => $item) {
$totals = array('total' => 0, 'indexed' => 0, 'visible' => 0);
foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
if (isset($bundle_info['admin'])) {
$bundle_info['admin'] += array(
'access callback' => 'user_access',
'access arguments' => array(),
'access' => FALSE,
);
if ($bundle_info['admin']['access callback']) {
$bundle_info['admin']['access'] = call_user_func_array($bundle_info['admin']['access callback'], $bundle_info['admin']['access arguments']);
}
}
// Fetch current per-bundle link total and indexed counts.
$status = xmlsitemap_get_link_type_indexed_status($entity, $bundle);
$totals['total'] += $status['total'];
$totals['indexed'] += $status['indexed'];
$totals['visible'] += $status['visible'];
$row = array();
if (!empty($bundle_info['admin']['access'])) {
$row[] = l($bundle_info['label'], $bundle_info['admin']['real path'], array('query' => drupal_get_destination()));
}
else {
$row[] = $bundle_info['label'];
}
$row[] = $statuses[$bundle_info['xmlsitemap']['status'] ? 1 : 0];
$row[] = $priorities[number_format($bundle_info['xmlsitemap']['priority'], 1)];
$row[] = $status['total'];
$row[] = $status['indexed'];
$row[] = $status['visible'];
$rows[] = $row;
}
if ($rows) {
$rows[] = array(
!empty($type['access']) ? l($item['name'], $item['link'], array('query' => drupal_get_destination())) : check_plain($item['name']),
$statuses[$item['status'] ? 1 : 0],
$priorities[number_format($item['priority'], 1)],
array(
'data' => t('Totals'),
'colspan' => 3,
'header' => TRUE,
),
array(
'data' => $totals['total'],
'header' => TRUE,
),
array(
'data' => $totals['indexed'],
'header' => TRUE,
),
array(
'data' => $totals['visible'],
'header' => TRUE,
),
/*$totals['total'],
$totals['indexed'],
$totals['visible'],*/
);
$form['summary'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
}
$form[$type['type']]['list'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
}
/**
......
......@@ -408,6 +408,21 @@ function _xmlsitemap_check_changed_link(array $link, $original_link = NULL, $fla
return $changed;
}
/**
* Load a specific sitemap link from the database.
*
* @param $entity_type
* A string with the entity type.
* @param $entity_id
* An integer with the entity ID.
* @return
* A sitemap link (array) or FALSE if the conditions were not found.
*/
function xmlsitemap_link_load($entity_type, $entity_id) {
$link = xmlsitemap_link_load_multiple(array('type' => $entity_type, 'id' => $entity_id));
return $link ? reset($link) : FALSE;
}
/**
* Load sitemap links from the database.
*
......@@ -430,21 +445,6 @@ function xmlsitemap_link_load_multiple(array $conditions = array()) {
return $links;
}
/**
* Load a specific sitemap link from the database.
*
* @param $entity_type
* A string with the entity type.
* @param $entity_id
* An integer with the entity ID.
* @return
* A sitemap link (array) or FALSE if the conditions were not found.
*/
function xmlsitemap_link_load($entity_type, $entity_id) {
$link = xmlsitemap_link_load_multiple(array('type' => $entity_type, 'id' => $entity_id));
return $link ? reset($link) : FALSE;
}
/**
* Saves or updates a sitemap link.
*
......@@ -771,31 +771,45 @@ function xmlsitemap_get_changefreq_options() {
* @see hook_xmlsitemap_link_info()
* @see hook_xmlsitemap_link_info_alter()
*/
function xmlsitemap_get_link_info($type = NULL) {
function xmlsitemap_get_link_info($type = NULL, $reset = FALSE) {
global $language;
$link_info = &drupal_static(__FUNCTION__);
if ($reset) {
$link_info = NULL;
}
elseif ($cached = cache_get('xmlsitemap:link_info:' . $language->language)) {
$link_info = $cached->data;
}
if (!isset($link_info)) {
if ($cached = cache_get('xmlsitemap:link_info:' . $language->language)) {
$link_info = $cached->data;
}
else {
$link_info = array();
foreach (module_implements('xmlsitemap_link_info') as $module) {
$module_link_info = module_invoke($module, 'xmlsitemap_link_info');
foreach ($module_link_info as $type => $info) {
$module_link_info[$type] += array(
'type' => $type,
'module' => $module,
'purge' => TRUE,
'table' => FALSE,
);
$link_info = entity_get_info();
foreach ($link_info as $key => $info) {
if (empty($info['path callback']) || !isset($info['xmlsitemap'])) {
// Remove any non URL-able or XML sitemap un-supported entites.
unset($link_info[$key]);
}
foreach ($info['bundles'] as $bundle_key => $bundle) {
if (!isset($bundle['xmlsitemap'])) {
// Remove any un-supported entity bundles.
unset($link_info[$key]['bundles'][$bundle_key]);
}
$link_info = array_merge($link_info, $module_link_info);
}
drupal_alter('xmlsitemap_link_info', $link_info);
cache_set('xmlsitemap:link_info:' . $language->language, $link_info);
}
$link_info = array_merge($link_info, module_invoke_all('xmlsitemap_link_info'));
foreach ($link_info as $key => $info) {
$link_info[$key] += array(
'type' => $key,
'base table' => FALSE,
'bundles' => array(),
'object keys' => array(),
'admin' => array(),
);
}
drupal_alter('xmlsitemap_link_info', $link_info);
ksort($link_info);
// Cache by language since this info contains translated strings.
cache_set('xmlsitemap:link_info:' . $language->language, $link_info);
}
if (isset($type)) {
......@@ -810,8 +824,36 @@ function xmlsitemap_get_link_info($type = NULL) {
*/
function xmlsitemap_xmlsitemap_link_info() {
return array(
'frontpage' => array(),
'frontpage' => array(
'label' => t('Frontpage'),
'xmlsitemap' => array(
'settings callback' => 'xmlsitemap_link_frontpage_settings',
),
),
);
}
/**
* XML sitemap link type settings callback for frontpage link entity.
*/
function xmlsitemap_link_frontpage_settings(&$form) {
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
if (user_access('administer site configuration')) {
$form['#description'] = t('The front page path can be changed at <a href="@url-frontpage">@url-frontpage</a>.', array('@url-frontpage' => url('admin/settings/site-information')));
}
$form['xmlsitemap_frontpage_priority'] = array(
'#type' => 'select',
'#title' => t('Priority'),
'#options' => xmlsitemap_get_priority_options(),
'#default_value' => variable_get('xmlsitemap_frontpage_priority', 1.0),
);
$form['xmlsitemap_frontpage_changefreq'] = array(
'#type' => 'select',
'#title' => t('Change frequency'),
'#options' => xmlsitemap_get_changefreq_options(),
'#default_value' => variable_get('xmlsitemap_frontpage_changefreq', XMLSITEMAP_FREQUENCY_DAILY),
);
return $form;
}
function xmlsitemap_get_directory() {
......@@ -903,15 +945,15 @@ function xmlsitemap_get_link_type_indexed_status($entity_type, $bundle = '') {
$visible->condition('status', 1);
$visible->condition('access', 1);
$status['indexed'] = $indexed->countQuery()->execute();
$status['visible'] = $visible->countQuery()->execute();
$status['indexed'] = $indexed->countQuery()->execute()->fetchField();
$status['visible'] = $visible->countQuery()->execute()->fetchField();
$total = db_select($info['base table']);
$total->addField($info['object keys']['id']);
if (!empty($info['object keys']['bundle'])) {
$total->addField('xmlsitemap', $info['object keys']['id']);
if (!empty($info['object keys']['bundle']) && db_column_exists($info['base table'], $info['object keys']['bundle'])) {
$total->condition($info['object keys']['bundle'], $bundle);
}
$status['total'] = $total->countQuery()->execute();
$status['total'] = $total->countQuery()->execute()->fetchField();
return $status;
}
......@@ -5,6 +5,7 @@
* Implements hook_entity_info_alter().
*/
function xmlsitemap_node_entity_info_alter(&$entity_info) {
$entity_info['node']['xmlsitemap'] = array();
foreach (node_type_get_names() as $type => $name) {
$entity_info['node']['bundles'][$type]['xmlsitemap'] = array(
'priority' => variable_get('xmlsitemap_node_priority_' . $type, 0.5),
......
......@@ -5,6 +5,7 @@
* Implements hook_entity_info_alter().
*/
function xmlsitemap_taxonomy_entity_info_alter(&$entity_info) {
$entity_info['taxonomy_term']['xmlsitemap'] = array();
foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocabulary) {
$entity_info['taxonomy_term']['bundles'][$machine_name]['xmlsitemap'] = array(
'priority' => variable_get('xmlsitemap_taxonomy_priority_' . $vocabulary->vid, 0.5),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment