From a20f96b76dfe6faf8b4d841ee464a95ea54c35b3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Sun, 18 Jan 2015 22:11:41 +0100 Subject: [PATCH] replace flash messages library --- composer.json | 9 +- composer.lock | 51 ++++++- inc/3rdparty/class.messages.php | 232 -------------------------------- inc/poche/global.inc.php | 1 - 4 files changed, 57 insertions(+), 236 deletions(-) delete mode 100644 inc/3rdparty/class.messages.php diff --git a/composer.json b/composer.json index 11eaa561..3bb7bf07 100644 --- a/composer.json +++ b/composer.json @@ -22,12 +22,19 @@ "email": "hello@wallabag.org", "issues": "https://github.com/wallabag/wallabag/issues" }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/wallabag/PHP-Flash-Messages" + } + ], "require": { "twig/twig": "1.*", "twig/extensions": "1.0.*", "umpirsky/twig-gettext-extractor": "1.1.*", "fabpot/goutte": "2.0.*@dev", "ezyang/htmlpurifier": "dev-master", - "mgargano/simplehtmldom": "dev-master" + "mgargano/simplehtmldom": "dev-master", + "wallabag/PHP-Flash-Messages": "dev-master" } } \ No newline at end of file diff --git a/composer.lock b/composer.lock index baf59eef..a984ce52 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "67435ca652abe6c90bdd29701ecd679a", + "hash": "f5e69c21a929d0997c771526484a9d7e", "packages": [ { "name": "ezyang/htmlpurifier", @@ -1335,6 +1335,52 @@ ], "description": "The Twig Gettext Extractor is Poedit friendly tool which extracts translations from twig templates.", "time": "2013-02-14 16:41:48" + }, + { + "name": "wallabag/php-flash-messages", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wallabag/PHP-Flash-Messages.git", + "reference": "ea68eb768f32156baa15f7a3cd880ba8ff5af6ab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wallabag/PHP-Flash-Messages/zipball/ea68eb768f32156baa15f7a3cd880ba8ff5af6ab", + "reference": "ea68eb768f32156baa15f7a3cd880ba8ff5af6ab", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "files": [ + "class.messages.php" + ] + }, + "license": [ + "Apache" + ], + "authors": [ + { + "name": "Nicolas Lœuillet", + "email": "nicolas@loeuillet.org", + "homepage": "http://www.cdetc.fr" + } + ], + "description": "Session-based Flash Messages class for PHP", + "homepage": "https://github.com/wallabag/PHP-Flash-Messages", + "keywords": [ + "flash", + "messages", + "php-flash-messages", + "sessions" + ], + "support": { + "source": "https://github.com/wallabag/PHP-Flash-Messages/tree/master" + }, + "time": "2015-01-18 19:51:55" } ], "packages-dev": [], @@ -1343,7 +1389,8 @@ "stability-flags": { "fabpot/goutte": 20, "ezyang/htmlpurifier": 20, - "mgargano/simplehtmldom": 20 + "mgargano/simplehtmldom": 20, + "wallabag/php-flash-messages": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/inc/3rdparty/class.messages.php b/inc/3rdparty/class.messages.php deleted file mode 100644 index fbca0df0..00000000 --- a/inc/3rdparty/class.messages.php +++ /dev/null @@ -1,232 +0,0 @@ -×\n%s\n"; - var $msgBefore = '

'; - var $msgAfter = "

\n"; - - - /** - * Constructor - * @author Mike Everhart - */ - public function __construct() { - - // Generate a unique ID for this user and session - $this->msgId = md5(uniqid()); - - // Create the session array if it doesnt already exist - settype($_SESSION, 'array'); - if( !array_key_exists('flash_messages', $_SESSION) ) $_SESSION['flash_messages'] = array(); - - } - - /** - * Add a message to the queue - * - * @author Mike Everhart - * - * @param string $type The type of message to add - * @param string $message The message - * @param string $redirect_to (optional) If set, the user will be redirected to this URL - * @return bool - * - */ - public function add($type, $message, $redirect_to=null) { - - if( !isset($_SESSION['flash_messages']) ) return false; - - if( !isset($type) || !isset($message[0]) ) return false; - - // Replace any shorthand codes with their full version - if( strlen(trim($type)) == 1 ) { - $type = str_replace( array('h', 'i', 'w', 'e', 's'), array('help', 'info', 'warning', 'error', 'success'), $type ); - - // Backwards compatibility... - } elseif( $type == 'information' ) { - $type = 'info'; - } - - // Make sure it's a valid message type - if( !in_array($type, $this->msgTypes) ) die('"' . strip_tags($type) . '" is not a valid message type!' ); - - // If the session array doesn't exist, create it - if( !array_key_exists( $type, $_SESSION['flash_messages'] ) ) $_SESSION['flash_messages'][$type] = array(); - - $_SESSION['flash_messages'][$type][] = $message; - - if( !is_null($redirect_to) ) { - header("Location: $redirect_to"); - exit(); - } - - return true; - - } - - //----------------------------------------------------------------------------------------------- - // display() - // print queued messages to the screen - //----------------------------------------------------------------------------------------------- - /** - * Display the queued messages - * - * @author Mike Everhart - * - * @param string $type Which messages to display - * @param bool $print True = print the messages on the screen - * @return mixed - * - */ - public function display($type='all', $print=true) { - $messages = ''; - $data = ''; - - if( !isset($_SESSION['flash_messages']) ) return false; - - if( $type == 'g' || $type == 'growl' ) { - $this->displayGrowlMessages(); - return true; - } - - // Print a certain type of message? - if( in_array($type, $this->msgTypes) ) { - foreach( $_SESSION['flash_messages'][$type] as $msg ) { - $messages .= $this->msgBefore . $msg . $this->msgAfter; - } - - $data .= sprintf($this->msgWrapper, $this->msgClass, $type, $messages); - - // Clear the viewed messages - $this->clear($type); - - // Print ALL queued messages - } elseif( $type == 'all' ) { - foreach( $_SESSION['flash_messages'] as $type => $msgArray ) { - $messages = ''; - foreach( $msgArray as $msg ) { - $messages .= $this->msgBefore . $msg . $this->msgAfter; - } - $data .= sprintf($this->msgWrapper, $this->msgClass, $type, $messages); - } - - // Clear ALL of the messages - $this->clear(); - - // Invalid Message Type? - } else { - return false; - } - - // Print everything to the screen or return the data - if( $print ) { - echo $data; - } else { - return $data; - } - } - - - /** - * Check to see if there are any queued error messages - * - * @author Mike Everhart - * - * @return bool true = There ARE error messages - * false = There are NOT any error messages - * - */ - public function hasErrors() { - return empty($_SESSION['flash_messages']['error']) ? false : true; - } - - /** - * Check to see if there are any ($type) messages queued - * - * @author Mike Everhart - * - * @param string $type The type of messages to check for - * @return bool - * - */ - public function hasMessages($type=null) { - if( !is_null($type) ) { - if( !empty($_SESSION['flash_messages'][$type]) ) return $_SESSION['flash_messages'][$type]; - } else { - foreach( $this->msgTypes as $type ) { - if( !empty($_SESSION['flash_messages']) ) return true; - } - } - return false; - } - - /** - * Clear messages from the session data - * - * @author Mike Everhart - * - * @param string $type The type of messages to clear - * @return bool - * - */ - public function clear($type='all') { - if( $type == 'all' ) { - unset($_SESSION['flash_messages']); - } else { - unset($_SESSION['flash_messages'][$type]); - } - return true; - } - - public function __toString() { return $this->hasMessages(); } - - public function __destruct() { - //$this->clear(); - } - - -} // end class -?> diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php index 1ecef8bf..3e04b383 100755 --- a/inc/poche/global.inc.php +++ b/inc/poche/global.inc.php @@ -17,7 +17,6 @@ define('ROOT', INCLUDES . '/..'); require_once INCLUDES . '/poche/Tools.class.php'; require_once INCLUDES . '/poche/User.class.php'; require_once INCLUDES . '/poche/Url.class.php'; -require_once INCLUDES . '/3rdparty/class.messages.php'; require_once ROOT . '/vendor/autoload.php'; require_once INCLUDES . '/poche/Template.class.php'; require_once INCLUDES . '/poche/Language.class.php'; -- 2.41.0