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

Diff of /contributions/modules/favorite_nodes/favorite_nodes.module

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

revision 1.8.2.12, Sat Apr 11 17:50:58 2009 UTC revision 1.8.2.13, Thu May 14 18:28:26 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: favorite_nodes.module,v 1.8.2.10 2009/03/28 16:19:49 kbahey Exp $  // $Id: favorite_nodes.module,v 1.8.2.12 2009/04/11 17:50:58 kbahey Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 80  function favorite_nodes_menu() { Line 80  function favorite_nodes_menu() {
80        'access arguments' => array(FAVORITE_NODES_PERM_VIEW),        'access arguments' => array(FAVORITE_NODES_PERM_VIEW),
81    );    );
82    
83    if ($user->uid && variable_get(FAVORITE_NODES_MENUS, 0)) {    if (variable_get(FAVORITE_NODES_MENUS, 0)) {
84      foreach (_node_types_natcasesort() as $type) {      foreach (_node_types_natcasesort() as $type) {
85        if (variable_get(FAVORITE_NODES_NODE_TYPE . $type->type, 0)) {        if (variable_get(FAVORITE_NODES_NODE_TYPE . $type->type, 0)) {
86          $items["favorites/view/$user->uid/$type->type"] = array(          $items["favorites/view/$type->type"] = array(
87              'title'            => t('Favorite @type', array('@type' => $type->name)),            'title'            => t('Favorite @type', array('@type' => $type->name)),
88              'page callback'    => 'favorite_nodes_view_page',            'page callback'    => 'favorite_nodes_view_page',
89              'type'             => MENU_NORMAL_ITEM,            'type'             => MENU_NORMAL_ITEM,
90              'access arguments' => array(FAVORITE_NODES_PERM_VIEW),            'access arguments' => array(FAVORITE_NODES_PERM_VIEW),
91          );          );
92        }        }
93      }      }
# Line 101  function favorite_nodes_menu() { Line 101  function favorite_nodes_menu() {
101  function favorite_nodes_theme() {  function favorite_nodes_theme() {
102    return array(    return array(
103      'favorite_nodes_view_table' => array(      'favorite_nodes_view_table' => array(
104        'arguments' => array('list' => array(), 'uid' => NULL, 'type' => NULL),        'arguments' => array('list' => array(), 'type' => NULL, 'uid' => NULL),
105      ),      ),
106      'favorite_nodes_view_teasers' => array(      'favorite_nodes_view_teasers' => array(
107        'arguments' => array('list' => array(), 'uid' => NULL, 'type' => NULL),        'arguments' => array('list' => array(), 'type' => NULL, 'uid' => NULL),
108      )      )
109    );    );
110  }  }
# Line 136  function _node_types_natcasesort() { Line 136  function _node_types_natcasesort() {
136  /**  /**
137   * Implementation of hook_user().   * Implementation of hook_user().
138   */   */
139  function favorite_nodes_user($op, &$edit, &$user, $category = NULL) {  function favorite_nodes_user($op, &$edit, &$account, $category = NULL) {
   
140    switch ($op) {    switch ($op) {
141      case 'view':      case 'view':
142        $fav_list = array();        $types = array();
143    
144        foreach (_node_types_natcasesort() as $type) {        foreach (_node_types_natcasesort() as $type) {
145            $types[$type->name] = $type->type;
146    
147          if (variable_get(FAVORITE_NODES_NODE_TYPE . $type->type, 0)) {          if (variable_get(FAVORITE_NODES_NODE_TYPE . $type->type, 0)) {
148            $uid = intval($user->uid);            $favorites[$type->name] = favorite_nodes_get($account->uid, $type->type, variable_get(FAVORITE_NODES_PROFILE_LIMIT, 5));
149            $favorites = favorite_nodes_get($uid, $type->type, variable_get(FAVORITE_NODES_PROFILE_LIMIT, 5));          }
150          }
151    
152          if (!empty($favorites)) {
153            $account->content['favorite_nodes_list'] = array(
154              '#type'  => 'user_profile_category',
155              '#title' => t('Favorites'),
156            );
157    
158            foreach($favorites as $type => $favorite) {
159            $items = array();            $items = array();
160            if (!empty($favorites)) {            foreach($favorite as $id => $object) {
161              $user->content['favorite_nodes_list'] = array(              $items[] = l($object->title, "node/$object->nid");
               '#type' => 'user_profile_category',  
               '#title' => t('Favorites'),  
             );  
             foreach ($favorites as $favorite) {  
               $items[] = l($favorite->title, "node/$favorite->nid");  
             }  
             $user->content['favorite_nodes_list']['Favorites'][$type->name] = array(  
               '#type' => 'user_profile_item',  
               '#title' => l($type->name, "favorite_nodes/view/$user->uid/$type->type"),  
               '#value' => theme('item_list', $items),  
             );  
162            }            }
163    
164              $account->content['favorite_nodes_list']['Favorites'][$type] = array(
165                '#type'  => 'user_profile_item',
166                '#title' => l($type, "favorite_nodes/view/" . $types[$type] . "/" . $account->uid),
167                '#value' => theme('item_list', $items),
168              );
169          }          }
170        }        }
171        break;        break;
172    
173      case 'delete':      case 'delete':
174        favorite_nodes_delete_favorites($user->uid);        favorite_nodes_delete_favorites($account->uid);
175        break;        break;
176    }    }
177  }  }
# Line 548  function favorite_nodes_delete_page() { Line 554  function favorite_nodes_delete_page() {
554   * Page to display a user's favorite list.   * Page to display a user's favorite list.
555   */   */
556  function favorite_nodes_view_page() {  function favorite_nodes_view_page() {
557    $uid  = arg(2);    global $user;
558    $type = arg(3);  
559    $output = theme('favorite_nodes_view_'. variable_get(FAVORITE_NODES_PAGE_TYPE, 'table'), favorite_nodes_get($uid, $type), $uid, $type);    $a2 = arg(2);
560    print theme('page', $output);    $a3 = arg(3);
561    
562      if (isset($a2)) {
563        // argument 2 is specified
564        if (is_numeric($a2)) {
565          // It is a number, so it is a user's uid
566          $uid = $a2;
567        }
568        else {
569          // It is not a number, so a node type
570          $type = $a2;
571          if (isset($a3)) {
572            // We have argument 2, it must be a uid
573            $uid = $a3;
574          }
575          else {
576            $uid = $user->uid;
577          }
578        }
579      }
580      else {
581        // No arguments specified
582        if ($user->uid) {
583          // Use the uid for the currently logged in user
584          $uid = $user->uid;
585        }
586        else {
587          return t('No favorites');
588        }
589      }
590    
591      return theme('favorite_nodes_view_'. variable_get(FAVORITE_NODES_PAGE_TYPE, 'table'), favorite_nodes_get($uid, $type), $uid, $type);
592  }  }
593    
594  /**  /**

Legend:
Removed from v.1.8.2.12  
changed lines
  Added in v.1.8.2.13

  ViewVC Help
Powered by ViewVC 1.1.2