b2evolution PHP Cross Reference Blogging Systems

Source: /inc/_init_hit.inc.php - 212 lines - 6217 bytes - Text - Print

Description: This is for www only. You don't want to include this when runnignin CLI (command line) mode This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This is for www only. You don't want to include this when runnignin CLI (command line) mode
   4   *
   5   * This file is part of the evoCore framework - {@link http://evocore.net/}
   6   * See also {@link http://sourceforge.net/projects/evocms/}.
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   *
  10   * {@internal License choice
  11   * - If you have received this file as part of a package, please find the license.txt file in
  12   *   the same folder or the closest folder above for complete license terms.
  13   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  14   *   then you must choose one of the following licenses before using the file:
  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  17   * }}
  18   *
  19   * @package evocore
  20   *
  21   * @version $Id: _init_hit.inc.php 6136 2014-03-08 07:59:48Z manuel $
  22   */
  23  if( !defined('EVO_CONFIG_LOADED') ) die( 'Please, do not access this page directly.' );
  24  
  25  
  26  $Timer->resume( '_init_hit' );
  27  
  28  /**
  29   * Do we want robots to index this page? -- Will be use to produce meta robots tag
  30   * @global boolean or NULL to ignore
  31   */
  32  $robots_index = NULL;
  33  
  34  /**
  35   * Do we want robots to follow links on this page? -- Will be use to produce meta robots tag
  36   * @global boolean or NULL to ignore
  37   */
  38  $robots_follow = NULL;
  39  
  40  $content_type_header = NULL;
  41  
  42  /**
  43   * Default 200 = success
  44   */
  45  $http_response_code = 200;
  46  
  47  /**
  48   * @global array IDs of featured posts that are being displayed -- needed so we can filter it out of normal post flow
  49   */
  50  $featured_displayed_item_IDs = array();
  51  
  52  // Initialize some variables for template functions
  53  $required_js = array();
  54  $required_css = array();
  55  $headlines = array();
  56  
  57  // ############ Get ReqPath & ReqURI ##############
  58  list($ReqPath,$ReqURI) = get_ReqURI();
  59  
  60  /**
  61   * Full requested Host (including protocol).
  62   *
  63   * {@internal Note: on IIS you can receive 'off' in the HTTPS field!! :[ }}
  64   *
  65   * @global string
  66   */
  67  $ReqHost = '';
  68  if( !empty($_SERVER['HTTP_HOST']) )
  69  {
  70      $ReqHost = ( (isset($_SERVER['HTTPS']) && ( $_SERVER['HTTPS'] != 'off' ) ) ?'https://':'http://').$_SERVER['HTTP_HOST'];
  71  }
  72  
  73  
  74  $ReqURL = $ReqHost.$ReqURI;
  75  
  76  
  77  $Debuglog->add( 'vars: $ReqHost: '.$ReqHost, 'request' );
  78  $Debuglog->add( 'vars: $ReqURI: '.$ReqURI, 'request' );
  79  $Debuglog->add( 'vars: $ReqPath: '.$ReqPath, 'request' );
  80  
  81  /**
  82   * Same domain htsrv url.
  83   *
  84   * @global string
  85   */
  86  $samedomain_htsrv_url = get_samedomain_htsrv_url();
  87  
  88  /**
  89   * Secure htsrv url.
  90   *
  91   * @global string
  92   */
  93  $secure_htsrv_url = get_secure_htsrv_url();
  94  
  95  // on which page are we ?
  96  /* old:
  97  $pagenow = explode( '/', $_SERVER['PHP_SELF'] );
  98  $pagenow = trim( $pagenow[(count($pagenow) - 1)] );
  99  $pagenow = explode( '?', $pagenow );
 100  $pagenow = $pagenow[0];
 101  */
 102  // find precisely the first occurrence of something.php in PHP_SELF, extract that and ignore any extra path.
 103  if( ! preg_match( '#/([A-Za-z0-9_\-.]+\.php[0-9]?)#i', $_SERVER['PHP_SELF'], $matches ) &&
 104        ! preg_match( '#/([A-Za-z0-9_\-.]+\.php[0-9]?)#i', $ReqURI, $matches ) )
 105  {
 106      debug_die('Can\'t identify current .php script name in PHP_SELF.');
 107  }
 108  $pagenow = $matches[1];
 109  //pre_dump( '', $_SERVER['PHP_SELF'], $pagenow );
 110  
 111  
 112  /**
 113   * Number of view counts increased on this page
 114   * @var integer
 115   */
 116  $view_counts_on_this_page = 0;
 117  
 118  
 119  /**
 120   * Locale selection:
 121   * We need to do this as early as possible in order to set DB connection charset below
 122   * fp> that does not explain why it needs to be here!! Why do we need to set the Db charset HERE? BEFORE WHAT?
 123   *
 124   * sam2kb> ideally we should set the right DB charset at the time when we connect to the database. The reason is until we do it all data pulled out from DB is in wrong encoding. I put the code here because it depends on _param.funcs, so if move the _param.funcs higher we can also move this code right under _connect_db
 125   * See also http://forums.b2evolution.net//viewtopic.php?p=95100
 126   *
 127   */
 128  $Debuglog->add( 'Login: default_locale from conf: '.$default_locale, 'locale' );
 129  
 130  locale_overwritefromDB();
 131  $Debuglog->add( 'Login: default_locale from DB: '.$default_locale, 'locale' );
 132  
 133  $default_locale = locale_from_httpaccept(); // set default locale by autodetect
 134  $Debuglog->add( 'Login: default_locale from HTTP_ACCEPT: '.$default_locale, 'locale' );
 135  
 136  load_funcs('_core/_param.funcs.php');
 137  
 138  // $locale_from_get: USE CASE: allow overriding the locale via GET param &locale=, e.g. for tests.
 139  if( ($locale_from_get = param( 'locale', 'string', NULL, true )) )
 140  {
 141      $locale_from_get = str_replace('_', '-', $locale_from_get);
 142      if( $locale_from_get != $default_locale )
 143      {
 144          if( isset( $locales[$locale_from_get] ) )
 145          {
 146              $default_locale = $locale_from_get;
 147              $Debuglog->add('Overriding locale from REQUEST: '.$default_locale, 'locale');
 148          }
 149          else
 150          {
 151              $Debuglog->add('$locale_from_get ('.$locale_from_get.') is not set. Available locales: '.implode(', ', array_keys($locales)), 'locale');
 152              $locale_from_get = false;
 153          }
 154      }
 155      else
 156      {
 157          $Debuglog->add('$locale_from_get == $default_locale ('.$locale_from_get.').', 'locale');
 158      }
 159  
 160      if( $locale_from_get )
 161      { // locale from GET being used. It should not get overridden below.
 162          $redir = 'no'; // do not redirect to canonical URL
 163      }
 164  }
 165  
 166  
 167  /**
 168   * Activate default locale:
 169   */
 170  locale_activate( $default_locale );
 171  
 172  // Set encoding for MySQL connection:
 173  $DB->set_connection_charset( $current_charset );
 174  
 175  
 176  /**
 177   * The Hit class
 178   */
 179  load_class( 'sessions/model/_hit.class.php', 'Hit' );
 180  /**
 181   * @global Hit The Hit object
 182   */
 183  $Hit = new Hit(); // This may INSERT a basedomain and a useragent but NOT the HIT itself!
 184  
 185  $Timer->pause( '_init_hit' );
 186  
 187  
 188  
 189  // Init user SESSION:
 190  if( $use_session )
 191  {
 192      require dirname(__FILE__).'/_init_session.inc.php';
 193  }
 194  
 195  if( is_logged_in() )
 196  {
 197      $timeout_online = $Settings->get( 'timeout_online' );
 198      if( empty( $current_User->lastseen_ts ) || ( $current_User->lastseen_ts < date2mysql( $localtimenow - $timeout_online ) ) )
 199      {
 200          $current_User->set( 'lastseen_ts', date2mysql( $localtimenow ) );
 201          $current_User->dbupdate();
 202      }
 203  }
 204  
 205  $Timer->resume( '_init_hit' );
 206  
 207  // Init charset handling:
 208  init_charsets( $current_charset );
 209  
 210  $Timer->pause( '_init_hit' );
 211  
 212  ?>

title

Description

title

Description

title

Description

title

title

Body