Core update (better API)

This commit is contained in:
markseu 2015-06-03 00:29:00 +02:00
parent f98a98be1a
commit 481ebbd51e
3 changed files with 22 additions and 14 deletions

View file

@ -1,4 +1,4 @@
Yellow 0.5.18
Yellow 0.5.19
=============
[![Yellow](https://raw.githubusercontent.com/wiki/datenstrom/yellow/images/yellow.jpg)](http://datenstrom.se/yellow)

View file

@ -5,7 +5,7 @@
// Yellow main class
class Yellow
{
const Version = "0.5.18";
const Version = "0.5.19";
var $page; //current page
var $pages; //pages from file system
var $files; //files from file system
@ -710,15 +710,15 @@ class YellowPage
}
// Set page relation
function setPage($type, $page)
function setPage($key, $page)
{
$page->relations[$type] = $this;
$page->relations[$key] = $this;
}
// Return related page
function getPage($type)
function getPage($key)
{
return !is_null($this->relations[$type]) ? $this->relations[$type] : $this;
return !is_null($this->relations[$key]) ? $this->relations[$key] : $this;
}
// Return absolute page location
@ -942,8 +942,9 @@ class YellowPageCollection extends ArrayObject
function similar($page, $ascendingOrder = false)
{
$location = $page->location;
$keywords = $page->get("keywords").",".$page->get("tag").",".$page->get("author");
$tokens = array_unique(array_filter(explode(',', $keywords), "strlen"));
$keywords = $this->yellow->toolbox->createTextKeywords($page->get("title"));
$keywords .= ",".$page->get("tag").",".$page->get("author");
$tokens = array_unique(array_filter(preg_split("/,\s*/", $keywords), "strlen"));
if(!empty($tokens))
{
$array = array();
@ -2134,11 +2135,16 @@ class YellowLookup
// Check if location is within current request
function isActiveLocation($location, $currentLocation)
{
if($location != $this->yellow->pages->getHomeLocation($currentLocation))
if($this->isFileLocation($location))
{
$active = substru($currentLocation, 0, strlenu($location))==$location;
$active = $currentLocation==$location;
} else {
$active = $this->getDirectoryLocation($currentLocation)==$location;
if($location == $this->yellow->pages->getHomeLocation($location))
{
$active = $this->getDirectoryLocation($currentLocation)==$location;
} else {
$active = substru($currentLocation, 0, strlenu($location))==$location;
}
}
return $active;
}
@ -2610,11 +2616,12 @@ class YellowToolbox
}
// Create keywords from text string
function createTextKeywords($text, $keywordsMax)
function createTextKeywords($text, $keywordsMax = 0)
{
$tokens = preg_split("/[,\s\(\)]/", strtoloweru($text));
$tokens = array_unique(preg_split("/[,\s\(\)]/", strtoloweru($text)));
foreach($tokens as $key=>$value) if(strlenu($value) < 3) unset($tokens[$key]);
return implode(", ", array_slice(array_unique($tokens), 0, $keywordsMax));
if($keywordsMax) $tokens = array_slice($tokens, 0, $keywordsMax);
return implode(", ", $tokens);
}
// Create title from text string

View file

@ -17,6 +17,7 @@
<?php $yellow->page->set("pageClass", "page") ?>
<?php $yellow->page->set("pageClass", $yellow->page->get("pageClass")." ".$yellow->page->get("template")) ?>
<?php if($yellow->page->isExisting("sidebar")) $yellow->page->set("pageClass", $yellow->page->get("pageClass")." with-sidebar") ?>
<?php if($yellow->page->get("navigation") == "navigation-sidebar") { $yellow->page->set("pageClass", $yellow->page->get("pageClass")." with-sidebar"); $yellow->page->set("navigation", "navigation"); $yellow->page->set("sidebar", "navigation-sidebar"); } ?>
<div class="<?php echo $yellow->page->getHtml("pageClass") ?>">
<div class="header">
<div class="sitename"><h1><a href="<?php echo $yellow->page->base."/" ?>"><i class="sitename-logo"></i><?php echo $yellow->page->getHtml("sitename") ?></a></h1></div>