');
}
####################################################
####################################################
// 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 ""; }
} else {
#echo '';
if ($HTTP_USER_AGENT == "Atomz/1.0") { echo ""; }
}
}
############################################################
# function to get directory listing
#
function dirList($folder){
//Load Directory Into Array
$handle=opendir($folder) or die ("Can't open $folder: $php_errormsg");
while ($item = readdir($handle))
if ( !strstr($item, '.trash') &&
$item != "notverysecurepasswordfile.inc" &&
$item != ".DS_Store" &&
$item != ".htaccess" &&
$item != "." &&
$item != ".."
){
$files[] = $item;
}
//Clean up
closedir($handle);
return $files;
}
############################################################
# function to get an array containing the directories in a certain place...
#
function pagelist($folder){
//Load Directory Into Array
$files = dirList($folder);
// process
foreach ($files as $file){
// check to see if protected, and if so, don't show
if (
# getXMLData($file, 'title') != 'Main Preferences'
getXMLData($file, 'protected') != 'on'
){
/*$fields = array(
'id',
'parent',
'type',
'archive_date',
'title',
'sort',
'name',
'publish',
'menu',
'protected',
'locked',
'excerpt'
);*/
$filelistarray = getXML($file);
$filelist[] = $filelistarray[page];
}
}
return $filelist;
}
############################################################
# function to count number of files.
#
function filecount(){
global $datastore;
//Load Directory Into Array - special version which only picks up unprotected files...
$handle=opendir($datastore) or die ("Can't open $datastore: $php_errormsg");
while ($item = readdir($handle))
if ( !strstr($item, '.trash') &&
$item != "notverysecurepasswordfile.inc" &&
$item != ".DS_Store" &&
$item != ".htaccess" &&
$item != "." &&
$item != ".." &&
getXMLData("$item", 'protected') != 'on' &&
getXMLData("$item", 'name') != '404' &&
getXMLData("$item", 'name') != 'help'
){
$files[] = $item;
#echo $item;
}
//Clean up
closedir($handle);
// process
$filecount = count($files);
return $filecount;
}
############################################################
# function to sort out which pages to display
#
function filter($menuitems){
foreach ($menuitems as $file => $info){
if ( $info[menu] == "on" &&
$info[publish] == "on" &&
$info[type] != "alog" &&
$info[type] != "qlog"
){
$filtered[] = $info;
}
}
return $filtered;
}
############################################################
# function to get only the archive pages
#
function editfilter($menuitems){
foreach ($menuitems as $file => $info){
if (
$info[type] != "alog" &&
$info[type] != "qlog"
){
$editfiltered[] = $info;
}
}
return $editfiltered;
}
############################################################
# function to get only the archive pages
#
function archivefilter($menuitems){
foreach ($menuitems as $file => $info){
if (
$info[type] == "alog" ||
$info[type] == "qlog"
){
$archivefiltered[] = $info;
}
}
return $archivefiltered;
}
############################################################
# function to sort out and draw menu
#
function makepath($page){
# -------------------------------------------
# start tracking page lineages
$n=0;
$lineage[$n] = $page[parent];
while ($lineage[$n] > 0){
$work = lookupName($lineage[$n]);
$n++;
$lineage[$n] = getXMLData($work, 'parent');
}
$lineage = array_reverse($lineage);
# reset path, otherwise we get section1/section1/section1 etc.
unset($path);
unset($itemdepth);
# build up URL
foreach ($lineage as $ancestor){
$par = lookupParent($ancestor);
if(!empty($par)){
$pararray = explode('/', $par);
$justname = array_pop($pararray);
$par = $justname;
if ($par == ''){
$path = '';
} else {
$path .= "$par/";
}
$itemdepth++;
}
}
#if($path==''){ $path ='/'; }
#echo $path;
return $path;
}
############################################################
# function to sort out and draw menu
#
function menu($folder, $mode='open', $parent=0, $level=0, $id='menu', $editmode='off'){
global $page, $debug;
if (strstr($_SERVER['REQUEST_URI'], 'editor')){ $mode = 'open'; }
$files = pageList($folder);
arraySort ($files, "sort");
# filtering is here to decide which files get shown when in the editor/dashbaord
if ($editmode=='editmode'){
$files = editfilter($files);
} elseif ($editmode=='archivemode'){
$files = archivefilter($files);
arraySort ($files, "archive_date", "SORT_DESC");
} else {
$files = filter($files);
}
if($level > 0){
$parent = getXMLData($page, 'id');
}
# -------------------------------------------------
#echo count($files);
#foreach ($files as $i => $menuitem){
for ($i = 0; $i <= count(pageList($folder)); $i++) {
#echo $i;
foreach ($files as $x => $menuitemcrosscheck){
$ans = "";
if ($menuitemcrosscheck[parent] == $i ){
$structure[$i][] = $menuitemcrosscheck;
$ans = " *********";
}
if ($debug) {
echo 'looking at page id '.$menuitemcrosscheck[id].' (called '.$menuitemcrosscheck[title].') which has parent '.$menuitemcrosscheck[parent].' to see if the parent matches '.$i.$ans.' '; }
}
}
#echo '
';
#print_r($structure);
#echo '
';
foreach ($structure as $s => $sections){
$sectionsize[$s] = count($sections);
}
foreach ($sectionsize as $n => $section){
#echo " in section $n : $sectionsize[$n] ";
}
# -------------------------------------------------
// process
if ($editmode == "archivemode") {
$hidestatus = " class=\"togglehide\"";
} else {
$hidestatus = "";
}
echo "
\n";
}
############################################################
# function to draw menu
function displayMenu($menuitems, $mode, $parent, $level, $sectionsize, $editmode){
// $menuitems is the array with pages and their data in
// $parent is the level to start at: 0 is root level
// $level is the level we are currently at while looping through...
global $page, $subfolder;
foreach ($menuitems as $s => $menuitem){
if (isset($_SESSION['validusername']) && $editmode != "editmode" && $editmode != "archivemode"){
#$mode='closed'; // prevent open menus during editing, but not in editmenu or archive
}
# -------------------------------------------
// indicate if a section has subitems
if($sectionsize[$menuitem{id}] > 0) {
$exp = " exp"; # additional class for expandable items
} else {
$exp = "";
}
# -------------------------------------------
// add active status for list item tags
// ie. if active *or within an active section*
if (getXMLData($page, 'id') == $menuitem[id] ||
getXMLData($page, 'parent') == $menuitem[id]
){
$listatus = " class=\"on\"";
} else {
$listatus = "";
}
# -------------------------------------------
if (getXMLData($page, 'id') == $menuitem[id]
){
// css-free active items - do we need BOTH?
$stropen = '';
$strclose = '';
$astatus = " class=\"on$exp\"";
} elseif(getXMLData($page, 'parent') == $menuitem[id]) {
// active within sections
$astatus = " class=\"on$exp\"";
} else {
// clear variables if not
$stropen = '';
$strclose = '';
$astatus = " class=\"off$exp\"";
}
# -------------------------------------------
# -------------------------------------------
if($editmode == "editmode"){ // if in edit mode - indicate publish status
// (instead of 'on' class)
$astatus = ' class="p"';
$pstatus = 'published, and is set to appear in the menu';
if($menuitem[menu] != 'on') {
$astatus = ' class="xm"';
$pstatus = 'published, but is not set to appear in the menu';
} elseif($menuitem[publish] != 'on') {
$astatus = ' class="xp"';
$pstatus = 'not published, but is set to appear in the menu';
}
if($menuitem[menu] != 'on' && $menuitem[publish] != 'on') {
$astatus = ' class="xp"';
$pstatus = 'not published, and set not to appear in the menu';
}
}
# start drawing the menu
if ($menuitem[parent] == $parent){
if ($level > 0 &&
$i == 0
){
// first loop only
echo "
";
}
echo "
";
# if ($level > $depth){ // this is (on the way to) how to do menu modes...
$i++;
if($editmode == "statusmode"){
########################// special status version of menu
echo "$menuitem[title]$menuitem[name]$menuitem[sort]";
} elseif($editmode == "editmode"){
########################// special editor version of menu
$length = strlen($menuitem[title]);
// shorten long names for the menu
if($length > 26){
$edit_title = str_chop($menuitem[title], 26, true);
} else {
$edit_title = $menuitem[title];
}
echo "".$stropen.$edit_title.$strclose."";
} elseif($editmode == "archivemode"){
########################// special archive version of menu
$length = strlen($menuitem[title]);
// shorten long names for the menu
if($length > 26){
$edit_title = str_chop($menuitem[title], 26, true);
} else {
$edit_title = $menuitem[title];
}
echo "".$stropen.$edit_title.$strclose." - ".strftime("%e/%m/%G",$menuitem[archive_date])."";
} else {
########################// normal menu drawing happens here
echo "".$stropen.$menuitem[title].$strclose."";
}
//
if($mode == 'closed'){
//look to see if this item has relevant ancestor
if(getXMLData($page, 'parent')!=0){
$thisparent = getXMLData($page, 'parent');
$gparid = lookupID($thisparent);
$grandparent = lookupParent($gparid);
}
if ( getXMLData($page, 'id') == $menuitem[id] ||
getXMLData($page, 'parent') == $menuitem[id]
#||
#getXMLData($page, 'grandparent') == $menuitem[id]
){
// only draw the next bit of the menu if we're in that section etc.
displayMenu($menuitems, $mode, $menuitem[id], $level+1, $sectionsize, $editmode);
}
} else { //menumode is 'open'
displayMenu($menuitems, $mode, $menuitem[id], $level+1, $sectionsize, $editmode);
}
echo "