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

//  Copyright 2010 Ameoto Systems. All Rights Resurved.
//  Written by TheTooth, hide@address.com

session_start();
error_reporting(E_ALL);
$sys['version'] = '1.4.2 r89';
$sys['console'] = false;
$SELF = ($_SERVER["SERVER_PROTOCOL"] == 'HTTP/1.1' ? 'http://' : 'https://').dirname($_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
define("Init", 0);
define("Self", $SELF, true);
// Die pretty :)
function halt($message){
	$errorDoc = file_get_contents('paper/error.txt');
	die(str_replace('::fail::', $message, $errorDoc));
}
// Config Check
if((@include("paper/config.php")) === false){
	halt('No configuration found, please run the <a href="install.php">installer</a>.');
}
// System serial number
$serial = (string)"E".substr(sha1($config['salt']), 0, 8);
// Get the current page
if(!isset($_REQUEST['page'])){
    $page = 'home';
}else{
	$page = $_REQUEST['page'];
	$page = trim(rawurldecode($page));
	$page = strtolower(strip_tags($page));
	$page = preg_replace("/\/$/", "", $page);
	if($page == ''){
		$page = 'home';
	}
    if(substr_count($page,'..') > 0 || substr_count($page,'~') > 0){
		$page = 'home';
		header("HTTP/1.0 403 Forbidden");
    }
}
define("Page", $page, true);
include("paper/lang.".$config['lang'].".php");
include('paper/init.php');
// Begin Output.
if((@require('themes/'.$config['theme'].'/header.php')) && (@file_exists('themes/'.$config['theme'].'/footer.php')) === false){
	halt($fail['theme_include']);
}elseif(!isset($argv)){
	// Load engine
	require("paper/engine.php");
	// System events
	Request();
	// Render Page
	if(!isset($_REQUEST['act'])){
		if(!file_exists($full) || !is_file($full)){
			if(file_exists('pages/404.txt')){
				$parser = new Parser();
				$Render = $parser->parse(file_get_contents('pages/404.txt'));
				echo eval('?>'.$Render.'<?php ');
			}else{
				echo $fail['404'];
			}
		}elseif(file_exists($cache) && filemtime($cache) >= filemtime($full) && $config['debug'] == false){
			if($config['inlinephp'] == true){
				include($cache);
			}else{
				echo file_get_contents($cache);
			}
		}else{
			if(!isset($parser)){
				$parser = new Parser();
			}
			$Render = $parser->parse(file_get_contents($full));
			if($config['inlinephp'] == true){
				echo eval('?>'.$Render.'<?php ');
			}else{
				echo $Render;
			}
			if($parser->_restrict(file_get_contents($full)) && $config['debug'] == false){
				$cacheHandle = fopen ($cache, 'w') or exit($fail['cache']);
				fwrite ($cacheHandle, $Render);
				fclose($cacheHandle);
			}elseif(file_exists($cache)){
				unlink($cache);
			}
			unset($parser);
			unset($Render);
		}
	}
	// Load sub extensions
	if(isset($ext)){
		$ext->_loadSub();
	}
	//If user is authenticated display admin tools
	if(isset($_SESSION['logged']) && array_key_exists($_SESSION["logged"],$user)){
		// Check for lock file
		if(file_exists("pages/$".str_replace("/", ";", Page).".lock")){
			$lockSet = str_split(fgets(fopen("pages/$".str_replace("/", ";", Page).".lock", "r")), 14);
			if(($lockSet[0]-date('YmdHis')) < -500){
				unlink("pages/$".str_replace("/", ";", Page).".lock");
			}
		}
		//Display editor
		if(isset($_REQUEST['act']) && $_REQUEST['act'] == 'Edit' && ($user[$_SESSION["logged"]][1] == (1||2) || $page == '$user-'.$_SESSION['logged'])){
			echo '<h1>Editing</h1>';
			if(isset($_REQUEST['preview'])){
				$content = stripslashes($_REQUEST['message']);
				if(!isset($parser)){
					$parser = new Parser();
				}
				$Render = $parser->parse($content);
				if($config['inlinephp'] == true){
					eval('?><div class="quote">'.$Render.'</div><?php ');
				}else{
					echo '<div class="quote">'.$Render.'</div>';
				}
				unset($parser);
				unset($Render);
			}
			if(file_exists("pages/$".str_replace("/", ";", $page).".lock") && !isset($_REQUEST['FORCE']) && !isset($_REQUEST['preview'])){
				echo '<p>'.str_replace('::user', $lockSet[1], $txt['pageLock']).' ',
				'(<a href="'.Self.'/?page='.$page.'&amp;act=Edit&amp;FORCE=true">'.$inter['Continue'].'</a>)</p>';
			}else{
				$lockfile = fopen("pages/$".str_replace("/", ";", $page).".lock", "w");
				fwrite($lockfile, date('YmdHis').$_SESSION['logged']);
				fclose($lockfile);
				echo '<form name="editor" action="'.Self.'/?page='.$page.'" method="post" enctype="multipart/form-data">',
				'<p>Page name: <input type="text" name="namespace" value="'.$page.'"></p>',
				'<script type="text/javascript">edToolbar(\'canvas\');</script><textarea name="message" id="canvas" rows="24" onKeyDown="insertTab(this, event);">';
				if(isset($_REQUEST['preview'])){
					echo htmlentities($content, ENT_COMPAT, 'UTF-8');
				}elseif(file_exists($full)){
					echo htmlentities(file_get_contents($full), ENT_COMPAT, 'UTF-8');
				}
				echo '</textarea><div class="quote"><p><input type="file" name="uploadedfile" /> '.$txt['uploadReplace'].'<input type="checkbox" name="file_rw" /></p>',
				'</div><br /><div align="right" id="btn">',
				'<button type="submit" name="act" value="Cancel" class="btn">'.$inter['Cancel'].'</button>',
				'<button type="submit" name="preview" onclick="document.forms[\'editor\'].action = \''.Self.'/?page='.$page.'&act=Edit\'; return true;" class="btn">'.$inter['Preview'].'</button>',
				'<button type="submit" name="act" value="Save" class="btn">'.$inter['Save'].'</button>',
				'</div></form>';
			}
		}
	}elseif($config['login'] == true){
		echo '<div style="text-align:right;"><a href="javascript:ReverseDisplay(\'login\')" style="text-decoration:none">+</a></div>',
		'<form name="login" action="'.Self.'/?page='.Page.'" method="post"><div id="login" style="display:none;">',
		'<input type="hidden" name="act" value="log" />'.$inter['Username'].': <input type="text" name="username" /> ',
		$inter['Password'].': <input type="password" name="password" />',
		'<button type="submit" value="Login">'.$inter['Login'].'</button> '.(file_exists('register.php') ? '<a href="'.Self.'/register.php">Register</a>' : '').'</div></form>';
	}
	require('themes/'.$config['theme'].'/footer.php');
}
session_write_close();
?>
Return current item: WhiteCrane