| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: token.pages.inc,v 1.7.2.5 2010/08/10 03:33:32 davereid Exp $ 3 4 /** 5 * @file 6 * User page callbacks for the token module. 7 */ 8 9 /** 10 * For a given context, builds a formatted list of tokens and descriptions 11 * of their replacement values. 12 * 13 * @param types 14 * The token types to display documentation for. Can be either a single 15 * string or an array of token types. Defaults to 'all'. 16 * @param prefix 17 * The prefix your module will use when parsing tokens. Defaults to '[' 18 * @param suffix 19 * The suffix your module will use when parsing tokens. Defaults to ']' 20 * @return An HTML table containing the formatting docs. 21 */ 22 function theme_token_help($types = 'all', $prefix = TOKEN_PREFIX, $suffix = TOKEN_SUFFIX) { 23 token_include(); 24 $full_list = token_get_list($types); 25 26 $headers = array(t('Token'), t('Replacement value')); 27 $rows = array(); 28 foreach ($full_list as $key => $category) { 29 $rows[] = array(array('data' => drupal_ucfirst($key) .' '. t('tokens'), 'class' => 'region', 'colspan' => 2)); 30 foreach ($category as $token => $description) { 31 $row = array(); 32 $row[] = $prefix . $token . $suffix; 33 $row[] = $description; 34 $rows[] = $row; 35 } 36 } 37 38 $output = theme('table', $headers, $rows, array('class' => 'description')); 39 return $output; 40 } 41 42 /** 43 * Provide a 'tree' display of nested tokens. 44 */ 45 function theme_token_tree($token_types = array(), $global_types = TRUE, $click_insert = TRUE) { 46 //$info = token_get_list('all'); 47 $info = token_get_list($token_types); 48 49 if ($token_types == 'all') { 50 // $token_types = array('all'); 51 } 52 elseif ($global_types) { 53 // $token_types[] = 'global'; 54 // $token_types = array_unique($token_types); 55 } 56 else { 57 unset($info['global']); 58 } 59 60 // Check for token type validity and sort. 61 //$token_types = array_intersect($token_types, array_keys($info)); 62 $token_types = array_keys($info); 63 sort($token_types); 64 65 $header = array( 66 t('Token'), 67 t('Description'), 68 ); 69 $rows = array(); 70 71 foreach ($token_types as $type) { 72 $parent = NULL; 73 74 if (count($token_types) > 1) { 75 $rows[] = _token_token_tree_format_row($type, array(), TRUE); 76 $parent = $type; 77 } 78 79 foreach ($info[$type] as $token => $description) { 80 $rows[] = _token_token_tree_format_row("[$token]", array('description' => $description, 'parent' => $parent)); 81 } 82 } 83 84 if (count($rows)) { 85 drupal_add_js(drupal_get_path('module', 'token') . '/jquery.treeTable.js'); 86 drupal_add_css(drupal_get_path('module', 'token') . '/jquery.treeTable.css'); 87 drupal_add_js(drupal_get_path('module', 'token') . '/token.js'); 88 drupal_add_css(drupal_get_path('module', 'token') . '/token.css'); 89 } 90 else { 91 $rows[] = array(array( 92 'data' => t('No tokens available.'), 93 'colspan' => 2, 94 )); 95 } 96 97 $table_options = array( 98 'attributes' => array('class' => 'token-tree'), 99 'caption' => '', 100 ); 101 if ($click_insert) { 102 $table_options['caption'] = t('Click a token to insert it into the field you\'ve last clicked.'); 103 $table_options['attributes']['class'] .= ' token-click-insert'; 104 } 105 return theme('table', $header, $rows, $table_options['attributes'], $table_options['caption']); 106 } 107 108 /** 109 * Build a row in the token tree. 110 */ 111 function _token_token_tree_format_row($token, $token_info = array(), $is_group = FALSE) { 112 $row = array( 113 'id' => _token_clean_css_identifier($token), 114 'class' => array(), 115 'data' => array( 116 'token' => '', 117 'description' => !empty($token_info['description']) ? $token_info['description'] : '', 118 ), 119 ); 120 121 if ($is_group) { 122 // This is a token type/group. 123 $row['data']['token'] = drupal_ucfirst($token); 124 $row['class'][] = 'token-group'; 125 $row['id'] .= '-group'; 126 } 127 else { 128 // This is a token. 129 $row['data']['token'] = array( 130 'data' => $token, 131 'class' => 'token-key', 132 ); 133 if (!empty($token_info['parent'])) { 134 $row['class'][] = 'child-of-' . _token_clean_css_identifier($token_info['parent']) . '-group'; 135 } 136 } 137 138 $row['class'] = implode(' ', $row['class']); 139 140 return $row; 141 } 142 143 function _token_clean_css_identifier($id) { 144 return 'token-' . str_replace(array('][', '_', ' ', ':'), '-', trim($id, '[]')); 145 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |