diff options
Diffstat (limited to 'h-source/Application')
-rw-r--r-- | h-source/Application/Include/languages.php | 1 | ||||
-rw-r--r-- | h-source/Application/Include/myFunctions.php | 95 |
2 files changed, 66 insertions, 30 deletions
diff --git a/h-source/Application/Include/languages.php b/h-source/Application/Include/languages.php index ad67f4d..4df9ee8 100644 --- a/h-source/Application/Include/languages.php +++ b/h-source/Application/Include/languages.php @@ -316,6 +316,7 @@ class Lang /*0268*/"No modems found" => "Non รจ stato trovato alcun modem", /*0269*/"Download the xml file of all the <b>modems</b> in the database" => "Scarica il file xml di tutti i <b>modem</b> presenti nel database", /*0270*/"Modems and ADSL cards" => "Modem e schede ADSL", + /*0271*/"Table of contents" => "Indice dei contenuti", ), 'es' => array ( diff --git a/h-source/Application/Include/myFunctions.php b/h-source/Application/Include/myFunctions.php index 1356281..5cceaea 100644 --- a/h-source/Application/Include/myFunctions.php +++ b/h-source/Application/Include/myFunctions.php @@ -178,9 +178,6 @@ function htmlDiff($old, $new) $old = str_replace("\r\n"," \r\n ",$old); $new = str_replace("\r\n"," \r\n ",$new); -// $old = str_replace("\n"," \n ",$old); -// $new = str_replace("\n"," \n ",$new); - $ret = null; $diff = diff(removeEmptyStrings(explode(' ', $old)),removeEmptyStrings(explode(' ', $new))); foreach($diff as $k) @@ -272,6 +269,8 @@ function decodeWikiText($string) $string = preg_replace_callback('/(\[tab )(lang=)([^\s]+)(\s*\])(.*?)(\[\/tab\])/s', 'createTabs',$string); + $string = preg_replace_callback('/(__TOC__)/s', 'createToc',$string); + $string = preg_replace('/(\[lang\])(.*?)(\[\/lang\])/s', '<div class="div_lang">${2}</div>',$string); $string = preg_replace('/(\{\{)/s', '[',$string); @@ -280,11 +279,11 @@ function decodeWikiText($string) if ($decodeAnotherTime and $decodeCounter<=30) { - return decodeWikiText(Tabs::render().$string); + return decodeWikiText(Toc::render().Tabs::render().$string); } else { - return Tabs::render().$string; + return Toc::render().Tabs::render().$string; } } @@ -382,6 +381,12 @@ function createNode($match,$hnodeTag,$htmlTagBegin,$htmlTagEng) } } +function createToc($match) +{ + Toc::create(); + return null; +} + //table of contents class Toc { @@ -389,41 +394,71 @@ class Toc public static $links = array(); public static $level = 1; - public function render($array = null, $useSelf = true) + private static $html = null; + + public function create() { - if (!isset($array) and $useSelf) + $c=0; + foreach (self::$links as $link) { - $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) + if ((int)substr($link,0,1) === 1) { - $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 + $c++; + } + + self::$links = array_slice(self::$links,$c); + + $res = array(); + + if (count(self::$links) > 0) + { + self::$links[] = '1fine'; + + $res[] = "<div class='tables_of_contents'><div class='tables_of_contents_title'>".gtext("Table of contents")."</div><ul>"; + foreach (self::$links as $link) { - self::$level = $startChar; - $str .= null; + $startChar = (int)substr($link,0,1); + + if (strcmp(self::$level,$startChar) === 0) + { + $res[] = "<li><a href='#".substr($link,1)."'>".substr($link,1)."</a></li>"; + } + else if ($startChar > self::$level) + { + $diff = (int)$startChar - (int)self::$level; + if ($diff !== 1) + { + return null; + } + + self::$level = $startChar; + $res[] = "<ul><li><a href='#".substr($link,1)."'>".substr($link,1)."</a></li>"; + } + else + { + $diff = (int)self::$level - (int)$startChar; + + for ($i=0;$i<$diff;$i++) + { + $res[] = "</ul>"; + } + self::$level = $startChar; + $res[] = "<li><a href='#".substr($link,1)."'>".substr($link,1)."</a></li>"; + } } + array_pop($res); + $res[] = "</ul></div>"; } - $str .= "</ul>"; self::$links = array(); - return $str; + self::$html = implode('',$res); + } + + public function render() + { + echo self::$html; } - } //create h1, h2, h3 ($level=1,2,3) |