/text.php
PHP | 692 lines | 646 code | 10 blank | 36 comment | 105 complexity | 51170031c723af15772d56f7e9e9f3e9 MD5 | raw file
- <?php
- # This is the text parser.
- /*function $text {
- if ( $mode == "_" ) $text = str_replace("_"," ",$text);
- else $text = str_replace(" ","_",$text);
- return $text;
- }*/
- function listItems($list,$del) {
- $list = preg_replace('#^'.$del.' (.+?)$#im','<li>$1</li>',$list);
- //$list = preg_replace('#\\\\"(.+?)\\\\"#im','"$1"',$list);
- return $list;
- }
- function parseText($text) {
- global $opts,$lang;
- $data = preg_split("#$#im",$text);
- if ( isset($_GET['text']) || ( isset($_GET['export']) && $_GET['export'] == 'text' ) ) {
- $omode = 'text';
- } else {
- $omode = '';
- }
- $filters = array(
- # List items
- # Headers
- 'chea' => array('#^h([1-7])\.([a-z0-9]+)?:([^:]*):([^:]*): *(.+)#im','<h$1 style="color:$3;background:$4;" id="$2">$5</h$1>','$5'."\n".str_pad($opts['hhSt'],$opts['hhSz'],$opts['hhSt'],STR_PAD_LEFT) ),
- 'hea' => array('#^h([1-7])\.([a-z0-9]+)? *(.+)#im','<h$1 id="$2">$3</h$1>','$3'."\n".str_pad($opts['hhSt'],$opts['hhSz'],$opts['hhSt'],STR_PAD_LEFT)."\n" ),
- # href
- array('#(?![\\w\/\\\\])"([^"]+)":([^ <>|\\s]+(?:[a-z0-9?&/]))(?!\\w)#im','<a href="$2">$1</a>','$1'),
- # target
- array('#(?![\\w\/\\\\])\\^([^^:]+):([^^]+)\\^#im','<a href="#$1">$2</a>','$2'),
- # TagLink
- array('#(?<![\w/\\\\])\{, *([^\\r\\n\\t}:]+) *}#ime','\'<a href="./?tag=\'.\'$1\'.\'" class="wikiPage">$1</a>\'','\'$1\''),
- # WikiPage
- //<a href="./?page=$1" class="wikiPage">$1</a>
- array('#(?<![\w/\\\\])\{ *([^\\r\\n\\t}:]+?) *}#ime','\'<a href="./?page=\'.\'$1\'.\'" class="wikiPage">$1</a>\'','\'$1\''),
- array('#(?<![\w/\\\\])\{ *([^\\r\\n\\t}:]+[^ }]) *}#ime','\'<a href="./?page=\'.\'$1\'.\'" class="wikiPage">$1</a>\'','\'$1\''),
- array('#(?<![\w/\\\\])\{ *([^\\r\\n\\t}:]+[^ }]):(text|html) *}#ime','\'<a href="./?export=$2&page=\'.\'$1\'.\'" class="wikiPage">$1</a>\'','\'$1\''),
- array('#(?<![\w/\\\\])\{ *([^\\r\\n\\t}:]+[^ }])\#([\\w]+)(?::(text|html))? *}#ime','\'<a href="./?page=\'.\'$1\'.\'&export=$3#$2" class="wikiPage">$1</a>\'','\'$1\''),
- # Italics
- array('#(?<![\\w/\\\\])/([^/<>]+)/(?![\\w/>])#im','<span style="font-style:italic;">$1</span>','$1'),
- # Underline
- array('#(?<![\\w\\\\])_([^_]+)_(?![\\w])#im','<span style="text-decoration:underline;">$1</span>','$1'),
- # Bold
- array('#(?<![\\w\\\\])\\*(?! )([^*]+)\\*(?![\\w])#im','<strong>$1</strong>','$1'),
- # Del
- array('#(?<![\\w\\\\-])-((?!-).+?)-(?![\\w-])#im','<del>$1</del>','$1'),
- # Colors
- array('#(?<![\\w\\\\])%:([^:]*):([^:]*):([^%]+?)%#im','<span style="color:$1; background:$2;">$3</span>','$3'),
- # Search Link
- array('#(?<![\\w\\\\])\{([^\\r\\n\\t}]+)(?:\#|>|>) *([^\\r\\n\\t}]+) *: *([a-z0-9]+) (.*?) *}#im','<a href="./?search=$2&q=$3 $4">$1</a>','$3'),
- array('#(?<![\\w\\\\])\{(?:\#|>|>) *([^\\r\\n\\t}]+) *: *([a-z0-9]+) (.*?) *}#im','<a href="./?search=$1&q=$2 $3">$3</a>','$3'),
- # Image
- array('#!l:([^\\s\\\\!]+)!?([^!]*)!#im','<img src="$1" align="left" alt="$2" />','[$2]'),
- array('#!r:([^\\s\\\\!]+)!?([^!]*)!#im','<img src="$1" align="right" alt="$2" />','[$2]'),
- array('#!([^\s\\\\!]+)\\!?([^!]*)!#im','<img src="$1" alt="$2" />','[$2]'),
- # Rogue Hyperlink
- array('#(?<![\\w\\\\:!"])(http|ftp|gopher|irc|https)://[^" <>\\s]+#im','<a href="$0">$0</a>','$0'),
- # Horizontal rule
- array('#^---([0-9a-z]+)?$#im',"<hr id=".'"$1"'." />",str_pad($opts['hrSt'],$opts['hrSz'],$opts['hrSt'],STR_PAD_LEFT)."\n" ),
- # Search Box
- array('#(?<![\\w\\\\])\#searchBox (.*?)\##im','<form method="get" action="./"><input type="hidden" name="search" value="$1" /><input type="text" name="q" /><input type="submit" value="'.$lang['searBtn'].'" /> <a href="./?search=$1">'.$lang['searHlL'].'</a></form>',''),
- # Block quote
- 'blk' => array('#^: ([^\\r\\n]+)$#im','<blockquote>$1</blockquote>',' "$1"',0),
- # Colored Paragraphs
- 'cpar' => array('#^:([^:]*):([^:]*):(.+?)$#im','<div style="color:$1;background:$2;">$3</div>','$3',0),
- # Breaks
- 'brk' => array('#^(?!===|<blockquote|<h[0-7r]|</?pre|</?li|</?ul|</?ol|<table|<tr|<td)([\\s]+)$#im','<br />','$1',0),
- # Paragraphs
- 'par' => array('#^(?!===|<blockquote|<h[0-7r]|</?pre|</?li|</?ul|</?ol|<table|<tr|<td|<br)(.+?)$#im','<div>$1</div>','$1','$1',0),
- );
- # Filters to NOT process in pre-plus mode
- $preplusNo = array('brk','cpar','par','blk','hea','chea');
- if ( $omode === 'text' ) {
- foreach ( $filters as $num => $text ) {
- $filters[$num][1] = $text[2];
- }
- }
- $mode = ''; // table/list mode indicator
- $level = 0; // current level in list mode
- $dlevel = 0; // delimeter level
- $lcnt = 1; // counter for numbered lists in text mode
- $datNum = 0;
- $relNum = 0;
- foreach ( $data as $textNum => $text ) {
- # Get User Filters
- if ( is_file("pages/$opts[usersyntax].php") ) {
- $userSyntaxClass = new configParse;
- $userSyntax = $userSyntaxClass->parseFile(getPage("pages/$opts[usersyntax].php"));
- if ( is_array($userSyntax) ) {
- foreach($userSyntax as $find => $repl) {
- if ( preg_match('#(.*?) (%[0-9]+)#im',$repl,$reRepl) ) {
- $repl = $reRepl[1];
- $trepl = $reRepl[2];
- }
- if ( isset($_GET['export']) && $_GET['export'] == 'text' ) {
- if ( isset($trepl) ) {
- $repl = $trepl;
- } else {
- $repl = '%1';
- }
- }
- preg_match_all('#%[0-9]+#im',$find,$vars);
- # Escape all regex special chars
- $find = preg_replace('#([][()+?*^$\\{}\#\\\\|.])#im','\\\\$1',$find);
- $Rxfind = '#(?<![\\w\\\\])';
- $Rxfind .= preg_replace('#%[0-9]+#im','(.*?)',$find);
- $Rxfind .= '(?![\\w])#im';
- $Rxrepl = preg_replace('#%([0-9]+)#im','\$$1',$repl);
- $text = preg_replace($Rxfind,$Rxrepl,$text);
- //([^*]+)
- }
- }
- }
- # Preformatted
- if ( preg_match('#^===\\+?(:[^:]*:[^:]*:)?$#im',$text) && ( $mode != 'pre' && $mode != 'preplus') ) {
- $text = trim($text);
- if ( $tabmode == 'tab' ) {
- $output[count($output)-1] .= "\n</table>\n";
- $tabmode = '';
- }
- if ( preg_match('#^===\\+#im',$text) ) {
- $mode = 'preplus';
- } else {
- $mode = 'pre';
- }
- if ( $omode === 'text' ) {
- $text = preg_replace('#^===\\+?.*?$#im','',$text);
- } else {
- $text = preg_replace('#^===\\+?$#im','<pre>',$text);
- $text = preg_replace('#^===\\+?:([^:]*):([^:]*):$#im','<pre style="color:$1;background:$2;">',$text);
- }
- } elseif ( preg_match('#^===\\+?$#im',$text) && ( $mode == 'pre' || $mode == 'preplus' ) ) {
- $mode = '';
- if ( $omode !== 'text' ) {
- $text = preg_replace('#^===\\+?$#im','</pre>',$text);
- } else {
- $text = preg_replace('#^===\\+?$#im','',$text);
- }
- }
- if ( $omode === 'text' && $mode != 'pre' ) {
- foreach ( $filters as $num => $filter) {
- if ( ( $num != 'pre' && $num != 'cpre') ) {
- $text = preg_replace($filter[0],$filter[1],$text);
- }
- }
- }
- if ( !preg_match('#^;.*#im',$text) ) {
- if ( preg_match('#^===\\+?(:[^:]*:[^:]*:)?$#im',$text) && ( $mode != 'pre' && $mode != 'preplus') ) {
- if ( preg_match('#===\\+#im',$text) ) {
- $mode = 'preplus';
- } else {
- $mode = 'pre';
- }
- if ( $omode === 'text' ) {
- $text = preg_replace('#^===\\+?.*?$#im','',$text);
- } else {
- $text = preg_replace('#^===\\+?$#im','<pre>',$text);
- $text = preg_replace('#^===\\+?:([^:]*):([^:]*):$#im','<pre style="color:$1;background:$2;">',$text);
- }
- } elseif ( preg_match('#^===\\+?$#im',$text) && ( $mode == 'pre' || $mode == 'preplus' ) ) {
- $mode = '';
- if ( $omode !== 'text' ) {
- $text = preg_replace('#^===\\+?$#im','</pre>',$text);
- } else {
- $text = preg_replace('#^===\\+?$#im','',$text);
- }
- }
- if ( $mode != 'pre' ) {
- if ( preg_match('#^(\\*{1,}|\#{1,}) (.+?)$#im',$text,$nesting) ) {
- if ( preg_match('#^\\*#im',$text) ){
- $deli = 'ul';
- } elseif ( preg_match('#^\##im',$text) ) {
- $deli = 'ol';
- }
- $text = preg_replace('#^[*|\#]+ #im','',$text);
- $iLev = strlen($nesting[1]);
- if ( $level < $iLev ) {
- $listPrefix = '';
- for ( $n=$iLev-$level;$n>0;$n-- ) {
- $dlevel++;
- $delis[$dlevel] = $deli;
- $listPrefix .= "<$delis[$dlevel]>";
- }
- $level = $iLev;
- if ( $omode !== 'text' ) {
- $text = $listPrefix."<li>".trim($text)."</li>";
- } else {
- $line = '* '.trim($text);
- $text = "\n".str_pad($line,strlen($line)+$level*2,' ',STR_PAD_LEFT);
- }
- } elseif ( $level > $iLev ) {
- $listSuffix = '';
- for ( $n=$level-$iLev;$n>0;$n-- ) {
- $listSuffix .= "</$delis[$dlevel]>";
- unset($delis[$dlevel]);
- $dlevel--;
- }
- if ( $omode !== 'text' ) {
- $text = "$listSuffix<li>".trim($text)."</li>";
- } else {
- $line = '* '.trim($text);
- $text = "\n".str_pad($line,strlen($line)+$dlevel*2,' ',STR_PAD_LEFT);
- }
- $level = $iLev;
- } else {
- if ( $omode !== 'text' ) {
- $text = "<li>".trim($text)."</li>";
- } else {
- $line = '* '.trim($text);
- $text = "\n".str_pad($line,strlen($line)+$level*2,' ',STR_PAD_LEFT);
- }
- }
- } elseif ( $level > 0 ) {
- $listSuffix = '';
- while($level > 0) {
- if ( $omode !== 'text' ) {
- $listSuffix .= "</".$delis[$dlevel].">";
- }
- $dlevel--;
- $level--;
- }
- $output[count($output)-1] .= "\n$listSuffix";
- }
- }
- # Table Parsing
- $realNum = '';
- if ( !isset($tabmode) ) $tabmode = '';
- if ( $mode != 'pre' ) {
- if ( preg_match('#^\\|(.+)\\|$#im',$text) && $mode != 'pre' && $omode !== 'text' ) {
- $tableInsert = '';
- if ( $tabmode != 'tab' ) {
- if ( preg_match('#^\\|:([a-z0-9\#]*):([a-z0-9\#]*):(?:([a-z0-9\#]*):)?\\|$#im',$text,$tableFormat) || preg_match('#^\\|:([a-z0-9\#]*):([a-z0-9\#]*):(?:([a-z0-9\#]*))?:(?:([a-z0-9\#]*):)?\\|$#im',$text,$tableFormat) ) {
- if ( strlen($tableFormat[3]) <1 ) $tableFormat[3] = 'none';
- $tableInsert = "<table cellpadding=\"2\" cellspacing=\"0\" style=\"border: solid 1px $tableFormat[3]; color:$tableFormat[1];background:$tableFormat[2];\">";
- if ( isset($tableFormat[4]) ) {
- $tdstyle = " border: solid 1px $tableFormat[4];";
- }
- $text = '';
- } else {
- $tableInsert = "<table cellpadding=\"2\" cellspacing=\"0\">";
- }
- $tabmode = 'tab';
- if ( !isset($tdstyle) ) $tdstyle = '';
- }
- //$text = preg_replace('#^\\|:([^:]*):([^:]*):(.+?)\\
- $text = preg_replace('#^\\|:([a-z0-9\#]*):([a-z0-9\#]*):([a-z0-9\#]*):(.+?)\\|$#im','<tr><td style="color:$1;background:$2;border:solid 1px $3;'.$tdstyle.'">$4</td></tr>',$text);
- $text = preg_replace('#^\\|:([a-z0-9\#]*):([a-z0-9\#]*):(.+?)\\|$#im','<tr><td style="color:$1;background:$2;'.$tdstyle.'">$3</td></tr>',$text);
- $text = preg_replace('#^\\|(.+?)\\|$#im','<tr><td style="'.$tdstyle.'">$1</td></tr>',$text);
- $text = preg_replace('#\\|:([^:\\|]*):([^:\\|]*):([^:\\|]*):#im','</td><td style="color:$1;background:$2;border:solid 1px $3;'.$tdstyle.'">',$text);
- $text = preg_replace('#\\|:([^:\\|]*):([^:\\|]*):#im','</td><td style="color:$1;background:$2;'.$tdstyle.'">',$text);
- $text = preg_replace('#\\|#im','</td><td style="'.$tdstyle.'">',$text);
- $text = $tableInsert.$text;
- } elseif ( $tabmode == 'tab' ) {
- $output[count($output)-1] .= "\n</table>\n";
- $tabmode = '';
- } elseif ( $omode === 'text' && preg_match('#^\\|(.+)\\|$#im',$text,$texTab) ) {
- $datNum = $textNum;
- $mode = 'txtab';
- while ( preg_match('#^\\|(.+)\\|$#im',$data[$datNum],$texTab ) ) {
- foreach($texTab as $row => $texRow) {
- if ( preg_match('#^:([a-z0-9\#]*):([a-z0-9\#]*):(?:([a-z0-9\#]*):)?$#im',$texRow) ) {
- break;
- }
- foreach ( $filters as $num => $filter) {
- $texRow = preg_replace($filter[0],$filter[1],$texRow);
- }
- if ( $row > 0 ) {
- $texRow = explode('|',preg_replace('#(:[^:]*:[^:]*:)?#im','',html_entity_decode($texRow)));
- $tabData[] = $texRow;
- foreach($texRow as $cell => $rowLen) {
- if ( !isset($celLen[$cell]) || strlen($rowLen) > $celLen[$cell] ) {
- $celLen[$cell] = strlen($rowLen);
- }
- }
- }
- $data[$datNum] = preg_replace('#^\\|(.+)\\|$#im','$1',$data[$datNum]);
- }
- $datNum++;
- }
- $text = '';
- foreach($tabData as $vals) {
- $text.="\n";
- foreach($vals as $num => $val) {
- $text.=str_pad($val,$celLen[$num]+5,' ',STR_PAD_RIGHT);
- }
- }
- $tabData = array();
- } elseif ( $mode == 'txtab') {
- unset($celLen);
- $celLen = array();
- $mode = '';
- }
- }
- if ( $mode != 'pre' ) {
- foreach ( $filters as $num => $filter) {
- if ( $mode != 'preplus' || !in_array($num,$preplusNo) ) {
- $text = preg_replace($filter[0],$filter[1],$text);
- }
- }
- # Clear escapes
- $text = preg_replace('#\\\\(?=[\#-*/_"{!%h]|h\\d)#im','',$text);
- }
- $output[] = $text;
- }
- if ( $realNum >= $datNum ) {
- $realNum++;
- $datNum = $realNum;
- } else {
- $realNum++;
- }
- }
- return implode("",$output);
- }
- function getCompFiles($file) {
- global $opts;
- $files = array();
- for ( $n=1;$n<=$opts['prevNum'];$n++ ) {
- if ( is_file("pages/$file.las$n.php") ) {
- $files[] = "las$n";
- }
- }
- return $files;
- }
- function compFilesList($filenm) {
- global $lang;
- $output = '<div><h3>'.$lang['compLabl'].'</h3>';
- global $opts;
- $compFiles = getCompFiles($filenm);
- $output .= "<ul>";
- foreach ( $compFiles as $file ) {
- $date = date($opts['date'],filemtime("pages/$filenm.$file.php"));
- if ( isset($_GET['diff']) && $_GET['diff'] == $file ) {
- $output .= "<li>$date</li>";
- } else {
- $output .= '<li><a href="./?page='."$filenm&diff=$file\">$date</a></li>";
- }
- }
- $output .= "</ul></div>";
- return $output;
- }
- function compFiles($file1,$file2,$mode=0) {
- function simpLines(&$text) {
- $text = trim($text);
- }
- $array1 = explode("\n",getPage($file1));
- $array2 = explode("\n",getPage($file2));
- array_walk($array1,'simpLines');
- array_walk($array2,'simpLines');
- $same = array_intersect($array1,$array2);
- $same2 = array_intersect($array2,$array1);
- $removed = $array1;
- if ( $mode === 1 ) return $removed;
- foreach($same as $num => $val ) {
- unset($removed[$num]);
- }
- $added = $array2;
- if ( $mode === 2 ) return $added;
- foreach($same2 as $num => $val) {
- unset($added[$num]);
- }
- function compCol($value,$action) {
- if ($action == 'add') $color = array('#000','#8f8');
- elseif ($action == 'rem') $color = array('#000','#f88');
- else $color = array('','');
- $value = '<div style="color:'.$color[0].';background:'.$color[1].';">'.htmlspecialchars($value).'</div>';
- return $value;
- }
- if ( $mode === 3 ) {
- $output = "<p>";
- foreach($added as $item) {
- $output .= compCol($item,'add');
- }
- foreach($removed as $item) {
- $output .= compCol($item,'rem');
- }
- return $output;
- }
- $same = array_intersect($array2,$same);
- $added = array_intersect($array2,$added);
- $counter = 0;
- foreach ( $same as $num => $val ) {
- array_splice($array2,$num,1,compCol($val,'sam'));
- }
- foreach ( $added as $num => $val ) {
- array_splice($array2,$num,1,compCol($val,'add'));
- }
- foreach ( $removed as $num => $val ) {
- array_splice($array2,$num+$counter,0,compCol($val,'rem'));
- $counter++;
- }
- return(implode('',$array2));
- }
- function breaks($str,$res='u') {
- if ( $res == 'u' ) {
- $str = preg_replace('/(\\r\\n)|(\\r(?!\\n))/sim',"\n",$str);
- } elseif ( $res == 'w' ) {
- $str = preg_replace('/((?<!\\r)\\n)|(\\r(?!\\n))/sim',"\r\n",$str);
- } elseif ( $res == 'm' ) {
- $str = preg_replace('/(\\r\\n)|((?!\\r)\\n)/sim',"\r",$str);
- }
- return $str;
- }
- # Get time offset
- function timeOffset($time) {
- global $opts;
- $offset = $time - date('Z',time()) + ($opts['time']*60*60) + ( date('I',time()) * $opts['tdst'] * 60*60 );
- return $offset;
- if ( isset($_GET['debug']) ) {
- echo date('Z',time())."<br />".$opts['time']*60*60;
- }
- echo $opts['time'];
- }
- function getPage($file) {
- global $sitepass;
- ob_start();
- include($file);
- $data = ob_get_contents();
- ob_end_clean();
- if ( !isset($_GET['edit']) ) {
- return preg_replace('#^\#pass *= *(.*?)$#im','',$data);
- } else {
- return $data;
- }
- }
- function getFileSettings($file) {
- global $sitepass;
- ob_start();
- if ( is_file($file) ) {
- require ($file);
- } else {
- return;
- }
- $file = ob_get_contents();
- ob_end_clean();
- if ( preg_match('#^\#pass *= *(.*?)$#im',$file,$userPass) ) {
- $user = crypt($userPass[1],substr($userPass[1],strlen($userPass[1])-2,2));
- } else {
- $user = '';
- }
- $data = array($priv,$pass,$user);
- return $data;
- }
- function getTags($iTag='',$mode=0) {
- $handle = opendir("pages/tags");
- $tags = array();
- while ( $file = readdir($handle) ) {
- if ( strlen($file) > 4 ) {
- require "pages/tags/$file";
- foreach($pageTags as $tag) {
- if ( strlen($tag) > 0 ) {
- $justTags[] = $tag;
- $tags[$tag][] = str_replace('.php','',$file);
- }
- }
- }
- }
- $justTags = array_unique($justTags);
- if ( strlen($iTag) > 0 ) {
- $file = '';
- foreach ( $tags[$iTag] as $thisTag ) {
- $file .= "* { $thisTag }\n";
- }
- return $file;
- } else {
- foreach ( $justTags as $tag ) {
- $file .= "{,$tag}, ";
- }
- return $file;
- }
- }
- function getFileTags($name,$mode=1) {
- global $lang;
- # mode = 1 for formatted tags
- # mode = 0 for raw list
- if ( is_file("pages/tags/$name.php") ) {
- require "pages/tags/$name.php";
- if ( $mode == 0 ) {
- array_walk($pageTags,strClean,"_");
- return implode(', ',$pageTags);
- } elseif ( $mode == 1 ) {
- $output = '';
- foreach ( $pageTags as $tag ) {
- $tag = $tag;
- $output[] = "<a href=\"./?tag=$tag\">$tag</a>";
- }
- return implode(', ',$output);
- }
- } else {
- // return $lang['noTags'];
- return;
- }
- }
- function searchIndex() {
- global $sitepass,$opts,$lang;
- # Get master file list
- $files = fileLister();
- # Associate pages with permissions
- # There will be two indexes -- one for private and one for public
- foreach ( $files as $file => $data ) {
- $settings = getFileSettings("pages/$data[0].php");
- $indexData = pageIndex(getPage("pages/$data[0].php"));
- if ( $settings[0] < 1 ) {
- $publicIndex[] = $data[0].','.implode(" ",$indexData);
- }
- $privateIndex[] = $data[0].','.implode(" ",$indexData);
- }
- $handle = fopen("pages/pubindex.php","w");
- fwrite($handle,'<?php $pass = 1; $priv = 1; if ( isset($sitepass) ) {?>'.implode("\n",$publicIndex).'<?php }?>');
- fclose($handle);
- $handle = fopen("pages/priindex.php","w");
- fwrite($handle,'<?php $pass = 1; $priv = 1; if ( isset($sitepass) ) {?>'.implode("\n",$privateIndex).'<?php }?>');
- fclose($handle);
- unset($handle);
- return $lang['searNdx'];
- }
- function pageIndex($content) {
- global $opts,$lang;
- $_GET['export'] = 'text';
- $content = parseText($content);
- unset($_GET['export']);
- $indexData = array_unique(preg_split('#'.$opts['srWrdFlt'].'#im',$content));
- foreach($indexData as $index => $data) {
- if (strlen($data) < $opts['srWrdLen']) {
- unset($indexData[$index]);
- }
- }
- return $indexData;
- }
- function pageSearch($keywords,$mode) {
- $keywords = preg_split('#[\\s]+#',$keywords);
- if ( $mode == 'pri' ) $index = getPage("pages/priindex.php");
- else $index = getPage("pages/pubindex.php");
- preg_match_all('#^(.*?),(.*?)$#sim',$index,$index,PREG_SET_ORDER);
- foreach($index as $val) {
- if ( preg_match('#'.implode('|',$keywords).'#im',$val[2]) ) {
- $matches[]=$val[1];
- }
- }
- if ( !is_array($matches) ) {
- return false;
- } elseif ( count($matches) == 1 ) {
- return "{ $matches[0] }";
- } else {
- return "\n* {".implode("}\n* {",$matches)."}";
- }
- }
- class configParse {
- var $file;
- var $data;
- function parseFile($file) {
- $this->file = explode("\n",$file);
- foreach ( $this->file as $option ) {
- if ( !preg_match('#^;#im',$option) && strlen(trim($option)) > 3 ) {
- if ( preg_match('#^((?!;)[^= ]+) *= *(.+)#im',$option,$option) ) {
- $this->data[trim($option[1])] = trim(str_replace('\n',"\n",$option[2]));
- }
- }
- }
- return $this->data;
- }
- }
- # Generate List of all files
- function filelister($sortMethod='name',$mode=0) {
- global $opts,$lang;
- $fileList = array();
- $handle=opendir('pages');
- $n=0;
- while ( $fileName = readdir($handle) ) {
- if ( !preg_match('#(\\.(las[0-9]+\\.php|pass|priv|lock))$#im',$fileName) && !preg_match('#^\\.+$#im',$fileName) && $fileName != 'recent.php' && $fileName != 'pubindex.php' && $fileName != 'priindex.php' && !is_dir("pages/$fileName") && $fileName != "$opts[usersyntax].php") {
- if ( $mode == 0 ) {
- $fileList[$n][] = str_replace('.php','',$fileName);
- $fileList[$n][] = filemtime('pages/'.($fileName));
- } else {
- $fileList[] = str_replace('.php','',$fileName);
- }
- if ( strlen($sortMethod) < 3 ) {
- $sortMethod = $opts['listSrt'];
- }
- $names[] = str_replace('.php','',$fileName);
- if ( $mode == 0 ) {
- $dates[] = $fileList[$n][1];
- }
- $n++;
- }
- }
- if ( $sortMethod == 'name' ) {
- array_multisort($names,SORT_ASC, $fileList);
- } else {
- array_multisort($dates,SORT_DESC, $fileList);
- }
- return $fileList;
- }
- # I tried to enforce all lower case file names
- # But it was impossible to support international
- # characters under that scheme. I'm using this function
- # as a workaround to make page names case insensitive
- # It just runs a case-insensitive search for the file name
- # using the filelister as an index. Slowdown is negligible.
- function fileNameSearch($name) {
- $files = filelister('name',1);
- if ( preg_match('#:('.$name.'):#im',':'.implode(':',$files).':',$result) ) {
- return($result[1]);
- } else {
- return false;
- }
- }
- function minkiSearch($data,$pageName) {
- global $lang;
- $rdata = preg_split('#[\\r\\n]+#sim',$data);
- foreach ( $rdata as $query ) {
- if ( preg_match('#^([a-z0-9]+) (.*)#im',$query,$match) ) {
- $queries[$match[1]] = $match[2];
- $qOut[] = "|$match[1]|$match[2]|";
- }
- }
- sort($qOut);
- preg_match('#^([a-z0-9]+) (.*)#im',$_GET['q'],$query);
- if ( isset($queries[$query[1]]) ) {
- $search = str_replace('%s',urlencode($query[2]),$queries[$query[1]]);
- header("location: $search");
- } elseif ( !isset($_GET['edit']) ) {
- $file = "##searchBox##\n\n";
- $file .= "|*$lang[searCoK]*|*$lang[searCoE]*|\n".implode("\n",$qOut)."\n\n";
- $file .= $lang['searHlp'];
- return $file;
- } else {
- return $data;
- }
- }
- # Generate RSS 2.0 Feed
- function makeRssFeed($page) {
- global $opts;
- global $fname,$opts,$lang;
- //$now = date('D, d M o H:i:s e',timeOffset(time()));
- $now = date('r',time());
- $oldData = file_get_contents('index.xml');
- preg_match_all('#<item>.*?</item>#sim',$oldData,$oldItems1);
- $oldItems = $oldItems1[0];
- if ( $opts['rssMode'] != 0 ) $opts['rssMode'] = 3;
- $content = htmlentities(compFiles("pages/$fname.las1.php","pages/$fname.php",$opts['rssMode']));
- if ( count($oldItems) >= $opts['rssnum']) {
- $oldItems = array_slice($oldItems,0,$opts['rssnum']-1);
- }
- $items = "<item>\n<title>$fname</title>\n<link>$opts[url]?page=$fname</link>\n<description>$content</description>\n<comments>$opts[url]?page=$fname&edit</comments><pubDate>$now</pubDate>\n</item>";
- if ( count($oldItems) > 0 ) {
- $items .= "\n".implode("\n",$oldItems);
- }
- $output = <<<output
- <?xml version="1.0"?>
- <rss version="2.0">
- <channel>
- <title>$opts[title]</title>
- <link>$opts[url]</link>
- <description>$opts[desc]</description>
- <lastBuildDate>$now</lastBuildDate>
- $items
- </channel>
- </rss>
- output;
- $handle = fopen('index.xml','w');
- fwrite($handle,$output);
- fclose($handle);
- unset($handle);
- }
- ?>