Location: PHPKode > projects > Shinobu > index.php
<?php

/* ---

	Copyright (C) 2008-2009 Frank Smit
	http://shinobu.61924.nl/

	This file is part of Shinobu.

	Shinobu is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Shinobu is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Shinobu. If not, see <http://www.gnu.org/licenses/>.

--- */

$start_timer = microtime();

error_reporting(E_ALL);

// Define system vars and include important files
define('SHINOBU', 1);
require './system/core/init.php';

if (MOD_REWRITE === true)
{
	$protocol = (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'off') ? 'http://' : 'https://';
	$port = (isset($_SERVER['SERVER_PORT']) && (($_SERVER['SERVER_PORT'] != '80' && $protocol == 'http://') || ($_SERVER['SERVER_PORT'] != '443' && $protocol == 'https://')) && strpos($_SERVER['HTTP_HOST'], ':') === false) ? ':'.$_SERVER['SERVER_PORT'] : '';
	$current_url = urldecode($protocol.$_SERVER['HTTP_HOST'].$port.$_SERVER['REQUEST_URI']);

	$prefix_pos = strpos($current_url, '?q=') === false ? false : true;

	if ($prefix_pos === true)
	{
		header('HTTP/1.1 301 Moved Permanently');
		header('Location: '.str_replace(array('index.php?q=', $url_query), '', $current_url)); exit;
	}
}

// Send no-cache headers
header('Expires: Thu, 21 Jul 1977 07:30:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache'); // For HTTP/1.0 compability
header('Content-type: text/html; charset='.$sys_lang['s_encoding']);

// Get uri
$sys_request = array();
$sys_request[0] = isset($_GET['q']) ? trim($_GET['q'], '/') : false;

if ($sys_request[0] !== false)
{
	// Remove uri suffix and /'s at the beginning and end of the uri
	if (URI_SUFFIX != '')
	{
		$suffix_pos = strpos($sys_request[0], URI_SUFFIX);
		$sys_tmp = explode('/', is_bool($suffix_pos) && !$suffix_pos ? NULL : substr($sys_request[0], 0, $suffix_pos));
	}
	else
		$sys_tmp = explode('/', $sys_request[0]);
}

// Filter uri parts
if (isset($sys_tmp) && count($sys_tmp) > 0)
	foreach ($sys_tmp as $v)
		$sys_request[] = preg_replace('/[^A-Za-z0-9_\-(),]+/', '', $v);

if (empty($sys_request[1]))
	unset($sys_request[1]);

// Load template (and parser) and assign content
require SYS_LIBRARY_DIR.'template_parser.php';
$sys_tpl = new template_parser(SYS_THEME_DIR.$sys_config['theme'].'/main.tpl');

// Assign tags
$sys_tpl->assign(
	array(
		'content_direction',
		'content_encoding',
		'content_type',
		'theme_path',
		'website_title',
		'website_description',
		'main_navigation',
		'user_block',
		'software_version'),
	array(
		$sys_lang['s_direction'],
		$sys_lang['s_encoding'],
		'text/html',
		SYS_THEME_PATH.$sys_config['theme'],
		$sys_config['website_title'],
		$sys_config['website_description'],
		generate_navigation(),
		generate_user_block(),
		'<a href="http://shinobu.61924.nl/">Shinobu</a> '.SHINOBU_VERSION)
	);

$sys_tpl->assign('whoisonline_block', ($sys_config['user_online_stats'] === 1 ? generate_whoisonline_block() : null));

// Start capturing stuff for the main content
ob_start();

// Load page
$sys_page = find_page($sys_request);

if ($sys_page !== false && is_file($sys_page))
	require $sys_page;
else
	send_404();

// Stop capturing stuff for the main content
$sys_tpl->assign('main_content', ob_get_clean());

// Replace all tags in the template
$sys_tpl->process();

// Close database connection
$sys_db->close();

// Show debug information is debug mode is enabled
if (SYSTEM_DEBUG === true)
	$sys_tpl->template = str_replace('<!-- DEBUG -->', output_debug_info($start_timer, microtime()), $sys_tpl->template);

// DISPLAY :O
exit($sys_tpl->output());

?>
Return current item: Shinobu