From 63c0cf521f8097b0dadaf1228176dc38c7d897f6 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 15 May 2014 18:28:24 +0200 Subject: Working on config.tgz composition through config modules --- inc/database.inc.php | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ inc/db.inc.php | 79 ------------------------------------------ inc/message.inc.php | 14 +++++++- inc/render.inc.php | 18 ++++++++++ inc/request.inc.php | 45 ++++++++++++++++++++++++ inc/session.inc.php | 6 +++- inc/taskmanager.inc.php | 86 +++++++++++++++++++++++++++++++++++++++++++++ inc/util.inc.php | 19 ++++++++++ 8 files changed, 278 insertions(+), 81 deletions(-) create mode 100644 inc/database.inc.php delete mode 100644 inc/db.inc.php create mode 100644 inc/request.inc.php create mode 100644 inc/taskmanager.inc.php (limited to 'inc') diff --git a/inc/database.inc.php b/inc/database.inc.php new file mode 100644 index 00000000..70f50116 --- /dev/null +++ b/inc/database.inc.php @@ -0,0 +1,92 @@ + "SET NAMES utf8")); + } catch (PDOException $e) { + Util::traceError('Connecting to the local database failed: ' . $e->getMessage()); + } + } + + /** + * If you just need the first row of a query you can use this. + * Will return an associative array, or false if no row matches the query + */ + public static function queryFirst($query, $args = array()) + { + $res = self::simpleQuery($query, $args); + if ($res === false) return false; + return $res->fetch(PDO::FETCH_ASSOC); + } + + /** + * Execute the given query and return the number of rows affected. + * Mostly useful for UPDATEs or INSERTs + */ + public static function exec($query, $args = array()) + { + $res = self::simpleQuery($query, $args); + if ($res === false) return false; + return $res->rowCount(); + } + + /** + * Get id (promary key) of last row inserted. + * + * @return int the id + */ + public static function lastInsertId() + { + return self::$dbh->lastInsertId(); + } + + /** + * Execute the given query and return the corresponding PDOStatement object + * Note that this will re-use PDOStatements, so if you run the same + * query again with different params, do not rely on the first PDOStatement + * still being valid. If you need to do something fancy, use Database::prepare + */ + public static function simpleQuery($query, $args = array()) + { + self::init(); + try { + if (!isset(self::$statements[$query])) { + self::$statements[$query] = self::$dbh->prepare($query); + } else { + self::$statements[$query]->closeCursor(); + } + if (self::$statements[$query]->execute($args) === false) { + Util::traceError("Database Error: \n" . implode("\n", self::$statements[$query]->errorInfo())); + } + return self::$statements[$query]; + } catch (Exception $e) { + return false; + } + } + + /** + * Simply calls PDO::prepare and returns the PDOStatement. + * You must call PDOStatement::execute manually on it. + */ + public static function prepare($query) + { + self:init(); + return self::$dbh->prepare($query); + } + +} + diff --git a/inc/db.inc.php b/inc/db.inc.php deleted file mode 100644 index a797ae93..00000000 --- a/inc/db.inc.php +++ /dev/null @@ -1,79 +0,0 @@ - "SET NAMES utf8")); - } catch (PDOException $e) { - Util::traceError('Connecting to the local database failed: ' . $e->getMessage()); - } - } - - /** - * If you just need the first row of a query you can use this. - * Will return an associative array, or false if no row matches the query - */ - public static function queryFirst($query, $args = array()) - { - $res = self::simpleQuery($query, $args); - if ($res === false) return false; - return $res->fetch(PDO::FETCH_ASSOC); - } - - /** - * Execute the given query and return the number of rows affected. - * Mostly useful for UPDATEs or INSERTs - */ - public static function exec($query, $args = array()) - { - $res = self::simpleQuery($query, $args); - if ($res === false) return false; - return $res->rowCount(); - } - - /** - * Execute the given query and return the corresponding PDOStatement object - * Note that this will re-use PDOStatements, so if you run the same - * query again with different params, do not rely on the first PDOStatement - * still being valid. If you need to do something fancy, use Database::prepare - */ - public static function simpleQuery($query, $args = array()) - { - self::init(); - //if (empty($args)) Util::traceError('Query with zero arguments!'); - if (!isset(self::$statements[$query])) { - self::$statements[$query] = self::$dbh->prepare($query); - } else { - self::$statements[$query]->closeCursor(); - } - if (self::$statements[$query]->execute($args) === false) { - Util::traceError("Database Error: \n" . implode("\n", self::$statements[$query]->errorInfo())); - } - return self::$statements[$query]; - } - - /** - * Simply calls PDO::prepare and returns the PDOStatement. - * You must call PDOStatement::execute manually on it. - */ - public static function prepare($query) - { - self:init(); - return self::$dbh->prepare($query); - } - -} - diff --git a/inc/message.inc.php b/inc/message.inc.php index 3117630b..6c95764c 100644 --- a/inc/message.inc.php +++ b/inc/message.inc.php @@ -1,6 +1,7 @@ 'Benutzername oder Kennwort falsch', 'token' => 'Ungültiges Token. CSRF Angriff?', @@ -21,11 +22,21 @@ $error_text = array( 'upload-failed' => 'Upload von {{0}} schlug fehl!', 'config-activated' => 'Konfiguration wurde aktiviert', 'error-write' => 'Fehler beim Schreiben von {{0}}', + 'error-read' => 'Fehler beim Lesen von {{0}}', + 'error-archive' => 'Korruptes Archiv oder nicht unterstütztes Format', + 'error-rename' => 'Konnte {{0}} nicht in {{1}} umbenennen', + 'error-nodir' => 'Das Verzeichnis {{0}} existiert nicht.', + 'empty-archive' => 'Das Archiv enthält keine Dateien oder Verzeichnisse', + 'error-extract' => 'Konnte Archiv nicht nach {{0}} entpacken - {{1}}', + 'module-added' => 'Modul erfolgreich hinzugefügt', + 'taskmanager-error' => 'Verbindung zum Taskmanager fehlgeschlagen', + 'task-error' => 'Ausführung fehlgeschlagen: {{0}}', ); class Message { private static $list = array(); + private static $alreadyDisplayed = array(); private static $flushed = false; /** @@ -83,6 +94,7 @@ class Message $message = str_replace('{{' . $index . '}}', $text, $message); } Render::addTemplate('messagebox-' . $item['type'], array('message' => $message)); + self::$alreadyDisplayed[] = $item; } self::$list = array(); self::$flushed = true; @@ -109,7 +121,7 @@ class Message public static function toRequest() { $parts = array(); - foreach (self::$list as $item) { + foreach (array_merge(self::$list, self::$alreadyDisplayed) as $item) { $str = 'message[]=' . urlencode($item['type'] . '|' .$item['id']); if (!empty($item['params'])) { $str .= '|' . implode('|', $item['params']); diff --git a/inc/render.inc.php b/inc/render.inc.php index a3cef516..dff32798 100644 --- a/inc/render.inc.php +++ b/inc/render.inc.php @@ -39,6 +39,7 @@ class Render