/
adview.php
316 lines (232 loc) · 8.79 KB
/
adview.php
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?php // $Revision: 2.14 $
/************************************************************************/
/* phpAdsNew 2 */
/* =========== */
/* */
/* Copyright (c) 2000-2002 by the phpAdsNew developers */
/* For more information visit: http://www.phpadsnew.com */
/* */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License. */
/************************************************************************/
// Figure out our location
define ('phpAds_path', '.');
/*********************************************************/
/* Include required files */
/*********************************************************/
require (phpAds_path."/config.inc.php");
require_once (phpAds_path."/libraries/lib-io.inc.php");
require (phpAds_path."/libraries/lib-db.inc.php");
if ($phpAds_config['log_adviews'] || $phpAds_config['acl'])
{
require (phpAds_path."/libraries/lib-remotehost.inc.php");
if ($phpAds_config['log_adviews'])
require (phpAds_path."/libraries/lib-log.inc.php");
if ($phpAds_config['acl'])
require (phpAds_path."/libraries/lib-limitations.inc.php");
}
require (phpAds_path."/libraries/lib-cache.inc.php");
/*********************************************************/
/* Register input variables */
/*********************************************************/
phpAds_registerGlobal (
'campaignid'
,'clientid'
,'clientID'
,'source'
,'n'
,'what'
,'referer'
);
/*********************************************************/
/* Main code */
/*********************************************************/
// Determine the user ID
$userid = phpAds_getUniqueUserID();
// Send the user ID
phpAds_setCookie("phpAds_id", $userid, time()+365*24*60*60);
$url = parse_url($phpAds_config['url_prefix']);
if (!isset($campaignid)) $campaignid = 0;
if (isset($clientID) && !isset($clientid)) $clientid = $clientID;
if (!isset($clientid)) $clientid = 0;
if (!isset($n)) $n = 'default';
if (!isset($source)) $source = '';
if (!isset($what)) $what = '';
$source = phpAds_deriveSource($source);
// Remove referer, to be sure it doesn't cause problems with limitations
if (isset($HTTP_SERVER_VARS['HTTP_REFERER'])) unset($HTTP_SERVER_VARS['HTTP_REFERER']);
if (isset($HTTP_REFERER)) unset($HTTP_REFERER);
if (phpAds_dbConnect())
{
mt_srand(floor((isset($n) && strlen($n) > 5 ? hexdec($n[0].$n[2].$n[3].$n[4].$n[5]): 1000000) * (double)microtime()));
// Reset followed zone chain
$phpAds_followedChain = array();
$found = false;
$first = true;
while (($first || $what != '') && $found == false)
{
$first = false;
if (substr($what,0,5) == 'zone:')
{
if (!defined('LIBVIEWZONE_INCLUDED'))
require (phpAds_path.'/libraries/lib-view-zone.inc.php');
$row = phpAds_fetchBannerZone($what, $clientid, $campaignid, '', $source, false);
}
else
{
if (!defined('LIBVIEWQUERY_INCLUDED'))
require (phpAds_path.'/libraries/lib-view-query.inc.php');
if (!defined('LIBVIEWDIRECT_INCLUDED'))
require (phpAds_path.'/libraries/lib-view-direct.inc.php');
$row = phpAds_fetchBannerDirect($what, $clientid, $campaignid, '', $source, false);
}
if (is_array ($row))
$found = true;
else
$what = $row;
}
}
else
{
$found = false;
}
if ($found)
{
// Log this impression
if (!phpAds_isViewBlocked($row['bannerid']))
{
if ($phpAds_config['log_adviews'])
phpAds_logImpression ($userid, $row['bannerid'], $row['zoneid'], $source);
// Send block cookies
phpAds_updateViewBlockTime($row['bannerid']);
}
// Block
phpAds_updateAdBlockTime($row['bannerid'], $row['block']);
// Set capping
phpAds_updateAdCapping($row['bannerid'], $row['capping'], $row['session_capping']);
// Set geotracking
phpAds_updateGeoTracking($phpAds_geo);
// Send bannerid headers
$cookie = array();
$cookie['bannerid'] = $row["bannerid"];
// Send zoneid headers
if ($row['zoneid'] != 0)
$cookie['zoneid'] = $row['zoneid'];
// Send source headers
if (isset($source) && $source != '')
$cookie['source'] = $source;
switch ($row['storagetype'])
{
case 'url':
$row['imageurl'] = str_replace ('{timestamp}', time(), $row['imageurl']);
$row['url'] = str_replace ('{timestamp}', time(), $row['url']);
// Replace random
if (preg_match ('#\{random(:([0-9]+)){0,1}\}#i', $row['imageurl'], $matches))
{
if ($matches[2])
$lastdigits = $matches[2];
else
$lastdigits = 8;
$lastrandom = '';
for ($r=0; $r<$lastdigits; $r=$r+9)
$lastrandom .= (string)mt_rand (111111111, 999999999);
$lastrandom = substr($lastrandom, 0 - $lastdigits);
$row['imageurl'] = str_replace ($matches[0], $lastrandom, $row['imageurl']);
}
if (preg_match ('#\{random(:([0-9]+)){0,1}\}#i', $row['url'], $matches))
{
if ($matches[2])
$randomdigits = $matches[2];
else
$randomdigits = 8;
if (isset($lastdigits) && $lastdigits == $randomdigits)
$randomnumber = $lastrandom;
else
{
$randomnumber = '';
for ($r=0; $r<$randomdigits; $r=$r+9)
$randomnumber .= (string)mt_rand (111111111, 999999999);
$randomnumber = substr($randomnumber, 0 - $randomdigits);
}
$row['url'] = str_replace ($matches[0], $randomnumber, $row['url']);
}
// Store destination URL
$cookie['dest'] = $row['url'];
// Redirect to the banner
phpAds_setCookie ("phpAds_banner[".$n."]", serialize($cookie), 0);
phpAds_flushCookie ();
if ($HTTP_SERVER_VARS['SERVER_PORT'] == 443)
$row['imageurl'] = str_replace ($phpAds_config['type_web_url'], $phpAds_config['type_web_ssl_url'], $row['imageurl']);
header ("Location: ".$row['imageurl']);
break;
case 'web':
$cookie['dest'] = $row['url'];
// Redirect to the banner
phpAds_setCookie ("phpAds_banner[".$n."]", serialize($cookie), 0);
phpAds_flushCookie ();
if ($HTTP_SERVER_VARS['SERVER_PORT'] == 443)
$phpAds_config['type_web_url'] = $phpAds_config['type_web_ssl_url'];
$row['imageurl'] = str_replace ('{image_url_prefix}', $phpAds_config['type_web_url'], $row['imageurl']);
header ("Location: ".$row['imageurl']);
break;
case 'sql':
$cookie['dest'] = $row['url'];
if (preg_match ("#Mozilla/(1|2|3|4)#", $HTTP_SERVER_VARS['HTTP_USER_AGENT']) && !preg_match("#compatible#", $HTTP_SERVER_VARS['HTTP_USER_AGENT']))
{
// Workaround for Netscape 4 problem
// with animated GIFs. Redirect to
// adimage to prevent banner changing
// at the end of each animation loop
phpAds_setCookie ("phpAds_banner[".$n."]", serialize($cookie), 0);
phpAds_flushCookie ();
if ($HTTP_SERVER_VARS['SERVER_PORT'] == 443) $phpAds_config['url_prefix'] = str_replace ('http://', 'https://', $phpAds_config['url_prefix']);
header ("Location: ".str_replace('{url_prefix}', $phpAds_config['url_prefix'], $row['imageurl']));
}
else
{
// Workaround for IE 4-5.5 problem
// Load the banner from the database
// and show the image directly to prevent
// broken images when shown during a
// form submit
$res = phpAds_dbQuery("
SELECT
contents
FROM
".$phpAds_config['tbl_images']."
WHERE
filename = '".$row['filename']."'
");
if ($image = phpAds_dbFetchArray($res))
{
phpAds_setCookie ("phpAds_banner[".$n."]", serialize($cookie), 0);
phpAds_flushCookie ();
header ('Content-type: image/'.$row['contenttype'].'; name='.md5(microtime()).'.'.$row['contenttype']);
echo $image['contents'];
}
}
break;
}
}
else
{
phpAds_setCookie ("phpAds_banner[".$n."]", 'DEFAULT', 0);
phpAds_flushCookie ();
if ($phpAds_config['default_banner_url'] != '')
header ("Location: ".$phpAds_config['default_banner_url']);
else
{
// Show 1x1 Gif, to ensure not broken image icon
// is shown.
header ("Content-type: image/gif");
echo chr(0x47).chr(0x49).chr(0x46).chr(0x38).chr(0x39).chr(0x61).chr(0x01).chr(0x00).
chr(0x01).chr(0x00).chr(0x80).chr(0x00).chr(0x00).chr(0x04).chr(0x02).chr(0x04).
chr(0x00).chr(0x00).chr(0x00).chr(0x21).chr(0xF9).chr(0x04).chr(0x01).chr(0x00).
chr(0x00).chr(0x00).chr(0x00).chr(0x2C).chr(0x00).chr(0x00).chr(0x00).chr(0x00).
chr(0x01).chr(0x00).chr(0x01).chr(0x00).chr(0x00).chr(0x02).chr(0x02).chr(0x44).
chr(0x01).chr(0x00).chr(0x3B);
}
}
phpAds_dbClose();
?>