array( 'navigate_favorites' => array( 'callback' => NULL, 'content' => 'Favorites', 'name' => 'Favorites', 'single' => FALSE, ), ) ); break; case 'delete': navigate_favorites_delete_widget($settings['wid']); break; case 'export': return navigate_favorites_export($settings['wid']); break; case 'import': navigate_favorites_import($settings['wid'], $settings['uid'], $settings['options']); break; } } /** * Export */ function navigate_favorites_export($wid) { $favorites = array(); $result = db_query("SELECT * FROM {navigate_favorites} WHERE wid = '%d'", $wid); while ($row = db_fetch_array($result)) { $favorites[] = array( 'name' => $row['name'], 'path' => $row['path'], 'weight' => $row['weight'], ); } return $favorites; } /** * Export as plain text */ function navigate_favorites_export_text($wid) { $favorites = array(); $result = db_query("SELECT * FROM {navigate_favorites} WHERE wid = '%d'", $wid); $divider = ''; $string = ''; while ($row = db_fetch_array($result)) { $string .= $divider . $row['name'] .'|'. $row['path'] .'|'. $row['weight']; $divider = '||'; } return $string; } /** * Import */ function navigate_favorites_import($wid, $uid, $options) { foreach ($options as $favorite) { db_query("INSERT INTO {navigate_favorites} (uid, wid, name, path, weight) VALUES (%d, %d, '%s', '%s', %d)", $uid, $wid, $favorite['name'], $favorite['path'], $favorite['weight']); } } /** * Full import from import field */ function navigate_favorites_import_full($wid) { global $user; db_query("DELETE FROM {navigate_favorites} WHERE wid = '%d'", $wid); if ($_POST['content'] != '') { $content = $_POST['content']; $favorites = explode('||', $_POST['content']); foreach ($favorites as $favorite) { $array = explode('|', $favorite); db_query("INSERT INTO {navigate_favorites} (uid, wid, name, path, weight) VALUES (%d, %d, '%s', '%s', %d)", $user->uid, $wid, $array[0], $array[1], $array[2]); } } $output = navigate_favorites_output($wid); echo $output; } /** * 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.', 'wid' => $wid, )); $inputs['export'] = navigate_textarea(array( 'name' => 'content', 'class' => 'navigate-favorites-export', 'filters' => 'true', 'submit' => 'Export', 'hide_filters' => 1, 'callback' => 'navigate_favorites_export', 'help' => 'Click the export button and it will load the content in this box.', 'wid' => $wid, )); $inputs['import'] = navigate_textarea(array( 'name' => 'content', 'class' => 'navigate-favorites-import', 'filters' => 'true', 'submit' => 'Import', 'hide_filters' => 1, 'callback' => 'navigate_favorites_import', 'help' => 'Click the import button to import favorites list. Note that this will repace your current list.', 'wid' => $wid, )); $output = theme('navigate_favorites_widget', $inputs, $wid); return $output; } /** * Theme favorites widget */ function theme_navigate_favorites_widget($inputs, $wid) { $content['widget'] = ''; if (user_access('navigate customize')) { $content['widget'] = ' '; } $sortable = ''; if (user_access('navigate customize')) { $sortable = ' navigate-favorites-list-sortable '; } $content['widget'] .= ' '; $content['title'] = t('Favorites'); $content['settings'] = ''; 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; case 'export': echo navigate_favorites_export_text($wid); die(); case 'import': navigate_favorites_import_full($wid); 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) { $path_array = explode('|', $item); $name = $path_array[0]; $path = $path_array[1]; db_query("INSERT INTO {navigate_favorites} (uid, wid, name, path, weight) VALUES (%d, %d, '%s', '%s', %d)", $user->uid, $_POST['wid'], $name, $path, $weight); } } else { db_query("INSERT INTO {navigate_favorites} (uid, wid, name, path, weight) VALUES (%d, %d, '%s', '%s', %d)", $user->uid, $_POST['wid'], $name, $path, $weight); } $output = navigate_favorites_output($_POST['wid']); echo $output; } function navigate_favorites_output($wid) { $output = ''; $result = db_query("SELECT * FROM {navigate_favorites} WHERE wid = '%d' ORDER BY weight ASC", $wid); while ($row = db_fetch_array($result)) { $delete = ''; if (user_access('navigate customize')) { $delete = ''; } $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; } /** * Implementation of hook_theme(). */ function navigate_favorites_theme() { return array( 'navigate_favorites_widget' => array( 'arguments' => array('inputs' => NULL, 'wid' => NULL), ), ); }