/branches/v3.0-aha/wikini/formatters/raw.php |
---|
New file |
0,0 → 1,31 |
<?php |
/* |
raw.php |
Copyright 2002, 2003 David DELON |
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 |
*/ |
if ($test=$_REQUEST["text"]) { |
echo ""; |
} |
else if ($lines = file($text)) { |
foreach ($lines as $line) { |
// To avoid loop:ignore inclusion of other raw link |
if (!(preg_match("/^\[\[\|(\S*)(\s+(.+))?\]\]$/", $line, $matches))) |
echo $line; |
} |
} |
?> |
/branches/v3.0-aha/wikini/formatters/code.php |
---|
New file |
0,0 → 1,33 |
<pre> |
<?php |
/* |
code.php |
Copyright (c) 2002, Hendrik Mans <hendrik@mans.de> |
Copyright 2002 Charles NEPOTE |
All rights reserved. |
Redistribution and use in source and binary forms, with or without |
modification, are permitted provided that the following conditions |
are met: |
1. Redistributions of source code must retain the above copyright |
notice, this list of conditions and the following disclaimer. |
2. 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. |
3. The name of the author may not be used to endorse or promote products |
derived from this software without specific prior written permission. |
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. |
*/ |
echo htmlentities($text)."\n"; |
?> |
</pre> |
/branches/v3.0-aha/wikini/formatters/action.php |
---|
New file |
0,0 → 1,64 |
<?php |
/* |
action.php |
Copyright (c) 2002, Hendrik Mans <hendrik@mans.de> |
Copyright 2003 David DELON |
All rights reserved. |
Redistribution and use in source and binary forms, with or without |
modification, are permitted provided that the following conditions |
are met: |
1. Redistributions of source code must retain the above copyright |
notice, this list of conditions and the following disclaimer. |
2. 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. |
3. The name of the author may not be used to endorse or promote products |
derived from this software without specific prior written permission. |
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. |
*/ |
// This may look a bit strange, but all possible formatting tags have to be in a single regular expression for this to work correctly. Yup! |
if (!function_exists("wakka2callback")) |
{ |
function wakka2callback($things) |
{ |
$thing = $things[1]; |
global $wiki; |
// events |
if (preg_match("/^\{\{(.*?)\}\}$/s", $thing, $matches)) |
{ |
if ($matches[1]) |
return $wiki->Action($matches[1]); |
else |
return "{{}}"; |
} |
else if (preg_match("/^.*$/s", $thing, $matches)) |
{ |
return ""; |
} |
// if we reach this point, it must have been an accident. |
return $thing; |
} |
} |
$text = str_replace("\r", "", $text); |
$text = trim($text)."\n"; |
$text = preg_replace_callback( |
"/(\{\{.*?\}\}|.*)/msU", "wakka2callback", $text); |
echo $text ; |
?> |
/branches/v3.0-aha/wikini/formatters/coloration_delphi.php |
---|
New file |
0,0 → 1,77 |
<?php |
/* |
* $Id: coloration_delphi.php,v 1.1 2005-09-22 14:02:49 ddelon Exp $ |
* |
* Souligneur syntaxique Delphi |
* |
* copyrigth Eric Feldstein 2003 2004 mailto:garfield_fr@tiscali.fr |
* |
* Licence : la meme que wikini (voir le fichier LICENCE). |
* Vous êtes libre d'utiliser et de modifier ce code à condition de laisser le copyright |
* d'origine. Vous pouvez bien sur vous ajouter à la liste des auteurs. |
* |
* Installation : copier le fichier dans le repertoire "formatters" de WikiNi |
*/ |
include_once('formatters/hightlighter.class.inc'); |
$DH = new Hightlighter(); |
$DH->isCaseSensitiv = false; |
//************* commentaires ************* |
$DH->comment = array('({[^$][^}]*})', //commentaires: { ... } |
'(\(\*[^$](.*)\*\))' //commentaires: (* ... *) |
); |
$DH->commentLine = array('(//.*\n)'); //commentaire // |
$DH->commentStyle = "color: red; font-style: italic"; //style CSS pour balise SPAN |
//************* directives de compilation ************* |
$DH->directive = array('({\\$[^{}]*})', //directive {$....} |
'(\(\*\\$(.*)\*\))' //directive (*$....*) |
); |
$DH->directiveStyle = "color: green"; //style CSS pour balise SPAN |
//************* chaines de caracteres ************* |
$DH->string = array("('[^']*')",'(#\d+)'); //chaine = 'xxxxxxxx' ou #23 |
$DH->stringStyle = "background: yellow"; |
//************* nombres ************* |
$DH->number[] = '(\b\d+(\.\d*)?([eE][+-]?\d+)?)'; //123 ou 123. ou 123.456 ou 123.E-34 ou 123.e-34 123.45E+34 ou 4e54 |
$DH->number[] = '(\$[0-9A-Fa-f]+\b)'; //ajout des nombres hexadecimaux : $AF |
$DH->numberStyle = 'color: blue'; |
//************* mots clé ************* |
$DH->keywords['MotCle']['words'] = array('absolute','abstract','and','array','as','asm', |
'begin', |
'case','class','const','constructor', |
'default','destructor','dispinterface','div','do','downto', |
'else','end','except','exports','external', |
'file','finalization','finally','for','function', |
'goto', |
'if','implementation','inherited','initialization','inline','interface','is', |
'label','library','loop','message', |
'mod', |
'nil','not', |
'object','of','or','out','overload','override', |
'packed','private','procedure','program','property','protected','public','published', |
'raise','read','record','repeat','resourcestring', |
'set','shl','shr','stdcall','string', |
'then','threadvar','to','try','type','unit','until', |
'use','uses', |
'var','virtual','while', |
'with','write', |
'xor' |
); |
$DH->keywords['MotCle']['style'] = 'font-weight: bold'; //style CSS pour balise SPAN |
//************* liste des symboles ************* |
$DH->symboles = array('#','$','&','(','(.',')','*','+',',','-','.','.)','..', |
'/',':',':=',';','<','<=','<>','=','>','>=','@','[',']','^'); |
$DH->symbolesStyle = ''; |
//************* identifiants ************* |
$DH->identifier = array('[_A-Za-z]?[_A-Za-z0-9]+'); |
$DH->identStyle = ''; |
echo "<pre>".$DH->Analyse($text)."</pre>"; |
unset($DH); |
?> |
/branches/v3.0-aha/wikini/formatters/wakka.php |
---|
New file |
0,0 → 1,340 |
<?php |
/* |
wakka.php |
Copyright (c) 2002, Hendrik Mans <hendrik@mans.de> |
Copyright 2002, 2003 David DELON |
Copyright 2002, 2003 Charles NEPOTE |
Copyright 2002, 2003 Patrick PAUL |
Copyright 2003 Eric DELORD |
Copyright 2003 Eric FELDSTEIN |
All rights reserved. |
Redistribution and use in source and binary forms, with or without |
modification, are permitted provided that the following conditions |
are met: |
1. Redistributions of source code must retain the above copyright |
notice, this list of conditions and the following disclaimer. |
2. 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. |
3. The name of the author may not be used to endorse or promote products |
derived from this software without specific prior written permission. |
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. |
*/ |
// This may look a bit strange, but all possible formatting tags have to be in a single regular expression for this to work correctly. Yup! |
if (!function_exists("wakka2callback")) |
{ |
include("formatters/tableaux.php"); //EF => tableaux |
function wakka2callback($things) |
{ |
$thing = $things[1]; |
$result=''; |
static $oldIndentLevel = 0; |
static $oldIndentLength= 0; |
static $indentClosers = array(); |
static $newIndentSpace= array(); |
static $br = 1; |
$brf=0; |
global $wiki; |
// convert HTML thingies |
if ($thing == "<") |
return "<"; |
else if ($thing == ">") |
return ">"; |
//EF=> tableaux |
else if (preg_match("/^\[\|(.*)\|\]/s", $thing)) |
{ |
return parsetable($thing); |
} //end tableaux |
// bold |
else if ($thing == "**") |
{ |
static $bold = 0; |
return (++$bold % 2 ? "<b>" : "</b>"); |
} |
// italic |
else if ($thing == "//") |
{ |
static $italic = 0; |
return (++$italic % 2 ? "<i>" : "</i>"); |
} |
// underlinue |
else if ($thing == "__") |
{ |
static $underline = 0; |
return (++$underline % 2 ? "<u>" : "</u>"); |
} |
// monospace |
else if ($thing == "##") |
{ |
static $monospace = 0; |
return (++$monospace % 2 ? "<tt>" : "</tt>"); |
} |
// Deleted |
else if ($thing == "@@") |
{ |
static $deleted = 0; |
return (++$deleted % 2 ? "<span class=\"del\">" : "</span>"); |
} |
// Inserted |
else if ($thing == "££") |
{ |
static $inserted = 0; |
return (++$inserted % 2 ? "<span class=\"add\">" : "</span>"); |
} |
// urls |
else if (preg_match("/^([a-z]+:\/\/\S+?)([^[:alnum:]^\/])?$/", $thing, $matches)) { |
$url = $matches[1]; |
if (!isset($matches[2])) $matches[2] = ''; |
return "<a href=\"$url\">$url</a>".$matches[2]; |
} |
// header level 5 |
else if ($thing == "==") |
{ |
static $l5 = 0; |
$br = 0; |
return (++$l5 % 2 ? "<h5>" : "</h5>"); |
} |
// header level 4 |
else if ($thing == "===") |
{ |
static $l4 = 0; |
$br = 0; |
return (++$l4 % 2 ? "<h4>" : "</h4>"); |
} |
// header level 3 |
else if ($thing == "====") |
{ |
static $l3 = 0; |
$br = 0; |
return (++$l3 % 2 ? "<h3>" : "</h3>"); |
} |
// header level 2 |
else if ($thing == "=====") |
{ |
static $l2 = 0; |
$br = 0; |
return (++$l2 % 2 ? "<h2>" : "</h2>"); |
} |
// header level 1 |
else if ($thing == "======") |
{ |
static $l1 = 0; |
$br = 0; |
return (++$l1 % 2 ? "<h1>" : "</h1>"); |
} |
// forced line breaks |
else if ($thing == "---") |
{ |
return "<br />"; |
} |
// escaped text |
else if (preg_match("/^\"\"(.*)\"\"$/s", $thing, $matches)) |
{ |
return $matches[1]; |
} |
// code text |
else if (preg_match("/^\%\%(.*)\%\%$/s", $thing, $matches)) |
{ |
// check if a language has been specified |
$code = $matches[1]; |
$language=''; |
if (preg_match("/^\((.+?)\)(.*)$/s", $code, $matches)) |
{ |
list(, $language, $code) = $matches; |
} |
//Select formatter for syntaxe hightlighting |
if (file_exists("formatters/coloration_".$language.".php")){ |
$formatter = "coloration_".$language; |
}else{ |
$formatter = "code"; |
} |
$output = "<div class=\"code\">"; |
$output .= $wiki->Format(trim($code), $formatter); |
$output .= "</div>"; |
return $output; |
} |
// raw inclusion from another wiki |
// (regexp documentation : see "forced link" below) |
else if (preg_match("/^\[\[\|(\S*)(\s+(.+))?\]\]$/", $thing, $matches)) |
{ |
list (,$url,,$text) = $matches; |
if (!$text) $text = "404"; |
if ($url) |
{ |
$url.="/wakka.php?wiki=".$text."/raw"; |
return $wiki->Format($wiki->Format($url, "raw"),"wakka"); |
} |
else |
{ |
return ""; |
} |
} |
// forced links |
// \S : any character that is not a whitespace character |
// \s : any whitespace character |
else if (preg_match("/^\[\[(\S*)\s+(.+)?\]\]$/", $thing, $matches)) |
{ |
list (, $url, $text) = $matches; |
if ($url) |
{ |
if ($url!=($url=(preg_replace("/@@|££|\[\[/","",$url))))$result="</span>"; |
if (!$text) $text = $url; |
$text=preg_replace("/@@|££|\[\[/","",$text); |
return $result.$wiki->Link($url, "", $text); |
} |
else |
{ |
return ""; |
} |
} |
// indented text |
else if ((preg_match("/\n(\t+|([ ]{1})+)(-|([0-9,a-z,A-Z]+)\))?/s", $thing, $matches)) |
|| (preg_match("/^(\t+|([ ]{1})+)(-|([0-9,a-z,A-Z]+)\))?/s", $thing, $matches) && $brf=1)) |
{ |
// new line |
if ($brf) $br=0; |
$result .= ($br ? "<br />\n" : ""); |
// we definitely want no line break in this one. |
$br = 0; |
// find out which indent type we want |
if (!isset($matches[3])) $matches[3] = ''; |
$newIndentType = $matches[3]; |
if (!$newIndentType) { $opener = "<div class=\"indent\">"; $closer = "</div>"; $br = 1; } |
else if ($newIndentType == "-") { $opener = "<ul>\n"; $closer = "</li>\n</ul>"; $li = 1; } |
else { $opener = "<ol type=\"".$matches[4]."\">\n"; $closer = "</li>\n</ol>"; $li = 1; } |
// get new indent level |
if (strpos($matches[1],"\t")) $newIndentLevel = strlen($matches[1]); |
else |
{ |
$newIndentLevel=$oldIndentLevel; |
$newIndentLength = strlen($matches[1]); |
if ($newIndentLength>$oldIndentLength) |
{ |
$newIndentLevel++; |
$newIndentSpace[$newIndentLength]=$newIndentLevel; |
} |
else if ($newIndentLength<$oldIndentLength) |
$newIndentLevel=$newIndentSpace[$newIndentLength]; |
} |
$op=0; |
if ($newIndentLevel > $oldIndentLevel) |
{ |
for ($i = 0; $i < $newIndentLevel - $oldIndentLevel; $i++) |
{ |
$result .= $opener; |
$op=1; |
array_push($indentClosers, $closer); |
} |
} |
else if ($newIndentLevel < $oldIndentLevel) |
{ |
for ($i = 0; $i < $oldIndentLevel - $newIndentLevel; $i++) |
{ |
$op=1; |
$result .= array_pop($indentClosers); |
if ($oldIndentLevel && $li) $result .= "</li>"; |
} |
} |
if (isset($li) && $op) $result .= "<li>"; |
else if (isset($li)) |
$result .= "</li>\n<li>"; |
$oldIndentLevel = $newIndentLevel; |
$oldIndentLength= $newIndentLength; |
return $result; |
} |
// new lines |
else if ($thing == "\n") |
{ |
// if we got here, there was no tab in the next line; this means that we can close all open indents. |
$c = count($indentClosers); |
for ($i = 0; $i < $c; $i++) |
{ |
$result .= array_pop($indentClosers); |
$br = 0; |
} |
$oldIndentLevel = 0; |
$oldIndentLength= 0; |
$newIndentSpace=array(); |
$result .= ($br ? "<br />\n" : "\n"); |
$br = 1; |
return $result; |
} |
// events |
else if (preg_match("/^\{\{(.*?)\}\}$/s", $thing, $matches)) |
{ |
if ($matches[1]) |
return $wiki->Action($matches[1]); |
else |
return "{{}}"; |
} |
// interwiki links! |
else if (preg_match("/^[A-Z][A-Z,a-z]+[:]([A-Z,a-z,0-9]*)$/s", $thing)) |
{ |
return $wiki->Link($thing); |
} |
// wiki links! |
else if (preg_match("/^[A-Z][a-z]+[A-Z,0-9][A-Z,a-z,0-9]*$/s", $thing)) |
{ |
return $wiki->Link($thing); |
} |
// separators |
else if (preg_match("/-{4,}/", $thing, $matches)) |
{ |
// TODO: This could probably be improved for situations where someone puts text on the same line as a separator. |
// Which is a stupid thing to do anyway! HAW HAW! Ahem. |
$br = 0; |
return "<hr />"; |
} |
// if we reach this point, it must have been an accident. |
return $thing; |
} |
} |
$text = str_replace("\r", "", $text); |
$text = chop($text)."\n"; |
$text = preg_replace_callback( |
"/(\%\%.*?\%\%|". |
"^\[\|.*?\|\]|". //EF => tableaux |
"\"\".*?\"\"|". |
"\[\[.*?\]\]|". |
"\b[a-z]+:\/\/\S+|". |
"\*\*|\#\#|@@|££|__|<|>|\/\/|". |
"======|=====|====|===|==|". |
"-{4,}|---|". |
"\n(\t+|([ ]{1})+)(-|[0-9,a-z,A-Z]+\))?|". |
"^(\t+|([ ]{1})+)(-|[0-9,a-z,A-Z]+\))?|". |
"\{\{.*?\}\}|". |
"\b[A-Z][A-Z,a-z]+[:]([A-Z,a-z,0-9]*)\b|". |
"\b([A-Z][a-z]+[A-Z,0-9][A-Z,a-z,0-9]*)\b|". |
"\n)/ms", "wakka2callback", $text); |
// we're cutting the last <br /> |
$text = preg_replace("/<br \/>$/","", trim($text)); |
echo $text ; |
?> |
/branches/v3.0-aha/wikini/formatters/coloration_php.php |
---|
New file |
0,0 → 1,30 |
<?php |
/* |
coloration_php.php |
Copyright (c) 2002, Hendrik Mans <hendrik@mans.de> |
Copyright 2003 Eric FELDSTEIN |
All rights reserved. |
Redistribution and use in source and binary forms, with or without |
modification, are permitted provided that the following conditions |
are met: |
1. Redistributions of source code must retain the above copyright |
notice, this list of conditions and the following disclaimer. |
2. 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. |
3. The name of the author may not be used to endorse or promote products |
derived from this software without specific prior written permission. |
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. |
*/ |
highlight_string($text) |
?> |
/branches/v3.0-aha/wikini/formatters/tableaux.php |
---|
New file |
0,0 → 1,87 |
<?php |
function parsetable($thing) |
{ |
$tableattr = 'border="1"'; |
// echo "parsetable debut : \$thing = $thing<br>"; |
// recuperation des attributs |
preg_match("/^\[\|(.*)$/m",$thing,$match); |
// echo "parsetable : \$match = ";var_dump($match);echo "<br>"; |
if ($match[1]){ |
$tableattr = $match[1]; |
} |
$table = "<table $tableattr >\n"; |
//suppression de [|xxxx et de |] |
$thing = preg_replace("/^\[\|(.*)$/m","",$thing); |
$thing = trim(preg_replace("/\|\]/m","",$thing)); |
// echo "parsetable suppression [| |]: \$thing = $thing<br>"; |
//recuperation de chaque ligne |
$rows = preg_split("/$/m",$thing,-1,PREG_SPLIT_NO_EMPTY); |
// echo "parsetable preg_split:";var_dump($rows);echo "<br>"; |
//analyse de chaque ligne |
foreach ($rows as $row){ |
$table .= parsetablerow($row); |
} |
$table.= "</table>"; |
return $table; |
} |
//parse la definition d'une ligne |
function parsetablerow($row) |
{ |
$rowattr = ""; |
$row = trim($row); |
// echo "parsetablerow debut : \$row = $row<br>"; |
//detection des attributs de ligne => si la ligne ne commence pas par | alors attribut |
if (!preg_match("/^\|/",$row,$match)){ |
preg_match("/^!([^\|]*)!\|/",$row,$match); |
$rowattr = $match[1]; |
// echo "\$rowattr = $rowattr<br>"; |
$row = trim(preg_replace("/^!([^\|]*)!/","",$row)); |
} |
$result .= " <tr $rowattr>\n"; |
$row = preg_replace("/^\|/","",$row); |
$row = preg_replace("/\|$/","",$row); |
// echo "parsetablerow sans attribut : \$row = $row<br>"; |
//recuperation de chaque cellule |
$cells = explode("|",$row); //nb : seule les indices impaire sont significatif |
// echo "parsetablerow preg_split \$cells:";var_dump($cells);echo "<br>"; |
$i=0; |
foreach ($cells as $cell){ |
// if ($i % 2){ |
// echo "\$cell = $cell<br>"; |
$result .= parsetablecell($cell); |
// } |
$i++; |
} |
$result .= " </tr>\n"; |
return $result; |
} |
//parse la definition d'une cellule |
function parsetablecell($cell) |
{ |
global $wiki; |
$cellattr = ""; |
if (preg_match("/^!(.*)!/",$cell,$match)){ |
$cellattr = $match[1]; |
} |
$cell = preg_replace("/^!(.*)!/","",$cell); |
//si espace au debut => align=right |
//si espace a la fin => align=left |
//si espace debut et fin => align=center |
if (preg_match("/^\s(.*)/",$cell)){ |
$align="right"; |
} |
if (preg_match("/^(.*)\s$/",$cell)){ |
$align="left"; |
} |
if (preg_match("/^\s(.*)\s$/",$cell)){ |
$align="center"; |
} |
if ($align) $cellattr .= " align=\"$align\""; |
// echo "\$this->classname = ".get_class($wiki)."<br>"; |
return " <td $cellattr>".$wiki->Format($cell)."</td>\n"; |
} |
?> |
/branches/v3.0-aha/wikini/formatters/php.php |
---|
New file |
0,0 → 1,3 |
<?php |
highlight_string($text) |
?> |
/branches/v3.0-aha/wikini/formatters/hightlighter.class.inc |
---|
New file |
0,0 → 1,250 |
<?php |
/* |
* $Id: hightlighter.class.inc,v 1.1 2005-09-22 14:02:49 ddelon Exp $ |
* |
* Souligneur générique pour colorier la syntaxe de langage de programmation |
* |
* copyrigth Eric Feldstein 2004 mailto:garfield_fr@tiscali.fr |
* |
* Licence : la meme que wikini(voir le fichier LICENCE). |
* Vous êtes libre d'utiliser et de modifier ce code à condition de laisser le copyright |
* d'origine. Vous pouvez bien sur vous ajouter à la liste des auteurs. |
* |
* INSTALLATION : copier le fichier dans le repertoire "formatters" de WikiNi |
* UTILISATION : importer la classe dans le script de coloration |
* ATTRIBUTS DE LA CLASSE : |
* - isCaseSensitiv : booleen - indique si la syntaxe est sensible a la casse |
* - comment : array - tableau d'expressions regulieres definissant les commentaires multiligne |
* ex : array('({[^$][^}]*})', //commentaires: { ... } |
* '(\(\*[^$](.*)\*\))' //commentaires: (* ... *) |
* ); |
* - commentLine : array tableau d'expressions regulieres definissant les commentaires monoligne |
* ex : array('(//.*\n)'); //commentaire // |
* - commentStyle : string - style CSS inline a utiliser pour la coloration(utilisé dans une |
* balise <SPAN style="..."></SPAN>) |
* - directive : array - tableau d'expression reguliere pour definir les directive de |
* compilation |
* - directiveStyle : string - style CSS inline a utiliser pour la coloration |
* - string : array - tableau d'expression reguliere pour definir les chaine de caracteres |
* - stringStyle : string - style CSS inline a utiliser pour la coloration |
* - number : array - tableau d'expression reguliere pour definir les nombres |
* - numberStyle : string - style CSS inline a utiliser pour la coloration |
* - keywords : array - tableau asociatif contenant des tableaux de liste de mots avec leur style. Ex : |
* $oHightlighter->keywords['Liste1']['words'] = array('liste1mot1','liste1mot2','liste1mot3'); |
* $oHightlighter->keywords['Liste1']['style'] = 'color: red'; |
* $oHightlighter->keywords['Liste2']['words'] = array('liste2mot1','liste2mot2'); |
* $oHightlighter->keywords['Liste2']['style'] = 'color: yellow'; |
* chaque tableau keywords['...'] DOIT posseder les 2 clé 'words' et 'style'. |
* - symboles : array - tableau conteant la liste des symboles |
* - symbolesStyle : string - style CSS inline a utiliser pour la coloration |
* - identifier : array - tableau d'expression reguliere pour definir les identifiants |
* - identStyle : string - style CSS inline a utiliser pour la coloration |
* METHODE PUBLIQUE DE LA CLASSE : |
* - Analyse($text) : $text string Chaine a analyser |
* renvoie le texte colorié. |
* |
* NOTES IMPORTANTES |
* - Les expressions reguliere doivent être entre parenthèse capturante pour etre utilisé |
* dans une fonction de remplacement. Voir le fichier coloration_delphi.php pour un exemple |
* - Lorsque un style est defini à vide, l'expression reguliere n'est pas prise en compte dans |
* l'analyse. |
* - L'option de recherche est msU : multiligne, le . peut être un \n et la recherche |
* est 'not greedy' qui inverse la tendance à la gourmandise des expressions régulières. |
*/ |
class Hightlighter{ |
//sensibilite majuscule/minuscule |
var $isCaseSensitiv = false; |
//commentaires |
var $comment = array(); //commentaire multiligne |
var $commentLine = array(); //commentaire monoligne |
var $commentStyle = '';//'color: red'; |
//directives de compilation |
var $directive = array(); |
var $directiveStyle = '';//'color: green'; |
//chaine de caracteres |
var $string = array(); |
var $stringStyle = ''; |
//nombre |
var $number = array(); |
var $numberStyle = ''; |
//mots clé |
var $keywords = array(); |
//séparateurs |
var $symboles = array(); |
var $symbolesStyle = ''; |
//identifiant |
var $identifier = array(); |
var $identStyle = ''; |
//******************************************************* |
// Variable privées |
//******************************************************* |
var $_patOpt = 'msU'; //option de recherche |
var $_pattern = ''; //modele complet |
var $_commentPattern = ''; //modele des commentaires |
var $_directivePattern = '';//modele des directives |
var $_numberPattern = ''; //modele des nombres |
var $_stringPattern = ''; //modele des chaine de caracteres |
var $_keywordPattern = ''; //modele pour le mots cle |
var $_symbolesPattern = ''; //modele pour les symbole |
var $_separatorPattern = '';//modele pour les sparateurs |
var $_identPattern = ''; //modele pour les identifiants |
/******************************************************** |
Methodes de la classe |
*********************************************************/ |
/** |
* Renvoie le pattern pour les commentaires |
*/ |
function _getCommentPattern(){ |
$a = array_merge($this->commentLine,$this->comment); |
return implode('|',$a); |
} |
/** |
* Renvoie le pattern pour les directives de compilation |
*/ |
function _getDirectivePattern(){ |
return implode('|',$this->directive); |
} |
/** |
* Renvoie le pattern pour les chaine de caracteres |
*/ |
function _getStringPattern(){ |
return implode('|',$this->string); |
} |
/** |
* Renvoie le pattern pour les nombre |
*/ |
function _getNumberPattern(){ |
return implode('|',$this->number); |
} |
/** |
* Renvoie le pattern pour les mots clé |
*/ |
function _getKeywordPattern(){ |
$aResult = array(); |
foreach($this->keywords as $key=>$keyword){ |
$aResult = array_merge($aResult, $keyword['words']); |
$this->keywords[$key]['pattern'] = '\b'.implode('\b|\b',$keyword['words']).'\b'; |
} |
return '\b'.implode('\b|\b',$aResult).'\b'; |
} |
/** |
* Renvoie le pattern pour les symboles |
*/ |
function _getSymbolesPattern(){ |
$a = array(); |
foreach($this->symboles as $s){ |
$a[] = preg_quote($s,'`'); |
} |
return implode('|',$a); |
} |
/** |
* Renvoie le pattern pour les identifiants |
*/ |
function _getIdentifierPattern(){ |
return implode('|',$this->identifier); |
} |
/** |
* Liste des separateur d'apres la liste des symboles |
*/ |
function _getSeparatorPattern(){ |
$a = array_unique(preg_split('//', implode('',$this->symboles), -1, PREG_SPLIT_NO_EMPTY)); |
$pattern = '['.preg_quote(implode('',$a),'`').'\s]+'; |
return $pattern; |
} |
/** |
* Renvoie le modele a utiliser dans l'expression regulière |
* |
* @return string Modele de l'expression régulière |
*/ |
function _getPattern(){ |
$this->_separatorPattern = $this->_getSeparatorPattern(); |
$this->_symbolesPattern = $this->_getSymbolesPattern(); |
$this->_commentPattern = $this->_getCommentPattern(); |
$this->_directivePattern = $this->_getDirectivePattern(); |
$this->_stringPattern = $this->_getStringPattern(); |
$this->_numberPattern = $this->_getNumberPattern(); |
$this->_keywordPattern = $this->_getKeywordPattern(); |
$this->_identPattern = $this->_getIdentifierPattern(); |
//construction du modele globale en fonction de l'existance d'un style(optimisation) |
if($this->commentStyle){ $a[] = $this->_commentPattern; } |
if($this->directiveStyle){ $a[] = $this->_directivePattern; } |
if($this->stringStyle){ $a[] = $this->_stringPattern; } |
if($this->numberStyle){ $a[] = $this->_numberPattern; } |
if(count($this->keywords)>0){ $a[] = $this->_keywordPattern; } |
if($this->symbolesStyle){ $a[] = $this->_symbolesPattern; } |
if($this->identStyle){ $a[] = $this->_identPattern; } |
$this->_pattern = implode('|',$a); |
return $this->_pattern; |
} |
/** |
* Fonction de remplacement de chaque élement avec leur style. |
*/ |
function replacecallback($match){ |
$text = $match[0]; |
$pcreOpt = $this->_patOpt; |
$pcreOpt .= ($this->isCaseSensitiv)?'':'i'; |
//commentaires |
if($this->commentStyle){ |
if (preg_match('`'.$this->_commentPattern."`$pcreOpt",$text,$m)){ |
return "<span style=\"$this->commentStyle\">".$match[0].'</span>'; |
} |
} |
//directive de compilation |
if ($this->directiveStyle){ |
if (preg_match('`'.$this->_directivePattern."`$pcreOpt",$text,$m)){ |
return "<span style=\"$this->directiveStyle\">".$match[0].'</span>'; |
} |
} |
//chaine de caracteres |
if ($this->stringStyle){ |
if (preg_match('`'.$this->_stringPattern."`$pcreOpt",$text,$m)){ |
return "<span style=\"$this->stringStyle\">".$match[0].'</span>'; |
} |
} |
//nombres |
if ($this->numberStyle){ |
if (preg_match('`'.$this->_numberPattern."`$pcreOpt",$text,$m)){ |
return "<span style=\"$this->numberStyle\">".$match[0].'</span>'; |
} |
} |
//mot clé |
if (count($this->keywords)>0){ |
foreach($this->keywords as $key=>$keywords){ |
if ($keywords['style']){ |
if(preg_match('`'.$keywords['pattern']."`$pcreOpt",$text,$m)){ |
return "<span style=\"".$keywords['style']."\">".$match[0].'</span>'; |
} |
} |
} |
} |
//symboles |
if ($this->symbolesStyle){ |
if (preg_match('`'.$this->_symbolesPattern."`$pcreOpt",$text,$m)){ |
return "<span style=\"$this->symbolesStyle\">".$match[0].'</span>'; |
} |
} |
//identifiants |
if ($this->identStyle){ |
if (preg_match('`'.$this->_identPattern."`$pcreOpt",$text,$m)){ |
return "<span style=\"$this->identStyle\">".$match[0].'</span>'; |
} |
} |
return $match[0]; |
} |
/** |
* renvois le code colorié |
* |
* @param $text string Texte a analyser |
* @return string texte colorié |
*/ |
function Analyse($text){ |
$pattern = '`'.$this->_getPattern()."`$this->_patOpt"; |
if (!$this->isCaseSensitiv){ |
$pattern .= 'i'; |
} |
$text = preg_replace_callback($pattern,array($this,'replacecallback'),$text); |
return $text; |
} |
} //class Hightlighter |
?> |