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

Legend:
Removed from v.1.6.2.1  
changed lines
  Added in v.1.6.2.2

  ViewVC Help
Powered by ViewVC 1.1.2