first import
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
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
|
||||
files[] = xmlsitemap_user.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-12-08
|
||||
version = "7.x-2.0-rc2+0-dev"
|
||||
core = "7.x"
|
||||
project = "xmlsitemap"
|
||||
datestamp = "1354931808"
|
||||
|
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @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>View user profiles</em> permission</a>.', array('@perm-link' => url('admin/people/permissions/' . DRUPAL_ANONYMOUS_RID, array('fragment' => 'module-user')))),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function xmlsitemap_user_uninstall() {
|
||||
drupal_load('module', 'user');
|
||||
drupal_load('module', 'xmlsitemap');
|
||||
xmlsitemap_link_bundle_delete('user', 'user');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_update_last_removed().
|
||||
*/
|
||||
function xmlsitemap_user_update_last_removed() {
|
||||
return 6202;
|
||||
}
|
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_entity_info_alter().
|
||||
*/
|
||||
function xmlsitemap_user_entity_info_alter(&$entity_info) {
|
||||
$entity_info['user']['bundle label'] = t('User');
|
||||
$entity_info['user']['xmlsitemap'] = array(
|
||||
'process callback' => 'xmlsitemap_user_xmlsitemap_process_user_links',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_link_save($link);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_presave().
|
||||
*/
|
||||
function xmlsitemap_user_user_presave(&$edit, $account, $category) {
|
||||
if (!empty($account->uid)) {
|
||||
$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_user_insert(&$edit, $account, $category) {
|
||||
$link = xmlsitemap_user_create_link($account);
|
||||
xmlsitemap_link_save($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_update().
|
||||
*/
|
||||
function xmlsitemap_user_user_update(&$edit, $account, $category) {
|
||||
$link = xmlsitemap_user_create_link($account);
|
||||
xmlsitemap_link_save($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_delete().
|
||||
*/
|
||||
function xmlsitemap_user_user_delete($account) {
|
||||
xmlsitemap_link_delete('user', $account->uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_extra_fields().
|
||||
*/
|
||||
function xmlsitemap_user_field_extra_fields() {
|
||||
$extras['user']['user']['form']['xmlsitemap'] = array(
|
||||
'label' => t('XML sitemap'),
|
||||
'description' => t('XML sitemap module element'),
|
||||
'weight' => 30,
|
||||
);
|
||||
return $extras;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*
|
||||
* @see user_admin_settings()
|
||||
* @see xmlsitemap_add_link_bundle_settings()
|
||||
*/
|
||||
function xmlsitemap_user_form_user_profile_form_alter(&$form, $form_state) {
|
||||
// Add the link options.
|
||||
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
|
||||
xmlsitemap_add_form_link_options($form, 'user', 'user', $form['#user']->uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*
|
||||
* @see user_admin_settings()
|
||||
* @see xmlsitemap_add_link_bundle_settings()
|
||||
*/
|
||||
function xmlsitemap_user_form_user_admin_settings_alter(&$form, $form_state) {
|
||||
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
|
||||
xmlsitemap_add_link_bundle_settings($form, $form_state, 'user', 'user');
|
||||
$form['email_title'] += array('#weight' => 10);
|
||||
$form['email'] += array('#weight' => 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
$uri = entity_uri('user', $account);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_variables().
|
||||
*/
|
||||
function xmlsitemap_user_variables() {
|
||||
$defaults = array();
|
||||
return $defaults;
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Unit tests for the xmlsitemap_user module.
|
||||
*/
|
||||
|
||||
class XMLSitemapUserFunctionalTest extends XMLSitemapTestHelper {
|
||||
protected $normal_user;
|
||||
protected $accounts = array();
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'XML sitemap user',
|
||||
'description' => 'Functional tests for the XML sitemap user module.',
|
||||
'group' => 'XML sitemap',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp($modules = array()) {
|
||||
$modules[] = 'xmlsitemap_user';
|
||||
parent::setUp($modules);
|
||||
|
||||
// Save the user settings before creating the users.
|
||||
xmlsitemap_link_bundle_settings_save('user', 'user', array('status' => 1, 'priority' => 0.5));
|
||||
|
||||
// Create the users
|
||||
$this->admin_user = $this->drupalCreateUser(array('administer users', 'administer permissions', 'administer xmlsitemap'));
|
||||
$this->normal_user = $this->drupalCreateUser(array('access content'));
|
||||
|
||||
// Update the normal user to make its sitemap link visible.
|
||||
$account = clone $this->normal_user;
|
||||
user_save($account, array('access' => 1, 'login' => 1));
|
||||
}
|
||||
|
||||
function testBlockedUser() {
|
||||
$this->drupalLogin($this->admin_user);
|
||||
$this->assertSitemapLinkVisible('user', $this->normal_user->uid);
|
||||
|
||||
// Mark the user as blocked.
|
||||
$edit = array(
|
||||
'status' => 0,
|
||||
);
|
||||
|
||||
// This will pass when http://drupal.org/node/360925 is fixed.
|
||||
$this->drupalPost('user/' . $this->normal_user->uid . '/edit', $edit, t('Save'));
|
||||
$this->assertText('The changes have been saved.');
|
||||
$this->assertSitemapLinkNotVisible('user', $this->normal_user->uid);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user