'favorites', 'module' => 'navigate_favorites', 'content' => navigate_add_widget_link('', 'navigate_favorites_load'), ), ); case 'delete': navigate_favorites_delete_widget($settings['wid']); break; } } /** * Delete a favorites widget */ function navigate_favorites_delete_widget($wid) { db_query("DELETE FROM {navigate_favorites} WHERE wid = '%d'", $wid); } /** * Generate favorites widget */ function navigate_favorites_widget($wid) { $settings = navigate_widget_settings_get($wid); $inputs['favorite_name'] = navigate_input(array( 'name' => 'favorite_name', 'class' => 'navigate-favorite-name', 'select_all' => TRUE, 'clear' => TRUE, 'callback' => 'navigate_favorites_add', 'help' => 'Type a description for this page and click enter to add it to your favorites.

For advanced users, use the following format to add a group of links:
Title One|path/to/page;Title Two|path/to/page', 'wid' => $wid, )); $inputs['favorite_button'] = navigate_callback_button(array( 'class' => 'navigate-favorites-add', 'callback' => 'navigate_favorites_add', 'content' => '', 'help' => 'Click to add favorite.', )); $output = theme('navigate_favorites_widget', $inputs, $wid); return $output; } /** * Theme favorites widget */ function theme_navigate_favorites_widget($inputs, $wid) { $content['widget'] = ' '; $content['title'] = t('Favorites'); return $content; } /** * Implementation of hook_perm() */ function navigate_favorites_perm() { return array("navigate_favorites use"); } /** * Implementation of hook_navigate_widget_process() */ function navigate_favorites_navigate_widget_process($wid, $action) { switch ($action) { case 'add': navigate_favorites_add(); break; case 'remove': navigate_favorites_remove(); break; case 'sort': navigate_favorites_sort(); break; } } /** * Add a new favorite */ function navigate_favorites_add() { global $user; // Get next weight $weight = db_result(db_query_range("SELECT weight FROM {navigate_favorites} WHERE uid = '%d' AND wid = '%d' ORDER BY weight DESC", $user->uid, $_POST['wid'], 0, 1)); $weight++; // Get path. If there is a | in the name, use the right-side as the path $name = $_POST['name']; $path = $_POST['return']; if (strpos($_POST['name'], '|') !== FALSE) { $items = explode(';', $_POST['name']); foreach ($items as $item) { $fav_id = db_next_id('{navigate_favorites}_fav_id'); $path_array = explode('|', $item); $name = $path_array[0]; $path = $path_array[1]; db_query("INSERT INTO {navigate_favorites} SET fav_id = '%d', uid = '%d', wid = '%d', name = '%s', path = '%s', weight = '%d'", $fav_id, $user->uid, $_POST['wid'], $name, $path, $weight); } } else { $fav_id = db_next_id('{navigate_favorites}_fav_id'); db_query("INSERT INTO {navigate_favorites} SET fav_id = '%d', uid = '%d', wid = '%d', name = '%s', path = '%s', weight = '%d'", $fav_id, $user->uid, $_POST['wid'], $name, $path, $weight); } $output = navigate_favorites_output($_POST['wid']); echo $output; } function navigate_favorites_output($wid) { $result = db_query("SELECT * FROM {navigate_favorites} WHERE wid = '%d' ORDER BY weight ASC", $wid); while ($row = db_fetch_array($result)) { $output .= ' '; } return $output; } /** * Remove a favorite */ function navigate_favorites_remove() { global $user; db_query("DELETE FROM {navigate_favorites} WHERE uid = '%d' AND fav_id = '%d'", $user->uid, $_POST['fav_id']); $output = navigate_favorites_output($_POST['wid']); echo $output; } /** * Save the re-sorting of favorites */ function navigate_favorites_sort() { $i = 1; foreach ($_POST['navigate_favorites_id'] as $fav_id) { db_query("UPDATE {navigate_favorites} SET weight = '%d' WHERE fav_id = '%d'", $i, $fav_id); $i++; } } /** * Implementation of hook_user */ function navigate_favorites_user($op, &$edit, &$account, $category='') { switch ($op) { case 'delete': db_query("DELETE * FROM {navigate_favorites} WHERE uid = '%d'", $account->uid); break; } } /** * Implementation of hook_navigate_help_page() */ function navigate_favorites_navigate_help_page() { $help['content'] = t('

The Favorites widget allows you to keep a shortlist of your favorite locations on the current Drupal site. Here\'s a quick list of functionality:

'); $help['title'] = 'Favorites'; $help['access'] = user_access('navigate_favorites use'); return $help; }