| 1 |
<?php
|
| 2 |
function plazes_help($section) {
|
| 3 |
switch ($section) {
|
| 4 |
case 'admin/help#plazes':
|
| 5 |
return t('Show <a href="%url">plazes</a> in user profiles.', array('%url' => 'http://beta.plazes.com/'));
|
| 6 |
case 'admin/modules#description':
|
| 7 |
return t('This modules connects with the plazes website and shows the latest known plaze of your users, once they supply their Plazes username and password. If the GMap Filter module is installed, it prints the plaze on a Google Map.');
|
| 8 |
}
|
| 9 |
}
|
| 10 |
|
| 11 |
function plazes_settings() {
|
| 12 |
$form = array();
|
| 13 |
|
| 14 |
$form['plazes_cache_time'] = array(
|
| 15 |
'#type' => 'select', '#title' => t('Cache time'),
|
| 16 |
'#default_value' => variable_get('plazes_cache_time', 30),
|
| 17 |
'#options' => array(
|
| 18 |
1 => format_plural(1, '%count minute', '%count minutes'),
|
| 19 |
5 => format_plural(5, '%count minute', '%count minutes'),
|
| 20 |
10 => format_plural(10, '%count minute', '%count minutes'),
|
| 21 |
30 => format_plural(30, '%count minute', '%count minutes'),
|
| 22 |
60 => format_plural(1, '%count hour', '%count hours'),
|
| 23 |
120 => format_plural(2, '%count hour', '%count hours'),
|
| 24 |
), '#description' => t('The time for caching of plazes data.'),
|
| 25 |
);
|
| 26 |
$form['plazes_profile_message'] = array(
|
| 27 |
'#type' => 'textarea', '#title' => t('Message shown on user profile'),
|
| 28 |
'#default_value' => variable_get('plazes_profile_message', '%username can be found here: <a href="%plazeurl">%plazename</a>.'), 50, 6, t('Here you can setup the text that will be shown on the profile page with the Plazes info. You can use substitution variables here, like %plazeurl and %plazename.'),
|
| 29 |
'#rows' => 8,
|
| 30 |
);
|
| 31 |
|
| 32 |
return $form;
|
| 33 |
}
|
| 34 |
|
| 35 |
function _plazes_location() {
|
| 36 |
return 'http://beta.plazes.com/xmlrpc/whereami.php';
|
| 37 |
}
|
| 38 |
|
| 39 |
// return array with key => val
|
| 40 |
function plazes_api_whereami($username, $passwd) {
|
| 41 |
return xmlrpc(_plazes_location(), 'plazes.whereami', $username, md5('PLAZES'. $passwd));
|
| 42 |
}
|
| 43 |
|
| 44 |
function plazes_user_form($user) {
|
| 45 |
$form = array();
|
| 46 |
|
| 47 |
$form['plazes'] = array(
|
| 48 |
'#type' => 'fieldset', '#title' => t('Plazes'), '#weight' => 4
|
| 49 |
);
|
| 50 |
$form['plazes']['plazes_user'] = array(
|
| 51 |
'#type' => 'textfield', '#title' => t('Plazes login'), '#size' => 30,
|
| 52 |
'#maxlength' => 255, '#default_value' => $user->plazes_user
|
| 53 |
);
|
| 54 |
$form['plazes']['plazes_passwd'] = array(
|
| 55 |
'#type' => 'password', '#title' => t('Password'), '#size' => 30,
|
| 56 |
'#maxlength' => 255, '#default_value' => $user->plazes_passwd
|
| 57 |
);
|
| 58 |
|
| 59 |
return $form;
|
| 60 |
}
|
| 61 |
|
| 62 |
function plazes_user_update(&$user) {
|
| 63 |
$plazes_cache_time = variable_get('plazes_cache_time', 30);
|
| 64 |
if ((time() - $user->plazes_last_update) >= ($plazes_cache_time * 60)) {
|
| 65 |
if (($user->plazes_user != '') && ($user->plazes_passwd != '')) {
|
| 66 |
$plaze = plazes_api_whereami($user->plazes_user, $user->plazes_passwd);
|
| 67 |
$user->plaze = $plaze;
|
| 68 |
$user->plazes_last_update = time();
|
| 69 |
user_save($user, array('plaze' => $user->plaze, 'plazes_last_update' => $user->plazes_last_update));
|
| 70 |
}
|
| 71 |
}
|
| 72 |
}
|
| 73 |
|
| 74 |
function plazes_user_view(&$account) {
|
| 75 |
plazes_user_update($account);
|
| 76 |
if (is_array($account->plaze)) {
|
| 77 |
$output = '';
|
| 78 |
if (module_exist('gmap')) {
|
| 79 |
$output .= theme('plaze_gmap', $account);
|
| 80 |
}
|
| 81 |
$output .= theme('plaze', $account);
|
| 82 |
return array(t('Plazes') => $output);
|
| 83 |
}
|
| 84 |
}
|
| 85 |
|
| 86 |
function plazes_user($op, &$edit, &$user, $category = NULL) {
|
| 87 |
switch ($op) {
|
| 88 |
case 'view':
|
| 89 |
return plazes_user_view($user);
|
| 90 |
break;
|
| 91 |
case 'form':
|
| 92 |
if ($category == 'account') {
|
| 93 |
return plazes_user_form($user);
|
| 94 |
}
|
| 95 |
break;
|
| 96 |
}
|
| 97 |
}
|
| 98 |
|
| 99 |
function theme_plaze_gmap($account) {
|
| 100 |
global $user;
|
| 101 |
|
| 102 |
if (($account->plaze['plazelon'] != 999) && ($account->plaze['plazelat'] != 999)) {
|
| 103 |
$points = $account->plaze['plazelon'] .', '. $account->plaze['plazelat'];
|
| 104 |
if (($user->uid != $account->uid) && (!empty($user->plaze)) && is_array($user->plaze)) {
|
| 105 |
$points .= '+'. $user->plaze['plazelon'] .', '. $user->plaze['plazelat'];
|
| 106 |
}
|
| 107 |
$gmap = array(
|
| 108 |
'id' => 'plazesmap'. $account->uid,
|
| 109 |
'center' => $account->plaze['plazelon'] .', '. $account->plaze['plazelat'],
|
| 110 |
'points' => $points,
|
| 111 |
);
|
| 112 |
return gmap_from_var($gmap);
|
| 113 |
}
|
| 114 |
}
|
| 115 |
|
| 116 |
function theme_plaze($account) {
|
| 117 |
global $user;
|
| 118 |
|
| 119 |
$output = '<div class="plazes-plaze">';
|
| 120 |
$output .= t(variable_get('plazes_profile_message', '%username can be found here: <a href="%plazeurl">%plazename</a>.'),
|
| 121 |
array(
|
| 122 |
'%username' => $account->plaze['username'],
|
| 123 |
'%plazeurl' => $account->plaze['plazeurl'],
|
| 124 |
'%plazename' => $account->plaze['plazename'],
|
| 125 |
'%plazecountry' => $account->plaze['plazecountry'],
|
| 126 |
'%plazecity' => $account->plaze['plazecity'],
|
| 127 |
'%plazelat' => $account->plaze['plazelat'],
|
| 128 |
'%plazelon' => $account->plaze['plazelon']
|
| 129 |
)
|
| 130 |
);
|
| 131 |
$output .= '</div>';
|
| 132 |
|
| 133 |
return $output;
|
| 134 |
}
|