b2evolution PHP Cross Reference Blogging Systems

Source: /inc/_init_session.inc.php - 152 lines - 6214 bytes - Text - Print

Description: This file initializes everything BUT the blog! It is useful when you want to do very customized templates! It is also called by more complete initializers.

   1  <?php
   2  /**
   3   * This file initializes everything BUT the blog!
   4   *
   5   * It is useful when you want to do very customized templates!
   6   * It is also called by more complete initializers.
   7   *
   8   * This file is part of the evoCore framework - {@link http://evocore.net/}
   9   * See also {@link http://sourceforge.net/projects/evocms/}.
  10   *
  11   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
  12   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
  13   * Parts of this file are copyright (c)2005-2006 by PROGIDISTRI - {@link http://progidistri.com/}.
  14   *
  15   * {@internal License choice
  16   * - If you have received this file as part of a package, please find the license.txt file in
  17   *   the same folder or the closest folder above for complete license terms.
  18   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  19   *   then you must choose one of the following licenses before using the file:
  20   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  21   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  22   * }}
  23   *
  24   * {@internal Open Source relicensing agreement:
  25   * Daniel HAHLER grants Francois PLANQUE the right to license
  26   * Daniel HAHLER's contributions to this file and the b2evolution project
  27   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  28   *
  29   * Matt FOLLETT grants Francois PLANQUE the right to license
  30   * Matt FOLLETT's contributions to this file and the b2evolution project
  31   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  32   * }}
  33   *
  34   * @package evocore
  35   *
  36   * @version $Id: _init_session.inc.php 6136 2014-03-08 07:59:48Z manuel $
  37   */
  38  if( !defined('EVO_CONFIG_LOADED') ) die( 'Please, do not access this page directly.' );
  39  
  40  
  41  $Timer->resume( '_init_session' );
  42  
  43  // fp> This needs to move to a better place
  44  // Check base domain for admin
  45  load_funcs( '_core/_url.funcs.php' );
  46  if( !empty($is_admin_page) )
  47  {    // Make sure we are calling the right page (on the right domain) to make sure that session cookie goes through:
  48      if( ! is_same_url( $ReqHost.$ReqPath, $admin_url) )
  49      {    // The requested URL does not look like it's under the admin URL...
  50          header('X-Evo-Redirect: Redirect to canonical $admin_url'); // Add debug header to find the cause for infinite redirects better!
  51          header_redirect( $admin_url, 302 );
  52      }
  53  }
  54  
  55  /**
  56   * The Session class.
  57   */
  58  load_class( 'sessions/model/_session.class.php', 'Session' );
  59  /**
  60   * The Session object.
  61   * It has to be instantiated before the "SessionLoaded" hook.
  62   * @global Session
  63   * @todo dh> This needs the same "SET NAMES" MySQL-setup as with Session::dbsave() - see the "TODO" with unserialize() in Session::Session()
  64   * @todo dh> makes no sense in CLI mode (no cookie); Add isset() checks to calls on the $Session object, e.g. below?
  65   *       fp> We might want to use a special session for CLI. And for cron jobs through http as well.
  66   */
  67  $Session = new Session(); // If this can't pull a session from the DB it will always INSERT a new one!
  68  
  69  /**
  70   * Handle saving the HIT and updating the SESSION at the end of the page
  71   */
  72  register_shutdown_function( 'shutdown' );
  73  
  74  
  75  // NOTE: it might be faster (though more bandwidth intensive) to spit cached pages (CachePageContent event) than to look into blocking the request (SessionLoaded event).
  76  $Plugins->trigger_event( 'SessionLoaded' );
  77  
  78  
  79  // Trigger a page content caching plugin. This would either return the cached content here or start output buffering
  80  /* fp> if you still need this, please let me know which plugin uses that.
  81  
  82      if( $Session->get( 'core.no_CachePageContent' ) )
  83      { // The event is disabled for this request:
  84          $Session->delete('core.no_CachePageContent');
  85          $Debuglog->add( 'Login: Skipping CachePageContent event, because of core.no_CachePageContent setting.', 'plugins' );
  86      }
  87      elseif( ( $get_return = $Plugins->trigger_event_first_true( 'CachePageContent' ) ) // Plugin responded to the event
  88              && ( isset($get_return['data']) ) ) // cached content returned
  89      {
  90          echo $get_return['data'];
  91          // Note: we should not use debug_info() here, because the plugin has probably sent a Content-Length header.
  92          exit(0);
  93      }
  94  
  95  
  96  // TODO: we need an event hook here for the transport_optimizer_plugin, which must get called,
  97  //       AFTER another plugin might have started an output buffer for caching already.
  98  //       Plugin priority is no option, because CachePageContent is a trigger_event_first_true event, for obvious reasons.
  99  //       Name?
 100  //       This must not be exactly here, but before any output.
 101  */
 102  
 103  
 104  // The following is needed during login, not sure that's right :/
 105  load_class( 'users/model/_usersettings.class.php', 'UserSettings' );
 106  /**
 107   * Interface to user settings
 108   *
 109   * @global UserSettings $UserSettings
 110   */
 111  $UserSettings = new UserSettings();
 112  
 113  
 114  // LOGIN:
 115  // fp> TODO: even if the session already has a user, we still need to get in there... that should be changed.
 116  $Timer->pause( '_init_session' );
 117  require dirname(__FILE__).'/_init_login.inc.php';
 118  $Timer->resume( '_init_session' );
 119  
 120  
 121  
 122  /*
 123   * User locale selection. Only override it if not set from REQUEST.
 124   */
 125  if( is_logged_in() && $current_User->get('locale') != $current_locale && ! $locale_from_get )
 126  { // change locale to users preference
 127      /*
 128       * User locale selection:
 129       * TODO: this should get done before instantiating $current_User, because we already use T_() there...
 130       */
 131      locale_activate( $current_User->get('locale') );
 132      if( $current_locale == $current_User->get('locale') )
 133      {
 134          $default_locale = $current_locale;
 135          $Debuglog->add( 'Login: default_locale from user profile: '.$default_locale, 'locale' );
 136      }
 137      else
 138      {
 139          $Debuglog->add( 'Login: locale from user profile could not be activated: '.$current_User->get('locale'), 'locale' );
 140      }
 141      // Init charset based on the selected locale
 142      if( init_charsets( $current_charset ) )
 143      { // Charset was changed reload current User from db to make sure that all of it's data is in the current charset
 144          $UserCache = & get_UserCache();
 145          $UserCache->clear();
 146          $current_User = & $UserCache->get_by_ID( $current_User->ID );
 147      }
 148  }
 149  
 150  
 151  $Timer->pause( '_init_session' );
 152  ?>

title

Description

title

Description

title

Description

title

title

Body