From f246548be615b269ade8a177d52e89baf22b0c86 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Thu, 20 Oct 2011 15:23:15 +0000 Subject: improved wiki formatting: nested lists are now allowed - Luis Alberto (Ark74) issue --- h-source/Application/Include/myFunctions.php | 66 +++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 10 deletions(-) (limited to 'h-source') diff --git a/h-source/Application/Include/myFunctions.php b/h-source/Application/Include/myFunctions.php index 61c2ec2..b33c19b 100644 --- a/h-source/Application/Include/myFunctions.php +++ b/h-source/Application/Include/myFunctions.php @@ -221,11 +221,14 @@ function getLinkToUser($user) } } - +$decodeAnotherTime = false; //decode the text of the wiki function decodeWikiText($string) { + global $decodeAnotherTime; + + $decodeAnotherTime = false; $string = preg_replace('/(\[hr\])/', '
',$string); @@ -250,12 +253,14 @@ function decodeWikiText($string) $string = preg_replace('/(\[i\])(.*?)(\[\/i\])/s', '${2}',$string); $string = preg_replace('/(\[del\])(.*?)(\[\/del\])/s', '${2}',$string); + + $string = preg_replace_callback('/(\[\*\])(.*?)(\[\/\*\])/s', 'createItem',$string); + + $string = preg_replace_callback('/(\[list\])(.*?)(\[\/list\])/s', 'createList',$string); + + $string = preg_replace_callback('/(\[enum\])(.*?)(\[\/enum\])/s', 'createEnum',$string); - $string = preg_replace('/(\[\*\])(.*?)(\[\/\*\])/s', '
  • ${2}
  • ',$string); - - $string = preg_replace('/(\[list\])(.*?)(\[\/list\])/s', '',$string); - - $string = preg_replace('/(\[enum\])(.*?)(\[\/enum\])/s', '
      ${2}
    ',$string); +// $string = preg_replace('/(\[enum\])(.*?)(\[\/enum\])/s', '
      ${2}
    ',$string); $string = preg_replace('/(\[code\])(.*?)(\[\/code\])/s', '
    ${2}
    ',$string); @@ -274,8 +279,15 @@ function decodeWikiText($string) $string = preg_replace('/(\{\{)/s', '[',$string); $string = preg_replace('/(\}\})/s', ']',$string); - - return Tabs::render()."\n\n".$string; + + if ($decodeAnotherTime) + { + return decodeWikiText(Tabs::render().$string); + } + else + { + return Tabs::render().$string; + } } //create the list of the tabs in the description entry @@ -321,8 +333,6 @@ class Tabs function checkUrl($url) { -// $match = '/^http\:\/\/(www\.)?[a-zA-Z0-9\-\_]+(\.[a-zA-Z0-9\-\_]+)?\.(com|net|it|info|org|eu|uk)((\/[a-zA-Z0-9\_\-\+]+)+[\/]?)?(\?([a-zA-Z0-9\_\-\+\s]+\=[a-zA-Z0-9\_\-\s\+\&]+)+)?(#[a-zA-Z0-9\_\-\+\s]+)?([\s]*)?$/'; - $match = '/^http(s)?\:\/\/(www\.)?[a-zA-Z0-9\-\_]+(\.[a-zA-Z0-9\-\_]+)*\.(com|net|it|info|org|eu|uk|ca|us|cl)((\/[a-zA-Z0-9\_\.\-\:\+]+)*(\/([a-zA-Z0-9\_\:\-\.\+]+\.(php|html|htm|asp|aspx|jsp|cgi))?)?)?(\?([a-zA-Z0-9\_\-\+\s]+\=[a-zA-Z0-9\_\-\s\+\&]+)+)?(#[a-zA-Z0-9\_\-\+\s]+)?([\s]*)?$/'; if (preg_match($match,$url)) @@ -356,6 +366,42 @@ function linkTo($match) } } +function createNode($match,$hnodeTag,$htmlTagBegin,$htmlTagEng) +{ + $numb = strlen($hnodeTag); + global $decodeAnotherTime; + + if (strstr($match[2],$hnodeTag)) + { + $string = substr($match[0],$numb); + $string = decodeWikiText($string); + $decodeAnotherTime = true; + return $hnodeTag.$string; + } + else + { + return $htmlTagBegin.$match[2].$htmlTagEng; + } +} + +//create
  • +function createItem($match) +{ + return createNode($match,'[*]',"
  • ","
  • "); +} + +//create +function createList($match) +{ + return createNode($match,'[list]',""); +} + +//create
      +function createEnum($match) +{ + return createNode($match,'[enum]',"
        ","
      "); +} + function linkToInternalPage($match) { return "".$match[2].""; -- cgit v1.2.3