You are here

function favorites_remove_favorite in Favorites 6

Same name and namespace in other branches
  1. 7.2 favorites.module \favorites_remove_favorite()
  2. 7 favorites.module \favorites_remove_favorite()

Deletes a favorite.

1 string reference to 'favorites_remove_favorite'
favorites_menu in ./favorites.module
Implements hook_menu().

File

./favorites.module, line 64
The favorites module allows users to bookmark any path within a site.

Code

function favorites_remove_favorite($favorite) {
  global $user;
  $access = user_access('manage own favorites') && $user->uid == $favorite->uid;

  // no admin page implemented yet! || user_access('manage all favorites');
  if ($access && drupal_valid_token($_GET['token'], $favorite->timestamp . $favorite->uid . $favorite->path)) {
    db_query("DELETE FROM {favorites} WHERE fid = %d", $favorite->fid);
    if ($_GET['js'] == 1) {
      drupal_json(array(
        'list' => favorites_list(),
      ));
      return;
    }
  }
  else {
    drupal_set_message(t('You do not have permission to remove this favorite.'), 'error');
  }

  // Unless this is an AJAX request, the query string contains the redirection page.
  if (!$_GET['js']) {
    drupal_goto();
  }
}