aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas Lœuillet <nicolas@loeuillet.org>2015-01-18 22:11:41 +0100
committerNicolas Lœuillet <nicolas@loeuillet.org>2015-01-18 22:11:41 +0100
commita20f96b76dfe6faf8b4d841ee464a95ea54c35b3 (patch)
treee57c09232b399d38d463740771f4eed7d1d41fa7
parentadf17b677edeb2387671f6a0f12123e7497b5938 (diff)
downloadwallabag-a20f96b76dfe6faf8b4d841ee464a95ea54c35b3.tar.gz
wallabag-a20f96b76dfe6faf8b4d841ee464a95ea54c35b3.tar.zst
wallabag-a20f96b76dfe6faf8b4d841ee464a95ea54c35b3.zip
replace flash messages library
-rw-r--r--composer.json9
-rw-r--r--composer.lock51
-rw-r--r--inc/3rdparty/class.messages.php232
-rwxr-xr-xinc/poche/global.inc.php1
4 files changed, 57 insertions, 236 deletions
diff --git a/composer.json b/composer.json
index 11eaa561..3bb7bf07 100644
--- a/composer.json
+++ b/composer.json
@@ -22,12 +22,19 @@
22 "email": "hello@wallabag.org", 22 "email": "hello@wallabag.org",
23 "issues": "https://github.com/wallabag/wallabag/issues" 23 "issues": "https://github.com/wallabag/wallabag/issues"
24 }, 24 },
25 "repositories": [
26 {
27 "type": "vcs",
28 "url": "https://github.com/wallabag/PHP-Flash-Messages"
29 }
30 ],
25 "require": { 31 "require": {
26 "twig/twig": "1.*", 32 "twig/twig": "1.*",
27 "twig/extensions": "1.0.*", 33 "twig/extensions": "1.0.*",
28 "umpirsky/twig-gettext-extractor": "1.1.*", 34 "umpirsky/twig-gettext-extractor": "1.1.*",
29 "fabpot/goutte": "2.0.*@dev", 35 "fabpot/goutte": "2.0.*@dev",
30 "ezyang/htmlpurifier": "dev-master", 36 "ezyang/htmlpurifier": "dev-master",
31 "mgargano/simplehtmldom": "dev-master" 37 "mgargano/simplehtmldom": "dev-master",
38 "wallabag/PHP-Flash-Messages": "dev-master"
32 } 39 }
33} \ No newline at end of file 40} \ 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 @@
4 "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 4 "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5 "This file is @generated automatically" 5 "This file is @generated automatically"
6 ], 6 ],
7 "hash": "67435ca652abe6c90bdd29701ecd679a", 7 "hash": "f5e69c21a929d0997c771526484a9d7e",
8 "packages": [ 8 "packages": [
9 { 9 {
10 "name": "ezyang/htmlpurifier", 10 "name": "ezyang/htmlpurifier",
@@ -1335,6 +1335,52 @@
1335 ], 1335 ],
1336 "description": "The Twig Gettext Extractor is Poedit friendly tool which extracts translations from twig templates.", 1336 "description": "The Twig Gettext Extractor is Poedit friendly tool which extracts translations from twig templates.",
1337 "time": "2013-02-14 16:41:48" 1337 "time": "2013-02-14 16:41:48"
1338 },
1339 {
1340 "name": "wallabag/php-flash-messages",
1341 "version": "dev-master",
1342 "source": {
1343 "type": "git",
1344 "url": "https://github.com/wallabag/PHP-Flash-Messages.git",
1345 "reference": "ea68eb768f32156baa15f7a3cd880ba8ff5af6ab"
1346 },
1347 "dist": {
1348 "type": "zip",
1349 "url": "https://api.github.com/repos/wallabag/PHP-Flash-Messages/zipball/ea68eb768f32156baa15f7a3cd880ba8ff5af6ab",
1350 "reference": "ea68eb768f32156baa15f7a3cd880ba8ff5af6ab",
1351 "shasum": ""
1352 },
1353 "require": {
1354 "php": ">=5.3.0"
1355 },
1356 "type": "library",
1357 "autoload": {
1358 "files": [
1359 "class.messages.php"
1360 ]
1361 },
1362 "license": [
1363 "Apache"
1364 ],
1365 "authors": [
1366 {
1367 "name": "Nicolas Lœuillet",
1368 "email": "nicolas@loeuillet.org",
1369 "homepage": "http://www.cdetc.fr"
1370 }
1371 ],
1372 "description": "Session-based Flash Messages class for PHP",
1373 "homepage": "https://github.com/wallabag/PHP-Flash-Messages",
1374 "keywords": [
1375 "flash",
1376 "messages",
1377 "php-flash-messages",
1378 "sessions"
1379 ],
1380 "support": {
1381 "source": "https://github.com/wallabag/PHP-Flash-Messages/tree/master"
1382 },
1383 "time": "2015-01-18 19:51:55"
1338 } 1384 }
1339 ], 1385 ],
1340 "packages-dev": [], 1386 "packages-dev": [],
@@ -1343,7 +1389,8 @@
1343 "stability-flags": { 1389 "stability-flags": {
1344 "fabpot/goutte": 20, 1390 "fabpot/goutte": 20,
1345 "ezyang/htmlpurifier": 20, 1391 "ezyang/htmlpurifier": 20,
1346 "mgargano/simplehtmldom": 20 1392 "mgargano/simplehtmldom": 20,
1393 "wallabag/php-flash-messages": 20
1347 }, 1394 },
1348 "prefer-stable": false, 1395 "prefer-stable": false,
1349 "prefer-lowest": false, 1396 "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 @@
1<?php
2//--------------------------------------------------------------------------------------------------
3// Session-Based Flash Messages v1.0
4// Copyright 2012 Mike Everhart (http://mikeeverhart.net)
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//
18//------------------------------------------------------------------------------
19// Description:
20//------------------------------------------------------------------------------
21//
22// Stores messages in Session data to be easily retrieved later on.
23// This class includes four different types of messages:
24// - Success
25// - Error
26// - Warning
27// - Information
28//
29// See README for basic usage instructions, or see samples/index.php for more advanced samples
30//
31//--------------------------------------------------------------------------------------------------
32// Changelog
33//--------------------------------------------------------------------------------------------------
34//
35// 2011-05-15 - v1.0 - Initial Version
36//
37//--------------------------------------------------------------------------------------------------
38
39class Messages {
40
41 //-----------------------------------------------------------------------------------------------
42 // Class Variables
43 //-----------------------------------------------------------------------------------------------
44 var $msgId;
45 var $msgTypes = array( 'help', 'info', 'warning', 'success', 'error' );
46 var $msgClass = 'messages';
47 var $msgWrapper = "<div class='%s %s'><a href='#' class='closeMessage'>&times;</a>\n%s</div>\n";
48 var $msgBefore = '<p>';
49 var $msgAfter = "</p>\n";
50
51
52 /**
53 * Constructor
54 * @author Mike Everhart
55 */
56 public function __construct() {
57
58 // Generate a unique ID for this user and session
59 $this->msgId = md5(uniqid());
60
61 // Create the session array if it doesnt already exist
62 settype($_SESSION, 'array');
63 if( !array_key_exists('flash_messages', $_SESSION) ) $_SESSION['flash_messages'] = array();
64
65 }
66
67 /**
68 * Add a message to the queue
69 *
70 * @author Mike Everhart
71 *
72 * @param string $type The type of message to add
73 * @param string $message The message
74 * @param string $redirect_to (optional) If set, the user will be redirected to this URL
75 * @return bool
76 *
77 */
78 public function add($type, $message, $redirect_to=null) {
79
80 if( !isset($_SESSION['flash_messages']) ) return false;
81
82 if( !isset($type) || !isset($message[0]) ) return false;
83
84 // Replace any shorthand codes with their full version
85 if( strlen(trim($type)) == 1 ) {
86 $type = str_replace( array('h', 'i', 'w', 'e', 's'), array('help', 'info', 'warning', 'error', 'success'), $type );
87
88 // Backwards compatibility...
89 } elseif( $type == 'information' ) {
90 $type = 'info';
91 }
92
93 // Make sure it's a valid message type
94 if( !in_array($type, $this->msgTypes) ) die('"' . strip_tags($type) . '" is not a valid message type!' );
95
96 // If the session array doesn't exist, create it
97 if( !array_key_exists( $type, $_SESSION['flash_messages'] ) ) $_SESSION['flash_messages'][$type] = array();
98
99 $_SESSION['flash_messages'][$type][] = $message;
100
101 if( !is_null($redirect_to) ) {
102 header("Location: $redirect_to");
103 exit();
104 }
105
106 return true;
107
108 }
109
110 //-----------------------------------------------------------------------------------------------
111 // display()
112 // print queued messages to the screen
113 //-----------------------------------------------------------------------------------------------
114 /**
115 * Display the queued messages
116 *
117 * @author Mike Everhart
118 *
119 * @param string $type Which messages to display
120 * @param bool $print True = print the messages on the screen
121 * @return mixed
122 *
123 */
124 public function display($type='all', $print=true) {
125 $messages = '';
126 $data = '';
127
128 if( !isset($_SESSION['flash_messages']) ) return false;
129
130 if( $type == 'g' || $type == 'growl' ) {
131 $this->displayGrowlMessages();
132 return true;
133 }
134
135 // Print a certain type of message?
136 if( in_array($type, $this->msgTypes) ) {
137 foreach( $_SESSION['flash_messages'][$type] as $msg ) {
138 $messages .= $this->msgBefore . $msg . $this->msgAfter;
139 }
140
141 $data .= sprintf($this->msgWrapper, $this->msgClass, $type, $messages);
142
143 // Clear the viewed messages
144 $this->clear($type);
145
146 // Print ALL queued messages
147 } elseif( $type == 'all' ) {
148 foreach( $_SESSION['flash_messages'] as $type => $msgArray ) {
149 $messages = '';
150 foreach( $msgArray as $msg ) {
151 $messages .= $this->msgBefore . $msg . $this->msgAfter;
152 }
153 $data .= sprintf($this->msgWrapper, $this->msgClass, $type, $messages);
154 }
155
156 // Clear ALL of the messages
157 $this->clear();
158
159 // Invalid Message Type?
160 } else {
161 return false;
162 }
163
164 // Print everything to the screen or return the data
165 if( $print ) {
166 echo $data;
167 } else {
168 return $data;
169 }
170 }
171
172
173 /**
174 * Check to see if there are any queued error messages
175 *
176 * @author Mike Everhart
177 *
178 * @return bool true = There ARE error messages
179 * false = There are NOT any error messages
180 *
181 */
182 public function hasErrors() {
183 return empty($_SESSION['flash_messages']['error']) ? false : true;
184 }
185
186 /**
187 * Check to see if there are any ($type) messages queued
188 *
189 * @author Mike Everhart
190 *
191 * @param string $type The type of messages to check for
192 * @return bool
193 *
194 */
195 public function hasMessages($type=null) {
196 if( !is_null($type) ) {
197 if( !empty($_SESSION['flash_messages'][$type]) ) return $_SESSION['flash_messages'][$type];
198 } else {
199 foreach( $this->msgTypes as $type ) {
200 if( !empty($_SESSION['flash_messages']) ) return true;
201 }
202 }
203 return false;
204 }
205
206 /**
207 * Clear messages from the session data
208 *
209 * @author Mike Everhart
210 *
211 * @param string $type The type of messages to clear
212 * @return bool
213 *
214 */
215 public function clear($type='all') {
216 if( $type == 'all' ) {
217 unset($_SESSION['flash_messages']);
218 } else {
219 unset($_SESSION['flash_messages'][$type]);
220 }
221 return true;
222 }
223
224 public function __toString() { return $this->hasMessages(); }
225
226 public function __destruct() {
227 //$this->clear();
228 }
229
230
231} // end class
232?>
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 . '/..');
17require_once INCLUDES . '/poche/Tools.class.php'; 17require_once INCLUDES . '/poche/Tools.class.php';
18require_once INCLUDES . '/poche/User.class.php'; 18require_once INCLUDES . '/poche/User.class.php';
19require_once INCLUDES . '/poche/Url.class.php'; 19require_once INCLUDES . '/poche/Url.class.php';
20require_once INCLUDES . '/3rdparty/class.messages.php';
21require_once ROOT . '/vendor/autoload.php'; 20require_once ROOT . '/vendor/autoload.php';
22require_once INCLUDES . '/poche/Template.class.php'; 21require_once INCLUDES . '/poche/Template.class.php';
23require_once INCLUDES . '/poche/Language.class.php'; 22require_once INCLUDES . '/poche/Language.class.php';