includes/common.php
changeset 1103 90225c988124
parent 1099 73abd46f5148
child 1109 c424a15a1656
equal deleted inserted replaced
1102:faef5e62e1e0 1103:90225c988124
     1 <?php
     1 <?php
     2 
     2 
     3 /*
     3 /*
     4  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
     4  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
     5  * Version 1.1.6 (Caoineag beta 1)
     5  * Copyright (C) 2006-2009 Dan Fuhry
     6  * Copyright (C) 2006-2008 Dan Fuhry
       
     7  *
     6  *
     8  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
     7  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
     9  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
     8  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    10  *
     9  *
    11  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
    10  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
    42 // Our version number
    41 // Our version number
    43 // This needs to match the version number in the database. This number should
    42 // This needs to match the version number in the database. This number should
    44 // be the expected output of enano_version(), which will always be in the
    43 // be the expected output of enano_version(), which will always be in the
    45 // format of 1.0.2, 1.0.2a1, 1.0.2b1, 1.0.2RC1
    44 // format of 1.0.2, 1.0.2a1, 1.0.2b1, 1.0.2RC1
    46 // You'll want to change this for custom distributions.
    45 // You'll want to change this for custom distributions.
    47 $version = '1.1.6';
    46 $version = '1.1.7';
    48 
    47 
    49 /**
    48 /**
    50  * Returns a floating-point number with the current UNIX timestamp in microseconds. Defined very early because we gotta call it
    49  * Returns a floating-point number with the current UNIX timestamp in microseconds. Defined very early because we gotta call it
    51  * from very early on in the script to measure the starting time of Enano.
    50  * from very early on in the script to measure the starting time of Enano.
    52  * @return float
    51  * @return float
   225 // question mark.
   224 // question mark.
   226 $sep = ( strstr(contentPath, '?') ) ? '&' : '?';
   225 $sep = ( strstr(contentPath, '?') ) ? '&' : '?';
   227 define('urlSeparator', $sep);
   226 define('urlSeparator', $sep);
   228 unset($sep); // save 10 bytes of memory...
   227 unset($sep); // save 10 bytes of memory...
   229 
   228 
   230 // Sometimes there are critical failures triggered by initialization functions in the Enano API that are recurring
       
   231 // and cannot be fixed except for manual intervention. This is where that code should go.
       
   232 if ( isset($_GET['do']) && $_GET['do'] == 'diag' && isset($_GET['sub']) )
       
   233 {
       
   234   switch($_GET['sub'])
       
   235   {
       
   236     case 'cookie_destroy':
       
   237       unset($_COOKIE['sid']);
       
   238       setcookie('sid', '', time()-3600*24, scriptPath);
       
   239       setcookie('sid', '', time()-3600*24, scriptPath.'/');
       
   240       die('Session cookie cleared. <a href="'.htmlspecialchars($_SERVER['PHP_SELF']).'">Continue</a>');
       
   241       break;
       
   242   }
       
   243 }
       
   244 
       
   245 // Build the list of system tables (this is mostly done in constants.php, but that's before table_prefix is known)
   229 // Build the list of system tables (this is mostly done in constants.php, but that's before table_prefix is known)
   246 if ( defined('table_prefix') && !defined('ENANO_TABLELIST_PREFIXED') )
   230 if ( defined('table_prefix') && !defined('ENANO_TABLELIST_PREFIXED') )
   247 {
   231 {
   248   define('ENANO_TABLELIST_PREFIXED', 1);
   232   define('ENANO_TABLELIST_PREFIXED', 1);
   249   foreach ( $system_table_list as $i => $_ )
   233   foreach ( $system_table_list as $i => $_ )
   395     eval($cmd);
   379     eval($cmd);
   396   }
   380   }
   397   
   381   
   398   profiler_log('Finished base_classes_initted hook');
   382   profiler_log('Finished base_classes_initted hook');
   399   
   383   
   400   // For special and administration pages, sometimes there is a "preloader" function that must be run
       
   401   // before the session manager and/or path manager get the init signal. Call it here.  
       
   402   $p = RenderMan::strToPageId($paths->get_pageid_from_url());
       
   403   if( ( $p[1] == 'Admin' || $p[1] == 'Special' ) && function_exists('page_'.$p[1].'_'.$p[0].'_preloader'))
       
   404   {
       
   405     call_user_func('page_'.$p[1].'_'.$p[0].'_preloader');
       
   406   }
       
   407   
       
   408   profiler_log('Checked for preloader');
       
   409   
       
   410   // One quick security check...
   384   // One quick security check...
   411   if ( !is_valid_ip($_SERVER['REMOTE_ADDR']) )
   385   if ( !is_valid_ip($_SERVER['REMOTE_ADDR']) )
   412   {
   386   {
   413     die('SECURITY: spoofed IP address: ' . htmlspecialchars($_SERVER['REMOTE_ADDR']));
   387     die('SECURITY: spoofed IP address: ' . htmlspecialchars($_SERVER['REMOTE_ADDR']));
   414   }
   388   }
   415 
   389   
       
   390   // For special and administration pages, sometimes there is a "preloader" function that must be run
       
   391   // before the session manager and/or path manager get the init signal. Call it here.
       
   392   $title = get_title(true);
       
   393   list($page_id, $namespace) = RenderMan::strToPageID($title);
       
   394   list($page_id_top) = explode('/', $page_id);
       
   395   $fname = "page_{$namespace}_{$page_id_top}_preloader";
       
   396   if( ( $namespace == 'Admin' || $namespace == 'Special' ) && function_exists($fname))
       
   397   {
       
   398     call_user_func($fname);
       
   399   }
       
   400   
       
   401   profiler_log('Checked for (and ran, if applicable) preloader');
       
   402   
   416   // All checks passed! Start the main components up.  
   403   // All checks passed! Start the main components up.  
   417   $session->start();
   404   $session->start();
   418   
   405   
   419   // Add all of our built in special pages
   406   // Add all of our built in special pages
   420   foreach ( array('SpecialUserFuncs', 'SpecialPageFuncs', 'SpecialAdmin', 'SpecialCSS', 'SpecialUpDownload', 'SpecialSearch', 'PrivateMessages', 'SpecialGroups', 'SpecialLog') as $plugin )
   407   foreach ( array('SpecialUserFuncs', 'SpecialPageFuncs', 'SpecialAdmin', 'SpecialCSS', 'SpecialUpDownload', 'SpecialSearch', 'PrivateMessages', 'SpecialGroups', 'SpecialLog') as $plugin )
   437     eval($cmd);
   424     eval($cmd);
   438   }
   425   }
   439   
   426   
   440   profiler_log('Ran session_started hook');
   427   profiler_log('Ran session_started hook');
   441   
   428   
   442   $paths->init();
   429   $paths->init($title);
   443   
   430   
   444   // setup output format
   431   // setup output format
   445   if ( defined('ENANO_OUTPUT_FORMAT') )
   432   if ( defined('ENANO_OUTPUT_FORMAT') )
   446     $class = 'Output_' . ENANO_OUTPUT_FORMAT;
   433     $class = 'Output_' . ENANO_OUTPUT_FORMAT;
   447   else
   434   else