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

Diff of /contributions/modules/bookmarks2/bookmarks2.module

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

revision 1.8.4.4, Sat Jul 26 18:00:53 2008 UTC revision 1.8.4.5, Tue Aug 5 12:49:31 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: bookmarks2.module,v 1.8.4.3 2008/01/19 15:54:34 deekayen Exp $  // $Id: bookmarks2.module,v 1.8.4.4 2008/07/26 18:00:53 sanduhrs Exp $
3    
4  /**  /**
5   * @file   * @file
6   * Lets users keep bookmarks   * Lets users keep bookmarks
7   *   *
8   * @author David Kent Norman   * @author David Kent Norman
9     * Stefan Auditor <stefan.auditor@erdfisch.de>
10   * @link http://deekayen.net/   * @link http://deekayen.net/
11   * @todo There's some code/functionality duplication to eliminate   * @todo There's some code/functionality duplication to eliminate
12   *       Callbacks are underutilized   *       Callbacks are underutilized
# Line 13  Line 14 
14   *       password reminder re-encryption if users enter their old key with a new key   *       password reminder re-encryption if users enter their old key with a new key
15   */   */
16    
 /********************************************************************  
  * Drupal Hooks  
  ********************************************************************/  
   
 /**  
  * Implementation of hook_block().  
  */  
 function bookmarks2_block($op = 'list', $delta = 0) {  
   if ($op == 'list') {  
     $blocks[0]['info'] = t('User bookmarks');  
     return $blocks;  
   }  
   elseif ($op == 'view') {  
     switch ($delta) {  
       case 0:  
         return theme('bookmarks2_block');  
         break;  
     }  
     return $block;  
   }  
 }  
   
17  /**  /**
18   * Implementation of hook_help().   * Implementation of hook_help().
  *  
  * @param string $section  
  * @return string  
19   */   */
20  function bookmarks2_help($section) {  function bookmarks2_help($section) {
21    switch ($section) {    switch ($section) {
# Line 51  function bookmarks2_help($section) { Line 27  function bookmarks2_help($section) {
27    
28  /**  /**
29   * Implementation of hook_menu().   * Implementation of hook_menu().
  *  
  * @param bool $may_cache  
  * @return array  
30   */   */
31  function bookmarks2_menu($may_cache) {  function bookmarks2_menu($may_cache) {
32    global $user;    global $user;
33    $items = array();  
34    $access = user_access('access bookmarks2');    if ($may_cache) {
35        $items[] = array(
36    // Main menu item        'path' => 'bookmarks2',
37    $items[] = array('path' => "bookmarks2/$user->uid", 'title' => t('My bookmarks'),        'title' => t('My bookmarks'),
38                      'callback' => 'bookmarks2_page', 'access' => $access, 'type' => MENU_NORMAL_ITEM);        'callback' => 'bookmarks2_page',
39          'access' => user_access('access bookmarks2'),
40    // Top level tabs      );
41    $items[] = array('path' => "bookmarks2/$user->uid/overview", 'title' => t('list'),      $items[] = array(
42      'access' => $access, 'weight' => -10, 'type' => MENU_DEFAULT_LOCAL_TASK);        'path' => "bookmarks2/overview",
43    $items[] = array('path' => "bookmarks2/$user->uid/add", 'title' => t('add bookmark'),        'title' => t('List'),
44      'callback' => 'bookmarks2_page', 'access' => $access, 'weight' => 10,        'access' => user_access('access bookmarks2'),
45      'type' => MENU_LOCAL_TASK);        'weight' => -10,
46    $items[] = array('path' => "bookmarks2/$user->uid/delete", 'title' => t('delete bookmark'),        'type' => MENU_DEFAULT_LOCAL_TASK,
47      'callback' => 'bookmarks2_delete', 'access' => $access, 'type' => MENU_CALLBACK);      );
48    $items[] = array('path' => "bookmarks2/$user->uid/folders", 'title' => t('folders'),      $items[] = array(
49      'callback' => 'bookmarks2_page', 'access' => $access, 'weight' => 15,        'path' => "bookmarks2/add",
50      'type' => MENU_LOCAL_TASK);        'title' => t('Add bookmark'),
51    $items[] = array('path' => "bookmarks2/$user->uid/addfolder", 'title' => t('add folder'),        'callback' => 'drupal_get_form',
52      'callback' => 'bookmarks2_page', 'access' => $access, 'weight' => 20,        'callback arguments' => array('bookmarks2_form'),
53      'type' => MENU_LOCAL_TASK);        'access' => user_access('access bookmarks2'),
54    $items[] = array('path' => "bookmarks2/$user->uid/deletefolder", 'title' => t('delete folder'),        'weight' => 10,
55      'callback' => 'bookmarks2_folder_delete', 'access' => $access, 'type' => MENU_CALLBACK);        'type' => MENU_LOCAL_TASK,
56    $items[] = array('path' => "bookmarks2/$user->uid/config", 'title' => t('bookmark preferences'),      );
57      'callback' => 'bookmarks2_page', 'access' => $access, 'weight' => 25,      $items[] = array(
58      'type' => MENU_LOCAL_TASK);        'path' => "bookmarks2/delete",
59    $items[] = array('path' => "bookmarks2/$user->uid/rss.xml", 'title' => t('feed'),        'title' => t('Delete bookmark'),
60      'callback' => 'bookmarks2_feed', 'access' => $access,        'callback' => 'drupal_get_form',
61      'type' => MENU_CALLBACK);        'callback arguments' => 'bookmarks2_delete_confirm',
62    $items[] = array('path' => "admin/settings/bookmarks2", 'title' => t('Bookmarks Settings'),        'access' => user_access('access bookmarks2'),
63      'callback' => 'drupal_get_form', 'callback arguments' => array('bookmarks2_admin_settings'), 'access' => user_access("access administration pages"), 'weight' => 25,        'type' => MENU_CALLBACK,
64      'type' => MENU_NORMAL_ITEM);      );
65        $items[] = array(
66          'path' => "bookmarks2/folders",
67          'title' => t('Folders'),
68          'callback' => 'bookmarks2_folder_overview',
69          'access' => user_access('access bookmarks2'),
70          'weight' => 15,
71          'type' => MENU_LOCAL_TASK,
72        );
73        $items[] = array(
74          'path' => "bookmarks2/folder/add",
75          'title' => t('Add folder'),
76          'callback' => 'drupal_get_form',
77          'callback arguments' => array('bookmarks2_folder_form'),
78          'access' => user_access('access bookmarks2'),
79          'weight' => 20,
80          'type' => MENU_LOCAL_TASK,
81        );
82        $items[] = array(
83          'path' => "bookmarks2/folders/edit",
84          'title' => t('Edit folder'),
85          'callback' => 'drupal_get_form',
86          'callback arguments' => array('bookmarks2_folder_form'),
87          'access' => user_access('access bookmarks2'),
88          'weight' => 20,
89          'type' => MENU_LOCAL_TASK,
90        );
91        $items[] = array(
92          'path' => "bookmarks2/folder/delete",
93          'title' => t('Delete folder'),
94          'callback' => 'drupal_get_form',
95          'callback arguments' => array('bookmarks2_folder_delete_confirm'),
96          'access' => user_access('access bookmarks2'),
97          'type' => MENU_CALLBACK,
98        );
99        $items[] = array(
100          'path' => 'bookmarks2/edit',
101          'title' => t('Edit bookmark'),
102          'callback' => 'drupal_get_form',
103          'callback arguments' => array('bookmarks2_form'),
104          'access' => user_access('access bookmarks2'),
105          'type' => MENU_CALLBACK,
106        );
107        $items[] = array(
108          'path' => "bookmarks2/config",
109          'title' => t('Preferences'),
110          'callback' => 'drupal_get_form',
111          'callback arguments' => array('_bookmarks2_config'),
112          'access' => user_access('access bookmarks2'),
113          'weight' => 25,
114          'type' => MENU_LOCAL_TASK,
115        );
116        $items[] = array(
117          'path' => "admin/settings/bookmarks2",
118          'title' => t('Bookmarks settings'),
119          'callback' => 'drupal_get_form',
120          'callback arguments' => array('bookmarks2_admin_settings'),
121          'access' => user_access("access administration pages"),
122        );
123      }
124      else {
125        $items[] = array(
126          'path' => 'bookmarks2/'. $user->uid .'/rss.xml',
127          'title' => t('feed'),
128          'callback' => 'bookmarks2_feed',
129          'access' => user_access('access bookmarks2'),
130          'type' => MENU_CALLBACK,
131        );
132      }
133    
134    return $items;    return $items;
135  }  }
136    
137  /**  /**
138   * Implementation of hook_perm().   * Implementation of hook_block().
  *  
  * @return array  
139   */   */
140  function bookmarks2_perm() {  function bookmarks2_block($op = 'list', $delta = 0, $edit = array()) {
141    return array('access bookmarks2');    global $user;
142    
143      if ($op == 'list') {
144        $blocks[0] = array (
145          'info' => t('User bookmarks'),
146        );
147        return $blocks;
148      }
149      elseif ($op == 'view') {
150        switch ($delta) {
151          case 0:
152            if ($user->uid != 0 && user_access('access bookmarks2')) {
153              $block = array(
154                'subject' => t('My bookmarks'),
155                'content' => bookmarks2_block_1(),
156              );
157            }
158            break;
159        }
160        return $block;
161      }
162  }  }
163    
164  /**  /**
165   * Returns an user's bookmarks block.   * Returns an user's bookmarks block.
  *  
  * @return array the paramter to pass to the block function.  
166   */   */
167  function theme_bookmarks2_block() {  function bookmarks2_block_1() {
   
168    global $user;    global $user;
169    
170    // Do not let anonymous users have bookmarks, even if the admin decides this    $result = db_query('SELECT b.url, b.title, b.description, b.options FROM {bookmarks2} b WHERE b.uid = %d ORDER BY b.title', $user->uid);
171    if ($user->uid != 0 && user_access('access bookmarks2')) {    $bookmarks = array();
172      while ($data = db_fetch_object($result)) {
173      $result = db_query('SELECT b.url, b.title, b.description, b.options FROM {bookmarks2} b WHERE b.uid = %d ORDER BY b.title', $user->uid);      $bookmarks[] = '<div class="icon">'. theme('bookmarks2_delete', $data->url) .'</div>'. _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, true);
174      $bookmarks = array();    }
     while ($data = db_fetch_object($result)) {  
       $bookmarks[] = '<div class="icon">'. theme('bookmarks2_delete', $data->url) .'</div>'. _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, true);  
     }  
175    
176      // Print bookmarks list as an item list    $links = array(
177      $output = (count($bookmarks) ? theme('item_list', $bookmarks) : t('You have no bookmarks.'));      'bookmarks2_quick_link' => array(
178      $links = array(        'title' => t('Quick link'),
179        'bookmarks2_quick_link' => array(        'href' => "bookmarks2/add/quick",
180          'title' => t('quick link'),        'attributes' => array(
181          'href' => "bookmarks2/$user->uid/add/quick",          'title' => t('Bookmark the current page.'),
182          'attributes' => array(          'class' => 'bookmarks2_link',
           'title' => t('Bookmark the current page.'),  
           'class' => 'bookmarks2_link',  
         ),  
         'query' => 'title='. urlencode(drupal_get_title()),  
183        ),        ),
184        'bookmarks2_manage' => array(        'query' => 'title='. urlencode(drupal_get_title()),
185          'title' => t('manage'),      ),
186          'href' => "bookmarks2/$user->uid",      'bookmarks2_manage' => array(
187          'attributes' => array(        'title' => t('Manage'),
188            'title' => t('Manage your bookmarks.'),        'href' => 'bookmarks2',
189            'class' => 'bookmarks2_link',        'attributes' => array(
190          ),          'title' => t('Manage your bookmarks.'),
191            'class' => 'bookmarks2_link',
192        ),        ),
193      );      ),
194      $output .= '<div class="links">'. theme('links', $links) .'</div>';    );
195    
196      return array(    return theme('bookmarks2_block', $bookmarks, $links);
197        'subject' => t('%user\'s bookmarks', array('%user' => $user->name)),  }
       'content' => $output  
     );  
   }  
198    
199    // Not a logged in user or has no rights  /**
200    else {   * Implementation of hook_perm().
201      return FALSE;   */
202    }  function bookmarks2_perm() {
203      return array('administer bookmarks2', 'access bookmarks2');
204    }
205    
206    /**
207     * Theme the block
208     */
209    function theme_bookmarks2_block($items = array(), $links = array()) {
210      $output = (count($items) ? theme('item_list', $items) : t('You have no bookmarks.'));
211      $output .= '<div class="links">'. theme('links', $links) .'</div>';
212      return $output;
213  }  }
214    
215  /**  /**
216   * Returns a bookmarks delete icon.   * Returns a bookmarks delete icon.
  *  
  * @param string $bookmark_url  
  *   The URL of the page to remove  
  * @return string the delete icon to be emitted  
217   */   */
218  function theme_bookmarks2_delete($url) {  function theme_bookmarks2_delete($url) {
219      $query = 'url='. urlencode($url);
220      return l(theme('image', drupal_get_path('module', 'bookmarks2') .'/trash.gif', t('delete')), "bookmarks2/delete", array("title" => t("Delete this bookmark from your list.")), $query, NULL, FALSE, TRUE);
221    }
222    
223    /**
224     * The controller for managing bookmarks.  Callback happens via menu().
225     *
226     * @return string Completely themed HTML page.
227     */
228    function bookmarks2_page() {
229    global $user;    global $user;
230    
231    $query = 'url='. urlencode($url) .'&block=1';    // Generate overview
232    return l(theme('image', 'modules/bookmarks2/trash.gif', t('delete')), "bookmarks2/$user->uid/delete", array("title" => t("Delete this bookmark from your list.")), $query, NULL, FALSE, TRUE);    $output = bookmarks2_overview();
233    
234      // Add rss functionality
235      $feed_title = t("!user's bookmarks", array('!user' => $user->name));
236      $feed_url = url('bookmarks2/'. $user->uid .'/rss.xml');
237      drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="'. $feed_title .'" href="'. $feed_url .'" />');
238      $output .= theme('feed_icon', $feed_url, $feed_title);
239    
240      return $output;
241  }  }
242    
243  /**  /**
# Line 198  function bookmarks2_feed() { Line 270  function bookmarks2_feed() {
270  }  }
271    
272  /**  /**
  * The controller for managing bookmarks.  Callback happens via menu().  
  *  
  * @return string Completely themed HTML page.  
  */  
 function bookmarks2_page() {  
   global $user;  
   
   $edit = $_POST;  
   $op   = $_POST['op'];  
   
   switch (($op ? $op : arg(2))) {  
     case 'add':  
       $title = t('Create new bookmark');  
       if (arg(3) == 'quick') {  
         $edit = bookmarks2_load_quicklink();  
       }  
       elseif (arg(3) == 'weblink') {  
         $edit = bookmarks2_load_weblink(arg(4));  
       }  
       $output = drupal_get_form('bookmarks2_form', $edit);  
       break;  
   
     case 'edit':  
       $title = t('Edit bookmark');  
       $output = ($url = urldecode($_GET['url'])) ? drupal_get_form('bookmarks2_form', bookmarks2_load($url)) : drupal_set_message(t('Bookmark cannot be edited, because it is not in your list.'), 'error');  
       break;  
   
     case t('Save'):  
       $title = t('Bookmarks');  
       if (bookmarks2_validate($edit)) {  
         bookmarks2_save($edit);  
         drupal_goto("bookmarks2/$user->uid");  
       }  
       else {  
         $output = drupal_get_form('bookmarks2_form', $edit);  
       }  
       break;  
   
     case 'folders' :  
       $title = t('Bookmark folders');  
       $output = bookmarks2_folder_overview();  
       break;  
   
     case 'addfolder':  
       $title = t('Create new folder');  
       $output = drupal_get_form('bookmarks2_folder_form', $edit);  
       break;  
   
     case 'folderedit':  
       $title = t('Edit folder');  
       $output = ($fid = $_GET['fid']) ? drupal_get_form('bookmarks2_folder_form', _bookmarks2_folder_load($fid)) : drupal_set_message(t('Folder cannot be edited, because it is not in your list.'), 'error');  
       break;  
   
     case 'config':  
       $title = t('Configure bookmark preferences');  
       $output = drupal_get_form('_bookmarks2_config');  
       break;  
   
     case t('Save folder'):  
       $title = t('Folder');  
       _bookmarks2_folder_save($edit);  
       drupal_goto("bookmarks2/$user->uid/folders");  
       break;  
   
     case t('Save bookmark preferences'):  
       $title = t('Boomark preferences');  
       _bookmarks2_config_save($edit);  
       drupal_goto("bookmarks2/$user->uid");  
       break;  
   
     default:  
       $output = bookmarks2_overview();  
   }  
   
   $rss = '<link rel="alternate" type="application/rss+xml" title="'  
     . t("%user's bookmarks", array('%user' => $user->name))  
     .'" href="'. url(implode('/', array($_GET['q'], 'rss.xml'))) .'" />';  
   
   drupal_set_html_head($rss);  
   
   drupal_set_title($title);  
   print theme('page', $output);  
 }  
   
 /**  
273   * Confirmation screen to make sure user really wants to delete their bookmark   * Confirmation screen to make sure user really wants to delete their bookmark
  *  
  * @return string  
274   */   */
275  function bookmarks2_delete() {  function bookmarks2_delete_confirm(&$form_state = null, $url = NULL, $uid = NULL) {
276    global $user;    if (!$url) {
277        $url = check_plain($_GET['url']);
   if (!$_GET['url'] && $_GET['url'] != '0') {  
     drupal_set_message(t('Bookmark cannot be deleted, because no URL was specified.'), 'error');  
     return drupal_goto("bookmarks2/{$user->uid}");  
278    }    }
279    
280    return drupal_get_form('bookmarks2_delete_confirm', $_GET['url'], $user->uid);    $form['url'] = array(
281  }      '#type' => 'hidden',
282        '#value' => $url,
283      );
284  function bookmarks2_delete_confirm($url, $uid) {    return confirm_form($form, t('Are you sure you want to delete this bookmark?'), 'bookmarks2', NULL, t('Delete'));
   $form['url'] = array('#type' => 'hidden', '#value' => $url);  
   return confirm_form($form, t('Are you sure you want to delete this bookmark?'), "bookmarks2/{$uid}", '', t('Delete'), t('Cancel'));  
285  }  }
286    
   
287  /**  /**
288   * Actually deletes a bookmark after a confirmation on a previous screen   * Actually deletes a bookmark after a confirmation on a previous screen
  *  
  * @param string $form_id  
  * @param array $form_values  
  * @return string  
289   */   */
290  function bookmarks2_delete_confirm_submit($form_id, $form_values) {  function bookmarks2_delete_confirm_submit($form_id, $form_values) {
291    global $user;    global $user;
292    
293    db_query("DELETE FROM {bookmarks2} WHERE uid = %d AND url = '%s'", $user->uid, $form_values['url']);    db_query("DELETE FROM {bookmarks2} WHERE uid = %d AND url = '%s'", $user->uid, $form_state['values']['url']);
294    drupal_set_message(t('Deleted bookmark.'));    drupal_set_message(t('Deleted bookmark.'));
295    
296    return "bookmarks2/{$user->uid}";    drupal_goto('bookmarks2');
297  }  }
298    
299  /**  /**
# Line 326  function bookmarks2_delete_confirm_submi Line 301  function bookmarks2_delete_confirm_submi
301   *   *
302   * @todo name the folder in the question   * @todo name the folder in the question
303   */   */
304  function bookmarks2_folder_delete() {  function bookmarks2_folder_delete_confirm(&$form_state, $fid = NULL) {
305    global $user;    if (!$fid) {
306        $fid = (int) check_plain($_GET['fid']);
   if (!is_numeric($_GET['fid'])) {  
     drupal_set_message(t('Folder cannot be deleted, because no folder ID was specified.'), 'error');  
     return drupal_goto("bookmarks2/{$user->uid}");  
307    }    }
308    
309    return drupal_get_form('bookmarks2_folder_delete_confirm', $_GET['fid'], $user->uid);    $form['fid'] = array(
310  }      '#type' => 'hidden',
311        '#value' => $fid,
312      );
313  function bookmarks2_folder_delete_confirm($fid, $uid) {    return confirm_form($form, t('Are you sure you want to delete this folder?'), 'bookmarks2/folders', NULL, t('Delete'));
   $form['fid'] = array('#type' => 'hidden', '#value' => (int)$fid);  
   return confirm_form($form, t('Are you sure you want to delete this folder?'), "bookmarks2/{$uid}", '', t('Delete'), t('Cancel'));  
314  }  }
315    
316    
# Line 350  function bookmarks2_folder_delete_confir Line 320  function bookmarks2_folder_delete_confir
320   * @param int $fid   * @param int $fid
321   * @return string   * @return string
322   */   */
323  function bookmarks2_folder_delete_confirm_submit($form_id, $form_values, $fid = 0, $child = false) {  function bookmarks2_folder_delete_confirm_submit($form, &$form_state, $fid = 0, $child = false) {
324    global $user;    global $user;
325    
326    if ($child) {    if ($child) {
# Line 362  function bookmarks2_folder_delete_confir Line 332  function bookmarks2_folder_delete_confir
332      }      }
333    }    }
334    else {    else {
335      if (!is_numeric($form_values['fid'])) {      if (!is_numeric($form_state['values']['fid'])) {
336        drupal_set_message(t('Folder ID is not the correct format!', 'error'));        drupal_set_message(t('Folder ID is not the correct format!', 'error'));
337      }      }
338      else {      else {
339          db_query('DELETE FROM {bookmarks2} WHERE uid = %d AND fid = %d', $user->uid, $form_state['values']['fid']);
340        db_query('DELETE FROM {bookmarks2} WHERE uid = %d AND fid = %d', $user->uid, $form_values['fid']);        db_query('DELETE FROM {bookmarks2_folders} WHERE uid = %d AND fid = %d', $user->uid, $form_state['values']['fid']);
       db_query('DELETE FROM {bookmarks2_folders} WHERE uid = %d AND fid = %d', $user->uid, $form_values['fid']);  
       bookmarks2_folder_delete_confirm_submit(NULL, NULL, $form_values['fid'], true);  
341        drupal_set_message(t('Deleted bookmark folder.'));        drupal_set_message(t('Deleted bookmark folder.'));
342      }      }
343    
344      return "bookmarks2/{$user->uid}";      drupal_goto('bookmarks2/folders');
345    }    }
346  }  }
347    
348    /**
349     * Get a folder tree for the form select box
350     */
351  function _bookmarks2_folder_select_options() {  function _bookmarks2_folder_select_options() {
352    $folders = _bookmarks2_folder_child(true);    $folders = _bookmarks2_folder_child(true);
353    if ($edit != NULL) {    if ($edit != NULL) {
# Line 390  function _bookmarks2_folder_select_optio Line 361  function _bookmarks2_folder_select_optio
361    
362  /**  /**
363   * Bookmark creation and update form   * Bookmark creation and update form
  *  
  * @param array $edit  
  * @return string  
364   */   */
365  function bookmarks2_form($edit = null) {  function bookmarks2_form($edit = null) {
366      if (arg(2) == 'quick') {
367        $edit = bookmarks2_load_quicklink();
368      }
369      if (arg(1) == 'edit' && is_string($_GET['url'])) {
370        $edit = bookmarks2_load(check_plain($_GET['url']));
371      }
372    
373    $form['details'] = array(    $form['details'] = array(
374      '#type' => 'fieldset',      '#type' => 'fieldset',
375      '#title' => t('Bookmark details')      '#title' => t('Bookmark details')
# Line 491  function bookmarks2_form($edit = null) { Line 466  function bookmarks2_form($edit = null) {
466  }  }
467    
468  /**  /**
469     * Form validation
470     */
471    function bookmarks2_form_validate($form, &$form_state) {
472      if ((isset($form_state['values']['pword']) && $form_state['values']['pword'] == '') && (!isset($form_state['values']['key']) || !$form_state['values']['key'])) {
473        form_set_error('pword', t('You must supply your bookmark reminder key to encrypt the password for your login reminder.'));
474      }
475      elseif ($form_state['values']['key'] && !_bookmarks2_check_key($form_state['values']['key'])) {
476        form_set_error('key', t('The reminder key you supplied does not match the one on record.'));
477      }
478    }
479    
480    /**
481     * Form submit handler
482     */
483    function bookmarks2_form_submit($form_id, $form_values) {
484      global $user;
485    
486      $encrypted_pword = '';
487      $options = 0;
488      $options |= ($form_values['_blank']) ? $form_values['_blank'] : 0;
489    
490      if ($form_values['pword'] && $form_values['key']) {
491        $encrypted_pword = _bookmarks2_encrypt_pword($form_values['key'], $form_values['pword']);
492      }
493    
494      $form_values['old_url'] = urldecode($form_values['old_url']);
495      if ($form_values['old_url'] && db_result(db_query("SELECT COUNT(b.uid) FROM {bookmarks2} b WHERE b.uid = %d AND b.url = '%s'", $user->uid, $form_values['old_url']))) {
496        if (!$form_values['pword'] && !$form_values['key']) {
497          $encrypted_pword = db_result(db_query("SELECT pword FROM {bookmarks2} b WHERE b.uid = %d AND b.url = '%s'", $user->uid, $form_values['old_url']));
498        }
499        db_query("UPDATE {bookmarks2} SET fid = %d, title = '%s', url = '%s', description = '%s', uname = '%s', pword = '%s', options = %d WHERE uid = %d AND url = '%s'", $form_values['fid'], $form_values['title'], $form_values['url'], $form_values['description'], $form_values['uname'], $encrypted_pword, $options, $user->uid, $form_values['old_url']);
500        drupal_set_message(t('The bookmark has been updated.'));
501        drupal_goto('bookmarks2');
502      }
503      else {
504        db_query("INSERT INTO {bookmarks2} (uid, fid, url, title, description, uname, pword, options) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', %d)", $user->uid, $form_values['fid'], $form_values['url'], $form_values['title'], $form_values['description'], $form_values['uname'], $encrypted_pword, $options);
505        drupal_set_message(t('The link has been added to your bookmarks.'));
506      }
507    }
508    
509    /**
510   * Bookmark folder creation and update form   * Bookmark folder creation and update form
  *  
  * @param array $edit  
  * @return string  
511   */   */
512  function bookmarks2_folder_form($edit = null) {  function bookmarks2_folder_form($edit = null) {
513      if (arg(2) == 'edit' && is_numeric($_GET['fid'])) {
514        $edit = _bookmarks2_folder_load(check_plain($_GET['fid']));
515      }
516    
517    $form['details'] = array(    $form['details'] = array(
518      '#type' => 'fieldset',      '#type' => 'fieldset',
519      '#title' => t('Folder details')      '#title' => t('Folder details')
# Line 530  function bookmarks2_folder_form($edit = Line 547  function bookmarks2_folder_form($edit =
547  }  }
548    
549  /**  /**
550   * lets individuals set preferences for bookmarks in the bookmark preferences tab   * Update or save a bookmark folder
551   *   */
552   * @return string  function bookmarks2_folder_form_submit($form_id, $form_values) {
553      global $user;
554    
555      if (db_result(db_query("SELECT COUNT(fid) FROM {bookmarks2_folders} WHERE fid = %d AND uid = %d", $form_values['fid'], $user->uid))) {
556        db_query("UPDATE {bookmarks2_folders} SET fname = '%s', f_parent_id = %d WHERE uid = %d AND fid = %d", $form_values['fname'], $form_values['f_parent_id'], $user->uid, $form_values['fid']);
557        drupal_set_message(t('The folder has been updated.'));
558      }
559      else {
560        db_query("INSERT INTO {bookmarks2_folders} (uid, f_parent_id, fname) VALUES (%d, %d, '%s')", $user->uid, $form_values['f_parent_id'], $form_values['fname']);
561        drupal_set_message(t('The folder has been added to your bookmarks.'));
562      }
563    }
564    
565    /**
566     * Let individuals set preferences for bookmarks in the bookmark preferences tab
567   */   */
568  function _bookmarks2_config() {  function _bookmarks2_config() {
569    $form['link_display'] = array(    $form['link_display'] = array(
# Line 563  function _bookmarks2_config() { Line 594  function _bookmarks2_config() {
594    }    }
595    $form['submit'] = array(    $form['submit'] = array(
596      '#type' => 'submit',      '#type' => 'submit',
597      '#value' => 'Save bookmark preferences'      '#value' => 'Save preferences'
598    );    );
599    
600    return $form;    return $form;
# Line 571  function _bookmarks2_config() { Line 602  function _bookmarks2_config() {
602    
603  /**  /**
604   * Grabs a user's preferences for bookmarks from the database   * Grabs a user's preferences for bookmarks from the database
  *  
  * @param string $var  
  * @param mixed $default  
  * @return mixed  
605   */   */
606  function _bookmarks2_user_pref($var, $default) {  function _bookmarks2_user_pref($var, $default) {
607    static $options;    static $options;
# Line 590  function _bookmarks2_user_pref($var, $de Line 617  function _bookmarks2_user_pref($var, $de
617    
618  /**  /**
619   * Write prefs to db   * Write prefs to db
  *  
  * @see _bookmarks2_config()  
  * @param array $edit  
620   */   */
621  function _bookmarks2_config_save($edit) {  function _bookmarks2_config_submit($form_id, $form_values) {
622    global $user;    global $user;
623    
624    $options = 0;    $options = 0;
625    $options |= $edit['link_display'];    $options |= $form_values['link_display'];
626    $key = false;    $key = false;
627    $existing_key = _bookmarks2_fetch_key();    $existing_key = _bookmarks2_fetch_key();
628    
629    if ($existing_key && empty($edit['key'])) {    if ($existing_key && empty($form_values['key'])) {
630      $key = $existing_key;      $key = $existing_key;
631    }    }
632    elseif (!empty($edit['key'])) {    elseif (!empty($form_values['key'])) {
633      $key = _bookmarks2_hash_key($edit['key']);      $key = _bookmarks2_hash_key($form_values['key']);
634      db_query("UPDATE {bookmarks2} SET pword = '' WHERE uid = %d", $user->uid);      db_query("UPDATE {bookmarks2} SET pword = '' WHERE uid = %d", $user->uid);
635    }    }
636    
# Line 685  function bookmarks2_load_quicklink() { Line 709  function bookmarks2_load_quicklink() {
709  }  }
710    
711  /**  /**
  * Pulls a node title and weblink from the database for a given node number  
  *  
  * @param int $nid  
  * @return array  
  */  
 function bookmarks2_load_weblink($nid) {  
   return db_fetch_array(db_query('SELECT n.title, w.weblink url FROM {node} n, {weblink} w WHERE n.nid = w.nid AND n.nid = %d', $nid));  
 }  
   
 /**  
712   * Main bookmark list   * Main bookmark list
713   *   *
714   * @return string   * @return string
# Line 703  function bookmarks2_overview() { Line 717  function bookmarks2_overview() {
717    global $user;    global $user;
718    $key = isset($_POST['overview_key']) ? $_POST['overview_key'] : '';    $key = isset($_POST['overview_key']) ? $_POST['overview_key'] : '';
719    
   $output = '';  
   $header = array();  
720    $crypt_ok = _bookmarks2_crypt_ok() && variable_get('bookmarks2_login_reminder_enabled', 0);    $crypt_ok = _bookmarks2_crypt_ok() && variable_get('bookmarks2_login_reminder_enabled', 0);
721    $good_key = _bookmarks2_check_key($key);    $good_key = _bookmarks2_check_key($key);
722    if ($key && !$good_key) {    if ($key && !$good_key) {
# Line 712  function bookmarks2_overview() { Line 724  function bookmarks2_overview() {
724    }    }
725    $link_display = _bookmarks2_user_pref('link_display', 0);    $link_display = _bookmarks2_user_pref('link_display', 0);
726    
727    
728    
729    $header[] = array('data' => t('title'), 'field' => 'title', 'sort' => 'asc');    $header[] = array('data' => t('title'), 'field' => 'title', 'sort' => 'asc');
730    if (!$link_display) {    if (!$link_display) {
731      $header[] = array('data' => t('link'), 'field' => 'url');      $header[] = array('data' => t('link'), 'field' => 'url');
# Line 744  function bookmarks2_overview() { Line 758  function bookmarks2_overview() {
758  </div><input type="submit" name="op" value="'. t('Display password reminders') .'" class="form-submit" />  </div><input type="submit" name="op" value="'. t('Display password reminders') .'" class="form-submit" />
759  </fieldset></div></form>';  </fieldset></div></form>';
760      }      }
761    
762      $header[] = array('data' => t('username'), 'field' => 'uname');      $header[] = array('data' => t('username'), 'field' => 'uname');
763      $header[] = array('data' => t('password'), 'field' => 'pword');      $header[] = array('data' => t('password'), 'field' => 'pword');
764      if ($good_key) {      if ($good_key) {
# Line 754  function bookmarks2_overview() { Line 769  function bookmarks2_overview() {
769    }    }
770    $header[] = array('data' => t('operations'), 'colspan' => 2);    $header[] = array('data' => t('operations'), 'colspan' => 2);
771    
772    $result = db_query('SELECT b.url, b.title, b.description, b.uname, b.pword, b.options FROM {bookmarks2} b WHERE b.uid = '. db_escape_string($user->uid) .' AND b.fid = 0 '. tablesort_sql($header));    $result = db_query('SELECT b.url, b.title, b.description, b.uname, b.pword, b.options FROM {bookmarks2} b
773                            WHERE b.uid = %d AND b.fid = 0'. tablesort_sql($header), $user->uid);
774    
775    $rows = array();    $rows = array();
   
776    while ($data = db_fetch_object($result)) {    while ($data = db_fetch_object($result)) {
777      if ($crypt_ok) {      if ($crypt_ok) {
778        if (empty($data->pword)) {        if (empty($data->pword)) {
# Line 770  function bookmarks2_overview() { Line 785  function bookmarks2_overview() {
785          $decrypted_pword = '<em>'. t('hidden') .'</em>';          $decrypted_pword = '<em>'. t('hidden') .'</em>';
786        }        }
787        if ($link_display) {        if ($link_display) {
788          $rows[] = array(_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), $data->uname, $decrypted_pword, '&nbsp;'. l(t('edit'), "bookmarks2/$user->uid/edit", null, 'url='. urlencode($data->url)) .' '. l(t('delete'), "bookmarks2/$user->uid/delete", null, 'url='. urlencode($data->url)));          $rows[] = array(
789              _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display),
790              $data->uname,
791              $decrypted_pword,
792              l(t('edit'), "bookmarks2/edit", null, 'url='. urlencode($data->url)),
793              l(t('delete'), "bookmarks2/delete", null, 'url='. urlencode($data->url)),
794            );
795        }        }
796        else {        else {
797          $rows[] = array($data->title, _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), $data->uname, $decrypted_pword, '&nbsp;'. l(t('edit'), "bookmarks2/$user->uid/edit", null, 'url='. urlencode($data->url)) .' '. l(t('delete'), "bookmarks2/$user->uid/delete", null, 'url='. urlencode($data->url)));          $rows[] = array(
798              $data->title,
799              _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display),
800              $data->uname,
801              $decrypted_pword,
802              l(t('edit'), "bookmarks2/edit", null, 'url='. urlencode($data->url)),
803              l(t('delete'), "bookmarks2/delete", null, 'url='. urlencode($data->url)),
804            );
805        }        }
806      }      }
807      else {      else {
808        if ($link_display) {        if ($link_display) {
809          $rows[] = array(_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), '&nbsp;'. l(t('edit'), "bookmarks2/$user->uid/edit", null, 'url='. urlencode($data->url)) .' '. l(t('delete'), "bookmarks2/$user->uid/delete", null, 'url='. urlencode($data->url)));          $rows[] = array(
810              _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display),
811              l(t('edit'), "bookmarks2/edit", null, 'url='. urlencode($data->url)),
812              l(t('delete'), "bookmarks2/delete", null, 'url='. urlencode($data->url)),
813            );
814        }        }
815        else {        else {
816          $rows[] = array($data->title, _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), '&nbsp;'. l(t('edit'), "bookmarks2/$user->uid/edit", null, 'url='. urlencode($data->url)) .' '. l(t('delete'), "bookmarks2/$user->uid/delete", null, 'url='. urlencode($data->url)));          $rows[] = array(
817              $data->title,
818              _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display),
819              l(t('edit'), "bookmarks2/edit", null, 'url='. urlencode($data->url)),
820              l(t('delete'), "bookmarks2/delete", null, 'url='. urlencode($data->url)),
821            );
822        }        }
823    
824      }      }
825    }    }
826    
# Line 847  function _bookmarks2_overview_folders($l Line 885  function _bookmarks2_overview_folders($l
885              $decrypted_pword = '<em>'. t('hidden') .'</em>';              $decrypted_pword = '<em>'. t('hidden') .'</em>';
886            }            }
887            if ($link_display) {            if ($link_display) {
888              $rows[] = array(_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), $data->uname, $decrypted_pword, '&nbsp;'. l(t('edit'), "bookmarks2/$user->uid/edit", null, 'url='. urlencode($data->url)) .' '. l(t('delete'), "bookmarks2/$user->uid/delete", null, 'url='. urlencode($data->url)));              $rows[] = array(
889                  _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display),
890                  $data->uname,
891                  $decrypted_pword,
892                  l(t('edit'), "bookmarks2/edit", null, 'url='. urlencode($data->url)),
893                  l(t('delete'), "bookmarks2/delete", null, 'url='. urlencode($data->url)),
894                );
895            }            }
896            else {            else {
897              $rows[] = array($data->title, _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), $data->uname, $decrypted_pword, '&nbsp;'. l(t('edit'), "bookmarks2/$user->uid/edit", null, 'url='. urlencode($data->url)) .' '. l(t('delete'), "bookmarks2/$user->uid/delete", null, 'url='. urlencode($data->url)));              $rows[] = array(
898                  $data->title,
899                  _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display),
900                  $data->uname, $decrypted_pword,
901                  l(t('edit'), "bookmarks2/edit", null, 'url='. urlencode($data->url)),
902                  l(t('delete'), "bookmarks2/delete", null, 'url='. urlencode($data->url)),
903                );
904            }            }
905          }          }
906          else {          else {
907            if ($link_display) {            if ($link_display) {
908              $rows[] = array(_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), '&nbsp;'. l(t('edit'), "bookmarks2/$user->uid/edit", null, 'url='. urlencode($data->url)) .' '. l(t('delete'), "bookmarks2/$user->uid/delete", null, 'url='. urlencode($data->url)));              $rows[] = array(
909                  _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display),
910                  l(t('edit'), "bookmarks2/edit", null, 'url='. urlencode($data->url)),
911                  l(t('delete'), "bookmarks2/delete", null, 'url='. urlencode($data->url)),
912                );
913            }            }
914            else {            else {
915              $rows[] = array($data->title, _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), '&nbsp;'. l(t('edit'), "bookmarks2/$user->uid/edit", null, 'url='. urlencode($data->url)) .' '. l(t('delete'), "bookmarks2/$user->uid/delete", null, 'url='. urlencode($data->url)));              $rows[] = array(
916                  $data->title,
917                  _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display),
918                  l(t('edit'), "bookmarks2/edit", null, 'url='. urlencode($data->url)),
919                  l(t('delete'), "bookmarks2/delete", null, 'url='. urlencode($data->url)),
920                );
921            }            }
922          }          }
923        }        }
# Line 879  function bookmarks2_folder_overview() { Line 938  function bookmarks2_folder_overview() {
938    global $user;    global $user;
939    
940    $header = array(    $header = array(
941      array('data' => t('fname')),      array('data' => t('Name')),
942      array('data' => t('operations'), 'colspan' => 2)      array('data' => t('Operations'), 'colspan' => 2),
943    );    );
944    
945    $folders = _bookmarks2_folder_child();    $folders = _bookmarks2_folder_child();
946    
947    while (list($key, $value) = each($folders)) {    while (list($key, $value) = each($folders)) {
948      $fname = (strlen($value) > 50) ? substr($value, 0, 47) .'...' : $value;      $fname = (strlen($value) > 50) ? substr($value, 0, 47) .'...' : $value;
949      $rows[] = array($value, '&nbsp;'. l(t('edit'), "bookmarks2/$user->uid/folderedit", null, 'fid='. $key) .' '. l(t('delete'), "bookmarks2/$user->uid/deletefolder", null, 'fid='. $key));      $rows[] = array(
950          $value,
951          l(t('edit'), 'bookmarks2/folders/edit', null, 'fid='. $key),
952          l(t('delete'), 'bookmarks2/folder/delete', null, 'fid='. $key));
953    }    }
954    
955    $output .= (count($rows) == 0) ? t('You have no folders.') : theme('table', $header, $rows);    $output .= !count($rows) ? t('You have no folders.') : theme('table', $header, $rows);
956    return $output;    return $output;
957  }  }
958    
# Line 966  function bookmarks2_save($edit) { Line 1028  function bookmarks2_save($edit) {
1028  }  }
1029    
1030  /**  /**
  * Update or save a bookmark folder  
  *  
  * @param array $edit  
  */  
 function _bookmarks2_folder_save($edit) {  
   global $user;  
   
   if (db_result(db_query("SELECT COUNT(fid) FROM {bookmarks2_folders} WHERE fid = %d AND uid = %d", $edit['fid'], $user->uid))) {  
     db_query("UPDATE {bookmarks2_folders} SET fname = '%s', f_parent_id = %d WHERE uid = %d AND fid = %d", $edit['fname'], $edit['f_parent_id'], $user->uid, $edit['fid']);  
     drupal_set_message(t('The folder has been updated.'));  
   }  
   else {  
     db_query("INSERT INTO {bookmarks2_folders} (uid, f_parent_id, fname) VALUES (%d, %d, '%s')", $user->uid, $edit['f_parent_id'], $edit['fname']);  
     drupal_set_message(t('The folder has been added to your bookmarks.'));  
   }  
 }  
   
 /**  
1031   * Administration settings to turn on password reminder or not   * Administration settings to turn on password reminder or not
1032   *   *
1033   * @return array   * @return array
1034   */   */
1035  function bookmarks2_admin_settings() {  function bookmarks2_admin_settings() {
   $form = array();  
1036    $form['bookmarks2_link_crop_size'] = array(    $form['bookmarks2_link_crop_size'] = array(
1037      '#type' => 'textfield',      '#type' => 'textfield',
1038      '#title' => t('Link crop length'),      '#title' => t('Link crop length'),
# Line 1016  function bookmarks2_admin_settings() { Line 1059  function bookmarks2_admin_settings() {
1059  }  }
1060    
1061  /**  /**
  * Check form input for problems  
  *  
  * @param array $edit  
  * @return bool  
  */  
 function bookmarks2_validate($edit) {  
   $errors = array();  
   
   if (isset($edit['title']) && !$edit['title']) {  
     $errors['title'] = t('You must supply a title.');  
   }  
   if (isset($edit['url']) && !$edit['url']) {  
     $errors['url'] = t('You must supply an URL.');  
   }  
   if (isset($edit['pword']) && $edit['pword'] && (!isset($edit['key']) || !$edit['key'])) {  
     $errors['key'] = t('You must supply your bookmark reminder key to encrypt the password for your login reminder.');  
   }  
   elseif ($edit['key'] && !_bookmarks2_check_key($edit['key'])) {  
     $errors['key'] = t('The reminder key you supplied does not match the one on record.');  
   }  
   
   foreach ($errors as $name => $message) {  
     form_set_error($name, $message);  
   }  
   return count($errors) == 0;  
 }  
   
 /**  
1062   * Return a relative URI that Drupal can recognize internally.   * Return a relative URI that Drupal can recognize internally.
1063   *   *
1064   * @return string   * @return string

Legend:
Removed from v.1.8.4.4  
changed lines
  Added in v.1.8.4.5

  ViewVC Help
Powered by ViewVC 1.1.2