commit b98d95d10d2d7a5db3ee1274fc175c8e78f2f661
parent af18f6da413605ca863c8734e47dd609888deccc
Author: markseu <mark2011@mayberg.se>
Date: Sun, 16 Aug 2020 12:20:21 +0200
Updated layout files, new format for shared pages
Diffstat:
6 files changed, 50 insertions(+), 174 deletions(-)
diff --git a/system/extensions/core.php b/system/extensions/core.php
@@ -2,7 +2,7 @@
// Core extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/core
class YellowCore {
- const VERSION = "0.8.19";
+ const VERSION = "0.8.20";
const RELEASE = "0.8.15";
public $page; // current page
public $content; // content files
@@ -424,8 +424,8 @@ class YellowPage {
public $rawData; // raw data of page
public $metaDataOffsetBytes; // meta data offset
public $metaData; // meta data
- public $pageCollection; // page collection
- public $pageRelations; // page relations
+ public $pageCollections; // additional pages
+ public $sharedPages; // shared pages
public $headerData; // response header
public $outputData; // response output
public $parser; // content parser
@@ -440,8 +440,8 @@ class YellowPage {
public function __construct($yellow) {
$this->yellow = $yellow;
$this->metaData = new YellowArray();
- $this->pageCollection = new YellowPageCollection($yellow);
- $this->pageRelations = array();
+ $this->pageCollections = array();
+ $this->sharedPages = array();
$this->headerData = array();
}
@@ -502,6 +502,7 @@ class YellowPage {
$this->yellow->system->get("coreServerAddress"),
$this->yellow->system->get("coreServerBase"),
rtrim($this->yellow->system->get("editLocation"), "/").$this->location));
+ $this->setPage("main", $this);
} else {
$this->set("type", $this->yellow->toolbox->getFileType($this->fileName));
$this->set("group", $this->yellow->toolbox->getFileGroup($this->fileName, $this->yellow->system->get("coreMediaDirectory")));
@@ -534,7 +535,7 @@ class YellowPage {
// Parse page content on demand
public function parseContent($sizeMax = 0) {
- if (!is_object($this->parser)) {
+ if (!is_null($this->rawData) && !is_object($this->parser)) {
if ($this->yellow->extension->isExisting($this->get("parser"))) {
$value = $this->yellow->extension->data[$this->get("parser")];
if (method_exists($value["object"], "onParseContentRaw")) {
@@ -642,6 +643,10 @@ class YellowPage {
// Parse page layout
public function parsePageLayout($name) {
+ foreach ($this->yellow->content->getShared($this->location) as $page) {
+ $this->sharedPages[basename($page->location)] = $page;
+ $page->sharedPages["main"] = $this;
+ }
$this->outputData = null;
foreach ($this->yellow->extension->data as $key=>$value) {
if (method_exists($value["object"], "onParsePageLayout")) {
@@ -774,23 +779,23 @@ class YellowPage {
}
// Set page collection with additional pages
- public function setPages($pages) {
- $this->pageCollection = $pages;
+ public function setPages($key, $pages) {
+ $this->pageCollections[$key] = $pages;
}
// Return page collection with additional pages
- public function getPages() {
- return $this->pageCollection;
+ public function getPages($key) {
+ return isset($this->pageCollections[$key]) ? $this->pageCollections[$key] : new YellowPageCollection($this->yellow);
}
- // Set related page
+ // Set shared page
public function setPage($key, $page) {
- $this->pageRelations[$key] = $page;
+ $this->sharedPages[$key] = $page;
}
- // Return related page
+ // Return shared page
public function getPage($key) {
- return isset($this->pageRelations[$key]) ? $this->pageRelations[$key] : $this;
+ return isset($this->sharedPages[$key]) ? $this->sharedPages[$key] : new YellowPage($this->yellow);
}
// Return page URL
@@ -883,9 +888,10 @@ class YellowPage {
// Return last modification date, Unix time or HTTP format
public function getLastModified($httpFormat = false) {
- $lastModified = max($this->lastModified, $this->getModified(), $this->pageCollection->getModified(),
- $this->yellow->system->getModified(), $this->yellow->language->getModified(), $this->yellow->extension->getModified());
- foreach ($this->pageRelations as $page) $lastModified = max($lastModified, $page->getModified());
+ $lastModified = max($this->lastModified, $this->getModified(), $this->yellow->system->getModified(),
+ $this->yellow->language->getModified(), $this->yellow->extension->getModified());
+ foreach ($this->pageCollections as $pages) $lastModified = max($lastModified, $pages->getModified());
+ foreach ($this->sharedPages as $page) $lastModified = max($lastModified, $page->getModified());
return $httpFormat ? $this->yellow->toolbox->getHttpDateFormatted($lastModified) : $lastModified;
}
@@ -961,9 +967,9 @@ class YellowPage {
return isset($this->headerData[$key]);
}
- // Check if related page exists
+ // Check if shared page exists
public function isPage($key) {
- return isset($this->pageRelations[$key]);
+ return isset($this->sharedPages[$key]);
}
}
@@ -1320,18 +1326,6 @@ class YellowContent {
return $pages;
}
- // Return page with shared content, null if not found
- public function shared($name) {
- $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("coreContentSharedDirectory").$name;
- $page = $this->find($location);
- }
- if ($page) $page->setPage("main", $this->yellow->page);
- return $page;
- }
-
// Return page collection that's empty
public function clean() {
return new YellowPageCollection($this->yellow);
@@ -1372,6 +1366,16 @@ class YellowContent {
return $pages;
}
+ // Return shared pages
+ public function getShared($location) {
+ $pages = new YellowPageCollection($this->yellow);
+ $location = $this->getHomeLocation($location).$this->yellow->system->get("coreContentSharedDirectory");
+ foreach ($this->scanLocation($location) as $page) {
+ if ($page->get("status")=="shared") $pages->append($page);
+ }
+ return $pages;
+ }
+
// Return root location
public function getRootLocation($location) {
$rootLocation = "root/";
@@ -1409,6 +1413,9 @@ class YellowContent {
if (empty($parentTopLocation)) $parentTopLocation = "$token/";
return $parentTopLocation;
}
+
+ // TODO: remove later, for backwards compatibility
+ public function shared($name) { return null; }
}
class YellowMedia {
diff --git a/system/extensions/install-blog.zip b/system/extensions/install-blog.zip
Binary files differ.
diff --git a/system/extensions/install-wiki.zip b/system/extensions/install-wiki.zip
Binary files differ.
diff --git a/system/extensions/update.php b/system/extensions/update.php
@@ -2,7 +2,7 @@
// Update extension, https://github.com/datenstrom/yellow-extensions/tree/master/source/update
class YellowUpdate {
- const VERSION = "0.8.31";
+ const VERSION = "0.8.33";
const PRIORITY = "2";
public $yellow; // access to API
public $updates; // number of updates
@@ -54,144 +54,15 @@ class YellowUpdate {
// Handle update
public function onUpdate($action) {
- if ($action=="update") { // TODO: remove later, converts old content settings
- if ($this->yellow->system->isExisting("multiLanguageMode")) {
- $coreMultiLanguageMode = $this->yellow->system->get("multiLanguageMode");
- $fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreSystemFile");
- if (!$this->yellow->system->save($fileName, array("coreMultiLanguageMode" => $coreMultiLanguageMode))) {
- $this->yellow->log("error", "Can't write file '$fileName'!");
- }
- $path = $this->yellow->system->get("coreContentDirectory");
- foreach ($this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/^.*\.md$/", true, false) as $entry) {
- $fileData = $fileDataNew = $this->yellow->toolbox->readFile($entry);
- $fileStatusUnlisted = false;
- $tokens = explode("/", substru($entry, strlenu($path)));
- for ($i=0; $i<count($tokens)-1; ++$i) {
- if (!preg_match("/^[\d\-\_\.]+(.*)$/", $tokens[$i]) && $tokens[$i]!="shared") {
- $fileStatusUnlisted = true;
- break;
- }
- }
- $fileDataNew = preg_replace("/Status: hidden/i", "Status: shared", $fileDataNew);
- $fileDataNew = preg_replace("/Status: ignore/i", "Build: exclude", $fileDataNew);
- if ($fileStatusUnlisted && empty($this->yellow->toolbox->getMetaData($fileDataNew, "status"))) {
- $fileDataNew = $this->yellow->toolbox->setMetaData($fileDataNew, "status", "unlisted");
- }
- if ($fileData!=$fileDataNew) {
- $modified = $this->yellow->toolbox->getFileModified($entry);
- if (!$this->yellow->toolbox->deleteFile($entry) ||
- !$this->yellow->toolbox->createFile($entry, $fileDataNew) ||
- !$this->yellow->toolbox->modifyFile($entry, $modified)) {
- $this->yellow->log("error", "Can't write file '$entry'!");
- }
- }
- }
- }
- }
- if ($action=="update") { // TODO: remove later, converts old language settings
- if ($this->yellow->system->isExisting("coreTextFile")) {
- $fileNameSource = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreTextFile");
- $fileNameDestination = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreLanguageFile");
- if (is_file($fileNameSource) && !is_file($fileNameDestination)) {
- if (!$this->yellow->toolbox->renameFile($fileNameSource, $fileNameDestination)) {
- $this->yellow->log("error", "Can't write file '$fileNameDestination'!");
- }
- }
- $imageDirectoryLength = strlenu($this->yellow->system->get("coreImageDirectory"));
- $fileData = $this->yellow->toolbox->readFile($fileNameDestination);
- $fileDataNew = "";
- foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
- if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (strposu($matches[1], ".") &&
- substru($matches[1], 0, $imageDirectoryLength)!=$this->yellow->system->get("coreImageDirectory")) {
- $line = $this->yellow->system->get("coreImageDirectory").$line;
- }
- }
- $fileDataNew .= $line;
- }
- if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($fileNameDestination, $fileDataNew)) {
- $this->yellow->log("error", "Can't write file '$fileNameDestination'!");
- }
- $path = $this->yellow->system->get("coreExtensionDirectory");
- foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*-language\.txt/", false, false) as $entry) {
- $entryShort = str_replace("-language.txt", ".txt", $entry);
- if (is_file($entryShort) && !$this->yellow->toolbox->deleteFile($entry, $this->yellow->system->get("coreTrashDirectory"))) {
- $this->yellow->log("error", "Can't delete file '$entry'!");
- }
- }
- }
- }
if ($action=="update") { // TODO: remove later, converts old layout files
- if ($this->yellow->system->isExisting("coreLayoutDir")) {
- $path = $this->yellow->system->get("coreLayoutDir");
- foreach ($this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/^.*\.html$/", true, false) as $entry) {
- $fileData = $fileDataNew = $this->yellow->toolbox->readFile($entry);
- $fileDataNew = str_replace("yellow->getLayoutArgs", "yellow->getLayoutArguments", $fileDataNew);
- $fileDataNew = str_replace("toolbox->getLocationArgs", "toolbox->getLocationArguments", $fileDataNew);
- $fileDataNew = str_replace("toolbox->getTextArgs", "toolbox->getTextArguments", $fileDataNew);
- $fileDataNew = str_replace("toolbox->normaliseArgs", "toolbox->normaliseArguments", $fileDataNew);
- $fileDataNew = str_replace("toolbox->isLocationArgs", "toolbox->isLocationArguments", $fileDataNew);
- $fileDataNew = str_replace("text->getHtml", "language->getTextHtml", $fileDataNew);
- $fileDataNew = str_replace("\$this->yellow->page->get(\"navigation\")", "\"navigation\"", $fileDataNew);
- $fileDataNew = str_replace("\$this->yellow->page->get(\"header\")", "\"header\"", $fileDataNew);
- $fileDataNew = str_replace("\$this->yellow->page->get(\"sidebar\")", "\"sidebar\"", $fileDataNew);
- $fileDataNew = str_replace("\$this->yellow->page->get(\"footer\")", "\"footer\"", $fileDataNew);
- $fileDataNew = str_replace("<link rel=\"icon\" type=\"image/png\" href=\"<?php echo \$resourceLocation.\$this->yellow->page->getHtml(\"theme\").\"-icon.png\" ?>\" />", "<?php /* Add icons and files here */ ?>", $fileDataNew);
- if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($entry, $fileDataNew)) {
- $this->yellow->log("error", "Can't write file '$entry'!");
- }
- }
- }
- }
- if ($action=="update") { // TODO: remove later, converts old resource files
- if ($this->yellow->system->isExisting("coreResourceDir")) {
- $pathSource = "system/resources/";
- $pathDestination = $this->yellow->system->get("coreThemeDirectory");
- if (is_dir($pathSource) && !is_dir($pathDestination)) {
- if (!$this->yellow->toolbox->renameDirectory($pathSource, $pathDestination)) {
- $this->yellow->log("error", "Can't write directory '$pathDestination'!");
- }
- }
- if (is_dir($pathSource) && is_dir($pathDestination)) {
- foreach ($this->yellow->toolbox->getDirectoryEntries($pathSource, "/.*/", true, false, false) as $entry) {
- $entrySource = $pathSource.$entry;
- $entryDestination = $pathDestination.$entry;
- $dataSource = $this->yellow->toolbox->readFile($entrySource);
- $dataDestination = $this->yellow->toolbox->readFile($entryDestination);
- if ($dataSource!=$dataDestination && !$this->yellow->toolbox->copyFile($entrySource, $entryDestination)) {
- $this->yellow->log("error", "Can't write file '$entryDestination'!");
- }
- }
- if (!$this->yellow->toolbox->deleteDirectory($pathSource, $this->yellow->system->get("coreTrashDirectory"))) {
- $this->yellow->log("error", "Can't delete directory '$pathSource'!");
- }
- }
- foreach ($this->yellow->toolbox->getDirectoryEntries($pathDestination, "/^.*\-icon\.png$/", true, false) as $entry) {
- $entryShort = str_replace("-icon.png", ".png", $entry);
- if (!is_file($entryShort) && !$this->yellow->toolbox->copyFile($entry, $entryShort)) {
- $this->yellow->log("error", "Can't write file '$entryShort'!");
- }
- }
- foreach ($this->yellow->toolbox->getDirectoryEntries($pathDestination, "/bundle-.*/", true, false) as $entry) {
- if (!$this->yellow->toolbox->deleteFile($entry)) {
- $this->yellow->log("error", "Can't delete file '$entry'!");
- }
- }
- }
- if ($this->yellow->system->get("metaDefaultImage")=="icon") {
- $fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreSystemFile");
- if (!$this->yellow->system->save($fileName, array("metaDefaultImage" => "favicon"))) {
- $this->yellow->log("error", "Can't write file '$fileName'!");
- }
- }
- }
- if ($action=="update") { // TODO: remove later, converts old commandline
- if ($this->yellow->system->isExisting("coreStaticDir")) {
- $fileName = "yellow.php";
- $fileData = $fileDataNew = $this->yellow->toolbox->readFile($fileName);
- $fileDataNew = str_replace("command(\$argv[1], \$argv[2], \$argv[3], \$argv[4], \$argv[5], \$argv[6], \$argv[7])", "command()", $fileDataNew);
- if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($fileName, $fileDataNew)) {
- $this->yellow->log("error", "Can't write file '$fileName'!");
+ $path = $this->yellow->system->get("coreLayoutDirectory");
+ foreach ($this->yellow->toolbox->getDirectoryEntriesRecursive($path, "/^.*\.html$/", true, false) as $entry) {
+ $fileData = $fileDataNew = $this->yellow->toolbox->readFile($entry);
+ $fileDataNew = str_replace("\$this->yellow->content->shared(\"header\")", "null", $fileDataNew);
+ $fileDataNew = str_replace("\$this->yellow->content->shared(\"footer\")", "null", $fileDataNew);
+ $fileDataNew = str_replace("php if (\$page = null)", "php /* Remove this line */ if (\$page = null)", $fileDataNew);
+ if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($entry, $fileDataNew)) {
+ $this->yellow->log("error", "Can't write file '$entry'!");
}
}
}
@@ -527,7 +398,7 @@ class YellowUpdate {
if ($statusCode==200) {
foreach ($this->getExtensionFileNames($settings) as $fileName) {
list($entry, $flags) = $this->yellow->toolbox->getTextList($settings[$fileName], ",", 2);
- if (strposu($entry, ".")===false) {
+ if (strposu($entry, ".")===false) { // TODO: remove later, converts old extension settings
list($dummy, $entry, $flags) = $this->yellow->toolbox->getTextList($settings[$fileName], ",", 3);
}
if (!$this->yellow->lookup->isContentFile($fileName)) {
diff --git a/system/layouts/footer.html b/system/layouts/footer.html
@@ -1,7 +1,6 @@
<div class="footer" role="contentinfo">
<div class="siteinfo">
-<?php if ($page = $this->yellow->content->shared("footer")) $this->yellow->page->setPage("footer", $page) ?>
-<?php if ($this->yellow->page->isPage("footer")) echo $this->yellow->page->getPage("footer")->getContent() ?>
+<?php echo $this->yellow->page->getPage("footer")->getContent() ?>
</div>
<div class="siteinfo-banner"></div>
</div>
diff --git a/system/layouts/header.html b/system/layouts/header.html
@@ -14,8 +14,7 @@
<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>
-<?php if ($page = $this->yellow->content->shared("header")) $this->yellow->page->setPage("header", $page) ?>
-<?php if ($this->yellow->page->isPage("header")) echo $this->yellow->page->getPage("header")->getContent() ?>
+<?php echo $this->yellow->page->getPage("header")->getContent() ?>
</div>
<div class="sitename-banner"></div>
<?php $this->yellow->layout("navigation") ?>