1 | <?php |
---|
2 | |
---|
3 | // +-----------------------------------------------------------------------+ |
---|
4 | // | Piwigo - a PHP based picture gallery | |
---|
5 | // +-----------------------------------------------------------------------+ |
---|
6 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
7 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
8 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
9 | // +-----------------------------------------------------------------------+ |
---|
10 | // | This program is free software; you can redistribute it and/or modify | |
---|
11 | // | it under the terms of the GNU General Public License as published by | |
---|
12 | // | the Free Software Foundation | |
---|
13 | // | | |
---|
14 | // | This program is distributed in the hope that it will be useful, but | |
---|
15 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
16 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
17 | // | General Public License for more details. | |
---|
18 | // | | |
---|
19 | // | You should have received a copy of the GNU General Public License | |
---|
20 | // | along with this program; if not, write to the Free Software | |
---|
21 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
22 | // | USA. | |
---|
23 | // +-----------------------------------------------------------------------+ |
---|
24 | |
---|
25 | // Keeps file coded in UTF-8 without BOM : é |
---|
26 | |
---|
27 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
28 | |
---|
29 | global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values, $ec_debug; |
---|
30 | |
---|
31 | // --------------------------------------------------------------------------- |
---|
32 | // $ec_conf initalization |
---|
33 | // --------------------------------------------------------------------------- |
---|
34 | |
---|
35 | // $ec_conf has numeric indexes (instead of string keys like 'activated', |
---|
36 | // 'howto'...) because of its first reading, done with the "explode" function. |
---|
37 | // It would be very easy to build a string keys indexed array, thanks to |
---|
38 | // following instructions : |
---|
39 | /* |
---|
40 | $t = pwg_db_fetch_row(pwg_query(" |
---|
41 | SELECT `value` |
---|
42 | FROM `".CONFIG_TABLE."` |
---|
43 | WHERE `param` = 'event_cats'; |
---|
44 | ")); |
---|
45 | $ec_conf_temp = explode(',', $t[0]); |
---|
46 | $ec_conf = array(); $i = 0; |
---|
47 | foreach ($ec_conf_default as $k => $v) $ec_conf[$k] = ec_conf_temp[$i++]; |
---|
48 | */ |
---|
49 | // Though, I prefer to keep $ec_conf with numeric indexes, so to be compelled |
---|
50 | // to go through function change_ec_conf() to modify ec_conf, and thus update |
---|
51 | // the DB at the same time. |
---|
52 | |
---|
53 | //---------------------------------------------------------------------------- |
---|
54 | // The following lines allow to change the number of configuration items, the |
---|
55 | // default values they can have, and also their possible other values, very |
---|
56 | // quickly. |
---|
57 | |
---|
58 | // Give possible $ec_conf values. In case values cannot be predicted, just |
---|
59 | // provide an empty array : array() . |
---|
60 | $ec_conf_possible_values = array( |
---|
61 | 'activated' => array('0', '1'), // 0 |
---|
62 | 'howto' => array('0', '1'), // 1 |
---|
63 | 'dup_allow' => array('0', '1', '2'), // 2 |
---|
64 | 'duplic_display' => array('0', '1', '2'), // 3 |
---|
65 | 'auto_code_dg_nb' => array( '4', '5', '8', '10', '12', '15', |
---|
66 | '16', '20', '24', '25', '30', '32'), // 4 |
---|
67 | 'unknown_code' => array('0', '1', '2'), // 5 |
---|
68 | 'unknown_code_ap_id' => array(), // 6 |
---|
69 | 'comment_display' => array('0', '1'), // 7 |
---|
70 | 'in_help_display' => array('0', '1'), // 8 |
---|
71 | 'display_connection' => array('0', '1'), // 9 |
---|
72 | 'simple_mode_on' => array('0', '1'), // 10 |
---|
73 | 'display_full_button' => array('0', '1'), // 11 |
---|
74 | ); |
---|
75 | |
---|
76 | // $ec_conf_index is an array of the indexes of $ec_conf. Thus does it allow |
---|
77 | // to check if X exists when asking for $ec_conf[X]. |
---|
78 | $ec_conf_index = array_flip(array_keys($ec_conf_possible_values)); |
---|
79 | |
---|
80 | // Get current value of $ec_conf, if the entry in the DB exists. |
---|
81 | $t = array(); $u = '0'; $v = false; $w = false; $ec_conf = array(); $s = '0'; |
---|
82 | if ($w = ( // $w becomes true if the query succeeds <=> if EC was already in |
---|
83 | // $t gets event_cats config value, as an array with one unique entry |
---|
84 | ($t = pwg_db_fetch_row(pwg_query(" |
---|
85 | SELECT `value` |
---|
86 | FROM `".CONFIG_TABLE."` |
---|
87 | WHERE `param` = 'event_cats'; |
---|
88 | "))) !== false) |
---|
89 | ) { |
---|
90 | $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index)); |
---|
91 | $u = $ec_conf[0]; |
---|
92 | $s = ($v) ? $ec_conf[1] : '0'; // the aknowledgement message is displayed |
---|
93 | // again if the configuration changes |
---|
94 | } |
---|
95 | if ($v and !$w) die('$v true with $w false in ec_conf.inc.php'); |
---|
96 | // $w is false if the entry in the table doesn't exist; |
---|
97 | // $v is false if the entry in the table doesn't exist; or exists, but its |
---|
98 | // number of parameters is different than the number of default parameters. |
---|
99 | // $u is '0' if the plugin has not yet been activated, '1' if it has been. |
---|
100 | // $s allows to display the aknowledgement message when config changes. |
---|
101 | // If $v or $w are false, all $ec_conf values are set to default values. But |
---|
102 | // default values must first take values specified in $conf, if they are set. |
---|
103 | |
---|
104 | // Determine whether simple mode is ON or OFF |
---|
105 | $simple_mode_on = ( |
---|
106 | (!$v and !$w) or ( |
---|
107 | // $ec_conf[10] <=> read_ec_conf('simple_mode_on') |
---|
108 | isset($ec_conf[10]) and $ec_conf[10] == '1' |
---|
109 | ) or ( |
---|
110 | isset($conf['ec_display_full_button']) and |
---|
111 | $conf['ec_display_full_button'] == false |
---|
112 | ) |
---|
113 | ); |
---|
114 | |
---|
115 | if (!$v) { |
---|
116 | // Give configuration items names and default values. Only strings. |
---|
117 | $ec_conf_default = array( // PLUGIN CONFIGURATION ($ec_conf) : |
---|
118 | // --------------------------------- |
---|
119 | 'activated' // 0 // plugin activated, 0 or 1 |
---|
120 | => $u, // |
---|
121 | // |
---|
122 | 'howto' // 1 // whether the small aknowledgement message has |
---|
123 | => $s, // already been displayed, 0 or 1 |
---|
124 | // |
---|
125 | 'dup_allow' => ($simple_mode_on and isset($conf['ec_dup_allow']) and |
---|
126 | in_array($conf['ec_dup_allow'], |
---|
127 | $ec_conf_possible_values['ec_dup_allow'])) ? |
---|
128 | $conf['ec_dup_allow'] : (isset($ec_conf[2]) and in_array($ec_conf[2], |
---|
129 | $ec_conf_possible_values['dup_allow'])) ? $ec_conf[2] : '2', |
---|
130 | // 2 // duplication allowance : |
---|
131 | // 0 : no account; |
---|
132 | // 1 : all accounts; |
---|
133 | // 2 : specified by group, type, and user ids. |
---|
134 | // If Event Cats is in "simple mode", takes the |
---|
135 | // value of $conf['ec_dup_allow'] if it is set; |
---|
136 | // and an allowance to duplicate only generic |
---|
137 | // accounts will be defined. |
---|
138 | // |
---|
139 | 'duplic_display' => ($simple_mode_on and isset($conf['ec_duplic_display']) |
---|
140 | and in_array($conf['ec_duplic_display'], |
---|
141 | $ec_conf_possible_values['ec_duplic_display'])) ? |
---|
142 | $conf['ec_duplic_display'] : (isset($ec_conf[3]) and |
---|
143 | in_array($ec_conf[3], $ec_conf_possible_values['duplic_display'])) ? |
---|
144 | $ec_conf[3] : '2', |
---|
145 | // 3 // duplication link display in the menubar : |
---|
146 | // 0 : "Register" for everybody; |
---|
147 | // 1 : "Duplicate" for everybody; |
---|
148 | // 2 : "Register" only for generic accounts, |
---|
149 | // "Duplicate" for all other accounts; |
---|
150 | // If Event Cats is in "simple mode", takes the |
---|
151 | // value of $conf['ec_duplic_display'] if it's set. |
---|
152 | // |
---|
153 | 'auto_code_dg_nb' => ($simple_mode_on and isset($conf['ec_auto_code_dg_nb']) |
---|
154 | and in_array($conf['ec_auto_code_dg_nb'], |
---|
155 | $ec_conf_possible_values['ec_auto_code_dg_nb'])) ? |
---|
156 | $conf['ec_auto_code_dg_nb'] : (isset($ec_conf[4]) and |
---|
157 | in_array($ec_conf[4], $ec_conf_possible_values['auto_code_dg_nb'])) ? |
---|
158 | $ec_conf[4] : '10', |
---|
159 | // 4 // number of digits when creating a new code |
---|
160 | // automatically, several values |
---|
161 | // If Event Cats is in "simple mode", takes the |
---|
162 | // value of $conf['ec_auto_code_dg_nb'] if set. |
---|
163 | // |
---|
164 | 'unknown_code' // 5 // what to do in case an unknown code is used with |
---|
165 | => (isset($ec_conf[5]) and in_array($ec_conf[5], |
---|
166 | $ec_conf_possible_values['unknown_code'])) ? $ec_conf[5] : '1', |
---|
167 | // "autolog" parameter : |
---|
168 | // 0 : nothing (display home page, index.php |
---|
169 | // (not logged in of course)); |
---|
170 | // 1 : display "access denied" page; |
---|
171 | // 2 : display an A. P. precised below. |
---|
172 | // |
---|
173 | 'unknown_code_ap_id' // 6| the id of the Additional Page which must be |
---|
174 | => (isset($ec_conf[6])) ? $ec_conf[6] : '0', |
---|
175 | // used in case of usage of an unknow code; |
---|
176 | // several vals. |
---|
177 | // |
---|
178 | 'comment_display' => ($simple_mode_on and isset($conf['ec_comment_display']) |
---|
179 | and in_array($conf['ec_comment_display'], |
---|
180 | $ec_conf_possible_values['ec_comment_display'])) ? |
---|
181 | $conf['ec_comment_display'] : (isset($ec_conf[7]) and |
---|
182 | in_array($ec_conf[7], $ec_conf_possible_values['comment_display'])) ? |
---|
183 | $ec_conf[7] : '1', |
---|
184 | // 7 // the way the comment is displayed in "entries" |
---|
185 | // tab : 0, as tooltip; 1, on a line under code |
---|
186 | // If Event Cats is in "simple mode", takes the |
---|
187 | // value of $conf['ec_comment_display'] if set. |
---|
188 | // |
---|
189 | 'in_help_display' // 8 // whether the help banner is displayed. |
---|
190 | => (isset($ec_conf[8]) and in_array($ec_conf[8], |
---|
191 | $ec_conf_possible_values['in_help_display'])) ? $ec_conf[8] : '1', |
---|
192 | // 0: not displayed; 1 : displayed (surprising !) |
---|
193 | // |
---|
194 | 'display_connection' => ($simple_mode_on and |
---|
195 | isset($conf['ec_display_connection']) and |
---|
196 | in_array($conf['ec_display_connection'], |
---|
197 | $ec_conf_possible_values['ec_display_connection'])) ? |
---|
198 | $conf['ec_display_connection'] : (isset($ec_conf[9]) and |
---|
199 | in_array($ec_conf[9], $ec_conf_possible_values['display_connection'])) ? |
---|
200 | $ec_conf[9] : '1', |
---|
201 | // 9 // whether the "Connection" link must be displayed |
---|
202 | // for generic users, 0 or 1. |
---|
203 | // If Event Cats is in "simple mode", takes the |
---|
204 | // value of $conf['ec_display_connection'] if set. |
---|
205 | // |
---|
206 | 'simple_mode_on' => ($simple_mode_on) ? |
---|
207 | '1' : '0', // 10 // whether the presentation of the plugin is in |
---|
208 | // "simple mode" or not. |
---|
209 | // 0: normal view; 1 : simple view. |
---|
210 | // The default value can be modified to 0 (normal |
---|
211 | // view) if Event Cats was already installed |
---|
212 | // previously. |
---|
213 | // |
---|
214 | 'display_full_button' => ($simple_mode_on and |
---|
215 | isset($conf['ec_display_full_button']) and |
---|
216 | in_array($conf['ec_display_full_button'], |
---|
217 | $ec_conf_possible_values['ec_display_full_button'])) ? |
---|
218 | $conf['ec_display_full_button'] : (isset($ec_conf[11]) and |
---|
219 | in_array($ec_conf[11], $ec_conf_possible_values['display_full_button'])) ? |
---|
220 | $ec_conf[11] : '1', |
---|
221 | // 11 // whether the "Show full features" button must be |
---|
222 | // displayed, 0 or 1. The default value can be |
---|
223 | // modified to 0 (don't display) if |
---|
224 | // $conf['ec_display_full_button'] has val. false. |
---|
225 | ); |
---|
226 | |
---|
227 | // Once these lines have been updated, you don't need to change anything |
---|
228 | // else. Everything is managed by the code. |
---|
229 | //---------------------------------------------------------------------------- |
---|
230 | |
---|
231 | // Set $ec_conf to proper default values if needed, and writes its values |
---|
232 | // in the DB |
---|
233 | $ec_conf = array_values($ec_conf_default); |
---|
234 | |
---|
235 | change_ec_conf('activated', $u); // writes in the DB |
---|
236 | } |
---|
237 | // now : |
---|
238 | // _ the number of parameters is the same in the DB as the number of |
---|
239 | // default parameters; |
---|
240 | // _ the parameters have the default values if needed; |
---|
241 | // _ the plugin shows it is active if it is the case; |
---|
242 | // _ correct values will be returned when using procedure read_ec_conf($c). |
---|
243 | |
---|
244 | unset($s, $t, $u, $v, $w, $simple_mode_on); |
---|
245 | // And NOW can change_ec_conf and read_ec_conf be used properly... |
---|
246 | |
---|
247 | // --------------------------------------------------------------------------- |
---|
248 | // End of $ec_conf initalization |
---|
249 | // --------------------------------------------------------------------------- |
---|
250 | |
---|
251 | /* |
---|
252 | * change_ec_conf($c, $v) |
---|
253 | * updates Event Cats configuration values in the database as well as in |
---|
254 | * $ec_conf. |
---|
255 | * |
---|
256 | * @param |
---|
257 | * $c : conf value to update; |
---|
258 | * $v : value to give to $ec_conf[$c]. |
---|
259 | * @return |
---|
260 | * true or false whether the change was OK or not |
---|
261 | */ |
---|
262 | function change_ec_conf($c, $v) { |
---|
263 | global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values; |
---|
264 | |
---|
265 | if (array_key_exists($c, $ec_conf_index)) { |
---|
266 | if ( |
---|
267 | count($ec_conf_possible_values[$c]) == 0 or |
---|
268 | in_array($v, $ec_conf_possible_values[$c]) |
---|
269 | ) { |
---|
270 | $ec_conf[$ec_conf_index[$c]] = $v; |
---|
271 | return (pwg_query(" |
---|
272 | UPDATE `".CONFIG_TABLE."` |
---|
273 | SET `value` = \"".implode(',', $ec_conf)."\" |
---|
274 | WHERE `param` = 'event_cats'; |
---|
275 | ") !== false); |
---|
276 | } |
---|
277 | else { |
---|
278 | $page['errors'][] = 'Bad change_ec_conf value'; |
---|
279 | return false; |
---|
280 | } |
---|
281 | } |
---|
282 | else { |
---|
283 | $page['errors'][] = 'Bad change_ec_conf index'; |
---|
284 | return false; |
---|
285 | } |
---|
286 | } |
---|
287 | |
---|
288 | /* |
---|
289 | * read_ec_conf($c) |
---|
290 | * returns the value in $ec_conf using string keys. |
---|
291 | * |
---|
292 | * @param |
---|
293 | * $c : conf value to update; |
---|
294 | * @return |
---|
295 | * $ec_conf value |
---|
296 | */ |
---|
297 | function read_ec_conf($c) { |
---|
298 | global $ec_conf, $page, $ec_conf_index; |
---|
299 | if (array_key_exists($c, $ec_conf_index)) |
---|
300 | return $ec_conf[$ec_conf_index[$c]]; |
---|
301 | else { |
---|
302 | $page['errors'][] = 'Bad read_ec_conf index'; |
---|
303 | return false; |
---|
304 | } |
---|
305 | } |
---|
306 | |
---|
307 | ?> |
---|