You are here

function notifications_token_values in Notifications 6.4

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

Implementation of hook_token_values()

@ TODO: Work out event tokens

File

./notifications.module, line 1257
Notifications module

Code

function notifications_token_values($type, $object = NULL, $options = array()) {
  $language = isset($options['language']) ? $options['language'] : $GLOBALS['language'];
  switch ($type) {
    case 'subscription':
      $values = array();

      // Tokens only for registered users
      if ($subscription = messaging_check_object($object, 'Notifications_Subscription')) {
        $values['subscription-unsubscribe-url'] = notifications_build_url('unsubscribe', 'subscription', $subscription, array(
          'language' => $language,
        ));
        $values['subscription-edit-url'] = notifications_build_url('edit', 'subscription', $subscription, array(
          'language' => $language,
        ));
        $values['subscription-type'] = $subscription
          ->get_type('name');
        $values['subscription-name'] = $subscription
          ->get_name();
        $values['subscription-description-short'] = $subscription
          ->format_short(FALSE);
        $values['subscription-description-long'] = $subscription
          ->format_long(FALSE);

        // Old token, populate it for old templates
        $values['unsubscribe-url'] = $values['subscription-unsubscribe-url'];
      }
      return $values;
    case 'user':

      // Only for registered users.
      if (($account = $object) && !empty($account->uid)) {

        // We have a real user, so we produce full links
        $values['subscriptions-manage'] = url("user/{$account->uid}/notifications", array(
          'absolute' => TRUE,
          'language' => $language,
        ));
        $values['unsubscribe-url-global'] = notifications_build_url('unsubscribe', 'user', $account, array(
          'language' => $language,
        ));
        if (module_exists('realname')) {
          $values['user-realname'] = $account->realname;
        }
        return $values;
      }
      break;
    case 'destination':

      // These are just for registered users. For anonymous, notifications_anonymous will do it
      if (($destination = messaging_check_object($object, 'Messaging_Destination')) && !empty($destination->uid)) {
        $values['destination-unsubscribe-url'] = notifications_build_url('unsubscribe', 'destination', $destination, array(
          'language' => $language,
        ));
        $values['destination-manage-url'] = notifications_build_url('manage', 'destination', $destination, array(
          'language' => $language,
        ));
        $values['destination-edit-url'] = notifications_build_url('edit', 'destination', $destination, array(
          'language' => $language,
        ));
        return $values;
      }
      break;
    case 'event':
      if ($event = messaging_check_object($object, 'Notifications_Event')) {
        $timezone = isset($options['timezone']) ? $options['timezone'] : variable_get('date_default_timezone', 0);
        $values['event-type-description'] = $event
          ->get_type('description');
        $values['event-date-small'] = format_date($event->created, 'small', '', $timezone, $language->language);
        $values['event-date-medium'] = format_date($event->created, 'medium', '', $timezone, $language->language);
        $values['event-date-large'] = format_date($event->created, 'large', '', $timezone, $language->language);
        return $values;
      }
      break;
  }
}