[3969] | 1 | <?php |
---|
[3964] | 2 | |
---|
| 3 | /* |
---|
| 4 | Plugin Name: Event Cats |
---|
[10054] | 5 | Version: auto |
---|
[3970] | 6 | Description: A single URL can be enough to be identified, and a user can duplicate his account to create a new one getting immediately the same properties. / On peut être identifié grâce à un simple URL, et on peut dupliquer son compte pour créer un nouveau compte ayant immédiatement les mêmes propriétés. |
---|
[6269] | 7 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=326 |
---|
[4418] | 8 | Author: LucMorizur |
---|
| 9 | Author URI: http://lucmorizur.free.fr |
---|
[3964] | 10 | */ |
---|
| 11 | |
---|
| 12 | // +-----------------------------------------------------------------------+ |
---|
| 13 | // | Piwigo - a PHP based picture gallery | |
---|
| 14 | // +-----------------------------------------------------------------------+ |
---|
| 15 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
| 16 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 17 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 18 | // +-----------------------------------------------------------------------+ |
---|
| 19 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 20 | // | it under the terms of the GNU General Public License as published by | |
---|
| 21 | // | the Free Software Foundation | |
---|
| 22 | // | | |
---|
| 23 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 24 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 25 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 26 | // | General Public License for more details. | |
---|
| 27 | // | | |
---|
| 28 | // | You should have received a copy of the GNU General Public License | |
---|
| 29 | // | along with this program; if not, write to the Free Software | |
---|
| 30 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 31 | // | USA. | |
---|
| 32 | // +-----------------------------------------------------------------------+ |
---|
| 33 | |
---|
[8956] | 34 | // Keeps file coded in UTF-8 without BOM : é |
---|
[4421] | 35 | |
---|
[3964] | 36 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 37 | |
---|
| 38 | // pour faciliter le debug - make debug easier :o) |
---|
| 39 | //ini_set('error_reporting', E_ALL); |
---|
| 40 | //ini_set('display_errors', true); |
---|
| 41 | |
---|
[5058] | 42 | global $conf, $prefixeTable, $ec_lists, $template; |
---|
[3964] | 43 | |
---|
[4329] | 44 | define( // ------------------------------------------------------------------- |
---|
[8956] | 45 | 'EVNTCATS_INFO_VERSION', // VERSION HISTORY : |
---|
[21996] | 46 | '1.2.7' // Complies with Piwigo 2.5 |
---|
| 47 | // '1.2.6' // Fix bug 2267 « "Test" link in "autolog entries" admin page |
---|
[10458] | 48 | // doesn't work », and small improvements |
---|
| 49 | // '1.2.5' // Compatibility with Piwigo 2.2 (svn:10052) |
---|
[10059] | 50 | // '1.2.4' // Fix bug 2135: Constant ROOT_URL already defined; replaced by |
---|
[8956] | 51 | // // EC_ROOT_URL |
---|
[7099] | 52 | // '1.2.3' // Re-fix bug 1432 :-/ ... |
---|
[6269] | 53 | // '2.1.0' // When done, will simplfy and allow EC management from categories |
---|
| 54 | // management pages in admin pages... yes yes... |
---|
[6425] | 55 | // '1.2.2' // Corrections for Piwigo 2.1 compatibility |
---|
[6269] | 56 | // '1.2.1' // Improve EN translation thanks to Tosca |
---|
[4612] | 57 | // '1.2.0' // Add feature 1335, Possibility to display the 'Connection' |
---|
[8956] | 58 | // // link in identification block menu for generic users ; |
---|
[4612] | 59 | // // finish (yes !) english translation |
---|
[4553] | 60 | // '1.1.5' // Fix bugs 1324 and 1325 |
---|
| 61 | // '1.1.4' // Improve help banner |
---|
[8956] | 62 | // '1.1.3' // Better help banner management ; finalize banner texts |
---|
| 63 | // '1.1.2' // Better help banner example : some examples |
---|
| 64 | // '1.1.1' // Better help banner example ; but still no text in it |
---|
| 65 | // '1.1.0' // First bugs (1305 and 1306) corrected ; |
---|
[4553] | 66 | // add newly created user/group association with cat/AP (was |
---|
[8956] | 67 | // forgotten) ; begin help banner |
---|
[4553] | 68 | // '1.0.0' // Conception version |
---|
[4329] | 69 | ); // ------------------------------------------------------------------------ |
---|
| 70 | define( |
---|
| 71 | 'EVNTCATS_PATH', |
---|
| 72 | PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/' |
---|
| 73 | ); |
---|
| 74 | define( |
---|
| 75 | 'EVNTCATS_TABLE', |
---|
| 76 | $prefixeTable.'event_cats' |
---|
| 77 | ); |
---|
| 78 | define( |
---|
[8956] | 79 | 'EC_ROOT_URL', |
---|
[4329] | 80 | get_absolute_root_url() |
---|
| 81 | ); |
---|
[3964] | 82 | |
---|
[4169] | 83 | include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php'); |
---|
[3964] | 84 | |
---|
| 85 | class event_cats { |
---|
| 86 | // Sets the administration panel of the plugin |
---|
| 87 | function plugin_admin_menu($menu) { |
---|
| 88 | array_push($menu, |
---|
| 89 | array( |
---|
| 90 | 'NAME' => 'Event Cats', |
---|
| 91 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__). |
---|
| 92 | '/admin/evntcats_admin.php') |
---|
| 93 | ) |
---|
| 94 | ); |
---|
| 95 | return $menu; |
---|
| 96 | } |
---|
| 97 | } // End class |
---|
| 98 | |
---|
| 99 | $obj = new event_cats(); |
---|
| 100 | |
---|
[4282] | 101 | // Adds the translation of "duplicate" link |
---|
[4338] | 102 | load_language('duplic.lang', EVNTCATS_PATH); |
---|
[4282] | 103 | |
---|
[3964] | 104 | // Admin help management |
---|
| 105 | add_event_handler('get_popup_help_content', 'ec_popup_help_content', |
---|
| 106 | EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
| 107 | |
---|
| 108 | function ec_popup_help_content($popup_help_content, $page) { |
---|
| 109 | return ( |
---|
[6425] | 110 | $help_content = (is_admin() and $page == 'help') ? |
---|
[8956] | 111 | load_language($page.'.html', EVNTCATS_PATH, array('return' => true)) : false |
---|
[3964] | 112 | ) ? $popup_help_content.$help_content : $popup_help_content; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | //---------------------------------- |
---|
| 116 | |
---|
| 117 | /** |
---|
| 118 | * |
---|
| 119 | * auto_log_user() |
---|
[8956] | 120 | * the function uses the value of the argument "autolog" of the posted URL, as a code |
---|
| 121 | * to know which username has to be logged in. |
---|
[3964] | 122 | * |
---|
| 123 | * @param no parameter |
---|
| 124 | * @return no return value |
---|
| 125 | */ |
---|
| 126 | |
---|
| 127 | add_event_handler('init', 'auto_log_user'); |
---|
| 128 | |
---|
| 129 | function auto_log_user() { |
---|
[4554] | 130 | global $ec_lists; |
---|
[3964] | 131 | |
---|
| 132 | $ec_ap = NULL; |
---|
| 133 | $ec_cat = NULL; |
---|
| 134 | $ec_img = NULL; |
---|
[4247] | 135 | |
---|
[8956] | 136 | if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) { |
---|
[3975] | 137 | if (!is_a_guest()) { |
---|
| 138 | $url = ''; |
---|
[6269] | 139 | foreach ($_GET as $item => $value) { |
---|
[10458] | 140 | if ($url != '') $url.='&'; |
---|
| 141 | $url.= $item.'='.$value; |
---|
[6269] | 142 | } |
---|
[3975] | 143 | logout_user(); |
---|
[10458] | 144 | redirect(get_absolute_root_url().'index.php?'.$url); |
---|
[3975] | 145 | } |
---|
[3964] | 146 | build_ec_lists(); |
---|
| 147 | foreach ($ec_lists['ec_table'] as $ec_entry) { |
---|
| 148 | if ($code_exists = ($ec_entry['code'] == $_GET['autolog'])) break; |
---|
| 149 | } |
---|
| 150 | if ($code_exists) { |
---|
[3985] | 151 | if (is_in($ec_entry['action'], 'ec_ok')) { |
---|
[3964] | 152 | log_user($ec_entry['user_id'], false); |
---|
[3971] | 153 | if (isset($_GET['ap'])) $ec_ap = $_GET['ap']; |
---|
[3964] | 154 | if (isset($_GET['cat'])) $ec_cat = $_GET['cat']; |
---|
| 155 | if (isset($_GET['img'])) $ec_img = $_GET['img']; |
---|
[4092] | 156 | if ($ec_entry['forced'] == 'true') { |
---|
[3964] | 157 | if (empty($ec_entry['arg1']) and !empty($ec_entry['arg2'])) { |
---|
| 158 | $ec_ap = $ec_entry['arg2']; |
---|
| 159 | } |
---|
| 160 | elseif (!empty($ec_entry['arg1'])) { |
---|
| 161 | $ec_cat = $ec_entry['arg1']; |
---|
| 162 | if (!empty($ec_entry['arg2'])) $ec_img = $ec_entry['arg2']; |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | if (isset($ec_ap)) { |
---|
| 166 | if (array_key_exists($ec_ap,$ec_lists['add_pages'])) { |
---|
| 167 | redirect( |
---|
| 168 | PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap); |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | elseif (isset($ec_cat)) { |
---|
| 172 | if (array_key_exists($ec_cat, $ec_lists['categories'])) { |
---|
| 173 | if (isset($ec_img)) { |
---|
[4157] | 174 | if (ec_image_exists($ec_cat, $ec_img)) { |
---|
[8956] | 175 | redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat); |
---|
[3964] | 176 | } |
---|
| 177 | } |
---|
[4554] | 178 | redirect(PHPWG_ROOT_PATH.'index.php?/category/'.$ec_cat); |
---|
[3964] | 179 | } |
---|
| 180 | } |
---|
[3971] | 181 | redirect(make_index_url()); |
---|
[3964] | 182 | } |
---|
| 183 | else { |
---|
[3971] | 184 | if ( |
---|
| 185 | $ec_entry['action'] == 'ec_nok' or |
---|
| 186 | $ec_entry['action'] == 'ec_nok_ap_pb' |
---|
| 187 | ) { |
---|
| 188 | if ($ec_entry['action'] == 'ec_nok_ap_pb') access_denied(); |
---|
| 189 | $ec_ap = $ec_entry['arg2']; |
---|
| 190 | if (array_key_exists($ec_ap, $ec_lists['add_pages'])) { |
---|
| 191 | redirect( |
---|
| 192 | PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap); |
---|
[3964] | 193 | } |
---|
| 194 | access_denied(); |
---|
| 195 | } |
---|
| 196 | else { |
---|
| 197 | redirect(make_index_url()); |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | else { |
---|
| 202 | if ( |
---|
[4371] | 203 | read_ec_conf('unknown_code') == '2' and |
---|
[3964] | 204 | array_key_exists( |
---|
[3971] | 205 | read_ec_conf('unknown_code_ap_id'), $ec_lists['add_pages'] |
---|
[3964] | 206 | ) |
---|
| 207 | ) { |
---|
| 208 | redirect( |
---|
| 209 | PHPWG_ROOT_PATH. |
---|
[3971] | 210 | 'index.php?/additional_page/'.read_ec_conf('unknown_code_ap_id') |
---|
[3964] | 211 | ); |
---|
| 212 | } |
---|
[4371] | 213 | elseif (read_ec_conf('unknown_code') == '1' or |
---|
| 214 | read_ec_conf('unknown_code') == '2') { |
---|
[3964] | 215 | access_denied(); |
---|
| 216 | } |
---|
| 217 | else { |
---|
| 218 | redirect(make_index_url()); |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | /** |
---|
| 225 | * |
---|
| 226 | * assign_perm_for_new_user() |
---|
| 227 | * copies/paste groups+access+properties associations of previously connected |
---|
| 228 | * username, to newly created username. |
---|
| 229 | * |
---|
| 230 | * @param no parameter |
---|
| 231 | * @return no return value |
---|
| 232 | */ |
---|
| 233 | |
---|
| 234 | add_event_handler('register_user', 'assign_perm_for_new_user'); |
---|
| 235 | |
---|
[4371] | 236 | function assign_perm_for_new_user($new_user) { |
---|
[3964] | 237 | global $user; |
---|
| 238 | |
---|
[8956] | 239 | if (!is_a_guest() and !is_admin()) if ( |
---|
| 240 | read_ec_conf('dup_allow') == '1' or ( |
---|
| 241 | read_ec_conf('dup_allow') == '2' and |
---|
| 242 | dup_allowed($user['id']) |
---|
| 243 | ) |
---|
| 244 | ) { |
---|
| 245 | // User access |
---|
| 246 | $result = pwg_query(" |
---|
| 247 | SELECT `cat_id` |
---|
| 248 | FROM `".USER_ACCESS_TABLE."` |
---|
| 249 | WHERE `user_id` = ".$user['id']."; |
---|
| 250 | "); |
---|
| 251 | $insert = array(); |
---|
[21652] | 252 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[8956] | 253 | $insert[] = "(".$new_user['id'].",".$row['cat_id'].")"; |
---|
| 254 | if (!empty($insert)) pwg_query(" |
---|
| 255 | INSERT INTO `".USER_ACCESS_TABLE."` |
---|
| 256 | VALUES ".implode(',', $insert)."; |
---|
| 257 | "); |
---|
[3964] | 258 | |
---|
[8956] | 259 | // User groups |
---|
| 260 | $result = pwg_query(" |
---|
| 261 | SELECT `group_id` |
---|
| 262 | FROM `".USER_GROUP_TABLE."` |
---|
| 263 | WHERE `user_id` = ".$user['id']."; |
---|
| 264 | "); |
---|
| 265 | $insert = array(); |
---|
[21652] | 266 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[8956] | 267 | $insert[] = "(".$new_user['id'].",".$row['group_id'].")"; |
---|
| 268 | if (!empty($insert)) pwg_query(" |
---|
| 269 | INSERT INTO `".USER_GROUP_TABLE."` |
---|
| 270 | VALUES ".implode(',', $insert)."; |
---|
| 271 | "); |
---|
[3964] | 272 | |
---|
[8956] | 273 | // User infos |
---|
| 274 | $result = pwg_query(" |
---|
| 275 | SELECT `level` |
---|
| 276 | FROM `".USER_INFOS_TABLE."` |
---|
| 277 | WHERE `user_id` = ".$user['id']."; |
---|
| 278 | "); |
---|
| 279 | $insert = array(); |
---|
[21652] | 280 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[8956] | 281 | $insert[] = "(".$new_user['id'].",".$row['level'].")"; |
---|
| 282 | if (!empty($insert)) pwg_query(" |
---|
| 283 | UPDATE `".USER_INFOS_TABLE."` |
---|
| 284 | SET `level` = ".$user['level']." |
---|
| 285 | WHERE `user_id` = ".$new_user['id']."; |
---|
| 286 | "); |
---|
[3971] | 287 | } |
---|
[3964] | 288 | } |
---|
| 289 | |
---|
| 290 | /** |
---|
| 291 | * |
---|
| 292 | * duplicate_account_url() |
---|
[4553] | 293 | * adds a link for duplicating the currently identified user in |
---|
| 294 | * Identification block menu, in case the identifed user is granted to |
---|
| 295 | * duplication. Displays also the connection link for generic users, if |
---|
| 296 | * required in the configuration. |
---|
[3964] | 297 | * |
---|
[6269] | 298 | * ec_duplicate_prefilter |
---|
| 299 | * is used to modify the "quick connect" block in identification menu block, |
---|
| 300 | * so that visitors identifying themselves this way, are redirected to the |
---|
| 301 | * page they're currently displaying, instead of home page. This |
---|
| 302 | * functionnality has been added at version 2.1.0 in Piwigo core |
---|
| 303 | * (see bug:1484 Redirection after quickconnect), thus it is useless to |
---|
| 304 | * implement it from here for Piwigo versions higher or equal to 2.1.0. |
---|
| 305 | * |
---|
[3964] | 306 | * @param no parameter |
---|
| 307 | * @return no return value |
---|
| 308 | */ |
---|
| 309 | |
---|
| 310 | add_event_handler('blockmanager_apply', 'duplicate_account_url'); |
---|
| 311 | |
---|
[6269] | 312 | function ec_duplicate_prefilter($content, &$smarty) { |
---|
| 313 | $search = "<legend>{'Quick connect'|@translate}</legend>"; |
---|
| 314 | $addon = '<input type="hidden" name="redirect" value="{$U_REDIRECT}">'; |
---|
| 315 | $replacement = "<legend>{'Quick connect'|@translate}</legend>".$addon; |
---|
| 316 | return str_replace($search, $replacement, $content); |
---|
| 317 | } |
---|
| 318 | |
---|
[3971] | 319 | function duplicate_account_url() { |
---|
[4554] | 320 | global $lang, $template, $user; |
---|
[6269] | 321 | |
---|
[8956] | 322 | if (version_compare(PHPWG_VERSION, '2.1.0', '<')) { |
---|
| 323 | // Makes the "quick connect" fieldset able to redirect to current page |
---|
| 324 | // after user identification, just as does the "connection" link. |
---|
| 325 | $template->assign(array('U_REDIRECT' => $_SERVER['REQUEST_URI'])); |
---|
| 326 | $template->set_prefilter('menubar', 'ec_duplicate_prefilter'); |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | // Adds duplication link, if needed |
---|
| 330 | if (!is_admin() and !is_a_guest()) if ( |
---|
| 331 | read_ec_conf('dup_allow') == '1' or ( |
---|
| 332 | read_ec_conf('dup_allow') == '2' and |
---|
| 333 | dup_allowed($user['id']) |
---|
| 334 | ) |
---|
| 335 | ) { |
---|
| 336 | $template->assign('U_REGISTER', get_root_url().'register.php'); |
---|
[4329] | 337 | if ( |
---|
[8956] | 338 | read_ec_conf('duplic_display') == '1' or ( |
---|
| 339 | read_ec_conf('duplic_display') == '2' and |
---|
| 340 | !is_generic() |
---|
[4329] | 341 | ) |
---|
| 342 | ) { |
---|
[8956] | 343 | $lang['Register'] = $lang['Duplicate']; |
---|
| 344 | $lang['Create a new account'] = |
---|
| 345 | $lang['Create a new account with same properties']; |
---|
[4329] | 346 | } |
---|
[3971] | 347 | } |
---|
[8956] | 348 | |
---|
| 349 | // Adds connection link, if needed |
---|
| 350 | if (read_ec_conf('display_connection') == '1' and is_generic()) { |
---|
| 351 | // Adds connection link |
---|
| 352 | $template->assign( |
---|
| 353 | 'U_LOGIN', |
---|
| 354 | get_root_url().'identification.php?redirect='.$_SERVER['REQUEST_URI'] |
---|
| 355 | ); |
---|
| 356 | } |
---|
[3964] | 357 | } |
---|
| 358 | |
---|
[4553] | 359 | add_event_handler( |
---|
| 360 | 'get_admin_plugin_menu_links', |
---|
| 361 | array(&$obj, 'plugin_admin_menu') |
---|
| 362 | ); |
---|
[3964] | 363 | set_plugin_data($plugin['id'], $obj); |
---|
| 364 | |
---|
| 365 | ?> |
---|