From df0658f7e10d2bf87460195f792398d16eee811e Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Fri, 23 Dec 2011 01:43:53 +0100 Subject: Added plugin management to bakend and fixed db models. --- ratatoeskr/sys/models.php | 67 ++++++++++++++++++++++++++++++---------- ratatoeskr/sys/plugin_api.php | 2 +- ratatoeskr/sys/pluginpackage.php | 31 ++++++++++++++++--- 3 files changed, 78 insertions(+), 22 deletions(-) (limited to 'ratatoeskr/sys') diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php index f744fbf..a0a1fda 100644 --- a/ratatoeskr/sys/models.php +++ b/ratatoeskr/sys/models.php @@ -1179,6 +1179,7 @@ class Plugin * $help - Help page. * $license - License text. * $installed - Is this plugin installed? Used during the installation process. + * $update - Should the plugin be updated at next start? */ public $name; @@ -1194,6 +1195,7 @@ class Plugin public $help; public $license; public $installed; + public $update; private function __construct() { } @@ -1223,6 +1225,35 @@ class Plugin return $obj; } + /* + * Function: fill_from_pluginpackage + * Fills plugin data from an object. + * + * Parameters: + * $pkg - The object. + */ + public function fill_from_pluginpackage($pkg) + { + $this->name = $pkg->name; + $this->code = $pkg->code; + $this->classname = $pkg->classname; + $this->author = $pkg->author; + $this->versiontext = $pkg->versiontext; + $this->versioncount = $pkg->versioncount; + $this->short_description = $pkg->short_description; + $this->updatepath = $pkg->updatepath; + $this->web = $pkg->web; + $this->license = $pkg->license; + $this->help = $pkg->help; + + if(!empty($pkg->custompub)) + array2dir($pkg->custompub, dirname(__FILE__) . "/../plugin_extradata/public/" . $this->get_id()); + if(!empty($pkg->custompriv)) + array2dir($pkg->custompriv, dirname(__FILE__) . "/../plugin_extradata/private/" . $this->get_id()); + if(!empty($pkg->tpls)) + array2dir($pkg->tpls, dirname(__FILE__) . "/../templates/srv/plugintemplates/" . $this->get_id()); + } + /* * Constructor: by_id * Gets plugin by ID. @@ -1234,25 +1265,26 @@ class Plugin { $obj = new self; - $result = qdb("SELECT `name`, `author`, `versiontext`, `versioncount`, `short_description`, `updatepath`, `web`, `help`, `code`, `classname`, `active`, `license`, `installed` FROM `PREFIX_plugins` WHERE `id` = %d", $id); + $result = qdb("SELECT `name`, `author`, `versiontext`, `versioncount`, `short_description`, `updatepath`, `web`, `help`, `code`, `classname`, `active`, `license`, `installed`, `update` FROM `PREFIX_plugins` WHERE `id` = %d", $id); $sqlrow = mysql_fetch_assoc($result); if($sqlrow === False) throw new DoesNotExistError(); - $this->id = $id; - $this->name = $sqlrow["name"]; - $this->code = $sqlrow["code"]; - $this->classname = $sqlrow["classname"]; - $this->active = ($sqlrow["active"] == 1); - $this->author = $sqlrow["author"]; - $this->versiontext = $sqlrow["versiontext"]; - $this->versioncount = $sqlrow["versioncount"]; - $this->short_description = $sqlrow["short_description"]; - $this->updatepath = $sqlrow["updatepath"]; - $this->web = $sqlrow["web"]; - $this->help = $sqlrow["help"]; - $this->license = $sqlrow["license"]; - $this->installed = ($sqlrow["installed"] == 1); + $obj->id = $id; + $obj->name = $sqlrow["name"]; + $obj->code = $sqlrow["code"]; + $obj->classname = $sqlrow["classname"]; + $obj->active = ($sqlrow["active"] == 1); + $obj->author = $sqlrow["author"]; + $obj->versiontext = $sqlrow["versiontext"]; + $obj->versioncount = $sqlrow["versioncount"]; + $obj->short_description = $sqlrow["short_description"]; + $obj->updatepath = $sqlrow["updatepath"]; + $obj->web = $sqlrow["web"]; + $obj->help = $sqlrow["help"]; + $obj->license = $sqlrow["license"]; + $obj->installed = ($sqlrow["installed"] == 1); + $obj->update = ($sqlrow["update"] == 1); return $obj; } @@ -1278,8 +1310,8 @@ class Plugin */ public function save() { - qdb("UPDATE `PREFIX_plugins` SET `name` = '%s', `code` = '%s', `classname` = '%s', `active` = %d, `versiontext` = '%s', `versioncount` = %d, `short_description` = '%s', `updatepath` = '%s', `web` = '%s', `help` = '%s', `installed` = %d, `license` = '%s' WHERE `id` = %d", - $this->name, $this->code, $this->classname, ($this->active ? 1 : 0), $this->versiontext, $this->versioncount, $this->short_description, $this>updatepath, $this->web, $this->help, ($this->installed ? 1 : 0), $this->license, $this->id); + qdb("UPDATE `PREFIX_plugins` SET `name` = '%s', `author` = '%s', `code` = '%s', `classname` = '%s', `active` = %d, `versiontext` = '%s', `versioncount` = %d, `short_description` = '%s', `updatepath` = '%s', `web` = '%s', `help` = '%s', `installed` = %d, `update` = %d, `license` = '%s' WHERE `id` = %d", + $this->name, $this>author, $this->code, $this->classname, ($this->active ? 1 : 0), $this->versiontext, $this->versioncount, $this->short_description, $this->updatepath, $this->web, $this->help, ($this->installed ? 1 : 0), ($this->update ? 1 : 0), $this->license, $this->id); } /* @@ -1288,6 +1320,7 @@ class Plugin public function delete() { qdb("DELETE FROM `PREFIX_plugins` WHERE `id` = %d", $this->id); + qdb("DELETE FROM `PREFIX_plugin_kvstorage` WHERE `plugin` = %d", $this->id); if(is_dir(SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/private/" . $this->id)) delete_directory(SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/private/" . $this->id); if(is_dir(SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/public/" . $this->id)) diff --git a/ratatoeskr/sys/plugin_api.php b/ratatoeskr/sys/plugin_api.php index 362fd9e..f34a42a 100644 --- a/ratatoeskr/sys/plugin_api.php +++ b/ratatoeskr/sys/plugin_api.php @@ -15,7 +15,7 @@ require_once(dirname(__FILE__) . "/../frontend.php"); /* * Constant: APIVERSION - * The current API version. + * The current API version (1). */ define("APIVERSION", 1); diff --git a/ratatoeskr/sys/pluginpackage.php b/ratatoeskr/sys/pluginpackage.php index 0200c79..d8ce170 100644 --- a/ratatoeskr/sys/pluginpackage.php +++ b/ratatoeskr/sys/pluginpackage.php @@ -38,6 +38,29 @@ function dir2array($dir) return $rv; } +/* + * Function: array2dir + * Unpack an array into a directory. + * + * Parameters: + * $a - Array to unpack. + * $dir - Directory to unpack to. + */ +function array2dir($a, $dir) +{ + if(!is_dir($dir)) + mkdir($dir); + + foreach($a as $k => $v) + { + $k = "$dir/$k"; + if(is_array($v)) + array2dir($v, $k); + else + file_put_contents($k, $v); + } +} + /* * Class: InvalidPackage * An Exception that 's function can throw, if the package is invalid. @@ -99,7 +122,7 @@ class PluginPackage */ public function validate() { - function validate_url ($u) { return preg_match("/^http[s]{0,1}://.*$/", $u) != 0; } + function validate_url ($u) { return preg_match("/^http[s]{0,1}:\\/\\/.*$/", $u) != 0; } function validate_arraydir($a) { if(!is_array($a)) @@ -177,7 +200,7 @@ class PluginPackage throw new InvalidPackage("Wrong SHA1 hash"); $plugin = @unserialize($pluginser); - if(!($plugin instanceof this)) + if(!($plugin instanceof self)) throw new InvalidPackage("Not the correct class or not unserializeable."); $plugin->validate(); @@ -198,8 +221,8 @@ class PluginPackage public function save() { $this->validate(); - $ser = serialize($self); - return this::$magic . sha1($ser, True) . gzcompress($ser, 9); + $ser = serialize($this); + return self::$magic . sha1($ser, True) . gzcompress($ser, 9); } /* -- cgit v1.2.3-70-g09d2