2 // $Id: navigate_favorites.module,v 1.3.4.5 2008/11/08 19:03:04 stompeers Exp $
6 * Produces the Navigate Favorites widget
10 * Implementation of hook_init()
12 function navigate_favorites_init() {
13 if (user_access('navigate_favorites use')) {
14 drupal_add_js(drupal_get_path('module', 'navigate_favorites') .'/navigate_favorites.js', 'module', 'footer');
15 drupal_add_css(drupal_get_path('module', 'navigate_favorites') .'/navigate_favorites.css');
21 * Implementation of hook_navigation_widgets
23 function navigate_favorites_navigate_widgets($op, $settings = array()) {
26 switch ($settings['type']) {
28 return navigate_favorites_widget($settings['wid']);
36 'type' => 'favorites',
37 'module' => 'navigate_favorites',
38 'content' => navigate_add_widget_link('<div class="navigate-favorites-icon"></div>', 'navigate_favorites_load'),
43 navigate_favorites_delete_widget($settings['wid']);
50 * Delete a favorites widget
52 function navigate_favorites_delete_widget($wid) {
53 db_query("DELETE FROM {navigate_favorites} WHERE wid = '%d'", $wid);
58 * Generate favorites widget
60 function navigate_favorites_widget($wid) {
61 $settings = navigate_widget_settings_get($wid);
63 $inputs['favorite_name'] = navigate_input(array(
64 'name' => 'favorite_name',
65 'class' => 'navigate-favorite-name',
68 'callback' => 'navigate_favorites_add',
69 'help' => 'Type a description for this page and click enter to add it to your favorites.<br /><br />For advanced users, use the following format to add a group of links:<br /><strong>Title One|path/to/page;Title Two|path/to/page</strong>',
73 $inputs['favorite_button'] = navigate_callback_button(array(
74 'class' => 'navigate-favorites-add',
75 'callback' => 'navigate_favorites_add',
76 'content' => '<div class="navigate-favorites-add navigate-submit">'. t('Add') .'</div>',
77 'help' => 'Click to add favorite.',
80 $output = theme('navigate_favorites_widget', $inputs, $wid);
86 * Theme favorites widget
88 function theme_navigate_favorites_widget($inputs, $wid) {
89 $content['widget'] = '
90 <div class="navigate-shorten navigate-favorites-inputs">
91 <div class="navigate-favorites-input-outer">
92 '. $inputs['favorite_button'] .'
93 '. $inputs['favorite_name'] .'
96 <div class="navigate-favorites-list navigate-favorites-list-'. $wid .'">'. navigate_favorites_output($wid) .'</div>';
97 $content['title'] = t('Favorites');
104 * Implementation of hook_perm()
106 function navigate_favorites_perm() {
107 return array("navigate_favorites use");
112 * Implementation of hook_navigate_widget_process()
114 function navigate_favorites_navigate_widget_process($wid, $action) {
117 navigate_favorites_add();
120 navigate_favorites_remove();
123 navigate_favorites_sort();
132 function navigate_favorites_add() {
137 $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));
140 // Get path. If there is a | in the name, use the right-side as the path
141 $name = $_POST['name'];
142 $path = $_POST['return'];
143 if (strpos($_POST['name'], '|') !== FALSE) {
144 $items = explode(';', $_POST['name']);
145 foreach ($items as $item) {
146 $path_array = explode('|', $item);
147 $name = $path_array[0];
148 $path = $path_array[1];
149 db_query("INSERT INTO {navigate_favorites} (uid, wid, name, path, weight) VALUES (%d, %d, '%s', '%s', %d)", $user->uid, $_POST['wid'], $name, $path, $weight);
153 db_query("INSERT INTO {navigate_favorites} (uid, wid, name, path, weight) VALUES (%d, %d, '%s', '%s', %d)", $user->uid, $_POST['wid'], $name, $path, $weight);
156 $output = navigate_favorites_output($_POST['wid']);
160 function navigate_favorites_output($wid) {
162 $result = db_query("SELECT * FROM {navigate_favorites} WHERE wid = '%d' ORDER BY weight ASC", $wid);
163 while ($row = db_fetch_array($result)) {
165 <div id="navigate_favorites_id_'. $row['fav_id'] .'" class="navigate-favorites-link-outer">
166 <div class="navigate-favorites-delete">x<input type="hidden" class="navigate-favorites-id" value="'. $row['fav_id'] .'" /></div>
167 '. theme_navigate_link(array('title' => $row['name'], 'path' => $row['path'], 'wid' => $wid)) .'
177 function navigate_favorites_remove() {
179 db_query("DELETE FROM {navigate_favorites} WHERE uid = '%d' AND fav_id = '%d'", $user->uid, $_POST['fav_id']);
180 $output = navigate_favorites_output($_POST['wid']);
186 * Save the re-sorting of favorites
188 function navigate_favorites_sort() {
190 foreach ($_POST['navigate_favorites_id'] as $fav_id) {
191 db_query("UPDATE {navigate_favorites} SET weight = '%d' WHERE fav_id = '%d'", $i, $fav_id);
198 * Implementation of hook_user
200 function navigate_favorites_user($op, &$edit, &$account, $category='') {
203 db_query("DELETE FROM {navigate_favorites} WHERE uid = '%d'", $account->uid);
210 * Implementation of hook_navigate_help_page()
212 function navigate_favorites_navigate_help_page() {
213 $help['content'] = t('<p>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:</p>
215 <li><strong>To add a favorite</strong>, navigate to the page you want to add. Then fill in a title in the Favorites text box and click Add or press enter.</li>
216 <li><strong>To add a favorite to another site, or a url you can\'t navigate to</strong>, use the following format to type the favorite into the text box: <strong>Title of favorite|url/of/favorite</strong>. Note that that is a pipe character dividing the title and the url. For a url on your site, don\'t include a backslash at the beginning. For a url to another site, use the full url. For example: <strong>Example site|http://www.example.com</strong>. To add multiple favorites, use a semicolon separator, as in: Link 1|link/1;Link 2|link/2;Link 3...</li>
217 <li><strong>To re-order favorites</strong>, drag the favorite link to the new location and drop it.</li>
218 <li><strong>To delete a favorit</strong>e, hover over the link until you see a white \'x\', then click the x.</li>
221 $help['title'] = 'Favorites';
222 $help['access'] = user_access('navigate_favorites use');
228 * Implementation of hook_theme()
230 function navigate_favorites_theme() {
232 'navigate_favorites_widget' => array(
233 'arguments' => array('inputs' => NULL, 'wid' => NULL),