|
Source Code
<?php
/* * Nepto.SK - powerful website engine * * _core.php - main file; config, weblog, template and plugin loader * ____________________________________________________________ * * Developed by Ondrej Jombik <nepto AT platon.sk> * Copyright (c) 2001-2005 Platon SDG, http://platon.sk/ * All rights reserved. * * See README file for more information about this software. * See COPYING file for license information. * * Download the latest version from * http://platon.sk/projects/ */
/* $Platon: $ */
/* Wherever possible replace "" quotes for ''. We don't want to unneccessary load PHP parser engine. */
/* * Configuation loading */
require_once '_config/main.inc.php';
/* * Neccessary libraries inclusion */
require_once 'Platon.php'; require_once 'HTML/Template/Platon.php'; require_once 'Cache/Lite.php'; require_once 'phpWebLogAnalyzer/phpWebLogAnalyzer.inc.php';
/* * Language & last visit cookies */
$current_time = time(); $expire_time = $current_time + (3600 * 24 * 30 * 12 * 5); // five years $last_visit = intval($_COOKIE['last_visit']);
if ($_COOKIE['lang'] != $cfg['params']['lang']) { setcookie('lang', $cfg['params']['lang'], $expire_time, $cfg['url']); }
if ($last_visit < $current_time - 3600 || $last_visit > $current_time + 3600) { setcookie('last_visit', $current_time, $expire_time, $cfg['url']); }
/* * Caching */ $cfg['cache']['caching'] &= (isset($cfg['params']['cache']['caching']) ? $cfg['params']['cache']['caching'] : $cfg['cache']['default']); if (isset($cfg['params']['cache']['timeout'])) { $cfg['cache']['timeout'] = intval($cfg['params']['cache']['timeout']); } if (! $cfg['cache']['caching']) { $cfg['cache']['data'] = false; } else { /* Try to create cache directory. */ $cfg['cache']['dir2'] = Platon::str_replace_postfix('/', '', $cfg['cache']['dir']); // XXX: https://stackoverflow.com/questions/52703/php-is-dir-returns-true-for-non-existent-folder if (! is_dir($cfg['cache']['dir']) || ! is_readable($cfg['cache']['dir2'])) { if (! mkdir($cfg['cache']['dir2'], $cfg['cache']['mode'])) { // Houston, we have a problem! die('Cache directory creation failed. Contact administrator.'); } }
/* Create Cache_Lite object */ $cfg['cache']['object'] = new Cache_Lite(array( 'cacheDir' => $cfg['cache']['dir'], 'lifeTime' => $cfg['cache']['timeout'], 'caching' => $cfg['cache']['caching'])); /* Clear cache if not proper version */ if (! file_exists($cfg['cache']['dir'].'cache_VERSION_'.$cfg['version'])) { $cfg['cache']['object']->clean(); fclose(fopen($cfg['cache']['dir'].'cache_VERSION_'.$cfg['version'], 'w')); }
/* All GET varaibles, all POST variables and none COOKIE variables are used for cache key creation by default. */ $new_cookie_vars = isset($cfg['params']['cache']['_cookie']) ? array_intersect($_GET, $cfg['params']['cache']['_cookie']) : array(); // $new_get_vars = isset($cfg['params']['cache']['_get']) // ? array_intersect($_GET, $cfg['params']['cache']['_get']) // : $_GET; // $new_post_vars = isset($cfg['params']['cache']['_post']) // ? array_intersect($_POST, $cfg['params']['cache']['_post']) // : $_POST;
// temporary speed up $new_get_vars = &$_GET; $new_post_vars = &$_POST; if (isset($cfg['params']['cache']['_argv'])) { $new_argv_vars = Platon::str_replace_prefix( Platon::str_replace_postfix('index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']); $new_argv_vars[0] != '/' && $new_argv_vars = ''; } else { $new_argv_vars = ''; }
/* Unsetting "lang" variables in real CGI variables arrays outside caching case causes problems in Nepto.SK admin. This is safe solution */ unset($new_get_vars['lang']); unset($new_post_vars['lang']); $cfg['cache']['id'] = ($cfg['params']['script_name'] .'/'.serialize($new_get_vars) .'/'.serialize($new_post_vars) .'/'.serialize($new_cookie_vars) .$new_argv_vars);
$cfg['cache']['data'] = $cfg['cache']['object']->get(md5($cfg['cache']['id']), $cfg['params']['lang'].'_'.$cfg['params']['plugin'], $cfg['cache']['timeout'] <= 0 /* XXX: hack with $doNotTestCacheValidity */); }
/* * Check if we have cached data */
if ($cfg['cache']['data'] !== false) { /* Cache entry exists, do nothing */ $cfg['cache']['cached'] = 1; } else {
/* Data are not cached, do some real job now */
/* * Main template object */
$cfg['tmpl']['main']['object'] = new HTML_Template_Platon($cfg['dir']['tmpl'] . $cfg['tmpl']['main']['file']);
/* * Start of output buffering */
ob_start();
/* * Main stuff * * These global variables are provided for plugins and could be freely used: * $cfg - the whole engine configuration * $cfg['weblog']['object'] - phpWebLogAnalyzer object (removed!) * $cfg['tmpl']['main']['object'] - main template object * * TODO: $cfg array 1 level depth description * * Database access is provided by PEAR DB class. Each plugin should open than * handle itself if needed. It is a waste of system resources to initialize * that handle each time when Nepto.SK website engine is started, because lot * of plugins, such as common or menu, does not have any requirments for DB * access. */
/* Basic convention is to use include_once() on conditional inclusion. But there is a little possibility of chdir() failure, so require_once() is used, because it is slightly faster than include_once(). */
if (@chdir($cfg['dir']['plugin']['code'])) { require_once 'client.php'; @Platon::chdir_back($cfg['dir']['plugin']['code']); }
/* * Content-type HTTP header * * Why is this neccessary? There are plugins, especially dir_app plugins, * which runs stupid applications (for example Gallery2), which sends * Content-type header with charset=UTF-8 or someshit like that. In this * case our HTML meta tag Content-type becomes ignored. You are damn right, * that this is really not what we like and want! */
if (1) { /* Probably no one is curious about our encoding/charset, which is actually written in HTML head meta tags. Thus no encoding here. */ header('Content-type: text/html'); } else { header('Content-type: text/html; charset='.$cfg['encoding']); }
/* * Getting context of buffering */
$cfg['tmpl']['main']['object']->setParse('content', ob_get_contents()); ob_end_clean();
/* * Title template substitution */
$cfg['tmpl']['main']['object']->setParse('title', implode('', file($cfg['dir']['root'] . $cfg['dir']['tmpl'] . $cfg['tmpl']['title']['file'])));
/* * Basic substitutions */
$cfg['tmpl']['main']['object']->set(array(
/* URL substitutions */ 'cfg_url' => $cfg['url'], 'cfg_url_root' => $cfg['url'], 'cfg_url_images' => $cfg['url'].$cfg['dir']['images'], 'cfg_url_repository' => $cfg['url'].$cfg['dir']['repository'], 'cfg_url_style' => $cfg['url'].$cfg['dir']['style'], 'cfg_url_javascript' => $cfg['url'].$cfg['dir']['javascript'],
/* Misc substitutions */ 'cfg_name' => $cfg['name'], 'cfg_version' => $cfg['version'], 'cfg_encoding' => $cfg['encoding'], 'cfg_charset' => $cfg['encoding'], 'cfg_plugin' => $cfg['params']['plugin'], 'cfg_title' => $cfg['params']['title'], 'cfg_title_sep' => $cfg['title_sep'], 'cfg_lang' => $cfg['params']['lang'], 'cfg_script_name' => $cfg['params']['script_name'], 'cfg_style_level' => $cfg['params']['style_level'], 'cfg_headers' => count($cfg['params']['headers']) ? join("\n", $cfg['params']['headers']) : '' // ) ));
/* * Language variables */
$lang_rel = ''; foreach ($cfg['lang']['accepted'] as $lang) { if ($lang == $cfg['params']['lang']) { $cfg['tmpl']['main']['object']->set(array( "cfg_lang_$lang" => 1, "cfg_lang_$lang".'_link' => '#' )); } else { if (isset($cfg['params']['lang_link'][$lang])) { /* Remove all 'lang' parameter from URL. */ $request_uri = $_SERVER['REQUEST_URI']; $url_ar = strpos($request_uri, '?') !== false ? explode('?', $request_uri, 2) : array($request_uri, ''); $url_ar = Platon::query_string_remove_param($url_ar[1], 'lang'); $url_ar != '' && $url_ar = "&$url_ar";
if (! empty($cfg['params']['lang_link'][$lang])) { $new_request_uri = $cfg['params']['lang_link'][$lang]; $new_title = $cfg['scripts'][get_script_name($new_request_uri)]; $new_request_uri = $cfg['url'].$new_request_uri; } else { $new_request_uri = get_script_name($request_uri); $new_title = @$cfg['scripts'][Platon::str_replace_prefix($cfg['url'],'', $new_request_uri)]; $url_ar .= "&lang=$lang"; }
$new_title = is_array($new_title) && isset($new_title['title']) ? $new_title['title'] : ''; $new_title = is_array($new_title) && isset($new_title[$lang]) ? $new_title[$lang] : $new_title; $new_title = strlen($new_title) > 0 ? $cfg['name'].$cfg['title_sep'].$new_title : $cfg['name'];
if (strlen($url_ar) > 1) { $new_request_uri .= (strchr($new_request_uri, '?') ? '&' : '?'); $new_request_uri .= substr($url_ar, 1); // $url_ar starts with '&' } } else { $new_request_uri = '#'; }
$cfg['tmpl']['main']['object']->set(array( 'cfg_lang_'.$lang => 0, 'cfg_lang_'.$lang.'_link' => $new_request_uri, 'cfg_lang_'.$lang.'_title'=> $new_title )); $lang_rel .= sprintf('<link rel="alternate" type="text/html"' .' href="%s" hreflang="%s" lang="%s" title="%s">'."\n", $new_request_uri, $lang, $lang, $new_title);
} }
/* * Another substitutions */
$cfg['tmpl']['main']['object']->set(array( 'cfg_lang_rel' => $lang_rel, 'cfg_stat_count' => '~' /* $sessions_count */, 'cfg_stat_lastmod' => date('Y-m-d', @filemtime($cfg['dir']['root'].'_config/config.inc.php')), 'cfg_stat_time' => '<TIME>', 'cfg_stat_weblog' => '<WEBLOG>' ));
/* * Write out */
if (1 || $cfg['cache']['caching']) { $cfg['cache']['data'] = $cfg['tmpl']['main']['object']->getContent(); if ($cfg['cache']['caching']) { $cfg['cache']['object']->save($cfg['cache']['data']); } } else { // simple writeout // because it is without <TIME> substitution, it is never used $cfg['tmpl']['main']['object']->Output(); exit; }
}
/* * Write access into web log */
if (0) { // phpWebLogAnalyzer disabled $cfg['time']['weblog']['start'] = Platon::get_mtime(); $cfg['weblog']['object'] = new Web_Log($cfg['weblog']['dsn'], $cfg['weblog']['session_timeout'], $cfg['weblog']['ident_timeout']); $cfg['weblog']['object']->enableRawLog(); $cfg['weblog']['object']->setTruncateQueryStringsKeys('session'); $cfg['weblog']['object']->registerAccess(); // return value ignored $cfg['time']['weblog']['end'] = Platon::get_mtime(); }
/* * Final writeout */
echo str_replace('<TIME>', sprintf('%.2f', Platon::get_mtime() - $cfg['time']['start']), str_replace('<WEBLOG>', sprintf('%.2f', @$cfg['time']['weblog']['end'] - @$cfg['time']['weblog']['start']), $cfg['cache']['data']));
if ($cfg['cache']['cached']) { print("<!--\n Output data cached.\n Cache ID: ".$cfg['cache']['id']."\n-->\n"); }
?>
|
|
|