<?
/*
tags.php Durchsucht Templates nach bekannten zusatzbefehlen und führt diese aus
Copyright (C) 2004 Thomas Meinusch
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc.,\ 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA.
*/
#################################################################
/*
require("wikiparser.php");
function wiki($wikisyntax){
return parse($wikisyntax);
}
*/
function wiki($wikisyntax){
$temp=code($wikisyntax, 'txt2html');
do{
preg_match ("/(===)\ (.*)\ (===)/i", $temp, $matches);
$temp=str_replace($matches[0],
"<h3>".$matches[2]."</h3>",$temp);
}while($matches[0][0]=='=');
$temp=str_replace("</h1><br />","</h1>",$temp);
do{
preg_match ("/(==)\ (.*)\ (==)/i", $temp, $matches);
$temp=str_replace($matches[0],
"<h2>".$matches[2]."</h2>",$temp);
}while($matches[0][0]=='=');
$temp=str_replace("</h2><br />","</h2>",$temp);
do{
preg_match ("/(=)\ (.*)\ (=)/i", $temp, $matches);
$temp=str_replace($matches[0],
"<h1>".$matches[2]."</h1>",$temp);
}while($matches[0][0]=='=');
$temp=str_replace("</h1><br />","</h1>",$temp);
# LINK
do{
preg_match ("/\[(.*)\|(.*)\]/i", $temp, $matches);
if(substr($matches[0],0,5)=='[http'){
$temp=str_replace($matches[0],
"<a href='".$matches[1]."' title='".$matches[2]."' class='external autonumber' target=_blank>".$matches[1]."</a>",$temp);
}
}while(substr($matches[0],0,5)=='[http');
preg_match ("/\[\[Bild:(.*)\|(.*)\|(.*)\]\]/i", $temp, $matches);
//[[Bild:Benz_auto.jpg|thumb|Das erste Auto mit einem [[Benzin|Benzin-Antrieb]] aus dem Jahre [[1886]]]]
// echo $matches[0];
// do{
$temp=str_replace($matches[0],
'<div class="thumb tleft">
<div><a href="?src=Bild.html&info_src='.$matches[1].'" class="internal" title="'.$matches[3].'" target="FACCIN_Bild"><img src="pics/'.$matches[1].'" alt="'.$matches[3].'" longdesc="Bild:'.$matches[3].'" /></a>
<div class="thumbcaption">
<div class="magnify" style="float:right"><a href="?src=Bild.html&info_src='.$matches[1].'" class="internal" title="vergrößern" target="FACCIN_Bild"><img src="pics/magnify-clip.png" width="15" height="11" alt="vergrößern" /></a></div>'.$matches[3].'</div>
</div>
</div>',$temp);
# Tabellen
preg_match ("/\{\|(.*)/i", $temp, $matches1);
$pos=strpos($temp,$matches1[0]);
$pstr=substr($temp,$pos);
$wikitable=substr($pstr,0,strpos($pstr, "|}")+2);
if(strlen("$wikitable")>2){
$htmltable="<table".code(substr($wikitable,2,strpos($wikitable,"\n")-8),'html2txt').">\n";
$tr=0;
foreach(explode("\n",$wikitable) as $x){
if(substr($x,0,2)=="|-"){
if($tr) $htmltable.="\n</tr>\n";
$htmltable.="<tr".code(substr($x,2,-6),'html2txt').">\n";
$tr++;
}
if(substr($x,0,2)=="| "){
$tdc=0;
$x=str_replace("||","</td>\n<td>",$x);
$x=str_replace("<br />","</td>",$x);
if(substr($x,0,7)!="| </td>"){
$x=substr($x,2);
}
foreach(explode("|", $x) as $td){
if($tdc%2==0){
$htmltable.="<td ".code($td,'html2txt').">";
}else{
$htmltable.=$td;
}
$tdc++;
}
}
}
$htmltable.="\n</tr>\n</table>\n";
$temp=str_replace($wikitable,$htmltable,$temp);
}
# Liste: ul li
$ul=0;
$wikilist="";
$htmllist="";
foreach(explode("\n",$temp) as $x){
if($ul>0){
if(substr($x,0,2)!='* '){
$htmllist.="</ul>\n";
$ul--;
if($ul==0){
$temp=str_replace($wikilist, $htmllist,$temp);
}
}
}
if(substr($x,0,2)=='* '){
$tmp="<li>".substr($x,2)."</li>";
$tmp=str_replace("<br /></li>","</li>\n",$tmp);
if($ul==0){
$tmp="<ul>\n".$tmp;
$ul++;
}
$htmllist.=$tmp;
$wikilist.=$x."\n";
}
}
# Nr-Liste ol, li
$lines=explode("\n",$temp);
$ol=0;
$wikilist="";
$htmllist="";
foreach($lines as $x){
if($ol>0){
if(substr($x,0,2)!='# '){
$htmllist.="</ol>\n";
$ol--;
if($ol==0){
$temp=str_replace($wikilist, $htmllist,$temp);
}
}
}
if(substr($x,0,2)=='# '){
$tmp="<li>".substr($x,2)."</li>";
$tmp=str_replace("<br /></li>","</li>\n",$tmp);
if($ol==0){
$tmp="<ol>\n".$tmp;
$ol++;
}
$htmllist.=$tmp;
$wikilist.=$x."\n";
}
}
// $temp=nl2br($temp);
return $temp;
}
?>