Mercurial > defr > drupal > ad
comparison ad_token.inc @ 1:948362c2a207 ad
update advertisement
author | pierre |
---|---|
date | Thu, 02 Apr 2009 15:28:21 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d8a3998dac8e | 1:948362c2a207 |
---|---|
1 <?php | |
2 // $Id: ad_token.inc,v 1.1.2.1 2009/03/29 20:17:20 jeremy Exp $ | |
3 | |
4 /** | |
5 * @file | |
6 * Implementations of token module hooks for the Advertisement module. | |
7 * | |
8 * @ingroup token | |
9 */ | |
10 | |
11 /** | |
12 * Implementation of hook_token_values(). | |
13 */ | |
14 function ad_token_values($type, $object = NULL, $options = array()) { | |
15 $values = array(); | |
16 switch ($type) { | |
17 case 'ad': | |
18 if (isset($object)) { | |
19 $node = $object; | |
20 $notifications = module_invoke_all('adnotifyapi', 'register'); | |
21 module_load_include('pages.inc', 'ad'); | |
22 | |
23 $values['aid'] = $node->nid; | |
24 $values['title'] = $node->title; | |
25 $values['description'] = $node->body; | |
26 $values['log_message'] = $node->log; | |
27 $values['type'] = $node->adtype; | |
28 $values['status'] = $node->adstatus; | |
29 $values['url'] = url('node/'. $node->nid, array('absolute' => TRUE)); | |
30 $values['redirect'] = url($node->redirect, array('absolute' => TRUE)); | |
31 $values['comments'] = $node->comment_count; | |
32 | |
33 if (isset($node->notification)) { | |
34 $values['event'] = $node->notification->event; | |
35 $values['frequency'] = t(strtolower($notifications[$node->notification->event]), array('@when' => format_interval($node->notification->delay))); | |
36 } | |
37 | |
38 $values['created_small'] = format_date($node->created, 'small'); | |
39 $values['created_medium'] = format_date($node->created, 'medium'); | |
40 $values['created_large'] = format_date($node->created, 'large'); | |
41 $values['activated_small'] = $node->activated ? format_date($node->activated, 'small') : t('never'); | |
42 $values['activated_medium'] = $node->activated ? format_date($node->activated, 'medium') : t('never'); | |
43 $values['activated_large'] = $node->activated ? format_date($node->activated, 'large') : t('never'); | |
44 $values['expired_small'] = $node->expired ? format_date($node->expired, 'small') : t('never'); | |
45 $values['expired_medium'] = $node->expired ? format_date($node->expired, 'medium') : t('never'); | |
46 $values['expired_large'] = $node->expired ? format_date($node->expired, 'large') : t('never'); | |
47 $values['autoactivate_small'] = $node->autoactivate ? format_date($node->autoactivate, 'small') : t('never'); | |
48 $values['autoactivate_medium'] = $node->autoactivate ? format_date($node->autoactivate, 'medium') : t('never'); | |
49 $values['autoactivate_large'] = $node->autoactivate ? format_date($node->autoactivate, 'large') : t('never'); | |
50 $values['autoexpire_small'] = $node->autoexpire ? format_date($node->autoexpire, 'small') : t('never'); | |
51 $values['autoexpire_medium'] = $node->autoexpire ? format_date($node->autoexpire, 'medium') : t('never'); | |
52 $values['autoexpire_large'] = $node->autoexpire ? format_date($node->autoexpire, 'large') : t('never'); | |
53 | |
54 $statistics = ad_statistics($node->nid); | |
55 // maximums | |
56 $values['max_impressions'] = $node->maxviews; | |
57 $values['max_clicks'] = $node->maxclicks; | |
58 // global statistics | |
59 $values['global_impressions'] = isset($statistics['global']) && !empty($statistics['global']) ? $statistics['global']['views'] : 0; | |
60 $values['global_clicks'] = isset($statistics['global']) && !empty($statistics['global']) ? $statistics['global']['clicks'] : 0; | |
61 // last year statistics | |
62 $values['last_year_impressions'] = isset($statistics['last_year']) && !empty($statistics['last_year']) ? $statistics['last_year']['views'] : 0; | |
63 $values['last_year_clicks'] = isset($statistics['last_year']) && !empty($statistics['last_year']) ? $statistics['last_year']['clicks'] : 0; | |
64 // this year statistics | |
65 $values['this_year_impressions'] = isset($statistics['this_year']) && !empty($statistics['this_year']) ? $statistics['this_year']['views'] : 0; | |
66 $values['this_year_clicks'] = isset($statistics['this_year']) && !empty($statistics['this_year']) ? $statistics['this_year']['clicks'] : 0; | |
67 // last month statistics | |
68 $values['last_month_impressions'] = isset($statistics['last_month']) && !empty($statistics['last_month']) ? $statistics['last_month']['views'] : 0; | |
69 $values['last_month_clicks'] = isset($statistics['last_month']) && !empty($statistics['last_month']) ? $statistics['last_month']['clicks'] : 0; | |
70 // this month statistics | |
71 $values['this_month_impressions'] = isset($statistics['this_month']) && !empty($statistics['this_month']) ? $statistics['this_month']['views'] : 0; | |
72 $values['this_month_clicks'] = isset($statistics['this_month']) && !empty($statistics['this_month']) ? $statistics['this_month']['clicks'] : 0; | |
73 // yesterday statistics | |
74 $values['yesterday_impressions'] = isset($statistics['yesterday']) && !empty($statistics['yesterday']) ? $statistics['yesterday']['views'] : 0; | |
75 $values['yesterday_clicks'] = isset($statistics['yesterday']) && !empty($statistics['yesterday']) ? $statistics['yesterday']['clicks'] : 0; | |
76 // today statistics | |
77 $values['today_impressions'] = isset($statistics['today']) && !empty($statistics['today']) ? $statistics['today']['views'] : 0; | |
78 $values['today_clicks'] = isset($statistics['today']) && !empty($statistics['today']) ? $statistics['today']['clicks'] : 0; | |
79 // last hour statistics | |
80 $values['last_hour_impressions'] = isset($statistics['last_hour']) && !empty($statistics['last_hour']) ? $statistics['last_hour']['views'] : 0; | |
81 $values['last_hour_clicks'] = isset($statistics['last_hour']) && !empty($statistics['last_hour']) ? $statistics['last_hour']['clicks'] : 0; | |
82 // this hour statistics | |
83 $values['this_hour_impressions'] = isset($statistics['this_hour']) && !empty($statistics['this_hour']) ? $statistics['this_hour']['views'] : 0; | |
84 $values['this_hour_clicks'] = isset($statistics['this_hour']) && !empty($statistics['this_hour']) ? $statistics['this_hour']['clicks'] : 0; | |
85 } | |
86 break; | |
87 case 'ad_owner': | |
88 if (isset($object) && is_object($object)) { | |
89 $owner = $object; | |
90 $values['owner_name'] = $owner->name; | |
91 $values['owner_mail'] = $owner->mail; | |
92 $values['owner_uid'] = $owner->uid; | |
93 } | |
94 break; | |
95 } | |
96 return $values; | |
97 } | |
98 | |
99 /** | |
100 * Implementation of hook_token_list(). | |
101 */ | |
102 function ad_token_list($type = 'all') { | |
103 if ($type == 'ad' || $type == 'all') { | |
104 $tokens['ad']['aid'] = t('The ID of the advertisement.'); | |
105 $tokens['ad']['type'] = t('The type of ad.'); | |
106 $tokens['ad']['status'] = t('The status of the ad.'); | |
107 $tokens['ad']['url'] = t('The url of the advertisement.'); | |
108 $tokens['ad']['redirect'] = t('The redirection url of the advertisement.'); | |
109 $tokens['ad']['event'] = t('The type of event that has triggered this notification.'); | |
110 $tokens['ad']['frequency'] = t('A complete sentence describing the frequency this notification will be sent.'); | |
111 $tokens['ad']['title'] = t('The title of the advertisement.'); | |
112 $tokens['ad']['comments'] = t('The number of comments attached to the advertisement.'); | |
113 | |
114 $tokens['ad']['created_small'] = t('"Small" date format of when the advertisement was created.'); | |
115 $tokens['ad']['created_medium'] = t('"Medium" date format of when the advertisement was created.'); | |
116 $tokens['ad']['created_large'] = t('"Large" date format of when the advertisement was created.'); | |
117 $tokens['ad']['activated_small'] = t('"Small" date format when the advertisement was activated.'); | |
118 $tokens['ad']['activated_medium'] = t('"Medium" date format of when the advertisement was activated.'); | |
119 $tokens['ad']['activated_large'] = t('"Large" date format of when the advertisement was activated.'); | |
120 $tokens['ad']['expired_small'] = t('"Small" date format of when the advertisement was expired.'); | |
121 $tokens['ad']['expired_medium'] = t('"Medium" date format of when the advertisement was expired.'); | |
122 $tokens['ad']['expired_large'] = t('"Large" date format of when the advertisement was expired.'); | |
123 $tokens['ad']['autoactivate_small'] = t('"Small" date format of when the advertisement was automatically activated.'); | |
124 $tokens['ad']['autoactivate_medium'] = t('"Medium" date format of when the advertisement was automatically activated.'); | |
125 $tokens['ad']['autoactivate_large'] = t('"Large" date format of when the advertisement was automatically activated.'); | |
126 $tokens['ad']['autoexpire_small'] = t('"Small" date format of when the advertisement was automatically expired.'); | |
127 $tokens['ad']['autoexpire_medium'] = t('"Medium" date format of when the advertisement was automatically expired.'); | |
128 $tokens['ad']['autoexpire_large'] = t('"Large" date format of when the advertisement was automatically expired.'); | |
129 | |
130 $tokens['ad']['max_impressions'] = t('The maximum number of times this advertisement is allowed to be viewed.'); | |
131 $tokens['ad']['max_clicks'] = t('The maximum number of times this advertisement is allowed to be clicked.'); | |
132 $tokens['ad']['global_impressions'] = t('All time impression statistics'); | |
133 $tokens['ad']['global_clicks'] = t('All time click statistics.'); | |
134 $tokens['ad']['last_year_impressions'] = t('Ad impressions last year.'); | |
135 $tokens['ad']['last_year_clicks'] = t('Ad clicks last year.'); | |
136 $tokens['ad']['this_year_impressions'] = t('Ad impressions this year.'); | |
137 $tokens['ad']['this_year_clicks'] = t('Ad clicks this year.'); | |
138 $tokens['ad']['last_month_impressions'] = t('Ad impressions last month.'); | |
139 $tokens['ad']['last_month_clicks'] = t('Ad clicks this month.'); | |
140 $tokens['ad']['this_month_impressions'] = t('Ad impressions this month.'); | |
141 $tokens['ad']['this_month_clicks'] = t('Ad clicks this month.'); | |
142 $tokens['ad']['yesterday_impressions'] = t('Ad impressions yesterday.'); | |
143 $tokens['ad']['yesterday_clicks'] = t('Ad clicks yesterday.'); | |
144 $tokens['ad']['today_impressions'] = t('Ad impressions today.'); | |
145 $tokens['ad']['today_clicks'] = t('Ad clicks today.'); | |
146 $tokens['ad']['last_hour_impressions'] = t('Ad impressions last hour.'); | |
147 $tokens['ad']['last_hour_clicks'] = t('Ad clicks this hour.'); | |
148 $tokens['ad']['this_hour_impressions'] = t('Ad impressions this hour.'); | |
149 $tokens['ad']['this_hour_clicks'] = t('Ad clicks this hour.'); | |
150 } | |
151 if ($type == 'ad' || $type == 'all') { | |
152 $tokens['Ad owner']['owner_name'] = t('The username of the ad owner.'); | |
153 $tokens['Ad owner']['owner_mail'] = t('The email address of the ad owner.'); | |
154 $tokens['Ad owner']['owner_uid'] = t('The user ID of the ad owner.'); | |
155 } | |
156 return $tokens; | |
157 } |