6.x-3.x branch
Associate locations with users.
| Name | Description |
|---|---|
| location_user_form_user_admin_settings_alter | Alter the user_admin_settings form. |
| location_user_locationapi | Implementation of hook_locationapi(). |
| location_user_perm | |
| location_user_user | Implementation of hook_user(). |
- <?php
-
- /**
- * @file
- * Associate locations with users.
- */
-
- function location_user_perm() {
- return array(
- 'administer user locations',
- 'set own user location',
- 'view own user location',
- 'view all user locations',
- );
- }
-
- /**
- * Alter the user_admin_settings form.
- */
- function location_user_form_user_admin_settings_alter(&$form, &$form_state) {
- if (isset($form_state['values']['location_settings_user'])) {
- $settings = $form_state['values']['location_settings_user'];
- }
- else {
- $settings = variable_get('location_settings_user', array());
- }
-
- $form['location_settings_user'] = location_settings($settings);
- $form['location_settings_user']['#title'] = t('User locations');
-
- $form['location_settings_user']['form']['register'] = array(
- '#type' => 'checkbox',
- '#title' => t('Collect during registration'),
- '#default_value' => isset($settings['form']['register']) ? $settings['form']['register'] : FALSE,
- '#weight' => -5,
- );
- }
-
- /**
- * Implementation of hook_user().
- */
- function location_user_user($op, &$edit, &$account, $category = NULL) {
- global $user;
-
- switch ($op) {
- case 'load':
- $account->locations = location_load_locations($account->uid, 'uid');
- $account->location = count($account->locations) ? $account->locations[0] : array();
- break;
-
- case 'insert':
- case 'update':
- if (!empty($edit['locations'])) {
- location_save_locations($edit['locations'], array('uid' => $account->uid));
- }
- unset($edit['locations']);
- break;
-
- case 'delete':
- $locations = array();
- location_save_locations($locations, array('uid' => $account->uid));
- break;
-
- case 'form':
- if ($category == 'account') {
- if ((($user->uid == $account->uid) && user_access('set own user location')) || user_access('administer user locations')) {
- $settings = variable_get('location_settings_user', array());
- $form['locations'] = location_form($settings, $account->locations);
- return $form;
- }
- }
- break;
-
- case 'register':
- $settings = variable_get('location_settings_user', array());
- if (isset($settings['form']['register']) && $settings['form']['register']) {
- $form['locations'] = location_form($settings, array());
- return $form;
- }
- break;
-
- case 'view':
- if ((($user->uid == $account->uid) && user_access('view own user location')) || user_access('administer users') || user_access('view all user locations') || user_access('administer user locations')) {
- if (variable_get('location_display_location', 1) && isset($account->locations) && count($account->locations)) {
- $settings = variable_get('location_settings_user', array());
- $account->content['locations'] = location_display($settings, $account->locations);
- }
- }
- break;
- }
- }
-
- /**
- * Implementation of hook_locationapi().
- */
- function location_user_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
- switch ($op) {
- case 'instance_links':
- foreach ($obj as $k => $v) {
- if ($v['uid'] != 0) {
- $account = user_load(array('uid' => $v['uid']));
- $obj[$k]['href'] = 'user/'. $v['uid'];
- $obj[$k]['title'] = $account->name;
- $obj[$k]['type'] = t('User location');
- }
- }
- }
- }
-