/[drupal]/contributions/modules/user_tags/user_tags.module
ViewVC logotype

Diff of /contributions/modules/user_tags/user_tags.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.14.2.7, Tue Oct 9 09:03:31 2007 UTC revision 1.14.2.8, Tue May 6 19:12:40 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id:$  // $Id: user_tags.module,v 1.14.2.7 2007/10/09 09:03:31 flk Exp $
3    
4  /**  /**
5  * Implementation of hook_help().   * Implementation of hook_help().
6   */   */
7  function user_tags_help($section) {  function user_tags_help($section) {
8    switch ($section) {    switch ($section) {
# Line 17  function user_tags_help($section) { Line 17  function user_tags_help($section) {
17   * Implementation of hook_perm().   * Implementation of hook_perm().
18   */   */
19  function user_tags_perm() {  function user_tags_perm() {
20    return array('administer user tags', 'tag users');    return array('administer user tags', 'tag users', 'view user tags');
21  }  }
22    
23    
24  /**  /**
25  * Implementation of hook_menu().   * Implementation of hook_menu().
26   */   */
27  function user_tags_menu($may_cache) {  function user_tags_menu($may_cache) {
28    $access = 'tag users';    $access = 'tag users';
# Line 70  function user_tags_settings() { Line 70  function user_tags_settings() {
70    
71    $vocab = db_query("SELECT vid, name, description FROM {vocabulary}");    $vocab = db_query("SELECT vid, name, description FROM {vocabulary}");
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;
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)) {
78        $match_options[] = $enabled->vid;        $match_options[] = $enabled->vid;
79      }      }
80      $form["user_tags_vocabulary_list"] = array("#type" => "select",      $form["user_tags_vocabulary_list"] = array(
81       "#multiple" => true,        "#type" => 'select',
82          "#multiple" => true,
83        "#required" => true,        "#required" => true,
84        "#title" => t("Vocabularies Available"),        "#title" => t("Vocabularies Available"),
85        "#description" => t("To select multiple items, hold ctrl (command) and click on the items"),        "#description" => t("To select multiple items, hold ctrl (command) and click on the items"),
# Line 86  function user_tags_settings() { Line 87  function user_tags_settings() {
87        "#default_value" => $match_options        "#default_value" => $match_options
88      );      );
89    
90      $form["user_tags_display_options"] = array("#type" => "fieldset",      $form["user_tags_display_options"] = array(
91          "#type" => 'fieldset',
92        "#collapsible" => true,        "#collapsible" => true,
93        "#title" => t("Display Options")        "#title" => t("Display Options")
94      );      );
95    
96      $form["user_tags_display_options"]["user_tags_user_page"] = array("#type" => "checkbox",      $form["user_tags_display_options"]["user_tags_user_page"] = array(
97          "#type" => 'checkbox',
98        "#title" => t("Display tags on user's profile pages (user/username)"),        "#title" => t("Display tags on user's profile pages (user/username)"),
99        "#default_value" => variable_get("user_tag_user_page", true),        "#default_value" => variable_get("user_tags_user_page", true),
100        "#return_value" => true,        "#return_value" => true,
101      );      );
102    
103    } else {    }
104      drupal_set_message(t("You must add a ". l(t("vocabulary"), "admin/taxonomy") ."before using this module."), "error");    else {
105        drupal_set_message(t('You must add a !link before using this module.', array('!link' => l(t('vocabulary'), 'admin/taxonomy'))), "error");
106    }    }
107    
108    return system_settings_form($form);    return system_settings_form($form);
# Line 111  function user_tags_settings() { Line 115  function user_tags_settings() {
115  function user_tags_user($op, &$edit, &$account, $category = NULL) {  function user_tags_user($op, &$edit, &$account, $category = NULL) {
116    switch ($op) {    switch ($op) {
117      case 'view':      case 'view':
118        return user_tags_view_tags($account);        if (user_access('view user tags')) {
119            return user_tags_view_tags($account);
120          }
121          break;
122    
123      case 'load':      case 'load':
124        user_tags_load_tags($account);        user_tags_load_tags($account);
# Line 180  function user_tags_page_list() { Line 187  function user_tags_page_list() {
187        $rows[] = array(l($term_name, "tag/user/$term_tid"));        $rows[] = array(l($term_name, "tag/user/$term_tid"));
188      }      }
189    }    }
190    
191    return theme('table', array(t('Tags')), $rows);    return theme('table', array(t('Tags')), $rows);
192  }  }
193    
# Line 197  function user_tags_page_users($tid) { Line 204  function user_tags_page_users($tid) {
204    $term = taxonomy_get_term($tid);    $term = taxonomy_get_term($tid);
205    $tmp = array();    $tmp = array();
206    if (!$tid || $term->tid != $tid) {    if (!$tid || $term->tid != $tid) {
207      drupal_goto("tags");      drupal_goto('tags');
208    }    }
209    else {    else {
210      drupal_set_title($term->name);      drupal_set_title($term->name);
# Line 251  function user_tags_form_tags($category, Line 258  function user_tags_form_tags($category,
258    if ($category != 'tags') {    if ($category != 'tags') {
259      return;      return;
260    }    }
261    
262    if (!isset($account->taxonomy)) {    if (!isset($account->taxonomy)) {
263      if ($account->uid) {      if ($account->uid) {
264        $terms = user_tags_get_terms($account->uid);        $terms = user_tags_get_terms($account->uid);
# Line 274  function user_tags_form_tags($category, Line 281  function user_tags_form_tags($category,
281          if ($term->vid == $vocabulary->vid) {          if ($term->vid == $vocabulary->vid) {
282            // Commas and quotes in terms are special cases, so encode 'em.            // Commas and quotes in terms are special cases, so encode 'em.
283            if (preg_match('/,/', $term->name) || preg_match('/"/', $term->name)) {            if (preg_match('/,/', $term->name) || preg_match('/"/', $term->name)) {
284              $term->name = '"'.preg_replace('/"/', '""', $term->name).'"';              $term->name = '"'. preg_replace('/"/', '""', $term->name) .'"';
285            }            }
286            $typed_terms[] = $term->name;            $typed_terms[] = $term->name;
287          }          }
# Line 306  function user_tags_form_tags($category, Line 313  function user_tags_form_tags($category,
313            $default_terms[$term->tid] = $term;            $default_terms[$term->tid] = $term;
314          }          }
315        }        }
316    
317        $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);
318        $form['taxonomy']['tags'][$vocabulary->vid]['#weight'] = $vocabulary->weight;        $form['taxonomy']['tags'][$vocabulary->vid]['#weight'] = $vocabulary->weight;
319        $form['taxonomy']['tags'][$vocabulary->vid]['#required'] = $vocabulary->required;        $form['taxonomy']['tags'][$vocabulary->vid]['#required'] = $vocabulary->required;
# Line 433  function user_tags_get_similar_users($te Line 440  function user_tags_get_similar_users($te
440    if (empty($terms)) {    if (empty($terms)) {
441      return array();      return array();
442    }    }
443    
444    $args = implode(',', array_keys($terms));    $args = implode(',', array_keys($terms));
445    $result = db_query('SELECT    $result = db_query('SELECT
446                          u.uid AS uid,                          u.uid AS uid,
# Line 446  function user_tags_get_similar_users($te Line 453  function user_tags_get_similar_users($te
453                        LIMIT %d', $args, $limit);                        LIMIT %d', $args, $limit);
454    if (db_num_rows($result)) {    if (db_num_rows($result)) {
455      $items = array();      $items = array();
456    
457      while ($item = db_fetch_object($result)) {      while ($item = db_fetch_object($result)) {
458        $items[] = theme('username', user_load(array('uid' => $item->uid)));        $items[] = theme('username', user_load(array('uid' => $item->uid)));
459      }      }
460    
461      return $items;      return $items;
462    }    }
463    else {    else {

Legend:
Removed from v.1.14.2.7  
changed lines
  Added in v.1.14.2.8

  ViewVC Help
Powered by ViewVC 1.1.2