commit 8b2507510709b1a3f6572b9edb7162b2cc6851a1
parent a7a6a1de6f7d987983b2e7799b58e2ab02a2f542
Author: markseu <mark2011@mayberg.se>
Date: Fri, 4 Nov 2022 08:59:40 +0100
Updated API, new way of checking variables
Diffstat:
12 files changed, 348 insertions(+), 317 deletions(-)
diff --git a/system/extensions/command.php b/system/extensions/command.php
@@ -2,7 +2,7 @@
// Command extension, https://github.com/annaesvensson/yellow-command
class YellowCommand {
- const VERSION = "0.8.43";
+ const VERSION = "0.8.44";
public $yellow; // access to API
public $files; // number of files
public $links; // number of links
@@ -43,7 +43,7 @@ class YellowCommand {
public function processCommandBuild($command, $text) {
$statusCode = 0;
list($path, $location) = $this->yellow->toolbox->getTextArguments($text);
- if (empty($location) || substru($location, 0, 1)=="/") {
+ if (is_string_empty($location) || substru($location, 0, 1)=="/") {
if ($this->checkStaticSettings()) {
$statusCode = $this->buildStaticFiles($path, $location);
} else {
@@ -64,10 +64,10 @@ class YellowCommand {
// Build static files
public function buildStaticFiles($path, $locationFilter) {
- $path = rtrim(empty($path) ? $this->yellow->system->get("commandStaticBuildDirectory") : $path, "/");
+ $path = rtrim(is_string_empty($path) ? $this->yellow->system->get("commandStaticBuildDirectory") : $path, "/");
$this->files = $this->errors = 0;
$this->locationsArguments = $this->locationsArgumentsPagination = array();
- $statusCode = empty($locationFilter) ? $this->cleanStaticFiles($path, $locationFilter) : 200;
+ $statusCode = is_string_empty($locationFilter) ? $this->cleanStaticFiles($path, $locationFilter) : 200;
$staticUrl = $this->yellow->system->get("coreStaticUrl");
list($scheme, $address, $base) = $this->yellow->lookup->getUrlInformation($staticUrl);
$locations = $this->getContentLocations();
@@ -95,7 +95,7 @@ class YellowCommand {
if ($statusCodeLocation==100) break;
}
}
- if (empty($locationFilter)) {
+ if (is_string_empty($locationFilter)) {
foreach ($this->getMediaLocations() as $location) {
$statusCode = max($statusCode, $this->buildStaticFile($path, $location));
}
@@ -143,7 +143,7 @@ class YellowCommand {
// Request static file
public function requestStaticFile($scheme, $address, $base, $location) {
list($serverName, $serverPort) = $this->yellow->toolbox->getTextList($address, ":", 2);
- if (empty($serverPort)) $serverPort = $scheme=="https" ? 443 : 80;
+ if (is_string_empty($serverPort)) $serverPort = $scheme=="https" ? 443 : 80;
$_SERVER["SERVER_PROTOCOL"] = "HTTP/1.1";
$_SERVER["SERVER_NAME"] = $serverName;
$_SERVER["SERVER_PORT"] = $serverPort;
@@ -229,7 +229,7 @@ class YellowCommand {
public function processCommandCheck($command, $text) {
$statusCode = 0;
list($path, $location) = $this->yellow->toolbox->getTextArguments($text);
- if (empty($location) || substru($location, 0, 1)=="/") {
+ if (is_string_empty($location) || substru($location, 0, 1)=="/") {
if ($this->checkStaticSettings()) {
$statusCode = $this->checkStaticFiles($path, $location);
} else {
@@ -250,7 +250,7 @@ class YellowCommand {
// Check static files for broken links
public function checkStaticFiles($path, $locationFilter) {
- $path = rtrim(empty($path) ? $this->yellow->system->get("commandStaticBuildDirectory") : $path, "/");
+ $path = rtrim(is_string_empty($path) ? $this->yellow->system->get("commandStaticBuildDirectory") : $path, "/");
$this->links = $this->errors = 0;
$regex = "/^[^.]+$|".$this->yellow->system->get("commandStaticDefaultFile")."$/";
$fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($path, $regex, false, false);
@@ -267,7 +267,7 @@ class YellowCommand {
public function analyseLinks($path, $locationFilter, $fileNames) {
$statusCode = 200;
$links = array();
- if (!empty($fileNames)) {
+ if (!is_array_empty($fileNames)) {
$staticUrl = $this->yellow->system->get("coreStaticUrl");
list($scheme, $address, $base) = $this->yellow->lookup->getUrlInformation($staticUrl);
foreach ($fileNames as $fileName) {
@@ -280,7 +280,7 @@ class YellowCommand {
$location = rawurldecode($match);
if (preg_match("/^(.*?)#(.*)$/", $location, $tokens)) $location = $tokens[1];
if (preg_match("/^(\w+):\/\/([^\/]+)(.*)$/", $location, $matches)) {
- $url = $location.(empty($matches[3]) ? "/" : "");
+ $url = $location.(is_string_empty($matches[3]) ? "/" : "");
if (!isset($links[$url])) {
$links[$url] = $locationSource;
} else {
@@ -367,7 +367,7 @@ class YellowCommand {
// Show links
public function showLinks($data, $text) {
- if (!empty($data)) {
+ if (!is_array_empty($data)) {
echo "$text\n\n";
uksort($data, "strnatcasecmp");
$data = array_slice($data, 0, 99);
@@ -382,9 +382,9 @@ class YellowCommand {
public function processCommandClean($command, $text) {
$statusCode = 0;
list($path, $location) = $this->yellow->toolbox->getTextArguments($text);
- if (empty($location) || substru($location, 0, 1)=="/") {
+ if (is_string_empty($location) || substru($location, 0, 1)=="/") {
$statusCode = $this->cleanStaticFiles($path, $location);
- echo "Yellow $command: Static file".(empty($location) ? "s" : "")." ".($statusCode!=200 ? "not " : "")."cleaned\n";
+ echo "Yellow $command: Static file".(is_string_empty($location) ? "s" : "")." ".($statusCode!=200 ? "not " : "")."cleaned\n";
} else {
$statusCode = 400;
echo "Yellow $command: Invalid arguments\n";
@@ -395,8 +395,8 @@ class YellowCommand {
// Clean static files and directories
public function cleanStaticFiles($path, $location) {
$statusCode = 200;
- $path = rtrim(empty($path) ? $this->yellow->system->get("commandStaticBuildDirectory") : $path, "/");
- if (empty($location)) {
+ $path = rtrim(is_string_empty($path) ? $this->yellow->system->get("commandStaticBuildDirectory") : $path, "/");
+ if (is_string_empty($location)) {
foreach ($this->yellow->extension->data as $key=>$value) {
if (method_exists($value["object"], "onUpdate")) $value["object"]->onUpdate("clean");
}
@@ -458,7 +458,7 @@ class YellowCommand {
// Check static directory
public function checkStaticDirectory($path) {
$ok = false;
- if (!empty($path)) {
+ if (!is_string_empty($path)) {
if ($path==rtrim($this->yellow->system->get("commandStaticBuildDirectory"), "/")) $ok = true;
if ($path==rtrim($this->yellow->system->get("coreCacheDirectory"), "/")) $ok = true;
if ($path==rtrim($this->yellow->system->get("coreTrashDirectory"), "/")) $ok = true;
diff --git a/system/extensions/core.php b/system/extensions/core.php
@@ -2,7 +2,7 @@
// Core extension, https://github.com/annaesvensson/yellow-core
class YellowCore {
- const VERSION = "0.8.98";
+ const VERSION = "0.8.99";
const RELEASE = "0.8.21";
public $page; // current page
public $content; // content files
@@ -140,7 +140,7 @@ class YellowCore {
if ($statusCode==0) {
if ($this->lookup->isContentFile($fileName)) {
$statusCode = $this->sendPage($scheme, $address, $base, $location, $fileName, $cacheable, true);
- } elseif (!empty($fileName)) {
+ } elseif (!is_string_empty($fileName)) {
$statusCode = $this->sendFile(200, $fileName, $cacheable);
}
if (!is_readable($fileName)) $this->page->error(404);
@@ -167,7 +167,7 @@ class YellowCore {
$fileNameAbsolute = isset($error["file"]) ? $error["file"] : "";
$fileName = substru($fileNameAbsolute, strlenu($this->system->get("coreServerInstallDirectory")));
$this->log("error", "Can't parse file '$fileName'!");
- @header($this->toolbox->getHttpStatusFormatted(500));
+ $this->toolbox->sendHttpHeader($this->toolbox->getHttpStatusFormatted(500));
$troubleshooting = PHP_SAPI!="cli" ?
"<a href=\"".$this->getTroubleshootingUrl()."\">See troubleshooting</a>." : "See ".$this->getTroubleshootingUrl();
echo "<br/>\nCheck the log file. Activate the debug mode for more information. $troubleshooting\n";
@@ -176,7 +176,7 @@ class YellowCore {
// Show error message and terminate immediately
public function exitFatalError($errorMessage = "") {
- @header($this->toolbox->getHttpStatusFormatted(500));
+ $this->toolbox->sendHttpHeader($this->toolbox->getHttpStatusFormatted(500));
$troubleshooting = PHP_SAPI!="cli" ?
"<a href=\"".$this->getTroubleshootingUrl()."\">See troubleshooting</a>." : "See ".$this->getTroubleshootingUrl();
echo "$errorMessage $troubleshooting\n";
@@ -213,11 +213,11 @@ class YellowCore {
$lastModifiedFormatted = isset($headerData["Last-Modified"]) ? $headerData["Last-Modified"] : "";
if ($statusCode==200 && !isset($headerData["Cache-Control"]) && $this->toolbox->isNotModified($lastModifiedFormatted)) {
$statusCode = 304;
- @header($this->toolbox->getHttpStatusFormatted($statusCode));
+ $this->toolbox->sendHttpHeader($this->toolbox->getHttpStatusFormatted($statusCode));
} else {
- @header($this->toolbox->getHttpStatusFormatted($statusCode));
+ $this->toolbox->sendHttpHeader($this->toolbox->getHttpStatusFormatted($statusCode));
foreach ($headerData as $key=>$value) {
- @header("$key: $value");
+ $this->toolbox->sendHttpHeader("$key: $value");
}
if (!is_null($outputData)) echo $outputData;
}
@@ -229,12 +229,12 @@ class YellowCore {
$lastModifiedFormatted = $this->toolbox->getHttpDateFormatted($this->toolbox->getFileModified($fileName));
if ($statusCode==200 && $cacheable && $this->toolbox->isNotModified($lastModifiedFormatted)) {
$statusCode = 304;
- @header($this->toolbox->getHttpStatusFormatted($statusCode));
+ $this->toolbox->sendHttpHeader($this->toolbox->getHttpStatusFormatted($statusCode));
} else {
- @header($this->toolbox->getHttpStatusFormatted($statusCode));
- if (!$cacheable) @header("Cache-Control: no-cache, no-store");
- @header("Content-Type: ".$this->toolbox->getMimeContentType($fileName));
- @header("Last-Modified: ".$lastModifiedFormatted);
+ $this->toolbox->sendHttpHeader($this->toolbox->getHttpStatusFormatted($statusCode));
+ if (!$cacheable) $this->toolbox->sendHttpHeader("Cache-Control: no-cache, no-store");
+ $this->toolbox->sendHttpHeader("Content-Type: ".$this->toolbox->getMimeContentType($fileName));
+ $this->toolbox->sendHttpHeader("Last-Modified: ".$lastModifiedFormatted);
echo $this->toolbox->readFile($fileName);
}
return $statusCode;
@@ -242,10 +242,10 @@ class YellowCore {
// Send status response
public function sendStatus($statusCode, $location = "") {
- if (!empty($location)) $this->page->status($statusCode, $location);
- @header($this->toolbox->getHttpStatusFormatted($statusCode));
+ if (!is_string_empty($location)) $this->page->status($statusCode, $location);
+ $this->toolbox->sendHttpHeader($this->toolbox->getHttpStatusFormatted($statusCode));
foreach ($this->page->headerData as $key=>$value) {
- @header("$key: $value");
+ $this->toolbox->sendHttpHeader("$key: $value");
}
return $statusCode;
}
@@ -262,7 +262,7 @@ class YellowCore {
if ($statusCode!=0) break;
}
}
- if ($statusCode==0 && empty($command)) {
+ if ($statusCode==0 && is_string_empty($command)) {
$lineCounter = 0;
echo "Datenstrom Yellow is for people who make small websites. https://datenstrom.se/yellow/\n";
foreach ($this->getCommandHelp() as $line) {
@@ -334,7 +334,7 @@ class YellowCore {
// Return request information
public function getRequestInformation($scheme = "", $address = "", $base = "") {
- if (empty($scheme) && empty($address) && empty($base)) {
+ if (is_string_empty($scheme) && is_string_empty($address) && is_string_empty($base)) {
$url = $this->system->get("coreServerUrl");
if ($url=="auto" || $this->isCommandLine()) $url = $this->toolbox->detectServerUrl();
list($scheme, $address, $base) = $this->lookup->getUrlInformation($url);
@@ -347,14 +347,14 @@ class YellowCore {
}
$location = substru($this->toolbox->detectServerLocation(), strlenu($base));
$fileName = "";
- if (empty($fileName)) $fileName = $this->lookup->findFileFromMediaLocation($location);
- if (empty($fileName)) $fileName = $this->lookup->findFileFromContentLocation($location);
+ if (is_string_empty($fileName)) $fileName = $this->lookup->findFileFromMediaLocation($location);
+ if (is_string_empty($fileName)) $fileName = $this->lookup->findFileFromContentLocation($location);
return array($scheme, $address, $base, $location, $fileName);
}
// Return command information
public function getCommandInformation($line = "") {
- if (empty($line)) {
+ if (is_string_empty($line)) {
$line = $this->toolbox->getTextString(array_slice($this->toolbox->getServer("argv"), 1));
if ($this->system->get("coreDebugMode")>=3) {
echo "YellowCore::getCommandInformation $line<br/>\n";
@@ -372,7 +372,7 @@ class YellowCore {
$lines = is_array($output) ? $output : array($output);
foreach ($lines as $line) {
list($command, $dummy) = $this->toolbox->getTextList($line, " ", 2);
- if (!empty($command) && !isset($data[$command])) $data[$command] = $line;
+ if (!is_string_empty($command) && !isset($data[$command])) $data[$command] = $line;
}
}
}
@@ -513,13 +513,13 @@ class YellowPage {
public function parseMetaDataRaw($defaultKeys) {
foreach ($defaultKeys as $key) {
$value = $this->yellow->system->get($key);
- if (!empty($key) && !strempty($value)) $this->set($key, $value);
+ if (!is_string_empty($key) && !is_string_empty($value)) $this->set($key, $value);
}
if (preg_match("/^(\xEF\xBB\xBF)?\-\-\-[\r\n]+(.+?)\-\-\-[\r\n]+/s", $this->rawData, $parts)) {
$this->metaDataOffsetBytes = strlenb($parts[0]);
foreach (preg_split("/[\r\n]+/", $parts[2]) as $line) {
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (!empty($matches[1]) && !strempty($matches[2])) $this->set($matches[1], $matches[2]);
+ if (!is_string_empty($matches[1]) && !is_string_empty($matches[2])) $this->set($matches[1], $matches[2]);
}
}
} elseif (preg_match("/^(\xEF\xBB\xBF)?([^\r\n]+)[\r\n]+=+[\r\n]+/", $this->rawData, $parts)) {
@@ -565,7 +565,7 @@ class YellowPage {
}
if (!$this->isExisting("description")) {
$description = $this->yellow->toolbox->createTextDescription($this->parserData, 150);
- $this->set("description", !empty($description) ? $description : $this->get("title"));
+ $this->set("description", !is_string_empty($description) ? $description : $this->get("title"));
}
if ($this->yellow->system->get("coreDebugMode")>=3) {
echo "YellowPage::parseContent location:".$this->location."<br/>\n";
@@ -587,7 +587,7 @@ class YellowPage {
$output = $this->errorMessage;
}
}
- if ($this->yellow->system->get("coreDebugMode")>=3 && !empty($name)) {
+ if ($this->yellow->system->get("coreDebugMode")>=3 && !is_string_empty($name)) {
echo "YellowPage::parseContentShortcut name:$name type:$type<br/>\n";
}
return $output;
@@ -686,7 +686,7 @@ class YellowPage {
// Return page setting as language specific date
public function getDate($key, $format = "") {
- if (!empty($format)) {
+ if (!is_string_empty($format)) {
$format = $this->yellow->language->getText($format);
} else {
$format = $this->yellow->language->getText("coreDateFormatMedium");
@@ -701,7 +701,7 @@ class YellowPage {
// Return page setting as language specific date, relative to today
public function getDateRelative($key, $format = "", $daysLimit = 30) {
- if (!empty($format)) {
+ if (!is_string_empty($format)) {
$format = $this->yellow->language->getText($format);
} else {
$format = $this->yellow->language->getText("coreDateFormatMedium");
@@ -908,7 +908,7 @@ class YellowPage {
$statusCode = $this->statusCode;
if ($httpFormat) {
$statusCode = $this->yellow->toolbox->getHttpStatusFormatted($statusCode);
- if (!empty($this->errorMessage)) $statusCode .= ": ".$this->errorMessage;
+ if (!is_string_empty($this->errorMessage)) $statusCode .= ": ".$this->errorMessage;
}
return $statusCode;
}
@@ -919,7 +919,7 @@ class YellowPage {
$this->statusCode = $statusCode;
$this->lastModified = 0;
$this->headerData = array();
- if (!empty($location)) {
+ if (!is_string_empty($location)) {
$this->setHeader("Location", $location);
$this->setHeader("Cache-Control", "no-cache, no-store");
}
@@ -929,9 +929,9 @@ class YellowPage {
// Respond with error page
public function error($statusCode, $errorMessage = "") {
- if ($statusCode>=400 && empty($this->errorMessage)) {
+ if ($statusCode>=400 && is_string_empty($this->errorMessage)) {
$this->statusCode = $statusCode;
- $this->errorMessage = empty($errorMessage) ? "Page error!" : $errorMessage;
+ $this->errorMessage = is_string_empty($errorMessage) ? "Page error!" : $errorMessage;
}
}
@@ -1017,7 +1017,7 @@ class YellowPageCollection extends ArrayObject {
foreach (preg_split("/\s*,\s*/", $page->get($key)) as $pageValue) {
$pageValueLength = $exactMatch ? strlenu($pageValue) : $valueLength;
if ($value==substru(str_replace(" ", "-", strtoloweru($pageValue)), 0, $pageValueLength)) {
- if (empty($this->filterValue)) $this->filterValue = substru($pageValue, 0, $pageValueLength);
+ if (is_string_empty($this->filterValue)) $this->filterValue = substru($pageValue, 0, $pageValueLength);
array_push($array, $page);
break;
}
@@ -1062,7 +1062,7 @@ class YellowPageCollection extends ArrayObject {
$location = $page->location;
$keywords = strtoloweru($page->get("title").",".$page->get("tag").",".$page->get("author"));
$tokens = array_unique(array_filter(preg_split("/[,\s\(\)\+\-]/", $keywords), "strlen"));
- if (!empty($tokens)) {
+ if (!is_array_empty($tokens)) {
$array = array();
foreach ($this->getArrayCopy() as $page) {
$sortScore = 0;
@@ -1223,6 +1223,11 @@ class YellowPageCollection extends ArrayObject {
public function isPagination() {
return $this->paginationCount>1;
}
+
+ // Check if page collection is empty
+ public function isEmpty() {
+ return empty($this->getArrayCopy());
+ }
}
class YellowContent {
@@ -1241,7 +1246,7 @@ class YellowContent {
$scheme = $this->yellow->page->scheme;
$address = $this->yellow->page->address;
$base = $this->yellow->page->base;
- if (empty($location)) {
+ if (is_string_empty($location)) {
$rootLocations = $this->yellow->lookup->findContentRootLocations();
foreach ($rootLocations as $rootLocation=>$rootFileName) {
$page = new YellowPage($this->yellow);
@@ -1409,19 +1414,21 @@ class YellowContent {
// Return parent location
public function getParentLocation($location) {
+ $parentLocation = "";
$token = rtrim(substru($this->getRootLocation($location), 4), "/");
if (preg_match("#^($token.*\/).+?$#", $location, $matches)) {
if ($matches[1]!="$token/" || $this->yellow->lookup->isFileLocation($location)) $parentLocation = $matches[1];
}
- if (empty($parentLocation)) $parentLocation = "root$token/";
+ if (is_string_empty($parentLocation)) $parentLocation = "root$token/";
return $parentLocation;
}
// Return top-level location
public function getParentTopLocation($location) {
+ $parentTopLocation = "";
$token = rtrim(substru($this->getRootLocation($location), 4), "/");
if (preg_match("#^($token.+?\/)#", $location, $matches)) $parentTopLocation = $matches[1];
- if (empty($parentTopLocation)) $parentTopLocation = "$token/";
+ if (is_string_empty($parentTopLocation)) $parentTopLocation = "$token/";
return $parentTopLocation;
}
}
@@ -1442,7 +1449,7 @@ class YellowMedia {
$scheme = $this->yellow->page->scheme;
$address = $this->yellow->page->address;
$base = $this->yellow->system->get("coreServerBase");
- if (empty($location)) {
+ if (is_string_empty($location)) {
$fileNames = array($this->yellow->system->get("coreMediaDirectory"));
} else {
if ($this->yellow->system->get("coreDebugMode")>=2) echo "YellowMedia::scanLocation location:$location<br/>\n";
@@ -1521,7 +1528,7 @@ class YellowMedia {
if (preg_match("#^($token.*\/).+?$#", $location, $matches)) {
if ($matches[1]!="$token/" || $this->yellow->lookup->isFileLocation($location)) $parentLocation = $matches[1];
}
- if (empty($parentLocation)) $parentLocation = "";
+ if (is_string_empty($parentLocation)) $parentLocation = "";
return $parentLocation;
}
@@ -1529,7 +1536,7 @@ class YellowMedia {
public function getParentTopLocation($location) {
$token = rtrim($this->yellow->system->get("coreMediaLocation"), "/");
if (preg_match("#^($token.+?\/)#", $location, $matches)) $parentTopLocation = $matches[1];
- if (empty($parentTopLocation)) $parentTopLocation = "$token/";
+ if (is_string_empty($parentTopLocation)) $parentTopLocation = "$token/";
return $parentTopLocation;
}
}
@@ -1565,7 +1572,7 @@ class YellowSystem {
$this->modified = time();
$settingsNew = new YellowArray();
foreach ($settings as $key=>$value) {
- if (!empty($key) && !strempty($value)) {
+ if (!is_string_empty($key) && !is_string_empty($value)) {
$this->set($key, $value);
$settingsNew[$key] = $value;
}
@@ -1585,7 +1592,7 @@ class YellowSystem {
foreach ($lines as $line) {
if (preg_match("/^\#/", $line)) continue;
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (!empty($matches[1]) && !strempty($matches[2])) {
+ if (!is_string_empty($matches[1]) && !is_string_empty($matches[2])) {
$this->settingsDefaults[$matches[1]] = $matches[2];
}
}
@@ -1640,19 +1647,19 @@ class YellowSystem {
array_push($values, lcfirst(substru($entry, 0, -4)));
}
}
- return count($values) ? $values : array($valueDefault);
+ return !is_array_empty($values) ? $values : array($valueDefault);
}
public function getValues($key) { return $this->getAvailable($key); } //TODO: remove later, for backwards compatibility
// Return system settings
public function getSettings($filterStart = "", $filterEnd = "") {
$settings = array();
- if (empty($filterStart) && empty($filterEnd)) {
+ if (is_string_empty($filterStart) && is_string_empty($filterEnd)) {
$settings = array_merge($this->settingsDefaults->getArrayCopy(), $this->settings->getArrayCopy());
} else {
foreach (array_merge($this->settingsDefaults->getArrayCopy(), $this->settings->getArrayCopy()) as $key=>$value) {
- if (!empty($filterStart) && substru($key, 0, strlenu($filterStart))==$filterStart) $settings[$key] = $value;
- if (!empty($filterEnd) && substru($key, -strlenu($filterEnd))==$filterEnd) $settings[$key] = $value;
+ if (!is_string_empty($filterStart) && substru($key, 0, strlenu($filterStart))==$filterStart) $settings[$key] = $value;
+ if (!is_string_empty($filterEnd) && substru($key, -strlenu($filterEnd))==$filterEnd) $settings[$key] = $value;
}
}
return $settings;
@@ -1725,11 +1732,11 @@ class YellowLanguage {
foreach ($lines as $line) {
if (preg_match("/^\#/", $line)) continue;
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (lcfirst($matches[1])=="language" && !strempty($matches[2])) {
+ if (lcfirst($matches[1])=="language" && !is_string_empty($matches[2])) {
$language = $matches[2];
if (!isset($this->settings[$language])) $this->settings[$language] = new YellowArray();
}
- if (!empty($language) && !empty($matches[1]) && !strempty($matches[2])) {
+ if (!is_string_empty($language) && !is_string_empty($matches[1]) && !is_string_empty($matches[2])) {
$this->settings[$language][$matches[1]] = $matches[2];
$this->settingsDefaults[$matches[1]] = true;
}
@@ -1745,7 +1752,7 @@ class YellowLanguage {
// Return language setting
public function getText($key, $language = "") {
- if (empty($language)) $language = $this->language;
+ if (is_string_empty($language)) $language = $this->language;
return $this->isText($key, $language) ? $this->settings[$language][$key] : "[$key]";
}
@@ -1810,14 +1817,14 @@ class YellowLanguage {
// Return language settings
public function getSettings($filterStart = "", $filterEnd = "", $language = "") {
$settings = array();
- if (empty($language)) $language = $this->language;
+ if (is_string_empty($language)) $language = $this->language;
if (isset($this->settings[$language])) {
- if (empty($filterStart) && empty($filterEnd)) {
+ if (is_string_empty($filterStart) && is_string_empty($filterEnd)) {
$settings = $this->settings[$language]->getArrayCopy();
} else {
foreach ($this->settings[$language] as $key=>$value) {
- if (!empty($filterStart) && substru($key, 0, strlenu($filterStart))==$filterStart) $settings[$key] = $value;
- if (!empty($filterEnd) && substru($key, -strlenu($filterEnd))==$filterEnd) $settings[$key] = $value;
+ if (!is_string_empty($filterStart) && substru($key, 0, strlenu($filterStart))==$filterStart) $settings[$key] = $value;
+ if (!is_string_empty($filterEnd) && substru($key, -strlenu($filterEnd))==$filterEnd) $settings[$key] = $value;
}
}
}
@@ -1845,7 +1852,7 @@ class YellowLanguage {
// Check if language setting exists
public function isText($key, $language = "") {
- if (empty($language)) $language = $this->language;
+ if (is_string_empty($language)) $language = $this->language;
return isset($this->settings[$language]) && isset($this->settings[$language][$key]);
}
@@ -1882,7 +1889,7 @@ class YellowUser {
$settingsNew = new YellowArray();
$settingsNew["email"] = $email;
foreach ($settings as $key=>$value) {
- if (!empty($key) && !strempty($value)) {
+ if (!is_string_empty($key) && !is_string_empty($value)) {
$this->setUser($key, $value, $email);
$settingsNew[$key] = $value;
}
@@ -1914,7 +1921,7 @@ class YellowUser {
// Return user setting
public function getUser($key, $email = "") {
- if (empty($email)) $email = $this->email;
+ if (is_string_empty($email)) $email = $this->email;
return isset($this->settings[$email]) && isset($this->settings[$email][$key]) ? $this->settings[$email][$key] : "";
}
@@ -1926,7 +1933,7 @@ class YellowUser {
// Return user settings
public function getSettings($email = "") {
$settings = array();
- if (empty($email)) $email = $this->email;
+ if (is_string_empty($email)) $email = $this->email;
if (isset($this->settings[$email])) $settings = $this->settings[$email]->getArrayCopy();
return $settings;
}
@@ -1938,7 +1945,7 @@ class YellowUser {
// Check if user setting exists
public function isUser($key, $email = "") {
- if (empty($email)) $email = $this->email;
+ if (is_string_empty($email)) $email = $this->email;
return isset($this->settings[$email]) && isset($this->settings[$email][$key]);
}
@@ -2020,11 +2027,11 @@ class YellowLookup {
$pathBase = $this->yellow->system->get("coreContentDirectory");
$pathRoot = $this->yellow->system->get("coreMultiLanguageMode") ? "default/" : "";
$pathHome = "home/";
- if (!empty($pathRoot)) {
+ if (!is_string_empty($pathRoot)) {
$firstRoot = "";
$token = $root = rtrim($pathRoot, "/");
foreach ($this->yellow->toolbox->getDirectoryEntries($pathBase, "/.*/", true, true, false) as $entry) {
- if (empty($firstRoot)) $firstRoot = $token = $entry;
+ if (is_string_empty($firstRoot)) $firstRoot = $token = $entry;
if ($this->normaliseToken($entry)==$root) {
$token = $entry;
break;
@@ -2033,11 +2040,11 @@ class YellowLookup {
$pathRoot = $this->normaliseToken($token)."/";
$pathBase .= "$firstRoot/";
}
- if (!empty($pathHome)) {
+ if (!is_string_empty($pathHome)) {
$firstHome = "";
$token = $home = rtrim($pathHome, "/");
foreach ($this->yellow->toolbox->getDirectoryEntries($pathBase, "/.*/", true, true, false) as $entry) {
- if (empty($firstHome)) $firstHome = $token = $entry;
+ if (is_string_empty($firstHome)) $firstHome = $token = $entry;
if ($this->normaliseToken($entry)==$home) {
$token = $entry;
break;
@@ -2053,7 +2060,7 @@ class YellowLookup {
$language = $languageDefault;
$pathBase = $this->yellow->system->get("coreContentDirectory");
$pathRoot = $this->yellow->system->get("coreServerRootDirectory");
- if (!empty($pathRoot)) {
+ if (!is_string_empty($pathRoot)) {
$fileName = substru($fileName, strlenu($pathBase));
if (preg_match("/^(.+?)\//", $fileName, $matches)) {
$name = $this->normaliseToken($matches[1]);
@@ -2068,7 +2075,7 @@ class YellowLookup {
$rootLocations = array();
$pathBase = $this->yellow->system->get("coreContentDirectory");
$pathRoot = $this->yellow->system->get("coreServerRootDirectory");
- if (!empty($pathRoot)) {
+ if (!is_string_empty($pathRoot)) {
foreach ($this->yellow->toolbox->getDirectoryEntries($pathBase, "/.*/", true, true, false) as $entry) {
$token = $this->normaliseToken($entry)."/";
if ($token==$pathRoot) $token = "";
@@ -2097,7 +2104,7 @@ class YellowLookup {
if (substru($fileName, 0, strlenu($pathBase))==$pathBase && mb_check_encoding($fileName, "UTF-8")) {
$fileName = substru($fileName, strlenu($pathBase));
$tokens = explode("/", $fileName);
- if (!empty($pathRoot)) {
+ if (!is_string_empty($pathRoot)) {
$token = $this->normaliseToken($tokens[0])."/";
if ($token!=$pathRoot) $location .= $token;
array_shift($tokens);
@@ -2132,12 +2139,12 @@ class YellowLookup {
$fileExtension = $this->yellow->system->get("coreContentExtension");
$tokens = explode("/", $location);
if ($this->isRootLocation($location)) {
- if (!empty($pathRoot)) {
+ if (!is_string_empty($pathRoot)) {
$token = (count($tokens)>2) ? $tokens[1] : rtrim($pathRoot, "/");
$path .= $this->findFileDirectory($path, $token, "", true, true, $found, $invalid);
}
} else {
- if (!empty($pathRoot)) {
+ if (!is_string_empty($pathRoot)) {
if (count($tokens)>2) {
if ($this->normaliseToken($tokens[1])==$this->normaliseToken(rtrim($pathRoot, "/"))) $invalid = true;
$path .= $this->findFileDirectory($path, $tokens[1], "", true, false, $found, $invalid);
@@ -2158,7 +2165,7 @@ class YellowLookup {
$path .= $this->findFileDirectory($path, $tokens[0], "", true, true, $found, $invalid);
}
if (!$directory) {
- if (!strempty($tokens[$i])) {
+ if (!is_string_empty($tokens[$i])) {
$token = $tokens[$i].$fileExtension;
if ($token==$fileDefault) $invalid = true;
$path .= $this->findFileDirectory($path, $token, $fileExtension, false, true, $found, $invalid);
@@ -2290,15 +2297,15 @@ class YellowLookup {
// Normalise file/directory token
public function normaliseToken($text, $fileExtension = "", $removeExtension = false) {
- if (!empty($fileExtension)) $text = ($pos = strrposu($text, ".")) ? substru($text, 0, $pos) : $text;
- if (preg_match("/^[\d\-\_\.]+(.*)$/", $text, $matches) && !empty($matches[1])) $text = $matches[1];
+ if (!is_string_empty($fileExtension)) $text = ($pos = strrposu($text, ".")) ? substru($text, 0, $pos) : $text;
+ if (preg_match("/^[\d\-\_\.]+(.*)$/", $text, $matches) && !is_string_empty($matches[1])) $text = $matches[1];
return preg_replace("/[^\pL\d\-\_]/u", "-", $text).($removeExtension ? "" : $fileExtension);
}
// Normalise name
public function normaliseName($text, $removePrefix = false, $removeExtension = false, $filterStrict = false) {
if ($removeExtension) $text = ($pos = strrposu($text, ".")) ? substru($text, 0, $pos) : $text;
- if ($removePrefix && preg_match("/^[\d\-\_\.]+(.*)$/", $text, $matches) && !empty($matches[1])) $text = $matches[1];
+ if ($removePrefix && preg_match("/^[\d\-\_\.]+(.*)$/", $text, $matches) && !is_string_empty($matches[1])) $text = $matches[1];
if ($filterStrict) $text = strtoloweru($text);
return preg_replace("/[^\pL\d\-\_]/u", "-", $text);
}
@@ -2307,7 +2314,7 @@ class YellowLookup {
public function normalisePrefix($text) {
$prefix = "";
if (preg_match("/^([\d\-\_\.]*)(.*)$/", $text, $matches)) $prefix = $matches[1];
- if (!empty($prefix) && !preg_match("/[\-\_\.]$/", $prefix)) $prefix .= "-";
+ if (!is_string_empty($prefix) && !preg_match("/[\-\_\.]$/", $prefix)) $prefix .= "-";
return $prefix;
}
@@ -2315,7 +2322,7 @@ class YellowLookup {
public function normaliseUpperLower($input) {
$array = array();
foreach ($input as $key=>$value) {
- if (empty($key) || strempty($value)) continue;
+ if (is_string_empty($key) || is_string_empty($value)) continue;
$keySearch = strtoloweru($key);
foreach ($array as $keyNew=>$valueNew) {
if (strtoloweru($keyNew)==$keySearch) {
@@ -2419,7 +2426,7 @@ class YellowLookup {
$nested = false;
if (!$checkHomeLocation || $location==$this->yellow->content->getHomeLocation($location)) {
$path = dirname($fileName);
- if (count($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", true, true, false))) $nested = true;
+ if (!is_array_empty($this->yellow->toolbox->getDirectoryEntries($path, "/.*/", true, true, false))) $nested = true;
}
return $nested;
}
@@ -2507,17 +2514,17 @@ class YellowToolbox {
$matches[2] = $value;
$found = true;
}
- if (!empty($matches[1]) && !strempty($matches[2])) {
- if (!empty($locationArguments)) $locationArguments .= "/";
+ if (!is_string_empty($matches[1]) && !is_string_empty($matches[2])) {
+ if (!is_string_empty($locationArguments)) $locationArguments .= "/";
$locationArguments .= "$matches[1]:$matches[2]";
}
}
}
- if (!$found && !empty($key) && !strempty($value)) {
- if (!empty($locationArguments)) $locationArguments .= "/";
+ if (!$found && !is_string_empty($key) && !is_string_empty($value)) {
+ if (!is_string_empty($locationArguments)) $locationArguments .= "/";
$locationArguments .= "$key:$value";
}
- if (!empty($locationArguments)) {
+ if (!is_string_empty($locationArguments)) {
$locationArguments = $this->normaliseArguments($locationArguments, false, false);
if (!$this->isLocationArgumentsPagination($locationArguments)) $locationArguments .= "/";
}
@@ -2528,14 +2535,14 @@ class YellowToolbox {
public function getLocationArgumentsCleanUrl() {
$locationArguments = "";
foreach (array_merge($_GET, $_POST) as $key=>$value) {
- if (!empty($key) && !strempty($value)) {
- if (!empty($locationArguments)) $locationArguments .= "/";
+ if (!is_string_empty($key) && !is_string_empty($value)) {
+ if (!is_string_empty($locationArguments)) $locationArguments .= "/";
$key = str_replace(array("/", ":", "="), array("\x1c", "\x1d", "\x1e"), $key);
$value = str_replace(array("/", ":", "="), array("\x1c", "\x1d", "\x1e"), $value);
$locationArguments .= "$key:$value";
}
}
- if (!empty($locationArguments)) {
+ if (!is_string_empty($locationArguments)) {
$locationArguments = $this->normaliseArguments($locationArguments, false, false);
if (!$this->isLocationArgumentsPagination($locationArguments)) $locationArguments .= "/";
}
@@ -2597,7 +2604,7 @@ class YellowToolbox {
"woff2" => "application/font-woff2",
"xml" => "text/xml; charset=utf-8");
$fileType = $this->getFileType($fileName);
- if (empty($fileType)) {
+ if (is_string_empty($fileType)) {
$contentType = $contentTypes["html"];
} elseif (array_key_exists($fileType, $contentTypes)) {
$contentType = $contentTypes[$fileType];
@@ -2605,6 +2612,11 @@ class YellowToolbox {
return $contentType;
}
+ // Send HTTP header
+ public function sendHttpHeader($text) {
+ if (!headers_sent()) header($text);
+ }
+
// Return files and directories
public function getDirectoryEntries($path, $regex = "/.*/", $sort = true, $directories = true, $includePath = true) {
$entries = array();
@@ -2658,7 +2670,7 @@ class YellowToolbox {
$ok = false;
if ($mkdir) {
$path = dirname($fileName);
- if (!empty($path) && !is_dir($path)) @mkdir($path, 0777, true);
+ if (!is_string_empty($path) && !is_dir($path)) @mkdir($path, 0777, true);
}
$fileHandle = @fopen($fileName, "wb");
if ($fileHandle) {
@@ -2679,7 +2691,7 @@ class YellowToolbox {
$ok = false;
if ($mkdir) {
$path = dirname($fileName);
- if (!empty($path) && !is_dir($path)) @mkdir($path, 0777, true);
+ if (!is_string_empty($path) && !is_dir($path)) @mkdir($path, 0777, true);
}
$fileHandle = @fopen($fileName, "ab");
if ($fileHandle) {
@@ -2699,7 +2711,7 @@ class YellowToolbox {
clearstatcache();
if ($mkdir) {
$path = dirname($fileNameDestination);
- if (!empty($path) && !is_dir($path)) @mkdir($path, 0777, true);
+ if (!is_string_empty($path) && !is_dir($path)) @mkdir($path, 0777, true);
}
return @copy($fileNameSource, $fileNameDestination);
}
@@ -2709,7 +2721,7 @@ class YellowToolbox {
clearstatcache();
if ($mkdir) {
$path = dirname($fileNameDestination);
- if (!empty($path) && !is_dir($path)) @mkdir($path, 0777, true);
+ if (!is_string_empty($path) && !is_dir($path)) @mkdir($path, 0777, true);
}
return @rename($fileNameSource, $fileNameDestination);
}
@@ -2722,7 +2734,7 @@ class YellowToolbox {
// Delete file
public function deleteFile($fileName, $pathTrash = "") {
clearstatcache();
- if (empty($pathTrash)) {
+ if (is_string_empty($pathTrash)) {
$ok = @unlink($fileName);
} else {
if (!is_dir($pathTrash)) @mkdir($pathTrash, 0777, true);
@@ -2738,7 +2750,7 @@ class YellowToolbox {
// Delete directory
public function deleteDirectory($path, $pathTrash = "") {
clearstatcache();
- if (empty($pathTrash)) {
+ if (is_string_empty($pathTrash)) {
$iterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $file) {
@@ -2794,9 +2806,9 @@ class YellowToolbox {
}
// Return number of bytes
- public function getNumberBytes($string) {
- $bytes = intval($string);
- switch (strtoupperu(substru($string, -1))) {
+ public function getNumberBytes($text) {
+ $bytes = intval($text);
+ switch (strtoupperu(substru($text, -1))) {
case "G": $bytes *= 1024*1024*1024; break;
case "M": $bytes *= 1024*1024; break;
case "K": $bytes *= 1024; break;
@@ -2810,18 +2822,18 @@ class YellowToolbox {
foreach ($lines as &$line) {
$line = $line."\n";
}
- if (strempty($text) || substru($text, -1, 1)=="\n") array_pop($lines);
+ if (is_string_empty($text) || substru($text, -1, 1)=="\n") array_pop($lines);
return $lines;
}
//Â Return settings from text
function getTextSettings($text, $blockStart) {
$settings = new YellowArray();
- if (empty($blockStart)) {
+ if (is_string_empty($blockStart)) {
foreach ($this->getTextLines($text) as $line) {
if (preg_match("/^\#/", $line)) continue;
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (!empty($matches[1]) && !strempty($matches[2])) {
+ if (!is_string_empty($matches[1]) && !is_string_empty($matches[2])) {
$settings[$matches[1]] = $matches[2];
}
}
@@ -2831,11 +2843,11 @@ class YellowToolbox {
foreach ($this->getTextLines($text) as $line) {
if (preg_match("/^\#/", $line)) continue;
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (lcfirst($matches[1])==$blockStart && !strempty($matches[2])) {
+ if (lcfirst($matches[1])==$blockStart && !is_string_empty($matches[2])) {
$blockKey = $matches[2];
$settings[$blockKey] = new YellowArray();
}
- if (!empty($blockKey) && !empty($matches[1]) && !strempty($matches[2])) {
+ if (!is_string_empty($blockKey) && !is_string_empty($matches[1]) && !is_string_empty($matches[2])) {
$settings[$blockKey][$matches[1]] = $matches[2];
}
}
@@ -2847,10 +2859,10 @@ class YellowToolbox {
//Â Set settings in text
function setTextSettings($text, $blockStart, $blockKey, $settings) {
$textNew = "";
- if (empty($blockStart)) {
+ if (is_string_empty($blockStart)) {
foreach ($this->getTextLines($text) as $line) {
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (!empty($matches[1]) && isset($settings[$matches[1]])) {
+ if (!is_string_empty($matches[1]) && isset($settings[$matches[1]])) {
$textNew .= "$matches[1]: ".$settings[$matches[1]]."\n";
unset($settings[$matches[1]]);
continue;
@@ -2866,11 +2878,11 @@ class YellowToolbox {
$textStart = $textMiddle = $textEnd = "";
foreach ($this->getTextLines($text) as $line) {
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (lcfirst($matches[1])==$blockStart && !strempty($matches[2])) {
+ if (lcfirst($matches[1])==$blockStart && !is_string_empty($matches[2])) {
$scan = lcfirst($matches[2])==lcfirst($blockKey);
}
}
- if (!$scan && empty($textMiddle)) {
+ if (!$scan && is_string_empty($textMiddle)) {
$textStart .= $line;
} elseif ($scan) {
$textMiddle .= $line;
@@ -2881,7 +2893,7 @@ class YellowToolbox {
$textSettings = "";
foreach ($this->getTextLines($textMiddle) as $line) {
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (!empty($matches[1]) && isset($settings[$matches[1]])) {
+ if (!is_string_empty($matches[1]) && isset($settings[$matches[1]])) {
$textSettings .= "$matches[1]: ".$settings[$matches[1]]."\n";
unset($settings[$matches[1]]);
continue;
@@ -2892,11 +2904,11 @@ class YellowToolbox {
foreach ($settings as $key=>$value) {
$textSettings .= (strposu($key, "/") ? $key : ucfirst($key)).": $value\n";
}
- if (!empty($textMiddle)) {
+ if (!is_string_empty($textMiddle)) {
$textMiddle = $textSettings;
- if (!empty($textEnd)) $textMiddle .= "\n";
+ if (!is_string_empty($textEnd)) $textMiddle .= "\n";
} else {
- if (!empty($textStart)) $textEnd .= "\n";
+ if (!is_string_empty($textStart)) $textEnd .= "\n";
$textEnd .= $textSettings;
}
$textNew = $textStart.$textMiddle.$textEnd;
@@ -2907,16 +2919,16 @@ class YellowToolbox {
//Â Remove settings from text
function unsetTextSettings($text, $blockStart, $blockKey) {
$textNew = "";
- if (!empty($blockStart)) {
+ if (!is_string_empty($blockStart)) {
$scan = false;
$textStart = $textMiddle = $textEnd = "";
foreach ($this->getTextLines($text) as $line) {
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (lcfirst($matches[1])==$blockStart && !strempty($matches[2])) {
+ if (lcfirst($matches[1])==$blockStart && !is_string_empty($matches[2])) {
$scan = lcfirst($matches[2])==lcfirst($blockKey);
}
}
- if (!$scan && empty($textMiddle)) {
+ if (!$scan && is_string_empty($textMiddle)) {
$textStart .= $line;
} elseif ($scan) {
$textMiddle .= $line;
@@ -2966,7 +2978,7 @@ class YellowToolbox {
} else {
$key = $value = $tokens[$i];
}
- if (!strempty($key) && (!strempty($value) || in_array(strtolower($key), $attributesAllowEmptyString))) {
+ if (!is_string_empty($key) && (!is_string_empty($value) || in_array(strtolower($key), $attributesAllowEmptyString))) {
$attributes[$key] = $value;
}
}
@@ -2994,8 +3006,8 @@ class YellowToolbox {
$text = "";
foreach ($tokens as $token) {
if (preg_match("/\s/", $token)) $token = "\"$token\"";
- if (empty($token)) $token = $optional;
- if (!empty($text)) $text .= " ";
+ if (is_string_empty($token)) $token = $optional;
+ if (!is_string_empty($text)) $text .= " ";
$text .= $token;
}
return $text;
@@ -3035,21 +3047,21 @@ class YellowToolbox {
$elementName = isset($matches[2][0]) ? $matches[2][0] : "";
$elementAttributes = isset($matches[3][0]) ? $matches[3][0] : "";
$elementEnd = isset($matches[4][0]) ? $matches[4][0] : "";
- if (!strempty($elementBefore) && !$hiddenLevel) {
+ if (!is_string_empty($elementBefore) && !$hiddenLevel) {
$rawText = preg_replace("/\s+/s", " ", html_entity_decode($elementBefore, ENT_QUOTES, "UTF-8"));
- if (empty($elementStart) && in_array(strtolower($elementName), $elementsBlock)) $rawText = rtrim($rawText)." ";
- if (substru($rawText, 0, 1)==" " && (empty($output) || substru($output, -1)==" ")) $rawText = ltrim($rawText);
+ if (is_string_empty($elementStart) && in_array(strtolower($elementName), $elementsBlock)) $rawText = rtrim($rawText)." ";
+ if (substru($rawText, 0, 1)==" " && (is_string_empty($output) || substru($output, -1)==" ")) $rawText = ltrim($rawText);
$output .= $this->getTextTruncated($rawText, $lengthMax);
$lengthMax -= strlenu($rawText);
}
- if (!empty($elementRawData) && $elementRawData==$endMarker) {
+ if (!is_string_empty($elementRawData) && $elementRawData==$endMarker) {
$output .= $endMarkerText;
$lengthMax = 0;
}
if ($lengthMax<=0 || !$elementFound) break;
if ($hiddenLevel>0 || preg_match("/aria-hidden=\"true\"/i", $elementAttributes)) {
- if (!empty($elementName) && empty($elementEnd) && !in_array(strtolower($elementName), $elementsVoid)) {
- if (empty($elementStart)) {
+ if (!is_string_empty($elementName) && is_string_empty($elementEnd) && !in_array(strtolower($elementName), $elementsVoid)) {
+ if (is_string_empty($elementStart)) {
++$hiddenLevel;
} else {
--$hiddenLevel;
@@ -3069,17 +3081,17 @@ class YellowToolbox {
$elementStart = isset($matches[1][0]) ? $matches[1][0] : "";
$elementName = isset($matches[2][0]) ? $matches[2][0] : "";
$elementEnd = isset($matches[4][0]) ? $matches[4][0] : "";
- if (!strempty($elementBefore)) {
+ if (!is_string_empty($elementBefore)) {
$output .= $this->getTextTruncated($elementBefore, $lengthMax);
$lengthMax -= strlenu($elementBefore);
}
- if (!empty($elementRawData) && $elementRawData==$endMarker) {
+ if (!is_string_empty($elementRawData) && $elementRawData==$endMarker) {
$output .= $endMarkerText;
$lengthMax = 0;
}
if ($lengthMax<=0 || !$elementFound) break;
- if (!empty($elementName) && empty($elementEnd) && !in_array(strtolower($elementName), $elementsVoid)) {
- if (empty($elementStart)) {
+ if (!is_string_empty($elementName) && is_string_empty($elementEnd) && !in_array(strtolower($elementName), $elementsVoid)) {
+ if (is_string_empty($elementStart)) {
array_push($elementsOpen, $elementName);
} else {
array_pop($elementsOpen);
@@ -3107,10 +3119,10 @@ class YellowToolbox {
public function createSalt($length, $bcryptFormat = false) {
$dataBuffer = $salt = "";
$dataBufferSize = $bcryptFormat ? intval(ceil($length/4) * 3) : intval(ceil($length/2));
- if (empty($dataBuffer) && function_exists("random_bytes")) {
+ if (is_string_empty($dataBuffer) && function_exists("random_bytes")) {
$dataBuffer = @random_bytes($dataBufferSize);
}
- if (empty($dataBuffer) && function_exists("openssl_random_pseudo_bytes")) {
+ if (is_string_empty($dataBuffer) && function_exists("openssl_random_pseudo_bytes")) {
$dataBuffer = @openssl_random_pseudo_bytes($dataBufferSize);
}
if (strlenb($dataBuffer)==$dataBufferSize) {
@@ -3133,12 +3145,12 @@ class YellowToolbox {
case "bcrypt": $prefix = sprintf("$2y$%02d$", $cost);
$salt = $this->createSalt(22, true);
$hash = crypt($text, $prefix.$salt);
- if (empty($salt) || strlenb($hash)!=60) $hash = "";
+ if (is_string_empty($salt) || strlenb($hash)!=60) $hash = "";
break;
case "sha256": $prefix = "$5y$";
$salt = $this->createSalt(32);
$hash = "$prefix$salt".hash("sha256", $salt.$text);
- if (empty($salt) || strlenb($hash)!=100) $hash = "";
+ if (is_string_empty($salt) || strlenb($hash)!=100) $hash = "";
break;
}
return $hash;
@@ -3183,7 +3195,7 @@ class YellowToolbox {
$key = lcfirst($key);
foreach ($this->getTextLines($parts[2]) as $line) {
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (lcfirst($matches[1])==$key && !strempty($matches[2])) {
+ if (lcfirst($matches[1])==$key && !is_string_empty($matches[2])) {
$value = $matches[2];
break;
}
@@ -3261,7 +3273,7 @@ class YellowToolbox {
$_SERVER["LOCATION_ARGUMENTS"] = $matches[2];
foreach (explode("/", $matches[2]) as $token) {
if (preg_match("/^(.*?)$separator(.*)$/", $token, $matches)) {
- if (!empty($matches[1]) && !strempty($matches[2])) {
+ if (!is_string_empty($matches[1]) && !is_string_empty($matches[2])) {
$matches[1] = str_replace(array("\x1c", "\x1d", "\x1e"), array("/", ":", "="), $matches[1]);
$matches[2] = str_replace(array("\x1c", "\x1d", "\x1e"), array("/", ":", "="), $matches[2]);
$_REQUEST[$matches[1]] = $matches[2];
@@ -3288,7 +3300,7 @@ class YellowToolbox {
// Detect server timezone
public function detectServerTimezone() {
$timezone = ini_get("date.timezone");
- if (empty($timezone)) {
+ if (is_string_empty($timezone)) {
if (PHP_OS=="Darwin") {
if (preg_match("#zoneinfo/(.*)#", @readlink("/etc/localtime"), $matches)) $timezone = $matches[1];
} else {
@@ -3325,9 +3337,9 @@ class YellowToolbox {
// Detect browser language
public function detectBrowserLanguage($languages, $languageDefault) {
$languageFound = $languageDefault;
- foreach (preg_split("/\s*,\s*/", $this->getServer("HTTP_ACCEPT_LANGUAGE")) as $string) {
- list($language, $dummy) = $this->getTextList($string, ";", 2);
- if (!empty($language) && in_array($language, $languages)) {
+ foreach (preg_split("/\s*,\s*/", $this->getServer("HTTP_ACCEPT_LANGUAGE")) as $text) {
+ list($language, $dummy) = $this->getTextList($text, ";", 2);
+ if (!is_string_empty($language) && in_array($language, $languages)) {
$languageFound = $language;
break;
}
@@ -3340,11 +3352,11 @@ class YellowToolbox {
$width = $height = 0;
if (strtoupperu(substru(PHP_OS, 0, 3))=="WIN") {
exec("powershell \$Host.UI.RawUI.WindowSize.Width", $outputLines, $returnStatus);
- if ($returnStatus==0 && !empty($outputLines)) {
+ if ($returnStatus==0 && !is_array_empty($outputLines)) {
$width = intval(end($outputLines));
}
exec("powershell \$Host.UI.RawUI.WindowSize.Height", $outputLines, $returnStatus);
- if ($returnStatus==0 && !empty($outputLines)) {
+ if ($returnStatus==0 && !is_array_empty($outputLines)) {
$height = intval(end($outputLines));
}
} else {
@@ -3363,7 +3375,7 @@ class YellowToolbox {
$type = "";
$fileHandle = @fopen($fileName, "rb");
if ($fileHandle) {
- if (empty($fileType)) $fileType = $this->getFileType($fileName);
+ if (is_string_empty($fileType)) $fileType = $this->getFileType($fileName);
if ($fileType=="gif") {
$dataSignature = fread($fileHandle, 6);
$dataHeader = fread($fileHandle, 7);
@@ -3540,7 +3552,7 @@ class YellowToolbox {
}
$output .= "<$elementStart$elementName";
foreach ($elementAttributes as $key=>$value) $output .= " $key=\"$value\"";
- if (!empty($elementEnd)) $output .= " ";
+ if (!is_string_empty($elementEnd)) $output .= " ";
$output .= "$elementEnd>";
}
if (!$elementFound) break;
@@ -3606,7 +3618,7 @@ class YellowToolbox {
// Check if there are location arguments in current HTTP request
public function isLocationArguments($location = "") {
- if (empty($location)) $location = $this->getServer("LOCATION").$this->getServer("LOCATION_ARGUMENTS");
+ if (is_string_empty($location)) $location = $this->getServer("LOCATION").$this->getServer("LOCATION_ARGUMENTS");
$separator = $this->getLocationArgumentsSeparator();
return preg_match("/[^\/]+$separator.*$/", $location);
}
@@ -3624,8 +3636,8 @@ class YellowToolbox {
}
class YellowArray extends ArrayObject {
- public function __construct() {
- parent::__construct(array());
+ public function __construct($array = []) {
+ parent::__construct($array);
}
// Set array element
@@ -3670,6 +3682,11 @@ class YellowArray extends ArrayObject {
if (is_string($key)) $key = lcfirst($key);
return parent::offsetExists($key);
}
+
+ // Check if array is empty
+ public function isEmpty() {
+ return empty($this->getArrayCopy());
+ }
}
// Make string lowercase, UTF-8 compatible
@@ -3723,6 +3740,12 @@ function substrb() {
}
// Check if string is empty
-function strempty($string) {
+function is_string_empty($string) {
return is_null($string) || $string==="";
}
+function strempty($string) { return is_null($string) || $string===""; } //TODO: remove later, for backwards compatibility
+
+// Check if array is empty
+function is_array_empty($array) {
+ return is_null($array) || (is_array($array) ? empty($array) : empty($array->getArrayCopy()));
+}
diff --git a/system/extensions/edit.php b/system/extensions/edit.php
@@ -2,7 +2,7 @@
// Edit extension, https://github.com/annaesvensson/yellow-edit
class YellowEdit {
- const VERSION = "0.8.66";
+ const VERSION = "0.8.67";
public $yellow; // access to API
public $response; // web response
public $merge; // text merge
@@ -40,7 +40,7 @@ class YellowEdit {
$fileDataNew = "";
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (lcfirst($matches[1])=="email" && !strempty($matches[2])) {
+ if (lcfirst($matches[1])=="email" && !is_string_empty($matches[2])) {
$status = $this->yellow->user->getUser("status", $matches[2]);
$reserved = strtotime($this->yellow->user->getUser("modified", $matches[2])) + 60*60*24;
$cleanup = $status!="active" && $status!="inactive" && $reserved<=time();
@@ -89,8 +89,8 @@ class YellowEdit {
$output = null;
if ($name=="edit" && $type=="inline") {
list($target, $description) = $this->yellow->toolbox->getTextList($text, " ", 2);
- if (empty($target) || $target=="-") $target = "main";
- if (empty($description)) $description = ucfirst($name);
+ if (is_string_empty($target) || $target=="-") $target = "main";
+ if (is_string_empty($description)) $description = ucfirst($name);
$pageTarget = $target=="main" ? $page->getPage("main") : $page->getPage("main")->getPage($target);
$output = "<a href=\"".$pageTarget->get("pageEditUrl")."\">".htmlspecialchars($description)."</a>";
}
@@ -144,7 +144,7 @@ class YellowEdit {
}
uksort($data, "strnatcasecmp");
foreach ($data as $line) echo "$line\n";
- if (count($data)==0) echo "Yellow $command: No user accounts\n";
+ if (is_array_empty($data)) echo "Yellow $command: No user accounts\n";
return 200;
}
@@ -152,7 +152,7 @@ class YellowEdit {
public function userAdd($command, $text) {
$status = "ok";
list($option, $email, $password) = $this->yellow->toolbox->getTextArguments($text);
- if (empty($email) || empty($password)) $status = $this->response->status = "incomplete";
+ if (is_string_empty($email) || is_string_empty($password)) $status = $this->response->status = "incomplete";
if ($status=="ok") $status = $this->getUserAccount("add", $email, $password);
if ($status=="ok" && $this->isUserAccountTaken($email)) $status = "taken";
switch ($status) {
@@ -196,7 +196,7 @@ class YellowEdit {
public function userChange($command, $text) {
$status = "ok";
list($option, $email, $password) = $this->yellow->toolbox->getTextArguments($text);
- if (empty($email)) $status = $this->response->status = "invalid";
+ if (is_string_empty($email)) $status = $this->response->status = "invalid";
if ($status=="ok") $status = $this->getUserAccount("change", $email, $password);
if ($status=="ok" && !$this->yellow->user->isExisting($email)) $status = "unknown";
switch ($status) {
@@ -208,7 +208,7 @@ class YellowEdit {
if ($status=="ok") {
$fileNameUser = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreUserFile");
$settings = array(
- "hash" => empty($password) ? $this->yellow->user->getUser("hash", $email) : $this->response->createHash($password),
+ "hash" => is_string_empty($password) ? $this->yellow->user->getUser("hash", $email) : $this->response->createHash($password),
"failed" => "0",
"modified" => date("Y-m-d H:i:s", time()));
$status = $this->yellow->user->save($fileNameUser, $email, $settings) ? "ok" : "error";
@@ -223,7 +223,7 @@ class YellowEdit {
public function userRemove($command, $text) {
$status = "ok";
list($option, $email) = $this->yellow->toolbox->getTextArguments($text);
- if (empty($email)) $status = $this->response->status = "invalid";
+ if (is_string_empty($email)) $status = $this->response->status = "invalid";
if ($status=="ok") $status = $this->getUserAccount("remove", $email, "");
if ($status=="ok" && !$this->yellow->user->isExisting($email)) $status = "unknown";
switch ($status) {
@@ -345,7 +345,7 @@ class YellowEdit {
$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 (is_string_empty($name) || is_string_empty($email) || is_string_empty($password) || is_string_empty($consent)) $this->response->status = "incomplete";
if ($this->response->status=="ok") $this->response->status = $this->getUserAccount($this->response->action, $email, $password);
if ($this->response->status=="ok" && $this->response->isLoginRestriction()) $this->response->status = "next";
if ($this->response->status=="ok" && $this->isUserAccountTaken($email)) $this->response->status = "next";
@@ -445,7 +445,7 @@ class YellowEdit {
$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 (is_string_empty($password)) $this->response->status = "password";
if ($this->response->status=="ok") $this->response->status = $this->getUserAccount($this->response->action, $email, $password);
if ($this->response->status=="ok") {
$fileNameUser = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreUserFile");
@@ -510,7 +510,7 @@ class YellowEdit {
$this->response->status = $this->getUserStatus($email, $this->yellow->page->getRequest("action"));
if ($this->response->status=="ok") {
list($email, $hash) = $this->yellow->toolbox->getTextList($this->yellow->user->getUser("pending", $email), ":", 2);
- if (!$this->yellow->user->isExisting($email) || empty($hash)) $this->response->status = "done";
+ if (!$this->yellow->user->isExisting($email) || is_string_empty($hash)) $this->response->status = "done";
}
if ($this->response->status=="ok") {
$fileNameUser = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreUserFile");
@@ -542,7 +542,7 @@ class YellowEdit {
$this->response->status = "ok";
$name = trim($this->yellow->page->getRequest("name"));
$email = $this->response->userEmail;
- if (empty($name)) $this->response->status = "none";
+ if (is_string_empty($name)) $this->response->status = "none";
if ($this->response->status=="ok" && $name!=$this->yellow->user->getUser("name", $email)) $this->response->status = "mismatch";
if ($this->response->status=="ok") $this->response->status = $this->getUserAccount($this->response->action, $email, "");
if ($this->response->status=="ok") {
@@ -593,8 +593,8 @@ class YellowEdit {
$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 ($email!=$emailSource || !is_string_empty($password)) {
+ if (is_string_empty($email)) $this->response->status = "invalid";
if ($this->response->status=="ok") $this->response->status = $this->getUserAccount($this->response->action, $email, $password);
if ($this->response->status=="ok" && $email!=$emailSource && $this->isUserAccountTaken($email)) $this->response->status = "taken";
if ($this->response->status=="ok" && $email!=$emailSource) {
@@ -619,7 +619,7 @@ class YellowEdit {
$settings = array(
"name" => $name,
"language" => $language,
- "pending" => $email.":".(empty($password) ? $this->yellow->user->getUser("hash", $emailSource) : $this->response->createHash($password)),
+ "pending" => $email.":".(is_string_empty($password) ? $this->yellow->user->getUser("hash", $emailSource) : $this->response->createHash($password)),
"failed" => "0",
"modified" => date("Y-m-d H:i:s", time()));
$this->response->status = $this->yellow->user->save($fileNameUser, $emailSource, $settings) ? "ok" : "error";
@@ -657,7 +657,7 @@ class YellowEdit {
$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 (is_string_empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) $this->response->status = "invalid";
}
if ($this->response->status=="ok") {
$fileNameSystem = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile");
@@ -684,7 +684,7 @@ class YellowEdit {
$this->response->status = "ok";
if ($this->yellow->page->getRequest("option")=="check") {
list($statusCode, $rawData) = $this->response->getUpdateInformation();
- $this->response->status = empty($rawData) ? "ok" : "updates";
+ $this->response->status = is_string_empty($rawData) ? "ok" : "updates";
$this->response->rawDataOutput = $rawData;
if ($statusCode!=200) {
$this->response->status = "error";
@@ -706,7 +706,7 @@ class YellowEdit {
// Process request to create page
public function processRequestCreate($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
- if ($this->response->isUserAccess("create", $location) && !empty($this->yellow->page->getRequest("rawdataedit"))) {
+ if ($this->response->isUserAccess("create", $location) && !is_string_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");
@@ -732,7 +732,7 @@ class YellowEdit {
// Process request to edit page
public function processRequestEdit($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
- if ($this->response->isUserAccess("edit", $location) && !empty($this->yellow->page->getRequest("rawdataedit"))) {
+ if ($this->response->isUserAccess("edit", $location) && !is_string_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");
@@ -863,7 +863,7 @@ class YellowEdit {
$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 (is_string_empty($action) || $this->isRequestSameSite("POST", $scheme, $address)) {
if ($action=="login") {
$email = $this->yellow->page->getRequest("email");
$password = $this->yellow->page->getRequest("password");
@@ -876,9 +876,9 @@ class YellowEdit {
$this->response->userFailedEmail = $email;
$this->response->userFailedExpire = PHP_INT_MAX;
}
- } elseif (!empty($authToken) && !empty($csrfToken)) {
+ } elseif (!is_string_empty($authToken) && !is_string_empty($csrfToken)) {
$csrfTokenReceived = isset($_POST["csrftoken"]) ? $_POST["csrftoken"] : "";
- $csrfTokenIrrelevant = empty($action);
+ $csrfTokenIrrelevant = is_string_empty($action);
if ($this->response->checkAuthToken($authToken, $csrfToken, $csrfTokenReceived, $csrfTokenIrrelevant)) {
$this->response->userEmail = $email = $this->response->getAuthEmail($authToken);
$this->response->language = $this->getUserLanguage($email);
@@ -897,7 +897,7 @@ class YellowEdit {
public function checkUserUnauth($scheme, $address, $base, $location, $fileName) {
$ok = false;
$action = $this->yellow->page->getRequest("action");
- if (empty($action) || $action=="signup" || $action=="forgot") {
+ if (is_string_empty($action) || $action=="signup" || $action=="forgot") {
$ok = true;
} elseif ($this->yellow->page->isRequest("actiontoken")) {
$actionToken = $this->yellow->page->getRequest("actiontoken");
@@ -919,7 +919,7 @@ class YellowEdit {
// Check user failed
public function checkUserFailed($scheme, $address, $base, $location, $fileName) {
- if (!empty($this->response->userFailedError)) {
+ if (!is_string_empty($this->response->userFailedError)) {
if ($this->response->userFailedExpire>time() && $this->yellow->user->isExisting($this->response->userFailedEmail)) {
$email = $this->response->userFailedEmail;
$failed = $this->yellow->user->getUser("failed", $email)+1;
@@ -975,9 +975,9 @@ class YellowEdit {
}
if (is_null($status)) {
$status = "ok";
- if (!empty($password) && strlenu($password)<$this->yellow->system->get("editUserPasswordMinLength")) $status = "short";
- if (!empty($password) && $password==$email) $status = "weak";
- if (!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL)) $status = "invalid";
+ if (!is_string_empty($password) && strlenu($password)<$this->yellow->system->get("editUserPasswordMinLength")) $status = "short";
+ if (!is_string_empty($password) && $password==$email) $status = "weak";
+ if (!is_string_empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL)) $status = "invalid";
}
return $status;
}
@@ -1046,9 +1046,9 @@ class YellowEditResponse {
// Process page data
public function processPageData($page) {
if ($this->isUser()) {
- 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 (is_string_empty($this->rawDataSource)) $this->rawDataSource = $page->rawData;
+ if (is_string_empty($this->rawDataEdit)) $this->rawDataEdit = $page->rawData;
+ if (is_string_empty($this->rawDataEndOfLine)) $this->rawDataEndOfLine = $this->getEndOfLine($page->rawData);
if ($page->statusCode==404 || $this->yellow->toolbox->isLocationArguments()) {
$this->rawDataEdit = $this->getRawDataGenerated($page);
$this->rawDataReadonly = true;
@@ -1058,9 +1058,9 @@ class YellowEditResponse {
$this->rawDataReadonly = false;
}
}
- if (empty($this->language)) $this->language = $page->get("language");
- if (empty($this->action)) $this->action = $this->isUser() ? "none" : "login";
- if (empty($this->status)) $this->status = "none";
+ if (is_string_empty($this->language)) $this->language = $page->get("language");
+ if (is_string_empty($this->action)) $this->action = $this->isUser() ? "none" : "login";
+ if (is_string_empty($this->status)) $this->status = "none";
if ($this->status=="error") $this->action = "error";
}
@@ -1074,14 +1074,14 @@ class YellowEditResponse {
if ($this->yellow->content->find($page->location)) {
$page->location = $this->getPageNewLocation($page->rawData, $page->location, $page->get("pageNewLocation"));
$page->fileName = $this->getPageNewFile($page->location, $page->fileName, $page->get("published"));
- while ($this->yellow->content->find($page->location) || empty($page->fileName)) {
+ while ($this->yellow->content->find($page->location) || is_string_empty($page->fileName)) {
$page->rawData = $this->yellow->toolbox->setMetaData($page->rawData, "title", $this->getTitleNext($page->rawData));
$page->rawData = $this->yellow->toolbox->normaliseLines($page->rawData, $endOfLine);
$page->location = $this->getPageNewLocation($page->rawData, $page->location, $page->get("pageNewLocation"));
$page->fileName = $this->getPageNewFile($page->location, $page->fileName, $page->get("published"));
if (++$pageCounter>999) break;
}
- if ($this->yellow->content->find($page->location) || empty($page->fileName)) {
+ if ($this->yellow->content->find($page->location) || is_string_empty($page->fileName)) {
$page->error(500, "Page '".$page->get("title")."' is not possible!");
}
} else {
@@ -1109,11 +1109,11 @@ class YellowEditResponse {
if ($this->isMetaModified($pageSource, $page) && $page->location!=$this->yellow->content->getHomeLocation($page->location)) {
$page->location = $this->getPageNewLocation($page->rawData, $page->location, $page->get("pageNewLocation"), true);
$page->fileName = $this->getPageNewFile($page->location, $page->fileName, $page->get("published"));
- if ($page->location!=$pageSource->location && ($this->yellow->content->find($page->location) || empty($page->fileName))) {
+ if ($page->location!=$pageSource->location && ($this->yellow->content->find($page->location) || is_string_empty($page->fileName))) {
$page->error(500, "Page '".$page->get("title")."' is not possible!");
}
}
- if (empty($page->rawData)) $page->error(500, "Page has been modified by someone else!");
+ if (is_string_empty($page->rawData)) $page->error(500, "Page has been modified by someone else!");
if (!$this->isUserAccess("edit", $page->location) ||
!$this->isUserAccess("edit", $pageSource->location)) {
$page->error(500, "Page '".$page->get("title")."' is restricted!");
@@ -1173,7 +1173,7 @@ class YellowEditResponse {
if ($file->get("type")=="html" || $file->get("type")=="svg") {
$fileData = $this->yellow->toolbox->readFile($fileNameTemp);
$fileData = $this->yellow->toolbox->normaliseData($fileData, $file->get("type"));
- if (empty($fileData) || !$this->yellow->toolbox->createFile($fileNameTemp, $fileData)) {
+ if (is_string_empty($fileData) || !$this->yellow->toolbox->createFile($fileNameTemp, $fileData)) {
$file->error(500, "Can't write file '$fileNameTemp'!");
}
}
@@ -1329,7 +1329,7 @@ class YellowEditResponse {
public function getEndOfLine($rawData = "") {
$endOfLine = $this->yellow->system->get("editEndOfLine");
if ($endOfLine=="auto") {
- $rawData = empty($rawData) ? PHP_EOL : substru($rawData, 0, 4096);
+ $rawData = is_string_empty($rawData) ? PHP_EOL : substru($rawData, 0, 4096);
$endOfLine = strposu($rawData, "\r")===false ? "lf" : "crlf";
}
return $endOfLine;
@@ -1352,7 +1352,7 @@ class YellowEditResponse {
}
}
}
- if (!empty($rawData)) $rawData = "<p>$rawData</p>\n";
+ if (!is_string_empty($rawData)) $rawData = "<p>$rawData</p>\n";
}
return array($statusCode, $rawData);
}
@@ -1402,7 +1402,7 @@ class YellowEditResponse {
// Return location for new/modified page
public function getPageNewLocation($rawData, $pageLocation, $pageNewLocation, $pageMatchLocation = false) {
- $location = empty($pageNewLocation) ? "@title" : $pageNewLocation;
+ $location = is_string_empty($pageNewLocation) ? "@title" : $pageNewLocation;
$location = preg_replace("/@title/i", $this->getPageNewTitle($rawData), $location);
$location = preg_replace("/@timestamp/i", $this->getPageNewData($rawData, "published", true, "U"), $location);
$location = preg_replace("/@date/i", $this->getPageNewData($rawData, "published", true, "Y-m-d"), $location);
@@ -1428,7 +1428,7 @@ class YellowEditResponse {
public function getPageNewTitle($rawData) {
$title = $this->yellow->toolbox->getMetaData($rawData, "title");
$titleSlug = $this->yellow->toolbox->getMetaData($rawData, "titleSlug");
- $value = empty($titleSlug) ? $title : $titleSlug;
+ $value = is_string_empty($titleSlug) ? $title : $titleSlug;
$value = $this->yellow->lookup->normaliseName($value, true, false, true);
return trim(preg_replace("/-+/", "-", $value), "-");
}
@@ -1437,8 +1437,8 @@ class YellowEditResponse {
public function getPageNewData($rawData, $key, $filterFirst = false, $dateFormat = "") {
$value = $this->yellow->toolbox->getMetaData($rawData, $key);
if ($filterFirst && preg_match("/^(.*?)\,(.*)$/", $value, $matches)) $value = $matches[1];
- if (!empty($dateFormat)) $value = date($dateFormat, strtotime($value));
- if (strempty($value)) $value = "none";
+ if (!is_string_empty($dateFormat)) $value = date($dateFormat, strtotime($value));
+ if (is_string_empty($value)) $value = "none";
$value = $this->yellow->lookup->normaliseName($value, true, false, true);
return trim(preg_replace("/-+/", "-", $value), "-");
}
@@ -1446,7 +1446,7 @@ class YellowEditResponse {
// Return file name for new/modified page
public function getPageNewFile($location, $pageFileName = "", $pagePrefix = "") {
$fileName = $this->yellow->lookup->findFileFromContentLocation($location);
- if (!empty($fileName)) {
+ if (!is_string_empty($fileName)) {
if (!is_dir(dirname($fileName))) {
$path = "";
$tokens = explode("/", $fileName);
@@ -1465,7 +1465,7 @@ class YellowEditResponse {
$path .= $tokens[$i]."/";
}
$fileName = $path.$tokens[$i];
- $pageFileName = empty($pageFileName) ? $fileName : $pageFileName;
+ $pageFileName = is_string_empty($pageFileName) ? $fileName : $pageFileName;
}
$prefix = $this->getPageNewPrefix($location, $pageFileName, $pagePrefix);
if ($this->yellow->lookup->isFileLocation($location)) {
@@ -1489,7 +1489,7 @@ class YellowEditResponse {
// Return prefix for new/modified page
public function getPageNewPrefix($location, $pageFileName, $pagePrefix) {
- if (empty($pagePrefix)) {
+ if (is_string_empty($pagePrefix)) {
if ($this->yellow->lookup->isFileLocation($location)) {
if (preg_match("#^(.*)\/(.+?)$#", $pageFileName, $matches)) $pagePrefix = $matches[2];
} else {
@@ -1501,7 +1501,7 @@ class YellowEditResponse {
// Return location for new file
public function getFileNewLocation($fileNameShort, $pageLocation, $fileNewLocation) {
- $location = empty($fileNewLocation) ? $this->yellow->system->get("editUploadNewLocation") : $fileNewLocation;
+ $location = is_string_empty($fileNewLocation) ? $this->yellow->system->get("editUploadNewLocation") : $fileNewLocation;
$location = preg_replace("/@timestamp/i", time(), $location);
$location = preg_replace("/@date/i", date("Y-m-d"), $location);
$location = preg_replace("/@type/i", $this->yellow->toolbox->getFileType($fileNameShort), $location);
@@ -1541,7 +1541,7 @@ class YellowEditResponse {
$fileText = $fileNumber = $fileExtension = "";
if (preg_match("/^(.*?)(\d*)(\..*?)?$/", $fileNameShort, $matches)) {
$fileText = $matches[1];
- $fileNumber = strempty($matches[2]) ? "-2" : $matches[2]+1;
+ $fileNumber = is_string_empty($matches[2]) ? "-2" : $matches[2]+1;
$fileExtension = $matches[3];
}
return $fileText.$fileNumber.$fileExtension;
@@ -1552,7 +1552,7 @@ class YellowEditResponse {
$titleText = $titleNumber = "";
if (preg_match("/^(.*?)(\d*)$/", $this->yellow->toolbox->getMetaData($rawData, "title"), $matches)) {
$titleText = $matches[1];
- $titleNumber = strempty($matches[2]) ? " 2" : $matches[2]+1;
+ $titleNumber = is_string_empty($matches[2]) ? " 2" : $matches[2]+1;
}
return $titleText.$titleNumber;
}
@@ -1617,7 +1617,7 @@ class YellowEditResponse {
public function createAuthToken($email, $expire) {
$hash = $this->yellow->user->getUser("hash", $email);
$signature = $this->yellow->toolbox->createHash($hash."auth".$expire, "sha256");
- if (empty($signature)) $signature = "padd"."error-hash-algorithm-sha256";
+ if (is_string_empty($signature)) $signature = "padd"."error-hash-algorithm-sha256";
return substrb($signature, 4).$this->yellow->user->getUser("stamp", $email).dechex($expire);
}
@@ -1625,7 +1625,7 @@ class YellowEditResponse {
public function createActionToken($email, $action, $expire) {
$hash = $this->yellow->user->getUser("hash", $email);
$signature = $this->yellow->toolbox->createHash($hash.$action.$expire, "sha256");
- if (empty($signature)) $signature = "padd"."error-hash-algorithm-sha256";
+ if (is_string_empty($signature)) $signature = "padd"."error-hash-algorithm-sha256";
return substrb($signature, 4);
}
@@ -1639,7 +1639,7 @@ class YellowEditResponse {
$algorithm = $this->yellow->system->get("editUserHashAlgorithm");
$cost = $this->yellow->system->get("editUserHashCost");
$hash = $this->yellow->toolbox->createHash($password, $algorithm, $cost);
- if (empty($hash)) $hash = "error-hash-algorithm-$algorithm";
+ if (is_string_empty($hash)) $hash = "error-hash-algorithm-$algorithm";
return $hash;
}
@@ -1682,7 +1682,7 @@ class YellowEditResponse {
// Return user email from authentication, timing attack safe email lookup
public function getAuthEmail($authToken, $stamp = "") {
$email = "";
- if (empty($stamp)) $stamp = substrb($authToken, 96, 20);
+ if (is_string_empty($stamp)) $stamp = substrb($authToken, 96, 20);
foreach ($this->yellow->user->settings as $key=>$value) {
if ($this->yellow->toolbox->verifyToken($value["stamp"], $stamp)) $email = $key;
}
@@ -1759,7 +1759,7 @@ class YellowEditResponse {
$deleted = $deletedOriginal;
}
}
- return !empty($fileNameDeleted) && $this->yellow->lookup->isContentFile($fileNameRestored) &&
+ return !is_string_empty($fileNameDeleted) && $this->yellow->lookup->isContentFile($fileNameRestored) &&
$this->yellow->toolbox->renameFile($fileNameDeleted, $fileNameRestored, true) &&
$this->yellow->toolbox->createFile($fileNameRestored, $rawDataRestored);
}
@@ -1785,7 +1785,7 @@ class YellowEditResponse {
$deleted = $deletedOriginal;
}
}
- return !empty($pathDeleted) && $this->yellow->lookup->isContentFile($fileNameRestored) &&
+ return !is_string_empty($pathDeleted) && $this->yellow->lookup->isContentFile($fileNameRestored) &&
$this->yellow->toolbox->renameDirectory($pathDeleted, dirname($fileNameRestored), true) &&
$this->yellow->toolbox->createFile($fileNameRestored, $rawDataRestored);
}
@@ -1824,14 +1824,14 @@ class YellowEditResponse {
// Check if user is logged in
public function isUser() {
- return !empty($this->userEmail);
+ return !is_string_empty($this->userEmail);
}
// Check if user with access
public function isUserAccess($action, $location = "") {
$userHome = $this->yellow->user->getUser("home", $this->userEmail);
$tokens = preg_split("/\s*,\s*/", $this->yellow->user->getUser("access", $this->userEmail));
- return in_array($action, $tokens) && (empty($location) || substru($location, 0, strlenu($userHome))==$userHome);
+ return in_array($action, $tokens) && (is_string_empty($location) || substru($location, 0, strlenu($userHome))==$userHome);
}
}
diff --git a/system/extensions/image.php b/system/extensions/image.php
@@ -2,7 +2,7 @@
// Image extension, https://github.com/annaesvensson/yellow-image
class YellowImage {
- const VERSION = "0.8.17";
+ const VERSION = "0.8.18";
public $yellow; // access to API
// Handle initialisation
@@ -32,20 +32,20 @@ class YellowImage {
if ($name=="image" && $type=="inline") {
list($name, $alt, $style, $width, $height) = $this->yellow->toolbox->getTextArguments($text);
if (!preg_match("/^\w+:/", $name)) {
- if (empty($alt)) $alt = $this->yellow->language->getText("imageDefaultAlt");
- if (empty($width)) $width = "100%";
- if (empty($height)) $height = $width;
+ if (is_string_empty($alt)) $alt = $this->yellow->language->getText("imageDefaultAlt");
+ if (is_string_empty($width)) $width = "100%";
+ if (is_string_empty($height)) $height = $width;
$path = $this->yellow->lookup->findMediaDirectory("coreImageLocation");
list($src, $width, $height) = $this->getImageInformation($path.$name, $width, $height);
} else {
- if (empty($alt)) $alt = $this->yellow->language->getText("imageDefaultAlt");
+ if (is_string_empty($alt)) $alt = $this->yellow->language->getText("imageDefaultAlt");
$src = $this->yellow->lookup->normaliseUrl("", "", "", $name);
$width = $height = 0;
}
$output = "<img src=\"".htmlspecialchars($src)."\"";
if ($width && $height) $output .= " width=\"".htmlspecialchars($width)."\" height=\"".htmlspecialchars($height)."\"";
- if (!empty($alt)) $output .= " alt=\"".htmlspecialchars($alt)."\" title=\"".htmlspecialchars($alt)."\"";
- if (!empty($style)) $output .= " class=\"".htmlspecialchars($style)."\"";
+ if (!is_string_empty($alt)) $output .= " alt=\"".htmlspecialchars($alt)."\" title=\"".htmlspecialchars($alt)."\"";
+ if (!is_string_empty($style)) $output .= " class=\"".htmlspecialchars($style)."\"";
$output .= " />";
}
return $output;
diff --git a/system/extensions/install-blog.bin b/system/extensions/install-blog.bin
Binary files differ.
diff --git a/system/extensions/install-wiki.bin b/system/extensions/install-wiki.bin
Binary files differ.
diff --git a/system/extensions/install.php b/system/extensions/install.php
@@ -2,7 +2,7 @@
// Install extension, https://github.com/annaesvensson/yellow-install
class YellowInstall {
- const VERSION = "0.8.83";
+ const VERSION = "0.8.84";
const PRIORITY = "1";
public $yellow; // access to API
@@ -24,7 +24,7 @@ class YellowInstall {
// Process request to install website
public function processRequestInstall($scheme, $address, $base, $location, $fileName) {
$statusCode = 0;
- if ($this->yellow->lookup->isContentFile($fileName) || empty($fileName)) {
+ if ($this->yellow->lookup->isContentFile($fileName) || is_string_empty($fileName)) {
if ($this->yellow->system->get("updateCurrentRelease")=="none") {
$this->checkServerRequirements();
$author = trim(preg_replace("/[^\pL\d\-\. ]/u", "-", $this->yellow->page->getRequest("author")));
@@ -71,7 +71,7 @@ class YellowInstall {
$statusCode = 0;
if ($this->yellow->system->get("updateCurrentRelease")=="none") {
$this->checkCommandRequirements();
- if (empty($command)) {
+ if (is_string_empty($command)) {
$statusCode = 200;
echo "Datenstrom Yellow is for people who make small websites. https://datenstrom.se/yellow/\n";
echo "Syntax: php yellow.php\n";
@@ -159,7 +159,7 @@ class YellowInstall {
$version = $settings->get("version");
$modified = strtotime($settings->get("published"));
$fileNamePhp = $this->yellow->system->get("coreExtensionDirectory").$extension.".php";
- if (!empty($extension) && !empty($version) && !is_file($fileNamePhp)) {
+ if (!is_string_empty($extension) && !is_string_empty($version) && !is_file($fileNamePhp)) {
$statusCode = max($statusCode, $this->yellow->extension->get("update")->updateExtensionSettings($extension, $action, $settings));
$statusCode = max($statusCode, $this->yellow->extension->get("update")->updateExtensionFile(
$fileNamePhp, $fileDataPhp, $modified, 0, 0, "create", $extension));
@@ -182,8 +182,8 @@ class YellowInstall {
// Update user
public function updateUser($email, $password, $name, $language) {
$statusCode = 200;
- if (!empty($email) && !empty($password) && $this->yellow->extension->isExisting("edit")) {
- if (empty($name)) $name = $this->yellow->system->get("sitename");
+ if (!is_string_empty($email) && !is_string_empty($password) && $this->yellow->extension->isExisting("edit")) {
+ if (is_string_empty($name)) $name = $this->yellow->system->get("sitename");
$fileNameUser = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreUserFile");
$settings = array(
"name" => $name,
@@ -220,7 +220,7 @@ class YellowInstall {
$statusCode = 200;
$fileName = $this->yellow->lookup->findFileFromContentLocation($location);
$fileData = str_replace("\r\n", "\n", $this->yellow->toolbox->readFile($fileName));
- if (!empty($fileData) && $language!="en") {
+ if (!is_string_empty($fileData) && $language!="en") {
$titleOld = "Title: ".$this->yellow->language->getText("{$name}Title", "en")."\n";
$titleNew = "Title: ".$this->yellow->language->getText("{$name}Title", $language)."\n";
$fileData = str_replace($titleOld, $titleNew, $fileData);
@@ -247,7 +247,7 @@ class YellowInstall {
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreLanguageFile");
$fileData = $this->yellow->toolbox->readFile($fileName);
if (strposu($fileData, "Language:")===false) {
- if (!empty($fileData)) $fileData .= "\n";
+ if (!is_string_empty($fileData)) $fileData .= "\n";
$fileData .= "Language: $language\n";
$fileData .= "media/images/photo.jpg: ".$this->yellow->language->getText("installExampleImage", $language)."\n";
if (!$this->yellow->toolbox->createFile($fileName, $fileData)) {
@@ -377,10 +377,10 @@ class YellowInstall {
$languages = array();
foreach (preg_split("/\s*,\s*/", $this->yellow->toolbox->getServer("HTTP_ACCEPT_LANGUAGE")) as $string) {
list($language, $dummy) = $this->yellow->toolbox->getTextList($string, ";", 2);
- if (!empty($language)) array_push($languages, $language);
+ if (!is_string_empty($language)) array_push($languages, $language);
}
foreach (preg_split("/\s*,\s*/", $languagesDefault) as $language) {
- if (!empty($language)) array_push($languages, $language);
+ if (!is_string_empty($language)) array_push($languages, $language);
}
return array_unique($languages);
}
@@ -395,7 +395,7 @@ class YellowInstall {
}
if ($this->yellow->system->get("sitename")=="Datenstrom Yellow") $settings["sitename"] = $this->yellow->toolbox->detectServerSitename();
if ($this->yellow->system->get("coreTimezone")=="UTC") $settings["coreTimezone"] = $this->yellow->toolbox->detectServerTimezone();
- if ($this->yellow->system->get("coreStaticUrl")=="auto" && !empty(getenv("URL"))) $settings["coreStaticUrl"] = getenv("URL");
+ if ($this->yellow->system->get("coreStaticUrl")=="auto" && getenv("URL")!==false) $settings["coreStaticUrl"] = getenv("URL");
if ($this->yellow->system->get("updateEventPending")=="none") $settings["updateEventPending"] = "website/install";
$settings["updateCurrentRelease"] = YellowCore::RELEASE;
return $settings;
@@ -435,7 +435,7 @@ class YellowInstall {
$languages = array();
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
- if (!empty($matches[1]) && !empty($matches[2]) && strposu($matches[1], "/")) {
+ if (!is_string_empty($matches[1]) && !is_string_empty($matches[2]) && strposu($matches[1], "/")) {
$extension = basename($matches[1]);
$extension = $this->yellow->lookup->normaliseName($extension, true, true);
list($entry, $flags) = $this->yellow->toolbox->getTextList($matches[2], ",", 2);
diff --git a/system/extensions/markdown.php b/system/extensions/markdown.php
@@ -2,7 +2,7 @@
// Markdown extension, https://github.com/annaesvensson/yellow-markdown
class YellowMarkdown {
- const VERSION = "0.8.22";
+ const VERSION = "0.8.23";
public $yellow; // access to API
// Handle initialisation
@@ -3911,7 +3911,7 @@ class YellowMarkdownParser extends MarkdownExtraParser {
// Handle fenced code blocks
public function _doFencedCodeBlocks_callback($matches) {
$text = $matches[4];
- $name = empty($matches[2]) ? "" : trim("$matches[2] $matches[3]");
+ $name = is_string_empty($matches[2]) ? "" : trim("$matches[2] $matches[3]");
$output = $this->page->parseContentShortcut($name, $text, "code");
if (is_null($output)) {
$attr = $this->doExtraAttributes("pre", ".$matches[2] $matches[3]");
@@ -3926,7 +3926,7 @@ class YellowMarkdownParser extends MarkdownExtraParser {
$text = $matches[1];
$level = $matches[3][0]=="=" ? 1 : 2;
$attr = $this->doExtraAttributes("h$level", $dummy =& $matches[2]);
- if (empty($attr) && $level>=2) $attr = $this->getIdAttribute($text);
+ if (is_string_empty($attr) && $level>=2) $attr = $this->getIdAttribute($text);
$output = "<h$level$attr>".$this->runSpanGamut($text)."</h$level>";
return "\n".$this->hashBlock($output)."\n\n";
}
@@ -3936,7 +3936,7 @@ class YellowMarkdownParser extends MarkdownExtraParser {
$text = $matches[2];
$level = strlen($matches[1]);
$attr = $this->doExtraAttributes("h$level", $dummy =& $matches[3]);
- if (empty($attr) && $level>=2) $attr = $this->getIdAttribute($text);
+ if (is_string_empty($attr) && $level>=2) $attr = $this->getIdAttribute($text);
$output = "<h$level$attr>".$this->runSpanGamut($text)."</h$level>";
return "\n".$this->hashBlock($output)."\n\n";
}
@@ -3948,7 +3948,7 @@ class YellowMarkdownParser extends MarkdownExtraParser {
$title = isset($matches[7]) ? $matches[7] : "";
$attr = $this->doExtraAttributes("a", $dummy =& $matches[8]);
$output = "<a href=\"".$this->encodeURLAttribute($url)."\"";
- if (!empty($title)) $output .= " title=\"".$this->encodeAttribute($title)."\"";
+ if (!is_string_empty($title)) $output .= " title=\"".$this->encodeAttribute($title)."\"";
$output .= $attr;
$output .= ">".$this->runSpanGamut($text)."</a>";
return $this->hashPart($output);
@@ -3964,8 +3964,8 @@ class YellowMarkdownParser extends MarkdownExtraParser {
$title = isset($matches[7]) ? $matches[7] : $matches[2];
$attr = $this->doExtraAttributes("img", $dummy =& $matches[8]);
$output = "<img src=\"".$this->encodeURLAttribute($src)."\"";
- if (!empty($alt)) $output .= " alt=\"".$this->encodeAttribute($alt)."\"";
- if (!empty($title)) $output .= " title=\"".$this->encodeAttribute($title)."\"";
+ if (!is_string_empty($alt)) $output .= " alt=\"".$this->encodeAttribute($alt)."\"";
+ if (!is_string_empty($title)) $output .= " title=\"".$this->encodeAttribute($title)."\"";
$output .= $attr;
$output .= $this->empty_element_suffix;
return $this->hashPart($output);
@@ -4016,7 +4016,7 @@ class YellowMarkdownParser extends MarkdownExtraParser {
$level = strspn(str_replace(array("![", " "), "", $lines), "!");
$attr = " class=\"notice$level\"";
}
- if (!empty($text)) {
+ if (!is_string_empty($text)) {
++$this->noticeLevel;
$output = "<div$attr>\n".$this->runBlockGamut($text)."\n</div>";
--$this->noticeLevel;
diff --git a/system/extensions/meta.php b/system/extensions/meta.php
@@ -2,7 +2,7 @@
// Meta extension, https://github.com/annaesvensson/yellow-meta
class YellowMeta {
- const VERSION = "0.8.15";
+ const VERSION = "0.8.16";
public $yellow; // access to API
// Handle initialisation
@@ -45,7 +45,7 @@ class YellowMeta {
$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->getTextArguments(trim($matches[1]));
- if (empty($alt)) $alt = $page->get("title");
+ if (is_string_empty($alt)) $alt = $page->get("title");
} else {
$name = $this->yellow->system->get("metaDefaultImage");
$alt = $page->isExisting("imageAlt") ? $page->get("imageAlt") : $page->get("title");
diff --git a/system/extensions/serve.php b/system/extensions/serve.php
@@ -2,7 +2,7 @@
// Serve extension, https://github.com/annaesvensson/yellow-serve
class YellowServe {
- const VERSION = "0.8.21";
+ const VERSION = "0.8.22";
public $yellow; // access to API
// Handle initialisation
@@ -27,9 +27,9 @@ class YellowServe {
// Process command to start built-in web server
public function processCommandServe($command, $text) {
list($url) = $this->yellow->toolbox->getTextArguments($text);
- if (empty($url)) $url = "http://localhost:8000/";
+ if (is_string_empty($url)) $url = "http://localhost:8000/";
list($scheme, $address, $base) = $this->yellow->lookup->getUrlInformation($url);
- if ($scheme=="http" && !empty($address) && empty($base)) {
+ if ($scheme=="http" && !is_string_empty($address) && is_string_empty($base)) {
if (!preg_match("/\:\d+$/", $address)) $address .= ":8000";
if ($this->checkServerSettings("$scheme://$address/")) {
echo "Starting built-in web server. Open a web browser and go to $scheme://$address/\n";
@@ -37,7 +37,7 @@ class YellowServe {
exec("php -S $address yellow.php 2>&1", $outputLines, $returnStatus);
$statusCode = $returnStatus!=0 ? 500 : 200;
if ($statusCode!=200) {
- $output = !empty($outputLines) ? end($outputLines) : "Please check arguments!";
+ $output = !is_array_empty($outputLines) ? end($outputLines) : "Please check arguments!";
if (preg_match("/^\[(.*?)\]\s*(.*)$/", $output, $matches)) $output = $matches[2];
echo "ERROR starting web server: $output\n";
}
diff --git a/system/extensions/update-current.ini b/system/extensions/update-current.ini
@@ -1,21 +1,21 @@
# Datenstrom Yellow update settings
Extension: Command
-Version: 0.8.43
+Version: 0.8.44
Description: Command line of the website.
DocumentationUrl: https://github.com/annaesvensson/yellow-command
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/command.zip
-Published: 2022-10-30 00:30:52
+Published: 2022-11-03 18:04:20
Developer: Anna Svensson
Tag: feature
system/extensions/command.php: command.php, create, update
Extension: Core
-Version: 0.8.98
+Version: 0.8.99
Description: Core functionality of the website.
DocumentationUrl: https://github.com/annaesvensson/yellow-core
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/core.zip
-Published: 2022-10-30 19:38:43
+Published: 2022-11-03 18:37:24
Developer: Mark Seuffert, David Fehrmann
Tag: feature
system/extensions/core.php: core.php, create, update
@@ -27,11 +27,11 @@ system/layouts/navigation.html: navigation.html, create, update, careful
system/layouts/pagination.html: pagination.html, create, update, careful
Extension: Edit
-Version: 0.8.66
+Version: 0.8.67
Description: Edit your website in a web browser.
DocumentationUrl: https://github.com/annaesvensson/yellow-edit
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/edit.zip
-Published: 2022-10-30 01:47:46
+Published: 2022-11-03 18:50:28
Developer: Anna Svensson
Tag: feature
system/extensions/edit.php: edit.php, create, update
@@ -42,11 +42,11 @@ system/extensions/edit.woff: edit.woff, delete
content/shared/page-new-default.md: page-new-default.md, create, optional
Extension: Image
-Version: 0.8.17
+Version: 0.8.18
Description: Images and thumbnails.
DocumentationUrl: https://github.com/annaesvensson/yellow-image
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/image.zip
-Published: 2022-10-20 20:50:25
+Published: 2022-11-03 18:17:42
Developer: Anna Svensson
Tag: feature
system/extensions/image.php: image.php, create, update
@@ -54,11 +54,11 @@ media/images/photo.jpg: photo.jpg, create, optional
media/thumbnails/photo-100x40.jpg: photo-100x40.jpg, create, optional
Extension: Install
-Version: 0.8.83
+Version: 0.8.84
Description: Install a brand new, shiny website.
DocumentationUrl: https://github.com/annaesvensson/yellow-install
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/install.zip
-Published: 2022-10-30 19:38:16
+Published: 2022-11-03 19:08:28
Developer: Anna Svensson
Status: unlisted
system/extensions/install.php: install.php, create
@@ -76,31 +76,31 @@ media/downloads/yellow.pdf: yellow.pdf, create
./robots.txt: robots.txt, create
Extension: Markdown
-Version: 0.8.22
+Version: 0.8.23
Description: Text formatting for humans.
DocumentationUrl: https://github.com/annaesvensson/yellow-markdown
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/markdown.zip
-Published: 2022-08-24 21:47:46
+Published: 2022-11-03 18:21:05
Developer: Anna Svensson
Tag: feature
system/extensions/markdown.php: markdown.php, create, update
Extension: Meta
-Version: 0.8.15
+Version: 0.8.16
Description: Meta data for humans and machines.
DocumentationUrl: https://github.com/annaesvensson/yellow-meta
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/meta.zip
-Published: 2022-05-08 10:08:53
+Published: 2022-11-03 18:23:11
Developer: Anna Svensson, Steffen Schultz
Tag: feature
system/extensions/meta.php: meta.php, create, update
Extension: Serve
-Version: 0.8.21
+Version: 0.8.22
Description: Built-in web server.
DocumentationUrl: https://github.com/annaesvensson/yellow-serve
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/serve.zip
-Published: 2022-10-30 00:34:51
+Published: 2022-11-03 18:24:31
Developer: Anna Svensson
Tag: feature
system/extensions/serve.php: serve.php, create, update
@@ -121,11 +121,11 @@ system/themes/stockholm-opensans-light.woff: stockholm-opensans-light.woff, crea
system/themes/stockholm-opensans-regular.woff: stockholm-opensans-regular.woff, create, update, careful
Extension: Update
-Version: 0.8.88
+Version: 0.8.89
Description: Keep your website up to date.
DocumentationUrl: https://github.com/annaesvensson/yellow-update
DownloadUrl: https://github.com/datenstrom/yellow-extensions/raw/main/downloads/update.zip
-Published: 2022-10-30 23:20:51
+Published: 2022-11-03 18:14:57
Developer: Anna Svensson
Tag: feature
system/extensions/update.php: update.php, create, update
diff --git a/system/extensions/update.php b/system/extensions/update.php
@@ -2,7 +2,7 @@
// Update extension, https://github.com/annaesvensson/yellow-update
class YellowUpdate {
- const VERSION = "0.8.88";
+ const VERSION = "0.8.89";
const PRIORITY = "2";
public $yellow; // access to API
public $extensions; // number of extensions
@@ -102,7 +102,7 @@ class YellowUpdate {
public function processCommandAbout($command, $text) {
$statusCode = 200;
$extensions = $this->getExtensionsFromText($text);
- if (!empty($extensions)) {
+ if (!is_array_empty($extensions)) {
list($statusCode, $settings) = $this->getExtensionAboutInformation($extensions);
if ($statusCode==200) {
foreach ($settings as $key=>$value) {
@@ -124,7 +124,7 @@ class YellowUpdate {
// Process command to install extensions
public function processCommandInstall($command, $text) {
$extensions = $this->getExtensionsFromText($text);
- if (!empty($extensions)) {
+ if (!is_array_empty($extensions)) {
$this->extensions = 0;
list($statusCode, $settings) = $this->getExtensionInstallInformation($extensions);
if ($statusCode==200) $statusCode = $this->downloadExtensions($settings);
@@ -145,7 +145,7 @@ class YellowUpdate {
// Process command to uninstall extensions
public function processCommandUninstall($command, $text) {
$extensions = $this->getExtensionsFromText($text);
- if (!empty($extensions)) {
+ if (!is_array_empty($extensions)) {
$this->extensions = 0;
list($statusCode, $settings) = $this->getExtensionUninstallInformation($extensions, "core, update");
if ($statusCode==200) $statusCode = $this->removeExtensions($settings);
@@ -165,9 +165,9 @@ class YellowUpdate {
// Process command to update website
public function processCommandUpdate($command, $text) {
$extensions = $this->getExtensionsFromText($text);
- if (!empty($extensions)) {
+ if (!is_array_empty($extensions)) {
list($statusCode, $settings) = $this->getExtensionUpdateInformation($extensions);
- if ($statusCode!=200 || !empty($settings)) {
+ if ($statusCode!=200 || !is_array_empty($settings)) {
$this->extensions = 0;
if ($statusCode==200) $statusCode = $this->downloadExtensions($settings);
if ($statusCode==200) $statusCode = $this->updateExtensions("update");
@@ -179,7 +179,7 @@ class YellowUpdate {
}
} else {
list($statusCode, $settings) = $this->getExtensionUpdateInformation(array("all"));
- if (!empty($settings)) {
+ if (!is_array_empty($settings)) {
foreach ($settings as $key=>$value) {
echo ucfirst($key)." ".$value->get("version")."\n";
}
@@ -229,7 +229,7 @@ class YellowUpdate {
foreach ($settings as $key=>$value) {
$fileName = $path.$this->yellow->lookup->normaliseName($key, true, false, true).".zip";
list($statusCode, $fileData) = $this->getExtensionFile($value->get("downloadUrl"));
- if (empty($fileData) || !$this->yellow->toolbox->createFile($fileName.".download", $fileData)) {
+ if (is_string_empty($fileData) || !$this->yellow->toolbox->createFile($fileName.".download", $fileData)) {
$statusCode = 500;
$this->yellow->page->error($statusCode, "Can't write file '$fileName'!");
break;
@@ -273,7 +273,7 @@ class YellowUpdate {
$fileData = $zip->getFromName($pathBase.$this->yellow->system->get("updateExtensionFile"));
$settings = $this->yellow->toolbox->getTextSettings($fileData, "");
list($extension, $version, $newModified, $oldModified) = $this->getExtensionInformation($settings);
- if (!empty($extension) && !empty($version)) {
+ if (!is_string_empty($extension) && !is_string_empty($version)) {
$statusCode = max($statusCode, $this->updateExtensionSettings($extension, $action, $settings));
$paths = $this->getExtensionDirectories($zip, $pathBase);
foreach ($this->getExtensionFileNames($settings) as $fileName) {
@@ -320,8 +320,8 @@ class YellowUpdate {
$fileName = $this->yellow->toolbox->normalisePath($fileName);
if ($this->yellow->lookup->isValidFile($fileName)) {
$create = $update = $delete = false;
- if (preg_match("/create/i", $flags) && !is_file($fileName) && !empty($fileData)) $create = true;
- if (preg_match("/update/i", $flags) && is_file($fileName) && !empty($fileData)) $update = true;
+ if (preg_match("/create/i", $flags) && !is_file($fileName) && !is_string_empty($fileData)) $create = true;
+ if (preg_match("/update/i", $flags) && is_file($fileName) && !is_string_empty($fileData)) $update = true;
if (preg_match("/delete/i", $flags) && is_file($fileName)) $delete = true;
if (preg_match("/optional/i", $flags) && $this->yellow->extension->isExisting($extension)) $create = $update = $delete = false;
if (preg_match("/careful/i", $flags) && is_file($fileName) && $lastModified!=$oldModified) $update = false;
@@ -421,7 +421,7 @@ class YellowUpdate {
public function updateExtensionPending() {
$statusCode = 0;
$path = $this->yellow->system->get("coreExtensionDirectory");
- if (count($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", false, false))>0) {
+ if (!is_array_empty($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", false, false))) {
$statusCode = $this->updateExtensions("install");
if ($statusCode==200) $statusCode = 303;
if ($statusCode>=400) {
@@ -450,7 +450,7 @@ class YellowUpdate {
break;
}
foreach ($settingsCurrent as $extension=>$block) {
- if (!empty($fileDataNew)) $fileDataNew .= "\n";
+ if (!is_string_empty($fileDataNew)) $fileDataNew .= "\n";
foreach ($block as $key=>$value) {
$fileDataNew .= (strposu($key, "/") ? $key : ucfirst($key)).": $value\n";
}
@@ -475,24 +475,28 @@ class YellowUpdate {
$settings = new YellowArray();
$settings->exchangeArray($this->yellow->system->settingsDefaults->getArrayCopy());
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
- preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
- if (empty($fileDataStart) && preg_match("/^\#/", $line)) {
- $fileDataStart = $line."\n";
- } elseif (!empty($matches[1]) && !strempty($matches[2])) {
- $settings[$matches[1]] = $matches[2];
+ if (preg_match("/^\#/", $line)) {
+ if (is_string_empty($fileDataStart)) $fileDataStart = $line."\n";
+ continue;
+ }
+ if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
+ if (!is_string_empty($matches[1]) && !is_string_empty($matches[2])) {
+ $settings[$matches[1]] = $matches[2];
+ }
}
}
foreach ($settings as $key=>$value) {
- $fileDataSettings .= ucfirst($key).(strempty($value) ? ":\n" : ": $value\n");
+ $fileDataSettings .= ucfirst($key).(is_string_empty($value) ? ":\n" : ": $value\n");
}
$fileDataNew = $fileDataStart.$fileDataSettings;
} elseif ($action=="uninstall") {
- if (!empty($extension)) {
+ if (!is_string_empty($extension)) {
$fileDataNew = "";
$regex = "/^".ucfirst($extension)."[A-Z]+/";
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
- preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
- if (!empty($matches[1]) && preg_match($regex, $matches[1])) continue;
+ if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
+ if (!is_string_empty($matches[1]) && preg_match($regex, $matches[1])) continue;
+ }
$fileDataNew .= $line;
}
}
@@ -513,48 +517,52 @@ class YellowUpdate {
$fileDataStart = $fileDataSettings = $language = "";
$settings = new YellowArray();
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
- preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
- if (empty($fileDataStart) && preg_match("/^\#/", $line)) {
- $fileDataStart = $line."\n";
- } elseif (!empty($matches[1]) && !strempty($matches[2])) {
- if (lcfirst($matches[1])=="language") {
- if (!empty($settings)) {
- if (!empty($fileDataSettings)) $fileDataSettings .= "\n";
- foreach ($settings as $key=>$value) {
- $fileDataSettings .= (strposu($key, "/") ? $key : ucfirst($key)).": $value\n";
+ if (preg_match("/^\#/", $line)) {
+ if (is_string_empty($fileDataStart)) $fileDataStart = $line."\n";
+ continue;
+ }
+ if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
+ if (!is_string_empty($matches[1]) && !is_string_empty($matches[2])) {
+ if (lcfirst($matches[1])=="language") {
+ if (!is_array_empty($settings)) {
+ if (!is_string_empty($fileDataSettings)) $fileDataSettings .= "\n";
+ foreach ($settings as $key=>$value) {
+ $fileDataSettings .= (strposu($key, "/") ? $key : ucfirst($key)).": $value\n";
+ }
}
- }
- $language = $matches[2];
- $settings = new YellowArray();
- $settings["language"] = $language;
- foreach ($this->yellow->language->settingsDefaults as $key=>$value) {
- $require = preg_match("/^([a-z]*)[A-Z]+/", $key, $tokens) ? $tokens[1] : "core";
- if ($require=="language") $require = "core";
- if ($this->yellow->extension->isExisting($require) &&
- $this->yellow->language->isText($key, $language)) {
- $settings[$key] = $this->yellow->language->getText($key, $language);
+ $language = $matches[2];
+ $settings = new YellowArray();
+ $settings["language"] = $language;
+ foreach ($this->yellow->language->settingsDefaults as $key=>$value) {
+ $require = preg_match("/^([a-z]*)[A-Z]+/", $key, $tokens) ? $tokens[1] : "core";
+ if ($require=="language") $require = "core";
+ if ($this->yellow->extension->isExisting($require) &&
+ $this->yellow->language->isText($key, $language)) {
+ $settings[$key] = $this->yellow->language->getText($key, $language);
+ }
}
}
- }
- if (!empty($language)) {
- $settings[$matches[1]] = $matches[2];
+ if (!is_string_empty($language)) {
+ $settings[$matches[1]] = $matches[2];
+ }
}
}
}
- if (!empty($settings)) {
- if (!empty($fileDataSettings)) $fileDataSettings .= "\n";
+ if (!is_array_empty($settings)) {
+ if (!is_string_empty($fileDataSettings)) $fileDataSettings .= "\n";
foreach ($settings as $key=>$value) {
$fileDataSettings .= (strposu($key, "/") ? $key : ucfirst($key)).": $value\n";
}
}
$fileDataNew = $fileDataStart.$fileDataSettings;
} elseif ($action=="uninstall") {
- if (!empty($extension) && ucfirst($extension)!="Language") {
+ if (!is_string_empty($extension) && ucfirst($extension)!="Language") {
$fileDataNew = "";
$regex = "/^".ucfirst($extension)."[A-Z]+/";
foreach ($this->yellow->toolbox->getTextLines($fileData) as $line) {
- preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
- if (!empty($matches[1]) && preg_match($regex, $matches[1])) continue;
+ if (preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches)) {
+ if (!is_string_empty($matches[1]) && preg_match($regex, $matches[1])) continue;
+ }
$fileDataNew .= $line;
}
}
@@ -575,7 +583,7 @@ class YellowUpdate {
}
$updateEventPending = $this->yellow->system->get("updateEventPending");
if ($updateEventPending=="none") $updateEventPending = "";
- if (!empty($updateEventPending)) $updateEventPending .= ",";
+ if (!is_string_empty($updateEventPending)) $updateEventPending .= ",";
$updateEventPending .= "$extension/$action";
$fileName = $this->yellow->system->get("coreExtensionDirectory").$this->yellow->system->get("coreSystemFile");
if (!$this->yellow->system->save($fileName, array("updateEventPending" => $updateEventPending))) {
@@ -599,7 +607,7 @@ class YellowUpdate {
public function removeExtensionArchive($extension, $action, $settings) {
$statusCode = 200;
$fileNames = $this->getExtensionFileNames($settings, true);
- if (count($fileNames)) {
+ if (!is_array_empty($fileNames)) {
$statusCode = max($statusCode, $this->updateExtensionNotification($extension, $action));
foreach ($fileNames as $fileName) {
$statusCode = max($statusCode, $this->removeExtensionFile($fileName));
@@ -848,7 +856,7 @@ class YellowUpdate {
break;
}
}
- if (!empty($pathMultiLanguage)) break;
+ if (!is_string_empty($pathMultiLanguage)) break;
}
$fileNameSource = $pathBase.$pathMultiLanguage.$entry;
} else {
@@ -870,7 +878,7 @@ class YellowUpdate {
if ($value->isExisting("developer")) $responsible = "Developed by ".$value["developer"].".";
if ($value->isExisting("designer")) $responsible = "Designed by ".$value["designer"].".";
if ($value->isExisting("translator")) $responsible = "Translated by ".$value["translator"].".";
- if (empty($description)) $description = "No description available.";
+ if (is_string_empty($description)) $description = "No description available.";
return "$description $responsible";
}