[Index]    [Classes]    [Variables]

PHP Cross Reference of Joomla 1.0.15 Documentation

title

Body

[close]

/ -> index.php (source)

   1  <?php
   2  /**
   3  * @version $Id: index.php 10041 2008-02-15 21:48:13Z eddieajau $
   4  * @package Joomla
   5  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
   6  * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  */
  13  
  14  // Set flag that this is a parent file
  15  define( '_VALID_MOS', 1 );
  16  
  17  // checks for configuration file, if none found loads installation page
  18  if (!file_exists( 'configuration.php' ) || filesize( 'configuration.php' ) < 10) {
  19      $self = rtrim( dirname( $_SERVER['PHP_SELF'] ), '/\\' ) . '/';
  20      header("Location: http://" . $_SERVER['HTTP_HOST'] . $self . "installation/index.php" );
  21      exit();
  22  }
  23  
  24  require ( 'globals.php' );
  25  require( 'configuration.php' );
  26  
  27  // SSL check - $http_host returns <live site url>:<port number if it is 443>
  28  $http_host = explode(':', $_SERVER['HTTP_HOST'] );
  29  if( (!empty( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] ) != 'off' || isset( $http_host[1] ) && $http_host[1] == 443) && substr( $mosConfig_live_site, 0, 8 ) != 'https://' ) {
  30      $mosConfig_live_site = 'https://'.substr( $mosConfig_live_site, 7 );
  31  }
  32  
  33  require_once ( 'includes/joomla.php' );
  34  
  35  //Installation sub folder check, removed for work with SVN
  36  if (file_exists( 'installation/index.php' ) && $_VERSION->SVN == 0) {
  37      define( '_INSTALL_CHECK', 1 );
  38      include  ( $mosConfig_absolute_path .'/offline.php');
  39      exit();
  40  }
  41  
  42  // displays offline/maintanance page or bar
  43  if ($mosConfig_offline == 1) {
  44      require ( $mosConfig_absolute_path .'/offline.php' );
  45  }
  46  
  47  // load system bot group
  48  $_MAMBOTS->loadBotGroup( 'system' );
  49  
  50  // trigger the onStart events
  51  $_MAMBOTS->trigger( 'onStart' );
  52  
  53  if (file_exists( $mosConfig_absolute_path .'/components/com_sef/sef.php' )) {
  54      require_once( $mosConfig_absolute_path .'/components/com_sef/sef.php' );
  55  } else {
  56      require_once ( $mosConfig_absolute_path .'/includes/sef.php' );
  57  }
  58  require_once ( $mosConfig_absolute_path .'/includes/frontend.php' );
  59  
  60  // retrieve some expected url (or form) arguments
  61  $option = strval( strtolower( mosGetParam( $_REQUEST, 'option' ) ) );
  62  $Itemid = intval( mosGetParam( $_REQUEST, 'Itemid', null ) );
  63  
  64  if ($option == '') {
  65      if ($Itemid) {
  66          $query = "SELECT id, link"
  67          . "\n FROM #__menu"
  68          . "\n WHERE menutype = 'mainmenu'"
  69          . "\n AND id = " . (int) $Itemid
  70          . "\n AND published = 1"
  71          ;
  72          $database->setQuery( $query );
  73      } else {
  74          $query = "SELECT id, link"
  75          . "\n FROM #__menu"
  76          . "\n WHERE menutype = 'mainmenu'"
  77          . "\n AND published = 1"
  78          . "\n ORDER BY parent, ordering"
  79          ;
  80          $database->setQuery( $query, 0, 1 );
  81      }
  82      $menu = new mosMenu( $database );
  83      if ($database->loadObject( $menu )) {
  84          $Itemid = $menu->id;
  85      }
  86      $link = $menu->link;
  87      if (($pos = strpos( $link, '?' )) !== false) {
  88          $link = substr( $link, $pos+1 ). '&Itemid='.$Itemid;
  89      }
  90      parse_str( $link, $temp );
  91      /** this is a patch, need to rework when globals are handled better */
  92      foreach ($temp as $k=>$v) {
  93          $GLOBALS[$k] = $v;
  94          $_REQUEST[$k] = $v;
  95          if ($k == 'option') {
  96              $option = $v;
  97          }
  98      }
  99  }
 100  if ( !$Itemid ) {
 101  // when no Itemid give a default value
 102      $Itemid = 99999999;
 103  }
 104  
 105  // mainframe is an API workhorse, lots of 'core' interaction routines
 106  $mainframe = new mosMainFrame( $database, $option, '.' );
 107  $mainframe->initSession();
 108  
 109  // trigger the onAfterStart events
 110  $_MAMBOTS->trigger( 'onAfterStart' );
 111  
 112  // checking if we can find the Itemid thru the content
 113  if ( $option == 'com_content' && $Itemid === 0 ) {
 114      $id     = intval( mosGetParam( $_REQUEST, 'id', 0 ) );
 115      $Itemid = $mainframe->getItemid( $id );
 116  }
 117  
 118  /** do we have a valid Itemid yet?? */
 119  if ( $Itemid === 0 ) {
 120      /** Nope, just use the homepage then. */
 121      $query = "SELECT id"
 122      . "\n FROM #__menu"
 123      . "\n WHERE menutype = 'mainmenu'"
 124      . "\n AND published = 1"
 125      . "\n ORDER BY parent, ordering"
 126      ;
 127      $database->setQuery( $query, 0, 1 );
 128      $Itemid = $database->loadResult();
 129  }
 130  
 131  // patch to lessen the impact on templates
 132  if ($option == 'search') {
 133      $option = 'com_search';
 134  }
 135  
 136  // loads english language file by default
 137  if ($mosConfig_lang=='') {
 138      $mosConfig_lang = 'english';
 139  }
 140  include_once( $mosConfig_absolute_path .'/language/' . $mosConfig_lang . '.php' );
 141  
 142  // frontend login & logout controls
 143  $return     = strval( mosGetParam( $_REQUEST, 'return', NULL ) );
 144  $message     = intval( mosGetParam( $_POST, 'message', 0 ) );
 145  
 146  // Get the information about the current user from the sessions table
 147  $my = $mainframe->getUser();
 148  
 149  if ($option == 'login') {
 150      $mainframe->login();
 151  
 152      // JS Popup message
 153      if ( $message ) {
 154          ?>
 155          <script language="javascript" type="text/javascript">
 156          <!--//
 157          alert( "<?php echo addslashes( _LOGIN_SUCCESS ); ?>" );
 158          //-->
 159          </script>
 160          <?php
 161      }
 162  
 163      if ( $return && !( strpos( $return, 'com_registration' ) || strpos( $return, 'com_login' ) ) ) {
 164      // checks for the presence of a return url
 165      // and ensures that this url is not the registration or login pages
 166          // If a sessioncookie exists, redirect to the given page. Otherwise, take an extra round for a cookiecheck
 167          if (isset( $_COOKIE[mosMainFrame::sessionCookieName()] )) {
 168              mosRedirect( $return );
 169          } else {
 170              mosRedirect( $mosConfig_live_site .'/index.php?option=cookiecheck&return=' . urlencode( $return ) );
 171          }
 172      } else {
 173          // If a sessioncookie exists, redirect to the start page. Otherwise, take an extra round for a cookiecheck
 174          if (isset( $_COOKIE[mosMainFrame::sessionCookieName()] )) {
 175              mosRedirect( $mosConfig_live_site .'/index.php' );
 176          } else {
 177              mosRedirect( $mosConfig_live_site .'/index.php?option=cookiecheck&return=' . urlencode( $mosConfig_live_site .'/index.php' ) );
 178          }
 179      }
 180  
 181  } else if ($option == 'logout') {
 182      $mainframe->logout();
 183  
 184      // JS Popup message
 185      if ( $message ) {
 186          ?>
 187          <script language="javascript" type="text/javascript">
 188          <!--//
 189          alert( "<?php echo addslashes( _LOGOUT_SUCCESS ); ?>" );
 190          //-->
 191          </script>
 192          <?php
 193      }
 194  
 195      if ( $return && !( strpos( $return, 'com_registration' ) || strpos( $return, 'com_login' ) ) ) {
 196      // checks for the presence of a return url
 197      // and ensures that this url is not the registration or logout pages
 198          mosRedirect( $return );
 199      } else {
 200          mosRedirect( $mosConfig_live_site.'/index.php' );
 201      }
 202  } else if ($option == 'cookiecheck') {
 203      // No cookie was set upon login. If it is set now, redirect to the given page. Otherwise, show error message.
 204      if (isset( $_COOKIE[mosMainFrame::sessionCookieName()] )) {
 205          mosRedirect( $return );
 206      } else {
 207          mosErrorAlert( _ALERT_ENABLED );
 208      }
 209  }
 210  
 211  // detect first visit
 212  $mainframe->detect();
 213  
 214  // set for overlib check
 215  $mainframe->set( 'loadOverlib', false );
 216  
 217  $gid = intval( $my->gid );
 218  
 219  // gets template for page
 220  $cur_template = $mainframe->getTemplate();
 221  /** temp fix - this feature is currently disabled */
 222  
 223  /** @global A places to store information from processing of the component */
 224  $_MOS_OPTION = array();
 225  
 226  // precapture the output of the component
 227  require_once ( $mosConfig_absolute_path . '/editor/editor.php' );
 228  
 229  ob_start();
 230  
 231  if ($path = $mainframe->getPath( 'front' )) {
 232      $task     = strval( mosGetParam( $_REQUEST, 'task', '' ) );
 233      $ret     = mosMenuCheck( $Itemid, $option, $task, $gid );
 234  
 235      if ($ret) {
 236          require_once( $path );
 237      } else {
 238          mosNotAuth();
 239      }
 240  } else {
 241      header( 'HTTP/1.0 404 Not Found' );
 242      echo _NOT_EXIST;
 243  }
 244  
 245  $_MOS_OPTION['buffer'] = ob_get_contents();
 246  
 247  ob_end_clean();
 248  
 249  initGzip();
 250  
 251  header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
 252  header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
 253  header( 'Cache-Control: no-store, no-cache, must-revalidate' );
 254  header( 'Cache-Control: post-check=0, pre-check=0', false );
 255  header( 'Pragma: no-cache' );
 256  
 257  // display the offline alert if an admin is logged in
 258  if (defined( '_ADMIN_OFFLINE' )) {
 259      include ( $mosConfig_absolute_path .'/offlinebar.php' );
 260  }
 261  
 262  // loads template file
 263  if ( !file_exists( $mosConfig_absolute_path .'/templates/'. $cur_template .'/index.php' ) ) {
 264      echo _TEMPLATE_WARN . $cur_template;
 265  } else {
 266      require_once( $mosConfig_absolute_path .'/templates/'. $cur_template .'/index.php' );
 267      echo '<!-- '. time() .' -->';
 268  }
 269  
 270  // displays queries performed for page
 271  if ($mosConfig_debug) {
 272      echo $database->_ticker . ' queries executed';
 273      echo '<pre>';
 274       foreach ($database->_log as $k=>$sql) {
 275           echo $k+1 . "\n" . $sql . '<hr />';
 276      }
 277      echo '</pre>';
 278  }
 279  
 280  doGzip();
 281  ?>