| 1 |
<?php
|
| 2 |
// $Id: token_weblinks.inc,v 1.1.2.6 2008/10/03 15:22:44 nancyw Exp $ */
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Token module support for the Weblinks module.
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Implementation of hook_token_list().
|
| 10 |
*/
|
| 11 |
function weblinks_token_list($type = 'all') {
|
| 12 |
$tokens = array();
|
| 13 |
if ($type == 'node' || $type == 'all') {
|
| 14 |
$tokens['node']['weight'] = t('The weight of the node.');
|
| 15 |
$tokens['node']['weblinks-url'] = t('The URL of the Web Link.');
|
| 16 |
$tokens['node']['weblinks-url-raw'] = t('Unfiltered URL of the Web Link. WARNING - raw user input.');
|
| 17 |
$tokens['node']['weblinks-title'] = t('The title of the Web Link.');
|
| 18 |
$tokens['node']['weblinks-title-raw'] = t('Unfiltered title of the Web Link. WARNING - raw user input.');
|
| 19 |
$tokens['node']['weblinks-click-count'] = t('How many times the Web Link has been clicked.');
|
| 20 |
$tokens['node']['weblinks-last-click'] = t('When the Web Link was last clicked on.');
|
| 21 |
$tokens['node']['weblinks-last-status'] = t('The status of the Web Link when it was last checked.');
|
| 22 |
$tokens['node']['weblinks-last-checked'] = t('The date/time when the Web Link was last checked.');
|
| 23 |
return $tokens;
|
| 24 |
}
|
| 25 |
}
|
| 26 |
|
| 27 |
/**
|
| 28 |
* Implementation of hook_token_values().
|
| 29 |
*/
|
| 30 |
function weblinks_token_values($type, $object = NULL, $options = array()) {
|
| 31 |
$tokens = array();
|
| 32 |
if ($type == 'node' && $object->type == 'weblinks') {
|
| 33 |
$tokens['weight'] = $object->weight;
|
| 34 |
$tokens['weblinks-url'] = decode_entities(check_plain($object->url));
|
| 35 |
$tokens['weblinks-url-raw'] = $object->url;
|
| 36 |
// Panels deletes the title (http://drupal.org/node/213751).
|
| 37 |
if (!isset($object->title)) {
|
| 38 |
$object->title = db_result(db_query("SELECT n.title FROM {node} n WHERE n.nid=%d", $object->nid));
|
| 39 |
}
|
| 40 |
$tokens['weblinks-title'] = decode_entities(check_plain($object->title));
|
| 41 |
$tokens['weblinks-title-raw'] = $object->title;
|
| 42 |
$tokens['weblinks-click-count'] = $object->click_count;
|
| 43 |
$tokens['weblinks-last-click'] = $object->last_click;
|
| 44 |
$tokens['weblinks-last-status'] = $object->last_status;
|
| 45 |
$tokens['weblinks-last-checked'] = $object->last_checked;
|
| 46 |
|
| 47 |
if (isset($object->last_click)) {
|
| 48 |
$tokens += _weblinks_token_date($object->last_click, 'clicked');
|
| 49 |
}
|
| 50 |
|
| 51 |
if (isset($object->last_checked)) {
|
| 52 |
$tokens += _weblinks_token_date($object->last_checked, 'checked');
|
| 53 |
}
|
| 54 |
|
| 55 |
return $tokens;
|
| 56 |
}
|
| 57 |
}
|
| 58 |
|
| 59 |
function _weblinks_token_date($date, $prefix = NULL) {
|
| 60 |
if ($prefix) {
|
| 61 |
$prefix .= '-';
|
| 62 |
}
|
| 63 |
$values = array(
|
| 64 |
$prefix .'small' => format_date($date, 'small'),
|
| 65 |
$prefix .'medium' => format_date($date, 'medium'),
|
| 66 |
$prefix .'large' => format_date($date, 'large'),
|
| 67 |
$prefix .'since' => $date ? format_interval(time() - $date) : t('Never'),
|
| 68 |
);
|
| 69 |
$date = (int)$date;
|
| 70 |
$values += array(
|
| 71 |
$prefix .'yyyy' => date('Y', $date),
|
| 72 |
$prefix .'yy' => date('y', $date),
|
| 73 |
$prefix .'month' => date('F', $date),
|
| 74 |
$prefix .'mon' => date('M', $date),
|
| 75 |
$prefix .'mm' => date('m', $date),
|
| 76 |
$prefix .'m' => date('n', $date),
|
| 77 |
$prefix .'ww' => date('W', $date),
|
| 78 |
$prefix .'date' => date('N', $date),
|
| 79 |
$prefix .'day' => date('l', $date),
|
| 80 |
$prefix .'ddd' => date('D', $date),
|
| 81 |
$prefix .'dd' => date('d', $date),
|
| 82 |
$prefix .'d' => date('j', $date),
|
| 83 |
$prefix .'hh' => date('h', $date),
|
| 84 |
$prefix .'mm' => date('i', $date),
|
| 85 |
$prefix .'ss' => date('d', $date),
|
| 86 |
);
|
| 87 |
|
| 88 |
return $values;
|
| 89 |
}
|