aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornicosomb <nicolas@loeuillet.org>2013-04-21 19:32:19 +0200
committernicosomb <nicolas@loeuillet.org>2013-04-21 19:32:19 +0200
commitf0070a15e4725255dad967bde76155a39d189631 (patch)
tree69bfdf8ddbc09467be830274f434190b42979aa1
parent6f87a19714057e370a6b970bbfb82af5abd968f9 (diff)
downloadwallabag-f0070a15e4725255dad967bde76155a39d189631.tar.gz
wallabag-f0070a15e4725255dad967bde76155a39d189631.tar.zst
wallabag-f0070a15e4725255dad967bde76155a39d189631.zip
flash messages pour indiquer qu'une action s'est bien effectuée ou qu'il y a eu une erreur0.2
-rw-r--r--css/style.css17
-rwxr-xr-ximg/messages/close.pngbin0 -> 662 bytes
-rwxr-xr-ximg/messages/cross.pngbin0 -> 655 bytes
-rwxr-xr-ximg/messages/help.pngbin0 -> 786 bytes
-rwxr-xr-ximg/messages/tick.pngbin0 -> 537 bytes
-rwxr-xr-ximg/messages/warning.pngbin0 -> 666 bytes
-rw-r--r--inc/class.messages.php231
-rw-r--r--inc/config.php9
-rw-r--r--inc/functions.php10
-rw-r--r--index.php3
-rw-r--r--tpl/home.html3
-rw-r--r--tpl/messages.html1
12 files changed, 266 insertions, 8 deletions
diff --git a/css/style.css b/css/style.css
index 7fc8f056..36ebf85d 100644
--- a/css/style.css
+++ b/css/style.css
@@ -199,4 +199,19 @@ body.article {
199 } 199 }
200} 200}
201 201
202 202/*** ***/
203/*** MESSAGES ***/
204
205.messages { width: 100%; -moz-border-radius: 4px; border-radius: 4px; display: block; padding: 10px 0; margin: 10px auto 10px; clear: both; }
206.messages a.closeMessage { margin: -14px -8px 0 0; display:none; width: 16px; height: 16px; float: right; background: url(../img/messages/close.png) no-repeat; }
207/*.messages:hover a.closeMessage { visibility:visible; }*/
208.messages p { margin: 3px 0 3px 10px !important; padding: 0 10px 0 23px !important; font-size: 14px; line-height: 16px; }
209.messages.error { border: 1px solid #C42608; color: #c00 !important; background: #FFF0EF; }
210.messages.error p { background: url(../img/messages/cross.png ) no-repeat 0px 50%; color:#c00 !important; }
211.messages.success {background: #E0FBCC; border: 1px solid #6DC70C; }
212.messages.success p { background: url(../img/messages/tick.png) no-repeat 0px 50%; color: #2B6301 !important; }
213.messages.warning { background: #FFFCD3; border: 1px solid #EBCD41; color: #000; }
214.messages.warning p { background: url(../img/messages/warning.png ) no-repeat 0px 50%; color: #5F4E01; }
215.messages.information, .messages.info { background: #DFEBFB; border: 1px solid #82AEE7; }
216.messages.information p, .messages.info p { background: url(../img/messages/help.png ) no-repeat 0px 50%; color: #064393; }
217.messages.information a { text-decoration: underline; } \ No newline at end of file
diff --git a/img/messages/close.png b/img/messages/close.png
new file mode 100755
index 00000000..731aa018
--- /dev/null
+++ b/img/messages/close.png
Binary files differ
diff --git a/img/messages/cross.png b/img/messages/cross.png
new file mode 100755
index 00000000..1514d51a
--- /dev/null
+++ b/img/messages/cross.png
Binary files differ
diff --git a/img/messages/help.png b/img/messages/help.png
new file mode 100755
index 00000000..5c870176
--- /dev/null
+++ b/img/messages/help.png
Binary files differ
diff --git a/img/messages/tick.png b/img/messages/tick.png
new file mode 100755
index 00000000..a9925a06
--- /dev/null
+++ b/img/messages/tick.png
Binary files differ
diff --git a/img/messages/warning.png b/img/messages/warning.png
new file mode 100755
index 00000000..628cf2da
--- /dev/null
+++ b/img/messages/warning.png
Binary files differ
diff --git a/inc/class.messages.php b/inc/class.messages.php
new file mode 100644
index 00000000..6d515bf6
--- /dev/null
+++ b/inc/class.messages.php
@@ -0,0 +1,231 @@
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'></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 if( !array_key_exists('flash_messages', $_SESSION) ) $_SESSION['flash_messages'] = array();
63
64 }
65
66 /**
67 * Add a message to the queue
68 *
69 * @author Mike Everhart
70 *
71 * @param string $type The type of message to add
72 * @param string $message The message
73 * @param string $redirect_to (optional) If set, the user will be redirected to this URL
74 * @return bool
75 *
76 */
77 public function add($type, $message, $redirect_to=null) {
78
79 if( !isset($_SESSION['flash_messages']) ) return false;
80
81 if( !isset($type) || !isset($message[0]) ) return false;
82
83 // Replace any shorthand codes with their full version
84 if( strlen(trim($type)) == 1 ) {
85 $type = str_replace( array('h', 'i', 'w', 'e', 's'), array('help', 'info', 'warning', 'error', 'success'), $type );
86
87 // Backwards compatibility...
88 } elseif( $type == 'information' ) {
89 $type = 'info';
90 }
91
92 // Make sure it's a valid message type
93 if( !in_array($type, $this->msgTypes) ) die('"' . strip_tags($type) . '" is not a valid message type!' );
94
95 // If the session array doesn't exist, create it
96 if( !array_key_exists( $type, $_SESSION['flash_messages'] ) ) $_SESSION['flash_messages'][$type] = array();
97
98 $_SESSION['flash_messages'][$type][] = $message;
99
100 if( !is_null($redirect_to) ) {
101 header("Location: $redirect_to");
102 exit();
103 }
104
105 return true;
106
107 }
108
109 //-----------------------------------------------------------------------------------------------
110 // display()
111 // print queued messages to the screen
112 //-----------------------------------------------------------------------------------------------
113 /**
114 * Display the queued messages
115 *
116 * @author Mike Everhart
117 *
118 * @param string $type Which messages to display
119 * @param bool $print True = print the messages on the screen
120 * @return mixed
121 *
122 */
123 public function display($type='all', $print=true) {
124 $messages = '';
125 $data = '';
126
127 if( !isset($_SESSION['flash_messages']) ) return false;
128
129 if( $type == 'g' || $type == 'growl' ) {
130 $this->displayGrowlMessages();
131 return true;
132 }
133
134 // Print a certain type of message?
135 if( in_array($type, $this->msgTypes) ) {
136 foreach( $_SESSION['flash_messages'][$type] as $msg ) {
137 $messages .= $this->msgBefore . $msg . $this->msgAfter;
138 }
139
140 $data .= sprintf($this->msgWrapper, $this->msgClass, $type, $messages);
141
142 // Clear the viewed messages
143 $this->clear($type);
144
145 // Print ALL queued messages
146 } elseif( $type == 'all' ) {
147 foreach( $_SESSION['flash_messages'] as $type => $msgArray ) {
148 $messages = '';
149 foreach( $msgArray as $msg ) {
150 $messages .= $this->msgBefore . $msg . $this->msgAfter;
151 }
152 $data .= sprintf($this->msgWrapper, $this->msgClass, $type, $messages);
153 }
154
155 // Clear ALL of the messages
156 $this->clear();
157
158 // Invalid Message Type?
159 } else {
160 return false;
161 }
162
163 // Print everything to the screen or return the data
164 if( $print ) {
165 echo $data;
166 } else {
167 return $data;
168 }
169 }
170
171
172 /**
173 * Check to see if there are any queued error messages
174 *
175 * @author Mike Everhart
176 *
177 * @return bool true = There ARE error messages
178 * false = There are NOT any error messages
179 *
180 */
181 public function hasErrors() {
182 return empty($_SESSION['flash_messages']['error']) ? false : true;
183 }
184
185 /**
186 * Check to see if there are any ($type) messages queued
187 *
188 * @author Mike Everhart
189 *
190 * @param string $type The type of messages to check for
191 * @return bool
192 *
193 */
194 public function hasMessages($type=null) {
195 if( !is_null($type) ) {
196 if( !empty($_SESSION['flash_messages'][$type]) ) return $_SESSION['flash_messages'][$type];
197 } else {
198 foreach( $this->msgTypes as $type ) {
199 if( !empty($_SESSION['flash_messages']) ) return true;
200 }
201 }
202 return false;
203 }
204
205 /**
206 * Clear messages from the session data
207 *
208 * @author Mike Everhart
209 *
210 * @param string $type The type of messages to clear
211 * @return bool
212 *
213 */
214 public function clear($type='all') {
215 if( $type == 'all' ) {
216 unset($_SESSION['flash_messages']);
217 } else {
218 unset($_SESSION['flash_messages'][$type]);
219 }
220 return true;
221 }
222
223 public function __toString() { return $this->hasMessages(); }
224
225 public function __destruct() {
226 //$this->clear();
227 }
228
229
230} // end class
231?> \ No newline at end of file
diff --git a/inc/config.php b/inc/config.php
index cf3529cb..9d4b7fae 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -28,8 +28,12 @@ require_once 'Session.class.php';
28require_once 'store/store.class.php'; 28require_once 'store/store.class.php';
29require_once 'store/sqlite.class.php'; 29require_once 'store/sqlite.class.php';
30require_once 'store/file.class.php'; 30require_once 'store/file.class.php';
31require_once 'class.messages.php';
31 32
32$store = new $storage_type(); 33Session::init();
34
35$store = new $storage_type();
36$msg = new Messages();
33 37
34# initialisation de RainTPL 38# initialisation de RainTPL
35raintpl::$tpl_dir = './tpl/'; 39raintpl::$tpl_dir = './tpl/';
@@ -37,4 +41,5 @@ raintpl::$cache_dir = './cache/';
37raintpl::$base_url = get_poche_url(); 41raintpl::$base_url = get_poche_url();
38raintpl::configure('path_replace', false); 42raintpl::configure('path_replace', false);
39raintpl::configure('debug', false); 43raintpl::configure('debug', false);
40$tpl = new raintpl(); \ No newline at end of file 44$tpl = new raintpl();
45$tpl->assign('msg', $msg); \ No newline at end of file
diff --git a/inc/functions.php b/inc/functions.php
index ec5b3d6a..205f3968 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -125,6 +125,7 @@ function prepare_url($url)
125 } 125 }
126 } 126 }
127 127
128 $msg->add('e', 'error during url preparation');
128 logm('error during url preparation'); 129 logm('error during url preparation');
129 return FALSE; 130 return FALSE;
130} 131}
@@ -236,7 +237,7 @@ function remove_directory($directory)
236 237
237function display_view($view, $id = 0, $full_head = 'yes') 238function display_view($view, $id = 0, $full_head = 'yes')
238{ 239{
239 global $tpl, $store; 240 global $tpl, $store, $msg;
240 241
241 switch ($view) 242 switch ($view)
242 { 243 {
@@ -300,7 +301,7 @@ function display_view($view, $id = 0, $full_head = 'yes')
300 */ 301 */
301function action_to_do($action, $url, $id = 0) 302function action_to_do($action, $url, $id = 0)
302{ 303{
303 global $store; 304 global $store, $msg;
304 305
305 switch ($action) 306 switch ($action)
306 { 307 {
@@ -315,9 +316,11 @@ function action_to_do($action, $url, $id = 0)
315 if (DOWNLOAD_PICTURES) { 316 if (DOWNLOAD_PICTURES) {
316 $content = filtre_picture($parametres_url['content'], $url, $last_id); 317 $content = filtre_picture($parametres_url['content'], $url, $last_id);
317 } 318 }
319 $msg->add('s', 'the link has been added successfully');
318 } 320 }
319 } 321 }
320 else { 322 else {
323 $msg->add('e', 'the link has been added successfully');
321 logm($url . ' is not a valid url'); 324 logm($url . ' is not a valid url');
322 } 325 }
323 326
@@ -326,14 +329,17 @@ function action_to_do($action, $url, $id = 0)
326 case 'delete': 329 case 'delete':
327 remove_directory(ABS_PATH . $id); 330 remove_directory(ABS_PATH . $id);
328 $store->deleteById($id); 331 $store->deleteById($id);
332 $msg->add('s', 'the link has been deleted successfully');
329 logm('delete link #' . $id); 333 logm('delete link #' . $id);
330 break; 334 break;
331 case 'toggle_fav' : 335 case 'toggle_fav' :
332 $store->favoriteById($id); 336 $store->favoriteById($id);
337 $msg->add('s', 'the favorite toggle has been done successfully');
333 logm('mark as favorite link #' . $id); 338 logm('mark as favorite link #' . $id);
334 break; 339 break;
335 case 'toggle_archive' : 340 case 'toggle_archive' :
336 $store->archiveById($id); 341 $store->archiveById($id);
342 $msg->add('s', 'the archive toggle has been done successfully');
337 logm('archive link #' . $id); 343 logm('archive link #' . $id);
338 break; 344 break;
339 default: 345 default:
diff --git a/index.php b/index.php
index f64a0418..6eefd277 100644
--- a/index.php
+++ b/index.php
@@ -10,9 +10,8 @@
10 10
11include dirname(__FILE__).'/inc/config.php'; 11include dirname(__FILE__).'/inc/config.php';
12 12
13# initialize session
14myTool::initPhp(); 13myTool::initPhp();
15Session::init(); 14
16# XSRF protection with token 15# XSRF protection with token
17if (!empty($_POST)) { 16if (!empty($_POST)) {
18 if (!Session::isToken($_POST['token'])) { 17 if (!Session::isToken($_POST['token'])) {
diff --git a/tpl/home.html b/tpl/home.html
index 33aec78c..ad881997 100644
--- a/tpl/home.html
+++ b/tpl/home.html
@@ -15,4 +15,5 @@
15 <li><img src="img/up.png" onclick="sort_links('{$view}', 'ia');" title="by date asc" /> by date <img src="img/down.png" onclick="sort_links('{$view}', 'id');" title="by date desc" /></li> 15 <li><img src="img/up.png" onclick="sort_links('{$view}', 'ia');" title="by date asc" /> by date <img src="img/down.png" onclick="sort_links('{$view}', 'id');" title="by date desc" /></li>
16 <li><img src="img/up.png" onclick="sort_links('{$view}', 'ta');" title="by title asc" /> by title <img src="img/down.png" onclick="sort_links('{$view}', 'td');" title="by title desc" /></li> 16 <li><img src="img/up.png" onclick="sort_links('{$view}', 'ta');" title="by title asc" /> by title <img src="img/down.png" onclick="sort_links('{$view}', 'td');" title="by title desc" /></li>
17 </ul> 17 </ul>
18 {/if} \ No newline at end of file 18 {/if}
19 {include="messages"} \ No newline at end of file
diff --git a/tpl/messages.html b/tpl/messages.html
new file mode 100644
index 00000000..87af259b
--- /dev/null
+++ b/tpl/messages.html
@@ -0,0 +1 @@
<div id="messages"><?php echo $msg->display(); ?></div> \ No newline at end of file