| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: xmlsitemap_user.module,v 1.12.2.16.2.23 2010/04/30 03:31:22 davereid Exp $ 3 4 /** 5 * Implements hook_xmlsitemap_link_info(). 6 */ 7 function xmlsitemap_user_xmlsitemap_link_info() { 8 $types['user'] = array( 9 'label' => t('Users'), 10 'bundle label' => t('User'), 11 'base table' => 'users', 12 'entity keys' => array( 13 'id' => 'uid', 14 ), 15 'bundles' => array( 16 'user' => array( 17 'label' => t('User'), 18 'admin' => array( 19 'path' => 'admin/user/settings', 20 'access arguments' => array('administer users'), 21 ), 22 ), 23 ), 24 'path callback' => 'xmlsitemap_user_path', 25 'load hook' => 'user_load', 26 'xmlsitemap' => array( 27 'process callback' => 'xmlsitemap_user_xmlsitemap_process_user_links', 28 ), 29 ); 30 return $types; 31 } 32 33 function xmlsitemap_user_path($account) { 34 return 'user/' . $account->uid; 35 } 36 37 /** 38 * Implements hook_cron(). 39 * 40 * Process old users not found in the {xmlsitemap} table. 41 */ 42 function xmlsitemap_user_cron() { 43 xmlsitemap_user_xmlsitemap_index_links(xmlsitemap_var('batch_limit')); 44 } 45 46 /** 47 * Implements hook_xmlsitemap_index_links(). 48 */ 49 function xmlsitemap_user_xmlsitemap_index_links($limit) { 50 $query = 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", array(), 0, $limit); 51 $uids = array(); 52 while ($uid = db_result($query)) { 53 $uids[] = $uid; 54 } 55 xmlsitemap_user_xmlsitemap_process_user_links($uids); 56 } 57 58 /** 59 * Process user sitemap links. 60 * 61 * @param $uids 62 * An array of user IDs. 63 */ 64 function xmlsitemap_user_xmlsitemap_process_user_links(array $uids) { 65 foreach ($uids as $uid) { 66 if ($account = user_load($uid)) { 67 $link = xmlsitemap_user_create_link($account); 68 xmlsitemap_link_save($link); 69 } 70 } 71 } 72 73 /** 74 * Implements hook_user(). 75 */ 76 function xmlsitemap_user_user($op, &$edit, $account, $category = NULL) { 77 switch ($op) { 78 case 'insert': 79 case 'update': 80 case 'after_update': 81 // We need to check both update and after update since the user hooks 82 // won't have an updated $account object until after_update. 83 $link = xmlsitemap_user_create_link($account); 84 if (isset($edit['xmlsitemap'])) { 85 $link = $edit['xmlsitemap'] + $link; 86 // Unset since we don't want this saved to $user->data. 87 unset($edit['xmlsitemap']); 88 } 89 xmlsitemap_link_save($link); 90 break; 91 case 'delete': 92 xmlsitemap_link_delete('user', $account->uid); 93 break; 94 } 95 } 96 97 /** 98 * Implements hook_form_FORM_ID_alter(). 99 * 100 * @see user_register() 101 * @see xmlsitemap_add_form_link_options() 102 */ 103 function xmlsitemap_user_form_user_register_alter(&$form, $form_state) { 104 // Add the link options. 105 module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin'); 106 xmlsitemap_add_form_link_options($form, 'user', 'user', $form['#uid']); 107 } 108 109 /** 110 * Implements hook_form_FORM_ID_alter(). 111 * 112 * @see user_admin_settings() 113 * @see xmlsitemap_add_form_link_options() 114 */ 115 function xmlsitemap_user_form_user_profile_form_alter(&$form, $form_state) { 116 // Add the link options. 117 module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin'); 118 xmlsitemap_add_form_link_options($form, 'user', 'user', $form['#uid']); 119 } 120 121 /** 122 * Implements hook_form_FORM_ID_alter(). 123 * 124 * @see user_admin_settings() 125 * @see xmlsitemap_add_link_bundle_settings() 126 */ 127 function xmlsitemap_user_form_user_admin_settings_alter(&$form, $form_state) { 128 module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin'); 129 xmlsitemap_add_link_bundle_settings($form, $form_state, 'user', 'user'); 130 array_unshift($form['#submit'], 'xmlsitemap_user_user_admin_settings_submit'); 131 } 132 133 function xmlsitemap_user_user_admin_settings_submit($form, &$form_state) { 134 xmlsitemap_link_bundle_settings_save('user', 'user', $form_state['values']['xmlsitemap']); 135 136 // Do not allow system_settings_form_submit() to run variable_set() on this. 137 unset($form_state['values']['xmlsitemap']); 138 } 139 140 /** 141 * Create a sitemap link from a user. 142 * 143 * The link will be saved as $account->xmlsitemap. 144 * 145 * @param $account 146 * A user object. 147 */ 148 function xmlsitemap_user_create_link(stdClass &$account) { 149 if (!isset($account->xmlsitemap)) { 150 $account->xmlsitemap = array(); 151 if ($account->uid && $link = xmlsitemap_link_load('user', $account->uid)) { 152 $account->xmlsitemap = $link; 153 } 154 } 155 156 $settings = xmlsitemap_link_bundle_load('user', 'user'); 157 158 $account->xmlsitemap += array( 159 'type' => 'user', 160 'subtype' => 'user', 161 'id' => $account->uid, 162 'loc' => 'user/' . $account->uid, 163 'status' => $settings['status'], 164 'status_default' => $settings['status'], 165 'status_override' => 0, 166 'priority' => $settings['priority'], 167 'priority_default' => $settings['priority'], 168 'priority_override' => 0, 169 ); 170 171 // The following values must always be checked because they are volatile. 172 $account->xmlsitemap['access'] = $account->uid && $account->status && $account->login && $account->access; 173 $account->xmlsitemap['language'] = !empty($account->language) ? $account->language : ''; 174 175 return $account->xmlsitemap; 176 } 177 178 /** 179 * Implementation of hook_variables(). 180 */ 181 function xmlsitemap_user_variables() { 182 $defaults = array(); 183 return $defaults; 184 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |