aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys
diff options
context:
space:
mode:
Diffstat (limited to 'ratatoeskr/sys')
-rw-r--r--ratatoeskr/sys/db.php150
-rw-r--r--ratatoeskr/sys/init_ste.php58
-rw-r--r--ratatoeskr/sys/models.php5652
-rw-r--r--ratatoeskr/sys/plugin_api.php462
-rw-r--r--ratatoeskr/sys/pluginpackage.php458
-rw-r--r--ratatoeskr/sys/pwhash.php106
-rw-r--r--ratatoeskr/sys/textprocessors.php62
-rw-r--r--ratatoeskr/sys/translation.php76
-rw-r--r--ratatoeskr/sys/urlprocess.php226
-rw-r--r--ratatoeskr/sys/utils.php216
10 files changed, 3733 insertions, 3733 deletions
diff --git a/ratatoeskr/sys/db.php b/ratatoeskr/sys/db.php
index 36d5348..d122502 100644
--- a/ratatoeskr/sys/db.php
+++ b/ratatoeskr/sys/db.php
@@ -1,9 +1,9 @@
<?php
/*
* File: ratatoeskr/sys/db.php
- *
+ *
* Helper functions for dealing with MySQL.
- *
+ *
* License:
* This file is part of Ratatöskr.
* Ratatöskr is licensed unter the MIT / X11 License.
@@ -11,7 +11,7 @@
*/
if(!defined("SETUP"))
- require_once(dirname(__FILE__) . "/../config.php");
+ require_once(dirname(__FILE__) . "/../config.php");
require_once(dirname(__FILE__) . "/utils.php");
@@ -24,17 +24,17 @@ $db_con = Null;
*/
function db_connect()
{
- global $config;
- global $db_con;
-
- $db_con = new PDO(
- "mysql:host=" . $config["mysql"]["server"] . ";dbname=" . $config["mysql"]["db"] . ";charset=utf8",
- $config["mysql"]["user"],
- $config["mysql"]["passwd"],
- array(
- PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
- ));
- $db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ global $config;
+ global $db_con;
+
+ $db_con = new PDO(
+ "mysql:host=" . $config["mysql"]["server"] . ";dbname=" . $config["mysql"]["db"] . ";charset=utf8",
+ $config["mysql"]["user"],
+ $config["mysql"]["passwd"],
+ array(
+ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
+ ));
+ $db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
/*
@@ -44,95 +44,95 @@ function db_connect()
*/
function sub_prefix($q)
{
- global $config;
- return str_replace("PREFIX_", $config["mysql"]["prefix"], $q);
+ global $config;
+ return str_replace("PREFIX_", $config["mysql"]["prefix"], $q);
}
/*
* Function: prep_stmt
- *
+ *
* Prepares a SQL statement using the global DB connection.
* This will also replace "PREFIX_" with the prefix defined in 'config.php'.
- *
+ *
* Parameters:
- * $q - The query / statement to prepare.
- *
+ * $q - The query / statement to prepare.
+ *
* Returns:
- * A PDOStatement object.
+ * A PDOStatement object.
*/
function prep_stmt($q)
{
- global $db_con;
-
- return $db_con->prepare(sub_prefix($q));
+ global $db_con;
+
+ return $db_con->prepare(sub_prefix($q));
}
/*
* Function: qdb
- *
+ *
* Prepares statement (1st argument) with <prep_stmt> and executes it with the remaining arguments.
- *
+ *
* Returns:
- * A PDOStatement object.
+ * A PDOStatement object.
*/
function qdb()
{
- $args = func_get_args();
- if(count($args) < 1)
- throw new InvalidArgumentException("qdb needs at least 1 argument");
-
- $stmt = prep_stmt($args[0]);
- $stmt->execute(array_slice($args, 1));
- return $stmt;
+ $args = func_get_args();
+ if(count($args) < 1)
+ throw new InvalidArgumentException("qdb needs at least 1 argument");
+
+ $stmt = prep_stmt($args[0]);
+ $stmt->execute(array_slice($args, 1));
+ return $stmt;
}
/*
* Class: Transaction
- *
+ *
* Makes using transactions easier.
*/
class Transaction
{
- public $startedhere;
-
- /*
- * Constructor: __construct
- *
- * Start a new transaction.
- */
- public function __construct()
- {
- global $db_con;
- $this->startedhere = !($db_con->inTransaction());
- if($this->startedhere)
- $db_con->beginTransaction();
- }
-
- /*
- * Function: commit
- *
- * Commit the transaction.
- */
- public function commit()
- {
- global $db_con;
-
- if($this->startedhere)
- $db_con->commit();
- }
-
- /*
- * Function: rollback
- *
- * Toll the transaction back.
- */
- public function rollback()
- {
- global $db_con;
-
- if($this->startedhere)
- $db_con->rollBack();
- }
+ public $startedhere;
+
+ /*
+ * Constructor: __construct
+ *
+ * Start a new transaction.
+ */
+ public function __construct()
+ {
+ global $db_con;
+ $this->startedhere = !($db_con->inTransaction());
+ if($this->startedhere)
+ $db_con->beginTransaction();
+ }
+
+ /*
+ * Function: commit
+ *
+ * Commit the transaction.
+ */
+ public function commit()
+ {
+ global $db_con;
+
+ if($this->startedhere)
+ $db_con->commit();
+ }
+
+ /*
+ * Function: rollback
+ *
+ * Toll the transaction back.
+ */
+ public function rollback()
+ {
+ global $db_con;
+
+ if($this->startedhere)
+ $db_con->rollBack();
+ }
}
?>
diff --git a/ratatoeskr/sys/init_ste.php b/ratatoeskr/sys/init_ste.php
index b0a90d1..e45afa6 100644
--- a/ratatoeskr/sys/init_ste.php
+++ b/ratatoeskr/sys/init_ste.php
@@ -2,9 +2,9 @@
/*
* File: ratatoeskr/sys/init_ste.php
- *
+ *
* When included, the file will initialize the global STECore instance.
- *
+ *
* License:
* This file is part of Ratatöskr.
* Ratatöskr is licensed unter the MIT / X11 License.
@@ -17,40 +17,40 @@ $tpl_basedir = dirname(__FILE__) . "/../templates";
if(!isset($ste))
{
- /*
- * Variable: $ste
- *
- * The global STECore instance.
- */
- $ste = new \ste\STECore(new \ste\FilesystemStorageAccess("$tpl_basedir/src", "$tpl_basedir/transc"));
- if(defined("__DEBUG__") && __DEBUG__)
- $ste->mute_runtime_errors = False;
+ /*
+ * Variable: $ste
+ *
+ * The global STECore instance.
+ */
+ $ste = new \ste\STECore(new \ste\FilesystemStorageAccess("$tpl_basedir/src", "$tpl_basedir/transc"));
+ if(defined("__DEBUG__") && __DEBUG__)
+ $ste->mute_runtime_errors = False;
}
$ste->register_tag(
- "l10n_replace",
- function($ste, $params, $sub)
- {
- $content = $sub($ste);
- foreach($params as $name => $replace)
- $content = str_replace("[[$name]]", $replace, $content);
- return $content;
- }
+ "l10n_replace",
+ function($ste, $params, $sub)
+ {
+ $content = $sub($ste);
+ foreach($params as $name => $replace)
+ $content = str_replace("[[$name]]", $replace, $content);
+ return $content;
+ }
);
$ste->register_tag(
- "capitalize",
- function($ste, $params, $sub)
- {
- return ucwords($sub($ste));
- }
+ "capitalize",
+ function($ste, $params, $sub)
+ {
+ return ucwords($sub($ste));
+ }
);
$ste->register_tag(
- "loremipsum",
- function($ste, $params, $sub)
- {
- $repeats = empty($params["repeat"]) ? 1 : $params["repeat"] + 0;
- return implode("\n\n", array_repeat("<p>Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>\n\n<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>\n\n<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>\n\n<p>Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>\n\n<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.</p>\n\n<p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.</p>\n\n<p>Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>", $repeats));
- }
+ "loremipsum",
+ function($ste, $params, $sub)
+ {
+ $repeats = empty($params["repeat"]) ? 1 : $params["repeat"] + 0;
+ return implode("\n\n", array_repeat("<p>Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>\n\n<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>\n\n<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>\n\n<p>Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>\n\n<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.</p>\n\n<p>At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.</p>\n\n<p>Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>", $repeats));
+ }
);
?>
diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php
index 12ca613..c6b7cee 100644
--- a/ratatoeskr/sys/models.php
+++ b/ratatoeskr/sys/models.php
@@ -2,7 +2,7 @@
/*
* File: ratatoeskr/sys/models.php
* Data models to make database accesses more comfortable.
- *
+ *
* License:
* This file is part of Ratatöskr.
* Ratatöskr is licensed unter the MIT / X11 License.
@@ -22,19 +22,19 @@ db_connect();
* Array of default file extensions for most IMAGETYPE_* constants
*/
$imagetype_file_extensions = array(
- IMAGETYPE_GIF => "gif",
- IMAGETYPE_JPEG => "jpg",
- IMAGETYPE_PNG => "png",
- IMAGETYPE_BMP => "bmp",
- IMAGETYPE_TIFF_II => "tif",
- IMAGETYPE_TIFF_MM => "tif",
+ IMAGETYPE_GIF => "gif",
+ IMAGETYPE_JPEG => "jpg",
+ IMAGETYPE_PNG => "png",
+ IMAGETYPE_BMP => "bmp",
+ IMAGETYPE_TIFF_II => "tif",
+ IMAGETYPE_TIFF_MM => "tif",
);
/*
* Variable: $ratatoeskr_settings
* The global <Settings> object. Can be accessed like an array.
* Has these fields:
- *
+ *
* "default_language" - The Language code of the default language.
* "comment_visible_default" - True, if comments should be visible by default.
* "allow_comments_default" - True, if comments should be allowed by default.
@@ -48,7 +48,7 @@ $ratatoeskr_settings = NULL;
/*
* Constants: ARTICLE_STATUS_
* Possible <Article>::$status values.
- *
+ *
* ARTICLE_STATUS_HIDDEN - Article is hidden (Numeric: 0)
* ARTICLE_STATUS_LIVE - Article is visible / live (Numeric: 1)
* ARTICLE_STATUS_STICKY - Article is sticky (Numeric: 2)
@@ -83,16 +83,16 @@ class InvalidDataError extends Exception { }
abstract class BySQLRowEnabled
{
- protected function __construct() { }
-
- abstract protected function populate_by_sqlrow($sqlrow);
-
- protected static function by_sqlrow($sqlrow)
- {
- $obj = new static();
- $obj->populate_by_sqlrow($sqlrow);
- return $obj;
- }
+ protected function __construct() { }
+
+ abstract protected function populate_by_sqlrow($sqlrow);
+
+ protected static function by_sqlrow($sqlrow)
+ {
+ $obj = new static();
+ $obj->populate_by_sqlrow($sqlrow);
+ return $obj;
+ }
}
/*
@@ -100,111 +100,111 @@ abstract class BySQLRowEnabled
* An abstract class for a KVStorage.
*
* See also:
- * <PluginKVStorage>, <ArticleExtradata>
+ * <PluginKVStorage>, <ArticleExtradata>
*/
abstract class KVStorage implements Countable, ArrayAccess, Iterator
{
- private $keybuffer;
- private $counter;
- private $silent_mode;
-
- private $common_vals;
-
- private $stmt_get;
- private $stmt_unset;
- private $stmt_update;
- private $stmt_create;
-
- final protected function init($sqltable, $common)
- {
- $sqltable = sub_prefix($sqltable);
-
- $this->silent_mode = False;
- $this->keybuffer = array();
-
- $selector = "WHERE ";
- $fields = "";
- foreach($common as $field => $val)
- {
- $selector .= "`$field` = ? AND ";
- $fields .= ", `$field`";
- $this->common_vals[] = $val;
- }
-
- $this->stmt_get = prep_stmt("SELECT `value` FROM `$sqltable` $selector `key` = ?");
- $this->stmt_unset = prep_stmt("DELETE FROM `$sqltable` $selector `key` = ?");
- $this->stmt_update = prep_stmt("UPDATE `$sqltable` SET `value` = ? $selector `key` = ?");
- $this->stmt_create = prep_stmt("INSERT INTO `$sqltable` (`key`, `value` $fields) VALUES (?,?" . str_repeat(",?", count($common)) . ")");
-
- $get_keys = prep_stmt("SELECT `key` FROM `$sqltable` $selector 1");
- $get_keys->execute($this->common_vals);
- while($sqlrow = $get_keys->fetch())
- $this->keybuffer[] = $sqlrow["key"];
-
- $this->counter = 0;
- }
-
- /*
- * Functions: Silent mode
- * If the silent mode is enabled, the KVStorage behaves even more like a PHP array, i.e. it just returns NULL,
- * if a unknown key was requested and does not throw an DoesNotExistError Exception.
- *
- * enable_silent_mode - Enable the silent mode.
- * disable_silent_mode - Disable the silent mode (default).
- */
- final public function enable_silent_mode() { $this->silent_mode = True; }
- final public function disable_silent_mode() { $this->silent_mode = False; }
-
- /* Countable interface implementation */
- final public function count() { return count($this->keybuffer); }
-
- /* ArrayAccess interface implementation */
- final public function offsetExists($offset) { return in_array($offset, $this->keybuffer); }
- final public function offsetGet($offset)
- {
- if($this->offsetExists($offset))
- {
- $this->stmt_get->execute(array_merge($this->common_vals, array($offset)));
- $sqlrow = $this->stmt_get->fetch();
- $this->stmt_get->closeCursor();
- return unserialize(base64_decode($sqlrow["value"]));
- }
- elseif($this->silent_mode)
- return NULL;
- else
- throw new DoesNotExistError();
- }
- final public function offsetUnset($offset)
- {
- if($this->offsetExists($offset))
- {
- unset($this->keybuffer[array_search($offset, $this->keybuffer)]);
- $this->keybuffer = array_merge($this->keybuffer);
- $this->stmt_unset->execute(array_merge($this->common_vals, array($offset)));
- $this->stmt_unset->closeCursor();
- }
- }
- final public function offsetSet($offset, $value)
- {
- if($this->offsetExists($offset))
- {
- $this->stmt_update->execute(array_merge(array(base64_encode(serialize($value))), $this->common_vals, array($offset)));
- $this->stmt_update->closeCursor();
- }
- else
- {
- $this->stmt_create->execute(array_merge(array($offset, base64_encode(serialize($value))), $this->common_vals));
- $this->stmt_create->closeCursor();
- $this->keybuffer[] = $offset;
- }
- }
-
- /* Iterator interface implementation */
- final public function rewind() { return $this->counter = 0; }
- final public function current() { return $this->offsetGet($this->keybuffer[$this->counter]); }
- final public function key() { return $this->keybuffer[$this->counter]; }
- final public function next() { ++$this->counter; }
- final public function valid() { return isset($this->keybuffer[$this->counter]); }
+ private $keybuffer;
+ private $counter;
+ private $silent_mode;
+
+ private $common_vals;
+
+ private $stmt_get;
+ private $stmt_unset;
+ private $stmt_update;
+ private $stmt_create;
+
+ final protected function init($sqltable, $common)
+ {
+ $sqltable = sub_prefix($sqltable);
+
+ $this->silent_mode = False;
+ $this->keybuffer = array();
+
+ $selector = "WHERE ";
+ $fields = "";
+ foreach($common as $field => $val)
+ {
+ $selector .= "`$field` = ? AND ";
+ $fields .= ", `$field`";
+ $this->common_vals[] = $val;
+ }
+
+ $this->stmt_get = prep_stmt("SELECT `value` FROM `$sqltable` $selector `key` = ?");
+ $this->stmt_unset = prep_stmt("DELETE FROM `$sqltable` $selector `key` = ?");
+ $this->stmt_update = prep_stmt("UPDATE `$sqltable` SET `value` = ? $selector `key` = ?");
+ $this->stmt_create = prep_stmt("INSERT INTO `$sqltable` (`key`, `value` $fields) VALUES (?,?" . str_repeat(",?", count($common)) . ")");
+
+ $get_keys = prep_stmt("SELECT `key` FROM `$sqltable` $selector 1");
+ $get_keys->execute($this->common_vals);
+ while($sqlrow = $get_keys->fetch())
+ $this->keybuffer[] = $sqlrow["key"];
+
+ $this->counter = 0;
+ }
+
+ /*
+ * Functions: Silent mode
+ * If the silent mode is enabled, the KVStorage behaves even more like a PHP array, i.e. it just returns NULL,
+ * if a unknown key was requested and does not throw an DoesNotExistError Exception.
+ *
+ * enable_silent_mode - Enable the silent mode.
+ * disable_silent_mode - Disable the silent mode (default).
+ */
+ final public function enable_silent_mode() { $this->silent_mode = True; }
+ final public function disable_silent_mode() { $this->silent_mode = False; }
+
+ /* Countable interface implementation */
+ final public function count() { return count($this->keybuffer); }
+
+ /* ArrayAccess interface implementation */
+ final public function offsetExists($offset) { return in_array($offset, $this->keybuffer); }
+ final public function offsetGet($offset)
+ {
+ if($this->offsetExists($offset))
+ {
+ $this->stmt_get->execute(array_merge($this->common_vals, array($offset)));
+ $sqlrow = $this->stmt_get->fetch();
+ $this->stmt_get->closeCursor();
+ return unserialize(base64_decode($sqlrow["value"]));
+ }
+ elseif($this->silent_mode)
+ return NULL;
+ else
+ throw new DoesNotExistError();
+ }
+ final public function offsetUnset($offset)
+ {
+ if($this->offsetExists($offset))
+ {
+ unset($this->keybuffer[array_search($offset, $this->keybuffer)]);
+ $this->keybuffer = array_merge($this->keybuffer);
+ $this->stmt_unset->execute(array_merge($this->common_vals, array($offset)));
+ $this->stmt_unset->closeCursor();
+ }
+ }
+ final public function offsetSet($offset, $value)
+ {
+ if($this->offsetExists($offset))
+ {
+ $this->stmt_update->execute(array_merge(array(base64_encode(serialize($value))), $this->common_vals, array($offset)));
+ $this->stmt_update->closeCursor();
+ }
+ else
+ {
+ $this->stmt_create->execute(array_merge(array($offset, base64_encode(serialize($value))), $this->common_vals));
+ $this->stmt_create->closeCursor();
+ $this->keybuffer[] = $offset;
+ }
+ }
+
+ /* Iterator interface implementation */
+ final public function rewind() { return $this->counter = 0; }
+ final public function current() { return $this->offsetGet($this->keybuffer[$this->counter]); }
+ final public function key() { return $this->keybuffer[$this->counter]; }
+ final public function next() { ++$this->counter; }
+ final public function valid() { return isset($this->keybuffer[$this->counter]); }
}
/*
@@ -213,224 +213,224 @@ abstract class KVStorage implements Countable, ArrayAccess, Iterator
*/
class User extends BySQLRowEnabled
{
- private $id;
-
- /*
- * Variables: Public class properties
- *
- * $username - The username.
- * $pwhash - <PasswordHash> of the password.
- * $mail - E-Mail-address.
- * $fullname - The full name of the user.
- * $language - Users language
- */
- public $username;
- public $pwhash;
- public $mail;
- public $fullname;
- public $language;
-
- /*
- * Constructor: create
- * Creates a new user.
- *
- * Parameters:
- * $username - The username
- * $pwhash - <PasswordHash> of the password
- *
- * Returns:
- * An User object
- *
- * Throws:
- * <AlreadyExistsError>
- */
- public static function create($username, $pwhash)
- {
- global $ratatoeskr_settings;
- global $db_con;
- try
- {
- $obj = self::by_name($username);
- }
- catch(DoesNotExistError $e)
- {
- global $ratatoeskr_settings;
- qdb("INSERT INTO `PREFIX_users` (`username`, `pwhash`, `mail`, `fullname`, `language`) VALUES (?, ?, '', '', ?)",
- $username, $pwhash, $ratatoeskr_settings["default_language"]);
- $obj = new self();
-
- $obj->id = $db_con->lastInsertId();
- $obj->username = $username;
- $obj->pwhash = $pwhash;
- $obj->mail = "";
- $obj->fullname = "";
- $obj->language = $ratatoeskr_settings["default_language"];
-
- return $obj;
- }
- throw new AlreadyExistsError("\"$name\" is already in database.");
- }
-
- protected function populate_by_sqlrow($sqlrow)
- {
- $this->id = $sqlrow["id"];
- $this->username = $sqlrow["username"];
- $this->pwhash = $sqlrow["pwhash"];
- $this->mail = $sqlrow["mail"];
- $this->fullname = $sqlrow["fullname"];
- $this->language = $sqlrow["language"];
- }
-
- /*
- * Constructor: by_id
- * Get a User object by ID
- *
- * Parameters:
- * $id - The ID.
- *
- * Returns:
- * An User object.
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_id($id)
- {
- $stmt = qdb("SELECT `id`, `username`, `pwhash`, `mail`, `fullname`, `language` FROM `PREFIX_users` WHERE `id` = ?", $id);
- $sqlrow = $stmt->fetch();
- if(!$sqlrow)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: by_name
- * Get a User object by username
- *
- * Parameters:
- * $username - The username.
- *
- * Returns:
- * An User object.
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_name($username)
- {
- $stmt = qdb("SELECT `id`, `username`, `pwhash`, `mail`, `fullname`, `language` FROM `PREFIX_users` WHERE `username` = ?", $username);
- $sqlrow = $stmt->fetch();
- if(!$sqlrow)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Function: all
- * Returns array of all available users.
- */
- public static function all()
- {
- $rv = array();
-
- $stmt = qdb("SELECT `id`, `username`, `pwhash`, `mail`, `fullname`, `language` FROM `PREFIX_users` WHERE 1");
- while($sqlrow = $stmt->fetch())
- $rv[] = self::by_sqlrow($sqlrow);
-
- return $rv;
- }
-
- /*
- * Function: get_id
- * Returns:
- * The user ID.
- */
- public function get_id()
- {
- return $this->id;
- }
-
- /*
- * Function: save
- * Saves the object to database
- *
- * Throws:
- * AlreadyExistsError
- */
- public function save()
- {
- $tx = new Transaction();
- try
- {
- $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_users` WHERE `username` = ? AND `id` != ?", $this->username, $this->id);
- $sqlrow = $stmt->fetch();
- if($sqlrow["n"] > 0)
- throw new AlreadyExistsError();
-
- qdb("UPDATE `PREFIX_users` SET `username` = ?, `pwhash` = ?, `mail` = ?, `fullname` = ?, `language` = ? WHERE `id` = ?",
- $this->username, $this->pwhash, $this->mail, $this->fullname, $this->language, $this->id);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /*
- * Function: delete
- * Deletes the user from the database.
- * WARNING: Do NOT use this object any longer after you called this function!
- */
- public function delete()
- {
- $tx = new Transaction();
- try
- {
- qdb("DELETE FROM `PREFIX_group_members` WHERE `user` = ?", $this->id);
- qdb("DELETE FROM `PREFIX_users` WHERE `id` = ?", $this->id);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /*
- * Function: get_groups
- * Returns:
- * List of all groups where this user is a member (array of <Group> objects).
- */
- public function get_groups()
- {
- $rv = array();
- $stmt = qdb("SELECT `a`.`id` AS `id`, `a`.`name` AS `name` FROM `PREFIX_groups` `a` INNER JOIN `PREFIX_group_members` `b` ON `a`.`id` = `b`.`group` WHERE `b`.`user` = ?", $this->id);
- while($sqlrow = $stmt->fetch())
- $rv[] = Group::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * Function: member_of
- * Checks, if the user is a member of a group.
- *
- * Parameters:
- * $group - A Group object
- *
- * Returns:
- * True, if the user is a member of $group. False, if not.
- */
- public function member_of($group)
- {
- $stmt = qdb("SELECT COUNT(*) AS `num` FROM `PREFIX_group_members` WHERE `user` = ? AND `group` = ?", $this->id, $group->get_id());
- $sqlrow = $stmt->fetch();
- return ($sqlrow["num"] > 0);
- }
+ private $id;
+
+ /*
+ * Variables: Public class properties
+ *
+ * $username - The username.
+ * $pwhash - <PasswordHash> of the password.
+ * $mail - E-Mail-address.
+ * $fullname - The full name of the user.
+ * $language - Users language
+ */
+ public $username;
+ public $pwhash;
+ public $mail;
+ public $fullname;
+ public $language;
+
+ /*
+ * Constructor: create
+ * Creates a new user.
+ *
+ * Parameters:
+ * $username - The username
+ * $pwhash - <PasswordHash> of the password
+ *
+ * Returns:
+ * An User object
+ *
+ * Throws:
+ * <AlreadyExistsError>
+ */
+ public static function create($username, $pwhash)
+ {
+ global $ratatoeskr_settings;
+ global $db_con;
+ try
+ {
+ $obj = self::by_name($username);
+ }
+ catch(DoesNotExistError $e)
+ {
+ global $ratatoeskr_settings;
+ qdb("INSERT INTO `PREFIX_users` (`username`, `pwhash`, `mail`, `fullname`, `language`) VALUES (?, ?, '', '', ?)",
+ $username, $pwhash, $ratatoeskr_settings["default_language"]);
+ $obj = new self();
+
+ $obj->id = $db_con->lastInsertId();
+ $obj->username = $username;
+ $obj->pwhash = $pwhash;
+ $obj->mail = "";
+ $obj->fullname = "";
+ $obj->language = $ratatoeskr_settings["default_language"];
+
+ return $obj;
+ }
+ throw new AlreadyExistsError("\"$name\" is already in database.");
+ }
+
+ protected function populate_by_sqlrow($sqlrow)
+ {
+ $this->id = $sqlrow["id"];
+ $this->username = $sqlrow["username"];
+ $this->pwhash = $sqlrow["pwhash"];
+ $this->mail = $sqlrow["mail"];
+ $this->fullname = $sqlrow["fullname"];
+ $this->language = $sqlrow["language"];
+ }
+
+ /*
+ * Constructor: by_id
+ * Get a User object by ID
+ *
+ * Parameters:
+ * $id - The ID.
+ *
+ * Returns:
+ * An User object.
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_id($id)
+ {
+ $stmt = qdb("SELECT `id`, `username`, `pwhash`, `mail`, `fullname`, `language` FROM `PREFIX_users` WHERE `id` = ?", $id);
+ $sqlrow = $stmt->fetch();
+ if(!$sqlrow)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: by_name
+ * Get a User object by username
+ *
+ * Parameters:
+ * $username - The username.
+ *
+ * Returns:
+ * An User object.
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_name($username)
+ {
+ $stmt = qdb("SELECT `id`, `username`, `pwhash`, `mail`, `fullname`, `language` FROM `PREFIX_users` WHERE `username` = ?", $username);
+ $sqlrow = $stmt->fetch();
+ if(!$sqlrow)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Function: all
+ * Returns array of all available users.
+ */
+ public static function all()
+ {
+ $rv = array();
+
+ $stmt = qdb("SELECT `id`, `username`, `pwhash`, `mail`, `fullname`, `language` FROM `PREFIX_users` WHERE 1");
+ while($sqlrow = $stmt->fetch())
+ $rv[] = self::by_sqlrow($sqlrow);
+
+ return $rv;
+ }
+
+ /*
+ * Function: get_id
+ * Returns:
+ * The user ID.
+ */
+ public function get_id()
+ {
+ return $this->id;
+ }
+
+ /*
+ * Function: save
+ * Saves the object to database
+ *
+ * Throws:
+ * AlreadyExistsError
+ */
+ public function save()
+ {
+ $tx = new Transaction();
+ try
+ {
+ $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_users` WHERE `username` = ? AND `id` != ?", $this->username, $this->id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow["n"] > 0)
+ throw new AlreadyExistsError();
+
+ qdb("UPDATE `PREFIX_users` SET `username` = ?, `pwhash` = ?, `mail` = ?, `fullname` = ?, `language` = ? WHERE `id` = ?",
+ $this->username, $this->pwhash, $this->mail, $this->fullname, $this->language, $this->id);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /*
+ * Function: delete
+ * Deletes the user from the database.
+ * WARNING: Do NOT use this object any longer after you called this function!
+ */
+ public function delete()
+ {
+ $tx = new Transaction();
+ try
+ {
+ qdb("DELETE FROM `PREFIX_group_members` WHERE `user` = ?", $this->id);
+ qdb("DELETE FROM `PREFIX_users` WHERE `id` = ?", $this->id);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /*
+ * Function: get_groups
+ * Returns:
+ * List of all groups where this user is a member (array of <Group> objects).
+ */
+ public function get_groups()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `a`.`id` AS `id`, `a`.`name` AS `name` FROM `PREFIX_groups` `a` INNER JOIN `PREFIX_group_members` `b` ON `a`.`id` = `b`.`group` WHERE `b`.`user` = ?", $this->id);
+ while($sqlrow = $stmt->fetch())
+ $rv[] = Group::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * Function: member_of
+ * Checks, if the user is a member of a group.
+ *
+ * Parameters:
+ * $group - A Group object
+ *
+ * Returns:
+ * True, if the user is a member of $group. False, if not.
+ */
+ public function member_of($group)
+ {
+ $stmt = qdb("SELECT COUNT(*) AS `num` FROM `PREFIX_group_members` WHERE `user` = ? AND `group` = ?", $this->id, $group->get_id());
+ $sqlrow = $stmt->fetch();
+ return ($sqlrow["num"] > 0);
+ }
}
/*
@@ -439,187 +439,187 @@ class User extends BySQLRowEnabled
*/
class Group extends BySQLRowEnabled
{
- private $id;
-
- /*
- * Variables: Public class properties
- *
- * $name - Name of the group.
- */
- public $name;
-
- /*
- * Constructor: create
- * Creates a new group.
- *
- * Parameters:
- * $name - The name of the group.
- *
- * Returns:
- * An Group object
- *
- * Throws:
- * <AlreadyExistsError>
- */
- public static function create($name)
- {
- global $db_con;
- try
- {
- $obj = self::by_name($name);
- }
- catch(DoesNotExistError $e)
- {
- qdb("INSERT INTO `PREFIX_groups` (`name`) VALUES (?)", $name);
- $obj = new self();
-
- $obj->id = $db_con->lastInsertId();
- $obj->name = $name;
-
- return $obj;
- }
- throw new AlreadyExistsError("\"$name\" is already in database.");
- }
-
- protected function populate_by_sqlrow($sqlrow)
- {
- $this->id = $sqlrow["id"];
- $this->name = $sqlrow["name"];
- }
-
- /*
- * Constructor: by_id
- * Get a Group object by ID
- *
- * Parameters:
- * $id - The ID.
- *
- * Returns:
- * A Group object.
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_id($id)
- {
- $stmt = qdb("SELECT `id`, `name` FROM `PREFIX_groups` WHERE `id` = ?", $id);
- $sqlrow = $stmt->fetch();
- if(!$sqlrow)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: by_name
- * Get a Group object by name
- *
- * Parameters:
- * $name - The group name.
- *
- * Returns:
- * A Group object.
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_name($name)
- {
- $stmt = qdb("SELECT `id`, `name` FROM `PREFIX_groups` WHERE `name` = ?", $name);
- $sqlrow = $stmt->fetch();
- if(!$sqlrow)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Function: all
- * Returns array of all groups
- */
- public static function all()
- {
- $rv = array();
-
- $stmt = qdb("SELECT `id`, `name` FROM `PREFIX_groups` WHERE 1");
- while($sqlrow = $stmt->fetch())
- $rv[] = self::by_sqlrow($sqlrow);
-
- return $rv;
- }
-
- /*
- * Function: get_id
- * Returns:
- * The group ID.
- */
- public function get_id()
- {
- return $this->id;
- }
-
- /*
- * Function: delete
- * Deletes the group from the database.
- */
- public function delete()
- {
- $tx = new Transaction();
- try
- {
- qdb("DELETE FROM `PREFIX_group_members` WHERE `group` = ?", $this->id);
- qdb("DELETE FROM `PREFIX_groups` WHERE `id` = ?", $this->id);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /*
- * Function: get_members
- * Get all members of the group.
- *
- * Returns:
- * Array of <User> objects.
- */
- public function get_members()
- {
- $rv = array();
- $stmt = qdb("SELECT `a`.`id` AS `id`, `a`.`username` AS `username`, `a`.`pwhash` AS `pwhash`, `a`.`mail` AS `mail`, `a`.`fullname` AS `fullname`, `a`.`language` AS `language`
+ private $id;
+
+ /*
+ * Variables: Public class properties
+ *
+ * $name - Name of the group.
+ */
+ public $name;
+
+ /*
+ * Constructor: create
+ * Creates a new group.
+ *
+ * Parameters:
+ * $name - The name of the group.
+ *
+ * Returns:
+ * An Group object
+ *
+ * Throws:
+ * <AlreadyExistsError>
+ */
+ public static function create($name)
+ {
+ global $db_con;
+ try
+ {
+ $obj = self::by_name($name);
+ }
+ catch(DoesNotExistError $e)
+ {
+ qdb("INSERT INTO `PREFIX_groups` (`name`) VALUES (?)", $name);
+ $obj = new self();
+
+ $obj->id = $db_con->lastInsertId();
+ $obj->name = $name;
+
+ return $obj;
+ }
+ throw new AlreadyExistsError("\"$name\" is already in database.");
+ }
+
+ protected function populate_by_sqlrow($sqlrow)
+ {
+ $this->id = $sqlrow["id"];
+ $this->name = $sqlrow["name"];
+ }
+
+ /*
+ * Constructor: by_id
+ * Get a Group object by ID
+ *
+ * Parameters:
+ * $id - The ID.
+ *
+ * Returns:
+ * A Group object.
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_id($id)
+ {
+ $stmt = qdb("SELECT `id`, `name` FROM `PREFIX_groups` WHERE `id` = ?", $id);
+ $sqlrow = $stmt->fetch();
+ if(!$sqlrow)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: by_name
+ * Get a Group object by name
+ *
+ * Parameters:
+ * $name - The group name.
+ *
+ * Returns:
+ * A Group object.
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_name($name)
+ {
+ $stmt = qdb("SELECT `id`, `name` FROM `PREFIX_groups` WHERE `name` = ?", $name);
+ $sqlrow = $stmt->fetch();
+ if(!$sqlrow)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Function: all
+ * Returns array of all groups
+ */
+ public static function all()
+ {
+ $rv = array();
+
+ $stmt = qdb("SELECT `id`, `name` FROM `PREFIX_groups` WHERE 1");
+ while($sqlrow = $stmt->fetch())
+ $rv[] = self::by_sqlrow($sqlrow);
+
+ return $rv;
+ }
+
+ /*
+ * Function: get_id
+ * Returns:
+ * The group ID.
+ */
+ public function get_id()
+ {
+ return $this->id;
+ }
+
+ /*
+ * Function: delete
+ * Deletes the group from the database.
+ */
+ public function delete()
+ {
+ $tx = new Transaction();
+ try
+ {
+ qdb("DELETE FROM `PREFIX_group_members` WHERE `group` = ?", $this->id);
+ qdb("DELETE FROM `PREFIX_groups` WHERE `id` = ?", $this->id);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /*
+ * Function: get_members
+ * Get all members of the group.
+ *
+ * Returns:
+ * Array of <User> objects.
+ */
+ public function get_members()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `a`.`id` AS `id`, `a`.`username` AS `username`, `a`.`pwhash` AS `pwhash`, `a`.`mail` AS `mail`, `a`.`fullname` AS `fullname`, `a`.`language` AS `language`
FROM `PREFIX_users` `a` INNER JOIN `PREFIX_group_members` `b` ON `a`.`id` = `b`.`user`
WHERE `b`.`group` = ?", $this->id);
- while($sqlrow = $stmt->fetch())
- $rv[] = User::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * Function: exclude_user
- * Excludes user from group.
- *
- * Parameters:
- * $user - <User> object.
- */
- public function exclude_user($user)
- {
- qdb("DELETE FROM `PREFIX_group_members` WHERE `user` = ? AND `group` = ?", $user->get_id(), $this->id);
- }
-
- /*
- * Function: include_user
- * Includes user to group.
- *
- * Parameters:
- * $user - <User> object.
- */
- public function include_user($user)
- {
- if(!$user->member_of($this))
- qdb("INSERT INTO `PREFIX_group_members` (`user`, `group`) VALUES (?, ?)", $user->get_id(), $this->id);
- }
+ while($sqlrow = $stmt->fetch())
+ $rv[] = User::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * Function: exclude_user
+ * Excludes user from group.
+ *
+ * Parameters:
+ * $user - <User> object.
+ */
+ public function exclude_user($user)
+ {
+ qdb("DELETE FROM `PREFIX_group_members` WHERE `user` = ? AND `group` = ?", $user->get_id(), $this->id);
+ }
+
+ /*
+ * Function: include_user
+ * Includes user to group.
+ *
+ * Parameters:
+ * $user - <User> object.
+ */
+ public function include_user($user)
+ {
+ if(!$user->member_of($this))
+ qdb("INSERT INTO `PREFIX_group_members` (`user`, `group`) VALUES (?, ?)", $user->get_id(), $this->id);
+ }
}
/*
@@ -628,220 +628,220 @@ WHERE `b`.`group` = ?", $this->id);
*/
class Translation
{
- /*
- * Variables: Public class variables.
- *
- * $text - The translated text.
- * $texttype - The type of the text. Has only a meaning in a context.
- */
- public $text;
- public $texttype;
-
- /*
- * Constructor: __construct
- * Creates a new Translation object.
- * IT WILL NOT BE STORED TO DATABASE!
- *
- * Parameters:
- * $text - The translated text.
- * $texttype - The type of the text. Has only a meaning in a context.
- *
- * See also:
- * <Multilingual>
- */
- public function __construct($text, $texttype)
- {
- $this->text = $text;
- $this->texttype = $texttype;
- }
+ /*
+ * Variables: Public class variables.
+ *
+ * $text - The translated text.
+ * $texttype - The type of the text. Has only a meaning in a context.
+ */
+ public $text;
+ public $texttype;
+
+ /*
+ * Constructor: __construct
+ * Creates a new Translation object.
+ * IT WILL NOT BE STORED TO DATABASE!
+ *
+ * Parameters:
+ * $text - The translated text.
+ * $texttype - The type of the text. Has only a meaning in a context.
+ *
+ * See also:
+ * <Multilingual>
+ */
+ public function __construct($text, $texttype)
+ {
+ $this->text = $text;
+ $this->texttype = $texttype;
+ }
}
/*
* Class: Multilingual
* Container for <Translation> objects.
* Translations can be accessed array-like. So, if you want the german translation: $translation = $my_multilingual["de"];
- *
+ *
* See also:
- * <languages.php>
+ * <languages.php>
*/
class Multilingual implements Countable, ArrayAccess, IteratorAggregate
{
- private $translations;
- private $id;
- private $to_be_deleted;
- private $to_be_created;
-
- private function __construct()
- {
- $this->translations = array();
- $this->to_be_deleted = array();
- $this->to_be_created = array();
- }
-
- /*
- * Function: get_id
- * Retuurns the ID of the object.
- */
- public function get_id()
- {
- return $this->id;
- }
-
- /*
- * Constructor: create
- * Creates a new Multilingual object
- *
- * Returns:
- * An Multilingual object.
- */
- public static function create()
- {
- global $db_con;
-
- $obj = new self();
- qdb("INSERT INTO `PREFIX_multilingual` () VALUES ()");
- $obj->id = $db_con->lastInsertId();
- return $obj;
- }
-
- /*
- * Constructor: by_id
- * Gets an Multilingual object by ID.
- *
- * Parameters:
- * $id - The ID.
- *
- * Returns:
- * An Multilingual object.
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_id($id)
- {
- $obj = new self();
- $stmt = qdb("SELECT `id` FROM `PREFIX_multilingual` WHERE `id` = ?", $id);
- $sqlrow = $stmt->fetch();
- if($sqlrow == False)
- throw new DoesNotExistError();
- $obj->id = $id;
-
- $stmt = qdb("SELECT `language`, `text`, `texttype` FROM `PREFIX_translations` WHERE `multilingual` = ?", $id);
- while($sqlrow = $stmt->fetch())
- $obj->translations[$sqlrow["language"]] = new Translation($sqlrow["text"], $sqlrow["texttype"]);
-
- return $obj;
- }
-
- /*
- * Function: save
- * Saves the translations to database.
- */
- public function save()
- {
- $tx = new Transaction();
- try
- {
- foreach($this->to_be_deleted as $deletelang)
- qdb("DELETE FROM `PREFIX_translations` WHERE `multilingual` = ? AND `language` = ?", $this->id, $deletelang);
-
- foreach($this->to_be_created as $lang)
- qdb("INSERT INTO `PREFIX_translations` (`multilingual`, `language`, `text`, `texttype`) VALUES (?, ?, ?, ?)",
- $this->id, $lang, $this->translations[$lang]->text, $this->translations[$lang]->texttype);
-
- foreach($this->translations as $lang => $translation)
- {
- if(!in_array($lang, $this->to_be_created))
- qdb("UPDATE `PREFIX_translations` SET `text` = ?, `texttype` = ? WHERE `multilingual` = ? AND `language` = ?",
- $translation->text, $translation->texttype, $this->id, $lang);
- }
-
- $this->to_be_deleted = array();
- $this->to_be_created = array();
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /*
- * Function: delete
- * Deletes the data from database.
- */
- public function delete()
- {
- $tx = new Transaction();
- try
- {
- qdb("DELETE FROM `PREFIX_translations` WHERE `multilingual` = ?", $this->id);
- qdb("DELETE FROM `PREFIX_multilingual` WHERE `id` = ?", $this->id);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /* Countable interface implementation */
- public function count() { return count($this->languages); }
-
- /* ArrayAccess interface implementation */
- public function offsetExists($offset) { return isset($this->translations[$offset]); }
- public function offsetGet($offset)
- {
- if(isset($this->translations[$offset]))
- return $this->translations[$offset];
- else
- throw new DoesNotExistError();
- }
- public function offsetUnset($offset)
- {
- unset($this->translations[$offset]);
- if(in_array($offset, $this->to_be_created))
- unset($this->to_be_created[array_search($offset, $this->to_be_created)]);
- else
- $this->to_be_deleted[] = $offset;
- }
- public function offsetSet($offset, $value)
- {
- if(!isset($this->translations[$offset]))
- {
- if(in_array($offset, $this->to_be_deleted))
- unset($this->to_be_deleted[array_search($offset, $this->to_be_deleted)]);
- else
- $this->to_be_created[] = $offset;
- }
- $this->translations[$offset] = $value;
- }
-
- /* IteratorAggregate interface implementation */
- public function getIterator() { return new ArrayIterator($this->translations); }
+ private $translations;
+ private $id;
+ private $to_be_deleted;
+ private $to_be_created;
+
+ private function __construct()
+ {
+ $this->translations = array();
+ $this->to_be_deleted = array();
+ $this->to_be_created = array();
+ }
+
+ /*
+ * Function: get_id
+ * Retuurns the ID of the object.
+ */
+ public function get_id()
+ {
+ return $this->id;
+ }
+
+ /*
+ * Constructor: create
+ * Creates a new Multilingual object
+ *
+ * Returns:
+ * An Multilingual object.
+ */
+ public static function create()
+ {
+ global $db_con;
+
+ $obj = new self();
+ qdb("INSERT INTO `PREFIX_multilingual` () VALUES ()");
+ $obj->id = $db_con->lastInsertId();
+ return $obj;
+ }
+
+ /*
+ * Constructor: by_id
+ * Gets an Multilingual object by ID.
+ *
+ * Parameters:
+ * $id - The ID.
+ *
+ * Returns:
+ * An Multilingual object.
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_id($id)
+ {
+ $obj = new self();
+ $stmt = qdb("SELECT `id` FROM `PREFIX_multilingual` WHERE `id` = ?", $id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow == False)
+ throw new DoesNotExistError();
+ $obj->id = $id;
+
+ $stmt = qdb("SELECT `language`, `text`, `texttype` FROM `PREFIX_translations` WHERE `multilingual` = ?", $id);
+ while($sqlrow = $stmt->fetch())
+ $obj->translations[$sqlrow["language"]] = new Translation($sqlrow["text"], $sqlrow["texttype"]);
+
+ return $obj;
+ }
+
+ /*
+ * Function: save
+ * Saves the translations to database.
+ */
+ public function save()
+ {
+ $tx = new Transaction();
+ try
+ {
+ foreach($this->to_be_deleted as $deletelang)
+ qdb("DELETE FROM `PREFIX_translations` WHERE `multilingual` = ? AND `language` = ?", $this->id, $deletelang);
+
+ foreach($this->to_be_created as $lang)
+ qdb("INSERT INTO `PREFIX_translations` (`multilingual`, `language`, `text`, `texttype`) VALUES (?, ?, ?, ?)",
+ $this->id, $lang, $this->translations[$lang]->text, $this->translations[$lang]->texttype);
+
+ foreach($this->translations as $lang => $translation)
+ {
+ if(!in_array($lang, $this->to_be_created))
+ qdb("UPDATE `PREFIX_translations` SET `text` = ?, `texttype` = ? WHERE `multilingual` = ? AND `language` = ?",
+ $translation->text, $translation->texttype, $this->id, $lang);
+ }
+
+ $this->to_be_deleted = array();
+ $this->to_be_created = array();
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /*
+ * Function: delete
+ * Deletes the data from database.
+ */
+ public function delete()
+ {
+ $tx = new Transaction();
+ try
+ {
+ qdb("DELETE FROM `PREFIX_translations` WHERE `multilingual` = ?", $this->id);
+ qdb("DELETE FROM `PREFIX_multilingual` WHERE `id` = ?", $this->id);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /* Countable interface implementation */
+ public function count() { return count($this->languages); }
+
+ /* ArrayAccess interface implementation */
+ public function offsetExists($offset) { return isset($this->translations[$offset]); }
+ public function offsetGet($offset)
+ {
+ if(isset($this->translations[$offset]))
+ return $this->translations[$offset];
+ else
+ throw new DoesNotExistError();
+ }
+ public function offsetUnset($offset)
+ {
+ unset($this->translations[$offset]);
+ if(in_array($offset, $this->to_be_created))
+ unset($this->to_be_created[array_search($offset, $this->to_be_created)]);
+ else
+ $this->to_be_deleted[] = $offset;
+ }
+ public function offsetSet($offset, $value)
+ {
+ if(!isset($this->translations[$offset]))
+ {
+ if(in_array($offset, $this->to_be_deleted))
+ unset($this->to_be_deleted[array_search($offset, $this->to_be_deleted)]);
+ else
+ $this->to_be_created[] = $offset;
+ }
+ $this->translations[$offset] = $value;
+ }
+
+ /* IteratorAggregate interface implementation */
+ public function getIterator() { return new ArrayIterator($this->translations); }
}
class SettingsIterator implements Iterator
{
- private $index;
- private $keys;
- private $settings_obj;
-
- public function __construct($settings_obj, $keys)
- {
- $this->index = 0;
- $this->settings_obj = $settings_obj;
- $this->keys = $keys;
- }
-
- /* Iterator implementation */
- public function current() { return $this->settings_obj[$this->keys[$this->index]]; }
- public function key() { return $this->keys[$this->index]; }
- public function next() { ++$this->index; }
- public function rewind() { $this->index = 0; }
- public function valid() { return $this->index < count($this->keys); }
+ private $index;
+ private $keys;
+ private $settings_obj;
+
+ public function __construct($settings_obj, $keys)
+ {
+ $this->index = 0;
+ $this->settings_obj = $settings_obj;
+ $this->keys = $keys;
+ }
+
+ /* Iterator implementation */
+ public function current() { return $this->settings_obj[$this->keys[$this->index]]; }
+ public function key() { return $this->keys[$this->index]; }
+ public function next() { ++$this->index; }
+ public function rewind() { $this->index = 0; }
+ public function valid() { return $this->index < count($this->keys); }
}
/*
@@ -851,102 +851,102 @@ class SettingsIterator implements Iterator
*/
class Settings implements ArrayAccess, IteratorAggregate, Countable
{
- /* Singleton implementation */
- private function __copy() {}
- private static $instance = NULL;
- /*
- * Constructor: get_instance
- * Get an instance of this class.
- * All instances are equal (ie. this is a singleton), so you can also use
- * the global <$ratatoeskr_settings> instance.
- */
- public static function get_instance()
- {
- if(self::$instance === NULL)
- self::$instance = new self;
- return self::$instance;
- }
-
- private $buffer;
- private $to_be_deleted;
- private $to_be_created;
- private $to_be_updated;
-
- private function __construct()
- {
- $this->buffer = array();
- $stmt = qdb("SELECT `key`, `value` FROM `PREFIX_settings_kvstorage` WHERE 1");
- while($sqlrow = $stmt->fetch())
- $this->buffer[$sqlrow["key"]] = unserialize(base64_decode($sqlrow["value"]));
-
- $this->to_be_created = array();
- $this->to_be_deleted = array();
- $this->to_be_updated = array();
- }
-
- public function save()
- {
- $tx = new Transaction();
- try
- {
- foreach($this->to_be_deleted as $k)
- qdb("DELETE FROM `PREFIX_settings_kvstorage` WHERE `key` = ?", $k);
- foreach($this->to_be_updated as $k)
- qdb("UPDATE `PREFIX_settings_kvstorage` SET `value` = ? WHERE `key` = ?", base64_encode(serialize($this->buffer[$k])), $k);
- foreach($this->to_be_created as $k)
- qdb("INSERT INTO `PREFIX_settings_kvstorage` (`key`, `value`) VALUES (?, ?)", $k, base64_encode(serialize($this->buffer[$k])));
-
- $this->to_be_created = array();
- $this->to_be_deleted = array();
- $this->to_be_updated = array();
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /* ArrayAccess implementation */
- public function offsetExists($offset)
- {
- return isset($this->buffer[$offset]);
- }
- public function offsetGet($offset)
- {
- return $this->buffer[$offset];
- }
- public function offsetSet ($offset, $value)
- {
- if(!$this->offsetExists($offset))
- {
- if(in_array($offset, $this->to_be_deleted))
- {
- $this->to_be_updated[] = $offset;
- unset($this->to_be_deleted[array_search($offset, $this->to_be_deleted)]);
- }
- else
- $this->to_be_created[] = $offset;
- }
- elseif((!in_array($offset, $this->to_be_created)) and (!in_array($offset, $this->to_be_updated)))
- $this->to_be_updated[] = $offset;
- $this->buffer[$offset] = $value;
- }
- public function offsetUnset($offset)
- {
- if(in_array($offset, $this->to_be_created))
- unset($this->to_be_created[array_search($offset, $this->to_be_created)]);
- else
- $this->to_be_deleted[] = $offset;
- unset($this->buffer[$offset]);
- }
-
- /* IteratorAggregate implementation */
- public function getIterator() { return new SettingsIterator($this, array_keys($this->buffer)); }
-
- /* Countable implementation */
- public function count() { return count($this->buffer); }
+ /* Singleton implementation */
+ private function __copy() {}
+ private static $instance = NULL;
+ /*
+ * Constructor: get_instance
+ * Get an instance of this class.
+ * All instances are equal (ie. this is a singleton), so you can also use
+ * the global <$ratatoeskr_settings> instance.
+ */
+ public static function get_instance()
+ {
+ if(self::$instance === NULL)
+ self::$instance = new self;
+ return self::$instance;
+ }
+
+ private $buffer;
+ private $to_be_deleted;
+ private $to_be_created;
+ private $to_be_updated;
+
+ private function __construct()
+ {
+ $this->buffer = array();
+ $stmt = qdb("SELECT `key`, `value` FROM `PREFIX_settings_kvstorage` WHERE 1");
+ while($sqlrow = $stmt->fetch())
+ $this->buffer[$sqlrow["key"]] = unserialize(base64_decode($sqlrow["value"]));
+
+ $this->to_be_created = array();
+ $this->to_be_deleted = array();
+ $this->to_be_updated = array();
+ }
+
+ public function save()
+ {
+ $tx = new Transaction();
+ try
+ {
+ foreach($this->to_be_deleted as $k)
+ qdb("DELETE FROM `PREFIX_settings_kvstorage` WHERE `key` = ?", $k);
+ foreach($this->to_be_updated as $k)
+ qdb("UPDATE `PREFIX_settings_kvstorage` SET `value` = ? WHERE `key` = ?", base64_encode(serialize($this->buffer[$k])), $k);
+ foreach($this->to_be_created as $k)
+ qdb("INSERT INTO `PREFIX_settings_kvstorage` (`key`, `value`) VALUES (?, ?)", $k, base64_encode(serialize($this->buffer[$k])));
+
+ $this->to_be_created = array();
+ $this->to_be_deleted = array();
+ $this->to_be_updated = array();
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /* ArrayAccess implementation */
+ public function offsetExists($offset)
+ {
+ return isset($this->buffer[$offset]);
+ }
+ public function offsetGet($offset)
+ {
+ return $this->buffer[$offset];
+ }
+ public function offsetSet ($offset, $value)
+ {
+ if(!$this->offsetExists($offset))
+ {
+ if(in_array($offset, $this->to_be_deleted))
+ {
+ $this->to_be_updated[] = $offset;
+ unset($this->to_be_deleted[array_search($offset, $this->to_be_deleted)]);
+ }
+ else
+ $this->to_be_created[] = $offset;
+ }
+ elseif((!in_array($offset, $this->to_be_created)) and (!in_array($offset, $this->to_be_updated)))
+ $this->to_be_updated[] = $offset;
+ $this->buffer[$offset] = $value;
+ }
+ public function offsetUnset($offset)
+ {
+ if(in_array($offset, $this->to_be_created))
+ unset($this->to_be_created[array_search($offset, $this->to_be_created)]);
+ else
+ $this->to_be_deleted[] = $offset;
+ unset($this->buffer[$offset]);
+ }
+
+ /* IteratorAggregate implementation */
+ public function getIterator() { return new SettingsIterator($this, array_keys($this->buffer)); }
+
+ /* Countable implementation */
+ public function count() { return count($this->buffer); }
}
$ratatoeskr_settings = Settings::get_instance();
@@ -961,16 +961,16 @@ $ratatoeskr_settings = Settings::get_instance();
*/
class PluginKVStorage extends KVStorage
{
- /*
- * Constructor: __construct
- *
- * Parameters:
- * $plugin_id - The ID of the Plugin.
- */
- public function __construct($plugin_id)
- {
- $this->init("PREFIX_plugin_kvstorage", array("plugin" => $plugin_id));
- }
+ /*
+ * Constructor: __construct
+ *
+ * Parameters:
+ * $plugin_id - The ID of the Plugin.
+ */
+ public function __construct($plugin_id)
+ {
+ $this->init("PREFIX_plugin_kvstorage", array("plugin" => $plugin_id));
+ }
}
/*
@@ -979,213 +979,213 @@ class PluginKVStorage extends KVStorage
*/
class Comment extends BySQLRowEnabled
{
- private $id;
- private $article_id;
- private $language;
- private $timestamp;
-
- /*
- * Variables: Public class variables.
- *
- * $author_name - Name of comment author.
- * $author_mail - E-Mail of comment author.
- * $text - Comment text.
- * $visible - Should the comment be visible?
- * $read_by_admin - Was the comment read by an admin.
- */
- public $author_name;
- public $author_mail;
- public $text;
- public $visible;
- public $read_by_admin;
-
- /*
- * Functions: Getters
- *
- * get_id - Gets the comment ID.
- * get_article - Gets the article.
- * get_language - Gets the language.
- * get_timestamp - Gets the timestamp.
- */
- public function get_id() { return $this->id; }
- public function get_article() { return Article::by_id($this->article_id); }
- public function get_language() { return $this->language; }
- public function get_timestamp() { return $this->timestamp; }
-
- /*
- * Constructor: create
- * Creates a new comment.
- * Automatically sets the $timestamp and $visible (default from setting "comment_visible_default").
- *
- * Parameters:
- * $article - An <Article> Object.
- * $language - Which language? (see <languages.php>)
- */
- public static function create($article, $language)
- {
- global $ratatoeskr_settings;
- global $db_con;
-
- $obj = new self();
- $obj->timestamp = time();
-
- qdb("INSERT INTO `PREFIX_comments` (`article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin`) VALUES (?, ?, '', '', '', ?, ?, 0)",
- $article->get_id(), $language, $obj->timestamp, $ratatoeskr_settings["comment_visible_default"] ? 1 : 0);
-
- $obj->id = $db_con->lastInsertId();
- $obj->article_id = $article->get_id();
- $obj->language = $language;
- $obj->author_name = "";
- $obj->author_mail = "";
- $obj->text = "";
- $obj->visible = $ratatoeskr_settings["comment_visible_default"];
- $obj->read_by_admin = False;
-
- return $obj;
- }
-
- protected function populate_by_sqlrow($sqlrow)
- {
- $this->id = $sqlrow["id"];
- $this->article_id = $sqlrow["article"];
- $this->language = $sqlrow["language"];
- $this->author_name = $sqlrow["author_name"];
- $this->author_mail = $sqlrow["author_mail"];
- $this->text = $sqlrow["text"];
- $this->timestamp = $sqlrow["timestamp"];
- $this->visible = $sqlrow["visible"] == 1;
- $this->read_by_admin = $sqlrow["read_by_admin"] == 1;
- }
-
- /*
- * Constructor: by_id
- * Gets a Comment by ID.
- *
- * Parameters:
- * $id - The comments ID.
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_id($id)
- {
- $stmt = qdb("SELECT `id`, `article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin` FROM `PREFIX_comments` WHERE `id` = ?", $id);
- $sqlrow = $stmt->fetch();
- if($sqlrow === False)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: all
- * Get all comments
- *
- * Returns:
- * Array of Comment objects
- */
- public static function all()
- {
- $rv = array();
- $stmt = qdb("SELECT `id`, `article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin` FROM `PREFIX_comments` WHERE 1");
- while($sqlrow = $stmt->fetch())
- $rv[] = self::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * 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:
- * HTML code.
- */
- public static function htmlize_comment_text($text)
- {
- global $ratatoeskr_settings;
-
- 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(),
- "u" => array(),
- "strong" => array(),
- "em" => array(),
- "p" => array("align" => 1),
- "br" => array(),
- "abbr" => array(),
- "acronym" => array(),
- "code" => array(),
- "pre" => array(),
- "blockquote" => array("cite" => 1),
- "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),
- "samp" => array(),
- "ul" => array(),
- "ol" => array(),
- "li" => array(),
- "del" => array(),
- "ins" => array(),
- "dl" => array(),
- "dd" => array(),
- "dt" => array(),
- "dfn" => array(),
- "div" => array(),
- "dir" => array(),
- "kbd" => array("prompt" => 1),
- "strike" => array(),
- "sub" => array(),
- "sup" => array(),
- "table" => array("style" => 1),
- "tbody" => array(), "thead" => array(), "tfoot" => array(),
- "tr" => array(),
- "td" => array("colspan" => 1, "rowspan" => 1),
- "th" => array("colspan" => 1, "rowspan" => 1),
- "tt" => array(),
- "var" => array()
- ));
- }
-
- /*
- * Function: create_html
- * Applys <htmlize_comment_text> 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.
- */
- public function save()
- {
- qdb("UPDATE `PREFIX_comments` SET `author_name` = ?, `author_mail` = ?, `text` = ?, `visible` = ?, `read_by_admin` = ? WHERE `id` = ?",
- $this->author_name, $this->author_mail, $this->text, ($this->visible ? 1 : 0), ($this->read_by_admin ? 1 : 0), $this->id);
- }
-
- /*
- * Function: delete
- */
- public function delete()
- {
- qdb("DELETE FROM `PREFIX_comments` WHERE `id` = ?", $this->id);
- }
+ private $id;
+ private $article_id;
+ private $language;
+ private $timestamp;
+
+ /*
+ * Variables: Public class variables.
+ *
+ * $author_name - Name of comment author.
+ * $author_mail - E-Mail of comment author.
+ * $text - Comment text.
+ * $visible - Should the comment be visible?
+ * $read_by_admin - Was the comment read by an admin.
+ */
+ public $author_name;
+ public $author_mail;
+ public $text;
+ public $visible;
+ public $read_by_admin;
+
+ /*
+ * Functions: Getters
+ *
+ * get_id - Gets the comment ID.
+ * get_article - Gets the article.
+ * get_language - Gets the language.
+ * get_timestamp - Gets the timestamp.
+ */
+ public function get_id() { return $this->id; }
+ public function get_article() { return Article::by_id($this->article_id); }
+ public function get_language() { return $this->language; }
+ public function get_timestamp() { return $this->timestamp; }
+
+ /*
+ * Constructor: create
+ * Creates a new comment.
+ * Automatically sets the $timestamp and $visible (default from setting "comment_visible_default").
+ *
+ * Parameters:
+ * $article - An <Article> Object.
+ * $language - Which language? (see <languages.php>)
+ */
+ public static function create($article, $language)
+ {
+ global $ratatoeskr_settings;
+ global $db_con;
+
+ $obj = new self();
+ $obj->timestamp = time();
+
+ qdb("INSERT INTO `PREFIX_comments` (`article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin`) VALUES (?, ?, '', '', '', ?, ?, 0)",
+ $article->get_id(), $language, $obj->timestamp, $ratatoeskr_settings["comment_visible_default"] ? 1 : 0);
+
+ $obj->id = $db_con->lastInsertId();
+ $obj->article_id = $article->get_id();
+ $obj->language = $language;
+ $obj->author_name = "";
+ $obj->author_mail = "";
+ $obj->text = "";
+ $obj->visible = $ratatoeskr_settings["comment_visible_default"];
+ $obj->read_by_admin = False;
+
+ return $obj;
+ }
+
+ protected function populate_by_sqlrow($sqlrow)
+ {
+ $this->id = $sqlrow["id"];
+ $this->article_id = $sqlrow["article"];
+ $this->language = $sqlrow["language"];
+ $this->author_name = $sqlrow["author_name"];
+ $this->author_mail = $sqlrow["author_mail"];
+ $this->text = $sqlrow["text"];
+ $this->timestamp = $sqlrow["timestamp"];
+ $this->visible = $sqlrow["visible"] == 1;
+ $this->read_by_admin = $sqlrow["read_by_admin"] == 1;
+ }
+
+ /*
+ * Constructor: by_id
+ * Gets a Comment by ID.
+ *
+ * Parameters:
+ * $id - The comments ID.
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_id($id)
+ {
+ $stmt = qdb("SELECT `id`, `article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin` FROM `PREFIX_comments` WHERE `id` = ?", $id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow === False)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: all
+ * Get all comments
+ *
+ * Returns:
+ * Array of Comment objects
+ */
+ public static function all()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `id`, `article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin` FROM `PREFIX_comments` WHERE 1");
+ while($sqlrow = $stmt->fetch())
+ $rv[] = self::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * 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:
+ * HTML code.
+ */
+ public static function htmlize_comment_text($text)
+ {
+ global $ratatoeskr_settings;
+
+ 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(),
+ "u" => array(),
+ "strong" => array(),
+ "em" => array(),
+ "p" => array("align" => 1),
+ "br" => array(),
+ "abbr" => array(),
+ "acronym" => array(),
+ "code" => array(),
+ "pre" => array(),
+ "blockquote" => array("cite" => 1),
+ "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),
+ "samp" => array(),
+ "ul" => array(),
+ "ol" => array(),
+ "li" => array(),
+ "del" => array(),
+ "ins" => array(),
+ "dl" => array(),
+ "dd" => array(),
+ "dt" => array(),
+ "dfn" => array(),
+ "div" => array(),
+ "dir" => array(),
+ "kbd" => array("prompt" => 1),
+ "strike" => array(),
+ "sub" => array(),
+ "sup" => array(),
+ "table" => array("style" => 1),
+ "tbody" => array(), "thead" => array(), "tfoot" => array(),
+ "tr" => array(),
+ "td" => array("colspan" => 1, "rowspan" => 1),
+ "th" => array("colspan" => 1, "rowspan" => 1),
+ "tt" => array(),
+ "var" => array()
+ ));
+ }
+
+ /*
+ * Function: create_html
+ * Applys <htmlize_comment_text> 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.
+ */
+ public function save()
+ {
+ qdb("UPDATE `PREFIX_comments` SET `author_name` = ?, `author_mail` = ?, `text` = ?, `visible` = ?, `read_by_admin` = ? WHERE `id` = ?",
+ $this->author_name, $this->author_mail, $this->text, ($this->visible ? 1 : 0), ($this->read_by_admin ? 1 : 0), $this->id);
+ }
+
+ /*
+ * Function: delete
+ */
+ public function delete()
+ {
+ qdb("DELETE FROM `PREFIX_comments` WHERE `id` = ?", $this->id);
+ }
}
/*
@@ -1194,185 +1194,185 @@ class Comment extends BySQLRowEnabled
*/
class Style extends BySQLRowEnabled
{
- private $id;
-
- /*
- * Variables: Public class variables.
- *
- * $name - The name of the style.
- * $code - The CSS code.
- */
- public $name;
- public $code;
-
- protected function populate_by_sqlrow($sqlrow)
- {
- $this->id = $sqlrow["id"];
- $this->name = $sqlrow["name"];
- $this->code = $sqlrow["code"];
- }
-
- /*
- * Function: test_name
- * Test, if a name is a valid Style name.
- *
- * Parameters:
- * $name - The name to test
- *
- * Returns:
- * True, if the name is a valid style name, False if not.
- */
- public static function test_name($name)
- {
- return preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $name) == 1;
- }
-
- /*
- * Function: get_id
- */
- public function get_id() { return $this->id; }
-
- /*
- * Constructor: create
- * Create a new style.
- *
- * Parameters:
- * $name - A name for the new style.
- *
- * Throws:
- * <AlreadyExistsError>
- */
- public static function create($name)
- {
- global $db_con;
-
- if(!self::test_name($name))
- throw new InvalidDataError("invalid_style_name");
-
- try
- {
- self::by_name($name);
- }
- catch(DoesNotExistError $e)
- {
- $obj = new self();
- $obj->name = $name;
- $obj->code = "";
-
- qdb("INSERT INTO `PREFIX_styles` (`name`, `code`) VALUES (?, '')", $name);
-
- $obj->id = $db_con->lastInsertId();
- return $obj;
- }
-
- throw new AlreadyExistsError();
- }
-
- /*
- * Constructor: by_id
- * Gets a Style object by ID.
- *
- * Parameters:
- * $id - The ID
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_id($id)
- {
- $stmt = qdb("SELECT `id`, `name`, `code` FROM `PREFIX_styles` WHERE `id` = ?", $id);
- $sqlrow = $stmt->fetch();
- if(!$sqlrow)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: by_name
- * Gets a Style object by name.
- *
- * Parameters:
- * $name - The name.
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_name($name)
- {
- $stmt = qdb("SELECT `id`, `name`, `code` FROM `PREFIX_styles` WHERE `name` = ?", $name);
- $sqlrow = $stmt->fetch();
- if(!$sqlrow)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: all
- * Get all styles
- *
- * Returns:
- * Array of Style objects
- */
- public static function all()
- {
- $rv = array();
- $stmt = qdb("SELECT `id`, `name`, `code` FROM `PREFIX_styles` WHERE 1");
- while($sqlrow = $stmt->fetch())
- $rv[] = self::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * Function: save
- * Save changes to database.
- *
- * Throws:
- * <AlreadyExistsError>
- */
- public function save()
- {
- if(!self::test_name($this->name))
- throw new InvalidDataError("invalid_style_name");
-
- $tx = new Transaction();
- try
- {
- $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_styles` WHERE `name` = ? AND `id` != ?", $this->name, $this->id);
- $sqlrow = $stmt->fetch();
- if($sqlrow["n"] > 0)
- throw new AlreadyExistsError();
-
- qdb("UPDATE `PREFIX_styles` SET `name` = ?, `code` = ? WHERE `id` = ?",
- $this->name, $this->code, $this->id);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /*
- * Function: delete
- */
- public function delete()
- {
- $tx = new Transaction();
- try
- {
- qdb("DELETE FROM `PREFIX_styles` WHERE `id` = ?", $this->id);
- qdb("DELETE FROM `PREFIX_section_style_relations` WHERE `style` = ?", $this->id);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
+ private $id;
+
+ /*
+ * Variables: Public class variables.
+ *
+ * $name - The name of the style.
+ * $code - The CSS code.
+ */
+ public $name;
+ public $code;
+
+ protected function populate_by_sqlrow($sqlrow)
+ {
+ $this->id = $sqlrow["id"];
+ $this->name = $sqlrow["name"];
+ $this->code = $sqlrow["code"];
+ }
+
+ /*
+ * Function: test_name
+ * Test, if a name is a valid Style name.
+ *
+ * Parameters:
+ * $name - The name to test
+ *
+ * Returns:
+ * True, if the name is a valid style name, False if not.
+ */
+ public static function test_name($name)
+ {
+ return preg_match("/^[a-zA-Z0-9\\-_\\.]+$/", $name) == 1;
+ }
+
+ /*
+ * Function: get_id
+ */
+ public function get_id() { return $this->id; }
+
+ /*
+ * Constructor: create
+ * Create a new style.
+ *
+ * Parameters:
+ * $name - A name for the new style.
+ *
+ * Throws:
+ * <AlreadyExistsError>
+ */
+ public static function create($name)
+ {
+ global $db_con;
+
+ if(!self::test_name($name))
+ throw new InvalidDataError("invalid_style_name");
+
+ try
+ {
+ self::by_name($name);
+ }
+ catch(DoesNotExistError $e)
+ {
+ $obj = new self();
+ $obj->name = $name;
+ $obj->code = "";
+
+ qdb("INSERT INTO `PREFIX_styles` (`name`, `code`) VALUES (?, '')", $name);
+
+ $obj->id = $db_con->lastInsertId();
+ return $obj;
+ }
+
+ throw new AlreadyExistsError();
+ }
+
+ /*
+ * Constructor: by_id
+ * Gets a Style object by ID.
+ *
+ * Parameters:
+ * $id - The ID
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_id($id)
+ {
+ $stmt = qdb("SELECT `id`, `name`, `code` FROM `PREFIX_styles` WHERE `id` = ?", $id);
+ $sqlrow = $stmt->fetch();
+ if(!$sqlrow)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: by_name
+ * Gets a Style object by name.
+ *
+ * Parameters:
+ * $name - The name.
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_name($name)
+ {
+ $stmt = qdb("SELECT `id`, `name`, `code` FROM `PREFIX_styles` WHERE `name` = ?", $name);
+ $sqlrow = $stmt->fetch();
+ if(!$sqlrow)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: all
+ * Get all styles
+ *
+ * Returns:
+ * Array of Style objects
+ */
+ public static function all()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `id`, `name`, `code` FROM `PREFIX_styles` WHERE 1");
+ while($sqlrow = $stmt->fetch())
+ $rv[] = self::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * Function: save
+ * Save changes to database.
+ *
+ * Throws:
+ * <AlreadyExistsError>
+ */
+ public function save()
+ {
+ if(!self::test_name($this->name))
+ throw new InvalidDataError("invalid_style_name");
+
+ $tx = new Transaction();
+ try
+ {
+ $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_styles` WHERE `name` = ? AND `id` != ?", $this->name, $this->id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow["n"] > 0)
+ throw new AlreadyExistsError();
+
+ qdb("UPDATE `PREFIX_styles` SET `name` = ?, `code` = ? WHERE `id` = ?",
+ $this->name, $this->code, $this->id);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /*
+ * Function: delete
+ */
+ public function delete()
+ {
+ $tx = new Transaction();
+ try
+ {
+ qdb("DELETE FROM `PREFIX_styles` WHERE `id` = ?", $this->id);
+ qdb("DELETE FROM `PREFIX_section_style_relations` WHERE `style` = ?", $this->id);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
}
/*
@@ -1381,205 +1381,205 @@ class Style extends BySQLRowEnabled
*/
class Plugin extends BySQLRowEnabled
{
- private $id;
-
- /*
- * Variables: Public class variables.
- *
- * $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.
- * $update - Should the plugin be updated at next start?
- * $api - The API version this Plugin needs.
- */
-
- 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;
- public $update;
- public $api;
-
- /*
- * 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` < ?", (time() - (60*5)));
- }
-
- /*
- * Function: get_id
- */
- public function get_id() { return $this->id; }
-
- /*
- * Constructor: create
- * Creates a new, empty plugin database entry
- */
- public static function create()
- {
- global $db_con;
-
- $obj = new self();
- qdb("INSERT INTO `PREFIX_plugins` (`added`) VALUES (?)", time());
- $obj->id = $db_con->lastInsertId();
- return $obj;
- }
-
- /*
- * Function: fill_from_pluginpackage
- * Fills plugin data from an <PluginPackage> object.
- *
- * Parameters:
- * $pkg - The <PluginPackage> 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;
- $this->api = $pkg->api;
-
- 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/src/plugintemplates/" . $this->get_id());
- }
-
- protected function populate_by_sqlrow($sqlrow)
- {
- $this->id = $sqlrow["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);
- $this->update = ($sqlrow["update"] == 1);
- $this->api = $sqlrow["api"];
- }
-
- /*
- * Constructor: by_id
- * Gets plugin by ID.
- *
- * Parameters:
- * $id - The ID
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_id($id)
- {
- $stmt = qdb("SELECT `id`, `name`, `author`, `versiontext`, `versioncount`, `short_description`, `updatepath`, `web`, `help`, `code`, `classname`, `active`, `license`, `installed`, `update`, `api` FROM `PREFIX_plugins` WHERE `id` = ?", $id);
- $sqlrow = $stmt->fetch();
- if($sqlrow === False)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: all
- * Gets all Plugins
- *
- * Returns:
- * List of <Plugin> objects.
- */
- public static function all()
- {
- $rv = array();
- $stmt = qdb("SELECT `id`, `name`, `author`, `versiontext`, `versioncount`, `short_description`, `updatepath`, `web`, `help`, `code`, `classname`, `active`, `license`, `installed`, `update`, `api` FROM `PREFIX_plugins` WHERE 1");
- while($sqlrow = $stmt->fetch())
- $rv[] = self::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * Function: save
- */
- public function save()
- {
- qdb("UPDATE `PREFIX_plugins` SET `name` = ?, `author` = ?, `code` = ?, `classname` = ?, `active` = ?, `versiontext` = ?, `versioncount` = ?, `short_description` = ?, `updatepath` = ?, `web` = ?, `help` = ?, `installed` = ?, `update` = ?, `license` = ?, `api` = ? WHERE `id` = ?",
- $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->api, $this->id);
- }
-
- /*
- * Function: delete
- */
- public function delete()
- {
- $tx = new Transaction();
- try
- {
- qdb("DELETE FROM `PREFIX_plugins` WHERE `id` = ?", $this->id);
- qdb("DELETE FROM `PREFIX_plugin_kvstorage` WHERE `plugin` = ?", $this->id);
- qdb("DELETE FROM `PREFIX_article_extradata` WHERE `plugin` = ?", $this->id);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
-
- 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);
- }
-
- /*
- * Function get_kvstorage
- * Get the KeyValue Storage for the plugin.
- *
- * Returns:
- * An <PluginKVStorage> object.
- */
- public function get_kvstorage()
- {
- return new PluginKVStorage($this->id);
- }
+ private $id;
+
+ /*
+ * Variables: Public class variables.
+ *
+ * $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.
+ * $update - Should the plugin be updated at next start?
+ * $api - The API version this Plugin needs.
+ */
+
+ 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;
+ public $update;
+ public $api;
+
+ /*
+ * 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` < ?", (time() - (60*5)));
+ }
+
+ /*
+ * Function: get_id
+ */
+ public function get_id() { return $this->id; }
+
+ /*
+ * Constructor: create
+ * Creates a new, empty plugin database entry
+ */
+ public static function create()
+ {
+ global $db_con;
+
+ $obj = new self();
+ qdb("INSERT INTO `PREFIX_plugins` (`added`) VALUES (?)", time());
+ $obj->id = $db_con->lastInsertId();
+ return $obj;
+ }
+
+ /*
+ * Function: fill_from_pluginpackage
+ * Fills plugin data from an <PluginPackage> object.
+ *
+ * Parameters:
+ * $pkg - The <PluginPackage> 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;
+ $this->api = $pkg->api;
+
+ 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/src/plugintemplates/" . $this->get_id());
+ }
+
+ protected function populate_by_sqlrow($sqlrow)
+ {
+ $this->id = $sqlrow["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);
+ $this->update = ($sqlrow["update"] == 1);
+ $this->api = $sqlrow["api"];
+ }
+
+ /*
+ * Constructor: by_id
+ * Gets plugin by ID.
+ *
+ * Parameters:
+ * $id - The ID
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_id($id)
+ {
+ $stmt = qdb("SELECT `id`, `name`, `author`, `versiontext`, `versioncount`, `short_description`, `updatepath`, `web`, `help`, `code`, `classname`, `active`, `license`, `installed`, `update`, `api` FROM `PREFIX_plugins` WHERE `id` = ?", $id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow === False)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: all
+ * Gets all Plugins
+ *
+ * Returns:
+ * List of <Plugin> objects.
+ */
+ public static function all()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `id`, `name`, `author`, `versiontext`, `versioncount`, `short_description`, `updatepath`, `web`, `help`, `code`, `classname`, `active`, `license`, `installed`, `update`, `api` FROM `PREFIX_plugins` WHERE 1");
+ while($sqlrow = $stmt->fetch())
+ $rv[] = self::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * Function: save
+ */
+ public function save()
+ {
+ qdb("UPDATE `PREFIX_plugins` SET `name` = ?, `author` = ?, `code` = ?, `classname` = ?, `active` = ?, `versiontext` = ?, `versioncount` = ?, `short_description` = ?, `updatepath` = ?, `web` = ?, `help` = ?, `installed` = ?, `update` = ?, `license` = ?, `api` = ? WHERE `id` = ?",
+ $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->api, $this->id);
+ }
+
+ /*
+ * Function: delete
+ */
+ public function delete()
+ {
+ $tx = new Transaction();
+ try
+ {
+ qdb("DELETE FROM `PREFIX_plugins` WHERE `id` = ?", $this->id);
+ qdb("DELETE FROM `PREFIX_plugin_kvstorage` WHERE `plugin` = ?", $this->id);
+ qdb("DELETE FROM `PREFIX_article_extradata` WHERE `plugin` = ?", $this->id);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+
+ 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);
+ }
+
+ /*
+ * Function get_kvstorage
+ * Get the KeyValue Storage for the plugin.
+ *
+ * Returns:
+ * An <PluginKVStorage> object.
+ */
+ public function get_kvstorage()
+ {
+ return new PluginKVStorage($this->id);
+ }
}
/*
@@ -1588,266 +1588,266 @@ class Plugin extends BySQLRowEnabled
*/
class Section extends BySQLRowEnabled
{
- private $id;
-
- /*
- * Variables: Public class variables
- *
- * $name - The name of the section.
- * $title - The title of the section (a <Multilingual> object).
- * $template - Name of the template.
- */
- public $name;
- public $title;
- public $template;
-
- protected function populate_by_sqlrow($sqlrow)
- {
- $this->id = $sqlrow["id"];
- $this->name = $sqlrow["name"];
- $this->title = Multilingual::by_id($sqlrow["title"]);
- $this->template = $sqlrow["template"];
- }
-
- /*
- * Function: test_name
- * Tests, if a name is a valid section name.
- *
- * Parameters:
- * $name - The name to test.
- *
- * Returns:
- * True, if the name is a valid section name, False otherwise.
- */
- public static function test_name($name)
- {
- return preg_match("/^[a-zA-Z0-9\\-_]+$/", $name) != 0;
- }
-
- /*
- * Function: get_id
- */
- public function get_id() { return $this->id; }
-
- /*
- * Constructor: create
- * Creates a new section.
- *
- * Parameters:
- * $name - The name of the new section.
- *
- * Throws:
- * <AlreadyExistsError>, <InvalidDataError>
- */
- public static function create($name)
- {
- global $db_con;
-
- if(!self::test_name($name))
- throw new InvalidDataError("invalid_section_name");
-
- try
- {
- $obj = self::by_name($name);
- }
- catch(DoesNotExistError $e)
- {
- $obj = new self();
- $obj->name = $name;
- $obj->title = Multilingual::create();
- $obj->template = "";
-
- qdb("INSERT INTO `PREFIX_sections` (`name`, `title`, `template`) VALUES (?, ?, '')", $name, $obj->title->get_id());
-
- $obj->id = $db_con->lastInsertId();
-
- return $obj;
- }
-
- throw new AlreadyExistsError();
- }
-
- /*
- * Constructor: by_id
- * Gets section by ID.
- *
- * Parameters:
- * $id - The ID.
- *
- * Returns:
- * A <Section> object.
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_id($id)
- {
- $stmt = qdb("SELECT `id`, `name`, `title`, `template` FROM `PREFIX_sections` WHERE `id` = ?", $id);
- $sqlrow = $stmt->fetch();
- if($sqlrow === False)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: by_name
- * Gets section by name.
- *
- * Parameters:
- * $name - The name.
- *
- * Returns:
- * A <Section> object.
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_name($name)
- {
- $stmt = qdb("SELECT `id`, `name`, `title`, `template` FROM `PREFIX_sections` WHERE `name` = ?", $name);
- $sqlrow = $stmt->fetch();
- if($sqlrow === False)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: all
- * Gets all sections.
- *
- * Returns:
- * Array of Section objects.
- */
- public static function all()
- {
- $rv = array();
- $stmt = qdb("SELECT `id`, `name`, `title`, `template` FROM `PREFIX_sections` WHERE 1");
- while($sqlrow = $stmt->fetch())
- $rv[] = self::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * Function: get_styles
- * Get all styles associated with this section.
- *
- * Returns:
- * List of <Style> objects.
- */
- public function get_styles()
- {
- $rv = array();
- $stmt = qdb("SELECT `a`.`id` AS `id`, `a`.`name` AS `name`, `a`.`code` AS `code` FROM `PREFIX_styles` `a` INNER JOIN `PREFIX_section_style_relations` `b` ON `a`.`id` = `b`.`style` WHERE `b`.`section` = ?", $this->id);
- while($sqlrow = $stmt->fetch())
- $rv[] = Style::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * Function: add_style
- * Add a style to this section.
- *
- * Parameters:
- * $style - A <Style> object.
- */
- public function add_style($style)
- {
- $tx = new Transaction();
- try
- {
- $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_section_style_relations` WHERE `style` = ? AND `section` = ?", $style->get_id(), $this->id);
- $sqlrow = $stmt->fetch();
- if($sqlrow["n"] == 0)
- qdb("INSERT INTO `PREFIX_section_style_relations` (`section`, `style`) VALUES (?, ?)", $this->id, $style->get_id());
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /*
- * Function: remove_style
- * Remove a style from this section.
- *
- * Parameters:
- * $style - A <Style> object.
- */
- public function remove_style($style)
- {
- qdb("DELETE FROM `PREFIX_section_style_relations` WHERE `section` = ? AND `style` = ?", $this->id, $style->get_id());
- }
-
- /*
- * Function: save
- *
- * Throws:
- * <AlreadyExistsError>, <InvalidDataError>
- */
- public function save()
- {
- if(!self::test_name($this->name))
- throw new InvalidDataError("invalid_section_name");
-
- $tx = new Transaction();
- try
- {
- $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_sections` WHERE `name` = ? AND `id` != ?", $this->name, $this->id);
- $sqlrow = $stmt->fetch();
- if($sqlrow["n"] > 0)
- throw new AlreadyExistsError();
-
- $this->title->save();
- qdb("UPDATE `PREFIX_sections` SET `name` = ?, `title` = ?, `template` = ? WHERE `id` = ?",
- $this->name, $this->title->get_id(), $this->template, $this->id);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /*
- * Function: delete
- */
- public function delete()
- {
- $tx = new Transaction();
- try
- {
- $this->title->delete();
- qdb("DELETE FROM `PREFIX_sections` WHERE `id` = ?", $this->id);
- qdb("DELETE FROM `PREFIX_section_style_relations` WHERE `section` = ?", $this->id);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /*
- * Function: get_articles
- * Get all articles in this section.
- *
- * Returns:
- * Array of <Article> objects
- */
- public function get_articles()
- {
- $rv = array();
- $stmt = qdb("SELECT `id`, `urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments` FROM `PREFIX_articles` WHERE `section` = ?", $this->id);
- while($sqlrow = $stmt->fetch())
- $rv[] = Article::by_sqlrow($sqlrow);
- return $rv;
- }
+ private $id;
+
+ /*
+ * Variables: Public class variables
+ *
+ * $name - The name of the section.
+ * $title - The title of the section (a <Multilingual> object).
+ * $template - Name of the template.
+ */
+ public $name;
+ public $title;
+ public $template;
+
+ protected function populate_by_sqlrow($sqlrow)
+ {
+ $this->id = $sqlrow["id"];
+ $this->name = $sqlrow["name"];
+ $this->title = Multilingual::by_id($sqlrow["title"]);
+ $this->template = $sqlrow["template"];
+ }
+
+ /*
+ * Function: test_name
+ * Tests, if a name is a valid section name.
+ *
+ * Parameters:
+ * $name - The name to test.
+ *
+ * Returns:
+ * True, if the name is a valid section name, False otherwise.
+ */
+ public static function test_name($name)
+ {
+ return preg_match("/^[a-zA-Z0-9\\-_]+$/", $name) != 0;
+ }
+
+ /*
+ * Function: get_id
+ */
+ public function get_id() { return $this->id; }
+
+ /*
+ * Constructor: create
+ * Creates a new section.
+ *
+ * Parameters:
+ * $name - The name of the new section.
+ *
+ * Throws:
+ * <AlreadyExistsError>, <InvalidDataError>
+ */
+ public static function create($name)
+ {
+ global $db_con;
+
+ if(!self::test_name($name))
+ throw new InvalidDataError("invalid_section_name");
+
+ try
+ {
+ $obj = self::by_name($name);
+ }
+ catch(DoesNotExistError $e)
+ {
+ $obj = new self();
+ $obj->name = $name;
+ $obj->title = Multilingual::create();
+ $obj->template = "";
+
+ qdb("INSERT INTO `PREFIX_sections` (`name`, `title`, `template`) VALUES (?, ?, '')", $name, $obj->title->get_id());
+
+ $obj->id = $db_con->lastInsertId();
+
+ return $obj;
+ }
+
+ throw new AlreadyExistsError();
+ }
+
+ /*
+ * Constructor: by_id
+ * Gets section by ID.
+ *
+ * Parameters:
+ * $id - The ID.
+ *
+ * Returns:
+ * A <Section> object.
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_id($id)
+ {
+ $stmt = qdb("SELECT `id`, `name`, `title`, `template` FROM `PREFIX_sections` WHERE `id` = ?", $id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow === False)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: by_name
+ * Gets section by name.
+ *
+ * Parameters:
+ * $name - The name.
+ *
+ * Returns:
+ * A <Section> object.
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_name($name)
+ {
+ $stmt = qdb("SELECT `id`, `name`, `title`, `template` FROM `PREFIX_sections` WHERE `name` = ?", $name);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow === False)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: all
+ * Gets all sections.
+ *
+ * Returns:
+ * Array of Section objects.
+ */
+ public static function all()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `id`, `name`, `title`, `template` FROM `PREFIX_sections` WHERE 1");
+ while($sqlrow = $stmt->fetch())
+ $rv[] = self::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * Function: get_styles
+ * Get all styles associated with this section.
+ *
+ * Returns:
+ * List of <Style> objects.
+ */
+ public function get_styles()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `a`.`id` AS `id`, `a`.`name` AS `name`, `a`.`code` AS `code` FROM `PREFIX_styles` `a` INNER JOIN `PREFIX_section_style_relations` `b` ON `a`.`id` = `b`.`style` WHERE `b`.`section` = ?", $this->id);
+ while($sqlrow = $stmt->fetch())
+ $rv[] = Style::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * Function: add_style
+ * Add a style to this section.
+ *
+ * Parameters:
+ * $style - A <Style> object.
+ */
+ public function add_style($style)
+ {
+ $tx = new Transaction();
+ try
+ {
+ $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_section_style_relations` WHERE `style` = ? AND `section` = ?", $style->get_id(), $this->id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow["n"] == 0)
+ qdb("INSERT INTO `PREFIX_section_style_relations` (`section`, `style`) VALUES (?, ?)", $this->id, $style->get_id());
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /*
+ * Function: remove_style
+ * Remove a style from this section.
+ *
+ * Parameters:
+ * $style - A <Style> object.
+ */
+ public function remove_style($style)
+ {
+ qdb("DELETE FROM `PREFIX_section_style_relations` WHERE `section` = ? AND `style` = ?", $this->id, $style->get_id());
+ }
+
+ /*
+ * Function: save
+ *
+ * Throws:
+ * <AlreadyExistsError>, <InvalidDataError>
+ */
+ public function save()
+ {
+ if(!self::test_name($this->name))
+ throw new InvalidDataError("invalid_section_name");
+
+ $tx = new Transaction();
+ try
+ {
+ $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_sections` WHERE `name` = ? AND `id` != ?", $this->name, $this->id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow["n"] > 0)
+ throw new AlreadyExistsError();
+
+ $this->title->save();
+ qdb("UPDATE `PREFIX_sections` SET `name` = ?, `title` = ?, `template` = ? WHERE `id` = ?",
+ $this->name, $this->title->get_id(), $this->template, $this->id);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /*
+ * Function: delete
+ */
+ public function delete()
+ {
+ $tx = new Transaction();
+ try
+ {
+ $this->title->delete();
+ qdb("DELETE FROM `PREFIX_sections` WHERE `id` = ?", $this->id);
+ qdb("DELETE FROM `PREFIX_section_style_relations` WHERE `section` = ?", $this->id);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /*
+ * Function: get_articles
+ * Get all articles in this section.
+ *
+ * Returns:
+ * Array of <Article> objects
+ */
+ public function get_articles()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `id`, `urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments` FROM `PREFIX_articles` WHERE `section` = ?", $this->id);
+ while($sqlrow = $stmt->fetch())
+ $rv[] = Article::by_sqlrow($sqlrow);
+ return $rv;
+ }
}
/*
@@ -1856,219 +1856,219 @@ class Section extends BySQLRowEnabled
*/
class Tag extends BySQLRowEnabled
{
- private $id;
-
- /*
- * Variables: Public class variables
- *
- * $name - The name of the tag
- * $title - The title (an <Multilingual> object)
- */
- public $name;
- public $title;
-
- /*
- * Function: test_name
- * Test, if a name is a valid tag name.
- *
- * Parameters:
- * $name - Name to test.
- *
- * Returns:
- * True, if the name is valid, False otherwise.
- */
- public static function test_name($name)
- {
- return (strpos($name, ",") === False) and (strpos($name, " ") === False);
- }
-
- /*
- * Function: get_id
- */
- public function get_id() { return $this->id; }
-
- protected function populate_by_sqlrow($sqlrow)
- {
- $this->id = $sqlrow["id"];
- $this->name = $sqlrow["name"];
- $this->title = Multilingual::by_id($sqlrow["title"]);
- }
-
- /*
- * Constructor: create
- * Create a new tag.
- *
- * Parameters:
- * $name - The name
- *
- * Throws:
- * <AlreadyExistsError>, <InvalidDataError>
- */
- public static function create($name)
- {
- global $db_con;
- if(!self::test_name($name))
- throw new InvalidDataError("invalid_tag_name");
-
- try
- {
- $obj = self::by_name($name);
- }
- catch(DoesNotExistError $e)
- {
- $obj = new self();
-
- $obj->name = $name;
- $obj->title = Multilingual::create();
-
- qdb("INSERT INTO `PREFIX_tags` (`name`, `title`) VALUES (?, ?)",
- $name, $obj->title->get_id());
- $obj->id = $db_con->lastInsertId();
-
- return $obj;
- }
- throw new AlreadyExistsError();
- }
-
- /*
- * Constructor: by_id
- * Get tag by ID
- *
- * Parameters:
- * $id - The ID
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_id($id)
- {
- $stmt = qdb("SELECT `id`, `name`, `title` FROM `PREFIX_tags` WHERE `id` = ?", $id);
- $sqlrow = $stmt->fetch();
- if($sqlrow === False)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: by_name
- * Get tag by name
- *
- * Parameters:
- * $name - The name
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_name($name)
- {
- $stmt = qdb("SELECT `id`, `name`, `title` FROM `PREFIX_tags` WHERE `name` = ?", $name);
- $sqlrow = $stmt->fetch();
- if($sqlrow === False)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: all
- * Get all tags
- *
- * Returns:
- * Array of Tag objects.
- */
- public static function all()
- {
- $rv = array();
- $stmt = qdb("SELECT `id`, `name`, `title` FROM `PREFIX_tags` WHERE 1");
- while($sqlrow = $stmt->fetch())
- $rv[] = self::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * Function: get_articles
- * Get all articles that are tagged with this tag
- *
- * Returns:
- * Array of <Article> objects
- */
- public function get_articles()
- {
- $rv = array();
- $stmt = qdb(
+ private $id;
+
+ /*
+ * Variables: Public class variables
+ *
+ * $name - The name of the tag
+ * $title - The title (an <Multilingual> object)
+ */
+ public $name;
+ public $title;
+
+ /*
+ * Function: test_name
+ * Test, if a name is a valid tag name.
+ *
+ * Parameters:
+ * $name - Name to test.
+ *
+ * Returns:
+ * True, if the name is valid, False otherwise.
+ */
+ public static function test_name($name)
+ {
+ return (strpos($name, ",") === False) and (strpos($name, " ") === False);
+ }
+
+ /*
+ * Function: get_id
+ */
+ public function get_id() { return $this->id; }
+
+ protected function populate_by_sqlrow($sqlrow)
+ {
+ $this->id = $sqlrow["id"];
+ $this->name = $sqlrow["name"];
+ $this->title = Multilingual::by_id($sqlrow["title"]);
+ }
+
+ /*
+ * Constructor: create
+ * Create a new tag.
+ *
+ * Parameters:
+ * $name - The name
+ *
+ * Throws:
+ * <AlreadyExistsError>, <InvalidDataError>
+ */
+ public static function create($name)
+ {
+ global $db_con;
+ if(!self::test_name($name))
+ throw new InvalidDataError("invalid_tag_name");
+
+ try
+ {
+ $obj = self::by_name($name);
+ }
+ catch(DoesNotExistError $e)
+ {
+ $obj = new self();
+
+ $obj->name = $name;
+ $obj->title = Multilingual::create();
+
+ qdb("INSERT INTO `PREFIX_tags` (`name`, `title`) VALUES (?, ?)",
+ $name, $obj->title->get_id());
+ $obj->id = $db_con->lastInsertId();
+
+ return $obj;
+ }
+ throw new AlreadyExistsError();
+ }
+
+ /*
+ * Constructor: by_id
+ * Get tag by ID
+ *
+ * Parameters:
+ * $id - The ID
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_id($id)
+ {
+ $stmt = qdb("SELECT `id`, `name`, `title` FROM `PREFIX_tags` WHERE `id` = ?", $id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow === False)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: by_name
+ * Get tag by name
+ *
+ * Parameters:
+ * $name - The name
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_name($name)
+ {
+ $stmt = qdb("SELECT `id`, `name`, `title` FROM `PREFIX_tags` WHERE `name` = ?", $name);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow === False)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: all
+ * Get all tags
+ *
+ * Returns:
+ * Array of Tag objects.
+ */
+ public static function all()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `id`, `name`, `title` FROM `PREFIX_tags` WHERE 1");
+ while($sqlrow = $stmt->fetch())
+ $rv[] = self::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * Function: get_articles
+ * Get all articles that are tagged with this tag
+ *
+ * Returns:
+ * Array of <Article> objects
+ */
+ public function get_articles()
+ {
+ $rv = array();
+ $stmt = qdb(
"SELECT `a`.`id` AS `id`, `a`.`urlname` AS `urlname`, `a`.`title` AS `title`, `a`.`text` AS `text`, `a`.`excerpt` AS `excerpt`, `a`.`meta` AS `meta`, `a`.`custom` AS `custom`, `a`.`article_image` AS `article_image`, `a`.`status` AS `status`, `a`.`section` AS `section`, `a`.`timestamp` AS `timestamp`, `a`.`allow_comments` AS `allow_comments`
FROM `PREFIX_articles` `a`
INNER JOIN `PREFIX_article_tag_relations` `b` ON `a`.`id` = `b`.`article`
WHERE `b`.`tag` = ?" , $this->id);
- while($sqlrow = $stmt->fetch())
- $rv[] = Article::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * Function: count_articles
- *
- * Returns:
- * The number of articles that are tagged with this tag.
- */
- public function count_articles()
- {
- $stmt = qdb("SELECT COUNT(*) AS `num` FROM `PREFIX_article_tag_relations` WHERE `tag` = ?", $this->id);
- $sqlrow = $stmt->fetch();
- return $sqlrow["num"];
- }
-
- /*
- * Function: save
- *
- * Throws:
- * <AlreadyExistsError>, <InvalidDataError>
- */
- public function save()
- {
- if(!self::test_name($this->name))
- throw new InvalidDataError("invalid_tag_name");
-
- $tx = new Transaction();
- try
- {
- $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_tags` WHERE `name` = ? AND `id` != ?", $this->name, $this->id);
- $sqlrow = $stmt->fetch();
- if($sqlrow["n"] > 0)
- throw new AlreadyExistsError();
-
- $this->title->save();
- qdb("UPDATE `PREFIX_tags` SET `name` = ?, `title` = ? WHERE `id` = ?",
- $this->name, $this->title->get_id(), $this->id);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /*
- * Function: delete
- */
- public function delete()
- {
- $tx = new Transaction();
- try
- {
- $this->title->delete();
- qdb("DELETE FROM `PREFIX_article_tag_relations` WHERE `tag` = ?", $this->id);
- qdb("DELETE FROM `PREFIX_tags` WHERE `id` = ?", $this->id);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
+ while($sqlrow = $stmt->fetch())
+ $rv[] = Article::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * Function: count_articles
+ *
+ * Returns:
+ * The number of articles that are tagged with this tag.
+ */
+ public function count_articles()
+ {
+ $stmt = qdb("SELECT COUNT(*) AS `num` FROM `PREFIX_article_tag_relations` WHERE `tag` = ?", $this->id);
+ $sqlrow = $stmt->fetch();
+ return $sqlrow["num"];
+ }
+
+ /*
+ * Function: save
+ *
+ * Throws:
+ * <AlreadyExistsError>, <InvalidDataError>
+ */
+ public function save()
+ {
+ if(!self::test_name($this->name))
+ throw new InvalidDataError("invalid_tag_name");
+
+ $tx = new Transaction();
+ try
+ {
+ $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_tags` WHERE `name` = ? AND `id` != ?", $this->name, $this->id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow["n"] > 0)
+ throw new AlreadyExistsError();
+
+ $this->title->save();
+ qdb("UPDATE `PREFIX_tags` SET `name` = ?, `title` = ? WHERE `id` = ?",
+ $this->name, $this->title->get_id(), $this->id);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /*
+ * Function: delete
+ */
+ public function delete()
+ {
+ $tx = new Transaction();
+ try
+ {
+ $this->title->delete();
+ qdb("DELETE FROM `PREFIX_article_tag_relations` WHERE `tag` = ?", $this->id);
+ qdb("DELETE FROM `PREFIX_tags` WHERE `id` = ?", $this->id);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
}
/*
@@ -2089,185 +2089,185 @@ class IOError extends Exception { }
*/
class Image extends BySQLRowEnabled
{
- private $id;
- private $filename;
-
- private static $pre_maxw = 150;
- private static $pre_maxh = 100;
-
- /*
- * Variables: Public class variables
- *
- * $name - The image name
- */
- public $name;
-
- protected function populate_by_sqlrow($sqlrow)
- {
- $this->id = $sqlrow["id"];
- $this->name = $sqlrow["name"];
- $this->file = $sqlrow["file"];
- }
-
- /*
- * Functions: Getters
- *
- * get_id - Get the ID
- * get_filename - Get the filename
- */
- public function get_id() { return $this->id; }
- public function get_filename() { return $this->file; }
-
- /*
- * Constructor: create
- * Create a new image
- *
- * Parameters:
- * $name - The name for the image
- * $file - An uploaded image file (move_uploaded_file must be able to move the file!).
- *
- * Throws:
- * <IOError>, <UnknownFileFormat>
- */
- public static function create($name, $file)
- {
- $obj = new self();
- $obj->name = $name;
- $obj->file = "0";
-
- $tx = new Transaction();
- try
- {
- global $db_con;
-
- qdb("INSERT INTO `PREFIX_images` (`name`, `file`) VALUES (?, '0')", $name);
- $obj->id = $db_con->lastInsertId();
- $obj->exchange_image($file);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- return $obj;
- }
-
- /*
- * Constructor: by_id
- * Get image by ID.
- *
- * Parameters:
- * $id - The ID
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_id($id)
- {
- $stmt = qdb("SELECT `id`, `name`, `file` FROM `PREFIX_images` WHERE `id` = ?", $id);
- $sqlrow = $stmt->fetch();
- if($sqlrow === False)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: all
- * Gets all images.
- *
- * Returns:
- * Array of <Image> objects.
- */
- public function all()
- {
- $rv = array();
- $stmt = qdb("SELECT `id`, `name`, `file` FROM `PREFIX_images` WHERE 1");
- while($sqlrow = $stmt->fetch())
- $rv[] = self::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * Function: exchange_image
- * Exchanges image file. Also saves object to database.
- *
- * Parameters:
- * $file - Location of new image.(move_uploaded_file must be able to move the file!)
- *
- * Throws:
- * <IOError>, <UnknownFileFormat>
- */
- public function exchange_image($file)
- {
- global $imagetype_file_extensions;
- if(!is_file($file))
- throw new IOError("\"$file\" is not available");
- $imageinfo = getimagesize($file);
- if($imageinfo === False)
- throw new UnknownFileFormat();
- if(!isset($imagetype_file_extensions[$imageinfo[2]]))
- throw new UnknownFileFormat();
- if(is_file(SITE_BASE_PATH . "/images/" . $this->file))
- unlink(SITE_BASE_PATH . "/images/" . $this->file);
- $new_fn = $this->id . "." . $imagetype_file_extensions[$imageinfo[2]];
- if(!move_uploaded_file($file, SITE_BASE_PATH . "/images/" . $new_fn))
- throw new IOError("Can not move file.");
- $this->file = $new_fn;
- $this->save();
-
- /* make preview image */
- switch($imageinfo[2])
- {
- case IMAGETYPE_GIF: $img = imagecreatefromgif (SITE_BASE_PATH . "/images/" . $new_fn); break;
- case IMAGETYPE_JPEG: $img = imagecreatefromjpeg(SITE_BASE_PATH . "/images/" . $new_fn); break;
- case IMAGETYPE_PNG: $img = imagecreatefrompng (SITE_BASE_PATH . "/images/" . $new_fn); break;
- default: $img = imagecreatetruecolor(40, 40); imagefill($img, 1, 1, imagecolorallocate($img, 127, 127, 127)); break;
- }
- $w_orig = imagesx($img);
- $h_orig = imagesy($img);
- if(($w_orig > self::$pre_maxw) or ($h_orig > self::$pre_maxh))
- {
- $ratio = $w_orig / $h_orig;
- if($ratio > 1)
- {
- $w_new = round(self::$pre_maxw);
- $h_new = round(self::$pre_maxw / $ratio);
- }
- else
- {
- $h_new = round(self::$pre_maxh);
- $w_new = round(self::$pre_maxh * $ratio);
- }
- $preview = imagecreatetruecolor($w_new, $h_new);
- imagecopyresized($preview, $img, 0, 0, 0, 0, $w_new, $h_new, $w_orig, $h_orig);
- imagepng($preview, SITE_BASE_PATH . "/images/previews/{$this->id}.png");
- }
- else
- imagepng($img, SITE_BASE_PATH . "/images/previews/{$this->id}.png");
- }
-
- /*
- * Function: save
- */
- public function save()
- {
- qdb("UPDATE `PREFIX_images` SET `name` = ?, `file` = ? WHERE `id` = ?",
- $this->name, $this->file, $this->id);
- }
-
- /*
- * Function: delete
- */
- public function delete()
- {
- qdb("DELETE FROM `PREFIX_images` WHERE `id` = ?", $this->id);
- if(is_file(SITE_BASE_PATH . "/images/" . $this->file))
- unlink(SITE_BASE_PATH . "/images/" . $this->file);
- if(is_file(SITE_BASE_PATH . "/images/previews/{$this->id}.png"))
- unlink(SITE_BASE_PATH . "/images/previews/{$this->id}.png");
- }
+ private $id;
+ private $filename;
+
+ private static $pre_maxw = 150;
+ private static $pre_maxh = 100;
+
+ /*
+ * Variables: Public class variables
+ *
+ * $name - The image name
+ */
+ public $name;
+
+ protected function populate_by_sqlrow($sqlrow)
+ {
+ $this->id = $sqlrow["id"];
+ $this->name = $sqlrow["name"];
+ $this->file = $sqlrow["file"];
+ }
+
+ /*
+ * Functions: Getters
+ *
+ * get_id - Get the ID
+ * get_filename - Get the filename
+ */
+ public function get_id() { return $this->id; }
+ public function get_filename() { return $this->file; }
+
+ /*
+ * Constructor: create
+ * Create a new image
+ *
+ * Parameters:
+ * $name - The name for the image
+ * $file - An uploaded image file (move_uploaded_file must be able to move the file!).
+ *
+ * Throws:
+ * <IOError>, <UnknownFileFormat>
+ */
+ public static function create($name, $file)
+ {
+ $obj = new self();
+ $obj->name = $name;
+ $obj->file = "0";
+
+ $tx = new Transaction();
+ try
+ {
+ global $db_con;
+
+ qdb("INSERT INTO `PREFIX_images` (`name`, `file`) VALUES (?, '0')", $name);
+ $obj->id = $db_con->lastInsertId();
+ $obj->exchange_image($file);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ return $obj;
+ }
+
+ /*
+ * Constructor: by_id
+ * Get image by ID.
+ *
+ * Parameters:
+ * $id - The ID
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_id($id)
+ {
+ $stmt = qdb("SELECT `id`, `name`, `file` FROM `PREFIX_images` WHERE `id` = ?", $id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow === False)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: all
+ * Gets all images.
+ *
+ * Returns:
+ * Array of <Image> objects.
+ */
+ public function all()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `id`, `name`, `file` FROM `PREFIX_images` WHERE 1");
+ while($sqlrow = $stmt->fetch())
+ $rv[] = self::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * Function: exchange_image
+ * Exchanges image file. Also saves object to database.
+ *
+ * Parameters:
+ * $file - Location of new image.(move_uploaded_file must be able to move the file!)
+ *
+ * Throws:
+ * <IOError>, <UnknownFileFormat>
+ */
+ public function exchange_image($file)
+ {
+ global $imagetype_file_extensions;
+ if(!is_file($file))
+ throw new IOError("\"$file\" is not available");
+ $imageinfo = getimagesize($file);
+ if($imageinfo === False)
+ throw new UnknownFileFormat();
+ if(!isset($imagetype_file_extensions[$imageinfo[2]]))
+ throw new UnknownFileFormat();
+ if(is_file(SITE_BASE_PATH . "/images/" . $this->file))
+ unlink(SITE_BASE_PATH . "/images/" . $this->file);
+ $new_fn = $this->id . "." . $imagetype_file_extensions[$imageinfo[2]];
+ if(!move_uploaded_file($file, SITE_BASE_PATH . "/images/" . $new_fn))
+ throw new IOError("Can not move file.");
+ $this->file = $new_fn;
+ $this->save();
+
+ /* make preview image */
+ switch($imageinfo[2])
+ {
+ case IMAGETYPE_GIF: $img = imagecreatefromgif (SITE_BASE_PATH . "/images/" . $new_fn); break;
+ case IMAGETYPE_JPEG: $img = imagecreatefromjpeg(SITE_BASE_PATH . "/images/" . $new_fn); break;
+ case IMAGETYPE_PNG: $img = imagecreatefrompng (SITE_BASE_PATH . "/images/" . $new_fn); break;
+ default: $img = imagecreatetruecolor(40, 40); imagefill($img, 1, 1, imagecolorallocate($img, 127, 127, 127)); break;
+ }
+ $w_orig = imagesx($img);
+ $h_orig = imagesy($img);
+ if(($w_orig > self::$pre_maxw) or ($h_orig > self::$pre_maxh))
+ {
+ $ratio = $w_orig / $h_orig;
+ if($ratio > 1)
+ {
+ $w_new = round(self::$pre_maxw);
+ $h_new = round(self::$pre_maxw / $ratio);
+ }
+ else
+ {
+ $h_new = round(self::$pre_maxh);
+ $w_new = round(self::$pre_maxh * $ratio);
+ }
+ $preview = imagecreatetruecolor($w_new, $h_new);
+ imagecopyresized($preview, $img, 0, 0, 0, 0, $w_new, $h_new, $w_orig, $h_orig);
+ imagepng($preview, SITE_BASE_PATH . "/images/previews/{$this->id}.png");
+ }
+ else
+ imagepng($img, SITE_BASE_PATH . "/images/previews/{$this->id}.png");
+ }
+
+ /*
+ * Function: save
+ */
+ public function save()
+ {
+ qdb("UPDATE `PREFIX_images` SET `name` = ?, `file` = ? WHERE `id` = ?",
+ $this->name, $this->file, $this->id);
+ }
+
+ /*
+ * Function: delete
+ */
+ public function delete()
+ {
+ qdb("DELETE FROM `PREFIX_images` WHERE `id` = ?", $this->id);
+ if(is_file(SITE_BASE_PATH . "/images/" . $this->file))
+ unlink(SITE_BASE_PATH . "/images/" . $this->file);
+ if(is_file(SITE_BASE_PATH . "/images/previews/{$this->id}.png"))
+ unlink(SITE_BASE_PATH . "/images/previews/{$this->id}.png");
+ }
}
/*
@@ -2282,243 +2282,243 @@ class RepositoryUnreachableOrInvalid extends Exception { }
*/
class Repository extends BySQLRowEnabled
{
- private $id;
- private $baseurl;
- private $name;
- private $description;
- private $lastrefresh;
-
- private $stream_ctx;
-
- /*
- * Variables: Public class variables
- * $packages - Array with all packages from this repository. A entry itself is an array: array(name, versioncounter, description)
- */
- public $packages;
-
- protected function __construct()
- {
- $this->stream_ctx = stream_context_create(array("http" => array("timeout" => 5)));
- }
-
- /*
- * Functions: Getters
- * get_id - Get internal ID.
- * get_baseurl - Get the baseurl of the repository.
- * get_name - Get repository name.
- * get_description - Get repository description.
- */
- public function get_id() { return $this->id; }
- public function get_baseurl() { return $this->baseurl; }
- public function get_name() { return $this->name; }
- public function get_description() { return $this->description; }
-
- /*
- * Constructor: create
- * Create a new repository entry from a base url.
- *
- * Parameters:
- * $baseurl - The baseurl of the repository.
- *
- * Throws:
- * Could throw a <RepositoryUnreachableOrInvalid> exception. In this case, nothing will be written to the database.
- */
- public static function create($baseurl)
- {
- $obj = new self();
-
- if(preg_match('/^(http[s]?:\\/\\/.*?)[\\/]?$/', $baseurl, $matches) == 0)
- throw new RepositoryUnreachableOrInvalid();
-
- $obj->baseurl = $matches[1];
- $obj->refresh(True);
-
- $tx = new Transaction();
- try
- {
- global $db_con;
-
- qdb("INSERT INTO `ratatoeskr_repositories` () VALUES ()");
- $obj->id = $db_con->lastInsertId();
- $obj->save();
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
-
- return $obj;
- }
-
- protected function populate_by_sqlrow($sqlrow)
- {
- $this->id = $sqlrow["id"];
- $this->name = $sqlrow["name"];
- $this->description = $sqlrow["description"];
- $this->baseurl = $sqlrow["baseurl"];
- $this->packages = unserialize(base64_decode($sqlrow["pkgcache"]));
- $this->lastrefresh = $sqlrow["lastrefresh"];
- }
-
- /*
- * Constructor: by_id
- * Get a repository entry by ID.
- *
- * Parameters:
- * $id - ID.
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_id($id)
- {
- $stmt = qdb("SELECT `id`, `name`, `description`, `baseurl`, `pkgcache`, `lastrefresh` FROM `PREFIX_repositories` WHERE `id` = ?", $id);
- $sqlrow = $stmt->fetch();
- if(!$sqlrow)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: all
- * Gets all available repositories.
- *
- * Returns:
- * Array of <Repository> objects.
- */
- public static function all()
- {
- $rv = array();
- $stmt = qdb("SELECT `id`, `name`, `description`, `baseurl`, `pkgcache`, `lastrefresh` FROM `PREFIX_repositories` WHERE 1");
- while($sqlrow = $stmt->fetch())
- $rv[] = self::by_sqlrow($sqlrow);
- return $rv;
- }
-
- private function save()
- {
- qdb("UPDATE `PREFIX_repositories` SET `baseurl` = ?, `name` = ?, `description` = ?, `pkgcache` = ?, `lastrefresh` = ? WHERE `id` = ?",
- $this->baseurl,
- $this->name,
- $this->description,
- base64_encode(serialize($this->packages)),
- $this->lastrefresh,
- $this->id);
- }
-
- /*
- * Function: delete
- * Delete the repository entry from the database.
- */
- public function delete()
- {
- qdb("DELETE FROM `PREFIX_repositories` WHERE `id` = ?", $this->id);
- }
-
- /*
- * Function: refresh
- * Refresh the package cache and the name and description.
- *
- * Parameters:
- * $force - Force a refresh, even if the data was already fetched in the last 6 hours (default: False).
- *
- * Throws:
- * <RepositoryUnreachableOrInvalid>
- */
- public function refresh($force = False)
- {
- if(($this->lastrefresh > (time() - (60*60*4))) and (!$force))
- return;
-
- $repometa = @file_get_contents($this->baseurl . "/repometa", False, $this->stream_ctx);
- if($repometa === FALSE)
- throw new RepositoryUnreachableOrInvalid();
- $repometa = @unserialize($repometa);
- if((!is_array($repometa)) or (!isset($repometa["name"])) or (!isset($repometa["description"])))
- throw new RepositoryUnreachableOrInvalid();
-
- $this->name = $repometa["name"];
- $this->description = $repometa["description"];
- $this->packages = @unserialize(@file_get_contents($this->baseurl . "/packagelist", False, $ctx));
-
- $this->lastrefresh = time();
-
- $this->save();
- }
-
- /*
- * Function: get_package_meta
- * Get metadata of a plugin package from this repository.
- *
- * Parameters:
- * $pkgname - The name of the package.
- *
- * Throws:
- * A <DoesNotExistError> Exception, if the package was not found.
- *
- * Returns:
- * A <PluginPackageMeta> object
- */
- public function get_package_meta($pkgname)
- {
- $found = False;
- foreach($this->packages as $p)
- {
- if($p[0] == $pkgname)
- {
- $found = True;
- break;
- }
- }
- if(!$found)
- throw new DoesNotExistError("Package not in package cache.");
-
- $pkgmeta = @unserialize(@file_get_contents($this->baseurl . "/packages/" . urlencode($pkgname) . "/meta", False, $this->stream_ctx));
-
- if(!($pkgmeta instanceof PluginPackageMeta))
- throw new DoesNotExistError();
-
- return $pkgmeta;
- }
-
- /*
- * Function: download_package
- * Download a package from the repository
- *
- * Parameters:
- * $pkgname - Name of the package.
- * $version - The version to download (defaults to "current").
- *
- * Throws:
- * * A <DoesNotExistError> Exception, if the package was not found.
- * * A <InvalidPackage> Exception, if the package was malformed.
- *
- * Returns:
- * A <PluginPackage> object.
- */
- public function download_package($pkgname, $version = "current")
- {
- $found = False;
- foreach($this->packages as $p)
- {
- if($p[0] == $pkgname)
- {
- $found = True;
- break;
- }
- }
- if(!$found)
- throw new DoesNotExistError("Package not in package cache.");
-
- $raw = @file_get_contents($this->baseurl . "/packages/" . urlencode($pkgname) . "/versions/" . urlencode($version), False, $this->stream_ctx);
- if($raw === False)
- throw new DoesNotExistError();
-
- return PluginPackage::load($raw);
- }
+ private $id;
+ private $baseurl;
+ private $name;
+ private $description;
+ private $lastrefresh;
+
+ private $stream_ctx;
+
+ /*
+ * Variables: Public class variables
+ * $packages - Array with all packages from this repository. A entry itself is an array: array(name, versioncounter, description)
+ */
+ public $packages;
+
+ protected function __construct()
+ {
+ $this->stream_ctx = stream_context_create(array("http" => array("timeout" => 5)));
+ }
+
+ /*
+ * Functions: Getters
+ * get_id - Get internal ID.
+ * get_baseurl - Get the baseurl of the repository.
+ * get_name - Get repository name.
+ * get_description - Get repository description.
+ */
+ public function get_id() { return $this->id; }
+ public function get_baseurl() { return $this->baseurl; }
+ public function get_name() { return $this->name; }
+ public function get_description() { return $this->description; }
+
+ /*
+ * Constructor: create
+ * Create a new repository entry from a base url.
+ *
+ * Parameters:
+ * $baseurl - The baseurl of the repository.
+ *
+ * Throws:
+ * Could throw a <RepositoryUnreachableOrInvalid> exception. In this case, nothing will be written to the database.
+ */
+ public static function create($baseurl)
+ {
+ $obj = new self();
+
+ if(preg_match('/^(http[s]?:\\/\\/.*?)[\\/]?$/', $baseurl, $matches) == 0)
+ throw new RepositoryUnreachableOrInvalid();
+
+ $obj->baseurl = $matches[1];
+ $obj->refresh(True);
+
+ $tx = new Transaction();
+ try
+ {
+ global $db_con;
+
+ qdb("INSERT INTO `ratatoeskr_repositories` () VALUES ()");
+ $obj->id = $db_con->lastInsertId();
+ $obj->save();
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+
+ return $obj;
+ }
+
+ protected function populate_by_sqlrow($sqlrow)
+ {
+ $this->id = $sqlrow["id"];
+ $this->name = $sqlrow["name"];
+ $this->description = $sqlrow["description"];
+ $this->baseurl = $sqlrow["baseurl"];
+ $this->packages = unserialize(base64_decode($sqlrow["pkgcache"]));
+ $this->lastrefresh = $sqlrow["lastrefresh"];
+ }
+
+ /*
+ * Constructor: by_id
+ * Get a repository entry by ID.
+ *
+ * Parameters:
+ * $id - ID.
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_id($id)
+ {
+ $stmt = qdb("SELECT `id`, `name`, `description`, `baseurl`, `pkgcache`, `lastrefresh` FROM `PREFIX_repositories` WHERE `id` = ?", $id);
+ $sqlrow = $stmt->fetch();
+ if(!$sqlrow)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: all
+ * Gets all available repositories.
+ *
+ * Returns:
+ * Array of <Repository> objects.
+ */
+ public static function all()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `id`, `name`, `description`, `baseurl`, `pkgcache`, `lastrefresh` FROM `PREFIX_repositories` WHERE 1");
+ while($sqlrow = $stmt->fetch())
+ $rv[] = self::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ private function save()
+ {
+ qdb("UPDATE `PREFIX_repositories` SET `baseurl` = ?, `name` = ?, `description` = ?, `pkgcache` = ?, `lastrefresh` = ? WHERE `id` = ?",
+ $this->baseurl,
+ $this->name,
+ $this->description,
+ base64_encode(serialize($this->packages)),
+ $this->lastrefresh,
+ $this->id);
+ }
+
+ /*
+ * Function: delete
+ * Delete the repository entry from the database.
+ */
+ public function delete()
+ {
+ qdb("DELETE FROM `PREFIX_repositories` WHERE `id` = ?", $this->id);
+ }
+
+ /*
+ * Function: refresh
+ * Refresh the package cache and the name and description.
+ *
+ * Parameters:
+ * $force - Force a refresh, even if the data was already fetched in the last 6 hours (default: False).
+ *
+ * Throws:
+ * <RepositoryUnreachableOrInvalid>
+ */
+ public function refresh($force = False)
+ {
+ if(($this->lastrefresh > (time() - (60*60*4))) and (!$force))
+ return;
+
+ $repometa = @file_get_contents($this->baseurl . "/repometa", False, $this->stream_ctx);
+ if($repometa === FALSE)
+ throw new RepositoryUnreachableOrInvalid();
+ $repometa = @unserialize($repometa);
+ if((!is_array($repometa)) or (!isset($repometa["name"])) or (!isset($repometa["description"])))
+ throw new RepositoryUnreachableOrInvalid();
+
+ $this->name = $repometa["name"];
+ $this->description = $repometa["description"];
+ $this->packages = @unserialize(@file_get_contents($this->baseurl . "/packagelist", False, $ctx));
+
+ $this->lastrefresh = time();
+
+ $this->save();
+ }
+
+ /*
+ * Function: get_package_meta
+ * Get metadata of a plugin package from this repository.
+ *
+ * Parameters:
+ * $pkgname - The name of the package.
+ *
+ * Throws:
+ * A <DoesNotExistError> Exception, if the package was not found.
+ *
+ * Returns:
+ * A <PluginPackageMeta> object
+ */
+ public function get_package_meta($pkgname)
+ {
+ $found = False;
+ foreach($this->packages as $p)
+ {
+ if($p[0] == $pkgname)
+ {
+ $found = True;
+ break;
+ }
+ }
+ if(!$found)
+ throw new DoesNotExistError("Package not in package cache.");
+
+ $pkgmeta = @unserialize(@file_get_contents($this->baseurl . "/packages/" . urlencode($pkgname) . "/meta", False, $this->stream_ctx));
+
+ if(!($pkgmeta instanceof PluginPackageMeta))
+ throw new DoesNotExistError();
+
+ return $pkgmeta;
+ }
+
+ /*
+ * Function: download_package
+ * Download a package from the repository
+ *
+ * Parameters:
+ * $pkgname - Name of the package.
+ * $version - The version to download (defaults to "current").
+ *
+ * Throws:
+ * * A <DoesNotExistError> Exception, if the package was not found.
+ * * A <InvalidPackage> Exception, if the package was malformed.
+ *
+ * Returns:
+ * A <PluginPackage> object.
+ */
+ public function download_package($pkgname, $version = "current")
+ {
+ $found = False;
+ foreach($this->packages as $p)
+ {
+ if($p[0] == $pkgname)
+ {
+ $found = True;
+ break;
+ }
+ }
+ if(!$found)
+ throw new DoesNotExistError("Package not in package cache.");
+
+ $raw = @file_get_contents($this->baseurl . "/packages/" . urlencode($pkgname) . "/versions/" . urlencode($version), False, $this->stream_ctx);
+ if($raw === False)
+ throw new DoesNotExistError();
+
+ return PluginPackage::load($raw);
+ }
}
/*
@@ -2527,508 +2527,508 @@ class Repository extends BySQLRowEnabled
*/
class Article extends BySQLRowEnabled
{
- private $id;
-
- private $section_id;
- private $section_obj;
-
- /*
- * Variables: Public class variables
- *
- * $urlname - URL name
- * $title - Title (an <Multilingual> object)
- * $text - The text (an <Multilingual> object)
- * $excerpt - Excerpt (an <Multilingual> object)
- * $meta - Keywords, comma seperated
- * $custom - Custom fields, is an array
- * $article_image - The article <Image>. If none: NULL
- * $status - One of the ARTICLE_STATUS_* constants
- * $timestamp - Timestamp
- * $allow_comments - Are comments allowed?
- */
- public $urlname;
- public $title;
- public $text;
- public $excerpt;
- public $meta;
- public $custom;
- public $article_image;
- public $status;
- public $timestamp;
- public $allow_comments;
-
- protected function __construct()
- {
- $this->section_obj = NULL;
- }
-
- protected function populate_by_sqlrow($sqlrow)
- {
- $this->id = $sqlrow["id"];
- $this->urlname = $sqlrow["urlname"];
- $this->title = Multilingual::by_id($sqlrow["title"]);
- $this->text = Multilingual::by_id($sqlrow["text"]);
- $this->excerpt = Multilingual::by_id($sqlrow["excerpt"]);
- $this->meta = $sqlrow["meta"];
- $this->custom = unserialize(base64_decode($sqlrow["custom"]));
- $this->article_image = $sqlrow["article_image"] == 0 ? NULL : Image::by_id($sqlrow["article_image"]);
- $this->status = $sqlrow["status"];
- $this->section_id = $sqlrow["section"];
- $this->timestamp = $sqlrow["timestamp"];
- $this->allow_comments = $sqlrow["allow_comments"] == 1;
- }
-
- /*
- * Function: get_id
- */
- public function get_id() { return $this->id; }
-
- /*
- * Function: test_urlname
- * Test, if a urlname is a valid urlname.
- *
- * Parameters:
- * $urlname - Urlname to test
- *
- * Returns:
- * True, if the urlname is valid, False otherwise.
- */
- public static function test_urlname($urlname)
- {
- return (bool) preg_match('/^[a-zA-Z0-9-_]+$/', $urlname);
- }
-
- /*
- * Function: test_status
- * Test, if a status is valid.
- *
- * Parameters:
- * $status - Status value to test.
- *
- * Returns:
- * True, if the status is a valid status value, False otherwise.
- */
- public static function test_status($status)
- {
- return is_numeric($status) and ($status >= 0) and ($status <= 3);
- }
-
- /*
- * Constructor: create
- * Create a new Article object.
- *
- * Parameters:
- * urlname - A unique URL name
- *
- * Throws:
- * <AlreadyExistsError>, <InvalidDataError>
- */
- public static function create($urlname)
- {
- global $ratatoeskr_settings;
- global $db_con;
-
- if(!self::test_urlname($urlname))
- throw new InvalidDataError("invalid_urlname");
-
- try
- {
- self::by_urlname($urlname);
- }
- catch(DoesNotExistError $e)
- {
- $obj = new self();
- $obj->urlname = $urlname;
- $obj->title = Multilingual::create();
- $obj->text = Multilingual::create();
- $obj->excerpt = Multilingual::create();
- $obj->meta = "";
- $obj->custom = array();
- $obj->article_image = NULL;
- $obj->status = ARTICLE_STATUS_HIDDEN;
- $obj->section_id = $ratatoeskr_settings["default_section"];
- $obj->timestamp = time();
- $obj->allow_comments = $ratatoeskr_settings["allow_comments_default"];
-
- qdb("INSERT INTO `PREFIX_articles` (`urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments`) VALUES ('', ?, ?, ?, '', ?, 0, ?, ?, ?, ?)",
- $obj->title->get_id(),
- $obj->text->get_id(),
- $obj->excerpt->get_id(),
- base64_encode(serialize($obj->custom)),
- $obj->status,
- $obj->section_id,
- $obj->timestamp,
- $obj->allow_comments ? 1 : 0);
- $obj->id = $db_con->lastInsertId();
- return $obj;
- }
-
- throw new AlreadyExistsError();
- }
-
- /*
- * Constructor: by_id
- * Get by ID.
- *
- * Parameters:
- * $id - The ID.
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_id($id)
- {
- $stmt = qdb("SELECT `id`, `urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments` FROM `PREFIX_articles` WHERE `id` = ?", $id);
- $sqlrow = $stmt->fetch();
- if($sqlrow === False)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: by_urlname
- * Get by urlname
- *
- * Parameters:
- * $urlname - The urlname
- *
- * Throws:
- * <DoesNotExistError>
- */
- public static function by_urlname($urlname)
- {
- $stmt = qdb("SELECT `id`, `urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments` FROM `PREFIX_articles` WHERE `urlname` = ?", $urlname);
- $sqlrow = $stmt->fetch();
- if($sqlrow === False)
- throw new DoesNotExistError();
-
- return self::by_sqlrow($sqlrow);
- }
-
- /*
- * Constructor: by_multi
- * Get Articles by multiple criterias
- *
- * Parameters:
- * $criterias - Array that can have these keys: id (int) , urlname (string), section (<Section> object), status (int), onlyvisible, langavail(string), tag (<Tag> object)
- * $sortby - Sort by this field (id, urlname, timestamp or title)
- * $sortdir - Sorting directory (ASC or DESC)
- * $count - How many entries (NULL for unlimited)
- * $offset - How many entries should be skipped (NULL for none)
- * $perpage - How many entries per page (NULL for no paging)
- * $page - Page number (starting at 1, NULL for no paging)
- * &$maxpage - Number of pages will be written here, if paging is activated.
- *
- * Returns:
- * Array of Article objects
- */
- public static function by_multi($criterias, $sortby, $sortdir, $count, $offset, $perpage, $page, &$maxpage)
- {
- $subqueries = array();
- $subparams = array();
- foreach($criterias as $k => $v)
- {
- switch($k)
- {
- case "id":
- $subqueries[] = "`a`.`id` = ?";
- $subparams[] = $v;
- break;
- case "urlname":
- $subqueries[] = "`a`.`urlname` = ?";
- $subparams[] = $v;
- break;
- case "section":
- $subqueries[] = "`a`.`section` = ?";
- $subparams[] = $v->get_id();
- break;
- case "status":
- $subqueries[] = "`a`.`status` = ?";
- $subparams[] = $v;
- break;
- case "onlyvisible":
- $subqueries[] = "`a`.`status` != 0";
- break;
- case "langavail":
- $subqueries[] = "`b`.`language` = ?";
- $subparams[] = $v;
- break;
- case "tag":
- $subqueries[] = "`c`.`tag` = ?";
- $subparams[] = $v->get_id();
- break;
- default: continue;
- }
- }
-
- if(($sortdir != "ASC") and ($sortdir != "DESC"))
- $sortdir = "ASC";
- $sorting = "";
- switch($sortby)
- {
- case "id": $sorting = "ORDER BY `a`.`id` $sortdir"; break;
- case "urlname": $sorting = "ORDER BY `a`.`urlname` $sortdir"; break;
- case "timestamp": $sorting = "ORDER BY `a`.`timestamp` $sortdir"; break;
- case "title": $sorting = "ORDER BY `b`.`text` $sortdir"; break;
- }
-
- $stmt = prep_stmt("SELECT `a`.`id` AS `id`, `a`.`urlname` AS `urlname`, `a`.`title` AS `title`, `a`.`text` AS `text`, `a`.`excerpt` AS `excerpt`, `a`.`meta` AS `meta`, `a`.`custom` AS `custom`, `a`.`article_image` AS `article_image`, `a`.`status` AS `status`, `a`.`section` AS `section`, `a`.`timestamp` AS `timestamp`, `a`.`allow_comments` AS `allow_comments` FROM `PREFIX_articles` `a`
+ private $id;
+
+ private $section_id;
+ private $section_obj;
+
+ /*
+ * Variables: Public class variables
+ *
+ * $urlname - URL name
+ * $title - Title (an <Multilingual> object)
+ * $text - The text (an <Multilingual> object)
+ * $excerpt - Excerpt (an <Multilingual> object)
+ * $meta - Keywords, comma seperated
+ * $custom - Custom fields, is an array
+ * $article_image - The article <Image>. If none: NULL
+ * $status - One of the ARTICLE_STATUS_* constants
+ * $timestamp - Timestamp
+ * $allow_comments - Are comments allowed?
+ */
+ public $urlname;
+ public $title;
+ public $text;
+ public $excerpt;
+ public $meta;
+ public $custom;
+ public $article_image;
+ public $status;
+ public $timestamp;
+ public $allow_comments;
+
+ protected function __construct()
+ {
+ $this->section_obj = NULL;
+ }
+
+ protected function populate_by_sqlrow($sqlrow)
+ {
+ $this->id = $sqlrow["id"];
+ $this->urlname = $sqlrow["urlname"];
+ $this->title = Multilingual::by_id($sqlrow["title"]);
+ $this->text = Multilingual::by_id($sqlrow["text"]);
+ $this->excerpt = Multilingual::by_id($sqlrow["excerpt"]);
+ $this->meta = $sqlrow["meta"];
+ $this->custom = unserialize(base64_decode($sqlrow["custom"]));
+ $this->article_image = $sqlrow["article_image"] == 0 ? NULL : Image::by_id($sqlrow["article_image"]);
+ $this->status = $sqlrow["status"];
+ $this->section_id = $sqlrow["section"];
+ $this->timestamp = $sqlrow["timestamp"];
+ $this->allow_comments = $sqlrow["allow_comments"] == 1;
+ }
+
+ /*
+ * Function: get_id
+ */
+ public function get_id() { return $this->id; }
+
+ /*
+ * Function: test_urlname
+ * Test, if a urlname is a valid urlname.
+ *
+ * Parameters:
+ * $urlname - Urlname to test
+ *
+ * Returns:
+ * True, if the urlname is valid, False otherwise.
+ */
+ public static function test_urlname($urlname)
+ {
+ return (bool) preg_match('/^[a-zA-Z0-9-_]+$/', $urlname);
+ }
+
+ /*
+ * Function: test_status
+ * Test, if a status is valid.
+ *
+ * Parameters:
+ * $status - Status value to test.
+ *
+ * Returns:
+ * True, if the status is a valid status value, False otherwise.
+ */
+ public static function test_status($status)
+ {
+ return is_numeric($status) and ($status >= 0) and ($status <= 3);
+ }
+
+ /*
+ * Constructor: create
+ * Create a new Article object.
+ *
+ * Parameters:
+ * urlname - A unique URL name
+ *
+ * Throws:
+ * <AlreadyExistsError>, <InvalidDataError>
+ */
+ public static function create($urlname)
+ {
+ global $ratatoeskr_settings;
+ global $db_con;
+
+ if(!self::test_urlname($urlname))
+ throw new InvalidDataError("invalid_urlname");
+
+ try
+ {
+ self::by_urlname($urlname);
+ }
+ catch(DoesNotExistError $e)
+ {
+ $obj = new self();
+ $obj->urlname = $urlname;
+ $obj->title = Multilingual::create();
+ $obj->text = Multilingual::create();
+ $obj->excerpt = Multilingual::create();
+ $obj->meta = "";
+ $obj->custom = array();
+ $obj->article_image = NULL;
+ $obj->status = ARTICLE_STATUS_HIDDEN;
+ $obj->section_id = $ratatoeskr_settings["default_section"];
+ $obj->timestamp = time();
+ $obj->allow_comments = $ratatoeskr_settings["allow_comments_default"];
+
+ qdb("INSERT INTO `PREFIX_articles` (`urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments`) VALUES ('', ?, ?, ?, '', ?, 0, ?, ?, ?, ?)",
+ $obj->title->get_id(),
+ $obj->text->get_id(),
+ $obj->excerpt->get_id(),
+ base64_encode(serialize($obj->custom)),
+ $obj->status,
+ $obj->section_id,
+ $obj->timestamp,
+ $obj->allow_comments ? 1 : 0);
+ $obj->id = $db_con->lastInsertId();
+ return $obj;
+ }
+
+ throw new AlreadyExistsError();
+ }
+
+ /*
+ * Constructor: by_id
+ * Get by ID.
+ *
+ * Parameters:
+ * $id - The ID.
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_id($id)
+ {
+ $stmt = qdb("SELECT `id`, `urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments` FROM `PREFIX_articles` WHERE `id` = ?", $id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow === False)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: by_urlname
+ * Get by urlname
+ *
+ * Parameters:
+ * $urlname - The urlname
+ *
+ * Throws:
+ * <DoesNotExistError>
+ */
+ public static function by_urlname($urlname)
+ {
+ $stmt = qdb("SELECT `id`, `urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments` FROM `PREFIX_articles` WHERE `urlname` = ?", $urlname);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow === False)
+ throw new DoesNotExistError();
+
+ return self::by_sqlrow($sqlrow);
+ }
+
+ /*
+ * Constructor: by_multi
+ * Get Articles by multiple criterias
+ *
+ * Parameters:
+ * $criterias - Array that can have these keys: id (int) , urlname (string), section (<Section> object), status (int), onlyvisible, langavail(string), tag (<Tag> object)
+ * $sortby - Sort by this field (id, urlname, timestamp or title)
+ * $sortdir - Sorting directory (ASC or DESC)
+ * $count - How many entries (NULL for unlimited)
+ * $offset - How many entries should be skipped (NULL for none)
+ * $perpage - How many entries per page (NULL for no paging)
+ * $page - Page number (starting at 1, NULL for no paging)
+ * &$maxpage - Number of pages will be written here, if paging is activated.
+ *
+ * Returns:
+ * Array of Article objects
+ */
+ public static function by_multi($criterias, $sortby, $sortdir, $count, $offset, $perpage, $page, &$maxpage)
+ {
+ $subqueries = array();
+ $subparams = array();
+ foreach($criterias as $k => $v)
+ {
+ switch($k)
+ {
+ case "id":
+ $subqueries[] = "`a`.`id` = ?";
+ $subparams[] = $v;
+ break;
+ case "urlname":
+ $subqueries[] = "`a`.`urlname` = ?";
+ $subparams[] = $v;
+ break;
+ case "section":
+ $subqueries[] = "`a`.`section` = ?";
+ $subparams[] = $v->get_id();
+ break;
+ case "status":
+ $subqueries[] = "`a`.`status` = ?";
+ $subparams[] = $v;
+ break;
+ case "onlyvisible":
+ $subqueries[] = "`a`.`status` != 0";
+ break;
+ case "langavail":
+ $subqueries[] = "`b`.`language` = ?";
+ $subparams[] = $v;
+ break;
+ case "tag":
+ $subqueries[] = "`c`.`tag` = ?";
+ $subparams[] = $v->get_id();
+ break;
+ default: continue;
+ }
+ }
+
+ if(($sortdir != "ASC") and ($sortdir != "DESC"))
+ $sortdir = "ASC";
+ $sorting = "";
+ switch($sortby)
+ {
+ case "id": $sorting = "ORDER BY `a`.`id` $sortdir"; break;
+ case "urlname": $sorting = "ORDER BY `a`.`urlname` $sortdir"; break;
+ case "timestamp": $sorting = "ORDER BY `a`.`timestamp` $sortdir"; break;
+ case "title": $sorting = "ORDER BY `b`.`text` $sortdir"; break;
+ }
+
+ $stmt = prep_stmt("SELECT `a`.`id` AS `id`, `a`.`urlname` AS `urlname`, `a`.`title` AS `title`, `a`.`text` AS `text`, `a`.`excerpt` AS `excerpt`, `a`.`meta` AS `meta`, `a`.`custom` AS `custom`, `a`.`article_image` AS `article_image`, `a`.`status` AS `status`, `a`.`section` AS `section`, `a`.`timestamp` AS `timestamp`, `a`.`allow_comments` AS `allow_comments` FROM `PREFIX_articles` `a`
INNER JOIN `PREFIX_translations` `b` ON `a`.`title` = `b`.`multilingual`
LEFT OUTER JOIN `PREFIX_article_tag_relations` `c` ON `a`.`id` = `c`.`article`
WHERE " . implode(" AND ", $subqueries) . " $sorting");
-
- $stmt->execute($subparams);
-
- $rows = array();
- $fetched_ids = array();
- while($sqlrow = $stmt->fetch())
- {
- if(!in_array($sqlrow["id"], $fetched_ids))
- {
- $rows[] = $sqlrow;
- $fetched_ids[] = $sqlrow["id"];
- }
- }
-
- if($count !== NULL)
- $rows = array_slice($rows, 0, $count);
- if($offset !== NULL)
- $rows = array_slice($rows, $offset);
- if(($perpage !== NULL) and ($page !== NULL))
- {
- $maxpage = ceil(count($rows) / $perpage);
- $rows = array_slice($rows, $perpage * ($page - 1), $perpage);
- }
-
- $rv = array();
- foreach($rows as $r)
- $rv[] = self::by_sqlrow($r);
- return $rv;
- }
-
- /*
- * Constructor: all
- * Get all articles
- *
- * Returns:
- * Array of Article objects
- */
- public static function all()
- {
- $rv = array();
- $stmt = qdb("SELECT `id`, `urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments` FROM `PREFIX_articles` WHERE 1");
- while($sqlrow = $stmt->fetch())
- $rv[] = self::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * Function: get_comments
- * Getting comments for this article.
- *
- * Parameters:
- * $limit_lang - Get only comments in a language (empty string for no limitation, this is the default).
- * $only_visible - Do you only want the visible comments? (Default: False)
- *
- * Returns:
- * Array of <Comment> objects.
- */
- public function get_comments($limit_lang = "", $only_visible = False)
- {
- $rv = array();
-
- $conditions = array("`article` = ?");
- $arguments = array($this->id);
- if($limit_lang != "")
- {
- $conditions[] = "`language` = ?";
- $arguments[] = $limit_lang;
- }
- if($only_visible)
- $conditions[] = "`visible` = 1";
-
- $stmt = prep_stmt("SELECT `id`, `article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin` FROM `PREFIX_comments` WHERE " . implode(" AND ", $conditions));
- $stmt->execute($arguments);
- while($sqlrow = $stmt->fetch())
- $rv[] = Comment::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * Function: get_tags
- * Get all Tags of this Article.
- *
- * Returns:
- * Array of <Tag> objects.
- */
- public function get_tags()
- {
- $rv = array();
- $stmt = qdb("SELECT `a`.`id` AS `id`, `a`.`name` AS `name`, `a`.`title` AS `title` FROM `PREFIX_tags` `a` INNER JOIN `PREFIX_article_tag_relations` `b` ON `a`.`id` = `b`.`tag` WHERE `b`.`article` = ?", $this->id);
- while($sqlrow = $stmt->fetch())
- $rv[] = Tag::by_sqlrow($sqlrow);
- return $rv;
- }
-
- /*
- * Function: set_tags
- * Set the Tags that should be associated with this Article.
- *
- * Parameters:
- * $tags - Array of <Tag> objects.
- */
- public function set_tags($tags)
- {
- $tx = new Transaction();
- try
- {
- foreach($tags as $tag)
- $tag->save();
-
- qdb("DELETE FROM `PREFIX_article_tag_relations` WHERE `article`= ?", $this->id);
-
- $articleid = $this->id;
- if(!empty($tags))
- {
- $stmt = prep_stmt(
- "INSERT INTO `PREFIX_article_tag_relations` (`article`, `tag`) VALUES " .
- implode(",", array_fill(0, count($tags), "(?,?)"))
- );
- $args = array();
- foreach($tags as $tag)
- {
- $args[] = $articleid;
- $args[] = $tag->get_id();
- }
- $stmt->execute($args);
- }
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /*
- * Function: get_section
- * Get the section of this article.
- *
- * Returns:
- * A <Section> object.
- */
- public function get_section()
- {
- if($this->section_obj === NULL)
- $this->section_obj = Section::by_id($this->section_id);
- return $this->section_obj;
- }
-
- /*
- * Function: set_section
- * Set the section of this article.
- *
- * Parameters:
- * $section - A <Section> object.
- */
- public function set_section($section)
- {
- $this->section_id = $section->get_id();
- $this->section_obj = $section;
- }
-
- /*
- * Function: get_extradata
- * Get the extradata for this article and the given plugin.
- *
- * Parameters:
- * $plugin_id - The ID of the plugin.
- *
- * Returns:
- * An <ArticleExtradata> object.
- */
- public function get_extradata($plugin_id)
- {
- return new ArticleExtradata($this->id, $plugin_id);
- }
-
- /*
- * Function: save
- *
- * Throws:
- * <AlreadyExistsError>, <InvalidDataError>
- */
- public function save()
- {
- if(!self::test_urlname($this->urlname))
- throw new InvalidDataError("invalid_urlname");
-
- if(!self::test_status($this->status))
- throw new InvalidDataError("invalid_article_status");
-
- $tx = new Transaction();
- try
- {
- $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_articles` WHERE `urlname` = ? AND `id` != ?", $this->urlname, $this->id);
- $sqlrow = $stmt->fetch();
- if($sqlrow["n"] > 0)
- throw new AlreadyExistsError();
-
- $this->title->save();
- $this->text->save();
- $this->excerpt->save();
-
- qdb("UPDATE `PREFIX_articles` SET `urlname` = ?, `title` = ?, `text` = ?, `excerpt` = ?, `meta` = ?, `custom` = ?, `article_image` = ?, `status` = ?, `section` = ?, `timestamp` = ?, `allow_comments` = ? WHERE `id` = ?",
- $this->urlname,
- $this->title->get_id(),
- $this->text->get_id(),
- $this->excerpt->get_id(),
- $this->meta,
- base64_encode(serialize($this->custom)),
- $this->article_image === NULL ? 0 : $this->article_image->get_id(),
- $this->status,
- $this->section_id,
- $this->timestamp,
- $this->allow_comments ? 1 : 0,
- $this->id
- );
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
-
- /*
- * Function: delete
- */
- public function delete()
- {
- $tx = new Transaction();
- try
- {
- $this->title->delete();
- $this->text->delete();
- $this->excerpt->delete();
-
- foreach($this->get_comments() as $comment)
- $comment->delete();
-
- qdb("DELETE FROM `PREFIX_article_tag_relations` WHERE `article` = ?", $this->id);
- qdb("DELETE FROM `PREFIX_article_extradata` WHERE `article` = ?", $this->id);
- qdb("DELETE FROM `PREFIX_articles` WHERE `id` = ?", $this->id);
- $tx->commit();
- }
- catch(Exception $e)
- {
- $tx->rollback();
- throw $e;
- }
- }
+
+ $stmt->execute($subparams);
+
+ $rows = array();
+ $fetched_ids = array();
+ while($sqlrow = $stmt->fetch())
+ {
+ if(!in_array($sqlrow["id"], $fetched_ids))
+ {
+ $rows[] = $sqlrow;
+ $fetched_ids[] = $sqlrow["id"];
+ }
+ }
+
+ if($count !== NULL)
+ $rows = array_slice($rows, 0, $count);
+ if($offset !== NULL)
+ $rows = array_slice($rows, $offset);
+ if(($perpage !== NULL) and ($page !== NULL))
+ {
+ $maxpage = ceil(count($rows) / $perpage);
+ $rows = array_slice($rows, $perpage * ($page - 1), $perpage);
+ }
+
+ $rv = array();
+ foreach($rows as $r)
+ $rv[] = self::by_sqlrow($r);
+ return $rv;
+ }
+
+ /*
+ * Constructor: all
+ * Get all articles
+ *
+ * Returns:
+ * Array of Article objects
+ */
+ public static function all()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `id`, `urlname`, `title`, `text`, `excerpt`, `meta`, `custom`, `article_image`, `status`, `section`, `timestamp`, `allow_comments` FROM `PREFIX_articles` WHERE 1");
+ while($sqlrow = $stmt->fetch())
+ $rv[] = self::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * Function: get_comments
+ * Getting comments for this article.
+ *
+ * Parameters:
+ * $limit_lang - Get only comments in a language (empty string for no limitation, this is the default).
+ * $only_visible - Do you only want the visible comments? (Default: False)
+ *
+ * Returns:
+ * Array of <Comment> objects.
+ */
+ public function get_comments($limit_lang = "", $only_visible = False)
+ {
+ $rv = array();
+
+ $conditions = array("`article` = ?");
+ $arguments = array($this->id);
+ if($limit_lang != "")
+ {
+ $conditions[] = "`language` = ?";
+ $arguments[] = $limit_lang;
+ }
+ if($only_visible)
+ $conditions[] = "`visible` = 1";
+
+ $stmt = prep_stmt("SELECT `id`, `article`, `language`, `author_name`, `author_mail`, `text`, `timestamp`, `visible`, `read_by_admin` FROM `PREFIX_comments` WHERE " . implode(" AND ", $conditions));
+ $stmt->execute($arguments);
+ while($sqlrow = $stmt->fetch())
+ $rv[] = Comment::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * Function: get_tags
+ * Get all Tags of this Article.
+ *
+ * Returns:
+ * Array of <Tag> objects.
+ */
+ public function get_tags()
+ {
+ $rv = array();
+ $stmt = qdb("SELECT `a`.`id` AS `id`, `a`.`name` AS `name`, `a`.`title` AS `title` FROM `PREFIX_tags` `a` INNER JOIN `PREFIX_article_tag_relations` `b` ON `a`.`id` = `b`.`tag` WHERE `b`.`article` = ?", $this->id);
+ while($sqlrow = $stmt->fetch())
+ $rv[] = Tag::by_sqlrow($sqlrow);
+ return $rv;
+ }
+
+ /*
+ * Function: set_tags
+ * Set the Tags that should be associated with this Article.
+ *
+ * Parameters:
+ * $tags - Array of <Tag> objects.
+ */
+ public function set_tags($tags)
+ {
+ $tx = new Transaction();
+ try
+ {
+ foreach($tags as $tag)
+ $tag->save();
+
+ qdb("DELETE FROM `PREFIX_article_tag_relations` WHERE `article`= ?", $this->id);
+
+ $articleid = $this->id;
+ if(!empty($tags))
+ {
+ $stmt = prep_stmt(
+ "INSERT INTO `PREFIX_article_tag_relations` (`article`, `tag`) VALUES " .
+ implode(",", array_fill(0, count($tags), "(?,?)"))
+ );
+ $args = array();
+ foreach($tags as $tag)
+ {
+ $args[] = $articleid;
+ $args[] = $tag->get_id();
+ }
+ $stmt->execute($args);
+ }
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /*
+ * Function: get_section
+ * Get the section of this article.
+ *
+ * Returns:
+ * A <Section> object.
+ */
+ public function get_section()
+ {
+ if($this->section_obj === NULL)
+ $this->section_obj = Section::by_id($this->section_id);
+ return $this->section_obj;
+ }
+
+ /*
+ * Function: set_section
+ * Set the section of this article.
+ *
+ * Parameters:
+ * $section - A <Section> object.
+ */
+ public function set_section($section)
+ {
+ $this->section_id = $section->get_id();
+ $this->section_obj = $section;
+ }
+
+ /*
+ * Function: get_extradata
+ * Get the extradata for this article and the given plugin.
+ *
+ * Parameters:
+ * $plugin_id - The ID of the plugin.
+ *
+ * Returns:
+ * An <ArticleExtradata> object.
+ */
+ public function get_extradata($plugin_id)
+ {
+ return new ArticleExtradata($this->id, $plugin_id);
+ }
+
+ /*
+ * Function: save
+ *
+ * Throws:
+ * <AlreadyExistsError>, <InvalidDataError>
+ */
+ public function save()
+ {
+ if(!self::test_urlname($this->urlname))
+ throw new InvalidDataError("invalid_urlname");
+
+ if(!self::test_status($this->status))
+ throw new InvalidDataError("invalid_article_status");
+
+ $tx = new Transaction();
+ try
+ {
+ $stmt = qdb("SELECT COUNT(*) AS `n` FROM `PREFIX_articles` WHERE `urlname` = ? AND `id` != ?", $this->urlname, $this->id);
+ $sqlrow = $stmt->fetch();
+ if($sqlrow["n"] > 0)
+ throw new AlreadyExistsError();
+
+ $this->title->save();
+ $this->text->save();
+ $this->excerpt->save();
+
+ qdb("UPDATE `PREFIX_articles` SET `urlname` = ?, `title` = ?, `text` = ?, `excerpt` = ?, `meta` = ?, `custom` = ?, `article_image` = ?, `status` = ?, `section` = ?, `timestamp` = ?, `allow_comments` = ? WHERE `id` = ?",
+ $this->urlname,
+ $this->title->get_id(),
+ $this->text->get_id(),
+ $this->excerpt->get_id(),
+ $this->meta,
+ base64_encode(serialize($this->custom)),
+ $this->article_image === NULL ? 0 : $this->article_image->get_id(),
+ $this->status,
+ $this->section_id,
+ $this->timestamp,
+ $this->allow_comments ? 1 : 0,
+ $this->id
+ );
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
+
+ /*
+ * Function: delete
+ */
+ public function delete()
+ {
+ $tx = new Transaction();
+ try
+ {
+ $this->title->delete();
+ $this->text->delete();
+ $this->excerpt->delete();
+
+ foreach($this->get_comments() as $comment)
+ $comment->delete();
+
+ qdb("DELETE FROM `PREFIX_article_tag_relations` WHERE `article` = ?", $this->id);
+ qdb("DELETE FROM `PREFIX_article_extradata` WHERE `article` = ?", $this->id);
+ qdb("DELETE FROM `PREFIX_articles` WHERE `id` = ?", $this->id);
+ $tx->commit();
+ }
+ catch(Exception $e)
+ {
+ $tx->rollback();
+ throw $e;
+ }
+ }
}
/*
@@ -3036,46 +3036,46 @@ WHERE " . implode(" AND ", $subqueries) . " $sorting");
* A Key-Value-Storage assigned to Articles for plugins to store additional data.
* Can be accessed like an array.
* Keys are strings and Values can be everything serialize() can process.
- *
+ *
* Extends the abstract <KVStorage> class.
*/
class ArticleExtradata extends KVStorage
{
- /*
- * Constructor: __construct
- *
- * Parameters:
- * $article_id - The ID of the Article.
- * $plugin_id - The ID of the Plugin.
- */
- public function __construct($article_id, $plugin_id)
- {
- $this->init("PREFIX_article_extradata", array(
- "article" => $article_id,
- "plugin" => $plugin_id,
- ));
- }
+ /*
+ * Constructor: __construct
+ *
+ * Parameters:
+ * $article_id - The ID of the Article.
+ * $plugin_id - The ID of the Plugin.
+ */
+ public function __construct($article_id, $plugin_id)
+ {
+ $this->init("PREFIX_article_extradata", array(
+ "article" => $article_id,
+ "plugin" => $plugin_id,
+ ));
+ }
}
/*
* Function: dbversion
* Get the version of the database structure currently used.
- *
+ *
* Returns:
- * The numerical version of the current database structure.
+ * The numerical version of the current database structure.
*/
function dbversion()
{
- /* Is the meta table present? If no, the version is 0. */
- $stmt = qdb("SELECT COUNT(*) FROM `information_schema`.`tables` WHERE `table_schema` = ? AND `table_name` = ?",
- $config["mysql"]["db"], sub_prefix("PREFIX_meta"));
- list($n) = $stmt->fetch();
- if($n == 0)
- return 0;
-
- $stmt = qdb("SELECT `value` FROM `PREFIX_meta` WHERE `key` = 'dbversion'");
- $sqlrow = $stmt->fetch();
- return unserialize(base64_decode($sqlrow["value"]));
+ /* Is the meta table present? If no, the version is 0. */
+ $stmt = qdb("SELECT COUNT(*) FROM `information_schema`.`tables` WHERE `table_schema` = ? AND `table_name` = ?",
+ $config["mysql"]["db"], sub_prefix("PREFIX_meta"));
+ list($n) = $stmt->fetch();
+ if($n == 0)
+ return 0;
+
+ $stmt = qdb("SELECT `value` FROM `PREFIX_meta` WHERE `key` = 'dbversion'");
+ $sqlrow = $stmt->fetch();
+ return unserialize(base64_decode($sqlrow["value"]));
}
/*
@@ -3084,12 +3084,12 @@ function dbversion()
*/
function clean_database()
{
- global $ratatoeskr_settings;
- if((!isset($ratatoeskr_settings["last_db_cleanup"])) or ($ratatoeskr_settings["last_db_cleanup"] < (time() - 86400)))
- {
- Plugin::clean_db();
- $ratatoeskr_settings["last_db_cleanup"] = time();
- }
+ global $ratatoeskr_settings;
+ if((!isset($ratatoeskr_settings["last_db_cleanup"])) or ($ratatoeskr_settings["last_db_cleanup"] < (time() - 86400)))
+ {
+ Plugin::clean_db();
+ $ratatoeskr_settings["last_db_cleanup"] = time();
+ }
}
?>
diff --git a/ratatoeskr/sys/plugin_api.php b/ratatoeskr/sys/plugin_api.php
index cd3e42b..45ce957 100644
--- a/ratatoeskr/sys/plugin_api.php
+++ b/ratatoeskr/sys/plugin_api.php
@@ -2,7 +2,7 @@
/*
* File: ratatoeskr/sys/plugin_api.php
* Plugin API contains the plugin base class and other interfaces to Ratatöskr.
- *
+ *
* License:
* This file is part of Ratatöskr.
* Ratatöskr is licensed unter the MIT / X11 License.
@@ -30,15 +30,15 @@ $url_handlers = array(); /* master URL handler */
/*
* Function: register_url_handler
* Register an URL handler. See <ratatoeskr/sys/urlprocess.php> for more details.
- *
+ *
* Parameters:
- * $name - The name of the new URL
- * $callback - The Function to be called (see <url_process>).
+ * $name - The name of the new URL
+ * $callback - The Function to be called (see <url_process>).
*/
function register_url_handler($name, $callback)
{
- global $url_handlers;
- $url_handlers[$name] = $callback;
+ global $url_handlers;
+ $url_handlers[$name] = $callback;
}
$pluginpages_handlers = array();
@@ -51,231 +51,231 @@ $articleeditor_plugins = array();
*/
abstract class RatatoeskrPlugin
{
- private $id;
-
- /*
- * Variables: Protected variables
- *
- * $kvstorage - The Key-Value-Storage for the Plugin.
- * $ste - Access to the global STECore object.
- * $rel_path_to_root - Relative URL to the root of the page.
- */
- protected $kvstorage;
- protected $ste;
- protected $rel_path_to_root;
-
- /*
- * Constructor: __construct
- * Performing some neccessary initialisation stuff.
- * If you are overwriting this function, you *really* should call parent::__construct!
- *
- * Parameters:
- * $id - The ID of the plugin (not the name).
- */
- public function __construct($id)
- {
- global $ste, $rel_path_to_root;
- $this->id = $id;
-
- $this->kvstorage = new PluginKVStorage($id);
- $this->ste = $ste;
- $this->rel_path_to_root = $rel_path_to_root;
- }
-
- /*
- * Functions: Some getters
- *
- * get_id - get the Plugin-ID
- * get_custompriv_dir - Get path to the custompriv directory of your plugin.
- * get_custompub_dir - Get path to the custompub directory of your plugin.
- * get_custompub_url - Get URL (can be accessed from the web) to the custompub directory of your plugin.
- * get_template_dir - Get path to your template directory to be used with STE.
- */
- final public function get_id() { return $this->id; }
- final protected function get_custompriv_dir() { return SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/private/" . $this->id; }
- final protected function get_custompub_dir() { return SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/public/" . $this->id; }
- final protected function get_custompub_url() { return $GLOBALS["rel_path_to_root"] . "/ratatoeskr/plugin_extradata/public/" . $this->id; }
- final protected function get_template_dir() { return "/plugintemplates/" . $this->id; }
-
- /*
- * Function: register_url_handler
- * Register a URL handler
- *
- * Parameters:
- * $name - Name of URL
- * $fx - The function.
- */
- final protected function register_url_handler($name, $fx)
- {
- register_url_handler($name, $fx);
- }
-
- /*
- * Function: register_ste_tag
- * Register a custom STE tag.
- *
- * Parameters:
- * $name - Name of your new STE tag.
- * $fx - Function to register with this tag.
- */
- final protected function register_ste_tag($name, $fx)
- {
- $this->ste->register_tag($name, $fx);
- }
-
- /*
- * Function: register_textprocessor
- * Register a textprocessor.
- *
- * Parameters:
- * $name - The name of the textprocessor-
- * $fx - Function to register (function($input), returns HTML).
- * $visible_in_backend - Should this textprocessor be visible in the backend? Defaults to True.
- */
- final protected function register_textprocessor($name, $fx, $visible_in_backend=True)
- {
- textprocessor_register($name, $fx, $visible_in_backend);
- }
-
- /*
- * Function: register_comment_validator
- * Register a comment validator.
- *
- * A comment validator is a function, that checks the $_POST fields and decides whether a comment should be stored or not (throws an <CommentRejected> exception with the rejection reason as the message).
- *
- * Parameters:
- * $fx - Validator function.
- */
- final protected function register_comment_validator($fx)
- {
- global $comment_validators;
- $comment_validators[] = $fx;
- }
- /*
- * Function: register_on_comment_store
- * Register a function that will be called, after a comment was saved.
- *
- * Parameters:
- * $fx - Function, that accepts one parameter (a <Comment> object).
- */
- final protected function register_on_comment_store($fx)
- {
- global $on_comment_store;
- $on_comment_store[] = $fx;
- }
-
- /*
- * Function: register_backend_pluginpage
- * Register a backend subpage for your plugin.
- *
- * Parameters:
- * $label - The label for the page.
- * $fx - A function for <url_process>.
- *
- * Your $fx should output output the result of a STE template, which should load "/systemtemplates/master.html" and overwrite the "content" section.
- *
- * If you need a URL to your pluginpage, you can use <get_backend_pluginpage_url> and the STE variable $rel_path_to_pluginpage.
- *
- * See also:
- * <prepare_backend_pluginpage>
- */
- final protected function register_backend_pluginpage($label, $fx)
- {
- global $pluginpages_handlers;
-
- $this->ste->vars["pluginpages"][$this->id] = $label;
- asort($this->ste->vars["pluginpages"]);
- $pluginid = $this->id;
- $pluginpages_handlers["p{$this->id}"] = function(&$data, $url_now, &$url_next) use($pluginid, $fx)
- {
- global $ste, $rel_path_to_root;
- $ste->vars["rel_path_to_pluginpage"] = "$rel_path_to_root/backend/pluginpages/p$pluginid";
- $rv = call_user_func_array($fx, array(&$data, $url_now, &$url_next));
- unset($ste->vars["rel_path_to_pluginpage"]);
- return $rv;
- };
- }
-
- /*
- * Function: register_articleeditor_plugin
- * Register a plugin for the article editor in the backend.
- *
- * Parameters:
- * $label - The label for the plugin.
- * $fx - A function that will be called during the articleeditor.
- * This function must accept these parameters:
- * * $article - An <Article> object or NULL, if no Article is edited right now.
- * * $about_to_save - If True, the article is about to be saved.
- * If you want to veto the saving, return the rejection reason as a string.
- * If everything is okay and you need to save additional data, return a callback function that accepts the saved <Article> object (that callback should also write data back to the template, if necessary).
- * If everything is okay and you do not need to save additional data, return NULL.
- * $template - The name of the template to display in the editor, relative to your template directory. If you do not want to display anything, you can set ths to NULL.
- */
- final protected function register_articleeditor_plugin($label, $fx, $template)
- {
- global $articleeditor_plugins;
-
- $articleeditor_plugins[] = array(
- "label" => $label,
- "fx" => $fx,
- "template" => $this->get_template_dir() . "/" . $template,
- "display" => $template != NULL
- );
- }
-
- /*
- * Function: get_backend_pluginpage_url
- * Get the URL to your backend plugin page.
- *
- * Returns:
- * The URL to your backend plugin page.
- */
- final protected function get_backend_pluginpage_url()
- {
- global $rel_path_to_root;
- return "$rel_path_to_root/backend/pluginpages/p{$this->id}";
- }
-
- /*
- * Function: get_article_extradata
- * Get the <ArticleExtradata> object for this plugin and the given article.
- *
- * Parameters:
- * $article - An <Article> object.
- *
- * Returns:
- * An <ArticleExtradata> object for this plugin and the given article.
- */
- final protected function get_article_extradata($article)
- {
- return new ArticleExtradata($article->get_id(), $this->id);
- }
-
- /*
- * Function: prepare_backend_pluginpage
- * Automatically sets the page title and highlights the menu-entry of your backend subpage.
- */
- final protected function prepare_backend_pluginpage()
- {
- $this->ste->vars["section"] = "plugins";
- $this->ste->vars["submenu"] = "plugin" . $this->id;
- $this->ste->vars["pagetitle"] = $this->ste->vars["pluginpages"][$this->id];
- }
-
- /*
- * Functions: Functions that are called at special events
- *
- * init - Will be called after plugin is loaded. You should register your stuff here.
- * atexit - Will be called, when Ratatöskr will exit.
- * install - Will be called after installation. If your plugin needs to initialize some database stuff or generate files, this is the right function.
- * uninstall - Will be called during uninstallation. If you used the install function you should undo your custom installation stuff.
- * update - Will be called after your plugin was updated to a new version.
- */
- public function init() {}
- public function atexit() {}
- public function install() {}
- public function uninstall() {}
- public function update() {}
+ private $id;
+
+ /*
+ * Variables: Protected variables
+ *
+ * $kvstorage - The Key-Value-Storage for the Plugin.
+ * $ste - Access to the global STECore object.
+ * $rel_path_to_root - Relative URL to the root of the page.
+ */
+ protected $kvstorage;
+ protected $ste;
+ protected $rel_path_to_root;
+
+ /*
+ * Constructor: __construct
+ * Performing some neccessary initialisation stuff.
+ * If you are overwriting this function, you *really* should call parent::__construct!
+ *
+ * Parameters:
+ * $id - The ID of the plugin (not the name).
+ */
+ public function __construct($id)
+ {
+ global $ste, $rel_path_to_root;
+ $this->id = $id;
+
+ $this->kvstorage = new PluginKVStorage($id);
+ $this->ste = $ste;
+ $this->rel_path_to_root = $rel_path_to_root;
+ }
+
+ /*
+ * Functions: Some getters
+ *
+ * get_id - get the Plugin-ID
+ * get_custompriv_dir - Get path to the custompriv directory of your plugin.
+ * get_custompub_dir - Get path to the custompub directory of your plugin.
+ * get_custompub_url - Get URL (can be accessed from the web) to the custompub directory of your plugin.
+ * get_template_dir - Get path to your template directory to be used with STE.
+ */
+ final public function get_id() { return $this->id; }
+ final protected function get_custompriv_dir() { return SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/private/" . $this->id; }
+ final protected function get_custompub_dir() { return SITE_BASE_PATH . "/ratatoeskr/plugin_extradata/public/" . $this->id; }
+ final protected function get_custompub_url() { return $GLOBALS["rel_path_to_root"] . "/ratatoeskr/plugin_extradata/public/" . $this->id; }
+ final protected function get_template_dir() { return "/plugintemplates/" . $this->id; }
+
+ /*
+ * Function: register_url_handler
+ * Register a URL handler
+ *
+ * Parameters:
+ * $name - Name of URL
+ * $fx - The function.
+ */
+ final protected function register_url_handler($name, $fx)
+ {
+ register_url_handler($name, $fx);
+ }
+
+ /*
+ * Function: register_ste_tag
+ * Register a custom STE tag.
+ *
+ * Parameters:
+ * $name - Name of your new STE tag.
+ * $fx - Function to register with this tag.
+ */
+ final protected function register_ste_tag($name, $fx)
+ {
+ $this->ste->register_tag($name, $fx);
+ }
+
+ /*
+ * Function: register_textprocessor
+ * Register a textprocessor.
+ *
+ * Parameters:
+ * $name - The name of the textprocessor-
+ * $fx - Function to register (function($input), returns HTML).
+ * $visible_in_backend - Should this textprocessor be visible in the backend? Defaults to True.
+ */
+ final protected function register_textprocessor($name, $fx, $visible_in_backend=True)
+ {
+ textprocessor_register($name, $fx, $visible_in_backend);
+ }
+
+ /*
+ * Function: register_comment_validator
+ * Register a comment validator.
+ *
+ * A comment validator is a function, that checks the $_POST fields and decides whether a comment should be stored or not (throws an <CommentRejected> exception with the rejection reason as the message).
+ *
+ * Parameters:
+ * $fx - Validator function.
+ */
+ final protected function register_comment_validator($fx)
+ {
+ global $comment_validators;
+ $comment_validators[] = $fx;
+ }
+ /*
+ * Function: register_on_comment_store
+ * Register a function that will be called, after a comment was saved.
+ *
+ * Parameters:
+ * $fx - Function, that accepts one parameter (a <Comment> object).
+ */
+ final protected function register_on_comment_store($fx)
+ {
+ global $on_comment_store;
+ $on_comment_store[] = $fx;
+ }
+
+ /*
+ * Function: register_backend_pluginpage
+ * Register a backend subpage for your plugin.
+ *
+ * Parameters:
+ * $label - The label for the page.
+ * $fx - A function for <url_process>.
+ *
+ * Your $fx should output output the result of a STE template, which should load "/systemtemplates/master.html" and overwrite the "content" section.
+ *
+ * If you need a URL to your pluginpage, you can use <get_backend_pluginpage_url> and the STE variable $rel_path_to_pluginpage.
+ *
+ * See also:
+ * <prepare_backend_pluginpage>
+ */
+ final protected function register_backend_pluginpage($label, $fx)
+ {
+ global $pluginpages_handlers;
+
+ $this->ste->vars["pluginpages"][$this->id] = $label;
+ asort($this->ste->vars["pluginpages"]);
+ $pluginid = $this->id;
+ $pluginpages_handlers["p{$this->id}"] = function(&$data, $url_now, &$url_next) use($pluginid, $fx)
+ {
+ global $ste, $rel_path_to_root;
+ $ste->vars["rel_path_to_pluginpage"] = "$rel_path_to_root/backend/pluginpages/p$pluginid";
+ $rv = call_user_func_array($fx, array(&$data, $url_now, &$url_next));
+ unset($ste->vars["rel_path_to_pluginpage"]);
+ return $rv;
+ };
+ }
+
+ /*
+ * Function: register_articleeditor_plugin
+ * Register a plugin for the article editor in the backend.
+ *
+ * Parameters:
+ * $label - The label for the plugin.
+ * $fx - A function that will be called during the articleeditor.
+ * This function must accept these parameters:
+ * * $article - An <Article> object or NULL, if no Article is edited right now.
+ * * $about_to_save - If True, the article is about to be saved.
+ * If you want to veto the saving, return the rejection reason as a string.
+ * If everything is okay and you need to save additional data, return a callback function that accepts the saved <Article> object (that callback should also write data back to the template, if necessary).
+ * If everything is okay and you do not need to save additional data, return NULL.
+ * $template - The name of the template to display in the editor, relative to your template directory. If you do not want to display anything, you can set ths to NULL.
+ */
+ final protected function register_articleeditor_plugin($label, $fx, $template)
+ {
+ global $articleeditor_plugins;
+
+ $articleeditor_plugins[] = array(
+ "label" => $label,
+ "fx" => $fx,
+ "template" => $this->get_template_dir() . "/" . $template,
+ "display" => $template != NULL
+ );
+ }
+
+ /*
+ * Function: get_backend_pluginpage_url
+ * Get the URL to your backend plugin page.
+ *
+ * Returns:
+ * The URL to your backend plugin page.
+ */
+ final protected function get_backend_pluginpage_url()
+ {
+ global $rel_path_to_root;
+ return "$rel_path_to_root/backend/pluginpages/p{$this->id}";
+ }
+
+ /*
+ * Function: get_article_extradata
+ * Get the <ArticleExtradata> object for this plugin and the given article.
+ *
+ * Parameters:
+ * $article - An <Article> object.
+ *
+ * Returns:
+ * An <ArticleExtradata> object for this plugin and the given article.
+ */
+ final protected function get_article_extradata($article)
+ {
+ return new ArticleExtradata($article->get_id(), $this->id);
+ }
+
+ /*
+ * Function: prepare_backend_pluginpage
+ * Automatically sets the page title and highlights the menu-entry of your backend subpage.
+ */
+ final protected function prepare_backend_pluginpage()
+ {
+ $this->ste->vars["section"] = "plugins";
+ $this->ste->vars["submenu"] = "plugin" . $this->id;
+ $this->ste->vars["pagetitle"] = $this->ste->vars["pluginpages"][$this->id];
+ }
+
+ /*
+ * Functions: Functions that are called at special events
+ *
+ * init - Will be called after plugin is loaded. You should register your stuff here.
+ * atexit - Will be called, when Ratatöskr will exit.
+ * install - Will be called after installation. If your plugin needs to initialize some database stuff or generate files, this is the right function.
+ * uninstall - Will be called during uninstallation. If you used the install function you should undo your custom installation stuff.
+ * update - Will be called after your plugin was updated to a new version.
+ */
+ public function init() {}
+ public function atexit() {}
+ public function install() {}
+ public function uninstall() {}
+ public function update() {}
}
?>
diff --git a/ratatoeskr/sys/pluginpackage.php b/ratatoeskr/sys/pluginpackage.php
index 863df71..5365e48 100644
--- a/ratatoeskr/sys/pluginpackage.php
+++ b/ratatoeskr/sys/pluginpackage.php
@@ -3,7 +3,7 @@
/*
* File: ratatoeskr/sys/pluginpackage.php
* Handle plugin packages easily.
- *
+ *
* License:
* This file is part of Ratatöskr.
* Unlike the other parts of Ratatöskr, *this* file ist *not* licensed under the
@@ -15,68 +15,68 @@
/*
* Function: dir2array
* Pack a directory into an array.
- *
+ *
* Parameters:
- * $dir - The directory to pack.
- *
+ * $dir - The directory to pack.
+ *
* Returns:
- * Associative array. Keys are filenames, values are either the file's content as a string or another array, if it's a directory.
+ * Associative array. Keys are filenames, values are either the file's content as a string or another array, if it's a directory.
*/
function dir2array($dir)
{
- $rv = array();
- foreach(scandir($dir) as $fn)
- {
- if(($fn == ".") or ($fn == ".."))
- continue;
- $fn_new = $dir . "/" . $fn;
- if(is_dir($fn_new))
- $rv[$fn] = dir2array($fn_new);
- elseif(is_file($fn_new))
- $rv[$fn] = file_get_contents($fn_new);
- }
- return $rv;
+ $rv = array();
+ foreach(scandir($dir) as $fn)
+ {
+ if(($fn == ".") or ($fn == ".."))
+ continue;
+ $fn_new = $dir . "/" . $fn;
+ if(is_dir($fn_new))
+ $rv[$fn] = dir2array($fn_new);
+ elseif(is_file($fn_new))
+ $rv[$fn] = file_get_contents($fn_new);
+ }
+ return $rv;
}
/*
* Function: array2dir
* Unpack an array into a directory.
- *
+ *
* Parameters:
- * $a - Array to unpack.
- * $dir - Directory to unpack to.
+ * $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);
- }
+ 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);
+ }
}
function validate_url ($u) { return preg_match("/^http[s]{0,1}:\\/\\/.*$/", $u) != 0; }
function validate_arraydir($a)
{
- if(!is_array($a))
- return False;
- foreach($a as $k=>$v)
- {
- if(!is_string($k))
- return False;
- if(is_array($v) and (!validate_arraydir($v)))
- return False;
- elseif(!is_string($v))
- return False;
- }
- return True;
-}
+ if(!is_array($a))
+ return False;
+ foreach($a as $k=>$v)
+ {
+ if(!is_string($k))
+ return False;
+ if(is_array($v) and (!validate_arraydir($v)))
+ return False;
+ elseif(!is_string($v))
+ return False;
+ }
+ return True;
+}
/*
* Class: InvalidPackage
@@ -90,164 +90,164 @@ class InvalidPackage extends Exception {}
*/
class PluginPackage
{
- public static $magic = "R7RPLGPACKV001";
-
- /*
- * Variables: Mandatory values
- *
- * $code - The plugin code
- * $classname - The name of the plugins main class
- * $name - Name of the plugin (must be at least one character, allowed chars: a-z A-Z 0-9 - _)
- * $author - The author of the plugin (preferably in the format: Name<mail@address>)
- * $versiontext - A text to describe the current version, something like "1.1 Beta"
- * $versioncount - A number for this version, should be increased with every release
- * $api - The used API version
- * $short_description - A short description.
- */
- public $code = NULL;
- public $classname = NULL;
- public $name = NULL;
- public $author = NULL;
- public $versiontext = NULL;
- public $versioncount = NULL;
- public $api = NULL;
- public $short_description = NULL;
-
- /*
- * Variables: Optional values
- *
- * $updatepath - A URL that points to a update information resource (serialize'd array("current-version" => VERSIONCOUNT, "dl-path" => DOWNLOAD PATH); will get overwritten/set by the default repository software.
- * $web - A URL to the webpage for the plugin. If left empty, the default repository software will set this to the description page of your plugin.
- * $license - The license text of your plugin.
- * $help - A help / manual (formatted in HTML) for your plugin.
- * $custompub - <dir2array> 'd directory that contains custom public(i.e. can later be accessed from the web) data.
- * $custompriv - <dir2array> 'd directory that contains custom private data.
- * $tpls - <dir2array> 'd directory containing custom STE templates.
- */
- public $updatepath = NULL;
- public $web = NULL;
- public $license = NULL;
- public $help = NULL;
- public $custompub = NULL;
- public $custompriv = NULL;
- public $tpls = NULL;
-
- /*
- * Function: validate
- * Validate, if the variables are set correctly.
- * Will throw an <InvalidPackage> exception if invalid.
- */
- public function validate()
- {
- if(!is_string($this->code))
- throw new InvalidPackage("Invalid code value.");
- if(!is_string($this->classname))
- throw new InvalidPackage("Invalid classname value.");
- if(preg_match("/^[a-zA-Z0-9_\\-]+$/", $this->name) == 0)
- throw new InvalidPackage("Invalid name value (must be at least 1 character, accepted chars: a-z A-Z 0-9 - _).");
- if(!is_string($this->author))
- throw new InvalidPackage("Invalid author value.");
- if(!is_string($this->versiontext))
- throw new InvalidPackage("Invalid versiontext value.");
- if(!is_numeric($this->versioncount))
- throw new InvalidPackage("Invalid versioncount value. Must be a number.");
- if(!is_numeric($this->api))
- throw new InvalidPackage("Invalid api value. Must be a number.");
- if(!is_string($this->short_description))
- throw new InvalidPackage("Invalid short_description value.");
-
- if((!empty($this->updatepath)) and (!validate_url($this->updatepath)))
- throw new InvalidPackage("Invalid updatepath value. Must be an URL. " .$this->updatepath);
- if((!empty($this->web)) and (!validate_url($this->web)))
- throw new InvalidPackage("Invalid web value. Must be an URL.");
- if(($this->license !== NULL) and (!is_string($this->license)))
- throw new InvalidPackage("Invalid license value.");
- if(($this->help !== NULL) and (!is_string($this->help)))
- throw new InvalidPackage("Invalid help value.");
- if(($this->custompub !== NULL) and (!validate_arraydir($this->custompub)))
- throw new InvalidPackage("Invalid custompub value.");
- if(($this->custompriv !== NULL) and (!validate_arraydir($this->custompriv)))
- throw new InvalidPackage("Invalid custompriv value.");
- if(($this->tpls !== NULL) and (!validate_arraydir($this->tpls)))
- throw new InvalidPackage("Invalid tpls value.");
- return True;
- }
-
- /*
- * Function: load
- * Load a plugin package from binary data.
- *
- * Parameters:
- * $plugin_raw - The raw package to load.
- *
- * Returns:
- * The <PluginPackage> object.
- *
- * Throws:
- * <InvalidPackage> if package is invalid.
- */
- public static function load($plugin_raw)
- {
- /* Read and compare magic number */
- $magic = substr($plugin_raw, 0, strlen(self::$magic));
- if($magic != self::$magic)
- throw new InvalidPackage("Wrong magic number");
-
- /* Read sha1sum and uncompress serialized plugin, then compare the hash */
- $sha1sum = substr($plugin_raw, strlen(self::$magic), 20);
- $pluginser = gzuncompress(substr($plugin_raw, strlen(self::$magic) + 20));
- if(sha1($pluginser, True) != $sha1sum)
- throw new InvalidPackage("Wrong SHA1 hash");
-
- $plugin = @unserialize($pluginser);
- if(!($plugin instanceof self))
- throw new InvalidPackage("Not the correct class or not unserializeable.");
-
- $plugin->validate();
-
- return $plugin;
- }
-
- /*
- * Function: save
- * Save the plugin.
- *
- * Returns:
- * A binary plugin package.
- *
- * Throws:
- * <InvalidPackage> if package is invalid.
- */
- public function save()
- {
- $this->validate();
- $ser = serialize($this);
- return self::$magic . sha1($ser, True) . gzcompress($ser, 9);
- }
-
- /*
- * Function: extract_meta
- * Get just the metadata of this package.
- *
- * Returns:
- * A <PluginPackageMeta> object.
- */
- public function extract_meta()
- {
- $meta = new PluginPackageMeta();
-
- $meta->name = $this->name;
- $meta->author = $this->author;
- $meta->versiontext = $this->versiontext;
- $meta->versioncount = $this->versioncount;
- $meta->api = $this->api;
- $meta->short_description = $this->short_description;
- $meta->updatepath = $this->updatepath;
- $meta->web = $this->web;
- $meta->license = $this->license;
-
- return $meta;
- }
+ public static $magic = "R7RPLGPACKV001";
+
+ /*
+ * Variables: Mandatory values
+ *
+ * $code - The plugin code
+ * $classname - The name of the plugins main class
+ * $name - Name of the plugin (must be at least one character, allowed chars: a-z A-Z 0-9 - _)
+ * $author - The author of the plugin (preferably in the format: Name<mail@address>)
+ * $versiontext - A text to describe the current version, something like "1.1 Beta"
+ * $versioncount - A number for this version, should be increased with every release
+ * $api - The used API version
+ * $short_description - A short description.
+ */
+ public $code = NULL;
+ public $classname = NULL;
+ public $name = NULL;
+ public $author = NULL;
+ public $versiontext = NULL;
+ public $versioncount = NULL;
+ public $api = NULL;
+ public $short_description = NULL;
+
+ /*
+ * Variables: Optional values
+ *
+ * $updatepath - A URL that points to a update information resource (serialize'd array("current-version" => VERSIONCOUNT, "dl-path" => DOWNLOAD PATH); will get overwritten/set by the default repository software.
+ * $web - A URL to the webpage for the plugin. If left empty, the default repository software will set this to the description page of your plugin.
+ * $license - The license text of your plugin.
+ * $help - A help / manual (formatted in HTML) for your plugin.
+ * $custompub - <dir2array> 'd directory that contains custom public(i.e. can later be accessed from the web) data.
+ * $custompriv - <dir2array> 'd directory that contains custom private data.
+ * $tpls - <dir2array> 'd directory containing custom STE templates.
+ */
+ public $updatepath = NULL;
+ public $web = NULL;
+ public $license = NULL;
+ public $help = NULL;
+ public $custompub = NULL;
+ public $custompriv = NULL;
+ public $tpls = NULL;
+
+ /*
+ * Function: validate
+ * Validate, if the variables are set correctly.
+ * Will throw an <InvalidPackage> exception if invalid.
+ */
+ public function validate()
+ {
+ if(!is_string($this->code))
+ throw new InvalidPackage("Invalid code value.");
+ if(!is_string($this->classname))
+ throw new InvalidPackage("Invalid classname value.");
+ if(preg_match("/^[a-zA-Z0-9_\\-]+$/", $this->name) == 0)
+ throw new InvalidPackage("Invalid name value (must be at least 1 character, accepted chars: a-z A-Z 0-9 - _).");
+ if(!is_string($this->author))
+ throw new InvalidPackage("Invalid author value.");
+ if(!is_string($this->versiontext))
+ throw new InvalidPackage("Invalid versiontext value.");
+ if(!is_numeric($this->versioncount))
+ throw new InvalidPackage("Invalid versioncount value. Must be a number.");
+ if(!is_numeric($this->api))
+ throw new InvalidPackage("Invalid api value. Must be a number.");
+ if(!is_string($this->short_description))
+ throw new InvalidPackage("Invalid short_description value.");
+
+ if((!empty($this->updatepath)) and (!validate_url($this->updatepath)))
+ throw new InvalidPackage("Invalid updatepath value. Must be an URL. " .$this->updatepath);
+ if((!empty($this->web)) and (!validate_url($this->web)))
+ throw new InvalidPackage("Invalid web value. Must be an URL.");
+ if(($this->license !== NULL) and (!is_string($this->license)))
+ throw new InvalidPackage("Invalid license value.");
+ if(($this->help !== NULL) and (!is_string($this->help)))
+ throw new InvalidPackage("Invalid help value.");
+ if(($this->custompub !== NULL) and (!validate_arraydir($this->custompub)))
+ throw new InvalidPackage("Invalid custompub value.");
+ if(($this->custompriv !== NULL) and (!validate_arraydir($this->custompriv)))
+ throw new InvalidPackage("Invalid custompriv value.");
+ if(($this->tpls !== NULL) and (!validate_arraydir($this->tpls)))
+ throw new InvalidPackage("Invalid tpls value.");
+ return True;
+ }
+
+ /*
+ * Function: load
+ * Load a plugin package from binary data.
+ *
+ * Parameters:
+ * $plugin_raw - The raw package to load.
+ *
+ * Returns:
+ * The <PluginPackage> object.
+ *
+ * Throws:
+ * <InvalidPackage> if package is invalid.
+ */
+ public static function load($plugin_raw)
+ {
+ /* Read and compare magic number */
+ $magic = substr($plugin_raw, 0, strlen(self::$magic));
+ if($magic != self::$magic)
+ throw new InvalidPackage("Wrong magic number");
+
+ /* Read sha1sum and uncompress serialized plugin, then compare the hash */
+ $sha1sum = substr($plugin_raw, strlen(self::$magic), 20);
+ $pluginser = gzuncompress(substr($plugin_raw, strlen(self::$magic) + 20));
+ if(sha1($pluginser, True) != $sha1sum)
+ throw new InvalidPackage("Wrong SHA1 hash");
+
+ $plugin = @unserialize($pluginser);
+ if(!($plugin instanceof self))
+ throw new InvalidPackage("Not the correct class or not unserializeable.");
+
+ $plugin->validate();
+
+ return $plugin;
+ }
+
+ /*
+ * Function: save
+ * Save the plugin.
+ *
+ * Returns:
+ * A binary plugin package.
+ *
+ * Throws:
+ * <InvalidPackage> if package is invalid.
+ */
+ public function save()
+ {
+ $this->validate();
+ $ser = serialize($this);
+ return self::$magic . sha1($ser, True) . gzcompress($ser, 9);
+ }
+
+ /*
+ * Function: extract_meta
+ * Get just the metadata of this package.
+ *
+ * Returns:
+ * A <PluginPackageMeta> object.
+ */
+ public function extract_meta()
+ {
+ $meta = new PluginPackageMeta();
+
+ $meta->name = $this->name;
+ $meta->author = $this->author;
+ $meta->versiontext = $this->versiontext;
+ $meta->versioncount = $this->versioncount;
+ $meta->api = $this->api;
+ $meta->short_description = $this->short_description;
+ $meta->updatepath = $this->updatepath;
+ $meta->web = $this->web;
+ $meta->license = $this->license;
+
+ return $meta;
+ }
}
/*
@@ -256,33 +256,33 @@ class PluginPackage
*/
class PluginPackageMeta
{
- /*
- * Variables: Mandatory values
- *
- * $name - Name of the plugin (must be at least one character, allowed chars: a-z A-Z 0-9 - _)
- * $author - The author of the plugin (preferably in the format: Name<mail@address>)
- * $versiontext - A text to describe the current version, something like "1.1 Beta"
- * $versioncount - A number for this version, should be increased with every release
- * $api - The used API version
- * $short_description - A short description.
- */
- public $name = NULL;
- public $author = NULL;
- public $versiontext = NULL;
- public $versioncount = NULL;
- public $api = NULL;
- public $short_description = NULL;
-
- /*
- * Variables: Optional values
- *
- * $updatepath - A URL that points to a update information resource (serialize'd array("current-version" => VERSIONCOUNT, "dl-path" => DOWNLOAD PATH); will get overwritten/set by the default repository software.
- * $web - A URL to the webpage for the plugin. If left empty, the default repository software will set this to the description page of your plugin.
- * $license - The license text of your plugin.
- */
- public $updatepath = NULL;
- public $web = NULL;
- public $license = NULL;
+ /*
+ * Variables: Mandatory values
+ *
+ * $name - Name of the plugin (must be at least one character, allowed chars: a-z A-Z 0-9 - _)
+ * $author - The author of the plugin (preferably in the format: Name<mail@address>)
+ * $versiontext - A text to describe the current version, something like "1.1 Beta"
+ * $versioncount - A number for this version, should be increased with every release
+ * $api - The used API version
+ * $short_description - A short description.
+ */
+ public $name = NULL;
+ public $author = NULL;
+ public $versiontext = NULL;
+ public $versioncount = NULL;
+ public $api = NULL;
+ public $short_description = NULL;
+
+ /*
+ * Variables: Optional values
+ *
+ * $updatepath - A URL that points to a update information resource (serialize'd array("current-version" => VERSIONCOUNT, "dl-path" => DOWNLOAD PATH); will get overwritten/set by the default repository software.
+ * $web - A URL to the webpage for the plugin. If left empty, the default repository software will set this to the description page of your plugin.
+ * $license - The license text of your plugin.
+ */
+ public $updatepath = NULL;
+ public $web = NULL;
+ public $license = NULL;
}
?>
diff --git a/ratatoeskr/sys/pwhash.php b/ratatoeskr/sys/pwhash.php
index 8ec4762..5f31dbb 100644
--- a/ratatoeskr/sys/pwhash.php
+++ b/ratatoeskr/sys/pwhash.php
@@ -1,9 +1,9 @@
<?php
/*
* File: ratatoeskr/sys/pwhash.php
- *
+ *
* Hashing passwords
- *
+ *
* License:
* This file is part of Ratatöskr.
* Ratatöskr is licensed unter the MIT / X11 License.
@@ -14,61 +14,61 @@
* Class: PasswordHash
* Contains static functions for password hashes.
* Is just used as a namespace, can not be created.
- *
+ *
* It should be fairly difficult to break these salted hashes via bruteforce attacks.
*/
class PasswordHash
{
- private function __construct() {} /* Prevent construction */
-
- private static $saltlen_min = 20;
- private static $saltlen_max = 30;
- private static $iterations_min = 200;
- private static $iterations_max = 1000;
-
- private static function hash($data, $salt, $iterations)
- {
- $hash = $data . $salt;
- for($i = $iterations ;$i--;)
- $hash = sha1($data . $hash . $salt, (bool) $i);
- return $iterations . '$' . bin2hex($salt) . '$' . $hash;
- }
-
- /*
- * Function: create
- * Create a password hash string.
- *
- * Parameters:
- * $password - The password (or other data) to hash.
- *
- * Returns:
- * The salted hash as a string.
- */
- public static function create($password)
- {
- $salt = "";
- $saltlen = mt_rand(self::$saltlen_min, self::$saltlen_max);
- for($i = 0; $i < $saltlen; $i++)
- $salt .= chr(mt_rand(0,255));
- return self::hash($password, $salt, mt_rand(self::$iterations_min, self::$iterations_max));
- }
-
- /*
- * Function: validate
- * Validate a salted hash.
- *
- * Parameters:
- * $password - The password to test.
- * $pwhash - The hash to test against.
- *
- * Returns:
- * True, if $password was correct, False otherwise.
- */
- public static function validate($password, $pwhash)
- {
- list($iterations, $hexsalt, $hash) = explode('$', $pwhash);
- return self::hash($password, pack("H*", $hexsalt), $iterations) == $pwhash;
- }
+ private function __construct() {} /* Prevent construction */
+
+ private static $saltlen_min = 20;
+ private static $saltlen_max = 30;
+ private static $iterations_min = 200;
+ private static $iterations_max = 1000;
+
+ private static function hash($data, $salt, $iterations)
+ {
+ $hash = $data . $salt;
+ for($i = $iterations ;$i--;)
+ $hash = sha1($data . $hash . $salt, (bool) $i);
+ return $iterations . '$' . bin2hex($salt) . '$' . $hash;
+ }
+
+ /*
+ * Function: create
+ * Create a password hash string.
+ *
+ * Parameters:
+ * $password - The password (or other data) to hash.
+ *
+ * Returns:
+ * The salted hash as a string.
+ */
+ public static function create($password)
+ {
+ $salt = "";
+ $saltlen = mt_rand(self::$saltlen_min, self::$saltlen_max);
+ for($i = 0; $i < $saltlen; $i++)
+ $salt .= chr(mt_rand(0,255));
+ return self::hash($password, $salt, mt_rand(self::$iterations_min, self::$iterations_max));
+ }
+
+ /*
+ * Function: validate
+ * Validate a salted hash.
+ *
+ * Parameters:
+ * $password - The password to test.
+ * $pwhash - The hash to test against.
+ *
+ * Returns:
+ * True, if $password was correct, False otherwise.
+ */
+ public static function validate($password, $pwhash)
+ {
+ list($iterations, $hexsalt, $hash) = explode('$', $pwhash);
+ return self::hash($password, pack("H*", $hexsalt), $iterations) == $pwhash;
+ }
}
?>
diff --git a/ratatoeskr/sys/textprocessors.php b/ratatoeskr/sys/textprocessors.php
index ea6fb82..f5281bf 100644
--- a/ratatoeskr/sys/textprocessors.php
+++ b/ratatoeskr/sys/textprocessors.php
@@ -2,7 +2,7 @@
/*
* File: ratatoeskr/sys/textprocessors.php
* Manage text processors (functions that transform text to HTML) and implement some default ones.
- *
+ *
* License:
* This file is part of Ratatöskr.
* Ratatöskr is licensed unter the MIT / X11 License.
@@ -15,64 +15,64 @@ require_once(dirname(__FILE__) . "/utils.php");
/*
* Function: textprocessor_register
* Register a textprocessor.
- *
+ *
* Parameters:
- * $name - The name of the textprocessor
- * $fx - The textprocessor function (function($input), returns HTML)
- * $visible_in_backend - Should this textprocessor be visible in the backend? Defaults to True.
+ * $name - The name of the textprocessor
+ * $fx - The textprocessor function (function($input), returns HTML)
+ * $visible_in_backend - Should this textprocessor be visible in the backend? Defaults to True.
*/
function textprocessor_register($name, $fx, $visible_in_backend=True)
{
- global $textprocessors;
- $textprocessors[$name] = array($fx, $visible_in_backend);
+ global $textprocessors;
+ $textprocessors[$name] = array($fx, $visible_in_backend);
}
/*
* Function: textprocessor_apply
* Apply a textprocessor on a text.
- *
+ *
* Parameters:
- * $text - The input text.
- * $textprocessor - The name of the textprocessor.
- *
+ * $text - The input text.
+ * $textprocessor - The name of the textprocessor.
+ *
* Returns:
- * HTML
+ * HTML
*/
function textprocessor_apply($text, $textprocessor)
{
- global $textprocessors;
- if(!isset($textprocessors[$textprocessor]))
- throw new Exception("Unknown Textprocessor: $textprocessor");
-
- $fx = @$textprocessors[$textprocessor][0];
- if(!is_callable($fx))
- throw new Exception("Invalid Textprocessor: $textprocessor");
-
- return call_user_func($fx, $text);
+ global $textprocessors;
+ if(!isset($textprocessors[$textprocessor]))
+ throw new Exception("Unknown Textprocessor: $textprocessor");
+
+ $fx = @$textprocessors[$textprocessor][0];
+ if(!is_callable($fx))
+ throw new Exception("Invalid Textprocessor: $textprocessor");
+
+ return call_user_func($fx, $text);
}
/*
* Function: textprocessor_apply_translation
* Applys a textprocessor automatically on a <Translation> object. The used textprocessor is determined by the $texttype property.
- *
+ *
* Parameters:
- * $translationobj - The <Translation> object.
- *
+ * $translationobj - The <Translation> object.
+ *
* Returns:
- * HTML
+ * HTML
*/
function textprocessor_apply_translation($translationobj)
{
- return textprocessor_apply($translationobj->text, $translationobj->texttype);
+ return textprocessor_apply($translationobj->text, $translationobj->texttype);
}
if(!isset($textprocessors))
{
- $textprocessors = array(
- "Markdown" => array("Markdown", True),
- "Plain Text" => array(function($text) { return str_replace(array("\r\n", "\n"), array("<br />", "<br />"), htmlesc($text)); }, True),
- "HTML" => array(function($text) { return $text; }, True)
- );
+ $textprocessors = array(
+ "Markdown" => array("Markdown", True),
+ "Plain Text" => array(function($text) { return str_replace(array("\r\n", "\n"), array("<br />", "<br />"), htmlesc($text)); }, True),
+ "HTML" => array(function($text) { return $text; }, True)
+ );
}
?>
diff --git a/ratatoeskr/sys/translation.php b/ratatoeskr/sys/translation.php
index 1104bdb..4ca6ec8 100644
--- a/ratatoeskr/sys/translation.php
+++ b/ratatoeskr/sys/translation.php
@@ -2,7 +2,7 @@
/*
* File: ratatoeskr/sys/translation.php
* Load translation.
- *
+ *
* License:
* This file is part of Ratatöskr.
* Ratatöskr is licensed unter the MIT / X11 License.
@@ -13,55 +13,55 @@ require_once(dirname(__FILE__) . "/utils.php");
require_once(dirname(__FILE__) . "/init_ste.php");
if(!defined("SETUP"))
- require_once(dirname(__FILE__) . "/models.php");
+ require_once(dirname(__FILE__) . "/models.php");
if(!defined("TRANSLATION_PLUGIN_LOADED"))
{
- $ste->register_tag(
- "get_translation",
- function($ste, $params, $sub)
- {
- global $translation;
- if((!isset($translation)) or empty($params["for"]) or (!isset($translation[$params["for"]])))
- return "";
- $rv = $translation[$params["for"]];
- return (!empty($params["raw"])) ? $rv : htmlesc($rv);
- }
- );
- define("TRANSLATION_PLUGIN_LOADED", True);
+ $ste->register_tag(
+ "get_translation",
+ function($ste, $params, $sub)
+ {
+ global $translation;
+ if((!isset($translation)) or empty($params["for"]) or (!isset($translation[$params["for"]])))
+ return "";
+ $rv = $translation[$params["for"]];
+ return (!empty($params["raw"])) ? $rv : htmlesc($rv);
+ }
+ );
+ define("TRANSLATION_PLUGIN_LOADED", True);
}
/*
* Function: load_language
* Load a language (i.e. set the global $translation variable).
- *
+ *
* Parameters:
- * $lang - The language (2-Letter code, e.g. "en", "de", "it" ...) to load. NULL for default (from database).
+ * $lang - The language (2-Letter code, e.g. "en", "de", "it" ...) to load. NULL for default (from database).
*/
function load_language($lang=NULL)
{
- if(!defined("SETUP"))
- {
- global $ratatoeskr_settings;
- if($lang === NULL)
- $lang = $ratatoeskr_settings["default_language"];
- }
- else
- {
- if($lang === NULL)
- $lang = "en";
- }
-
- /*
- * Because we will include an file defined by the $lang param, we will
- * only allow alphabetic characters, so this function should not be
- * vulnerable to LFI-Exploits...
- */
- $lang = implode("", array_filter(str_split($lang, 1), "ctype_alpha"));
-
- require(dirname(__FILE__) . "/../translations/$lang.php");
-
- $GLOBALS["translation"] = $translation;
+ if(!defined("SETUP"))
+ {
+ global $ratatoeskr_settings;
+ if($lang === NULL)
+ $lang = $ratatoeskr_settings["default_language"];
+ }
+ else
+ {
+ if($lang === NULL)
+ $lang = "en";
+ }
+
+ /*
+ * Because we will include an file defined by the $lang param, we will
+ * only allow alphabetic characters, so this function should not be
+ * vulnerable to LFI-Exploits...
+ */
+ $lang = implode("", array_filter(str_split($lang, 1), "ctype_alpha"));
+
+ require(dirname(__FILE__) . "/../translations/$lang.php");
+
+ $GLOBALS["translation"] = $translation;
}
?>
diff --git a/ratatoeskr/sys/urlprocess.php b/ratatoeskr/sys/urlprocess.php
index d3c5edb..841ac67 100644
--- a/ratatoeskr/sys/urlprocess.php
+++ b/ratatoeskr/sys/urlprocess.php
@@ -1,9 +1,9 @@
<?php
/*
* File: ratatoeskr/sys/urlprocess.php
- *
+ *
* Providing functions / classes to handle URLs
- *
+ *
* License:
* This file is part of Ratatöskr.
* Ratatöskr is licensed unter the MIT / X11 License.
@@ -13,147 +13,147 @@
/*
* Function: url_action_simple
* Generate an action in a more simple way.
- *
+ *
* Parameters:
- * $function - A callback that gets the $data var as an input and returns the new $data var. Can throw an <Redirect> Exception.
- *
+ * $function - A callback that gets the $data var as an input and returns the new $data var. Can throw an <Redirect> Exception.
+ *
* Returns:
- * A callback that can be used as an url action.
+ * A callback that can be used as an url action.
*/
function url_action_simple($function)
{
- return function(&$data, $url_now, &$url_next) use ($function)
- {
- try
- {
- $data = call_user_func($function, $data);
- $url_next = array();
- }
- catch(Redirect $e)
- {
- $url_next = $e->nextpath;
- }
- };
+ return function(&$data, $url_now, &$url_next) use ($function)
+ {
+ try
+ {
+ $data = call_user_func($function, $data);
+ $url_next = array();
+ }
+ catch(Redirect $e)
+ {
+ $url_next = $e->nextpath;
+ }
+ };
}
/*
* Function: url_action_subactions
* Generate an action that contains subactions. Subactions can redirect to ".." to go to the level above.
- *
+ *
* Parameters:
- * $actions - Associative array of actions.
- *
+ * $actions - Associative array of actions.
+ *
* Returns:
- * A callback that can be used as an url action.
+ * A callback that can be used as an url action.
*/
function url_action_subactions($actions)
{
- return function(&$data, $url_now, &$url_next) use ($actions)
- {
- $result = url_process($url_next, $actions, $data);
- if($result !== NULL)
- $url_next = $result;
- else
- $url_next = array();
- };
+ return function(&$data, $url_now, &$url_next) use ($actions)
+ {
+ $result = url_process($url_next, $actions, $data);
+ if($result !== NULL)
+ $url_next = $result;
+ else
+ $url_next = array();
+ };
}
/*
* Function: url_action_alias
* Generate an action that is an alias for another one (i.e. redirects).
- *
+ *
* Parameters:
- * $for - Path (array) of the action this one should be an alias of.
+ * $for - Path (array) of the action this one should be an alias of.
*
* Returns:
- * A callback that can be used as an url action.
+ * A callback that can be used as an url action.
*/
function url_action_alias($for)
{
- return function(&$data, $url_now, &$url_next) use($for)
- {
- $url_next = array_merge($for, $url_next);
- };
+ return function(&$data, $url_now, &$url_next) use($for)
+ {
+ $url_next = array_merge($for, $url_next);
+ };
}
/*
* Function: url_process
* Choose an appropiate action for the given URL.
- *
+ *
* Parameters:
- * $url - Either an array containing the URL components or the URL (both relative).
- * $actions - Associative array of actions.
- * Key is the name (anything alphanumeric, should usually not start with '_', reserved for special URL names, see beneath).
- * Value is a callback of the form: function(&$data, $url_now, &$url_next). $data can be used for shared data between subactions. $url_next can be modified in order to redirect to another action / stop the routing.
- *
+ * $url - Either an array containing the URL components or the URL (both relative).
+ * $actions - Associative array of actions.
+ * Key is the name (anything alphanumeric, should usually not start with '_', reserved for special URL names, see beneath).
+ * Value is a callback of the form: function(&$data, $url_now, &$url_next). $data can be used for shared data between subactions. $url_next can be modified in order to redirect to another action / stop the routing.
+ *
* Special actions:
- * _index - If name is empty, the index will be called.
- * _default - If nothing was found, this is the default.
- * _notfound - If not even _default exists or NotFoundError was thrown.
- * _prelude - If existant, will be executed before everything else.
- * _epilog - If existant, will be executed after evrything else.
+ * _index - If name is empty, the index will be called.
+ * _default - If nothing was found, this is the default.
+ * _notfound - If not even _default exists or NotFoundError was thrown.
+ * _prelude - If existant, will be executed before everything else.
+ * _epilog - If existant, will be executed after evrything else.
*/
function url_process($url, $actions, &$data)
{
- $epilog_running = 0;
- if(is_string($url))
- $url = explode("/", $url);
- $url = array_filter($url, function($x) { return !empty($x); });
- if(count($url) == 0)
- $url = array("_index");
-
- if(isset($actions["_prelude"]))
- $url = array_merge(array("_prelude"), $url);
-
- $url_now = $url[0];
- $url_next = array_slice($url, 1);
-
- while(is_string($url_now) and ($url_now != "") and ($url_now != ".."))
- {
- $cb = NULL;
- if(empty($url_now))
- $url_now = "_index";
- if(isset($actions[$url_now]))
- $cb = $actions[$url_now];
- else if(isset($actions["_default"]))
- $cb = $actions["_default"];
- else if(isset($actions["_notfound"]))
- $cb = $actions["_notfound"];
- else
- throw new NotFoundError();
-
- try
- {
- call_user_func_array($cb, array(&$data, $url_now, &$url_next));
- }
- catch(NotFoundError $e)
- {
- if(isset($actions["_notfound"]))
- $url_next = array("_notfound");
- else
- throw $e;
- }
-
- if(count($url_next) > 0)
- {
- $url_now = $url_next[0];
- $url_next = array_slice($url_next, 1);
- }
- else if(isset($actions["_epilog"]) and ($epilog_running <= 0))
- {
- $epilog_running = 2;
- $url_now = "_epilog";
- }
- else
- $url_now = "";
-
- --$epilog_running;
- }
-
- if($url_now == "..")
- return $url_next;
- else
- return NULL;
+ $epilog_running = 0;
+ if(is_string($url))
+ $url = explode("/", $url);
+ $url = array_filter($url, function($x) { return !empty($x); });
+ if(count($url) == 0)
+ $url = array("_index");
+
+ if(isset($actions["_prelude"]))
+ $url = array_merge(array("_prelude"), $url);
+
+ $url_now = $url[0];
+ $url_next = array_slice($url, 1);
+
+ while(is_string($url_now) and ($url_now != "") and ($url_now != ".."))
+ {
+ $cb = NULL;
+ if(empty($url_now))
+ $url_now = "_index";
+ if(isset($actions[$url_now]))
+ $cb = $actions[$url_now];
+ else if(isset($actions["_default"]))
+ $cb = $actions["_default"];
+ else if(isset($actions["_notfound"]))
+ $cb = $actions["_notfound"];
+ else
+ throw new NotFoundError();
+
+ try
+ {
+ call_user_func_array($cb, array(&$data, $url_now, &$url_next));
+ }
+ catch(NotFoundError $e)
+ {
+ if(isset($actions["_notfound"]))
+ $url_next = array("_notfound");
+ else
+ throw $e;
+ }
+
+ if(count($url_next) > 0)
+ {
+ $url_now = $url_next[0];
+ $url_next = array_slice($url_next, 1);
+ }
+ else if(isset($actions["_epilog"]) and ($epilog_running <= 0))
+ {
+ $epilog_running = 2;
+ $url_now = "_epilog";
+ }
+ else
+ $url_now = "";
+
+ --$epilog_running;
+ }
+
+ if($url_now == "..")
+ return $url_next;
+ else
+ return NULL;
}
/*
@@ -163,12 +163,12 @@ function url_process($url, $actions, &$data)
*/
class Redirect extends Exception
{
- public $nextpath;
- public function __construct($nextpath)
- {
- $this->nextpath = $nextpath;
- parent::__construct();
- }
+ public $nextpath;
+ public function __construct($nextpath)
+ {
+ $this->nextpath = $nextpath;
+ parent::__construct();
+ }
}
/*
* Class: NotFoundError
diff --git a/ratatoeskr/sys/utils.php b/ratatoeskr/sys/utils.php
index c2f8e66..4b4298f 100644
--- a/ratatoeskr/sys/utils.php
+++ b/ratatoeskr/sys/utils.php
@@ -1,9 +1,9 @@
<?php
/*
* File: ratatoeskr/sys/utils.php
- *
+ *
* Various useful helper functions.
- *
+ *
* License:
* This file is part of Ratatöskr.
* Ratatöskr is licensed unter the MIT / X11 License.
@@ -12,110 +12,110 @@
/*
* Function: array_repeat
- *
+ *
* Parameters:
- *
- * $val -
- * $n -
- *
+ *
+ * $val -
+ * $n -
+ *
* Returns:
- *
- * An array with $val $n-times repeated.
+ *
+ * An array with $val $n-times repeated.
*/
function array_repeat($val, $n)
{
- $rv = array();
- for($i = 0; $i < $n; ++$i)
- array_push($rv, $val);
- return $rv;
+ $rv = array();
+ for($i = 0; $i < $n; ++$i)
+ array_push($rv, $val);
+ return $rv;
}
/*
* Function: array_blend
- *
+ *
* Blend multiple arrays together.
- *
+ *
* Example:
- *
- * array_blend(array(1,2,3), array(4,5,6), array(7,8,9));
- * will return array(1,4,7,2,5,8,3,6,9)
+ *
+ * array_blend(array(1,2,3), array(4,5,6), array(7,8,9));
+ * will return array(1,4,7,2,5,8,3,6,9)
*/
function array_blend()
{
- $arrays = array_filter(func_get_args(), "is_array");
-
- switch(count($arrays))
- {
- case 0: return array(); break;
- case 1: return $arrays[0]; break;
- default:
- $rv = array();
- while(array_sum(array_map("count", $arrays)) > 0)
- {
- for($i = 0; $i < count($arrays); ++$i)
- {
- $val = array_shift($arrays[$i]);
- if($val === NULL)
- continue;
- array_push($rv, $val);
- }
- }
- return $rv;
- break;
- }
+ $arrays = array_filter(func_get_args(), "is_array");
+
+ switch(count($arrays))
+ {
+ case 0: return array(); break;
+ case 1: return $arrays[0]; break;
+ default:
+ $rv = array();
+ while(array_sum(array_map("count", $arrays)) > 0)
+ {
+ for($i = 0; $i < count($arrays); ++$i)
+ {
+ $val = array_shift($arrays[$i]);
+ if($val === NULL)
+ continue;
+ array_push($rv, $val);
+ }
+ }
+ return $rv;
+ break;
+ }
}
/*
* Function: array_filter_empty
- *
+ *
* Filters all empty elements out of an array.
*
* Parameters:
- *
- * $input - The input array
+ *
+ * $input - The input array
*
* Returns:
- *
- * The $input without its empty elements.
+ *
+ * The $input without its empty elements.
*/
function array_filter_empty($input)
{
- return array_filter($input, function($x){return !empty($x);});
+ return array_filter($input, function($x){return !empty($x);});
}
/*
* Function: array_filter_keys
- *
+ *
* Like PHPs `array_filter`, but callback will get the key, not the value of the array element.
*/
function array_filter_keys($input, $callback)
{
- if(!is_array($input))
- throw new InvalidArgumentException("Argument 1 must be an array");
- if(empty($input))
- return array();
- $delete_keys = array_filter(array_keys($input), function ($x) use ($callback) { return !$callback($x);});
- foreach($delete_keys as $key)
- unset($input[$key]);
- return $input;
+ if(!is_array($input))
+ throw new InvalidArgumentException("Argument 1 must be an array");
+ if(empty($input))
+ return array();
+ $delete_keys = array_filter(array_keys($input), function ($x) use ($callback) { return !$callback($x);});
+ foreach($delete_keys as $key)
+ unset($input[$key]);
+ return $input;
}
/*
* Function: array_kvpairs_to_assoc
* Convert array of key-value pairs to an associative array.
- *
+ *
* Parameters:
- * $input - Array of key-value pairs
- *
+ * $input - Array of key-value pairs
+ *
* Returns:
- * An associative array.
+ * An associative array.
*/
function array_kvpairs_to_assoc($input)
{
- $rv = array();
- foreach($input as $kvpair)
- $rv[$kvpair[0]] = $kvpair[1];
- return $rv;
+ $rv = array();
+ foreach($input as $kvpair)
+ $rv[$kvpair[0]] = $kvpair[1];
+ return $rv;
}
/*
@@ -124,79 +124,79 @@ function array_kvpairs_to_assoc($input)
*/
function intcmp($a, $b)
{
- return ($a == $b) ? 0 : (($a < $b) ? -1 : 1);
+ return ($a == $b) ? 0 : (($a < $b) ? -1 : 1);
}
/*
* Function: ucount
- *
+ *
* Count elements of an array matching unser-defined rules.
- *
+ *
* Parameters:
- * $array - The input array.
- * $callback - A callback function. It will be called with the current value as the only parameter. The value is counted, if callback returns TRUE.
+ * $array - The input array.
+ * $callback - A callback function. It will be called with the current value as the only parameter. The value is counted, if callback returns TRUE.
*
* Returns:
- *
- * Number of elements where $callback returned TRUE.
+ *
+ * Number of elements where $callback returned TRUE.
*/
function ucount($array, $callback)
{
- return count(array_filter($array, $callback));
+ return count(array_filter($array, $callback));
}
/*
* Function: vcount
- *
+ *
* Counts how often $value appears in $array.
- *
+ *
* Parameters:
- *
- * $array -
- * $value -
- *
+ *
+ * $array -
+ * $value -
+ *
* Returns:
- *
- * How often $value appears in $array.
+ *
+ * How often $value appears in $array.
*/
function vcount($array, $value)
{
- return ucount($array, function($x){return $x===$value;});
+ return ucount($array, function($x){return $x===$value;});
}
/*
* Function: self_url
- *
+ *
* Gets current URL.
- *
+ *
* From: http://dev.kanngard.net/Permalinks/ID_20050507183447.html
*/
function self_url() {
- $s = empty($_SERVER["HTTPS"]) ? ''
- : ($_SERVER["HTTPS"] == "on") ? "s"
- : "";
- $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
- $port = ($_SERVER["SERVER_PORT"] == "80") ? ""
- : (":".$_SERVER["SERVER_PORT"]);
- return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
+ $s = empty($_SERVER["HTTPS"]) ? ''
+ : ($_SERVER["HTTPS"] == "on") ? "s"
+ : "";
+ $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
+ $port = ($_SERVER["SERVER_PORT"] == "80") ? ""
+ : (":".$_SERVER["SERVER_PORT"]);
+ return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2) {
- return substr($s1, 0, strpos($s1, $s2));
+ return substr($s1, 0, strpos($s1, $s2));
}
/*
* Function: htmlesc
* Escape HTML (shorter than htmlspecialchars)
- *
+ *
* Parameters:
- * $text - Input text.
- *
+ * $text - Input text.
+ *
* Returns:
- * HTML
+ * HTML
*/
function htmlesc($text)
{
- return htmlspecialchars($text, ENT_QUOTES, "UTF-8");
+ return htmlspecialchars($text, ENT_QUOTES, "UTF-8");
}
/*
@@ -205,20 +205,20 @@ function htmlesc($text)
*/
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);
+ $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);
}
/*