Bläddra i källkod

Hello application interface (snippet update)

markseu 12 år sedan
förälder
incheckning
1fea1bc3b0
3 ändrade filer med 46 tillägg och 18 borttagningar
  1. 44 16
      system/core/core.php
  2. 1 1
      system/snippets/content.php
  3. 1 1
      system/snippets/navigation.php

+ 44 - 16
system/core/core.php

@@ -5,7 +5,7 @@
 // Yellow main class
 // Yellow main class
 class Yellow
 class Yellow
 {
 {
-	const Version = "0.1.11";
+	const Version = "0.1.12";
 	var $page;				//current page data
 	var $page;				//current page data
 	var $pages;				//current page tree from file system
 	var $pages;				//current page tree from file system
 	var $toolbox;			//toolbox with helpers
 	var $toolbox;			//toolbox with helpers
@@ -495,10 +495,18 @@ class Yellow_Page
 		return $statusCode;
 		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
 	// Return pages on the same level as current page
@@ -508,11 +516,10 @@ class Yellow_Page
 		return $this->yellow->pages->findChildren($parentLocation, $showHidden);
 		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
 	// Check if response header exists
@@ -657,7 +664,19 @@ class Yellow_PageCollection extends ArrayObject
 		foreach($this->getIterator() as $page) $modified = max($modified, $page->getModified());
 		foreach($this->getIterator() as $page) $modified = max($modified, $page->getModified());
 		return $httpFormat ? $this->yellow->toolbox->getHttpTimeFormatted($modified) : $modified;
 		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
 	// Check if there is an active pagination
 	function isPagination()
 	function isPagination()
 	{
 	{
@@ -686,27 +705,28 @@ class Yellow_Pages
 		return $this->findChildrenRecursive("", $showHidden, $levelMax);
 		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);
 		return $this->findChildren("", $showHidden);
 	}
 	}
-
-	// Find a specific page
+	
+	// Return page collection with a specific page
 	function find($location, $absoluteLocation = false)
 	function find($location, $absoluteLocation = false)
 	{
 	{
 		if($absoluteLocation) $location = substru($location, strlenu($this->serverBase));
 		if($absoluteLocation) $location = substru($location, strlenu($this->serverBase));
 		$parentLocation = $this->getParentLocation($location);
 		$parentLocation = $this->getParentLocation($location);
 		$this->scanChildren($parentLocation);
 		$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
 	// Find child pages
 	function findChildren($location, $showHidden = false)
 	function findChildren($location, $showHidden = false)
 	{
 	{
-		$pages = new Yellow_PageCollection($this->yellow, $location);
 		$this->scanChildren($location);
 		$this->scanChildren($location);
+		$pages = new Yellow_PageCollection($this->yellow, $location);
 		foreach($this->pages[$location] as $page) if($page->isVisible() || $showHidden) $pages->append($page);
 		foreach($this->pages[$location] as $page) if($page->isVisible() || $showHidden) $pages->append($page);
 		return $pages;
 		return $pages;
 	}
 	}
@@ -715,8 +735,8 @@ class Yellow_Pages
 	function findChildrenRecursive($location, $showHidden = false, $levelMax = 0)
 	function findChildrenRecursive($location, $showHidden = false, $levelMax = 0)
 	{
 	{
 		--$levelMax;
 		--$levelMax;
-		$pages = new Yellow_PageCollection($this->yellow, $location);
 		$this->scanChildren($location);
 		$this->scanChildren($location);
+		$pages = new Yellow_PageCollection($this->yellow, $location);
 		foreach($this->pages[$location] as $page)
 		foreach($this->pages[$location] as $page)
 		{
 		{
 			if($page->isVisible() || $showHidden)
 			if($page->isVisible() || $showHidden)
@@ -781,6 +801,14 @@ class Yellow_Pages
 		if(preg_match("/^(.*\/)(.+?)$/", $location, $matches)) $parentLocation = $matches[1]!="/" ? $matches[1] : "";
 		if(preg_match("/^(.*\/)(.+?)$/", $location, $matches)) $parentLocation = $matches[1]!="/" ? $matches[1] : "";
 		return $parentLocation;
 		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
 // Yellow toolbox with helpers

+ 1 - 1
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">
 <div class="content">
 <h1><?php echo $title ?></h1>
 <h1><?php echo $title ?></h1>
 <?php echo $text ?>
 <?php echo $text ?>

+ 1 - 1
system/snippets/navigation.php

@@ -1,6 +1,6 @@
 <div class="navigation">
 <div class="navigation">
 <ul>
 <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>
 <li><a<?php echo $page->isActive() ? " class=\"active\"" : "" ?> href="<?php echo $page->getLocation() ?>"><?php echo $page->getTitle() ?></a></li>
 <?php endforeach ?>
 <?php endforeach ?>
 </ul>
 </ul>