commit 248b44405034691a8a4f004bce84d2348c65539c
parent 55ccd83426824a2d3cfe99e41466c59fae5df2c4
Author: Szymon Mikulicz <szymon.mikulicz@posteo.net>
Date: Thu, 25 Jun 2020 23:00:26 +0200
Merge branch 'master' of https://github.com/datenstrom/yellow
Diffstat:
12 files changed, 561 insertions(+), 528 deletions(-)
diff --git a/system/extensions/bundle.php b/system/extensions/bundle.php
@@ -4,7 +4,7 @@
// This file may be used and distributed under the terms of the public license.
class YellowBundle {
- const VERSION = "0.8.11";
+ const VERSION = "0.8.12";
const TYPE = "feature";
public $yellow; //access to API
@@ -23,21 +23,19 @@ class YellowBundle {
}
// Handle command
- public function onCommand($args) {
- list($command) = $args;
+ public function onCommand($command, $text) {
switch ($command) {
- case "clean": $statusCode = $this->processCommandClean($args); break;
+ case "clean": $statusCode = $this->processCommandClean($command, $text); break;
default: $statusCode = 0;
}
return $statusCode;
}
// Process command to clean bundles
- public function processCommandClean($args) {
+ public function processCommandClean($command, $text) {
$statusCode = 0;
- list($command, $path) = $args;
- if ($path=="all") {
- $path = $this->yellow->system->get("coreResourceDir");
+ if ($command=="clean" && $text=="all") {
+ $path = $this->yellow->system->get("coreResourceDirectory");
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/bundle-.*/", false, false) as $entry) {
if (!$this->yellow->toolbox->deleteFile($entry)) $statusCode = 500;
}
@@ -100,7 +98,7 @@ class YellowBundle {
if (!empty($fileNames)) {
$autoVersioning = intval($modified/(60*60*24));
$id = substru(md5($autoVersioning.$base.implode($fileNames)), 0, 10);
- $fileNameBundle = $this->yellow->system->get("coreResourceDir")."bundle-$id.min.$type";
+ $fileNameBundle = $this->yellow->system->get("coreResourceDirectory")."bundle-$id.min.$type";
$locationBundle = $base.$this->yellow->system->get("coreResourceLocation")."bundle-$id.min.$type";
$rawDataAttribute = $attribute=="defer" ? "defer=\"defer\" " : "";
if ($type=="css") {
@@ -133,8 +131,8 @@ class YellowBundle {
// Process bundle, convert URLs
public function processBundleConvert($scheme, $address, $base, $fileData, $fileName, $type) {
if ($type=="css") {
- $extensionDirLength = strlenu($this->yellow->system->get("coreExtensionDir"));
- if (substru($fileName, 0, $extensionDirLength) == $this->yellow->system->get("coreExtensionDir")) {
+ $extensionDirectoryLength = strlenu($this->yellow->system->get("coreExtensionDirectory"));
+ if (substru($fileName, 0, $extensionDirectoryLength) == $this->yellow->system->get("coreExtensionDirectory")) {
$base .= $this->yellow->system->get("coreExtensionLocation");
} else {
$base .= $this->yellow->system->get("coreResourceLocation");
diff --git a/system/extensions/command.php b/system/extensions/command.php
@@ -4,15 +4,15 @@
// This file may be used and distributed under the terms of the public license.
class YellowCommand {
- const VERSION = "0.8.14";
+ const VERSION = "0.8.15";
const TYPE = "feature";
const PRIORITY = "3";
- public $yellow; //access to API
- public $files; //number of files
- public $links; //number of links
- public $errors; //number of errors
- public $locationsArgs; //locations with location arguments detected
- public $locationsArgsPagination; //locations with pagination arguments detected
+ public $yellow; //access to API
+ public $files; //number of files
+ public $links; //number of links
+ public $errors; //number of errors
+ public $locationsArguments; //locations with location arguments detected
+ public $locationsArgumentsPagination; //locations with pagination arguments detected
// Handle initialisation
public function onLoad($yellow) {
@@ -20,15 +20,14 @@ class YellowCommand {
}
// Handle command
- public function onCommand($args) {
- list($command) = $args;
+ public function onCommand($command, $text) {
switch ($command) {
case "": $statusCode = $this->processCommandHelp(); break;
- case "about": $statusCode = $this->processCommandAbout($args); break;
- case "build": $statusCode = $this->processCommandBuild($args); break;
- case "check": $statusCode = $this->processCommandCheck($args); break;
- case "clean": $statusCode = $this->processCommandClean($args); break;
- case "serve": $statusCode = $this->processCommandServe($args); break;
+ case "about": $statusCode = $this->processCommandAbout($command, $text); break;
+ case "build": $statusCode = $this->processCommandBuild($command, $text); break;
+ case "check": $statusCode = $this->processCommandCheck($command, $text); break;
+ case "clean": $statusCode = $this->processCommandClean($command, $text); break;
+ case "serve": $statusCode = $this->processCommandServe($command, $text); break;
default: $statusCode = 0;
}
return $statusCode;
@@ -55,7 +54,7 @@ class YellowCommand {
}
// Process command to show website version and updates
- public function processCommandAbout($args) {
+ public function processCommandAbout($command, $text) {
echo "Datenstrom Yellow ".YellowCore::VERSION."\n";
list($statusCode, $dataCurrent) = $this->getExtensionsVersion();
list($statusCode, $dataLatest) = $this->getExtensionsVersion(true);
@@ -71,17 +70,17 @@ class YellowCommand {
}
// Process command to build static website
- public function processCommandBuild($args) {
+ public function processCommandBuild($command, $text) {
$statusCode = 0;
- list($command, $path, $location) = $args;
- if (empty($location) || $location[0]=="/") {
+ list($path, $location) = $this->yellow->toolbox->getTextArguments($text);
+ if (empty($location) || substru($location, 0, 1)=="/") {
if ($this->checkStaticSettings()) {
$statusCode = $this->buildStaticFiles($path, $location);
} else {
$statusCode = 500;
$this->files = 0;
$this->errors = 1;
- $fileName = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("coreSystemFile");
+ $fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreSystemFile");
echo "ERROR building files: Please configure CoreStaticUrl in file '$fileName'!\n";
}
echo "Yellow $command: $this->files file".($this->files!=1 ? "s" : "");
@@ -95,9 +94,9 @@ class YellowCommand {
// Build static files
public function buildStaticFiles($path, $locationFilter) {
- $path = rtrim(empty($path) ? $this->yellow->system->get("coreStaticDir") : $path, "/");
+ $path = rtrim(empty($path) ? $this->yellow->system->get("coreStaticDirectory") : $path, "/");
$this->files = $this->errors = 0;
- $this->locationsArgs = $this->locationsArgsPagination = array();
+ $this->locationsArguments = $this->locationsArgumentsPagination = array();
$statusCode = empty($locationFilter) ? $this->cleanStaticFiles($path, $locationFilter) : 200;
$staticUrl = $this->yellow->system->get("coreStaticUrl");
list($scheme, $address, $base) = $this->yellow->lookup->getUrlInformation($staticUrl);
@@ -108,16 +107,16 @@ class YellowCommand {
if (!preg_match("#^$base$locationFilter#", "$base$location")) continue;
$statusCode = max($statusCode, $this->buildStaticFile($path, $location, true));
}
- foreach ($this->locationsArgs as $location) {
+ foreach ($this->locationsArguments as $location) {
echo "\rBuilding static website ".$this->getProgressPercent($this->files, $filesEstimated, 5, 60)."%... ";
if (!preg_match("#^$base$locationFilter#", "$base$location")) continue;
$statusCode = max($statusCode, $this->buildStaticFile($path, $location, true));
}
- $filesEstimated = $this->files + count($this->locationsArgs) + count($this->locationsArgsPagination);
- foreach ($this->locationsArgsPagination as $location) {
+ $filesEstimated = $this->files + count($this->locationsArguments) + count($this->locationsArgumentsPagination);
+ foreach ($this->locationsArgumentsPagination as $location) {
echo "\rBuilding static website ".$this->getProgressPercent($this->files, $filesEstimated, 5, 95)."%... ";
if (!preg_match("#^$base$locationFilter#", "$base$location")) continue;
- if (substru($location, -1)!=$this->yellow->toolbox->getLocationArgsSeparator()) {
+ if (substru($location, -1)!=$this->yellow->toolbox->getLocationArgumentsSeparator()) {
$statusCode = max($statusCode, $this->buildStaticFile($path, $location, false, true));
}
for ($pageNumber=2; $pageNumber<=999; ++$pageNumber) {
@@ -237,17 +236,17 @@ class YellowCommand {
}
if (substru($location, 0, strlenu($base))!=$base) continue;
$location = substru($location, strlenu($base));
- if (!$this->yellow->toolbox->isLocationArgs($location)) continue;
- if (!$this->yellow->toolbox->isLocationArgsPagination($location)) {
+ if (!$this->yellow->toolbox->isLocationArguments($location)) continue;
+ if (!$this->yellow->toolbox->isLocationArgumentsPagination($location)) {
$location = rtrim($location, "/")."/";
- if (!isset($this->locationsArgs[$location])) {
- $this->locationsArgs[$location] = $location;
+ if (!isset($this->locationsArguments[$location])) {
+ $this->locationsArguments[$location] = $location;
if (defined("DEBUG") && DEBUG>=2) echo "YellowCommand::analyseLocations detected location:$location<br/>\n";
}
} else {
$location = rtrim($location, "0..9");
- if (!isset($this->locationsArgsPagination[$location])) {
- $this->locationsArgsPagination[$location] = $location;
+ if (!isset($this->locationsArgumentsPagination[$location])) {
+ $this->locationsArgumentsPagination[$location] = $location;
if (defined("DEBUG") && DEBUG>=2) echo "YellowCommand::analyseLocations detected location:$location<br/>\n";
}
}
@@ -255,17 +254,17 @@ class YellowCommand {
}
// Process command to check static files for broken links
- public function processCommandCheck($args) {
+ public function processCommandCheck($command, $text) {
$statusCode = 0;
- list($command, $path, $location) = $args;
- if (empty($location) || $location[0]=="/") {
+ list($path, $location) = $this->yellow->toolbox->getTextArguments($text);
+ if (empty($location) || substru($location, 0, 1)=="/") {
if ($this->checkStaticSettings()) {
$statusCode = $this->checkStaticFiles($path, $location);
} else {
$statusCode = 500;
$this->links = 0;
$this->errors = 1;
- $fileName = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("coreSystemFile");
+ $fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreSystemFile");
echo "ERROR checking files: Please configure CoreStaticUrl in file '$fileName'!\n";
}
echo "Yellow $command: $this->links link".($this->links!=1 ? "s" : "");
@@ -279,7 +278,7 @@ class YellowCommand {
// Check static files for broken links
public function checkStaticFiles($path, $locationFilter) {
- $path = rtrim(empty($path) ? $this->yellow->system->get("coreStaticDir") : $path, "/");
+ $path = rtrim(empty($path) ? $this->yellow->system->get("coreStaticDirectory") : $path, "/");
$this->links = $this->errors = 0;
$regex = "/^[^.]+$|".$this->yellow->system->get("coreStaticDefaultFile")."$/";
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($path, $regex, false, false);
@@ -402,10 +401,10 @@ class YellowCommand {
}
// Process command to clean static files
- public function processCommandClean($args) {
+ public function processCommandClean($command, $text) {
$statusCode = 0;
- list($command, $path, $location) = $args;
- if (empty($location) || $location[0]=="/") {
+ list($path, $location) = $this->yellow->toolbox->getTextArguments($text);
+ if (empty($location) || substru($location, 0, 1)=="/") {
$statusCode = $this->cleanStaticFiles($path, $location);
echo "Yellow $command: Static file".(empty($location) ? "s" : "")." ".($statusCode!=200 ? "not " : "")."cleaned\n";
} else {
@@ -418,7 +417,7 @@ class YellowCommand {
// Clean static files and directories
public function cleanStaticFiles($path, $location) {
$statusCode = 200;
- $path = rtrim(empty($path) ? $this->yellow->system->get("coreStaticDir") : $path, "/");
+ $path = rtrim(empty($path) ? $this->yellow->system->get("coreStaticDirectory") : $path, "/");
if (empty($location)) {
$statusCode = max($statusCode, $this->broadcastCommand("clean", "all"));
$statusCode = max($statusCode, $this->cleanStaticDirectory($path));
@@ -458,20 +457,20 @@ class YellowCommand {
}
// Broadcast command to other extensions
- public function broadcastCommand($args) {
+ public function broadcastCommand($command, $text) {
$statusCode = 0;
foreach ($this->yellow->extensions->extensions as $key=>$value) {
if (method_exists($value["obj"], "onCommand") && $key!="command") {
- $statusCode = max($statusCode, $value["obj"]->onCommand(func_get_args()));
+ $statusCode = max($statusCode, $value["obj"]->onCommand($command, $text));
}
}
return $statusCode;
}
// Process command to start built-in web server
- public function processCommandServe($args) {
- list($command, $path, $url) = $args;
- if (empty($path) && is_dir($this->yellow->system->get("coreStaticDir"))) $path = $this->yellow->system->get("coreStaticDir");
+ public function processCommandServe($command, $text) {
+ list($path, $url) = $this->yellow->toolbox->getTextArguments($text);
+ if (empty($path) && is_dir($this->yellow->system->get("coreStaticDirectory"))) $path = $this->yellow->system->get("coreStaticDirectory");
if (empty($url)) $url = "http://localhost:8000";
list($scheme, $address, $base) = $this->yellow->lookup->getUrlInformation($url);
if ($scheme=="http" && !empty($address)) {
@@ -501,8 +500,8 @@ class YellowCommand {
public function checkStaticDirectory($path) {
$ok = false;
if (!empty($path)) {
- if ($path==rtrim($this->yellow->system->get("coreStaticDir"), "/")) $ok = true;
- if ($path==rtrim($this->yellow->system->get("coreTrashDir"), "/")) $ok = true;
+ if ($path==rtrim($this->yellow->system->get("coreStaticDirectory"), "/")) $ok = true;
+ if ($path==rtrim($this->yellow->system->get("coreTrashDirectory"), "/")) $ok = true;
if (is_file("$path/".$this->yellow->system->get("coreStaticDefaultFile"))) $ok = true;
if (is_file("$path/yellow.php")) $ok = false;
}
@@ -597,7 +596,7 @@ class YellowCommand {
// Return media locations
public function getMediaLocations() {
$locations = array();
- $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($this->yellow->system->get("coreMediaDir"), "/.*/", false, false);
+ $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($this->yellow->system->get("coreMediaDirectory"), "/.*/", false, false);
foreach ($fileNames as $fileName) {
array_push($locations, "/".$fileName);
}
@@ -608,15 +607,15 @@ class YellowCommand {
public function getSystemLocations() {
$locations = array();
$regex = "/\.(css|gif|ico|js|jpg|png|svg|txt|woff|woff2)$/";
- $extensionDirLength = strlenu($this->yellow->system->get("coreExtensionDir"));
- $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($this->yellow->system->get("coreExtensionDir"), $regex, false, false);
+ $extensionDirectoryLength = strlenu($this->yellow->system->get("coreExtensionDirectory"));
+ $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($this->yellow->system->get("coreExtensionDirectory"), $regex, false, false);
foreach ($fileNames as $fileName) {
- array_push($locations, $this->yellow->system->get("coreExtensionLocation").substru($fileName, $extensionDirLength));
+ array_push($locations, $this->yellow->system->get("coreExtensionLocation").substru($fileName, $extensionDirectoryLength));
}
- $resourceDirLength = strlenu($this->yellow->system->get("coreResourceDir"));
- $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($this->yellow->system->get("coreResourceDir"), $regex, false, false);
+ $resourceDirectoryLength = strlenu($this->yellow->system->get("coreResourceDirectory"));
+ $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($this->yellow->system->get("coreResourceDirectory"), $regex, false, false);
foreach ($fileNames as $fileName) {
- array_push($locations, $this->yellow->system->get("coreResourceLocation").substru($fileName, $resourceDirLength));
+ array_push($locations, $this->yellow->system->get("coreResourceLocation").substru($fileName, $resourceDirectoryLength));
}
return $locations;
}
@@ -625,11 +624,11 @@ class YellowCommand {
public function getExtraLocations($path) {
$locations = array();
$pathIgnore = "($path/|".
- $this->yellow->system->get("coreStaticDir")."|".
- $this->yellow->system->get("coreCacheDir")."|".
- $this->yellow->system->get("coreContentDir")."|".
- $this->yellow->system->get("coreMediaDir")."|".
- $this->yellow->system->get("coreSystemDir").")";
+ $this->yellow->system->get("coreStaticDirectory")."|".
+ $this->yellow->system->get("coreCacheDirectory")."|".
+ $this->yellow->system->get("coreContentDirectory")."|".
+ $this->yellow->system->get("coreMediaDirectory")."|".
+ $this->yellow->system->get("coreSystemDirectory").")";
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive(".", "/.*/", false, false);
foreach ($fileNames as $fileName) {
$fileName = substru($fileName, 2);
diff --git a/system/extensions/core.php b/system/extensions/core.php
@@ -4,7 +4,7 @@
// This file may be used and distributed under the terms of the public license.
class YellowCore {
- const VERSION = "0.8.12";
+ const VERSION = "0.8.13";
const TYPE = "feature";
public $page; //current page
public $content; //content files from file system
@@ -36,9 +36,9 @@ class YellowCore {
$this->system->setDefault("coreStaticUrl", "");
$this->system->setDefault("coreStaticDefaultFile", "index.html");
$this->system->setDefault("coreStaticErrorFile", "404.html");
- $this->system->setDefault("coreStaticDir", "public/");
- $this->system->setDefault("coreCacheDir", "cache/");
- $this->system->setDefault("coreTrashDir", "system/trash/");
+ $this->system->setDefault("coreStaticDirectory", "public/");
+ $this->system->setDefault("coreCacheDirectory", "cache/");
+ $this->system->setDefault("coreTrashDirectory", "system/trash/");
$this->system->setDefault("coreServerUrl", "auto");
$this->system->setDefault("coreServerTimezone", "UTC");
$this->system->setDefault("coreMultiLanguageMode", "0");
@@ -47,18 +47,18 @@ class YellowCore {
$this->system->setDefault("coreImageLocation", "/media/images/");
$this->system->setDefault("coreExtensionLocation", "/media/extensions/");
$this->system->setDefault("coreResourceLocation", "/media/resources/");
- $this->system->setDefault("coreMediaDir", "media/");
- $this->system->setDefault("coreDownloadDir", "media/downloads/");
- $this->system->setDefault("coreImageDir", "media/images/");
- $this->system->setDefault("coreSystemDir", "system/");
- $this->system->setDefault("coreExtensionDir", "system/extensions/");
- $this->system->setDefault("coreLayoutDir", "system/layouts/");
- $this->system->setDefault("coreResourceDir", "system/resources/");
- $this->system->setDefault("coreSettingDir", "system/settings/");
- $this->system->setDefault("coreContentDir", "content/");
- $this->system->setDefault("coreContentRootDir", "default/");
- $this->system->setDefault("coreContentHomeDir", "home/");
- $this->system->setDefault("coreContentSharedDir", "shared/");
+ $this->system->setDefault("coreMediaDirectory", "media/");
+ $this->system->setDefault("coreDownloadDirectory", "media/downloads/");
+ $this->system->setDefault("coreImageDirectory", "media/images/");
+ $this->system->setDefault("coreSystemDirectory", "system/");
+ $this->system->setDefault("coreExtensionDirectory", "system/extensions/");
+ $this->system->setDefault("coreLayoutDirectory", "system/layouts/");
+ $this->system->setDefault("coreResourceDirectory", "system/resources/");
+ $this->system->setDefault("coreSettingDirectory", "system/settings/");
+ $this->system->setDefault("coreContentDirectory", "content/");
+ $this->system->setDefault("coreContentRootDirectory", "default/");
+ $this->system->setDefault("coreContentHomeDirectory", "home/");
+ $this->system->setDefault("coreContentSharedDirectory", "shared/");
$this->system->setDefault("coreContentDefaultFile", "page.md");
$this->system->setDefault("coreContentErrorFile", "page-error-(.*).md");
$this->system->setDefault("coreContentExtension", ".md");
@@ -91,11 +91,10 @@ class YellowCore {
// Handle initialisation
public function load() {
- $this->system->load($this->system->get("coreSettingDir").$this->system->get("coreSystemFile"));
- $this->extensions->load($this->system->get("coreExtensionDir"));
- $this->text->load($this->system->get("coreExtensionDir"));
- $this->text->load($this->system->get("coreSettingDir"), $this->system->get("coreTextFile"), $this->system->get("language"));
- $this->lookup->detectLocationArguments();
+ $this->system->load($this->system->get("coreSettingDirectory").$this->system->get("coreSystemFile"));
+ $this->extensions->load($this->system->get("coreExtensionDirectory"));
+ $this->text->load($this->system->get("coreExtensionDirectory"));
+ $this->text->load($this->system->get("coreSettingDirectory"), $this->system->get("coreTextFile"), $this->system->get("language"));
$this->lookup->detectFileSystem();
$this->startup();
}
@@ -131,8 +130,8 @@ class YellowCore {
public function processRequest($scheme, $address, $base, $location, $fileName, $cacheable) {
$statusCode = 0;
if (is_readable($fileName)) {
- if ($this->toolbox->isRequestCleanUrl($location)) {
- $location = $location.$this->toolbox->getLocationArgsCleanUrl();
+ if ($this->lookup->isRequestCleanUrl($location)) {
+ $location = $location.$this->toolbox->getLocationArgumentsCleanUrl();
$location = $this->lookup->normaliseUrl($scheme, $address, $base, $location);
$statusCode = $this->sendStatus(303, $location);
}
@@ -173,7 +172,7 @@ class YellowCore {
// Read page
public function readPage($scheme, $address, $base, $location, $fileName, $cacheable, $statusCode, $pageError) {
if ($statusCode>=400) {
- $locationError = $this->content->getHomeLocation($this->page->location).$this->system->get("coreContentSharedDir");
+ $locationError = $this->content->getHomeLocation($this->page->location).$this->system->get("coreContentSharedDirectory");
$fileNameError = $this->lookup->findFileFromLocation($locationError, true).$this->system->get("coreContentErrorFile");
$fileNameError = strreplaceu("(.*)", $statusCode, $fileNameError);
if (is_file($fileNameError)) {
@@ -200,7 +199,7 @@ class YellowCore {
$this->page->parsePage();
$statusCode = $this->page->statusCode;
$lastModifiedFormatted = $this->page->getHeader("Last-Modified");
- if ($statusCode==200 && $this->page->isCacheable() && $this->toolbox->isRequestNotModified($lastModifiedFormatted)) {
+ if ($statusCode==200 && $this->page->isCacheable() && $this->toolbox->isNotModified($lastModifiedFormatted)) {
$statusCode = 304;
@header($this->toolbox->getHttpStatusFormatted($statusCode));
} else {
@@ -225,7 +224,7 @@ class YellowCore {
// Send file response
public function sendFile($statusCode, $fileName, $cacheable) {
$lastModifiedFormatted = $this->toolbox->getHttpDateFormatted($this->toolbox->getFileModified($fileName));
- if ($statusCode==200 && $cacheable && $this->toolbox->isRequestNotModified($lastModifiedFormatted)) {
+ if ($statusCode==200 && $cacheable && $this->toolbox->isNotModified($lastModifiedFormatted)) {
$statusCode = 304;
@header($this->toolbox->getHttpStatusFormatted($statusCode));
} else {
@@ -264,20 +263,20 @@ class YellowCore {
}
// Handle command
- public function command($args = null) {
+ public function command($line = "") {
$statusCode = 0;
$this->toolbox->timerStart($time);
+ list($command, $text) = $this->getCommandInformation($line);
foreach ($this->extensions->extensions as $key=>$value) {
if (method_exists($value["obj"], "onCommand")) {
$this->lookup->commandHandler = $key;
- $statusCode = $value["obj"]->onCommand(func_get_args());
+ $statusCode = $value["obj"]->onCommand($command, $text);
if ($statusCode!=0) break;
}
}
if ($statusCode==0) {
$this->lookup->commandHandler = "core";
$statusCode = 400;
- list($command) = func_get_args();
echo "Yellow $command: Command not found\n";
}
$this->toolbox->timerStop($time);
@@ -319,19 +318,23 @@ class YellowCore {
}
if ($statusCode==0) {
$line = date("Y-m-d H:i:s")." ".trim($action)." ".trim($message)."\n";
- $this->toolbox->appendFile($this->system->get("coreExtensionDir").$this->system->get("coreLogFile"), $line);
+ $this->toolbox->appendFile($this->system->get("coreExtensionDirectory").$this->system->get("coreLogFile"), $line);
}
}
// Include layout
- public function layout($name, $args = null) {
- $this->lookup->layoutArgs = func_get_args();
+ public function layout($name, $arguments = null) {
+ $this->lookup->layoutArguments = func_get_args();
$this->page->includeLayout($name);
}
// Return layout arguments
- public function getLayoutArgs($sizeMin = 9) {
- return array_pad($this->lookup->layoutArgs, $sizeMin, null);
+ public function getLayoutArguments($sizeMin = 9) {
+ return array_pad($this->lookup->layoutArguments, $sizeMin, null);
+ }
+
+ public function getLayoutArgs($sizeMin = 9) { //TODO: remove later, for backwards compatibility
+ return $this->getLayoutArguments($sizeMin);
}
// Return request information
@@ -348,12 +351,21 @@ class YellowCore {
$this->system->set("serverBase", $base);
if (defined("DEBUG") && DEBUG>=3) echo "YellowCore::getRequestInformation $scheme://$address$base<br/>\n";
}
- $location = substru($this->toolbox->getLocation(), strlenu($base));
+ $location = substru($this->toolbox->detectServerLocation(), strlenu($base));
if (empty($fileName)) $fileName = $this->lookup->findFileFromSystem($location);
if (empty($fileName)) $fileName = $this->lookup->findFileFromMedia($location);
if (empty($fileName)) $fileName = $this->lookup->findFileFromLocation($location);
return array($scheme, $address, $base, $location, $fileName);
}
+
+ // Return command information
+ public function getCommandInformation($line = "") {
+ if (empty($line)) {
+ $line = $this->toolbox->getTextString(array_slice($this->toolbox->getServer("argv"), 1));
+ if (defined("DEBUG") && DEBUG>=3) echo "YellowCore::getCommandInformation $line<br/>\n";
+ }
+ return $this->toolbox->getTextList($line, " ", 2);
+ }
// Return request handler
public function getRequestHandler() {
@@ -466,7 +478,7 @@ class YellowPage {
rtrim($this->yellow->system->get("editLocation"), "/").$this->location));
} else {
$this->set("type", $this->yellow->toolbox->getFileType($this->fileName));
- $this->set("group", $this->yellow->toolbox->getFileGroup($this->fileName, $this->yellow->system->get("coreMediaDir")));
+ $this->set("group", $this->yellow->toolbox->getFileGroup($this->fileName, $this->yellow->system->get("coreMediaDirectory")));
$this->set("modified", date("Y-m-d H:i:s", $this->yellow->toolbox->getFileModified($this->fileName)));
}
if (!empty($pageError)) $this->set("pageError", $pageError);
@@ -543,7 +555,7 @@ class YellowPage {
$output = "Datenstrom Yellow ".YellowCore::VERSION;
if ($text=="error") $output = $this->get("pageError");
if ($text=="log") {
- $fileName = $this->yellow->system->get("coreExtensionDir").$this->yellow->system->get("coreLogFile");
+ $fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreLogFile");
$fileHandle = @fopen($fileName, "r");
if ($fileHandle) {
$dataBufferSize = 512;
@@ -569,7 +581,7 @@ class YellowPage {
if (!$this->isHeader("Content-Type")) $this->setHeader("Content-Type", "text/html; charset=utf-8");
if (!$this->isHeader("Content-Modified")) $this->setHeader("Content-Modified", $this->getModified(true));
if (!$this->isHeader("Last-Modified")) $this->setHeader("Last-Modified", $this->getLastModified(true));
- $fileNameTheme = $this->yellow->system->get("coreResourceDir").$this->yellow->lookup->normaliseName($this->get("theme")).".css";
+ $fileNameTheme = $this->yellow->system->get("coreResourceDirectory").$this->yellow->lookup->normaliseName($this->get("theme")).".css";
if (!is_file($fileNameTheme)) {
$this->error(500, "Theme '".$this->get("theme")."' does not exist!");
}
@@ -590,9 +602,6 @@ class YellowPage {
if ($this->yellow->getRequestHandler()=="core" && !$this->isAvailable() && $this->statusCode==200) {
$this->error(404);
}
- if ($this->yellow->toolbox->isRequestSelf()) {
- $this->error(404);
- }
if ($this->isExisting("pageClean")) $this->outputData = null;
foreach ($this->yellow->extensions->extensions as $key=>$value) {
if (method_exists($value["obj"], "onParsePageOutput")) {
@@ -620,8 +629,8 @@ class YellowPage {
// Include page layout
public function includeLayout($name) {
- $fileNameLayoutNormal = $this->yellow->system->get("coreLayoutDir").$this->yellow->lookup->normaliseName($name).".html";
- $fileNameLayoutTheme = $this->yellow->system->get("coreLayoutDir").
+ $fileNameLayoutNormal = $this->yellow->system->get("coreLayoutDirectory").$this->yellow->lookup->normaliseName($name).".html";
+ $fileNameLayoutTheme = $this->yellow->system->get("coreLayoutDirectory").
$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";
@@ -805,13 +814,13 @@ class YellowPage {
}
}
if ($name=="header") {
- $fileNameTheme = $this->yellow->system->get("coreResourceDir").$this->yellow->lookup->normaliseName($this->get("theme")).".css";
+ $fileNameTheme = $this->yellow->system->get("coreResourceDirectory").$this->yellow->lookup->normaliseName($this->get("theme")).".css";
if (is_file($fileNameTheme)) {
$locationTheme = $this->yellow->system->get("coreServerBase").
$this->yellow->system->get("coreResourceLocation").$this->yellow->lookup->normaliseName($this->get("theme")).".css";
$output .= "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"$locationTheme\" />\n";
}
- $fileNameScript = $this->yellow->system->get("coreResourceDir").$this->yellow->lookup->normaliseName($this->get("theme")).".js";
+ $fileNameScript = $this->yellow->system->get("coreResourceDirectory").$this->yellow->lookup->normaliseName($this->get("theme")).".js";
if (is_file($fileNameScript)) {
$locationScript = $this->yellow->system->get("coreServerBase").
$this->yellow->system->get("coreResourceLocation").$this->yellow->lookup->normaliseName($this->get("theme")).".js";
@@ -1123,12 +1132,12 @@ class YellowPageCollection extends ArrayObject {
// Return location for a page in pagination
public function getPaginationLocation($absoluteLocation = true, $pageNumber = 1) {
- $location = $locationArgs = "";
+ $location = $locationArguments = "";
if ($pageNumber>=1 && $pageNumber<=$this->paginationCount) {
$location = $this->yellow->page->getLocation($absoluteLocation);
- $locationArgs = $this->yellow->toolbox->getLocationArgsNew("page", $pageNumber>1 ? "$pageNumber" : "");
+ $locationArguments = $this->yellow->toolbox->getLocationArgumentsNew("page", $pageNumber>1 ? "$pageNumber" : "");
}
- return $location.$locationArgs;
+ return $location.$locationArguments;
}
// Return location for previous page in pagination
@@ -1311,7 +1320,7 @@ class YellowContent {
$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("coreContentSharedDir").$name;
+ $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);
@@ -1415,7 +1424,7 @@ class YellowMedia {
$address = $this->yellow->page->address;
$base = $this->yellow->system->get("coreServerBase");
if (empty($location)) {
- $fileNames = array($this->yellow->system->get("coreMediaDir"));
+ $fileNames = array($this->yellow->system->get("coreMediaDirectory"));
} else {
$fileNames = array();
$path = substru($location, 1);
@@ -1792,51 +1801,25 @@ class YellowLookup {
public $yellow; //access to API
public $requestHandler; //request handler name
public $commandHandler; //command handler name
- public $layoutArgs; //layout arguments
+ public $layoutArguments; //layout arguments
public function __construct($yellow) {
$this->yellow = $yellow;
}
- // Detect location arguments
- public function detectLocationArguments() {
- if (isset($_SERVER["REQUEST_URI"])) {
- $location = $_SERVER["REQUEST_URI"];
- $location = rawurldecode(($pos = strposu($location, "?")) ? substru($location, 0, $pos) : $location);
- $location = $this->yellow->toolbox->normaliseTokens($location, true);
- $separator = $this->yellow->toolbox->getLocationArgsSeparator();
- if (preg_match("/^(.*?\/)([^\/]+$separator.*)$/", $location, $matches)) {
- $_SERVER["LOCATION"] = $location = $matches[1];
- $_SERVER["LOCATION_ARGUMENTS"] = $matches[2];
- foreach (explode("/", $matches[2]) as $token) {
- if (preg_match("/^(.*?)$separator(.*)$/", $token, $matches)) {
- if (!empty($matches[1]) && !strempty($matches[2])) {
- $matches[1] = strreplaceu(array("\x1c", "\x1d", "\x1e"), array("/", ":", "="), $matches[1]);
- $matches[2] = strreplaceu(array("\x1c", "\x1d", "\x1e"), array("/", ":", "="), $matches[2]);
- $_REQUEST[$matches[1]] = $matches[2];
- }
- }
- }
- } else {
- $_SERVER["LOCATION"] = $location;
- $_SERVER["LOCATION_ARGUMENTS"] = "";
- }
- }
- }
-
// Detect file system
public function detectFileSystem() {
list($pathRoot, $pathHome) = $this->findFileSystemInformation();
- $this->yellow->system->set("coreContentRootDir", $pathRoot);
- $this->yellow->system->set("coreContentHomeDir", $pathHome);
+ $this->yellow->system->set("coreContentRootDirectory", $pathRoot);
+ $this->yellow->system->set("coreContentHomeDirectory", $pathHome);
date_default_timezone_set($this->yellow->system->get("coreServerTimezone"));
}
// Return file system information
public function findFileSystemInformation() {
- $path = $this->yellow->system->get("coreContentDir");
- $pathRoot = $this->yellow->system->get("coreContentRootDir");
- $pathHome = $this->yellow->system->get("coreContentHomeDir");
+ $path = $this->yellow->system->get("coreContentDirectory");
+ $pathRoot = $this->yellow->system->get("coreContentRootDirectory");
+ $pathHome = $this->yellow->system->get("coreContentHomeDirectory");
if (!$this->yellow->system->get("coreMultiLanguageMode")) $pathRoot = "";
if (!empty($pathRoot)) {
$token = $root = rtrim($pathRoot, "/");
@@ -1867,8 +1850,8 @@ class YellowLookup {
// Return root locations
public function findRootLocations($includePath = true) {
$locations = array();
- $pathBase = $this->yellow->system->get("coreContentDir");
- $pathRoot = $this->yellow->system->get("coreContentRootDir");
+ $pathBase = $this->yellow->system->get("coreContentDirectory");
+ $pathRoot = $this->yellow->system->get("coreContentRootDirectory");
if (!empty($pathRoot)) {
foreach ($this->yellow->toolbox->getDirectoryEntries($pathBase, "/.*/", true, true, false) as $entry) {
$token = $this->normaliseToken($entry)."/";
@@ -1886,9 +1869,9 @@ class YellowLookup {
public function findLocationFromFile($fileName) {
$invalid = false;
$location = "/";
- $pathBase = $this->yellow->system->get("coreContentDir");
- $pathRoot = $this->yellow->system->get("coreContentRootDir");
- $pathHome = $this->yellow->system->get("coreContentHomeDir");
+ $pathBase = $this->yellow->system->get("coreContentDirectory");
+ $pathRoot = $this->yellow->system->get("coreContentRootDirectory");
+ $pathHome = $this->yellow->system->get("coreContentHomeDirectory");
$fileDefault = $this->yellow->system->get("coreContentDefaultFile");
$fileExtension = $this->yellow->system->get("coreContentExtension");
if (substru($fileName, 0, strlenu($pathBase))==$pathBase && mb_check_encoding($fileName, "UTF-8")) {
@@ -1923,9 +1906,9 @@ class YellowLookup {
// Return file path from location
public function findFileFromLocation($location, $directory = false) {
$found = $invalid = false;
- $path = $this->yellow->system->get("coreContentDir");
- $pathRoot = $this->yellow->system->get("coreContentRootDir");
- $pathHome = $this->yellow->system->get("coreContentHomeDir");
+ $path = $this->yellow->system->get("coreContentDirectory");
+ $pathRoot = $this->yellow->system->get("coreContentRootDirectory");
+ $pathHome = $this->yellow->system->get("coreContentHomeDirectory");
$fileDefault = $this->yellow->system->get("coreContentDefaultFile");
$fileExtension = $this->yellow->system->get("coreContentExtension");
$tokens = explode("/", $location);
@@ -2037,12 +2020,14 @@ class YellowLookup {
// Return language from file path
public function findLanguageFromFile($fileName, $languageDefault) {
$language = $languageDefault;
- $pathBase = $this->yellow->system->get("coreContentDir");
- $pathRoot = $this->yellow->system->get("coreContentRootDir");
+ $pathBase = $this->yellow->system->get("coreContentDirectory");
+ $pathRoot = $this->yellow->system->get("coreContentRootDirectory");
if (!empty($pathRoot)) {
$fileName = substru($fileName, strlenu($pathBase));
- if (preg_match("/^(.+?)\//", $fileName, $matches)) $name = $this->normaliseToken($matches[1]);
- if (strlenu($name)==2) $language = $name;
+ if (preg_match("/^(.+?)\//", $fileName, $matches)) {
+ $name = $this->normaliseToken($matches[1]);
+ if (strlenu($name)==2) $language = $name;
+ }
}
return $language;
}
@@ -2053,7 +2038,7 @@ class YellowLookup {
if ($this->isFileLocation($location)) {
$mediaLocationLength = strlenu($this->yellow->system->get("coreMediaLocation"));
if (substru($location, 0, $mediaLocationLength)==$this->yellow->system->get("coreMediaLocation")) {
- $fileName = $this->yellow->system->get("coreMediaDir").substru($location, 7);
+ $fileName = $this->yellow->system->get("coreMediaDirectory").substru($location, 7);
}
}
return $fileName;
@@ -2066,9 +2051,9 @@ class YellowLookup {
$extensionLocationLength = strlenu($this->yellow->system->get("coreExtensionLocation"));
$resourceLocationLength = strlenu($this->yellow->system->get("coreResourceLocation"));
if (substru($location, 0, $extensionLocationLength)==$this->yellow->system->get("coreExtensionLocation")) {
- $fileName = $this->yellow->system->get("coreExtensionDir").substru($location, $extensionLocationLength);
+ $fileName = $this->yellow->system->get("coreExtensionDirectory").substru($location, $extensionLocationLength);
} elseif (substru($location, 0, $resourceLocationLength)==$this->yellow->system->get("coreResourceLocation")) {
- $fileName = $this->yellow->system->get("coreResourceDir").substru($location, $resourceLocationLength);
+ $fileName = $this->yellow->system->get("coreResourceDirectory").substru($location, $resourceLocationLength);
}
}
return $fileName;
@@ -2077,8 +2062,8 @@ class YellowLookup {
// Return file path from cache if possible
public function findFileFromCache($location, $fileName, $cacheable) {
if ($cacheable) {
- $location .= $this->yellow->toolbox->getLocationArgs();
- $fileNameStatic = rtrim($this->yellow->system->get("coreCacheDir"), "/").$location;
+ $location .= $this->yellow->toolbox->getLocationArguments();
+ $fileNameStatic = rtrim($this->yellow->system->get("coreCacheDirectory"), "/").$location;
if (!$this->isFileLocation($location)) $fileNameStatic .= $this->yellow->system->get("coreStaticDefaultFile");
if (is_readable($fileNameStatic)) $fileName = $fileNameStatic;
}
@@ -2138,7 +2123,7 @@ class YellowLookup {
}
}
$location = strreplaceu("/./", "/", $location);
- $location = strreplaceu(":", $this->yellow->toolbox->getLocationArgsSeparator(), $location);
+ $location = strreplaceu(":", $this->yellow->toolbox->getLocationArgumentsSeparator(), $location);
} else {
if ($filterStrict && !preg_match("/^(http|https|ftp|mailto):/", $location)) $location = "error-xss-filter";
}
@@ -2184,6 +2169,11 @@ class YellowLookup {
return $location;
}
+ // Check if clean URL is requested
+ public function isRequestCleanUrl($location) {
+ return isset($_REQUEST["clean-url"]) && substru($location, -1, 1)=="/";
+ }
+
// Check if location is specifying root
public function isRootLocation($location) {
return substru($location, 0, 1)!="/";
@@ -2218,9 +2208,9 @@ class YellowLookup {
// Check if location is available
public function isAvailableLocation($location, $fileName) {
$available = true;
- $pathBase = $this->yellow->system->get("coreContentDir");
+ $pathBase = $this->yellow->system->get("coreContentDirectory");
if (substru($fileName, 0, strlenu($pathBase))==$pathBase) {
- $sharedLocation = $this->yellow->content->getHomeLocation($location).$this->yellow->system->get("coreContentSharedDir");
+ $sharedLocation = $this->yellow->content->getHomeLocation($location).$this->yellow->system->get("coreContentSharedDirectory");
if (substru($location, 0, strlenu($sharedLocation))==$sharedLocation) $available = false;
}
return $available;
@@ -2242,30 +2232,30 @@ class YellowLookup {
// Check if file is valid
public function isValidFile($fileName) {
- $contentDirLength = strlenu($this->yellow->system->get("coreContentDir"));
- $mediaDirLength = strlenu($this->yellow->system->get("coreMediaDir"));
- $systemDirLength = strlenu($this->yellow->system->get("coreSystemDir"));
- return substru($fileName, 0, $contentDirLength)==$this->yellow->system->get("coreContentDir") ||
- substru($fileName, 0, $mediaDirLength)==$this->yellow->system->get("coreMediaDir") ||
- substru($fileName, 0, $systemDirLength)==$this->yellow->system->get("coreSystemDir");
+ $contentDirectoryLength = strlenu($this->yellow->system->get("coreContentDirectory"));
+ $mediaDirectoryLength = strlenu($this->yellow->system->get("coreMediaDirectory"));
+ $systemDirectoryLength = strlenu($this->yellow->system->get("coreSystemDirectory"));
+ return substru($fileName, 0, $contentDirectoryLength)==$this->yellow->system->get("coreContentDirectory") ||
+ substru($fileName, 0, $mediaDirectoryLength)==$this->yellow->system->get("coreMediaDirectory") ||
+ substru($fileName, 0, $systemDirectoryLength)==$this->yellow->system->get("coreSystemDirectory");
}
// Check if content file
public function isContentFile($fileName) {
- $contentDirLength = strlenu($this->yellow->system->get("coreContentDir"));
- return substru($fileName, 0, $contentDirLength)==$this->yellow->system->get("coreContentDir");
+ $contentDirectoryLength = strlenu($this->yellow->system->get("coreContentDirectory"));
+ return substru($fileName, 0, $contentDirectoryLength)==$this->yellow->system->get("coreContentDirectory");
}
// Check if media file
public function isMediaFile($fileName) {
- $mediaDirLength = strlenu($this->yellow->system->get("coreMediaDir"));
- return substru($fileName, 0, $mediaDirLength)==$this->yellow->system->get("coreMediaDir");
+ $mediaDirectoryLength = strlenu($this->yellow->system->get("coreMediaDirectory"));
+ return substru($fileName, 0, $mediaDirectoryLength)==$this->yellow->system->get("coreMediaDirectory");
}
// Check if system file
public function isSystemFile($fileName) {
- $systemDirLength = strlenu($this->yellow->system->get("coreSystemDir"));
- return substru($fileName, 0, $systemDirLength)==$this->yellow->system->get("coreSystemDir");
+ $systemDirectoryLength = strlenu($this->yellow->system->get("coreSystemDirectory"));
+ return substru($fileName, 0, $systemDirectoryLength)==$this->yellow->system->get("coreSystemDirectory");
}
}
@@ -2281,21 +2271,16 @@ class YellowToolbox {
return isset($_SERVER[$key]) ? $_SERVER[$key] : "";
}
- // Return location from current HTTP request
- public function getLocation() {
- return $this->getServer("LOCATION");
- }
-
// Return location arguments from current HTTP request
- public function getLocationArgs() {
+ public function getLocationArguments() {
return $this->getServer("LOCATION_ARGUMENTS");
}
// Return location arguments from current HTTP request, modify existing arguments
- public function getLocationArgsNew($key, $value) {
- $locationArgs = "";
+ public function getLocationArgumentsNew($key, $value) {
+ $locationArguments = "";
$found = false;
- $separator = $this->getLocationArgsSeparator();
+ $separator = $this->getLocationArgumentsSeparator();
foreach (explode("/", $this->getServer("LOCATION_ARGUMENTS")) as $token) {
if (preg_match("/^(.*?)$separator(.*)$/", $token, $matches)) {
if ($matches[1]==$key) {
@@ -2303,41 +2288,42 @@ class YellowToolbox {
$found = true;
}
if (!empty($matches[1]) && !strempty($matches[2])) {
- if (!empty($locationArgs)) $locationArgs .= "/";
- $locationArgs .= "$matches[1]:$matches[2]";
+ if (!empty($locationArguments)) $locationArguments .= "/";
+ $locationArguments .= "$matches[1]:$matches[2]";
}
}
}
if (!$found && !empty($key) && !strempty($value)) {
- if (!empty($locationArgs)) $locationArgs .= "/";
- $locationArgs .= "$key:$value";
+ if (!empty($locationArguments)) $locationArguments .= "/";
+ $locationArguments .= "$key:$value";
}
- if (!empty($locationArgs)) {
- $locationArgs = $this->normaliseArgs($locationArgs, false, false);
- if (!$this->isLocationArgsPagination($locationArgs)) $locationArgs .= "/";
+ if (!empty($locationArguments)) {
+ $locationArguments = $this->normaliseArguments($locationArguments, false, false);
+ if (!$this->isLocationArgumentsPagination($locationArguments)) $locationArguments .= "/";
}
- return $locationArgs;
+ return $locationArguments;
}
// Return location arguments from current HTTP request, convert form parameters
- public function getLocationArgsCleanUrl() {
+ public function getLocationArgumentsCleanUrl() {
+ $locationArguments = "";
foreach (array_merge($_GET, $_POST) as $key=>$value) {
if (!empty($key) && !strempty($value)) {
- if (!empty($locationArgs)) $locationArgs .= "/";
+ if (!empty($locationArguments)) $locationArguments .= "/";
$key = strreplaceu(array("/", ":", "="), array("\x1c", "\x1d", "\x1e"), $key);
$value = strreplaceu(array("/", ":", "="), array("\x1c", "\x1d", "\x1e"), $value);
- $locationArgs .= "$key:$value";
+ $locationArguments .= "$key:$value";
}
}
- if (!empty($locationArgs)) {
- $locationArgs = $this->normaliseArgs($locationArgs, false, false);
- if (!$this->isLocationArgsPagination($locationArgs)) $locationArgs .= "/";
+ if (!empty($locationArguments)) {
+ $locationArguments = $this->normaliseArguments($locationArguments, false, false);
+ if (!$this->isLocationArgumentsPagination($locationArguments)) $locationArguments .= "/";
}
- return $locationArgs;
+ return $locationArguments;
}
// Return location arguments separator
- public function getLocationArgsSeparator() {
+ public function getLocationArgumentsSeparator() {
return (strtoupperu(substru(PHP_OS, 0, 3))!="WIN") ? ":" : "=";
}
@@ -2366,10 +2352,10 @@ class YellowToolbox {
}
// Normalise location arguments
- public function normaliseArgs($text, $appendSlash = true, $filterStrict = true) {
+ public function normaliseArguments($text, $appendSlash = true, $filterStrict = true) {
if ($appendSlash) $text .= "/";
if ($filterStrict) $text = strreplaceu(" ", "-", strtoloweru($text));
- $text = strreplaceu(":", $this->getLocationArgsSeparator(), $text);
+ $text = strreplaceu(":", $this->getLocationArgumentsSeparator(), $text);
return strreplaceu(array("%2F","%3A","%3D"), array("/",":","="), rawurlencode($text));
}
@@ -2529,10 +2515,10 @@ class YellowToolbox {
// Return files and directories
public function getDirectoryEntries($path, $regex = "/.*/", $sort = true, $directories = true, $includePath = true) {
$entries = array();
- $dirHandle = @opendir($path);
- if ($dirHandle) {
+ $directoryHandle = @opendir($path);
+ if ($directoryHandle) {
$path = rtrim($path, "/");
- while (($entry = readdir($dirHandle))!==false) {
+ while (($entry = readdir($directoryHandle))!==false) {
if (substru($entry, 0, 1)==".") continue;
$entry = $this->normaliseUnicode($entry);
if (preg_match($regex, $entry)) {
@@ -2544,7 +2530,7 @@ class YellowToolbox {
}
}
if ($sort) natcasesort($entries);
- closedir($dirHandle);
+ closedir($directoryHandle);
}
return $entries;
}
@@ -2745,8 +2731,14 @@ class YellowToolbox {
return $attributes;
}
+ // Return array of specific size from text string
+ public function getTextList($text, $separator, $size) {
+ $tokens = explode($separator, $text, $size);
+ return array_pad($tokens, $size, null);
+ }
+
// Return arguments from text string, space separated
- public function getTextArgs($text, $optional = "-", $sizeMin = 9) {
+ public function getTextArguments($text, $optional = "-", $sizeMin = 9) {
$text = preg_replace("/\s+/s", " ", trim($text));
$tokens = str_getcsv($text, " ", "\"");
foreach ($tokens as $key=>$value) {
@@ -2756,7 +2748,7 @@ class YellowToolbox {
}
// Return text string from arguments, space separated
- public function getTextImplode($tokens, $optional = "-") {
+ public function getTextString($tokens, $optional = "-") {
$text = "";
foreach ($tokens as $token) {
if (preg_match("/\s/", $token)) $token = "\"$token\"";
@@ -2774,7 +2766,7 @@ class YellowToolbox {
return str_word_count($text);
}
- // Return text truncated at word boundary
+ // Return text string truncated at word boundary
public function getTextTruncated($text, $lengthMax) {
if (strlenu($text)>$lengthMax-1) {
$text = substru($text, 0, $lengthMax);
@@ -2984,6 +2976,33 @@ class YellowToolbox {
return "$scheme://$address$base/";
}
+ // Detect server location
+ public function detectServerLocation() {
+ if (isset($_SERVER["REQUEST_URI"])) {
+ $location = $_SERVER["REQUEST_URI"];
+ $location = rawurldecode(($pos = strposu($location, "?")) ? substru($location, 0, $pos) : $location);
+ $location = $this->normaliseTokens($location, true);
+ $separator = $this->getLocationArgumentsSeparator();
+ if (preg_match("/^(.*?\/)([^\/]+$separator.*)$/", $location, $matches)) {
+ $_SERVER["LOCATION"] = $location = $matches[1];
+ $_SERVER["LOCATION_ARGUMENTS"] = $matches[2];
+ foreach (explode("/", $matches[2]) as $token) {
+ if (preg_match("/^(.*?)$separator(.*)$/", $token, $matches)) {
+ if (!empty($matches[1]) && !strempty($matches[2])) {
+ $matches[1] = strreplaceu(array("\x1c", "\x1d", "\x1e"), array("/", ":", "="), $matches[1]);
+ $matches[2] = strreplaceu(array("\x1c", "\x1d", "\x1e"), array("/", ":", "="), $matches[2]);
+ $_REQUEST[$matches[1]] = $matches[2];
+ }
+ }
+ }
+ } else {
+ $_SERVER["LOCATION"] = $location;
+ $_SERVER["LOCATION_ARGUMENTS"] = "";
+ }
+ }
+ return $this->getServer("LOCATION");
+ }
+
// Detect server timezone
public function detectServerTimezone() {
$timezone = @date_default_timezone_get();
@@ -3098,32 +3117,32 @@ class YellowToolbox {
}
// Check if there are location arguments in current HTTP request
- public function isLocationArgs($location = "") {
+ public function isLocationArguments($location = "") {
if (empty($location)) $location = $this->getServer("LOCATION").$this->getServer("LOCATION_ARGUMENTS");
- $separator = $this->getLocationArgsSeparator();
+ $separator = $this->getLocationArgumentsSeparator();
return preg_match("/[^\/]+$separator.*$/", $location);
}
// Check if there are pagination arguments in current HTTP request
- public function isLocationArgsPagination($location) {
- $separator = $this->getLocationArgsSeparator();
+ public function isLocationArgumentsPagination($location) {
+ $separator = $this->getLocationArgumentsSeparator();
return preg_match("/^(.*\/)?page$separator.*$/", $location);
}
- // Check if script location is requested
- public function isRequestSelf() {
- return substru($this->getServer("REQUEST_URI"), -10, 10)=="yellow.php";
- }
-
- // Check if clean URL is requested
- public function isRequestCleanUrl($location) {
- return isset($_REQUEST["clean-url"]) && substru($location, -1, 1)=="/";
- }
-
// Check if unmodified since last HTTP request
- public function isRequestNotModified($lastModifiedFormatted) {
+ public function isNotModified($lastModifiedFormatted) {
return $this->getServer("HTTP_IF_MODIFIED_SINCE")==$lastModifiedFormatted;
}
+
+ //TODO: remove later, for backwards compatibility
+ public function getLocationArgs() { return $this->getLocationArguments(); }
+ public function getLocationArgsNew($key, $value) { return $this->getLocationArgumentsNew($key, $value); }
+ public function getLocationArgsCleanUrl() { return $this->getLocationArgumentsCleanUrl(); }
+ public function getLocationArgsSeparator() { return $this->getLocationArgumentsSeparator(); }
+ public function getTextArgs($text, $optional = "-", $sizeMin = 9) { return $this->getTextArguments($text, $optional, $sizeMin); }
+ public function normaliseArgs($text, $appendSlash = true, $filterStrict = true) { return $this->normaliseArguments($text, $appendSlash, $filterStrict); }
+ public function isLocationArgs($location = "") { return $this->isLocationArguments($location); }
+ public function isLocationArgsPagination($location) { return $this->isLocationArgumentsPagination($location); }
}
class YellowExtensions {
@@ -3169,6 +3188,21 @@ class YellowExtensions {
$this->yellow->system->set("trashDir", "system/trash/");
$this->yellow->system->set("contentDir", "content/");
$this->yellow->system->set("contentPagination", "page");
+ $this->yellow->system->set("coreStaticDir", "public/");
+ $this->yellow->system->set("coreCacheDir", "cache/");
+ $this->yellow->system->set("coreTrashDir", "system/trash/");
+ $this->yellow->system->set("coreMediaDir", "media/");
+ $this->yellow->system->set("coreDownloadDir", "media/downloads/");
+ $this->yellow->system->set("coreImageDir", "media/images/");
+ $this->yellow->system->set("coreSystemDir", "system/");
+ $this->yellow->system->set("coreExtensionDir", "system/extensions/");
+ $this->yellow->system->set("coreLayoutDir", "system/layouts/");
+ $this->yellow->system->set("coreResourceDir", "system/resources/");
+ $this->yellow->system->set("coreSettingDir", "system/settings/");
+ $this->yellow->system->set("coreContentDir", "content/");
+ $this->yellow->system->set("coreContentRootDir", "default/");
+ $this->yellow->system->set("coreContentHomeDir", "home/");
+ $this->yellow->system->set("coreContentSharedDir", "shared/");
}
// Register extension
diff --git a/system/extensions/edit.js b/system/extensions/edit.js
@@ -12,7 +12,7 @@ var yellow = {
onPageShow: function(e) { yellow.edit.pageShow(e); },
onUpdatePane: function() { yellow.edit.updatePane(yellow.edit.paneId, yellow.edit.paneAction, yellow.edit.paneStatus); },
onResizePane: function() { yellow.edit.resizePane(yellow.edit.paneId, yellow.edit.paneAction, yellow.edit.paneStatus); },
- action: function(action, status, args) { yellow.edit.processAction(action, status, args); }
+ action: function(action, status, arguments) { yellow.edit.processAction(action, status, arguments); }
};
yellow.edit = {
@@ -71,7 +71,7 @@ yellow.edit = {
for (; element; element=element.parentNode) {
if (element.tagName=="A") break;
}
- this.processAction(element.getAttribute("data-action"), element.getAttribute("data-status"), element.getAttribute("data-args"));
+ this.processAction(element.getAttribute("data-action"), element.getAttribute("data-status"), element.getAttribute("data-arguments"));
},
// Handle page cache
@@ -333,7 +333,7 @@ yellow.edit = {
"<li><span>"+yellow.toolbox.encodeHtml(yellow.system.userEmail)+"</span></li>"+
"<li><a href=\"#\" data-action=\"settings\">"+this.getText("MenuSettings")+"</a></li>" +
"<li><a href=\"#\" data-action=\"help\">"+this.getText("MenuHelp")+"</a></li>" +
- "<li><a href=\"#\" data-action=\"submit\" data-args=\"action:logout\">"+this.getText("MenuLogout")+"</a></li>"+
+ "<li><a href=\"#\" data-action=\"submit\" data-arguments=\"action:logout\">"+this.getText("MenuLogout")+"</a></li>"+
"</ul>";
break;
case "yellow-pane-information":
@@ -397,7 +397,7 @@ yellow.edit = {
setTimeout("yellow.action('submit', '', 'action:update/option:check/');", 500);
}
if (paneStatus=="updates") {
- document.getElementById("yellow-pane-update-status").innerHTML = "<a href=\"#\" data-action=\"submit\" data-args=\"action:update\">"+this.getText("UpdateStatusUpdates")+"</a>";
+ document.getElementById("yellow-pane-update-status").innerHTML = "<a href=\"#\" data-action=\"submit\" data-arguments=\"action:update\">"+this.getText("UpdateStatusUpdates")+"</a>";
}
break;
case "yellow-pane-create":
@@ -427,7 +427,7 @@ yellow.edit = {
if (document.getElementById(paneId+"-submit").className != className) {
document.getElementById(paneId+"-submit").className = className;
document.getElementById(paneId+"-submit").innerHTML = this.getText(paneAction+"Button");
- document.getElementById(paneId+"-submit").setAttribute("data-args", "action:"+paneAction);
+ document.getElementById(paneId+"-submit").setAttribute("data-arguments", "action:"+paneAction);
this.resizePane(paneId, paneAction, paneStatus);
}
}
@@ -543,10 +543,10 @@ yellow.edit = {
},
// Process action
- processAction: function(action, status, args) {
+ processAction: function(action, status, arguments) {
action = action ? action : "none";
status = status ? status : "none";
- args = args ? args : "none";
+ arguments = arguments ? arguments : "none";
if (action!="none") {
if (yellow.system.debug) console.log("yellow.edit.processAction action:"+action+" status:"+status);
var paneId = (status!="next" && status!="done") ? "yellow-pane-"+action : "yellow-pane-information";
@@ -570,16 +570,16 @@ yellow.edit = {
case "delete": this.showPane(paneId, action, status, true); break;
case "menu": this.showPane(paneId, action, status); break;
case "close": this.hidePane(this.paneId); break;
- case "toolbar": this.processToolbar(status, args); break;
- case "settings": this.processSettings(args); break;
- case "submit": this.processSubmit(args); break;
+ case "toolbar": this.processToolbar(status, arguments); break;
+ case "settings": this.processSettings(arguments); break;
+ case "submit": this.processSubmit(arguments); break;
case "help": this.processHelp(); break;
}
}
},
// Process toolbar
- processToolbar: function(status, args) {
+ processToolbar: function(status, arguments) {
if (yellow.system.debug) console.log("yellow.edit.processToolbar status:"+status);
var elementText = document.getElementById(this.paneId+"-text");
var elementPreview = document.getElementById(this.paneId+"-preview");
@@ -601,7 +601,7 @@ yellow.edit = {
case "ol": yellow.editor.setMarkdown(elementText, "1. ", "insert-multiline-block", true); break;
case "tl": yellow.editor.setMarkdown(elementText, "- [ ] ", "insert-multiline-block", true); break;
case "link": yellow.editor.setMarkdown(elementText, "[link](url)", "insert", false, yellow.editor.getMarkdownLink); break;
- case "text": yellow.editor.setMarkdown(elementText, args, "insert"); break;
+ case "text": yellow.editor.setMarkdown(elementText, arguments, "insert"); break;
case "status": yellow.editor.setMetaData(elementText, "status", true); break;
case "file": this.showFileDialog(); break;
case "undo": yellow.editor.undo(); break;
@@ -653,15 +653,15 @@ yellow.edit = {
},
// Process settings
- processSettings: function(args) {
- var action = args!="none" ? args : "account";
+ processSettings: function(arguments) {
+ var action = arguments!="none" ? arguments : "account";
if (action!=this.paneAction && action!="settings") this.processAction(action);
},
// Process submit
- processSubmit: function(args) {
+ processSubmit: function(arguments) {
var settings = { "action":"none", "csrftoken":this.getCookie("csrftoken") };
- var tokens = args.split("/");
+ var tokens = arguments.split("/");
for (var i=0; i<tokens.length; i++) {
var pair = tokens[i].split(/[:=]/);
if (!pair[0] || !pair[1]) continue;
@@ -726,7 +726,7 @@ yellow.edit = {
for (var i=0; i<tokens.length; i++) {
var token = tokens[i].replace(/[\:]/g,"");
var className = token.replace("+1", "plus1").replace("-1", "minus1").replace(/_/g, "-");
- rawDataEmojis += "<li><a href=\"#\" id=\"yellow-popup-list-"+yellow.toolbox.encodeHtml(token)+"\" data-action=\"toolbar\" data-status=\"text\" data-args=\":"+yellow.toolbox.encodeHtml(token)+":\"><i class=\"ea ea-"+yellow.toolbox.encodeHtml(className)+"\"></i></a></li>";
+ rawDataEmojis += "<li><a href=\"#\" id=\"yellow-popup-list-"+yellow.toolbox.encodeHtml(token)+"\" data-action=\"toolbar\" data-status=\"text\" data-arguments=\":"+yellow.toolbox.encodeHtml(token)+":\"><i class=\"ea ea-"+yellow.toolbox.encodeHtml(className)+"\"></i></a></li>";
}
}
elementDiv.innerHTML = "<ul class=\"yellow-dropdown yellow-dropdown-menu\">"+rawDataEmojis+"</ul>";
@@ -737,7 +737,7 @@ yellow.edit = {
var tokens = yellow.system.fontawesomeToolbarButtons.split(" ");
for (var i=0; i<tokens.length; i++) {
var token = tokens[i].replace(/[\:]/g,"");
- rawDataIcons += "<li><a href=\"#\" id=\"yellow-popup-list-"+yellow.toolbox.encodeHtml(token)+"\" data-action=\"toolbar\" data-status=\"text\" data-args=\":"+yellow.toolbox.encodeHtml(token)+":\"><i class=\"fa "+yellow.toolbox.encodeHtml(token)+"\"></i></a></li>";
+ rawDataIcons += "<li><a href=\"#\" id=\"yellow-popup-list-"+yellow.toolbox.encodeHtml(token)+"\" data-action=\"toolbar\" data-status=\"text\" data-arguments=\":"+yellow.toolbox.encodeHtml(token)+":\"><i class=\"fa "+yellow.toolbox.encodeHtml(token)+"\"></i></a></li>";
}
}
elementDiv.innerHTML = "<ul class=\"yellow-dropdown yellow-dropdown-menu\">"+rawDataIcons+"</ul>";
@@ -916,7 +916,7 @@ yellow.edit = {
var tokens = yellow.system.editSettingsActions.split(/\s*,\s*/);
for (var i=0; i<tokens.length; i++) {
var token = tokens[i];
- rawDataActions += "<a href=\"#\""+(token==paneAction ? "class=\"active\"": "")+" data-action=\"settings\" data-args=\""+yellow.toolbox.encodeHtml(token)+"\">"+this.getText(token+"Title")+"</a><br />";
+ rawDataActions += "<a href=\"#\""+(token==paneAction ? "class=\"active\"": "")+" data-action=\"settings\" data-arguments=\""+yellow.toolbox.encodeHtml(token)+"\">"+this.getText(token+"Title")+"</a><br />";
}
}
return rawDataActions;
@@ -990,9 +990,9 @@ yellow.edit = {
return (key in yellow.text) ? yellow.text[key] : "["+key+"]";
},
- // Return cookie string
- getCookie: function(name) {
- return yellow.toolbox.getCookie(name);
+ // Return browser cookie
+ getCookie: function(key) {
+ return yellow.toolbox.getCookie(key);
},
// Check if user with access
@@ -1464,9 +1464,9 @@ yellow.toolbox = {
return lines;
},
- // Return cookie string
- getCookie: function(name) {
- var matches = document.cookie.match("(^|; )"+name+"=([^;]+)");
+ // Return browser cookie
+ getCookie: function(key) {
+ var matches = document.cookie.match("(^|; )"+key+"=([^;]+)");
return matches ? unescape(matches[2]) : "";
},
@@ -1480,15 +1480,15 @@ yellow.toolbox = {
},
// Submit form with post method
- submitForm: function(args) {
+ submitForm: function(arguments) {
var elementForm = document.createElement("form");
elementForm.setAttribute("method", "post");
- for (var key in args) {
- if (!args.hasOwnProperty(key)) continue;
+ for (var key in arguments) {
+ if (!arguments.hasOwnProperty(key)) continue;
var elementInput = document.createElement("input");
elementInput.setAttribute("type", "hidden");
elementInput.setAttribute("name", key);
- elementInput.setAttribute("value", args[key]);
+ elementInput.setAttribute("value", arguments[key]);
elementForm.appendChild(elementInput);
}
document.body.appendChild(elementForm);
diff --git a/system/extensions/edit.php b/system/extensions/edit.php
@@ -4,7 +4,7 @@
// This file may be used and distributed under the terms of the public license.
class YellowEdit {
- const VERSION = "0.8.25";
+ const VERSION = "0.8.26";
const TYPE = "feature";
public $yellow; //access to API
public $response; //web response
@@ -33,7 +33,7 @@ class YellowEdit {
$this->yellow->system->setDefault("editLoginRestriction", "0");
$this->yellow->system->setDefault("editLoginSessionTimeout", "2592000");
$this->yellow->system->setDefault("editBruteForceProtection", "25");
- $this->users->load($this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile"));
+ $this->users->load($this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile"));
}
// Handle request
@@ -87,10 +87,9 @@ class YellowEdit {
}
// Handle command
- public function onCommand($args) {
- list($command) = $args;
+ public function onCommand($command, $text) {
switch ($command) {
- case "user": $statusCode = $this->processCommandUser($args); break;
+ case "user": $statusCode = $this->processCommandUser($command, $text); break;
default: $statusCode = 0;
}
return $statusCode;
@@ -103,36 +102,17 @@ class YellowEdit {
// Handle update
public function onUpdate($action) {
- if ($action=="update") { //TODO: remove later, converts old format
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
- $fileData = $this->yellow->toolbox->readFile($fileNameUser);
- foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
- preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
- if (lcfirst($matches[1])=="group") {
- $fileDataNew .= "Access: create, edit, delete, upload".($matches[2]=="administrator" ? ", system, update" : "")."\n";
- } elseif (!empty($matches[1]) && !empty($matches[2]) && $matches[1][0]!="#" && preg_match("/@/", $matches[1])) {
- list($hash, $name, $language, $status, $pending, $stamp, $timestamp, $failed, $group, $home) = explode(",", $matches[2]);
- $access = "create, edit, delete, upload".($group=="administrator" ? ", system, update" : "");
- $modified = date("Y-m-d H:i:s", $timestamp);
- $fileDataNew .= "Email: $matches[1]\nName: $name\nLanguage: $language\nHome: $home\nAccess: $access\nHash: $hash\nStamp: $stamp\nPending: $pending\nFailed: $failed\nModified: $modified\nStatus: $status\n\n";
- } else {
- $fileDataNew .= $line;
- }
- }
- $fileDataNew = rtrim($fileDataNew)."\n";
- if ($fileData!=$fileDataNew && !$this->yellow->toolbox->createFile($fileNameUser, $fileDataNew)) {
- $this->yellow->log("error", "Can't write file '$fileNameUser'!");
- }
- }
if ($action=="update") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $cleanup = false;
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$fileData = $this->yellow->toolbox->readFile($fileNameUser);
$fileDataNew = "";
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
- preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
- if (lcfirst($matches[1])=="email" && !strempty($matches[2])) {
- $status = $this->users->getUser($matches[2], "status");
- $cleanup = !empty($status) && $status!="active" && $status!="inactive";
+ if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
+ if (lcfirst($matches[1])=="email" && !strempty($matches[2])) {
+ $status = $this->users->getUser($matches[2], "status");
+ $cleanup = !empty($status) && $status!="active" && $status!="inactive";
+ }
}
if (!$cleanup) $fileDataNew .= $line;
}
@@ -144,21 +124,20 @@ class YellowEdit {
}
// Process command to update user account
- public function processCommandUser($args) {
- list($command, $option) = $args;
+ public function processCommandUser($command, $text) {
+ list($option) = $this->yellow->toolbox->getTextArguments($text);
switch ($option) {
- case "": $statusCode = $this->userShow($args); break;
- case "add": $statusCode = $this->userAdd($args); break;
- case "change": $statusCode = $this->userChange($args); break;
- case "remove": $statusCode = $this->userRemove($args); break;
+ case "": $statusCode = $this->userShow($command, $text); break;
+ case "add": $statusCode = $this->userAdd($command, $text); break;
+ case "change": $statusCode = $this->userChange($command, $text); break;
+ case "remove": $statusCode = $this->userRemove($command, $text); break;
default: $statusCode = 400; echo "Yellow $command: Invalid arguments\n";
}
return $statusCode;
}
// Show user accounts
- public function userShow($args) {
- list($command) = $args;
+ public function userShow($command, $text) {
foreach ($this->users->getData() as $line) {
echo "$line\n";
}
@@ -167,9 +146,9 @@ class YellowEdit {
}
// Add user account
- public function userAdd($args) {
+ public function userAdd($command, $text) {
$status = "ok";
- list($command, $option, $email, $password, $name) = $args;
+ list($option, $email, $password, $name) = $this->yellow->toolbox->getTextArguments($text);
if (empty($email) || empty($password)) $status = $this->response->status = "incomplete";
if (empty($name)) $name = $this->yellow->system->get("sitename");
if ($status=="ok") $status = $this->getUserAccount($email, $password, "add");
@@ -182,7 +161,7 @@ class YellowEdit {
case "short": echo "ERROR updating settings: Please enter a longer password!\n"; break;
}
if ($status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array(
"name" => $name,
"language" => $this->yellow->system->get("language"),
@@ -209,9 +188,9 @@ class YellowEdit {
}
// Change user account
- public function userChange($args) {
+ public function userChange($command, $text) {
$status = "ok";
- list($command, $option, $email, $password, $name) = $args;
+ list($option, $email, $password, $name) = $this->yellow->toolbox->getTextArguments($text);
if (empty($email)) $status = $this->response->status = "invalid";
if ($status=="ok") $status = $this->getUserAccount($email, $password, "change");
if ($status=="ok" && !$this->users->isExisting($email)) $status = "unknown";
@@ -222,7 +201,7 @@ class YellowEdit {
case "short": echo "ERROR updating settings: Please enter a longer password!\n"; break;
}
if ($status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array(
"name" => empty($name) ? $this->users->getUser($email, "name") : $name,
"hash" => empty($password) ? $this->users->getUser($email, "hash") : $this->users->createHash($password),
@@ -237,9 +216,9 @@ class YellowEdit {
}
// Remove user account
- public function userRemove($args) {
+ public function userRemove($command, $text) {
$status = "ok";
- list($command, $option, $email) = $args;
+ list($option, $email) = $this->yellow->toolbox->getTextArguments($text);
$name = $this->users->getUser($email, "name");
if (empty($email)) $status = $this->response->status = "invalid";
if (empty($name)) $name = $this->yellow->system->get("sitename");
@@ -250,7 +229,7 @@ class YellowEdit {
case "unknown": echo "ERROR updating settings: Can't find email '$email'!\n"; break;
}
if ($status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$status = $this->users->remove($fileNameUser, $email) ? "ok" : "error";
if ($status=="error") echo "ERROR updating settings: Can't write file '$fileNameUser'!\n";
$this->yellow->log($status=="ok" ? "info" : "error", "Remove user '".strtok($name, " ")."'");
@@ -264,7 +243,7 @@ class YellowEdit {
public function processRequest($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
if ($this->checkUserAuth($scheme, $address, $base, $location, $fileName)) {
- switch ($_REQUEST["action"]) {
+ switch ($this->yellow->page->getRequest("action")) {
case "": $statusCode = $this->processRequestShow($scheme, $address, $base, $location, $fileName); break;
case "login": $statusCode = $this->processRequestLogin($scheme, $address, $base, $location, $fileName); break;
case "logout": $statusCode = $this->processRequestLogout($scheme, $address, $base, $location, $fileName); break;
@@ -280,7 +259,7 @@ class YellowEdit {
}
} elseif ($this->checkUserUnauth($scheme, $address, $base, $location, $fileName)) {
$this->yellow->lookup->requestHandler = "core";
- switch ($_REQUEST["action"]) {
+ switch ($this->yellow->page->getRequest("action")) {
case "": $statusCode = $this->processRequestShow($scheme, $address, $base, $location, $fileName); break;
case "signup": $statusCode = $this->processRequestSignup($scheme, $address, $base, $location, $fileName); break;
case "forgot": $statusCode = $this->processRequestForgot($scheme, $address, $base, $location, $fileName); break;
@@ -318,7 +297,7 @@ class YellowEdit {
// Process request for user login
public function processRequestLogin($scheme, $address, $base, $location, $fileName) {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array("failed" => "0", "modified" => date("Y-m-d H:i:s", time()));
if ($this->users->save($fileNameUser, $this->response->userEmail, $settings)) {
$home = $this->users->getUser($this->response->userEmail, "home");
@@ -353,16 +332,16 @@ class YellowEdit {
public function processRequestSignup($scheme, $address, $base, $location, $fileName) {
$this->response->action = "signup";
$this->response->status = "ok";
- $name = trim(preg_replace("/[^\pL\d\-\. ]/u", "-", $_REQUEST["name"]));
- $email = trim($_REQUEST["email"]);
- $password = trim($_REQUEST["password"]);
- $consent = trim($_REQUEST["consent"]);
+ $name = trim(preg_replace("/[^\pL\d\-\. ]/u", "-", $this->yellow->page->getRequest("name")));
+ $email = trim($this->yellow->page->getRequest("email"));
+ $password = trim($this->yellow->page->getRequest("password"));
+ $consent = trim($this->yellow->page->getRequest("consent"));
if (empty($name) || empty($email) || empty($password) || empty($consent)) $this->response->status = "incomplete";
if ($this->response->status=="ok") $this->response->status = $this->getUserAccount($email, $password, $this->response->action);
if ($this->response->status=="ok" && $this->response->isLoginRestriction()) $this->response->status = "next";
if ($this->response->status=="ok" && $this->users->isTaken($email)) $this->response->status = "next";
if ($this->response->status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array(
"name" => $name,
"language" => $this->yellow->lookup->findLanguageFromFile($fileName, $this->yellow->system->get("language")),
@@ -394,10 +373,10 @@ class YellowEdit {
public function processRequestConfirm($scheme, $address, $base, $location, $fileName) {
$this->response->action = "confirm";
$this->response->status = "ok";
- $email = $_REQUEST["email"];
- $this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
+ $email = $this->yellow->page->getRequest("email");
+ $this->response->status = $this->getUserStatus($email, $this->yellow->page->getRequest("action"));
if ($this->response->status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array("failed" => "0", "modified" => date("Y-m-d H:i:s", time()), "status" => "unapproved");
$this->response->status = $this->users->save($fileNameUser, $email, $settings) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
@@ -414,10 +393,10 @@ class YellowEdit {
public function processRequestApprove($scheme, $address, $base, $location, $fileName) {
$this->response->action = "approve";
$this->response->status = "ok";
- $email = $_REQUEST["email"];
- $this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
+ $email = $this->yellow->page->getRequest("email");
+ $this->response->status = $this->getUserStatus($email, $this->yellow->page->getRequest("action"));
if ($this->response->status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array("failed" => "0", "modified" => date("Y-m-d H:i:s", time()), "status" => "active");
$this->response->status = $this->users->save($fileNameUser, $email, $settings) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
@@ -435,7 +414,7 @@ class YellowEdit {
public function processRequestForgot($scheme, $address, $base, $location, $fileName) {
$this->response->action = "forgot";
$this->response->status = "ok";
- $email = trim($_REQUEST["email"]);
+ $email = trim($this->yellow->page->getRequest("email"));
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $this->response->status = "invalid";
if ($this->response->status=="ok" && !$this->users->isExisting($email)) $this->response->status = "next";
if ($this->response->status=="ok") {
@@ -450,14 +429,14 @@ class YellowEdit {
public function processRequestRecover($scheme, $address, $base, $location, $fileName) {
$this->response->action = "recover";
$this->response->status = "ok";
- $email = trim($_REQUEST["email"]);
- $password = trim($_REQUEST["password"]);
- $this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
+ $email = trim($this->yellow->page->getRequest("email"));
+ $password = trim($this->yellow->page->getRequest("password"));
+ $this->response->status = $this->getUserStatus($email, $this->yellow->page->getRequest("action"));
if ($this->response->status=="ok") {
if (empty($password)) $this->response->status = "password";
if ($this->response->status=="ok") $this->response->status = $this->getUserAccount($email, $password, $this->response->action);
if ($this->response->status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array("hash" => $this->users->createHash($password), "failed" => "0", "modified" => date("Y-m-d H:i:s", time()));
$this->response->status = $this->users->save($fileNameUser, $email, $settings) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
@@ -475,10 +454,10 @@ class YellowEdit {
public function processRequestReactivate($scheme, $address, $base, $location, $fileName) {
$this->response->action = "reactivate";
$this->response->status = "ok";
- $email = $_REQUEST["email"];
- $this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
+ $email = $this->yellow->page->getRequest("email");
+ $this->response->status = $this->getUserStatus($email, $this->yellow->page->getRequest("action"));
if ($this->response->status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array("failed" => "0", "modified" => date("Y-m-d H:i:s", time()), "status" => "active");
$this->response->status = $this->users->save($fileNameUser, $email, $settings) ? "done" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
@@ -491,14 +470,14 @@ class YellowEdit {
public function processRequestVerify($scheme, $address, $base, $location, $fileName) {
$this->response->action = "verify";
$this->response->status = "ok";
- $email = $emailSource = $_REQUEST["email"];
- $this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
+ $email = $emailSource = $this->yellow->page->getRequest("email");
+ $this->response->status = $this->getUserStatus($email, $this->yellow->page->getRequest("action"));
if ($this->response->status=="ok") {
$emailSource = $this->users->getUser($email, "pending");
if ($this->users->getUser($emailSource, "status")!="active") $this->response->status = "done";
}
if ($this->response->status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array("failed" => "0", "modified" => date("Y-m-d H:i:s", time()), "status" => "unchanged");
$this->response->status = $this->users->save($fileNameUser, $email, $settings) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
@@ -515,14 +494,14 @@ class YellowEdit {
public function processRequestChange($scheme, $address, $base, $location, $fileName) {
$this->response->action = "change";
$this->response->status = "ok";
- $email = $emailSource = trim($_REQUEST["email"]);
- $this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
+ $email = $emailSource = trim($this->yellow->page->getRequest("email"));
+ $this->response->status = $this->getUserStatus($email, $this->yellow->page->getRequest("action"));
if ($this->response->status=="ok") {
list($email, $hash) = explode(":", $this->users->getUser($email, "pending"), 2);
if (!$this->users->isExisting($email) || empty($hash)) $this->response->status = "done";
}
if ($this->response->status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array(
"hash" => $hash,
"pending" => "none",
@@ -533,7 +512,7 @@ class YellowEdit {
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
if ($this->response->status=="ok" && $email!=$emailSource) {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->remove($fileNameUser, $emailSource) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
@@ -549,7 +528,7 @@ class YellowEdit {
public function processRequestQuit($scheme, $address, $base, $location, $fileName) {
$this->response->action = "quit";
$this->response->status = "ok";
- $name = trim($_REQUEST["name"]);
+ $name = trim($this->yellow->page->getRequest("name"));
$email = $this->response->userEmail;
if (empty($name)) $this->response->status = "none";
if ($this->response->status=="ok" && $name!=$this->users->getUser($email, "name")) $this->response->status = "mismatch";
@@ -566,10 +545,10 @@ class YellowEdit {
public function processRequestRemove($scheme, $address, $base, $location, $fileName) {
$this->response->action = "remove";
$this->response->status = "ok";
- $email = $_REQUEST["email"];
- $this->response->status = $this->getUserStatus($email, $_REQUEST["action"]);
+ $email = $this->yellow->page->getRequest("email");
+ $this->response->status = $this->getUserStatus($email, $this->yellow->page->getRequest("action"));
if ($this->response->status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array("failed" => "0", "modified" => date("Y-m-d H:i:s", time()), "status" => "removed");
$this->response->status = $this->users->save($fileNameUser, $email, $settings) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
@@ -580,7 +559,7 @@ class YellowEdit {
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't send email on this server!");
}
if ($this->response->status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$this->response->status = $this->users->remove($fileNameUser, $email) ? "ok" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
@@ -596,17 +575,17 @@ class YellowEdit {
public function processRequestAccount($scheme, $address, $base, $location, $fileName) {
$this->response->action = "account";
$this->response->status = "ok";
- $email = trim($_REQUEST["email"]);
+ $email = trim($this->yellow->page->getRequest("email"));
$emailSource = $this->response->userEmail;
- $password = trim($_REQUEST["password"]);
- $name = trim(preg_replace("/[^\pL\d\-\. ]/u", "-", $_REQUEST["name"]));
- $language = trim($_REQUEST["language"]);
+ $password = trim($this->yellow->page->getRequest("password"));
+ $name = trim(preg_replace("/[^\pL\d\-\. ]/u", "-", $this->yellow->page->getRequest("name")));
+ $language = trim($this->yellow->page->getRequest("language"));
if ($email!=$emailSource || !empty($password)) {
if (empty($email)) $this->response->status = "invalid";
if ($this->response->status=="ok") $this->response->status = $this->getUserAccount($email, $password, $this->response->action);
if ($this->response->status=="ok" && $email!=$emailSource && $this->users->isTaken($email)) $this->response->status = "taken";
if ($this->response->status=="ok" && $email!=$emailSource) {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array(
"name" => $name,
"language" => $language,
@@ -622,7 +601,7 @@ class YellowEdit {
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
}
if ($this->response->status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array(
"name" => $name,
"language" => $language,
@@ -639,7 +618,7 @@ class YellowEdit {
}
} else {
if ($this->response->status=="ok") {
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$settings = array("name" => $name, "language" => $language, "failed" => "0", "modified" => date("Y-m-d H:i:s", time()));
$this->response->status = $this->users->save($fileNameUser, $email, $settings) ? "done" : "error";
if ($this->response->status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
@@ -660,14 +639,14 @@ class YellowEdit {
if ($this->response->isUserAccess("system")) {
$this->response->action = "system";
$this->response->status = "ok";
- $sitename = trim($_REQUEST["sitename"]);
- $author = trim($_REQUEST["author"]);
- $email = trim($_REQUEST["email"]);
+ $sitename = trim($this->yellow->page->getRequest("sitename"));
+ $author = trim($this->yellow->page->getRequest("author"));
+ $email = trim($this->yellow->page->getRequest("email"));
if ($email!=$this->yellow->system->get("email")) {
- if(empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) $this->response->status = "invalid";
+ if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) $this->response->status = "invalid";
}
if ($this->response->status=="ok") {
- $fileName = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("coreSystemFile");
+ $fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreSystemFile");
$settings = array("sitename" => $sitename, "author" => $author, "email" => $email);
$file = $this->response->getFileSystem($scheme, $address, $base, $location, $fileName, $settings);
$this->response->status = (!$file->isError() && $this->yellow->system->save($fileName, $settings)) ? "done" : "error";
@@ -689,8 +668,8 @@ class YellowEdit {
if ($this->response->isUserAccess("update")) {
$this->response->action = "update";
$this->response->status = "ok";
- $extension = trim($_REQUEST["extension"]);
- $option = trim($_REQUEST["option"]);
+ $extension = trim($this->yellow->page->getRequest("extension"));
+ $option = trim($this->yellow->page->getRequest("option"));
if ($option=="check") {
list($statusCode, $updates, $rawData) = $this->response->getUpdateInformation();
$this->response->status = $updates ? "updates" : "ok";
@@ -700,7 +679,7 @@ class YellowEdit {
$this->response->rawDataOutput = "";
}
} else {
- $this->response->status = $this->yellow->command("update", $extension, $option)==0 ? "done" : "error";
+ $this->response->status = $this->yellow->command("update $extension $option")==0 ? "done" : "error";
}
if ($this->response->status=="done") {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
@@ -715,11 +694,11 @@ class YellowEdit {
// Process request to create page
public function processRequestCreate($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
- if ($this->response->isUserAccess("create", $location) && !empty($_REQUEST["rawdataedit"])) {
- $this->response->rawDataSource = $_REQUEST["rawdatasource"];
- $this->response->rawDataEdit = $_REQUEST["rawdatasource"];
- $this->response->rawDataEndOfLine = $_REQUEST["rawdataendofline"];
- $rawData = $_REQUEST["rawdataedit"];
+ if ($this->response->isUserAccess("create", $location) && !empty($this->yellow->page->getRequest("rawdataedit"))) {
+ $this->response->rawDataSource = $this->yellow->page->getRequest("rawdatasource");
+ $this->response->rawDataEdit = $this->yellow->page->getRequest("rawdatasource");
+ $this->response->rawDataEndOfLine = $this->yellow->page->getRequest("rawdataendofline");
+ $rawData = $this->yellow->page->getRequest("rawdataedit");
$page = $this->response->getPageNew($scheme, $address, $base, $location, $fileName,
$rawData, $this->response->getEndOfLine());
if (!$page->isError()) {
@@ -741,10 +720,10 @@ class YellowEdit {
// Process request to edit page
public function processRequestEdit($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
- if ($this->response->isUserAccess("edit", $location) && !empty($_REQUEST["rawdataedit"])) {
- $this->response->rawDataSource = $_REQUEST["rawdatasource"];
- $this->response->rawDataEdit = $_REQUEST["rawdataedit"];
- $this->response->rawDataEndOfLine = $_REQUEST["rawdataendofline"];
+ if ($this->response->isUserAccess("edit", $location) && !empty($this->yellow->page->getRequest("rawdataedit"))) {
+ $this->response->rawDataSource = $this->yellow->page->getRequest("rawdatasource");
+ $this->response->rawDataEdit = $this->yellow->page->getRequest("rawdataedit");
+ $this->response->rawDataEndOfLine = $this->yellow->page->getRequest("rawdataendofline");
$rawDataFile = $this->yellow->toolbox->readFile($fileName);
$page = $this->response->getPageEdit($scheme, $address, $base, $location, $fileName,
$this->response->rawDataSource, $this->response->rawDataEdit, $rawDataFile, $this->response->rawDataEndOfLine);
@@ -780,15 +759,15 @@ class YellowEdit {
public function processRequestDelete($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
if ($this->response->isUserAccess("delete", $location) && is_file($fileName)) {
- $this->response->rawDataSource = $_REQUEST["rawdatasource"];
- $this->response->rawDataEdit = $_REQUEST["rawdatasource"];
- $this->response->rawDataEndOfLine = $_REQUEST["rawdataendofline"];
+ $this->response->rawDataSource = $this->yellow->page->getRequest("rawdatasource");
+ $this->response->rawDataEdit = $this->yellow->page->getRequest("rawdatasource");
+ $this->response->rawDataEndOfLine = $this->yellow->page->getRequest("rawdataendofline");
$rawDataFile = $this->yellow->toolbox->readFile($fileName);
$page = $this->response->getPageDelete($scheme, $address, $base, $location, $fileName,
$rawDataFile, $this->response->rawDataEndOfLine);
if (!$page->isError()) {
if ($this->yellow->lookup->isFileLocation($location)) {
- if ($this->yellow->toolbox->deleteFile($fileName, $this->yellow->system->get("coreTrashDir"))) {
+ if ($this->yellow->toolbox->deleteFile($fileName, $this->yellow->system->get("coreTrashDirectory"))) {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
$statusCode = $this->yellow->sendStatus(303, $location);
} else {
@@ -796,7 +775,7 @@ class YellowEdit {
$statusCode = $this->yellow->processRequest($scheme, $address, $base, $location, $fileName, false);
}
} else {
- if ($this->yellow->toolbox->deleteDirectory(dirname($fileName), $this->yellow->system->get("coreTrashDir"))) {
+ if ($this->yellow->toolbox->deleteDirectory(dirname($fileName), $this->yellow->system->get("coreTrashDirectory"))) {
$location = $this->yellow->lookup->normaliseUrl($scheme, $address, $base, $location);
$statusCode = $this->yellow->sendStatus(303, $location);
} else {
@@ -815,7 +794,7 @@ class YellowEdit {
// Process request to show preview
public function processRequestPreview($scheme, $address, $base, $location, $fileName) {
$page = $this->response->getPagePreview($scheme, $address, $base, $location, $fileName,
- $_REQUEST["rawdataedit"], $_REQUEST["rawdataendofline"]);
+ $this->yellow->page->getRequest("rawdataedit"), $this->yellow->page->getRequest("rawdataendofline"));
$statusCode = $this->yellow->sendData(200, $page->outputData, "", false);
if (defined("DEBUG") && DEBUG>=1) {
$parser = $page->get("parser");
@@ -843,7 +822,7 @@ class YellowEdit {
} else {
$data["error"] = "Can't write file '$fileNameShort'!";
}
- $statusCode = $this->yellow->sendData(is_null($data["error"]) ? 200 : 500, json_encode($data), "a.json", false);
+ $statusCode = $this->yellow->sendData(isset($data["error"]) ? 500 : 200, json_encode($data), "a.json", false);
return $statusCode;
}
@@ -856,10 +835,13 @@ class YellowEdit {
// Check user authentication
public function checkUserAuth($scheme, $address, $base, $location, $fileName) {
- if ($this->isRequestSameSite("POST", $scheme, $address) || $_REQUEST["action"]=="") {
- if ($_REQUEST["action"]=="login") {
- $email = $_REQUEST["email"];
- $password = $_REQUEST["password"];
+ $action = $this->yellow->page->getRequest("action");
+ $authToken = $this->yellow->toolbox->getCookie("authtoken");
+ $csrfToken = $this->yellow->toolbox->getCookie("csrftoken");
+ if (empty($action) || $this->isRequestSameSite("POST", $scheme, $address)) {
+ if ($action=="login") {
+ $email = $this->yellow->page->getRequest("email");
+ $password = $this->yellow->page->getRequest("password");
if ($this->users->checkAuthLogin($email, $password)) {
$this->response->createCookies($scheme, $address, $base, $email);
$this->response->userEmail = $email;
@@ -869,14 +851,16 @@ class YellowEdit {
$this->response->userFailedEmail = $email;
$this->response->userFailedExpire = PHP_INT_MAX;
}
- } elseif (isset($_COOKIE["authtoken"]) && isset($_COOKIE["csrftoken"])) {
- if ($this->users->checkAuthToken($_COOKIE["authtoken"], $_COOKIE["csrftoken"], $_POST["csrftoken"], $_REQUEST["action"]=="")) {
- $this->response->userEmail = $email = $this->users->getAuthEmail($_COOKIE["authtoken"]);
+ } elseif (!empty($authToken) && !empty($csrfToken)) {
+ $csrfTokenReceived = isset($_POST["csrftoken"]) ? $_POST["csrftoken"] : "";
+ $csrfTokenIrrelevant = empty($action);
+ if ($this->users->checkAuthToken($authToken, $csrfToken, $csrfTokenReceived, $csrfTokenIrrelevant)) {
+ $this->response->userEmail = $email = $this->users->getAuthEmail($authToken);
$this->response->language = $this->getUserLanguage($email);
} else {
$this->response->userFailedError = "auth";
- $this->response->userFailedEmail = $this->users->getAuthEmail($_COOKIE["authtoken"]);
- $this->response->userFailedExpire = $this->users->getAuthExpire($_COOKIE["authtoken"]);
+ $this->response->userFailedEmail = $this->users->getAuthEmail($authToken);
+ $this->response->userFailedExpire = $this->users->getAuthExpire($authToken);
}
}
}
@@ -886,16 +870,22 @@ class YellowEdit {
// Check user without authentication
public function checkUserUnauth($scheme, $address, $base, $location, $fileName) {
$ok = false;
- if ($_REQUEST["action"]=="" || $_REQUEST["action"]=="signup" || $_REQUEST["action"]=="forgot") {
+ $action = $this->yellow->page->getRequest("action");
+ if (empty($action) || $action=="signup" || $action=="forgot") {
$ok = true;
- } elseif (isset($_REQUEST["actiontoken"])) {
- if ($this->users->checkActionToken($_REQUEST["actiontoken"], $_REQUEST["email"], $_REQUEST["action"], $_REQUEST["expire"])) {
+ } elseif ($this->yellow->page->isRequest("actiontoken")) {
+ $actionToken = $this->yellow->page->getRequest("actiontoken");
+ $email = $this->yellow->page->getRequest("email");
+ $action = $this->yellow->page->getRequest("action");
+ $expire = $this->yellow->page->getRequest("expire");
+ $langauge = $this->yellow->page->getRequest("language");
+ if ($this->users->checkActionToken($actionToken, $email, $action, $expire)) {
$ok = true;
- $this->response->language = $this->getActionLanguage($_REQUEST["language"]);
+ $this->response->language = $this->getActionLanguage($language);
} else {
$this->response->userFailedError = "action";
- $this->response->userFailedEmail = $_REQUEST["email"];
- $this->response->userFailedExpire = $_REQUEST["expire"];
+ $this->response->userFailedEmail = $email;
+ $this->response->userFailedExpire = $expire;
}
}
return $ok;
@@ -907,7 +897,7 @@ class YellowEdit {
if ($this->response->userFailedExpire>time() && $this->users->isExisting($this->response->userFailedEmail)) {
$email = $this->response->userFailedEmail;
$failed = $this->users->getUser($email, "failed")+1;
- $fileNameUser = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("editUserFile");
+ $fileNameUser = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("editUserFile");
$status = $this->users->save($fileNameUser, $email, array("failed" => $failed)) ? "ok" : "error";
if ($status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
if ($failed==$this->yellow->system->get("editBruteForceProtection")) {
@@ -981,9 +971,10 @@ class YellowEdit {
// Check if request came from same site
public function isRequestSameSite($method, $scheme, $address) {
- if (preg_match("#^(\w+)://([^/]+)(.*)$#", $_SERVER["HTTP_REFERER"], $matches)) $origin = "$matches[1]://$matches[2]";
- if (isset($_SERVER["HTTP_ORIGIN"])) $origin = $_SERVER["HTTP_ORIGIN"];
- return $_SERVER["REQUEST_METHOD"]==$method && $origin=="$scheme://$address";
+ $origin = "";
+ if (preg_match("#^(\w+)://([^/]+)(.*)$#", $this->yellow->toolbox->getServer("HTTP_REFERER"), $matches)) $origin = "$matches[1]://$matches[2]";
+ if ($this->yellow->toolbox->getServer("HTTP_ORIGIN")) $origin = $this->yellow->toolbox->getServer("HTTP_ORIGIN");
+ return $this->yellow->toolbox->getServer("REQUEST_METHOD")==$method && $origin=="$scheme://$address";
}
}
@@ -1015,7 +1006,7 @@ class YellowEditResponse {
if (empty($this->rawDataSource)) $this->rawDataSource = $page->rawData;
if (empty($this->rawDataEdit)) $this->rawDataEdit = $page->rawData;
if (empty($this->rawDataEndOfLine)) $this->rawDataEndOfLine = $this->getEndOfLine($page->rawData);
- if ($page->statusCode==404 || $this->yellow->toolbox->isLocationArgs()) {
+ if ($page->statusCode==404 || $this->yellow->toolbox->isLocationArguments()) {
$this->rawDataEdit = $this->getRawDataGenerated($page);
$this->rawDataReadonly = true;
}
@@ -1279,6 +1270,9 @@ class YellowEditResponse {
// Return update information
public function getUpdateInformation() {
+ $statusCode = 200;
+ $updates = 0;
+ $rawData = "";
if ($this->yellow->extensions->isExisting("update")) {
list($statusCodeCurrent, $dataCurrent) = $this->yellow->extensions->get("update")->getExtensionsVersion();
list($statusCodeLatest, $dataLatest) = $this->yellow->extensions->get("update")->getExtensionsVersion(true);
@@ -1292,14 +1286,12 @@ class YellowEditResponse {
}
if ($updates==0) {
foreach ($dataCurrent as $key=>$value) {
- if (!is_null($dataModified[$key]) && !is_null($dataLatest[$key])) {
- $output = $this->yellow->text->getTextHtml("editUpdateModified", $this->language)." - <a href=\"#\" data-action=\"submit\" data-args=\"".$this->yellow->toolbox->normaliseArgs("action:update/extension:$key/option:force")."\">".$this->yellow->text->getTextHtml("editUpdateForce", $this->language)."</a><br />\n";
+ if (isset($dataModified[$key]) && isset($dataLatest[$key])) {
+ $output = $this->yellow->text->getTextHtml("editUpdateModified", $this->language)." - <a href=\"#\" data-action=\"submit\" data-arguments=\"".$this->yellow->toolbox->normaliseArguments("action:update/extension:$key/option:force")."\">".$this->yellow->text->getTextHtml("editUpdateForce", $this->language)."</a><br />\n";
$rawData .= preg_replace("/@extension/i", htmlspecialchars(ucfirst($key)." $dataLatest[$key]"), $output);
}
}
}
- } else {
- $statusCode = 200;
}
return array($statusCode, $updates, $rawData);
}
@@ -1313,10 +1305,11 @@ class YellowEditResponse {
// Return raw data for new page
public function getRawDataNew($page, $customTitle = false) {
+ $fileName = "";
foreach ($this->yellow->content->path($page->location)->reverse() as $ancestor) {
if ($ancestor->isExisting("layoutNew")) {
$name = $this->yellow->lookup->normaliseName($ancestor->get("layoutNew"));
- $location = $this->yellow->content->getHomeLocation($page->location).$this->yellow->system->get("coreContentSharedDir");
+ $location = $this->yellow->content->getHomeLocation($page->location).$this->yellow->system->get("coreContentSharedDirectory");
$fileName = $this->yellow->lookup->findFileFromLocation($location, true).$this->yellow->system->get("editNewFile");
$fileName = strreplaceu("(.*)", $name, $fileName);
if (is_file($fileName)) break;
@@ -1324,7 +1317,7 @@ class YellowEditResponse {
}
if (!is_file($fileName)) {
$name = $this->yellow->lookup->normaliseName($this->yellow->system->get("layout"));
- $location = $this->yellow->content->getHomeLocation($page->location).$this->yellow->system->get("coreContentSharedDir");
+ $location = $this->yellow->content->getHomeLocation($page->location).$this->yellow->system->get("coreContentSharedDirectory");
$fileName = $this->yellow->lookup->findFileFromLocation($location, true).$this->yellow->system->get("editNewFile");
$fileName = strreplaceu("(.*)", $name, $fileName);
}
@@ -1415,17 +1408,19 @@ class YellowEditResponse {
}
$prefix = $this->getPageNewPrefix($location, $pageFileName, $pagePrefix);
if ($this->yellow->lookup->isFileLocation($location)) {
- preg_match("#^(.*)\/(.+?)$#", $fileName, $matches);
- $path = $matches[1];
- $text = $this->yellow->lookup->normaliseName($matches[2], true, true);
- if (preg_match("/^[\d\-\_\.]*$/", $text)) $prefix = "";
- $fileName = $path."/".$prefix.$text.$this->yellow->system->get("coreContentExtension");
+ if (preg_match("#^(.*)\/(.+?)$#", $fileName, $matches)) {
+ $path = $matches[1];
+ $text = $this->yellow->lookup->normaliseName($matches[2], true, true);
+ if (preg_match("/^[\d\-\_\.]*$/", $text)) $prefix = "";
+ $fileName = $path."/".$prefix.$text.$this->yellow->system->get("coreContentExtension");
+ }
} else {
- preg_match("#^(.*)\/(.+?)$#", dirname($fileName), $matches);
- $path = $matches[1];
- $text = $this->yellow->lookup->normaliseName($matches[2], true, false);
- if (preg_match("/^[\d\-\_\.]*$/", $text)) $prefix = "";
- $fileName = $path."/".$prefix.$text."/".$this->yellow->system->get("coreContentDefaultFile");
+ if (preg_match("#^(.*)\/(.+?)$#", dirname($fileName), $matches)) {
+ $path = $matches[1];
+ $text = $this->yellow->lookup->normaliseName($matches[2], true, false);
+ if (preg_match("/^[\d\-\_\.]*$/", $text)) $prefix = "";
+ $fileName = $path."/".$prefix.$text."/".$this->yellow->system->get("coreContentDefaultFile");
+ }
}
}
return $fileName;
@@ -1435,11 +1430,9 @@ class YellowEditResponse {
public function getPageNewPrefix($location, $pageFileName, $pagePrefix) {
if (empty($pagePrefix)) {
if ($this->yellow->lookup->isFileLocation($location)) {
- preg_match("#^(.*)\/(.+?)$#", $pageFileName, $matches);
- $pagePrefix = $matches[2];
+ if (preg_match("#^(.*)\/(.+?)$#", $pageFileName, $matches)) $pagePrefix = $matches[2];
} else {
- preg_match("#^(.*)\/(.+?)$#", dirname($pageFileName), $matches);
- $pagePrefix = $matches[2];
+ if (preg_match("#^(.*)\/(.+?)$#", dirname($pageFileName), $matches)) $pagePrefix = $matches[2];
}
}
return $this->yellow->lookup->normalisePrefix($pagePrefix, true);
@@ -1461,11 +1454,12 @@ class YellowEditResponse {
// Return group for new file
public function getFileNewGroup($fileNameShort) {
- $path = $this->yellow->system->get("coreMediaDir");
+ $group = "none";
+ $path = $this->yellow->system->get("coreMediaDirectory");
$fileType = $this->yellow->toolbox->getFileType($fileNameShort);
- $fileName = $this->yellow->system->get(preg_match("/(gif|jpg|png|svg)$/", $fileType) ? "coreImageDir" : "coreDownloadDir").$fileNameShort;
- preg_match("#^$path(.+?)\/#", $fileName, $matches);
- return strtoloweru($matches[1]);
+ $fileName = $this->yellow->system->get(preg_match("/(gif|jpg|png|svg)$/", $fileType) ? "coreImageDirectory" : "coreDownloadDirectory").$fileNameShort;
+ if (preg_match("#^$path(.+?)\/#", $fileName, $matches)) $group = strtoloweru($matches[1]);
+ return $group;
}
// Return folder for new file
@@ -1477,18 +1471,22 @@ class YellowEditResponse {
// Return next file name
public function getFileNext($fileNameShort) {
- preg_match("/^(.*?)(\d*)(\..*?)?$/", $fileNameShort, $matches);
- $fileText = $matches[1];
- $fileNumber = strempty($matches[2]) ? "-2" : $matches[2]+1;
- $fileExtension = $matches[3];
+ $fileText = $fileNumber = $fileExtension = "";
+ if (preg_match("/^(.*?)(\d*)(\..*?)?$/", $fileNameShort, $matches)) {
+ $fileText = $matches[1];
+ $fileNumber = strempty($matches[2]) ? "-2" : $matches[2]+1;
+ $fileExtension = $matches[3];
+ }
return $fileText.$fileNumber.$fileExtension;
}
// Return next title
public function getTitleNext($rawData) {
- preg_match("/^(.*?)(\d*)$/", $this->yellow->toolbox->getMetaData($rawData, "title"), $matches);
- $titleText = $matches[1];
- $titleNumber = strempty($matches[2]) ? " 2" : $matches[2]+1;
+ $titleText = $titleNumber = "";
+ if(preg_match("/^(.*?)(\d*)$/", $this->yellow->toolbox->getMetaData($rawData, "title"), $matches)) {
+ $titleText = $matches[1];
+ $titleNumber = strempty($matches[2]) ? " 2" : $matches[2]+1;
+ }
return $titleText.$titleNumber;
}
@@ -1530,7 +1528,7 @@ class YellowEditResponse {
$mailMessage = "$message\r\n\r\n$url\r\n-- \r\n$footer";
return mail($mailTo, $mailSubject, $mailMessage, $mailHeaders);
}
-
+
// Create browser cookies
public function createCookies($scheme, $address, $base, $email) {
$expire = time() + $this->yellow->system->get("editLoginSessionTimeout");
@@ -1617,25 +1615,28 @@ class YellowEditUsers {
$fileData = $this->yellow->toolbox->readFile($fileName);
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
if (preg_match("/^\#/", $line)) continue;
- preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
- if (lcfirst($matches[1])=="email" && !strempty($matches[2])) {
- $email = $matches[2];
- if (defined("DEBUG") && DEBUG>=3) echo "YellowEditUsers::load email:$email<br/>\n";
- }
- if (!empty($email) && !empty($matches[1]) && !strempty($matches[2])) {
- $this->setUser($email, $matches[1], $matches[2]);
+ if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
+ if (lcfirst($matches[1])=="email" && !strempty($matches[2])) {
+ $email = $matches[2];
+ if (defined("DEBUG") && DEBUG>=3) echo "YellowEditUsers::load email:$email<br/>\n";
+ }
+ if (!empty($email) && !empty($matches[1]) && !strempty($matches[2])) {
+ $this->setUser($email, $matches[1], $matches[2]);
+ }
}
}
}
// Save user to file
public function save($fileName, $email, $settings) {
+ $scan = false;
$fileData = $this->yellow->toolbox->readFile($fileName);
$fileDataStart = $fileDataMiddle = $fileDataEnd = "";
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
- preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
- if (lcfirst($matches[1])=="email" && !strempty($matches[2])) {
- $scan = $matches[2]==$email;
+ if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
+ if (lcfirst($matches[1])=="email" && !strempty($matches[2])) {
+ $scan = $matches[2]==$email;
+ }
}
if (!$scan && empty($fileDataMiddle)) {
$fileDataStart .= $line;
@@ -1653,19 +1654,21 @@ class YellowEditUsers {
$settingsNew[$key] = $value;
}
}
+ $fileDataSettings = "";
foreach ($this->yellow->toolbox->getTextLines($fileDataMiddle) as $line) {
- preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
- if (!empty($matches[1]) && !is_null($settingsNew[$matches[1]])) {
- $fileDataSettings .= "$matches[1]: ".$settingsNew[$matches[1]]."\n";
- unset($settingsNew[$matches[1]]);
- } else {
- $fileDataSettings .= $line;
+ if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
+ if (!empty($matches[1]) && isset($settingsNew[$matches[1]])) {
+ $fileDataSettings .= "$matches[1]: ".$settingsNew[$matches[1]]."\n";
+ unset($settingsNew[$matches[1]]);
+ continue;
+ }
}
+ $fileDataSettings .= $line;
}
foreach ($settingsNew as $key=>$value) {
$fileDataSettings .= ucfirst($key).": $value\n";
}
- if(!empty($fileDataSettings)) {
+ if (!empty($fileDataSettings)) {
$fileDataSettings = preg_replace("/\n+/", "\n", $fileDataSettings);
if (!empty($fileDataStart) && substr($fileDataStart, -2)!="\n\n") $fileDataSettings = "\n".$fileDataSettings;
if (!empty($fileDataEnd)) $fileDataSettings .= "\n";
@@ -1676,12 +1679,14 @@ class YellowEditUsers {
// Remove user from file
public function remove($fileName, $email) {
+ $scan = false;
$fileData = $this->yellow->toolbox->readFile($fileName);
$fileDataStart = $fileDataMiddle = $fileDataEnd = "";
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
- preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
- if (lcfirst($matches[1])=="email" && !strempty($matches[2])) {
- $scan = $matches[2]==$email;
+ if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
+ if (lcfirst($matches[1])=="email" && !strempty($matches[2])) {
+ $scan = $matches[2]==$email;
+ }
}
if (!$scan && empty($fileDataMiddle)) {
$fileDataStart .= $line;
@@ -1691,20 +1696,20 @@ class YellowEditUsers {
$fileDataEnd .= $line;
}
}
- unset($this->users[$email]);
+ if (isset($this->users[$email])) unset($this->users[$email]);
$fileDataNew = rtrim($fileDataStart.$fileDataEnd)."\n";
return $this->yellow->toolbox->createFile($fileName, $fileDataNew);
}
// Set user setting
public function setUser($email, $key, $value) {
- if (is_null($this->users[$email])) $this->users[$email] = new YellowDataCollection();
+ if (!isset($this->users[$email])) $this->users[$email] = new YellowDataCollection();
$this->users[$email][$key] = $value;
}
// Return user setting
public function getUser($email, $key) {
- return !is_null($this->users[$email]) && !is_null($this->users[$email][$key]) ? $this->users[$email][$key] : "";
+ return isset($this->users[$email]) && isset($this->users[$email][$key]) ? $this->users[$email][$key] : "";
}
// Check user authentication from email and password
@@ -1715,13 +1720,13 @@ class YellowEditUsers {
}
// Check user authentication from tokens
- public function checkAuthToken($authToken, $csrfTokenExpected, $csrfTokenReceived, $ignoreCsrfToken) {
+ public function checkAuthToken($authToken, $csrfTokenExpected, $csrfTokenReceived, $csrfTokenIrrelevant) {
$signature = "$5y$".substrb($authToken, 0, 96);
$email = $this->getAuthEmail($authToken);
$expire = $this->getAuthExpire($authToken);
return $expire>time() && $this->isExisting($email) && $this->users[$email]["status"]=="active" &&
$this->yellow->toolbox->verifyHash($this->users[$email]["hash"]."auth".$expire, "sha256", $signature) &&
- ($this->yellow->toolbox->verifyToken($csrfTokenExpected, $csrfTokenReceived) || $ignoreCsrfToken);
+ ($this->yellow->toolbox->verifyToken($csrfTokenExpected, $csrfTokenReceived) || $csrfTokenIrrelevant);
}
// Check action token
@@ -1730,7 +1735,7 @@ class YellowEditUsers {
return $expire>time() && $this->isExisting($email) &&
$this->yellow->toolbox->verifyHash($this->users[$email]["hash"].$action.$expire, "sha256", $signature);
}
-
+
// Create authentication token
public function createAuthToken($email, $expire) {
$signature = $this->yellow->toolbox->createHash($this->users[$email]["hash"]."auth".$expire, "sha256");
@@ -1770,6 +1775,7 @@ class YellowEditUsers {
// Return user email from authentication, timing attack safe email lookup
public function getAuthEmail($authToken, $stamp = "") {
+ $email = "";
if (empty($stamp)) $stamp = substrb($authToken, 96, 20);
foreach ($this->users as $key=>$value) {
if ($this->yellow->toolbox->verifyToken($value["stamp"], $stamp)) $email = $key;
@@ -1812,7 +1818,7 @@ class YellowEditUsers {
// Check if user exists
public function isExisting($email) {
- return !is_null($this->users[$email]);
+ return isset($this->users[$email]);
}
}
@@ -1967,6 +1973,7 @@ class YellowEditMerge {
// Return merged text, null if not possible
public function getOutput($diff, $showDiff = false) {
$output = "";
+ $conflict = false;
if (!$showDiff) {
for ($i=0; $i<count($diff); ++$i) {
if ($diff[$i][0]!=YellowEditMerge::REMOVE) $output .= $diff[$i][1];
diff --git a/system/extensions/image.php b/system/extensions/image.php
@@ -4,7 +4,7 @@
// This file may be used and distributed under the terms of the public license.
class YellowImage {
- const VERSION = "0.8.7";
+ const VERSION = "0.8.8";
const TYPE = "feature";
public $yellow; //access to API
@@ -16,7 +16,7 @@ class YellowImage {
$this->yellow->system->setDefault("imageUploadHeightMax", "1280");
$this->yellow->system->setDefault("imageUploadJpgQuality", "80");
$this->yellow->system->setDefault("imageThumbnailLocation", "/media/thumbnails/");
- $this->yellow->system->setDefault("imageThumbnailDir", "media/thumbnails/");
+ $this->yellow->system->setDefault("imageThumbnailDirectory", "media/thumbnails/");
$this->yellow->system->setDefault("imageThumbnailJpgQuality", "80");
}
@@ -24,12 +24,12 @@ class YellowImage {
public function onParseContentShortcut($page, $name, $text, $type) {
$output = null;
if ($name=="image" && $type=="inline") {
- list($name, $alt, $style, $width, $height) = $this->yellow->toolbox->getTextArgs($text);
+ list($name, $alt, $style, $width, $height) = $this->yellow->toolbox->getTextArguments($text);
if (!preg_match("/^\w+:/", $name)) {
if (empty($alt)) $alt = $this->yellow->system->get("imageAlt");
if (empty($width)) $width = "100%";
if (empty($height)) $height = $width;
- list($src, $width, $height) = $this->getImageInformation($this->yellow->system->get("coreImageDir").$name, $width, $height);
+ list($src, $width, $height) = $this->getImageInformation($this->yellow->system->get("coreImageDirectory").$name, $width, $height);
} else {
if (empty($alt)) $alt = $this->yellow->system->get("imageAlt");
$src = $this->yellow->lookup->normaliseUrl("", "", "", $name);
@@ -64,21 +64,19 @@ class YellowImage {
}
// Handle command
- public function onCommand($args) {
- list($command) = $args;
+ public function onCommand($command, $text) {
switch ($command) {
- case "clean": $statusCode = $this->processCommandClean($args); break;
+ case "clean": $statusCode = $this->processCommandClean($command, $text); break;
default: $statusCode = 0;
}
return $statusCode;
}
// Process command to clean thumbnails
- public function processCommandClean($args) {
+ public function processCommandClean($command, $text) {
$statusCode = 0;
- list($command, $path) = $args;
- if ($path=="all") {
- $path = $this->yellow->system->get("imageThumbnailDir");
+ if ($command=="clean" && $text=="all") {
+ $path = $this->yellow->system->get("imageThumbnailDirectory");
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", false, false) as $entry) {
if (!$this->yellow->toolbox->deleteFile($entry)) $statusCode = 500;
}
@@ -89,7 +87,7 @@ class YellowImage {
// Return image info, create thumbnail on demand
public function getImageInformation($fileName, $widthOutput, $heightOutput) {
- $fileNameShort = substru($fileName, strlenu($this->yellow->system->get("coreImageDir")));
+ $fileNameShort = substru($fileName, strlenu($this->yellow->system->get("coreImageDirectory")));
list($widthInput, $heightInput, $type) = $this->yellow->toolbox->detectImageInformation($fileName);
$widthOutput = $this->convertValueAndUnit($widthOutput, $widthInput);
$heightOutput = $this->convertValueAndUnit($heightOutput, $heightInput);
@@ -101,7 +99,7 @@ class YellowImage {
$fileNameThumb = ltrim(str_replace(array("/", "\\", "."), "-", dirname($fileNameShort)."/".pathinfo($fileName, PATHINFO_FILENAME)), "-");
$fileNameThumb .= "-".$widthOutput."x".$heightOutput;
$fileNameThumb .= ".".pathinfo($fileName, PATHINFO_EXTENSION);
- $fileNameOutput = $this->yellow->system->get("imageThumbnailDir").$fileNameThumb;
+ $fileNameOutput = $this->yellow->system->get("imageThumbnailDirectory").$fileNameThumb;
if ($this->isFileNotUpdated($fileName, $fileNameOutput)) {
$image = $this->loadImage($fileName, $type);
$image = $this->resizeImage($image, $widthInput, $heightInput, $widthOutput, $heightOutput);
diff --git a/system/extensions/meta.php b/system/extensions/meta.php
@@ -4,7 +4,7 @@
// This file may be used and distributed under the terms of the public license.
class YellowMeta {
- const VERSION = "0.8.11";
+ const VERSION = "0.8.12";
const TYPE = "feature";
public $yellow; //access to API
@@ -20,7 +20,7 @@ class YellowMeta {
if ($name=="header" && !$page->isError()) {
list($imageUrl, $imageAlt) = $this->getImageInformation($page);
$locale = $this->yellow->text->getText("languageLocale", $page->get("language"));
- $output .= "<meta property=\"og:url\" content=\"".htmlspecialchars($page->getUrl().$this->yellow->toolbox->getLocationArgs())."\" />\n";
+ $output .= "<meta property=\"og:url\" content=\"".htmlspecialchars($page->getUrl().$this->yellow->toolbox->getLocationArguments())."\" />\n";
$output .= "<meta property=\"og:locale\" content=\"".htmlspecialchars($locale)."\" />\n";
$output .= "<meta property=\"og:type\" content=\"website\" />\n";
$output .= "<meta property=\"og:title\" content=\"".$page->getHtml("title")."\" />\n";
@@ -47,7 +47,7 @@ class YellowMeta {
$name = $page->get("image");
$alt = $page->isExisting("imageAlt") ? $page->get("imageAlt") : $page->get("title");
} elseif (preg_match("/\[image(\s.*?)\]/", $page->getContent(true), $matches)) {
- list($name, $alt) = $this->yellow->toolbox->getTextArgs(trim($matches[1]));
+ list($name, $alt) = $this->yellow->toolbox->getTextArguments(trim($matches[1]));
if (empty($alt)) $alt = $page->get("title");
} else {
$name = $this->yellow->system->get("metaDefaultImage");
diff --git a/system/extensions/stockholm.php b/system/extensions/stockholm.php
@@ -4,7 +4,7 @@
// This file may be used and distributed under the terms of the public license.
class YellowStockholm {
- const VERSION = "0.8.7";
+ const VERSION = "0.8.8";
const TYPE = "theme";
public $yellow; //access to API
@@ -15,7 +15,7 @@ class YellowStockholm {
// Handle update
public function onUpdate($action) {
- $fileName = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("coreSystemFile");
+ $fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreSystemFile");
if ($action=="install") {
$this->yellow->system->save($fileName, array("theme" => "stockholm"));
} elseif ($action=="uninstall" && $this->yellow->system->get("theme")=="stockholm") {
diff --git a/system/extensions/update.php b/system/extensions/update.php
@@ -4,7 +4,7 @@
// This file may be used and distributed under the terms of the public license.
class YellowUpdate {
- const VERSION = "0.8.19";
+ const VERSION = "0.8.20";
const TYPE = "feature";
const PRIORITY = "2";
public $yellow; //access to API
@@ -14,7 +14,7 @@ class YellowUpdate {
public function onLoad($yellow) {
$this->yellow = $yellow;
$this->yellow->system->setDefault("updateExtensionUrl", "https://github.com/datenstrom/yellow-extensions");
- $this->yellow->system->setDefault("updateExtensionDir", "/Users/yourname/Documents/GitHub/");
+ $this->yellow->system->setDefault("updateExtensionDirectory", "/Users/yourname/Documents/GitHub/");
$this->yellow->system->setDefault("updateExtensionFile", "extension.ini");
$this->yellow->system->setDefault("updateVersionFile", "version.ini");
$this->yellow->system->setDefault("updateWaffleFile", "waffle.ini");
@@ -31,16 +31,15 @@ class YellowUpdate {
}
// Handle command
- public function onCommand($args) {
+ public function onCommand($command, $text) {
$statusCode = 0;
if ($this->isExtensionPending()) $statusCode = $this->processCommandPending();
if ($statusCode==0) {
- list($command) = $args;
switch ($command) {
- case "clean": $statusCode = $this->processCommandClean($args); break;
- case "install": $statusCode = $this->processCommandInstall($args); break;
- case "uninstall": $statusCode = $this->processCommandUninstall($args); break;
- case "update": $statusCode = $this->processCommandUpdate($args); break;
+ case "clean": $statusCode = $this->processCommandClean($command, $text); break;
+ case "install": $statusCode = $this->processCommandInstall($command, $text); break;
+ case "uninstall": $statusCode = $this->processCommandUninstall($command, $text); break;
+ case "update": $statusCode = $this->processCommandUpdate($command, $text); break;
default: $statusCode = 0; break;
}
}
@@ -62,7 +61,7 @@ class YellowUpdate {
$coreStaticUrl = $this->yellow->system->get("staticUrl");
$coreServerUrl = empty($this->yellow->system->get("serverUrl")) ? "auto" : $this->yellow->system->get("serverUrl");
$coreServerTimezone = $this->yellow->system->get("timezone");
- $fileName = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("coreSystemFile");
+ $fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreSystemFile");
$this->yellow->system->save($fileName, array("coreStaticUrl" => $coreStaticUrl, "coreServerUrl" => $coreServerUrl,
"coreServerTimezone" => $coreServerTimezone));
}
@@ -70,9 +69,9 @@ class YellowUpdate {
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("coreSettingDir").$this->yellow->system->get("coreSystemFile");
+ $fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreSystemFile");
$this->yellow->system->save($fileName, array("coreMultiLanguageMode" => $coreMultiLanguageMode));
- $path = $this->yellow->system->get("coreContentDir");
+ $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;
@@ -102,7 +101,7 @@ class YellowUpdate {
if ($action=="update") { //TODO: remove later, converts old layout files
if ($this->yellow->system->isExisting("navigation")) {
$navigation = $this->yellow->system->get("navigation");
- $path = $this->yellow->system->get("coreLayoutDir");
+ $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("system->get(\"serverScheme\")", "system->get(\"coreServerScheme\")", $fileDataNew);
@@ -132,7 +131,7 @@ class YellowUpdate {
if (method_exists($value["obj"], "onUpdate")) $value["obj"]->onUpdate($action);
}
}
- $fileName = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("coreSystemFile");
+ $fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreSystemFile");
$this->yellow->system->save($fileName, array("updateNotification" => "none"));
$fileData = $this->yellow->toolbox->readFile($fileName);
$fileDataHeader = $fileDataSettings = $fileDataFooter = "";
@@ -142,7 +141,7 @@ class YellowUpdate {
preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
if (empty($fileDataHeader) && preg_match("/^\#/", $line)) {
$fileDataHeader = $line;
- } elseif (!empty($matches[1]) && !empty($matches[2]) && isset($settings[$matches[1]])) {
+ } elseif (!empty($matches[1]) && isset($settings[$matches[1]])) {
$settings[$matches[1]] = $matches[2];
} elseif (!empty($matches[1]) && substru($matches[1], 0, 1)!="#") {
$fileDataFooter .= "# $line";
@@ -166,11 +165,10 @@ class YellowUpdate {
}
// Process command to clean downloads
- public function processCommandClean($args) {
+ public function processCommandClean($command, $text) {
$statusCode = 0;
- list($command, $path) = $args;
- if ($path=="all") {
- $path = $this->yellow->system->get("coreExtensionDir");
+ if ($command=="clean" && $text=="all") {
+ $path = $this->yellow->system->get("coreExtensionDirectory");
$regex = "/^.*\\".$this->yellow->system->get("coreDownloadExtension")."$/";
foreach ($this->yellow->toolbox->getDirectoryEntries($path, $regex, false, false) as $entry) {
if (!$this->yellow->toolbox->deleteFile($entry)) $statusCode = 500;
@@ -181,8 +179,8 @@ class YellowUpdate {
}
// Process command to install extensions
- public function processCommandInstall($args) {
- list($command, $extensions) = $this->getExtensionInformation($args);
+ public function processCommandInstall($command, $text) {
+ list($extensions) = $this->getExtensionInformation($text);
if (!empty($extensions)) {
$this->updates = 0;
list($statusCode, $data) = $this->getInstallInformation($extensions);
@@ -198,8 +196,8 @@ class YellowUpdate {
}
// Process command to uninstall extensions
- public function processCommandUninstall($args) {
- list($command, $extensions) = $this->getExtensionInformation($args);
+ public function processCommandUninstall($command, $text) {
+ list($extensions) = $this->getExtensionInformation($text);
if (!empty($extensions)) {
$this->updates = 0;
list($statusCode, $data) = $this->getUninstallInformation($extensions, "core, command, update");
@@ -214,8 +212,8 @@ class YellowUpdate {
}
// Process command to update website
- public function processCommandUpdate($args) {
- list($command, $extensions, $force) = $this->getExtensionInformation($args);
+ public function processCommandUpdate($command, $text) {
+ list($extensions, $force) = $this->getExtensionInformation($text);
list($statusCode, $data) = $this->getUpdateInformation($extensions, $force);
if ($statusCode!=200 || !empty($data)) {
$this->updates = 0;
@@ -259,7 +257,7 @@ class YellowUpdate {
if ($updateNotification=="none") $updateNotification = "";
if (!empty($updateNotification)) $updateNotification .= ",";
$updateNotification .= "$extension/$action";
- $fileName = $this->yellow->system->get("coreSettingDir").$this->yellow->system->get("coreSystemFile");
+ $fileName = $this->yellow->system->get("coreSettingDirectory").$this->yellow->system->get("coreSystemFile");
if (!$this->yellow->system->save($fileName, array("updateNotification" => $updateNotification))) {
$statusCode = 500;
$this->yellow->page->error(500, "Can't write file '$fileName'!");
@@ -268,9 +266,8 @@ class YellowUpdate {
}
// Return extension information
- public function getExtensionInformation($args) {
- $command = array_shift($args);
- $extensions = array_unique(array_filter($args, "strlen"));
+ public function getExtensionInformation($text) {
+ $extensions = array_unique(array_filter($this->yellow->toolbox->getTextArguments($text), "strlen"));
$force = false;
foreach ($extensions as $key=>$value) {
if ($value=="force") {
@@ -278,7 +275,7 @@ class YellowUpdate {
unset($extensions[$key]);
}
}
- return array($command, $extensions, $force);
+ return array($extensions, $force);
}
// Return install information
@@ -394,7 +391,7 @@ class YellowUpdate {
// Download extensions
public function downloadExtensions($data) {
$statusCode = 200;
- $path = $this->yellow->system->get("coreExtensionDir");
+ $path = $this->yellow->system->get("coreExtensionDirectory");
$fileExtension = $this->yellow->system->get("coreDownloadExtension");
foreach ($data as $key=>$value) {
$fileName = $path.$this->yellow->lookup->normaliseName($key, true, false, true).".zip";
@@ -422,7 +419,7 @@ class YellowUpdate {
public function updateExtensions($action, $force = false) {
$statusCode = 200;
if (function_exists("opcache_reset")) opcache_reset();
- $path = $this->yellow->system->get("coreExtensionDir");
+ $path = $this->yellow->system->get("coreExtensionDirectory");
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false) as $entry) {
$statusCode = max($statusCode, $this->updateExtensionArchive($entry, $action, $force));
if (!$this->yellow->toolbox->deleteFile($entry)) {
@@ -507,7 +504,7 @@ class YellowUpdate {
}
}
if ($update) {
- if (!$this->yellow->toolbox->deleteFile($fileName, $this->yellow->system->get("coreTrashDir")) ||
+ if (!$this->yellow->toolbox->deleteFile($fileName, $this->yellow->system->get("coreTrashDirectory")) ||
!$this->yellow->toolbox->createFile($fileName, $fileData) ||
!$this->yellow->toolbox->modifyFile($fileName, $modified)) {
$statusCode = 500;
@@ -515,7 +512,7 @@ class YellowUpdate {
}
}
if ($delete) {
- if (!$this->yellow->toolbox->deleteFile($fileName, $this->yellow->system->get("coreTrashDir"))) {
+ if (!$this->yellow->toolbox->deleteFile($fileName, $this->yellow->system->get("coreTrashDirectory"))) {
$statusCode = 500;
$this->yellow->page->error($statusCode, "Can't delete file '$fileName'!");
}
@@ -546,8 +543,8 @@ class YellowUpdate {
$fileNameSource = $pathBase.basename($entry);
}
if ($this->yellow->system->get("coreMultiLanguageMode") && $this->yellow->lookup->isContentFile($fileName)) {
- $contentDirLength = strlenu($this->yellow->system->get("coreContentDir"));
- $fileNameDestination = $page->fileName.substru($fileName, $contentDirLength);
+ $contentDirectoryLength = strlenu($this->yellow->system->get("coreContentDirectory"));
+ $fileNameDestination = $page->fileName.substru($fileName, $contentDirectoryLength);
} else {
$fileNameDestination = $fileName;
}
@@ -575,7 +572,7 @@ class YellowUpdate {
$statusCode = 200;
$fileName = $this->yellow->toolbox->normaliseTokens($fileName);
if ($this->yellow->lookup->isValidFile($fileName) && !empty($extension)) {
- if (!$this->yellow->toolbox->deleteFile($fileName, $this->yellow->system->get("coreTrashDir"))) {
+ if (!$this->yellow->toolbox->deleteFile($fileName, $this->yellow->system->get("coreTrashDirectory"))) {
$statusCode = 500;
$this->yellow->page->error($statusCode, "Can't delete file '$fileName'!");
}
@@ -693,7 +690,7 @@ class YellowUpdate {
// Check if extension pending
public function isExtensionPending() {
- $path = $this->yellow->system->get("coreExtensionDir");
+ $path = $this->yellow->system->get("coreExtensionDirectory");
return count($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", false, false))>0;
}
}
diff --git a/system/layouts/pagination.html b/system/layouts/pagination.html
@@ -1,4 +1,4 @@
-<?php list($name, $pages) = $this->yellow->getLayoutArgs() ?>
+<?php list($name, $pages) = $this->yellow->getLayoutArguments() ?>
<?php if ($pages->isPagination()): ?>
<div class="pagination" role="navigation">
<?php if ($pages->getPaginationPrevious()): ?>
diff --git a/system/settings/system.ini b/system/settings/system.ini
@@ -12,9 +12,9 @@ Status: public
CoreStaticUrl: https://mikuli.cz/
CoreStaticDefaultFile: index.html
CoreStaticErrorFile: 404.html
-CoreStaticDir: public/
-CoreCacheDir: cache/
-CoreTrashDir: system/trash/
+CoreStaticDirectory: public/
+CoreCacheDirectory: cache/
+CoreTrashDirectory: system/trash/
CoreServerUrl: auto
CoreServerTimezone: UTC
CoreMultiLanguageMode: 0
@@ -23,18 +23,18 @@ CoreDownloadLocation: /media/downloads/
CoreImageLocation: /media/images/
CoreExtensionLocation: /media/extensions/
CoreResourceLocation: /media/resources/
-CoreMediaDir: media/
-CoreDownloadDir: media/downloads/
-CoreImageDir: media/images/
-CoreSystemDir: system/
-CoreExtensionDir: system/extensions/
-CoreLayoutDir: system/layouts/
-CoreResourceDir: system/resources/
-CoreSettingDir: system/settings/
-CoreContentDir: content/
-CoreContentRootDir: default/
-CoreContentHomeDir: home/
-CoreContentSharedDir: shared/
+CoreMediaDirectory: media/
+CoreDownloadDirectory: media/downloads/
+CoreImageDirectory: media/images/
+CoreSystemDirectory: system/
+CoreExtensionDirectory: system/extensions/
+CoreLayoutDirectory: system/layouts/
+CoreResourceDirectory: system/resources/
+CoreSettingDirectory: system/settings/
+CoreContentDirectory: content/
+CoreContentRootDirectory: default/
+CoreContentHomeDirectory: home/
+CoreContentSharedDirectory: shared/
CoreContentDefaultFile: page.md
CoreContentErrorFile: page-error-(.*).md
CoreContentExtension: .md
@@ -42,7 +42,7 @@ CoreDownloadExtension: .download
CoreTextFile: text.ini
CoreLogFile: yellow.log
UpdateExtensionUrl: https://github.com/datenstrom/yellow-extensions
-UpdateExtensionDir: /Users/yourname/Documents/GitHub/
+UpdateExtensionDirectory: /Users/yourname/Documents/GitHub/
UpdateExtensionFile: extension.ini
UpdateVersionFile: version.ini
UpdateWaffleFile: waffle.ini
@@ -68,6 +68,6 @@ ImageUploadWidthMax: 1280
ImageUploadHeightMax: 1280
ImageUploadJpgQuality: 80
ImageThumbnailLocation: /media/thumbnails/
-ImageThumbnailDir: media/thumbnails/
+ImageThumbnailDirectory: media/thumbnails/
ImageThumbnailJpgQuality: 80
MetaDefaultImage: icon
diff --git a/yellow.php b/yellow.php
@@ -12,5 +12,5 @@ if (PHP_SAPI!="cli") {
} else {
$yellow = new YellowCore();
$yellow->load();
- exit($yellow->command($argv[1], $argv[2], $argv[3], $argv[4], $argv[5], $argv[6], $argv[7]));
+ exit($yellow->command());
}