| 1 |
<?php
|
| 2 |
// $Id: location_user.module,v 1.2 2008/12/05 18:22:31 bdragon Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Associate locations with users.
|
| 7 |
*/
|
| 8 |
|
| 9 |
function location_user_perm() {
|
| 10 |
return array(
|
| 11 |
'administer user locations',
|
| 12 |
'set own user location',
|
| 13 |
'view own user location',
|
| 14 |
'view all user locations',
|
| 15 |
);
|
| 16 |
}
|
| 17 |
|
| 18 |
/**
|
| 19 |
* Alter the user_admin_settings form.
|
| 20 |
*/
|
| 21 |
function location_user_form_user_admin_settings_alter(&$form, &$form_state) {
|
| 22 |
if (isset($form_state['values']['location_settings_user'])) {
|
| 23 |
$settings = $form_state['values']['location_settings_user'];
|
| 24 |
}
|
| 25 |
else {
|
| 26 |
$settings = variable_get('location_settings_user', array());
|
| 27 |
}
|
| 28 |
|
| 29 |
$form['location_settings_user'] = location_settings($settings);
|
| 30 |
$form['location_settings_user']['#title'] = t('User locations');
|
| 31 |
|
| 32 |
$form['location_settings_user']['form']['register'] = array(
|
| 33 |
'#type' => 'checkbox',
|
| 34 |
'#title' => t('Collect during registration'),
|
| 35 |
'#default_value' => isset($settings['form']['register']) ? $settings['form']['register'] : FALSE,
|
| 36 |
'#weight' => -5,
|
| 37 |
);
|
| 38 |
}
|
| 39 |
|
| 40 |
/**
|
| 41 |
* Implementation of hook_user().
|
| 42 |
*/
|
| 43 |
function location_user_user($op, &$edit, &$account, $category = NULL) {
|
| 44 |
global $user;
|
| 45 |
|
| 46 |
switch ($op) {
|
| 47 |
case 'load':
|
| 48 |
$account->locations = location_load_locations($account->uid, 'uid');
|
| 49 |
$account->location = count($account->locations) ? $account->locations[0] : array();
|
| 50 |
break;
|
| 51 |
|
| 52 |
case 'insert':
|
| 53 |
case 'update':
|
| 54 |
if (!empty($edit['locations'])) {
|
| 55 |
location_save_locations($edit['locations'], array('uid' => $account->uid));
|
| 56 |
}
|
| 57 |
unset($edit['locations']);
|
| 58 |
break;
|
| 59 |
|
| 60 |
case 'delete':
|
| 61 |
$locations = array();
|
| 62 |
location_save_locations($locations, array('uid' => $account->uid));
|
| 63 |
break;
|
| 64 |
|
| 65 |
case 'form':
|
| 66 |
if ($category == 'account') {
|
| 67 |
if ((($user->uid == $account->uid) && user_access('set own user location')) || user_access('administer user locations')) {
|
| 68 |
$settings = variable_get('location_settings_user', array());
|
| 69 |
$form['locations'] = location_form($settings, $account->locations);
|
| 70 |
return $form;
|
| 71 |
}
|
| 72 |
}
|
| 73 |
break;
|
| 74 |
|
| 75 |
case 'register':
|
| 76 |
$settings = variable_get('location_settings_user', array());
|
| 77 |
if (isset($settings['form']['register']) && $settings['form']['register']) {
|
| 78 |
$form['locations'] = location_form($settings, array());
|
| 79 |
return $form;
|
| 80 |
}
|
| 81 |
break;
|
| 82 |
|
| 83 |
case 'view':
|
| 84 |
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')) {
|
| 85 |
if (variable_get('location_display_location', 1) && isset($account->locations) && count($account->locations)) {
|
| 86 |
$settings = variable_get('location_settings_user', array());
|
| 87 |
$account->content['locations'] = location_display($settings, $account->locations);
|
| 88 |
}
|
| 89 |
}
|
| 90 |
break;
|
| 91 |
}
|
| 92 |
}
|
| 93 |
|
| 94 |
/**
|
| 95 |
* Implementation of hook_locationapi().
|
| 96 |
*/
|
| 97 |
function location_user_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
|
| 98 |
switch ($op) {
|
| 99 |
case 'instance_links':
|
| 100 |
foreach ($obj as $k => $v) {
|
| 101 |
if ($v['uid'] != 0) {
|
| 102 |
$account = user_load(array('uid' => $v['uid']));
|
| 103 |
$obj[$k]['href'] = 'user/'. $v['uid'];
|
| 104 |
$obj[$k]['title'] = $account->name;
|
| 105 |
$obj[$k]['type'] = t('User location');
|
| 106 |
}
|
| 107 |
}
|
| 108 |
}
|
| 109 |
}
|