[3969] | 1 | <?php |
---|
[3964] | 2 | |
---|
| 3 | /* |
---|
| 4 | Plugin Name: Event Cats |
---|
| 5 | Version: 1.0.0 |
---|
[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. |
---|
[4019] | 7 | Plugin URI: http://piwigo.org/svn/extensions/event_cats |
---|
[3964] | 8 | Author: P@t, LucMorizur |
---|
| 9 | Author URI: http://www.gauchon.fr, http://lucmorizur.free.fr |
---|
| 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 | |
---|
| 34 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 35 | |
---|
| 36 | // pour faciliter le debug - make debug easier :o) |
---|
| 37 | //ini_set('error_reporting', E_ALL); |
---|
| 38 | //ini_set('display_errors', true); |
---|
| 39 | |
---|
[4239] | 40 | global $conf, $prefixeTable, $ec_lists, $ec_debug, |
---|
[3964] | 41 | $ec_ap_ok; // whether Additional Pages is installed and activated |
---|
| 42 | |
---|
| 43 | define('EVNTCATS_INFO_VERSION','1.0.0'); |
---|
| 44 | define('EVNTCATS_PATH',PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)). '/'); |
---|
| 45 | define('EVNTCATS_TABLE',$prefixeTable.'event_cats'); |
---|
| 46 | define('ROOT_URL',get_absolute_root_url()); |
---|
| 47 | |
---|
| 48 | $ec_ap_ok = defined('AP_DIR'); |
---|
| 49 | |
---|
[4239] | 50 | if (!isset($ec_lists)) $ec_lists = array(); |
---|
[3964] | 51 | |
---|
[4169] | 52 | include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php'); |
---|
[3964] | 53 | |
---|
| 54 | class event_cats { |
---|
| 55 | // Sets the administration panel of the plugin |
---|
| 56 | function plugin_admin_menu($menu) { |
---|
| 57 | array_push($menu, |
---|
| 58 | array( |
---|
| 59 | 'NAME' => 'Event Cats', |
---|
| 60 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__). |
---|
| 61 | '/admin/evntcats_admin.php') |
---|
| 62 | ) |
---|
| 63 | ); |
---|
| 64 | return $menu; |
---|
| 65 | } |
---|
| 66 | } // End class |
---|
| 67 | |
---|
| 68 | $obj = new event_cats(); |
---|
| 69 | |
---|
| 70 | // Admin help management |
---|
| 71 | add_event_handler('get_popup_help_content', 'ec_popup_help_content', |
---|
| 72 | EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
| 73 | |
---|
| 74 | function ec_popup_help_content($popup_help_content, $page) { |
---|
| 75 | return ( |
---|
| 76 | $help_content = ($page == 'event_cats' and is_admin()) ? |
---|
| 77 | load_language('help.html', EVNTCATS_PATH, array('return' => true)) : false |
---|
| 78 | ) ? $popup_help_content.$help_content : $popup_help_content; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | //---------------------------------- |
---|
| 82 | |
---|
| 83 | /** |
---|
| 84 | * |
---|
| 85 | * auto_log_user() |
---|
| 86 | * the function uses the value of the argument "autolog" of the posted URL, as a code |
---|
| 87 | * to know which username has to be logged in. |
---|
| 88 | * |
---|
| 89 | * @param no parameter |
---|
| 90 | * @return no return value |
---|
| 91 | */ |
---|
| 92 | |
---|
| 93 | add_event_handler('init', 'auto_log_user'); |
---|
| 94 | |
---|
| 95 | function auto_log_user() { |
---|
[3971] | 96 | global $ec_lists; |
---|
[3964] | 97 | |
---|
| 98 | $ec_ap = NULL; |
---|
| 99 | $ec_cat = NULL; |
---|
| 100 | $ec_img = NULL; |
---|
| 101 | |
---|
[4247] | 102 | // For compatibility ; must be removed |
---|
| 103 | if (isset($_GET['log'])) $_GET['autolog'] = $_GET['log']; |
---|
| 104 | // For compatibility ; must be removed |
---|
| 105 | |
---|
[3971] | 106 | if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) { |
---|
[3975] | 107 | if (!is_a_guest()) { |
---|
| 108 | $url = ''; |
---|
| 109 | foreach ($_GET as $item => $value) { |
---|
| 110 | $url.= '&'.$item.'='.$value; |
---|
| 111 | } |
---|
| 112 | logout_user(); |
---|
| 113 | redirect(make_index_url().$url); |
---|
| 114 | } |
---|
[3964] | 115 | build_ec_lists(); |
---|
| 116 | foreach ($ec_lists['ec_table'] as $ec_entry) { |
---|
| 117 | if ($code_exists = ($ec_entry['code'] == $_GET['autolog'])) break; |
---|
| 118 | } |
---|
| 119 | if ($code_exists) { |
---|
[3985] | 120 | if (is_in($ec_entry['action'], 'ec_ok')) { |
---|
[3964] | 121 | log_user($ec_entry['user_id'], false); |
---|
[3971] | 122 | if (isset($_GET['ap'])) $ec_ap = $_GET['ap']; |
---|
[3964] | 123 | if (isset($_GET['cat'])) $ec_cat = $_GET['cat']; |
---|
| 124 | if (isset($_GET['img'])) $ec_img = $_GET['img']; |
---|
[4092] | 125 | if ($ec_entry['forced'] == 'true') { |
---|
[3964] | 126 | if (empty($ec_entry['arg1']) and !empty($ec_entry['arg2'])) { |
---|
| 127 | $ec_ap = $ec_entry['arg2']; |
---|
| 128 | } |
---|
| 129 | elseif (!empty($ec_entry['arg1'])) { |
---|
| 130 | $ec_cat = $ec_entry['arg1']; |
---|
| 131 | if (!empty($ec_entry['arg2'])) $ec_img = $ec_entry['arg2']; |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | if (isset($ec_ap)) { |
---|
| 135 | if (array_key_exists($ec_ap,$ec_lists['add_pages'])) { |
---|
| 136 | redirect( |
---|
| 137 | PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | elseif (isset($ec_cat)) { |
---|
| 141 | if (array_key_exists($ec_cat, $ec_lists['categories'])) { |
---|
| 142 | if (isset($ec_img)) { |
---|
[4157] | 143 | if (ec_image_exists($ec_cat, $ec_img)) { |
---|
[3964] | 144 | redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat); |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | redirect(PHPWG_ROOT_PATH.'index.php?/category/'.$ec_cat); |
---|
| 148 | } |
---|
| 149 | } |
---|
[3971] | 150 | redirect(make_index_url()); |
---|
[3964] | 151 | } |
---|
| 152 | else { |
---|
[3971] | 153 | if ( |
---|
| 154 | $ec_entry['action'] == 'ec_nok' or |
---|
| 155 | $ec_entry['action'] == 'ec_nok_ap_pb' |
---|
| 156 | ) { |
---|
| 157 | if ($ec_entry['action'] == 'ec_nok_ap_pb') access_denied(); |
---|
| 158 | $ec_ap = $ec_entry['arg2']; |
---|
| 159 | if (array_key_exists($ec_ap, $ec_lists['add_pages'])) { |
---|
| 160 | redirect( |
---|
| 161 | PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap); |
---|
[3964] | 162 | } |
---|
| 163 | access_denied(); |
---|
| 164 | } |
---|
| 165 | else { |
---|
| 166 | redirect(make_index_url()); |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | else { |
---|
| 171 | if ( |
---|
[3971] | 172 | read_ec_conf('unknown_code') == 2 and |
---|
[3964] | 173 | array_key_exists( |
---|
[3971] | 174 | read_ec_conf('unknown_code_ap_id'), $ec_lists['add_pages'] |
---|
[3964] | 175 | ) |
---|
| 176 | ) { |
---|
| 177 | redirect( |
---|
| 178 | PHPWG_ROOT_PATH. |
---|
[3971] | 179 | 'index.php?/additional_page/'.read_ec_conf('unknown_code_ap_id') |
---|
[3964] | 180 | ); |
---|
| 181 | } |
---|
[3971] | 182 | elseif (read_ec_conf('unknown_code') == 1 or |
---|
| 183 | read_ec_conf('unknown_code') == 2) { |
---|
[3964] | 184 | access_denied(); |
---|
| 185 | } |
---|
| 186 | else { |
---|
| 187 | redirect(make_index_url()); |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | /** |
---|
| 194 | * |
---|
| 195 | * assign_perm_for_new_user() |
---|
| 196 | * copies/paste groups+access+properties associations of previously connected |
---|
| 197 | * username, to newly created username. |
---|
| 198 | * |
---|
| 199 | * @param no parameter |
---|
| 200 | * @return no return value |
---|
| 201 | */ |
---|
| 202 | |
---|
| 203 | add_event_handler('register_user', 'assign_perm_for_new_user'); |
---|
| 204 | |
---|
| 205 | function assign_perm_for_new_user($new_user) |
---|
[3971] | 206 | { |
---|
[3964] | 207 | global $user; |
---|
| 208 | |
---|
| 209 | if (!is_a_guest() and !is_admin()) |
---|
| 210 | { |
---|
| 211 | // User access |
---|
| 212 | $query = 'SELECT cat_id FROM '.USER_ACCESS_TABLE.' WHERE user_id = '.$user['id'].';'; |
---|
| 213 | $result = pwg_query($query); |
---|
| 214 | $insert = array(); |
---|
| 215 | while ($row = mysql_fetch_assoc($result)) |
---|
| 216 | { |
---|
| 217 | $insert[] = '('.$new_user['id'].','.$row['cat_id'].')'; |
---|
| 218 | } |
---|
| 219 | if (!empty($insert)) |
---|
| 220 | { |
---|
| 221 | pwg_query('INSERT INTO '.USER_ACCESS_TABLE.' VALUES '.implode(',', $insert).';'); |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | // User groups |
---|
| 225 | $query = 'SELECT group_id FROM '.USER_GROUP_TABLE.' WHERE user_id = '.$user['id'].';'; |
---|
| 226 | $result = pwg_query($query); |
---|
| 227 | $insert = array(); |
---|
| 228 | while ($row = mysql_fetch_assoc($result)) |
---|
| 229 | { |
---|
| 230 | $insert[] = '('.$new_user['id'].','.$row['group_id'].')'; |
---|
| 231 | } |
---|
| 232 | if (!empty($insert)) |
---|
| 233 | { |
---|
| 234 | pwg_query('INSERT INTO '.USER_GROUP_TABLE.' VALUES '.implode(',', $insert).';'); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | // User infos |
---|
| 238 | $query = 'SELECT level FROM '.USER_INFOS_TABLE.' WHERE user_id = '.$user['id'].';'; |
---|
| 239 | $result = pwg_query($query); |
---|
| 240 | $insert = array(); |
---|
| 241 | while ($row = mysql_fetch_assoc($result)) |
---|
| 242 | { |
---|
| 243 | $insert[] = '('.$new_user['id'].','.$row['level'].')'; |
---|
| 244 | } |
---|
| 245 | if (!empty($insert)) |
---|
| 246 | { |
---|
| 247 | $query = 'UPDATE '.USER_INFOS_TABLE.' SET level = '.$user['level'].' WHERE user_id = '.$new_user['id'].';'; |
---|
| 248 | pwg_query($query); |
---|
| 249 | } |
---|
[3971] | 250 | } |
---|
[3964] | 251 | } |
---|
| 252 | |
---|
| 253 | /** |
---|
| 254 | * |
---|
| 255 | * duplicate_account_url() |
---|
| 256 | * adds a link "Duplicate" in Identification block menu. |
---|
| 257 | * |
---|
| 258 | * @param no parameter |
---|
| 259 | * @return no return value |
---|
| 260 | */ |
---|
| 261 | |
---|
| 262 | add_event_handler('blockmanager_apply', 'duplicate_account_url'); |
---|
| 263 | |
---|
[3971] | 264 | function duplicate_account_url() { |
---|
| 265 | global $lang, $template; |
---|
[4233] | 266 | |
---|
| 267 | if (is_admin() and read_ec_conf('reg_display') == '0') |
---|
| 268 | change_ec_conf('reg_display', '1;'.$lang['Register']); |
---|
[3971] | 269 | if (!is_admin() and !is_a_guest()) { |
---|
[3964] | 270 | $template->assign( 'U_REGISTER', get_root_url().'register.php'); |
---|
| 271 | $lang['Create a new account'] = l10n('Duplicate account'); |
---|
| 272 | $lang['Register'] = l10n('Duplicate'); |
---|
[3971] | 273 | } |
---|
[3964] | 274 | } |
---|
| 275 | |
---|
| 276 | add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') ); |
---|
| 277 | set_plugin_data($plugin['id'], $obj); |
---|
| 278 | |
---|
| 279 | ?> |
---|