cvs: phd /themes/php phpweb.php

From: Date: Fri, 17 Aug 2007 09:17:43 +0000
Subject: cvs: phd /themes/php phpweb.php
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969377548@lists.php.net to get a copy of this message
bjori Fri Aug 17 09:17:43 2007 UTC Modified files: /phd/themes/php phpweb.php Log: Refactor the next/prev page generation into their own methods http://cvs.php.net/viewvc.cgi/phd/themes/php/phpweb.php?r1=1.6&r2=1.7&diff_format=u Index: phd/themes/php/phpweb.php diff -u phd/themes/php/phpweb.php:1.6 phd/themes/php/phpweb.php:1.7 --- phd/themes/php/phpweb.php:1.6 Thu Aug 16 18:36:28 2007 +++ phd/themes/php/phpweb.php Fri Aug 17 09:17:43 2007 @@ -1,5 +1,5 @@ <?php -/* $Id: phpweb.php,v 1.6 2007/08/16 18:36:28 bjori Exp $ */ +/* $Id: phpweb.php,v 1.7 2007/08/17 09:17:43 bjori Exp $ */ class phpweb extends phpdotnet implements PhDTheme { protected $streams = array(); @@ -75,61 +75,8 @@ $incl = 'include_once "./toc/' .$parent. '.inc";'; $up = array($this->getFilename($parent).$ext, PhDHelper::getDescription($parent, true)); - // {{{ Create the "next" link - if (!empty($siblings[$id]["children"])) { - $tmp = reset($siblings[$id]["children"]); - $next = array($tmp["filename"].$ext, (empty($tmp["ldesc"]) ? $tmp["sdesc"] : $tmp["ldesc"])); - } else { - // don't overwrite these variables - $tid = $id; - $tsiblings = $siblings; - $tparent = $parent; - do { - if (!isset($tsiblings[$tid])) { - break; - } - - // Seek to $tid - in_array($tsiblings[$tid], $tsiblings, false, true) or die(var_export(debug_backtrace(), true) ."\n$tid\n$tparent"); // This should *never* happen - $tmp = next($tsiblings); - prev($tsiblings); // Reset the internal pointer to previous pos - if ($tmp) { - $next = array($tmp["filename"].$ext, (empty($tmp["sdesc"]) ? $tmp["ldesc"] : $tmp["sdesc"])); - break; - } - - // We are the end element in this chapter - $tgrandpa = PhDHelper::getParent($tparent); - if (!$tgrandpa || $tgrandpa == "ROOT") { - // There is no next relative - break; - } - - $tsiblings = PhDHelper::getChildren($tgrandpa); - $tid = $tparent; - $tparent = $tgrandpa; - } while(true); - } // }}} - - // {{{ Create the "previous" link - do { - if (!isset($siblings[$id])) { - break; - } - - // Seek to $id - in_array($siblings[$id], $siblings, false, true); - $tmp = prev($siblings); - if ($tmp) { - while (!empty($tmp["children"])) { - $tmp = end($tmp["children"]); - } - $prev = array($tmp["filename"].$ext, (empty($tmp["sdesc"]) ? $tmp["ldesc"] : $tmp["sdesc"])); - break; - } - - $prev = array(PhDHelper::getFilename($parent).$ext, PhDHelper::getDescription($parent, false)); - } while(false); // }}} + $prev = $this->createPrev($id, $parent, $siblings); + $next = $this->createNext($id, $parent, $siblings); } $setup = array( @@ -158,6 +105,70 @@ public function footer($id) { return "<?php manual_footer(); ?>"; } + protected function createPrev($id, $parent, $siblings) { + $ext = '.' .$this->ext; + $prev = array(null, null); + // {{{ Create the "previous" link + do { + if (!isset($siblings[$id])) { + break; + } + + // Seek to $id + in_array($siblings[$id], $siblings, false, true); + $tmp = prev($siblings); + if ($tmp) { + while (!empty($tmp["children"])) { + $tmp = end($tmp["children"]); + } + $prev = array($tmp["filename"].$ext, (empty($tmp["sdesc"]) ? $tmp["ldesc"] : $tmp["sdesc"])); + break; + } + + $prev = array(PhDHelper::getFilename($parent).$ext, PhDHelper::getDescription($parent, false)); + } while(false); // }}} + return $prev; + } + protected function createNext($id, $parent, $siblings) { + $ext = '.' .$this->ext; + $next = array(null, null); + // {{{ Create the "next" link + if (!empty($siblings[$id]["children"])) { + $tmp = reset($siblings[$id]["children"]); + $next = array($tmp["filename"].$ext, (empty($tmp["ldesc"]) ? $tmp["sdesc"] : $tmp["ldesc"])); + } else { + // don't overwrite these variables + $tid = $id; + $tsiblings = $siblings; + $tparent = $parent; + do { + if (!isset($tsiblings[$tid])) { + break; + } + + // Seek to $tid + in_array($tsiblings[$tid], $tsiblings, false, true) or die(var_export(debug_backtrace(), true) ."\n$tid\n$tparent"); // This should *never* happen + $tmp = next($tsiblings); + prev($tsiblings); // Reset the internal pointer to previous pos + if ($tmp) { + $next = array($tmp["filename"].$ext, (empty($tmp["sdesc"]) ? $tmp["ldesc"] : $tmp["sdesc"])); + break; + } + + // We are the end element in this chapter + $tgrandpa = PhDHelper::getParent($tparent); + if (!$tgrandpa || $tgrandpa == "ROOT") { + // There is no next relative + break; + } + + $tsiblings = PhDHelper::getChildren($tgrandpa); + $tid = $tparent; + $tparent = $tgrandpa; + } while(true); + } // }}} + return $next; + } public function __destruct() { copy("php/manual.php", "php/index.php"); }

« previous php.doc (#969377548) next »