[3969] | 1 | <?php |
---|
[3962] | 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 | |
---|
[8956] | 25 | // Keeps file coded in UTF-8 without BOM : é |
---|
[4421] | 26 | |
---|
[4333] | 27 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 28 | |
---|
[8956] | 29 | global $ec_conf, $page, $ec_conf_index, $ec_conf_default, |
---|
| 30 | $ec_conf_possible_values; |
---|
[3962] | 31 | |
---|
[8956] | 32 | // $ec_conf initalization |
---|
[3962] | 33 | |
---|
[4329] | 34 | // $ec_conf has numeric indexes (instead of string keys like 'activated', |
---|
| 35 | // 'howto'...) because of its first reading, done with the "explode" function. |
---|
[8956] | 36 | // It would be very easy to build a string keys indexed array, thanks to |
---|
[4329] | 37 | // following instructions : |
---|
| 38 | /* |
---|
[21652] | 39 | $t = pwg_db_fetch_row(pwg_query(" |
---|
[4329] | 40 | SELECT `value` |
---|
| 41 | FROM `".CONFIG_TABLE."` |
---|
| 42 | WHERE `param` = 'event_cats'; |
---|
| 43 | ")); |
---|
| 44 | $ec_conf_temp = explode(',', $t[0]); |
---|
| 45 | $ec_conf = array(); $i = 0; |
---|
| 46 | foreach ($ec_conf_default as $k => $v) $ec_conf[$k] = ec_conf_temp[$i++]; |
---|
| 47 | */ |
---|
| 48 | // Though, I prefer to keep $ec_conf with numeric indexes, so to be compelled |
---|
| 49 | // to go through function change_ec_conf() to modify ec_conf, and thus update |
---|
| 50 | // the DB at the same time. |
---|
| 51 | |
---|
[4437] | 52 | //---------------------------------------------------------------------------- |
---|
[8956] | 53 | // The following lines allow to change the number of configuration items, the |
---|
| 54 | // default values they can have, and also their possible other values, very |
---|
| 55 | // quickly. |
---|
[4437] | 56 | |
---|
[8956] | 57 | // Gives configuration items names and default values. Only strings. |
---|
| 58 | $ec_conf_default = array( // PLUGIN CONFIGURATION ($ec_conf) : |
---|
| 59 | // --------------------------------- |
---|
| 60 | 'activated' // plugin activated, 0 or 1 |
---|
| 61 | => '0', // |
---|
| 62 | // |
---|
| 63 | 'howto' // whether the small aknowledgement message has |
---|
| 64 | => '0', // already been displayed, 0 or 1 |
---|
| 65 | // |
---|
| 66 | 'dup_allow' // duplication allowance : |
---|
| 67 | => '2', // 0 : no account ; |
---|
| 68 | // 1 : all accounts ; |
---|
| 69 | // 2 : specified by group and user ids ; |
---|
| 70 | // |
---|
| 71 | 'duplic_display' // duplication link display in the menubar : |
---|
| 72 | => '2', // 0 : "Register" for everybody ; |
---|
| 73 | // 1 : "Duplicate" for everybody ; |
---|
| 74 | // 2 : "Register" only for generic accounts, |
---|
| 75 | // "Duplicate" for all other accounts ; |
---|
| 76 | // |
---|
| 77 | 'auto_code_dg_nb' // number of digits when creating a new code |
---|
| 78 | => '10', // automatically, several values |
---|
| 79 | // |
---|
| 80 | 'unknown_code' // what to do in case an unknown code is used with |
---|
| 81 | => '1', // "autolog" parameter : |
---|
| 82 | // 0 : nothing (display home page, index.php (not |
---|
| 83 | // logged in of course)) ; |
---|
| 84 | // 1 : display "access denied" page ; |
---|
| 85 | // 2 : display an Additional Page precised below. |
---|
| 86 | // |
---|
| 87 | 'unknown_code_ap_id' // the id of the Additional Page which must be used |
---|
| 88 | => '0', // in case of usage of an unknow code, several vals. |
---|
| 89 | // |
---|
| 90 | 'comment_display' // the way the comment is displayed in "entries" |
---|
| 91 | => '1', // tab : 0, as tooltip ; 1, on a line under code |
---|
| 92 | // |
---|
| 93 | 'in_help_display' // whether the help banner is displayed. |
---|
| 94 | => '1', // 0: not displayed ; 1 : displayed (surprising !) |
---|
| 95 | // |
---|
| 96 | 'display_connection' // whether the "Connection" link must be displayed |
---|
| 97 | => '0', // for generic users, 0 or 1. |
---|
| 98 | ); |
---|
| 99 | |
---|
| 100 | // Gives possible values. In case values cannot be predicted, just provide an |
---|
| 101 | // empty array : array() . |
---|
[4329] | 102 | $ec_conf_possible_values = array( |
---|
[8956] | 103 | 'activated' => array('0', '1'), |
---|
| 104 | 'howto' => array('0', '1'), |
---|
| 105 | 'dup_allow' => array('0', '1', '2'), |
---|
| 106 | 'duplic_display' => array('0', '1', '2'), |
---|
| 107 | 'auto_code_dg_nb' => array( '4', '5', '8', '10', '12', '15', |
---|
| 108 | '16', '20', '24', '25', '30', '32'), |
---|
| 109 | 'unknown_code' => array('0', '1', '2'), |
---|
| 110 | 'unknown_code_ap_id' => array(), |
---|
| 111 | 'comment_display' => array('0', '1'), |
---|
| 112 | 'in_help_display' => array('0', '1'), |
---|
| 113 | 'display_connection' => array('0', '1'), |
---|
[4329] | 114 | ); |
---|
| 115 | |
---|
[8956] | 116 | // Once these lines have been updated, you don't need to change anything |
---|
| 117 | // else. Everything is managed by the code ; the only effect being that |
---|
| 118 | // existing configuration values in the DB are reset to their default |
---|
| 119 | // values -- normally not a harmful effect. |
---|
| 120 | //---------------------------------------------------------------------------- |
---|
[4437] | 121 | |
---|
[8956] | 122 | $ec_conf_index = array_flip(array_keys($ec_conf_default)); |
---|
| 123 | |
---|
| 124 | $t = array(); $u = '0'; $v = false; |
---|
[21652] | 125 | $r = pwg_query(" |
---|
| 126 | SELECT `value` |
---|
| 127 | FROM `".CONFIG_TABLE."` |
---|
| 128 | WHERE `param` = 'event_cats'; |
---|
| 129 | "); |
---|
| 130 | if (pwg_db_num_rows($r)) { |
---|
| 131 | $t = pwg_db_fetch_row($r); |
---|
[4239] | 132 | $v = (count($ec_conf = explode(',', $t[0])) == count($ec_conf_index)); |
---|
[8956] | 133 | $u = $ec_conf[0]; |
---|
[3962] | 134 | } |
---|
[8956] | 135 | // $v is false |
---|
| 136 | // _ if the entry in the table doesn't exist ; |
---|
| 137 | // _ if the entry in the table exists, but its number of parameters is |
---|
| 138 | // different than the number of default parameters. |
---|
| 139 | // $u is '0' if the plugin has not yet been activated, '1' if it has been. |
---|
| 140 | if (!$v) { |
---|
| 141 | $ec_conf = array_values($ec_conf_default); |
---|
| 142 | change_ec_conf('activated', $u); // writes in the DB |
---|
[4239] | 143 | } |
---|
| 144 | // now : |
---|
| 145 | // _ the number of parameters is the same in the DB as the number of |
---|
[8956] | 146 | // default parameters ; |
---|
| 147 | // _ the parameters have the default values if needed ; |
---|
| 148 | // _ the plugin shows it is active if it is the case. |
---|
| 149 | unset($t, $u, $v); |
---|
[3962] | 150 | |
---|
| 151 | /* |
---|
| 152 | * change_ec_conf($c, $v) |
---|
| 153 | * updates Event Cats configuration values in the database as well as in |
---|
| 154 | * $ec_conf. |
---|
| 155 | * |
---|
| 156 | * @param |
---|
[8956] | 157 | * $c : conf value to update ; |
---|
[3962] | 158 | * $v : value to give to $ec_conf[$c]. |
---|
| 159 | * @return |
---|
| 160 | * true or false whether the change was OK or not |
---|
| 161 | */ |
---|
| 162 | function change_ec_conf($c, $v) { |
---|
[4329] | 163 | global $ec_conf, $page, $ec_conf_index, $ec_conf_possible_values; |
---|
[4239] | 164 | if (array_key_exists($c, $ec_conf_index)) { |
---|
[4329] | 165 | if ( |
---|
| 166 | count($ec_conf_possible_values[$c]) == 0 or |
---|
| 167 | in_array($v, $ec_conf_possible_values[$c]) |
---|
| 168 | ) { |
---|
| 169 | $ec_conf[$ec_conf_index[$c]] = $v; |
---|
[7068] | 170 | return (pwg_query(" |
---|
[4329] | 171 | UPDATE `".CONFIG_TABLE."` |
---|
| 172 | SET `value` = \"".implode(',', $ec_conf)."\" |
---|
| 173 | WHERE `param` = 'event_cats'; |
---|
[7068] | 174 | ") !== false); |
---|
[4329] | 175 | } |
---|
| 176 | else { |
---|
| 177 | $page['errors'][] = 'Bad change_ec_conf value'; |
---|
| 178 | return false; |
---|
| 179 | } |
---|
[4239] | 180 | } |
---|
| 181 | else { |
---|
[4329] | 182 | $page['errors'][] = 'Bad change_ec_conf index'; |
---|
[4173] | 183 | return false; |
---|
[3962] | 184 | } |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | /* |
---|
| 188 | * read_ec_conf($c) |
---|
| 189 | * returns the value in $ec_conf using string keys. |
---|
| 190 | * |
---|
| 191 | * @param |
---|
[8956] | 192 | * $c : conf value to update ; |
---|
[3962] | 193 | * @return |
---|
| 194 | * $ec_conf value |
---|
| 195 | */ |
---|
| 196 | function read_ec_conf($c) { |
---|
[4239] | 197 | global $ec_conf, $page, $ec_conf_index; |
---|
| 198 | if (array_key_exists($c, $ec_conf_index)) |
---|
| 199 | return $ec_conf[$ec_conf_index[$c]]; |
---|
| 200 | else { |
---|
[4329] | 201 | $page['errors'][] = 'Bad read_ec_conf index'; |
---|
[4173] | 202 | return false; |
---|
[3962] | 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | ?> |
---|