root / trunk / phpBB / includes / functions_user.php
History | View | Annotate | Download (94.3 kB)
| 1 | 3670 | psotfx | <?php
|
|---|---|---|---|
| 2 | 5276 | bartvb | /**
|
| 3 | 5114 | acydburn | * |
| 4 | 5114 | acydburn | * @package phpBB3 |
| 5 | 5276 | bartvb | * @copyright (c) 2005 phpBB Group |
| 6 | 11653 | git-gate | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
| 7 | 5114 | acydburn | * |
| 8 | 5114 | acydburn | */ |
| 9 | 3670 | psotfx | |
| 10 | 5114 | acydburn | /**
|
| 11 | 8146 | acydburn | * @ignore |
| 12 | 8146 | acydburn | */ |
| 13 | 8146 | acydburn | if (!defined('IN_PHPBB')) |
| 14 | 8146 | acydburn | {
|
| 15 | 8146 | acydburn | exit;
|
| 16 | 8146 | acydburn | } |
| 17 | 8146 | acydburn | |
| 18 | 8146 | acydburn | /**
|
| 19 | 5114 | acydburn | * Obtain user_ids from usernames or vice versa. Returns false on |
| 20 | 5114 | acydburn | * success else the error string |
| 21 | 7150 | acydburn | * |
| 22 | 7150 | acydburn | * @param array &$user_id_ary The user ids to check or empty if usernames used |
| 23 | 7150 | acydburn | * @param array &$username_ary The usernames to check or empty if user ids used |
| 24 | 7150 | acydburn | * @param mixed $user_type Array of user types to check, false if not restricting by user type |
| 25 | 5114 | acydburn | */ |
| 26 | 7150 | acydburn | function user_get_id_name(&$user_id_ary, &$username_ary, $user_type = false) |
| 27 | 4780 | psotfx | {
|
| 28 | 4780 | psotfx | global $db; |
| 29 | 4780 | psotfx | |
| 30 | 4780 | psotfx | // Are both arrays already filled? Yep, return else
|
| 31 | 5276 | bartvb | // are neither array filled?
|
| 32 | 4780 | psotfx | if ($user_id_ary && $username_ary) |
| 33 | 4780 | psotfx | {
|
| 34 | 5967 | acydburn | return false; |
| 35 | 4780 | psotfx | } |
| 36 | 4780 | psotfx | else if (!$user_id_ary && !$username_ary) |
| 37 | 4780 | psotfx | {
|
| 38 | 4780 | psotfx | return 'NO_USERS'; |
| 39 | 4780 | psotfx | } |
| 40 | 4780 | psotfx | |
| 41 | 4780 | psotfx | $which_ary = ($user_id_ary) ? 'user_id_ary' : 'username_ary'; |
| 42 | 4780 | psotfx | |
| 43 | 5824 | acydburn | if ($$which_ary && !is_array($$which_ary)) |
| 44 | 4780 | psotfx | {
|
| 45 | 4780 | psotfx | $$which_ary = array($$which_ary); |
| 46 | 4780 | psotfx | } |
| 47 | 4780 | psotfx | |
| 48 | 6494 | naderman | $sql_in = ($which_ary == 'user_id_ary') ? array_map('intval', $$which_ary) : array_map('utf8_clean_string', $$which_ary); |
| 49 | 4780 | psotfx | unset($$which_ary); |
| 50 | 4780 | psotfx | |
| 51 | 6114 | acydburn | $user_id_ary = $username_ary = array(); |
| 52 | 6114 | acydburn | |
| 53 | 4780 | psotfx | // Grab the user id/username records
|
| 54 | 6494 | naderman | $sql_where = ($which_ary == 'user_id_ary') ? 'user_id' : 'username_clean'; |
| 55 | 5276 | bartvb | $sql = 'SELECT user_id, username |
| 56 | 6271 | acydburn | FROM ' . USERS_TABLE . ' |
| 57 | 6271 | acydburn | WHERE ' . $db->sql_in_set($sql_where, $sql_in); |
| 58 | 6544 | acydburn | |
| 59 | 7150 | acydburn | if ($user_type !== false && !empty($user_type)) |
| 60 | 6544 | acydburn | {
|
| 61 | 7150 | acydburn | $sql .= ' AND ' . $db->sql_in_set('user_type', $user_type); |
| 62 | 6544 | acydburn | } |
| 63 | 6544 | acydburn | |
| 64 | 4780 | psotfx | $result = $db->sql_query($sql); |
| 65 | 4780 | psotfx | |
| 66 | 4780 | psotfx | if (!($row = $db->sql_fetchrow($result))) |
| 67 | 4780 | psotfx | {
|
| 68 | 6015 | acydburn | $db->sql_freeresult($result); |
| 69 | 4780 | psotfx | return 'NO_USERS'; |
| 70 | 4780 | psotfx | } |
| 71 | 4780 | psotfx | |
| 72 | 4780 | psotfx | do
|
| 73 | 4780 | psotfx | {
|
| 74 | 4780 | psotfx | $username_ary[$row['user_id']] = $row['username']; |
| 75 | 4780 | psotfx | $user_id_ary[] = $row['user_id']; |
| 76 | 4780 | psotfx | } |
| 77 | 4780 | psotfx | while ($row = $db->sql_fetchrow($result)); |
| 78 | 4780 | psotfx | $db->sql_freeresult($result); |
| 79 | 4780 | psotfx | |
| 80 | 4780 | psotfx | return false; |
| 81 | 4780 | psotfx | } |
| 82 | 4780 | psotfx | |
| 83 | 5114 | acydburn | /**
|
| 84 | 6048 | acydburn | * Get latest registered username and update database to reflect it |
| 85 | 6048 | acydburn | */ |
| 86 | 6048 | acydburn | function update_last_username() |
| 87 | 6048 | acydburn | {
|
| 88 | 6048 | acydburn | global $db; |
| 89 | 6048 | acydburn | |
| 90 | 6048 | acydburn | // Get latest username
|
| 91 | 6742 | davidmj | $sql = 'SELECT user_id, username, user_colour |
| 92 | 6048 | acydburn | FROM ' . USERS_TABLE . ' |
| 93 | 6048 | acydburn | WHERE user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') |
| 94 | 6048 | acydburn | ORDER BY user_id DESC';
|
| 95 | 6048 | acydburn | $result = $db->sql_query_limit($sql, 1); |
| 96 | 6048 | acydburn | $row = $db->sql_fetchrow($result); |
| 97 | 6048 | acydburn | $db->sql_freeresult($result); |
| 98 | 6048 | acydburn | |
| 99 | 6048 | acydburn | if ($row) |
| 100 | 6048 | acydburn | {
|
| 101 | 6048 | acydburn | set_config('newest_user_id', $row['user_id'], true); |
| 102 | 6048 | acydburn | set_config('newest_username', $row['username'], true); |
| 103 | 6742 | davidmj | set_config('newest_user_colour', $row['user_colour'], true); |
| 104 | 6048 | acydburn | } |
| 105 | 6048 | acydburn | } |
| 106 | 6048 | acydburn | |
| 107 | 6048 | acydburn | /**
|
| 108 | 5114 | acydburn | * Updates a username across all relevant tables/fields |
| 109 | 6015 | acydburn | * |
| 110 | 6015 | acydburn | * @param string $old_name the old/current username |
| 111 | 6015 | acydburn | * @param string $new_name the new username |
| 112 | 5114 | acydburn | */ |
| 113 | 4780 | psotfx | function user_update_name($old_name, $new_name) |
| 114 | 4780 | psotfx | {
|
| 115 | 5272 | acydburn | global $config, $db, $cache; |
| 116 | 4780 | psotfx | |
| 117 | 4780 | psotfx | $update_ary = array( |
| 118 | 6021 | acydburn | FORUMS_TABLE => array('forum_last_poster_name'), |
| 119 | 6021 | acydburn | MODERATOR_CACHE_TABLE => array('username'), |
| 120 | 6021 | acydburn | POSTS_TABLE => array('post_username'), |
| 121 | 6021 | acydburn | TOPICS_TABLE => array('topic_first_poster_name', 'topic_last_poster_name'), |
| 122 | 4780 | psotfx | ); |
| 123 | 4780 | psotfx | |
| 124 | 4780 | psotfx | foreach ($update_ary as $table => $field_ary) |
| 125 | 4780 | psotfx | {
|
| 126 | 4780 | psotfx | foreach ($field_ary as $field) |
| 127 | 4780 | psotfx | {
|
| 128 | 5276 | bartvb | $sql = "UPDATE $table |
| 129 | 5357 | acydburn | SET $field = '" . $db->sql_escape($new_name) . "' |
| 130 | 5357 | acydburn | WHERE $field = '" . $db->sql_escape($old_name) . "'"; |
| 131 | 4780 | psotfx | $db->sql_query($sql); |
| 132 | 4780 | psotfx | } |
| 133 | 4780 | psotfx | } |
| 134 | 4780 | psotfx | |
| 135 | 4807 | psotfx | if ($config['newest_username'] == $old_name) |
| 136 | 4807 | psotfx | {
|
| 137 | 6117 | acydburn | set_config('newest_username', $new_name, true); |
| 138 | 4807 | psotfx | } |
| 139 | 8306 | acydburn | |
| 140 | 8306 | acydburn | // Because some tables/caches use username-specific data we need to purge this here.
|
| 141 | 8306 | acydburn | $cache->destroy('sql', MODERATOR_CACHE_TABLE); |
| 142 | 4807 | psotfx | } |
| 143 | 4807 | psotfx | |
| 144 | 5114 | acydburn | /**
|
| 145 | 8379 | Kellanved | * Adds an user |
| 146 | 8379 | Kellanved | * |
| 147 | 8379 | Kellanved | * @param mixed $user_row An array containing the following keys (and the appropriate values): username, group_id (the group to place the user in), user_email and the user_type(usually 0). Additional entries not overridden by defaults will be forwarded. |
| 148 | 8379 | Kellanved | * @param string $cp_data custom profile fields, see custom_profile::build_insert_sql_array |
| 149 | 8783 | acydburn | * @return the new user's ID. |
| 150 | 6048 | acydburn | */ |
| 151 | 6048 | acydburn | function user_add($user_row, $cp_data = false) |
| 152 | 6048 | acydburn | {
|
| 153 | 6058 | acydburn | global $db, $user, $auth, $config, $phpbb_root_path, $phpEx; |
| 154 | 6048 | acydburn | |
| 155 | 6056 | acydburn | if (empty($user_row['username']) || !isset($user_row['group_id']) || !isset($user_row['user_email']) || !isset($user_row['user_type'])) |
| 156 | 6048 | acydburn | {
|
| 157 | 6048 | acydburn | return false; |
| 158 | 6048 | acydburn | } |
| 159 | 6048 | acydburn | |
| 160 | 7748 | acydburn | $username_clean = utf8_clean_string($user_row['username']); |
| 161 | 7748 | acydburn | |
| 162 | 7748 | acydburn | if (empty($username_clean)) |
| 163 | 7748 | acydburn | {
|
| 164 | 7748 | acydburn | return false; |
| 165 | 7748 | acydburn | } |
| 166 | 7748 | acydburn | |
| 167 | 6048 | acydburn | $sql_ary = array( |
| 168 | 6048 | acydburn | 'username' => $user_row['username'], |
| 169 | 7748 | acydburn | 'username_clean' => $username_clean, |
| 170 | 6048 | acydburn | 'user_password' => (isset($user_row['user_password'])) ? $user_row['user_password'] : '', |
| 171 | 6743 | davidmj | 'user_pass_convert' => 0, |
| 172 | 6628 | acydburn | 'user_email' => strtolower($user_row['user_email']), |
| 173 | 10060 | nickvergessen | 'user_email_hash' => phpbb_email_hash($user_row['user_email']), |
| 174 | 6048 | acydburn | 'group_id' => $user_row['group_id'], |
| 175 | 6048 | acydburn | 'user_type' => $user_row['user_type'], |
| 176 | 6048 | acydburn | ); |
| 177 | 6048 | acydburn | |
| 178 | 6048 | acydburn | // These are the additional vars able to be specified
|
| 179 | 6048 | acydburn | $additional_vars = array( |
| 180 | 6048 | acydburn | 'user_permissions' => '', |
| 181 | 6151 | naderman | 'user_timezone' => $config['board_timezone'], |
| 182 | 6048 | acydburn | 'user_dateformat' => $config['default_dateformat'], |
| 183 | 6048 | acydburn | 'user_lang' => $config['default_lang'], |
| 184 | 8494 | acydburn | 'user_style' => (int) $config['default_style'], |
| 185 | 6048 | acydburn | 'user_actkey' => '', |
| 186 | 6048 | acydburn | 'user_ip' => '', |
| 187 | 6048 | acydburn | 'user_regdate' => time(), |
| 188 | 6383 | acydburn | 'user_passchg' => time(), |
| 189 | 9696 | rxu | 'user_options' => 230271, |
| 190 | 9636 | acydburn | // We do not set the new flag here - registration scripts need to specify it
|
| 191 | 9636 | acydburn | 'user_new' => 0, |
| 192 | 6048 | acydburn | |
| 193 | 6394 | grahamje | 'user_inactive_reason' => 0, |
| 194 | 6394 | grahamje | 'user_inactive_time' => 0, |
| 195 | 6048 | acydburn | 'user_lastmark' => time(), |
| 196 | 6048 | acydburn | 'user_lastvisit' => 0, |
| 197 | 6048 | acydburn | 'user_lastpost_time' => 0, |
| 198 | 6048 | acydburn | 'user_lastpage' => '', |
| 199 | 6048 | acydburn | 'user_posts' => 0, |
| 200 | 7994 | acydburn | 'user_dst' => (int) $config['board_dst'], |
| 201 | 6048 | acydburn | 'user_colour' => '', |
| 202 | 6663 | acydburn | 'user_occ' => '', |
| 203 | 6524 | davidmj | 'user_interests' => '', |
| 204 | 6048 | acydburn | 'user_avatar' => '', |
| 205 | 6048 | acydburn | 'user_avatar_type' => 0, |
| 206 | 6048 | acydburn | 'user_avatar_width' => 0, |
| 207 | 6048 | acydburn | 'user_avatar_height' => 0, |
| 208 | 6048 | acydburn | 'user_new_privmsg' => 0, |
| 209 | 6048 | acydburn | 'user_unread_privmsg' => 0, |
| 210 | 6048 | acydburn | 'user_last_privmsg' => 0, |
| 211 | 6048 | acydburn | 'user_message_rules' => 0, |
| 212 | 6048 | acydburn | 'user_full_folder' => PRIVMSGS_NO_BOX, |
| 213 | 6048 | acydburn | 'user_emailtime' => 0, |
| 214 | 6048 | acydburn | |
| 215 | 6048 | acydburn | 'user_notify' => 0, |
| 216 | 6048 | acydburn | 'user_notify_pm' => 1, |
| 217 | 6048 | acydburn | 'user_notify_type' => NOTIFY_EMAIL, |
| 218 | 6048 | acydburn | 'user_allow_pm' => 1, |
| 219 | 6048 | acydburn | 'user_allow_viewonline' => 1, |
| 220 | 6048 | acydburn | 'user_allow_viewemail' => 1, |
| 221 | 6048 | acydburn | 'user_allow_massemail' => 1, |
| 222 | 6048 | acydburn | |
| 223 | 6048 | acydburn | 'user_sig' => '', |
| 224 | 6048 | acydburn | 'user_sig_bbcode_uid' => '', |
| 225 | 6209 | davidmj | 'user_sig_bbcode_bitfield' => '', |
| 226 | 8350 | acydburn | |
| 227 | 8121 | kellanved | 'user_form_salt' => unique_id(),
|
| 228 | 6048 | acydburn | ); |
| 229 | 6048 | acydburn | |
| 230 | 6048 | acydburn | // Now fill the sql array with not required variables
|
| 231 | 6048 | acydburn | foreach ($additional_vars as $key => $default_value) |
| 232 | 6048 | acydburn | {
|
| 233 | 6048 | acydburn | $sql_ary[$key] = (isset($user_row[$key])) ? $user_row[$key] : $default_value; |
| 234 | 6048 | acydburn | } |
| 235 | 6048 | acydburn | |
| 236 | 6058 | acydburn | // Any additional variables in $user_row not covered above?
|
| 237 | 6058 | acydburn | $remaining_vars = array_diff(array_keys($user_row), array_keys($sql_ary)); |
| 238 | 6058 | acydburn | |
| 239 | 6058 | acydburn | // Now fill our sql array with the remaining vars
|
| 240 | 6058 | acydburn | if (sizeof($remaining_vars)) |
| 241 | 6058 | acydburn | {
|
| 242 | 6058 | acydburn | foreach ($remaining_vars as $key) |
| 243 | 6058 | acydburn | {
|
| 244 | 6058 | acydburn | $sql_ary[$key] = $user_row[$key]; |
| 245 | 6058 | acydburn | } |
| 246 | 6058 | acydburn | } |
| 247 | 6058 | acydburn | |
| 248 | 6238 | davidmj | $sql = 'INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); |
| 249 | 6048 | acydburn | $db->sql_query($sql); |
| 250 | 6048 | acydburn | |
| 251 | 6048 | acydburn | $user_id = $db->sql_nextid(); |
| 252 | 6048 | acydburn | |
| 253 | 6048 | acydburn | // Insert Custom Profile Fields
|
| 254 | 6048 | acydburn | if ($cp_data !== false && sizeof($cp_data)) |
| 255 | 6048 | acydburn | {
|
| 256 | 6048 | acydburn | $cp_data['user_id'] = (int) $user_id; |
| 257 | 6058 | acydburn | |
| 258 | 6058 | acydburn | if (!class_exists('custom_profile')) |
| 259 | 6058 | acydburn | {
|
| 260 | 6058 | acydburn | include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx); |
| 261 | 6058 | acydburn | } |
| 262 | 6058 | acydburn | |
| 263 | 8146 | acydburn | $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . |
| 264 | 6058 | acydburn | $db->sql_build_array('INSERT', custom_profile::build_insert_sql_array($cp_data)); |
| 265 | 6048 | acydburn | $db->sql_query($sql); |
| 266 | 6048 | acydburn | } |
| 267 | 6048 | acydburn | |
| 268 | 6048 | acydburn | // Place into appropriate group...
|
| 269 | 6048 | acydburn | $sql = 'INSERT INTO ' . USER_GROUP_TABLE . ' ' . $db->sql_build_array('INSERT', array( |
| 270 | 6048 | acydburn | 'user_id' => (int) $user_id, |
| 271 | 6048 | acydburn | 'group_id' => (int) $user_row['group_id'], |
| 272 | 6048 | acydburn | 'user_pending' => 0) |
| 273 | 6048 | acydburn | ); |
| 274 | 6048 | acydburn | $db->sql_query($sql); |
| 275 | 6048 | acydburn | |
| 276 | 6114 | acydburn | // Now make it the users default group...
|
| 277 | 6782 | davidmj | group_set_user_default($user_row['group_id'], array($user_id), false); |
| 278 | 6114 | acydburn | |
| 279 | 9636 | acydburn | // Add to newly registered users group if user_new is 1
|
| 280 | 9636 | acydburn | if ($config['new_member_post_limit'] && $sql_ary['user_new']) |
| 281 | 9636 | acydburn | {
|
| 282 | 9636 | acydburn | $sql = 'SELECT group_id |
| 283 | 9636 | acydburn | FROM ' . GROUPS_TABLE . " |
| 284 | 9636 | acydburn | WHERE group_name = 'NEWLY_REGISTERED' |
| 285 | 9636 | acydburn | AND group_type = " . GROUP_SPECIAL; |
| 286 | 9636 | acydburn | $result = $db->sql_query($sql); |
| 287 | 9636 | acydburn | $add_group_id = (int) $db->sql_fetchfield('group_id'); |
| 288 | 9636 | acydburn | $db->sql_freeresult($result); |
| 289 | 9636 | acydburn | |
| 290 | 9636 | acydburn | if ($add_group_id) |
| 291 | 9636 | acydburn | {
|
| 292 | 10003 | acydburn | // Because these actions only fill the log unneccessarily we skip the add_log() entry with a little hack. :/
|
| 293 | 10003 | acydburn | $GLOBALS['skip_add_log'] = true; |
| 294 | 10003 | acydburn | |
| 295 | 9636 | acydburn | // Add user to "newly registered users" group and set to default group if admin specified so.
|
| 296 | 9636 | acydburn | if ($config['new_member_group_default']) |
| 297 | 9636 | acydburn | {
|
| 298 | 9636 | acydburn | group_user_add($add_group_id, $user_id, false, false, true); |
| 299 | 10640 | git-gate | $user_row['group_id'] = $add_group_id; |
| 300 | 9636 | acydburn | } |
| 301 | 9636 | acydburn | else
|
| 302 | 9636 | acydburn | {
|
| 303 | 9636 | acydburn | group_user_add($add_group_id, $user_id); |
| 304 | 9636 | acydburn | } |
| 305 | 10003 | acydburn | |
| 306 | 10003 | acydburn | unset($GLOBALS['skip_add_log']); |
| 307 | 9636 | acydburn | } |
| 308 | 9636 | acydburn | } |
| 309 | 9636 | acydburn | |
| 310 | 6151 | naderman | // set the newest user and adjust the user count if the user is a normal user and no activation mail is sent
|
| 311 | 10099 | bantu | if ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_FOUNDER) |
| 312 | 6151 | naderman | {
|
| 313 | 6151 | naderman | set_config('newest_user_id', $user_id, true); |
| 314 | 6151 | naderman | set_config('newest_username', $user_row['username'], true); |
| 315 | 9398 | acydburn | set_config_count('num_users', 1, true); |
| 316 | 6782 | davidmj | |
| 317 | 6782 | davidmj | $sql = 'SELECT group_colour |
| 318 | 6782 | davidmj | FROM ' . GROUPS_TABLE . ' |
| 319 | 8379 | Kellanved | WHERE group_id = ' . (int) $user_row['group_id']; |
| 320 | 6782 | davidmj | $result = $db->sql_query_limit($sql, 1); |
| 321 | 6782 | davidmj | $row = $db->sql_fetchrow($result); |
| 322 | 6782 | davidmj | $db->sql_freeresult($result); |
| 323 | 6782 | davidmj | |
| 324 | 6782 | davidmj | set_config('newest_user_colour', $row['group_colour'], true); |
| 325 | 6151 | naderman | } |
| 326 | 6151 | naderman | |
| 327 | 6048 | acydburn | return $user_id; |
| 328 | 6048 | acydburn | } |
| 329 | 6048 | acydburn | |
| 330 | 6048 | acydburn | /**
|
| 331 | 5114 | acydburn | * Remove User |
| 332 | 5114 | acydburn | */ |
| 333 | 5700 | acydburn | function user_delete($mode, $user_id, $post_username = false) |
| 334 | 4811 | psotfx | {
|
| 335 | 6514 | grahamje | global $cache, $config, $db, $user, $auth; |
| 336 | 6383 | acydburn | global $phpbb_root_path, $phpEx; |
| 337 | 4811 | psotfx | |
| 338 | 6803 | acydburn | $sql = 'SELECT * |
| 339 | 6803 | acydburn | FROM ' . USERS_TABLE . ' |
| 340 | 6803 | acydburn | WHERE user_id = ' . $user_id; |
| 341 | 6803 | acydburn | $result = $db->sql_query($sql); |
| 342 | 6803 | acydburn | $user_row = $db->sql_fetchrow($result); |
| 343 | 6803 | acydburn | $db->sql_freeresult($result); |
| 344 | 6803 | acydburn | |
| 345 | 6803 | acydburn | if (!$user_row) |
| 346 | 6803 | acydburn | {
|
| 347 | 6803 | acydburn | return false; |
| 348 | 6803 | acydburn | } |
| 349 | 6803 | acydburn | |
| 350 | 7527 | acydburn | // Before we begin, we will remove the reports the user issued.
|
| 351 | 7527 | acydburn | $sql = 'SELECT r.post_id, p.topic_id |
| 352 | 7527 | acydburn | FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p |
| 353 | 7527 | acydburn | WHERE r.user_id = ' . $user_id . ' |
| 354 | 7527 | acydburn | AND p.post_id = r.post_id';
|
| 355 | 7527 | acydburn | $result = $db->sql_query($sql); |
| 356 | 7527 | acydburn | |
| 357 | 7527 | acydburn | $report_posts = $report_topics = array(); |
| 358 | 7527 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 359 | 7527 | acydburn | {
|
| 360 | 7527 | acydburn | $report_posts[] = $row['post_id']; |
| 361 | 7527 | acydburn | $report_topics[] = $row['topic_id']; |
| 362 | 7527 | acydburn | } |
| 363 | 7527 | acydburn | $db->sql_freeresult($result); |
| 364 | 7527 | acydburn | |
| 365 | 7527 | acydburn | if (sizeof($report_posts)) |
| 366 | 7527 | acydburn | {
|
| 367 | 7527 | acydburn | $report_posts = array_unique($report_posts); |
| 368 | 7527 | acydburn | $report_topics = array_unique($report_topics); |
| 369 | 7527 | acydburn | |
| 370 | 7527 | acydburn | // Get a list of topics that still contain reported posts
|
| 371 | 7527 | acydburn | $sql = 'SELECT DISTINCT topic_id |
| 372 | 7527 | acydburn | FROM ' . POSTS_TABLE . ' |
| 373 | 7527 | acydburn | WHERE ' . $db->sql_in_set('topic_id', $report_topics) . ' |
| 374 | 7527 | acydburn | AND post_reported = 1 |
| 375 | 7527 | acydburn | AND ' . $db->sql_in_set('post_id', $report_posts, true); |
| 376 | 7527 | acydburn | $result = $db->sql_query($sql); |
| 377 | 7527 | acydburn | |
| 378 | 7527 | acydburn | $keep_report_topics = array(); |
| 379 | 7527 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 380 | 7527 | acydburn | {
|
| 381 | 7527 | acydburn | $keep_report_topics[] = $row['topic_id']; |
| 382 | 7527 | acydburn | } |
| 383 | 7527 | acydburn | $db->sql_freeresult($result); |
| 384 | 7527 | acydburn | |
| 385 | 7527 | acydburn | if (sizeof($keep_report_topics)) |
| 386 | 7527 | acydburn | {
|
| 387 | 7527 | acydburn | $report_topics = array_diff($report_topics, $keep_report_topics); |
| 388 | 7527 | acydburn | } |
| 389 | 7527 | acydburn | unset($keep_report_topics); |
| 390 | 7527 | acydburn | |
| 391 | 7527 | acydburn | // Now set the flags back
|
| 392 | 7527 | acydburn | $sql = 'UPDATE ' . POSTS_TABLE . ' |
| 393 | 7527 | acydburn | SET post_reported = 0 |
| 394 | 7527 | acydburn | WHERE ' . $db->sql_in_set('post_id', $report_posts); |
| 395 | 7527 | acydburn | $db->sql_query($sql); |
| 396 | 7527 | acydburn | |
| 397 | 7527 | acydburn | if (sizeof($report_topics)) |
| 398 | 7527 | acydburn | {
|
| 399 | 7527 | acydburn | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 400 | 7527 | acydburn | SET topic_reported = 0 |
| 401 | 7527 | acydburn | WHERE ' . $db->sql_in_set('topic_id', $report_topics); |
| 402 | 7527 | acydburn | $db->sql_query($sql); |
| 403 | 7527 | acydburn | } |
| 404 | 7527 | acydburn | } |
| 405 | 7527 | acydburn | |
| 406 | 7527 | acydburn | // Remove reports
|
| 407 | 7527 | acydburn | $db->sql_query('DELETE FROM ' . REPORTS_TABLE . ' WHERE user_id = ' . $user_id); |
| 408 | 7527 | acydburn | |
| 409 | 8233 | kellanved | if ($user_row['user_avatar'] && $user_row['user_avatar_type'] == AVATAR_UPLOAD) |
| 410 | 8233 | kellanved | {
|
| 411 | 8233 | kellanved | avatar_delete('user', $user_row); |
| 412 | 8233 | kellanved | } |
| 413 | 8350 | acydburn | |
| 414 | 4811 | psotfx | switch ($mode) |
| 415 | 4811 | psotfx | {
|
| 416 | 4811 | psotfx | case 'retain': |
| 417 | 6436 | acydburn | |
| 418 | 8911 | acydburn | $db->sql_transaction('begin'); |
| 419 | 8911 | acydburn | |
| 420 | 6436 | acydburn | if ($post_username === false) |
| 421 | 6436 | acydburn | {
|
| 422 | 6436 | acydburn | $post_username = $user->lang['GUEST']; |
| 423 | 6436 | acydburn | } |
| 424 | 6436 | acydburn | |
| 425 | 7881 | acydburn | // If the user is inactive and newly registered we assume no posts from this user being there...
|
| 426 | 7881 | acydburn | if ($user_row['user_type'] == USER_INACTIVE && $user_row['user_inactive_reason'] == INACTIVE_REGISTER && !$user_row['user_posts']) |
| 427 | 7881 | acydburn | {
|
| 428 | 7881 | acydburn | } |
| 429 | 7881 | acydburn | else
|
| 430 | 7881 | acydburn | {
|
| 431 | 7881 | acydburn | $sql = 'UPDATE ' . FORUMS_TABLE . ' |
| 432 | 7881 | acydburn | SET forum_last_poster_id = ' . ANONYMOUS . ", forum_last_poster_name = '" . $db->sql_escape($post_username) . "', forum_last_poster_colour = '' |
| 433 | 7881 | acydburn | WHERE forum_last_poster_id = $user_id"; |
| 434 | 7881 | acydburn | $db->sql_query($sql); |
| 435 | 4811 | psotfx | |
| 436 | 7881 | acydburn | $sql = 'UPDATE ' . POSTS_TABLE . ' |
| 437 | 7881 | acydburn | SET poster_id = ' . ANONYMOUS . ", post_username = '" . $db->sql_escape($post_username) . "' |
| 438 | 7881 | acydburn | WHERE poster_id = $user_id"; |
| 439 | 7881 | acydburn | $db->sql_query($sql); |
| 440 | 4811 | psotfx | |
| 441 | 7881 | acydburn | $sql = 'UPDATE ' . POSTS_TABLE . ' |
| 442 | 7881 | acydburn | SET post_edit_user = ' . ANONYMOUS . " |
| 443 | 7881 | acydburn | WHERE post_edit_user = $user_id"; |
| 444 | 7881 | acydburn | $db->sql_query($sql); |
| 445 | 6436 | acydburn | |
| 446 | 7881 | acydburn | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 447 | 7881 | acydburn | SET topic_poster = ' . ANONYMOUS . ", topic_first_poster_name = '" . $db->sql_escape($post_username) . "', topic_first_poster_colour = '' |
| 448 | 7881 | acydburn | WHERE topic_poster = $user_id"; |
| 449 | 7881 | acydburn | $db->sql_query($sql); |
| 450 | 4811 | psotfx | |
| 451 | 7881 | acydburn | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 452 | 7881 | acydburn | SET topic_last_poster_id = ' . ANONYMOUS . ", topic_last_poster_name = '" . $db->sql_escape($post_username) . "', topic_last_poster_colour = '' |
| 453 | 7881 | acydburn | WHERE topic_last_poster_id = $user_id"; |
| 454 | 7881 | acydburn | $db->sql_query($sql); |
| 455 | 6513 | acydburn | |
| 456 | 9599 | rxu | $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' |
| 457 | 9599 | rxu | SET poster_id = ' . ANONYMOUS . " |
| 458 | 9599 | rxu | WHERE poster_id = $user_id"; |
| 459 | 9599 | rxu | $db->sql_query($sql); |
| 460 | 9599 | rxu | |
| 461 | 7881 | acydburn | // Since we change every post by this author, we need to count this amount towards the anonymous user
|
| 462 | 6513 | acydburn | |
| 463 | 7881 | acydburn | // Update the post count for the anonymous user
|
| 464 | 7881 | acydburn | if ($user_row['user_posts']) |
| 465 | 7881 | acydburn | {
|
| 466 | 7881 | acydburn | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 467 | 7881 | acydburn | SET user_posts = user_posts + ' . $user_row['user_posts'] . ' |
| 468 | 7881 | acydburn | WHERE user_id = ' . ANONYMOUS; |
| 469 | 7881 | acydburn | $db->sql_query($sql); |
| 470 | 7881 | acydburn | } |
| 471 | 6513 | acydburn | } |
| 472 | 8911 | acydburn | |
| 473 | 8911 | acydburn | $db->sql_transaction('commit'); |
| 474 | 8911 | acydburn | |
| 475 | 5700 | acydburn | break;
|
| 476 | 4811 | psotfx | |
| 477 | 4811 | psotfx | case 'remove': |
| 478 | 4811 | psotfx | |
| 479 | 4811 | psotfx | if (!function_exists('delete_posts')) |
| 480 | 4811 | psotfx | {
|
| 481 | 6803 | acydburn | include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); |
| 482 | 4811 | psotfx | } |
| 483 | 4811 | psotfx | |
| 484 | 4811 | psotfx | // Delete posts, attachments, etc.
|
| 485 | 4811 | psotfx | delete_posts('poster_id', $user_id); |
| 486 | 4811 | psotfx | |
| 487 | 6015 | acydburn | break;
|
| 488 | 4811 | psotfx | } |
| 489 | 4811 | psotfx | |
| 490 | 8911 | acydburn | $db->sql_transaction('begin'); |
| 491 | 8911 | acydburn | |
| 492 | 10651 | git-gate | $table_ary = array(USERS_TABLE, USER_GROUP_TABLE, TOPICS_WATCH_TABLE, FORUMS_WATCH_TABLE, ACL_USERS_TABLE, TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, FORUMS_TRACK_TABLE, PROFILE_FIELDS_DATA_TABLE, MODERATOR_CACHE_TABLE, DRAFTS_TABLE, BOOKMARKS_TABLE, SESSIONS_KEYS_TABLE, PRIVMSGS_FOLDER_TABLE, PRIVMSGS_RULES_TABLE); |
| 493 | 4811 | psotfx | |
| 494 | 4811 | psotfx | foreach ($table_ary as $table) |
| 495 | 4811 | psotfx | {
|
| 496 | 5276 | bartvb | $sql = "DELETE FROM $table |
| 497 | 4811 | psotfx | WHERE user_id = $user_id"; |
| 498 | 4811 | psotfx | $db->sql_query($sql); |
| 499 | 4811 | psotfx | } |
| 500 | 4811 | psotfx | |
| 501 | 6511 | acydburn | $cache->destroy('sql', MODERATOR_CACHE_TABLE); |
| 502 | 6511 | acydburn | |
| 503 | 10053 | acydburn | // Delete user log entries about this user
|
| 504 | 10053 | acydburn | $sql = 'DELETE FROM ' . LOG_TABLE . ' |
| 505 | 10053 | acydburn | WHERE reportee_id = ' . $user_id; |
| 506 | 10053 | acydburn | $db->sql_query($sql); |
| 507 | 10053 | acydburn | |
| 508 | 10053 | acydburn | // Change user_id to anonymous for this users triggered events
|
| 509 | 10053 | acydburn | $sql = 'UPDATE ' . LOG_TABLE . ' |
| 510 | 10053 | acydburn | SET user_id = ' . ANONYMOUS . ' |
| 511 | 10053 | acydburn | WHERE user_id = ' . $user_id; |
| 512 | 10053 | acydburn | $db->sql_query($sql); |
| 513 | 10053 | acydburn | |
| 514 | 9569 | bantu | // Delete the user_id from the zebra table
|
| 515 | 9569 | bantu | $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' |
| 516 | 9569 | bantu | WHERE user_id = ' . $user_id . ' |
| 517 | 9569 | bantu | OR zebra_id = ' . $user_id; |
| 518 | 9569 | bantu | $db->sql_query($sql); |
| 519 | 9569 | bantu | |
| 520 | 9249 | terrafrost | // Delete the user_id from the banlist
|
| 521 | 9351 | acydburn | $sql = 'DELETE FROM ' . BANLIST_TABLE . ' |
| 522 | 9249 | terrafrost | WHERE ban_userid = ' . $user_id; |
| 523 | 9249 | terrafrost | $db->sql_query($sql); |
| 524 | 9249 | terrafrost | |
| 525 | 9342 | terrafrost | // Delete the user_id from the session table
|
| 526 | 9342 | terrafrost | $sql = 'DELETE FROM ' . SESSIONS_TABLE . ' |
| 527 | 9342 | terrafrost | WHERE session_user_id = ' . $user_id; |
| 528 | 9342 | terrafrost | $db->sql_query($sql); |
| 529 | 9342 | terrafrost | |
| 530 | 6342 | acydburn | // Remove any undelivered mails...
|
| 531 | 6342 | acydburn | $sql = 'SELECT msg_id, user_id |
| 532 | 6342 | acydburn | FROM ' . PRIVMSGS_TO_TABLE . ' |
| 533 | 6342 | acydburn | WHERE author_id = ' . $user_id . ' |
| 534 | 6342 | acydburn | AND folder_id = ' . PRIVMSGS_NO_BOX; |
| 535 | 6342 | acydburn | $result = $db->sql_query($sql); |
| 536 | 6342 | acydburn | |
| 537 | 6342 | acydburn | $undelivered_msg = $undelivered_user = array(); |
| 538 | 6342 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 539 | 6342 | acydburn | {
|
| 540 | 6342 | acydburn | $undelivered_msg[] = $row['msg_id']; |
| 541 | 6342 | acydburn | $undelivered_user[$row['user_id']][] = true; |
| 542 | 6342 | acydburn | } |
| 543 | 6342 | acydburn | $db->sql_freeresult($result); |
| 544 | 6342 | acydburn | |
| 545 | 6342 | acydburn | if (sizeof($undelivered_msg)) |
| 546 | 6342 | acydburn | {
|
| 547 | 6342 | acydburn | $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' |
| 548 | 6342 | acydburn | WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg); |
| 549 | 6342 | acydburn | $db->sql_query($sql); |
| 550 | 6342 | acydburn | } |
| 551 | 6342 | acydburn | |
| 552 | 6342 | acydburn | $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' |
| 553 | 6342 | acydburn | WHERE author_id = ' . $user_id . ' |
| 554 | 6342 | acydburn | AND folder_id = ' . PRIVMSGS_NO_BOX; |
| 555 | 6342 | acydburn | $db->sql_query($sql); |
| 556 | 6342 | acydburn | |
| 557 | 6650 | acydburn | // Delete all to-information
|
| 558 | 6342 | acydburn | $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' |
| 559 | 6342 | acydburn | WHERE user_id = ' . $user_id; |
| 560 | 6342 | acydburn | $db->sql_query($sql); |
| 561 | 6342 | acydburn | |
| 562 | 6342 | acydburn | // Set the remaining author id to anonymous - this way users are still able to read messages from users being removed
|
| 563 | 6342 | acydburn | $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . ' |
| 564 | 6342 | acydburn | SET author_id = ' . ANONYMOUS . ' |
| 565 | 6342 | acydburn | WHERE author_id = ' . $user_id; |
| 566 | 6342 | acydburn | $db->sql_query($sql); |
| 567 | 6342 | acydburn | |
| 568 | 6342 | acydburn | $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' |
| 569 | 6342 | acydburn | SET author_id = ' . ANONYMOUS . ' |
| 570 | 6342 | acydburn | WHERE author_id = ' . $user_id; |
| 571 | 6342 | acydburn | $db->sql_query($sql); |
| 572 | 6342 | acydburn | |
| 573 | 6342 | acydburn | foreach ($undelivered_user as $_user_id => $ary) |
| 574 | 6342 | acydburn | {
|
| 575 | 6342 | acydburn | if ($_user_id == $user_id) |
| 576 | 6342 | acydburn | {
|
| 577 | 6342 | acydburn | continue;
|
| 578 | 6342 | acydburn | } |
| 579 | 6342 | acydburn | |
| 580 | 8146 | acydburn | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 581 | 6342 | acydburn | SET user_new_privmsg = user_new_privmsg - ' . sizeof($ary) . ', |
| 582 | 6342 | acydburn | user_unread_privmsg = user_unread_privmsg - ' . sizeof($ary) . ' |
| 583 | 6342 | acydburn | WHERE user_id = ' . $_user_id; |
| 584 | 6342 | acydburn | $db->sql_query($sql); |
| 585 | 6342 | acydburn | } |
| 586 | 6342 | acydburn | |
| 587 | 8911 | acydburn | $db->sql_transaction('commit'); |
| 588 | 8911 | acydburn | |
| 589 | 4811 | psotfx | // Reset newest user info if appropriate
|
| 590 | 4811 | psotfx | if ($config['newest_user_id'] == $user_id) |
| 591 | 4811 | psotfx | {
|
| 592 | 6048 | acydburn | update_last_username(); |
| 593 | 4811 | psotfx | } |
| 594 | 4811 | psotfx | |
| 595 | 6803 | acydburn | // Decrement number of users if this user is active
|
| 596 | 6803 | acydburn | if ($user_row['user_type'] != USER_INACTIVE && $user_row['user_type'] != USER_IGNORE) |
| 597 | 6803 | acydburn | {
|
| 598 | 9398 | acydburn | set_config_count('num_users', -1, true); |
| 599 | 6803 | acydburn | } |
| 600 | 4811 | psotfx | |
| 601 | 4811 | psotfx | return false; |
| 602 | 4811 | psotfx | } |
| 603 | 4811 | psotfx | |
| 604 | 5114 | acydburn | /**
|
| 605 | 6436 | acydburn | * Flips user_type from active to inactive and vice versa, handles group membership updates |
| 606 | 8146 | acydburn | * |
| 607 | 6436 | acydburn | * @param string $mode can be flip for flipping from active/inactive, activate or deactivate |
| 608 | 5114 | acydburn | */ |
| 609 | 6436 | acydburn | function user_active_flip($mode, $user_id_ary, $reason = INACTIVE_MANUAL) |
| 610 | 4807 | psotfx | {
|
| 611 | 6437 | acydburn | global $config, $db, $user, $auth; |
| 612 | 4807 | psotfx | |
| 613 | 6436 | acydburn | $deactivated = $activated = 0; |
| 614 | 6436 | acydburn | $sql_statements = array(); |
| 615 | 4807 | psotfx | |
| 616 | 6436 | acydburn | if (!is_array($user_id_ary)) |
| 617 | 4807 | psotfx | {
|
| 618 | 6436 | acydburn | $user_id_ary = array($user_id_ary); |
| 619 | 4807 | psotfx | } |
| 620 | 4807 | psotfx | |
| 621 | 6436 | acydburn | if (!sizeof($user_id_ary)) |
| 622 | 6436 | acydburn | {
|
| 623 | 6436 | acydburn | return;
|
| 624 | 6436 | acydburn | } |
| 625 | 6436 | acydburn | |
| 626 | 6436 | acydburn | $sql = 'SELECT user_id, group_id, user_type, user_inactive_reason |
| 627 | 6436 | acydburn | FROM ' . USERS_TABLE . ' |
| 628 | 6436 | acydburn | WHERE ' . $db->sql_in_set('user_id', $user_id_ary); |
| 629 | 4807 | psotfx | $result = $db->sql_query($sql); |
| 630 | 4807 | psotfx | |
| 631 | 4807 | psotfx | while ($row = $db->sql_fetchrow($result)) |
| 632 | 4807 | psotfx | {
|
| 633 | 6436 | acydburn | $sql_ary = array(); |
| 634 | 6436 | acydburn | |
| 635 | 8146 | acydburn | if ($row['user_type'] == USER_IGNORE || $row['user_type'] == USER_FOUNDER || |
| 636 | 8146 | acydburn | ($mode == 'activate' && $row['user_type'] != USER_INACTIVE) || |
| 637 | 6436 | acydburn | ($mode == 'deactivate' && $row['user_type'] == USER_INACTIVE)) |
| 638 | 4807 | psotfx | {
|
| 639 | 6436 | acydburn | continue;
|
| 640 | 4807 | psotfx | } |
| 641 | 4807 | psotfx | |
| 642 | 6436 | acydburn | if ($row['user_type'] == USER_INACTIVE) |
| 643 | 6436 | acydburn | {
|
| 644 | 6436 | acydburn | $activated++;
|
| 645 | 6436 | acydburn | } |
| 646 | 6436 | acydburn | else
|
| 647 | 6436 | acydburn | {
|
| 648 | 6436 | acydburn | $deactivated++;
|
| 649 | 4807 | psotfx | |
| 650 | 6436 | acydburn | // Remove the users session key...
|
| 651 | 6436 | acydburn | $user->reset_login_keys($row['user_id']); |
| 652 | 6436 | acydburn | } |
| 653 | 4807 | psotfx | |
| 654 | 6436 | acydburn | $sql_ary += array( |
| 655 | 6436 | acydburn | 'user_type' => ($row['user_type'] == USER_NORMAL) ? USER_INACTIVE : USER_NORMAL, |
| 656 | 6436 | acydburn | 'user_inactive_time' => ($row['user_type'] == USER_NORMAL) ? time() : 0, |
| 657 | 6436 | acydburn | 'user_inactive_reason' => ($row['user_type'] == USER_NORMAL) ? $reason : 0, |
| 658 | 6436 | acydburn | ); |
| 659 | 4807 | psotfx | |
| 660 | 6436 | acydburn | $sql_statements[$row['user_id']] = $sql_ary; |
| 661 | 5086 | acydburn | } |
| 662 | 6436 | acydburn | $db->sql_freeresult($result); |
| 663 | 5109 | acydburn | |
| 664 | 6436 | acydburn | if (sizeof($sql_statements)) |
| 665 | 4807 | psotfx | {
|
| 666 | 6436 | acydburn | foreach ($sql_statements as $user_id => $sql_ary) |
| 667 | 5700 | acydburn | {
|
| 668 | 6436 | acydburn | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 669 | 6436 | acydburn | SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
| 670 | 6436 | acydburn | WHERE user_id = ' . $user_id; |
| 671 | 6436 | acydburn | $db->sql_query($sql); |
| 672 | 5700 | acydburn | } |
| 673 | 5700 | acydburn | |
| 674 | 6436 | acydburn | $auth->acl_clear_prefetch(array_keys($sql_statements)); |
| 675 | 4807 | psotfx | } |
| 676 | 4807 | psotfx | |
| 677 | 6436 | acydburn | if ($deactivated) |
| 678 | 6436 | acydburn | {
|
| 679 | 9398 | acydburn | set_config_count('num_users', $deactivated * (-1), true); |
| 680 | 6436 | acydburn | } |
| 681 | 6436 | acydburn | |
| 682 | 6436 | acydburn | if ($activated) |
| 683 | 6436 | acydburn | {
|
| 684 | 9398 | acydburn | set_config_count('num_users', $activated, true); |
| 685 | 6436 | acydburn | } |
| 686 | 6436 | acydburn | |
| 687 | 6436 | acydburn | // Update latest username
|
| 688 | 6436 | acydburn | update_last_username(); |
| 689 | 4780 | psotfx | } |
| 690 | 4780 | psotfx | |
| 691 | 5114 | acydburn | /**
|
| 692 | 6015 | acydburn | * Add a ban or ban exclusion to the banlist. Bans either a user, an IP or an email address |
| 693 | 6015 | acydburn | * |
| 694 | 6015 | acydburn | * @param string $mode Type of ban. One of the following: user, ip, email |
| 695 | 6015 | acydburn | * @param mixed $ban Banned entity. Either string or array with usernames, ips or email addresses |
| 696 | 6015 | acydburn | * @param int $ban_len Ban length in minutes |
| 697 | 6015 | acydburn | * @param string $ban_len_other Ban length as a date (YYYY-MM-DD) |
| 698 | 6015 | acydburn | * @param boolean $ban_exclude Exclude these entities from banning? |
| 699 | 6015 | acydburn | * @param string $ban_reason String describing the reason for this ban |
| 700 | 6015 | acydburn | * @return boolean |
| 701 | 6015 | acydburn | */ |
| 702 | 5323 | acydburn | function user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason = '') |
| 703 | 4806 | psotfx | {
|
| 704 | 8202 | acydburn | global $db, $user, $auth, $cache; |
| 705 | 4806 | psotfx | |
| 706 | 4807 | psotfx | // Delete stale bans
|
| 707 | 5228 | acydburn | $sql = 'DELETE FROM ' . BANLIST_TABLE . ' |
| 708 | 5228 | acydburn | WHERE ban_end < ' . time() . ' |
| 709 | 5228 | acydburn | AND ban_end <> 0';
|
| 710 | 4806 | psotfx | $db->sql_query($sql); |
| 711 | 4806 | psotfx | |
| 712 | 4806 | psotfx | $ban_list = (!is_array($ban)) ? array_unique(explode("\n", $ban)) : $ban; |
| 713 | 4806 | psotfx | $ban_list_log = implode(', ', $ban_list); |
| 714 | 4806 | psotfx | |
| 715 | 4806 | psotfx | $current_time = time(); |
| 716 | 4806 | psotfx | |
| 717 | 5276 | bartvb | // Set $ban_end to the unix time when the ban should end. 0 is a permanent ban.
|
| 718 | 4806 | psotfx | if ($ban_len) |
| 719 | 4806 | psotfx | {
|
| 720 | 4806 | psotfx | if ($ban_len != -1 || !$ban_len_other) |
| 721 | 4806 | psotfx | {
|
| 722 | 4806 | psotfx | $ban_end = max($current_time, $current_time + ($ban_len) * 60); |
| 723 | 4806 | psotfx | } |
| 724 | 4806 | psotfx | else
|
| 725 | 4806 | psotfx | {
|
| 726 | 4806 | psotfx | $ban_other = explode('-', $ban_len_other); |
| 727 | 8146 | acydburn | if (sizeof($ban_other) == 3 && ((int)$ban_other[0] < 9999) && |
| 728 | 7591 | kellanved | (strlen($ban_other[0]) == 4) && (strlen($ban_other[1]) == 2) && (strlen($ban_other[2]) == 2)) |
| 729 | 7591 | kellanved | {
|
| 730 | 10751 | git-gate | $time_offset = (isset($user->timezone) && isset($user->dst)) ? (int) $user->timezone + (int) $user->dst : 0; |
| 731 | 10751 | git-gate | $ban_end = max($current_time, gmmktime(0, 0, 0, (int)$ban_other[1], (int)$ban_other[2], (int)$ban_other[0]) - $time_offset); |
| 732 | 7591 | kellanved | } |
| 733 | 7591 | kellanved | else
|
| 734 | 7591 | kellanved | {
|
| 735 | 11097 | git-gate | trigger_error('LENGTH_BAN_INVALID', E_USER_WARNING); |
| 736 | 7591 | kellanved | } |
| 737 | 4806 | psotfx | } |
| 738 | 4806 | psotfx | } |
| 739 | 4806 | psotfx | else
|
| 740 | 4806 | psotfx | {
|
| 741 | 4806 | psotfx | $ban_end = 0; |
| 742 | 4806 | psotfx | } |
| 743 | 4806 | psotfx | |
| 744 | 7005 | davidmj | $founder = $founder_names = array(); |
| 745 | 6104 | acydburn | |
| 746 | 6104 | acydburn | if (!$ban_exclude) |
| 747 | 6104 | acydburn | {
|
| 748 | 6104 | acydburn | // Create a list of founder...
|
| 749 | 7005 | davidmj | $sql = 'SELECT user_id, user_email, username_clean |
| 750 | 6104 | acydburn | FROM ' . USERS_TABLE . ' |
| 751 | 6104 | acydburn | WHERE user_type = ' . USER_FOUNDER; |
| 752 | 6104 | acydburn | $result = $db->sql_query($sql); |
| 753 | 6104 | acydburn | |
| 754 | 6104 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 755 | 6104 | acydburn | {
|
| 756 | 6104 | acydburn | $founder[$row['user_id']] = $row['user_email']; |
| 757 | 7005 | davidmj | $founder_names[$row['user_id']] = $row['username_clean']; |
| 758 | 6104 | acydburn | } |
| 759 | 6104 | acydburn | $db->sql_freeresult($result); |
| 760 | 6104 | acydburn | } |
| 761 | 6104 | acydburn | |
| 762 | 5293 | bartvb | $banlist_ary = array(); |
| 763 | 4806 | psotfx | |
| 764 | 4806 | psotfx | switch ($mode) |
| 765 | 4806 | psotfx | {
|
| 766 | 4806 | psotfx | case 'user': |
| 767 | 4806 | psotfx | $type = 'ban_userid'; |
| 768 | 4806 | psotfx | |
| 769 | 8668 | acydburn | // At the moment we do not support wildcard username banning
|
| 770 | 5357 | acydburn | |
| 771 | 8668 | acydburn | // Select the relevant user_ids.
|
| 772 | 8668 | acydburn | $sql_usernames = array(); |
| 773 | 8668 | acydburn | |
| 774 | 8668 | acydburn | foreach ($ban_list as $username) |
| 775 | 8668 | acydburn | {
|
| 776 | 8668 | acydburn | $username = trim($username); |
| 777 | 8668 | acydburn | if ($username != '') |
| 778 | 5293 | bartvb | {
|
| 779 | 8668 | acydburn | $clean_name = utf8_clean_string($username); |
| 780 | 8668 | acydburn | if ($clean_name == $user->data['username_clean']) |
| 781 | 5293 | bartvb | {
|
| 782 | 8668 | acydburn | trigger_error('CANNOT_BAN_YOURSELF', E_USER_WARNING); |
| 783 | 5293 | bartvb | } |
| 784 | 8668 | acydburn | if (in_array($clean_name, $founder_names)) |
| 785 | 8668 | acydburn | {
|
| 786 | 8668 | acydburn | trigger_error('CANNOT_BAN_FOUNDER', E_USER_WARNING); |
| 787 | 8668 | acydburn | } |
| 788 | 8668 | acydburn | $sql_usernames[] = $clean_name; |
| 789 | 5293 | bartvb | } |
| 790 | 8668 | acydburn | } |
| 791 | 5323 | acydburn | |
| 792 | 8668 | acydburn | // Make sure we have been given someone to ban
|
| 793 | 8668 | acydburn | if (!sizeof($sql_usernames)) |
| 794 | 8668 | acydburn | {
|
| 795 | 11097 | git-gate | trigger_error('NO_USER_SPECIFIED', E_USER_WARNING); |
| 796 | 8668 | acydburn | } |
| 797 | 6199 | grahamje | |
| 798 | 8668 | acydburn | $sql = 'SELECT user_id |
| 799 | 8668 | acydburn | FROM ' . USERS_TABLE . ' |
| 800 | 8668 | acydburn | WHERE ' . $db->sql_in_set('username_clean', $sql_usernames); |
| 801 | 6104 | acydburn | |
| 802 | 10653 | git-gate | // Do not allow banning yourself, the guest account, or founders.
|
| 803 | 10653 | git-gate | $non_bannable = array($user->data['user_id'], ANONYMOUS); |
| 804 | 8668 | acydburn | if (sizeof($founder)) |
| 805 | 8668 | acydburn | {
|
| 806 | 10653 | git-gate | $sql .= ' AND ' . $db->sql_in_set('user_id', array_merge(array_keys($founder), $non_bannable), true); |
| 807 | 8668 | acydburn | } |
| 808 | 8668 | acydburn | else
|
| 809 | 8668 | acydburn | {
|
| 810 | 10653 | git-gate | $sql .= ' AND ' . $db->sql_in_set('user_id', $non_bannable, true); |
| 811 | 8668 | acydburn | } |
| 812 | 6104 | acydburn | |
| 813 | 8668 | acydburn | $result = $db->sql_query($sql); |
| 814 | 4806 | psotfx | |
| 815 | 8668 | acydburn | if ($row = $db->sql_fetchrow($result)) |
| 816 | 8668 | acydburn | {
|
| 817 | 8668 | acydburn | do
|
| 818 | 4806 | psotfx | {
|
| 819 | 8668 | acydburn | $banlist_ary[] = (int) $row['user_id']; |
| 820 | 4806 | psotfx | } |
| 821 | 8668 | acydburn | while ($row = $db->sql_fetchrow($result)); |
| 822 | 8668 | acydburn | } |
| 823 | 8668 | acydburn | else
|
| 824 | 8668 | acydburn | {
|
| 825 | 5323 | acydburn | $db->sql_freeresult($result); |
| 826 | 11097 | git-gate | trigger_error('NO_USERS', E_USER_WARNING); |
| 827 | 4806 | psotfx | } |
| 828 | 8668 | acydburn | $db->sql_freeresult($result); |
| 829 | 5357 | acydburn | break;
|
| 830 | 4806 | psotfx | |
| 831 | 4806 | psotfx | case 'ip': |
| 832 | 4806 | psotfx | $type = 'ban_ip'; |
| 833 | 4806 | psotfx | |
| 834 | 4806 | psotfx | foreach ($ban_list as $ban_item) |
| 835 | 4806 | psotfx | {
|
| 836 | 4806 | psotfx | if (preg_match('#^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})[ ]*\-[ ]*([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$#', trim($ban_item), $ip_range_explode)) |
| 837 | 4806 | psotfx | {
|
| 838 | 5276 | bartvb | // This is an IP range
|
| 839 | 4806 | psotfx | // Don't ask about all this, just don't ask ... !
|
| 840 | 4806 | psotfx | $ip_1_counter = $ip_range_explode[1]; |
| 841 | 4806 | psotfx | $ip_1_end = $ip_range_explode[5]; |
| 842 | 4806 | psotfx | |
| 843 | 4806 | psotfx | while ($ip_1_counter <= $ip_1_end) |
| 844 | 4806 | psotfx | {
|
| 845 | 4806 | psotfx | $ip_2_counter = ($ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[2] : 0; |
| 846 | 4806 | psotfx | $ip_2_end = ($ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[6]; |
| 847 | 4806 | psotfx | |
| 848 | 5083 | acydburn | if ($ip_2_counter == 0 && $ip_2_end == 254) |
| 849 | 4806 | psotfx | {
|
| 850 | 4806 | psotfx | $ip_2_counter = 256; |
| 851 | 4806 | psotfx | $ip_2_fragment = 256; |
| 852 | 4806 | psotfx | |
| 853 | 5293 | bartvb | $banlist_ary[] = "$ip_1_counter.*"; |
| 854 | 4806 | psotfx | } |
| 855 | 4806 | psotfx | |
| 856 | 4806 | psotfx | while ($ip_2_counter <= $ip_2_end) |
| 857 | 4806 | psotfx | {
|
| 858 | 4806 | psotfx | $ip_3_counter = ($ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[3] : 0; |
| 859 | 4806 | psotfx | $ip_3_end = ($ip_2_counter < $ip_2_end || $ip_1_counter < $ip_1_end) ? 254 : $ip_range_explode[7]; |
| 860 | 4806 | psotfx | |
| 861 | 4806 | psotfx | if ($ip_3_counter == 0 && $ip_3_end == 254) |
| 862 | 4806 | psotfx | {
|
| 863 | 4806 | psotfx | $ip_3_counter = 256; |
| 864 | 4806 | psotfx | $ip_3_fragment = 256; |
| 865 | 4806 | psotfx | |
| 866 | 5293 | bartvb | $banlist_ary[] = "$ip_1_counter.$ip_2_counter.*"; |
| 867 | 4806 | psotfx | } |
| 868 | 4806 | psotfx | |
| 869 | 4806 | psotfx | while ($ip_3_counter <= $ip_3_end) |
| 870 | 4806 | psotfx | {
|
| 871 | 4806 | psotfx | $ip_4_counter = ($ip_3_counter == $ip_range_explode[3] && $ip_2_counter == $ip_range_explode[2] && $ip_1_counter == $ip_range_explode[1]) ? $ip_range_explode[4] : 0; |
| 872 | 4806 | psotfx | $ip_4_end = ($ip_3_counter < $ip_3_end || $ip_2_counter < $ip_2_end) ? 254 : $ip_range_explode[8]; |
| 873 | 4806 | psotfx | |
| 874 | 4806 | psotfx | if ($ip_4_counter == 0 && $ip_4_end == 254) |
| 875 | 4806 | psotfx | {
|
| 876 | 4806 | psotfx | $ip_4_counter = 256; |
| 877 | 4806 | psotfx | $ip_4_fragment = 256; |
| 878 | 4806 | psotfx | |
| 879 | 5293 | bartvb | $banlist_ary[] = "$ip_1_counter.$ip_2_counter.$ip_3_counter.*"; |
| 880 | 4806 | psotfx | } |
| 881 | 4806 | psotfx | |
| 882 | 4806 | psotfx | while ($ip_4_counter <= $ip_4_end) |
| 883 | 4806 | psotfx | {
|
| 884 | 5293 | bartvb | $banlist_ary[] = "$ip_1_counter.$ip_2_counter.$ip_3_counter.$ip_4_counter"; |
| 885 | 4806 | psotfx | $ip_4_counter++;
|
| 886 | 4806 | psotfx | } |
| 887 | 4806 | psotfx | $ip_3_counter++;
|
| 888 | 4806 | psotfx | } |
| 889 | 4806 | psotfx | $ip_2_counter++;
|
| 890 | 4806 | psotfx | } |
| 891 | 4806 | psotfx | $ip_1_counter++;
|
| 892 | 4806 | psotfx | } |
| 893 | 4806 | psotfx | } |
| 894 | 6816 | acydburn | else if (preg_match('#^([0-9]{1,3})\.([0-9\*]{1,3})\.([0-9\*]{1,3})\.([0-9\*]{1,3})$#', trim($ban_item)) || preg_match('#^[a-f0-9:]+\*?$#i', trim($ban_item))) |
| 895 | 6816 | acydburn | {
|
| 896 | 6816 | acydburn | // Normal IP address
|
| 897 | 6816 | acydburn | $banlist_ary[] = trim($ban_item); |
| 898 | 6816 | acydburn | } |
| 899 | 6816 | acydburn | else if (preg_match('#^\*$#', trim($ban_item))) |
| 900 | 6816 | acydburn | {
|
| 901 | 6816 | acydburn | // Ban all IPs
|
| 902 | 7961 | acydburn | $banlist_ary[] = '*'; |
| 903 | 6816 | acydburn | } |
| 904 | 4806 | psotfx | else if (preg_match('#^([\w\-_]\.?){2,}$#is', trim($ban_item))) |
| 905 | 4806 | psotfx | {
|
| 906 | 5276 | bartvb | // hostname
|
| 907 | 4806 | psotfx | $ip_ary = gethostbynamel(trim($ban_item)); |
| 908 | 4806 | psotfx | |
| 909 | 6816 | acydburn | if (!empty($ip_ary)) |
| 910 | 4806 | psotfx | {
|
| 911 | 6816 | acydburn | foreach ($ip_ary as $ip) |
| 912 | 4806 | psotfx | {
|
| 913 | 6816 | acydburn | if ($ip) |
| 914 | 6816 | acydburn | {
|
| 915 | 6880 | davidmj | if (strlen($ip) > 40) |
| 916 | 6880 | davidmj | {
|
| 917 | 6880 | davidmj | continue;
|
| 918 | 6880 | davidmj | } |
| 919 | 6880 | davidmj | |
| 920 | 6816 | acydburn | $banlist_ary[] = $ip; |
| 921 | 6816 | acydburn | } |
| 922 | 4806 | psotfx | } |
| 923 | 4806 | psotfx | } |
| 924 | 4806 | psotfx | } |
| 925 | 9594 | bantu | |
| 926 | 9594 | bantu | if (empty($banlist_ary)) |
| 927 | 5276 | bartvb | {
|
| 928 | 11097 | git-gate | trigger_error('NO_IPS_DEFINED', E_USER_WARNING); |
| 929 | 5276 | bartvb | } |
| 930 | 4806 | psotfx | } |
| 931 | 5357 | acydburn | break;
|
| 932 | 4806 | psotfx | |
| 933 | 4806 | psotfx | case 'email': |
| 934 | 4806 | psotfx | $type = 'ban_email'; |
| 935 | 4806 | psotfx | |
| 936 | 4806 | psotfx | foreach ($ban_list as $ban_item) |
| 937 | 4806 | psotfx | {
|
| 938 | 6104 | acydburn | $ban_item = trim($ban_item); |
| 939 | 6104 | acydburn | |
| 940 | 6104 | acydburn | if (preg_match('#^.*?@*|(([a-z0-9\-]+\.)+([a-z]{2,3}))$#i', $ban_item)) |
| 941 | 4806 | psotfx | {
|
| 942 | 6880 | davidmj | if (strlen($ban_item) > 100) |
| 943 | 6880 | davidmj | {
|
| 944 | 6880 | davidmj | continue;
|
| 945 | 6880 | davidmj | } |
| 946 | 6880 | davidmj | |
| 947 | 6104 | acydburn | if (!sizeof($founder) || !in_array($ban_item, $founder)) |
| 948 | 6104 | acydburn | {
|
| 949 | 6104 | acydburn | $banlist_ary[] = $ban_item; |
| 950 | 6104 | acydburn | } |
| 951 | 4806 | psotfx | } |
| 952 | 4806 | psotfx | } |
| 953 | 5276 | bartvb | |
| 954 | 5276 | bartvb | if (sizeof($ban_list) == 0) |
| 955 | 5276 | bartvb | {
|
| 956 | 11097 | git-gate | trigger_error('NO_EMAILS_DEFINED', E_USER_WARNING); |
| 957 | 5276 | bartvb | } |
| 958 | 5357 | acydburn | break;
|
| 959 | 5357 | acydburn | |
| 960 | 5357 | acydburn | default:
|
| 961 | 11097 | git-gate | trigger_error('NO_MODE', E_USER_WARNING); |
| 962 | 5357 | acydburn | break;
|
| 963 | 4806 | psotfx | } |
| 964 | 4806 | psotfx | |
| 965 | 5276 | bartvb | // Fetch currently set bans of the specified type and exclude state. Prevent duplicate bans.
|
| 966 | 6894 | acydburn | $sql_where = ($type == 'ban_userid') ? 'ban_userid <> 0' : "$type <> ''"; |
| 967 | 6894 | acydburn | |
| 968 | 4806 | psotfx | $sql = "SELECT $type |
| 969 | 4806 | psotfx | FROM " . BANLIST_TABLE . " |
| 970 | 6894 | acydburn | WHERE $sql_where |
| 971 | 8949 | toonarmy | AND ban_exclude = " . (int) $ban_exclude; |
| 972 | 4806 | psotfx | $result = $db->sql_query($sql); |
| 973 | 4806 | psotfx | |
| 974 | 6925 | acydburn | // Reset $sql_where, because we use it later...
|
| 975 | 6925 | acydburn | $sql_where = ''; |
| 976 | 6925 | acydburn | |
| 977 | 4806 | psotfx | if ($row = $db->sql_fetchrow($result)) |
| 978 | 4806 | psotfx | {
|
| 979 | 5293 | bartvb | $banlist_ary_tmp = array(); |
| 980 | 4806 | psotfx | do
|
| 981 | 4806 | psotfx | {
|
| 982 | 4806 | psotfx | switch ($mode) |
| 983 | 4806 | psotfx | {
|
| 984 | 4806 | psotfx | case 'user': |
| 985 | 5293 | bartvb | $banlist_ary_tmp[] = $row['ban_userid']; |
| 986 | 5357 | acydburn | break;
|
| 987 | 4806 | psotfx | |
| 988 | 4806 | psotfx | case 'ip': |
| 989 | 5293 | bartvb | $banlist_ary_tmp[] = $row['ban_ip']; |
| 990 | 5357 | acydburn | break;
|
| 991 | 4806 | psotfx | |
| 992 | 4806 | psotfx | case 'email': |
| 993 | 5293 | bartvb | $banlist_ary_tmp[] = $row['ban_email']; |
| 994 | 5357 | acydburn | break;
|
| 995 | 4806 | psotfx | } |
| 996 | 4806 | psotfx | } |
| 997 | 4806 | psotfx | while ($row = $db->sql_fetchrow($result)); |
| 998 | 4806 | psotfx | |
| 999 | 9840 | nickvergessen | $banlist_ary_tmp = array_intersect($banlist_ary, $banlist_ary_tmp); |
| 1000 | 9840 | nickvergessen | |
| 1001 | 9840 | nickvergessen | if (sizeof($banlist_ary_tmp)) |
| 1002 | 9840 | nickvergessen | {
|
| 1003 | 9840 | nickvergessen | // One or more entities are already banned/excluded, delete the existing bans, so they can be re-inserted with the given new length
|
| 1004 | 9840 | nickvergessen | $sql = 'DELETE FROM ' . BANLIST_TABLE . ' |
| 1005 | 9840 | nickvergessen | WHERE ' . $db->sql_in_set($type, $banlist_ary_tmp) . ' |
| 1006 | 9840 | nickvergessen | AND ban_exclude = ' . (int) $ban_exclude; |
| 1007 | 9840 | nickvergessen | $db->sql_query($sql); |
| 1008 | 9840 | nickvergessen | } |
| 1009 | 9840 | nickvergessen | |
| 1010 | 5293 | bartvb | unset($banlist_ary_tmp); |
| 1011 | 4806 | psotfx | } |
| 1012 | 5357 | acydburn | $db->sql_freeresult($result); |
| 1013 | 4806 | psotfx | |
| 1014 | 5276 | bartvb | // We have some entities to ban
|
| 1015 | 5293 | bartvb | if (sizeof($banlist_ary)) |
| 1016 | 4806 | psotfx | {
|
| 1017 | 5276 | bartvb | $sql_ary = array(); |
| 1018 | 5357 | acydburn | |
| 1019 | 5293 | bartvb | foreach ($banlist_ary as $ban_entry) |
| 1020 | 4806 | psotfx | {
|
| 1021 | 5276 | bartvb | $sql_ary[] = array( |
| 1022 | 5323 | acydburn | $type => $ban_entry, |
| 1023 | 7961 | acydburn | 'ban_start' => (int) $current_time, |
| 1024 | 7961 | acydburn | 'ban_end' => (int) $ban_end, |
| 1025 | 7961 | acydburn | 'ban_exclude' => (int) $ban_exclude, |
| 1026 | 7961 | acydburn | 'ban_reason' => (string) $ban_reason, |
| 1027 | 7961 | acydburn | 'ban_give_reason' => (string) $ban_give_reason, |
| 1028 | 5323 | acydburn | ); |
| 1029 | 4806 | psotfx | } |
| 1030 | 8350 | acydburn | |
| 1031 | 6497 | acydburn | $db->sql_multi_insert(BANLIST_TABLE, $sql_ary); |
| 1032 | 4806 | psotfx | |
| 1033 | 5276 | bartvb | // If we are banning we want to logout anyone matching the ban
|
| 1034 | 4806 | psotfx | if (!$ban_exclude) |
| 1035 | 4806 | psotfx | {
|
| 1036 | 4806 | psotfx | switch ($mode) |
| 1037 | 4806 | psotfx | {
|
| 1038 | 4806 | psotfx | case 'user': |
| 1039 | 8668 | acydburn | $sql_where = 'WHERE ' . $db->sql_in_set('session_user_id', $banlist_ary); |
| 1040 | 5357 | acydburn | break;
|
| 1041 | 4806 | psotfx | |
| 1042 | 4806 | psotfx | case 'ip': |
| 1043 | 6271 | acydburn | $sql_where = 'WHERE ' . $db->sql_in_set('session_ip', $banlist_ary); |
| 1044 | 5357 | acydburn | break;
|
| 1045 | 4806 | psotfx | |
| 1046 | 4806 | psotfx | case 'email': |
| 1047 | 5293 | bartvb | $banlist_ary_sql = array(); |
| 1048 | 5357 | acydburn | |
| 1049 | 5357 | acydburn | foreach ($banlist_ary as $ban_entry) |
| 1050 | 5276 | bartvb | {
|
| 1051 | 6271 | acydburn | $banlist_ary_sql[] = (string) str_replace('*', '%', $ban_entry); |
| 1052 | 5276 | bartvb | } |
| 1053 | 5276 | bartvb | |
| 1054 | 4806 | psotfx | $sql = 'SELECT user_id |
| 1055 | 4806 | psotfx | FROM ' . USERS_TABLE . ' |
| 1056 | 6271 | acydburn | WHERE ' . $db->sql_in_set('user_email', $banlist_ary_sql); |
| 1057 | 4806 | psotfx | $result = $db->sql_query($sql); |
| 1058 | 4806 | psotfx | |
| 1059 | 4806 | psotfx | $sql_in = array(); |
| 1060 | 5357 | acydburn | |
| 1061 | 4806 | psotfx | if ($row = $db->sql_fetchrow($result)) |
| 1062 | 4806 | psotfx | {
|
| 1063 | 4806 | psotfx | do
|
| 1064 | 4806 | psotfx | {
|
| 1065 | 4806 | psotfx | $sql_in[] = $row['user_id']; |
| 1066 | 4806 | psotfx | } |
| 1067 | 4806 | psotfx | while ($row = $db->sql_fetchrow($result)); |
| 1068 | 4806 | psotfx | |
| 1069 | 6271 | acydburn | $sql_where = 'WHERE ' . $db->sql_in_set('session_user_id', $sql_in); |
| 1070 | 4806 | psotfx | } |
| 1071 | 5357 | acydburn | $db->sql_freeresult($result); |
| 1072 | 5357 | acydburn | break;
|
| 1073 | 4806 | psotfx | } |
| 1074 | 4806 | psotfx | |
| 1075 | 5357 | acydburn | if (isset($sql_where) && $sql_where) |
| 1076 | 4806 | psotfx | {
|
| 1077 | 4806 | psotfx | $sql = 'DELETE FROM ' . SESSIONS_TABLE . " |
| 1078 | 5276 | bartvb | $sql_where"; |
| 1079 | 4806 | psotfx | $db->sql_query($sql); |
| 1080 | 6256 | acydburn | |
| 1081 | 6256 | acydburn | if ($mode == 'user') |
| 1082 | 6256 | acydburn | {
|
| 1083 | 6271 | acydburn | $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . ' ' . ((in_array('*', $banlist_ary)) ? '' : 'WHERE ' . $db->sql_in_set('user_id', $banlist_ary)); |
| 1084 | 6256 | acydburn | $db->sql_query($sql); |
| 1085 | 6256 | acydburn | } |
| 1086 | 4806 | psotfx | } |
| 1087 | 4806 | psotfx | } |
| 1088 | 4806 | psotfx | |
| 1089 | 4806 | psotfx | // Update log
|
| 1090 | 4806 | psotfx | $log_entry = ($ban_exclude) ? 'LOG_BAN_EXCLUDE_' : 'LOG_BAN_'; |
| 1091 | 7426 | acydburn | |
| 1092 | 9602 | nickvergessen | // Add to moderator log, admin log and user notes
|
| 1093 | 4806 | psotfx | add_log('admin', $log_entry . strtoupper($mode), $ban_reason, $ban_list_log); |
| 1094 | 7426 | acydburn | add_log('mod', 0, 0, $log_entry . strtoupper($mode), $ban_reason, $ban_list_log); |
| 1095 | 9602 | nickvergessen | if ($mode == 'user') |
| 1096 | 9602 | nickvergessen | {
|
| 1097 | 9602 | nickvergessen | foreach ($banlist_ary as $user_id) |
| 1098 | 9602 | nickvergessen | {
|
| 1099 | 9602 | nickvergessen | add_log('user', $user_id, $log_entry . strtoupper($mode), $ban_reason, $ban_list_log); |
| 1100 | 9602 | nickvergessen | } |
| 1101 | 9602 | nickvergessen | } |
| 1102 | 6104 | acydburn | |
| 1103 | 8202 | acydburn | $cache->destroy('sql', BANLIST_TABLE); |
| 1104 | 8202 | acydburn | |
| 1105 | 5276 | bartvb | return true; |
| 1106 | 4806 | psotfx | } |
| 1107 | 4806 | psotfx | |
| 1108 | 8202 | acydburn | // There was nothing to ban/exclude. But destroying the cache because of the removal of stale bans.
|
| 1109 | 8202 | acydburn | $cache->destroy('sql', BANLIST_TABLE); |
| 1110 | 8202 | acydburn | |
| 1111 | 4806 | psotfx | return false; |
| 1112 | 4806 | psotfx | } |
| 1113 | 4806 | psotfx | |
| 1114 | 5114 | acydburn | /**
|
| 1115 | 5114 | acydburn | * Unban User |
| 1116 | 5114 | acydburn | */ |
| 1117 | 4806 | psotfx | function user_unban($mode, $ban) |
| 1118 | 4806 | psotfx | {
|
| 1119 | 8202 | acydburn | global $db, $user, $auth, $cache; |
| 1120 | 4806 | psotfx | |
| 1121 | 4807 | psotfx | // Delete stale bans
|
| 1122 | 5228 | acydburn | $sql = 'DELETE FROM ' . BANLIST_TABLE . ' |
| 1123 | 5228 | acydburn | WHERE ban_end < ' . time() . ' |
| 1124 | 5228 | acydburn | AND ban_end <> 0';
|
| 1125 | 4806 | psotfx | $db->sql_query($sql); |
| 1126 | 4806 | psotfx | |
| 1127 | 5323 | acydburn | if (!is_array($ban)) |
| 1128 | 5323 | acydburn | {
|
| 1129 | 5323 | acydburn | $ban = array($ban); |
| 1130 | 5323 | acydburn | } |
| 1131 | 6015 | acydburn | |
| 1132 | 6271 | acydburn | $unban_sql = array_map('intval', $ban); |
| 1133 | 4806 | psotfx | |
| 1134 | 6271 | acydburn | if (sizeof($unban_sql)) |
| 1135 | 4806 | psotfx | {
|
| 1136 | 4806 | psotfx | // Grab details of bans for logging information later
|
| 1137 | 4806 | psotfx | switch ($mode) |
| 1138 | 4806 | psotfx | {
|
| 1139 | 4806 | psotfx | case 'user': |
| 1140 | 9602 | nickvergessen | $sql = 'SELECT u.username AS unban_info, u.user_id |
| 1141 | 6271 | acydburn | FROM ' . USERS_TABLE . ' u, ' . BANLIST_TABLE . ' b |
| 1142 | 6271 | acydburn | WHERE ' . $db->sql_in_set('b.ban_id', $unban_sql) . ' |
| 1143 | 6271 | acydburn | AND u.user_id = b.ban_userid';
|
| 1144 | 5357 | acydburn | break;
|
| 1145 | 4806 | psotfx | |
| 1146 | 4806 | psotfx | case 'email': |
| 1147 | 5276 | bartvb | $sql = 'SELECT ban_email AS unban_info |
| 1148 | 6271 | acydburn | FROM ' . BANLIST_TABLE . ' |
| 1149 | 6271 | acydburn | WHERE ' . $db->sql_in_set('ban_id', $unban_sql); |
| 1150 | 5357 | acydburn | break;
|
| 1151 | 4806 | psotfx | |
| 1152 | 4806 | psotfx | case 'ip': |
| 1153 | 5276 | bartvb | $sql = 'SELECT ban_ip AS unban_info |
| 1154 | 6271 | acydburn | FROM ' . BANLIST_TABLE . ' |
| 1155 | 6271 | acydburn | WHERE ' . $db->sql_in_set('ban_id', $unban_sql); |
| 1156 | 5357 | acydburn | break;
|
| 1157 | 4806 | psotfx | } |
| 1158 | 4806 | psotfx | $result = $db->sql_query($sql); |
| 1159 | 4806 | psotfx | |
| 1160 | 5276 | bartvb | $l_unban_list = ''; |
| 1161 | 9602 | nickvergessen | $user_ids_ary = array(); |
| 1162 | 4806 | psotfx | while ($row = $db->sql_fetchrow($result)) |
| 1163 | 4806 | psotfx | {
|
| 1164 | 4806 | psotfx | $l_unban_list .= (($l_unban_list != '') ? ', ' : '') . $row['unban_info']; |
| 1165 | 9611 | nickvergessen | if ($mode == 'user') |
| 1166 | 9611 | nickvergessen | {
|
| 1167 | 9611 | nickvergessen | $user_ids_ary[] = $row['user_id']; |
| 1168 | 9611 | nickvergessen | } |
| 1169 | 4806 | psotfx | } |
| 1170 | 5323 | acydburn | $db->sql_freeresult($result); |
| 1171 | 4806 | psotfx | |
| 1172 | 6271 | acydburn | $sql = 'DELETE FROM ' . BANLIST_TABLE . ' |
| 1173 | 6271 | acydburn | WHERE ' . $db->sql_in_set('ban_id', $unban_sql); |
| 1174 | 5323 | acydburn | $db->sql_query($sql); |
| 1175 | 5323 | acydburn | |
| 1176 | 9602 | nickvergessen | // Add to moderator log, admin log and user notes
|
| 1177 | 4806 | psotfx | add_log('admin', 'LOG_UNBAN_' . strtoupper($mode), $l_unban_list); |
| 1178 | 7426 | acydburn | add_log('mod', 0, 0, 'LOG_UNBAN_' . strtoupper($mode), $l_unban_list); |
| 1179 | 9602 | nickvergessen | if ($mode == 'user') |
| 1180 | 9602 | nickvergessen | {
|
| 1181 | 9602 | nickvergessen | foreach ($user_ids_ary as $user_id) |
| 1182 | 9602 | nickvergessen | {
|
| 1183 | 9602 | nickvergessen | add_log('user', $user_id, 'LOG_UNBAN_' . strtoupper($mode), $l_unban_list); |
| 1184 | 9602 | nickvergessen | } |
| 1185 | 9602 | nickvergessen | } |
| 1186 | 4806 | psotfx | } |
| 1187 | 4806 | psotfx | |
| 1188 | 8202 | acydburn | $cache->destroy('sql', BANLIST_TABLE); |
| 1189 | 8202 | acydburn | |
| 1190 | 4806 | psotfx | return false; |
| 1191 | 4806 | psotfx | } |
| 1192 | 4811 | psotfx | |
| 1193 | 5114 | acydburn | /**
|
| 1194 | 10751 | git-gate | * Internet Protocol Address Whois |
| 1195 | 10751 | git-gate | * RFC3912: WHOIS Protocol Specification |
| 1196 | 9317 | toonarmy | * |
| 1197 | 10751 | git-gate | * @param string $ip Ip address, either IPv4 or IPv6. |
| 1198 | 10751 | git-gate | * |
| 1199 | 10751 | git-gate | * @return string Empty string if not a valid ip address. |
| 1200 | 10751 | git-gate | * Otherwise make_clickable()'ed whois result. |
| 1201 | 5114 | acydburn | */ |
| 1202 | 4811 | psotfx | function user_ipwhois($ip) |
| 1203 | 4811 | psotfx | {
|
| 1204 | 10751 | git-gate | if (empty($ip)) |
| 1205 | 10751 | git-gate | {
|
| 1206 | 10751 | git-gate | return ''; |
| 1207 | 10751 | git-gate | } |
| 1208 | 4811 | psotfx | |
| 1209 | 10751 | git-gate | if (preg_match(get_preg_expression('ipv4'), $ip)) |
| 1210 | 8095 | acydburn | {
|
| 1211 | 10751 | git-gate | // IPv4 address
|
| 1212 | 10751 | git-gate | $whois_host = 'whois.arin.net.'; |
| 1213 | 10751 | git-gate | } |
| 1214 | 10751 | git-gate | else if (preg_match(get_preg_expression('ipv6'), $ip)) |
| 1215 | 10751 | git-gate | {
|
| 1216 | 10751 | git-gate | // IPv6 address
|
| 1217 | 10751 | git-gate | $whois_host = 'whois.sixxs.net.'; |
| 1218 | 10751 | git-gate | } |
| 1219 | 10751 | git-gate | else
|
| 1220 | 10751 | git-gate | {
|
| 1221 | 8095 | acydburn | return ''; |
| 1222 | 8095 | acydburn | } |
| 1223 | 8095 | acydburn | |
| 1224 | 10751 | git-gate | $ipwhois = ''; |
| 1225 | 10751 | git-gate | |
| 1226 | 10751 | git-gate | if (($fsk = @fsockopen($whois_host, 43))) |
| 1227 | 4811 | psotfx | {
|
| 1228 | 9317 | toonarmy | // CRLF as per RFC3912
|
| 1229 | 9315 | toonarmy | fputs($fsk, "$ip\r\n"); |
| 1230 | 4811 | psotfx | while (!feof($fsk)) |
| 1231 | 4811 | psotfx | {
|
| 1232 | 4811 | psotfx | $ipwhois .= fgets($fsk, 1024); |
| 1233 | 4811 | psotfx | } |
| 1234 | 4811 | psotfx | @fclose($fsk); |
| 1235 | 4811 | psotfx | } |
| 1236 | 4811 | psotfx | |
| 1237 | 9315 | toonarmy | $match = array(); |
| 1238 | 9315 | toonarmy | |
| 1239 | 10751 | git-gate | // Test for referrals from $whois_host to other whois databases, roll on rwhois
|
| 1240 | 9315 | toonarmy | if (preg_match('#ReferralServer: whois://(.+)#im', $ipwhois, $match)) |
| 1241 | 4811 | psotfx | {
|
| 1242 | 9315 | toonarmy | if (strpos($match[1], ':') !== false) |
| 1243 | 4811 | psotfx | {
|
| 1244 | 9315 | toonarmy | $pos = strrpos($match[1], ':'); |
| 1245 | 9315 | toonarmy | $server = substr($match[1], 0, $pos); |
| 1246 | 9315 | toonarmy | $port = (int) substr($match[1], $pos + 1); |
| 1247 | 9315 | toonarmy | unset($pos); |
| 1248 | 9315 | toonarmy | } |
| 1249 | 9315 | toonarmy | else
|
| 1250 | 9315 | toonarmy | {
|
| 1251 | 9315 | toonarmy | $server = $match[1]; |
| 1252 | 9315 | toonarmy | $port = 43; |
| 1253 | 9315 | toonarmy | } |
| 1254 | 9315 | toonarmy | |
| 1255 | 9315 | toonarmy | $buffer = ''; |
| 1256 | 9315 | toonarmy | |
| 1257 | 9315 | toonarmy | if (($fsk = @fsockopen($server, $port))) |
| 1258 | 9315 | toonarmy | {
|
| 1259 | 9315 | toonarmy | fputs($fsk, "$ip\r\n"); |
| 1260 | 9315 | toonarmy | while (!feof($fsk)) |
| 1261 | 4811 | psotfx | {
|
| 1262 | 9315 | toonarmy | $buffer .= fgets($fsk, 1024); |
| 1263 | 4811 | psotfx | } |
| 1264 | 9315 | toonarmy | @fclose($fsk); |
| 1265 | 4811 | psotfx | } |
| 1266 | 9315 | toonarmy | |
| 1267 | 10751 | git-gate | // Use the result from $whois_host if we don't get any result here
|
| 1268 | 9315 | toonarmy | $ipwhois = (empty($buffer)) ? $ipwhois : $buffer; |
| 1269 | 4811 | psotfx | } |
| 1270 | 4811 | psotfx | |
| 1271 | 8095 | acydburn | $ipwhois = htmlspecialchars($ipwhois); |
| 1272 | 8095 | acydburn | |
| 1273 | 8095 | acydburn | // Magic URL ;)
|
| 1274 | 8095 | acydburn | return trim(make_clickable($ipwhois, false, '')); |
| 1275 | 4811 | psotfx | } |
| 1276 | 4780 | psotfx | |
| 1277 | 5114 | acydburn | /**
|
| 1278 | 6015 | acydburn | * Data validation ... used primarily but not exclusively by ucp modules |
| 1279 | 5114 | acydburn | * |
| 1280 | 5114 | acydburn | * "Master" function for validating a range of data types |
| 1281 | 5114 | acydburn | */ |
| 1282 | 4487 | psotfx | function validate_data($data, $val_ary) |
| 1283 | 4487 | psotfx | {
|
| 1284 | 8563 | acydburn | global $user; |
| 1285 | 8563 | acydburn | |
| 1286 | 4487 | psotfx | $error = array(); |
| 1287 | 4473 | psotfx | |
| 1288 | 4487 | psotfx | foreach ($val_ary as $var => $val_seq) |
| 1289 | 4487 | psotfx | {
|
| 1290 | 4487 | psotfx | if (!is_array($val_seq[0])) |
| 1291 | 4487 | psotfx | {
|
| 1292 | 4487 | psotfx | $val_seq = array($val_seq); |
| 1293 | 4487 | psotfx | } |
| 1294 | 4473 | psotfx | |
| 1295 | 4487 | psotfx | foreach ($val_seq as $validate) |
| 1296 | 4487 | psotfx | {
|
| 1297 | 4487 | psotfx | $function = array_shift($validate); |
| 1298 | 4487 | psotfx | array_unshift($validate, $data[$var]); |
| 1299 | 4473 | psotfx | |
| 1300 | 4487 | psotfx | if ($result = call_user_func_array('validate_' . $function, $validate)) |
| 1301 | 4487 | psotfx | {
|
| 1302 | 8563 | acydburn | // Since errors are checked later for their language file existence, we need to make sure custom errors are not adjusted.
|
| 1303 | 8563 | acydburn | $error[] = (empty($user->lang[$result . '_' . strtoupper($var)])) ? $result : $result . '_' . strtoupper($var); |
| 1304 | 4473 | psotfx | } |
| 1305 | 4473 | psotfx | } |
| 1306 | 4473 | psotfx | } |
| 1307 | 4473 | psotfx | |
| 1308 | 4487 | psotfx | return $error; |
| 1309 | 4473 | psotfx | } |
| 1310 | 4473 | psotfx | |
| 1311 | 5114 | acydburn | /**
|
| 1312 | 5114 | acydburn | * Validate String |
| 1313 | 6225 | naderman | * |
| 1314 | 6225 | naderman | * @return boolean|string Either false if validation succeeded or a string which will be used as the error message (with the variable name appended) |
| 1315 | 5114 | acydburn | */ |
| 1316 | 4487 | psotfx | function validate_string($string, $optional = false, $min = 0, $max = 0) |
| 1317 | 4473 | psotfx | {
|
| 1318 | 4487 | psotfx | if (empty($string) && $optional) |
| 1319 | 4487 | psotfx | {
|
| 1320 | 4487 | psotfx | return false; |
| 1321 | 4487 | psotfx | } |
| 1322 | 4473 | psotfx | |
| 1323 | 6548 | acydburn | if ($min && utf8_strlen(htmlspecialchars_decode($string)) < $min) |
| 1324 | 4473 | psotfx | {
|
| 1325 | 4487 | psotfx | return 'TOO_SHORT'; |
| 1326 | 4487 | psotfx | } |
| 1327 | 6548 | acydburn | else if ($max && utf8_strlen(htmlspecialchars_decode($string)) > $max) |
| 1328 | 4487 | psotfx | {
|
| 1329 | 4487 | psotfx | return 'TOO_LONG'; |
| 1330 | 4487 | psotfx | } |
| 1331 | 4473 | psotfx | |
| 1332 | 4487 | psotfx | return false; |
| 1333 | 4487 | psotfx | } |
| 1334 | 4473 | psotfx | |
| 1335 | 5114 | acydburn | /**
|
| 1336 | 5114 | acydburn | * Validate Number |
| 1337 | 6225 | naderman | * |
| 1338 | 6225 | naderman | * @return boolean|string Either false if validation succeeded or a string which will be used as the error message (with the variable name appended) |
| 1339 | 5114 | acydburn | */ |
| 1340 | 4487 | psotfx | function validate_num($num, $optional = false, $min = 0, $max = 1E99) |
| 1341 | 4487 | psotfx | {
|
| 1342 | 4487 | psotfx | if (empty($num) && $optional) |
| 1343 | 4487 | psotfx | {
|
| 1344 | 4487 | psotfx | return false; |
| 1345 | 4487 | psotfx | } |
| 1346 | 4473 | psotfx | |
| 1347 | 4487 | psotfx | if ($num < $min) |
| 1348 | 4487 | psotfx | {
|
| 1349 | 4487 | psotfx | return 'TOO_SMALL'; |
| 1350 | 4473 | psotfx | } |
| 1351 | 5276 | bartvb | else if ($num > $max) |
| 1352 | 4487 | psotfx | {
|
| 1353 | 4487 | psotfx | return 'TOO_LARGE'; |
| 1354 | 4487 | psotfx | } |
| 1355 | 4487 | psotfx | |
| 1356 | 4487 | psotfx | return false; |
| 1357 | 4473 | psotfx | } |
| 1358 | 4473 | psotfx | |
| 1359 | 5114 | acydburn | /**
|
| 1360 | 8280 | kellanved | * Validate Date |
| 1361 | 8280 | kellanved | * @param String $string a date in the dd-mm-yyyy format |
| 1362 | 8280 | kellanved | * @return boolean |
| 1363 | 8280 | kellanved | */ |
| 1364 | 8280 | kellanved | function validate_date($date_string, $optional = false) |
| 1365 | 8280 | kellanved | {
|
| 1366 | 8280 | kellanved | $date = explode('-', $date_string); |
| 1367 | 8280 | kellanved | if ((empty($date) || sizeof($date) != 3) && $optional) |
| 1368 | 8280 | kellanved | {
|
| 1369 | 8280 | kellanved | return false; |
| 1370 | 8280 | kellanved | } |
| 1371 | 8280 | kellanved | else if ($optional) |
| 1372 | 8280 | kellanved | {
|
| 1373 | 8280 | kellanved | for ($field = 0; $field <= 1; $field++) |
| 1374 | 8280 | kellanved | {
|
| 1375 | 8280 | kellanved | $date[$field] = (int) $date[$field]; |
| 1376 | 8280 | kellanved | if (empty($date[$field])) |
| 1377 | 8280 | kellanved | {
|
| 1378 | 8280 | kellanved | $date[$field] = 1; |
| 1379 | 8280 | kellanved | } |
| 1380 | 8280 | kellanved | } |
| 1381 | 8280 | kellanved | $date[2] = (int) $date[2]; |
| 1382 | 8280 | kellanved | // assume an arbitrary leap year
|
| 1383 | 8280 | kellanved | if (empty($date[2])) |
| 1384 | 8280 | kellanved | {
|
| 1385 | 8280 | kellanved | $date[2] = 1980; |
| 1386 | 8280 | kellanved | } |
| 1387 | 8280 | kellanved | } |
| 1388 | 8350 | acydburn | |
| 1389 | 8280 | kellanved | if (sizeof($date) != 3 || !checkdate($date[1], $date[0], $date[2])) |
| 1390 | 8280 | kellanved | {
|
| 1391 | 8280 | kellanved | return 'INVALID'; |
| 1392 | 8280 | kellanved | } |
| 1393 | 8280 | kellanved | |
| 1394 | 8280 | kellanved | return false; |
| 1395 | 8280 | kellanved | } |
| 1396 | 8280 | kellanved | |
| 1397 | 8280 | kellanved | |
| 1398 | 8280 | kellanved | /**
|
| 1399 | 5114 | acydburn | * Validate Match |
| 1400 | 6225 | naderman | * |
| 1401 | 6225 | naderman | * @return boolean|string Either false if validation succeeded or a string which will be used as the error message (with the variable name appended) |
| 1402 | 5114 | acydburn | */ |
| 1403 | 7426 | acydburn | function validate_match($string, $optional = false, $match = '') |
| 1404 | 3870 | psotfx | {
|
| 1405 | 4487 | psotfx | if (empty($string) && $optional) |
| 1406 | 4487 | psotfx | {
|
| 1407 | 4487 | psotfx | return false; |
| 1408 | 4487 | psotfx | } |
| 1409 | 3870 | psotfx | |
| 1410 | 7426 | acydburn | if (empty($match)) |
| 1411 | 7426 | acydburn | {
|
| 1412 | 7426 | acydburn | return false; |
| 1413 | 7426 | acydburn | } |
| 1414 | 7426 | acydburn | |
| 1415 | 4487 | psotfx | if (!preg_match($match, $string)) |
| 1416 | 3870 | psotfx | {
|
| 1417 | 4487 | psotfx | return 'WRONG_DATA'; |
| 1418 | 3870 | psotfx | } |
| 1419 | 6015 | acydburn | |
| 1420 | 4487 | psotfx | return false; |
| 1421 | 4487 | psotfx | } |
| 1422 | 3870 | psotfx | |
| 1423 | 5114 | acydburn | /**
|
| 1424 | 11047 | git-gate | * Validate Language Pack ISO Name |
| 1425 | 11047 | git-gate | * |
| 1426 | 11047 | git-gate | * Tests whether a language name is valid and installed |
| 1427 | 11047 | git-gate | * |
| 1428 | 11047 | git-gate | * @param string $lang_iso The language string to test |
| 1429 | 11047 | git-gate | * |
| 1430 | 11047 | git-gate | * @return bool|string Either false if validation succeeded or |
| 1431 | 11047 | git-gate | * a string which will be used as the error message |
| 1432 | 11047 | git-gate | * (with the variable name appended) |
| 1433 | 11047 | git-gate | */ |
| 1434 | 11047 | git-gate | function validate_language_iso_name($lang_iso) |
| 1435 | 11047 | git-gate | {
|
| 1436 | 11047 | git-gate | global $db; |
| 1437 | 11047 | git-gate | |
| 1438 | 11047 | git-gate | $sql = 'SELECT lang_id |
| 1439 | 11047 | git-gate | FROM ' . LANG_TABLE . " |
| 1440 | 11047 | git-gate | WHERE lang_iso = '" . $db->sql_escape($lang_iso) . "'"; |
| 1441 | 11047 | git-gate | $result = $db->sql_query($sql); |
| 1442 | 11047 | git-gate | $lang_id = (int) $db->sql_fetchfield('lang_id'); |
| 1443 | 11047 | git-gate | $db->sql_freeresult($result); |
| 1444 | 11047 | git-gate | |
| 1445 | 11047 | git-gate | return ($lang_id) ? false : 'WRONG_DATA'; |
| 1446 | 11047 | git-gate | } |
| 1447 | 11047 | git-gate | |
| 1448 | 11047 | git-gate | /**
|
| 1449 | 5114 | acydburn | * Check to see if the username has been taken, or if it is disallowed. |
| 1450 | 5114 | acydburn | * Also checks if it includes the " character, which we don't allow in usernames. |
| 1451 | 5114 | acydburn | * Used for registering, changing names, and posting anonymously with a username |
| 1452 | 6225 | naderman | * |
| 1453 | 6894 | acydburn | * @param string $username The username to check |
| 1454 | 6894 | acydburn | * @param string $allowed_username An allowed username, default being $user->data['username'] |
| 1455 | 6894 | acydburn | * |
| 1456 | 6614 | acydburn | * @return mixed Either false if validation succeeded or a string which will be used as the error message (with the variable name appended) |
| 1457 | 5114 | acydburn | */ |
| 1458 | 6894 | acydburn | function validate_username($username, $allowed_username = false) |
| 1459 | 4213 | psotfx | {
|
| 1460 | 6571 | davidmj | global $config, $db, $user, $cache; |
| 1461 | 4019 | psotfx | |
| 1462 | 6571 | davidmj | $clean_username = utf8_clean_string($username); |
| 1463 | 6894 | acydburn | $allowed_username = ($allowed_username === false) ? $user->data['username_clean'] : utf8_clean_string($allowed_username); |
| 1464 | 6571 | davidmj | |
| 1465 | 6894 | acydburn | if ($allowed_username == $clean_username) |
| 1466 | 4487 | psotfx | {
|
| 1467 | 4487 | psotfx | return false; |
| 1468 | 4487 | psotfx | } |
| 1469 | 4487 | psotfx | |
| 1470 | 7384 | acydburn | // ... fast checks first.
|
| 1471 | 7748 | acydburn | if (strpos($username, '"') !== false || strpos($username, '"') !== false || empty($clean_username)) |
| 1472 | 7384 | acydburn | {
|
| 1473 | 7384 | acydburn | return 'INVALID_CHARS'; |
| 1474 | 7384 | acydburn | } |
| 1475 | 7384 | acydburn | |
| 1476 | 7374 | davidmj | $mbstring = $pcre = false; |
| 1477 | 7374 | davidmj | |
| 1478 | 7374 | davidmj | // generic UTF-8 character types supported?
|
| 1479 | 11379 | git-gate | if (phpbb_pcre_utf8_support())
|
| 1480 | 4487 | psotfx | {
|
| 1481 | 7374 | davidmj | $pcre = true; |
| 1482 | 7374 | davidmj | } |
| 1483 | 7374 | davidmj | else if (function_exists('mb_ereg_match')) |
| 1484 | 7374 | davidmj | {
|
| 1485 | 7374 | davidmj | mb_regex_encoding('UTF-8');
|
| 1486 | 7374 | davidmj | $mbstring = true; |
| 1487 | 7374 | davidmj | } |
| 1488 | 7374 | davidmj | |
| 1489 | 7374 | davidmj | switch ($config['allow_name_chars']) |
| 1490 | 7374 | davidmj | {
|
| 1491 | 7374 | davidmj | case 'USERNAME_CHARS_ANY': |
| 1492 | 7374 | davidmj | $pcre = true; |
| 1493 | 7374 | davidmj | $regex = '.+'; |
| 1494 | 7374 | davidmj | break;
|
| 1495 | 7374 | davidmj | |
| 1496 | 7374 | davidmj | case 'USERNAME_ALPHA_ONLY': |
| 1497 | 7374 | davidmj | $pcre = true; |
| 1498 | 7883 | davidmj | $regex = '[A-Za-z0-9]+'; |
| 1499 | 7374 | davidmj | break;
|
| 1500 | 7374 | davidmj | |
| 1501 | 7374 | davidmj | case 'USERNAME_ALPHA_SPACERS': |
| 1502 | 7374 | davidmj | $pcre = true; |
| 1503 | 7883 | davidmj | $regex = '[A-Za-z0-9-[\]_+ ]+'; |
| 1504 | 7374 | davidmj | break;
|
| 1505 | 7374 | davidmj | |
| 1506 | 7374 | davidmj | case 'USERNAME_LETTER_NUM': |
| 1507 | 7374 | davidmj | if ($pcre) |
| 1508 | 7374 | davidmj | {
|
| 1509 | 7374 | davidmj | $regex = '[\p{Lu}\p{Ll}\p{N}]+'; |
| 1510 | 7374 | davidmj | } |
| 1511 | 7374 | davidmj | else if ($mbstring) |
| 1512 | 7374 | davidmj | {
|
| 1513 | 7374 | davidmj | $regex = '[[:upper:][:lower:][:digit:]]+'; |
| 1514 | 7374 | davidmj | } |
| 1515 | 7374 | davidmj | else
|
| 1516 | 7374 | davidmj | {
|
| 1517 | 7374 | davidmj | $pcre = true; |
| 1518 | 7374 | davidmj | $regex = '[a-zA-Z0-9]+'; |
| 1519 | 7374 | davidmj | } |
| 1520 | 7374 | davidmj | break;
|
| 1521 | 7374 | davidmj | |
| 1522 | 7374 | davidmj | case 'USERNAME_LETTER_NUM_SPACERS': |
| 1523 | 7374 | davidmj | if ($pcre) |
| 1524 | 7374 | davidmj | {
|
| 1525 | 7374 | davidmj | $regex = '[-\]_+ [\p{Lu}\p{Ll}\p{N}]+'; |
| 1526 | 7374 | davidmj | } |
| 1527 | 7374 | davidmj | else if ($mbstring) |
| 1528 | 7374 | davidmj | {
|
| 1529 | 9352 | toonarmy | $regex = '[-\]_+ \[[:upper:][:lower:][:digit:]]+'; |
| 1530 | 7374 | davidmj | } |
| 1531 | 7374 | davidmj | else
|
| 1532 | 7374 | davidmj | {
|
| 1533 | 7374 | davidmj | $pcre = true; |
| 1534 | 7374 | davidmj | $regex = '[-\]_+ [a-zA-Z0-9]+'; |
| 1535 | 7374 | davidmj | } |
| 1536 | 7374 | davidmj | break;
|
| 1537 | 7374 | davidmj | |
| 1538 | 7374 | davidmj | case 'USERNAME_ASCII': |
| 1539 | 7384 | acydburn | default:
|
| 1540 | 7374 | davidmj | $pcre = true; |
| 1541 | 7374 | davidmj | $regex = '[\x01-\x7F]+'; |
| 1542 | 7374 | davidmj | break;
|
| 1543 | 7374 | davidmj | } |
| 1544 | 7374 | davidmj | |
| 1545 | 7374 | davidmj | if ($pcre) |
| 1546 | 7374 | davidmj | {
|
| 1547 | 7374 | davidmj | if (!preg_match('#^' . $regex . '$#u', $username)) |
| 1548 | 7374 | davidmj | {
|
| 1549 | 7374 | davidmj | return 'INVALID_CHARS'; |
| 1550 | 7374 | davidmj | } |
| 1551 | 7374 | davidmj | } |
| 1552 | 7374 | davidmj | else if ($mbstring) |
| 1553 | 7374 | davidmj | {
|
| 1554 | 9386 | acydburn | mb_ereg_search_init($username, '^' . $regex . '$'); |
| 1555 | 7374 | davidmj | if (!mb_ereg_search())
|
| 1556 | 7374 | davidmj | {
|
| 1557 | 7374 | davidmj | return 'INVALID_CHARS'; |
| 1558 | 7374 | davidmj | } |
| 1559 | 7374 | davidmj | } |
| 1560 | 7374 | davidmj | |
| 1561 | 4213 | psotfx | $sql = 'SELECT username |
| 1562 | 4213 | psotfx | FROM ' . USERS_TABLE . " |
| 1563 | 6571 | davidmj | WHERE username_clean = '" . $db->sql_escape($clean_username) . "'"; |
| 1564 | 4213 | psotfx | $result = $db->sql_query($sql); |
| 1565 | 6015 | acydburn | $row = $db->sql_fetchrow($result); |
| 1566 | 6015 | acydburn | $db->sql_freeresult($result); |
| 1567 | 4019 | psotfx | |
| 1568 | 6015 | acydburn | if ($row) |
| 1569 | 3670 | psotfx | {
|
| 1570 | 4213 | psotfx | return 'USERNAME_TAKEN'; |
| 1571 | 4019 | psotfx | } |
| 1572 | 4019 | psotfx | |
| 1573 | 4213 | psotfx | $sql = 'SELECT group_name |
| 1574 | 4213 | psotfx | FROM ' . GROUPS_TABLE . " |
| 1575 | 6494 | naderman | WHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($username)) . "'"; |
| 1576 | 4213 | psotfx | $result = $db->sql_query($sql); |
| 1577 | 6015 | acydburn | $row = $db->sql_fetchrow($result); |
| 1578 | 6015 | acydburn | $db->sql_freeresult($result); |
| 1579 | 4213 | psotfx | |
| 1580 | 6015 | acydburn | if ($row) |
| 1581 | 4019 | psotfx | {
|
| 1582 | 4213 | psotfx | return 'USERNAME_TAKEN'; |
| 1583 | 3670 | psotfx | } |
| 1584 | 4019 | psotfx | |
| 1585 | 6572 | acydburn | $bad_usernames = $cache->obtain_disallowed_usernames(); |
| 1586 | 6571 | davidmj | |
| 1587 | 6571 | davidmj | foreach ($bad_usernames as $bad_username) |
| 1588 | 4213 | psotfx | {
|
| 1589 | 7909 | acydburn | if (preg_match('#^' . $bad_username . '$#', $clean_username)) |
| 1590 | 3670 | psotfx | {
|
| 1591 | 4213 | psotfx | return 'USERNAME_DISALLOWED'; |
| 1592 | 3670 | psotfx | } |
| 1593 | 4213 | psotfx | } |
| 1594 | 4019 | psotfx | |
| 1595 | 4213 | psotfx | return false; |
| 1596 | 4213 | psotfx | } |
| 1597 | 4019 | psotfx | |
| 1598 | 5114 | acydburn | /**
|
| 1599 | 6317 | acydburn | * Check to see if the password meets the complexity settings |
| 1600 | 6317 | acydburn | * |
| 1601 | 6317 | acydburn | * @return boolean|string Either false if validation succeeded or a string which will be used as the error message (with the variable name appended) |
| 1602 | 6317 | acydburn | */ |
| 1603 | 6317 | acydburn | function validate_password($password) |
| 1604 | 6317 | acydburn | {
|
| 1605 | 6317 | acydburn | global $config, $db, $user; |
| 1606 | 6317 | acydburn | |
| 1607 | 11089 | git-gate | if ($password === '' || $config['pass_complex'] === 'PASS_TYPE_ANY') |
| 1608 | 6317 | acydburn | {
|
| 1609 | 11089 | git-gate | // Password empty or no password complexity required.
|
| 1610 | 6317 | acydburn | return false; |
| 1611 | 6317 | acydburn | } |
| 1612 | 6317 | acydburn | |
| 1613 | 7249 | davidmj | $pcre = $mbstring = false; |
| 1614 | 7249 | davidmj | |
| 1615 | 6814 | naderman | // generic UTF-8 character types supported?
|
| 1616 | 11379 | git-gate | if (phpbb_pcre_utf8_support())
|
| 1617 | 6317 | acydburn | {
|
| 1618 | 6814 | naderman | $upp = '\p{Lu}'; |
| 1619 | 6814 | naderman | $low = '\p{Ll}'; |
| 1620 | 6814 | naderman | $num = '\p{N}'; |
| 1621 | 6814 | naderman | $sym = '[^\p{Lu}\p{Ll}\p{N}]'; |
| 1622 | 7249 | davidmj | $pcre = true; |
| 1623 | 6317 | acydburn | } |
| 1624 | 7249 | davidmj | else if (function_exists('mb_ereg_match')) |
| 1625 | 7249 | davidmj | {
|
| 1626 | 7249 | davidmj | mb_regex_encoding('UTF-8');
|
| 1627 | 7249 | davidmj | $upp = '[[:upper:]]'; |
| 1628 | 7249 | davidmj | $low = '[[:lower:]]'; |
| 1629 | 7249 | davidmj | $num = '[[:digit:]]'; |
| 1630 | 7249 | davidmj | $sym = '[^[:upper:][:lower:][:digit:]]'; |
| 1631 | 7249 | davidmj | $mbstring = true; |
| 1632 | 7249 | davidmj | } |
| 1633 | 6814 | naderman | else
|
| 1634 | 6814 | naderman | {
|
| 1635 | 6814 | naderman | $upp = '[A-Z]'; |
| 1636 | 6814 | naderman | $low = '[a-z]'; |
| 1637 | 6814 | naderman | $num = '[0-9]'; |
| 1638 | 6814 | naderman | $sym = '[^A-Za-z0-9]'; |
| 1639 | 7249 | davidmj | $pcre = true; |
| 1640 | 6814 | naderman | } |
| 1641 | 6317 | acydburn | |
| 1642 | 6814 | naderman | $chars = array(); |
| 1643 | 6814 | naderman | |
| 1644 | 6814 | naderman | switch ($config['pass_complex']) |
| 1645 | 6814 | naderman | {
|
| 1646 | 11089 | git-gate | // No break statements below ...
|
| 1647 | 11089 | git-gate | // We require strong passwords in case pass_complex is not set or is invalid
|
| 1648 | 11089 | git-gate | default:
|
| 1649 | 6814 | naderman | |
| 1650 | 11089 | git-gate | // Require mixed case letters, numbers and symbols
|
| 1651 | 11089 | git-gate | case 'PASS_TYPE_SYMBOL': |
| 1652 | 11089 | git-gate | $chars[] = $sym; |
| 1653 | 11089 | git-gate | |
| 1654 | 11089 | git-gate | // Require mixed case letters and numbers
|
| 1655 | 6814 | naderman | case 'PASS_TYPE_ALPHA': |
| 1656 | 6814 | naderman | $chars[] = $num; |
| 1657 | 6814 | naderman | |
| 1658 | 11089 | git-gate | // Require mixed case letters
|
| 1659 | 11089 | git-gate | case 'PASS_TYPE_CASE': |
| 1660 | 6814 | naderman | $chars[] = $low; |
| 1661 | 6814 | naderman | $chars[] = $upp; |
| 1662 | 6814 | naderman | } |
| 1663 | 6814 | naderman | |
| 1664 | 7249 | davidmj | if ($pcre) |
| 1665 | 6814 | naderman | {
|
| 1666 | 7249 | davidmj | foreach ($chars as $char) |
| 1667 | 6814 | naderman | {
|
| 1668 | 7249 | davidmj | if (!preg_match('#' . $char . '#u', $password)) |
| 1669 | 7416 | acydburn | {
|
| 1670 | 7249 | davidmj | return 'INVALID_CHARS'; |
| 1671 | 7249 | davidmj | } |
| 1672 | 6814 | naderman | } |
| 1673 | 6814 | naderman | } |
| 1674 | 7249 | davidmj | else if ($mbstring) |
| 1675 | 7249 | davidmj | {
|
| 1676 | 7249 | davidmj | foreach ($chars as $char) |
| 1677 | 7249 | davidmj | {
|
| 1678 | 7885 | davidmj | if (mb_ereg($char, $password) === false) |
| 1679 | 7249 | davidmj | {
|
| 1680 | 7249 | davidmj | return 'INVALID_CHARS'; |
| 1681 | 7249 | davidmj | } |
| 1682 | 7249 | davidmj | } |
| 1683 | 7249 | davidmj | } |
| 1684 | 6814 | naderman | |
| 1685 | 6317 | acydburn | return false; |
| 1686 | 6317 | acydburn | } |
| 1687 | 6317 | acydburn | |
| 1688 | 6317 | acydburn | /**
|
| 1689 | 5114 | acydburn | * Check to see if email address is banned or already present in the DB |
| 1690 | 6225 | naderman | * |
| 1691 | 6930 | acydburn | * @param string $email The email to check |
| 1692 | 6930 | acydburn | * @param string $allowed_email An allowed email, default being $user->data['user_email'] |
| 1693 | 6930 | acydburn | * |
| 1694 | 6930 | acydburn | * @return mixed Either false if validation succeeded or a string which will be used as the error message (with the variable name appended) |
| 1695 | 5114 | acydburn | */ |
| 1696 | 6930 | acydburn | function validate_email($email, $allowed_email = false) |
| 1697 | 4213 | psotfx | {
|
| 1698 | 4213 | psotfx | global $config, $db, $user; |
| 1699 | 4019 | psotfx | |
| 1700 | 6628 | acydburn | $email = strtolower($email); |
| 1701 | 6930 | acydburn | $allowed_email = ($allowed_email === false) ? strtolower($user->data['user_email']) : strtolower($allowed_email); |
| 1702 | 6628 | acydburn | |
| 1703 | 6930 | acydburn | if ($allowed_email == $email) |
| 1704 | 3670 | psotfx | {
|
| 1705 | 4487 | psotfx | return false; |
| 1706 | 4487 | psotfx | } |
| 1707 | 3996 | psotfx | |
| 1708 | 6135 | acydburn | if (!preg_match('/^' . get_preg_expression('email') . '$/i', $email)) |
| 1709 | 4487 | psotfx | {
|
| 1710 | 4487 | psotfx | return 'EMAIL_INVALID'; |
| 1711 | 4487 | psotfx | } |
| 1712 | 4487 | psotfx | |
| 1713 | 6414 | acydburn | // Check MX record.
|
| 1714 | 6414 | acydburn | // The idea for this is from reading the UseBB blog/announcement. :)
|
| 1715 | 6414 | acydburn | if ($config['email_check_mx']) |
| 1716 | 6414 | acydburn | {
|
| 1717 | 6414 | acydburn | list(, $domain) = explode('@', $email); |
| 1718 | 6414 | acydburn | |
| 1719 | 6803 | acydburn | if (phpbb_checkdnsrr($domain, 'A') === false && phpbb_checkdnsrr($domain, 'MX') === false) |
| 1720 | 6414 | acydburn | {
|
| 1721 | 6414 | acydburn | return 'DOMAIN_NO_MX_RECORD'; |
| 1722 | 6414 | acydburn | } |
| 1723 | 6414 | acydburn | } |
| 1724 | 6414 | acydburn | |
| 1725 | 8563 | acydburn | if (($ban_reason = $user->check_ban(false, false, $email, true)) !== false) |
| 1726 | 4487 | psotfx | {
|
| 1727 | 8563 | acydburn | return ($ban_reason === true) ? 'EMAIL_BANNED' : $ban_reason; |
| 1728 | 5277 | bartvb | } |
| 1729 | 5277 | bartvb | |
| 1730 | 4487 | psotfx | if (!$config['allow_emailreuse']) |
| 1731 | 4487 | psotfx | {
|
| 1732 | 4799 | psotfx | $sql = 'SELECT user_email_hash |
| 1733 | 4487 | psotfx | FROM ' . USERS_TABLE . " |
| 1734 | 10060 | nickvergessen | WHERE user_email_hash = " . $db->sql_escape(phpbb_email_hash($email)); |
| 1735 | 4487 | psotfx | $result = $db->sql_query($sql); |
| 1736 | 6015 | acydburn | $row = $db->sql_fetchrow($result); |
| 1737 | 6015 | acydburn | $db->sql_freeresult($result); |
| 1738 | 4213 | psotfx | |
| 1739 | 6015 | acydburn | if ($row) |
| 1740 | 4487 | psotfx | {
|
| 1741 | 4487 | psotfx | return 'EMAIL_TAKEN'; |
| 1742 | 3670 | psotfx | } |
| 1743 | 3670 | psotfx | } |
| 1744 | 4062 | psotfx | |
| 1745 | 4487 | psotfx | return false; |
| 1746 | 4213 | psotfx | } |
| 1747 | 4062 | psotfx | |
| 1748 | 7726 | acydburn | /**
|
| 1749 | 7726 | acydburn | * Validate jabber address |
| 1750 | 7726 | acydburn | * Taken from the jabber class within flyspray (see author notes) |
| 1751 | 7726 | acydburn | * |
| 1752 | 7726 | acydburn | * @author flyspray.org |
| 1753 | 7726 | acydburn | */ |
| 1754 | 7726 | acydburn | function validate_jabber($jid) |
| 1755 | 7726 | acydburn | {
|
| 1756 | 7726 | acydburn | if (!$jid) |
| 1757 | 7726 | acydburn | {
|
| 1758 | 7726 | acydburn | return false; |
| 1759 | 7726 | acydburn | } |
| 1760 | 7429 | kellanved | |
| 1761 | 10752 | git-gate | $separator_pos = strpos($jid, '@'); |
| 1762 | 7429 | kellanved | |
| 1763 | 10752 | git-gate | if ($separator_pos === false) |
| 1764 | 7726 | acydburn | {
|
| 1765 | 7726 | acydburn | return 'WRONG_DATA'; |
| 1766 | 7726 | acydburn | } |
| 1767 | 7726 | acydburn | |
| 1768 | 10752 | git-gate | $username = substr($jid, 0, $separator_pos); |
| 1769 | 10752 | git-gate | $realm = substr($jid, $separator_pos + 1); |
| 1770 | 7726 | acydburn | |
| 1771 | 7726 | acydburn | if (strlen($username) == 0 || strlen($realm) < 3) |
| 1772 | 7726 | acydburn | {
|
| 1773 | 7726 | acydburn | return 'WRONG_DATA'; |
| 1774 | 7726 | acydburn | } |
| 1775 | 7726 | acydburn | |
| 1776 | 7726 | acydburn | $arr = explode('.', $realm); |
| 1777 | 7726 | acydburn | |
| 1778 | 7726 | acydburn | if (sizeof($arr) == 0) |
| 1779 | 7726 | acydburn | {
|
| 1780 | 7726 | acydburn | return 'WRONG_DATA'; |
| 1781 | 7726 | acydburn | } |
| 1782 | 7726 | acydburn | |
| 1783 | 7726 | acydburn | foreach ($arr as $part) |
| 1784 | 7726 | acydburn | {
|
| 1785 | 7726 | acydburn | if (substr($part, 0, 1) == '-' || substr($part, -1, 1) == '-') |
| 1786 | 7726 | acydburn | {
|
| 1787 | 7726 | acydburn | return 'WRONG_DATA'; |
| 1788 | 7726 | acydburn | } |
| 1789 | 7726 | acydburn | |
| 1790 | 7726 | acydburn | if (!preg_match("@^[a-zA-Z0-9-.]+$@", $part)) |
| 1791 | 7726 | acydburn | {
|
| 1792 | 7726 | acydburn | return 'WRONG_DATA'; |
| 1793 | 7726 | acydburn | } |
| 1794 | 7726 | acydburn | } |
| 1795 | 7726 | acydburn | |
| 1796 | 7726 | acydburn | $boundary = array(array(0, 127), array(192, 223), array(224, 239), array(240, 247), array(248, 251), array(252, 253)); |
| 1797 | 7726 | acydburn | |
| 1798 | 7726 | acydburn | // Prohibited Characters RFC3454 + RFC3920
|
| 1799 | 7726 | acydburn | $prohibited = array( |
| 1800 | 7726 | acydburn | // Table C.1.1
|
| 1801 | 7726 | acydburn | array(0x0020, 0x0020), // SPACE |
| 1802 | 7726 | acydburn | // Table C.1.2
|
| 1803 | 7726 | acydburn | array(0x00A0, 0x00A0), // NO-BREAK SPACE |
| 1804 | 7726 | acydburn | array(0x1680, 0x1680), // OGHAM SPACE MARK |
| 1805 | 7726 | acydburn | array(0x2000, 0x2001), // EN QUAD |
| 1806 | 7726 | acydburn | array(0x2001, 0x2001), // EM QUAD |
| 1807 | 7726 | acydburn | array(0x2002, 0x2002), // EN SPACE |
| 1808 | 7726 | acydburn | array(0x2003, 0x2003), // EM SPACE |
| 1809 | 7726 | acydburn | array(0x2004, 0x2004), // THREE-PER-EM SPACE |
| 1810 | 7726 | acydburn | array(0x2005, 0x2005), // FOUR-PER-EM SPACE |
| 1811 | 7726 | acydburn | array(0x2006, 0x2006), // SIX-PER-EM SPACE |
| 1812 | 7726 | acydburn | array(0x2007, 0x2007), // FIGURE SPACE |
| 1813 | 7726 | acydburn | array(0x2008, 0x2008), // PUNCTUATION SPACE |
| 1814 | 7726 | acydburn | array(0x2009, 0x2009), // THIN SPACE |
| 1815 | 7726 | acydburn | array(0x200A, 0x200A), // HAIR SPACE |
| 1816 | 7726 | acydburn | array(0x200B, 0x200B), // ZERO WIDTH SPACE |
| 1817 | 7726 | acydburn | array(0x202F, 0x202F), // NARROW NO-BREAK SPACE |
| 1818 | 7726 | acydburn | array(0x205F, 0x205F), // MEDIUM MATHEMATICAL SPACE |
| 1819 | 7726 | acydburn | array(0x3000, 0x3000), // IDEOGRAPHIC SPACE |
| 1820 | 7726 | acydburn | // Table C.2.1
|
| 1821 | 7726 | acydburn | array(0x0000, 0x001F), // [CONTROL CHARACTERS] |
| 1822 | 7726 | acydburn | array(0x007F, 0x007F), // DELETE |
| 1823 | 7726 | acydburn | // Table C.2.2
|
| 1824 | 7726 | acydburn | array(0x0080, 0x009F), // [CONTROL CHARACTERS] |
| 1825 | 7726 | acydburn | array(0x06DD, 0x06DD), // ARABIC END OF AYAH |
| 1826 | 7726 | acydburn | array(0x070F, 0x070F), // SYRIAC ABBREVIATION MARK |
| 1827 | 7726 | acydburn | array(0x180E, 0x180E), // MONGOLIAN VOWEL SEPARATOR |
| 1828 | 7726 | acydburn | array(0x200C, 0x200C), // ZERO WIDTH NON-JOINER |
| 1829 | 7726 | acydburn | array(0x200D, 0x200D), // ZERO WIDTH JOINER |
| 1830 | 7726 | acydburn | array(0x2028, 0x2028), // LINE SEPARATOR |
| 1831 | 7726 | acydburn | array(0x2029, 0x2029), // PARAGRAPH SEPARATOR |
| 1832 | 7726 | acydburn | array(0x2060, 0x2060), // WORD JOINER |
| 1833 | 7726 | acydburn | array(0x2061, 0x2061), // FUNCTION APPLICATION |
| 1834 | 7726 | acydburn | array(0x2062, 0x2062), // INVISIBLE TIMES |
| 1835 | 7726 | acydburn | array(0x2063, 0x2063), // INVISIBLE SEPARATOR |
| 1836 | 7726 | acydburn | array(0x206A, 0x206F), // [CONTROL CHARACTERS] |
| 1837 | 7726 | acydburn | array(0xFEFF, 0xFEFF), // ZERO WIDTH NO-BREAK SPACE |
| 1838 | 7726 | acydburn | array(0xFFF9, 0xFFFC), // [CONTROL CHARACTERS] |
| 1839 | 7726 | acydburn | array(0x1D173, 0x1D17A), // [MUSICAL CONTROL CHARACTERS] |
| 1840 | 7726 | acydburn | // Table C.3
|
| 1841 | 7726 | acydburn | array(0xE000, 0xF8FF), // [PRIVATE USE, PLANE 0] |
| 1842 | 7726 | acydburn | array(0xF0000, 0xFFFFD), // [PRIVATE USE, PLANE 15] |
| 1843 | 7726 | acydburn | array(0x100000, 0x10FFFD), // [PRIVATE USE, PLANE 16] |
| 1844 | 7726 | acydburn | // Table C.4
|
| 1845 | 7726 | acydburn | array(0xFDD0, 0xFDEF), // [NONCHARACTER CODE POINTS] |
| 1846 | 7726 | acydburn | array(0xFFFE, 0xFFFF), // [NONCHARACTER CODE POINTS] |
| 1847 | 7726 | acydburn | array(0x1FFFE, 0x1FFFF), // [NONCHARACTER CODE POINTS] |
| 1848 | 7726 | acydburn | array(0x2FFFE, 0x2FFFF), // [NONCHARACTER CODE POINTS] |
| 1849 | 7726 | acydburn | array(0x3FFFE, 0x3FFFF), // [NONCHARACTER CODE POINTS] |
| 1850 | 7726 | acydburn | array(0x4FFFE, 0x4FFFF), // [NONCHARACTER CODE POINTS] |
| 1851 | 7726 | acydburn | array(0x5FFFE, 0x5FFFF), // [NONCHARACTER CODE POINTS] |
| 1852 | 7726 | acydburn | array(0x6FFFE, 0x6FFFF), // [NONCHARACTER CODE POINTS] |
| 1853 | 7726 | acydburn | array(0x7FFFE, 0x7FFFF), // [NONCHARACTER CODE POINTS] |
| 1854 | 7726 | acydburn | array(0x8FFFE, 0x8FFFF), // [NONCHARACTER CODE POINTS] |
| 1855 | 7726 | acydburn | array(0x9FFFE, 0x9FFFF), // [NONCHARACTER CODE POINTS] |
| 1856 | 7726 | acydburn | array(0xAFFFE, 0xAFFFF), // [NONCHARACTER CODE POINTS] |
| 1857 | 7726 | acydburn | array(0xBFFFE, 0xBFFFF), // [NONCHARACTER CODE POINTS] |
| 1858 | 7726 | acydburn | array(0xCFFFE, 0xCFFFF), // [NONCHARACTER CODE POINTS] |
| 1859 | 7726 | acydburn | array(0xDFFFE, 0xDFFFF), // [NONCHARACTER CODE POINTS] |
| 1860 | 7726 | acydburn | array(0xEFFFE, 0xEFFFF), // [NONCHARACTER CODE POINTS] |
| 1861 | 7726 | acydburn | array(0xFFFFE, 0xFFFFF), // [NONCHARACTER CODE POINTS] |
| 1862 | 7726 | acydburn | array(0x10FFFE, 0x10FFFF), // [NONCHARACTER CODE POINTS] |
| 1863 | 7726 | acydburn | // Table C.5
|
| 1864 | 7726 | acydburn | array(0xD800, 0xDFFF), // [SURROGATE CODES] |
| 1865 | 7726 | acydburn | // Table C.6
|
| 1866 | 7726 | acydburn | array(0xFFF9, 0xFFF9), // INTERLINEAR ANNOTATION ANCHOR |
| 1867 | 7726 | acydburn | array(0xFFFA, 0xFFFA), // INTERLINEAR ANNOTATION SEPARATOR |
| 1868 | 7726 | acydburn | array(0xFFFB, 0xFFFB), // INTERLINEAR ANNOTATION TERMINATOR |
| 1869 | 7726 | acydburn | array(0xFFFC, 0xFFFC), // OBJECT REPLACEMENT CHARACTER |
| 1870 | 7726 | acydburn | array(0xFFFD, 0xFFFD), // REPLACEMENT CHARACTER |
| 1871 | 7726 | acydburn | // Table C.7
|
| 1872 | 7726 | acydburn | array(0x2FF0, 0x2FFB), // [IDEOGRAPHIC DESCRIPTION CHARACTERS] |
| 1873 | 7726 | acydburn | // Table C.8
|
| 1874 | 7726 | acydburn | array(0x0340, 0x0340), // COMBINING GRAVE TONE MARK |
| 1875 | 7726 | acydburn | array(0x0341, 0x0341), // COMBINING ACUTE TONE MARK |
| 1876 | 7726 | acydburn | array(0x200E, 0x200E), // LEFT-TO-RIGHT MARK |
| 1877 | 7726 | acydburn | array(0x200F, 0x200F), // RIGHT-TO-LEFT MARK |
| 1878 | 7726 | acydburn | array(0x202A, 0x202A), // LEFT-TO-RIGHT EMBEDDING |
| 1879 | 7726 | acydburn | array(0x202B, 0x202B), // RIGHT-TO-LEFT EMBEDDING |
| 1880 | 7726 | acydburn | array(0x202C, 0x202C), // POP DIRECTIONAL FORMATTING |
| 1881 | 7726 | acydburn | array(0x202D, 0x202D), // LEFT-TO-RIGHT OVERRIDE |
| 1882 | 7726 | acydburn | array(0x202E, 0x202E), // RIGHT-TO-LEFT OVERRIDE |
| 1883 | 7726 | acydburn | array(0x206A, 0x206A), // INHIBIT SYMMETRIC SWAPPING |
| 1884 | 7726 | acydburn | array(0x206B, 0x206B), // ACTIVATE SYMMETRIC SWAPPING |
| 1885 | 7726 | acydburn | array(0x206C, 0x206C), // INHIBIT ARABIC FORM SHAPING |
| 1886 | 7726 | acydburn | array(0x206D, 0x206D), // ACTIVATE ARABIC FORM SHAPING |
| 1887 | 7726 | acydburn | array(0x206E, 0x206E), // NATIONAL DIGIT SHAPES |
| 1888 | 7726 | acydburn | array(0x206F, 0x206F), // NOMINAL DIGIT SHAPES |
| 1889 | 7726 | acydburn | // Table C.9
|
| 1890 | 7726 | acydburn | array(0xE0001, 0xE0001), // LANGUAGE TAG |
| 1891 | 7726 | acydburn | array(0xE0020, 0xE007F), // [TAGGING CHARACTERS] |
| 1892 | 7726 | acydburn | // RFC3920
|
| 1893 | 7726 | acydburn | array(0x22, 0x22), // " |
| 1894 | 7726 | acydburn | array(0x26, 0x26), // & |
| 1895 | 7726 | acydburn | array(0x27, 0x27), // ' |
| 1896 | 7726 | acydburn | array(0x2F, 0x2F), // / |
| 1897 | 7726 | acydburn | array(0x3A, 0x3A), // : |
| 1898 | 7726 | acydburn | array(0x3C, 0x3C), // < |
| 1899 | 7726 | acydburn | array(0x3E, 0x3E), // > |
| 1900 | 7726 | acydburn | array(0x40, 0x40) // @ |
| 1901 | 7726 | acydburn | ); |
| 1902 | 7726 | acydburn | |
| 1903 | 7726 | acydburn | $pos = 0; |
| 1904 | 7726 | acydburn | $result = true; |
| 1905 | 7726 | acydburn | |
| 1906 | 7726 | acydburn | while ($pos < strlen($username)) |
| 1907 | 7726 | acydburn | {
|
| 1908 | 7726 | acydburn | $len = $uni = 0; |
| 1909 | 7726 | acydburn | for ($i = 0; $i <= 5; $i++) |
| 1910 | 7726 | acydburn | {
|
| 1911 | 7726 | acydburn | if (ord($username[$pos]) >= $boundary[$i][0] && ord($username[$pos]) <= $boundary[$i][1]) |
| 1912 | 7726 | acydburn | {
|
| 1913 | 7726 | acydburn | $len = $i + 1; |
| 1914 | 7726 | acydburn | $uni = (ord($username[$pos]) - $boundary[$i][0]) * pow(2, $i * 6); |
| 1915 | 7726 | acydburn | |
| 1916 | 7726 | acydburn | for ($k = 1; $k < $len; $k++) |
| 1917 | 7726 | acydburn | {
|
| 1918 | 7726 | acydburn | $uni += (ord($username[$pos + $k]) - 128) * pow(2, ($i - $k) * 6); |
| 1919 | 7726 | acydburn | } |
| 1920 | 7726 | acydburn | |
| 1921 | 7726 | acydburn | break;
|
| 1922 | 7726 | acydburn | } |
| 1923 | 7726 | acydburn | } |
| 1924 | 7726 | acydburn | |
| 1925 | 7726 | acydburn | if ($len == 0) |
| 1926 | 7726 | acydburn | {
|
| 1927 | 7726 | acydburn | return 'WRONG_DATA'; |
| 1928 | 7726 | acydburn | } |
| 1929 | 7726 | acydburn | |
| 1930 | 7726 | acydburn | foreach ($prohibited as $pval) |
| 1931 | 7726 | acydburn | {
|
| 1932 | 7726 | acydburn | if ($uni >= $pval[0] && $uni <= $pval[1]) |
| 1933 | 7726 | acydburn | {
|
| 1934 | 7726 | acydburn | $result = false; |
| 1935 | 7726 | acydburn | break 2; |
| 1936 | 7726 | acydburn | } |
| 1937 | 7726 | acydburn | } |
| 1938 | 7726 | acydburn | |
| 1939 | 7726 | acydburn | $pos = $pos + $len; |
| 1940 | 7726 | acydburn | } |
| 1941 | 7726 | acydburn | |
| 1942 | 7726 | acydburn | if (!$result) |
| 1943 | 7726 | acydburn | {
|
| 1944 | 7726 | acydburn | return 'WRONG_DATA'; |
| 1945 | 7726 | acydburn | } |
| 1946 | 7726 | acydburn | |
| 1947 | 7726 | acydburn | return false; |
| 1948 | 7726 | acydburn | } |
| 1949 | 7726 | acydburn | |
| 1950 | 5114 | acydburn | /**
|
| 1951 | 5114 | acydburn | * Remove avatar |
| 1952 | 5114 | acydburn | */ |
| 1953 | 7740 | kellanved | function avatar_delete($mode, $row, $clean_db = false) |
| 1954 | 4213 | psotfx | {
|
| 1955 | 4621 | psotfx | global $phpbb_root_path, $config, $db, $user; |
| 1956 | 4062 | psotfx | |
| 1957 | 6511 | acydburn | // Check if the users avatar is actually *not* a group avatar
|
| 1958 | 6511 | acydburn | if ($mode == 'user') |
| 1959 | 4019 | psotfx | {
|
| 1960 | 7429 | kellanved | if (strpos($row['user_avatar'], 'g') === 0 || (((int)$row['user_avatar'] !== 0) && ((int)$row['user_avatar'] !== (int)$row['user_id']))) |
| 1961 | 6511 | acydburn | {
|
| 1962 | 6511 | acydburn | return false; |
| 1963 | 6511 | acydburn | } |
| 1964 | 4019 | psotfx | } |
| 1965 | 8350 | acydburn | |
| 1966 | 7740 | kellanved | if ($clean_db) |
| 1967 | 7740 | kellanved | {
|
| 1968 | 7740 | kellanved | avatar_remove_db($row[$mode . '_avatar']); |
| 1969 | 7740 | kellanved | } |
| 1970 | 7429 | kellanved | $filename = get_avatar_filename($row[$mode . '_avatar']); |
| 1971 | 7429 | kellanved | if (file_exists($phpbb_root_path . $config['avatar_path'] . '/' . $filename)) |
| 1972 | 6511 | acydburn | {
|
| 1973 | 7429 | kellanved | @unlink($phpbb_root_path . $config['avatar_path'] . '/' . $filename); |
| 1974 | 6511 | acydburn | return true; |
| 1975 | 6511 | acydburn | } |
| 1976 | 6511 | acydburn | |
| 1977 | 4215 | psotfx | return false; |
| 1978 | 5998 | acydburn | } |
| 1979 | 4215 | psotfx | |
| 1980 | 5114 | acydburn | /**
|
| 1981 | 5114 | acydburn | * Remote avatar linkage |
| 1982 | 5114 | acydburn | */ |
| 1983 | 4597 | psotfx | function avatar_remote($data, &$error) |
| 1984 | 4213 | psotfx | {
|
| 1985 | 6354 | acydburn | global $config, $db, $user, $phpbb_root_path, $phpEx; |
| 1986 | 4062 | psotfx | |
| 1987 | 5080 | bartvb | if (!preg_match('#^(http|https|ftp)://#i', $data['remotelink'])) |
| 1988 | 4062 | psotfx | {
|
| 1989 | 4213 | psotfx | $data['remotelink'] = 'http://' . $data['remotelink']; |
| 1990 | 4213 | psotfx | } |
| 1991 | 7677 | kellanved | if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.(gif|jpg|jpeg|png)$#i', $data['remotelink'])) |
| 1992 | 4213 | psotfx | {
|
| 1993 | 4597 | psotfx | $error[] = $user->lang['AVATAR_URL_INVALID']; |
| 1994 | 4597 | psotfx | return false; |
| 1995 | 4062 | psotfx | } |
| 1996 | 4062 | psotfx | |
| 1997 | 5952 | acydburn | // Make sure getimagesize works...
|
| 1998 | 7899 | kellanved | if (($image_data = @getimagesize($data['remotelink'])) === false && (empty($data['width']) || empty($data['height']))) |
| 1999 | 4062 | psotfx | {
|
| 2000 | 6149 | acydburn | $error[] = $user->lang['UNABLE_GET_IMAGE_SIZE']; |
| 2001 | 5952 | acydburn | return false; |
| 2002 | 5952 | acydburn | } |
| 2003 | 4062 | psotfx | |
| 2004 | 7899 | kellanved | if (!empty($image_data) && ($image_data[0] < 2 || $image_data[1] < 2)) |
| 2005 | 7150 | acydburn | {
|
| 2006 | 7150 | acydburn | $error[] = $user->lang['AVATAR_NO_SIZE']; |
| 2007 | 7150 | acydburn | return false; |
| 2008 | 7150 | acydburn | } |
| 2009 | 7150 | acydburn | |
| 2010 | 5952 | acydburn | $width = ($data['width'] && $data['height']) ? $data['width'] : $image_data[0]; |
| 2011 | 5952 | acydburn | $height = ($data['width'] && $data['height']) ? $data['height'] : $image_data[1]; |
| 2012 | 5952 | acydburn | |
| 2013 | 7150 | acydburn | if ($width < 2 || $height < 2) |
| 2014 | 5952 | acydburn | {
|
| 2015 | 5952 | acydburn | $error[] = $user->lang['AVATAR_NO_SIZE']; |
| 2016 | 5952 | acydburn | return false; |
| 2017 | 5952 | acydburn | } |
| 2018 | 5952 | acydburn | |
| 2019 | 6354 | acydburn | // Check image type
|
| 2020 | 6354 | acydburn | include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx); |
| 2021 | 6354 | acydburn | $types = fileupload::image_types();
|
| 2022 | 6354 | acydburn | $extension = strtolower(filespec::get_extension($data['remotelink'])); |
| 2023 | 6354 | acydburn | |
| 2024 | 7899 | kellanved | if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]]))) |
| 2025 | 6354 | acydburn | {
|
| 2026 | 6354 | acydburn | if (!isset($types[$image_data[2]])) |
| 2027 | 6354 | acydburn | {
|
| 2028 | 6354 | acydburn | $error[] = $user->lang['UNABLE_GET_IMAGE_SIZE']; |
| 2029 | 6354 | acydburn | } |
| 2030 | 6354 | acydburn | else
|
| 2031 | 6354 | acydburn | {
|
| 2032 | 6354 | acydburn | $error[] = sprintf($user->lang['IMAGE_FILETYPE_MISMATCH'], $types[$image_data[2]][0], $extension); |
| 2033 | 6354 | acydburn | } |
| 2034 | 6354 | acydburn | return false; |
| 2035 | 6354 | acydburn | } |
| 2036 | 6354 | acydburn | |
| 2037 | 5952 | acydburn | if ($config['avatar_max_width'] || $config['avatar_max_height']) |
| 2038 | 5952 | acydburn | {
|
| 2039 | 5952 | acydburn | if ($width > $config['avatar_max_width'] || $height > $config['avatar_max_height']) |
| 2040 | 4062 | psotfx | {
|
| 2041 | 11603 | git-gate | $error[] = phpbb_avatar_error_wrong_size($width, $height); |
| 2042 | 4597 | psotfx | return false; |
| 2043 | 4062 | psotfx | } |
| 2044 | 5952 | acydburn | } |
| 2045 | 5952 | acydburn | |
| 2046 | 5952 | acydburn | if ($config['avatar_min_width'] || $config['avatar_min_height']) |
| 2047 | 5952 | acydburn | {
|
| 2048 | 5952 | acydburn | if ($width < $config['avatar_min_width'] || $height < $config['avatar_min_height']) |
| 2049 | 4062 | psotfx | {
|
| 2050 | 11603 | git-gate | $error[] = phpbb_avatar_error_wrong_size($width, $height); |
| 2051 | 4597 | psotfx | return false; |
| 2052 | 4062 | psotfx | } |
| 2053 | 4213 | psotfx | } |
| 2054 | 4062 | psotfx | |
| 2055 | 5023 | acydburn | return array(AVATAR_REMOTE, $data['remotelink'], $width, $height); |
| 2056 | 4213 | psotfx | } |
| 2057 | 4213 | psotfx | |
| 2058 | 5114 | acydburn | /**
|
| 2059 | 5114 | acydburn | * Avatar upload using the upload class |
| 2060 | 5114 | acydburn | */ |
| 2061 | 4597 | psotfx | function avatar_upload($data, &$error) |
| 2062 | 4213 | psotfx | {
|
| 2063 | 6015 | acydburn | global $phpbb_root_path, $config, $db, $user, $phpEx; |
| 2064 | 4213 | psotfx | |
| 2065 | 5109 | acydburn | // Init upload class
|
| 2066 | 6015 | acydburn | include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx); |
| 2067 | 10922 | git-gate | $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $config['avatar_filesize'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], (isset($config['mime_triggers']) ? explode('|', $config['mime_triggers']) : false)); |
| 2068 | 5276 | bartvb | |
| 2069 | 5080 | bartvb | if (!empty($_FILES['uploadfile']['name'])) |
| 2070 | 4213 | psotfx | {
|
| 2071 | 5109 | acydburn | $file = $upload->form_upload('uploadfile'); |
| 2072 | 4062 | psotfx | } |
| 2073 | 5109 | acydburn | else
|
| 2074 | 4062 | psotfx | {
|
| 2075 | 5109 | acydburn | $file = $upload->remote_upload($data['uploadurl']); |
| 2076 | 4213 | psotfx | } |
| 2077 | 8350 | acydburn | |
| 2078 | 7429 | kellanved | $prefix = $config['avatar_salt'] . '_'; |
| 2079 | 7429 | kellanved | $file->clean_filename('avatar', $prefix, $data['user_id']); |
| 2080 | 4062 | psotfx | |
| 2081 | 6364 | acydburn | $destination = $config['avatar_path']; |
| 2082 | 6364 | acydburn | |
| 2083 | 6930 | acydburn | // Adjust destination path (no trailing slash)
|
| 2084 | 6930 | acydburn | if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') |
| 2085 | 6364 | acydburn | {
|
| 2086 | 6813 | davidmj | $destination = substr($destination, 0, -1); |
| 2087 | 6364 | acydburn | } |
| 2088 | 6364 | acydburn | |
| 2089 | 6364 | acydburn | $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); |
| 2090 | 6930 | acydburn | if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) |
| 2091 | 6364 | acydburn | {
|
| 2092 | 6364 | acydburn | $destination = ''; |
| 2093 | 6364 | acydburn | } |
| 2094 | 6364 | acydburn | |
| 2095 | 6787 | acydburn | // Move file and overwrite any existing image
|
| 2096 | 6787 | acydburn | $file->move_file($destination, true); |
| 2097 | 6364 | acydburn | |
| 2098 | 5109 | acydburn | if (sizeof($file->error)) |
| 2099 | 4213 | psotfx | {
|
| 2100 | 5109 | acydburn | $file->remove();
|
| 2101 | 5109 | acydburn | $error = array_merge($error, $file->error); |
| 2102 | 4062 | psotfx | } |
| 2103 | 5276 | bartvb | |
| 2104 | 7453 | kellanved | return array(AVATAR_UPLOAD, $data['user_id'] . '_' . time() . '.' . $file->get('extension'), $file->get('width'), $file->get('height')); |
| 2105 | 3670 | psotfx | } |
| 2106 | 3670 | psotfx | |
| 2107 | 5114 | acydburn | /**
|
| 2108 | 7429 | kellanved | * Generates avatar filename from the database entry |
| 2109 | 7429 | kellanved | */ |
| 2110 | 7429 | kellanved | function get_avatar_filename($avatar_entry) |
| 2111 | 7429 | kellanved | {
|
| 2112 | 7429 | kellanved | global $config; |
| 2113 | 7429 | kellanved | |
| 2114 | 8350 | acydburn | |
| 2115 | 7429 | kellanved | if ($avatar_entry[0] === 'g') |
| 2116 | 7429 | kellanved | {
|
| 2117 | 7429 | kellanved | $avatar_group = true; |
| 2118 | 7429 | kellanved | $avatar_entry = substr($avatar_entry, 1); |
| 2119 | 7429 | kellanved | } |
| 2120 | 7429 | kellanved | else
|
| 2121 | 7429 | kellanved | {
|
| 2122 | 7429 | kellanved | $avatar_group = false; |
| 2123 | 7429 | kellanved | } |
| 2124 | 7429 | kellanved | $ext = substr(strrchr($avatar_entry, '.'), 1); |
| 2125 | 7429 | kellanved | $avatar_entry = intval($avatar_entry); |
| 2126 | 7429 | kellanved | return $config['avatar_salt'] . '_' . (($avatar_group) ? 'g' : '') . $avatar_entry . '.' . $ext; |
| 2127 | 7429 | kellanved | } |
| 2128 | 7429 | kellanved | |
| 2129 | 7429 | kellanved | /**
|
| 2130 | 5114 | acydburn | * Avatar Gallery |
| 2131 | 5114 | acydburn | */ |
| 2132 | 5319 | acydburn | function avatar_gallery($category, $avatar_select, $items_per_column, $block_var = 'avatar_row') |
| 2133 | 4603 | psotfx | {
|
| 2134 | 5319 | acydburn | global $user, $cache, $template; |
| 2135 | 5228 | acydburn | global $config, $phpbb_root_path; |
| 2136 | 4603 | psotfx | |
| 2137 | 5319 | acydburn | $avatar_list = array(); |
| 2138 | 5319 | acydburn | |
| 2139 | 4603 | psotfx | $path = $phpbb_root_path . $config['avatar_gallery_path']; |
| 2140 | 4603 | psotfx | |
| 2141 | 4978 | acydburn | if (!file_exists($path) || !is_dir($path)) |
| 2142 | 4978 | acydburn | {
|
| 2143 | 6241 | naderman | $avatar_list = array($user->lang['NO_AVATAR_CATEGORY'] => array()); |
| 2144 | 4978 | acydburn | } |
| 2145 | 5319 | acydburn | else
|
| 2146 | 5319 | acydburn | {
|
| 2147 | 5319 | acydburn | // Collect images
|
| 2148 | 5319 | acydburn | $dp = @opendir($path); |
| 2149 | 4978 | acydburn | |
| 2150 | 8211 | acydburn | if (!$dp) |
| 2151 | 8211 | acydburn | {
|
| 2152 | 8211 | acydburn | return array($user->lang['NO_AVATAR_CATEGORY'] => array()); |
| 2153 | 8211 | acydburn | } |
| 2154 | 8211 | acydburn | |
| 2155 | 5743 | davidmj | while (($file = readdir($dp)) !== false) |
| 2156 | 4603 | psotfx | {
|
| 2157 | 8091 | kellanved | if ($file[0] != '.' && preg_match('#^[^&"\'<>]+$#i', $file) && is_dir("$path/$file")) |
| 2158 | 4603 | psotfx | {
|
| 2159 | 5319 | acydburn | $avatar_row_count = $avatar_col_count = 0; |
| 2160 | 8350 | acydburn | |
| 2161 | 8211 | acydburn | if ($dp2 = @opendir("$path/$file")) |
| 2162 | 4603 | psotfx | {
|
| 2163 | 8211 | acydburn | while (($sub_file = readdir($dp2)) !== false) |
| 2164 | 5319 | acydburn | {
|
| 2165 | 8211 | acydburn | if (preg_match('#^[^&\'"<>]+\.(?:gif|png|jpe?g)$#i', $sub_file)) |
| 2166 | 5319 | acydburn | {
|
| 2167 | 8211 | acydburn | $avatar_list[$file][$avatar_row_count][$avatar_col_count] = array( |
| 2168 | 9554 | acydburn | 'file' => rawurlencode($file) . '/' . rawurlencode($sub_file), |
| 2169 | 9554 | acydburn | 'filename' => rawurlencode($sub_file), |
| 2170 | 8211 | acydburn | 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $sub_file))), |
| 2171 | 8211 | acydburn | ); |
| 2172 | 8211 | acydburn | $avatar_col_count++;
|
| 2173 | 8211 | acydburn | if ($avatar_col_count == $items_per_column) |
| 2174 | 8211 | acydburn | {
|
| 2175 | 8211 | acydburn | $avatar_row_count++;
|
| 2176 | 8211 | acydburn | $avatar_col_count = 0; |
| 2177 | 8211 | acydburn | } |
| 2178 | 5319 | acydburn | } |
| 2179 | 4603 | psotfx | } |
| 2180 | 8211 | acydburn | closedir($dp2); |
| 2181 | 4603 | psotfx | } |
| 2182 | 4603 | psotfx | } |
| 2183 | 4603 | psotfx | } |
| 2184 | 5319 | acydburn | closedir($dp); |
| 2185 | 4603 | psotfx | } |
| 2186 | 4603 | psotfx | |
| 2187 | 5319 | acydburn | if (!sizeof($avatar_list)) |
| 2188 | 4978 | acydburn | {
|
| 2189 | 6241 | naderman | $avatar_list = array($user->lang['NO_AVATAR_CATEGORY'] => array()); |
| 2190 | 4978 | acydburn | } |
| 2191 | 5276 | bartvb | |
| 2192 | 5319 | acydburn | @ksort($avatar_list); |
| 2193 | 8204 | acydburn | |
| 2194 | 5319 | acydburn | $category = (!$category) ? key($avatar_list) : $category; |
| 2195 | 5319 | acydburn | $avatar_categories = array_keys($avatar_list); |
| 2196 | 5319 | acydburn | |
| 2197 | 5319 | acydburn | $s_category_options = ''; |
| 2198 | 5319 | acydburn | foreach ($avatar_categories as $cat) |
| 2199 | 5319 | acydburn | {
|
| 2200 | 5319 | acydburn | $s_category_options .= '<option value="' . $cat . '"' . (($cat == $category) ? ' selected="selected"' : '') . '>' . $cat . '</option>'; |
| 2201 | 5319 | acydburn | } |
| 2202 | 5319 | acydburn | |
| 2203 | 5319 | acydburn | $template->assign_vars(array( |
| 2204 | 7602 | kellanved | 'S_AVATARS_ENABLED' => true, |
| 2205 | 5319 | acydburn | 'S_IN_AVATAR_GALLERY' => true, |
| 2206 | 5319 | acydburn | 'S_CAT_OPTIONS' => $s_category_options) |
| 2207 | 5319 | acydburn | ); |
| 2208 | 8204 | acydburn | |
| 2209 | 8203 | kellanved | $avatar_list = (isset($avatar_list[$category])) ? $avatar_list[$category] : array(); |
| 2210 | 5319 | acydburn | |
| 2211 | 5319 | acydburn | foreach ($avatar_list as $avatar_row_ary) |
| 2212 | 5319 | acydburn | {
|
| 2213 | 5319 | acydburn | $template->assign_block_vars($block_var, array()); |
| 2214 | 5319 | acydburn | |
| 2215 | 5319 | acydburn | foreach ($avatar_row_ary as $avatar_col_ary) |
| 2216 | 5319 | acydburn | {
|
| 2217 | 5319 | acydburn | $template->assign_block_vars($block_var . '.avatar_column', array( |
| 2218 | 5319 | acydburn | 'AVATAR_IMAGE' => $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_col_ary['file'], |
| 2219 | 5319 | acydburn | 'AVATAR_NAME' => $avatar_col_ary['name'], |
| 2220 | 5319 | acydburn | 'AVATAR_FILE' => $avatar_col_ary['filename']) |
| 2221 | 5319 | acydburn | ); |
| 2222 | 5319 | acydburn | |
| 2223 | 5319 | acydburn | $template->assign_block_vars($block_var . '.avatar_option_column', array( |
| 2224 | 5319 | acydburn | 'AVATAR_IMAGE' => $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_col_ary['file'], |
| 2225 | 5319 | acydburn | 'S_OPTIONS_AVATAR' => $avatar_col_ary['filename']) |
| 2226 | 5319 | acydburn | ); |
| 2227 | 5319 | acydburn | } |
| 2228 | 5319 | acydburn | } |
| 2229 | 5319 | acydburn | |
| 2230 | 5319 | acydburn | return $avatar_list; |
| 2231 | 4603 | psotfx | } |
| 2232 | 4603 | psotfx | |
| 2233 | 7495 | kellanved | |
| 2234 | 6905 | acydburn | /**
|
| 2235 | 7495 | kellanved | * Tries to (re-)establish avatar dimensions |
| 2236 | 7495 | kellanved | */ |
| 2237 | 7495 | kellanved | function avatar_get_dimensions($avatar, $avatar_type, &$error, $current_x = 0, $current_y = 0) |
| 2238 | 7495 | kellanved | {
|
| 2239 | 7551 | kellanved | global $config, $phpbb_root_path, $user; |
| 2240 | 8350 | acydburn | |
| 2241 | 7495 | kellanved | switch ($avatar_type) |
| 2242 | 7495 | kellanved | {
|
| 2243 | 7495 | kellanved | case AVATAR_REMOTE : |
| 2244 | 7495 | kellanved | break;
|
| 2245 | 7495 | kellanved | |
| 2246 | 7495 | kellanved | case AVATAR_UPLOAD : |
| 2247 | 7495 | kellanved | $avatar = $phpbb_root_path . $config['avatar_path'] . '/' . get_avatar_filename($avatar); |
| 2248 | 7495 | kellanved | break;
|
| 2249 | 8350 | acydburn | |
| 2250 | 7495 | kellanved | case AVATAR_GALLERY : |
| 2251 | 7495 | kellanved | $avatar = $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar ; |
| 2252 | 7495 | kellanved | break;
|
| 2253 | 7495 | kellanved | } |
| 2254 | 7616 | acydburn | |
| 2255 | 7495 | kellanved | // Make sure getimagesize works...
|
| 2256 | 7495 | kellanved | if (($image_data = @getimagesize($avatar)) === false) |
| 2257 | 7495 | kellanved | {
|
| 2258 | 7495 | kellanved | $error[] = $user->lang['UNABLE_GET_IMAGE_SIZE']; |
| 2259 | 7495 | kellanved | return false; |
| 2260 | 7495 | kellanved | } |
| 2261 | 7503 | acydburn | |
| 2262 | 7495 | kellanved | if ($image_data[0] < 2 || $image_data[1] < 2) |
| 2263 | 7495 | kellanved | {
|
| 2264 | 7495 | kellanved | $error[] = $user->lang['AVATAR_NO_SIZE']; |
| 2265 | 7495 | kellanved | return false; |
| 2266 | 7495 | kellanved | } |
| 2267 | 8350 | acydburn | |
| 2268 | 7495 | kellanved | // try to maintain ratio
|
| 2269 | 7495 | kellanved | if (!(empty($current_x) && empty($current_y))) |
| 2270 | 7495 | kellanved | {
|
| 2271 | 7495 | kellanved | if ($current_x != 0) |
| 2272 | 7495 | kellanved | {
|
| 2273 | 7495 | kellanved | $image_data[1] = (int) floor(($current_x / $image_data[0]) * $image_data[1]); |
| 2274 | 7495 | kellanved | $image_data[1] = min($config['avatar_max_height'], $image_data[1]); |
| 2275 | 7495 | kellanved | $image_data[1] = max($config['avatar_min_height'], $image_data[1]); |
| 2276 | 7495 | kellanved | } |
| 2277 | 7495 | kellanved | if ($current_y != 0) |
| 2278 | 7495 | kellanved | {
|
| 2279 | 7495 | kellanved | $image_data[0] = (int) floor(($current_y / $image_data[1]) * $image_data[0]); |
| 2280 | 7495 | kellanved | $image_data[0] = min($config['avatar_max_width'], $image_data[1]); |
| 2281 | 7495 | kellanved | $image_data[0] = max($config['avatar_min_width'], $image_data[1]); |
| 2282 | 7495 | kellanved | } |
| 2283 | 7495 | kellanved | } |
| 2284 | 7495 | kellanved | return array($image_data[0], $image_data[1]); |
| 2285 | 7495 | kellanved | } |
| 2286 | 7495 | kellanved | |
| 2287 | 7495 | kellanved | /**
|
| 2288 | 6905 | acydburn | * Uploading/Changing user avatar |
| 2289 | 6905 | acydburn | */ |
| 2290 | 10652 | git-gate | function avatar_process_user(&$error, $custom_userdata = false, $can_upload = null) |
| 2291 | 6905 | acydburn | {
|
| 2292 | 6905 | acydburn | global $config, $phpbb_root_path, $auth, $user, $db; |
| 2293 | 6905 | acydburn | |
| 2294 | 6905 | acydburn | $data = array( |
| 2295 | 6905 | acydburn | 'uploadurl' => request_var('uploadurl', ''), |
| 2296 | 6905 | acydburn | 'remotelink' => request_var('remotelink', ''), |
| 2297 | 7495 | kellanved | 'width' => request_var('width', 0), |
| 2298 | 7495 | kellanved | 'height' => request_var('height', 0), |
| 2299 | 6905 | acydburn | ); |
| 2300 | 6905 | acydburn | |
| 2301 | 6905 | acydburn | $error = validate_data($data, array( |
| 2302 | 6905 | acydburn | 'uploadurl' => array('string', true, 5, 255), |
| 2303 | 6905 | acydburn | 'remotelink' => array('string', true, 5, 255), |
| 2304 | 6905 | acydburn | 'width' => array('string', true, 1, 3), |
| 2305 | 6905 | acydburn | 'height' => array('string', true, 1, 3), |
| 2306 | 6905 | acydburn | )); |
| 2307 | 6905 | acydburn | |
| 2308 | 6905 | acydburn | if (sizeof($error)) |
| 2309 | 6905 | acydburn | {
|
| 2310 | 6905 | acydburn | return false; |
| 2311 | 6905 | acydburn | } |
| 2312 | 6905 | acydburn | |
| 2313 | 6905 | acydburn | $sql_ary = array(); |
| 2314 | 7150 | acydburn | |
| 2315 | 7150 | acydburn | if ($custom_userdata === false) |
| 2316 | 7150 | acydburn | {
|
| 2317 | 7150 | acydburn | $userdata = &$user->data; |
| 2318 | 7150 | acydburn | } |
| 2319 | 7150 | acydburn | else
|
| 2320 | 7150 | acydburn | {
|
| 2321 | 7150 | acydburn | $userdata = &$custom_userdata; |
| 2322 | 7150 | acydburn | } |
| 2323 | 7150 | acydburn | |
| 2324 | 7150 | acydburn | $data['user_id'] = $userdata['user_id']; |
| 2325 | 6905 | acydburn | $change_avatar = ($custom_userdata === false) ? $auth->acl_get('u_chgavatar') : true; |
| 2326 | 6905 | acydburn | $avatar_select = basename(request_var('avatar_select', '')); |
| 2327 | 6905 | acydburn | |
| 2328 | 6905 | acydburn | // Can we upload?
|
| 2329 | 10652 | git-gate | if (is_null($can_upload)) |
| 2330 | 10652 | git-gate | {
|
| 2331 | 10761 | git-gate | $can_upload = ($config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $change_avatar && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; |
| 2332 | 10652 | git-gate | } |
| 2333 | 6905 | acydburn | |
| 2334 | 6905 | acydburn | if ((!empty($_FILES['uploadfile']['name']) || $data['uploadurl']) && $can_upload) |
| 2335 | 6905 | acydburn | {
|
| 2336 | 6905 | acydburn | list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = avatar_upload($data, $error); |
| 2337 | 6905 | acydburn | } |
| 2338 | 6905 | acydburn | else if ($data['remotelink'] && $change_avatar && $config['allow_avatar_remote']) |
| 2339 | 6905 | acydburn | {
|
| 2340 | 6905 | acydburn | list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = avatar_remote($data, $error); |
| 2341 | 6905 | acydburn | } |
| 2342 | 6905 | acydburn | else if ($avatar_select && $change_avatar && $config['allow_avatar_local']) |
| 2343 | 6905 | acydburn | {
|
| 2344 | 6905 | acydburn | $category = basename(request_var('category', '')); |
| 2345 | 6905 | acydburn | |
| 2346 | 6905 | acydburn | $sql_ary['user_avatar_type'] = AVATAR_GALLERY; |
| 2347 | 6905 | acydburn | $sql_ary['user_avatar'] = $avatar_select; |
| 2348 | 6905 | acydburn | |
| 2349 | 6905 | acydburn | // check avatar gallery
|
| 2350 | 6905 | acydburn | if (!is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) |
| 2351 | 6905 | acydburn | {
|
| 2352 | 6905 | acydburn | $sql_ary['user_avatar'] = ''; |
| 2353 | 6905 | acydburn | $sql_ary['user_avatar_type'] = $sql_ary['user_avatar_width'] = $sql_ary['user_avatar_height'] = 0; |
| 2354 | 6905 | acydburn | } |
| 2355 | 6905 | acydburn | else
|
| 2356 | 6905 | acydburn | {
|
| 2357 | 10751 | git-gate | list($sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . urldecode($sql_ary['user_avatar'])); |
| 2358 | 6905 | acydburn | $sql_ary['user_avatar'] = $category . '/' . $sql_ary['user_avatar']; |
| 2359 | 6905 | acydburn | } |
| 2360 | 6905 | acydburn | } |
| 2361 | 6905 | acydburn | else if (isset($_POST['delete']) && $change_avatar) |
| 2362 | 6905 | acydburn | {
|
| 2363 | 6905 | acydburn | $sql_ary['user_avatar'] = ''; |
| 2364 | 6905 | acydburn | $sql_ary['user_avatar_type'] = $sql_ary['user_avatar_width'] = $sql_ary['user_avatar_height'] = 0; |
| 2365 | 6905 | acydburn | } |
| 2366 | 7756 | kellanved | else if (!empty($userdata['user_avatar'])) |
| 2367 | 6905 | acydburn | {
|
| 2368 | 7495 | kellanved | // Only update the dimensions
|
| 2369 | 8350 | acydburn | |
| 2370 | 7495 | kellanved | if (empty($data['width']) || empty($data['height'])) |
| 2371 | 7495 | kellanved | {
|
| 2372 | 7495 | kellanved | if ($dims = avatar_get_dimensions($userdata['user_avatar'], $userdata['user_avatar_type'], $error, $data['width'], $data['height'])) |
| 2373 | 7495 | kellanved | {
|
| 2374 | 7495 | kellanved | list($guessed_x, $guessed_y) = $dims; |
| 2375 | 7495 | kellanved | if (empty($data['width'])) |
| 2376 | 7495 | kellanved | {
|
| 2377 | 7495 | kellanved | $data['width'] = $guessed_x; |
| 2378 | 7495 | kellanved | } |
| 2379 | 7495 | kellanved | if (empty($data['height'])) |
| 2380 | 7495 | kellanved | {
|
| 2381 | 7495 | kellanved | $data['height'] = $guessed_y; |
| 2382 | 7495 | kellanved | } |
| 2383 | 7495 | kellanved | } |
| 2384 | 7495 | kellanved | } |
| 2385 | 8146 | acydburn | if (($config['avatar_max_width'] || $config['avatar_max_height']) && |
| 2386 | 7580 | kellanved | (($data['width'] != $userdata['user_avatar_width']) || $data['height'] != $userdata['user_avatar_height'])) |
| 2387 | 6905 | acydburn | {
|
| 2388 | 6905 | acydburn | if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) |
| 2389 | 6905 | acydburn | {
|
| 2390 | 11603 | git-gate | $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']); |
| 2391 | 6905 | acydburn | } |
| 2392 | 6905 | acydburn | } |
| 2393 | 6905 | acydburn | |
| 2394 | 6905 | acydburn | if (!sizeof($error)) |
| 2395 | 6905 | acydburn | {
|
| 2396 | 6905 | acydburn | if ($config['avatar_min_width'] || $config['avatar_min_height']) |
| 2397 | 6905 | acydburn | {
|
| 2398 | 6905 | acydburn | if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) |
| 2399 | 6905 | acydburn | {
|
| 2400 | 11603 | git-gate | $error[] = phpbb_avatar_error_wrong_size($data['width'], $data['height']); |
| 2401 | 6905 | acydburn | } |
| 2402 | 6905 | acydburn | } |
| 2403 | 6905 | acydburn | } |
| 2404 | 6905 | acydburn | |
| 2405 | 6905 | acydburn | if (!sizeof($error)) |
| 2406 | 6905 | acydburn | {
|
| 2407 | 6905 | acydburn | $sql_ary['user_avatar_width'] = $data['width']; |
| 2408 | 6905 | acydburn | $sql_ary['user_avatar_height'] = $data['height']; |
| 2409 | 6905 | acydburn | } |
| 2410 | 6905 | acydburn | } |
| 2411 | 6905 | acydburn | |
| 2412 | 6905 | acydburn | if (!sizeof($error)) |
| 2413 | 6905 | acydburn | {
|
| 2414 | 6905 | acydburn | // Do we actually have any data to update?
|
| 2415 | 6905 | acydburn | if (sizeof($sql_ary)) |
| 2416 | 6905 | acydburn | {
|
| 2417 | 8709 | Kellanved | $ext_new = $ext_old = ''; |
| 2418 | 6905 | acydburn | if (isset($sql_ary['user_avatar'])) |
| 2419 | 6905 | acydburn | {
|
| 2420 | 6905 | acydburn | $userdata = ($custom_userdata === false) ? $user->data : $custom_userdata; |
| 2421 | 8709 | Kellanved | $ext_new = (empty($sql_ary['user_avatar'])) ? '' : substr(strrchr($sql_ary['user_avatar'], '.'), 1); |
| 2422 | 8709 | Kellanved | $ext_old = (empty($userdata['user_avatar'])) ? '' : substr(strrchr($userdata['user_avatar'], '.'), 1); |
| 2423 | 6905 | acydburn | |
| 2424 | 8709 | Kellanved | if ($userdata['user_avatar_type'] == AVATAR_UPLOAD) |
| 2425 | 6905 | acydburn | {
|
| 2426 | 8709 | Kellanved | // Delete old avatar if present
|
| 2427 | 8709 | Kellanved | if ((!empty($userdata['user_avatar']) && empty($sql_ary['user_avatar'])) |
| 2428 | 8709 | Kellanved | || ( !empty($userdata['user_avatar']) && !empty($sql_ary['user_avatar']) && $ext_new !== $ext_old)) |
| 2429 | 8709 | Kellanved | {
|
| 2430 | 8709 | Kellanved | avatar_delete('user', $userdata); |
| 2431 | 8709 | Kellanved | } |
| 2432 | 6905 | acydburn | } |
| 2433 | 6905 | acydburn | } |
| 2434 | 8783 | acydburn | |
| 2435 | 8701 | Kellanved | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 2436 | 8701 | Kellanved | SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
| 2437 | 8701 | Kellanved | WHERE user_id = ' . (($custom_userdata === false) ? $user->data['user_id'] : $custom_userdata['user_id']); |
| 2438 | 8701 | Kellanved | $db->sql_query($sql); |
| 2439 | 8701 | Kellanved | |
| 2440 | 6905 | acydburn | } |
| 2441 | 6905 | acydburn | } |
| 2442 | 6905 | acydburn | |
| 2443 | 6905 | acydburn | return (sizeof($error)) ? false : true; |
| 2444 | 6905 | acydburn | } |
| 2445 | 6905 | acydburn | |
| 2446 | 11603 | git-gate | /**
|
| 2447 | 11603 | git-gate | * Returns a language string with the avatar size of the new avatar and the allowed maximum and minimum |
| 2448 | 11603 | git-gate | * |
| 2449 | 11603 | git-gate | * @param $width int The width of the new uploaded/selected avatar |
| 2450 | 11603 | git-gate | * @param $height int The height of the new uploaded/selected avatar |
| 2451 | 11603 | git-gate | * @return string |
| 2452 | 11603 | git-gate | */ |
| 2453 | 11603 | git-gate | function phpbb_avatar_error_wrong_size($width, $height) |
| 2454 | 11603 | git-gate | {
|
| 2455 | 11603 | git-gate | global $config, $user; |
| 2456 | 11603 | git-gate | |
| 2457 | 11603 | git-gate | return $user->lang('AVATAR_WRONG_SIZE', |
| 2458 | 11603 | git-gate | $user->lang('PIXELS', (int) $config['avatar_min_width']), |
| 2459 | 11603 | git-gate | $user->lang('PIXELS', (int) $config['avatar_min_height']), |
| 2460 | 11603 | git-gate | $user->lang('PIXELS', (int) $config['avatar_max_width']), |
| 2461 | 11603 | git-gate | $user->lang('PIXELS', (int) $config['avatar_max_height']), |
| 2462 | 11603 | git-gate | $user->lang('PIXELS', (int) $width), |
| 2463 | 11603 | git-gate | $user->lang('PIXELS', (int) $height)); |
| 2464 | 11603 | git-gate | } |
| 2465 | 11603 | git-gate | |
| 2466 | 11603 | git-gate | /**
|
| 2467 | 11603 | git-gate | * Returns an explanation string with maximum avatar settings |
| 2468 | 11603 | git-gate | * |
| 2469 | 11603 | git-gate | * @return string |
| 2470 | 11603 | git-gate | */ |
| 2471 | 11603 | git-gate | function phpbb_avatar_explanation_string() |
| 2472 | 11603 | git-gate | {
|
| 2473 | 11603 | git-gate | global $config, $user; |
| 2474 | 11603 | git-gate | |
| 2475 | 11603 | git-gate | return $user->lang('AVATAR_EXPLAIN', |
| 2476 | 11603 | git-gate | $user->lang('PIXELS', (int) $config['avatar_max_width']), |
| 2477 | 11603 | git-gate | $user->lang('PIXELS', (int) $config['avatar_max_height']), |
| 2478 | 11603 | git-gate | round($config['avatar_filesize'] / 1024)); |
| 2479 | 11603 | git-gate | } |
| 2480 | 11603 | git-gate | |
| 2481 | 4780 | psotfx | //
|
| 2482 | 4780 | psotfx | // Usergroup functions
|
| 2483 | 4780 | psotfx | //
|
| 2484 | 5276 | bartvb | |
| 2485 | 5114 | acydburn | /**
|
| 2486 | 5114 | acydburn | * Add or edit a group. If we're editing a group we only update user |
| 2487 | 5114 | acydburn | * parameters such as rank, etc. if they are changed |
| 2488 | 5114 | acydburn | */ |
| 2489 | 5709 | acydburn | function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow_desc_bbcode = false, $allow_desc_urls = false, $allow_desc_smilies = false) |
| 2490 | 4487 | psotfx | {
|
| 2491 | 4780 | psotfx | global $phpbb_root_path, $config, $db, $user, $file_upload; |
| 2492 | 4487 | psotfx | |
| 2493 | 4780 | psotfx | $error = array(); |
| 2494 | 4487 | psotfx | |
| 2495 | 9625 | acydburn | // Attributes which also affect the users table
|
| 2496 | 9625 | acydburn | $user_attribute_ary = array('group_colour', 'group_rank', 'group_avatar', 'group_avatar_type', 'group_avatar_width', 'group_avatar_height'); |
| 2497 | 6650 | acydburn | |
| 2498 | 7007 | acydburn | // Check data. Limit group name length.
|
| 2499 | 7007 | acydburn | if (!utf8_strlen($name) || utf8_strlen($name) > 60) |
| 2500 | 4487 | psotfx | {
|
| 2501 | 6452 | acydburn | $error[] = (!utf8_strlen($name)) ? $user->lang['GROUP_ERR_USERNAME'] : $user->lang['GROUP_ERR_USER_LONG']; |
| 2502 | 4487 | psotfx | } |
| 2503 | 8350 | acydburn | |
| 2504 | 7449 | kellanved | $err = group_validate_groupname($group_id, $name); |
| 2505 | 7449 | kellanved | if (!empty($err)) |
| 2506 | 7449 | kellanved | {
|
| 2507 | 7449 | kellanved | $error[] = $user->lang[$err]; |
| 2508 | 7449 | kellanved | } |
| 2509 | 8350 | acydburn | |
| 2510 | 4780 | psotfx | if (!in_array($type, array(GROUP_OPEN, GROUP_CLOSED, GROUP_HIDDEN, GROUP_SPECIAL, GROUP_FREE))) |
| 2511 | 4780 | psotfx | {
|
| 2512 | 4780 | psotfx | $error[] = $user->lang['GROUP_ERR_TYPE']; |
| 2513 | 4780 | psotfx | } |
| 2514 | 4487 | psotfx | |
| 2515 | 4780 | psotfx | if (!sizeof($error)) |
| 2516 | 4780 | psotfx | {
|
| 2517 | 11015 | git-gate | $current_legend = phpbb_group_positions::GROUP_DISABLED; |
| 2518 | 11015 | git-gate | $current_teampage = phpbb_group_positions::GROUP_DISABLED; |
| 2519 | 11015 | git-gate | |
| 2520 | 11015 | git-gate | $legend = new phpbb_group_positions($db, 'legend'); |
| 2521 | 11015 | git-gate | $teampage = new phpbb_group_positions($db, 'teampage'); |
| 2522 | 11015 | git-gate | if ($group_id) |
| 2523 | 11015 | git-gate | {
|
| 2524 | 11015 | git-gate | $current_legend = $legend->get_group_value($group_id); |
| 2525 | 11015 | git-gate | $current_teampage = $teampage->get_group_value($group_id); |
| 2526 | 11015 | git-gate | } |
| 2527 | 11015 | git-gate | |
| 2528 | 11015 | git-gate | if (!empty($group_attributes['group_legend'])) |
| 2529 | 11015 | git-gate | {
|
| 2530 | 11015 | git-gate | if (($group_id && ($current_legend == phpbb_group_positions::GROUP_DISABLED)) || !$group_id) |
| 2531 | 11015 | git-gate | {
|
| 2532 | 11015 | git-gate | // Old group currently not in the legend or new group, add at the end.
|
| 2533 | 11015 | git-gate | $group_attributes['group_legend'] = 1 + $legend->get_group_count(); |
| 2534 | 11015 | git-gate | } |
| 2535 | 11015 | git-gate | else
|
| 2536 | 11015 | git-gate | {
|
| 2537 | 11015 | git-gate | // Group stayes in the legend
|
| 2538 | 11015 | git-gate | $group_attributes['group_legend'] = $current_legend; |
| 2539 | 11015 | git-gate | } |
| 2540 | 11015 | git-gate | } |
| 2541 | 11015 | git-gate | else if ($group_id && ($current_legend > phpbb_group_positions::GROUP_DISABLED)) |
| 2542 | 11015 | git-gate | {
|
| 2543 | 11015 | git-gate | // Group is removed from the legend
|
| 2544 | 11015 | git-gate | $legend->delete_group($group_id, true); |
| 2545 | 11015 | git-gate | $group_attributes['group_legend'] = phpbb_group_positions::GROUP_DISABLED; |
| 2546 | 11015 | git-gate | } |
| 2547 | 11015 | git-gate | else
|
| 2548 | 11015 | git-gate | {
|
| 2549 | 11015 | git-gate | $group_attributes['group_legend'] = phpbb_group_positions::GROUP_DISABLED; |
| 2550 | 11015 | git-gate | } |
| 2551 | 11015 | git-gate | |
| 2552 | 11015 | git-gate | if (!empty($group_attributes['group_teampage'])) |
| 2553 | 11015 | git-gate | {
|
| 2554 | 11015 | git-gate | if (($group_id && ($current_teampage == phpbb_group_positions::GROUP_DISABLED)) || !$group_id) |
| 2555 | 11015 | git-gate | {
|
| 2556 | 11015 | git-gate | // Old group currently not on the teampage or new group, add at the end.
|
| 2557 | 11015 | git-gate | $group_attributes['group_teampage'] = 1 + $teampage->get_group_count(); |
| 2558 | 11015 | git-gate | } |
| 2559 | 11015 | git-gate | else
|
| 2560 | 11015 | git-gate | {
|
| 2561 | 11015 | git-gate | // Group stayes on the teampage
|
| 2562 | 11015 | git-gate | $group_attributes['group_teampage'] = $current_teampage; |
| 2563 | 11015 | git-gate | } |
| 2564 | 11015 | git-gate | } |
| 2565 | 11015 | git-gate | else if ($group_id && ($current_teampage > phpbb_group_positions::GROUP_DISABLED)) |
| 2566 | 11015 | git-gate | {
|
| 2567 | 11015 | git-gate | // Group is removed from the teampage
|
| 2568 | 11015 | git-gate | $teampage->delete_group($group_id, true); |
| 2569 | 11015 | git-gate | $group_attributes['group_teampage'] = phpbb_group_positions::GROUP_DISABLED; |
| 2570 | 11015 | git-gate | } |
| 2571 | 11015 | git-gate | else
|
| 2572 | 11015 | git-gate | {
|
| 2573 | 11015 | git-gate | $group_attributes['group_teampage'] = phpbb_group_positions::GROUP_DISABLED; |
| 2574 | 11015 | git-gate | } |
| 2575 | 11015 | git-gate | |
| 2576 | 11015 | git-gate | // Unset the objects, we don't need them anymore.
|
| 2577 | 11015 | git-gate | unset($legend); |
| 2578 | 11015 | git-gate | unset($teampage); |
| 2579 | 11015 | git-gate | |
| 2580 | 8007 | kellanved | $user_ary = array(); |
| 2581 | 4780 | psotfx | $sql_ary = array( |
| 2582 | 4780 | psotfx | 'group_name' => (string) $name, |
| 2583 | 5709 | acydburn | 'group_desc' => (string) $desc, |
| 2584 | 5709 | acydburn | 'group_desc_uid' => '', |
| 2585 | 6209 | davidmj | 'group_desc_bitfield' => '', |
| 2586 | 4780 | psotfx | 'group_type' => (int) $type, |
| 2587 | 4780 | psotfx | ); |
| 2588 | 4438 | psotfx | |
| 2589 | 5709 | acydburn | // Parse description
|
| 2590 | 5709 | acydburn | if ($desc) |
| 2591 | 5709 | acydburn | {
|
| 2592 | 6188 | davidmj | generate_text_for_storage($sql_ary['group_desc'], $sql_ary['group_desc_uid'], $sql_ary['group_desc_bitfield'], $sql_ary['group_desc_options'], $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies); |
| 2593 | 5709 | acydburn | } |
| 2594 | 5709 | acydburn | |
| 2595 | 5228 | acydburn | if (sizeof($group_attributes)) |
| 2596 | 4780 | psotfx | {
|
| 2597 | 9625 | acydburn | // Merge them with $sql_ary to properly update the group
|
| 2598 | 9625 | acydburn | $sql_ary = array_merge($sql_ary, $group_attributes); |
| 2599 | 4780 | psotfx | } |
| 2600 | 4780 | psotfx | |
| 2601 | 5574 | acydburn | // Setting the log message before we set the group id (if group gets added)
|
| 2602 | 5574 | acydburn | $log = ($group_id) ? 'LOG_GROUP_UPDATED' : 'LOG_GROUP_CREATED'; |
| 2603 | 5574 | acydburn | |
| 2604 | 6209 | davidmj | $query = ''; |
| 2605 | 6209 | davidmj | |
| 2606 | 5957 | acydburn | if ($group_id) |
| 2607 | 5957 | acydburn | {
|
| 2608 | 8007 | kellanved | $sql = 'SELECT user_id |
| 2609 | 8007 | kellanved | FROM ' . USERS_TABLE . ' |
| 2610 | 8007 | kellanved | WHERE group_id = ' . $group_id; |
| 2611 | 8007 | kellanved | $result = $db->sql_query($sql); |
| 2612 | 8007 | kellanved | |
| 2613 | 8007 | kellanved | while ($row = $db->sql_fetchrow($result)) |
| 2614 | 8007 | kellanved | {
|
| 2615 | 8007 | kellanved | $user_ary[] = $row['user_id']; |
| 2616 | 8007 | kellanved | } |
| 2617 | 8007 | kellanved | $db->sql_freeresult($result); |
| 2618 | 8007 | kellanved | |
| 2619 | 8007 | kellanved | if (isset($sql_ary['group_avatar']) && !$sql_ary['group_avatar']) |
| 2620 | 8007 | kellanved | {
|
| 2621 | 8007 | kellanved | remove_default_avatar($group_id, $user_ary); |
| 2622 | 8007 | kellanved | } |
| 2623 | 9625 | acydburn | |
| 2624 | 8007 | kellanved | if (isset($sql_ary['group_rank']) && !$sql_ary['group_rank']) |
| 2625 | 8007 | kellanved | {
|
| 2626 | 8007 | kellanved | remove_default_rank($group_id, $user_ary); |
| 2627 | 8007 | kellanved | } |
| 2628 | 8007 | kellanved | |
| 2629 | 5957 | acydburn | $sql = 'UPDATE ' . GROUPS_TABLE . ' |
| 2630 | 6238 | davidmj | SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " |
| 2631 | 5957 | acydburn | WHERE group_id = $group_id"; |
| 2632 | 6803 | acydburn | $db->sql_query($sql); |
| 2633 | 6803 | acydburn | |
| 2634 | 6803 | acydburn | // Since we may update the name too, we need to do this on other tables too...
|
| 2635 | 6803 | acydburn | $sql = 'UPDATE ' . MODERATOR_CACHE_TABLE . " |
| 2636 | 6803 | acydburn | SET group_name = '" . $db->sql_escape($sql_ary['group_name']) . "' |
| 2637 | 6803 | acydburn | WHERE group_id = $group_id"; |
| 2638 | 6803 | acydburn | $db->sql_query($sql); |
| 2639 | 9625 | acydburn | |
| 2640 | 9625 | acydburn | // One special case is the group skip auth setting. If this was changed we need to purge permissions for this group
|
| 2641 | 9625 | acydburn | if (isset($group_attributes['group_skip_auth'])) |
| 2642 | 9625 | acydburn | {
|
| 2643 | 9625 | acydburn | // Get users within this group...
|
| 2644 | 9625 | acydburn | $sql = 'SELECT user_id |
| 2645 | 9625 | acydburn | FROM ' . USER_GROUP_TABLE . ' |
| 2646 | 9625 | acydburn | WHERE group_id = ' . $group_id . ' |
| 2647 | 9625 | acydburn | AND user_pending = 0';
|
| 2648 | 9625 | acydburn | $result = $db->sql_query($sql); |
| 2649 | 9625 | acydburn | |
| 2650 | 9625 | acydburn | $user_id_ary = array(); |
| 2651 | 9625 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 2652 | 9625 | acydburn | {
|
| 2653 | 9625 | acydburn | $user_id_ary[] = $row['user_id']; |
| 2654 | 9625 | acydburn | } |
| 2655 | 9625 | acydburn | $db->sql_freeresult($result); |
| 2656 | 9625 | acydburn | |
| 2657 | 9625 | acydburn | if (!empty($user_id_ary)) |
| 2658 | 9625 | acydburn | {
|
| 2659 | 9625 | acydburn | global $auth; |
| 2660 | 9625 | acydburn | |
| 2661 | 9625 | acydburn | // Clear permissions cache of relevant users
|
| 2662 | 9625 | acydburn | $auth->acl_clear_prefetch($user_id_ary); |
| 2663 | 9625 | acydburn | } |
| 2664 | 9625 | acydburn | } |
| 2665 | 5957 | acydburn | } |
| 2666 | 5957 | acydburn | else
|
| 2667 | 5957 | acydburn | {
|
| 2668 | 6238 | davidmj | $sql = 'INSERT INTO ' . GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); |
| 2669 | 6803 | acydburn | $db->sql_query($sql); |
| 2670 | 5957 | acydburn | } |
| 2671 | 4780 | psotfx | |
| 2672 | 5574 | acydburn | if (!$group_id) |
| 2673 | 5574 | acydburn | {
|
| 2674 | 5574 | acydburn | $group_id = $db->sql_nextid(); |
| 2675 | 9625 | acydburn | |
| 2676 | 7445 | kellanved | if (isset($sql_ary['group_avatar_type']) && $sql_ary['group_avatar_type'] == AVATAR_UPLOAD) |
| 2677 | 7429 | kellanved | {
|
| 2678 | 7429 | kellanved | group_correct_avatar($group_id, $sql_ary['group_avatar']); |
| 2679 | 7429 | kellanved | } |
| 2680 | 5574 | acydburn | } |
| 2681 | 5574 | acydburn | |
| 2682 | 5228 | acydburn | // Set user attributes
|
| 2683 | 4780 | psotfx | $sql_ary = array(); |
| 2684 | 5228 | acydburn | if (sizeof($group_attributes)) |
| 2685 | 4780 | psotfx | {
|
| 2686 | 9625 | acydburn | // Go through the user attributes array, check if a group attribute matches it and then set it. ;)
|
| 2687 | 9625 | acydburn | foreach ($user_attribute_ary as $attribute) |
| 2688 | 4780 | psotfx | {
|
| 2689 | 9625 | acydburn | if (!isset($group_attributes[$attribute])) |
| 2690 | 5228 | acydburn | {
|
| 2691 | 9625 | acydburn | continue;
|
| 2692 | 9625 | acydburn | } |
| 2693 | 5902 | acydburn | |
| 2694 | 9625 | acydburn | // If we are about to set an avatar, we will not overwrite user avatars if no group avatar is set...
|
| 2695 | 9625 | acydburn | if (strpos($attribute, 'group_avatar') === 0 && !$group_attributes[$attribute]) |
| 2696 | 9625 | acydburn | {
|
| 2697 | 9625 | acydburn | continue;
|
| 2698 | 5228 | acydburn | } |
| 2699 | 9625 | acydburn | |
| 2700 | 9625 | acydburn | $sql_ary[$attribute] = $group_attributes[$attribute]; |
| 2701 | 4780 | psotfx | } |
| 2702 | 4780 | psotfx | } |
| 2703 | 4780 | psotfx | |
| 2704 | 8007 | kellanved | if (sizeof($sql_ary) && sizeof($user_ary)) |
| 2705 | 4780 | psotfx | {
|
| 2706 | 8007 | kellanved | group_set_user_default($group_id, $user_ary, $sql_ary); |
| 2707 | 4780 | psotfx | } |
| 2708 | 4780 | psotfx | |
| 2709 | 5957 | acydburn | $name = ($type == GROUP_SPECIAL) ? $user->lang['G_' . $name] : $name; |
| 2710 | 4780 | psotfx | add_log('admin', $log, $name); |
| 2711 | 6894 | acydburn | |
| 2712 | 6894 | acydburn | group_update_listings($group_id);
|
| 2713 | 4438 | psotfx | } |
| 2714 | 4438 | psotfx | |
| 2715 | 4780 | psotfx | return (sizeof($error)) ? $error : false; |
| 2716 | 4780 | psotfx | } |
| 2717 | 4438 | psotfx | |
| 2718 | 7429 | kellanved | |
| 2719 | 5114 | acydburn | /**
|
| 2720 | 7429 | kellanved | * Changes a group avatar's filename to conform to the naming scheme |
| 2721 | 7429 | kellanved | */ |
| 2722 | 7429 | kellanved | function group_correct_avatar($group_id, $old_entry) |
| 2723 | 7429 | kellanved | {
|
| 2724 | 7429 | kellanved | global $config, $db, $phpbb_root_path; |
| 2725 | 7429 | kellanved | |
| 2726 | 7429 | kellanved | $group_id = (int)$group_id; |
| 2727 | 7429 | kellanved | $ext = substr(strrchr($old_entry, '.'), 1); |
| 2728 | 7429 | kellanved | $old_filename = get_avatar_filename($old_entry); |
| 2729 | 7429 | kellanved | $new_filename = $config['avatar_salt'] . "_g$group_id.$ext"; |
| 2730 | 7429 | kellanved | $new_entry = 'g' . $group_id . '_' . substr(time(), -5) . ".$ext"; |
| 2731 | 8350 | acydburn | |
| 2732 | 7429 | kellanved | $avatar_path = $phpbb_root_path . $config['avatar_path']; |
| 2733 | 7429 | kellanved | if (@rename($avatar_path . '/'. $old_filename, $avatar_path . '/' . $new_filename)) |
| 2734 | 7429 | kellanved | {
|
| 2735 | 7429 | kellanved | $sql = 'UPDATE ' . GROUPS_TABLE . ' |
| 2736 | 7429 | kellanved | SET group_avatar = \'' . $db->sql_escape($new_entry) . "' |
| 2737 | 7429 | kellanved | WHERE group_id = $group_id"; |
| 2738 | 7429 | kellanved | $db->sql_query($sql); |
| 2739 | 7429 | kellanved | } |
| 2740 | 7429 | kellanved | } |
| 2741 | 7429 | kellanved | |
| 2742 | 7740 | kellanved | |
| 2743 | 7429 | kellanved | /**
|
| 2744 | 7740 | kellanved | * Remove avatar also for users not having the group as default |
| 2745 | 7740 | kellanved | */ |
| 2746 | 7740 | kellanved | function avatar_remove_db($avatar_name) |
| 2747 | 7740 | kellanved | {
|
| 2748 | 7740 | kellanved | global $config, $db; |
| 2749 | 8350 | acydburn | |
| 2750 | 7740 | kellanved | $sql = 'UPDATE ' . USERS_TABLE . " |
| 2751 | 7740 | kellanved | SET user_avatar = '', |
| 2752 | 8146 | acydburn | user_avatar_type = 0 |
| 2753 | 7740 | kellanved | WHERE user_avatar = '" . $db->sql_escape($avatar_name) . '\''; |
| 2754 | 7740 | kellanved | $db->sql_query($sql); |
| 2755 | 7740 | kellanved | } |
| 2756 | 7740 | kellanved | |
| 2757 | 7740 | kellanved | |
| 2758 | 7740 | kellanved | /**
|
| 2759 | 5114 | acydburn | * Group Delete |
| 2760 | 5114 | acydburn | */ |
| 2761 | 4780 | psotfx | function group_delete($group_id, $group_name = false) |
| 2762 | 4780 | psotfx | {
|
| 2763 | 6511 | acydburn | global $db, $phpbb_root_path, $phpEx; |
| 2764 | 4438 | psotfx | |
| 2765 | 4780 | psotfx | if (!$group_name) |
| 2766 | 4438 | psotfx | {
|
| 2767 | 5765 | acydburn | $group_name = get_group_name($group_id); |
| 2768 | 4438 | psotfx | } |
| 2769 | 4438 | psotfx | |
| 2770 | 4780 | psotfx | $start = 0; |
| 2771 | 4780 | psotfx | |
| 2772 | 4438 | psotfx | do
|
| 2773 | 4438 | psotfx | {
|
| 2774 | 4780 | psotfx | $user_id_ary = $username_ary = array(); |
| 2775 | 4780 | psotfx | |
| 2776 | 4780 | psotfx | // Batch query for group members, call group_user_del
|
| 2777 | 4780 | psotfx | $sql = 'SELECT u.user_id, u.username |
| 2778 | 4780 | psotfx | FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . " u |
| 2779 | 4780 | psotfx | WHERE ug.group_id = $group_id |
| 2780 | 5228 | acydburn | AND u.user_id = ug.user_id";
|
| 2781 | 5228 | acydburn | $result = $db->sql_query_limit($sql, 200, $start); |
| 2782 | 4780 | psotfx | |
| 2783 | 4780 | psotfx | if ($row = $db->sql_fetchrow($result)) |
| 2784 | 4780 | psotfx | {
|
| 2785 | 4780 | psotfx | do
|
| 2786 | 4780 | psotfx | {
|
| 2787 | 4780 | psotfx | $user_id_ary[] = $row['user_id']; |
| 2788 | 4780 | psotfx | $username_ary[] = $row['username']; |
| 2789 | 4780 | psotfx | |
| 2790 | 4780 | psotfx | $start++;
|
| 2791 | 4780 | psotfx | } |
| 2792 | 4780 | psotfx | while ($row = $db->sql_fetchrow($result)); |
| 2793 | 4780 | psotfx | |
| 2794 | 4780 | psotfx | group_user_del($group_id, $user_id_ary, $username_ary, $group_name); |
| 2795 | 4780 | psotfx | } |
| 2796 | 4780 | psotfx | else
|
| 2797 | 4780 | psotfx | {
|
| 2798 | 4780 | psotfx | $start = 0; |
| 2799 | 4780 | psotfx | } |
| 2800 | 4780 | psotfx | $db->sql_freeresult($result); |
| 2801 | 4438 | psotfx | } |
| 2802 | 4780 | psotfx | while ($start); |
| 2803 | 5276 | bartvb | |
| 2804 | 11015 | git-gate | // Delete group from legend and teampage
|
| 2805 | 11015 | git-gate | $legend = new phpbb_group_positions($db, 'legend'); |
| 2806 | 11015 | git-gate | $legend->delete_group($group_id); |
| 2807 | 11015 | git-gate | unset($legend); |
| 2808 | 11015 | git-gate | $teampage = new phpbb_group_positions($db, 'teampage'); |
| 2809 | 11015 | git-gate | $teampage->delete_group($group_id); |
| 2810 | 11015 | git-gate | unset($teampage); |
| 2811 | 11015 | git-gate | |
| 2812 | 4780 | psotfx | // Delete group
|
| 2813 | 5276 | bartvb | $sql = 'DELETE FROM ' . GROUPS_TABLE . " |
| 2814 | 4780 | psotfx | WHERE group_id = $group_id"; |
| 2815 | 4780 | psotfx | $db->sql_query($sql); |
| 2816 | 4438 | psotfx | |
| 2817 | 5603 | acydburn | // Delete auth entries from the groups table
|
| 2818 | 5603 | acydburn | $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . " |
| 2819 | 5603 | acydburn | WHERE group_id = $group_id"; |
| 2820 | 5603 | acydburn | $db->sql_query($sql); |
| 2821 | 5603 | acydburn | |
| 2822 | 6114 | acydburn | // Re-cache moderators
|
| 2823 | 6511 | acydburn | if (!function_exists('cache_moderators')) |
| 2824 | 6511 | acydburn | {
|
| 2825 | 6511 | acydburn | include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); |
| 2826 | 6511 | acydburn | } |
| 2827 | 6511 | acydburn | |
| 2828 | 6114 | acydburn | cache_moderators(); |
| 2829 | 6114 | acydburn | |
| 2830 | 4780 | psotfx | add_log('admin', 'LOG_GROUP_DELETE', $group_name); |
| 2831 | 4780 | psotfx | |
| 2832 | 7575 | davidmj | // Return false - no error
|
| 2833 | 7575 | davidmj | return false; |
| 2834 | 4780 | psotfx | } |
| 2835 | 4780 | psotfx | |
| 2836 | 5114 | acydburn | /**
|
| 2837 | 5114 | acydburn | * Add user(s) to group |
| 2838 | 6366 | acydburn | * |
| 2839 | 6650 | acydburn | * @return mixed false if no errors occurred, else the user lang string for the relevant error, for example 'NO_USER' |
| 2840 | 5114 | acydburn | */ |
| 2841 | 5228 | acydburn | function group_user_add($group_id, $user_id_ary = false, $username_ary = false, $group_name = false, $default = false, $leader = 0, $pending = 0, $group_attributes = false) |
| 2842 | 4780 | psotfx | {
|
| 2843 | 4780 | psotfx | global $db, $auth; |
| 2844 | 4780 | psotfx | |
| 2845 | 4780 | psotfx | // We need both username and user_id info
|
| 2846 | 6114 | acydburn | $result = user_get_id_name($user_id_ary, $username_ary); |
| 2847 | 4780 | psotfx | |
| 2848 | 6114 | acydburn | if (!sizeof($user_id_ary) || $result !== false) |
| 2849 | 5698 | acydburn | {
|
| 2850 | 5747 | acydburn | return 'NO_USER'; |
| 2851 | 5698 | acydburn | } |
| 2852 | 5698 | acydburn | |
| 2853 | 4438 | psotfx | // Remove users who are already members of this group
|
| 2854 | 5276 | bartvb | $sql = 'SELECT user_id, group_leader |
| 2855 | 5276 | bartvb | FROM ' . USER_GROUP_TABLE . ' |
| 2856 | 6271 | acydburn | WHERE ' . $db->sql_in_set('user_id', $user_id_ary) . " |
| 2857 | 4438 | psotfx | AND group_id = $group_id"; |
| 2858 | 4438 | psotfx | $result = $db->sql_query($sql); |
| 2859 | 4438 | psotfx | |
| 2860 | 4438 | psotfx | $add_id_ary = $update_id_ary = array(); |
| 2861 | 6015 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 2862 | 4438 | psotfx | {
|
| 2863 | 6497 | acydburn | $add_id_ary[] = (int) $row['user_id']; |
| 2864 | 6015 | acydburn | |
| 2865 | 6015 | acydburn | if ($leader && !$row['group_leader']) |
| 2866 | 4438 | psotfx | {
|
| 2867 | 6497 | acydburn | $update_id_ary[] = (int) $row['user_id']; |
| 2868 | 4438 | psotfx | } |
| 2869 | 4438 | psotfx | } |
| 2870 | 4438 | psotfx | $db->sql_freeresult($result); |
| 2871 | 4438 | psotfx | |
| 2872 | 4438 | psotfx | // Do all the users exist in this group?
|
| 2873 | 4780 | psotfx | $add_id_ary = array_diff($user_id_ary, $add_id_ary); |
| 2874 | 4438 | psotfx | |
| 2875 | 5276 | bartvb | // If we have no users
|
| 2876 | 4438 | psotfx | if (!sizeof($add_id_ary) && !sizeof($update_id_ary)) |
| 2877 | 4438 | psotfx | {
|
| 2878 | 4438 | psotfx | return 'GROUP_USERS_EXIST'; |
| 2879 | 4438 | psotfx | } |
| 2880 | 4438 | psotfx | |
| 2881 | 6345 | acydburn | $db->sql_transaction('begin'); |
| 2882 | 6345 | acydburn | |
| 2883 | 6497 | acydburn | // Insert the new users
|
| 2884 | 4438 | psotfx | if (sizeof($add_id_ary)) |
| 2885 | 4438 | psotfx | {
|
| 2886 | 6497 | acydburn | $sql_ary = array(); |
| 2887 | 4438 | psotfx | |
| 2888 | 6497 | acydburn | foreach ($add_id_ary as $user_id) |
| 2889 | 6497 | acydburn | {
|
| 2890 | 6497 | acydburn | $sql_ary[] = array( |
| 2891 | 7961 | acydburn | 'user_id' => (int) $user_id, |
| 2892 | 7961 | acydburn | 'group_id' => (int) $group_id, |
| 2893 | 7961 | acydburn | 'group_leader' => (int) $leader, |
| 2894 | 7961 | acydburn | 'user_pending' => (int) $pending, |
| 2895 | 6497 | acydburn | ); |
| 2896 | 4438 | psotfx | } |
| 2897 | 6497 | acydburn | |
| 2898 | 6497 | acydburn | $db->sql_multi_insert(USER_GROUP_TABLE, $sql_ary); |
| 2899 | 4438 | psotfx | } |
| 2900 | 4438 | psotfx | |
| 2901 | 4438 | psotfx | if (sizeof($update_id_ary)) |
| 2902 | 4438 | psotfx | {
|
| 2903 | 5276 | bartvb | $sql = 'UPDATE ' . USER_GROUP_TABLE . ' |
| 2904 | 5276 | bartvb | SET group_leader = 1 |
| 2905 | 6271 | acydburn | WHERE ' . $db->sql_in_set('user_id', $update_id_ary) . " |
| 2906 | 4438 | psotfx | AND group_id = $group_id"; |
| 2907 | 4438 | psotfx | $db->sql_query($sql); |
| 2908 | 4438 | psotfx | } |
| 2909 | 4438 | psotfx | |
| 2910 | 4780 | psotfx | if ($default) |
| 2911 | 4438 | psotfx | {
|
| 2912 | 9879 | rxu | group_user_attributes('default', $group_id, $user_id_ary, false, $group_name, $group_attributes); |
| 2913 | 4438 | psotfx | } |
| 2914 | 4438 | psotfx | |
| 2915 | 6345 | acydburn | $db->sql_transaction('commit'); |
| 2916 | 6345 | acydburn | |
| 2917 | 4780 | psotfx | // Clear permissions cache of relevant users
|
| 2918 | 4780 | psotfx | $auth->acl_clear_prefetch($user_id_ary); |
| 2919 | 4780 | psotfx | |
| 2920 | 4780 | psotfx | if (!$group_name) |
| 2921 | 4780 | psotfx | {
|
| 2922 | 5765 | acydburn | $group_name = get_group_name($group_id); |
| 2923 | 4780 | psotfx | } |
| 2924 | 4780 | psotfx | |
| 2925 | 9903 | nickvergessen | $log = ($leader) ? 'LOG_MODS_ADDED' : (($pending) ? 'LOG_USERS_PENDING' : 'LOG_USERS_ADDED'); |
| 2926 | 4438 | psotfx | |
| 2927 | 4780 | psotfx | add_log('admin', $log, $group_name, implode(', ', $username_ary)); |
| 2928 | 4780 | psotfx | |
| 2929 | 6366 | acydburn | group_update_listings($group_id);
|
| 2930 | 6366 | acydburn | |
| 2931 | 6366 | acydburn | // Return false - no error
|
| 2932 | 6366 | acydburn | return false; |
| 2933 | 4438 | psotfx | } |
| 2934 | 4438 | psotfx | |
| 2935 | 5114 | acydburn | /**
|
| 2936 | 5114 | acydburn | * Remove a user/s from a given group. When we remove users we update their |
| 2937 | 5114 | acydburn | * default group_id. We do this by examining which "special" groups they belong |
| 2938 | 5114 | acydburn | * to. The selection is made based on a reasonable priority system |
| 2939 | 6366 | acydburn | * |
| 2940 | 6366 | acydburn | * @return false if no errors occurred, else the user lang string for the relevant error, for example 'NO_USER' |
| 2941 | 5114 | acydburn | */ |
| 2942 | 4780 | psotfx | function group_user_del($group_id, $user_id_ary = false, $username_ary = false, $group_name = false) |
| 2943 | 4438 | psotfx | {
|
| 2944 | 9397 | acydburn | global $db, $auth, $config; |
| 2945 | 4438 | psotfx | |
| 2946 | 9397 | acydburn | if ($config['coppa_enable']) |
| 2947 | 9397 | acydburn | {
|
| 2948 | 10215 | acydburn | $group_order = array('ADMINISTRATORS', 'GLOBAL_MODERATORS', 'NEWLY_REGISTERED', 'REGISTERED_COPPA', 'REGISTERED', 'BOTS', 'GUESTS'); |
| 2949 | 9397 | acydburn | } |
| 2950 | 9397 | acydburn | else
|
| 2951 | 9397 | acydburn | {
|
| 2952 | 10215 | acydburn | $group_order = array('ADMINISTRATORS', 'GLOBAL_MODERATORS', 'NEWLY_REGISTERED', 'REGISTERED', 'BOTS', 'GUESTS'); |
| 2953 | 9397 | acydburn | } |
| 2954 | 4438 | psotfx | |
| 2955 | 4780 | psotfx | // We need both username and user_id info
|
| 2956 | 6114 | acydburn | $result = user_get_id_name($user_id_ary, $username_ary); |
| 2957 | 4438 | psotfx | |
| 2958 | 6114 | acydburn | if (!sizeof($user_id_ary) || $result !== false) |
| 2959 | 5698 | acydburn | {
|
| 2960 | 5747 | acydburn | return 'NO_USER'; |
| 2961 | 5698 | acydburn | } |
| 2962 | 5698 | acydburn | |
| 2963 | 5276 | bartvb | $sql = 'SELECT * |
| 2964 | 5276 | bartvb | FROM ' . GROUPS_TABLE . ' |
| 2965 | 6271 | acydburn | WHERE ' . $db->sql_in_set('group_name', $group_order); |
| 2966 | 4780 | psotfx | $result = $db->sql_query($sql); |
| 2967 | 4621 | psotfx | |
| 2968 | 4780 | psotfx | $group_order_id = $special_group_data = array(); |
| 2969 | 4780 | psotfx | while ($row = $db->sql_fetchrow($result)) |
| 2970 | 4438 | psotfx | {
|
| 2971 | 4780 | psotfx | $group_order_id[$row['group_name']] = $row['group_id']; |
| 2972 | 4780 | psotfx | |
| 2973 | 5228 | acydburn | $special_group_data[$row['group_id']] = array( |
| 2974 | 6350 | grahamje | 'group_colour' => $row['group_colour'], |
| 2975 | 6350 | grahamje | 'group_rank' => $row['group_rank'], |
| 2976 | 5228 | acydburn | ); |
| 2977 | 6015 | acydburn | |
| 2978 | 6015 | acydburn | // Only set the group avatar if one is defined...
|
| 2979 | 6015 | acydburn | if ($row['group_avatar']) |
| 2980 | 6015 | acydburn | {
|
| 2981 | 6015 | acydburn | $special_group_data[$row['group_id']] = array_merge($special_group_data[$row['group_id']], array( |
| 2982 | 6350 | grahamje | 'group_avatar' => $row['group_avatar'], |
| 2983 | 6350 | grahamje | 'group_avatar_type' => $row['group_avatar_type'], |
| 2984 | 6350 | grahamje | 'group_avatar_width' => $row['group_avatar_width'], |
| 2985 | 6350 | grahamje | 'group_avatar_height' => $row['group_avatar_height']) |
| 2986 | 6015 | acydburn | ); |
| 2987 | 6015 | acydburn | } |
| 2988 | 4438 | psotfx | } |
| 2989 | 4780 | psotfx | $db->sql_freeresult($result); |
| 2990 | 4438 | psotfx | |
| 2991 | 5196 | acydburn | // Get users default groups - we only need to reset default group membership if the group from which the user gets removed is set as default
|
| 2992 | 5196 | acydburn | $sql = 'SELECT user_id, group_id |
| 2993 | 5196 | acydburn | FROM ' . USERS_TABLE . ' |
| 2994 | 6271 | acydburn | WHERE ' . $db->sql_in_set('user_id', $user_id_ary); |
| 2995 | 5196 | acydburn | $result = $db->sql_query($sql); |
| 2996 | 5276 | bartvb | |
| 2997 | 5196 | acydburn | $default_groups = array(); |
| 2998 | 5196 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 2999 | 5196 | acydburn | {
|
| 3000 | 5196 | acydburn | $default_groups[$row['user_id']] = $row['group_id']; |
| 3001 | 5196 | acydburn | } |
| 3002 | 5196 | acydburn | $db->sql_freeresult($result); |
| 3003 | 5276 | bartvb | |
| 3004 | 4780 | psotfx | // What special group memberships exist for these users?
|
| 3005 | 5196 | acydburn | $sql = 'SELECT g.group_id, g.group_name, ug.user_id |
| 3006 | 5276 | bartvb | FROM ' . USER_GROUP_TABLE . ' ug, ' . GROUPS_TABLE . ' g |
| 3007 | 6271 | acydburn | WHERE ' . $db->sql_in_set('ug.user_id', $user_id_ary) . " |
| 3008 | 4780 | psotfx | AND g.group_id = ug.group_id |
| 3009 | 5276 | bartvb | AND g.group_id <> $group_id |
| 3010 | 4780 | psotfx | AND g.group_type = " . GROUP_SPECIAL . ' |
| 3011 | 4780 | psotfx | ORDER BY ug.user_id, g.group_id';
|
| 3012 | 4780 | psotfx | $result = $db->sql_query($sql); |
| 3013 | 4780 | psotfx | |
| 3014 | 4780 | psotfx | $temp_ary = array(); |
| 3015 | 4780 | psotfx | while ($row = $db->sql_fetchrow($result)) |
| 3016 | 4438 | psotfx | {
|
| 3017 | 9409 | acydburn | if ($default_groups[$row['user_id']] == $group_id && (!isset($temp_ary[$row['user_id']]) || $group_order_id[$row['group_name']] < $temp_ary[$row['user_id']])) |
| 3018 | 4780 | psotfx | {
|
| 3019 | 4780 | psotfx | $temp_ary[$row['user_id']] = $row['group_id']; |
| 3020 | 4780 | psotfx | } |
| 3021 | 4438 | psotfx | } |
| 3022 | 4780 | psotfx | $db->sql_freeresult($result); |
| 3023 | 4438 | psotfx | |
| 3024 | 9409 | acydburn | // sql_where_ary holds the new default groups and their users
|
| 3025 | 4780 | psotfx | $sql_where_ary = array(); |
| 3026 | 4780 | psotfx | foreach ($temp_ary as $uid => $gid) |
| 3027 | 4438 | psotfx | {
|
| 3028 | 4780 | psotfx | $sql_where_ary[$gid][] = $uid; |
| 3029 | 4438 | psotfx | } |
| 3030 | 4780 | psotfx | unset($temp_ary); |
| 3031 | 4438 | psotfx | |
| 3032 | 4780 | psotfx | foreach ($special_group_data as $gid => $default_data_ary) |
| 3033 | 4438 | psotfx | {
|
| 3034 | 5533 | acydburn | if (isset($sql_where_ary[$gid]) && sizeof($sql_where_ary[$gid])) |
| 3035 | 4621 | psotfx | {
|
| 3036 | 9636 | acydburn | remove_default_rank($group_id, $sql_where_ary[$gid]); |
| 3037 | 8007 | kellanved | remove_default_avatar($group_id, $sql_where_ary[$gid]); |
| 3038 | 8007 | kellanved | group_set_user_default($gid, $sql_where_ary[$gid], $default_data_ary); |
| 3039 | 4438 | psotfx | } |
| 3040 | 4438 | psotfx | } |
| 3041 | 4780 | psotfx | unset($special_group_data); |
| 3042 | 4438 | psotfx | |
| 3043 | 5276 | bartvb | $sql = 'DELETE FROM ' . USER_GROUP_TABLE . " |
| 3044 | 4780 | psotfx | WHERE group_id = $group_id |
| 3045 | 6271 | acydburn | AND " . $db->sql_in_set('user_id', $user_id_ary); |
| 3046 | 4780 | psotfx | $db->sql_query($sql); |
| 3047 | 4438 | psotfx | |
| 3048 | 4780 | psotfx | // Clear permissions cache of relevant users
|
| 3049 | 4780 | psotfx | $auth->acl_clear_prefetch($user_id_ary); |
| 3050 | 4438 | psotfx | |
| 3051 | 4780 | psotfx | if (!$group_name) |
| 3052 | 4438 | psotfx | {
|
| 3053 | 5765 | acydburn | $group_name = get_group_name($group_id); |
| 3054 | 4438 | psotfx | } |
| 3055 | 4438 | psotfx | |
| 3056 | 4780 | psotfx | $log = 'LOG_GROUP_REMOVE'; |
| 3057 | 4438 | psotfx | |
| 3058 | 9636 | acydburn | if ($group_name) |
| 3059 | 9636 | acydburn | {
|
| 3060 | 9636 | acydburn | add_log('admin', $log, $group_name, implode(', ', $username_ary)); |
| 3061 | 9636 | acydburn | } |
| 3062 | 4438 | psotfx | |
| 3063 | 6894 | acydburn | group_update_listings($group_id);
|
| 3064 | 6894 | acydburn | |
| 3065 | 6366 | acydburn | // Return false - no error
|
| 3066 | 6366 | acydburn | return false; |
| 3067 | 4438 | psotfx | } |
| 3068 | 4438 | psotfx | |
| 3069 | 8007 | kellanved | |
| 3070 | 5114 | acydburn | /**
|
| 3071 | 8007 | kellanved | * Removes the group avatar of the default group from the users in user_ids who have that group as default. |
| 3072 | 8007 | kellanved | */ |
| 3073 | 8007 | kellanved | function remove_default_avatar($group_id, $user_ids) |
| 3074 | 8007 | kellanved | {
|
| 3075 | 8007 | kellanved | global $db; |
| 3076 | 8007 | kellanved | |
| 3077 | 8007 | kellanved | if (!is_array($user_ids)) |
| 3078 | 8007 | kellanved | {
|
| 3079 | 8007 | kellanved | $user_ids = array($user_ids); |
| 3080 | 8007 | kellanved | } |
| 3081 | 8007 | kellanved | if (empty($user_ids)) |
| 3082 | 8007 | kellanved | {
|
| 3083 | 8007 | kellanved | return false; |
| 3084 | 8007 | kellanved | } |
| 3085 | 8007 | kellanved | |
| 3086 | 8007 | kellanved | $user_ids = array_map('intval', $user_ids); |
| 3087 | 8007 | kellanved | |
| 3088 | 8007 | kellanved | $sql = 'SELECT * |
| 3089 | 8007 | kellanved | FROM ' . GROUPS_TABLE . ' |
| 3090 | 8007 | kellanved | WHERE group_id = ' . (int)$group_id; |
| 3091 | 8007 | kellanved | $result = $db->sql_query($sql); |
| 3092 | 8007 | kellanved | if (!$row = $db->sql_fetchrow($result)) |
| 3093 | 8007 | kellanved | {
|
| 3094 | 8008 | kellanved | $db->sql_freeresult($result); |
| 3095 | 8007 | kellanved | return false; |
| 3096 | 8007 | kellanved | } |
| 3097 | 8008 | kellanved | $db->sql_freeresult($result); |
| 3098 | 8350 | acydburn | |
| 3099 | 8146 | acydburn | $sql = 'UPDATE ' . USERS_TABLE . " |
| 3100 | 8146 | acydburn | SET user_avatar = '', |
| 3101 | 8146 | acydburn | user_avatar_type = 0, |
| 3102 | 8146 | acydburn | user_avatar_width = 0, |
| 3103 | 8146 | acydburn | user_avatar_height = 0 |
| 3104 | 8146 | acydburn | WHERE group_id = " . (int) $group_id . " |
| 3105 | 8146 | acydburn | AND user_avatar = '" . $db->sql_escape($row['group_avatar']) . "' |
| 3106 | 8146 | acydburn | AND " . $db->sql_in_set('user_id', $user_ids); |
| 3107 | 8350 | acydburn | |
| 3108 | 8007 | kellanved | $db->sql_query($sql); |
| 3109 | 8007 | kellanved | } |
| 3110 | 8007 | kellanved | |
| 3111 | 8007 | kellanved | /**
|
| 3112 | 8007 | kellanved | * Removes the group rank of the default group from the users in user_ids who have that group as default. |
| 3113 | 8007 | kellanved | */ |
| 3114 | 8007 | kellanved | function remove_default_rank($group_id, $user_ids) |
| 3115 | 8007 | kellanved | {
|
| 3116 | 8007 | kellanved | global $db; |
| 3117 | 8007 | kellanved | |
| 3118 | 8007 | kellanved | if (!is_array($user_ids)) |
| 3119 | 8007 | kellanved | {
|
| 3120 | 8007 | kellanved | $user_ids = array($user_ids); |
| 3121 | 8007 | kellanved | } |
| 3122 | 8007 | kellanved | if (empty($user_ids)) |
| 3123 | 8007 | kellanved | {
|
| 3124 | 8007 | kellanved | return false; |
| 3125 | 8007 | kellanved | } |
| 3126 | 8007 | kellanved | |
| 3127 | 8007 | kellanved | $user_ids = array_map('intval', $user_ids); |
| 3128 | 8007 | kellanved | |
| 3129 | 8007 | kellanved | $sql = 'SELECT * |
| 3130 | 8007 | kellanved | FROM ' . GROUPS_TABLE . ' |
| 3131 | 8007 | kellanved | WHERE group_id = ' . (int)$group_id; |
| 3132 | 8007 | kellanved | $result = $db->sql_query($sql); |
| 3133 | 8007 | kellanved | if (!$row = $db->sql_fetchrow($result)) |
| 3134 | 8007 | kellanved | {
|
| 3135 | 8008 | kellanved | $db->sql_freeresult($result); |
| 3136 | 8007 | kellanved | return false; |
| 3137 | 8007 | kellanved | } |
| 3138 | 8008 | kellanved | $db->sql_freeresult($result); |
| 3139 | 8007 | kellanved | |
| 3140 | 8007 | kellanved | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 3141 | 8007 | kellanved | SET user_rank = 0 |
| 3142 | 8146 | acydburn | WHERE group_id = ' . (int)$group_id . ' |
| 3143 | 8146 | acydburn | AND user_rank <> 0 |
| 3144 | 8146 | acydburn | AND user_rank = ' . (int)$row['group_rank'] . ' |
| 3145 | 8007 | kellanved | AND ' . $db->sql_in_set('user_id', $user_ids); |
| 3146 | 8007 | kellanved | $db->sql_query($sql); |
| 3147 | 8007 | kellanved | } |
| 3148 | 8007 | kellanved | |
| 3149 | 8007 | kellanved | /**
|
| 3150 | 5114 | acydburn | * This is used to promote (to leader), demote or set as default a member/s |
| 3151 | 5114 | acydburn | */ |
| 3152 | 5228 | acydburn | function group_user_attributes($action, $group_id, $user_id_ary = false, $username_ary = false, $group_name = false, $group_attributes = false) |
| 3153 | 4440 | psotfx | {
|
| 3154 | 6015 | acydburn | global $db, $auth, $phpbb_root_path, $phpEx, $config; |
| 3155 | 4440 | psotfx | |
| 3156 | 4780 | psotfx | // We need both username and user_id info
|
| 3157 | 6114 | acydburn | $result = user_get_id_name($user_id_ary, $username_ary); |
| 3158 | 4440 | psotfx | |
| 3159 | 6114 | acydburn | if (!sizeof($user_id_ary) || $result !== false) |
| 3160 | 5698 | acydburn | {
|
| 3161 | 8634 | Kellanved | return 'NO_USERS'; |
| 3162 | 5698 | acydburn | } |
| 3163 | 5698 | acydburn | |
| 3164 | 6015 | acydburn | if (!$group_name) |
| 3165 | 6015 | acydburn | {
|
| 3166 | 6015 | acydburn | $group_name = get_group_name($group_id); |
| 3167 | 6015 | acydburn | } |
| 3168 | 6015 | acydburn | |
| 3169 | 4619 | psotfx | switch ($action) |
| 3170 | 4615 | psotfx | {
|
| 3171 | 4615 | psotfx | case 'demote': |
| 3172 | 4780 | psotfx | case 'promote': |
| 3173 | 8668 | acydburn | |
| 3174 | 8634 | Kellanved | $sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . " |
| 3175 | 8634 | Kellanved | WHERE group_id = $group_id |
| 3176 | 8634 | Kellanved | AND user_pending = 1 |
| 3177 | 8634 | Kellanved | AND " . $db->sql_in_set('user_id', $user_id_ary); |
| 3178 | 8634 | Kellanved | $result = $db->sql_query_limit($sql, 1); |
| 3179 | 8634 | Kellanved | $not_empty = ($db->sql_fetchrow($result)); |
| 3180 | 8634 | Kellanved | $db->sql_freeresult($result); |
| 3181 | 8634 | Kellanved | if ($not_empty) |
| 3182 | 8634 | Kellanved | {
|
| 3183 | 8634 | Kellanved | return 'NO_VALID_USERS'; |
| 3184 | 8634 | Kellanved | } |
| 3185 | 8668 | acydburn | |
| 3186 | 4619 | psotfx | $sql = 'UPDATE ' . USER_GROUP_TABLE . ' |
| 3187 | 5276 | bartvb | SET group_leader = ' . (($action == 'promote') ? 1 : 0) . " |
| 3188 | 4780 | psotfx | WHERE group_id = $group_id |
| 3189 | 8634 | Kellanved | AND user_pending = 0 |
| 3190 | 6271 | acydburn | AND " . $db->sql_in_set('user_id', $user_id_ary); |
| 3191 | 4615 | psotfx | $db->sql_query($sql); |
| 3192 | 4621 | psotfx | |
| 3193 | 4780 | psotfx | $log = ($action == 'promote') ? 'LOG_GROUP_PROMOTED' : 'LOG_GROUP_DEMOTED'; |
| 3194 | 5228 | acydburn | break;
|
| 3195 | 4615 | psotfx | |
| 3196 | 4780 | psotfx | case 'approve': |
| 3197 | 6015 | acydburn | // Make sure we only approve those which are pending ;)
|
| 3198 | 6698 | acydburn | $sql = 'SELECT u.user_id, u.user_email, u.username, u.username_clean, u.user_notify_type, u.user_jabber, u.user_lang |
| 3199 | 6015 | acydburn | FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . ' ug |
| 3200 | 6015 | acydburn | WHERE ug.group_id = ' . $group_id . ' |
| 3201 | 6015 | acydburn | AND ug.user_pending = 1 |
| 3202 | 6015 | acydburn | AND ug.user_id = u.user_id |
| 3203 | 6271 | acydburn | AND ' . $db->sql_in_set('ug.user_id', $user_id_ary); |
| 3204 | 6015 | acydburn | $result = $db->sql_query($sql); |
| 3205 | 6015 | acydburn | |
| 3206 | 6015 | acydburn | $user_id_ary = $email_users = array(); |
| 3207 | 6015 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 3208 | 6015 | acydburn | {
|
| 3209 | 6015 | acydburn | $user_id_ary[] = $row['user_id']; |
| 3210 | 6015 | acydburn | $email_users[] = $row; |
| 3211 | 6015 | acydburn | } |
| 3212 | 6015 | acydburn | $db->sql_freeresult($result); |
| 3213 | 6015 | acydburn | |
| 3214 | 6015 | acydburn | if (!sizeof($user_id_ary)) |
| 3215 | 6015 | acydburn | {
|
| 3216 | 6015 | acydburn | return false; |
| 3217 | 6015 | acydburn | } |
| 3218 | 6015 | acydburn | |
| 3219 | 5276 | bartvb | $sql = 'UPDATE ' . USER_GROUP_TABLE . " |
| 3220 | 5276 | bartvb | SET user_pending = 0 |
| 3221 | 5276 | bartvb | WHERE group_id = $group_id |
| 3222 | 6271 | acydburn | AND " . $db->sql_in_set('user_id', $user_id_ary); |
| 3223 | 4619 | psotfx | $db->sql_query($sql); |
| 3224 | 4621 | psotfx | |
| 3225 | 6015 | acydburn | // Send approved email to users...
|
| 3226 | 6015 | acydburn | include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); |
| 3227 | 6015 | acydburn | $messenger = new messenger(); |
| 3228 | 6015 | acydburn | |
| 3229 | 6015 | acydburn | foreach ($email_users as $row) |
| 3230 | 6015 | acydburn | {
|
| 3231 | 6015 | acydburn | $messenger->template('group_approved', $row['user_lang']); |
| 3232 | 6015 | acydburn | |
| 3233 | 6015 | acydburn | $messenger->to($row['user_email'], $row['username']); |
| 3234 | 6015 | acydburn | $messenger->im($row['user_jabber'], $row['username']); |
| 3235 | 6015 | acydburn | |
| 3236 | 6015 | acydburn | $messenger->assign_vars(array( |
| 3237 | 6548 | acydburn | 'USERNAME' => htmlspecialchars_decode($row['username']), |
| 3238 | 6548 | acydburn | 'GROUP_NAME' => htmlspecialchars_decode($group_name), |
| 3239 | 6015 | acydburn | 'U_GROUP' => generate_board_url() . "/ucp.$phpEx?i=groups&mode=membership") |
| 3240 | 6015 | acydburn | ); |
| 3241 | 6015 | acydburn | |
| 3242 | 6015 | acydburn | $messenger->send($row['user_notify_type']); |
| 3243 | 6015 | acydburn | } |
| 3244 | 6015 | acydburn | |
| 3245 | 6015 | acydburn | $messenger->save_queue();
|
| 3246 | 6015 | acydburn | |
| 3247 | 6015 | acydburn | $log = 'LOG_USERS_APPROVED'; |
| 3248 | 5228 | acydburn | break;
|
| 3249 | 4619 | psotfx | |
| 3250 | 4780 | psotfx | case 'default': |
| 3251 | 9759 | nickvergessen | // We only set default group for approved members of the group
|
| 3252 | 9759 | nickvergessen | $sql = 'SELECT user_id |
| 3253 | 9759 | nickvergessen | FROM ' . USER_GROUP_TABLE . " |
| 3254 | 9759 | nickvergessen | WHERE group_id = $group_id |
| 3255 | 9759 | nickvergessen | AND user_pending = 0 |
| 3256 | 9759 | nickvergessen | AND " . $db->sql_in_set('user_id', $user_id_ary); |
| 3257 | 9759 | nickvergessen | $result = $db->sql_query($sql); |
| 3258 | 9759 | nickvergessen | |
| 3259 | 9759 | nickvergessen | $user_id_ary = $username_ary = array(); |
| 3260 | 9759 | nickvergessen | while ($row = $db->sql_fetchrow($result)) |
| 3261 | 9759 | nickvergessen | {
|
| 3262 | 9759 | nickvergessen | $user_id_ary[] = $row['user_id']; |
| 3263 | 9759 | nickvergessen | } |
| 3264 | 9759 | nickvergessen | $db->sql_freeresult($result); |
| 3265 | 9759 | nickvergessen | |
| 3266 | 9759 | nickvergessen | $result = user_get_id_name($user_id_ary, $username_ary); |
| 3267 | 9759 | nickvergessen | if (!sizeof($user_id_ary) || $result !== false) |
| 3268 | 9759 | nickvergessen | {
|
| 3269 | 9759 | nickvergessen | return 'NO_USERS'; |
| 3270 | 9759 | nickvergessen | } |
| 3271 | 9759 | nickvergessen | |
| 3272 | 8146 | acydburn | $sql = 'SELECT user_id, group_id FROM ' . USERS_TABLE . ' |
| 3273 | 8007 | kellanved | WHERE ' . $db->sql_in_set('user_id', $user_id_ary, false, true); |
| 3274 | 8007 | kellanved | $result = $db->sql_query($sql); |
| 3275 | 8007 | kellanved | |
| 3276 | 8007 | kellanved | $groups = array(); |
| 3277 | 8007 | kellanved | while ($row = $db->sql_fetchrow($result)) |
| 3278 | 8007 | kellanved | {
|
| 3279 | 8007 | kellanved | if (!isset($groups[$row['group_id']])) |
| 3280 | 8007 | kellanved | {
|
| 3281 | 8007 | kellanved | $groups[$row['group_id']] = array(); |
| 3282 | 8007 | kellanved | } |
| 3283 | 8007 | kellanved | $groups[$row['group_id']][] = $row['user_id']; |
| 3284 | 8007 | kellanved | } |
| 3285 | 8007 | kellanved | $db->sql_freeresult($result); |
| 3286 | 8007 | kellanved | |
| 3287 | 8007 | kellanved | foreach ($groups as $gid => $uids) |
| 3288 | 8007 | kellanved | {
|
| 3289 | 8007 | kellanved | remove_default_rank($gid, $uids); |
| 3290 | 8007 | kellanved | remove_default_avatar($gid, $uids); |
| 3291 | 8007 | kellanved | } |
| 3292 | 5228 | acydburn | group_set_user_default($group_id, $user_id_ary, $group_attributes); |
| 3293 | 4780 | psotfx | $log = 'LOG_GROUP_DEFAULTS'; |
| 3294 | 6015 | acydburn | break;
|
| 3295 | 4615 | psotfx | } |
| 3296 | 4615 | psotfx | |
| 3297 | 4780 | psotfx | // Clear permissions cache of relevant users
|
| 3298 | 4780 | psotfx | $auth->acl_clear_prefetch($user_id_ary); |
| 3299 | 4780 | psotfx | |
| 3300 | 4615 | psotfx | add_log('admin', $log, $group_name, implode(', ', $username_ary)); |
| 3301 | 4440 | psotfx | |
| 3302 | 6894 | acydburn | group_update_listings($group_id);
|
| 3303 | 6894 | acydburn | |
| 3304 | 8634 | Kellanved | return false; |
| 3305 | 4440 | psotfx | } |
| 3306 | 4440 | psotfx | |
| 3307 | 5114 | acydburn | /**
|
| 3308 | 7450 | kellanved | * A small version of validate_username to check for a group name's existence. To be called directly. |
| 3309 | 7449 | kellanved | */ |
| 3310 | 7452 | acydburn | function group_validate_groupname($group_id, $group_name) |
| 3311 | 7449 | kellanved | {
|
| 3312 | 7449 | kellanved | global $config, $db; |
| 3313 | 7449 | kellanved | |
| 3314 | 8146 | acydburn | $group_name = utf8_clean_string($group_name); |
| 3315 | 7449 | kellanved | |
| 3316 | 7449 | kellanved | if (!empty($group_id)) |
| 3317 | 7449 | kellanved | {
|
| 3318 | 7449 | kellanved | $sql = 'SELECT group_name |
| 3319 | 7452 | acydburn | FROM ' . GROUPS_TABLE . ' |
| 3320 | 7452 | acydburn | WHERE group_id = ' . (int) $group_id; |
| 3321 | 7449 | kellanved | $result = $db->sql_query($sql); |
| 3322 | 7449 | kellanved | $row = $db->sql_fetchrow($result); |
| 3323 | 7449 | kellanved | $db->sql_freeresult($result); |
| 3324 | 7452 | acydburn | |
| 3325 | 7452 | acydburn | if (!$row) |
| 3326 | 7449 | kellanved | {
|
| 3327 | 7449 | kellanved | return false; |
| 3328 | 7449 | kellanved | } |
| 3329 | 7452 | acydburn | |
| 3330 | 7452 | acydburn | $allowed_groupname = utf8_clean_string($row['group_name']); |
| 3331 | 7452 | acydburn | |
| 3332 | 7452 | acydburn | if ($allowed_groupname == $group_name) |
| 3333 | 7452 | acydburn | {
|
| 3334 | 7452 | acydburn | return false; |
| 3335 | 7452 | acydburn | } |
| 3336 | 7449 | kellanved | } |
| 3337 | 7449 | kellanved | |
| 3338 | 7449 | kellanved | $sql = 'SELECT group_name |
| 3339 | 7449 | kellanved | FROM ' . GROUPS_TABLE . " |
| 3340 | 7452 | acydburn | WHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($group_name)) . "'"; |
| 3341 | 7449 | kellanved | $result = $db->sql_query($sql); |
| 3342 | 7449 | kellanved | $row = $db->sql_fetchrow($result); |
| 3343 | 7449 | kellanved | $db->sql_freeresult($result); |
| 3344 | 8350 | acydburn | |
| 3345 | 7449 | kellanved | if ($row) |
| 3346 | 7449 | kellanved | {
|
| 3347 | 7449 | kellanved | return 'GROUP_NAME_TAKEN'; |
| 3348 | 7449 | kellanved | } |
| 3349 | 7452 | acydburn | |
| 3350 | 7450 | kellanved | return false; |
| 3351 | 7449 | kellanved | } |
| 3352 | 7449 | kellanved | |
| 3353 | 7449 | kellanved | /**
|
| 3354 | 5228 | acydburn | * Set users default group |
| 3355 | 6894 | acydburn | * |
| 3356 | 8783 | acydburn | * @access private |
| 3357 | 5228 | acydburn | */ |
| 3358 | 8007 | kellanved | function group_set_user_default($group_id, $user_id_ary, $group_attributes = false, $update_listing = false) |
| 3359 | 5228 | acydburn | {
|
| 3360 | 9759 | nickvergessen | global $cache, $db; |
| 3361 | 5228 | acydburn | |
| 3362 | 6114 | acydburn | if (empty($user_id_ary)) |
| 3363 | 5228 | acydburn | {
|
| 3364 | 5228 | acydburn | return;
|
| 3365 | 5228 | acydburn | } |
| 3366 | 5228 | acydburn | |
| 3367 | 5228 | acydburn | $attribute_ary = array( |
| 3368 | 5228 | acydburn | 'group_colour' => 'string', |
| 3369 | 5276 | bartvb | 'group_rank' => 'int', |
| 3370 | 5228 | acydburn | 'group_avatar' => 'string', |
| 3371 | 5228 | acydburn | 'group_avatar_type' => 'int', |
| 3372 | 5228 | acydburn | 'group_avatar_width' => 'int', |
| 3373 | 5228 | acydburn | 'group_avatar_height' => 'int', |
| 3374 | 5228 | acydburn | ); |
| 3375 | 5228 | acydburn | |
| 3376 | 5228 | acydburn | $sql_ary = array( |
| 3377 | 5228 | acydburn | 'group_id' => $group_id |
| 3378 | 5228 | acydburn | ); |
| 3379 | 5228 | acydburn | |
| 3380 | 5228 | acydburn | // Were group attributes passed to the function? If not we need to obtain them
|
| 3381 | 5228 | acydburn | if ($group_attributes === false) |
| 3382 | 5228 | acydburn | {
|
| 3383 | 5228 | acydburn | $sql = 'SELECT ' . implode(', ', array_keys($attribute_ary)) . ' |
| 3384 | 5276 | bartvb | FROM ' . GROUPS_TABLE . " |
| 3385 | 5228 | acydburn | WHERE group_id = $group_id"; |
| 3386 | 5228 | acydburn | $result = $db->sql_query($sql); |
| 3387 | 5228 | acydburn | $group_attributes = $db->sql_fetchrow($result); |
| 3388 | 5228 | acydburn | $db->sql_freeresult($result); |
| 3389 | 5228 | acydburn | } |
| 3390 | 5276 | bartvb | |
| 3391 | 5228 | acydburn | foreach ($attribute_ary as $attribute => $type) |
| 3392 | 5228 | acydburn | {
|
| 3393 | 5228 | acydburn | if (isset($group_attributes[$attribute])) |
| 3394 | 5228 | acydburn | {
|
| 3395 | 7927 | kellanved | // If we are about to set an avatar or rank, we will not overwrite with empty, unless we are not actually changing the default group
|
| 3396 | 8007 | kellanved | if ((strpos($attribute, 'group_avatar') === 0 || strpos($attribute, 'group_rank') === 0) && !$group_attributes[$attribute]) |
| 3397 | 5902 | acydburn | {
|
| 3398 | 5902 | acydburn | continue;
|
| 3399 | 5902 | acydburn | } |
| 3400 | 5902 | acydburn | |
| 3401 | 5228 | acydburn | settype($group_attributes[$attribute], $type); |
| 3402 | 5228 | acydburn | $sql_ary[str_replace('group_', 'user_', $attribute)] = $group_attributes[$attribute]; |
| 3403 | 5228 | acydburn | } |
| 3404 | 5228 | acydburn | } |
| 3405 | 5276 | bartvb | |
| 3406 | 6015 | acydburn | // Before we update the user attributes, we will make a list of those having now the group avatar assigned
|
| 3407 | 8350 | acydburn | if (isset($sql_ary['user_avatar'])) |
| 3408 | 6015 | acydburn | {
|
| 3409 | 6015 | acydburn | // Ok, get the original avatar data from users having an uploaded one (we need to remove these from the filesystem)
|
| 3410 | 6511 | acydburn | $sql = 'SELECT user_id, group_id, user_avatar |
| 3411 | 6015 | acydburn | FROM ' . USERS_TABLE . ' |
| 3412 | 6271 | acydburn | WHERE ' . $db->sql_in_set('user_id', $user_id_ary) . ' |
| 3413 | 6015 | acydburn | AND user_avatar_type = ' . AVATAR_UPLOAD; |
| 3414 | 6015 | acydburn | $result = $db->sql_query($sql); |
| 3415 | 6015 | acydburn | |
| 3416 | 6015 | acydburn | while ($row = $db->sql_fetchrow($result)) |
| 3417 | 6015 | acydburn | {
|
| 3418 | 6511 | acydburn | avatar_delete('user', $row); |
| 3419 | 6015 | acydburn | } |
| 3420 | 6015 | acydburn | $db->sql_freeresult($result); |
| 3421 | 6015 | acydburn | } |
| 3422 | 8007 | kellanved | else
|
| 3423 | 8007 | kellanved | {
|
| 3424 | 8007 | kellanved | unset($sql_ary['user_avatar_type']); |
| 3425 | 8007 | kellanved | unset($sql_ary['user_avatar_height']); |
| 3426 | 8007 | kellanved | unset($sql_ary['user_avatar_width']); |
| 3427 | 8007 | kellanved | } |
| 3428 | 6015 | acydburn | |
| 3429 | 5228 | acydburn | $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' |
| 3430 | 6271 | acydburn | WHERE ' . $db->sql_in_set('user_id', $user_id_ary); |
| 3431 | 5228 | acydburn | $db->sql_query($sql); |
| 3432 | 6350 | grahamje | |
| 3433 | 8350 | acydburn | if (isset($sql_ary['user_colour'])) |
| 3434 | 6511 | acydburn | {
|
| 3435 | 6511 | acydburn | // Update any cached colour information for these users
|
| 3436 | 6511 | acydburn | $sql = 'UPDATE ' . FORUMS_TABLE . " SET forum_last_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' |
| 3437 | 6511 | acydburn | WHERE " . $db->sql_in_set('forum_last_poster_id', $user_id_ary); |
| 3438 | 6511 | acydburn | $db->sql_query($sql); |
| 3439 | 6350 | grahamje | |
| 3440 | 6511 | acydburn | $sql = 'UPDATE ' . TOPICS_TABLE . " SET topic_first_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' |
| 3441 | 6511 | acydburn | WHERE " . $db->sql_in_set('topic_poster', $user_id_ary); |
| 3442 | 6511 | acydburn | $db->sql_query($sql); |
| 3443 | 6350 | grahamje | |
| 3444 | 6511 | acydburn | $sql = 'UPDATE ' . TOPICS_TABLE . " SET topic_last_poster_colour = '" . $db->sql_escape($sql_ary['user_colour']) . "' |
| 3445 | 6511 | acydburn | WHERE " . $db->sql_in_set('topic_last_poster_id', $user_id_ary); |
| 3446 | 6511 | acydburn | $db->sql_query($sql); |
| 3447 | 6742 | davidmj | |
| 3448 | 6748 | davidmj | global $config; |
| 3449 | 6748 | davidmj | |
| 3450 | 6782 | davidmj | if (in_array($config['newest_user_id'], $user_id_ary)) |
| 3451 | 6742 | davidmj | {
|
| 3452 | 6742 | davidmj | set_config('newest_user_colour', $sql_ary['user_colour'], true); |
| 3453 | 6742 | davidmj | } |
| 3454 | 6511 | acydburn | } |
| 3455 | 6894 | acydburn | |
| 3456 | 6894 | acydburn | if ($update_listing) |
| 3457 | 6894 | acydburn | {
|
| 3458 | 6894 | acydburn | group_update_listings($group_id);
|
| 3459 | 6894 | acydburn | } |
| 3460 | 9759 | nickvergessen | |
| 3461 | 9759 | nickvergessen | // Because some tables/caches use usercolour-specific data we need to purge this here.
|
| 3462 | 9759 | nickvergessen | $cache->destroy('sql', MODERATOR_CACHE_TABLE); |
| 3463 | 5228 | acydburn | } |
| 3464 | 5228 | acydburn | |
| 3465 | 5228 | acydburn | /**
|
| 3466 | 5765 | acydburn | * Get group name |
| 3467 | 5765 | acydburn | */ |
| 3468 | 5765 | acydburn | function get_group_name($group_id) |
| 3469 | 5765 | acydburn | {
|
| 3470 | 5765 | acydburn | global $db, $user; |
| 3471 | 5765 | acydburn | |
| 3472 | 5765 | acydburn | $sql = 'SELECT group_name, group_type |
| 3473 | 5765 | acydburn | FROM ' . GROUPS_TABLE . ' |
| 3474 | 5765 | acydburn | WHERE group_id = ' . (int) $group_id; |
| 3475 | 5765 | acydburn | $result = $db->sql_query($sql); |
| 3476 | 5765 | acydburn | $row = $db->sql_fetchrow($result); |
| 3477 | 5765 | acydburn | $db->sql_freeresult($result); |
| 3478 | 5765 | acydburn | |
| 3479 | 9636 | acydburn | if (!$row || ($row['group_type'] == GROUP_SPECIAL && empty($user->lang))) |
| 3480 | 5765 | acydburn | {
|
| 3481 | 5765 | acydburn | return ''; |
| 3482 | 5765 | acydburn | } |
| 3483 | 5765 | acydburn | |
| 3484 | 5765 | acydburn | return ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']; |
| 3485 | 5765 | acydburn | } |
| 3486 | 5765 | acydburn | |
| 3487 | 5765 | acydburn | /**
|
| 3488 | 5157 | acydburn | * Obtain either the members of a specified group, the groups the specified user is subscribed to |
| 3489 | 7143 | acydburn | * or checking if a specified user is in a specified group. This function does not return pending memberships. |
| 3490 | 5157 | acydburn | * |
| 3491 | 5196 | acydburn | * Note: Never use this more than once... first group your users/groups |
| 3492 | 5114 | acydburn | */ |
| 3493 | 5157 | acydburn | function group_memberships($group_id_ary = false, $user_id_ary = false, $return_bool = false) |
| 3494 | 4780 | psotfx | {
|
| 3495 | 4780 | psotfx | global $db; |
| 3496 | 4780 | psotfx | |
| 3497 | 5157 | acydburn | if (!$group_id_ary && !$user_id_ary) |
| 3498 | 4780 | psotfx | {
|
| 3499 | 4780 | psotfx | return true; |
| 3500 | 4780 | psotfx | } |
| 3501 | 4780 | psotfx | |
| 3502 | 6271 | acydburn | if ($user_id_ary) |
| 3503 | 6271 | acydburn | {
|
| 3504 | 6271 | acydburn | $user_id_ary = (!is_array($user_id_ary)) ? array($user_id_ary) : $user_id_ary; |
| 3505 | 6271 | acydburn | } |
| 3506 | 6271 | acydburn | |
| 3507 | 6271 | acydburn | if ($group_id_ary) |
| 3508 | 6271 | acydburn | {
|
| 3509 | 6271 | acydburn | $group_id_ary = (!is_array($group_id_ary)) ? array($group_id_ary) : $group_id_ary; |
| 3510 | 6271 | acydburn | } |
| 3511 | 6271 | acydburn | |
| 3512 | 6698 | acydburn | $sql = 'SELECT ug.*, u.username, u.username_clean, u.user_email |
| 3513 | 5196 | acydburn | FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u |
| 3514 | 7007 | acydburn | WHERE ug.user_id = u.user_id |
| 3515 | 7007 | acydburn | AND ug.user_pending = 0 AND ';
|
| 3516 | 5157 | acydburn | |
| 3517 | 6271 | acydburn | if ($group_id_ary) |
| 3518 | 4780 | psotfx | {
|
| 3519 | 6271 | acydburn | $sql .= ' ' . $db->sql_in_set('ug.group_id', $group_id_ary); |
| 3520 | 4780 | psotfx | } |
| 3521 | 6271 | acydburn | |
| 3522 | 6271 | acydburn | if ($user_id_ary) |
| 3523 | 5157 | acydburn | {
|
| 3524 | 6271 | acydburn | $sql .= ($group_id_ary) ? ' AND ' : ' '; |
| 3525 | 6271 | acydburn | $sql .= $db->sql_in_set('ug.user_id', $user_id_ary); |
| 3526 | 5157 | acydburn | } |
| 3527 | 5276 | bartvb | |
| 3528 | 5157 | acydburn | $result = ($return_bool) ? $db->sql_query_limit($sql, 1) : $db->sql_query($sql); |
| 3529 | 5196 | acydburn | |
| 3530 | 5157 | acydburn | $row = $db->sql_fetchrow($result); |
| 3531 | 4780 | psotfx | |
| 3532 | 5157 | acydburn | if ($return_bool) |
| 3533 | 5157 | acydburn | {
|
| 3534 | 5157 | acydburn | $db->sql_freeresult($result); |
| 3535 | 5157 | acydburn | return ($row) ? true : false; |
| 3536 | 5157 | acydburn | } |
| 3537 | 5157 | acydburn | |
| 3538 | 5196 | acydburn | if (!$row) |
| 3539 | 5196 | acydburn | {
|
| 3540 | 5196 | acydburn | return false; |
| 3541 | 5196 | acydburn | } |
| 3542 | 5157 | acydburn | |
| 3543 | 5196 | acydburn | $return = array(); |
| 3544 | 5196 | acydburn | |
| 3545 | 5157 | acydburn | do
|
| 3546 | 5157 | acydburn | {
|
| 3547 | 5196 | acydburn | $return[] = $row; |
| 3548 | 5157 | acydburn | } |
| 3549 | 5157 | acydburn | while ($row = $db->sql_fetchrow($result)); |
| 3550 | 5196 | acydburn | |
| 3551 | 5196 | acydburn | $db->sql_freeresult($result); |
| 3552 | 5196 | acydburn | |
| 3553 | 5196 | acydburn | return $return; |
| 3554 | 4780 | psotfx | } |
| 3555 | 4780 | psotfx | |
| 3556 | 6366 | acydburn | /**
|
| 3557 | 6366 | acydburn | * Re-cache moderators and foes if group has a_ or m_ permissions |
| 3558 | 6366 | acydburn | */ |
| 3559 | 6366 | acydburn | function group_update_listings($group_id) |
| 3560 | 6366 | acydburn | {
|
| 3561 | 6366 | acydburn | global $auth; |
| 3562 | 6366 | acydburn | |
| 3563 | 6366 | acydburn | $hold_ary = $auth->acl_group_raw_data($group_id, array('a_', 'm_')); |
| 3564 | 6366 | acydburn | |
| 3565 | 6366 | acydburn | if (!sizeof($hold_ary)) |
| 3566 | 6366 | acydburn | {
|
| 3567 | 6366 | acydburn | return;
|
| 3568 | 6366 | acydburn | } |
| 3569 | 6366 | acydburn | |
| 3570 | 6366 | acydburn | $mod_permissions = $admin_permissions = false; |
| 3571 | 6366 | acydburn | |
| 3572 | 6366 | acydburn | foreach ($hold_ary as $g_id => $forum_ary) |
| 3573 | 6366 | acydburn | {
|
| 3574 | 6366 | acydburn | foreach ($forum_ary as $forum_id => $auth_ary) |
| 3575 | 6366 | acydburn | {
|
| 3576 | 6366 | acydburn | foreach ($auth_ary as $auth_option => $setting) |
| 3577 | 6366 | acydburn | {
|
| 3578 | 6366 | acydburn | if ($mod_permissions && $admin_permissions) |
| 3579 | 6366 | acydburn | {
|
| 3580 | 6366 | acydburn | break 3; |
| 3581 | 6366 | acydburn | } |
| 3582 | 6366 | acydburn | |
| 3583 | 6366 | acydburn | if ($setting != ACL_YES) |
| 3584 | 6366 | acydburn | {
|
| 3585 | 6366 | acydburn | continue;
|
| 3586 | 6366 | acydburn | } |
| 3587 | 6366 | acydburn | |
| 3588 | 6366 | acydburn | if ($auth_option == 'm_') |
| 3589 | 6366 | acydburn | {
|
| 3590 | 6366 | acydburn | $mod_permissions = true; |
| 3591 | 6366 | acydburn | } |
| 3592 | 6366 | acydburn | |
| 3593 | 6366 | acydburn | if ($auth_option == 'a_') |
| 3594 | 6366 | acydburn | {
|
| 3595 | 6366 | acydburn | $admin_permissions = true; |
| 3596 | 6366 | acydburn | } |
| 3597 | 6366 | acydburn | } |
| 3598 | 6366 | acydburn | } |
| 3599 | 6366 | acydburn | } |
| 3600 | 6366 | acydburn | |
| 3601 | 6366 | acydburn | if ($mod_permissions) |
| 3602 | 6366 | acydburn | {
|
| 3603 | 6511 | acydburn | if (!function_exists('cache_moderators')) |
| 3604 | 6511 | acydburn | {
|
| 3605 | 6597 | davidmj | global $phpbb_root_path, $phpEx; |
| 3606 | 6511 | acydburn | include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); |
| 3607 | 6511 | acydburn | } |
| 3608 | 6366 | acydburn | cache_moderators(); |
| 3609 | 6366 | acydburn | } |
| 3610 | 6366 | acydburn | |
| 3611 | 6366 | acydburn | if ($mod_permissions || $admin_permissions) |
| 3612 | 6366 | acydburn | {
|
| 3613 | 6956 | acydburn | if (!function_exists('update_foes')) |
| 3614 | 6956 | acydburn | {
|
| 3615 | 6956 | acydburn | global $phpbb_root_path, $phpEx; |
| 3616 | 6956 | acydburn | include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); |
| 3617 | 6956 | acydburn | } |
| 3618 | 7115 | acydburn | update_foes(array($group_id)); |
| 3619 | 6366 | acydburn | } |
| 3620 | 6366 | acydburn | } |
| 3621 | 6366 | acydburn | |
| 3622 | 9646 | Kellanved | |
| 3623 | 9646 | Kellanved | |
| 3624 | 9646 | Kellanved | /**
|
| 3625 | 9646 | Kellanved | * Funtion to make a user leave the NEWLY_REGISTERED system group. |
| 3626 | 9646 | Kellanved | * @access public |
| 3627 | 9646 | Kellanved | * @param $user_id The id of the user to remove from the group |
| 3628 | 9646 | Kellanved | */ |
| 3629 | 9646 | Kellanved | function remove_newly_registered($user_id, $user_data = false) |
| 3630 | 9646 | Kellanved | {
|
| 3631 | 9646 | Kellanved | global $db; |
| 3632 | 9646 | Kellanved | |
| 3633 | 9646 | Kellanved | if ($user_data === false) |
| 3634 | 9646 | Kellanved | {
|
| 3635 | 9646 | Kellanved | $sql = 'SELECT * |
| 3636 | 9646 | Kellanved | FROM ' . USERS_TABLE . ' |
| 3637 | 9646 | Kellanved | WHERE user_id = ' . $user_id; |
| 3638 | 9646 | Kellanved | $result = $db->sql_query($sql); |
| 3639 | 9646 | Kellanved | $user_row = $db->sql_fetchrow($result); |
| 3640 | 9646 | Kellanved | $db->sql_freeresult($result); |
| 3641 | 9646 | Kellanved | |
| 3642 | 9646 | Kellanved | if (!$user_row) |
| 3643 | 9646 | Kellanved | {
|
| 3644 | 9646 | Kellanved | return false; |
| 3645 | 9646 | Kellanved | } |
| 3646 | 9646 | Kellanved | else
|
| 3647 | 9646 | Kellanved | {
|
| 3648 | 9646 | Kellanved | $user_data = $user_row; |
| 3649 | 9646 | Kellanved | } |
| 3650 | 9646 | Kellanved | } |
| 3651 | 10003 | acydburn | |
| 3652 | 9646 | Kellanved | if (empty($user_data['user_new'])) |
| 3653 | 9646 | Kellanved | {
|
| 3654 | 9646 | Kellanved | return false; |
| 3655 | 9646 | Kellanved | } |
| 3656 | 10003 | acydburn | |
| 3657 | 9646 | Kellanved | $sql = 'SELECT group_id |
| 3658 | 9646 | Kellanved | FROM ' . GROUPS_TABLE . " |
| 3659 | 9646 | Kellanved | WHERE group_name = 'NEWLY_REGISTERED' |
| 3660 | 9646 | Kellanved | AND group_type = " . GROUP_SPECIAL; |
| 3661 | 9646 | Kellanved | $result = $db->sql_query($sql); |
| 3662 | 9646 | Kellanved | $group_id = (int) $db->sql_fetchfield('group_id'); |
| 3663 | 9646 | Kellanved | $db->sql_freeresult($result); |
| 3664 | 9646 | Kellanved | |
| 3665 | 9646 | Kellanved | if (!$group_id) |
| 3666 | 9646 | Kellanved | {
|
| 3667 | 9646 | Kellanved | return false; |
| 3668 | 9646 | Kellanved | } |
| 3669 | 9646 | Kellanved | |
| 3670 | 9646 | Kellanved | // We need to call group_user_del here, because this function makes sure everything is correctly changed.
|
| 3671 | 9646 | Kellanved | // A downside for a call within the session handler is that the language is not set up yet - so no log entry
|
| 3672 | 9646 | Kellanved | group_user_del($group_id, $user_id); |
| 3673 | 9646 | Kellanved | |
| 3674 | 9646 | Kellanved | // Set user_new to 0 to let this not be triggered again
|
| 3675 | 9646 | Kellanved | $sql = 'UPDATE ' . USERS_TABLE . ' |
| 3676 | 9646 | Kellanved | SET user_new = 0 |
| 3677 | 9646 | Kellanved | WHERE user_id = ' . $user_id; |
| 3678 | 9646 | Kellanved | $db->sql_query($sql); |
| 3679 | 9646 | Kellanved | |
| 3680 | 9646 | Kellanved | // The new users group was the users default group?
|
| 3681 | 9646 | Kellanved | if ($user_data['group_id'] == $group_id) |
| 3682 | 9646 | Kellanved | {
|
| 3683 | 9646 | Kellanved | // Which group is now the users default one?
|
| 3684 | 9646 | Kellanved | $sql = 'SELECT group_id |
| 3685 | 9646 | Kellanved | FROM ' . USERS_TABLE . ' |
| 3686 | 9646 | Kellanved | WHERE user_id = ' . $user_id; |
| 3687 | 9646 | Kellanved | $result = $db->sql_query($sql); |
| 3688 | 9646 | Kellanved | $user_data['group_id'] = $db->sql_fetchfield('group_id'); |
| 3689 | 9646 | Kellanved | $db->sql_freeresult($result); |
| 3690 | 9646 | Kellanved | } |
| 3691 | 9646 | Kellanved | |
| 3692 | 9646 | Kellanved | return $user_data['group_id']; |
| 3693 | 9646 | Kellanved | } |

