token.module 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  1. <?php
  2. /**
  3. * @file
  4. * Enhances the token API in core: adds a browseable UI, missing tokens, etc.
  5. */
  6. /**
  7. * The maximum depth for token tree recursion.
  8. */
  9. define('TOKEN_MAX_DEPTH', 9);
  10. /**
  11. * Implements hook_help().
  12. */
  13. function token_help($path, $arg) {
  14. if ($path == 'admin/help#token') {
  15. if (current_path() != 'admin/help/token') {
  16. // Because system_modules() executes hook_help() for each module to 'test'
  17. // if they will return anything, but not actually display it, we want to
  18. // return a TRUE value if this is not actually the help page.
  19. return TRUE;
  20. }
  21. $output = '<dl>';
  22. $output .= '<dt>' . t('List of the currently available tokens on this site') . '</dt>';
  23. $output .= '<dd>' . theme('token_tree', array('token_types' => 'all', 'click_insert' => FALSE, 'show_restricted' => TRUE)) . '</dd>';
  24. $output .= '</dl>';
  25. return $output;
  26. }
  27. }
  28. /**
  29. * Implements hook_system_info_alter().
  30. *
  31. * Prevent the token_actions module from being enabled since updates may have
  32. * left the old module files still in the directory.
  33. */
  34. function token_system_info_alter(&$info, $file, $type) {
  35. if ($type == 'module' && $file->name == 'token_actions') {
  36. $info['hidden'] = TRUE;
  37. }
  38. }
  39. /**
  40. * Return an array of the core modules supported by token.module.
  41. */
  42. function _token_core_supported_modules() {
  43. return array('book', 'field', 'menu', 'profile');
  44. }
  45. /**
  46. * Implements hook_menu().
  47. */
  48. function token_menu() {
  49. /*$items['token/autocomplete/all/%menu_tail'] = array(
  50. 'page callback' => 'token_autocomplete',
  51. 'access callback' => TRUE,
  52. 'type' => MENU_CALLBACK,
  53. 'file' => 'token.pages.inc',
  54. );*/
  55. $items['token/autocomplete/%token_type'] = array(
  56. 'page callback' => 'token_autocomplete_token',
  57. 'page arguments' => array(2),
  58. 'access callback' => TRUE,
  59. 'type' => MENU_CALLBACK,
  60. 'file' => 'token.pages.inc',
  61. );
  62. /*$items['token/autocomplete/%token_type/%menu_tail'] = array(
  63. 'page callback' => 'token_autocomplete_token',
  64. 'page arguments' => array(2, 3),
  65. 'access callback' => TRUE,
  66. 'type' => MENU_CALLBACK,
  67. 'file' => 'token.pages.inc',
  68. );*/
  69. $items['token/tree'] = array(
  70. 'page callback' => 'token_page_output_tree',
  71. 'access callback' => TRUE,
  72. 'type' => MENU_CALLBACK,
  73. 'file' => 'token.pages.inc',
  74. 'theme callback' => 'ajax_base_page_theme',
  75. );
  76. // Devel token pages.
  77. if (module_exists('devel')) {
  78. $items['node/%node/devel/token'] = array(
  79. 'title' => 'Tokens',
  80. 'page callback' => 'token_devel_token_object',
  81. 'page arguments' => array('node', 1),
  82. 'access arguments' => array('access devel information'),
  83. 'type' => MENU_LOCAL_TASK,
  84. 'file' => 'token.pages.inc',
  85. 'weight' => 5,
  86. );
  87. $items['comment/%comment/devel/token'] = array(
  88. 'title' => 'Tokens',
  89. 'page callback' => 'token_devel_token_object',
  90. 'page arguments' => array('comment', 1),
  91. 'access arguments' => array('access devel information'),
  92. 'type' => MENU_LOCAL_TASK,
  93. 'file' => 'token.pages.inc',
  94. 'weight' => 5,
  95. );
  96. $items['taxonomy/term/%taxonomy_term/devel/token'] = array(
  97. 'title' => 'Tokens',
  98. 'page callback' => 'token_devel_token_object',
  99. 'page arguments' => array('taxonomy_term', 2),
  100. 'access arguments' => array('access devel information'),
  101. 'type' => MENU_LOCAL_TASK,
  102. 'file' => 'token.pages.inc',
  103. 'weight' => 5,
  104. );
  105. $items['user/%user/devel/token'] = array(
  106. 'title' => 'Tokens',
  107. 'page callback' => 'token_devel_token_object',
  108. 'page arguments' => array('user', 1),
  109. 'access arguments' => array('access devel information'),
  110. 'type' => MENU_LOCAL_TASK,
  111. 'file' => 'token.pages.inc',
  112. 'weight' => 5,
  113. );
  114. }
  115. // Admin menu callback to clear token caches.
  116. $items['token/flush-cache'] = array(
  117. 'page callback' => 'token_flush_cache_callback',
  118. 'access arguments' => array('flush caches'),
  119. 'type' => MENU_CALLBACK,
  120. 'file' => 'token.pages.inc',
  121. );
  122. return $items;
  123. }
  124. /**
  125. * Implements hook_admin_menu_output_alter().
  126. */
  127. function token_admin_menu_output_alter(&$content) {
  128. $content['icon']['icon']['flush-cache']['token'] = array(
  129. '#title' => t('Token registry'),
  130. '#href' => 'token/flush-cache',
  131. '#options' => array(
  132. 'query' => drupal_get_destination() + array('token' => drupal_get_token('token/flush-cache')),
  133. ),
  134. );
  135. }
  136. function token_type_load($token_type) {
  137. $info = token_get_info();
  138. return isset($info['types'][$token_type]) ? $info['types'][$token_type] : FALSE;
  139. }
  140. /**
  141. * Implements hook_theme().
  142. */
  143. function token_theme() {
  144. $info['tree_table'] = array(
  145. 'variables' => array(
  146. 'header' => array(),
  147. 'rows' => array(),
  148. 'attributes' => array(),
  149. 'empty' => '',
  150. 'caption' => '',
  151. ),
  152. 'file' => 'token.pages.inc',
  153. );
  154. $info['token_tree'] = array(
  155. 'variables' => array(
  156. 'token_types' => array(),
  157. 'global_types' => TRUE,
  158. 'click_insert' => TRUE,
  159. 'show_restricted' => FALSE,
  160. 'recursion_limit' => 3,
  161. 'dialog' => FALSE,
  162. ),
  163. 'file' => 'token.pages.inc',
  164. );
  165. $info['token_tree_link'] = array(
  166. 'variables' => array(
  167. 'text' => NULL,
  168. 'options' => array(),
  169. 'dialog' => TRUE,
  170. ) + $info['token_tree']['variables'],
  171. 'file' => 'token.pages.inc',
  172. );
  173. return $info;
  174. }
  175. /**
  176. * Implements hook_library().
  177. */
  178. function token_library() {
  179. // jQuery treeTable plugin.
  180. $libraries['treeTable'] = array(
  181. 'title' => 'jQuery treeTable',
  182. 'website' => 'http://plugins.jquery.com/project/treetable',
  183. 'version' => '2.3.0',
  184. 'js' => array(
  185. drupal_get_path('module', 'token') . '/jquery.treeTable.js' => array(),
  186. ),
  187. 'css' => array(
  188. drupal_get_path('module', 'token') . '/jquery.treeTable.css' => array(),
  189. ),
  190. );
  191. $libraries['dialog'] = array(
  192. 'title' => 'Token dialog',
  193. 'version' => '1.0',
  194. 'js' => array(
  195. drupal_get_path('module', 'token') . '/token.js' => array(),
  196. ),
  197. 'dependencies' => array(
  198. array('system', 'ui.dialog'),
  199. ),
  200. );
  201. return $libraries;
  202. }
  203. /**
  204. * Implements hook_form_alter().
  205. *
  206. * Adds a submit handler to forms which could affect the tokens available on
  207. * the site.
  208. */
  209. function token_form_alter(&$form, $form_state, $form_id) {
  210. switch ($form_id) {
  211. // Profile field forms.
  212. case 'profile_field_form':
  213. case 'profile_field_delete':
  214. // User picture form.
  215. case 'user_admin_settings':
  216. // System date type form.
  217. // @todo Remove when http://drupal.org/node/1173706 is fixed.
  218. case 'system_add_date_format_type_form':
  219. case 'system_delete_date_format_type_form':
  220. $form += array('#submit' => array());
  221. array_unshift($form['#submit'], 'token_clear_cache');
  222. break;
  223. }
  224. }
  225. /**
  226. * Implements hook_block_view_alter().
  227. */
  228. function token_block_view_alter(&$data, $block) {
  229. if (!empty($block->title) && $block->title != '<none>') {
  230. // Perform unsanitized token replacement since _block_render_blocks() will
  231. // call check_plain() on $block->title.
  232. $block->title = token_replace($block->title, array(), array('sanitize' => FALSE));
  233. }
  234. }
  235. /**
  236. * Implements hook_form_FORM_ID_alter().
  237. */
  238. function token_form_block_add_block_form_alter(&$form, $form_state) {
  239. token_form_block_admin_configure_alter($form, $form_state);
  240. }
  241. /**
  242. * Implements hook_form_FORM_ID_alter().
  243. */
  244. function token_form_block_admin_configure_alter(&$form, $form_state) {
  245. $form['settings']['title']['#description'] .= ' ' . t('This field supports tokens.');
  246. // @todo Figure out why this token validation does not seem to be working here.
  247. $form['settings']['title']['#element_validate'][] = 'token_element_validate';
  248. $form['settings']['title'] += array('#token_types' => array());
  249. }
  250. /**
  251. * Implements hook_widget_form_alter().
  252. */
  253. function token_field_widget_form_alter(&$element, &$form_state, $context) {
  254. if (!empty($element['#description']) && !empty($context['instance']['description'])) {
  255. $element['#description'] = filter_xss_admin(token_replace($context['instance']['description']));
  256. }
  257. }
  258. /**
  259. * Implements hook_field_info_alter().
  260. */
  261. function token_field_info_alter(&$info) {
  262. $defaults = array(
  263. 'taxonomy_term_reference' => 'taxonomy_term_reference_plain',
  264. 'number_integer' => 'number_unformatted',
  265. 'number_decimal' => 'number_unformatted',
  266. 'number_float' => 'number_unformatted',
  267. 'file' => 'file_url_plain',
  268. 'image' => 'file_url_plain',
  269. 'text' => 'text_default',
  270. 'text_long' => 'text_default',
  271. 'text_with_summary' => 'text_default',
  272. 'list_integer' => 'list_default',
  273. 'list_float' => 'list_default',
  274. 'list_text' => 'list_default',
  275. 'list_boolean' => 'list_default',
  276. );
  277. foreach ($defaults as $field_type => $default_token_formatter) {
  278. if (isset($info[$field_type])) {
  279. $info[$field_type] += array('default_token_formatter' => $default_token_formatter);
  280. }
  281. }
  282. }
  283. /**
  284. * Implements hook_field_display_alter().
  285. */
  286. function token_field_display_alter(&$display, $context) {
  287. if ($context['view_mode'] == 'token') {
  288. $view_mode_settings = field_view_mode_settings($context['instance']['entity_type'], $context['instance']['bundle']);
  289. // If the token view mode fell back to the 'default' view mode, then
  290. // use the default token formatter.
  291. if (empty($view_mode_settings[$context['view_mode']]['custom_settings'])) {
  292. $field_type_info = field_info_field_types($context['field']['type']);
  293. // If the field has specified a specific formatter to be used by default
  294. // with tokens, use that, otherwise use the default formatter.
  295. $formatter = !empty($field_type_info['default_token_formatter']) ? $field_type_info['default_token_formatter'] : $field_type_info['default_formatter'];
  296. // Now that we have a formatter, fill in all the settings.
  297. $display['type'] = $formatter;
  298. $formatter_info = field_info_formatter_types($formatter);
  299. $display['settings'] = isset($formatter_info['settings']) ? $formatter_info['settings'] : array();
  300. $display['settings']['label'] = 'hidden';
  301. $display['module'] = $formatter_info['module'];
  302. }
  303. }
  304. }
  305. /**
  306. * Implements hook_field_create_instance().
  307. */
  308. function token_field_create_instance($instance) {
  309. token_clear_cache();
  310. }
  311. /**
  312. * Implements hook_field_update_instance().
  313. */
  314. function token_field_update_instance($instance) {
  315. token_clear_cache();
  316. }
  317. /**
  318. * Implements hook_field_delete_instance().
  319. */
  320. function token_field_delete_instance($instance) {
  321. token_clear_cache();
  322. }
  323. /**
  324. * Clear token caches and static variables.
  325. */
  326. function token_clear_cache() {
  327. if (db_table_exists('cache_token')) {
  328. cache_clear_all('*', 'cache_token', TRUE);
  329. }
  330. drupal_static_reset('token_get_info');
  331. drupal_static_reset('token_get_global_token_types');
  332. drupal_static_reset('token_get_entity_mapping');
  333. drupal_static_reset('token_build_tree');
  334. drupal_static_reset('_token_profile_fields');
  335. drupal_static_reset('token_menu_link_load');
  336. drupal_static_reset('token_book_link_load');
  337. drupal_static_reset('token_node_menu_link_load');
  338. drupal_static_reset('_token_field_info');
  339. }
  340. /**
  341. * Return an array of entity type to token type mappings.
  342. *
  343. * Why do we need this? Because when the token API was moved to core we did not
  344. * re-use the entity type as the base name for taxonomy terms and vocabulary
  345. * tokens.
  346. *
  347. * @see token_entity_info_alter()
  348. * @see http://drupal.org/node/737726
  349. */
  350. function token_get_entity_mapping($value_type = 'token', $value = NULL, $fallback = FALSE) {
  351. $mapping = &drupal_static(__FUNCTION__, array());
  352. if (empty($mapping)) {
  353. foreach (entity_get_info() as $entity_type => $info) {
  354. $mapping[$entity_type] = !empty($info['token type']) ? $info['token type'] : $entity_type;
  355. }
  356. // Allow modules to alter the mapping array.
  357. drupal_alter('token_entity_mapping', $mapping);
  358. }
  359. if (!isset($value)) {
  360. return $value_type == 'token' ? array_flip($mapping) : $mapping;
  361. }
  362. elseif ($value_type == 'token') {
  363. $return = array_search($value, $mapping);
  364. return $return !== FALSE ? $return : ($fallback ? $value : FALSE);
  365. }
  366. elseif ($value_type == 'entity') {
  367. return isset($mapping[$value]) ? $mapping[$value] : ($fallback ? $value : FALSE);
  368. }
  369. }
  370. /**
  371. * Implements hook_entity_info_alter().
  372. *
  373. * Because some token types to do not match their entity type names, we have to
  374. * map them to the proper type. This is purely for other modules' benefit.
  375. *
  376. * @see token_get_entity_mapping()
  377. * @see http://drupal.org/node/737726
  378. */
  379. function token_entity_info_alter(&$info) {
  380. foreach (array_keys($info) as $entity_type) {
  381. // Add a token view mode if it does not already exist. Only work with
  382. // fieldable entities.
  383. if (!empty($info[$entity_type]['fieldable'])) {
  384. if (!isset($info[$entity_type])) {
  385. $info[$entity_type]['view modes'] = array();
  386. }
  387. if (!isset($info[$entity_type]['view modes']['token'])) {
  388. $info[$entity_type]['view modes']['token'] = array(
  389. 'label' => t('Tokens'),
  390. 'custom settings' => FALSE,
  391. );
  392. }
  393. }
  394. if (!empty($info[$entity_type]['token type'])) {
  395. // If the entity's token type is already defined, great!
  396. continue;
  397. }
  398. // Fill in default token types for entities.
  399. switch ($entity_type) {
  400. case 'taxonomy_term':
  401. case 'taxonomy_vocabulary':
  402. // Stupid taxonomy token types...
  403. $info[$entity_type]['token type'] = str_replace('taxonomy_', '', $entity_type);
  404. break;
  405. default:
  406. // By default the token type is the same as the entity type.
  407. $info[$entity_type]['token type'] = $entity_type;
  408. break;
  409. }
  410. }
  411. }
  412. /**
  413. * Implements hook_module_implements_alter().
  414. *
  415. * Adds missing token support for core modules.
  416. */
  417. function token_module_implements_alter(&$implementations, $hook) {
  418. module_load_include('inc', 'token', 'token.tokens');
  419. if ($hook == 'tokens' || $hook == 'token_info' || $hook == 'token_info_alter' || $hook == 'tokens_alter') {
  420. foreach (_token_core_supported_modules() as $module) {
  421. if (module_exists($module) && function_exists($module . '_' . $hook)) {
  422. $implementations[$module] = FALSE;
  423. }
  424. }
  425. // Move token.module to get included first since it is responsible for
  426. // other modules.
  427. unset($implementations['token']);
  428. $implementations = array_merge(array('token' => 'tokens'), $implementations);
  429. }
  430. }
  431. /**
  432. * Implements hook_flush_caches().
  433. */
  434. function token_flush_caches() {
  435. if (db_table_exists('cache_token')) {
  436. return array('cache_token');
  437. }
  438. }
  439. /**
  440. * Retrieve, sort, store token info from the cache.
  441. *
  442. * @param $token_type
  443. * The optional token type that if specified will return
  444. * $info['types'][$token_type].
  445. * @param $token
  446. * The optional token name if specified will return
  447. * $info['tokens'][$token_type][$token].
  448. *
  449. * @return
  450. * An array of all token information from hook_token_info(), or the array
  451. * of a token type or specific token.
  452. *
  453. * @see hook_token_info()
  454. * @see hook_token_info_alter()
  455. */
  456. function token_get_info($token_type = NULL, $token = NULL) {
  457. global $language;
  458. // Use the advanced drupal_static() pattern, since this is called very often.
  459. static $drupal_static_fast;
  460. if (!isset($drupal_static_fast)) {
  461. $drupal_static_fast['token_info'] = &drupal_static(__FUNCTION__);
  462. }
  463. $token_info = &$drupal_static_fast['token_info'];
  464. if (empty($token_info)) {
  465. $cid = "info:{$language->language}";
  466. if ($cache = cache_get($cid, 'cache_token')) {
  467. $token_info = $cache->data;
  468. }
  469. else {
  470. $token_info = token_info();
  471. foreach (array_keys($token_info['types']) as $type_key) {
  472. if (isset($token_info['types'][$type_key]['type'])) {
  473. $base_type = $token_info['types'][$type_key]['type'];
  474. // If this token type extends another token type, then merge in
  475. // the base token type's tokens.
  476. if (isset($token_info['tokens'][$base_type])) {
  477. $token_info['tokens'] += array($type_key => array());
  478. $token_info['tokens'][$type_key] += $token_info['tokens'][$base_type];
  479. }
  480. }
  481. else {
  482. // Add a 'type' value to each token type so we can properly use
  483. // token_type_load().
  484. $token_info['types'][$type_key]['type'] = $type_key;
  485. }
  486. }
  487. // Pre-sort tokens.
  488. uasort($token_info['types'], 'token_asort_tokens');
  489. foreach (array_keys($token_info['tokens']) as $type) {
  490. uasort($token_info['tokens'][$type], 'token_asort_tokens');
  491. }
  492. // Store info in cache for future use.
  493. cache_set($cid, $token_info, 'cache_token');
  494. }
  495. }
  496. if (isset($token_type) && isset($token)) {
  497. return isset($token_info['tokens'][$token_type][$token]) ? $token_info['tokens'][$token_type][$token] : NULL;
  498. }
  499. elseif (isset($token_type)) {
  500. return isset($token_info['types'][$token_type]) ? $token_info['types'][$token_type] : NULL;
  501. }
  502. else {
  503. return $token_info;
  504. }
  505. }
  506. /**
  507. * Return the module responsible for a token.
  508. *
  509. * @param string $type
  510. * The token type.
  511. * @param string $name
  512. * The token name.
  513. *
  514. * @return mixed
  515. * The value of $info['tokens'][$type][$name]['module'] from token_get_info(),
  516. * or NULL if the value does not exist.
  517. */
  518. function _token_module($type, $name) {
  519. $token_info = token_get_info($type, $name);
  520. return isset($token_info['module']) ? $token_info['module'] : NULL;
  521. }
  522. /**
  523. * uasort() callback to sort tokens by the 'name' property.
  524. */
  525. function token_asort_tokens($token_a, $token_b) {
  526. return strnatcmp($token_a['name'], $token_b['name']);
  527. }
  528. /**
  529. * Get a list of token types that can be used without any context (global).
  530. *
  531. * @return
  532. * An array of global token types.
  533. */
  534. function token_get_global_token_types() {
  535. $global_types = &drupal_static(__FUNCTION__, array());
  536. if (empty($global_types)) {
  537. $token_info = token_get_info();
  538. foreach ($token_info['types'] as $type => $type_info) {
  539. // If the token types has not specified that 'needs-data' => TRUE, then
  540. // it is a global token type that will always be replaced in any context.
  541. if (empty($type_info['needs-data'])) {
  542. $global_types[] = $type;
  543. }
  544. }
  545. }
  546. return $global_types;
  547. }
  548. /**
  549. * Validate an tokens in raw text based on possible contexts.
  550. *
  551. * @param $value
  552. * A string with the raw text containing the raw tokens, or an array of
  553. * tokens from token_scan().
  554. * @param $tokens
  555. * An array of token types that will be used when token replacement is
  556. * performed.
  557. * @return
  558. * An array with the invalid tokens in their original raw forms.
  559. */
  560. function token_get_invalid_tokens_by_context($value, $valid_types = array()) {
  561. if (in_array('all', $valid_types)) {
  562. $info = token_get_info();
  563. $valid_types = array_keys($info['types']);
  564. }
  565. else {
  566. // Add the token types that are always valid in global context.
  567. $valid_types = array_merge($valid_types, token_get_global_token_types());
  568. }
  569. $invalid_tokens = array();
  570. $value_tokens = is_string($value) ? token_scan($value) : $value;
  571. foreach ($value_tokens as $type => $tokens) {
  572. if (!in_array($type, $valid_types)) {
  573. // If the token type is not a valid context, its tokens are invalid.
  574. $invalid_tokens = array_merge($invalid_tokens, array_values($tokens));
  575. }
  576. else {
  577. // Check each individual token for validity.
  578. $invalid_tokens = array_merge($invalid_tokens, token_get_invalid_tokens($type, $tokens));
  579. }
  580. }
  581. array_unique($invalid_tokens);
  582. return $invalid_tokens;
  583. }
  584. /**
  585. * Validate an array of tokens based on their token type.
  586. *
  587. * @param $type
  588. * The type of tokens to validate (e.g. 'node', etc.)
  589. * @param $tokens
  590. * A keyed array of tokens, and their original raw form in the source text.
  591. * @return
  592. * An array with the invalid tokens in their original raw forms.
  593. */
  594. function token_get_invalid_tokens($type, $tokens) {
  595. $token_info = token_get_info();
  596. $invalid_tokens = array();
  597. foreach ($tokens as $token => $full_token) {
  598. if (isset($token_info['tokens'][$type][$token])) {
  599. continue;
  600. }
  601. // Split token up if it has chains.
  602. $parts = explode(':', $token, 2);
  603. if (!isset($token_info['tokens'][$type][$parts[0]])) {
  604. // This is an invalid token (not defined).
  605. $invalid_tokens[] = $full_token;
  606. }
  607. elseif (count($parts) == 2) {
  608. $sub_token_info = $token_info['tokens'][$type][$parts[0]];
  609. if (!empty($sub_token_info['dynamic'])) {
  610. // If this token has been flagged as a dynamic token, skip it.
  611. continue;
  612. }
  613. elseif (empty($sub_token_info['type'])) {
  614. // If the token has chains, but does not support it, it is invalid.
  615. $invalid_tokens[] = $full_token;
  616. }
  617. else {
  618. // Resursively check the chained tokens.
  619. $sub_tokens = token_find_with_prefix(array($token => $full_token), $parts[0]);
  620. $invalid_tokens = array_merge($invalid_tokens, token_get_invalid_tokens($sub_token_info['type'], $sub_tokens));
  621. }
  622. }
  623. }
  624. return $invalid_tokens;
  625. }
  626. /**
  627. * Validate a form element that should have tokens in it.
  628. *
  629. * Form elements that want to add this validation should have the #token_types
  630. * parameter defined.
  631. *
  632. * For example:
  633. * @code
  634. * $form['my_node_text_element'] = array(
  635. * '#type' => 'textfield',
  636. * '#title' => t('Some text to token-ize that has a node context.'),
  637. * '#default_value' => 'The title of this node is [node:title].',
  638. * '#element_validate' => array('token_element_validate'),
  639. * '#token_types' => array('node'),
  640. * '#min_tokens' => 1,
  641. * '#max_tokens' => 10,
  642. * );
  643. * @endcode
  644. */
  645. function token_element_validate(&$element, &$form_state) {
  646. $value = isset($element['#value']) ? $element['#value'] : $element['#default_value'];
  647. if (!drupal_strlen($value)) {
  648. // Empty value needs no further validation since the element should depend
  649. // on using the '#required' FAPI property.
  650. return $element;
  651. }
  652. $tokens = token_scan($value);
  653. $title = empty($element['#title']) ? $element['#parents'][0] : $element['#title'];
  654. // @todo Find old Drupal 6 style tokens and add them to invalid tokens.
  655. // Validate if an element must have a minimum number of tokens.
  656. if (isset($element['#min_tokens']) && count($tokens) < $element['#min_tokens']) {
  657. // @todo Change this error message to include the minimum number.
  658. $error = format_plural($element['#min_tokens'], 'The %element-title cannot contain fewer than one token.', 'The %element-title must contain at least @count tokens.', array('%element-title' => $title));
  659. form_error($element, $error);
  660. }
  661. // Validate if an element must have a maximum number of tokens.
  662. if (isset($element['#max_tokens']) && count($tokens) > $element['#max_tokens']) {
  663. // @todo Change this error message to include the maximum number.
  664. $error = format_plural($element['#max_tokens'], 'The %element-title must contain as most one token.', 'The %element-title must contain at most @count tokens.', array('%element-title' => $title));
  665. form_error($element, $error);
  666. }
  667. // Check if the field defines specific token types.
  668. if (isset($element['#token_types'])) {
  669. $invalid_tokens = token_get_invalid_tokens_by_context($tokens, $element['#token_types']);
  670. if ($invalid_tokens) {
  671. form_error($element, t('The %element-title is using the following invalid tokens: @invalid-tokens.', array('%element-title' => $title, '@invalid-tokens' => implode(', ', $invalid_tokens))));
  672. }
  673. }
  674. return $element;
  675. }
  676. /**
  677. * Deprecated. Use token_element_validate() instead.
  678. */
  679. function token_element_validate_token_context(&$element, &$form_state) {
  680. return token_element_validate($element, $form_state);
  681. }
  682. /**
  683. * Implements hook_form_FORM_ID_alter().
  684. */
  685. function token_form_field_ui_field_edit_form_alter(&$form, $form_state) {
  686. if (!isset($form['instance']) || !empty($form['#field']['locked'])) {
  687. return;
  688. }
  689. if (($form['#field']['type'] == 'file' || $form['#field']['type'] == 'image') && isset($form['instance']['settings']['file_directory']) && !module_exists('filefield_paths')) {
  690. // GAH! We can only support global tokens in the upload file directory path.
  691. $form['instance']['settings']['file_directory']['#element_validate'][] = 'token_element_validate';
  692. $form['instance']['settings']['file_directory'] += array('#token_types' => array());
  693. $form['instance']['settings']['file_directory']['#description'] .= ' ' . t('This field supports tokens.');
  694. }
  695. // Note that the description is tokenized via token_field_widget_form_alter().
  696. $form['instance']['description']['#description'] .= '<br />' . t('This field supports tokens.');
  697. $form['instance']['description']['#element_validate'][] = 'token_element_validate';
  698. $form['instance']['description'] += array('#token_types' => array());
  699. $form['instance']['settings']['token_tree'] = array(
  700. '#theme' => 'token_tree',
  701. '#token_types' => array(),
  702. '#dialog' => TRUE,
  703. '#weight' => $form['instance']['description']['#weight'] + 0.5,
  704. );
  705. }
  706. /**
  707. * Implements hook_form_FORM_ID_alter().
  708. *
  709. * Alters the configure action form to add token context validation and
  710. * adds the token tree for a better token UI and selection.
  711. */
  712. function token_form_system_actions_configure_alter(&$form, $form_state) {
  713. $action = actions_function_lookup($form['actions_action']['#value']);
  714. switch ($action) {
  715. case 'system_message_action':
  716. case 'system_send_email_action':
  717. case 'system_goto_action':
  718. $form['token_tree'] = array(
  719. '#theme' => 'token_tree',
  720. '#token_types' => 'all',
  721. '#dialog' => TRUE,
  722. '#weight' => 100,
  723. );
  724. // @todo Add token validation to the action fields that can use tokens.
  725. break;
  726. }
  727. }
  728. /**
  729. * Implements hook_form_FORM_ID_alter().
  730. *
  731. * Alters the user e-mail fields to add token context validation and
  732. * adds the token tree for a better token UI and selection.
  733. */
  734. function token_form_user_admin_settings_alter(&$form, &$form_state) {
  735. $email_token_help = t('Available variables are: [site:name], [site:url], [user:name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url].');
  736. foreach (element_children($form) as $key) {
  737. $element = &$form[$key];
  738. // Remove the crummy default token help text.
  739. if (!empty($element['#description'])) {
  740. $element['#description'] = trim(str_replace($email_token_help, t('The list of available tokens that can be used in e-mails is provided below.'), $element['#description']));
  741. }
  742. switch ($key) {
  743. case 'email_admin_created':
  744. case 'email_pending_approval':
  745. case 'email_no_approval_required':
  746. case 'email_password_reset':
  747. case 'email_cancel_confirm':
  748. // Do nothing, but allow execution to continue.
  749. break;
  750. case 'email_activated':
  751. case 'email_blocked':
  752. case 'email_canceled':
  753. // These fieldsets have their e-mail elements inside a 'settings'
  754. // sub-element, so switch to that element instead.
  755. $element = &$form[$key]['settings'];
  756. break;
  757. default:
  758. continue 2;
  759. }
  760. foreach (element_children($element) as $sub_key) {
  761. if (!isset($element[$sub_key]['#type'])) {
  762. continue;
  763. }
  764. elseif ($element[$sub_key]['#type'] == 'textfield' && substr($sub_key, -8) === '_subject') {
  765. // Add validation to subject textfields.
  766. $element[$sub_key]['#element_validate'][] = 'token_element_validate';
  767. $element[$sub_key] += array('#token_types' => array('user'));
  768. }
  769. elseif ($element[$sub_key]['#type'] == 'textarea' && substr($sub_key, -5) === '_body') {
  770. // Add validation to body textareas.
  771. $element[$sub_key]['#element_validate'][] = 'token_element_validate';
  772. $element[$sub_key] += array('#token_types' => array('user'));
  773. }
  774. }
  775. }
  776. // Add the token tree UI.
  777. $form['email']['token_tree'] = array(
  778. '#theme' => 'token_tree',
  779. '#token_types' => array('user'),
  780. '#show_restricted' => TRUE,
  781. '#dialog' => TRUE,
  782. '#weight' => 90,
  783. );
  784. }
  785. /**
  786. * Build a tree array of tokens used for themeing or information.
  787. *
  788. * @param $token_type
  789. * The token type.
  790. * @param $flat_tree
  791. * A boolean if TRUE will only make a flat array of tokens, otherwise
  792. * child tokens will be inside the 'children' parameter of a token.
  793. * @param $show_restricted
  794. * A boolean if TRUE will show restricted tokens. Otherwise they will be
  795. * hidden. Default is FALSE.
  796. * @param $recursion_limit
  797. * An integer with the maximum number of token levels to recurse.
  798. * @param $parents
  799. * An optional array with the current parents of the tokens.
  800. */
  801. function token_build_tree($token_type, array $options = array()) {
  802. global $language;
  803. // Static cache of already built token trees.
  804. $trees = &drupal_static(__FUNCTION__, array());
  805. $options += array(
  806. 'restricted' => FALSE,
  807. 'depth' => 4,
  808. 'data' => array(),
  809. 'values' => FALSE,
  810. 'flat' => FALSE,
  811. );
  812. // Do not allow past the maximum token information depth.
  813. $options['depth'] = min($options['depth'], TOKEN_MAX_DEPTH);
  814. // If $token_type is an entity, make sure we are using the actual token type.
  815. if ($entity_token_type = token_get_entity_mapping('entity', $token_type)) {
  816. $token_type = $entity_token_type;
  817. }
  818. $tree_cid = "tree:{$token_type}:{$language->language}:{$options['depth']}";
  819. // If we do not have this base tree in the static cache, check {cache_token}
  820. // otherwise generate and store it in the cache.
  821. if (!isset($trees[$tree_cid])) {
  822. if ($cache = cache_get($tree_cid, 'cache_token')) {
  823. $trees[$tree_cid] = $cache->data;
  824. }
  825. else {
  826. $options['parents'] = array();
  827. $trees[$tree_cid] = _token_build_tree($token_type, $options);
  828. cache_set($tree_cid, $trees[$tree_cid], 'cache_token');
  829. }
  830. }
  831. $tree = $trees[$tree_cid];
  832. // If the user has requested a flat tree, convert it.
  833. if (!empty($options['flat'])) {
  834. $tree = token_flatten_tree($tree);
  835. }
  836. // Fill in token values.
  837. if (!empty($options['values'])) {
  838. $token_values = array();
  839. foreach ($tree as $token => $token_info) {
  840. if (!empty($token_info['dynamic']) || !empty($token_info['restricted'])) {
  841. continue;
  842. }
  843. elseif (!isset($token_info['value'])) {
  844. $token_values[$token_info['token']] = $token;
  845. }
  846. }
  847. if (!empty($token_values)) {
  848. $token_values = token_generate($token_type, $token_values, $options['data']);
  849. foreach ($token_values as $token => $replacement) {
  850. $tree[$token]['value'] = $replacement;
  851. }
  852. }
  853. }
  854. return $tree;
  855. }
  856. /**
  857. * Flatten a token tree.
  858. */
  859. function token_flatten_tree($tree) {
  860. $result = array();
  861. foreach ($tree as $token => $token_info) {
  862. $result[$token] = $token_info;
  863. if (isset($token_info['children']) && is_array($token_info['children'])) {
  864. $result += token_flatten_tree($token_info['children']);
  865. // unset($result[$token]['children']);
  866. }
  867. }
  868. return $result;
  869. }
  870. /**
  871. * Generate a token tree.
  872. */
  873. function _token_build_tree($token_type, array $options) {
  874. $options += array(
  875. 'parents' => array(),
  876. );
  877. $info = token_get_info();
  878. if ($options['depth'] <= 0 || !isset($info['types'][$token_type]) || !isset($info['tokens'][$token_type])) {
  879. return array();
  880. }
  881. $tree = array();
  882. foreach ($info['tokens'][$token_type] as $token => $token_info) {
  883. // Build the raw token string.
  884. $token_parents = $options['parents'];
  885. if (empty($token_parents)) {
  886. // If the parents array is currently empty, assume the token type is its
  887. // parent.
  888. $token_parents[] = $token_type;
  889. }
  890. elseif (in_array($token, array_slice($token_parents, 1))) {
  891. // Prevent duplicate recursive tokens. For example, this will prevent
  892. // the tree from generating the following tokens or deeper:
  893. // [comment:parent:parent]
  894. // [comment:parent:root:parent]
  895. continue;
  896. }
  897. $token_parents[] = $token;
  898. if (!empty($token_info['dynamic'])) {
  899. $token_parents[] = '?';
  900. }
  901. $raw_token = '[' . implode(':', $token_parents) . ']';
  902. $tree[$raw_token] = $token_info;
  903. $tree[$raw_token]['raw token'] = $raw_token;
  904. // Add the token's real name (leave out the base token type).
  905. $tree[$raw_token]['token'] = implode(':', array_slice($token_parents, 1));
  906. // Add the token's parent as its raw token value.
  907. if (!empty($options['parents'])) {
  908. $tree[$raw_token]['parent'] = '[' . implode(':', $options['parents']) . ']';
  909. }
  910. // Fetch the child tokens.
  911. if (!empty($token_info['type'])) {
  912. $child_options = $options;
  913. $child_options['depth']--;
  914. $child_options['parents'] = $token_parents;
  915. $tree[$raw_token]['children'] = _token_build_tree($token_info['type'], $child_options);
  916. }
  917. }
  918. return $tree;
  919. }
  920. /**
  921. * Get a translated menu link by its mlid, without access checking.
  922. *
  923. * This function is a copy of menu_link_load() but with its own cache and a
  924. * simpler query to load the link. This also skips normal menu link access
  925. * checking by using _token_menu_link_translate().
  926. *
  927. * @param $mlid
  928. * The mlid of the menu item.
  929. *
  930. * @return
  931. * A menu link translated for rendering.
  932. *
  933. * @see menu_link_load()
  934. * @see _token_menu_link_translate()
  935. */
  936. function token_menu_link_load($mlid) {
  937. $cache = &drupal_static(__FUNCTION__, array());
  938. if (!is_numeric($mlid)) {
  939. return FALSE;
  940. }
  941. if (!isset($cache[$mlid])) {
  942. $item = db_query("SELECT * FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path WHERE ml.mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc();
  943. if (!empty($item)) {
  944. _token_menu_link_translate($item);
  945. }
  946. $cache[$mlid] = $item;
  947. }
  948. return $cache[$mlid];
  949. }
  950. /**
  951. * Get a translated book menu link by its mlid, without access checking.
  952. *
  953. * This function is a copy of book_link_load() but with its own cache and a
  954. * simpler query to load the link. This also skips normal menu link access
  955. * checking by using _token_menu_link_translate().
  956. *
  957. * @param $mlid
  958. * The mlid of the book menu item.
  959. *
  960. * @return
  961. * A book menu link translated for rendering.
  962. *
  963. * @see book_link_load()
  964. * @see _token_menu_link_translate()
  965. */
  966. function token_book_link_load($mlid) {
  967. $cache = &drupal_static(__FUNCTION__, array());
  968. if (!is_numeric($mlid)) {
  969. return FALSE;
  970. }
  971. if (!isset($cache[$mlid])) {
  972. $item = db_query("SELECT * FROM {menu_links} ml INNER JOIN {book} b ON b.mlid = ml.mlid LEFT JOIN {menu_router} m ON m.path = ml.router_path WHERE ml.mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc();
  973. if (!empty($item)) {
  974. _token_menu_link_translate($item);
  975. }
  976. $cache[$mlid] = $item;
  977. }
  978. return $cache[$mlid];
  979. }
  980. function _token_menu_link_translate(&$item) {
  981. $map = array();
  982. if (!is_array($item['options'])) {
  983. $item['options'] = unserialize($item['options']);
  984. }
  985. if ($item['external']) {
  986. $item['access'] = 1;
  987. $item['href'] = $item['link_path'];
  988. $item['title'] = $item['link_title'];
  989. $item['localized_options'] = $item['options'];
  990. }
  991. else {
  992. // Complete the path of the menu link with elements from the current path,
  993. // if it contains dynamic placeholders (%).
  994. $map = explode('/', $item['link_path']);
  995. if (strpos($item['link_path'], '%') !== FALSE) {
  996. // Invoke registered to_arg callbacks.
  997. if (!empty($item['to_arg_functions'])) {
  998. _menu_link_map_translate($map, $item['to_arg_functions']);
  999. }
  1000. }
  1001. $item['href'] = implode('/', $map);
  1002. // Skip links containing untranslated arguments.
  1003. if (strpos($item['href'], '%') !== FALSE) {
  1004. $item['access'] = FALSE;
  1005. return FALSE;
  1006. }
  1007. $item['access'] = TRUE;
  1008. _menu_item_localize($item, $map, TRUE);
  1009. }
  1010. // Allow other customizations - e.g. adding a page-specific query string to the
  1011. // options array. For performance reasons we only invoke this hook if the link
  1012. // has the 'alter' flag set in the options array.
  1013. if (!empty($item['options']['alter'])) {
  1014. drupal_alter('translated_menu_link', $item, $map);
  1015. }
  1016. return $map;
  1017. }
  1018. /**
  1019. * Prepare a string for use as a valid token name.
  1020. *
  1021. * @param $name
  1022. * The token name to clean.
  1023. * @return
  1024. * The cleaned token name.
  1025. */
  1026. function token_clean_token_name($name) {
  1027. static $names = array();
  1028. if (!isset($names[$name])) {
  1029. $cleaned_name = strtr($name, array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => ''));
  1030. $cleaned_name = preg_replace('/[^\w\-]/i', '', $cleaned_name);
  1031. $cleaned_name = trim($cleaned_name, '-');
  1032. $names[$name] = $cleaned_name;
  1033. }
  1034. return $names[$name];
  1035. }
  1036. /**
  1037. * Do not use this function yet. Its API has not been finalized.
  1038. */
  1039. function token_render_array(array $array, array $options = array()) {
  1040. $rendered = array();
  1041. foreach (element_children($array) as $key) {
  1042. $value = $array[$key];
  1043. $rendered[] = is_array($value) ? render($value) : (string) $value;
  1044. }
  1045. if (!empty($options['sanitize'])) {
  1046. $rendered = array_map('check_plain', $rendered);
  1047. }
  1048. $join = isset($options['join']) ? $options['join'] : ', ';
  1049. return implode($join, $rendered);
  1050. }
  1051. /**
  1052. * Do not use this function yet. Its API has not been finalized.
  1053. */
  1054. function token_render_array_value($value, array $options = array()) {
  1055. $rendered = is_array($value) ? render($value) : (string) $value;
  1056. if (!empty($options['sanitize'])) {
  1057. $rendered = check_plain($rendered);
  1058. }
  1059. return $rendered;
  1060. }
  1061. /**
  1062. * Copy of drupal_render_cache_get() that does not care about request method.
  1063. */
  1064. function token_render_cache_get($elements) {
  1065. if (!$cid = drupal_render_cid_create($elements)) {
  1066. return FALSE;
  1067. }
  1068. $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
  1069. if (!empty($cid) && $cache = cache_get($cid, $bin)) {
  1070. // Add additional libraries, JavaScript, CSS and other data attached
  1071. // to this element.
  1072. if (isset($cache->data['#attached'])) {
  1073. drupal_process_attached($cache->data);
  1074. }
  1075. // Return the rendered output.
  1076. return $cache->data['#markup'];
  1077. }
  1078. return FALSE;
  1079. }
  1080. /**
  1081. * Coyp of drupal_render_cache_set() that does not care about request method.
  1082. */
  1083. function token_render_cache_set(&$markup, $elements) {
  1084. // This should only run of drupal_render_cache_set() did not.
  1085. if (in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD'))) {
  1086. return FALSE;
  1087. }
  1088. $original_method = $_SERVER['REQUEST_METHOD'];
  1089. $_SERVER['REQUEST_METHOD'] = 'GET';
  1090. drupal_render_cache_set($markup, $elements);
  1091. $_SERVER['REQUEST_METHOD'] = $original_method;
  1092. }
  1093. function token_menu_link_load_all_parents($mlid) {
  1094. $cache = &drupal_static(__FUNCTION__, array());
  1095. if (!is_numeric($mlid)) {
  1096. return array();
  1097. }
  1098. if (!isset($cache[$mlid])) {
  1099. $cache[$mlid] = array();
  1100. $plid = db_query("SELECT plid FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchField();
  1101. while ($plid && $parent = token_menu_link_load($plid)) {
  1102. $cache[$mlid] = array($plid => $parent['title']) + $cache[$mlid];
  1103. $plid = $parent['plid'];
  1104. }
  1105. }
  1106. return $cache[$mlid];
  1107. }
  1108. function token_taxonomy_term_load_all_parents($tid) {
  1109. $cache = &drupal_static(__FUNCTION__, array());
  1110. if (!is_numeric($tid)) {
  1111. return array();
  1112. }
  1113. if (!isset($cache[$tid])) {
  1114. $cache[$tid] = array();
  1115. $parents = taxonomy_get_parents_all($tid);
  1116. array_shift($parents); // Remove this term from the array.
  1117. $parents = array_reverse($parents);
  1118. foreach ($parents as $term) {
  1119. $cache[$tid][$term->tid] = entity_label('taxonomy_term', $term);
  1120. }
  1121. }
  1122. return $cache[$tid];
  1123. }
  1124. /**
  1125. * Load the preferred menu link associated with a node.
  1126. *
  1127. * @param $node
  1128. * A node object.
  1129. *
  1130. * @return
  1131. * A menu link array from token_menu_link_load() or FALSE if a menu link was
  1132. * not found.
  1133. *
  1134. * @see menu_node_prepare()
  1135. * @see token_menu_link_load()
  1136. */
  1137. function token_node_menu_link_load($node) {
  1138. $cache = &drupal_static(__FUNCTIon__, array());
  1139. if (!isset($cache[$node->nid])) {
  1140. $mlid = FALSE;
  1141. // Nodes do not have their menu links loaded via menu_node_load().
  1142. if (!isset($node->menu)) {
  1143. // We need to clone the node as menu_node_prepare() may cause data loss.
  1144. // @see http://drupal.org/node/1317926
  1145. $menu_node = clone $node;
  1146. menu_node_prepare($menu_node);
  1147. $mlid = !empty($menu_node->menu['mlid']) ? $menu_node->menu['mlid'] : FALSE;
  1148. }
  1149. else {
  1150. $mlid = !empty($node->menu['mlid']) ? $node->menu['mlid'] : FALSE;
  1151. }
  1152. $cache[$node->nid] = $mlid;
  1153. }
  1154. return $cache[$node->nid] ? token_menu_link_load($cache[$node->nid]) : FALSE;
  1155. }