wrong ext
[platal.git] / classes / miniwiki.php
CommitLineData
f18f4920 1<?php
2
3class MiniWiki
4{
5
6 private static $patternsWiki = array();
7 private static $replacementHTML = array();
8 private static $replacementText = array();
9
5d1fffc0 10 public static function Markup($id, $pattern, $replacement, $replacementTxt) {
11 MiniWiki::$patternsWiki[$id] = $pattern;
12 MiniWiki::$replacementHTML[$id] = $replacement;
13 MiniWiki::$replacementText[$id] = $replacementTxt;
f18f4920 14 }
15
16 public static function init() {
17 if (isset(MiniWiki::$patternsWiki[0])) {
18 return;
19 }
5d1fffc0 20 MiniWiki::Markup(0, "/(\r\n|\r([^\n]))/", "\n$2", "\n$2");
21
f18f4920 22 // retours à la ligne avec \\
5d1fffc0 23 MiniWiki::Markup(1, "/\\\\(?".">(\\\\*))\n/e", "str_repeat('<br />\n',strlen('$1'))", "str_repeat('\\\\n',strlen('$1'))");
f18f4920 24
25 // bold, italic and others
26 // ''' bold '''
5d1fffc0 27 MiniWiki::Markup(2, "/'''(.*?)'''/",'<strong>$1</strong>','*$1*');
f18f4920 28 // '' italic ''
5d1fffc0 29 MiniWiki::Markup(3, "/''(.*?)''/",'<em>$1</em>','/$1/');
f18f4920 30 // '+ big +'
5d1fffc0 31 MiniWiki::Markup(4, "/'\\+(.*?)\\+'/",'<big>$1</big>','*$1*');
f18f4920 32 // '- small -'
5d1fffc0 33 MiniWiki::Markup(5, "/'\\-(.*?)\\-'/",'<small>$1</small>','$1');
f18f4920 34 // '^superscript^'
5d1fffc0 35 MiniWiki::Markup(6, "/'\\^(.*?)\\^'/",'<sup>$1</sup>','$1');
f18f4920 36 // '_subscript_'
5d1fffc0 37 MiniWiki::Markup(7, "/'_(.*?)_'/",'<sub>$1</sub>','$1');
f18f4920 38 // {+ underline +}
5d1fffc0 39 MiniWiki::Markup(8, "/{+(.*?)+}/",'<ins>$1</ins>','_$1_');
f18f4920 40 // {- strikeout -}
5d1fffc0 41 MiniWiki::Markup(9, "/{-(.*?)-}/",'<del>$1</del>','_$1_');
f18f4920 42 // [+ big +] [++ bigger ++] [+++ even bigger +++] ...
5d1fffc0 43 MiniWiki::Markup(10, '/\\[(([-+])+)(.*?)\\1\\]/e',"'<span style=\'font-size:'.(round(pow(6/5,$2strlen('$1'))*100,0)).'%\'>$3</span>'", "'$3'");
f18f4920 44
45 // ----- <hr/>
5d1fffc0 46 MiniWiki::Markup(11, '/(\n|^)----+/s', '$1<hr/>', '$1----');
f18f4920 47 // titles
5d1fffc0 48 MiniWiki::Markup(12, '/(\n|^)(!+)([^\n]*)/se', "'$1<h'.strlen('$2').'>$3</h'.strlen('$2').'>'", "'$1$3'");
f18f4920 49
50 // * unordered list
5d1fffc0 51 MiniWiki::Markup(13, "/(^|\n)\*(([^\n]*(\n|$))(\*[^\n]*(\n|$))*)/se", "'<ul><li>'.str_replace(\"\\n*\",'</li><li>','$2').'</li></ul>'", "$0");
f18f4920 52 // # unordered list
5d1fffc0 53 MiniWiki::Markup(14, "/(^|\n)#(([^\n]*(\n|$))(#[^\n]*(\n|$))*)/se", "'<ol><li>'.str_replace(\"\\n#\",'</li><li>','$2').'</li></ol>'", "$0");
f18f4920 54
55 // links
5d1fffc0 56 MiniWiki::Markup(15, '/((?:https?|ftp):\/\/(?:\.*,*[\w@~%$£µ&i#\-+=_\/\?;])*)/ui', '<a href="\\0">\\0</a>', '\\0');
57 MiniWiki::Markup(16, '/(\s|^|\\[\\[)www\.((?:\.*,*[\w@~%$£µ&i#\-+=_\/\?;])*)/iu', '\\1<a href="http://www.\\2">www.\\2</a>', 'http://www.\\2');
58 MiniWiki::Markup(17, '/(?:mailto:)?([a-z0-9.\-+_]+@([\-.+_]?[a-z0-9])+)/i', '<a href="mailto:\\0">\\0</a>', '\\0');
59 MiniWiki::Markup(18, '/\\[\\[\\s*<a href="([^>]*)">.*<\/a>\\s*\|([^\\]]+)\\]\\]/i', '<a href="\\1">\\2</a>', '\\2 (\\1)');
f18f4920 60
61 // paragraphs and empty lines
5d1fffc0 62 MiniWiki::Markup(19, "/\n\n/", '</p><p>', "\n\n");
63 MiniWiki::Markup(20, "/\n/", ' ', "\n");
64 MiniWiki::Markup(21, "/^.*<\/p><p>.*$/s", "<p>$0</p>", "$0");
f18f4920 65 }
66
5d1fffc0 67 public static function WikiToHTML($wiki, $notitle = false) {
68 if ($notitle) {
69 $oldrule12 = MiniWiki::$replacementHTML[12];
70 MiniWiki::$replacementHTML[12] = "'$0'";
71 }
72 $html = preg_replace(MiniWiki::$patternsWiki, MiniWiki::$replacementHTML, htmlentities($wiki));
73 if ($notitle) {
74 MiniWiki::$replacementHTML[12] = $oldrule12;
75 }
76 return $html;
f18f4920 77 }
78};
79
80MiniWiki::init();
81?>