aboutsummaryrefslogtreecommitdiff
path: root/h-source
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2011-10-23 12:34:06 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2011-10-23 12:34:06 +0000
commit0cc7100dcf9abbab90cd49930074e3b9eaf15095 (patch)
treef7b5f4748c487792c9f6d4ef06ee472a6ad70a82 /h-source
parent4d739f188d22ff70e2376a738f27cc36ab8cdc00 (diff)
improved wiki formatting: added TOC - part 2
Diffstat (limited to 'h-source')
-rw-r--r--h-source/Application/Include/languages.php1
-rw-r--r--h-source/Application/Include/myFunctions.php95
-rw-r--r--h-source/Public/Css/main.css13
3 files changed, 79 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)
diff --git a/h-source/Public/Css/main.css b/h-source/Public/Css/main.css
index 1f6e597..0ffd46c 100644
--- a/h-source/Public/Css/main.css
+++ b/h-source/Public/Css/main.css
@@ -687,6 +687,17 @@ ins
{
margin-bottom:10px;
}
+.tables_of_contents
+{
+ margin:10px 0;
+ padding:5px;
+ background-color:#C7DAEF;
+}
+.tables_of_contents_title
+{
+ margin:5px;
+ font-weight:bold;
+}
/*wiki code*/
.code_pre
{
@@ -712,11 +723,13 @@ ins
{
font:bold 17px/1 sans-serif,arial;
color:gray;
+ padding:2px 0;
}
.div_h3
{
font:bold 16px/1 sans-serif,arial;
color:gray;
+ padding:2px 0;
}
.div_lang
{