You are here

function notifications_token_values in Notifications 6.3

Same name and namespace in other branches
  1. 5 notifications.module \notifications_token_values()
  2. 6.4 notifications.module \notifications_token_values()
  3. 6 notifications.module \notifications_token_values()
  4. 6.2 notifications.module \notifications_token_values()

Implementation of hook_token_values()

@ TODO: Work out event tokens

File

./notifications.module, line 1214
Notifications module

Code

function notifications_token_values($type, $object = NULL, $options = array()) {
  $values = array();
  switch ($type) {
    case 'subscription':
      if ($subscription = $object) {
        $link = notifications_get_link('unsubscribe', array(
          'sid' => $subscription->sid,
          'signed' => TRUE,
          'absolute' => TRUE,
        ));
        $values['subscription-unsubscribe-url'] = url($link['href'], $link['options']);
      }
      break;
    case 'user':
      if (($account = $object) && !empty($object->uid)) {

        // We have a real user, so we produce full links
        $values['subscriptions-manage'] = url("user/{$account->uid}/notifications", array(
          'absolute' => TRUE,
        ));
        $link = notifications_get_link('unsubscribe', array(
          'uid' => $account->uid,
          'signed' => TRUE,
          'absolute' => TRUE,
        ));
        $values['unsubscribe-url'] = url($link['href'], $link['options']);
      }
      break;
    case 'event':
      if ($event = (object) $object) {
        $account = notifications_load_user($event->eid);
        $type = notifications_event_types($event->type, $event->action);
        $values['event-name'] = $type ? $type['description'] : '';
        $values['event-user'] = $account ? check_plain($account->name) : variable_get('user_anonymous', t('Anonymous'));
      }
      break;
  }
  return $values;
}