浏览代码

Hello application interface (remix by Datentechniker David)

markseu 12 年之前
父节点
当前提交
a2dda76e6c
共有 1 个文件被更改,包括 32 次插入8 次删除
  1. 32 8
      system/core/core.php

+ 32 - 8
system/core/core.php

@@ -5,7 +5,7 @@
 // Yellow main class
 // Yellow main class
 class Yellow
 class Yellow
 {
 {
-	const Version = "0.1.13";
+	const Version = "0.1.14";
 	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
@@ -362,6 +362,7 @@ class Yellow_Page
 	function parseMeta()
 	function parseMeta()
 	{
 	{
 		$this->set("title", $this->yellow->toolbox->createTextTitle($this->location));
 		$this->set("title", $this->yellow->toolbox->createTextTitle($this->location));
+		$this->set("modified", date("c", is_readable($this->fileName) ? filemtime($this->fileName) : 0));
 		$this->set("sitename", $this->yellow->config->get("sitename"));
 		$this->set("sitename", $this->yellow->config->get("sitename"));
 		$this->set("author", $this->yellow->config->get("author"));
 		$this->set("author", $this->yellow->config->get("author"));
 		$this->set("language", $this->yellow->config->get("language"));
 		$this->set("language", $this->yellow->config->get("language"));
@@ -479,9 +480,8 @@ class Yellow_Page
 	// Return page modification time, Unix time
 	// Return page modification time, Unix time
 	function getModified($httpFormat = false)
 	function getModified($httpFormat = false)
 	{
 	{
-		$modified = is_readable($this->fileName) ? filemtime($this->fileName) : 0;
-		if($this->isExisting("modified")) $modified = strtotime($this->get("modified"));
-		return $httpFormat ? $this->yellow->toolbox->getHttpTimeFormatted($modified) : $modified;
+	   $modified = strtotime($this->get("modified"));
+	   return $httpFormat ? $this->yellow->toolbox->getHttpTimeFormatted($modified) : $modified;
 	}
 	}
 	
 	
 	// Return page status code
 	// Return page status code
@@ -592,6 +592,21 @@ class Yellow_PageCollection extends ArrayObject
 		}
 		}
 		return $this;
 		return $this;
 	}
 	}
+	
+	// Sort page collection by meta data
+	function sort($key, $ascendingOrder = true)
+	{
+		$callback = function($a, $b) use ($key, $ascendingOrder)
+		{
+			return $ascendingOrder ?
+				strnatcasecmp($a->get($key), $b->get($key)) :
+				strnatcasecmp($b->get($key), $a->get($key));
+		};
+		$array = $this->getArrayCopy();
+		usort($array, $callback);
+		$this->exchangeArray($array);
+		return $this;
+	}
 
 
 	// Merge page collection
 	// Merge page collection
 	function merge($input)
 	function merge($input)
@@ -600,8 +615,15 @@ class Yellow_PageCollection extends ArrayObject
 		return $this;
 		return $this;
 	}
 	}
 	
 	
+	// Limit the number of pages in page collection
+	function limit($pagesMax)
+	{
+		$this->exchangeArray(array_slice($this->getArrayCopy(), 0, $pagesMax));
+		return $this;
+	}
+	
 	// Reverse page collection
 	// Reverse page collection
-	function reverse($entriesMax = 0)
+	function reverse()
 	{
 	{
 		$this->exchangeArray(array_reverse($this->getArrayCopy()));
 		$this->exchangeArray(array_reverse($this->getArrayCopy()));
 		return $this;
 		return $this;
@@ -1173,17 +1195,19 @@ class Yellow_Toolbox
 				$elementFound = preg_match("/&.*?\;|<\s*?(\/?\w*)\s*?(.*?)\s*?\>/s", $text, $matches, PREG_OFFSET_CAPTURE, $offsetBytes);
 				$elementFound = preg_match("/&.*?\;|<\s*?(\/?\w*)\s*?(.*?)\s*?\>/s", $text, $matches, PREG_OFFSET_CAPTURE, $offsetBytes);
 				$element = $matches[0][0];
 				$element = $matches[0][0];
 				$elementName = $matches[1][0];
 				$elementName = $matches[1][0];
+				$elementText = $matches[2][0];
 				$elementOffsetBytes = $elementFound ? $matches[0][1] : strlenb($text);
 				$elementOffsetBytes = $elementFound ? $matches[0][1] : strlenb($text);
 				$string = substrb($text, $offsetBytes, $elementOffsetBytes - $offsetBytes);
 				$string = substrb($text, $offsetBytes, $elementOffsetBytes - $offsetBytes);
 				$length = strlenu($string);
 				$length = strlenu($string);
 				$output .= substru($string, 0, $length < $lengthMax ? $length : $lengthMax-1);
 				$output .= substru($string, 0, $length < $lengthMax ? $length : $lengthMax-1);
 				$lengthMax -= $length + ($element[0]=='&' ? 1 : 0);
 				$lengthMax -= $length + ($element[0]=='&' ? 1 : 0);
 				if($lengthMax<=0 || !$elementFound) break;
 				if($lengthMax<=0 || !$elementFound) break;
-				if(!empty($elementName))
+				if(!empty($elementName) && substru($elementText, -1)!='/' &&
+				   !preg_match("/^(area|br|col|hr|img|input|col|param)/i", $elementName))
 				{
 				{
-					if(!preg_match("/^(\/|area|br|col|hr|img|input|col|param)/i", $elementName))
+					if($elementName[0] != '/')
 					{
 					{
-						if(substru($matches[2][0], -1) != '/') array_push($elementsOpen, $elementName);
+						array_push($elementsOpen, $elementName);
 					} else {
 					} else {
 						array_pop($elementsOpen);
 						array_pop($elementsOpen);
 					}
 					}