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

Diff of /contributions/modules/interests/interests.module

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

revision 1.6, Sat Nov 3 04:15:43 2007 UTC revision 1.7, Fri Apr 24 06:43:38 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2    // $Id: $
3    
4  /**  /**
5   * Implementation of hook_menu().   * @file interests.module
6     * Module that allows users to select taxonomy terms from vocabularies as 'interests'.
7   */   */
 function interests_menu($may_cache) {  
         global $user;  
8    
9    /**
10     * Implementation of hook_help().
11     */
12    function interests_help($path, $arg) {
13      switch ($path) {
14        case 'admin/help#interests':
15          return t("<p>The interests module allows users to select taxonomy terms from vocabularies as 'interests'. Each time they visit a node with that taxonomy term applied to it the interest level bumps up one, or creates a new interest for them. Interests can be added/removed manually on an administration/user level or by the user themselves.</p>");
16          break;
17      }
18    }
19    
20    /**
21     * Implementation of hook_menu().
22     */
23    function interests_menu() {
24    $items = array();    $items = array();
25    
26    if ($may_cache) {    $items['user/%user/interests'] = array(
27      $items[] = array('path' => 'interests',      'title' => t('My Interests'),
28        'title' => t('My Interests'),      'page callback' => 'interests_my_interests',
29        'callback' => 'interests_browse',      'page arguments' => array(1),
30        'access' => user_access('access interests'),      'access callback' => 'user_access',
31        'type' => MENU_NORMAL_ITEM);      'access arguments' => array('access interests'),
32            $items[] = array('path' => 'interests/add',      'type' => MENU_LOCAL_TASK,
33        'title' => t('Add Interest'),    );
34        'callback' => 'interests_add_node',    $items['user/%user/interests/edit'] = array(
35        'access' => user_access('access interests'),      'title' => t('Change My Interests'),
36        'type' => MENU_CALLBACK);      'page callback' => 'drupal_get_form',
37          $items[] = array('path' => 'interests/edit',      'page arguments' =>  array('interests_interests_form', 1),
38                          'title' => t('Change My Interests'),      'access callback' => 'user_access',
39                          'callback' => 'drupal_get_form',      'access arguments' => array('access interests'),
40                          'callback arguments' =>  array('interests_interests_form'),      'type' => MENU_CALLBACK,
41                          'access' => user_access('access interests'),    );
42                          'type' => MENU_CALLBACK);    $items['admin/user/interests'] = array(
43            $items[] = array('path' => 'admin/user/interests',      'title' => t('Interests'),
44        'title' => t('Interests'),      'description' => t('Interests per user.'),
45        'description' => t('Interets per user.'),      'page callback' => 'interests_user_overview',
46        'access' => user_access('admin interests'),      'access callback' => 'user_access',
47        'callback' => 'interests_user_overview',      'access arguments' => array('administer interests'),
48                          'callback arguments' => array(arg(1)));      'type' => MENU_NORMAL_ITEM,
49            $items[] = array('path' => 'admin/content/interests',    );
50        'title' => t('Interests'),    $items['admin/user/interests/edit'] = array(
51        'description' => t('Set which vocabularies can be interests.'),      'title' => t('Edit Interests'),
52        'access' => user_access('admin interests'),      'page callback' => 'drupal_get_form',
53        'callback' => 'drupal_get_form',      'page arguments' => array('interests_interests_form'),
54                          'callback arguments' => 'interests_vocabs_form',      'access callback' => 'user_access',
55                          );      'access arguments' => array('administer interests'),
56      $items[] = array('path' => 'admin/user/interests/add',      'type' => MENU_CALLBACK,
57        'title' => t('Add Interests to user'),    );
58        'callback' => 'drupal_get_form',    $items['interests/add'] = array(
59        'callback arguments' => array('interests_interests_form'),      'title' => t('Add Interest'),
60        'access' => user_access('admin interests'),      'page callback' => 'interests_add_node',
61        'type' => MENU_CALLBACK,      'access callback' => 'user_access',
62                          );      'access arguments' => array('access interests'),
63      $items[] = array('path' => 'admin/user/interests/edit',      'type' => MENU_CALLBACK,
64        'title' => t('Edit Interests'),    );
65        'callback' => 'drupal_get_form',  
       'callback arguments' => array('interests_interests_form'),  
       'access' => user_access('admin interests'),  
       'type' => MENU_CALLBACK);  
     $items[] = array('path' => 'admin/user/interests/delete',  
       'title' => t('Delete Interests'),  
       'callback' => 'drupal_get_form',  
       'callback arguments' => array('interests_interests_delete'),  
       'access' => user_access('admin interests'),  
       'type' => MENU_CALLBACK);  
   }  
         elseif (!$may_cache){  
           if (isset($user->uid) && arg(0) == 'node' && is_numeric(arg(1))){  
                         $terms = taxonomy_node_get_terms(arg(1));  
                         if ($terms){  
                                 foreach ($terms as $term){  
                                         _interests_dynamic_add($term->tid);  
                                 }  
                         }  
                 }  
         }  
   
66    return $items;    return $items;
67  }  }
68    
# Line 76  function interests_menu($may_cache) { Line 70  function interests_menu($may_cache) {
70   * Implementation of hook_perm().   * Implementation of hook_perm().
71   */   */
72  function interests_perm() {  function interests_perm() {
73          return array('access interests', 'edit interests', 'administer interests');    return array('access interests', 'administer interests');
74    }
75    
76    /**
77     * Implementation of hook_nodeapi().
78     */
79    function interests_nodeapi(&$node, $op, $a3, $a4) {
80      switch ($op) {
81        case 'view':
82          global $user;
83          // Only do this for pages not teasers
84          if ($user->uid && $a4) {
85            $terms = taxonomy_node_get_terms($node);
86            if ($terms) {
87              foreach ($terms as $term) {
88                if (interests_is_interest($user->uid, $term->tid)) {
89                  _interests_dynamic_add($term->tid, $user->uid);
90                }
91              }
92            }
93          }
94      }
95    }
96    
97    /**
98     * Implementations of hook_form_alter().
99     */
100    function interests_form_alter(&$form, &$form_state, $form_id) {
101      if ($form_id == 'taxonomy_form_vocabulary') {
102        $vid = (int) arg(5);
103        $count = db_result(db_query("SELECT COUNT(*) FROM {interests_vocabs} WHERE vid = %d", $vid));
104        $form['settings']['interests'] = array(
105          '#type' => 'checkbox',
106          '#title' => t('Use as interests vocabulary'),
107          '#default_value' => $count ? TRUE : FALSE,
108          '#description' => t('If checked, this vocabulary will be used as an interests vocabulary.'),
109        );
110    
111        $form['#submit'][] = 'interests_taxonomy_form_vocabulary_submit';
112      }
113    }
114    
115    /**
116     * Submit function for the taxonomy_form_vocabulary form
117     * Used to save whether or not the vocab is an interests vocab.
118     */
119    function interests_taxonomy_form_vocabulary_submit($form, &$form_state) {
120      $vocabs = _interests_get_vocabs();
121      if ($form_state['values']['interests']) {
122        if (!in_array($form_state['values']['vid'], $vocabs)) {
123          db_query("INSERT INTO {interests_vocabs} VALUES (%d)", $form_state['values']['vid']);
124        }
125      }
126      else {
127        if (in_array($form_state['values']['vid'], $vocabs)) {
128          db_query("DELETE FROM {interests_vocabs} WHERE vid = %d", $form_state['values']['vid']);
129        }
130      }
131    }
132    
133    /**
134     * Implementation of hook_link().
135     */
136    function interests_link($type, $node = NULL, $teaser = FALSE) {
137      $links = array();
138    
139      if ($type == 'node') {
140        if (!$teaser) {
141          if (user_access('access interests')) {
142            $links['interests_add_interests'] = array(
143              'title' => t('set as interest'),
144              'href' => 'interests/add/' . $node->nid,
145            );
146          }
147        }
148      }
149      return $links;
150    }
151    
152    /**
153     * My interests form (tab on my account page)
154     */
155    function interests_interests_form($form_state, $user) {
156      $output = l(t('Back to user list'), 'admin/user/interests');
157    
158      if (is_numeric(arg(4))) {
159        $uid = arg(4);
160        $default_values = _interests_get_interests($uid);
161        $result = db_query("SELECT uid, name FROM {users} WHERE uid = %d", $uid);
162        while ($row = db_fetch_object($result)) {
163          $uname = $row->name;
164        }
165      }
166      else {
167        $default_values = _interests_get_interests($user->uid);
168        $uid = $user->uid;
169        $uname = $user->name;
170      }
171    
172      $vocabs = _interests_get_vocabs();
173    
174      if (!empty($vocabs)) {
175        foreach ($vocabs as $i => $voc) {
176          $vocab_obj = taxonomy_vocabulary_load($voc);
177          //Generate a taxonomy term hiearchy selector
178          $tree = taxonomy_get_tree($voc);
179          if ($tree) {
180            foreach ($tree as $term) {
181              $choice = new stdClass();
182              $choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name);
183              $termlist[$vocab_obj->name][] = $choice;
184            }
185          }
186        }
187    
188        $form['interest_terms'] = array(
189          '#type' => 'select',
190          '#title' => t('Interests for ' . $uname),
191          '#multiple' => TRUE,
192          '#default_value' => $default_values,
193          '#options' => $termlist,
194        );
195        $form['uid'] = array(
196          '#type' => 'hidden',
197          '#value' => $uid,
198        );
199        $form['submit'] = array(
200          '#type' => 'submit',
201          '#value' => 'Save',
202        );
203      }
204      else {
205        $form['novocabs'] = array(
206          '#value' => t('No vocabularies have been assigned as a Interest vocabulary.'),
207        );
208      }
209      return $form;
210    }
211    
212    /**
213     * My interests form submit
214     */
215    function interests_interests_form_submit($form, &$form_state) {
216      $current_result = db_query("SELECT * FROM {interests} WHERE uid = %d", $form_state['values']['uid']);
217      while ($current_row = db_fetch_array($current_result)) {
218        $current_list[] = array('tid' => $current_row['tid'], 'uid' => $current_row['uid']);
219      }
220    
221      if ($current_list) {
222        foreach ($current_list as $i => $current_term) {
223          if (array_key_exists($current_term['tid'], $form_state['values']['interest_terms'])) {
224            unset($form_state['values']['interest_terms'][$current_term['tid']]);
225            unset($current_list[$i]);
226          }
227        }
228      }
229      foreach ($form_state['values']['interest_terms'] as $tid) {
230        $insert_result = db_query("INSERT INTO {interests} values (%d, %d, 0)", $form_state['values']['uid'], $tid);
231      }
232      if ($current_list) {
233        foreach ($current_list as $current) {
234          $delete_result = db_query("DELETE FROM {interests} WHERE uid = %d AND tid = %d", $form_state['values']['uid'], $current['tid']);
235        }
236      }
237    
238      drupal_set_message('Interests updated');
239    
240      $form_state['redirect'] = 'user/' . $form_state['values']['uid'] . '/interests';
241    }
242    
243    function interests_user_overview() {
244      $result = db_query('SELECT DISTINCT u.uid, u.name FROM {users} u WHERE u.uid != 0 ORDER BY u.name');
245      while ($row = db_fetch_object($result)) {
246        $table_row[] = array($row->name, l('Edit Interests', 'admin/user/interests/edit/' . $row->uid));
247      }
248      $output = theme('table', array('Username', 'Edit'), $table_row);
249    
250      return $output;
251    }
252    
253    /**
254     * Get the users interests
255     */
256    function _interests_get_interests($uid) {
257      $rows = array();
258    
259      if ($uid) {
260        $result = db_query("SELECT tid FROM {interests} WHERE uid = %d", $uid);
261        while ($row = db_fetch_array($result)) {
262          $rows[] = $row['tid'];
263        }
264      }
265    
266      return $rows;
267    }
268    
269    /**
270     * Return whether or not the term is one of the users interests.
271     */
272    function interests_is_interest($uid, $tid) {
273      if (!$uid || !$tid) {
274        return FALSE;
275      }
276    
277      $interests = _interests_get_interests($uid);
278    
279      if (in_array($tid, $interests)) {
280        return TRUE;
281      }
282    
283      return FALSE;
284    }
285    
286    /**
287     * Gets a list of interests vocabs.
288     */
289    function _interests_get_vocabs() {
290      $vocabs = array();
291      $result = db_query("SELECT * FROM {interests_vocabs}");
292      while ($row = db_fetch_object($result)) {
293        $vocabs[$row->vid] = $row->vid;
294      }
295      return $vocabs;
296    }
297    
298    /**
299     * Adds a nodes terms to the current users interests.
300     */
301    function interests_add_node() {
302      global $user;
303      if ($user->uid) {
304        $current_vocabs = _interests_get_vocabs();
305        $node = node_load(arg(2));
306        $terms = taxonomy_node_get_terms($node);
307        if ($terms) {
308          foreach ($terms as $term) {
309            if (interests_is_interest($user->uid, $term->tid)) {
310              _interests_dynamic_add($term->tid, $user->uid);
311            }
312          }
313        }
314      }
315    
316      drupal_goto('node/' . $node->nid);
317    }
318    
319    /**
320     * Adds a new interest tid to the database for the given user
321     * If the interest is already there it adds one to the count for that interest.
322     */
323    function _interests_dynamic_add($tid, $uid) {
324      if (!$uid || !$tid) {
325        return FALSE;
326      }
327    
328      $any_rows = FALSE;
329    
330      $result = db_query("SELECT * FROM {interests} WHERE uid = %d AND tid = %d", $uid, $tid);
331      while ($row = db_fetch_array($result)) {
332        $any_rows = TRUE;
333        $counter = $row['counter'] + 1;
334        db_query("UPDATE {interests} SET counter = %d WHERE uid = %d AND tid = %d", $counter, $uid, $tid);
335      }
336    
337      if (!$any_rows) {
338        db_query("INSERT INTO {interests} VALUES (%d, %d, 1)", $uid, $tid);
339      }
340  }  }
341    
342  function interests_link($type, $node = NULL, $teaser = FALSE){  /**
343          $links = array();   * Displays list of users that have most interest matches with you
344     * and list of nodes that best match your interests.
345     */
346    function interests_my_interests($user) {
347      $in = '';
348      $query_vars = array();
349    
350      if (module_exists('blog')) {
351        $blog_enabled = TRUE;
352      }
353    
354      $output = l(t('Change My Interests'), 'user/' . $user->uid . '/interests/edit');
355    
356          if ($type == 'node'){    // Do the selection of users where at least one tag matches, order by number of matches - Limited to 10
357                  if (!$teaser){  
358                          if (user_access('access interests')){    $my_tags = db_query("SELECT tid FROM {interests} WHERE uid = %d", $user->uid);
359                                  $links['interests_add_interests'] = array(  
360                                          'title' => t('set as interest'),    while ($row = db_fetch_array($my_tags)) {
361                                          'href' => 'interests/add/'.$node->nid,      $in .= $in ? ', %d' : '%d';
362                                  );      $query_vars[] = $row['tid'];
363                          }    }
364                  }    if ($in != '') {
365          }      $query_vars[] = $user->uid;
366          return $links;      $sql = "SELECT DISTINCT u.uid, u.name, SUM(i.counter) AS total_count
367  }                                FROM {interests} i, {users} u
368                                  WHERE u.uid = i.uid
369  function interests_interests_form($arg = NULL) {                                AND i.tid IN ($in)
370          global $user;                                AND i.uid NOT IN (%d, 0)
371                                  GROUP BY u.uid, u.name
372          $output = l(t('Back to user list'), 'admin/user/interests');                                ORDER BY total_count DESC
373                                  LIMIT 10";
374          if (is_numeric(arg(4))){      $result_users = db_query("SELECT DISTINCT u.uid, u.name, SUM(i.counter) AS total_count
375                  $default_values = _interests_tid_user_list(arg(4));                                FROM {interests} i, {users} u
376                  $uid = arg(4);                                WHERE u.uid = i.uid
377                  $result = db_query("SELECT uid, name from {users} WHERE uid = '%s'", arg(4));                                AND i.tid IN ($in)
378                  while ($row = db_fetch_object($result)){                                AND i.uid NOT IN (%d, 0)
379                          $uname = $row->name;                                GROUP BY u.uid, u.name
380                  }                                ORDER BY total_count DESC
381          }                                LIMIT 10", $query_vars);
382          else{  
383                  $default_values = _interests_tid_user_list($user->uid);      $table_rows = array();
384                  $uid = $user->uid;      while ($row = db_fetch_array($result_users)) {
385                  $uname = $user->name;        if ($blog_enabled) {
386          }          $table_rows[] = array(
387              'username' => $row['name'],
388          $vocabs = _interests_get_vocabs();            'blog' => l(t('View Blog'), 'blog/' . $row['uid']),
389              'profile' => l(t('View Profile'), 'user/' . $row['uid'])
390          if (!empty($vocabs)){          );
391                  foreach ($vocabs AS $i => $voc){        }
392                          $termlist[$voc->name] = _interests_tid_list($vocabs);        else {
393                  }          $table_rows[] = array(
394            $form['interest_terms'] = array(            'username' => $row['name'],
395                          '#type' => 'select',            'profile' => l(t('View Profile'), 'user/' . $row['uid'])
396                          '#title' => t('Interests for '.$uname),          );
397                          '#multiple' => TRUE,        }
398                          '#default_value' => $default_values,      }
399                          '#options' => $termlist  
400            );      if (!empty($table_rows)) {
401                  $form['uid'] = array(        $output .= "<h3>Users with similar interests</h3>";
402                          '#type' => 'hidden',        if ($blog_enabled) {
403                          '#value' => $uid          $output .= theme('table', array('Username', 'Blog', 'Profile'), $table_rows);
404                  );        }
405                  $form['submit'] = array(        else {
406                          '#type' => 'submit',          $output .= theme('table', array('Username', 'Profile'), $table_rows);
407                          '#value' => 'Change'        }
408                  );      }
409          }    }
410          else{    else {
411                  $form['novocabs'] = array(      $output .= "<p>You haven't specified any interests yet.</p>";
412                          '#value' => t('No vocabularies have been setup yet.'),    }
413                  );  
414          }    // Do the selection of nodes where tags match
415          return $form;    $types = db_query("SELECT nt.type, nt.name FROM {node_type} nt");
416  }    while ($type = db_fetch_array($types)) {
417        $nodes = db_query("SELECT n.nid, n.title, SUM(i.counter) AS total_count
418  function interests_interests_form_submit($form_id, $form_values){                         FROM {interests} i, {term_node} tn, {node} n
419          $currentResult = db_query("SELECT * FROM {interests} WHERE uid = '%s'", $form_values['uid']);                         WHERE n.nid = tn.nid
420          while ($currentRow = db_fetch_array($currentResult)){                         AND i.tid = tn.tid
421                  $currentList[] = array('tid' => $currentRow['tid'], 'uid' => $currentRow['uid']);                         AND i.uid = %d
422          }                         AND n.type = '%s'
423                           GROUP BY n.nid, n.title
424          if ($currentList){                         ORDER BY total_count DESC, n.changed DESC
425                  foreach ($currentList as $i => $currentTerm){                         LIMIT 5", $user->uid, $type['type']);
426                          if (array_key_exists($currentTerm['tid'], $form_values['interest_terms'])){  
427                                  unset($form_values['interest_terms'][$currentTerm['tid']]);      $list = array();
428                                  unset($currentList[$i]);      while ($node = db_fetch_array($nodes)) {
429                          }        $list[] = l($node['title'], 'node/' . $node['nid']);
430                  }      }
431          }      if (!empty($list)) {
432          foreach ($form_values['interest_terms'] as $tid){        $output .= theme('item_list', $list, t($type['name']), 'ul');
433                  $insertResult = db_query("INSERT INTO {interests} values ('%s', '%s', '1')", $form_values['uid'], $tid);      }
434          }    }
435          if ($currentList){  
436                  foreach ($currentList AS $current){    return $output;
437                          $deleteResult = db_query("DELETE FROM {interests} WHERE uid ='%s' AND tid='%s'", $form_values['uid'], $current['tid']);  }
438                  }  
439          }  /**
440     * Creates the content for the interests block.
441          return 'interests';   */
442  }  function _interests_user_suggestions() {
443      global $user;
444  function interests_user_overview(){    $output = '';
445    
446          $result = db_query('SELECT DISTINCT u.uid, u.name FROM {users} u WHERE u.uid != 0 ORDER BY u.name asc');    if ($user->uid == 0) {
447          while ($row = db_fetch_object($result)){      $output .= t("This site uses interest tagging for authenticated users");
448                  $tableRow[] = array($row->name, l('Edit Interests', 'admin/user/interests/add/'.$row->uid));    }
449          }    else {
450          $output = theme('table', array('Username', 'Edit'), $tableRow);      if (module_exists('tagadelic')) {
451          $result = db_query("SELECT i.counter AS count, t.tid, t.name, t.vid, t.weight
452          return $output;                            FROM {interests} i, {term_data} t
453  }                            WHERE t.tid = i.tid
454                              AND i.uid = %d
455  function _interests_get_vocabs(){                            ORDER BY t.name DESC", $user->uid);
456          static $return = array();        $tags = tagadelic_build_weighted_tags($result, $steps = 6);
457          $output .= theme('tagadelic_weighted', $tags);
458          $result = db_query("SELECT * FROM {interests_vocabs}");      }
459          while ($row = db_fetch_object($result)){    }
460                  $return[$row->vid] = $row->vid;    return $output;
         }  
         return $return;  
 }  
   
 function interests_vocabs_form(){  
   
         $vocabs = taxonomy_get_vocabularies();  
         if (!empty($vocabs)){  
   
                 foreach ($vocabs AS $vocab){  
                         $options[$vocab->vid] = $vocab->name;  
                 }  
                 $default_options = _interests_get_vocabs();  
   
                 $form['vocabularies'] = array(  
                         '#type' => 'select',  
                         '#options' => $options,  
                         '#title' => t('Vocabularies'),  
                         '#default_value' => $default_options,  
                         '#multiple' => true,  
                 );  
                 $form['submit'] = array(  
                         '#type' => 'submit',  
                         '#value' => 'Submit',  
                 );  
         }  
         else{  
                 $form['novocabs'] = array(  
                         '#value' => t('There are no taxonomy vocabularies yet.'),  
                 );  
         }  
   
         return $form;  
 }  
   
 function interests_vocabs_form_submit($form_id, &$form_values){  
   
         $currentVocabs = _interests_get_vocabs();  
   
         foreach ($form_values['vocabularies'] AS $i => $vocab){  
                 if (!isset($currentVocabs[$i])){  
                         db_query("INSERT INTO {interests_vocabs} VALUES (%s)", $vocab);  
                         unset($currentVocabs[$i]);  
                 }  
                 else{  
                         unset($currentVocabs[$i]);  
                 }  
         }  
         if (!empty($currentVocabs)){  
                 foreach ($currentVocabs AS $x => $delVocab){  
                         db_query("DELETE FROM {interests_vocabs} WHERE vid = '%s'", $delVocab);  
                 }  
         }  
 }  
   
 function interests_add_node(){  
         $nid = arg(2);  
   
         $terms = taxonomy_node_get_terms($nid);  
   if ($terms){  
                 foreach ($terms as $term){  
                         _interests_dynamic_add($term->tid);  
                 }  
         }  
   
         drupal_goto('node/'.$nid);  
 }  
   
 function _interests_dynamic_add($tid){  
         global $user;  
         $result = db_query("SELECT * FROM {interests} WHERE uid = '%s' AND tid = '%s'", $user->uid, $tid);  
         if (db_num_rows($result) != 0){  
                 while ($row = db_fetch_array($result)){  
                         $counter = $row['counter'] + 1;  
                         db_query("UPDATE {interests} SET counter = '%s' WHERE uid = '%s' AND tid = '%s'", $counter, $user->uid, $tid);  
                 }  
         }  
         else{  
                 db_query("INSERT INTO {interests} VALUES ('%s', '%s', 0)", $user->uid, $tid);  
         }  
   
 }  
   
 function _interests_tid_user_list($uid = NULL){  
         $result = db_query("SELECT tid FROM {interests} WHERE uid='%s'", $uid);  
   while ($row = db_fetch_array($result)){  
                 $rows[] = $row['tid'];  
         }  
         return $rows;  
 }  
   
 function _interests_tid_list($vocabularies) {  
   
   $tids = array();  
         foreach ($vocabularies as $vocab){  
           $result = db_query("SELECT DISTINCT(td.tid), td.name, td.weight, v.name as vocabname, v.weight FROM {term_data} td LEFT JOIN {vocabulary} v ON v.vid = td.vid WHERE td.vid = '%s' ORDER BY v.weight, v.name, td.weight, td.name", $vocab);  
           while ($obj = db_fetch_object($result)) {  
             $tids[$obj->tid] = $obj->vocabname.": ".$obj->name;  
           }  
         }  
   return $tids;  
 }  
   
 function interests_browse() {  
         global $user;  
   
         $output = l(t('Change My Interests'), 'interests/edit');  
   
         //Do the selection of users where at least one tag matches, order by number of matches - Limited to 10  
   
   
         $myTags = db_query("SELECT i.tid FROM {interests} i WHERE i.uid = '%s'", $user->uid);  
         if (db_num_rows($myTags) >= 1){  
                 while ($row = db_fetch_array($myTags)){  
                         $like .= "i.tid = '".$row['tid']."'  OR ";  
                 }  
                 $like = rtrim($like, ' OR ');  
                 if (isset($like)) {  
                         $resultUsers = db_query("SELECT i.uid, i.tid, u.name, t.name AS tname FROM {interests} i, {users} u, {term_data} t WHERE ($like) AND i.uid != '%s' AND i.uid != '0' AND u.uid = i.uid AND i.tid = t.tid GROUP BY i.uid ORDER BY i.counter desc LIMIT 10", $user->uid);  
                         if (db_num_rows($resultUsers) >=1){  
                     $output .= "<h2>".t('Users with similar interests')."</h2>";  
                                 while ($row = db_fetch_array($resultUsers)){  
                                         $tableRow[] = array('username' => $row['name'],  
                                                                                                         'blog' => l(t('View Blog'), 'blog/'.$row['uid']),  
                                                                                                         'profile' => l(t('View Profile'), 'user/'.$row['uid']));  
                                 }  
                                 $output .= theme('table', array('Username', 'Blog', 'Profile'), $tableRow);  
                         }  
                 }  
                 else{  
                         $output .= "<p>".t("You haven't specified any interests yet.")."</p>n";  
                 }  
   
                 //Do the selection of nodes where tags match  
                 $resultTypes = db_query("SELECT nt.type, nt.name FROM {node_type} nt");  
                 while ($row = db_fetch_array($resultTypes)){  
                         $result = db_query("SELECT i.counter, t.tid, t.name, n.nid, n.title FROM {interests} i, {term_data} t, {term_node} tn, {node} n WHERE n.nid = tn.nid AND tn.tid = t.tid AND i.tid = t.tid AND i.uid = '%s' AND n.type = '%s' GROUP BY n.nid ORDER BY i.counter desc, n.changed desc LIMIT 5", $user->uid, $row['type']);  
                         if (db_num_rows($result)){  
                                 $sectionTitle = $row['name'];  
                                 $output .= "<h2>$sectionTitle</h2>";  
                                 $output .= "<ul>";  
   
                                 while ($rowNodes = db_fetch_array($result)){  
                                         $output .= "<li>".l($rowNodes['title'], 'node/'.$rowNodes['nid'])."</li>";  
                                 }  
   
                                 $output .= "</ul>";  
                         }  
                 }  
   }  
         else{  
                 $output .= t("<br />You haven't specified any interests yet.");  
         }  
         return $output;  
   
 }  
   
 function _interests_user_suggestions(){  
         global $user;  
   
         if ($user->uid == 0){  
                 $output = t("This site uses interest tagging for authenticated users");  
         }  
         else{  
                 $result = db_query("SELECT i.counter AS count, t.tid, t.name, t.vid, t.weight FROM {interests} i, {term_data} t WHERE t.tid = i.tid AND i.uid = '%s' ORDER BY t.name DESC", $user->uid);  
                 $tags = tagadelic_build_weighted_tags($result, $steps = 6);  
                 $output = theme('tagadelic_weighted', $tags);  
         }  
         return $output;  
461  }  }
462    
463  /**  /**
464   * Implementation of hook_block().   * Implementation of hook_block().
465   */   */
466  function interests_block($op = 'list', $delta = 0, $edit = array()) {  function interests_block($op = 'list', $delta = 0, $edit = array()) {
467    switch ($op) {    switch ($op) {
468      case 'list':      case 'list':
469        $blocks[0]['info'] = t('Suggested Tags');        $blocks[0]['info'] = t('Interests terms tag block');
470          $blocks[0]['cache'] = BLOCK_NO_CACHE;
471        return $blocks;        return $blocks;
472                  case 'configure':      case 'configure':
473                          $form = array();        $form = array();
474                          return $form;        return $form;
475      case 'view': default:      case 'view':
476        switch ($delta) {        switch ($delta) {
477          case 0:          case 0:
478            return array('subject' => 'Suggested Tags', 'content' => _interests_user_suggestions());            $block = array(
479        }              'subject' => 'Your Interests',
480    }              'content' => _interests_user_suggestions()
481              );
482              return $block;
483          } // End delta switch
484      } // End op switch
485  }  }
   
 ?>  

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.2