mikuli.cz

:)
git clone https://git.sr.ht/~ashymad/mikuli.cz
Log | Files | Refs

commit b1780f0f4d5f1a57952f9b3d92dd3e1d7f3aea53
parent f31a6ba1211d6c2d3f313d52ba8454c73385c094
Author: markseu <mark2011@mayberg.se>
Date:   Thu, 18 Aug 2016 21:57:07 +0200

System update (SVG support)

Diffstat:
Msystem/plugins/commandline.php | 23++++++++++++++---------
Msystem/plugins/core.php | 88+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Msystem/plugins/update.php | 14+++++++-------
Msystem/plugins/webinterface.php | 10++++++++--
4 files changed, 79 insertions(+), 56 deletions(-)

diff --git a/system/plugins/commandline.php b/system/plugins/commandline.php @@ -5,7 +5,7 @@ // Command line plugin class YellowCommandline { - const VERSION = "0.6.15"; + const VERSION = "0.6.16"; var $yellow; //access to API var $files; //number of files var $errors; //number of errors @@ -137,7 +137,7 @@ class YellowCommandline { $fileData = ob_get_contents(); $modified = strtotime($this->yellow->page->getHeader("Last-Modified")); - if($modified==0) $modified = filemtime($this->yellow->page->fileName); + if($modified==0) $modified = $this->yellow->toolbox->getFileModified($this->yellow->page->fileName); if($statusCode>=301 && $statusCode<=303) { $fileData = $this->getStaticRedirect($this->yellow->page->getHeader("Location")); @@ -155,9 +155,10 @@ class YellowCommandline ob_end_clean(); } else { $statusCode = 200; + $modified = $this->yellow->toolbox->getFileModified($this->yellow->page->fileName); $fileName = $this->getStaticFile($path, $location, $statusCode); if(!$this->yellow->toolbox->copyFile($this->yellow->page->fileName, $fileName, true) || - !$this->yellow->toolbox->modifyFile($fileName, filemtime($this->yellow->page->fileName))) + !$this->yellow->toolbox->modifyFile($fileName, $modified)) { $statusCode = 500; $this->yellow->page->statusCode = $statusCode; @@ -398,8 +399,7 @@ class YellowCommandline function getMediaLocations() { $locations = array(); - $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive( - $this->yellow->config->get("mediaDir"), "/.*/", false, false); + $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($this->yellow->config->get("mediaDir"), "/.*/", false, false); foreach($fileNames as $fileName) { array_push($locations, "/".$fileName); @@ -411,18 +411,23 @@ class YellowCommandline function getSystemLocations() { $locations = array(); - $fileNames = $this->yellow->toolbox->getDirectoryEntries( - $this->yellow->config->get("pluginDir"), "/\.(css|ico|js|jpg|png|txt|woff)/", false, false); + $regex = "/\.(css|ico|js|jpg|png|svg|txt|woff)/"; + $fileNames = $this->yellow->toolbox->getDirectoryEntries($this->yellow->config->get("pluginDir"), $regex, false, false); foreach($fileNames as $fileName) { array_push($locations, $this->yellow->config->get("pluginLocation").basename($fileName)); } - $fileNames = $this->yellow->toolbox->getDirectoryEntries( - $this->yellow->config->get("themeDir"), "/\.(css|ico|js|jpg|png|txt|woff)/", false, false); + $fileNames = $this->yellow->toolbox->getDirectoryEntries($this->yellow->config->get("themeDir"), $regex, false, false); foreach($fileNames as $fileName) { array_push($locations, $this->yellow->config->get("themeLocation").basename($fileName)); } + $assetDirLength = strlenu($this->yellow->config->get("assetDir")); + $fileNames = $this->yellow->toolbox->getDirectoryEntriesRecursive($this->yellow->config->get("assetDir"), $regex, false, false); + foreach($fileNames as $fileName) + { + array_push($locations, $this->yellow->config->get("assetLocation").substru($fileName, $assetDirLength)); + } array_push($locations, "/".$this->yellow->config->get("robotsFile")); return $locations; } diff --git a/system/plugins/core.php b/system/plugins/core.php @@ -222,7 +222,7 @@ class YellowCore // Send file response function sendFile($statusCode, $fileName, $cacheable) { - $lastModifiedFormatted = $this->toolbox->getHttpDateFormatted(filemtime($fileName)); + $lastModifiedFormatted = $this->toolbox->getHttpDateFormatted($this->toolbox->getFileModified($fileName)); if($statusCode==200 && $cacheable && $this->toolbox->isRequestNotModified($lastModifiedFormatted)) { $statusCode = 304; @@ -288,7 +288,7 @@ class YellowCore $base = empty($base) ? $this->config->get("serverBase") : $base; $location = $this->toolbox->getLocation(); $location = substru($location, strlenu($base)); - if(preg_match("/\.(css|ico|js|jpg|png|txt|woff)$/", $location)) + if(preg_match("/\.(css|ico|js|jpg|png|svg|txt|woff)$/", $location)) { $pluginLocationLength = strlenu($this->config->get("pluginLocation")); $themeLocationLength = strlenu($this->config->get("themeLocation")); @@ -334,7 +334,7 @@ class YellowCore // Return static file from cache if available function getStaticFileFromCache($location, $fileName, $cacheable) { - if(is_readable($fileName) && $cacheable && PHP_SAPI!="cli") + if($cacheable && PHP_SAPI!="cli") { $location .= $this->toolbox->getLocationArgs(); $fileNameStatic = rtrim($this->config->get("staticDir"), '/').$location; @@ -347,11 +347,16 @@ class YellowCore // Check if static file function isStaticFile($location, $fileName, $cacheable) { - $fileName = $this->getStaticFileFromCache($location, $fileName, $cacheable); - $staticDirLength = strlenu($this->config->get("staticDir")); - $systemDirLength = strlenu($this->config->get("systemDir")); - return substru($fileName, 0, $staticDirLength)==$this->config->get("staticDir") || - substru($fileName, 0, $systemDirLength)==$this->config->get("systemDir"); + $ok = false; + if(is_readable($fileName)) + { + $fileName = $this->getStaticFileFromCache($location, $fileName, $cacheable); + $staticDirLength = strlenu($this->config->get("staticDir")); + $systemDirLength = strlenu($this->config->get("systemDir")); + $ok = substru($fileName, 0, $staticDirLength)==$this->config->get("staticDir") || + substru($fileName, 0, $systemDirLength)==$this->config->get("systemDir"); + } + return $ok; } // Check if request can be redirected into content directory @@ -1743,7 +1748,7 @@ class YellowConfig function load($fileName) { if(defined("DEBUG") && DEBUG>=2) echo "YellowConfig::load file:$fileName<br/>\n"; - $this->modified = filemtime($fileName); + $this->modified = $this->yellow->toolbox->getFileModified($fileName); $fileData = $this->yellow->toolbox->readFile($fileName); foreach($this->yellow->toolbox->getTextLines($fileData) as $line) { @@ -2722,6 +2727,7 @@ class YellowToolbox "js" => "application/javascript", "jpg" => "image/jpeg", "png" => "image/png", + "svg" => "image/svg+xml", "txt" => "text/plain", "woff" => "application/font-woff", "xml" => "text/xml; charset=utf-8"); @@ -2774,24 +2780,6 @@ class YellowToolbox return $entries; } - // Return file extension - function getFileExtension($fileName) - { - return strtoloweru(($pos = strrposu($fileName, '.')) ? substru($fileName, $pos+1) : ""); - } - - // Return file modification date, Unix time - function getFileModified($fileName) - { - $modified = is_readable($fileName) ? filemtime($fileName) : 0; - if($modified==0) - { - $path = dirname($fileName); - $modified = is_readable($path) ? filemtime($path) : 0; - } - return $modified; - } - // Read file, empty string if not found function readFile($fileName, $sizeMax = 0) { @@ -2908,6 +2896,18 @@ class YellowToolbox return $ok; } + // Return file extension + function getFileExtension($fileName) + { + return strtoloweru(($pos = strrposu($fileName, '.')) ? substru($fileName, $pos+1) : ""); + } + + // Return file modification date, Unix time + function getFileModified($fileName) + { + return is_file($fileName) ? filemtime($fileName) : 0; + } + // Return lines from text string function getTextLines($text) { @@ -3097,7 +3097,7 @@ class YellowToolbox return $language; } - // Detect image dimensions and type, png or jpg + // Detect image dimensions and type for jpg/png/svg function detectImageInfo($fileName) { $width = $height = 0; @@ -3105,17 +3105,8 @@ class YellowToolbox $fileHandle = @fopen($fileName, "rb"); if($fileHandle) { - if(substru(strtoloweru($fileName), -3)=="png") + if(substru(strtoloweru($fileName), -3)=="jpg") { - $dataSignature = fread($fileHandle, 8); - $dataHeader = fread($fileHandle, 16); - if(!feof($fileHandle) && $dataSignature=="\x89PNG\r\n\x1a\n") - { - $width = (ord($dataHeader[10])<<8) + ord($dataHeader[11]); - $height = (ord($dataHeader[14])<<8) + ord($dataHeader[15]); - $type = "png"; - } - } else if(substru(strtoloweru($fileName), -3)=="jpg") { $dataBufferSizeMax = filesize($fileName); $dataBufferSize = min($dataBufferSizeMax, 4096); $dataBuffer = fread($fileHandle, $dataBufferSize); @@ -3143,6 +3134,27 @@ class YellowToolbox } } } + } else if(substru(strtoloweru($fileName), -3)=="png") { + $dataSignature = fread($fileHandle, 8); + $dataHeader = fread($fileHandle, 16); + if(!feof($fileHandle) && $dataSignature=="\x89PNG\r\n\x1a\n") + { + $width = (ord($dataHeader[10])<<8) + ord($dataHeader[11]); + $height = (ord($dataHeader[14])<<8) + ord($dataHeader[15]); + $type = "png"; + } + } else if(substru(strtoloweru($fileName), -3)=="svg") { + $dataBufferSizeMax = filesize($fileName); + $dataBufferSize = min($dataBufferSizeMax, 4096); + $dataBuffer = fread($fileHandle, $dataBufferSize); + $dataSignature = substrb($dataBuffer, 0, 5); + if(!feof($fileHandle) && $dataSignature=="\x3csvg\x20") + { + $dataBuffer = ($pos = strposu($dataBuffer, '>')) ? substru($dataBuffer, 0, $pos) : $dataBuffer; + if(preg_match("/ width=\"(\d+)\"/", $dataBuffer, $matches)) $width = $matches[1]; + if(preg_match("/ height=\"(\d+)\"/", $dataBuffer, $matches)) $height = $matches[1]; + $type = "svg"; + } } fclose($fileHandle); } diff --git a/system/plugins/update.php b/system/plugins/update.php @@ -5,7 +5,7 @@ // Update plugin class YellowUpdate { - const VERSION = "0.6.7"; + const VERSION = "0.6.8"; var $yellow; //access to API // Handle initialisation @@ -26,7 +26,7 @@ class YellowUpdate { $statusCode = $this->processRequestInstallation($serverScheme, $serverName, $base, $location, $fileName); } else { - $statusCode = $this->processRequestUpdate($serverScheme, $serverName, $base, $location, $fileName); + $statusCode = $this->processRequestPending($serverScheme, $serverName, $base, $location, $fileName); } return $statusCode; } @@ -49,7 +49,7 @@ class YellowUpdate return "update [FEATURE]"; } - // Update software + // Update website function updateCommand($args) { list($command, $feature) = $args; @@ -64,7 +64,7 @@ class YellowUpdate if($statusCode==200) $statusCode = $this->download($data); if($statusCode==200) $statusCode = $this->update(); if($statusCode!=200) echo "ERROR updating files: ".$this->yellow->page->get("pageError")."\n"; - echo "Yellow $command: Software ".($statusCode!=200 ? "not " : "")."updated\n"; + echo "Yellow $command: Website ".($statusCode!=200 ? "not " : "")."updated\n"; } else { if($statusCode!=200) echo "ERROR updating files: ".$this->yellow->page->get("pageError")."\n"; echo "Yellow $command: No updates available\n"; @@ -84,7 +84,7 @@ class YellowUpdate return $statusCode; } - // Download available updates + // Download available software function download($data) { $statusCode = 0; @@ -261,8 +261,8 @@ class YellowUpdate return $ok; } - // Process request to update software - function processRequestUpdate($serverScheme, $serverName, $base, $location, $fileName) + // Process request to install pending software + function processRequestPending($serverScheme, $serverName, $base, $location, $fileName) { $statusCode = 0; if($this->isContentFile($fileName)) diff --git a/system/plugins/webinterface.php b/system/plugins/webinterface.php @@ -33,6 +33,12 @@ class YellowWebinterface $this->users->load($this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile")); } + // Handle update + function onUpdate($name) + { + return $this->cleanCommand(array("clean", "all")); + } + // Handle request function onRequest($serverScheme, $serverName, $base, $location, $fileName) { @@ -500,7 +506,7 @@ class YellowWebinterface return $statusCode; } - // Process request to show version + // Process request to show software version function processRequestVersion($serverScheme, $serverName, $base, $location, $fileName) { $this->response->action = "version"; @@ -531,7 +537,7 @@ class YellowWebinterface return $statusCode; } - // Process request to update software + // Process request to update website function processRequestUpdate($serverScheme, $serverName, $base, $location, $fileName) { $statusCode = 0;