b2evolution PHP Cross Reference Blogging Systems

Source: /htsrv/track.php - 105 lines - 2765 bytes - Text - Print

Description: This is the goal tracker + redirect handler. See also {@link http://sourceforge.net/projects/evocms/}.

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

title

Description

title

Description

title

Description

title

title

Body