includes/common.php
changeset 372 5bd429428101
parent 371 dc6026376919
child 378 c1c7fa6b329f
equal deleted inserted replaced
371:dc6026376919 372:5bd429428101
   119 require_once(ENANO_ROOT.'/includes/pageprocess.php');
   119 require_once(ENANO_ROOT.'/includes/pageprocess.php');
   120 require_once(ENANO_ROOT.'/includes/tagcloud.php');
   120 require_once(ENANO_ROOT.'/includes/tagcloud.php');
   121 
   121 
   122 strip_magic_quotes_gpc();
   122 strip_magic_quotes_gpc();
   123 
   123 
       
   124 profiler_log('Files included and magic_quotes_gpc reversed if applicable');
       
   125 
   124 // Enano has five main components: the database abstraction layer (DBAL), the session manager,
   126 // Enano has five main components: the database abstraction layer (DBAL), the session manager,
   125 // the path/URL manager, the template engine, and the plugin manager.
   127 // the path/URL manager, the template engine, and the plugin manager.
   126 // Each part has its own class and a global object; nearly all Enano functions are handled by one of these five components.
   128 // Each part has its own class and a global object; nearly all Enano functions are handled by one of these five components.
   127 // All of these classes are singletons and are designed to carry as much data as possible within the object
   129 // All of these classes are singletons and are designed to carry as much data as possible within the object
   128 // to make data access and function calling easy.
   130 // to make data access and function calling easy.
   160 if ( !isset($dbdriver) )
   162 if ( !isset($dbdriver) )
   161   $dbdriver = 'mysql';
   163   $dbdriver = 'mysql';
   162 
   164 
   163 $db = new $dbdriver();
   165 $db = new $dbdriver();
   164 $db->connect();
   166 $db->connect();
       
   167 
       
   168 profiler_log('Database connected');
   165 
   169 
   166 // The URL separator is the character appended to contentPath + url_title type strings.
   170 // The URL separator is the character appended to contentPath + url_title type strings.
   167 // If the contentPath has a ? in it, this should be an ampersand; else, it should be a
   171 // If the contentPath has a ? in it, this should be an ampersand; else, it should be a
   168 // question mark.
   172 // question mark.
   169 $sep = ( strstr(contentPath, '?') ) ? '&' : '?';
   173 $sep = ( strstr(contentPath, '?') ) ? '&' : '?';
   201   $enano_config[$r['config_name']] = $r['config_value'];
   205   $enano_config[$r['config_name']] = $r['config_value'];
   202 }
   206 }
   203 
   207 
   204 $db->free_result();
   208 $db->free_result();
   205 
   209 
       
   210 profiler_log('Config fetched');
       
   211 
   206 // Now that we have the config, check the Enano version.
   212 // Now that we have the config, check the Enano version.
   207 if ( enano_version(false, true) != $version && !defined('IN_ENANO_UPGRADE') )
   213 if ( enano_version(false, true) != $version && !defined('IN_ENANO_UPGRADE') )
   208 {
   214 {
   209   grinding_halt('Version mismatch', '<p>It seems that the Enano release we\'re trying to run ('.$version.') is different from the version specified in your database ('.enano_version().'). Perhaps you need to <a href="'.scriptPath.'/install/upgrade.php">upgrade</a>?</p>');
   215   grinding_halt('Version mismatch', '<p>It seems that the Enano release we\'re trying to run ('.$version.') is different from the version specified in your database ('.enano_version().'). Perhaps you need to <a href="'.scriptPath.'/install/upgrade.php">upgrade</a>?</p>');
   210 }
   216 }
   238     grinding_halt('AES block size changed', '<p>Enano has detected that the AES block size in constants.php has been changed. This change cannot be performed after installation, otherwise all passwords would have to be re-encrypted.</p><p>Please change the block size back to ' . $ks . ' bits and reload this page.</p>');
   244     grinding_halt('AES block size changed', '<p>Enano has detected that the AES block size in constants.php has been changed. This change cannot be performed after installation, otherwise all passwords would have to be re-encrypted.</p><p>Please change the block size back to ' . $ks . ' bits and reload this page.</p>');
   239   }
   245   }
   240 }
   246 }
   241 
   247 
   242 // Is there no default language?
   248 // Is there no default language?
   243 if ( getConfig('lang_default') === false && !defined('IN_ENANO_MIGRATION') )
   249 if ( getConfig('default_language') === false && !defined('IN_ENANO_MIGRATION') )
   244 {
   250 {
   245   $q = $db->sql_query('SELECT lang_id FROM '.table_prefix.'language LIMIT 1;');
   251   $q = $db->sql_query('SELECT lang_id FROM '.table_prefix.'language LIMIT 1;');
   246   if ( !$q )
   252   if ( !$q )
   247     $db->_die('common.php - setting default language');
   253     $db->_die('common.php - setting default language');
   248   if ( $db->numrows() < 1 && !defined('ENANO_ALLOW_LOAD_NOLANG') )
   254   if ( $db->numrows() < 1 && !defined('ENANO_ALLOW_LOAD_NOLANG') )
   258   }
   264   }
   259   $row = $db->fetchrow();
   265   $row = $db->fetchrow();
   260   setConfig('default_language', $row['lang_id']);
   266   setConfig('default_language', $row['lang_id']);
   261 }
   267 }
   262 
   268 
       
   269 profiler_log('Ran checks');
       
   270 
   263 // Load plugin manager
   271 // Load plugin manager
   264 $plugins = new pluginLoader();
   272 $plugins = new pluginLoader();
   265 
   273 
   266 //
   274 //
   267 // Mainstream API boot-up
   275 // Mainstream API boot-up
   275 // Load plugins from common because we can't give plugins full abilities in object context
   283 // Load plugins from common because we can't give plugins full abilities in object context
   276 foreach ( $plugins->load_list as $f )
   284 foreach ( $plugins->load_list as $f )
   277 {
   285 {
   278   include_once $f;
   286   include_once $f;
   279 }
   287 }
       
   288 
       
   289 profiler_log('Loaded plugins');
   280 
   290 
   281 // Three fifths of the Enano API gets the breath of life right here.
   291 // Three fifths of the Enano API gets the breath of life right here.
   282 $session = new sessionManager();
   292 $session = new sessionManager();
   283 $paths = new pathManager();
   293 $paths = new pathManager();
   284 $template = new template();
   294 $template = new template();
   285 $email = new EmailEncryptor();
   295 $email = new EmailEncryptor();
   286 
   296 
       
   297 profiler_log('Instanciated important singletons');
       
   298 
   287 // We've got the five main objects - flick on the switch so if a problem occurs, we can have a "friendly" UI
   299 // We've got the five main objects - flick on the switch so if a problem occurs, we can have a "friendly" UI
   288 define('ENANO_BASE_CLASSES_INITIALIZED', '');
   300 define('ENANO_BASE_CLASSES_INITIALIZED', '');
   289 
   301 
   290 // From here on out, none of this functionality is needed during the installer stage.
   302 // From here on out, none of this functionality is needed during the installer stage.
   291 // Once $paths->init() is called, we could be redirected to the main page, so we don't want
   303 // Once $paths->init() is called, we could be redirected to the main page, so we don't want
   299   foreach ( $code as $cmd )
   311   foreach ( $code as $cmd )
   300   {
   312   {
   301     eval($cmd);
   313     eval($cmd);
   302   }
   314   }
   303   
   315   
       
   316   profiler_log('Finished base_classes_initted hook');
       
   317   
   304   // For special and administration pages, sometimes there is a "preloader" function that must be run
   318   // For special and administration pages, sometimes there is a "preloader" function that must be run
   305   // before the session manager and/or path manager get the init signal. Call it here.  
   319   // before the session manager and/or path manager get the init signal. Call it here.  
   306   $p = RenderMan::strToPageId($paths->get_pageid_from_url());
   320   $p = RenderMan::strToPageId($paths->get_pageid_from_url());
   307   if( ( $p[1] == 'Admin' || $p[1] == 'Special' ) && function_exists('page_'.$p[1].'_'.$p[0].'_preloader'))
   321   if( ( $p[1] == 'Admin' || $p[1] == 'Special' ) && function_exists('page_'.$p[1].'_'.$p[0].'_preloader'))
   308   {
   322   {
   309     @call_user_func('page_'.$p[1].'_'.$p[0].'_preloader');
   323     @call_user_func('page_'.$p[1].'_'.$p[0].'_preloader');
   310   }
   324   }
       
   325   
       
   326   profiler_log('Checked for preloader');
   311   
   327   
   312   // One quick security check...
   328   // One quick security check...
   313   if ( !is_valid_ip($_SERVER['REMOTE_ADDR']) )
   329   if ( !is_valid_ip($_SERVER['REMOTE_ADDR']) )
   314   {
   330   {
   315     die('SECURITY: spoofed IP address');
   331     die('SECURITY: spoofed IP address');
   325   $code = $plugins->setHook('session_started');
   341   $code = $plugins->setHook('session_started');
   326   foreach ( $code as $cmd )
   342   foreach ( $code as $cmd )
   327   {
   343   {
   328     eval($cmd);
   344     eval($cmd);
   329   }
   345   }
       
   346   
       
   347   profiler_log('Ran session_started hook');
   330   
   348   
   331   $paths->init();
   349   $paths->init();
   332   
   350   
   333   // We're ready for whatever life throws us now.
   351   // We're ready for whatever life throws us now.
   334   define('ENANO_MAINSTREAM', '');
   352   define('ENANO_MAINSTREAM', '');
   367   foreach ( $code as $cmd )
   385   foreach ( $code as $cmd )
   368   {
   386   {
   369     eval($cmd);
   387     eval($cmd);
   370   }
   388   }
   371   
   389   
       
   390   profiler_log('Ran disabled-site checks and common_post');
       
   391   
   372   if ( isset($_GET['noheaders']) )
   392   if ( isset($_GET['noheaders']) )
   373     $template->no_headers = true;
   393     $template->no_headers = true;
   374 }
   394 }
   375 
   395 
       
   396 profiler_log('common finished');
       
   397 
   376 // That's the end. Enano should be loaded now :-)
   398 // That's the end. Enano should be loaded now :-)
   377 
   399 
   378 ?>
   400 ?>