commit 1fea1bc3b0a0958bd26a4f88f48cc5689553d8cf
parent 026f23139cda9704d6a9ce4688966a7358d270a0
Author: markseu <mark2011@mayberg.se>
Date: Thu, 8 Aug 2013 16:42:48 +0200
Hello application interface (snippet update)
Diffstat:
3 files changed, 46 insertions(+), 18 deletions(-)
diff --git a/system/core/core.php b/system/core/core.php
@@ -5,7 +5,7 @@
// Yellow main class
class Yellow
{
- const Version = "0.1.11";
+ const Version = "0.1.12";
var $page; //current page data
var $pages; //current page tree from file system
var $toolbox; //toolbox with helpers
@@ -495,10 +495,18 @@ class Yellow_Page
return $statusCode;
}
- // Return child pages relative to current page
- function getChildren($showHidden = false)
+ // Return parent page relative to current page
+ function getParent()
{
- return $this->yellow->pages->findChildren($this->location, $showHidden);
+ $parentLocation = $this->yellow->pages->getParentLocation($this->location);
+ return $this->yellow->pages->find($parentLocation, false)->first();
+ }
+
+ // Return top-level parent page of current page
+ function getParentTop()
+ {
+ $parentTopLocation = $this->yellow->pages->getParentTopLocation($this->location);
+ return $this->yellow->pages->find($parentTopLocation, false)->first();
}
// Return pages on the same level as current page
@@ -508,11 +516,10 @@ class Yellow_Page
return $this->yellow->pages->findChildren($parentLocation, $showHidden);
}
- // Return parent page relative to current page
- function getParent()
+ // Return child pages relative to current page
+ function getChildren($showHidden = false)
{
- $parentLocation = $this->yellow->pages->getParentLocation($this->location);
- return $this->yellow->pages->find($parentLocation, false);
+ return $this->yellow->pages->findChildren($this->location, $showHidden);
}
// Check if response header exists
@@ -657,7 +664,19 @@ class Yellow_PageCollection extends ArrayObject
foreach($this->getIterator() as $page) $modified = max($modified, $page->getModified());
return $httpFormat ? $this->yellow->toolbox->getHttpTimeFormatted($modified) : $modified;
}
+
+ // Return first page in page collection
+ function first()
+ {
+ return $this->offsetGet(0);
+ }
+ // Return last page in page collection
+ function last()
+ {
+ return $this->offsetGet($this->count()-1);
+ }
+
// Check if there is an active pagination
function isPagination()
{
@@ -686,27 +705,28 @@ class Yellow_Pages
return $this->findChildrenRecursive("", $showHidden, $levelMax);
}
- // Return top-level navigation pages
- function root($showHidden = false)
+ // Return page collection with top-level navigation
+ function top($showHidden = false)
{
return $this->findChildren("", $showHidden);
}
-
- // Find a specific page
+
+ // Return page collection with a specific page
function find($location, $absoluteLocation = false)
{
if($absoluteLocation) $location = substru($location, strlenu($this->serverBase));
$parentLocation = $this->getParentLocation($location);
$this->scanChildren($parentLocation);
- foreach($this->pages[$parentLocation] as $page) if($page->location == $location) return $page;
- return false;
+ $pages = new Yellow_PageCollection($this->yellow, $parentLocation);
+ foreach($this->pages[$parentLocation] as $page) if($page->location == $location) $pages->append($page);
+ return $pages;
}
// Find child pages
function findChildren($location, $showHidden = false)
{
- $pages = new Yellow_PageCollection($this->yellow, $location);
$this->scanChildren($location);
+ $pages = new Yellow_PageCollection($this->yellow, $location);
foreach($this->pages[$location] as $page) if($page->isVisible() || $showHidden) $pages->append($page);
return $pages;
}
@@ -715,8 +735,8 @@ class Yellow_Pages
function findChildrenRecursive($location, $showHidden = false, $levelMax = 0)
{
--$levelMax;
- $pages = new Yellow_PageCollection($this->yellow, $location);
$this->scanChildren($location);
+ $pages = new Yellow_PageCollection($this->yellow, $location);
foreach($this->pages[$location] as $page)
{
if($page->isVisible() || $showHidden)
@@ -781,6 +801,14 @@ class Yellow_Pages
if(preg_match("/^(.*\/)(.+?)$/", $location, $matches)) $parentLocation = $matches[1]!="/" ? $matches[1] : "";
return $parentLocation;
}
+
+ // Return top-level parent location
+ function getParentTopLocation($location)
+ {
+ $parentTopLocation = "/";
+ if(preg_match("/^(.+?\/)/", $location, $matches)) $parentTopLocation = $matches[1];
+ return $parentTopLocation;
+ }
}
// Yellow toolbox with helpers
diff --git a/system/snippets/content.php b/system/snippets/content.php
@@ -1,4 +1,4 @@
-<?php list($name, $title, $text) = $yellow->getSnippetArgs(); ?>
+<?php list($name, $title, $text) = $yellow->getSnippetArgs() ?>
<div class="content">
<h1><?php echo $title ?></h1>
<?php echo $text ?>
diff --git a/system/snippets/navigation.php b/system/snippets/navigation.php
@@ -1,6 +1,6 @@
<div class="navigation">
<ul>
-<?php foreach($yellow->pages->root() as $page): ?>
+<?php foreach($yellow->pages->top() as $page): ?>
<li><a<?php echo $page->isActive() ? " class=\"active\"" : "" ?> href="<?php echo $page->getLocation() ?>"><?php echo $page->getTitle() ?></a></li>
<?php endforeach ?>
</ul>