uc_store.tokens.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * @file
  4. * Token hooks for the uc_store module.
  5. */
  6. /**
  7. * Implements hook_token_info().
  8. */
  9. function uc_store_token_info() {
  10. $type = array(
  11. 'name' => t('Store information'),
  12. 'description' => t('Tokens for store-specific, but globally available, information.'),
  13. );
  14. $site['login-link'] = array(
  15. 'name' => t('Login URL'),
  16. 'description' => t('A link to the site login page.'),
  17. );
  18. $site['logo'] = array(
  19. 'name' => t('Logo'),
  20. 'description' => t('The image showing the site logo.'),
  21. );
  22. $store['name'] = array(
  23. 'name' => t('Store name'),
  24. 'description' => t('The Ubercart store name.'),
  25. );
  26. $store['link'] = array(
  27. 'name' => t('Store link'),
  28. 'description' => t('A link to the Ubercart store using the store name.'),
  29. );
  30. $store['owner'] = array(
  31. 'name' => t('Owner'),
  32. 'description' => t('The Ubercart store owner.'),
  33. );
  34. $store['email'] = array(
  35. 'name' => t('Email'),
  36. 'description' => t('The Ubercart store e-mail address.'),
  37. );
  38. $store['phone'] = array(
  39. 'name' => t('Phone number'),
  40. 'description' => t('The Ubercart store phone number.'),
  41. );
  42. $store['fax'] = array(
  43. 'name' => t('Fax number'),
  44. 'description' => t('The Ubercart store fax number.'),
  45. );
  46. $store['address'] = array(
  47. 'name' => t('Address'),
  48. 'description' => t('The Ubercart store mailing address.'),
  49. );
  50. $store['help-url'] = array(
  51. 'name' => t('Help page URL'),
  52. 'description' => t('The URL to the store help page.'),
  53. 'type' => 'url',
  54. );
  55. return array(
  56. 'types' => array('store' => $type),
  57. 'tokens' => array(
  58. 'site' => $site,
  59. 'store' => $store,
  60. ),
  61. );
  62. }
  63. /**
  64. * Implements hook_tokens().
  65. */
  66. function uc_store_tokens($type, $tokens, $data = array(), $options = array()) {
  67. $replacements = array();
  68. if ($type == 'site') {
  69. foreach ($tokens as $name => $original) {
  70. switch ($name) {
  71. case 'login-link':
  72. $login_link = url('user', array('absolute' => TRUE));
  73. $replacements[$original] = l($login_link, $login_link);
  74. break;
  75. case 'logo':
  76. // Use a logo; but only if we have one to use.
  77. $replacements[$original] = '';
  78. if ($uri = theme_get_setting('logo')) {
  79. $replacements[$original] = theme('image', array('path' => $uri));
  80. }
  81. break;
  82. }
  83. }
  84. }
  85. if ($type == 'store') {
  86. foreach ($tokens as $name => $original) {
  87. switch ($name) {
  88. case 'name':
  89. $replacements[$original] = uc_store_name();
  90. break;
  91. case 'link':
  92. $replacements[$original] = l(uc_store_name(), '<front>', array('absolute' => TRUE));
  93. break;
  94. case 'owner':
  95. $replacements[$original] = variable_get('uc_store_owner', '');
  96. break;
  97. case 'email':
  98. $replacements[$original] = uc_store_email();
  99. break;
  100. case 'phone':
  101. $replacements[$original] = variable_get('uc_store_phone', '');
  102. break;
  103. case 'fax':
  104. $replacements[$original] = variable_get('uc_store_fax', '');
  105. break;
  106. case 'address':
  107. $replacements[$original] = uc_store_address();
  108. break;
  109. case 'help-url':
  110. $replacements[$original] = url(variable_get('uc_store_help_page', ''), array('absolute' => TRUE));
  111. break;
  112. }
  113. }
  114. // Handle chaining for tokens that have 'type' defined in hook_token_info()
  115. if ($link_tokens = token_find_with_prefix($tokens, 'help-url')) {
  116. $replacements += token_generate('url', $link_tokens, array('path' => variable_get('uc_store_help_page', '')), $options);
  117. }
  118. }
  119. return $replacements;
  120. }