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
|
<?php
/**
* This is the goal tracker + redirect handler.
*
* See also {@link https://launchpad.net/quam-plures}.
*
* @copyright (c) 2009 by the Quam Plures developers - {@link http://quamplures.net/}
* @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}.
*
* @license http://quamplures.net/license.html GNU General Public License (GPL)
*
* @author fplanque: Francois PLANQUE.
*
* @package pond
*/
/**
* @global Hit
*/
global $Hit;
/**
* Do the MAIN initializations:
*/
require_once dirname(__FILE__).'/../conf/_config.php';
/**
* HEAVY :(
*/
require_once $inc_path.'_main.inc.php';
param( 'key', 'string', '' );
$sql = 'SELECT *
FROM T_track__goal
WHERE goal_key = '.$DB->quote($key);
$Goal = $DB->get_row( $sql );
if( empty($Goal) )
{
require $templates_path.'_404_not_found.main.php'; // error & exit
exit(0);
}
if( !empty($Goal->goal_redir_url) )
{ // TODO adapt and use header_redirect()
$redir_url = $Goal->goal_redir_url;
if( preg_match( '/\$([a-z_]+)\$/i', $redir_url, $matches ) )
{ // We want to replace a special code like $hit_ID$ in the redir URL:
// Tblue> What about using preg_replace_callback() to do this?
// echo $matches[1];
switch( $matches[1] )
{
case 'hit_ID':
// We need to log the HIT now! Because we need the hit ID!
$Hit->log();
$redir_url = str_replace( '$hit_ID$', $Hit->ID, $redir_url );
break;
}
}
header( 'HTTP/1.1 302 Found' );
header( 'Location: '.$redir_url, true, 302 ); // explictly setting the status is required for (fast)cgi
// TODO: dh> str_repeat won't be enough (when gzipped), see http://core.trac.wordpress.org/ticket/8942
// should be probably a more general function and get used in e.g. bad_request_die(), too (if necessary)
echo str_repeat( ' ', 1024 );
flush();
// At this point Firefox 2 will redirect without waiting for the end of the page, but IE7 will not :/
}
else
{ // No redirection specified, we send a blank pixel instead:
// TODO: dh> Looks like caching should get prevented here?! (so additional requests arrive here, too)?!
// fp> yes.
$blank_gif = $rsc_path.'img/blank.gif';
header('Content-type: image/gif' );
header('Content-Length: '.filesize( $blank_gif ) );
readfile( $blank_gif );
flush();
}
// We need to log the HIT now! Because we need the hit ID!
$Hit->log();
// pre_dump($Hit);
$extra_params = '';
if( isset( $_SERVER['QUERY_STRING'] ) )
{
$extra_params = '&'.$_SERVER['QUERY_STRING'].'&';
$extra_params = str_replace( '&key='.$key.'&', '&', $extra_params );
$extra_params = trim( $extra_params, '&' );
}
// Record a goal hit:
$sql = 'INSERT INTO T_track__goalhit( ghit_goal_ID, ghit_hit_ID, ghit_params )
VALUES( '.$Goal->goal_ID.', '.$Hit->ID.', '.$DB->quote($extra_params).' )';
$DB->query( $sql );
?>
|