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