aboutsummaryrefslogtreecommitdiff
path: root/h-source
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2011-10-21 18:45:09 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2011-10-21 18:45:09 +0000
commit4d739f188d22ff70e2376a738f27cc36ab8cdc00 (patch)
tree6e120d595661a44a0d44ea578225c876611ed34f /h-source
parentf246548be615b269ade8a177d52e89baf22b0c86 (diff)
improved wiki: added TOC - part 1 - Ark74 issue
Diffstat (limited to 'h-source')
-rw-r--r--h-source/Application/Include/myFunctions.php89
1 files changed, 78 insertions, 11 deletions
diff --git a/h-source/Application/Include/myFunctions.php b/h-source/Application/Include/myFunctions.php
index b33c19b..1356281 100644
--- a/h-source/Application/Include/myFunctions.php
+++ b/h-source/Application/Include/myFunctions.php
@@ -221,13 +221,17 @@ function getLinkToUser($user)
}
}
+$decodeCounter = 0;
$decodeAnotherTime = false;
//decode the text of the wiki
function decodeWikiText($string)
{
global $decodeAnotherTime;
+ global $decodeCounter;
+ $decodeCounter++;
+
$decodeAnotherTime = false;
$string = preg_replace('/(\[hr\])/', '<hr />',$string);
@@ -259,19 +263,13 @@ function decodeWikiText($string)
$string = preg_replace_callback('/(\[list\])(.*?)(\[\/list\])/s', 'createList',$string);
$string = preg_replace_callback('/(\[enum\])(.*?)(\[\/enum\])/s', 'createEnum',$string);
-
-// $string = preg_replace('/(\[enum\])(.*?)(\[\/enum\])/s', '<ol>${2}</ol>',$string);
-
+
$string = preg_replace('/(\[code\])(.*?)(\[\/code\])/s', '<pre class="code_pre">${2}</pre>',$string);
$string = preg_replace('/(\[p\])(.*?)(\[\/p\])/s', '<p>${2}</p>',$string);
-
- $string = preg_replace('/(\[h1\])(.*?)(\[\/h1\])/s', '<div class="div_h1">${2}</div>',$string);
-
- $string = preg_replace('/(\[h2\])(.*?)(\[\/h2\])/s', '<div class="div_h2">${2}</div>',$string);
-
- $string = preg_replace('/(\[h3\])(.*?)(\[\/h3\])/s', '<div class="div_h3">${2}</div>',$string);
+ $string = preg_replace_callback('/(\[)(h)(1|2|3)(\])(.*?)(\[\/)(h)(1|2|3)(\])/s', 'createHeadGeneric',$string);
+
$string = preg_replace_callback('/(\[tab )(lang=)([^\s]+)(\s*\])(.*?)(\[\/tab\])/s', 'createTabs',$string);
$string = preg_replace('/(\[lang\])(.*?)(\[\/lang\])/s', '<div class="div_lang">${2}</div>',$string);
@@ -280,7 +278,7 @@ function decodeWikiText($string)
$string = preg_replace('/(\}\})/s', ']',$string);
- if ($decodeAnotherTime)
+ if ($decodeAnotherTime and $decodeCounter<=30)
{
return decodeWikiText(Tabs::render().$string);
}
@@ -299,7 +297,7 @@ function createTabs($match)
return null;
}
-//create the HTMLof the tats in the description entry
+//create the HTM Lof the tabs in the description entry
class Tabs
{
public static $tabList = array();
@@ -384,6 +382,75 @@ function createNode($match,$hnodeTag,$htmlTagBegin,$htmlTagEng)
}
}
+//table of contents
+class Toc
+{
+
+ public static $links = array();
+ public static $level = 1;
+
+ public function render($array = null, $useSelf = true)
+ {
+ if (!isset($array) and $useSelf)
+ {
+ $array = self::$links;
+ }
+
+ $count = 0;
+ $str = "<ul>";
+ foreach ($array as $link)
+ {
+ $startChar = (int)substr($link,0,1);
+ echo $startChar;
+ if (strcmp(self::$level,$startChar) === 0)
+ {
+ $str .= "<li>".substr($link,1)."</li>";
+ $count++;
+ }
+ else if ($startChar > self::$level)
+ {
+ self::$level = $startChar;
+ $str .= self::render(array_slice($array,$count),false);
+ break;
+ }
+ else
+ {
+ self::$level = $startChar;
+ $str .= null;
+ }
+ }
+ $str .= "</ul>";
+ self::$links = array();
+ return $str;
+ }
+
+}
+
+//create h1, h2, h3 ($level=1,2,3)
+function createHead($match,$level)
+{
+ Toc::$links[] = $level.$match[5];
+
+ return "<div id='".$match[5]."' class='div_h$level'>".$match[5]."</div>";
+}
+
+//create <h1></h1>,<h2></h2>,<h3></h3>
+function createHeadGeneric($match)
+{
+ if (strcmp($match[3],'1') === 0)
+ {
+ return createHead($match,'1');
+ }
+ else if (strcmp($match[3],'2') === 0)
+ {
+ return createHead($match,'2');
+ }
+ else
+ {
+ return createHead($match,'3');
+ }
+}
+
//create <li></li>
function createItem($match)
{