';
$curdir = getcwd();
if (stristr($_SERVER['SERVER_SOFTWARE'], 'apache')) {
$soft = "Apache, which is likely to be called www-data, ";
} elseif (stristr($_SERVER['SERVER_SOFTWARE'], 'IIS')) {
$soft = "IIS, which is likely to be called IUSR_".php_uname("n").", ";
} else {
$soft = "";
}
$uname = php_uname("s");
if (strtoupper(substr($uname, 0, 3)) === 'WIN') {
$os = "Windows";
} else {
$os = "a Unix of some description";
}
echo <<<__EOF
Installation failed. I do not have permission to write
files in this folder.
This machine appears to be using $os. You should give write
permissions to this folder ($curdir) to the user account that runs $soft
and then refresh this page.
__EOF;
die();
}
function failed_install_template($fname) {
echo 'FAIL';
echo <<<__EOF
Installation failed. Writing out the template file "$fname" failed.
__EOF;
die();
}
function search() {
$parts = explode("cruciforum.php",$_SERVER["SCRIPT_NAME"]);
$url = "http://" . $_SERVER["HTTP_HOST"] . $parts[0];
$user = $_GET["user"];
$srch = "http://www.google.com/search?q=inurl:$url+%22Author: $user%22";
header("Location: $srch");
}
function email() {
echo "not yet ";
echo "email to ";
global $FROMTR, $TOTR;
$decemail = strtr($_GET["email"], $TOTR, $FROMTR);
echo $decemail;
die();
}
function newthread() {
// load passed data
$textile = new Textile;
$text = $textile->TextileRestricted(stripslashes($_POST["text"]),1);
$name = trim(htmlentities(stripslashes($_POST["name"])));
if ($name == "") $name = "anonymous";
$subject = htmlentities(stripslashes($_POST["threadsubject"]));
if ($subject == "") $subject = "(post by $name)";
$website = trim(htmlentities(stripslashes($_POST["website"])));
if ($website != "") {
// prefix http if required
if (strpos($website,"http") != 0) {
$website = "http://" . $website;
}
$website = "→";
}
$email = trim(htmlentities(stripslashes($_POST["email"])));
global $FORUMNAME;
if ($email != "") {
global $FROMTR, $TOTR;
$encemail = strtr($email, $FROMTR, $TOTR);
$emailhref = "→";
} else {
$emailhref = "";
}
// get the lock
$lockfile = fopen('editing.lock','w');
flock($lockfile,LOCK_EX);
// find highest post number and add 1
$next_post_number = getNextPostNumber();
$long_next_post_number = sprintf('%09d',$next_post_number);
// create dt/dl for tN.html
global $extras;
$dtdl = fill_template($extras["thread_page_post"], Array(
"TEXT" => $text,
"NAME" => $name,
"EMAIL" => $emailhref,
"WEBSITE" => $website,
"EMAILMD5" => md5($email),
"DATE" => date('d/m/y H.i')
));
// load thread.tmpl, write out tN.html
write_from_template("thread.tmpl", makeFilename($next_post_number,"t"), Array(
"THREADTITLE" => $subject,
"FORUMNAME" => $FORUMNAME,
"THREADID" => $long_next_post_number,
"FIRSTPOST" => $dtdl
));
// load tpost.tmpl, write out tpostN.html
write_from_template("tpost.tmpl", makeFilename($next_post_number,"tpost"), Array(
"THREADTITLE" => $subject,
"FORUMNAME" => $FORUMNAME,
"THREADID" => $long_next_post_number
));
// create LI for index.html
$li = fill_template($extras["index_page_link"], Array(
"THREADTITLE" => $subject,
"NAME" => $name,
"THREADFILE" => makeFilename($next_post_number,"t"),
"DATE" => date("jS M y")
));
// load index.html
$indexdata = file_get_contents("index.html");
// does index.html have too many threads in?
$threadcount = substr_count($indexdata, '
');
global $THREADS_PER_LIST_PAGE;
if ($threadcount >= intval($THREADS_PER_LIST_PAGE * 1.5)) {
// find highest list number and add 1
$highest = 0;
foreach (glob('l[0-9]*.html') as $fn) {
# strip off the number at the beginning
if (preg_match('/l([0-9]+)\.html/', $fn, $matches)) {
$num = intval($matches[1]);
if ($num > $highest) $highest = $num;
}
}
$newlistnum = $highest + 1;
// load list.tmpl
$tmpldata = file_get_contents("list.tmpl");
if ($newlistnum == 1) {
$backdest = "index.html";
} else {
$backdest = "l".$highest.".html";
}
$tmpldata = fill_template($tmpldata, Array(
"FORUMNAME" => $FORUMNAME,
"PREVPAGE" => $backdest
));
$indexdata = preg_replace(
'/(id="prev" href=")[^"]+(">previous posts)/',
'${1}l' . $newlistnum . '.html$2',
$indexdata
);
// extract all
s from index.html
preg_match_all('/
.*?<\/li>/s', $indexdata, $matches); // use . instead of " or it doesn't work
$new_page_parts = array_slice($matches[0], -$THREADS_PER_LIST_PAGE);
$index_page_parts = array_slice($matches[0], 0, -($THREADS_PER_LIST_PAGE));
$new_page_lis = "";
$index_page_lis = "";
foreach ($new_page_parts as $part) {
$new_page_lis .= $part . "\n";
}
foreach ($index_page_parts as $part) {
$index_page_lis .= $part . "\n";
}
// remove all lis from indexdata
$indexdata = preg_replace('/
.*?<\/li>/s','',$indexdata);
// add the index lis to indexdata
$indexdata = str_replace("", $index_page_lis . "\n", $indexdata);
file_put_contents("index.html", $indexdata);
$tmpldata = str_replace("", $new_page_lis . "\n", $tmpldata);
file_put_contents("l" . $newlistnum . ".html", $tmpldata);
// put those threads into lN.html
}
// add LI to index.html
$indexdata = str_replace('
', '
' . "\n" . $li, $indexdata);
// write out index.html
file_put_contents("index.html", $indexdata);
// release the lock
flock($lockfile,LOCK_UN);
// redirect to tN.html
header("Location: " . makeFilename($next_post_number,"t"));
die();
}
function getNextPostNumber() {
// does a binary search to find the highest filename
$max = 1;
while (file_exists(makeFilename($max,"t"))) {
$max = $max * 2;
}
$min = intval($max / 2);
while ($max - $min > 1) {
$guess = intval(($min + $max) / 2);
if (file_exists(makeFilename($guess,"t"))) {
$min = $guess;
} else {
$max = $guess;
}
}
return $max;
}
function makeFilename($n, $prefix) {
// make a 000/056/t123456789.html filename from 56789
$n2 = sprintf('%09d',$n);
return substr($n2,0,3) . "/" . substr($n2,3,3) . "/" . $prefix . $n2 . ".html";
}
function newpost() {
// load passed data
$threadid = $_POST["thread"];
if (!is_numeric($threadid)) badcall();
$textile = new Textile;
$text = $textile->TextileRestricted(stripslashes($_POST["text"]),1);
$name = trim(htmlentities(stripslashes($_POST["name"])));
if ($name == "") $name = "anonymous";
$website = trim(htmlentities(stripslashes($_POST["website"])));
if ($website != "") {
// prefix http if required
if (strpos($website,"http") != 0) {
$website = "http://" . $website;
}
$website = "→";
}
$email = trim(htmlentities(stripslashes($_POST["email"])));
if ($email != "") {
global $FROMTR, $TOTR;
$encemail = strtr($email, $FROMTR, $TOTR);
$emailhref = "→";
} else {
$emailhref = "";
}
// get the lock
$lockfile = fopen('editing.lock','w');
flock($lockfile,LOCK_EX);
// load tN.html
$fname = makeFilename($threadid,"t");
$data = file_get_contents($fname);
// create dt/dd of post
global $extras;
$dtdl = fill_template($extras["thread_page_post"], Array(
"TEXT" => $text,
"NAME" => $name,
"EMAIL" => $emailhref,
"WEBSITE" => $website,
"EMAILMD5" => md5($email),
"DATE" => date('d/m/y H.i')
));
// write dt/dd into tN.html
$data = str_replace('', $dtdl . "\n", $data);
file_put_contents($fname, $data);
// loop
// load index.html, l1.html, l2.html, ...
// look for this thread link
// update number of replies in url
// write out file
$ret = increment_reply_count("index.html", $fname);
if ($ret == "notfound") {
$filec = 1;
while ($ret != "nosuchfile") {
$ret = increment_reply_count("l" . $filec . ".html", $fname);
if ($ret == "success") break;
}
}
// release the lock
flock($lockfile,LOCK_UN);
// redirect to tN.html
header("Location: " . makeFilename($threadid,"t"));
die();
}
function increment_reply_count($indexfile, $fname) {
if (!file_exists($indexfile)) return "nosuchfile";
$data = file_get_contents($indexfile);
if (strpos($data, $fname) === FALSE) {
return "notfound";
}
$re = '/' . str_replace("/","\\/",$fname) . '\?replies=([0-9]+)"/';
$v = preg_match($re, $data, $matches);
$replies = intval($matches[1]);
$replies += 1;
$data = str_replace($matches[0], $fname . "?replies=" . $replies . '"', $data);
file_put_contents($indexfile, $data);
}
function createfolder( $folder ) {
$folder = explode( "/" , $folder );
$mkfolder = '';
for( $i=0 ; isset( $folder[$i] ) ; $i++ ) {
$mkfolder .= $folder[$i];
if( !is_dir( $mkfolder ) )
mkdir( "$mkfolder" , 0777);
$mkfolder .= '/';
}
}
/**
* Example: get XHTML from a given Textile-markup string ($string)
*
* $textile = new Textile;
* echo $textile->TextileThis($string);
*
*/
/*
$Id: classTextile.php 216 2006-10-17 22:31:53Z zem $
$LastChangedRevision: 216 $
*/
/*
_____________
T E X T I L E
A Humane Web Text Generator
Version 2.0
Copyright (c) 2003-2004, Dean Allen
All rights reserved.
Thanks to Carlo Zottmann for refactoring
Textile's procedural code into a class framework
Additions and fixes Copyright (c) 2006 Alex Shiels http://thresholdstate.com/
_____________
L I C E N S E
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name Textile nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
_________
U S A G E
Block modifier syntax:
Header: h(1-6).
Paragraphs beginning with 'hn. ' (where n is 1-6) are wrapped in header tags.
Example: h1. Header... ->
Header...
Paragraph: p. (also applied by default)
Example: p. Text ->
Square [brackets] insert language attributes
p[no]. paragraph ->
paragraph
%[fr]phrase% -> phrase
Usually Textile block element syntax requires a dot and space before the block
begins, but since lists don't, they can be styled just using braces
#{color:blue} one ->
# big
one
# list
big
list
Using the span tag to style a phrase
It goes like this, %{color:red}the fourth the fifth%
-> It goes like this, the fourth the fifth
*/
class Textile
{
var $hlgn;
var $vlgn;
var $clas;
var $lnge;
var $styl;
var $cspn;
var $rspn;
var $a;
var $s;
var $c;
var $pnct;
var $rel;
var $fn;
var $shelf = array();
var $restricted = false;
var $noimage = false;
var $lite = false;
var $url_schemes = array();
var $glyph = array();
var $hu = '';
var $ver = '2.0.0';
var $rev = '$Rev: 216 $';
// -------------------------------------------------------------
function Textile()
{
$this->hlgn = "(?:\<(?!>)|(?|\<\>|\=|[()]+(?! ))";
$this->vlgn = "[\-^~]";
$this->clas = "(?:\([^)]+\))";
$this->lnge = "(?:\[[^]]+\])";
$this->styl = "(?:\{[^}]+\})";
$this->cspn = "(?:\\\\\d+)";
$this->rspn = "(?:\/\d+)";
$this->a = "(?:{$this->hlgn}|{$this->vlgn})*";
$this->s = "(?:{$this->cspn}|{$this->rspn})*";
$this->c = "(?:{$this->clas}|{$this->styl}|{$this->lnge}|{$this->hlgn})*";
$this->pnct = '[\!"#\$%&\'()\*\+,\-\./:;<=>\?@\[\\\]\^_`{\|}\~]';
$this->urlch = '[\w"$\-_.+!*\'(),";\/?:@=&%#{}|\\^~\[\]`]';
$this->url_schemes = array('http','https','ftp','mailto');
$this->btag = array('bq', 'bc', 'notextile', 'pre', 'h[1-6]', 'fn\d+', 'p');
$this->glyph = array(
'quote_single_open' => txt_quote_single_open,
'quote_single_close' => txt_quote_single_close,
'quote_double_open' => txt_quote_double_open,
'quote_double_close' => txt_quote_double_close,
'apostrophe' => txt_apostrophe,
'prime' => txt_prime,
'prime_double' => txt_prime_double,
'ellipsis' => txt_ellipsis,
'emdash' => txt_emdash,
'endash' => txt_endash,
'dimension' => txt_dimension,
'trademark' => txt_trademark,
'registered' => txt_registered,
'copyright' => txt_copyright,
);
if (defined('hu'))
$this->hu = hu;
}
// -------------------------------------------------------------
function TextileThis($text, $lite='', $encode='', $noimage='', $strict='', $rel='')
{
if ($rel)
$this->rel = ' rel="'.$rel.'" ';
$this->lite = $lite;
$this->noimage = $noimage;
if ($encode) {
$text = $this->incomingEntities($text);
$text = str_replace("x%x%", "&", $text);
return $text;
} else {
if(!$strict) {
$text = $this->cleanWhiteSpace($text);
}
$text = $this->getRefs($text);
if (!$lite) {
$text = $this->block($text);
}
$text = $this->retrieve($text);
// just to be tidy
$text = str_replace(" ", " \n", $text);
return $text;
}
}
// -------------------------------------------------------------
function TextileRestricted($text, $lite=1, $noimage=1, $rel='nofollow')
{
$this->restricted = true;
$this->lite = $lite;
$this->noimage = $noimage;
if ($rel)
$this->rel = ' rel="'.$rel.'" ';
// escape any raw html
$text = $this->encode_html($text, 0);
$text = $this->cleanWhiteSpace($text);
$text = $this->getRefs($text);
if ($lite) {
$text = $this->blockLite($text);
}
else {
$text = $this->block($text);
}
$text = $this->retrieve($text);
// just to be tidy
$text = str_replace(" ", " \n", $text);
return $text;
}
// -------------------------------------------------------------
function pba($in, $element = "") // "parse block attributes"
{
$style = '';
$class = '';
$lang = '';
$colspan = '';
$rowspan = '';
$id = '';
$atts = '';
if (!empty($in)) {
$matched = $in;
if ($element == 'td') {
if (preg_match("/\\\\(\d+)/", $matched, $csp)) $colspan = $csp[1];
if (preg_match("/\/(\d+)/", $matched, $rsp)) $rowspan = $rsp[1];
}
if ($element == 'td' or $element == 'tr') {
if (preg_match("/($this->vlgn)/", $matched, $vert))
$style[] = "vertical-align:" . $this->vAlign($vert[1]) . ";";
}
if (preg_match("/\{([^}]*)\}/", $matched, $sty)) {
$style[] = rtrim($sty[1], ';') . ';';
$matched = str_replace($sty[0], '', $matched);
}
if (preg_match("/\[([^]]+)\]/U", $matched, $lng)) {
$lang = $lng[1];
$matched = str_replace($lng[0], '', $matched);
}
if (preg_match("/\(([^()]+)\)/U", $matched, $cls)) {
$class = $cls[1];
$matched = str_replace($cls[0], '', $matched);
}
if (preg_match("/([(]+)/", $matched, $pl)) {
$style[] = "padding-left:" . strlen($pl[1]) . "em;";
$matched = str_replace($pl[0], '', $matched);
}
if (preg_match("/([)]+)/", $matched, $pr)) {
// $this->dump($pr);
$style[] = "padding-right:" . strlen($pr[1]) . "em;";
$matched = str_replace($pr[0], '', $matched);
}
if (preg_match("/($this->hlgn)/", $matched, $horiz))
$style[] = "text-align:" . $this->hAlign($horiz[1]) . ";";
if (preg_match("/^(.*)#(.*)$/", $class, $ids)) {
$id = $ids[2];
$class = $ids[1];
}
if ($this->restricted)
return ($lang) ? ' lang="' . $lang .'"':'';
return join('',array(
($style) ? ' style="' . join("", $style) .'"':'',
($class) ? ' class="' . $class .'"':'',
($lang) ? ' lang="' . $lang .'"':'',
($id) ? ' id="' . $id .'"':'',
($colspan) ? ' colspan="' . $colspan .'"':'',
($rowspan) ? ' rowspan="' . $rowspan .'"':''
));
}
return '';
}
// -------------------------------------------------------------
function hasRawText($text)
{
// checks whether the text has text not already enclosed by a block tag
$r = trim(preg_replace('@<(p|blockquote|div|form|table|ul|ol|pre|h\d)[^>]*?>.*\1>@s', '', trim($text)));
$r = trim(preg_replace('@<(hr|br)[^>]*?/>@', '', $r));
return '' != $r;
}
// -------------------------------------------------------------
function table($text)
{
$text = $text . "\n\n";
return preg_replace_callback("/^(?:table(_?{$this->s}{$this->a}{$this->c})\. ?\n)?^({$this->a}{$this->c}\.? ?\|.*\|)\n\n/smU",
array(&$this, "fTable"), $text);
}
// -------------------------------------------------------------
function fTable($matches)
{
$tatts = $this->pba($matches[1], 'table');
foreach(preg_split("/\|$/m", $matches[2], -1, PREG_SPLIT_NO_EMPTY) as $row) {
if (preg_match("/^($this->a$this->c\. )(.*)/m", ltrim($row), $rmtch)) {
$ratts = $this->pba($rmtch[1], 'tr');
$row = $rmtch[2];
} else $ratts = '';
$cells = array();
foreach(explode("|", $row) as $cell) {
$ctyp = "d";
if (preg_match("/^_/", $cell)) $ctyp = "h";
if (preg_match("/^(_?$this->s$this->a$this->c\. )(.*)/", $cell, $cmtch)) {
$catts = $this->pba($cmtch[1], 'td');
$cell = $cmtch[2];
} else $catts = '';
$cell = $this->graf($this->span($cell));
if (trim($cell) != '')
$cells[] = "\t\t\t$cell";
}
$rows[] = "\t\t