From f7d068536a874d25d6d645150e6ceb027c855e9b Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Sat, 3 Aug 2013 07:50:25 -0400 Subject: [PATCH] EXPERIMENTAL: Try not to build pages when we shouldn't have to. --- inc/config.php | 3 + inc/functions.php | 587 ++++++++++++++++++++++++++++-------------------------- 2 files changed, 307 insertions(+), 283 deletions(-) diff --git a/inc/config.php b/inc/config.php index e8422a75..120f3865 100644 --- a/inc/config.php +++ b/inc/config.php @@ -895,6 +895,9 @@ // Website favicon. // $config['url_favicon'] = '/favicon.gif'; + + // EXPERIMENTAL: Try not to build pages when we shouldn't have to. + $config['try_smarter'] = false; /* * ==================== diff --git a/inc/functions.php b/inc/functions.php index dc814a2f..b6862444 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -24,14 +24,14 @@ loadConfig(); function loadConfig() { global $board, $config, $__ip, $debug, $__version; - + $error = function_exists('error') ? 'error' : 'basic_error_function_because_the_other_isnt_loaded_yet'; - + reset_events(); - + if (!isset($_SERVER['REMOTE_ADDR'])) $_SERVER['REMOTE_ADDR'] = '0.0.0.0'; - + $arrays = array( 'db', 'cache', @@ -57,41 +57,41 @@ function loadConfig() { 'custom_pages', 'dashboard_links' ); - + $config = array(); foreach ($arrays as $key) { $config[$key] = array(); } - + require 'inc/config.php'; if (!file_exists('inc/instance-config.php')) $error('Tinyboard is not configured! Create inc/instance-config.php.'); - + require 'inc/instance-config.php'; - + if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) { require $board['dir'] . '/config.php'; } - + if (!isset($__version)) $__version = file_exists('.installed') ? trim(file_get_contents('.installed')) : false; $config['version'] = $__version; - + if ($config['debug']) { if (!isset($debug)) { $debug = array('sql' => array(), 'purge' => array(), 'cached' => array(), 'write' => array()); $debug['start'] = microtime(true); } } - + date_default_timezone_set($config['timezone']); - + if (!isset($config['global_message'])) $config['global_message'] = false; - + if (!isset($config['post_url'])) $config['post_url'] = $config['root'] . $config['file_post']; - + if (!isset($config['referer_match'])) if (isset($_SERVER['HTTP_HOST'])) { $config['referer_match'] = '/^' . @@ -117,10 +117,10 @@ function loadConfig() { } if (!isset($config['cookies']['path'])) $config['cookies']['path'] = &$config['root']; - + if (!isset($config['dir']['static'])) $config['dir']['static'] = $config['root'] . 'static/'; - + if (!isset($config['image_sticky'])) $config['image_sticky'] = $config['dir']['static'] . 'sticky.gif'; if (!isset($config['image_locked'])) @@ -129,27 +129,27 @@ function loadConfig() { $config['image_bumplocked'] = $config['dir']['static'] . 'sage.gif'; if (!isset($config['image_deleted'])) $config['image_deleted'] = $config['dir']['static'] . 'deleted.png'; - + if (!isset($config['uri_thumb'])) $config['uri_thumb'] = $config['root'] . $board['dir'] . $config['dir']['thumb']; elseif (isset($board['dir'])) $config['uri_thumb'] = sprintf($config['uri_thumb'], $board['dir']); - + if (!isset($config['uri_img'])) $config['uri_img'] = $config['root'] . $board['dir'] . $config['dir']['img']; elseif (isset($board['dir'])) $config['uri_img'] = sprintf($config['uri_img'], $board['dir']); - + if (!isset($config['uri_stylesheets'])) $config['uri_stylesheets'] = $config['root'] . 'stylesheets/'; - + if (!isset($config['url_stylesheet'])) $config['url_stylesheet'] = $config['uri_stylesheets'] . 'style.css'; if (!isset($config['url_javascript'])) $config['url_javascript'] = $config['root'] . $config['file_script']; if (!isset($config['additional_javascript_url'])) $config['additional_javascript_url'] = $config['root']; - + if ($config['root_file']) { chdir($config['root_file']); } @@ -164,15 +164,15 @@ function loadConfig() { // Keep the original address to properly comply with other board configurations if (!isset($__ip)) $__ip = $_SERVER['REMOTE_ADDR']; - + // ::ffff:0.0.0.0 if (preg_match('/^\:\:(ffff\:)?(\d+\.\d+\.\d+\.\d+)$/', $__ip, $m)) $_SERVER['REMOTE_ADDR'] = $m[2]; - + if (_setlocale(LC_ALL, $config['locale']) === false) { $error('The specified locale (' . $config['locale'] . ') does not exist on your platform!'); } - + if (extension_loaded('gettext')) { bindtextdomain('tinyboard', './inc/locale'); bind_textdomain_codeset('tinyboard', 'UTF-8'); @@ -182,11 +182,11 @@ function loadConfig() { _bind_textdomain_codeset('tinyboard', 'UTF-8'); _textdomain('tinyboard'); } - - + + if ($config['syslog']) openlog('tinyboard', LOG_ODELAY, LOG_SYSLOG); // open a connection to sysem logger - + if ($config['recaptcha']) require_once 'inc/lib/recaptcha/recaptchalib.php'; if ($config['cache']['enabled']) @@ -196,12 +196,12 @@ function loadConfig() { function basic_error_function_because_the_other_isnt_loaded_yet($message, $priority = true) { global $config; - + if ($config['syslog'] && $priority !== false) { // Use LOG_NOTICE instead of LOG_ERR or LOG_WARNING because most error message are not significant. _syslog($priority !== true ? $priority : LOG_NOTICE, $message); } - + // Yes, this is horrible. die('Error' . '