From 4d739f188d22ff70e2376a738f27cc36ab8cdc00 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Fri, 21 Oct 2011 18:45:09 +0000 Subject: improved wiki: added TOC - part 1 - Ark74 issue --- h-source/Application/Include/myFunctions.php | 89 ++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 11 deletions(-) (limited to 'h-source/Application') 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\])/', '
',$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', '
    ${2}
',$string); - + $string = preg_replace('/(\[code\])(.*?)(\[\/code\])/s', '
${2}
',$string); $string = preg_replace('/(\[p\])(.*?)(\[\/p\])/s', '

${2}

',$string); - - $string = preg_replace('/(\[h1\])(.*?)(\[\/h1\])/s', '
${2}
',$string); - - $string = preg_replace('/(\[h2\])(.*?)(\[\/h2\])/s', '
${2}
',$string); - - $string = preg_replace('/(\[h3\])(.*?)(\[\/h3\])/s', '
${2}
',$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', '
${2}
',$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 = ""; + self::$links = array(); + return $str; + } + +} + +//create h1, h2, h3 ($level=1,2,3) +function createHead($match,$level) +{ + Toc::$links[] = $level.$match[5]; + + return "
".$match[5]."
"; +} + +//create

,

,

+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
  • function createItem($match) { -- cgit v1.2.3