summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/pageutils.php24
-rw-r--r--inc/template.php12
2 files changed, 36 insertions, 0 deletions
diff --git a/inc/pageutils.php b/inc/pageutils.php
index c94d14624..f525c44d0 100644
--- a/inc/pageutils.php
+++ b/inc/pageutils.php
@@ -622,3 +622,27 @@ function utf8_decodeFN($file){
return urldecode($file);
}
+/**
+ * Find a page in the current namespace (determined from $ID) or any
+ * higher namespace
+ *
+ * Used for sidebars, but can be used other stuff as well
+ *
+ * @todo add event hook
+ * @param string $page the pagename you're looking for
+ * @return string|false the full page id of the found page, false if any
+ */
+function page_findnearest($page){
+ global $ID;
+
+ $ns = $ID;
+ do {
+ $ns = getNS($ns);
+ $pageid = ltrim("$ns:$page",':');
+ if(page_exists($pageid)){
+ return $pageid;
+ }
+ } while($ns);
+
+ return false;
+}
diff --git a/inc/template.php b/inc/template.php
index a18d7151f..c9e899034 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -1394,6 +1394,18 @@ function tpl_include_page($pageid,$print=true){
if(!$print) return $html;
echo $html;
+ return $html;
+}
+
+/**
+ * Include the sidebar, will check current namespaces first
+ */
+function tpl_sidebar($print=true){
+ global $conf;
+
+ $sidebar = page_findnearest($conf['sidebar']);
+ if($sidebar) return tpl_include_page($sidebar, $print);
+ return '';
}
/**