/[drupal]/contributions/modules/ad/adserve.php
ViewVC logotype

Contents of /contributions/modules/ad/adserve.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Tue Dec 26 08:10:19 2006 UTC (2 years, 11 months ago) by jeremy
Branch: MAIN
CVS Tags: DRUPAL-4-7--0-5, HEAD
Branch point for: DRUPAL-4-7
Changes since 1.1: +56 -49 lines
File MIME type: text/x-php
Implement schema for owners, permissions, notifications, and remote
hosts.  Move from Alpha to Beta status, meaning going forward an upgrade
path will be provided for schema changes.
 - ad.install
    o define ad_permissions table
    o define ad_owners table
    o define ad_notifications table
    o define ad_hosts table
 - ad.module
    o fix ad statistics to display even if none for current hour
    o implement statistics for current week
    o register unique hostid for each add owner for displaying ads
      remotely
    o enforce matching ad status and node status
    o only display clicks and statistics for ads, not all ad types
    o stub in support for ad owners, ad owner permissions and add owner
      notifications
    o display group name instead of just group id when listing ads
    o add regex in search for adserve.php to not match ie .swp files
 - adserve.php
    o implement cache types in switch statement
    o track hostid when viewing ads for displaying on remote sites
 - ad_text.module
    o use htmlentities() to encode ad text
1 <?php
2 // $Id: $
3
4 $debug = (int)$_GET['debug'];
5 $group = $_GET['group'];
6 $up = (int)$_GET['up'];
7 $cache = $_GET['cache'];
8 $hostid = $_GET['k'];
9
10 // Set defaults.
11 if (!$group) {
12 $group = 'default';
13 }
14 if (!$cache) {
15 $cache = 'database';
16 }
17
18 if ($debug) {
19 echo "Group: '$group'<br />";
20 echo "Updirs: '$up'<br />";
21 echo "Cache: '$cache'<br />";
22 echo "Host: '$hostid'<br />";
23 exit;
24 }
25
26 header("Content-Type: application/x-javascript; charset=utf-8");
27
28 // Move process to top level Drupal directory so we can perform a bootstrap.
29 for ($i = 1; $i <= $up; $i++) {
30 chdir('..');
31 }
32
33 switch ($cache) {
34 case 'database':
35 // Include just enough to make queries and to include other modules.
36 include_once './includes/bootstrap.inc';
37 include_once './includes/module.inc';
38 drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
39
40 // Query to randomly determine which ad to display.
41 $ad = db_fetch_object(db_query("SELECT a.aid, a.adtype, a.redirect FROM {ads} a INNER JOIN {ad_groups} g ON a.gid = g.gid WHERE a.adstatus = 'active' AND g.name = '%s' ORDER BY RAND() LIMIT 1", $group));
42 if (empty($ad)) {
43 echo "No ad found.";
44 return;
45 }
46
47 // Include appropriate module for displaying selected ad.
48 $module = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s'", "ad_$ad->adtype"));
49 include_once "$module";
50
51 print "document.write('". module_invoke("ad_$ad->adtype", 'display_ad', $ad) ."')";
52
53 // Update view statistics.
54 db_query("UPDATE {ad_statistics} SET count = count + 1 WHERE aid = %d AND action = 'view' AND date = %d AND hostid = '%s'", $ad->aid, date('YmdH'), $hostid);
55 // If column doesn't already exist, we need to add it.
56 if (!db_affected_rows()) {
57 db_query("INSERT INTO {ad_statistics} (aid, date, action, hostid, count) VALUES(%d, %d, 'view', '%s', 1)", $ad->aid, date('YmdH'), $hostid);
58 // If another process already added this row our INSERT will fail, if so
59 // we still need to increment it so we don't loose a view.
60 if (!db_affected_rows()) {
61 db_query("UPDATE {ad_statistics} SET count = count + 1 WHERE aid = %d AND action = 'view' AND date = %d AND hostid = '%s'", $ad->aid, date('YmdH'), $hostid);
62 }
63 }
64 break;
65
66 case 'file':
67 /**
68 * TODO: Implement file-based caching. Database caching is easier, so
69 * we'll start there.
70 */
71 print "document.write('The file cache is not implemented yet.')";
72
73 default:
74 /**
75 * TODO: The goal here is to provide alternative caching mechanisms without
76 * having to patch this file. The trick is in locating the required file
77 * that we will need to include and call into. Perhaps we will need to
78 * create hard rules (like 'the file needs to be in the top level directory,
79 * and named 'ad_cache_TYPE' where TYPE is replaced with the cache type.
80 * We can then simply call it and pass in all necessary arguments.
81 * Something like:
82 * $name = "ad_cache_$cache";
83 * include_once "$name.php";
84 * $name($group);
85 */
86 print "document.write('External cache types are not implemented yet.')";
87 }
88
89 ?>

  ViewVC Help
Powered by ViewVC 1.1.2