| 1 |
<?php |
<?php |
| 2 |
// $Id: bookmarks2.module,v 1.11 2007/12/21 12:15:25 sanduhrs Exp $ |
// $Id: bookmarks2.module,v 1.12 2008/07/26 18:04:16 sanduhrs Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 13 |
* 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 |
| 14 |
*/ |
*/ |
| 15 |
|
|
| 16 |
/******************************************************************** |
/** |
| 17 |
* Drupal Hooks |
* Implementation of hook_help(). |
| 18 |
********************************************************************/ |
*/ |
| 19 |
|
function bookmarks2_help($path, $arg) { |
| 20 |
|
switch ($path) { |
| 21 |
|
case 'user/bookmarks2': |
| 22 |
|
return t('A bookmark is a link to an address (URL) on the internet.'); |
| 23 |
|
break; |
| 24 |
|
} |
| 25 |
|
} |
| 26 |
|
|
| 27 |
|
/** |
| 28 |
|
* Implementation of hook_menu(). |
| 29 |
|
*/ |
| 30 |
|
function bookmarks2_menu() { |
| 31 |
|
$items['bookmarks2'] = array( |
| 32 |
|
'title' => 'My bookmarks', |
| 33 |
|
'page callback' => 'bookmarks2_page', |
| 34 |
|
'access arguments' => array('access bookmarks2'), |
| 35 |
|
); |
| 36 |
|
$items['bookmarks2/overview'] = array( |
| 37 |
|
'title' => t('List'), |
| 38 |
|
'access arguments' => array('access bookmarks2'), |
| 39 |
|
'weight' => -10, |
| 40 |
|
'type' => MENU_DEFAULT_LOCAL_TASK, |
| 41 |
|
); |
| 42 |
|
$items['bookmarks2/add'] = array( |
| 43 |
|
'title' => t('Add bookmark'), |
| 44 |
|
'page callback' => 'drupal_get_form', |
| 45 |
|
'page arguments' => array('bookmarks2_form'), |
| 46 |
|
'access arguments' => array('access bookmarks2'), |
| 47 |
|
'weight' => 10, |
| 48 |
|
'type' => MENU_LOCAL_TASK, |
| 49 |
|
); |
| 50 |
|
$items['bookmarks2/delete'] = array( |
| 51 |
|
'title' => t('Delete bookmark'), |
| 52 |
|
'page callback' => 'drupal_get_form', |
| 53 |
|
'page arguments' => array('bookmarks2_delete_confirm'), |
| 54 |
|
'access arguments' => array('access bookmarks2'), |
| 55 |
|
'type' => MENU_CALLBACK, |
| 56 |
|
); |
| 57 |
|
$items['bookmarks2/folders'] = array( |
| 58 |
|
'title' => t('Folders'), |
| 59 |
|
'page callback' => 'bookmarks2_folder_overview', |
| 60 |
|
'access arguments' => array('access bookmarks2'), |
| 61 |
|
'weight' => 15, |
| 62 |
|
'type' => MENU_LOCAL_TASK, |
| 63 |
|
); |
| 64 |
|
$items['bookmarks2/folder/add'] = array( |
| 65 |
|
'title' => t('Add folder'), |
| 66 |
|
'page callback' => 'drupal_get_form', |
| 67 |
|
'page arguments' => array('bookmarks2_folder_form'), |
| 68 |
|
'access arguments' => array('access bookmarks2'), |
| 69 |
|
'weight' => 20, |
| 70 |
|
'type' => MENU_LOCAL_TASK, |
| 71 |
|
); |
| 72 |
|
$items['bookmarks2/folders/edit'] = array( |
| 73 |
|
'title' => t('Edit folder'), |
| 74 |
|
'page callback' => 'drupal_get_form', |
| 75 |
|
'page arguments' => array('bookmarks2_folder_form'), |
| 76 |
|
'access arguments' => array('access bookmarks2'), |
| 77 |
|
'weight' => 20, |
| 78 |
|
'type' => MENU_LOCAL_TASK, |
| 79 |
|
); |
| 80 |
|
$items['bookmarks2/folder/delete'] = array( |
| 81 |
|
'title' => t('Delete folder'), |
| 82 |
|
'page callback' => 'drupal_get_form', |
| 83 |
|
'page arguments' => array('bookmarks2_folder_delete_confirm'), |
| 84 |
|
'access arguments' => array('access bookmarks2'), |
| 85 |
|
'type' => MENU_CALLBACK, |
| 86 |
|
); |
| 87 |
|
$items['bookmarks2/edit'] = array( |
| 88 |
|
'title' => t('Edit bookmark'), |
| 89 |
|
'page callback' => 'drupal_get_form', |
| 90 |
|
'page arguments' => array('bookmarks2_form'), |
| 91 |
|
'access arguments' => array('access bookmarks2'), |
| 92 |
|
'type' => MENU_CALLBACK, |
| 93 |
|
); |
| 94 |
|
$items['bookmarks2/config'] = array( |
| 95 |
|
'title' => t('Preferences'), |
| 96 |
|
'page callback' => 'drupal_get_form', |
| 97 |
|
'page arguments' => array('_bookmarks2_config'), |
| 98 |
|
'access arguments' => array('access bookmarks2'), |
| 99 |
|
'weight' => 25, |
| 100 |
|
'type' => MENU_LOCAL_TASK, |
| 101 |
|
); |
| 102 |
|
|
| 103 |
|
$items['bookmarks2/%/rss.xml'] = array( |
| 104 |
|
'title' => t('feed'), |
| 105 |
|
'page callback' => 'bookmarks2_feed', |
| 106 |
|
'page arguments' => array(1), |
| 107 |
|
'access arguments' => array('access bookmarks2'), |
| 108 |
|
'type' => MENU_CALLBACK, |
| 109 |
|
); |
| 110 |
|
$items['admin/settings/bookmarks2'] = array( |
| 111 |
|
'title' => t('Bookmarks Settings'), |
| 112 |
|
'page callback' => 'drupal_get_form', |
| 113 |
|
'page arguments' => array('bookmarks2_admin_settings'), |
| 114 |
|
'access arguments' => array('administer bookmarks2'), |
| 115 |
|
'description' => t('Change bookmarks settings.'), |
| 116 |
|
); |
| 117 |
|
|
| 118 |
|
return $items; |
| 119 |
|
} |
| 120 |
|
|
| 121 |
/** |
/** |
| 122 |
* Implementation of hook_block(). |
* Implementation of hook_block(). |
| 123 |
*/ |
*/ |
| 124 |
function bookmarks2_block($op = 'list', $delta = 0) { |
function bookmarks2_block($op = 'list', $delta = 0, $edit = array()) { |
| 125 |
|
global $user; |
| 126 |
|
|
| 127 |
if ($op == 'list') { |
if ($op == 'list') { |
| 128 |
$blocks[0]['info'] = t('User bookmarks'); |
$blocks[0] = array ( |
| 129 |
|
'info' => t('User bookmarks'), |
| 130 |
|
); |
| 131 |
return $blocks; |
return $blocks; |
| 132 |
} |
} |
| 133 |
elseif ($op == 'view') { |
elseif ($op == 'view') { |
| 134 |
switch ($delta) { |
switch ($delta) { |
| 135 |
case 0: |
case 0: |
| 136 |
return theme('bookmarks2_block'); |
if ($user->uid != 0 && user_access('access bookmarks2')) { |
| 137 |
|
$block = array( |
| 138 |
|
'subject' => t('My bookmarks'), |
| 139 |
|
'content' => bookmarks2_block_1(), |
| 140 |
|
); |
| 141 |
|
} |
| 142 |
break; |
break; |
| 143 |
} |
} |
| 144 |
return $block; |
return $block; |
| 146 |
} |
} |
| 147 |
|
|
| 148 |
/** |
/** |
| 149 |
* Implementation of hook_help(). |
* Returns an user's bookmarks block. |
|
* |
|
|
* @param string $section |
|
|
* @return string |
|
| 150 |
*/ |
*/ |
| 151 |
function bookmarks2_help($section) { |
function bookmarks2_block_1() { |
| 152 |
switch ($section) { |
global $user; |
| 153 |
case 'user/bookmarks2': |
|
| 154 |
return t('A bookmark is a link to an address (URL) on the internet.'); |
$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); |
| 155 |
break; |
$bookmarks = array(); |
| 156 |
|
while ($data = db_fetch_object($result)) { |
| 157 |
|
$bookmarks[] = '<div class="icon">'. theme('bookmarks2_delete', $data->url) .'</div>'. _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, true); |
| 158 |
} |
} |
|
} |
|
| 159 |
|
|
| 160 |
/** |
$links = array( |
| 161 |
* Implementation of hook_menu(). |
'bookmarks2_quick_link' => array( |
| 162 |
* |
'title' => t('Quick link'), |
| 163 |
* @param bool $may_cache |
'href' => "bookmarks2/add/quick", |
| 164 |
* @return array |
'attributes' => array( |
| 165 |
*/ |
'title' => t('Bookmark the current page.'), |
| 166 |
function bookmarks2_menu($may_cache) { |
'class' => 'bookmarks2_link', |
| 167 |
global $user; |
), |
| 168 |
$items = array(); |
'query' => 'title='. urlencode(drupal_get_title()), |
| 169 |
$access = user_access('access bookmarks2'); |
), |
| 170 |
|
'bookmarks2_manage' => array( |
| 171 |
|
'title' => t('Manage'), |
| 172 |
|
'href' => 'bookmarks2', |
| 173 |
|
'attributes' => array( |
| 174 |
|
'title' => t('Manage your bookmarks.'), |
| 175 |
|
'class' => 'bookmarks2_link', |
| 176 |
|
), |
| 177 |
|
), |
| 178 |
|
); |
| 179 |
|
|
| 180 |
// Main menu item |
return theme('bookmarks2_block', $bookmarks, $links); |
|
$items[] = array('path' => "bookmarks2/$user->uid", 'title' => t('My bookmarks'), |
|
|
'callback' => 'bookmarks2_page', 'access' => $access, 'type' => MENU_NORMAL_ITEM); |
|
|
|
|
|
// Top level tabs |
|
|
$items[] = array('path' => "bookmarks2/$user->uid/overview", 'title' => t('list'), |
|
|
'access' => $access, 'weight' => -10, 'type' => MENU_DEFAULT_LOCAL_TASK); |
|
|
$items[] = array('path' => "bookmarks2/$user->uid/add", 'title' => t('add bookmark'), |
|
|
'callback' => 'bookmarks2_page', 'access' => $access, 'weight' => 10, |
|
|
'type' => MENU_LOCAL_TASK); |
|
|
$items[] = array('path' => "bookmarks2/$user->uid/delete", 'title' => t('delete bookmark'), |
|
|
'callback' => 'bookmarks2_delete', 'access' => $access, 'type' => MENU_CALLBACK); |
|
|
$items[] = array('path' => "bookmarks2/$user->uid/folders", 'title' => t('folders'), |
|
|
'callback' => 'bookmarks2_page', 'access' => $access, 'weight' => 15, |
|
|
'type' => MENU_LOCAL_TASK); |
|
|
$items[] = array('path' => "bookmarks2/$user->uid/addfolder", 'title' => t('add folder'), |
|
|
'callback' => 'bookmarks2_page', 'access' => $access, 'weight' => 20, |
|
|
'type' => MENU_LOCAL_TASK); |
|
|
$items[] = array('path' => "bookmarks2/$user->uid/deletefolder", 'title' => t('delete folder'), |
|
|
'callback' => 'bookmarks2_folder_delete', 'access' => $access, 'type' => MENU_CALLBACK); |
|
|
$items[] = array('path' => "bookmarks2/$user->uid/config", 'title' => t('bookmark preferences'), |
|
|
'callback' => 'bookmarks2_page', 'access' => $access, 'weight' => 25, |
|
|
'type' => MENU_LOCAL_TASK); |
|
|
$items[] = array('path' => "bookmarks2/$user->uid/rss.xml", 'title' => t('feed'), |
|
|
'callback' => 'bookmarks2_feed', 'access' => $access, |
|
|
'type' => MENU_CALLBACK); |
|
|
$items[] = array('path' => "admin/settings/bookmarks2", 'title' => t('Bookmarks Settings'), |
|
|
'callback' => 'drupal_get_form', 'callback arguments' => array('bookmarks2_admin_settings'), 'access' => user_access("access administration pages"), 'weight' => 25, |
|
|
'type' => MENU_NORMAL_ITEM); |
|
|
return $items; |
|
| 181 |
} |
} |
| 182 |
|
|
| 183 |
/** |
/** |
| 184 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
|
* |
|
|
* @return array |
|
| 185 |
*/ |
*/ |
| 186 |
function bookmarks2_perm() { |
function bookmarks2_perm() { |
| 187 |
return array('access bookmarks2'); |
return array('administer bookmarks2', 'access bookmarks2'); |
| 188 |
} |
} |
| 189 |
|
|
| 190 |
/** |
/** |
| 191 |
* Returns an user's bookmarks block. |
* Implementation of hook_theme(). |
|
* |
|
|
* @return array the paramter to pass to the block function. |
|
| 192 |
*/ |
*/ |
| 193 |
function theme_bookmarks2_block() { |
function bookmarks2_theme($existing, $type, $theme, $path) { |
| 194 |
|
return array( |
| 195 |
global $user; |
'bookmarks2_block' => array( |
| 196 |
|
'arguments' => array(), |
| 197 |
// Do not let anonymous users have bookmarks, even if the admin decides this |
), |
| 198 |
if ($user->uid != 0 && user_access('access bookmarks2')) { |
'bookmarks2_delete' => array( |
| 199 |
|
'arguments' => array('url' => NULL), |
| 200 |
$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); |
), |
| 201 |
$bookmarks = array(); |
); |
| 202 |
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); |
|
|
} |
|
|
|
|
|
// Print bookmarks list as an item list |
|
|
$output = (count($bookmarks) ? theme('item_list', $bookmarks) : t('You have no bookmarks.')); |
|
|
$links = array( |
|
|
'bookmarks2_quick_link' => array( |
|
|
'title' => t('quick link'), |
|
|
'href' => "bookmarks2/$user->uid/add/quick", |
|
|
'attributes' => array( |
|
|
'title' => t('Bookmark the current page.'), |
|
|
'class' => 'bookmarks2_link', |
|
|
), |
|
|
'query' => 'title='. urlencode(drupal_get_title()), |
|
|
), |
|
|
'bookmarks2_manage' => array( |
|
|
'title' => t('manage'), |
|
|
'href' => "bookmarks2/$user->uid", |
|
|
'attributes' => array( |
|
|
'title' => t('Manage your bookmarks.'), |
|
|
'class' => 'bookmarks2_link', |
|
|
), |
|
|
), |
|
|
); |
|
|
$output .= '<div class="links">'. theme('links', $links) .'</div>'; |
|
|
|
|
|
return array( |
|
|
'subject' => t('%user\'s bookmarks', array('%user' => $user->name)), |
|
|
'content' => $output |
|
|
); |
|
|
} |
|
| 203 |
|
|
| 204 |
// Not a logged in user or has no rights |
/** |
| 205 |
else { |
* Theme the block |
| 206 |
return FALSE; |
*/ |
| 207 |
} |
function theme_bookmarks2_block($items = array(), $links = array()) { |
| 208 |
|
$output = (count($items) ? theme('item_list', $items) : t('You have no bookmarks.')); |
| 209 |
|
$output .= '<div class="links">'. theme('links', $links) .'</div>'; |
| 210 |
|
return $output; |
| 211 |
} |
} |
| 212 |
|
|
| 213 |
/** |
/** |
| 214 |
* 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 |
|
| 215 |
*/ |
*/ |
| 216 |
function theme_bookmarks2_delete($url) { |
function theme_bookmarks2_delete($url) { |
| 217 |
|
$query = 'url='. urlencode($url); |
| 218 |
|
return l(theme('image', drupal_get_path('module', 'bookmarks2') .'/trash.gif', t('delete')), "bookmarks2/delete", array('query' => $query, 'html' => TRUE)); |
| 219 |
|
} |
| 220 |
|
|
| 221 |
|
/** |
| 222 |
|
* The controller for managing bookmarks. Callback happens via menu(). |
| 223 |
|
* |
| 224 |
|
* @return string Completely themed HTML page. |
| 225 |
|
*/ |
| 226 |
|
function bookmarks2_page() { |
| 227 |
global $user; |
global $user; |
| 228 |
|
|
| 229 |
$query = 'url='. urlencode($url) .'&block=1'; |
// Generate overview |
| 230 |
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(); |
| 231 |
|
|
| 232 |
|
// Add rss functionality |
| 233 |
|
$feed_title = t("!user's bookmarks", array('!user' => $user->name)); |
| 234 |
|
$feed_url = url('bookmarks2/'. $user->uid .'/rss.xml'); |
| 235 |
|
drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="'. $feed_title .'" href="'. $feed_url .'" />'); |
| 236 |
|
$output .= theme('feed_icon', $feed_url, $feed_title); |
| 237 |
|
|
| 238 |
|
return $output; |
| 239 |
} |
} |
| 240 |
|
|
| 241 |
/** |
/** |
| 268 |
} |
} |
| 269 |
|
|
| 270 |
/** |
/** |
|
* 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); |
|
|
} |
|
|
|
|
|
/** |
|
| 271 |
* 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 |
|
| 272 |
*/ |
*/ |
| 273 |
function bookmarks2_delete() { |
function bookmarks2_delete_confirm(&$form_state = null, $url = NULL, $uid = NULL) { |
| 274 |
global $user; |
if (!$url) { |
| 275 |
|
$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}"); |
|
| 276 |
} |
} |
| 277 |
|
|
| 278 |
return drupal_get_form('bookmarks2_delete_confirm', $_GET['url'], $user->uid); |
$form['url'] = array( |
| 279 |
} |
'#type' => 'hidden', |
| 280 |
|
'#value' => $url, |
| 281 |
|
); |
| 282 |
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')); |
|
| 283 |
} |
} |
| 284 |
|
|
|
|
|
| 285 |
/** |
/** |
| 286 |
* Actually deletes a bookmark after a confirmation on a previous screen |
* Actually deletes a bookmark after a confirmation on a previous screen |
| 287 |
* |
* |
| 289 |
* @param array $form_values |
* @param array $form_values |
| 290 |
* @return string |
* @return string |
| 291 |
*/ |
*/ |
| 292 |
function bookmarks2_delete_confirm_submit($form_id, $form_values) { |
function bookmarks2_delete_confirm_submit($form, &$form_state) { |
| 293 |
global $user; |
global $user; |
| 294 |
|
|
| 295 |
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']); |
| 296 |
drupal_set_message(t('Deleted bookmark.')); |
drupal_set_message(t('Deleted bookmark.')); |
| 297 |
|
|
| 298 |
return "bookmarks2/{$user->uid}"; |
drupal_goto('bookmarks2'); |
| 299 |
} |
} |
| 300 |
|
|
| 301 |
/** |
/** |
| 303 |
* |
* |
| 304 |
* @todo name the folder in the question |
* @todo name the folder in the question |
| 305 |
*/ |
*/ |
| 306 |
function bookmarks2_folder_delete() { |
function bookmarks2_folder_delete_confirm(&$form_state, $fid = NULL) { |
| 307 |
global $user; |
if (!$fid) { |
| 308 |
|
$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}"); |
|
| 309 |
} |
} |
| 310 |
|
|
| 311 |
return drupal_get_form('bookmarks2_folder_delete_confirm', $_GET['fid'], $user->uid); |
$form['fid'] = array( |
| 312 |
} |
'#type' => 'hidden', |
| 313 |
|
'#value' => $fid, |
| 314 |
|
); |
| 315 |
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')); |
|
| 316 |
} |
} |
| 317 |
|
|
| 318 |
|
|
| 322 |
* @param int $fid |
* @param int $fid |
| 323 |
* @return string |
* @return string |
| 324 |
*/ |
*/ |
| 325 |
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) { |
| 326 |
|
//dprint_r($form_state); |
| 327 |
global $user; |
global $user; |
| 328 |
|
|
| 329 |
if ($child) { |
if ($child) { |
| 335 |
} |
} |
| 336 |
} |
} |
| 337 |
else { |
else { |
| 338 |
if (!is_numeric($form_values['fid'])) { |
if (!is_numeric($form_state['values']['fid'])) { |
| 339 |
drupal_set_message(t('Folder ID is not the correct format!', 'error')); |
drupal_set_message(t('Folder ID is not the correct format!', 'error')); |
| 340 |
} |
} |
| 341 |
else { |
else { |
| 342 |
|
db_query('DELETE FROM {bookmarks2} WHERE uid = %d AND fid = %d', $user->uid, $form_state['values']['fid']); |
| 343 |
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); |
|
| 344 |
drupal_set_message(t('Deleted bookmark folder.')); |
drupal_set_message(t('Deleted bookmark folder.')); |
| 345 |
} |
} |
| 346 |
|
|
| 347 |
return "bookmarks2/{$user->uid}"; |
drupal_goto('bookmarks2/folders'); |
| 348 |
} |
} |
| 349 |
} |
} |
| 350 |
|
|
| 351 |
|
/** |
| 352 |
|
* Get a folder tree |
| 353 |
|
*/ |
| 354 |
function _bookmarks2_folder_select_options() { |
function _bookmarks2_folder_select_options() { |
| 355 |
$folders = _bookmarks2_folder_child(true); |
$folders = _bookmarks2_folder_child(true); |
| 356 |
if ($edit != NULL) { |
if ($edit != NULL) { |
| 364 |
|
|
| 365 |
/** |
/** |
| 366 |
* Bookmark creation and update form |
* Bookmark creation and update form |
|
* |
|
|
* @param array $edit |
|
|
* @return string |
|
| 367 |
*/ |
*/ |
| 368 |
function bookmarks2_form($edit = null) { |
function bookmarks2_form(&$form_state) { |
| 369 |
|
if (arg(2) == 'quick') { |
| 370 |
|
$edit = bookmarks2_load_quicklink(); |
| 371 |
|
} |
| 372 |
|
if (arg(1) == 'edit' && is_string($_GET['url'])) { |
| 373 |
|
$edit = bookmarks2_load(check_plain($_GET['url'])); |
| 374 |
|
} |
| 375 |
|
|
| 376 |
$form['details'] = array( |
$form['details'] = array( |
| 377 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 378 |
'#title' => t('Bookmark details') |
'#title' => t('Bookmark details') |
| 469 |
} |
} |
| 470 |
|
|
| 471 |
/** |
/** |
| 472 |
|
* Form validation |
| 473 |
|
*/ |
| 474 |
|
function bookmarks2_form_validate($form, &$form_state) { |
| 475 |
|
if ((isset($form_state['values']['pword']) && $form_state['values']['pword'] == '') && (!isset($form_state['values']['key']) || !$form_state['values']['key'])) { |
| 476 |
|
form_set_error('pword', t('You must supply your bookmark reminder key to encrypt the password for your login reminder.')); |
| 477 |
|
} |
| 478 |
|
elseif ($form_state['values']['key'] && !_bookmarks2_check_key($form_state['values']['key'])) { |
| 479 |
|
form_set_error('key', t('The reminder key you supplied does not match the one on record.')); |
| 480 |
|
} |
| 481 |
|
} |
| 482 |
|
|
| 483 |
|
/** |
| 484 |
|
* Form submit handler |
| 485 |
|
*/ |
| 486 |
|
function bookmarks2_form_submit($form, &$form_state) { |
| 487 |
|
global $user; |
| 488 |
|
|
| 489 |
|
$encrypted_pword = ''; |
| 490 |
|
$options = 0; |
| 491 |
|
$options |= ($form_state['values']['_blank']) ? $form_state['values']['_blank'] : 0; |
| 492 |
|
|
| 493 |
|
if ($form_state['values']['pword'] && $form_state['values']['key']) { |
| 494 |
|
$encrypted_pword = _bookmarks2_encrypt_pword($form_state['values']['key'], $form_state['values']['pword']); |
| 495 |
|
} |
| 496 |
|
|
| 497 |
|
$form_state['values']['old_url'] = urldecode($form_state['values']['old_url']); |
| 498 |
|
if ($form_state['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_state['values']['old_url']))) { |
| 499 |
|
if (!$form_state['values']['pword'] && !$form_state['values']['key']) { |
| 500 |
|
$encrypted_pword = db_result(db_query("SELECT pword FROM {bookmarks2} b WHERE b.uid = %d AND b.url = '%s'", $user->uid, $form_state['values']['old_url'])); |
| 501 |
|
} |
| 502 |
|
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_state['values']['fid'], $form_state['values']['title'], $form_state['values']['url'], $form_state['values']['description'], $form_state['values']['uname'], $encrypted_pword, $options, $user->uid, $form_state['values']['old_url']); |
| 503 |
|
drupal_set_message(t('The bookmark has been updated.')); |
| 504 |
|
} |
| 505 |
|
else { |
| 506 |
|
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_state['values']['fid'], $form_state['values']['url'], $form_state['values']['title'], $form_state['values']['description'], $form_state['values']['uname'], $encrypted_pword, $options); |
| 507 |
|
drupal_set_message(t('The link has been added to your bookmarks.')); |
| 508 |
|
} |
| 509 |
|
} |
| 510 |
|
|
| 511 |
|
/** |
| 512 |
* Bookmark folder creation and update form |
* Bookmark folder creation and update form |
|
* |
|
|
* @param array $edit |
|
|
* @return string |
|
| 513 |
*/ |
*/ |
| 514 |
function bookmarks2_folder_form($edit = null) { |
function bookmarks2_folder_form($form_state) { |
| 515 |
|
if (arg(2) == 'edit' && is_numeric($_GET['fid'])) { |
| 516 |
|
$edit = _bookmarks2_folder_load(check_plain($_GET['fid'])); |
| 517 |
|
} |
| 518 |
|
|
| 519 |
$form['details'] = array( |
$form['details'] = array( |
| 520 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 521 |
'#title' => t('Folder details') |
'#title' => t('Folder details') |
| 549 |
} |
} |
| 550 |
|
|
| 551 |
/** |
/** |
| 552 |
* lets individuals set preferences for bookmarks in the bookmark preferences tab |
* Update or save a bookmark folder |
| 553 |
* |
*/ |
| 554 |
* @return string |
function bookmarks2_folder_form_submit($form, &$form_state) { |
| 555 |
|
global $user; |
| 556 |
|
|
| 557 |
|
if (db_result(db_query("SELECT COUNT(fid) FROM {bookmarks2_folders} WHERE fid = %d AND uid = %d", $form_state['values']['fid'], $user->uid))) { |
| 558 |
|
db_query("UPDATE {bookmarks2_folders} SET fname = '%s', f_parent_id = %d WHERE uid = %d AND fid = %d", $form_state['values']['fname'], $form_state['values']['f_parent_id'], $user->uid, $form_state['values']['fid']); |
| 559 |
|
drupal_set_message(t('The folder has been updated.')); |
| 560 |
|
} |
| 561 |
|
else { |
| 562 |
|
db_query("INSERT INTO {bookmarks2_folders} (uid, f_parent_id, fname) VALUES (%d, %d, '%s')", $user->uid, $form_state['values']['f_parent_id'], $form_state['values']['fname']); |
| 563 |
|
drupal_set_message(t('The folder has been added to your bookmarks.')); |
| 564 |
|
} |
| 565 |
|
} |
| 566 |
|
|
| 567 |
|
/** |
| 568 |
|
* Let individuals set preferences for bookmarks in the bookmark preferences tab |
| 569 |
*/ |
*/ |
| 570 |
function _bookmarks2_config() { |
function _bookmarks2_config() { |
| 571 |
$form['link_display'] = array( |
$form['link_display'] = array( |
| 596 |
} |
} |
| 597 |
$form['submit'] = array( |
$form['submit'] = array( |
| 598 |
'#type' => 'submit', |
'#type' => 'submit', |
| 599 |
'#value' => 'Save bookmark preferences' |
'#value' => 'Save preferences' |
| 600 |
); |
); |
| 601 |
|
|
| 602 |
return $form; |
return $form; |
| 604 |
|
|
| 605 |
/** |
/** |
| 606 |
* 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 |
|
| 607 |
*/ |
*/ |
| 608 |
function _bookmarks2_user_pref($var, $default) { |
function _bookmarks2_user_pref($var, $default) { |
| 609 |
static $options; |
static $options; |
| 619 |
|
|
| 620 |
/** |
/** |
| 621 |
* Write prefs to db |
* Write prefs to db |
|
* |
|
|
* @see _bookmarks2_config() |
|
|
* @param array $edit |
|
| 622 |
*/ |
*/ |
| 623 |
function _bookmarks2_config_save($edit) { |
function _bookmarks2_config_submit($form, &$form_state) { |
| 624 |
global $user; |
global $user; |
| 625 |
|
|
| 626 |
$options = 0; |
$options = 0; |
| 627 |
$options |= $edit['link_display']; |
$options |= $form_state['values']['link_display']; |
| 628 |
$key = false; |
$key = false; |
| 629 |
$existing_key = _bookmarks2_fetch_key(); |
$existing_key = _bookmarks2_fetch_key(); |
| 630 |
|
|
| 631 |
if ($existing_key && empty($edit['key'])) { |
if ($existing_key && empty($form_state['values']['key'])) { |
| 632 |
$key = $existing_key; |
$key = $existing_key; |
| 633 |
} |
} |
| 634 |
elseif (!empty($edit['key'])) { |
elseif (!empty($form_state['values']['key'])) { |
| 635 |
$key = _bookmarks2_hash_key($edit['key']); |
$key = _bookmarks2_hash_key($form_state['values']['key']); |
| 636 |
db_query("UPDATE {bookmarks2} SET pword = '' WHERE uid = %d", $user->uid); |
db_query("UPDATE {bookmarks2} SET pword = '' WHERE uid = %d", $user->uid); |
| 637 |
} |
} |
| 638 |
|
|
| 711 |
} |
} |
| 712 |
|
|
| 713 |
/** |
/** |
|
* 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)); |
|
|
} |
|
|
|
|
|
/** |
|
| 714 |
* Main bookmark list |
* Main bookmark list |
| 715 |
* |
* |
| 716 |
* @return string |
* @return string |
| 719 |
global $user; |
global $user; |
| 720 |
$key = isset($_POST['overview_key']) ? $_POST['overview_key'] : ''; |
$key = isset($_POST['overview_key']) ? $_POST['overview_key'] : ''; |
| 721 |
|
|
|
$output = ''; |
|
|
$header = array(); |
|
| 722 |
$crypt_ok = _bookmarks2_crypt_ok() && variable_get('bookmarks2_login_reminder_enabled', 0); |
$crypt_ok = _bookmarks2_crypt_ok() && variable_get('bookmarks2_login_reminder_enabled', 0); |
| 723 |
$good_key = _bookmarks2_check_key($key); |
$good_key = _bookmarks2_check_key($key); |
| 724 |
if ($key && !$good_key) { |
if ($key && !$good_key) { |
| 726 |
} |
} |
| 727 |
$link_display = _bookmarks2_user_pref('link_display', 0); |
$link_display = _bookmarks2_user_pref('link_display', 0); |
| 728 |
|
|
| 729 |
|
|
| 730 |
|
|
| 731 |
$header[] = array('data' => t('title'), 'field' => 'title', 'sort' => 'asc'); |
$header[] = array('data' => t('title'), 'field' => 'title', 'sort' => 'asc'); |
| 732 |
if (!$link_display) { |
if (!$link_display) { |
| 733 |
$header[] = array('data' => t('link'), 'field' => 'url'); |
$header[] = array('data' => t('link'), 'field' => 'url'); |
| 760 |
</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" /> |
| 761 |
</fieldset></div></form>'; |
</fieldset></div></form>'; |
| 762 |
} |
} |
| 763 |
|
|
| 764 |
$header[] = array('data' => t('username'), 'field' => 'uname'); |
$header[] = array('data' => t('username'), 'field' => 'uname'); |
| 765 |
$header[] = array('data' => t('password'), 'field' => 'pword'); |
$header[] = array('data' => t('password'), 'field' => 'pword'); |
| 766 |
if ($good_key) { |
if ($good_key) { |
| 771 |
} |
} |
| 772 |
$header[] = array('data' => t('operations'), 'colspan' => 2); |
$header[] = array('data' => t('operations'), 'colspan' => 2); |
| 773 |
|
|
| 774 |
$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 |
| 775 |
|
WHERE b.uid = %d AND b.fid = 0'. tablesort_sql($header), $user->uid); |
| 776 |
|
|
| 777 |
$rows = array(); |
$rows = array(); |
|
|
|
| 778 |
while ($data = db_fetch_object($result)) { |
while ($data = db_fetch_object($result)) { |
| 779 |
if ($crypt_ok) { |
if ($crypt_ok) { |
| 780 |
if (empty($data->pword)) { |
if (empty($data->pword)) { |
| 786 |
else { |
else { |
| 787 |
$decrypted_pword = '<em>'. t('hidden') .'</em>'; |
$decrypted_pword = '<em>'. t('hidden') .'</em>'; |
| 788 |
} |
} |
| 789 |
|
|
| 790 |
if ($link_display) { |
if ($link_display) { |
| 791 |
$rows[] = array(_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), $data->uname, $decrypted_pword, ' '. 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(_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), $data->uname, $decrypted_pword, ' '. l(t('edit'), "bookmarks2/$user->uid/edit", null, 'url='. urlencode($data->url)) .' '. l(t('delete'), "bookmarks2/$user->uid/delete", null, 'url='. urlencode($data->url))); |
| 792 |
} |
} |
| 793 |
else { |
else { |
| 794 |
$rows[] = array($data->title, _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), $data->uname, $decrypted_pword, ' '. 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($data->title, _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), $data->uname, $decrypted_pword, ' '. l(t('edit'), "bookmarks2/$user->uid/edit", null, 'url='. urlencode($data->url)) .' '. l(t('delete'), "bookmarks2/$user->uid/delete", null, 'url='. urlencode($data->url))); |
| 795 |
} |
} |
| 796 |
|
|
| 797 |
} |
} |
| 798 |
else { |
else { |
| 799 |
|
|
| 800 |
if ($link_display) { |
if ($link_display) { |
| 801 |
$rows[] = array(_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), ' '. 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( |
| 802 |
|
_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), |
| 803 |
|
l(t('edit'), "bookmarks2/edit", array('query' => 'url='. urlencode($data->url))), |
| 804 |
|
l(t('delete'), "bookmarks2/delete", array('query' => 'url='. urlencode($data->url))), |
| 805 |
|
); |
| 806 |
} |
} |
| 807 |
else { |
else { |
| 808 |
$rows[] = array($data->title, _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), ' '. 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( |
| 809 |
|
$data->title, |
| 810 |
|
_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), |
| 811 |
|
l(t('edit'), "bookmarks2/edit", array('query' => 'url='. urlencode($data->url))), |
| 812 |
|
l(t('delete'), "bookmarks2/delete", array('query' => 'url='. urlencode($data->url))), |
| 813 |
|
); |
| 814 |
} |
} |
| 815 |
|
|
| 816 |
} |
} |
| 817 |
} |
} |
| 818 |
|
|
| 830 |
* @param int $fid |
* @param int $fid |
| 831 |
* @return string |
* @return string |
| 832 |
*/ |
*/ |
| 833 |
function _bookmarks2_overview_folders($link_display, $fid = 0, $key = '', $crypt_ok = false, $good_key = false) { |
function _bookmarks2_overview_folders($form_state, $link_display, $fid = 0, $key = '', $crypt_ok = false, $good_key = false) { |
| 834 |
global $user; |
global $user; |
| 835 |
|
|
| 836 |
$form = array(); |
$form = array(); |
| 877 |
$decrypted_pword = '<em>'. t('hidden') .'</em>'; |
$decrypted_pword = '<em>'. t('hidden') .'</em>'; |
| 878 |
} |
} |
| 879 |
if ($link_display) { |
if ($link_display) { |
| 880 |
$rows[] = array(_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), $data->uname, $decrypted_pword, ' '. 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( |
| 881 |
|
_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), |
| 882 |
|
$data->uname, |
| 883 |
|
$decrypted_pword, |
| 884 |
|
l(t('edit'), "bookmarks2/edit", array('query' => 'url='. urlencode($data->url))), |
| 885 |
|
l(t('delete'), "bookmarks2/delete", array('query' => 'url='. urlencode($data->url))) |
| 886 |
|
); |
| 887 |
} |
} |
| 888 |
else { |
else { |
| 889 |
$rows[] = array($data->title, _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), $data->uname, $decrypted_pword, ' '. 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( |
| 890 |
|
$data->title, |
| 891 |
|
_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), |
| 892 |
|
$data->uname, |
| 893 |
|
$decrypted_pword, |
| 894 |
|
l(t('edit'), "bookmarks2/edit", array('query' => 'url='. urlencode($data->url))), |
| 895 |
|
l(t('delete'), "bookmarks2/delete", array('query' => 'url='. urlencode($data->url))) |
| 896 |
|
); |
| 897 |
} |
} |
| 898 |
} |
} |
| 899 |
else { |
else { |
| 900 |
if ($link_display) { |
if ($link_display) { |
| 901 |
$rows[] = array(_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), ' '. 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( |
| 902 |
|
_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), |
| 903 |
|
l(t('edit'), "bookmarks2/edit", array('query' => 'url='. urlencode($data->url))), |
| 904 |
|
l(t('delete'), "bookmarks2/delete", array('query' => 'url='. urlencode($data->url))) |
| 905 |
|
); |
| 906 |
} |
} |
| 907 |
else { |
else { |
| 908 |
$rows[] = array($data->title, _bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), ' '. 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 |
|
$data->title, |
| 910 |
|
_bookmarks2_get_link($data->url, $data->title, $data->description, $data->options, $link_display), |
| 911 |
|
l(t('edit'), "bookmarks2/edit", array('query' => 'url='. urlencode($data->url))), |
| 912 |
|
l(t('delete'), "bookmarks2/delete", array('query' => 'url='. urlencode($data->url))) |
| 913 |
|
); |
| 914 |
} |
} |
| 915 |
} |
} |
| 916 |
} |
} |
| 931 |
global $user; |
global $user; |
| 932 |
|
|
| 933 |
$header = array( |
$header = array( |
| 934 |
array('data' => t('fname')), |
array('data' => t('Name')), |
| 935 |
array('data' => t('operations'), 'colspan' => 2) |
array('data' => t('Operations'), 'colspan' => 2), |
| 936 |
); |
); |
| 937 |
|
|
| 938 |
$folders = _bookmarks2_folder_child(); |
$folders = _bookmarks2_folder_child(); |
| 939 |
|
|
| 940 |
while (list($key, $value) = each($folders)) { |
while (list($key, $value) = each($folders)) { |
| 941 |
$fname = (strlen($value) > 50) ? substr($value, 0, 47) .'...' : $value; |
$fname = (strlen($value) > 50) ? substr($value, 0, 47) .'...' : $value; |
| 942 |
$rows[] = array($value, ' '. l(t('edit'), "bookmarks2/$user->uid/folderedit", null, 'fid='. $key) .' '. l(t('delete'), "bookmarks2/$user->uid/deletefolder", null, 'fid='. $key)); |
$rows[] = array( |
| 943 |
|
$value, |
| 944 |
|
l(t('edit'), 'bookmarks2/folders/edit', array('query' => 'fid='. $key)), |
| 945 |
|
l(t('delete'), 'bookmarks2/folder/delete', array('query' => 'fid='. $key))); |
| 946 |
} |
} |
| 947 |
|
|
| 948 |
$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); |
| 949 |
return $output; |
return $output; |
| 950 |
} |
} |
| 951 |
|
|
| 1021 |
} |
} |
| 1022 |
|
|
| 1023 |
/** |
/** |
|
* 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.')); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
| 1024 |
* Administration settings to turn on password reminder or not |
* Administration settings to turn on password reminder or not |
| 1025 |
* |
* |
| 1026 |
* @return array |
* @return array |
| 1027 |
*/ |
*/ |
| 1028 |
function bookmarks2_admin_settings() { |
function bookmarks2_admin_settings() { |
|
$form = array(); |
|
| 1029 |
$form['bookmarks2_link_crop_size'] = array( |
$form['bookmarks2_link_crop_size'] = array( |
| 1030 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 1031 |
'#title' => t('Link crop length'), |
'#title' => t('Link crop length'), |
| 1052 |
} |
} |
| 1053 |
|
|
| 1054 |
/** |
/** |
|
* 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; |
|
|
} |
|
|
|
|
|
/** |
|
| 1055 |
* Return a relative URI that Drupal can recognize internally. |
* Return a relative URI that Drupal can recognize internally. |
| 1056 |
* |
* |
| 1057 |
* @return string |
* @return string |