diff --git a/index.php b/index.php
index 3171e4e..a6986ea 100644
--- a/index.php
+++ b/index.php
@@ -853,19 +853,70 @@ register_module([
}
page_renderer::register_part_preprocessor(function(&$parts) use ($show_sidebar) {
- global $settings;
+ global $settings, $pageindex;
if($show_sidebar)
{
// Show the sidebar
- $sidebar_contents = "Testing";
- $parts["{body}"] = "
-
" . $parts["{body}"] . "
";
+ $exec_start = microtime(true);
+
+ $sidebar_contents = "";
+ $sidebar_contents .= render_sidebar($pageindex);
+
+ $parts["{body}"] = "
+ " . $parts["{body}"] . "
+
+ ";
}
});
}
]);
+/*
+ * @summary Renders the sidebar for the given pageindex.
+ *
+ * @param $pageindex {array} - The pageindex to renderthe sidebar for
+ * @param $root_pagename {string} - The pagename that should be considered the root of the rendering. You don't usually need to use this, it is used by the algorithm itself since it is recursive.
+ *
+ * @returns {string} A HTML rendering of the sidebar for the given pageindex
+ */
+function render_sidebar($pageindex, $root_pagename = "")
+{
+ global $settings;
+
+ $result = "";
+ foreach ($pageindex as $pagename => $details)
+ {
+ // If we have a valid root pagename, and it isn't present at the
+ // beginning of the current pagename, skip it
+ if($root_pagename !== "" && strpos($pagename, $root_pagename) !== 0)
+ continue;
+
+ // The current page is the same as the root page, skip it
+ if($pagename == $root_pagename)
+ continue;
+
+
+ // If the part of the current pagename that comes after the root
+ // pagename has a slash in it, skip it as it is a sub-sub page.
+ if(strpos(substr($pagename, strlen($root_pagename)), "/") !== false)
+ continue;
+
+ $result .= "- $pagename\n";
+ $result .= render_sidebar($pageindex, $pagename);
+ $result .= "
";
+ }
+ $result .= "
";
+
+ return $result == "" ? "" : $result;
+}
+
diff --git a/module_index.json b/module_index.json
index e8771fc..4bb72da 100644
--- a/module_index.json
+++ b/module_index.json
@@ -13,7 +13,7 @@
"author": "Starbeamrainbowlabs",
"description": "",
"id": "extra-sidebar",
- "lastupdate": 1438079423
+ "lastupdate": 1438679978
},
{
"name": "Credits",
diff --git a/modules/extra-sidebar.php b/modules/extra-sidebar.php
index 16c9ef1..880c3fb 100644
--- a/modules/extra-sidebar.php
+++ b/modules/extra-sidebar.php
@@ -35,17 +35,77 @@ register_module([
}
page_renderer::register_part_preprocessor(function(&$parts) use ($show_sidebar) {
- global $settings;
+ global $settings, $pageindex;
if($show_sidebar)
{
// Show the sidebar
- $sidebar_contents = "Testing";
- $parts["{body}"] = "
-" . $parts["{body}"] . "
";
+ $exec_start = microtime(true);
+
+ $sidebar_contents = "";
+ $sidebar_contents .= render_sidebar($pageindex);
+
+ $parts["{body}"] = "
+ " . $parts["{body}"] . "
+
+ ";
}
});
}
]);
+/*
+ * @summary Renders the sidebar for the given pageindex.
+ *
+ * @param $pageindex {array} - The pageindex to renderthe sidebar for
+ * @param $root_pagename {string} - The pagename that should be considered the root of the rendering. You don't usually need to use this, it is used by the algorithm itself since it is recursive.
+ *
+ * @returns {string} A HTML rendering of the sidebar for the given pageindex
+ */
+function render_sidebar($pageindex, $root_pagename = "")
+{
+ global $settings;
+
+ $result = " $details)
+ {
+ // If we have a valid root pagename, and it isn't present at the
+ // beginning of the current pagename, skip it
+ if($root_pagename !== "" && strpos($pagename, $root_pagename) !== 0)
+ continue;
+
+ // The current page is the same as the root page, skip it
+ if($pagename == $root_pagename)
+ continue;
+
+
+ // If the part of the current pagename that comes after the root
+ // pagename has a slash in it, skip it as it is a sub-sub page.
+ if(strpos(substr($pagename, strlen($root_pagename)), "/") !== false)
+ continue;
+
+ $result .= "- $pagename\n";
+ $result .= render_sidebar($pageindex, $pagename);
+ $result .= "
\n";
+ }
+ $result .= "
\n";
+
+ return $result == "" ? "" : $result;
+}
+
?>