');
}
####################################################
####################################################
// this variable gives us the root level of whichever server we're on. So if the site system is being run from http://www.thing.net, then $sitelocation = http://www.thing.net - don't change this.
$root = "http://".$_SERVER['SERVER_NAME'];
// subfolder must be in the format "/subfolder"
$subfolder = getXMLdata('setup.xml', 'subfolder');
$sitelocation = $root.$subfolder;
####################################################
// prevent seesion IDs from screwing up the URL
ini_set('session.use_trans_sid', false);
// ensure php-written separators are XHTML valid
ini_set('arg_separator.output', "&");
// remove hash to turn off error reporting
# ini_set('display_errors','0');
####################################################
// get other required files
require_once ("13/inc/markdown.php");
#require_once ("13/inc/classTextile.php");
####################################################
#
# perform initiation and processing functions
#
####################################################
session_start();
// if login cookie is present, pass details to session variables as normal
if (isset($_COOKIE['id'])) {
$_SESSION['validusername'] = $_COOKIE['id'];
$_SESSION['userlevel'] = $_COOKIE['level'];
}
####################################################
# fetch overall and site config details
$configarray = getXML('config.xml');
// the getXML function produces a true reflection of the XML file
// and we want to access the first level as an array, not an array within an array.
$config = $configarray[config];
####################################################
# decide which page has been asked for
$page = process_uri();
# now get stuff for that page
$pageinfoarray = getXML($page);
$page_info = $pageinfoarray[page];
####################################################
####################################################
// get all variables...
foreach( $_REQUEST as $key => $value ){
$$key = $value;
}
foreach( $_SESSION as $skey => $svalue ){
$$skey = $svalue;
}
####################################################
# get contents of XML file and put it in an array, with keys
function getXML($file)
{
$output = array();
$data = getcontents($file);
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
xml_parse_into_struct($parser, $data, $values, $tags);
xml_parser_free($parser);
$hash_stack = array();
foreach ($values as $key => $val)
{
switch ($val['type'])
{
case 'open':
array_push($hash_stack, $val['tag']);
break;
case 'close':
array_pop($hash_stack);
break;
case 'complete':
array_push($hash_stack, $val['tag']);
eval("\$output['" . implode($hash_stack, "']['") . "'] = \"{$val['value']}\";");
array_pop($hash_stack);
break;
}
}
return $output;
}
####################################################
# XHTML tag handling... so that it can be stored as XML
# note that & goes FIRST so that subsequent encodings aren't screwed with.
function encodeTags($code){
$encoded = ereg_replace('&', '&', $code);
$encoded = ereg_replace('<', '<', $encoded);
$encoded = ereg_replace('>', '>', $encoded);
$encoded = ereg_replace('=', '=', $encoded);
$encoded = ereg_replace("'", ''', $encoded);
$encoded = ereg_replace('"', '"', $encoded);
return ($encoded);
}
####################################################
# XHTML tag handling... so that it can be stored as XML
function decodeTags($code){
$decoded = ereg_replace('<', '<', $code);
$decoded = ereg_replace('>', '>', $decoded);
return $encoded;
}
####################################################
# encoding difficult characters
function EncodeEntities ( $string )
{
$trans_tbl = array() ;
#$trans_tbl[chr(34)] = '"' ; // quote
$trans_tbl[chr(38)] = '&' ; // ampersand
#$trans_tbl[chr(60)] = '<' ; // less-than
#$trans_tbl[chr(62)] = '>' ; // more-than
$trans_tbl[chr(128)] = '€' ; // euro
$trans_tbl[chr(129)] = '€' ; // euro
$trans_tbl[chr(130)] = '‚' ; // low quote
$trans_tbl[chr(131)] = 'ƒ' ; // florin
$trans_tbl[chr(132)] = '„' ; // double low quote
$trans_tbl[chr(133)] = '…' ; // ellipsis
$trans_tbl[chr(134)] = '†' ; // dagger
$trans_tbl[chr(135)] = '‡' ; // double dagger
$trans_tbl[chr(136)] = 'ˆ' ; // circumflex
$trans_tbl[chr(137)] = '‰' ; // per thousand
$trans_tbl[chr(138)] = 'Š' ; // S caron
$trans_tbl[chr(139)] = '‹' ; // left angle quote
$trans_tbl[chr(140)] = 'Œ' ; // OE ligature
$trans_tbl[chr(142)] = 'Ž' ; // Z caron
$trans_tbl[chr(145)] = '‘' ; // left single quote
$trans_tbl[chr(146)] = '’' ; // right single quote
$trans_tbl[chr(147)] = '“' ; // left double quote
$trans_tbl[chr(148)] = '”' ; // right double quote
$trans_tbl[chr(149)] = '•' ; // bullet
$trans_tbl[chr(150)] = '–' ; // en dash
$trans_tbl[chr(151)] = '—' ; // em dash
$trans_tbl[chr(152)] = '˜' ; // small tilde
$trans_tbl[chr(153)] = '™' ; // trademark
$trans_tbl[chr(154)] = 'š' ; // small s caron
$trans_tbl[chr(155)] = '›' ; // right angle quote
$trans_tbl[chr(156)] = 'œ' ; // oe ligature
$trans_tbl[chr(158)] = 'ž' ; // small z caron
$trans_tbl[chr(159)] = 'Ÿ' ; // Y with diaeresis
for ( $i=160; $i<=255; $i++ ) {
$trans_tbl[chr($i)] = '' . $i . ';' ;
}
return strtr ( $string , $trans_tbl ) ;
}
####################################################
# security things
// This function checks the current request uri, to make sure it's not too long
// and therefore potentially full of shit. The default values are
// for a max uri size of 50 chars, and if too big to redirect to google.
function limit_uri($length = 75, $redirect = "http://www.google.com/"){
if( strlen($_SERVER['REQUEST_URI']) > $length
){
die("
Sorry
Not allowed, I'm afraid.
(error 1)
");
}
}
# this needs to be more clever...
function prevent_view(){
if( strstr($_SERVER['REQUEST_URI'], 'setup.inc')
){
die("
Sorry
Not allowed, I'm afraid.
(error 2)
");
}
}
####################################################
# uri processing things
// this code needs to check the URI and feed it to the page fetching functions
// with necessary alternatives for certain circumstances... etc.
function process_uri(){
global $debug, $subfolder, $config;
limit_uri(); // security check
#prevent_view(); // stop certain files from being accessed from browser
#---------------------------------------------------
# 1. check to see if a file with that name really exists
if(file_exists ($_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI']) and
($_SERVER['REQUEST_URI'] != "$subfolder/index.php") and
($_SERVER['REQUEST_URI'] != "$subfolder/") and
($_SERVER['REQUEST_URI'] != "$subfolder")){
$url=$_SERVER['REQUEST_URI'];
#echo '
This is an actual file, not from the database
';
include($_SERVER['DOCUMENT_ROOT'].$url);
exit;
}
#---------------------------------------------------
# 2. if not, check for content and get it
$url=strip_tags($_SERVER['REQUEST_URI']);
// need to rewrite this as a switch... construction.
if ($debug){
echo "
processing uri: $url
";
}
if ($url=="" ||
$url=="/" ||
$url=="/index.html" ||
$url=="$subfolder/index.html" ||
$url=="$subfolder/" ||
$url=="$subfolder"
){
$specific_page = $config[homepage];
return($specific_page);
} elseif (strstr($url,"$subfolder/editor/?")) {
$specific_page = "editor.xml";
return($specific_page);
} elseif (strstr($url,"$subfolder/modify/?")) {
$specific_page = "modify.xml";
return($specific_page);
} elseif ($url=="/add") {
$specific_page = "add.xml";
return($specific_page);
} elseif (strstr($url,"$subfolder/prefs")) {
$specific_page = "prefs.xml";
return($specific_page);
} elseif (strstr($url,"$subfolder/login")) {
$specific_page = "login.xml";
return($specific_page);
} elseif (strstr($url,"$subfolder/resources")) {
$specific_page = "resources.xml";
return($specific_page);
} elseif (strstr($url,"$subfolder/userpass")) {
$specific_page = "userpass.xml";
return($specific_page);
} elseif (strstr($url,"$subfolder/upload")) {
$specific_page = "upload.xml";
return($specific_page);
} elseif (strstr($url,"$subfolder/help")) {
$specific_page = "help.xml";
return($specific_page);
} elseif (checkForPage($url) != "nope"){
// the page request isn't one of the system pages
// and the page request does match something in the datastore
#print_r (checkForPage($url_array[$n]));
$getpage = checkForPage($url);
$thepage = $url;
return $getpage[$thepage];
} else {
$result='404.xml';
return $result;
}
}
############################################################
# function to draw dynamic body tag
function bodytag(){
global $page_info;
$body_id = str_replace(" ", "", strtolower($page_info[title]));
echo "";
}
############################################################
# function to insert code, for example for editor and login
function insertCode($page){
$codecheck = getXMLData($page, "code");
if ($codecheck != ""){
ob_start();
$code = getXMLData($page, "code");
@include_once ($code);
$buffer = ob_get_contents();
ob_end_clean();
print $buffer;
}
}
############################################################
# function to check for page existance...
function checkForPage($filename){
global $datastore;
global $subfolder;
$files = dirList($datastore);
// process
foreach ($files as $file){
$thispagearray = getXML($file);
$thispage = $thispagearray[page];
$pname = $thispage[pagename];
$name = $thispage[name];
$title = $thispage[title];
$type = $thispage[type];
$archive_date = $thispage[archive_date];
$archiveitem = strftime("/%G/%m",$archive_date).'/'.$pname;
#$archiveitem = $subfolder.$archiveitem;
// check to see if published
$pub = $thispage[publish];
// unpublished pages CANNOT be displayed
if($pub == "on"){
if($filename == $name){
$result = array($filename => $file);
break;
} elseif( $type == "alog" ||
$type == "qlog"
){
if ($filename == $archiveitem){
$result = array($filename => $file);
break;
}
} else {
$result = "nope";
}
}
}
#print_r ($result);
return $result;
}
############################################################
# function to exclude atomz. call function above and below code to be excluded, with
# variable 'start' and 'stop' to add the necessary bits
#
function xatomz($mode)
{
if($mode=='start') {
#echo '';
if ($HTTP_USER_AGENT == "Atomz/1.0") { echo "