From 377f9e9776677a6d3963718bfd48bba361571dfb Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Sun, 18 Jun 2006 14:15:21 +0200
Subject: [PATCH] simplified tpl_getparent

4th part of the global start series

darcs-hash:20060618121521-7ad00-8ea574bdb2c8a12560cf892c7ed53a4972af998d.gz
---
 inc/template.php | 32 ++++++--------------------------
 1 file changed, 6 insertions(+), 26 deletions(-)

diff --git a/inc/template.php b/inc/template.php
index 2cd4d0f06..78dc45e37 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -253,34 +253,14 @@ function tpl_pagelink($id,$name=NULL){
  * Tries to find out which page is parent.
  * returns false if none is available
  *
- * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
+ * @author Andreas Gohr <andi@splitbrain.org>
  */
-function tpl_getparent($ID){
+function tpl_getparent($id){
   global $conf;
-
-  if ($ID != $conf['start']) {
-    $idparts = explode(':', $ID);
-    $pn = array_pop($idparts);    // get the page name
-
-    for ($n=0; $n < 2; $n++) {
-      if (count($idparts) == 0) {
-        $ID = $conf['start'];     // go to topmost page
-        break;
-      }else{
-        $ns = array_pop($idparts);     // get the last part of namespace
-        if ($pn != $ns) {                 // are we already home?
-          array_push($idparts, $ns, $ns); // no, then add a page with same name
-          $ID = implode (':', $idparts); // as the namespace and recombine $ID
-          break;
-        }
-      }
-    }
-
-    if (@file_exists(wikiFN($ID))) {
-      return $ID;
-    }
-  }
-  return false;
+  $parent = getNS($id).':';
+  resolve_pageid('',$parent,$exists);
+  if($parent == $id) return false;
+  return $parent;
 }
 
 /**
-- 
GitLab