/[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.5.2.21, Mon Sep 29 16:46:15 2008 UTC revision 1.5.2.22, Sun Jan 4 02:39:24 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: favorite_nodes.module,v 1.5.2.20 2008/09/29 16:07:27 kbahey Exp $  // $Id: favorite_nodes.module,v 1.5.2.21 2008/09/29 16:46:15 kbahey Exp $
3    
4  define('FAVORITE_NODES_NODE_TYPE',         'favorite_nodes_node_type_');  define('FAVORITE_NODES_NODE_TYPE',         'favorite_nodes_node_type_');
5  define('FAVORITE_NODES_PERM_ADD',          'create favorite nodes');  define('FAVORITE_NODES_PERM_ADD',          'create favorite nodes');
# Line 13  define('FAVORITE_NODES_PROFILE_LIMIT', Line 13  define('FAVORITE_NODES_PROFILE_LIMIT',
13  define('FAVORITE_NODES_PAGE_TYPE',         'favorite_nodes_page_type');  define('FAVORITE_NODES_PAGE_TYPE',         'favorite_nodes_page_type');
14  define('FAVORITE_NODES_MENUS',             'favorite_nodes_menu');  define('FAVORITE_NODES_MENUS',             'favorite_nodes_menu');
15  define('FAVORITE_NODES_LIST_EMPTY_TITLES', 'favorite_nodes_list_empty_titles');  define('FAVORITE_NODES_LIST_EMPTY_TITLES', 'favorite_nodes_list_empty_titles');
16    define('FAVORITE_NODES_SHOWLINK',          'favorite_nodes_showlink');
17    
18  // View favorites in user info or in a menu_local_task of user page ?  // View favorites in user info or in a menu_local_task of user page ?
19  define('FAVORITE_NODES_VIEW_IN_PROFILE',   'favorite_nodes_view_in_profile');  define('FAVORITE_NODES_VIEW_IN_PROFILE',   'favorite_nodes_view_in_profile');
# Line 139  function _node_types_natcasesort() { Line 140  function _node_types_natcasesort() {
140  function favorite_nodes_user($op, &$edit, &$user, $category = null) {  function favorite_nodes_user($op, &$edit, &$user, $category = null) {
141    switch ($op) {    switch ($op) {
142      case 'view':      case 'view':
143        if (variable_get(FAVORITE_NODES_VIEW_IN_PROFILE, 1)) {        return theme('favorite_nodes_user_page', $user);
         $fav_list = array();  
         foreach (_node_types_natcasesort() as $type) {  
           if (variable_get(FAVORITE_NODES_NODE_TYPE . $type->type, 0)) {  
             $uid = intval($user->uid);  
             $favorites = favorite_nodes_get($uid, $type->type, variable_get(FAVORITE_NODES_BLOCK_LIMIT, 5));  
             $items = array();  
             if (!empty($favorites)) {  
               foreach ($favorites as $favorite) {  
                 $items[] = l($favorite->title, "node/$favorite->nid");  
               }  
             }  
             $fav_list[] = array(  
               'title' => l($type->name, "favorite_nodes/view/$user->uid/$type->type"),  
               'value' => theme('item_list', $items),  
             );  
           }  
         }  
         return array(t('Favorites') => $fav_list);  
       }  
144        break;        break;
145    
146      case 'delete':      case 'delete':
# Line 168  function favorite_nodes_user($op, &$edit Line 150  function favorite_nodes_user($op, &$edit
150  }  }
151    
152  /**  /**
153     * List of favorite enabled content types with favorites
154     */
155    function theme_favorite_nodes_user_page($account) {
156      $fav_list = array();
157      foreach (_node_types_natcasesort() as $type) {
158        if (variable_get(FAVORITE_NODES_NODE_TYPE . $type->type, 0)) {
159          $uid = intval($account->uid);
160          $favorites = favorite_nodes_get($uid, $type->type, variable_get(FAVORITE_NODES_BLOCK_LIMIT, 5));
161          $items = array();
162          if (!empty($favorites)) {
163            foreach ($favorites as $favorite) {
164              $items[] = l($favorite->title, "node/$favorite->nid");
165            }
166          }
167          $fav_list[] = array(
168            'title' => $items ? l($type->name, "favorite_nodes/view/$account->uid/$type->type") : $type->name,
169            'value' => theme('item_list', $items),
170          );
171        }
172      }
173      return array(t('Favorites') => $fav_list);
174    }
175    
176    /**
177   * Implementation of hook_nodeapi().   * Implementation of hook_nodeapi().
178   */   */
179  function favorite_nodes_nodeapi(&$node, $op, $teaser = null, $page = null) {  function favorite_nodes_nodeapi(&$node, $op, $teaser = null, $page = null) {
# Line 282  function favorite_nodes_block($op = 'lis Line 288  function favorite_nodes_block($op = 'lis
288  function favorite_nodes_link($type, $node = null, $teaser = false) {  function favorite_nodes_link($type, $node = null, $teaser = false) {
289    global $user;    global $user;
290    $links = array();    $links = array();
291    if ($type == 'node' && !$teaser) {    if ($type == 'node' && !$teaser && variable_get(FAVORITE_NODES_SHOWLINK, 1)) {
292      if (variable_get(FAVORITE_NODES_NODE_TYPE . $node->type, 0)) {      if (variable_get(FAVORITE_NODES_NODE_TYPE . $node->type, 0)) {
293        if (user_access(FAVORITE_NODES_PERM_ADD)) {        if (user_access(FAVORITE_NODES_PERM_ADD)) {
294          if (!_favorite_nodes_check($node->nid)) {          $links = theme('favorite_nodes_links', $node);
295            $links['favorite_nodes_add'] = array('title' => t('add to favorites'), 'href' => 'favorite_nodes/add/'. $node->nid, 'attributes' => array('class' => 'favorites add'));        }
296          }      }
297          else {    }
298            if (user_access(FAVORITE_NODES_PERM_VIEW)) {    return $links;
299              $links['favorite_nodes_in'] = array('title' => t('in favorites'));  }
300              $links['favorite_nodes_remove'] = array('title' => t('remove from favorites'), 'href' => 'favorite_nodes/delete/'. $node->nid, 'attributes' => array('class' => 'favorites remove'));  
301            }  /**
302     * Allow theming of links().
303     */
304    function theme_favorite_nodes_links($node) {
305      if (variable_get(FAVORITE_NODES_NODE_TYPE . $node->type, 0)) {
306        if (user_access(FAVORITE_NODES_PERM_ADD)) {
307          if (!_favorite_nodes_check($node->nid)) {
308            $links['favorite_nodes_add'] = array('title' => t('add to favorites'), 'href' => 'favorite_nodes/add/'. $node->nid, 'attributes' => array('class' => 'favorites add'));
309          }
310          else {
311            if (user_access(FAVORITE_NODES_PERM_VIEW)) {
312              $links['favorite_nodes_in'] = array('title' => t('in favorites'));
313              $links['favorite_nodes_remove'] = array('title' => t('remove from favorites'), 'href' => 'favorite_nodes/delete/'. $node->nid, 'attributes' => array('class' => 'favorites remove'));
314          }          }
315        }        }
316      }      }
# Line 360  function favorite_nodes_settings() { Line 378  function favorite_nodes_settings() {
378      '#description' => t('Whether to show a menu item in the navigation block for each node type?'),      '#description' => t('Whether to show a menu item in the navigation block for each node type?'),
379    );    );
380    
381      $form[$set][FAVORITE_NODES_SHOWLINK] = array(
382        '#type' => 'checkbox',
383        '#title' => t('Display Favorite Node options as links'),
384        '#return_value' => 1,
385        '#default_value' => variable_get(FAVORITE_NODES_SHOWLINK, 1),
386        '#description' => t('Whether to show link items in the node view?'),
387      );
388    
389    $set = 'types';    $set = 'types';
390    $form[$set] = array(    $form[$set] = array(
391      '#type' => 'fieldset',      '#type' => 'fieldset',

Legend:
Removed from v.1.5.2.21  
changed lines
  Added in v.1.5.2.22

  ViewVC Help
Powered by ViewVC 1.1.2