<?php
@include('webessence/weconfig.php');
include('webessence/includes/template.php');
if (!defined('WE_VERSION') || WE_VERSION == '')
we_die('This site has not been configured.');
$pathinfo = isset($_SERVER['PATH_INFO']) ? trim($_SERVER['PATH_INFO'], '/') : (isset($_SERVER['ORIG_PATH_INFO']) ? trim($_SERVER['ORIG_PATH_INFO'], '/') : '');
if (WE_CACHE)
{
$cachedir = 'webessence/cache/' . $pathinfo;
if (!empty($pathinfo))
$cachedir .= '/';
// Caching files are: md5 of request_uri + .(dot) + seconds to cache it
$request_md5 = md5($_SERVER['REQUEST_URI']);
$files = glob($cachedir . $request_md5 . '.*');
if (!empty($files))
{
$now = time();
$filename = $files[0];
$parts = explode('.', basename($filename));
if (filemtime($filename) + $parts[1] > $now)
{
readfile($filename);
exit;
}
}
}
if (!ini_get('date.timezone'))
@date_default_timezone_set(@date_default_timezone_get());
include('webessence/includes/page.php');
include('webessence/includes/db_entity.php');
include('webessence/includes/db_page.php');
include('webessence/includes/db_config.php');
$prepath = '';
$pathname = '';
$pos = strrpos($pathinfo, '/');
if ($pos === false)
$pathname = $pathinfo;
else
{
$prepath = substr($pathinfo, 0, $pos + 1);
$pathname = substr($pathinfo, $pos + 1);
}
$GLOBALS['we_mysqli'] = mysqli_or_we_die();
$dbPage = new DbPage($GLOBALS['we_mysqli']);
$page = $dbPage->GetByPathInfo($prepath, $pathname);
if ($page == null)
{
$GLOBALS['we_mysqli']->close();
header("HTTP/1.0 404 Not Found");
we_die('Page not found.');
}
//~ if (!file_exists(WE_PATH_ROOT . '/webessence/themes/' . WE_THEME . '/templates/' . $page->template))
//~ {
//~ $GLOBALS['we_mysqli']->close();
//~ die('Template ' . $page->template . 'does not exists.');
//~ }
$tpl = DbPage::prepare_template($page, $dbPage, $GLOBALS['we_mysqli']);
if ($tpl == null)
{
$GLOBALS['we_mysqli']->close();
header("HTTP/1.0 404 Not Found");
we_die('Page not found.');
}
// Toevoegen van eventuele plugins
foreach ($page->plugins as $plugin)
include(WE_PATH_ROOT . '/webessence/plugins/' . $plugin . '/' . $plugin . '.php');
$content = $tpl->parse();
if (WE_CACHE && $page->cache_minutes > 0)
{
if (!empty($pathinfo) && !is_dir($cachedir))
{
if (!mkdir($cachedir, 0700, true))
{
//?
}
}
file_put_contents($cachedir . $request_md5 . '.' . ($page->cache_minutes * 60), $content);
}
echo $content;
$GLOBALS['we_mysqli']->close();
?>