source: sipei/modules/token/tokenSTARTER.module

drupal-6.x
Last change on this file was ffa4103, checked in by Luis Peña <lpena@…>, 12 años ago

Cambiando el nombre de modulos a modules

  • Propiedad mode establecida a 100755
File size: 2.3 KB
Línea 
1<?php
2
3
4/**
5 * @file
6 * The Token API module.
7 *
8 * The Token module provides an API for providing tokens to other modules.
9 * Tokens are small bits of text that can be placed into larger documents
10 * via simple placeholders, like %site-name or [user].
11 *
12 * @ingroup token
13 */
14
15/**
16 * Implementation of hook_token_list().
17 */
18function tokenSTARTER_token_list($type = 'all') {
19  $tokens = array();
20
21  if ($type == 'global' || $type == 'all') {
22    $tokens['global']['random-sha1']  = t("A randomly generated SHA1 hash.");
23    $tokens['global']['site-date-timestamp'] = t('The current timestamp in seconds past January 1, 1970.');
24    $tokens['global']['random-num-1'] = t('A randomly generated single-digit number.');
25    $tokens['global']['random-num-3'] = t('A randomly generated three-digit number.');
26    $tokens['global']['random-num-10'] = t('A randomly generated ten-digit number.');
27    $tokens['global']['random-alpha-1'] = t('Randomly generated single-digit letter.');
28    $tokens['global']['random-alpha-3'] = t('Randomly generated three-digit letters.');
29    $tokens['global']['random-alpha-10'] = t('Randomly generated ten-digit letters.');
30  }
31  if ($type == 'node' || $type == 'all') {
32    // Node tokens here.
33  }
34
35  return $tokens;
36}
37
38/**
39 * Implementation of hook_token_values().
40 */
41function tokenSTARTER_token_values($type, $object = NULL, $options = array()) {
42  $values = array();
43  switch ($type) {
44    case 'global':
45      $values['random-sha1']  = sha1(rand());
46      // Create random numbers.
47      $values['random-num-1'] = mt_rand(0, 9);
48      $values['random-num-3'] = mt_rand(100, 999);
49      $values['random-num-10'] = mt_rand(10000, 99999) . mt_rand(10000, 99999);
50      // Create random letters.
51      $letters = range('a', 'z');
52      $values['random-alpha-1'] = $letters[array_rand($letters, 1)];
53      shuffle($letters);
54      $values['random-alpha-3'] = implode('', array_slice($letters, 0, 3));
55      shuffle($letters);
56      $values['random-alpha-10'] = implode('', array_slice($letters, 0, 10));
57      // Create a UNIX timestamp token.
58      $time = time();
59      $tz = variable_get('date_default_timezone', 0);
60      $values['site-date-timestamp'] = format_date($time, 'custom', 'Y', $tz);
61
62      break;
63    case 'node':
64      // Node tokens here.
65      break;
66  }
67  return $values;
68}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.