System update (version handling)
This commit is contained in:
parent
2b8adbaab8
commit
9fdeb9972b
3 changed files with 126 additions and 51 deletions
|
@ -5,7 +5,7 @@
|
|||
// Command line plugin
|
||||
class YellowCommandline
|
||||
{
|
||||
const Version = "0.6.7";
|
||||
const Version = "0.6.8";
|
||||
var $yellow; //access to API
|
||||
var $files; //number of files
|
||||
var $errors; //number of errors
|
||||
|
@ -16,7 +16,8 @@ class YellowCommandline
|
|||
function onLoad($yellow)
|
||||
{
|
||||
$this->yellow = $yellow;
|
||||
$this->yellow->config->setDefault("commandlineVersionUrl", "https://github.com/datenstrom/yellow-plugins");
|
||||
$this->yellow->config->setDefault("commandlinePluginsUrl", "https://github.com/datenstrom/yellow-plugins");
|
||||
$this->yellow->config->setDefault("commandlineThemesUrl", "https://github.com/datenstrom/yellow-themes");
|
||||
}
|
||||
|
||||
// Handle command
|
||||
|
@ -62,10 +63,9 @@ class YellowCommandline
|
|||
$statusCode = 0;
|
||||
$serverSoftware = $this->yellow->toolbox->getServerSoftware();
|
||||
echo "Yellow ".YellowCore::Version.", PHP ".PHP_VERSION.", $serverSoftware\n";
|
||||
$url = $this->yellow->config->get("commandlineVersionUrl");
|
||||
list($dummy, $command) = $args;
|
||||
list($statusCode, $versionCurrent) = $this->getPluginVersion();
|
||||
list($statusCode, $versionLatest) = $this->getPluginVersion($url);
|
||||
list($statusCode, $versionCurrent) = $this->getSoftwareVersion();
|
||||
list($statusCode, $versionLatest) = $this->getSoftwareVersion(false);
|
||||
foreach($versionCurrent as $key=>$value)
|
||||
{
|
||||
if($versionCurrent[$key] >= $versionLatest[$key])
|
||||
|
@ -76,7 +76,7 @@ class YellowCommandline
|
|||
++$updates;
|
||||
}
|
||||
}
|
||||
if($statusCode != 200) echo "ERROR checking updates at $url: $versionLatest[error]\n";
|
||||
if($statusCode != 200) echo "ERROR checking updates: $versionLatest[error]\n";
|
||||
if($updates) echo "Yellow $command: $updates update".($updates==1 ? "":"s")." available at $url\n";
|
||||
return $statusCode;
|
||||
}
|
||||
|
@ -427,58 +427,62 @@ class YellowCommandline
|
|||
return $locations;
|
||||
}
|
||||
|
||||
// Return plugin version
|
||||
function getPluginVersion($url = "")
|
||||
// Return software version
|
||||
function getSoftwareVersion($current = true)
|
||||
{
|
||||
$version = array();
|
||||
if(empty($url))
|
||||
if($current)
|
||||
{
|
||||
$statusCode = 200;
|
||||
$version["YellowCore"] = YellowCore::Version;
|
||||
foreach($this->yellow->plugins->plugins as $key=>$value) $version[$value["class"]] = $value[version];
|
||||
foreach($this->yellow->plugins->getData() as $key=>$value) $version[$key] = $value;
|
||||
foreach($this->yellow->themes->getData() as $key=>$value) $version[$key] = $value;
|
||||
} else {
|
||||
if(extension_loaded("curl"))
|
||||
{
|
||||
$pluginVersionUrl = $this->getPluginVersionUrl($url);
|
||||
$curlHandle = curl_init();
|
||||
curl_setopt($curlHandle, CURLOPT_URL, $pluginVersionUrl);
|
||||
curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; YellowCore/".YellowCore::Version).")";
|
||||
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 30);
|
||||
$rawData = curl_exec($curlHandle);
|
||||
$statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
|
||||
curl_close($curlHandle);
|
||||
if($statusCode == 200)
|
||||
{
|
||||
if(defined("DEBUG") && DEBUG>=2) echo "YellowCommandline::getPluginVersion file:$pluginVersionUrl\n";
|
||||
foreach($this->yellow->toolbox->getTextLines($rawData) as $line)
|
||||
{
|
||||
if(preg_match("/^(\w+)\s*:\s*([0-9\.]+)/", $line, $matches))
|
||||
{
|
||||
$version[$matches[1]] = $matches[2];
|
||||
if(defined("DEBUG") && DEBUG>=3) echo "YellowCommandline::getPluginVersion $matches[1]:$matches[2]\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if($statusCode == 0) $statusCode = 444;
|
||||
$version["error"] = $this->yellow->toolbox->getHttpStatusFormatted($statusCode);
|
||||
} else {
|
||||
$statusCode = 500;
|
||||
$version["error"] = "Plugin 'commandline' requires cURL library!";
|
||||
}
|
||||
list($statusCodePlugins, $versionPlugins) = $this->getSoftwareVersionFromUrl($this->yellow->config->get("commandlinePluginsUrl"));
|
||||
list($statusCodeThemes, $versionThemes) = $this->getSoftwareVersionFromUrl($this->yellow->config->get("commandlineThemesUrl"));
|
||||
$statusCode = max($statusCodePlugins, $statusCodeThemes);
|
||||
$version = array_merge($versionPlugins, $versionThemes);
|
||||
}
|
||||
uksort($version, strnatcasecmp);
|
||||
return array($statusCode, $version);
|
||||
}
|
||||
|
||||
// Return plugin version URL from repository
|
||||
function getPluginVersionUrl($url)
|
||||
// Return software version URL from repository
|
||||
function getSoftwareVersionFromUrl($url)
|
||||
{
|
||||
$version = array();
|
||||
$urlVersion = $url;
|
||||
if(preg_match("#^https://github.com/(.+)$#", $url, $matches))
|
||||
{
|
||||
$url = "https://raw.githubusercontent.com/".$matches[1]."/master/version.ini";
|
||||
$urlVersion = "https://raw.githubusercontent.com/".$matches[1]."/master/version.ini";
|
||||
}
|
||||
return $url;
|
||||
if(extension_loaded("curl"))
|
||||
{
|
||||
$curlHandle = curl_init();
|
||||
curl_setopt($curlHandle, CURLOPT_URL, $urlVersion);
|
||||
curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; YellowCore/".YellowCore::Version).")";
|
||||
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 30);
|
||||
$rawData = curl_exec($curlHandle);
|
||||
$statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
|
||||
curl_close($curlHandle);
|
||||
if($statusCode == 200)
|
||||
{
|
||||
if(defined("DEBUG") && DEBUG>=2) echo "YellowCommandline::getSoftwareVersion location:$urlVersion\n";
|
||||
foreach($this->yellow->toolbox->getTextLines($rawData) as $line)
|
||||
{
|
||||
if(preg_match("/^(\w+)\s*:\s*([0-9\.]+)/", $line, $matches))
|
||||
{
|
||||
$version[$matches[1]] = $matches[2];
|
||||
if(defined("DEBUG") && DEBUG>=3) echo "YellowCommandline::getSoftwareVersion $matches[1]:$matches[2]\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if($statusCode == 0) $statusCode = 444;
|
||||
$version["error"] = "$url - ".$this->yellow->toolbox->getHttpStatusFormatted($statusCode);
|
||||
} else {
|
||||
$statusCode = 500;
|
||||
$version["error"] = "Plugin 'commandline' requires cURL library!";
|
||||
}
|
||||
return array($statusCode, $version);
|
||||
}
|
||||
|
||||
// Return command help
|
||||
|
|
|
@ -10,6 +10,7 @@ class YellowCore
|
|||
var $pages; //pages from file system
|
||||
var $files; //files from file system
|
||||
var $plugins; //plugins
|
||||
var $themes; //themes
|
||||
var $config; //configuration
|
||||
var $text; //text strings
|
||||
var $lookup; //location and file lookup
|
||||
|
@ -21,6 +22,7 @@ class YellowCore
|
|||
$this->pages = new YellowPages($this);
|
||||
$this->files = new YellowFiles($this);
|
||||
$this->plugins = new YellowPlugins($this);
|
||||
$this->themes = new YellowThemes($this);
|
||||
$this->config = new YellowConfig($this);
|
||||
$this->text = new YellowText($this);
|
||||
$this->lookup = new YellowLookup($this);
|
||||
|
@ -79,6 +81,7 @@ class YellowCore
|
|||
}
|
||||
$this->config->load($this->config->get("configDir").$this->config->get("configFile"));
|
||||
$this->text->load($this->config->get("pluginDir").$this->config->get("textFile"));
|
||||
$this->themes->load($this->config->get("themeDir")."(.*).css");
|
||||
date_default_timezone_set($this->config->get("serverTime"));
|
||||
list($pathRoot, $pathHome) = $this->lookup->getContentInformation();
|
||||
$this->config->set("contentRootDir", $pathRoot);
|
||||
|
@ -561,7 +564,11 @@ class YellowPage
|
|||
$output .= "Yellow ".YellowCore::Version.", PHP ".PHP_VERSION.", $serverSoftware<br />\n";
|
||||
foreach($this->yellow->plugins->getData() as $key=>$value)
|
||||
{
|
||||
$output .= htmlspecialchars("$key: $value")."<br />\n";
|
||||
$output .= htmlspecialchars("$key $value")."<br />\n";
|
||||
}
|
||||
foreach($this->yellow->themes->getData() as $key=>$value)
|
||||
{
|
||||
$output .= htmlspecialchars("$key $value")."<br />\n";
|
||||
}
|
||||
} else {
|
||||
foreach($this->yellow->config->getData($text) as $key=>$value)
|
||||
|
@ -603,7 +610,7 @@ class YellowPage
|
|||
{
|
||||
$this->error(500, "Language '".$this->get("language")."' does not exist!");
|
||||
}
|
||||
if(!is_file($this->yellow->config->get("themeDir").$this->get("theme").".css"))
|
||||
if(!$this->yellow->themes->isExisting($this->get("theme")))
|
||||
{
|
||||
$this->error(500, "Theme '".$this->get("theme")."' does not exist!");
|
||||
}
|
||||
|
@ -1533,14 +1540,14 @@ class YellowFiles
|
|||
class YellowPlugins
|
||||
{
|
||||
var $yellow; //access to API
|
||||
var $plugins; //registered plugins
|
||||
var $modified; //plugin modification date
|
||||
var $plugins; //registered plugins
|
||||
|
||||
function __construct($yellow)
|
||||
{
|
||||
$this->yellow = $yellow;
|
||||
$this->plugins = array();
|
||||
$this->modified = 0;
|
||||
$this->plugins = array();
|
||||
}
|
||||
|
||||
// Load plugins
|
||||
|
@ -1583,7 +1590,7 @@ class YellowPlugins
|
|||
{
|
||||
$version = array();
|
||||
$version["YellowCore"] = YellowCore::Version;
|
||||
foreach($this->plugins as $key=>$value) $version[$value["class"]] = $value[version];
|
||||
foreach($this->plugins as $key=>$value) $version[$value["class"]] = $value["version"];
|
||||
uksort($version, strnatcasecmp);
|
||||
return $version;
|
||||
}
|
||||
|
@ -1601,6 +1608,70 @@ class YellowPlugins
|
|||
}
|
||||
}
|
||||
|
||||
// Yellow themes
|
||||
class YellowThemes
|
||||
{
|
||||
var $yellow; //access to API
|
||||
var $modified; //theme modification date
|
||||
var $themes; //themes
|
||||
|
||||
function __construct($yellow)
|
||||
{
|
||||
$this->yellow = $yellow;
|
||||
$this->modified = 0;
|
||||
$this->themes = array();
|
||||
}
|
||||
|
||||
// Load themes
|
||||
function load($fileName)
|
||||
{
|
||||
$path = dirname($fileName);
|
||||
$regex = "/^".basename($fileName)."$/";
|
||||
foreach($this->yellow->toolbox->getDirectoryEntries($path, $regex, true, false) as $entry)
|
||||
{
|
||||
$name = $this->yellow->lookup->normaliseName(basename($entry), true, true);
|
||||
$theme = $version = "";
|
||||
$this->modified = max($this->modified, filemtime($entry));
|
||||
$fileData = $this->yellow->toolbox->readFile($entry, 4096);
|
||||
foreach($this->yellow->toolbox->getTextLines($fileData) as $line)
|
||||
{
|
||||
preg_match("/^\/\*\s*(.*?)\s*:\s*(.*?)\s*\*\/$/", $line, $matches);
|
||||
if(lcfirst($matches[1])=="theme" && !strempty($matches[2])) $theme = $matches[2];
|
||||
if(lcfirst($matches[1])=="version" && !strempty($matches[2])) $version = $matches[2];
|
||||
if(!empty($line) && $line[0]!= '/') break;
|
||||
}
|
||||
if(!empty($theme) && !empty($version))
|
||||
{
|
||||
$this->themes[$name] = array();
|
||||
$this->themes[$name]["theme"] = $theme;
|
||||
$this->themes[$name]["version"] = $version;
|
||||
if(defined("DEBUG") && DEBUG>=3) echo "YellowThemes::load $theme:$version<br/>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return theme version
|
||||
function getData()
|
||||
{
|
||||
$version = array();
|
||||
foreach($this->themes as $key=>$value) $version[$value["theme"]] = $value["version"];
|
||||
uksort($version, strnatcasecmp);
|
||||
return $version;
|
||||
}
|
||||
|
||||
// Return theme modification date, Unix time or HTTP format
|
||||
function getModified($httpFormat = false)
|
||||
{
|
||||
return $httpFormat ? $this->yellow->toolbox->getHttpDateFormatted($this->modified) : $this->modified;
|
||||
}
|
||||
|
||||
// Check if theme exists
|
||||
function isExisting($name)
|
||||
{
|
||||
return !is_null($this->themes[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
// Yellow configuration
|
||||
class YellowConfig
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Flatsite theme */
|
||||
/* Theme: Flatsite theme */
|
||||
/* Version: 0.6.5 */
|
||||
/* Designer: Mark Mayberg */
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue