From 7d6a5eca4e0a38ae615634542859d29ab79c94e8 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sun, 18 Dec 2011 14:25:13 +0100 Subject: Modified db-model for plugins and fixed a bug in the frontend. * The db-model for plugins was updated, so it is compatible with the plugin packages. * Preview of comments now works again. --- ratatoeskr/frontend.php | 2 +- ratatoeskr/main.php | 6 +- ratatoeskr/setup/create_tables.php | 16 ++-- ratatoeskr/sys/models.php | 150 ++++++++++++++++++++++++++----------- ratatoeskr/sys/utils.php | 22 ++++++ 5 files changed, 142 insertions(+), 54 deletions(-) (limited to 'ratatoeskr') diff --git a/ratatoeskr/frontend.php b/ratatoeskr/frontend.php index 349fe80..f022958 100644 --- a/ratatoeskr/frontend.php +++ b/ratatoeskr/frontend.php @@ -750,7 +750,7 @@ function frontend_url_handler(&$data, $url_now, &$url_next) if(isset($_GET["comment"])) { if(isset($_POST["preview_comment"])) - $ste->vars["current"]["comment_prev"] = comment_filter(textprocessor_apply($_POST["comment_text"], $ratatoeskr_settings["comment_textprocessor"])); + $ste->vars["current"]["comment_prev"] = Comment::htmlize_comment_text($_POST["comment_text"]); else if(isset($_POST["post_comment"])) { $rejected = False; diff --git a/ratatoeskr/main.php b/ratatoeskr/main.php index 270537d..d3be695 100644 --- a/ratatoeskr/main.php +++ b/ratatoeskr/main.php @@ -20,14 +20,16 @@ require_once(dirname(__FILE__) . "/backend.php"); function ratatoeskr() { - global $backend_subactions, $ste, $url_handlers; + global $backend_subactions, $ste, $url_handlers, $ratatoeskr_settings; session_start(); if(!CONFIG_FILLED_OUT) return setup(); db_connect(); - $activeplugins = array_filter(PluginDB::all(), function($plugin) { return $plugin->active; }); + clean_database(); + + $activeplugins = array_filter(Plugin::all(), function($plugin) { return $plugin->active; }); $plugin_objs = array(); foreach($activeplugins as $plugin) { diff --git a/ratatoeskr/setup/create_tables.php b/ratatoeskr/setup/create_tables.php index 8405ade..543a7e3 100644 --- a/ratatoeskr/setup/create_tables.php +++ b/ratatoeskr/setup/create_tables.php @@ -61,17 +61,21 @@ CREATE TABLE `PREFIX_multilingual` ( PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -CREATE TABLE `PREFIX_plugins` ( +CREATE TABLE `ratatoeskr_plugins` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` text COLLATE utf8_unicode_ci NOT NULL, - `class` text COLLATE utf8_unicode_ci NOT NULL, - `version` text COLLATE utf8_unicode_ci NOT NULL, `author` text COLLATE utf8_unicode_ci NOT NULL, - `author_url` text COLLATE utf8_unicode_ci NOT NULL, - `description` text COLLATE utf8_unicode_ci NOT NULL, + `versiontext` text COLLATE utf8_unicode_ci NOT NULL, + `versioncount` int(11) NOT NULL, + `short_description` text COLLATE utf8_unicode_ci NOT NULL, + `updatepath` text COLLATE utf8_unicode_ci NOT NULL, + `web` text COLLATE utf8_unicode_ci NOT NULL, `help` text COLLATE utf8_unicode_ci NOT NULL, - `phpcode` text COLLATE utf8_unicode_ci NOT NULL, + `code` text COLLATE utf8_unicode_ci NOT NULL, + `classname` text COLLATE utf8_unicode_ci NOT NULL, `active` tinyint(4) NOT NULL, + `installed` tinyint(4) NOT NULL, + `added` bigint(20) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php index 2dadb22..f744fbf 100644 --- a/ratatoeskr/sys/models.php +++ b/ratatoeskr/sys/models.php @@ -928,18 +928,21 @@ class Comment } /* - * Function: create_html - * Creates the comments HTML representation. It applys the page's comment textprocessor on it + * Function: htmlize_comment_text + * Creates the HTML representation of a comment text. It applys the page's comment textprocessor on it * and filters some potentially harmful tags using kses. - * + * + * Parameters: + * $text - Text to HTMLize. + * * Returns: - * The HTML representation. + * HTML code. */ - public function create_html() + public static function htmlize_comment_text($text) { global $ratatoeskr_settings; - return kses(textprocessor_apply($this->text, $ratatoeskr_settings["comment_textprocessor"]), array( + return kses(textprocessor_apply($text, $ratatoeskr_settings["comment_textprocessor"]), array( "a" => array("href" => 1, "hreflang" => 1, "title" => 1, "rel" => 1, "rev" => 1), "b" => array(), "i" => array(), @@ -953,7 +956,12 @@ class Comment "code" => array(), "pre" => array(), "blockquote" => array("cite" => 1), - "h1" => array(), "h2" => array(), "h3" => array(), "h4" => array(), "h5" => array(), "h6" => array(), + "h1" => array(), + "h2" => array(), + "h3" => array(), + "h4" => array(), + "h5" => array(), + "h6" => array(), "img" => array("src" => 1, "alt" => 1, "width" => 1, "height" => 1), "s" => array(), "q" => array("cite" => 1), @@ -983,6 +991,18 @@ class Comment )); } + /* + * Function: create_html + * Applys onto this comment's text. + * + * Returns: + * The HTML representation. + */ + public function create_html() + { + return self::htmlize_comment_text($this->text); + } + /* * Function: save * Save changes to database. @@ -1136,40 +1156,56 @@ class Style } /* - * Class: PluginDB + * Class: Plugin * The representation of a plugin in the database. - * See for loader functions and higher-level plugin access. */ -class PluginDB +class Plugin { private $id; /* * Variables: Public class variables. * - * $name - Plugin name - * $class - Main class of the plugin - * $version - Plugin version - * $author - Plugin author - * $author_url - Website of author - * $description - Description of plugin - * $help - Help page (HTML) - * $phpcode - The plugin code - * $active - Is the plugin active? - */ - - public $name = ""; - public $class = ""; - public $version = ""; - public $author = ""; - public $author_url = ""; - public $description = ""; - public $help = ""; - public $phpcode = ""; - public $active = False; + * $name - Plugin name. + * $code - Plugin code. + * $classname - Main class of the plugin. + * $active - Is the plugin activated? + * $author - Author of the plugin. + * $versiontext - Version (text) + * $versioncount - Version (counter) + * $short_description - A short description. + * $updatepath - URL for updates. + * $web - Webpage of the plugin. + * $help - Help page. + * $license - License text. + * $installed - Is this plugin installed? Used during the installation process. + */ + + public $name; + public $code; + public $classname; + public $active; + public $author; + public $versiontext; + public $versioncount; + public $short_description; + public $updatepath; + public $web; + public $help; + public $license; + public $installed; private function __construct() { } + /* + * Function: clean_db + * Performs some datadase cleanup jobs on the plugin table. + */ + public static function clean_db() + { + qdb("DELETE FROM `PREFIX_plugins` WHERE `installed` = 0 AND `added` < %d", (time() - (60*5))); + } + /* * Function: get_id */ @@ -1182,7 +1218,7 @@ class PluginDB public static function create() { $obj = new self; - qdb("INSERT INTO `PREFIX_plugins` () VALUES ()"); + qdb("INSERT INTO `PREFIX_plugins` (`added`) VALUES (%d)", time()); $obj->id = mysql_insert_id(); return $obj; } @@ -1198,21 +1234,25 @@ class PluginDB { $obj = new self; - $result = qdb("SELECT `name`, `class`, `version`, `author`, `author_url`, `description`, `help`, `phpcode`, `active` FROM `PREFIX_plugins` WHERE `id` = %d", $id); + $result = qdb("SELECT `name`, `author`, `versiontext`, `versioncount`, `short_description`, `updatepath`, `web`, `help`, `code`, `classname`, `active`, `license`, `installed` FROM `PREFIX_plugins` WHERE `id` = %d", $id); $sqlrow = mysql_fetch_assoc($result); if($sqlrow === False) throw new DoesNotExistError(); - $obj->id = $id; - $obj->name = $sqlrow["name"]; - $obj->class = $sqlrow["class"]; - $obj->version = $sqlrow["version"]; - $obj->author = $sqlrow["author"]; - $obj->author_url = $sqlrow["author_url"]; - $obj->description = $sqlrow["description"]; - $obj->help = $sqlrow["help"]; - $obj->phpcode = $sqlrow["phpcode"]; - $obj->active = ($sqlrow["active"] == 1); + $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); return $obj; } @@ -1222,7 +1262,7 @@ class PluginDB * Gets all Plugins * * Returns: - * List of objects. + * List of objects. */ public static function all() { @@ -1238,8 +1278,8 @@ class PluginDB */ public function save() { - qdb("UPDATE `PREFIX_plugins` SET `name` = '%s', `class` = '%s', `version` = '%s', `author` = '%s', `author_url` = '%s', `description` = '%s', `help` = '%s', `phpcode` = '%s', `active` = %d WHERE `id` = %d`", - $this->name, $this->class, $this->version, $this->author, $this->author_url, $this->description, $this->help, $this->phpcode, $this->active ? 1 : 0, $this->id); + 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); } /* @@ -1248,6 +1288,12 @@ class PluginDB public function delete() { qdb("DELETE FROM `PREFIX_plugins` WHERE `id` = %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)) + delete_directory(SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/public/" . $this->id); + if(is_dir(SITE_BASE_PATH . "/ratatoeskr/templates/src/plugintemplates/" . $this->id)) + delete_directory(SITE_BASE_PATH . "/ratatoeskr/templates/src/plugintemplates/" . $this->id); } /* @@ -2307,4 +2353,18 @@ class Article } } +/* + * Function: clean_database + * Clean up the database + */ +function clean_database() +{ + global $ratatoeskr_settings; + if((!isset($ratatoeskr_settings["last_db_cleanup"])) or ($ratatoeskr_repositories["last_db_cleanup"] < (time() - 86400))) + { + Plugin::clean_db(); + $ratatoeskr_settings["last_db_cleanup"] = time(); + } +} + ?> diff --git a/ratatoeskr/sys/utils.php b/ratatoeskr/sys/utils.php index 5d0c3dc..d6093ca 100644 --- a/ratatoeskr/sys/utils.php +++ b/ratatoeskr/sys/utils.php @@ -199,6 +199,28 @@ function htmlesc($text) return htmlentities($text, ENT_QUOTES, "UTF-8"); } +/* + * Function: delete_directory + * Delete a directory and all of its content. + */ +function delete_directory($dir) +{ + $dir_content = scandir($dir); + foreach($dir_content as $f) + { + if(($f == "..") or ($f == ".")) + continue; + + $f = "$dir/$f"; + + if(is_dir($f)) + delete_directory($f); + else + unlink($f); + } + rmdir($dir); +} + /* * Constant: SITE_BASE_PATH * The Base path of this ratatoeskr site. -- cgit v1.2.3-70-g09d2