You are here

function _notifications_get_link in Notifications 6.4

Get notifications link from elements and params

Parameters

$elements: Array of path elements, not including the 'notifications' prefix

$params: Notifications link parameters as in notifications_build_link()

$options: Aditional parameters for the url() function

1 call to _notifications_get_link()
notifications_build_link in ./notifications.module
Return link array for notifications objects

File

./notifications.module, line 1599
Notifications module

Code

function _notifications_get_link($elements, $params = array()) {

  // Add some default values
  $params += array(
    'confirm' => TRUE,
    'signed' => FALSE,
    'destination' => FALSE,
    'query' => array(),
    'options' => array(),
  );
  if ($params['destination'] === TRUE) {
    $params['destination'] = $_GET['q'];
  }

  // Build query string using named parameters
  $query = $params['query'];
  if ($params['destination']) {
    $query['destination'] = $params['destination'];
  }

  // To skip the confirmation form, the link must be signed
  // Note tat the query string will be 'confirm=1' to skip confirmation form
  if (!$params['confirm']) {
    $query['confirm'] = 1;
    $params['signed'] = 1;
  }
  if ($params['signed']) {
    $query += array(
      'timestamp' => time(),
    );
    $query['signature'] = _notifications_signature($elements, $query);
  }

  // Build final link parameters
  $options = $params['options'];
  $options['query'] = $query;
  foreach (array(
    'absolute',
    'html',
    'language',
  ) as $name) {
    if (isset($params[$name])) {
      $options[$name] = $params[$name];
    }
  }
  return array(
    'href' => 'notifications/' . implode('/', $elements),
    'options' => $options,
  );
}