JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
metaform: merge ckeditor settings from cms
[wfpl.git] / session_messages.php
1 <?php
2
3 #  Copyright (C) 2007 Jason Woofenden
4 #
5 #  This program is free software: you can redistribute it and/or modify
6 #  it under the terms of the GNU General Public License as published by
7 #  the Free Software Foundation, either version 3 of the License, or
8 #  (at your option) any later version.
9 #  
10 #  This program is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #  GNU General Public License for more details.
14 #  
15 #  You should have received a copy of the GNU General Public License
16 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18
19 # require_once() this file instead of messages.php if you'd like to store
20 # save/restore messages in the session accross redirect()s. That's all you have
21 # to do. These functions are called when needed (from redirect() and
22 # display_messages()) if they are defined.
23
24 # see messages.php for documentation on how to use it.
25
26 require_once(__DIR__.'/'.'session.php');
27 require_once(__DIR__.'/'.'messages.php');
28
29 function session_save_messages() {
30         if(!isset($GLOBALS['wfpl_messages'])) {
31                 return;
32         }
33         if(!is_array($GLOBALS['wfpl_messages'])) {
34                 return;
35         }
36         if(!count($GLOBALS['wfpl_messages'])) {
37                 return;
38         }
39
40         init_session();
41         session_set('wfpl_messages', json_encode($GLOBALS['wfpl_messages']));
42 }
43
44 function session_restore_messages() {
45         if(session_exists()) {
46                 $messages = session_get('wfpl_messages');
47                 if($messages !== false) {
48                         session_clear('wfpl_messages');
49                         $messages = json_decode($messages, true);
50                         if ($messages !== null) {
51                                 return $messages;
52                         }
53                 }
54         }
55         return array();
56 }