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