You are here

function _favorites_save_favorite_cookie in Favorites 7

Same name and namespace in other branches
  1. 7.2 favorites.module \_favorites_save_favorite_cookie()

Helper function: Store a favorite as a cookie.

Used to abstract the storage model (cookie vs. db).

Parameters

$values: The sanitized values submitted by the user.

See also

favorites_add_favorite().

1 call to _favorites_save_favorite_cookie()
_favorites_save_favorite in ./favorites.module
Helper function: Store favorites for registered users.

File

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

Code

function _favorites_save_favorite_cookie($values) {

  // We need a unique ID for the cookie. In the DB storage,
  // the DB takes care of this with an auto increment value.
  // This is too much overhead in cookie storage, so
  // we will use an md5 hash as a unique ID.
  // The hash will be prefixed so on delete operations it is absolutely
  // clear whether to delete a cookie or a DB entry.
  $fid = 'c_' . md5($values['path'] . drupal_http_build_query(unserialize($values['query'])));
  $cookie_id = 'favorites_' . $fid;
  $cookie_data = serialize(array(
    'path' => $values['path'],
    'query' => $values['query'],
    'title' => $values['title'],
    'timestamp' => REQUEST_TIME,
  ));
  user_cookie_save(array(
    $cookie_id => $cookie_data,
  ));
  $_COOKIE['Drupal_visitor_' . $cookie_id] = $cookie_data;
}