phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Source for file track.php

Documentation is available at track.php

  1. <?php
  2. /**
  3.  * This is the goal tracker + redirect handler.
  4.  *
  5.  * See also {@link https://launchpad.net/quam-plures}.
  6.  *
  7.  * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
  8.  * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}.
  9.  *
  10.  * @license http://quamplures.net/license.html GNU General Public License (GPL)
  11.  *
  12.  * @author fplanque: Francois PLANQUE.
  13.  *
  14.  * @package pond
  15.  */
  16.  
  17. /**
  18.  * @global Hit 
  19.  */
  20. global $Hit;
  21.  
  22. /**
  23.  * Do the MAIN initializations:
  24.  */
  25. require_once dirname(__FILE__).'/../qp_config/_config.php';
  26.  
  27. /**
  28.  * HEAVY :(
  29.  */
  30. require_once $inc_path.'_main.inc.php';
  31.  
  32. param'key''string''' );
  33.  
  34. $sql 'SELECT *
  35.                     FROM T_track__goal
  36.                  WHERE goal_key = '.$DB->quote($key);
  37.  
  38. $Goal $DB->get_row$sql );
  39.  
  40. ifempty($Goal) )
  41. {
  42.     require $templates_path.'_404_not_found.main.php'// error & exit
  43.     exit(0);
  44. }
  45.  
  46. if!empty($Goal->goal_redir_url) )
  47. {    // TODO adapt and use header_redirect()
  48.  
  49.     $redir_url $Goal->goal_redir_url;
  50.  
  51.     ifpreg_match'/\$([a-z_]+)\$/i'$redir_url$matches ) )
  52.     {    // We want to replace a special code like $hit_ID$ in the redir URL:
  53.         // Tblue> What about using preg_replace_callback() to do this?
  54.         switch$matches[1)
  55.         {
  56.             case 'hit_ID':
  57.                 // We need to log the HIT now because we need the hit ID!
  58.                 $Hit->log()// log the hit on this page
  59.                 $redir_url str_replace'$hit_ID$'$Hit->ID$redir_url );
  60.                 break;
  61.         }
  62.     }
  63.  
  64.     header'HTTP/1.1 302 Found' );
  65.     header'Location: '.$redir_urltrue302 )// explictly setting the status is required for (fast)cgi
  66.     // TODO: dh> str_repeat won't be enough (when gzipped), see http://core.trac.wordpress.org/ticket/8942
  67.     //           should be probably a more general function and get used in e.g. bad_request_die(), too (if necessary)
  68.     echo str_repeat' '1024 );
  69.     flush();
  70.     // At this point Firefox 2 will redirect without waiting for the end of the page, but IE7 will not :/
  71. }
  72. else
  73. {    // No redirection specified, we send a blank pixel instead:
  74.     // TODO: dh> Looks like caching should get prevented here?! (so additional requests arrive here, too)?!
  75.     // fp> yes.
  76.     $blank_gif $rsc_path.'img/blank.gif';
  77.  
  78.      header('Content-type: image/gif' );
  79.     header('Content-Length: '.filesize$blank_gif ) );
  80.     readfile$blank_gif );
  81.     flush();
  82. }
  83.  
  84. // We need to log the HIT now because we need the hit ID!
  85. $Hit->log()// log the hit on this page
  86.  
  87. $extra_params '';
  88. ifisset$_SERVER['QUERY_STRING') )
  89. {
  90.     $extra_params '&'.$_SERVER['QUERY_STRING'].'&';
  91.     $extra_params str_replace'&key='.$key.'&''&'$extra_params );
  92.     $extra_params trim$extra_params'&' );
  93. }
  94.  
  95.  
  96. // Record a goal hit:
  97. $sql 'INSERT INTO T_track__goalhit( ghit_goal_ID, ghit_hit_ID, ghit_params )
  98.                 VALUES( '.$Goal->goal_ID.', '.$Hit->ID.', '.$DB->quote($extra_params).' )';
  99. $DB->query$sql );
  100.  
  101.  
  102.  
  103. ?>