Updated API, spring remix

This commit is contained in:
markseu 2023-05-19 13:49:25 +02:00
parent ab67f1407b
commit aacd46c273
9 changed files with 87 additions and 83 deletions

View file

@ -2,7 +2,7 @@
// Core extension, https://github.com/annaesvensson/yellow-core
class YellowCore {
const VERSION = "0.8.113";
const VERSION = "0.8.114";
const RELEASE = "0.8.22";
public $content; // content files
public $media; // media files
@ -98,7 +98,7 @@ class YellowCore {
$statusCode = 0;
$this->toolbox->timerStart($time);
ob_start();
list($scheme, $address, $base, $location, $fileName) = $this->getRequestInformation();
list($scheme, $address, $base, $location, $fileName) = $this->lookup->getRequestInformation();
$this->page->setRequestInformation($scheme, $address, $base, $location, $fileName, true);
foreach ($this->extension->data as $key=>$value) {
if (method_exists($value["object"], "onRequest")) {
@ -253,7 +253,7 @@ class YellowCore {
public function command($line = "") {
$statusCode = 0;
$this->toolbox->timerStart($time);
list($command, $text) = $this->getCommandInformation($line);
list($command, $text) = $this->lookup->getCommandInformation($line);
foreach ($this->extension->data as $key=>$value) {
if (method_exists($value["object"], "onCommand")) {
$this->lookup->commandHandler = $key;
@ -310,42 +310,6 @@ class YellowCore {
return array_pad($this->lookup->layoutArguments, $sizeMin, null);
}
// Return troubleshooting URL
public function getTroubleshootingUrl() {
return "https://datenstrom.se/yellow/help/troubleshooting";
}
// Return request information
public function getRequestInformation($scheme = "", $address = "", $base = "") {
if (is_string_empty($scheme) && is_string_empty($address) && is_string_empty($base)) {
$url = $this->system->get("coreServerUrl");
if ($url=="auto" || $this->lookup->isCommandLine()) $url = $this->toolbox->detectServerUrl();
list($scheme, $address, $base) = $this->lookup->getUrlInformation($url);
$this->system->set("coreServerScheme", $scheme);
$this->system->set("coreServerAddress", $address);
$this->system->set("coreServerBase", $base);
if ($this->system->get("coreDebugMode")>=3) {
echo "YellowCore::getRequestInformation $scheme://$address$base<br/>\n";
}
}
$location = substru($this->toolbox->detectServerLocation(), strlenu($base));
$fileName = "";
if (is_string_empty($fileName)) $fileName = $this->lookup->findFileFromMediaLocation($location);
if (is_string_empty($fileName)) $fileName = $this->lookup->findFileFromContentLocation($location);
return array($scheme, $address, $base, $location, $fileName);
}
// Return command information
public function getCommandInformation($line = "") {
if (is_string_empty($line)) {
$line = $this->toolbox->getTextString(array_slice($this->toolbox->getServer("argv"), 1));
if ($this->system->get("coreDebugMode")>=3) {
echo "YellowCore::getCommandInformation $line<br/>\n";
}
}
return $this->toolbox->getTextList($line, " ", 2);
}
// Return command help
public function getCommandHelp() {
$data = array();
@ -363,14 +327,9 @@ class YellowCore {
return $data;
}
// Return request handler
public function getRequestHandler() {
return $this->lookup->requestHandler;
}
// Return command handler
public function getCommandHandler() {
return $this->lookup->commandHandler;
// Return troubleshooting URL
public function getTroubleshootingUrl() {
return "https://datenstrom.se/yellow/help/troubleshooting";
}
// TODO: remove later, for backwards compatibility
@ -448,7 +407,7 @@ class YellowContent {
$address = $this->yellow->page->address;
$base = $this->yellow->page->base;
$one = ($pages->offsetGet(0)->location!=$this->yellow->page->location) ? $pages->offsetGet(0) : $this->yellow->page;
preg_match_all("/<h(\d) id=\"([^\"]+)\">(.*?)<\/h\d>/i", $one->getContent(), $matches, PREG_SET_ORDER);
preg_match_all("/<h(\d) id=\"([^\"]+)\">(.*?)<\/h\d>/i", $one->getContentHtml(), $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
if ($match[1]==2) {
$page = new YellowPage($this->yellow);
@ -1657,6 +1616,47 @@ class YellowLookup {
return array($scheme, $address, $base);
}
// Return request information
public function getRequestInformation($scheme = "", $address = "", $base = "") {
if (is_string_empty($scheme) && is_string_empty($address) && is_string_empty($base)) {
$url = $this->yellow->system->get("coreServerUrl");
if ($url=="auto" || $this->isCommandLine()) $url = $this->yellow->toolbox->detectServerUrl();
list($scheme, $address, $base) = $this->getUrlInformation($url);
$this->yellow->system->set("coreServerScheme", $scheme);
$this->yellow->system->set("coreServerAddress", $address);
$this->yellow->system->set("coreServerBase", $base);
if ($this->yellow->system->get("coreDebugMode")>=3) {
echo "YellowLookup::getRequestInformation $scheme://$address$base<br/>\n";
}
}
$location = substru($this->yellow->toolbox->detectServerLocation(), strlenu($base));
$fileName = "";
if (is_string_empty($fileName)) $fileName = $this->findFileFromMediaLocation($location);
if (is_string_empty($fileName)) $fileName = $this->findFileFromContentLocation($location);
return array($scheme, $address, $base, $location, $fileName);
}
// Return command information
public function getCommandInformation($line = "") {
if (is_string_empty($line)) {
$line = $this->yellow->toolbox->getTextString(array_slice($this->yellow->toolbox->getServer("argv"), 1));
if ($this->yellow->system->get("coreDebugMode")>=3) {
echo "YellowLookup::getCommandInformation $line<br/>\n";
}
}
return $this->yellow->toolbox->getTextList($line, " ", 2);
}
// Return request handler
public function getRequestHandler() {
return $this->requestHandler;
}
// Return command handler
public function getCommandHandler() {
return $this->commandHandler;
}
// Return attributes from text
public function getTextAttributes($text, $attributesAllowEmptyString) {
$tokens = array();
@ -3063,7 +3063,7 @@ class YellowPage {
$value = $this->yellow->extension->data[$this->get("parser")];
if (method_exists($value["object"], "onParseContentRaw")) {
$this->parser = $value["object"];
$this->parserData = $this->getContent(true);
$this->parserData = $this->getContentRaw();
$this->parserData = $this->parser->onParseContentRaw($this, $this->parserData);
foreach ($this->yellow->extension->data as $key=>$value) {
if (method_exists($value["object"], "onParseContentHtml")) {
@ -3073,7 +3073,7 @@ class YellowPage {
}
}
} else {
$this->parserData = $this->getContent(true);
$this->parserData = $this->getContentRaw();
$this->parserData = preg_replace("/\[yellow error\]/i", $this->errorMessage, $this->parserData);
}
if (!$this->isExisting("description")) {
@ -3126,12 +3126,12 @@ class YellowPage {
if ($this->yellow->lookup->isNestedLocation($this->location, $this->fileName, true)) {
$this->error(500, "Folder '".dirname($this->fileName)."' may not contain subfolders!");
}
if ($this->yellow->getRequestHandler()=="core" && $this->isExisting("redirect") && $this->statusCode==200) {
if ($this->yellow->lookup->getRequestHandler()=="core" && $this->isExisting("redirect") && $this->statusCode==200) {
$location = $this->yellow->lookup->normaliseLocation($this->get("redirect"), $this->location);
$location = $this->yellow->lookup->normaliseUrl($this->scheme, $this->address, "", $location);
$this->status(301, $location);
}
if ($this->yellow->getRequestHandler()=="core" && !$this->isAvailable() && $this->statusCode==200) {
if ($this->yellow->lookup->getRequestHandler()=="core" && !$this->isAvailable() && $this->statusCode==200) {
$this->error(404);
}
if ($this->isExisting("pageClean")) $this->outputData = null;
@ -3237,20 +3237,20 @@ class YellowPage {
return htmlspecialchars($this->getDateFormatted($key, $format));
}
// Return page content data, raw format
public function getContentRaw() {
$this->parseMetaUpdate();
return substrb($this->rawData, $this->metaDataOffsetBytes);
}
// Return page content data, HTML encoded or raw format
public function getContent($rawFormat = false) {
if ($rawFormat) {
$this->parseMetaUpdate();
$text = substrb($this->rawData, $this->metaDataOffsetBytes);
} else {
$this->parseContent();
$text = $this->parserData;
}
return $text;
public function getContentHtml() {
$this->parseContent();
return $this->parserData;
}
// Return page extra data, HTML encoded
public function getExtra($name) {
public function getExtraHtml($name) {
$output = "";
foreach ($this->yellow->extension->data as $key=>$value) {
if (method_exists($value["object"], "onParsePageExtra")) {
@ -3492,6 +3492,10 @@ class YellowPage {
public function isPage($key) {
return isset($this->sharedPages[$key]);
}
// TODO: remove later, for backwards compatibility
public function getContent($rawFormat = false) { return $rawFormat ? $this->getContentRaw() : $this->getContentHtml(); }
public function getExtra($name) { return $this->getExtraHtml($name); }
}
class YellowPageCollection extends ArrayObject {

View file

@ -2,7 +2,7 @@
// Edit extension, https://github.com/annaesvensson/yellow-edit
class YellowEdit {
const VERSION = "0.8.74";
const VERSION = "0.8.75";
public $yellow; // access to API
public $response; // web response
public $merge; // text merge
@ -63,7 +63,7 @@ class YellowEdit {
$scheme = $this->yellow->system->get("coreServerScheme");
$address = $this->yellow->system->get("coreServerAddress");
$base = rtrim($this->yellow->system->get("coreServerBase").$this->yellow->system->get("editLocation"), "/");
list($scheme, $address, $base, $location, $fileName) = $this->yellow->getRequestInformation($scheme, $address, $base);
list($scheme, $address, $base, $location, $fileName) = $this->yellow->lookup->getRequestInformation($scheme, $address, $base);
$this->yellow->page->setRequestInformation($scheme, $address, $base, $location, $fileName, false);
$statusCode = $this->processRequest($scheme, $address, $base, $location, $fileName);
}
@ -1165,7 +1165,7 @@ class YellowEditResponse {
$class = "page-preview layout-".$page->get("layout");
$output = "<div class=\"".htmlspecialchars($class)."\"><div class=\"content\"><div class=\"main\">";
if ($this->yellow->system->get("editToolbarButtons")!="none") $output .= "<h1>".$page->getHtml("titleContent")."</h1>\n";
$output .= $page->getContent();
$output .= $page->getContentHtml();
$output .= "</div></div></div>";
$page->statusCode = 200;
$page->outputData = $output;

View file

@ -2,7 +2,7 @@
// Install extension, https://github.com/annaesvensson/yellow-install
class YellowInstall {
const VERSION = "0.8.88";
const VERSION = "0.8.89";
const PRIORITY = "1";
public $yellow; // access to API
@ -346,7 +346,7 @@ class YellowInstall {
$rewrite = true;
if (!$this->isServerBuiltin()) {
$curlHandle = curl_init();
list($scheme, $address, $base) = $this->yellow->getRequestInformation();
list($scheme, $address, $base) = $this->yellow->lookup->getRequestInformation();
$location = $this->yellow->system->get("coreThemeLocation").$this->yellow->lookup->normaliseName($this->yellow->system->get("theme")).".css";
$url = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
curl_setopt($curlHandle, CURLOPT_URL, $url);

View file

@ -2,7 +2,7 @@
// Meta extension, https://github.com/annaesvensson/yellow-meta
class YellowMeta {
const VERSION = "0.8.16";
const VERSION = "0.8.17";
public $yellow; // access to API
// Handle initialisation
@ -43,7 +43,7 @@ class YellowMeta {
if ($page->isExisting("image")) {
$name = $page->get("image");
$alt = $page->isExisting("imageAlt") ? $page->get("imageAlt") : $page->get("title");
} elseif (preg_match("/\[image(\s.*?)\]/", $page->getContent(true), $matches)) {
} elseif (preg_match("/\[image(\s.*?)\]/", $page->getContentRaw(), $matches)) {
list($name, $alt) = $this->yellow->toolbox->getTextArguments(trim($matches[1]));
if (is_string_empty($alt)) $alt = $page->get("title");
} else {

View file

@ -1,11 +1,11 @@
# Datenstrom Yellow update settings
Extension: Core
Version: 0.8.113
Version: 0.8.114
Description: Core functionality of the website.
DocumentationUrl: https://github.com/annaesvensson/yellow-core
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/core.zip
Published: 2023-05-18 17:55:38
Published: 2023-05-19 13:37:00
Developer: Mark Seuffert, David Fehrmann
Tag: feature
system/extensions/core.php: core.php, create, update
@ -17,11 +17,11 @@ system/layouts/navigation.html: navigation.html, create, update, careful
system/layouts/pagination.html: pagination.html, create, update, careful
Extension: Edit
Version: 0.8.74
Version: 0.8.75
Description: Edit your website in a web browser.
DocumentationUrl: https://github.com/annaesvensson/yellow-edit
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/edit.zip
Published: 2023-05-18 18:03:30
Published: 2023-05-19 00:50:31
Developer: Anna Svensson
Tag: feature
system/extensions/edit.php: edit.php, create, update
@ -44,11 +44,11 @@ media/images/photo.jpg: photo.jpg, create, optional
media/thumbnails/photo-100x40.jpg: photo-100x40.jpg, create, optional
Extension: Install
Version: 0.8.88
Version: 0.8.89
Description: Install a brand new, shiny website.
DocumentationUrl: https://github.com/annaesvensson/yellow-install
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/install.zip
Published: 2023-04-16 23:55:50
Published: 2023-05-19 13:29:22
Developer: Anna Svensson
Status: unlisted
system/extensions/install.php: install.php, create
@ -76,11 +76,11 @@ Tag: feature
system/extensions/markdown.php: markdown.php, create, update
Extension: Meta
Version: 0.8.16
Version: 0.8.17
Description: Meta data for humans and machines.
DocumentationUrl: https://github.com/annaesvensson/yellow-meta
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/meta.zip
Published: 2022-11-03 18:23:11
Published: 2023-05-19 00:58:40
Developer: Anna Svensson, Steffen Schultz
Tag: feature
system/extensions/meta.php: meta.php, create, update

View file

@ -2,7 +2,7 @@
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php echo $this->yellow->page->getContent() ?>
<?php echo $this->yellow->page->getContentHtml() ?>
</div>
</div>
<?php $this->yellow->layout("footer") ?>

View file

@ -2,7 +2,7 @@
<div class="content">
<div class="main" role="main">
<h1><?php echo $this->yellow->page->getHtml("titleContent") ?></h1>
<?php echo $this->yellow->page->getContent() ?>
<?php echo $this->yellow->page->getContentHtml() ?>
</div>
</div>
<?php $this->yellow->layout("footer") ?>

View file

@ -1,10 +1,10 @@
<div class="footer" role="contentinfo">
<div class="siteinfo">
<?php echo $this->yellow->page->getPage("footer")->getContent() ?>
<?php echo $this->yellow->page->getPage("footer")->getContentHtml() ?>
</div>
<div class="siteinfo-banner"></div>
</div>
</div>
<?php echo $this->yellow->page->getExtra("footer") ?>
<?php echo $this->yellow->page->getExtraHtml("footer") ?>
</body>
</html>

View file

@ -7,14 +7,14 @@
<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 echo $this->yellow->page->getExtra("header") ?>
<?php echo $this->yellow->page->getExtraHtml("header") ?>
</head>
<body>
<div class="<?php echo "page layout-".$this->yellow->page->getHtml("layout") ?>">
<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 echo $this->yellow->page->getPage("header")->getContent() ?>
<?php echo $this->yellow->page->getPage("header")->getContentHtml() ?>
</div>
<div class="sitename-banner"></div>
<?php $this->yellow->layout("navigation") ?>