comparison ad.module @ 1:948362c2a207 ad

update advertisement
author pierre
date Thu, 02 Apr 2009 15:28:21 +0000
parents d8a3998dac8e
children e5584a19768b
comparison
equal deleted inserted replaced
0:d8a3998dac8e 1:948362c2a207
1 <?php 1 <?php
2 // $Id: ad.module,v 1.2.2.29.2.83.2.16 2009/02/17 18:56:26 jeremy Exp $ 2 // $Id: ad.module,v 1.2.2.29.2.83.2.16.2.12 2009/03/31 04:41:03 jeremy Exp $
3 3
4 /** 4 /**
5 * @file 5 * @file
6 * An advertising system for Drupal powered websites. 6 * An advertising system for Drupal powered websites.
7 * 7 *
8 * Copyright (c) 2005-2009. 8 * Copyright (c) 2005-2009.
9 * Jeremy Andrews <jeremy@tag1consulting.com>. 9 * Jeremy Andrews <jeremy@tag1consulting.com>.
10 */ 10 */
11 11
12 require_once('ad_token.inc');
12 13
13 /** 14 /**
14 * Implementation of hook_theme(). 15 * Implementation of hook_theme().
15 */ 16 */
16 function ad_theme() { 17 function ad_theme() {
101 $options['cache'] = variable_get('ad_cache', 'none'); 102 $options['cache'] = variable_get('ad_cache', 'none');
102 103
103 switch ($options['ad_display']) { 104 switch ($options['ad_display']) {
104 case 'raw': 105 case 'raw':
105 require_once(drupal_get_path('module', 'ad') .'/adserve.inc'); 106 require_once(drupal_get_path('module', 'ad') .'/adserve.inc');
107 require_once(drupal_get_path('module', 'ad') .'/adcache.inc');
106 $output = adserve_ad($options); 108 $output = adserve_ad($options);
107 break; 109 break;
108 case 'iframe': 110 case 'iframe':
109 case 'jquery': 111 case 'jquery':
110 $query['m'] = $options['ad_display']; 112 $query['m'] = $options['ad_display'];
146 } 148 }
147 else { 149 else {
148 // Choose ads from the specified group. 150 // Choose ads from the specified group.
149 $query['t'] = $group; 151 $query['t'] = $group;
150 $options['tids'] = $group; 152 $options['tids'] = $group;
153 }
154 if (isset($options['url'])) {
155 $query['u'] = $options['url'];
156 }
157 else {
158 $query['u'] = $_GET['q'];
151 } 159 }
152 $src = url($base_url .'/'. $adserve, array('query' => $query)); 160 $src = url($base_url .'/'. $adserve, array('query' => $query));
153 if ($options['ad_display'] == 'iframe') { 161 if ($options['ad_display'] == 'iframe') {
154 // TODO: We need to know the IFrame size before it is displayed. This 162 // TODO: We need to know the IFrame size before it is displayed. This
155 // limits the flexibility of what can be displayed in these frames. 163 // limits the flexibility of what can be displayed in these frames.
169 else if ($options['ad_display'] == 'jquery') { 177 else if ($options['ad_display'] == 'jquery') {
170 // The theme function uses this to generate a CSS id for jQuery to use. 178 // The theme function uses this to generate a CSS id for jQuery to use.
171 $output = $src; 179 $output = $src;
172 } 180 }
173 else { 181 else {
174 $output = '<script type="text/javascript" src="'. $src .'"></script>'; 182 $output = "<script type='text/javascript' src='$src'></script>";
175 } 183 }
176 break; 184 break;
177 } 185 }
178 186
179 if (user_access('show advertisements')) { 187 if (user_access('show advertisements')) {
180 return theme('ad_display', $group, $output, $options['ad_display']); 188 if (isset($options['div']) && $options['div'] !== FALSE) {
189 return theme('ad_display', $group, $output, $options['ad_display']);
190 }
191 else {
192 return theme('ad_display', $group, $output, 'raw');
193 }
181 } 194 }
182 else { 195 else {
183 return theme('ad_display', 'none', "<!-- Enable 'show advertisements' permission if you wish to display ads here. -->"); 196 return theme('ad_display', 'none', "<!-- Enable 'show advertisements' permission if you wish to display ads here. -->");
184 } 197 }
185 } 198 }
187 /** 200 /**
188 * Function to display the actual advertisement to the screen. Wrap it in a 201 * Function to display the actual advertisement to the screen. Wrap it in a
189 * theme function to make it possible to customize in your own theme. 202 * theme function to make it possible to customize in your own theme.
190 */ 203 */
191 function theme_ad_display($group, $display, $method = 'javascript') { 204 function theme_ad_display($group, $display, $method = 'javascript') {
192 static $id = 0; 205 static $id = -1;
206
207 // Increment counter for displaying multiple advertisements on the page.
208 $id++;
193 209
194 // The naming convention for the id attribute doesn't allow commas. 210 // The naming convention for the id attribute doesn't allow commas.
195 $group = preg_replace('/[,]/', '+', $group); 211 $group = preg_replace('/[,]/', '+', $group);
196 212
197 if ($method == 'jquery') { 213 if ($method == 'jquery') {
198 drupal_add_js('misc/jquery.js', 'core'); 214 drupal_add_js('misc/jquery.js', 'core');
199 return "\n<div class=\"advertisement group-$group\" id=\"group-id-$id\">\n <script type=\"text/javascript\">\n //<!--[CDATA[\n $(document).ready(function(){ jQuery(\"div#group-id-$id\").load(\"$display\"); });\n //]]>\n </script>\n</div>\n"; 215 return "\n<div class=\"advertisement group-$group\" id=\"group-id-$id\">\n <script type=\"text/javascript\">\n//<![CDATA[\n $(document).ready(function(){ jQuery(\"div#group-id-$id\").load(\"$display\"); });\n //]]>\n </script>\n</div>\n";
216 }
217 else if ($method == 'raw') {
218 return $display;
200 } 219 }
201 else { 220 else {
202 return "\n<div class=\"advertisement group-$group\" id=\"group-id-$group\">$display</div>\n"; 221 return "\n<div class=\"advertisement group-$group\" id=\"group-id-$group\">$display</div>\n";
203 } 222 }
204 } 223 }
205 224
206 /** 225 /**
207 * Update click counter then redirect host to ad's target URL. 226 * Update click counter then redirect host to ad's target URL.
208 */ 227 */
209 function ad_redirect($aid, $group, $hostid = 0) { 228 function ad_redirect($aid, $group = NULL) {
210 global $user; 229 global $user;
230 $hostid = isset($_GET['hostid']) ? $_GET['hostid'] : '';
231 $extra = isset($_GET['extra']) ? $_GET['extra'] : '';
211 if (function_exists('click_filter_status')) { 232 if (function_exists('click_filter_status')) {
212 $status = click_filter_status($aid, $hostid); 233 $status = click_filter_status($aid, $hostid);
213 if ($status == CLICK_VALID) { 234 if ($status == CLICK_VALID) {
214 ad_statistics_increment($aid, 'click', $group, $hostid); 235 ad_statistics_increment($aid, 'click', $group, $hostid);
215 } 236 }
222 // Allow source url to be passed in. 243 // Allow source url to be passed in.
223 $url = isset($_GET['u']) ? $_GET['u'] : ''; 244 $url = isset($_GET['u']) ? $_GET['u'] : '';
224 if (!isset($url) || !valid_url($url)) { 245 if (!isset($url) || !valid_url($url)) {
225 $url = referer_uri(); 246 $url = referer_uri();
226 } 247 }
227 db_query("INSERT INTO {ad_clicks} (aid, uid, status, hostname, user_agent, adgroup, hostid, url, timestamp) VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', '%s', %d)", $aid, $user->uid, $status, ip_address(), $_SERVER['HTTP_USER_AGENT'], $group, $hostid, $url, time()); 248 db_query("INSERT INTO {ad_clicks} (aid, uid, status, hostname, user_agent, adgroup, extra, hostid, url, timestamp) VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d)", $aid, $user->uid, $status, ip_address(), $_SERVER['HTTP_USER_AGENT'], $group, $extra, $hostid, $url, time());
228 249
229 // Determine where we're supposed to redirect the user. 250 // Determine where we're supposed to redirect the user.
230 $adtype = db_result(db_query('SELECT adtype FROM {ads} WHERE aid = %d', $aid)); 251 $adtype = db_result(db_query('SELECT adtype FROM {ads} WHERE aid = %d', $aid));
231 252
232 $node->nid = $node->aid = $aid; 253 $node->nid = $node->aid = $aid;
269 default: 290 default:
270 $target = array(); 291 $target = array();
271 break; 292 break;
272 } 293 }
273 return $target; 294 return $target;
295 }
296
297 /**
298 * Force the cache to be flushed.
299 */
300 function ad_rebuild_cache($verbose = FALSE) {
301 $cache = variable_get('ad_cache', 'none');
302 $build = "ad_cache_{$cache}_build";
303 if (function_exists($build)) {
304 if ($verbose) {
305 drupal_set_message('Rebuilding ad cache.');
306 }
307 $build();
308 }
274 } 309 }
275 310
276 /** 311 /**
277 * Ad API Helper Function: 312 * Ad API Helper Function:
278 * Append rel="nofollow" if globally enabled. 313 * Append rel="nofollow" if globally enabled.
305 340
306 $event = array('aid' => $aid, 'action' => $action, 'hostid' => $hostid); 341 $event = array('aid' => $aid, 'action' => $action, 'hostid' => $hostid);
307 module_invoke_all('adapi', 'statistics_increment', $event); 342 module_invoke_all('adapi', 'statistics_increment', $event);
308 } 343 }
309 344
310 function ad_status_array($admin = TRUE) { 345 /**
311 if ($admin) { 346 * Return an array with all status values user has permission to set.
312 // status options for administrators 347 * A user with 'administer advertisements' permission can update any status.
313 return array( 348 */
314 'pending' => t('This advertisement is currently waiting for administrative approval.'), 349 function ad_status_array($aid = 0, $status = NULL) {
315 'approved' => t('This advertisement has been approved and is currently waiting to be administratively activated.'), 350 $permissions = array();
316 'active' => t('This advertisement is actively being displayed.'), 351 // mark status as pending
317 'offline' => t('This advertisement has been temporarily disabled by its owner and is not currently being displayed.'), 352 if (user_access('administer advertisements') ||
318 'unpublished' => t('This advertisement has been unpublished and is not currently being displayed.'), 353 $status == 'pending' || $status == NULL ||
319 'expired' => t('This advertisement has expired.'), 354 ad_permission($aid, 'set status as pending')) {
320 'denied' => t('This advertisement was refused by the site administrator, it will not be displayed.')); 355 $permissions['pending'] = t('This advertisement is currently waiting for administrative approval.');
321 } 356 }
322 else { 357 // mark status from pending to approved
323 // status options for advertisement owners 358 if (user_access('administer advertisements') ||
324 return array( 359 $status == 'approved' ||
325 'active' => t('This advertisement is actively being displayed.'), 360 ($status == 'pending' &&
326 'offline' => t('This advertisement has been temporarily disabled and is not currently being displayed.')); 361 ad_permission($aid, 'set status from pending to approved'))) {
327 } 362 $permissions['approved'] = t('This advertisement has been approved and is currently waiting to be activated.');
363 }
364 // mark status as active (from pending, approved, or offline)
365 if (user_access('administer advertisements') ||
366 $status == 'active' ||
367 ($status == 'approved' &&
368 ad_permission($aid, 'set status from approved to active')) ||
369 ($status == 'offline' &&
370 ad_permission($aid, 'set status from offline to active'))) {
371 $permissions['active'] = t('This advertisement is actively being displayed.');
372 }
373 // mark status as offline (from pending, approved, or active)
374 if (user_access('administer advertisements') ||
375 $status == 'offline' ||
376 ($status == 'approved' &&
377 ad_permission($aid, 'set status from approved to offline')) ||
378 ($status == 'active' &&
379 ad_permission($aid, 'set status from active to offline'))) {
380 $permissions['offline'] = t('This advertisement has been temporarily disabled by its owner and is not currently being displayed.');
381 }
382 // mark status as expired (from active or offline)
383 if (user_access('administer advertisements') ||
384 $status == 'expired' ||
385 ($status == 'active' &&
386 ad_permission($aid, 'set status from active to expired')) ||
387 ($status == 'offline' &&
388 ad_permission($aid, 'set status from offline to expired'))) {
389 $permissions['expired'] = t('This advertisement has expired and is no longer being displayed.');
390 }
391 // mark status as denied (from pending or any)
392 if (user_access('administer advertisements') ||
393 $status == 'denied' ||
394 ($status == 'pending' &&
395 ad_permission($aid, 'set status from pending to denied')) ||
396 ad_permission($aid, 'set status as denied')) {
397 $permissions['denied'] = t('This advertisement was refused by the site administrator and will not be displayed.');
398 }
399 return $permissions;
328 } 400 }
329 401
330 /** 402 /**
331 * Display the status of the currently viewed ad. 403 * Display the status of the currently viewed ad.
332 */ 404 */
333 function theme_ad_status_display($node) { 405 function theme_ad_status_display($node) {
334 $status_array = ad_status_array(); 406 if (isset($node->adstatus)) {
335 $output = '<div class="adstatus">'; 407 $status_array = ad_status_array($node->nid, $node->adstatus);
336 $output .= '<p>'. t($status_array[$node->adstatus]) .'</p>'; 408 $output = '<div class="adstatus">';
337 switch ($node->adstatus) { 409 $output .= '<p>'. t($status_array[$node->adstatus]) .'</p>';
338 case 'approved': 410 switch ($node->adstatus) {
339 if ($node->autoactivate) { 411 case 'approved':
340 $output .= '<p>'. t('This advertisement will be automatically activated on %timestamp, in %time.', array('%timestamp' => format_date($node->autoactivate, 'large'), '%time' => format_interval($node->autoactivate - time()))) .'</p>'; 412 if ($node->autoactivate) {
341 } 413 $output .= '<p>'. t('This advertisement will be automatically activated on %timestamp, in %time.', array('%timestamp' => format_date($node->autoactivate, 'large'), '%time' => format_interval($node->autoactivate - time()))) .'</p>';
342 break; 414 }
343 case 'active': 415 break;
344 $activated = db_result(db_query("SELECT activated FROM {ads} WHERE aid = %d", $node->nid)); 416 case 'active':
345 if ($activated) { 417 $activated = db_result(db_query("SELECT activated FROM {ads} WHERE aid = %d", $node->nid));
346 $output .= '<p>'. t('This advertisement has been active since %date.', array('%date' => format_date($activated, 'large'))) .'</p>'; 418 if ($activated) {
347 } 419 $output .= '<p>'. t('This advertisement has been active since %date.', array('%date' => format_date($activated, 'large'))) .'</p>';
348 if ($node->autoexpire) { 420 }
349 $output .= '<p>'. t('This advertisement will expire on %timestamp, in %time.', array('%timestamp' => format_date($node->autoexpire, 'large'), '%time' => format_interval($node->autoexpire - time()))) .'</p>'; 421 if ($node->autoexpire) {
350 } 422 $output .= '<p>'. t('This advertisement will expire on %timestamp, in %time.', array('%timestamp' => format_date($node->autoexpire, 'large'), '%time' => format_interval($node->autoexpire - time()))) .'</p>';
351 if ($node->maxviews) { 423 }
352 $views = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $node->nid, date('YmdH', $node->activated))); 424 if ($node->maxviews) {
353 $output .= '<p>'. t('This advertisement will expire after %left more impressions.', array('%left' => $node->maxviews - $views)) .'</p>'; 425 $views = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $node->nid, date('YmdH', $node->activated)));
354 } 426 $output .= '<p>'. t('This advertisement will expire after %left more impressions.', array('%left' => $node->maxviews - $views)) .'</p>';
355 if ($node->maxclicks) { 427 }
356 $clicks = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d", $node->nid, date('YmdH', $node->activated))); 428 if ($node->maxclicks) {
357 $output .= '<p>'. t('This advertisement will expire after %left more clicks.', array('%left' => $node->maxclicks - $clicks)) .'</p>'; 429 $clicks = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d", $node->nid, date('YmdH', $node->activated)));
358 } 430 $output .= '<p>'. t('This advertisement will expire after %left more clicks.', array('%left' => $node->maxclicks - $clicks)) .'</p>';
359 break; 431 }
360 case 'expired': 432 break;
361 $expired = db_result(db_query("SELECT expired FROM {ads} WHERE aid = %d", $node->nid)); 433 case 'expired':
362 if ($expired) { 434 $expired = db_result(db_query("SELECT expired FROM {ads} WHERE aid = %d", $node->nid));
363 $output .= '<p>'. t('This advertisement expired %date.', array('%date' => format_date($expired, 'large'))) .'</p>'; 435 if ($expired) {
364 } 436 $output .= '<p>'. t('This advertisement expired %date.', array('%date' => format_date($expired, 'large'))) .'</p>';
365 break; 437 }
366 } 438 break;
367 $output .= '</div>'; 439 }
368 return theme('box', t('Status'), $output); 440 $output .= '</div>';
441 return theme('box', t('Status'), $output);
442 }
369 } 443 }
370 444
371 /** 445 /**
372 * Implementation of hook_help(). 446 * Implementation of hook_help().
373 */ 447 */
455 */ 529 */
456 function ad_perm() { 530 function ad_perm() {
457 return array('administer advertisements', 531 return array('administer advertisements',
458 'create advertisements', 532 'create advertisements',
459 'edit own advertisements', 533 'edit own advertisements',
534 'edit any advertisement',
535 'delete own advertisements',
536 'delete any advertisement',
460 'show advertisements'); 537 'show advertisements');
461 } 538 }
462 539
463 /** 540 /**
464 * Implementation of hook_node_info(). 541 * Implementation of hook_node_info().
467 $items['ad'] = array( 544 $items['ad'] = array(
468 'name' => t('Advertisement'), 545 'name' => t('Advertisement'),
469 'module' => 'ad', 546 'module' => 'ad',
470 'description' => t('Advertisements can be randomly displayed to visitors of your website.'), 547 'description' => t('Advertisements can be randomly displayed to visitors of your website.'),
471 ); 548 );
472
473 $adtypes = ad_get_types('data');
474 // New 'type' notation returns everything we need to define content type
475 foreach ($adtypes as $type => $data) {
476 $items['ad/'. $type] = $data;
477 }
478 return $items; 549 return $items;
479 } 550 }
480 551
481 /** 552 /**
482 * Implementation of hook_access(). 553 * Implementation of hook_access().
483 */ 554 */
484 function ad_access($op, $node, $account) { 555 function ad_access($op, $node, $account) {
485 if ($op == 'create') { 556 switch ($op) {
486 return user_access('create advertisements', $account); 557 case 'create':
487 } 558 return (user_access('create advertisements', $account) || user_access('administer advertisements'));
488 559 case 'update':
489 if ($op == 'update' || $op == 'delete') { 560 return (user_access('edit any advertisement', $account) || (user_access('edit own advertisements', $account) && is_ad_owner($node->nid)) || user_access('administer advertisements', $account));
490 return (user_access('administer advertisements', $account) || 561 case 'delete':
491 (module_exists('ad_owners') && ad_is_owner($node->nid) && user_access('edit own advertisements', $account))); 562 return (user_access('delete any advertisement', $account) || (user_access('delete own advertisements', $account) && is_ad_owner($node->nid)) || user_access('administer advertisements', $account));
563 case 'view':
564 return (user_access('show advertisements', $account) || user_access('administer advertisements', $account));
492 } 565 }
493 } 566 }
494 567
495 /** 568 /**
496 * Implementation of hook_form(). 569 * Implementation of hook_form().
497 */ 570 */
498 function ad_form($node, &$form_state) { 571 function ad_form(&$node, &$form_state) {
499 $form = array(); 572 $form = array();
500 573
501 $type = arg(3); 574 // When form_state is not empty, we should rather use it's values
502 if (function_exists('ad_'. $type .'_display_ad')) { 575 // to not loose data if validation fails.
503 $adtype = $type; 576 if (!empty($form_state['values'])) {
504 } 577 $node = (object)$form_state['values'];
505 else {
506 $adtype = isset($node->adtype) ? $node->adtype : '';
507 } 578 }
508 579
509 $form['aid'] = array( 580 $form['aid'] = array(
510 '#type' => 'value', 581 '#type' => 'value',
511 '#value' => isset($node->nid) ? $node->nid : 0, 582 '#value' => isset($node->nid) ? $node->nid : 0,
534 else if (!sizeof($adtypes)) { 605 else if (!sizeof($adtypes)) {
535 drupal_set_message(t('At least one ad type module must be enabled before you can create advertisements. For example, try <a href="!url">enabling</a> the ad_text or ad_image module.', array('!url' => url('admin/build/modules'))), 'error'); 606 drupal_set_message(t('At least one ad type module must be enabled before you can create advertisements. For example, try <a href="!url">enabling</a> the ad_text or ad_image module.', array('!url' => url('admin/build/modules'))), 'error');
536 } 607 }
537 } 608 }
538 609
610 // display ad type switch
611 if (!isset($node->adtype) || isset($node->adtype_select)) {
612 $adtypes = array(0 => '---');
613 $adtypes += ad_get_types('name');
614 $form['select'] = array(
615 '#type' => 'fieldset',
616 '#title' => t('Select Ad type'),
617 '#prefix' => '<div class="container-inline">',
618 '#suffix' => '</div>',
619 '#weight' => 3,
620 );
621 $form['select']['adtype_select'] = array(
622 '#type' => 'select',
623 '#required' => TRUE,
624 '#options' => $adtypes,
625 '#default_value' => isset($node->adtype_select) ? $node->adtype_select : '',
626 );
627 $form['select']['adtype_submit'] = array(
628 '#type' => 'submit',
629 '#value' => t('Select'),
630 '#validate' => array('ad_select_adtype'),
631 '#ahah' => array(
632 'path' => 'node/add/ad/ahah',
633 'wrapper' => 'adtype-ahah-wrapper',
634 ),
635 );
636 }
539 // display type-specific options 637 // display type-specific options
540 if (isset($adtype)) { 638 if (isset($node->adtype) && $node->adtype) {
541 $elements = module_invoke('ad_'. $adtype, 'adapi', 'form', $node); 639 if (isset($node->adtype_select) && $node->adtype_select && ($node->adtype_select != $node->adtype)) {
542 if (is_array($elements)) { 640 $node->adtype = $node->adtype_select;
543 foreach ($elements as $element => $values) { 641 }
544 $form[$element] = $values; 642 ad_form_add_adtype_elements($form, $node->adtype, $node);
545 } 643 // add ahah wrapper
546 } 644 $form['adtype_elements']['#prefix'] = '<div id="adtype-ahah-wrapper">';
547 $form['adtype'] = array( 645 $form['adtype_elements']['#suffix'] = '</div>';
548 '#type' => 'hidden', 646 }
549 '#value' => $adtype, 647 if (!isset($form['adtype_elements'])) {
648 $form['adtype_elements'] = array(
649 '#value' => '<div id="adtype-ahah-wrapper"></div>',
650 '#weight' => 3.1,
550 ); 651 );
551 } 652 }
552 653
553 if (user_access('administer advertisements')) { 654 // fieldset for updating ad status
554 // admins can set any status on advertisements 655 $form['adstatus'] = array(
555 $form['adstatus'] = array( 656 '#type' => 'fieldset',
556 '#type' => 'fieldset', 657 '#title' => t('Status'),
557 '#title' => t('Status'), 658 '#collapsible' => TRUE,
558 '#collapsible' => TRUE 659 '#weight' => 4,
559 ); 660 );
560 foreach (ad_status_array() as $status => $description) { 661 $nid = isset($node->nid) ? $node->nid : 0;
561 $form['adstatus']["ad$status"] = array( 662 $adstatus = isset($node->adstatus) ? $node->adstatus : '';
562 '#type' => 'radio', 663 // display all available status options
563 '#title' => t($status), 664 foreach (ad_status_array($nid, $adstatus) as $status => $description) {
564 '#return_value' => $status, 665 $form['adstatus']["ad$status"] = array(
565 '#default_value' => isset($node->adstatus) ? $node->adstatus : 'pending', 666 '#type' => 'radio',
566 '#description' => $description, 667 '#title' => t("$status"),
567 '#parents' => array('adstatus') 668 '#return_value' => $status,
568 ); 669 '#default_value' => isset($node->adstatus) ? $node->adstatus : 'pending',
569 } 670 '#description' => "$description",
570 } 671 '#parents' => array("adstatus")
571 else if (ad_adaccess($node, 'manage status')) {
572 if (!$node->adstatus || $node->adstatus == 'pending') {
573 $adstatus = ad_status_array();
574 $node->adstatus = 'pending';
575 $form['adstatus'] = array(
576 '#type' => 'fieldset',
577 '#title' => t('Status'),
578 '#collapsible' => TRUE
579 );
580 $form['adstatus']['display'] = array(
581 '#type' => 'markup',
582 '#value' => '<p><strong>'. t('Status') .':</strong> '. t($node->adstatus) .'<br />'. t($adstatus[$node->adstatus]),
583 );
584 $form['adstatus']['adpending'] = array(
585 '#type' => 'value',
586 '#value' => $node->adstatus
587 );
588 }
589 else {
590 $adstatus = ad_status_array(FALSE);
591 // display status options
592 $form['adstatus'] = array(
593 '#type' => 'fieldset',
594 '#title' => t('Status'),
595 '#collapsible' => TRUE
596 );
597 foreach ($adstatus as $status => $description) {
598 $form['adstatus']["ad$status"] = array(
599 '#type' => 'radio',
600 '#title' => t($status),
601 '#return_value' => $status,
602 '#default_value' => $node->adstatus ? $node->adstatus : 'pending',
603 '#description' => $description,
604 '#parents' => array("adstatus")
605 );
606 }
607 }
608 }
609 else {
610 $adstatus = ad_status_array();
611 if (!isset($node->adstatus)) {
612 $node->adstatus = 'pending';
613 }
614 $form['ad_adstatus'] = array(
615 '#type' => 'fieldset',
616 '#title' => t('Status'),
617 '#collapsible' => TRUE
618 );
619 $form['ad_adstatus']['adstatus_display'] = array(
620 '#type' => 'markup',
621 '#value' => '<p><strong>'. t('Status') .':</strong> '. t($node->adstatus) .'<br />'. t($adstatus[$node->adstatus]),
622 );
623 $form['adstatus'] = array(
624 '#type' => 'value',
625 '#value' => $node->adstatus
626 ); 672 );
627 } 673 }
628 674
629 // display scheduling options 675 // display scheduling options
630 $form['schedule'] = array( 676 $form['schedule'] = array(
642 isset($node->maxclicks) || 688 isset($node->maxclicks) ||
643 isset($form_state['values']['maxclicks'])) 689 isset($form_state['values']['maxclicks']))
644 ? FALSE : TRUE, 690 ? FALSE : TRUE,
645 ); 691 );
646 692
647 if (ad_adaccess($node, 'manage status')) { 693 if ((isset($node->nid) && ad_permission($node->nid, 'manage status')) ||
694 user_access('administer advertisements')) {
648 $form['schedule']['current'] = array( 695 $form['schedule']['current'] = array(
649 '#type' => 'markup', 696 '#type' => 'markup',
650 '#prefix' => '<div>', 697 '#prefix' => '<div>',
651 '#suffix' => '</div>', 698 '#suffix' => '</div>',
652 '#value' => t('The current date and time is "%date".', array('%date' => format_date(time(), 'custom', 'F j, Y H:i'))) 699 '#value' => t('The current date and time is "%date".', array('%date' => format_date(time(), 'custom', 'F j, Y H:i')))
700 '#type' => 'hidden', 747 '#type' => 'hidden',
701 '#value' => isset($node->autoexpire) ? $node->autoexpire : 0, 748 '#value' => isset($node->autoexpire) ? $node->autoexpire : 0,
702 ); 749 );
703 } 750 }
704 751
752 $form['#validate'][] = 'ad_select_adtype';
705 return $form; 753 return $form;
706 } 754 }
707 755
708 /** 756 /**
757 * Ad type switch submit handler.
758 */
759 function ad_select_adtype(&$form, &$form_state) {
760 if (!$form_state['values']['adtype'] && !$form_state['values']['adtype_select']) {
761 form_set_error('adtype_select', t('Please, select an Ad type.'));
762 }
763 if (!isset($form_state['values']['adtype']) || isset($form_state['values']['adtype_select']) && $form_state['values']['adtype'] != $form_state['values']['adtype_select']) {
764 $form_state['values']['adtype'] = $form_state['values']['adtype_select'];
765 $form_state['rebuild'] = TRUE;
766 }
767 }
768
769 /**
770 * Ad type switch AHAH menu handler.
771 */
772 function ad_form_ahah() {
773 $form_state = array('storage' => NULL, 'submitted' => FALSE);
774 $form_build_id = $_POST['form_build_id'];
775 $form = form_get_cache($form_build_id, $form_state);
776 ad_form_add_adtype_elements($form, $_POST['adtype_select']);
777 form_set_cache($form_build_id, $form, $form_state);
778 $form += array(
779 '#post' => $_POST,
780 '#programmed' => FALSE,
781 );
782 // Rebuild the form.
783 $form = form_builder($_POST['form_id'], $form, $form_state);
784 $output = drupal_render($form['adtype_elements']);
785 drupal_json(array(
786 'status' => TRUE,
787 'data' => $output,
788 ));
789 }
790
791 /**
792 * Loads Ad type elements into form.
793 */
794 function ad_form_add_adtype_elements(&$form, $adtype, $node = NULL) {
795 unset($form['adtype_elements']);
796 $form['adtype_elements'] = module_invoke('ad_'. $adtype, 'adapi', 'form', $node);
797 $form['adtype'] = array(
798 '#type' => 'hidden',
799 '#value' => $adtype,
800 );
801 $form['adtype_elements']['#weight'] = 3.1;
802 }
803
804 /**
709 * Implementation of hook_form_alter(). 805 * Implementation of hook_form_alter().
710 */ 806 */
711 function ad_form_alter(&$form, &$form_state, $form_id) { 807 function ad_form_alter(&$form, &$form_state, $form_id) {
712 if ($form_id == 'ad_node_form') {
713 $adtypes = ad_get_types('data');
714 if (isset($form['adtype']) && isset($form['adtype']['#value'])) {
715 $adtype = $form['adtype']['#value'];
716 if (isset($adtypes[$adtype])) {
717 // Valid advertisement type selected.
718 return;
719 }
720 }
721 if (sizeof($adtypes) == 1) {
722 // Auto select the appropriate advertisement type.
723 drupal_goto('node/add/ad/'. key($adtypes));
724 }
725 else {
726 foreach ($adtypes as $key => $adtype) {
727 $out = '<dt>'. l($adtype['name'], "node/add/ad/$key", array('title' => t('Add a !key', array('!key' => $adtype['name'])))) .'</dt>';
728 $out .= '<dd>'. $adtype['description'] .'</dd>';
729 $item[$key] = $out;
730 }
731 if (isset($item)) {
732 $output = t('Choose from the following advertisement types:');
733 $output .= '<dl>'. implode('', $item) .'</dl>';
734 }
735 else {
736 $output = t('You are not allowed to create advertisements.');
737 }
738
739 $form = array();
740 $form['select'] = array(
741 '#value' => $output,
742 );
743 $form['#tree'] = FALSE;
744 $form['#programmed'] = FALSE;
745 }
746 }
747 if ($form_id == 'taxonomy_form_vocabulary') { 808 if ($form_id == 'taxonomy_form_vocabulary') {
748 // Remove taxonomy form options not applicable for ad groups. 809 // Remove taxonomy form options not applicable for ad groups.
749 if ($form['vid']['#value'] == _ad_get_vid()) { 810 if ($form['vid']['#value'] == _ad_get_vid()) {
750 $form['help_ad_vocab'] = array( 811 $form['help_ad_vocab'] = array(
751 '#value' => t('This vocabulary was automatically created for use by the ad module. Only applicable options are available.'), 812 '#value' => t('This vocabulary was automatically created for use by the ad module. Only applicable options are available.'),
782 } 843 }
783 } 844 }
784 } 845 }
785 846
786 /** 847 /**
787 * Submit handler for global settings of all ad types.
788 *
789 * @see ad_form_alter()
790 */
791 function ad_global_settings_submit($form, &$form_state) {
792 variable_set('ad_'. $form_state['values']['adtype'] .'_default_permissions', $form_state['values']['default_permissions']);
793 unset($form_state['values']['adtype'], $form_state['values']['default_permissions']);
794 }
795
796 /**
797 * Implementation of hook_nodeapi(). 848 * Implementation of hook_nodeapi().
798 */ 849 */
799 function ad_nodeapi(&$node, $op, $teaser, $page) { 850 function ad_nodeapi(&$node, $op, $teaser, $page) {
800 global $user; 851 global $user;
801 852
814 break; 865 break;
815 866
816 case 'insert': 867 case 'insert':
817 if (isset($node->adtype)) { 868 if (isset($node->adtype)) {
818 if ($node->status != 1 && $node->adstatus == 'active') { 869 if ($node->status != 1 && $node->adstatus == 'active') {
819 $node->adstatus = 'unpublished'; 870 $node->adstatus = 'expired';
820 } 871 }
821 $activated = $node->adstatus == 'active' ? time() : 0; 872 $activated = $node->adstatus == 'active' ? time() : 0;
822 if (!isset($node->autoactive)) { 873 if (!isset($node->autoactivate)) {
823 $node->autoactivate = 0; 874 $node->autoactivate = 0;
824 } 875 }
825 if (!isset($node->maxviews)) { 876 if (!isset($node->maxviews)) {
826 $node->maxviews = 0; 877 $node->maxviews = 0;
827 } 878 }
835 886
836 case 'update': 887 case 'update':
837 if (isset($node->adtype)) { 888 if (isset($node->adtype)) {
838 $ad = db_fetch_object(db_query('SELECT * FROM {ads} WHERE aid = %d', $node->nid)); 889 $ad = db_fetch_object(db_query('SELECT * FROM {ads} WHERE aid = %d', $node->nid));
839 // Ad must be in approved state to be able to autoactivate it. 890 // Ad must be in approved state to be able to autoactivate it.
840 if ($node->adstatus != 'approved' && $node->autoactivate) { 891 if ($node->adstatus != 'approved' && isset($node->autoactive) && $node->autoactivate) {
841 if ($node->adstatus == 'active') { 892 if ($node->adstatus == 'active') {
842 // This ad is already active, no need to autoactivate it. 893 // This ad is already active, no need to autoactivate it.
843 $node->autoactivate = 0; 894 $node->autoactivate = 0;
844 } 895 }
845 else { 896 else {
846 drupal_set_message(t('This ad will not be automatically activated at the scheduled time because it is not in the <em>approved</em> state.'), 'error'); 897 drupal_set_message(t('This ad will not be automatically activated at the scheduled time because it is not in the <em>approved</em> state.'), 'error');
847 } 898 }
848 } 899 }
849 // If this node has been upublished, the ad should no longer be active. 900 // If this node has been upublished, the ad should no longer be active.
850 if ($node->status != 1 && $node->adstatus == 'active') { 901 if ($node->status != 1 && $node->adstatus == 'active') {
851 $node->adstatus = 'unpublished'; 902 $node->adstatus = 'expired';
852 }
853 // If a previously unpublished node has been published, reactivate the
854 // the ad.
855 else if ($node->status == 1 && $node->adstatus == 'unpublished') {
856 $node->adstatus = 'active';
857 // Special "publish" event, may as well track it even though we'll
858 // next also record an "active" event.
859 ad_statistics_increment($node->nid, 'publish');
860 } 903 }
861 // Check if ad is being manually activated. 904 // Check if ad is being manually activated.
862 if ($ad->adstatus != 'active' && $node->adstatus == 'active') { 905 if ($ad->adstatus != 'active' && $node->adstatus == 'active') {
863 $activated = time(); 906 $activated = time();
864 } 907 }
865 // Check if ad is being manually expired. 908 // Check if ad is being manually expired.
866 else if ($ad->adstatus != 'expired' && $node->adstatus == 'expired') { 909 else if ($ad->adstatus != 'expired' && $node->adstatus == 'expired') {
867 // Ad has been manually expired. 910 // Ad has been manually expired.
911 $activated = $ad->activated;
868 $expired = time(); 912 $expired = time();
869 } 913 }
870 // Ad has not been manually activated or expired, preserve timestamps. 914 // Ad has not been manually activated or expired, preserve timestamps.
871 else { 915 else {
872 $activated = $ad->activated; 916 $activated = $ad->activated;
875 // Ad status has changed, record the event. 919 // Ad status has changed, record the event.
876 if ($ad->adstatus != $node->adstatus) { 920 if ($ad->adstatus != $node->adstatus) {
877 ad_statistics_increment($node->nid, $node->adstatus); 921 ad_statistics_increment($node->nid, $node->adstatus);
878 } 922 }
879 // Update ads table with new information. 923 // Update ads table with new information.
880 db_query("UPDATE {ads} SET uid = %d, adstatus = '%s', adtype = '%s', redirect = '%s', autoactivate = %d, autoexpire = %d, activated = %d, maxviews = %d, maxclicks = %d, expired = %d WHERE aid = %d", $node->uid, $node->adstatus, $node->adtype, url('ad/redirect/'. $node->nid, array('absolute' => TRUE)), isset($node->autoactivate) && $node->autoactivate > 0 ? strtotime($node->autoactivate) : '', isset($node->autoexpire) && $node->autoexpire > 0 ? strtotime($node->autoexpire) : '', $activated, isset($node->maxviews) ? (int)$node->maxviews : 0, isset($node->maxclicks) ? (int)$node->maxclicks : 0, isset($expired) ? $expired : 0, $node->nid); 924 db_query("UPDATE {ads} SET uid = %d, adstatus = '%s', adtype = '%s', redirect = '%s', autoactivate = %d, autoexpire = %d, activated = %d, maxviews = %d, maxclicks = %d, expired = %d WHERE aid = %d", $node->uid, $node->adstatus, $node->adtype, url('ad/redirect/'. $node->nid, array('absolute' => TRUE)), isset($node->autoactivate) && strlen($node->autoactivate) > 1 ? strtotime($node->autoactivate) : '', isset($node->autoexpire) && strlen($node->autoexpire) > 1 ? strtotime($node->autoexpire) : '', isset($activated) ? $activated : 0, isset($node->maxviews) ? (int)$node->maxviews : 0, isset($node->maxclicks) ? (int)$node->maxclicks : 0, isset($expired) ? $expired : 0, $node->nid);
881 ad_statistics_increment($node->nid, 'update'); 925 ad_statistics_increment($node->nid, 'update');
882 } 926 }
883 break; 927 break;
884 928
885 case 'delete': 929 case 'delete':
916 $function = "ad_cache_$cache" .'_adcacheapi'; 960 $function = "ad_cache_$cache" .'_adcacheapi';
917 if (function_exists($function)) { 961 if (function_exists($function)) {
918 $function($op, $node); 962 $function($op, $node);
919 } 963 }
920 } 964 }
965
966 // Rebuild the cache after all hooks are invoked.
967 switch ($op) {
968 case 'insert':
969 case 'update':
970 case 'delete':
971 if (variable_get('ad_cache_file_rebuild_realtime', 0) &&
972 isset($node->adtype)) {
973 ad_rebuild_cache();
974 }
975 }
921 } 976 }
922 977
923 function ad_adapi($op, $node = NULL) { 978 function ad_adapi($op, $node = NULL) {
924 switch ($op) { 979 switch ($op) {
925 case 'permissions': 980 case 'permissions':
926 return array('access statistics', 'access click history', 'manage status'); 981 return array(
982 'access statistics' => TRUE,
983 'access click history' => TRUE,
984 'set status as pending' => FALSE,
985 'set status as denied' => FALSE,
986 'set status from pending to approved' => FALSE,
987 'set status from pending to denied' => FALSE,
988 'set status from approved to active' => TRUE,
989 'set status from approved to offline' => TRUE,
990 'set status from active to offline' => TRUE,
991 'set status from active to expired' => FALSE,
992 'set status from offline to active' => TRUE,
993 'set status from offline to expired' => FALSE,
994 );
927 break; 995 break;
928 } 996 }
929 } 997 }
930 998
931 /** 999 /**
944 $items['admin/content/ad/list'] = array( 1012 $items['admin/content/ad/list'] = array(
945 'title' => 'List', 1013 'title' => 'List',
946 'page callback' => 'ad_admin_list', 1014 'page callback' => 'ad_admin_list',
947 'access arguments' => array('administer advertisements'), 1015 'access arguments' => array('administer advertisements'),
948 'type' => MENU_DEFAULT_LOCAL_TASK, 1016 'type' => MENU_DEFAULT_LOCAL_TASK,
949 'file' => 'ad.admin.inc',
950 );
951 $items['admin/content/ad/statistics'] = array(
952 'title' => 'Statistics',
953 'page callback' => 'drupal_get_form',
954 'page arguments' => array('ad_admin_statistics'),
955 'access arguments' => array('administer advertisements'),
956 'type' => MENU_LOCAL_TASK,
957 'weight' => 1,
958 'file' => 'ad.admin.inc', 1017 'file' => 'ad.admin.inc',
959 ); 1018 );
960 $items['admin/content/ad/configure'] = array( 1019 $items['admin/content/ad/configure'] = array(
961 'title' => 'Settings', 1020 'title' => 'Settings',
962 'page callback' => 'drupal_get_form', 1021 'page callback' => 'drupal_get_form',
964 'access arguments' => array('administer advertisements'), 1023 'access arguments' => array('administer advertisements'),
965 'type' => MENU_LOCAL_TASK, 1024 'type' => MENU_LOCAL_TASK,
966 'weight' => 3, 1025 'weight' => 3,
967 'file' => 'ad.admin.inc', 1026 'file' => 'ad.admin.inc',
968 ); 1027 );
1028 $items['node/add/ad/ahah'] = array(
1029 'access arguments' => array('create advertisements'),
1030 'page callback' => 'ad_form_ahah',
1031 'type' => MENU_CALLBACK,
1032 );
969 1033
970 ad_menu_add_global_settings($items); 1034 ad_menu_add_global_settings($items);
971 1035
972 $items['admin/content/ad/groups'] = array( 1036 $items['admin/content/ad/groups'] = array(
973 'title' => 'Ad groups', 1037 'title' => 'Ad groups',
1022 $items["node/%node/details/%"] = array( 1086 $items["node/%node/details/%"] = array(
1023 'title' => 'Click details', 1087 'title' => 'Click details',
1024 'page callback' => 'ad_click_details', 1088 'page callback' => 'ad_click_details',
1025 'page arguments' => array(1, 3), 1089 'page arguments' => array(1, 3),
1026 'access arguments' => array(1, 'access click history'), 1090 'access arguments' => array(1, 'access click history'),
1027 'access callback' => 'ad_adaccess', 1091 'access callback' => 'ad_permission',
1028 'type' => MENU_CALLBACK, 1092 'type' => MENU_CALLBACK,
1029 'file' => 'ad.pages.inc', 1093 'file' => 'ad.pages.inc',
1030 ); 1094 );
1031 $items["ad/redirect/%/%/%"] = array( 1095 $items["ad/redirect/%"] = array(
1032 'access arguments' => array('show advertisements'), 1096 'access arguments' => array('show advertisements'),
1033 'type' => MENU_CALLBACK, 1097 'type' => MENU_CALLBACK,
1034 'page callback' => 'ad_redirect', 1098 'page callback' => 'ad_redirect',
1035 'page arguments' => (array(2, 3, 4)), 1099 'page arguments' => (array(2)),
1036 );
1037 $items["ad/redirect/%/%"] = array(
1038 'access arguments' => array('show advertisements'),
1039 'type' => MENU_CALLBACK,
1040 'page callback' => 'ad_redirect',
1041 'page arguments' => (array(2, 3)),
1042 ); 1100 );
1043 1101
1044 return $items; 1102 return $items;
1045 } 1103 }
1046 1104
1051 function ad_menu_add_global_settings(&$menu_items) { 1109 function ad_menu_add_global_settings(&$menu_items) {
1052 $adtypes = ad_get_types(); 1110 $adtypes = ad_get_types();
1053 foreach ($adtypes as $type => $name) { 1111 foreach ($adtypes as $type => $name) {
1054 // Ad type global settings. 1112 // Ad type global settings.
1055 $settings = 'ad_'. $type .'_global_settings'; 1113 $settings = 'ad_'. $type .'_global_settings';
1114 $file = 'ad_image.module';
1056 if (!function_exists($settings)) { 1115 if (!function_exists($settings)) {
1057 $settings = 'ad_no_global_settings'; 1116 $settings = 'ad_no_global_settings';
1117 $file = 'ad.admin.inc';
1058 } 1118 }
1059 $menu_items['admin/content/ad/configure/'. $type] = array( 1119 $menu_items['admin/content/ad/configure/'. $type] = array(
1060 'title' => $name, 1120 'title' => $name,
1061 'page callback' => 'drupal_get_form', 1121 'page callback' => 'drupal_get_form',
1062 'page arguments' => array($settings), 1122 'page arguments' => array($settings),
1114 } 1174 }
1115 1175
1116 /** 1176 /**
1117 * Determine whether the user has a given privilege. 1177 * Determine whether the user has a given privilege.
1118 * 1178 *
1119 * @param $ad 1179 * @param $aid
1120 * Node object or aid of advertisement. 1180 * ID of advertisement.
1121 * @param $permission 1181 * @param $permission
1122 * Special Ad owners permission which should be checked (such as 'manage owners') 1182 * Permission string which should be checked (such as 'access click history')
1123 * @param $account 1183 * @param $account
1124 * User object, which are accessing the ad or current user by default. 1184 * User object, which are accessing the ad or current user by default.
1125 */ 1185 */
1126 function ad_adaccess($ad, $permission, $account = NULL) { 1186 function ad_permission($aid, $string, $account = NULL) {
1127 global $user; 1187 global $user;
1128 static $permissions = array(); 1188 $access = FALSE;
1129 1189
1190 // by default, check permission for current user
1130 if (!isset($account)) { 1191 if (!isset($account)) {
1131 $account = $user; 1192 $account = $user;
1132 } 1193 }
1133 1194
1134 // User #1 has all privileges: 1195 // user #1 has all privileges
1135 if ($account->uid == 1) { 1196 if ($account->uid == 1) {
1136 return TRUE; 1197 return TRUE;
1137 } 1198 }
1138 1199
1139 // If you have administer permissions, you have all permissions. 1200 // if you have administer permissions, you have all permissions
1140 if (user_access('administer advertisements', $account)) { 1201 if (user_access('administer advertisements', $account)) {
1141 return TRUE; 1202 return TRUE;
1142 } 1203 }
1143 1204
1144 // Handle ad owners access 1205 // when used in the Drupal menu, $aid may be the full ad object.
1145 if (module_exists('ad_owners')) { 1206 if (is_object($aid) && isset($aid->aid)) {
1146 return ad_owners_adaccess($ad, $permission, $account); 1207 $aid = $aid->aid;
1147 } 1208 }
1148 1209 else if (is_object($aid)) {
1149 return FALSE; 1210 watchdog('ad', 'Invalid aid object passed into ad_permission, no aid->aid set.');
1211 $aid = 0;
1212 }
1213
1214 // invoke ad_owners module to determine user's access
1215 if (module_exists('ad_owners') &&
1216 function_exists('ad_owners_permission')) {
1217 $access = ad_owners_permission($aid, $string, $account);
1218 }
1219 // no ad_owners module, allow acces to statistics and click history
1220 else if (in_array($string, array('access statistics', 'access click history'))) {
1221 $access = TRUE;
1222 }
1223 // with no ad_owners module, all other permissions are denied unless user
1224 // has 'administer advertisements' permission
1225 return $access;
1150 } 1226 }
1151 1227
1152 /** 1228 /**
1153 * Returns ad types data. 1229 * Returns ad types data.
1154 * 1230 *
1283 break; 1359 break;
1284 case 'mail_text': 1360 case 'mail_text':
1285 switch ($arg1) { 1361 switch ($arg1) {
1286 case 'expired': 1362 case 'expired':
1287 return array( 1363 return array(
1288 'subject' => t('[%sitename ad] %event notification'), 1364 'subject' => t('[%site-name ad] %event notification'),
1289 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" that was being displayed on the %sitename website has expired.\n\n Your advertisement was viewed %global_views times and clicked %global_clicks times since it was activated on %activated_large.\n\n You can view additional statistics about this advertisement or update this notification at the following url:\n %url\n\nRegards,\n The %sitename Team\n\n-\n%siteurl"), 1365 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" that was being displayed on the %site-name website has expired.\n\n Your advertisement was viewed %global_impressions times and clicked %global_clicks times since it was activated on %activated_large.\n\n You can view additional statistics about this advertisement or update this notification at the following url:\n %url\n\nRegards,\n The %site-name Team\n\n-\n%site-url"),
1290 ); 1366 );
1291 case '-expired': 1367 case '-expired':
1292 return array( 1368 return array(
1293 'subject' => t('[%sitename ad] expiration notification'), 1369 'subject' => t('[%site-name ad] expiration notification'),
1294 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" that is being displayed on the %sitename website will expire on %autoexpire_large.\n\n Your advertisement has been viewed %today_views times and clicked %today_clicks times today. It was viewed %yesterday_views times and clicked %yesterday_clicks times yesterday. It has been viewed %global_views times and clicked %global_clicks times since it was activated on %activated_large.\n\n You can view additional statistics about this advertisement or update this notification at the following url:\n %url\n\nRegards,\n The %sitename Team\n\n-\n%siteurl"), 1370 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" that is being displayed on the %site-name website will expire on %autoexpire_large.\n\n Your advertisement has been viewed %today_impressions times and clicked %today_clicks times today. It was viewed %yesterday_impressions times and clicked %yesterday_clicks times yesterday. It has been viewed %global_impressions times and clicked %global_clicks times since it was activated on %activated_large.\n\n You can view additional statistics about this advertisement or update this notification at the following url:\n %url\n\nRegards,\n The %site-name Team\n\n-\n%site-url"),
1295 ); 1371 );
1296 case 'active': 1372 case 'active':
1297 return array( 1373 return array(
1298 'subject' => t('[%sitename ad] %event notification'), 1374 'subject' => t('[%site-name ad] %event notification'),
1299 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" is now actively being displayed on the %sitename website.\n\n Your advertisement has been viewed %global_views times and clicked %global_clicks times since it was activated on %activated_large.\n\n You can view additional statistics about this advertisement or update this notification at the following url:\n %url\n\nRegards,\n The %sitename Team\n\n-\n%siteurl"), 1375 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" is now actively being displayed on the %site-name website.\n\n Your advertisement has been viewed %global_impressions times and clicked %global_clicks times since it was activated on %activated_large.\n\n You can view additional statistics about this advertisement or update this notification at the following url:\n %url\n\nRegards,\n The %site-name Team\n\n-\n%site-url"),
1300 ); 1376 );
1301 case '-active': 1377 case '-active':
1302 return array( 1378 return array(
1303 'subject' => t('[%sitename ad] activation notification'), 1379 'subject' => t('[%site-name ad] activation notification'),
1304 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" will be actively displayed on the %sitename website on %autoactivate_large.\n\n You can view statistics about this advertisement or update this notification at the following url:\n %url\n\nRegards,\n The %sitename Team\n\n-\n%siteurl"), 1380 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" will be actively displayed on the %site-name website on %autoactivate_large.\n\n You can view statistics about this advertisement or update this notification at the following url:\n %url\n\nRegards,\n The %site-name Team\n\n-\n%site-url"),
1305 ); 1381 );
1306 case 'click': 1382 case 'click':
1307 return array( 1383 return array(
1308 'subject' => t('[%sitename ad] %event notification'), 1384 'subject' => t('[%site-name ad] %event notification'),
1309 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" on the %sitename website has been clicked.\n\n Your advertisement has been viewed %today_views times and clicked %today_clicks times today. It was viewed %yesterday_views times and clicked %yesterday_clicks times yesterday. It has been viewed %global_views times and clicked %global_clicks times since it was activated on %activated_large.\n\n You will receive this %frequency You can view additional statistics about this advertisement or update this notification at the following url:\n %url\n\nRegards,\n The %sitename Team\n\n-\n%siteurl"), 1385 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" on the %site-name website has been clicked.\n\n Your advertisement has been viewed %today_impressions times and clicked %today_clicks times today. It was viewed %yesterday_impressions times and clicked %yesterday_clicks times yesterday. It has been viewed %global_impressions times and clicked %global_clicks times since it was activated on %activated_large.\n\n You will receive this %frequency You can view additional statistics about this advertisement or update this notification at the following url:\n %url\n\nRegards,\n The %site-name Team\n\n-\n%site-url"),
1310 ); 1386 );
1311 case 'approved': 1387 case 'approved':
1312 return array( 1388 return array(
1313 'subject' => t('[%sitename ad] %event notification'), 1389 'subject' => t('[%site-name ad] %event notification'),
1314 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" on the %sitename website has been approved.\n\n You can view statistics about this advertisement at the following url:\n %url\n\nRegards,\n The %sitename Team\n\n-\n%siteurl"), 1390 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" on the %site-name website has been approved.\n\n You can view statistics about this advertisement at the following url:\n %url\n\nRegards,\n The %site-name Team\n\n-\n%site-url"),
1315 ); 1391 );
1316 case 'denied': 1392 case 'denied':
1317 return array( 1393 return array(
1318 'subject' => t('[%sitename ad] %event notification'), 1394 'subject' => t('[%site-name ad] %event notification'),
1319 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" on the %sitename website has been denied and will not be displayed.\n\n You can view statistics about this advertisement at the following url:\n %url\n\nRegards,\n The %sitename Team\n\n-\n%siteurl"), 1395 'body' => t("Hello %owner_name,\n\n This is an automatically generated notification to inform you that your advertisement \"%title\" on the %site-name website has been denied and will not be displayed.\n\n You can view statistics about this advertisement at the following url:\n %url\n\nRegards,\n The %site-name Team\n\n-\n%site-url"),
1320 ); 1396 );
1321 } 1397 }
1322 break; 1398 break;
1323 } 1399 }
1324 } 1400 }