| 1 |
<?php |
<?php |
| 2 |
// $id:$ |
// $Id:$ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 12 |
} |
} |
| 13 |
} |
} |
| 14 |
|
|
| 15 |
|
|
| 16 |
/** |
/** |
| 17 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 18 |
*/ |
*/ |
| 20 |
return array('administer user tags', 'tag users'); |
return array('administer user tags', 'tag users'); |
| 21 |
} |
} |
| 22 |
|
|
| 23 |
|
|
| 24 |
/** |
/** |
| 25 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 26 |
*/ |
*/ |
| 56 |
return $items; |
return $items; |
| 57 |
} |
} |
| 58 |
|
|
| 59 |
|
|
| 60 |
/** |
/** |
| 61 |
* Implementation of hook_settings(). |
* Implementation of hook_settings(). |
| 62 |
*/ |
*/ |
| 63 |
function user_tags_settings() { |
function user_tags_settings() { |
| 64 |
if ($_POST['user_tags_vocabulary_list']) { |
if ($_POST['user_tags_vocabulary_list']) { |
| 72 |
if (db_affected_rows() > 0) { |
if (db_affected_rows() > 0) { |
| 73 |
while($vocab_list = db_fetch_object($vocab)) { |
while($vocab_list = db_fetch_object($vocab)) { |
| 74 |
$options[$vocab_list->vid] = $vocab_list->name; |
$options[$vocab_list->vid] = $vocab_list->name; |
|
if ($vocab_list->description) { |
|
|
$options[$vocab_list->vid] .=" - ". $vocab_list->description; |
|
|
} |
|
| 75 |
} |
} |
| 76 |
$enabled_vocab = db_query("SELECT vu.vid, v.name FROM {user_tags_vocabulary} vu INNER JOIN {vocabulary} v ON v.vid = vu.vid"); |
$enabled_vocab = db_query("SELECT vu.vid, v.name FROM {user_tags_vocabulary} vu INNER JOIN {vocabulary} v ON v.vid = vu.vid"); |
| 77 |
while($enabled = db_fetch_object($enabled_vocab)) { |
while($enabled = db_fetch_object($enabled_vocab)) { |
| 104 |
return system_settings_form($form); |
return system_settings_form($form); |
| 105 |
} |
} |
| 106 |
|
|
| 107 |
|
|
| 108 |
/** |
/** |
| 109 |
* Implementation of hook_user(). |
* Implementation of hook_user(). |
| 110 |
*/ |
*/ |
| 111 |
function user_tags_user($op, &$edit, &$account, $category = NULL) { |
function user_tags_user($op, &$edit, &$account, $category = NULL) { |
| 112 |
switch ($op) { |
switch ($op) { |
| 113 |
case 'view': |
case 'view': |
| 114 |
return user_tags_view_tags($account); |
return user_tags_view_tags($account); |
|
break; |
|
| 115 |
|
|
| 116 |
case 'load': |
case 'load': |
| 117 |
return user_tags_load_tags($account); |
user_tags_load_tags($account); |
| 118 |
break; |
break; |
| 119 |
|
|
| 120 |
case 'form': |
case 'form': |
| 121 |
return user_tags_form_tags($category, $account); |
return user_tags_form_tags($category, $account); |
|
break; |
|
| 122 |
|
|
| 123 |
case 'submit': |
case 'submit': |
| 124 |
return user_tags_submit_tags($category, $edit, $account); |
user_tags_submit_tags($category, $edit, $account); |
| 125 |
break; |
break; |
| 126 |
|
|
| 127 |
case 'categories': |
case 'categories': |
| 128 |
return array(array('name' => 'tags', 'title' => t('tags'), 'weight' => 10)); |
return array(array('name' => 'tags', 'title' => t('Tags'), 'weight' => 10)); |
|
break; |
|
| 129 |
|
|
| 130 |
case 'delete': |
case 'delete': |
| 131 |
return user_tags_delete_tags($account); |
user_tags_delete_tags($account); |
| 132 |
break; |
break; |
| 133 |
} |
} |
| 134 |
} |
} |
| 135 |
|
|
| 136 |
|
|
| 137 |
/** |
/** |
| 138 |
* Find all terms associated to the given user, ordered by vocabulary and term weight. |
* Find all terms associated to the given user, ordered by vocabulary and term weight. |
| 139 |
|
* |
| 140 |
|
* @param int - $uid : User ID |
| 141 |
|
* @param char - $key : Key used for query rewriting - default to 'tid' |
| 142 |
|
* @return array - of terms assigned to a user |
| 143 |
*/ |
*/ |
| 144 |
function user_tags_get_terms($uid, $key = 'tid') { |
function user_tags_get_terms($uid, $key = 'tid') { |
| 145 |
static $terms; |
static $terms; |
| 154 |
return $terms[$uid]; |
return $terms[$uid]; |
| 155 |
} |
} |
| 156 |
|
|
| 157 |
|
|
| 158 |
/** |
/** |
| 159 |
* prints all the vocab in use atm |
* prints all the vocab in use atm |
| 160 |
* |
* |
| 161 |
* @param char $tid : term id |
* @param char $tid : term id |
| 162 |
* @return page listing off all the users with corresponding term |
* @return char - page listing off all the users with corresponding term |
| 163 |
*/ |
*/ |
| 164 |
function user_tags_page_list() { |
function user_tags_page_list() { |
| 165 |
$term = taxonomy_get_term($tid); |
$term = taxonomy_get_term($tid); |
| 171 |
$vocab_query = (db_query('SELECT DISTINCT(tu.vid) as vid, v.name FROM {term_user} tu INNER JOIN {vocabulary} v ON tu.vid = v.vid GROUP BY vid')); |
$vocab_query = (db_query('SELECT DISTINCT(tu.vid) as vid, v.name FROM {term_user} tu INNER JOIN {vocabulary} v ON tu.vid = v.vid GROUP BY vid')); |
| 172 |
$count_vocab = db_num_rows($vocab_query); |
$count_vocab = db_num_rows($vocab_query); |
| 173 |
|
|
| 174 |
while ($term = db_fetch_object($query)) { |
while ($term = db_fetch_object($query)) { |
| 175 |
$vocab[$term->vid][$term->tid] = $term->termname; |
$vocab[$term->vid][$term->tid] = $term->termname; |
| 176 |
} |
} |
| 177 |
|
|
| 179 |
foreach ($tid as $term_tid=>$term_name) { |
foreach ($tid as $term_tid=>$term_name) { |
| 180 |
$rows[] = array(l($term_name, "tag/user/$term_tid")); |
$rows[] = array(l($term_name, "tag/user/$term_tid")); |
| 181 |
} |
} |
| 182 |
}return theme('table', array(t('Tags')), $rows); |
} |
| 183 |
|
|
| 184 |
|
return theme('table', array(t('Tags')), $rows); |
|
|
|
| 185 |
} |
} |
| 186 |
|
|
| 187 |
|
|
| 188 |
|
/** |
| 189 |
|
* Generate a table of users and their tags |
| 190 |
|
* |
| 191 |
|
* @param int $tid : Term ID |
| 192 |
|
* @return char : page listing all users and their tags |
| 193 |
|
*/ |
| 194 |
function user_tags_page_users($tid) { |
function user_tags_page_users($tid) { |
| 195 |
$row = array(); |
$row = array(); |
| 196 |
$rows = array(); |
$rows = array(); |
| 218 |
return theme('table', array(t('Name'), t('Tags')), $rows); |
return theme('table', array(t('Name'), t('Tags')), $rows); |
| 219 |
} |
} |
| 220 |
} |
} |
| 221 |
|
|
| 222 |
|
|
| 223 |
/** |
/** |
| 224 |
* Enter description here... |
* Get all the terms associated with a user but limited to a specified Vocabulary ID |
| 225 |
* |
* |
| 226 |
* @param int $uid : user ID |
* @param int $uid : user ID |
| 227 |
* @param int $vid : vocabulary ID |
* @param int $vid : vocabulary ID |
| 228 |
* @param char $key : term ID |
* @param char $key : term ID |
| 229 |
* @return all the tags belonging to the user with the specified uid |
* @return array : all the tags belonging to the user with the specified uid |
| 230 |
*/ |
*/ |
| 231 |
function user_tags_get_terms_by_vocabulary($uid, $vid, $key = 'tid') { |
function user_tags_get_terms_by_vocabulary($uid, $vid, $key = 'tid') { |
| 232 |
$result = db_query('SELECT t.* FROM {term_data} t INNER JOIN {term_user} tu WHERE tu.tid = t.tid AND tu.vid = %d AND tu.uid =%d', $vid, $uid); |
$result = db_query('SELECT t.* FROM {term_data} t INNER JOIN {term_user} tu WHERE tu.tid = t.tid AND tu.vid = %d AND tu.uid =%d', $vid, $uid); |
| 237 |
return $terms; |
return $terms; |
| 238 |
} |
} |
| 239 |
|
|
| 240 |
|
|
| 241 |
/** |
/** |
| 242 |
* generate the categories selected for this module |
* generate the categories selected for this module |
| 243 |
* in admin setting, if user has already selected any tags |
* in admin setting, if user has already selected any tags |
| 245 |
* |
* |
| 246 |
* @param char $category : current page name |
* @param char $category : current page name |
| 247 |
* @param array $account : user details |
* @param array $account : user details |
| 248 |
* @return taxonomy form |
* @return array : taxonomy form |
| 249 |
*/ |
*/ |
| 250 |
function user_tags_form_tags($category, $account){ |
function user_tags_form_tags($category, $account){ |
| 251 |
if ($category != 'tags') { |
if ($category != 'tags') { |
| 252 |
return; |
return; |
| 253 |
} |
} |
| 254 |
|
|
| 255 |
if (!isset($account->taxonomy)) { |
if (!isset($account->taxonomy)) { |
| 256 |
if ($account->uid) { |
if ($account->uid) { |
| 257 |
$terms = user_tags_get_terms($account->uid); |
$terms = user_tags_get_terms($account->uid); |
| 306 |
$default_terms[$term->tid] = $term; |
$default_terms[$term->tid] = $term; |
| 307 |
} |
} |
| 308 |
} |
} |
| 309 |
|
|
| 310 |
$form['taxonomy']['tags'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, array_keys($default_terms), $vocabulary->help); |
$form['taxonomy']['tags'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, array_keys($default_terms), $vocabulary->help); |
| 311 |
$form['taxonomy']['tags'][$vocabulary->vid]['#weight'] = $vocabulary->weight; |
$form['taxonomy']['tags'][$vocabulary->vid]['#weight'] = $vocabulary->weight; |
| 312 |
$form['taxonomy']['tags'][$vocabulary->vid]['#required'] = $vocabulary->required; |
$form['taxonomy']['tags'][$vocabulary->vid]['#required'] = $vocabulary->required; |
| 318 |
return $form; |
return $form; |
| 319 |
} |
} |
| 320 |
|
|
| 321 |
function user_tags_load_tags($account){ |
|
| 322 |
|
/** |
| 323 |
|
* Load tags onto a User Object |
| 324 |
|
* |
| 325 |
|
* @param object $account : User Object for modifying (passed ByRef) |
| 326 |
|
*/ |
| 327 |
|
function user_tags_load_tags(&$account){ |
| 328 |
$result = db_query('SELECT t.* FROM {term_data} t INNER JOIN {term_user} tu WHERE tu.tid = t.tid AND tu.uid = %d ORDER BY weight, name', $account->uid); |
$result = db_query('SELECT t.* FROM {term_data} t INNER JOIN {term_user} tu WHERE tu.tid = t.tid AND tu.uid = %d ORDER BY weight, name', $account->uid); |
| 329 |
$account->taxonomy = array(); |
$account->taxonomy = array(); |
| 330 |
while ($term = db_fetch_object($result)) { |
while ($term = db_fetch_object($result)) { |
| 331 |
$account->taxonomy[$term->tid] = $term; |
$account->taxonomy[$term->tid] = $term; |
| 332 |
} |
} |
|
return $account->taxonomy; |
|
| 333 |
} |
} |
| 334 |
|
|
| 335 |
|
|
| 336 |
|
/** |
| 337 |
|
* Function for deleting tags from a user account |
| 338 |
|
* |
| 339 |
|
* @param object $account : User Object |
| 340 |
|
*/ |
| 341 |
function user_tags_delete_tags($account){ |
function user_tags_delete_tags($account){ |
| 342 |
db_query('DELETE FROM {term_user} WHERE uid = %d', $account->uid); |
db_query('DELETE FROM {term_user} WHERE uid = %d', $account->uid); |
| 343 |
} |
} |
| 344 |
|
|
| 345 |
|
|
| 346 |
|
/** |
| 347 |
|
* User submit handling function. |
| 348 |
|
* |
| 349 |
|
* @param char $category : The selected tab on the user profile page. |
| 350 |
|
* @param array $edit : the values returned from the submitted form |
| 351 |
|
* @param object $account : The User Object |
| 352 |
|
*/ |
| 353 |
function user_tags_submit_tags($category, $edit, $account){ |
function user_tags_submit_tags($category, $edit, $account){ |
| 354 |
if ($category != 'tags') { |
if ($category != 'tags') { |
| 355 |
return; |
return; |
| 402 |
unset($edit['taxonomy']); |
unset($edit['taxonomy']); |
| 403 |
} |
} |
| 404 |
|
|
| 405 |
|
|
| 406 |
|
/** |
| 407 |
|
* Return an array of links to user tags. |
| 408 |
|
* |
| 409 |
|
* @param object $account : User account object (from user_load() function) |
| 410 |
|
* @return array : nested array |
| 411 |
|
*/ |
| 412 |
function user_tags_view_tags($account){ |
function user_tags_view_tags($account){ |
| 413 |
$list = array(); |
$list = array(); |
| 414 |
foreach ($account->taxonomy as $tid => $term) { |
foreach ($account->taxonomy as $tid => $term) { |
| 419 |
return array('Tags' => $list); |
return array('Tags' => $list); |
| 420 |
} |
} |
| 421 |
} |
} |
| 422 |
|
|
| 423 |
|
/** |
| 424 |
|
* Find users with similar tags. Results are ordered so the closest matching user |
| 425 |
|
* is decided on number of matching terms, falling back to alphabetical on |
| 426 |
|
* username if matching terms are equal. |
| 427 |
|
* |
| 428 |
|
* @param array $terms : array of term objects with the array keys as term ID's (ie, the result of user_tags_get_terms($uid) |
| 429 |
|
* @param int $limit : optional, limit the number of results returned. Default: 5 |
| 430 |
|
* @return array : Array of output from theme_username. |
| 431 |
|
*/ |
| 432 |
|
function user_tags_get_similar_users($terms, $limit = 5) { |
| 433 |
|
if (empty($terms)) { |
| 434 |
|
return array(); |
| 435 |
|
} |
| 436 |
|
|
| 437 |
|
$args = implode(',', array_keys($terms)); |
| 438 |
|
$result = db_query('SELECT |
| 439 |
|
u.uid AS uid, |
| 440 |
|
COUNT(*) AS cnt |
| 441 |
|
FROM {users} u |
| 442 |
|
LEFT JOIN {term_user} tu ON tu.uid = u.uid AND tu.tid IN (%s) |
| 443 |
|
WHERE u.status = 1 AND tu.tid IS NOT NULL |
| 444 |
|
GROUP BY u.uid |
| 445 |
|
ORDER BY cnt DESC, u.name ASC |
| 446 |
|
LIMIT %d', $args, $limit); |
| 447 |
|
if (db_num_rows($result)) { |
| 448 |
|
$items = array(); |
| 449 |
|
|
| 450 |
|
while ($item = db_fetch_object($result)) { |
| 451 |
|
$items[] = theme('username', user_load(array('uid' => $item->uid))); |
| 452 |
|
} |
| 453 |
|
|
| 454 |
|
return $items; |
| 455 |
|
} |
| 456 |
|
else { |
| 457 |
|
return array(); |
| 458 |
|
} |
| 459 |
|
} |