[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 : |
---|
[10458] | 46 | '1.2.6' // Fix bug 2267 « "Test" link in "autolog entries" admin page |
---|
| 47 | // doesn't work », and small improvements |
---|
| 48 | // '1.2.5' // Compatibility with Piwigo 2.2 (svn:10052) |
---|
[10059] | 49 | // '1.2.4' // Fix bug 2135: Constant ROOT_URL already defined; replaced by |
---|
[8956] | 50 | // // EC_ROOT_URL |
---|
[7099] | 51 | // '1.2.3' // Re-fix bug 1432 :-/ ... |
---|
[6269] | 52 | // '2.1.0' // When done, will simplfy and allow EC management from categories |
---|
| 53 | // management pages in admin pages... yes yes... |
---|
[6425] | 54 | // '1.2.2' // Corrections for Piwigo 2.1 compatibility |
---|
[6269] | 55 | // '1.2.1' // Improve EN translation thanks to Tosca |
---|
[4612] | 56 | // '1.2.0' // Add feature 1335, Possibility to display the 'Connection' |
---|
[8956] | 57 | // // link in identification block menu for generic users ; |
---|
[4612] | 58 | // // finish (yes !) english translation |
---|
[4553] | 59 | // '1.1.5' // Fix bugs 1324 and 1325 |
---|
| 60 | // '1.1.4' // Improve help banner |
---|
[8956] | 61 | // '1.1.3' // Better help banner management ; finalize banner texts |
---|
| 62 | // '1.1.2' // Better help banner example : some examples |
---|
| 63 | // '1.1.1' // Better help banner example ; but still no text in it |
---|
| 64 | // '1.1.0' // First bugs (1305 and 1306) corrected ; |
---|
[4553] | 65 | // add newly created user/group association with cat/AP (was |
---|
[8956] | 66 | // forgotten) ; begin help banner |
---|
[4553] | 67 | // '1.0.0' // Conception version |
---|
[4329] | 68 | ); // ------------------------------------------------------------------------ |
---|
| 69 | define( |
---|
| 70 | 'EVNTCATS_PATH', |
---|
| 71 | PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/' |
---|
| 72 | ); |
---|
| 73 | define( |
---|
| 74 | 'EVNTCATS_TABLE', |
---|
| 75 | $prefixeTable.'event_cats' |
---|
| 76 | ); |
---|
| 77 | define( |
---|
[8956] | 78 | 'EC_ROOT_URL', |
---|
[4329] | 79 | get_absolute_root_url() |
---|
| 80 | ); |
---|
[3964] | 81 | |
---|
[4169] | 82 | include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php'); |
---|
[3964] | 83 | |
---|
| 84 | class event_cats { |
---|
| 85 | // Sets the administration panel of the plugin |
---|
| 86 | function plugin_admin_menu($menu) { |
---|
| 87 | array_push($menu, |
---|
| 88 | array( |
---|
| 89 | 'NAME' => 'Event Cats', |
---|
| 90 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__). |
---|
| 91 | '/admin/evntcats_admin.php') |
---|
| 92 | ) |
---|
| 93 | ); |
---|
| 94 | return $menu; |
---|
| 95 | } |
---|
| 96 | } // End class |
---|
| 97 | |
---|
| 98 | $obj = new event_cats(); |
---|
| 99 | |
---|
[4282] | 100 | // Adds the translation of "duplicate" link |
---|
[4338] | 101 | load_language('duplic.lang', EVNTCATS_PATH); |
---|
[4282] | 102 | |
---|
[3964] | 103 | // Admin help management |
---|
| 104 | add_event_handler('get_popup_help_content', 'ec_popup_help_content', |
---|
| 105 | EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
| 106 | |
---|
| 107 | function ec_popup_help_content($popup_help_content, $page) { |
---|
| 108 | return ( |
---|
[6425] | 109 | $help_content = (is_admin() and $page == 'help') ? |
---|
[8956] | 110 | load_language($page.'.html', EVNTCATS_PATH, array('return' => true)) : false |
---|
[3964] | 111 | ) ? $popup_help_content.$help_content : $popup_help_content; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | //---------------------------------- |
---|
| 115 | |
---|
| 116 | /** |
---|
| 117 | * |
---|
| 118 | * auto_log_user() |
---|
[8956] | 119 | * the function uses the value of the argument "autolog" of the posted URL, as a code |
---|
| 120 | * to know which username has to be logged in. |
---|
[3964] | 121 | * |
---|
| 122 | * @param no parameter |
---|
| 123 | * @return no return value |
---|
| 124 | */ |
---|
| 125 | |
---|
| 126 | add_event_handler('init', 'auto_log_user'); |
---|
| 127 | |
---|
| 128 | function auto_log_user() { |
---|
[4554] | 129 | global $ec_lists; |
---|
[3964] | 130 | |
---|
| 131 | $ec_ap = NULL; |
---|
| 132 | $ec_cat = NULL; |
---|
| 133 | $ec_img = NULL; |
---|
[4247] | 134 | |
---|
[8956] | 135 | if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) { |
---|
[3975] | 136 | if (!is_a_guest()) { |
---|
| 137 | $url = ''; |
---|
[6269] | 138 | foreach ($_GET as $item => $value) { |
---|
[10458] | 139 | if ($url != '') $url.='&'; |
---|
| 140 | $url.= $item.'='.$value; |
---|
[6269] | 141 | } |
---|
[3975] | 142 | logout_user(); |
---|
[10458] | 143 | redirect(get_absolute_root_url().'index.php?'.$url); |
---|
[3975] | 144 | } |
---|
[3964] | 145 | build_ec_lists(); |
---|
| 146 | foreach ($ec_lists['ec_table'] as $ec_entry) { |
---|
| 147 | if ($code_exists = ($ec_entry['code'] == $_GET['autolog'])) break; |
---|
| 148 | } |
---|
| 149 | if ($code_exists) { |
---|
[3985] | 150 | if (is_in($ec_entry['action'], 'ec_ok')) { |
---|
[3964] | 151 | log_user($ec_entry['user_id'], false); |
---|
[3971] | 152 | if (isset($_GET['ap'])) $ec_ap = $_GET['ap']; |
---|
[3964] | 153 | if (isset($_GET['cat'])) $ec_cat = $_GET['cat']; |
---|
| 154 | if (isset($_GET['img'])) $ec_img = $_GET['img']; |
---|
[4092] | 155 | if ($ec_entry['forced'] == 'true') { |
---|
[3964] | 156 | if (empty($ec_entry['arg1']) and !empty($ec_entry['arg2'])) { |
---|
| 157 | $ec_ap = $ec_entry['arg2']; |
---|
| 158 | } |
---|
| 159 | elseif (!empty($ec_entry['arg1'])) { |
---|
| 160 | $ec_cat = $ec_entry['arg1']; |
---|
| 161 | if (!empty($ec_entry['arg2'])) $ec_img = $ec_entry['arg2']; |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | if (isset($ec_ap)) { |
---|
| 165 | if (array_key_exists($ec_ap,$ec_lists['add_pages'])) { |
---|
| 166 | redirect( |
---|
| 167 | PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap); |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | elseif (isset($ec_cat)) { |
---|
| 171 | if (array_key_exists($ec_cat, $ec_lists['categories'])) { |
---|
| 172 | if (isset($ec_img)) { |
---|
[4157] | 173 | if (ec_image_exists($ec_cat, $ec_img)) { |
---|
[8956] | 174 | redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat); |
---|
[3964] | 175 | } |
---|
| 176 | } |
---|
[4554] | 177 | redirect(PHPWG_ROOT_PATH.'index.php?/category/'.$ec_cat); |
---|
[3964] | 178 | } |
---|
| 179 | } |
---|
[3971] | 180 | redirect(make_index_url()); |
---|
[3964] | 181 | } |
---|
| 182 | else { |
---|
[3971] | 183 | if ( |
---|
| 184 | $ec_entry['action'] == 'ec_nok' or |
---|
| 185 | $ec_entry['action'] == 'ec_nok_ap_pb' |
---|
| 186 | ) { |
---|
| 187 | if ($ec_entry['action'] == 'ec_nok_ap_pb') access_denied(); |
---|
| 188 | $ec_ap = $ec_entry['arg2']; |
---|
| 189 | if (array_key_exists($ec_ap, $ec_lists['add_pages'])) { |
---|
| 190 | redirect( |
---|
| 191 | PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap); |
---|
[3964] | 192 | } |
---|
| 193 | access_denied(); |
---|
| 194 | } |
---|
| 195 | else { |
---|
| 196 | redirect(make_index_url()); |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | else { |
---|
| 201 | if ( |
---|
[4371] | 202 | read_ec_conf('unknown_code') == '2' and |
---|
[3964] | 203 | array_key_exists( |
---|
[3971] | 204 | read_ec_conf('unknown_code_ap_id'), $ec_lists['add_pages'] |
---|
[3964] | 205 | ) |
---|
| 206 | ) { |
---|
| 207 | redirect( |
---|
| 208 | PHPWG_ROOT_PATH. |
---|
[3971] | 209 | 'index.php?/additional_page/'.read_ec_conf('unknown_code_ap_id') |
---|
[3964] | 210 | ); |
---|
| 211 | } |
---|
[4371] | 212 | elseif (read_ec_conf('unknown_code') == '1' or |
---|
| 213 | read_ec_conf('unknown_code') == '2') { |
---|
[3964] | 214 | access_denied(); |
---|
| 215 | } |
---|
| 216 | else { |
---|
| 217 | redirect(make_index_url()); |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | /** |
---|
| 224 | * |
---|
| 225 | * assign_perm_for_new_user() |
---|
| 226 | * copies/paste groups+access+properties associations of previously connected |
---|
| 227 | * username, to newly created username. |
---|
| 228 | * |
---|
| 229 | * @param no parameter |
---|
| 230 | * @return no return value |
---|
| 231 | */ |
---|
| 232 | |
---|
| 233 | add_event_handler('register_user', 'assign_perm_for_new_user'); |
---|
| 234 | |
---|
[4371] | 235 | function assign_perm_for_new_user($new_user) { |
---|
[3964] | 236 | global $user; |
---|
| 237 | |
---|
[8956] | 238 | if (!is_a_guest() and !is_admin()) if ( |
---|
| 239 | read_ec_conf('dup_allow') == '1' or ( |
---|
| 240 | read_ec_conf('dup_allow') == '2' and |
---|
| 241 | dup_allowed($user['id']) |
---|
| 242 | ) |
---|
| 243 | ) { |
---|
| 244 | // User access |
---|
| 245 | $result = pwg_query(" |
---|
| 246 | SELECT `cat_id` |
---|
| 247 | FROM `".USER_ACCESS_TABLE."` |
---|
| 248 | WHERE `user_id` = ".$user['id']."; |
---|
| 249 | "); |
---|
| 250 | $insert = array(); |
---|
| 251 | while ($row = mysql_fetch_assoc($result)) |
---|
| 252 | $insert[] = "(".$new_user['id'].",".$row['cat_id'].")"; |
---|
| 253 | if (!empty($insert)) pwg_query(" |
---|
| 254 | INSERT INTO `".USER_ACCESS_TABLE."` |
---|
| 255 | VALUES ".implode(',', $insert)."; |
---|
| 256 | "); |
---|
[3964] | 257 | |
---|
[8956] | 258 | // User groups |
---|
| 259 | $result = pwg_query(" |
---|
| 260 | SELECT `group_id` |
---|
| 261 | FROM `".USER_GROUP_TABLE."` |
---|
| 262 | WHERE `user_id` = ".$user['id']."; |
---|
| 263 | "); |
---|
| 264 | $insert = array(); |
---|
| 265 | while ($row = mysql_fetch_assoc($result)) |
---|
| 266 | $insert[] = "(".$new_user['id'].",".$row['group_id'].")"; |
---|
| 267 | if (!empty($insert)) pwg_query(" |
---|
| 268 | INSERT INTO `".USER_GROUP_TABLE."` |
---|
| 269 | VALUES ".implode(',', $insert)."; |
---|
| 270 | "); |
---|
[3964] | 271 | |
---|
[8956] | 272 | // User infos |
---|
| 273 | $result = pwg_query(" |
---|
| 274 | SELECT `level` |
---|
| 275 | FROM `".USER_INFOS_TABLE."` |
---|
| 276 | WHERE `user_id` = ".$user['id']."; |
---|
| 277 | "); |
---|
| 278 | $insert = array(); |
---|
| 279 | while ($row = mysql_fetch_assoc($result)) |
---|
| 280 | $insert[] = "(".$new_user['id'].",".$row['level'].")"; |
---|
| 281 | if (!empty($insert)) pwg_query(" |
---|
| 282 | UPDATE `".USER_INFOS_TABLE."` |
---|
| 283 | SET `level` = ".$user['level']." |
---|
| 284 | WHERE `user_id` = ".$new_user['id']."; |
---|
| 285 | "); |
---|
[3971] | 286 | } |
---|
[3964] | 287 | } |
---|
| 288 | |
---|
| 289 | /** |
---|
| 290 | * |
---|
| 291 | * duplicate_account_url() |
---|
[4553] | 292 | * adds a link for duplicating the currently identified user in |
---|
| 293 | * Identification block menu, in case the identifed user is granted to |
---|
| 294 | * duplication. Displays also the connection link for generic users, if |
---|
| 295 | * required in the configuration. |
---|
[3964] | 296 | * |
---|
[6269] | 297 | * ec_duplicate_prefilter |
---|
| 298 | * is used to modify the "quick connect" block in identification menu block, |
---|
| 299 | * so that visitors identifying themselves this way, are redirected to the |
---|
| 300 | * page they're currently displaying, instead of home page. This |
---|
| 301 | * functionnality has been added at version 2.1.0 in Piwigo core |
---|
| 302 | * (see bug:1484 Redirection after quickconnect), thus it is useless to |
---|
| 303 | * implement it from here for Piwigo versions higher or equal to 2.1.0. |
---|
| 304 | * |
---|
[3964] | 305 | * @param no parameter |
---|
| 306 | * @return no return value |
---|
| 307 | */ |
---|
| 308 | |
---|
| 309 | add_event_handler('blockmanager_apply', 'duplicate_account_url'); |
---|
| 310 | |
---|
[6269] | 311 | function ec_duplicate_prefilter($content, &$smarty) { |
---|
| 312 | $search = "<legend>{'Quick connect'|@translate}</legend>"; |
---|
| 313 | $addon = '<input type="hidden" name="redirect" value="{$U_REDIRECT}">'; |
---|
| 314 | $replacement = "<legend>{'Quick connect'|@translate}</legend>".$addon; |
---|
| 315 | return str_replace($search, $replacement, $content); |
---|
| 316 | } |
---|
| 317 | |
---|
[3971] | 318 | function duplicate_account_url() { |
---|
[4554] | 319 | global $lang, $template, $user; |
---|
[6269] | 320 | |
---|
[8956] | 321 | if (version_compare(PHPWG_VERSION, '2.1.0', '<')) { |
---|
| 322 | // Makes the "quick connect" fieldset able to redirect to current page |
---|
| 323 | // after user identification, just as does the "connection" link. |
---|
| 324 | $template->assign(array('U_REDIRECT' => $_SERVER['REQUEST_URI'])); |
---|
| 325 | $template->set_prefilter('menubar', 'ec_duplicate_prefilter'); |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | // Adds duplication link, if needed |
---|
| 329 | if (!is_admin() and !is_a_guest()) if ( |
---|
| 330 | read_ec_conf('dup_allow') == '1' or ( |
---|
| 331 | read_ec_conf('dup_allow') == '2' and |
---|
| 332 | dup_allowed($user['id']) |
---|
| 333 | ) |
---|
| 334 | ) { |
---|
| 335 | $template->assign('U_REGISTER', get_root_url().'register.php'); |
---|
[4329] | 336 | if ( |
---|
[8956] | 337 | read_ec_conf('duplic_display') == '1' or ( |
---|
| 338 | read_ec_conf('duplic_display') == '2' and |
---|
| 339 | !is_generic() |
---|
[4329] | 340 | ) |
---|
| 341 | ) { |
---|
[8956] | 342 | $lang['Register'] = $lang['Duplicate']; |
---|
| 343 | $lang['Create a new account'] = |
---|
| 344 | $lang['Create a new account with same properties']; |
---|
[4329] | 345 | } |
---|
[3971] | 346 | } |
---|
[8956] | 347 | |
---|
| 348 | // Adds connection link, if needed |
---|
| 349 | if (read_ec_conf('display_connection') == '1' and is_generic()) { |
---|
| 350 | // Adds connection link |
---|
| 351 | $template->assign( |
---|
| 352 | 'U_LOGIN', |
---|
| 353 | get_root_url().'identification.php?redirect='.$_SERVER['REQUEST_URI'] |
---|
| 354 | ); |
---|
| 355 | } |
---|
[3964] | 356 | } |
---|
| 357 | |
---|
[4553] | 358 | add_event_handler( |
---|
| 359 | 'get_admin_plugin_menu_links', |
---|
| 360 | array(&$obj, 'plugin_admin_menu') |
---|
| 361 | ); |
---|
[3964] | 362 | set_plugin_data($plugin['id'], $obj); |
---|
| 363 | |
---|
| 364 | ?> |
---|