Updated loading of plugins and themes

This commit is contained in:
markseu 2018-10-09 14:49:48 +02:00
parent e92d5ab973
commit 8dd44870cc
12 changed files with 21 additions and 34 deletions

View file

@ -1935,5 +1935,3 @@ class MinifyBasic extends Minify {
return $this->restoreExtractedData($content);
}
}
$yellow->plugins->register("bundle", "YellowBundle", YellowBundle::VERSION);

View file

@ -578,5 +578,3 @@ class YellowCommand {
return $statusCode;
}
}
$yellow->plugins->register("command", "YellowCommand", YellowCommand::VERSION);

View file

@ -4,7 +4,7 @@
// This file may be used and distributed under the terms of the public license.
class YellowCore {
const VERSION = "0.7.7";
const VERSION = "0.7.8";
public $page; //current page
public $pages; //pages from file system
public $files; //files from file system
@ -1468,25 +1468,26 @@ class YellowPlugins {
$this->modified = max($this->modified, filemtime($entry));
global $yellow;
require_once($entry);
$name = $this->yellow->lookup->normaliseName(basename($entry), true, true, true);
$this->register($name, "Yellow".ucfirst($name));
}
$callback = function ($a, $b) {
return $a["priority"] - $b["priority"];
};
uasort($this->plugins, $callback);
foreach ($this->plugins as $key=>$value) {
$this->plugins[$key]["obj"] = new $value["plugin"];
if (method_exists($this->plugins[$key]["obj"], "onLoad")) $this->plugins[$key]["obj"]->onLoad($yellow);
if (method_exists($this->plugins[$key]["obj"], "onLoad")) $this->plugins[$key]["obj"]->onLoad($this->yellow);
}
}
// Register plugin
public function register($name, $plugin, $version, $priority = 0) {
if (!$this->isExisting($name)) {
if ($priority==0) $priority = count($this->plugins) + 10;
public function register($name, $plugin, $obsoleteVersion = 0, $obsoletePriority = 0) {
if (!$this->isExisting($name) && class_exists($plugin)) {
$this->plugins[$name] = array();
$this->plugins[$name]["obj"] = new $plugin;
$this->plugins[$name]["plugin"] = $plugin;
$this->plugins[$name]["version"] = $version;
$this->plugins[$name]["priority"] = $priority;
$this->plugins[$name]["version"] = defined("$plugin::VERSION") ? $plugin::VERSION : 0;
$this->plugins[$name]["priority"] = defined("$plugin::PRIORITY") ? $plugin::PRIORITY : count($this->plugins) + 10;
}
}
@ -1537,31 +1538,32 @@ class YellowThemes {
$this->modified = max($this->modified, filemtime($entry));
global $yellow;
require_once($entry);
$name = $this->yellow->lookup->normaliseName(basename($entry), true, true, true);
$this->register($name, "YellowTheme".ucfirst($name));
}
foreach ($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.css$/", true, false) as $entry) {
if (defined("DEBUG") && DEBUG>=3) echo "YellowThemes::load file:$entry<br/>\n";
$this->modified = max($this->modified, filemtime($entry));
$name = $this->yellow->lookup->normaliseName(basename($entry), true, true);
if (substru($name, 0, 7)!="bundle-") $this->register($name, "", "");
$name = $this->yellow->lookup->normaliseName(basename($entry), true, true, true);
if (substru($name, 0, 7)!="bundle-") $this->register($name, "stdClass");
}
$callback = function ($a, $b) {
return $a["priority"] - $b["priority"];
};
uasort($this->themes, $callback);
foreach ($this->themes as $key=>$value) {
$this->themes[$key]["obj"] = empty($value["theme"]) ? new stdClass : new $value["theme"];
if (method_exists($this->themes[$key]["obj"], "onLoad")) $this->themes[$key]["obj"]->onLoad($yellow);
if (method_exists($this->themes[$key]["obj"], "onLoad")) $this->themes[$key]["obj"]->onLoad($this->yellow);
}
}
// Register theme
public function register($name, $theme, $version, $priority = 0) {
if (!$this->isExisting($name)) {
if ($priority==0) $priority = count($this->themes) + 10;
public function register($name, $theme, $obsoleteVersion = 0, $obsoletePriority = 0) {
if (!$this->isExisting($name) && class_exists($theme)) {
$this->themes[$name] = array();
$this->themes[$name]["obj"] = new $theme;
$this->themes[$name]["theme"] = $theme;
$this->themes[$name]["version"] = $version;
$this->themes[$name]["priority"] = $priority;
$this->themes[$name]["version"] = defined("$theme::VERSION") ? $theme::VERSION : 0;
$this->themes[$name]["priority"] = defined("$theme::PRIORITY") ? $theme::PRIORITY : count($this->themes) + 10;
}
}

View file

@ -1775,5 +1775,3 @@ class YellowMerge {
return !$conflict ? $output : null;
}
}
$yellow->plugins->register("edit", "YellowEdit", YellowEdit::VERSION);

View file

@ -257,5 +257,3 @@ class YellowImage {
((imagetypes()&(IMG_GIF|IMG_JPG|IMG_PNG))==(IMG_GIF|IMG_JPG|IMG_PNG));
}
}
$yellow->plugins->register("image", "YellowImage", YellowImage::VERSION);

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -5,6 +5,7 @@
class YellowInstall {
const VERSION = "0.7.4";
const PRIORITY = "1";
public $yellow; //access to API
// Handle initialisation
@ -299,5 +300,3 @@ class YellowInstall {
return $features;
}
}
$yellow->plugins->register("install", "YellowInstall", YellowInstall::VERSION, 1);

View file

@ -3863,6 +3863,3 @@ class YellowMarkdownExtraParser extends MarkdownExtraParser {
return $this->hashPart($output);
}
}
$yellow->plugins->register("markdown", "YellowMarkdown", YellowMarkdown::VERSION);

View file

@ -5,6 +5,7 @@
class YellowUpdate {
const VERSION = "0.7.22";
const PRIORITY = "2";
public $yellow; //access to API
public $updates; //number of updates
@ -632,5 +633,3 @@ class YellowUpdate {
return !is_null($data[$software]);
}
}
$yellow->plugins->register("update", "YellowUpdate", YellowUpdate::VERSION, 2);

View file

@ -6,5 +6,3 @@
class YellowThemeFlatsite {
const VERSION = "0.7.6";
}
$yellow->themes->register("flatsite", "YellowThemeFlatsite", YellowThemeFlatsite::VERSION);