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