annotate adcache.inc @ 3:416ea999ed76 ad

maj ad version rc1
author sly
date Mon, 20 Apr 2009 09:49:37 +0000
parents e5584a19768b
children 6aeff3329e01
rev   line source
pierre@1 1 <?php
pierre@1 2
pierre@1 3 /**
pierre@1 4 * Wrapper for calling adserve_cache functions.
pierre@1 5 */
pierre@1 6 function adserve_cache() {
pierre@1 7 static $functions = array();
pierre@1 8 $args = func_get_args();
pierre@1 9 $function = array_shift($args);
pierre@1 10
pierre@1 11 _debug_echo("adserve_cache function($function)");
pierre@1 12
pierre@1 13 if (!isset($functions[$function])) {
pierre@1 14 $cache = adserve_variable('adcache');
pierre@1 15 $test = "ad_cache_{$cache}_$function";
pierre@1 16 if (!function_exists($test)) {
pierre@1 17 _debug_echo("Cache function '$test' does not exist.\n");
pierre@1 18 $test = "adserve_cache_$function";
pierre@1 19 }
pierre@1 20 $functions[$function] = $test;
pierre@1 21 }
pierre@1 22
pierre@1 23 if (function_exists($functions[$function])) {
pierre@1 24 _debug_memory();
pierre@1 25 _debug_echo("Invoking cache function '". $functions[$function] ."'.");
pierre@1 26 return call_user_func_array($functions[$function], $args);
pierre@1 27 }
pierre@1 28 else {
pierre@1 29 _debug_echo("Cache function '". $functions[$function] ."' does not exist.\n");
pierre@1 30 }
pierre@1 31 return array();
pierre@1 32 }
pierre@1 33
pierre@1 34 /**
pierre@1 35 * Invoke adserve cache hook, including files as necessary.
pierre@1 36 */
pierre@1 37 function adserve_invoke_hook() {
pierre@1 38 static $hooks = array();
pierre@1 39 $args = func_get_args();
pierre@1 40 $hook = array_shift($args);
pierre@1 41 $action = array_shift($args);
pierre@1 42
pierre@1 43 _debug_echo("adserve_invoke_hook hook($hook) action($action)");
pierre@1 44
pierre@1 45 if (!isset($hooks[$hook])) {
pierre@1 46 $hooks[$hook] = adserve_cache('hook', $hook);
pierre@1 47 if (is_array($hooks[$hook]) && !empty($hooks[$hook]) &&
pierre@1 48 is_array($hooks[$hook]['file'])) {
pierre@1 49 // Include all necessary files.
pierre@1 50 foreach ($hooks[$hook]['file'] as $files) {
pierre@1 51 if (is_array($files)) {
pierre@1 52 foreach ($files as $file) {
pierre@1 53 $include_file = adserve_variable('root_dir') .'/'. $file;
pierre@1 54 if (file_exists($include_file) && is_file($include_file)) {
pierre@1 55 _debug_echo("Including file: '$include_file'.");
pierre@1 56 include_once($include_file);
pierre@1 57 }
pierre@1 58 else {
pierre@1 59 _debug_echo("Failed to include file: '$include_file'.");
pierre@1 60 }
pierre@1 61 }
pierre@1 62 }
pierre@1 63 }
pierre@1 64 }
pierre@1 65 }
pierre@1 66
pierre@1 67 $return = array();
pierre@1 68 if (is_array($hooks[$hook]) && !empty($hooks[$hook]) &&
pierre@1 69 is_array($hooks[$hook]['function'])) {
pierre@1 70 foreach ($hooks[$hook]['function'] as $weight => $functions) {
pierre@1 71 foreach ($functions as $function) {
pierre@1 72 if (function_exists($function)) {
pierre@1 73 _debug_echo("Invoking '$function'.");
pierre@1 74 $return[] = call_user_func_array($function, $args);
pierre@1 75 }
pierre@1 76 else {
pierre@1 77 _debug_echo("Function '$function' does not exist.\n");
pierre@1 78 }
pierre@1 79 }
pierre@1 80 }
pierre@1 81 }
pierre@1 82 else {
pierre@1 83 $function = "adserve_hook_$hook";
pierre@1 84 if (function_exists($function)) {
pierre@1 85 _debug_echo("Invoking '$function'.");
pierre@1 86 $return[] = call_user_func_array($function, $args);
pierre@1 87 }
pierre@1 88 else {
pierre@1 89 _debug_echo("Function '$function' does not exist.\n");
pierre@1 90 }
pierre@1 91 }
pierre@1 92
pierre@1 93 switch ($action) {
pierre@1 94 case 'intersect':
pierre@1 95 if (sizeof($return) == 1) {
pierre@1 96 return $return[0];
pierre@1 97 }
pierre@1 98 else {
pierre@1 99 return call_user_func_array('array_intersect', $return);
pierre@1 100 }
pierre@1 101
pierre@1 102 case 'merge':
pierre@1 103 if (sizeof($return) == 1) {
pierre@1 104 return $return[0];
pierre@1 105 }
pierre@1 106 else {
pierre@1 107 $merge = array();
pierre@1 108 foreach ($return as $array) {
pierre@1 109 $merge += $array;
pierre@1 110 }
pierre@1 111 return $merge;
pierre@1 112 }
pierre@1 113
pierre@1 114 case 'first':
pierre@1 115 foreach ($return as $item) {
pierre@1 116 if (is_array($item) && !empty($item)) {
pierre@1 117 return $item;
pierre@1 118 }
pierre@1 119 }
pierre@1 120 return array();
pierre@1 121
pierre@1 122 case 'append':
pierre@1 123 $append = '';
pierre@1 124 foreach ($return as $item) {
pierre@1 125 if (!is_array($item)) {
pierre@1 126 $append .= $item;
pierre@1 127 }
pierre@1 128 }
pierre@1 129 return $append;
pierre@1 130
pierre@1 131 default:
pierre@1 132 case 'raw':
pierre@1 133 default:
pierre@1 134 return $return;
pierre@1 135 }
pierre@1 136 }
pierre@1 137
pierre@1 138 /** Cache functions **/
pierre@1 139
pierre@1 140 /**
pierre@1 141 * Default initialization function, fully bootstraps Drupal to gain access to
pierre@1 142 * the database.
pierre@1 143 */
pierre@1 144 function adserve_cache_open() {
pierre@1 145 adserve_bootstrap();
pierre@1 146 }
pierre@1 147
pierre@1 148 /**
pierre@1 149 * Build and return the cache.
pierre@1 150 * TODO: It's expensive to build the cache each time we serve an ad, this should
pierre@1 151 * be cached in the database, not in a static.
pierre@1 152 */
pierre@1 153 function adserve_cache_get_cache($data = NULL) {
pierre@1 154 static $cache = NULL;
pierre@1 155 // if we don't the the cache yet, build it
pierre@1 156 if (is_null($cache)) {
pierre@1 157 $cache = module_invoke_all('ad_build_cache');
pierre@1 158 }
pierre@1 159
pierre@1 160 if ($data) {
pierre@1 161 if (isset($cache[$data])) {
pierre@1 162 return $cache[$data];
pierre@1 163 }
pierre@1 164 else {
pierre@1 165 return NULL;
pierre@1 166 }
pierre@1 167 }
pierre@1 168 return $cache;
pierre@1 169 }
pierre@1 170
pierre@1 171 /**
pierre@1 172 * Invoke the appropraite hook.
pierre@1 173 */
pierre@1 174 function adserve_cache_hook($hook) {
pierre@1 175 static $cache = NULL;
pierre@1 176 // if we don't have the cache yet, build it
pierre@1 177 if (is_null($cache)) {
pierre@1 178 $external = adserve_cache('get_cache');
pierre@1 179 $cache = adserve_cache('build_hooks', $external);
pierre@1 180 }
pierre@1 181
pierre@1 182 // return hook definition, if exists
pierre@1 183 if (is_array($cache) && isset($cache["hook_$hook"]) && is_array($cache["hook_$hook"])) {
pierre@1 184 _debug_echo("Invoking hook '$hook'.");
pierre@1 185 return $cache["hook_$hook"];
pierre@1 186 }
pierre@1 187 _debug_echo("Did not find hook '$hook'.");
pierre@1 188 }
pierre@1 189
pierre@1 190 /**
pierre@1 191 * Helper function to build hook tree.
pierre@1 192 */
pierre@1 193 function adserve_cache_build_hooks($cache) {
pierre@1 194 $return = array();
pierre@1 195 if (is_array($cache)) {
pierre@1 196 foreach ($cache as $module => $hooks) {
pierre@1 197 // supported cache hooks
pierre@1 198 foreach (array('hook_init', 'hook_filter', 'hook_weight', 'hook_select',
pierre@1 199 'hook_init_text', 'hook_exit_text',
pierre@1 200 'hook_increment_extra') as $hook) {
pierre@1 201 if (isset($hooks[$hook]) && is_array($hooks[$hook])) {
pierre@1 202 $weight = isset($hooks[$hook]['weight']) ? (int)$hooks[$hook]['weight'] : 0;
pierre@1 203 $return[$hook]['file'][$weight][] = $hooks[$hook]['file'];
pierre@1 204 $return[$hook]['function'][$weight][] = $hooks[$hook]['function'];
pierre@1 205 }
pierre@1 206 }
pierre@1 207 }
pierre@1 208 }
pierre@1 209 return $return;
pierre@1 210 }
pierre@1 211
pierre@1 212 /**
pierre@1 213 * Default function for retrieving list of ids.
pierre@1 214 */
pierre@1 215 function adserve_cache_id($type, $id) {
pierre@1 216 switch ($type) {
pierre@1 217 case 'nids':
pierre@1 218 $result = db_query("SELECT aid FROM {ads} WHERE adstatus = 'active' AND aid IN(%d)", $id);
pierre@1 219 break;
pierre@1 220 case 'tids':
pierre@1 221 $result = db_query("SELECT a.aid FROM {ads} a INNER JOIN {term_node} n ON a.aid = n.nid WHERE a.adstatus = 'active' AND n.tid IN(%d)", $id);
pierre@1 222 break;
pierre@1 223 case 'default':
pierre@1 224 $result = db_query("SELECT a.aid FROM {ads} a LEFT JOIN {term_node} n ON a.aid = n.nid WHERE a.adstatus = 'active' AND n.tid IS NULL");
pierre@1 225 break;
pierre@1 226 default:
pierre@1 227 _debug_echo("Unsupported type '$type'.");
pierre@1 228 }
pierre@1 229
pierre@1 230 $ids = array();
pierre@1 231 if (isset($result)) {
pierre@1 232 while ($ad = db_fetch_object($result)) {
pierre@1 233 $ids[$ad->aid] = $ad->aid;
pierre@1 234 }
pierre@1 235 }
pierre@1 236 return $ids;
pierre@1 237 }
pierre@1 238
pierre@1 239 /**
pierre@1 240 * Support filter hooks.
pierre@1 241 */
pierre@1 242 function adserve_hook_filter($ids, $hostid) {
pierre@1 243 return $ids;
pierre@1 244 }
pierre@1 245
pierre@1 246 /**
pierre@1 247 * Support weight hooks.
pierre@1 248 */
pierre@1 249 function adserve_hook_weight($ids, $hostid) {
pierre@1 250 return $ids;
pierre@1 251 }
pierre@1 252
pierre@1 253 /**
pierre@1 254 * Load and display an advertisement directly from the database.
pierre@1 255 */
pierre@1 256 function adserve_cache_display_ad($id) {
pierre@1 257 static $modules = array();
pierre@1 258
pierre@1 259 $ad = node_load($id);
pierre@1 260 if (!isset($modules[$ad->adtype])) {
pierre@1 261 $modules[$ad->adtype] = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s'", "ad_$ad->adtype"));
pierre@1 262 }
pierre@1 263 _debug_echo("Ad type '$ad->adtype', loading module '". $modules[$ad->adtype] ."'");
pierre@1 264 return module_invoke("ad_$ad->adtype", 'display_ad', $ad);
pierre@1 265 }
pierre@1 266
pierre@1 267 /**
pierre@1 268 * Validate aids.
pierre@1 269 */
pierre@1 270 function adserve_cache_validate($aids, $displayed, $hostid) {
pierre@1 271 $valid = array();
pierre@1 272 foreach ($aids as $aid) {
pierre@1 273 if (!in_array($aid, $displayed)) {
pierre@1 274 $valid[] = $aid;
pierre@1 275 }
pierre@1 276 }
pierre@1 277 return $valid;
pierre@1 278 }
pierre@1 279
pierre@1 280 /**
pierre@1 281 * Increment action directly in the database.
pierre@1 282 */
pierre@1 283 function adserve_cache_increment($action, $aid) {
pierre@1 284 $hostid = adserve_variable('hostid');
sly@2 285 _debug_echo("adserve_cache_increment action($action) aid($aid) hostid($hostid)");
pierre@1 286
pierre@1 287 // be sure that drupal is bootstrapped
pierre@1 288 adserve_bootstrap();
pierre@1 289
pierre@1 290 // allow add-on modules to implement their own statistics granularity
pierre@1 291 $extra = adserve_invoke_hook('increment_extra', 'merge', $action, $aid);
pierre@1 292 if (is_array($extra)) {
pierre@1 293 $extra = implode('|,|', $extra);
pierre@1 294 }
pierre@1 295 adserve_variable('extra', $extra);
sly@2 296 _debug_echo("adserve_cache_increment extra($extra)");
pierre@1 297
pierre@1 298 // update statistics
pierre@1 299 db_query("UPDATE {ad_statistics} SET count = count + 1 WHERE aid = %d AND action = '%s' AND date = %d AND adgroup = '%s' AND extra = '%s' AND hostid = '%s'", $aid, $action, date('YmdH'), adserve_variable('group'), $extra, $hostid);
pierre@1 300 // if column doesn't already exist, add it
pierre@1 301 if (!db_affected_rows()) {
pierre@1 302 db_query("INSERT INTO {ad_statistics} (aid, date, action, adgroup, extra, hostid, count) VALUES(%d, %d, '%s', '%s', '%s', '%s', 1)", $aid, date('YmdH'), $action, adserve_variable('group'), $extra, $hostid);
pierre@1 303 if (!db_affected_rows()) {
pierre@1 304 // we lost a race to add it, increment it
pierre@1 305 db_query("UPDATE {ad_statistics} SET count = count + 1 WHERE aid = %d AND action = '%s' AND date = %d AND adgroup = '%s' AND extra = '%s' AND hostid = '%s'", $aid, $action, date('YmdH'), adserve_variable('group'), $extra, $hostid);
pierre@1 306 }
pierre@1 307 }
pierre@1 308
pierre@1 309 if ($action == 'view') {
pierre@1 310 $ad = db_fetch_object(db_query('SELECT maxviews, activated FROM {ads} WHERE aid = %d', $aid));
pierre@1 311 // See if we need to perform additional queries.
pierre@1 312 if ($ad->maxviews) {
pierre@1 313 $views = (int)db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d", $aid, date('YmdH', $ad->activated)));
pierre@1 314 if ($views >= $ad->maxviews) {
pierre@1 315 db_query("UPDATE {ads} SET adstatus = 'expired', autoexpire = 0, autoexpired = %d, expired = %d WHERE aid = %d", time(), time(), $aid);
pierre@1 316 ad_statistics_increment('autoexpired', $aid);
pierre@1 317 ad_statistics_increment('expired', $aid);
pierre@1 318 }
pierre@1 319 }
pierre@1 320 }
pierre@1 321 }
pierre@1 322
pierre@1 323 /**
pierre@1 324 * Randomly select advertisements.
pierre@1 325 * @param array, valid ad ids.
pierre@1 326 * @param integer, how many advertisements to select
pierre@1 327 * @param string, the hostid
pierre@1 328 */
pierre@1 329 function adserve_hook_select($ids, $quantity = 1, $hostid = '') {
pierre@1 330 $select = 0;
pierre@1 331 $selected = array();
pierre@1 332 if (is_array($ids)) {
pierre@1 333 $ads = $ids;
pierre@1 334 foreach ($ids as $key => $value) {
pierre@1 335 $available = sizeof($ads);
pierre@1 336 $select++;
pierre@1 337 _debug_echo("Randomly selecting ad $select of $quantity.");
pierre@1 338 $id = 0;
pierre@1 339 if ($id == 0) {
pierre@1 340 $id = $available > 1 ? $ads[mt_rand(0, $available - 1)] : $ads[0];
pierre@1 341 _debug_echo("Randomly selected ID: $id.");
pierre@1 342 $selected[] = $id;
pierre@1 343 // strip away advertisments that have already been selected
pierre@1 344 $ads = adserve_cache('validate', $ads, array($id), $hostid);
pierre@1 345 }
pierre@1 346 if (($quantity == $select) || !count($ads)) {
pierre@1 347 // we have selected the right number of advertisements
pierre@1 348 break;
pierre@1 349 }
pierre@1 350 }
pierre@1 351 }
pierre@1 352 if ($select < $quantity) {
pierre@1 353 _debug_echo('No more advertisements available.');
pierre@1 354 }
pierre@1 355 return $selected;
pierre@1 356 }
pierre@1 357 /**
pierre@1 358 * Default wrapper function for displaying advertisements. This generally
pierre@1 359 * is not replaced by ad caches modules.
pierre@1 360 */
pierre@1 361 function adserve_cache_get_ad_ids() {
pierre@1 362 static $displayed_count = 0;
pierre@1 363 _debug_echo('Entering default adserve_display.');
pierre@1 364
pierre@1 365 // open the cache
pierre@1 366 adserve_cache('open');
pierre@1 367
pierre@1 368 $hostid = adserve_variable('hostid') ? adserve_variable('hostid') : 'none';
pierre@1 369 _debug_echo("Hostid: '$hostid'.");
pierre@1 370
pierre@1 371 // invoke hook_init
pierre@1 372 $init = adserve_invoke_hook('init', 'first', $hostid);
pierre@1 373
pierre@1 374 // start with list of advertisements provided externally
pierre@1 375 if (is_array($init) && !empty($init)) {
pierre@1 376 _debug_echo('Initialized externally.');
pierre@1 377 $quantity = $init['quantity'];
pierre@1 378 $id = $init['id'];
pierre@1 379 $aids = explode(',', $id);
pierre@1 380 $type = $init['type'];
pierre@1 381 }
pierre@1 382 else {
pierre@1 383 // build list of ad ids to choose from
pierre@1 384 $quantity = adserve_variable('quantity');
pierre@1 385 // use list for specific host
pierre@1 386 if ($ids = adserve_cache('id', 'host', NULL, $hostid)) {
pierre@1 387 $id = implode(',', $ids);
pierre@1 388 $type = 'host';
pierre@1 389 }
pierre@1 390 // use list of node ids
pierre@1 391 else if ($id = adserve_variable('nids')) {
pierre@1 392 $type = 'nids';
pierre@1 393 adserve_variable('group', "n$id");
pierre@1 394 }
pierre@1 395 // use list of group ids
pierre@1 396 else if ($id = adserve_variable('tids')) {
pierre@1 397 $type = 'tids';
pierre@1 398 adserve_variable('group', "t$id");
pierre@1 399 }
pierre@1 400 // use list without group ids
pierre@1 401 else {
pierre@1 402 $id = 0;
pierre@1 403 $type = 'default';
pierre@1 404 adserve_variable('group', "$id");
pierre@1 405 }
pierre@1 406 _debug_echo("Searching $type: $id");
pierre@1 407 $aids = adserve_cache('id', $type, $id, $hostid);
pierre@1 408 }
pierre@1 409
pierre@1 410 // prepare to select advertisements
pierre@1 411 $number_of_ads = sizeof($aids);
pierre@1 412 _debug_echo("Total ads: '$number_of_ads'.");
pierre@1 413
pierre@1 414 $displayed = adserve_variable("$type-displayed");
pierre@1 415 if (!is_array($displayed)) {
pierre@1 416 $displayed = array();
pierre@1 417 }
pierre@1 418 _debug_echo('Already displayed: '. sizeof($displayed));
pierre@1 419
pierre@1 420 // validate available advertisements
pierre@1 421 $aids = adserve_cache('validate', $aids, $displayed, $hostid);
pierre@1 422 $number_of_ads = sizeof($aids);
pierre@1 423 _debug_echo("Validated ads: '$number_of_ads'.");
pierre@1 424
pierre@1 425 // filter advertisements
pierre@1 426 $aids = adserve_invoke_hook('filter', 'intersect', $aids, $hostid);
pierre@1 427 $number_of_ads = sizeof($aids);
pierre@1 428 _debug_echo("Filtered ads: '$number_of_ads'.");
pierre@1 429
pierre@1 430
pierre@1 431 // apply weight to advertisements
pierre@1 432 $aids = adserve_invoke_hook('weight', 'first', $aids, $hostid);
pierre@1 433 $number_of_ads = sizeof($aids);
pierre@1 434 _debug_echo("Weighted ads: '$number_of_ads'.");
pierre@1 435
pierre@1 436 // select advertisements
pierre@1 437 $aids = adserve_invoke_hook('select', 'first', $aids, $quantity, $hostid);
pierre@1 438 $number_of_ads = sizeof($aids);
pierre@1 439 _debug_echo("Selected ads: '$number_of_ads'.");
pierre@1 440
pierre@1 441 // track which advertisements have been "displayed"
pierre@1 442 adserve_variable("$type-displayed", array_merge($aids, $displayed));
pierre@1 443
pierre@1 444 return $aids;
pierre@1 445 }
pierre@1 446
pierre@1 447 /**
pierre@1 448 * Default function for displaying advertisements. This is not generally
pierre@1 449 * replaced by ad cache modules.
pierre@1 450 */
pierre@1 451 function adserve_cache_display($ids) {
pierre@1 452 $output = '';
pierre@1 453 $ads = 0;
pierre@1 454 foreach ($ids as $id) {
pierre@1 455 $ad = adserve_cache('display_ad', $id);
pierre@1 456 _debug_echo('ad: '. htmlentities($ad));
pierre@1 457 // if displaying multiple ads, separate each with a div
pierre@1 458 if ($output) {
pierre@1 459 $group = adserve_variable('group');
pierre@1 460 $output .= "<div class=\"advertisement-space\" id=\"space-$group-$ads\"></div>";
pierre@1 461 }
pierre@1 462 // display advertisement
pierre@1 463 $output .= $ad;
pierre@1 464 // increment counters
pierre@1 465 if (adserve_variable('ad_display') == 'raw') {
sly@2 466 $output .= ad_display_image($id);
pierre@1 467 }
pierre@1 468 else {
pierre@1 469 adserve_cache('increment', 'view', $id);
pierre@1 470 }
pierre@1 471 $ads++;
pierre@1 472 }
pierre@1 473
pierre@1 474 if (empty($ids)) {
pierre@1 475 adserve_variable('error', TRUE);
pierre@1 476 $output = 'No active ads were found in '. adserve_variable('group');
pierre@1 477 adserve_cache('increment', 'count', NULL);
pierre@1 478 }
pierre@1 479
pierre@1 480 // close/update cache, if necessary
pierre@1 481 adserve_cache('close');
pierre@1 482
pierre@1 483 // update the dynamic portion of the output
pierre@1 484 $params = array();
pierre@1 485 $group = adserve_variable('group');
pierre@1 486 $replace = "/$group";
pierre@1 487 if ($hostid = adserve_variable('hostid')) {
pierre@1 488 $params[] = "hostid=$hostid";
pierre@1 489 }
pierre@1 490 if ($url = htmlentities(adserve_variable('url'))) {
pierre@1 491 $params[] = "url=$url";
pierre@1 492 }
pierre@1 493 if ($extra = adserve_variable('extra')) {
pierre@1 494 $params[] = "extra=$extra";
pierre@1 495 }
pierre@1 496 if (!empty($params)) {
pierre@1 497 $replace .= '?'. implode('&', $params);
pierre@1 498 }
pierre@1 499 $output = preg_replace('&/@HOSTID___&', $replace, $output);
pierre@1 500
pierre@1 501 // there was an error, hide the output in comments
pierre@1 502 if (adserve_variable('error')) {
pierre@1 503 $output = "<!-- $output -->";
pierre@1 504 }
pierre@1 505
pierre@1 506 // allow custom text to be displayed before and after advertisement
pierre@1 507 $init_text = adserve_invoke_hook('init_text', 'append');
pierre@1 508 $exit_text = adserve_invoke_hook('exit_text', 'append');
pierre@1 509 $output = $init_text . $output . $exit_text;
pierre@1 510
pierre@1 511 _debug_memory();
pierre@1 512
pierre@1 513 // TODO: turn all of these into hooks
pierre@1 514 switch (adserve_variable('ad_display')) {
pierre@1 515 case 'javascript':
pierre@1 516 default:
pierre@1 517 $output = str_replace(array("\r", "\n", "<", ">", "&"),
pierre@1 518 array('\r', '\n', '\x3c', '\x3e', '\x26'),
pierre@1 519 addslashes($output));
pierre@1 520 if (!adserve_variable('debug')) {
pierre@1 521 // Tell the web browser not to cache this script so the ad refreshes
pierre@1 522 // each time the page is viewed.
pierre@1 523 // Expires in the past:
pierre@1 524 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
pierre@1 525 // Last load:
pierre@1 526 header('Last-Modified: '. gmdate('D, d M Y H:i:s') .' GMT');
pierre@1 527 // HTTP 1.1:
pierre@1 528 header('Cache-Control: no-store, no-cache, must-revalidate');
pierre@1 529 header('Cache-Control: post-check=0, pre-check=0', false);
pierre@1 530 // HTTP 1.0:
pierre@1 531 header('Pragma: no-cache');
pierre@1 532 // Output is a JavaScript:
pierre@1 533 header('Content-Type: application/x-javascript; charset=utf-8');
pierre@1 534 }
pierre@1 535 print "document.write('$output');";
pierre@1 536 exit(0);
pierre@1 537 case 'iframe':
pierre@1 538 case 'jquery':
pierre@1 539 if (!adserve_variable('debug')) {
pierre@1 540 // Tell the web browser not to cache this frame so the ad refreshes
pierre@1 541 // each time the page is viewed.
pierre@1 542
pierre@1 543 // Expires in the past:
pierre@1 544 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
pierre@1 545 // Last load:
pierre@1 546 header('Last-Modified: '. gmdate('D, d M Y H:i:s') .' GMT');
pierre@1 547 // HTTP 1.1:
pierre@1 548 header('Cache-Control: no-store, no-cache, must-revalidate');
pierre@1 549 header('Cache-Control: post-check=0, pre-check=0', false);
pierre@1 550 // HTTP 1.0:
pierre@1 551 header('Pragma: no-cache');
pierre@1 552 }
pierre@1 553 else {
pierre@1 554 _debug_echo('Output: '. htmlentities($output));
pierre@1 555 }
pierre@1 556 print "$output";
pierre@1 557 exit(0);
pierre@1 558 case 'raw':
pierre@1 559 _debug_echo('Output: '. htmlentities($output));
pierre@1 560 chdir(adserve_variable('ad_dir'));
pierre@1 561 return $output;
pierre@1 562
pierre@1 563 }
pierre@1 564
pierre@1 565 _debug_echo('Output: '. htmlentities($output));
pierre@1 566 return $output;
pierre@1 567 }
pierre@1 568