Commit 19b970e4 authored by andrei.dincu's avatar andrei.dincu
Browse files

Issue #2249723 by andrei.dincu: Start porting xmlsitemap_user submodule by

inserting all hooks into xmlsitemap.module file
parent 8d4042bf
......@@ -244,6 +244,9 @@ function xmlsitemap_cron() {
if ($lifetime < \Drupal::config('xmlsitemap.settings')->get('minimum_lifetine')) {
return;
}
if (\Drupal::state()->get('xmlsitemap_entity_user')) {
xmlsitemap_xmlsitemap_index_links(xmlsitemap_var('batch_limit'));
}
// Regenerate the sitemap XML files.
module_load_include('generate.inc', 'xmlsitemap');
......@@ -377,6 +380,7 @@ function xmlsitemap_sitemap_load_multiple($smids = array(), array $conditions =
foreach ($sitemaps as &$sitemap) {
$sitemap->setContext(unserialize($sitemap->getContext()));
$uri = xmlsitemap_sitemap_uri($sitemap);
$sitemap->setContext(serialize($sitemap->getContext()));
$sitemap->uri = $uri;
}
......@@ -504,6 +508,9 @@ function xmlsitemap_sitemap_get_max_filesize(XmlSitemapInterface $sitemap) {
}
function xmlsitemap_sitemap_get_context_hash(array &$context) {
if (is_string($context)) {
$context = unserialize($context);
}
asort($context);
return Crypt::hashBase64(serialize($context));
}
......@@ -1563,3 +1570,150 @@ function xmlsitemap_get_operation_link($url, $options = array()) {
$link += array('query' => $destination);
return $link;
}
/**
* Hooks for xmlsitemap_user submodule
*/
/**
* Implements hook_entity_info_alter().
*/
function xmlsitemap_entity_info_alter(&$entity_info) {
if (!\Drupal::state()->get('xmlsitemap_entity_user')) {
return $entity_info;
}
$entity_info['user']['bundle label'] = t('User');
$entity_info['user']['xmlsitemap'] = array(
'process callback' => 'xmlsitemap_user_xmlsitemap_process_user_links',
);
}
/**
* Implements hook_xmlsitemap_index_links().
*/
function xmlsitemap_xmlsitemap_index_links($limit) {
if (!\Drupal::state()->get('xmlsitemap_entity_user')) {
return ;
}
$uids = db_query_range("SELECT u.uid FROM {users} u LEFT JOIN {xmlsitemap} x ON x.type = 'user' AND u.uid = x.id WHERE x.id IS NULL AND u.uid > 0 ORDER BY u.uid DESC", 0, $limit)->fetchCol();
xmlsitemap_user_xmlsitemap_process_user_links($uids);
}
/**
* Process user sitemap links.
*
* @param $uids
* An array of user IDs.
*/
function xmlsitemap_user_xmlsitemap_process_user_links(array $uids) {
if (!\Drupal::state()->get('xmlsitemap_entity_user')) {
return ;
}
$accounts = user_load_multiple($uids);
foreach ($accounts as $account) {
$link = xmlsitemap_user_create_link($account);
xmlsitemap_link_save($link);
}
}
/**
* Implements hook_user_presave().
*/
function xmlsitemap_user_presave(&$edit, $account, $category) {
drupal_set_message('ana are mere');
if (!\Drupal::state()->get('xmlsitemap_entity_user')) {
return ;
}
if (!empty($account->uid)) {
drupal_set_message('bogdan are mere');
$link = xmlsitemap_user_create_link($account);
if (isset($edit['xmlsitemap'])) {
$link = $edit['xmlsitemap'] + $link;
unset($edit['xmlsitemap']);
}
xmlsitemap_link_save($link);
}
}
/**
* Implements hook_user_insert().
*/
function xmlsitemap_user_insert(&$edit, $account, $category) {
if (!\Drupal::state()->get('xmlsitemap_entity_user')) {
return ;
}
$link = xmlsitemap_user_create_link($account);
xmlsitemap_link_save($link);
}
/**
* Implements hook_user_update().
*/
function xmlsitemap_user_update(&$edit, $account, $category) {
if (!\Drupal::state()->get('xmlsitemap_entity_user')) {
return ;
}
$link = xmlsitemap_user_create_link($account);
xmlsitemap_link_save($link);
}
/**
* Implements hook_user_delete().
*/
function xmlsitemap_user_delete($account) {
xmlsitemap_link_delete('user', $account->uid);
}
/**
* Implements hook_field_extra_fields().
*/
function xmlsitemap_field_extra_fields() {
$extras['user']['user']['form']['xmlsitemap'] = array(
'label' => t('XML sitemap'),
'description' => t('XML sitemap module element'),
'weight' => 30,
);
return $extras;
}
/**
* Create a sitemap link from a user.
*
* The link will be saved as $account->xmlsitemap.
*
* @param $account
* A user object.
*/
function xmlsitemap_user_create_link(&$account) {
if (!isset($account->xmlsitemap)) {
$account->xmlsitemap = array();
if ($account->uid && $link = xmlsitemap_link_load('user', $account->uid)) {
$account->xmlsitemap = $link;
}
}
$settings = xmlsitemap_link_bundle_load('user', 'user');
//$uri = entity_uri('user', $account);
$uri = $account->uri;
$account->xmlsitemap += array(
'type' => 'user',
'id' => $account->uid,
'subtype' => 'user',
'status' => $settings['status'],
'status_default' => $settings['status'],
'status_override' => 0,
'priority' => $settings['priority'],
'priority_default' => $settings['priority'],
'priority_override' => 0,
);
// The following values must always be checked because they are volatile.
$account->xmlsitemap['loc'] = $uri['path'];
$account->xmlsitemap['access'] = $account->uid && $account->status;
$account->xmlsitemap['language'] = !empty($account->language) ? $account->language : LANGUAGE_NONE;
return $account->xmlsitemap;
}
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