Commit 48011397 authored by Dave Reid's avatar Dave Reid
Browse files

by Dave Reid: Adding the xmlsitemap_user sub-module to the Drupal 7 branch.

parent f47c2275
; $Id$
name = XML sitemap user
description = Adds user profile links to the sitemap.
package = XML sitemap
dependencies[] = xmlsitemap
core = 7.x
files[] = xmlsitemap_user.module
files[] = xmlsitemap_user.install
<?php
// $Id$
/**
* @file
* Install and uninstall schema and functions for the xmlsitemap_user module.
*/
/**
* Implements hook_requirements().
*/
function xmlsitemap_user_requirements($phase) {
$requirements = array();
$t = get_t();
if ($phase == 'runtime') {
if (!user_access('access user profiles', drupal_anonymous_user())) {
$requirements['xmlsitemap_user_anonymous_permission'] = array(
'title' => $t('XML sitemap user'),
'value' => $t('Anonymous access to user profiles'),
'description' => $t('In order to list user profile links in the sitemap, the anonymous user must have the <a href="@perm-link"><em>access user profiles</em> permission</a>.', array('@perm-link' => url('admin/config/people/permissions', array('fragment' => 'module-user')))),
'severity' => REQUIREMENT_ERROR,
);
}
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function xmlsitemap_user_uninstall() {
drupal_load('module', 'user');
drupal_load('module', 'xmlsitemap');
db_query("DELETE FROM {variable} WHERE name LIKE 'xmlsitemap_settings_user_%%");
xmlsitemap_link_bundle_delete('user', 'user');
}
<?php
// $Id$
/**
* Implements hook_entity_info_alter().
*/
function xmlsitemap_user_entity_info_alter(&$entity_info) {
$entity_info['user']['bundle label'] = t('Users');
$entity_info['user']['xmlsitemap'] = array(
'process callback' => 'xmlsitemap_user_xmlsitemap_process_user_links',
);
$entity_info['user']['bundles']['user']['xmlsitemap'] = array('status' => 1);
dpm($entity_info);
}
/**
* Implements hook_xmlsitemap_link_info().
*/
/*function xmlsitemap_user_xmlsitemap_link_info() {
$types['user'] = array(
'label' => t('Users'),
'bundle label' => t('Users'),
'base table' => 'users',
'object keys' => array(
'id' => 'uid',
),
'bundles' => array(
'user' => array(
'label' => t('Users'),
),
),
'path callback' => 'user_path',
'load hook' => 'user_load',
'xmlsitemap' => array(
'process callback' => 'xmlsitemap_user_xmlsitemap_process_user_links',
),
);
return $types;
}*/
/**
* Implements hook_cron().
*
* Process old users not found in the {xmlsitemap} table.
*/
function xmlsitemap_user_cron() {
xmlsitemap_user_xmlsitemap_index_links(xmlsitemap_var('batch_limit'));
}
/**
* Implements hook_xmlsitemap_index_links().
*/
function xmlsitemap_user_xmlsitemap_index_links($limit) {
$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) {
$accounts = user_load_multiple($uids);
foreach ($accounts as $account) {
$link = xmlsitemap_user_create_link($account);
xmlsitemap_save_link($link);
}
}
/**
* Implements hook_user_insert().
*/
function xmlsitemap_user_user_insert(&$edit, $account, $category) {
$link = xmlsitemap_user_create_link($account);
xmlsitemap_save_link($link);
}
/**
* Implements hook_user_insert().
*/
function xmlsitemap_user_user_update(&$edit, $account, $category) {
$link = xmlsitemap_user_create_link($account);
xmlsitemap_save_link($link);
}
function xmlsitemap_user_user_cancel($edit, $account, $method) {
xmlsitemap_link_delete('user', $account->uid);
}
/**
* 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(stdClass &$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');
$account->xmlsitemap += array(
'type' => 'user',
'subtype' => 'user',
'id' => $account->uid,
'loc' => 'user/' . $account->uid,
'status' => 1, // @todo $settings['status'] defaults to 0 so fix this
'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['access'] = $account->uid && $account->status && $account->access;
$account->xmlsitemap['language'] = !empty($account->language) ? $account->language : LANGUAGE_NONE;
return $account->xmlsitemap;
}
/**
* Implementation of hook_variables().
*/
function xmlsitemap_user_variables() {
$defaults = array();
return $defaults;
}
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