'),
),
);
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' => '
'. t('Add') .'
',
'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'] = '
';
}
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:
To add a favorite, navigate to the page you want to add. Then fill in a title in the Favorites text box and click Add or press enter.
To add a favorite to another site, or a url you can\'t navigate to, use the following format to type the favorite into the text box: Title of favorite|url/of/favorite. 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: Example site|http://www.example.com. To add multiple favorites, use a semicolon separator, as in: Link 1|link/1;Link 2|link/2;Link 3...
To re-order favorites, drag the favorite link to the new location and drop it.
To delete a favorite, hover over the link until you see a white \'x\', then click the x.