Updated system, new API

This commit is contained in:
markseu 2019-03-18 22:07:19 +01:00
parent 3c9e321dc8
commit 6e4a32f81a
10 changed files with 85 additions and 50 deletions

View file

@ -182,10 +182,10 @@ class YellowCore {
$language = $this->lookup->findLanguageFromFile($fileName, $this->system->get("language"));
if ($this->text->isExisting("error${statusCode}Title", $language)) {
$rawData = "---\nTitle:".$this->text->getText("error${statusCode}Title", $language)."\n";
$rawData .= "Layout:error\nLanguage:$language\n---\n".$this->text->getText("error${statusCode}Text", $language);
$rawData .= "Layout:error\nSidebar:none\nLanguage:$language\n---\n".$this->text->getText("error${statusCode}Text", $language);
} else {
$rawData = "---\nTitle:".$this->toolbox->getHttpStatusFormatted($statusCode, true)."\n";
$rawData .= "Layout:error\nLanguage:en\n---\n[yellow error]";
$rawData .= "Layout:error\nSidebar:none\nLanguage:en\n---\n[yellow error]";
}
$cacheable = false;
} else {
@ -707,19 +707,19 @@ class YellowPage {
// Include page layout
public function includeLayout($name) {
$fileNameLayoutBasic = $this->yellow->system->get("layoutDir").$this->yellow->lookup->normaliseName($name).".html";
$fileNameLayoutNormal = $this->yellow->system->get("layoutDir").$this->yellow->lookup->normaliseName($name).".html";
$fileNameLayoutTheme = $this->yellow->system->get("layoutDir").
$this->yellow->lookup->normaliseName($name)."-".$this->yellow->lookup->normaliseName($this->get("theme")).".html";
$this->yellow->lookup->normaliseName($this->get("theme"))."-".$this->yellow->lookup->normaliseName($name).".html";
if (is_file($fileNameLayoutTheme)) {
if (defined("DEBUG") && DEBUG>=2) echo "YellowPage::includeLayout file:$fileNameLayoutTheme<br>\n";
$this->setLastModified(filemtime($fileNameLayoutTheme));
global $yellow; //TODO: remove later, for backwards compatibility
require($fileNameLayoutTheme);
} elseif (is_file($fileNameLayoutBasic)) {
if (defined("DEBUG") && DEBUG>=2) echo "YellowPage::includeLayout file:$fileNameLayoutBasic<br>\n";
$this->setLastModified(filemtime($fileNameLayoutBasic));
} elseif (is_file($fileNameLayoutNormal)) {
if (defined("DEBUG") && DEBUG>=2) echo "YellowPage::includeLayout file:$fileNameLayoutNormal<br>\n";
$this->setLastModified(filemtime($fileNameLayoutNormal));
global $yellow; //TODO: remove later, for backwards compatibility
require($fileNameLayoutBasic);
require($fileNameLayoutNormal);
} else {
$this->error(500, "Layout '$name' does not exist!");
echo "Layout error<br/>\n";
@ -884,13 +884,6 @@ class YellowPage {
$this->yellow->system->get("resourceLocation").$this->yellow->lookup->normaliseName($this->get("theme")).".js";
$output .= "<script type=\"text/javascript\" src=\"$locationScript\"></script>\n";
}
$fileNameIcon = $this->yellow->system->get("resourceDir").$this->yellow->lookup->normaliseName($this->get("theme"))."-icon.png";
if (is_file($fileNameIcon)) {
$locationIcon = $this->yellow->system->get("serverBase").
$this->yellow->system->get("resourceLocation").$this->yellow->lookup->normaliseName($this->get("theme"))."-icon.png";
$contentType = $this->yellow->toolbox->getMimeContentType($locationIcon);
$output .= "<link rel=\"icon\" type=\"$contentType\" href=\"$locationIcon\" />\n";
}
}
return $output;
}
@ -1337,18 +1330,6 @@ class YellowContent {
return $pages;
}
// Return page with shared content, null if not found
public function shared($location, $absoluteLocation = false, $name = "shared") {
if ($absoluteLocation) $location = substru($location, strlenu($this->yellow->page->base));
$locationShared = $this->yellow->lookup->getDirectoryLocation($location);
$page = $this->find($locationShared.$name);
if ($page==null) {
$locationShared = $this->getHomeLocation($location).$this->yellow->system->get("contentSharedDir");
$page = $this->find($locationShared.$name);
}
return $page;
}
// Return page collection with multiple languages
public function multi($location, $absoluteLocation = false, $showInvisible = false) {
$pages = new YellowPageCollection($this->yellow);
@ -1364,6 +1345,18 @@ class YellowContent {
return $pages;
}
// Return page with shared content, null if not found
public function shared($name, $argumentObsolete = null, $nameObsolete = null) {
$name = !empty($nameObsolete) ? $nameObsolete : $name; //TODO: remove later, for backwards compatibility
$location = $this->yellow->lookup->getDirectoryLocation($this->yellow->page->location).$name;
$page = $this->find($location);
if ($page==null) {
$location = $this->getHomeLocation($this->yellow->page->location).$this->yellow->system->get("contentSharedDir").$name;
$page = $this->find($location);
}
return $page;
}
// Return page collection that's empty
public function clean() {
return new YellowPageCollection($this->yellow);
@ -1784,6 +1777,11 @@ class YellowText {
return $output;
}
// Return text settings modification date, Unix time or HTTP format
public function getModified($httpFormat = false) {
return $httpFormat ? $this->yellow->toolbox->getHttpDateFormatted($this->modified) : $this->modified;
}
// Return languages
public function getLanguages() {
$languages = array();
@ -1793,11 +1791,6 @@ class YellowText {
return $languages;
}
// Return text settings modification date, Unix time or HTTP format
public function getModified($httpFormat = false) {
return $httpFormat ? $this->yellow->toolbox->getHttpDateFormatted($this->modified) : $this->modified;
}
// Normalise date into known format
public function normaliseDate($text) {
if (preg_match("/^\d+\-\d+$/", $text)) {
@ -3112,6 +3105,17 @@ class YellowExtensions {
public function getModified($httpFormat = false) {
return $httpFormat ? $this->yellow->toolbox->getHttpDateFormatted($this->modified) : $this->modified;
}
// Return extensions
public function getExtensions($type = "") {
$extensions = array();
foreach ($this->extensions as $key=>$value) {
if (empty($type) || $value["type"]==$type) {
array_push($extensions, $key);
}
}
return $extensions;
}
// Check if extension exists
public function isExisting($name) {
@ -3126,7 +3130,7 @@ class YellowPages { //TODO: remove later, for backwards compatibility
public function index($showInvisible = false, $multiLanguage = false, $levelMax = 0) { return $this->yellow->content->index($showInvisible, $multiLanguage, $levelMax); }
public function top($showInvisible = false) { return $this->yellow->content->top($showInvisible); }
public function path($location, $absoluteLocation = false) { return $this->yellow->content->path($location, $absoluteLocation); }
public function shared($location, $absoluteLocation = false, $name = "shared") { return $this->yellow->content->shared($location, $absoluteLocation, $name); }
public function shared($name, $argumentObsolete = null, $nameObsolete = null) { return $this->yellow->content->shared($name, $argumentObsolete, $nameObsolete); }
public function multi($location, $absoluteLocation = false, $showInvisible = false) { return $this->yellow->content->multi($location, $absoluteLocation, $showInvisible); }
public function clean() { return $this->yellow->content->clean(); }
public function getHomeLocation($location) { return $this->yellow->content->getHomeLocation($location); }

View file

@ -1019,9 +1019,8 @@ class YellowResponse {
$page->setRequestInformation($scheme, $address, $base, $location, $fileName);
$page->parseData($this->normaliseLines($rawData, $endOfLine), false, 200);
$this->yellow->text->setLanguage($page->get("language"));
$page->set("pageClass", "page-preview");
$page->set("pageClass", $page->get("pageClass")." layout-".$page->get("layout"));
$output = "<div class=\"".$page->getHtml("pageClass")."\"><div class=\"content\">";
$class = "page-preview layout-".$page->get("layout");
$output = "<div class=\"".htmlspecialchars($class)."\"><div class=\"content\">";
if ($this->yellow->system->get("editToolbarButtons")!="none") $output .= "<h1>".$page->getHtml("titleContent")."</h1>\n";
$output .= $page->getContent();
$output .= "</div></div>";

View file

@ -4,6 +4,23 @@
// This file may be used and distributed under the terms of the public license.
class YellowStockholm {
const VERSION = "0.8.2";
const VERSION = "0.8.3";
const TYPE = "theme";
public $yellow; //access to API
// Handle initialisation
public function onLoad($yellow) {
$this->yellow = $yellow;
}
// Handle update
public function onUpdate($action) {
$fileName = $this->yellow->system->get("settingDir").$this->yellow->system->get("systemFile");
if ($action=="install") {
$this->yellow->system->save($fileName, array("theme" => "stockholm"));
} elseif ($action=="uninstall" && $this->yellow->system->get("theme")=="stockholm") {
$theme = reset(array_diff($this->yellow->extensions->getExtensions("theme"), array("stockholm")));
$this->yellow->system->save($fileName, array("theme" => $theme));
}
}
}

View file

@ -4,7 +4,7 @@
// This file may be used and distributed under the terms of the public license.
class YellowUpdate {
const VERSION = "0.8.4";
const VERSION = "0.8.5";
const TYPE = "feature";
const PRIORITY = "2";
public $yellow; //access to API
@ -78,6 +78,21 @@ class YellowUpdate {
}
}
}
if ($action=="update") { //TODO: remove later, converts old header layout
$fileName = $this->yellow->system->get("layoutDir")."header.html";
$fileData = $this->yellow->toolbox->readFile($fileName);
$pos = strposu($fileData, "<\x3Fphp echo \$this->yellow->page->getExtra");
if ($pos && strposu($fileData, "<link rel=\"icon\"")===false) {
$fileDataNew = substru($fileData, 0, $pos);
$fileDataNew .= "<\x3Fphp \$resourceLocation = \$this->yellow->system->get(\"serverBase\").\$this->yellow->system->get(\"resourceLocation\") \x3F>\n";
$fileDataNew .= "<link rel=\"icon\" type=\"image/png\" href=\"<\x3Fphp echo \$resourceLocation.\$this->yellow->page->getHtml(\"theme\").\"-icon.png\" \x3F>\" />\n";
$fileDataNew .= substru($fileData, $pos);
$fileDataNew = str_replace("content->shared(\$this->yellow->page->location, false, ", "content->shared(", $fileDataNew);
if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($fileName, $fileDataNew)) {
$this->yellow->log("error", "Can't write file '$fileName'!");
}
}
}
if ($action=="update") { //TODO: remove later, converts old website icon
if ($this->yellow->system->isExisting("siteicon")) {
$theme = $this->yellow->system->get("theme");

View file

@ -7,16 +7,17 @@
<meta name="author" content="<?php echo $this->yellow->page->getHtml("author") ?>" />
<meta name="generator" content="Datenstrom Yellow" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<?php $resourceLocation = $this->yellow->system->get("serverBase").$this->yellow->system->get("resourceLocation") ?>
<link rel="icon" type="image/png" href="<?php echo $resourceLocation.$this->yellow->page->getHtml("theme")."-icon.png" ?>" />
<?php echo $this->yellow->page->getExtra("header") ?>
</head>
<body>
<?php if ($page = $this->yellow->content->shared($this->yellow->page->location, false, $this->yellow->page->get("header"))) $this->yellow->page->setPage("header", $page) ?>
<?php if ($page = $this->yellow->content->shared($this->yellow->page->location, false, $this->yellow->page->get("footer"))) $this->yellow->page->setPage("footer", $page) ?>
<?php if ($page = $this->yellow->content->shared($this->yellow->page->location, false, $this->yellow->page->get("sidebar"))) $this->yellow->page->setPage("sidebar", $page) ?>
<?php if ($this->yellow->page->get("navigation")=="navigation-sidebar") $this->yellow->page->setPage("navigation-sidebar", $this->yellow->page->getParentTop(true)) ?>
<?php $this->yellow->page->set("pageClass", "page layout-".$this->yellow->page->get("layout")) ?>
<?php if (!$this->yellow->page->isError() && ($this->yellow->page->isPage("sidebar") || $this->yellow->page->isPage("navigation-sidebar"))) $this->yellow->page->set("pageClass", $this->yellow->page->get("pageClass")." with-sidebar") ?>
<div class="<?php echo $this->yellow->page->getHtml("pageClass") ?>">
<?php if ($page = $this->yellow->content->shared($this->yellow->page->get("header"))) $this->yellow->page->setPage("header", $page) ?>
<?php if ($page = $this->yellow->content->shared($this->yellow->page->get("footer"))) $this->yellow->page->setPage("footer", $page) ?>
<?php if ($page = $this->yellow->content->shared($this->yellow->page->get("sidebar"))) $this->yellow->page->setPage("sidebar", $page) ?>
<?php if ($this->yellow->page->get("navigation")=="navigation-sidebar") $this->yellow->page->setPage("navigation-sidebar", $this->yellow->page) ?>
<?php $class = "page layout-".$this->yellow->page->get("layout").($this->yellow->page->isPage("sidebar") || $this->yellow->page->isPage("navigation-sidebar") ? " with-sidebar" : "") ?>
<div class="<?php echo htmlspecialchars($class) ?>">
<div class="header" role="banner">
<div class="sitename">
<h1><a href="<?php echo $this->yellow->page->getBase(true)."/" ?>"><i class="sitename-logo"></i><?php echo $this->yellow->page->getHtml("sitename") ?></a></h1>

View file

@ -7,8 +7,7 @@
<?php elseif ($this->yellow->page->isPage("navigation-sidebar")): ?>
<div class="sidebar" role="complementary">
<div class="navigation-sidebar">
<?php $page = $this->yellow->page->getPage("navigation-sidebar") ?>
<?php $pages = $page->getChildren(!$page->isVisible()) ?>
<?php $pages = $this->yellow->page->getParentTop(true)->getChildren() ?>
<?php $this->yellow->page->setLastModified($pages->getModified()) ?>
<p><?php echo $page->getHtml("titleNavigation") ?></p>
<ul>

View file

@ -12,19 +12,19 @@ html, body, div, form, pre, span, tr, th, td, img {
font-family: "Open Sans";
font-style: normal;
font-weight: 300;
src: url(opensans-light.woff) format("woff");
src: url(stockholm-opensans-light.woff) format("woff");
}
@font-face {
font-family: "Open Sans";
font-style: normal;
font-weight: 400;
src: url(opensans-regular.woff) format("woff");
src: url(stockholm-opensans-regular.woff) format("woff");
}
@font-face {
font-family: "Open Sans";
font-style: normal;
font-weight: 700;
src: url(opensans-bold.woff) format("woff");
src: url(stockholm-opensans-bold.woff) format("woff");
}
body {
margin: 1em;