/** * Open file for logging * * @param string $file File to open */ protected function file_open($file) { if (phpbb_is_writable(dirname($file))) { $this->file_handle = fopen($file, 'w'); } else { throw new \RuntimeException('Unable to write to migrator log file'); } }
function login_func($xmlrpc_params) { global $auth, $user, $config, $db, $phpbb_root_path, $phpEx; $params = php_xmlrpc_decode($xmlrpc_params); $user->setup('ucp'); $username = $params[0]; $password = $params[1]; $viewonline = isset($params[2]) ? !$params[2] : 1; set_var($username, $username, 'string', true); set_var($password, $password, 'string', true); header('Set-Cookie: mobiquo_a=0'); header('Set-Cookie: mobiquo_b=0'); header('Set-Cookie: mobiquo_c=0'); $login_result = $auth->login($username, $password, true, $viewonline); $usergroup_id = array(); if ($login_result['status'] == LOGIN_SUCCESS) { $auth->acl($user->data); //add tapatalk_users here,for push service if ($params[3] == '1' && push_table_exists()) { global $table_prefix; $sql = "SELECT * FROM " . $table_prefix . "tapatalk_users where userid = '" . $user->data['user_id'] . "'"; $result = $db->sql_query($sql); $userInfo = $db->sql_fetchrow($result); $db->sql_freeresult($result); $time = time(); if (empty($userInfo)) { $sql_data[$table_prefix . "tapatalk_users"]['sql'] = array('userid' => $user->data['user_id'], 'announcement' => 1, 'pm' => 1, 'subscribe' => 1, 'quote' => 1, 'tag' => 1, 'newtopic' => 1, 'updated' => time()); $sql = 'INSERT INTO ' . $table_prefix . "tapatalk_users" . ' ' . $db->sql_build_array('INSERT', $sql_data[$table_prefix . "tapatalk_users"]['sql']); $db->sql_query($sql); } else { $sql = "UPDATE " . $table_prefix . "tapatalk_users \n\t \tSET updated= '" . time() . "' WHERE userid='" . $user->data['user_id'] . "'"; $db->sql_query($sql); } } // Compatibility with mod NV who was here if (file_exists($phpbb_root_path . 'includes/mods/who_was_here.' . $phpEx)) { include_once $phpbb_root_path . 'includes/mods/who_was_here.' . $phpEx; if (class_exists('phpbb_mods_who_was_here') && method_exists('phpbb_mods_who_was_here', 'update_session')) { @phpbb_mods_who_was_here::update_session(); } } } else { $error_msg = str_replace('%s', '', strip_tags($user->lang[$login_result['error_msg']])); return new xmlrpcresp(new xmlrpcval(array('result' => new xmlrpcval(false, 'boolean'), 'result_text' => new xmlrpcval($error_msg, 'base64')), 'struct')); } if ($config['max_attachments'] == 0) { $config['max_attachments'] = 100; } $usergroup_id[] = new xmlrpcval($user->data['group_id']); $can_readpm = $config['allow_privmsg'] && $auth->acl_get('u_readpm') && ($user->data['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')); $can_sendpm = $config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($user->data['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')); $can_upload = $config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && (function_exists('phpbb_is_writable') ? phpbb_is_writable($phpbb_root_path . $config['avatar_path']) : 1) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false; $can_search = $auth->acl_get('u_search') && $auth->acl_getf_global('f_search') && $config['load_search']; $can_whosonline = $auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'); $max_filesize = $config['max_filesize'] === '0' || $config['max_filesize'] > 10485760 ? 10485760 : $config['max_filesize']; $response = new xmlrpcval(array('result' => new xmlrpcval(true, 'boolean'), 'user_id' => new xmlrpcval($user->data['user_id'], 'string'), 'username' => new xmlrpcval($user->data['username'], 'base64'), 'usergroup_id' => new xmlrpcval($usergroup_id, 'array'), 'icon_url' => new xmlrpcval(get_user_avatar_url($user->data['user_avatar'], $user->data['user_avatar_type']), 'string'), 'post_count' => new xmlrpcval($user->data['user_posts'], 'int'), 'can_pm' => new xmlrpcval($can_readpm, 'boolean'), 'can_send_pm' => new xmlrpcval($can_sendpm, 'boolean'), 'can_moderate' => new xmlrpcval($auth->acl_get('m_') || $auth->acl_getf_global('m_'), 'boolean'), 'max_attachment' => new xmlrpcval($config['max_attachments'], 'int'), 'max_png_size' => new xmlrpcval($max_filesize, 'int'), 'max_jpg_size' => new xmlrpcval($max_filesize, 'int'), 'can_search' => new xmlrpcval($can_search, 'boolean'), 'can_whosonline' => new xmlrpcval($can_whosonline, 'boolean'), 'can_upload_avatar' => new xmlrpcval($can_upload, 'boolean')), 'struct'); return new xmlrpcresp($response); }
/** * {@inheritDoc} */ function save() { if (!$this->is_modified) { return; } global $phpEx; if (!$this->_write('data_global')) { if (!function_exists('phpbb_is_writable')) { global $phpbb_root_path; include $phpbb_root_path . 'includes/functions.' . $phpEx; } // Now, this occurred how often? ... phew, just tell the user then... if (!phpbb_is_writable($this->cache_dir)) { // We need to use die() here, because else we may encounter an infinite loop (the message handler calls $cache->unload()) die('Fatal: ' . $this->cache_dir . ' is NOT writable.'); exit; } die('Fatal: Not able to open ' . $this->cache_dir . 'data_global.' . $phpEx); exit; } $this->is_modified = false; }
/** * Check if user is able to upload an avatar * * @return bool True if user can upload, false if not */ protected function can_upload() { return file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on'); }
/** * Uploading/Changing user avatar */ function avatar_process_user(&$error, $custom_userdata = false, $can_upload = null) { global $config, $phpbb_root_path, $auth, $user, $db; $data = array('uploadurl' => request_var('uploadurl', ''), 'remotelink' => request_var('remotelink', ''), 'width' => request_var('width', 0), 'height' => request_var('height', 0)); $error = validate_data($data, array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3))); if (sizeof($error)) { return false; } $sql_ary = array(); if ($custom_userdata === false) { $userdata =& $user->data; } else { $userdata =& $custom_userdata; } $data['user_id'] = $userdata['user_id']; $change_avatar = $custom_userdata === false ? $auth->acl_get('u_chgavatar') : true; $avatar_select = basename(request_var('avatar_select', '')); // Can we upload? if (is_null($can_upload)) { $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; } if ((!empty($_FILES['uploadfile']['name']) || $data['uploadurl']) && $can_upload) { list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = avatar_upload($data, $error); } else { if ($data['remotelink'] && $change_avatar && $config['allow_avatar_remote']) { list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = avatar_remote($data, $error); } else { if ($avatar_select && $change_avatar && $config['allow_avatar_local']) { $category = basename(request_var('category', '')); $sql_ary['user_avatar_type'] = AVATAR_GALLERY; $sql_ary['user_avatar'] = $avatar_select; // check avatar gallery if (!is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) { $sql_ary['user_avatar'] = ''; $sql_ary['user_avatar_type'] = $sql_ary['user_avatar_width'] = $sql_ary['user_avatar_height'] = 0; } else { 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'])); $sql_ary['user_avatar'] = $category . '/' . $sql_ary['user_avatar']; } } else { if (isset($_POST['delete']) && $change_avatar) { $sql_ary['user_avatar'] = ''; $sql_ary['user_avatar_type'] = $sql_ary['user_avatar_width'] = $sql_ary['user_avatar_height'] = 0; } else { if (!empty($userdata['user_avatar'])) { // Only update the dimensions if (empty($data['width']) || empty($data['height'])) { if ($dims = avatar_get_dimensions($userdata['user_avatar'], $userdata['user_avatar_type'], $error, $data['width'], $data['height'])) { list($guessed_x, $guessed_y) = $dims; if (empty($data['width'])) { $data['width'] = $guessed_x; } if (empty($data['height'])) { $data['height'] = $guessed_y; } } } if (($config['avatar_max_width'] || $config['avatar_max_height']) && ($data['width'] != $userdata['user_avatar_width'] || $data['height'] != $userdata['user_avatar_height'])) { if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) { $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']); } } if (!sizeof($error)) { if ($config['avatar_min_width'] || $config['avatar_min_height']) { if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) { $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']); } } } if (!sizeof($error)) { $sql_ary['user_avatar_width'] = $data['width']; $sql_ary['user_avatar_height'] = $data['height']; } } } } } } if (!sizeof($error)) { // Do we actually have any data to update? if (sizeof($sql_ary)) { $ext_new = $ext_old = ''; if (isset($sql_ary['user_avatar'])) { $userdata = $custom_userdata === false ? $user->data : $custom_userdata; $ext_new = empty($sql_ary['user_avatar']) ? '' : substr(strrchr($sql_ary['user_avatar'], '.'), 1); $ext_old = empty($userdata['user_avatar']) ? '' : substr(strrchr($userdata['user_avatar'], '.'), 1); if ($userdata['user_avatar_type'] == AVATAR_UPLOAD) { // Delete old avatar if present if (!empty($userdata['user_avatar']) && empty($sql_ary['user_avatar']) || !empty($userdata['user_avatar']) && !empty($sql_ary['user_avatar']) && $ext_new !== $ext_old) { avatar_delete('user', $userdata); } } } $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . ($custom_userdata === false ? $user->data['user_id'] : $custom_userdata['user_id']); $db->sql_query($sql); } } return sizeof($error) ? false : true; }
/** * Primary work on banner, can edit, copy or check a banner * * @param string $banner The banner's remote url * @param array $error The array error, passed by reference * @return null */ public function banner_process(&$banner, &$error) { $old_banner = $this->request->variable('old_banner', ''); $destination = $this->dir_helper->get_banner_path(); // Can we upload? $can_upload = $this->config['dir_storage_banner'] && file_exists($this->root_path . $destination) && phpbb_is_writable($this->root_path . $destination) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false; if ($banner && $can_upload) { $file = $this->_banner_upload($banner, $error); } else { if ($banner) { $file = $this->_banner_remote($banner, $error); } else { if ($this->request->is_set_post('delete_banner') && $old_banner) { $this->_banner_delete($old_banner); return; } } } if (!sizeof($error)) { if ($banner && $old_banner && !preg_match('/^(http:\\/\\/|https:\\/\\/|ftp:\\/\\/|ftps:\\/\\/|www\\.).+/si', $old_banner)) { $this->_banner_delete($old_banner); } $banner = !empty($file) ? $file : ''; } }
function main($id, $mode) { global $config, $phpbb_root_path, $phpEx; global $db, $user, $auth, $cache, $template; $user->add_lang('groups'); $return_page = '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '">', '</a>'); $mark_ary = request_var('mark', array(0)); $submit = !empty($_POST['submit']) ? true : false; $delete = !empty($_POST['delete']) ? true : false; $error = $data = array(); switch ($mode) { case 'membership': $this->page_title = 'UCP_USERGROUPS_MEMBER'; if ($submit || isset($_POST['change_default'])) { $action = isset($_POST['change_default']) ? 'change_default' : request_var('action', ''); $group_id = $action == 'change_default' ? request_var('default', 0) : request_var('selected', 0); if (!$group_id) { trigger_error('NO_GROUP_SELECTED'); } $sql = 'SELECT group_id, group_name, group_type FROM ' . GROUPS_TABLE . "\n\t\t\t\t\t\tWHERE group_id IN ({$group_id}, {$user->data['group_id']})"; $result = $db->sql_query($sql); $group_row = array(); while ($row = $db->sql_fetchrow($result)) { $row['group_name'] = $row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name']; $group_row[$row['group_id']] = $row; } $db->sql_freeresult($result); if (!sizeof($group_row)) { trigger_error('GROUP_NOT_EXIST'); } switch ($action) { case 'change_default': // User already having this group set as default? if ($group_id == $user->data['group_id']) { trigger_error($user->lang['ALREADY_DEFAULT_GROUP'] . $return_page); } if (!$auth->acl_get('u_chggrp')) { trigger_error($user->lang['NOT_AUTHORISED'] . $return_page); } // User needs to be member of the group in order to make it default if (!group_memberships($group_id, $user->data['user_id'], true)) { trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page); } if (confirm_box(true)) { group_user_attributes('default', $group_id, $user->data['user_id']); add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_CHANGE', sprintf($user->lang['USER_GROUP_CHANGE'], $group_row[$user->data['group_id']]['group_name'], $group_row[$group_id]['group_name'])); meta_refresh(3, $this->u_action); trigger_error($user->lang['CHANGED_DEFAULT_GROUP'] . $return_page); } else { $s_hidden_fields = array('default' => $group_id, 'change_default' => true); confirm_box(false, sprintf($user->lang['GROUP_CHANGE_DEFAULT'], $group_row[$group_id]['group_name']), build_hidden_fields($s_hidden_fields)); } break; case 'resign': // User tries to resign from default group but is not allowed to change it? if ($group_id == $user->data['group_id'] && !$auth->acl_get('u_chggrp')) { trigger_error($user->lang['NOT_RESIGN_FROM_DEFAULT_GROUP'] . $return_page); } if (!($row = group_memberships($group_id, $user->data['user_id']))) { trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page); } list(, $row) = each($row); $sql = 'SELECT group_type FROM ' . GROUPS_TABLE . ' WHERE group_id = ' . $group_id; $result = $db->sql_query($sql); $group_type = (int) $db->sql_fetchfield('group_type'); $db->sql_freeresult($result); if ($group_type != GROUP_OPEN && $group_type != GROUP_FREE) { trigger_error($user->lang['CANNOT_RESIGN_GROUP'] . $return_page); } if (confirm_box(true)) { group_user_del($group_id, $user->data['user_id']); add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_RESIGN', $group_row[$group_id]['group_name']); meta_refresh(3, $this->u_action); trigger_error($user->lang[$row['user_pending'] ? 'GROUP_RESIGNED_PENDING' : 'GROUP_RESIGNED_MEMBERSHIP'] . $return_page); } else { $s_hidden_fields = array('selected' => $group_id, 'action' => 'resign', 'submit' => true); confirm_box(false, $row['user_pending'] ? 'GROUP_RESIGN_PENDING' : 'GROUP_RESIGN_MEMBERSHIP', build_hidden_fields($s_hidden_fields)); } break; case 'join': $sql = 'SELECT ug.*, u.username, u.username_clean, u.user_email FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u WHERE ug.user_id = u.user_id AND ug.group_id = ' . $group_id . ' AND ug.user_id = ' . $user->data['user_id']; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row) { if ($row['user_pending']) { trigger_error($user->lang['ALREADY_IN_GROUP_PENDING'] . $return_page); } trigger_error($user->lang['ALREADY_IN_GROUP'] . $return_page); } // Check permission to join (open group or request) if ($group_row[$group_id]['group_type'] != GROUP_OPEN && $group_row[$group_id]['group_type'] != GROUP_FREE) { trigger_error($user->lang['CANNOT_JOIN_GROUP'] . $return_page); } if (confirm_box(true)) { if ($group_row[$group_id]['group_type'] == GROUP_FREE) { group_user_add($group_id, $user->data['user_id']); } else { group_user_add($group_id, $user->data['user_id'], false, false, false, 0, 1); include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx; $messenger = new messenger(); $sql = 'SELECT u.username, u.username_clean, u.user_email, u.user_notify_type, u.user_jabber, u.user_lang FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . " u\n\t\t\t\t\t\t\t\t\t\tWHERE ug.user_id = u.user_id\n\t\t\t\t\t\t\t\t\t\t\tAND ug.group_leader = 1\n\t\t\t\t\t\t\t\t\t\t\tAND ug.group_id = {$group_id}"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $messenger->template('group_request', $row['user_lang']); $messenger->to($row['user_email'], $row['username']); $messenger->im($row['user_jabber'], $row['username']); $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($row['username']), 'GROUP_NAME' => htmlspecialchars_decode($group_row[$group_id]['group_name']), 'REQUEST_USERNAME' => $user->data['username'], 'U_PENDING' => generate_board_url() . "/ucp.{$phpEx}?i=groups&mode=manage&action=list&g={$group_id}", 'U_GROUP' => generate_board_url() . "/memberlist.{$phpEx}?mode=group&g={$group_id}")); $messenger->send($row['user_notify_type']); } $db->sql_freeresult($result); $messenger->save_queue(); } add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_JOIN' . ($group_row[$group_id]['group_type'] == GROUP_FREE ? '' : '_PENDING'), $group_row[$group_id]['group_name']); meta_refresh(3, $this->u_action); trigger_error($user->lang[$group_row[$group_id]['group_type'] == GROUP_FREE ? 'GROUP_JOINED' : 'GROUP_JOINED_PENDING'] . $return_page); } else { $s_hidden_fields = array('selected' => $group_id, 'action' => 'join', 'submit' => true); confirm_box(false, $group_row[$group_id]['group_type'] == GROUP_FREE ? 'GROUP_JOIN' : 'GROUP_JOIN_PENDING', build_hidden_fields($s_hidden_fields)); } break; case 'demote': if (!($row = group_memberships($group_id, $user->data['user_id']))) { trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page); } list(, $row) = each($row); if (!$row['group_leader']) { trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page); } if (confirm_box(true)) { group_user_attributes('demote', $group_id, $user->data['user_id']); add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_DEMOTE', $group_row[$group_id]['group_name']); meta_refresh(3, $this->u_action); trigger_error($user->lang['USER_GROUP_DEMOTED'] . $return_page); } else { $s_hidden_fields = array('selected' => $group_id, 'action' => 'demote', 'submit' => true); confirm_box(false, 'USER_GROUP_DEMOTE', build_hidden_fields($s_hidden_fields)); } break; } } $sql = 'SELECT g.*, ug.group_leader, ug.user_pending FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug WHERE ug.user_id = ' . $user->data['user_id'] . ' AND g.group_id = ug.group_id ORDER BY g.group_type DESC, g.group_name'; $result = $db->sql_query($sql); $group_id_ary = array(); $leader_count = $member_count = $pending_count = 0; while ($row = $db->sql_fetchrow($result)) { $block = $row['group_leader'] ? 'leader' : ($row['user_pending'] ? 'pending' : 'member'); switch ($row['group_type']) { case GROUP_OPEN: $group_status = 'OPEN'; break; case GROUP_CLOSED: $group_status = 'CLOSED'; break; case GROUP_HIDDEN: $group_status = 'HIDDEN'; break; case GROUP_SPECIAL: $group_status = 'SPECIAL'; break; case GROUP_FREE: $group_status = 'FREE'; break; } $template->assign_block_vars($block, array('GROUP_ID' => $row['group_id'], 'GROUP_NAME' => $row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name'], 'GROUP_DESC' => $row['group_type'] != GROUP_SPECIAL ? generate_text_for_display($row['group_desc'], $row['group_desc_uid'], $row['group_desc_bitfield'], $row['group_desc_options']) : $user->lang['GROUP_IS_SPECIAL'], 'GROUP_SPECIAL' => $row['group_type'] != GROUP_SPECIAL ? false : true, 'GROUP_STATUS' => $user->lang['GROUP_IS_' . $group_status], 'GROUP_COLOUR' => $row['group_colour'], 'U_VIEW_GROUP' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=group&g=' . $row['group_id']), 'S_GROUP_DEFAULT' => $row['group_id'] == $user->data['group_id'] ? true : false, 'S_ROW_COUNT' => ${$block . '_count'}++)); $group_id_ary[] = (int) $row['group_id']; } $db->sql_freeresult($result); // Hide hidden groups unless user is an admin with group privileges $sql_and = $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') ? '<> ' . GROUP_SPECIAL : 'NOT IN (' . GROUP_SPECIAL . ', ' . GROUP_HIDDEN . ')'; $sql = 'SELECT group_id, group_name, group_colour, group_desc, group_desc_uid, group_desc_bitfield, group_desc_options, group_type, group_founder_manage FROM ' . GROUPS_TABLE . ' WHERE ' . (sizeof($group_id_ary) ? $db->sql_in_set('group_id', $group_id_ary, true) . ' AND ' : '') . "\n\t\t\t\t\t\tgroup_type {$sql_and}\n\t\t\t\t\tORDER BY group_type DESC, group_name"; $result = $db->sql_query($sql); $nonmember_count = 0; while ($row = $db->sql_fetchrow($result)) { switch ($row['group_type']) { case GROUP_OPEN: $group_status = 'OPEN'; break; case GROUP_CLOSED: $group_status = 'CLOSED'; break; case GROUP_HIDDEN: $group_status = 'HIDDEN'; break; case GROUP_SPECIAL: $group_status = 'SPECIAL'; break; case GROUP_FREE: $group_status = 'FREE'; break; } $template->assign_block_vars('nonmember', array('GROUP_ID' => $row['group_id'], 'GROUP_NAME' => $row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name'], 'GROUP_DESC' => $row['group_type'] != GROUP_SPECIAL ? generate_text_for_display($row['group_desc'], $row['group_desc_uid'], $row['group_desc_bitfield'], $row['group_desc_options']) : $user->lang['GROUP_IS_SPECIAL'], 'GROUP_SPECIAL' => $row['group_type'] != GROUP_SPECIAL ? false : true, 'GROUP_CLOSED' => $row['group_type'] != GROUP_CLOSED || $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') ? false : true, 'GROUP_STATUS' => $user->lang['GROUP_IS_' . $group_status], 'S_CAN_JOIN' => $row['group_type'] == GROUP_OPEN || $row['group_type'] == GROUP_FREE ? true : false, 'GROUP_COLOUR' => $row['group_colour'], 'U_VIEW_GROUP' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=group&g=' . $row['group_id']), 'S_ROW_COUNT' => $nonmember_count++)); } $db->sql_freeresult($result); $template->assign_vars(array('S_CHANGE_DEFAULT' => $auth->acl_get('u_chggrp') ? true : false, 'S_LEADER_COUNT' => $leader_count, 'S_MEMBER_COUNT' => $member_count, 'S_PENDING_COUNT' => $pending_count, 'S_NONMEMBER_COUNT' => $nonmember_count, 'S_UCP_ACTION' => $this->u_action)); break; case 'manage': $this->page_title = 'UCP_USERGROUPS_MANAGE'; $action = isset($_POST['addusers']) ? 'addusers' : request_var('action', ''); $group_id = request_var('g', 0); include $phpbb_root_path . 'includes/functions_display.' . $phpEx; add_form_key('ucp_groups'); if ($group_id) { $sql = 'SELECT * FROM ' . GROUPS_TABLE . "\n\t\t\t\t\t\tWHERE group_id = {$group_id}"; $result = $db->sql_query($sql); $group_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$group_row) { trigger_error($user->lang['NO_GROUP'] . $return_page); } // Check if the user is allowed to manage this group if set to founder only. if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage']) { trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . $return_page, E_USER_WARNING); } $group_name = $group_row['group_name']; $group_type = $group_row['group_type']; $avatar_img = !empty($group_row['group_avatar']) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : '<img src="' . $phpbb_root_path . 'adm/images/no_avatar.gif" alt="" />'; $template->assign_vars(array('GROUP_NAME' => $group_type == GROUP_SPECIAL ? $user->lang['G_' . $group_name] : $group_name, 'GROUP_INTERNAL_NAME' => $group_name, 'GROUP_COLOUR' => isset($group_row['group_colour']) ? $group_row['group_colour'] : '', 'GROUP_DESC_DISP' => generate_text_for_display($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_bitfield'], $group_row['group_desc_options']), 'GROUP_TYPE' => $group_row['group_type'], 'AVATAR' => $avatar_img, 'AVATAR_IMAGE' => $avatar_img, 'AVATAR_WIDTH' => isset($group_row['group_avatar_width']) ? $group_row['group_avatar_width'] : '', 'AVATAR_HEIGHT' => isset($group_row['group_avatar_height']) ? $group_row['group_avatar_height'] : '')); } switch ($action) { case 'edit': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . $return_page); } if (!($row = group_memberships($group_id, $user->data['user_id']))) { trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page); } list(, $row) = each($row); if (!$row['group_leader']) { trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page); } $file_uploads = @ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on' ? true : false; $user->add_lang(array('acp/groups', 'acp/common')); $data = $submit_ary = array(); $update = isset($_POST['update']) ? true : false; $error = array(); $avatar_select = basename(request_var('avatar_select', '')); $category = basename(request_var('category', '')); $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false; // Did we submit? if ($update) { $group_name = utf8_normalize_nfc(request_var('group_name', '', true)); $group_desc = utf8_normalize_nfc(request_var('group_desc', '', true)); $group_type = request_var('group_type', GROUP_FREE); $allow_desc_bbcode = request_var('desc_parse_bbcode', false); $allow_desc_urls = request_var('desc_parse_urls', false); $allow_desc_smilies = request_var('desc_parse_smilies', false); $submit_ary = array('colour' => request_var('group_colour', ''), 'rank' => request_var('group_rank', 0), 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0, 'message_limit' => request_var('group_message_limit', 0), 'max_recipients' => request_var('group_max_recipients', 0)); $data['uploadurl'] = request_var('uploadurl', ''); $data['remotelink'] = request_var('remotelink', ''); $data['width'] = request_var('width', ''); $data['height'] = request_var('height', ''); $delete = request_var('delete', ''); if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink']) { // Avatar stuff $var_ary = array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3)); if (!($error = validate_data($data, $var_ary))) { $data['user_id'] = "g{$group_id}"; if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload) { list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error); } else { if ($data['remotelink']) { list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error); } } } } else { if ($avatar_select && $config['allow_avatar_local']) { // check avatar gallery if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) { $submit_ary['avatar_type'] = AVATAR_GALLERY; list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select); $submit_ary['avatar'] = $category . '/' . $avatar_select; } } else { if ($delete) { $submit_ary['avatar'] = ''; $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0; } else { if ($data['width'] && $data['height']) { // Only update the dimensions? if ($config['avatar_max_width'] || $config['avatar_max_height']) { if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) { $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']); } } if (!sizeof($error)) { if ($config['avatar_min_width'] || $config['avatar_min_height']) { if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) { $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']); } } } if (!sizeof($error)) { $submit_ary['avatar_width'] = $data['width']; $submit_ary['avatar_height'] = $data['height']; } } } } } if (isset($submit_ary['avatar']) && $submit_ary['avatar'] && !isset($group_row['group_avatar']) || $delete) { if (isset($group_row['group_avatar']) && $group_row['group_avatar']) { avatar_delete('group', $group_row, true); } } if (!check_form_key('ucp_groups')) { $error[] = $user->lang['FORM_INVALID']; } // Validate submitted colour value if ($colour_error = validate_data($submit_ary, array('colour' => array('hex_colour', true)))) { // Replace "error" string with its real, localised form $error = array_merge($error, $colour_error); } if (!sizeof($error)) { // Only set the rank, colour, etc. if it's changed or if we're adding a new // group. This prevents existing group members being updated if no changes // were made. $group_attributes = array(); $test_variables = array('rank' => 'int', 'colour' => 'string', 'avatar' => 'string', 'avatar_type' => 'int', 'avatar_width' => 'int', 'avatar_height' => 'int', 'receive_pm' => 'int', 'legend' => 'int', 'message_limit' => 'int', 'max_recipients' => 'int'); foreach ($test_variables as $test => $type) { if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test])) { settype($submit_ary[$test], $type); $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test]; } } if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies))) { $cache->destroy('sql', GROUPS_TABLE); $message = $action == 'edit' ? 'GROUP_UPDATED' : 'GROUP_CREATED'; trigger_error($user->lang[$message] . $return_page); } } if (sizeof($error)) { $error = array_map(array(&$user, 'lang'), $error); $group_rank = $submit_ary['rank']; $group_desc_data = array('text' => $group_desc, 'allow_bbcode' => $allow_desc_bbcode, 'allow_smilies' => $allow_desc_smilies, 'allow_urls' => $allow_desc_urls); } } else { if (!$group_id) { $group_name = utf8_normalize_nfc(request_var('group_name', '', true)); $group_desc_data = array('text' => '', 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true); $group_rank = 0; $group_type = GROUP_OPEN; } else { $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']); $group_rank = $group_row['group_rank']; } } $sql = 'SELECT * FROM ' . RANKS_TABLE . ' WHERE rank_special = 1 ORDER BY rank_title'; $result = $db->sql_query($sql); $rank_options = '<option value="0"' . (!$group_rank ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>'; while ($row = $db->sql_fetchrow($result)) { $selected = $group_rank && $row['rank_id'] == $group_rank ? ' selected="selected"' : ''; $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>'; } $db->sql_freeresult($result); $type_free = $group_type == GROUP_FREE ? ' checked="checked"' : ''; $type_open = $group_type == GROUP_OPEN ? ' checked="checked"' : ''; $type_closed = $group_type == GROUP_CLOSED ? ' checked="checked"' : ''; $type_hidden = $group_type == GROUP_HIDDEN ? ' checked="checked"' : ''; $display_gallery = isset($_POST['display_gallery']) ? true : false; if ($config['allow_avatar'] && $config['allow_avatar_local'] && $display_gallery) { avatar_gallery($category, $avatar_select, 4); } $avatars_enabled = $config['allow_avatar'] && ($can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload']) || ($config['allow_avatar_local'] || $config['allow_avatar_remote'])) ? true : false; $template->assign_vars(array('S_EDIT' => true, 'S_INCLUDE_SWATCH' => true, 'S_FORM_ENCTYPE' => $config['allow_avatar'] && $can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload']) ? ' enctype="multipart/form-data"' : '', 'S_ERROR' => sizeof($error) ? true : false, 'S_SPECIAL_GROUP' => $group_type == GROUP_SPECIAL ? true : false, 'S_AVATARS_ENABLED' => $avatars_enabled, 'S_DISPLAY_GALLERY' => $config['allow_avatar'] && $config['allow_avatar_local'] && !$display_gallery ? true : false, 'S_IN_GALLERY' => $config['allow_avatar_local'] && $display_gallery ? true : false, 'S_UPLOAD_AVATAR_FILE' => $config['allow_avatar'] && $config['allow_avatar_upload'] && $can_upload ? true : false, 'S_UPLOAD_AVATAR_URL' => $config['allow_avatar'] && $config['allow_avatar_remote_upload'] && $can_upload ? true : false, 'S_LINK_AVATAR' => $config['allow_avatar'] && $config['allow_avatar_remote'] ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : '', 'GROUP_RECEIVE_PM' => isset($group_row['group_receive_pm']) && $group_row['group_receive_pm'] ? ' checked="checked"' : '', 'GROUP_MESSAGE_LIMIT' => isset($group_row['group_message_limit']) ? $group_row['group_message_limit'] : 0, 'GROUP_MAX_RECIPIENTS' => isset($group_row['group_max_recipients']) ? $group_row['group_max_recipients'] : 0, 'GROUP_DESC' => $group_desc_data['text'], 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'], 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'], 'S_DESC_SMILIES_CHECKED' => $group_desc_data['allow_smilies'], 'S_RANK_OPTIONS' => $rank_options, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'GROUP_TYPE_FREE' => GROUP_FREE, 'GROUP_TYPE_OPEN' => GROUP_OPEN, 'GROUP_TYPE_CLOSED' => GROUP_CLOSED, 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN, 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL, 'GROUP_FREE' => $type_free, 'GROUP_OPEN' => $type_open, 'GROUP_CLOSED' => $type_closed, 'GROUP_HIDDEN' => $type_hidden, 'U_SWATCH' => append_sid("{$phpbb_root_path}adm/swatch.{$phpEx}", 'form=ucp&name=group_colour'), 'S_UCP_ACTION' => $this->u_action . "&action={$action}&g={$group_id}", 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024))); break; case 'list': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . $return_page); } if (!($row = group_memberships($group_id, $user->data['user_id']))) { trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page); } list(, $row) = each($row); if (!$row['group_leader']) { trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page); } $user->add_lang(array('acp/groups', 'acp/common')); $start = request_var('start', 0); // Grab the leaders - always, on every page... $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\t\t\tWHERE ug.group_id = {$group_id}\n\t\t\t\t\t\t\t\tAND u.user_id = ug.user_id\n\t\t\t\t\t\t\t\tAND ug.group_leader = 1\n\t\t\t\t\t\t\tORDER BY ug.user_pending DESC, u.username_clean"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $template->assign_block_vars('leader', array('USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'U_USER_VIEW' => get_username_string('profile', $row['user_id'], $row['username']), 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id'])); } $db->sql_freeresult($result); // Total number of group members (non-leaders) $sql = 'SELECT COUNT(user_id) AS total_members FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\t\t\tAND group_leader = 0"; $result = $db->sql_query($sql); $total_members = (int) $db->sql_fetchfield('total_members'); $db->sql_freeresult($result); // Grab the members $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\t\t\tWHERE ug.group_id = {$group_id}\n\t\t\t\t\t\t\t\tAND u.user_id = ug.user_id\n\t\t\t\t\t\t\t\tAND ug.group_leader = 0\n\t\t\t\t\t\t\tORDER BY ug.user_pending DESC, u.username_clean"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); $pending = false; $approved = false; while ($row = $db->sql_fetchrow($result)) { if ($row['user_pending'] && !$pending) { $template->assign_block_vars('member', array('S_PENDING' => true)); $template->assign_var('S_PENDING_SET', true); $pending = true; } else { if (!$row['user_pending'] && !$approved) { $template->assign_block_vars('member', array('S_APPROVED' => true)); $template->assign_var('S_APPROVED_SET', true); $approved = true; } } $template->assign_block_vars('member', array('USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'U_USER_VIEW' => get_username_string('profile', $row['user_id'], $row['username']), 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id'])); } $db->sql_freeresult($result); $s_action_options = ''; $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'deleteusers' => 'DELETE'); foreach ($options as $option => $lang) { $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>'; } $template->assign_vars(array('S_LIST' => true, 'S_ACTION_OPTIONS' => $s_action_options, 'S_ON_PAGE' => on_page($total_members, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&action={$action}&g={$group_id}", $total_members, $config['topics_per_page'], $start), 'U_ACTION' => $this->u_action . "&g={$group_id}", 'S_UCP_ACTION' => $this->u_action . "&g={$group_id}", 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=ucp&field=usernames'))); break; case 'approve': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . $return_page); } if (!($row = group_memberships($group_id, $user->data['user_id']))) { trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page); } list(, $row) = each($row); if (!$row['group_leader']) { trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page); } $user->add_lang('acp/groups'); // Approve, demote or promote group_user_attributes('approve', $group_id, $mark_ary, false, false); trigger_error($user->lang['USERS_APPROVED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&action=list&g=' . $group_id . '">', '</a>')); break; case 'default': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . $return_page); } if (!($row = group_memberships($group_id, $user->data['user_id']))) { trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page); } list(, $row) = each($row); if (!$row['group_leader']) { trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page); } $group_row['group_name'] = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; if (confirm_box(true)) { if (!sizeof($mark_ary)) { $start = 0; do { $sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\t\t\t\t\tORDER BY user_id"; $result = $db->sql_query_limit($sql, 200, $start); $mark_ary = array(); if ($row = $db->sql_fetchrow($result)) { do { $mark_ary[] = $row['user_id']; } while ($row = $db->sql_fetchrow($result)); group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row); $start = sizeof($mark_ary) < 200 ? 0 : $start + 200; } else { $start = 0; } $db->sql_freeresult($result); } while ($start); } else { group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row); } $user->add_lang('acp/groups'); trigger_error($user->lang['GROUP_DEFS_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&action=list&g=' . $group_id . '">', '</a>')); } else { $user->add_lang('acp/common'); confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action))); } // redirect to last screen redirect($this->u_action . '&action=list&g=' . $group_id); break; case 'deleteusers': $user->add_lang(array('acp/groups', 'acp/common')); if (!($row = group_memberships($group_id, $user->data['user_id']))) { trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page); } list(, $row) = each($row); if (!$row['group_leader']) { trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page); } $group_row['group_name'] = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; if (confirm_box(true)) { if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . $return_page); } $error = group_user_del($group_id, $mark_ary, false, $group_row['group_name']); if ($error) { trigger_error($user->lang[$error] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&action=list&g=' . $group_id . '">', '</a>')); } trigger_error($user->lang['GROUP_USERS_REMOVE'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&action=list&g=' . $group_id . '">', '</a>')); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action))); } // redirect to last screen redirect($this->u_action . '&action=list&g=' . $group_id); break; case 'addusers': $user->add_lang(array('acp/groups', 'acp/common')); $names = utf8_normalize_nfc(request_var('usernames', '', true)); if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . $return_page); } if (!$names) { trigger_error($user->lang['NO_USERS'] . $return_page); } if (!($row = group_memberships($group_id, $user->data['user_id']))) { trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page); } list(, $row) = each($row); if (!$row['group_leader']) { trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page); } $name_ary = array_unique(explode("\n", $names)); $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; $default = request_var('default', 0); if (confirm_box(true)) { // Add user/s to group if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, 0, 0, $group_row)) { trigger_error($user->lang[$error] . $return_page); } trigger_error($user->lang['GROUP_USERS_ADDED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&action=list&g=' . $group_id . '">', '</a>')); } else { $s_hidden_fields = array('default' => $default, 'usernames' => $names, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action); confirm_box(false, sprintf($user->lang['GROUP_CONFIRM_ADD_USER' . (sizeof($name_ary) == 1 ? '' : 'S')], implode(', ', $name_ary)), build_hidden_fields($s_hidden_fields)); } trigger_error($user->lang['NO_USERS_ADDED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&action=list&g=' . $group_id . '">', '</a>')); break; default: $user->add_lang('acp/common'); $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_desc, g.group_desc_uid, g.group_desc_bitfield, g.group_desc_options, g.group_type, ug.group_leader FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug WHERE ug.user_id = ' . $user->data['user_id'] . ' AND g.group_id = ug.group_id AND ug.group_leader = 1 ORDER BY g.group_type DESC, g.group_name'; $result = $db->sql_query($sql); while ($value = $db->sql_fetchrow($result)) { $template->assign_block_vars('leader', array('GROUP_NAME' => $value['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $value['group_name']] : $value['group_name'], 'GROUP_DESC' => generate_text_for_display($value['group_desc'], $value['group_desc_uid'], $value['group_desc_bitfield'], $value['group_desc_options']), 'GROUP_TYPE' => $value['group_type'], 'GROUP_ID' => $value['group_id'], 'GROUP_COLOUR' => $value['group_colour'], 'U_LIST' => $this->u_action . "&action=list&g={$value['group_id']}", 'U_EDIT' => $this->u_action . "&action=edit&g={$value['group_id']}")); } $db->sql_freeresult($result); break; } break; } $this->tpl_name = 'ucp_groups_' . $mode; }
function main($mode, $sub) { global $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language; global $request, $phpbb_admin_path, $phpbb_adm_relative_path, $phpbb_container, $phpbb_config_php_file; // We must enable super globals, otherwise creating a new instance of the request class, // using the new container with a dbal connection will fail with the following PHP Notice: // Object of class phpbb_request_deactivated_super_global could not be converted to int $request->enable_super_globals(); // Create a normal container now $phpbb_container_builder = new \phpbb\di\container_builder($phpbb_config_php_file, $phpbb_root_path, $phpEx); $phpbb_container_builder->set_dump_container(false); $phpbb_container_builder->set_use_extensions(false); if (file_exists($phpbb_root_path . 'install/update/new/config')) { $phpbb_container_builder->set_config_path($phpbb_root_path . 'install/update/new/config'); } $phpbb_container = $phpbb_container_builder->get_container(); // Writes into global $cache $cache = $phpbb_container->get('cache'); $this->tpl_name = 'install_update'; $this->page_title = 'UPDATE_INSTALLATION'; $this->old_location = $phpbb_root_path . 'install/update/old/'; $this->new_location = $phpbb_root_path . 'install/update/new/'; // Init DB extract($phpbb_config_php_file->get_all()); require $phpbb_root_path . 'includes/constants.' . $phpEx; // Special options for conflicts/modified files define('MERGE_NO_MERGE_NEW', 1); define('MERGE_NO_MERGE_MOD', 2); define('MERGE_NEW_FILE', 3); define('MERGE_MOD_FILE', 4); $dbms = $phpbb_config_php_file->convert_30_dbms_to_31($dbms); $db = new $dbms(); // Connect to DB $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false); // We do not need this any longer, unset for safety purposes unset($dbpasswd); // We need to fill the config to let internal functions correctly work $config = new \phpbb\config\db($db, new \phpbb\cache\driver\null(), CONFIG_TABLE); set_config(null, null, null, $config); set_config_count(null, null, null, $config); // Force template recompile $config['load_tplcompile'] = 1; // First of all, init the user session $user->session_begin(); $auth->acl($user->data); // Overwrite user's language with the selected one. // Config needs to be changed to ensure that guests also get the selected language. $config_default_lang = $config['default_lang']; $config['default_lang'] = $language; $user->data['user_lang'] = $language; $user->add_lang(array('common', 'acp/common', 'acp/board', 'install', 'posting')); // Reset the default_lang $config['default_lang'] = $config_default_lang; unset($config_default_lang); // If we are within the intro page we need to make sure we get up-to-date version info if ($sub == 'intro') { $cache->destroy('_version_info'); } // Set custom template again. ;) $paths = array($phpbb_root_path . 'install/update/new/adm/style', $phpbb_admin_path . 'style'); $paths = array_filter($paths, 'is_dir'); $template->set_custom_style(array(array('name' => 'adm', 'ext_path' => 'adm/style/')), $paths); $template->assign_vars(array('S_USER_LANG' => $user->lang['USER_LANG'], 'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'], 'S_CONTENT_ENCODING' => 'UTF-8', 'S_CONTENT_FLOW_BEGIN' => $user->lang['DIRECTION'] == 'ltr' ? 'left' : 'right', 'S_CONTENT_FLOW_END' => $user->lang['DIRECTION'] == 'ltr' ? 'right' : 'left')); // Get current and latest version $version_helper = $phpbb_container->get('version_helper'); try { $this->latest_version = $version_helper->get_latest_on_current_branch(true); } catch (\RuntimeException $e) { $this->latest_version = false; $update_info = array(); include $phpbb_root_path . 'install/update/index.' . $phpEx; $info = empty($update_info) || !is_array($update_info) ? false : $update_info; if ($info !== false) { $this->latest_version = !empty($info['version']['to']) ? trim($info['version']['to']) : false; } } // For the current version we trick a bit. ;) $this->current_version = !empty($config['version_update_from']) ? $config['version_update_from'] : $config['version']; $up_to_date = version_compare(str_replace('rc', 'RC', strtolower($this->current_version)), str_replace('rc', 'RC', strtolower($this->latest_version)), '<') ? false : true; // Check for a valid update directory, else point the user to the phpbb.com website if (!file_exists($phpbb_root_path . 'install/update') || !file_exists($phpbb_root_path . 'install/update/index.' . $phpEx) || !file_exists($this->old_location) || !file_exists($this->new_location)) { $template->assign_vars(array('S_ERROR' => true, 'ERROR_MSG' => $up_to_date ? $user->lang['NO_UPDATE_FILES_UP_TO_DATE'] : sprintf($user->lang['NO_UPDATE_FILES_OUTDATED'], $config['version'], $this->current_version, $this->latest_version))); return; } $this->update_info = $this->get_file('update_info'); // Make sure the update directory holds the correct information // Since admins are able to run the update/checks more than once we only check if the current version is lower or equal than the version to which we update to. if (version_compare(str_replace('rc', 'RC', strtolower($this->current_version)), str_replace('rc', 'RC', strtolower($this->update_info['version']['to'])), '>')) { $template->assign_vars(array('S_ERROR' => true, 'ERROR_MSG' => sprintf($user->lang['INCOMPATIBLE_UPDATE_FILES'], $config['version'], $this->update_info['version']['from'], $this->update_info['version']['to']))); return; } // Check if the update files are actually meant to update from the current version if ($this->current_version != $this->update_info['version']['from']) { $template->assign_vars(array('S_ERROR' => true, 'ERROR_MSG' => sprintf($user->lang['INCOMPATIBLE_UPDATE_FILES'], $this->current_version, $this->update_info['version']['from'], $this->update_info['version']['to']))); } // Check if the update files stored are for the latest version... if (version_compare(strtolower($this->latest_version), strtolower($this->update_info['version']['to']), '>')) { $template->assign_vars(array('S_WARNING' => true, 'WARNING_MSG' => sprintf($user->lang['OLD_UPDATE_FILES'], $this->update_info['version']['from'], $this->update_info['version']['to'], $this->latest_version))); } // We store the "update to" version, because it is not always the latest. ;) $this->update_to_version = $this->update_info['version']['to']; // Fill DB version if (empty($config['dbms_version'])) { set_config('dbms_version', $db->sql_server_info(true)); } if ($this->test_update === false) { // What about the language file? Got it updated? if (in_array('language/' . $language . '/install.' . $phpEx, $this->update_info['files'])) { $lang = array(); include $this->new_location . 'language/' . $language . '/install.' . $phpEx; // this is the user's language.. just merge it $user->lang = array_merge($user->lang, $lang); } if ($language != 'en' && in_array('language/en/install.' . $phpEx, $this->update_info['files'])) { $lang = array(); include $this->new_location . 'language/en/install.' . $phpEx; // only add new keys to user's language in english $new_keys = array_diff(array_keys($lang), array_keys($user->lang)); foreach ($new_keys as $i => $new_key) { $user->lang[$new_key] = $lang[$new_key]; } } } // Include renderer and engine $this->include_file('includes/diff/diff.' . $phpEx); $this->include_file('includes/diff/engine.' . $phpEx); $this->include_file('includes/diff/renderer.' . $phpEx); // Make sure we stay at the file check if checking the files again if ($request->variable('check_again', false, false, \phpbb\request\request_interface::POST)) { $sub = $this->p_master->sub = 'file_check'; } switch ($sub) { case 'intro': $this->page_title = 'UPDATE_INSTALLATION'; $template->assign_vars(array('S_INTRO' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=version_check"))); // Make sure the update list is destroyed. $cache->destroy('_update_list'); $cache->destroy('_diff_files'); $cache->destroy('_expected_files'); break; case 'version_check': $this->page_title = 'STAGE_VERSION_CHECK'; $template->assign_vars(array('S_VERSION_CHECK' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=file_check"), 'S_UP_TO_DATE' => $up_to_date, 'LATEST_VERSION' => $this->latest_version, 'CURRENT_VERSION' => $this->current_version)); // Print out version the update package updates to if ($this->latest_version != $this->update_info['version']['to']) { $template->assign_var('PACKAGE_VERSION', $this->update_info['version']['to']); } // Since some people try to update to RC releases, but phpBB.com tells them the last version is the version they currently run // we are faced with the updater thinking the database schema is up-to-date; which it is, but should be updated none-the-less // We now try to cope with this by triggering the update process if (version_compare(str_replace('rc', 'RC', strtolower($this->current_version)), str_replace('rc', 'RC', strtolower($this->update_info['version']['to'])), '<')) { $template->assign_vars(array('S_UP_TO_DATE' => false)); } break; case 'update_db': // Redirect the user to the database update script with some explanations... $template->assign_vars(array('S_DB_UPDATE' => true, 'S_DB_UPDATE_FINISHED' => $config['version'] == $this->update_info['version']['to'] ? true : false, 'U_DB_UPDATE' => append_sid($phpbb_root_path . 'install/database_update.' . $phpEx, 'type=1&language=' . $user->data['user_lang']), 'U_DB_UPDATE_ACTION' => append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=update_db"), 'U_ACTION' => append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=file_check"), 'L_EVERYTHING_UP_TO_DATE' => $user->lang('EVERYTHING_UP_TO_DATE', append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'mode=login'), append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'mode=login&redirect=' . $phpbb_adm_relative_path . 'index.php%3Fi=send_statistics%26mode=send_statistics')))); // Do not display incompatible package note after successful update if ($config['version'] == $this->update_info['version']['to']) { $template->assign_var('S_ERROR', false); } break; case 'file_check': // retrieve info on what changes should have already been made to the files. $expected_files = $cache->get('_expected_files'); if (!$expected_files) { $expected_files = array(); } // Now make sure the previous file collection is no longer valid... $cache->destroy('_diff_files'); $this->page_title = 'STAGE_FILE_CHECK'; // Now make sure our update list is correct if the admin refreshes $action = request_var('action', ''); // We are directly within an update. To make sure our update list is correct we check its status. $update_list = $request->variable('check_again', false, false, \phpbb\request\request_interface::POST) ? false : $cache->get('_update_list'); $modified = $update_list !== false ? @filemtime($cache->get_driver()->cache_dir . 'data_update_list.' . $phpEx) : 0; // Make sure the list is up-to-date if ($update_list !== false) { $get_new_list = false; foreach ($this->update_info['files'] as $file) { if (file_exists($phpbb_root_path . $file) && filemtime($phpbb_root_path . $file) > $modified) { $get_new_list = true; break; } } } else { $get_new_list = true; } if (!$get_new_list && $update_list['status'] != -1) { $get_new_list = true; } if ($get_new_list) { $this->get_update_structure($update_list, $expected_files); $cache->put('_update_list', $update_list); // Refresh the page if we are still not finished... if ($update_list['status'] != -1) { $refresh_url = append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=file_check"); meta_refresh(2, $refresh_url); $template->assign_vars(array('S_IN_PROGRESS' => true, 'S_COLLECTED' => (int) $update_list['status'], 'S_TO_COLLECT' => sizeof($this->update_info['files']), 'L_IN_PROGRESS' => $user->lang['COLLECTING_FILE_DIFFS'], 'L_IN_PROGRESS_EXPLAIN' => sprintf($user->lang['NUMBER_OF_FILES_COLLECTED'], (int) $update_list['status'], sizeof($this->update_info['files']) + sizeof($this->update_info['deleted'])))); return; } } if ($action == 'diff') { $this->show_diff($update_list); return; } if (sizeof($update_list['no_update'])) { $template->assign_vars(array('S_NO_UPDATE_FILES' => true, 'NO_UPDATE_FILES' => implode(', ', array_map('htmlspecialchars', $update_list['no_update'])))); } $new_expected_files = array(); // Now assign the list to the template foreach ($update_list as $status => $filelist) { if ($status == 'no_update' || !sizeof($filelist) || $status == 'status' || $status == 'status_deleted') { continue; } /* $template->assign_block_vars('files', array( 'S_STATUS' => true, 'STATUS' => $status, 'L_STATUS' => $user->lang['STATUS_' . strtoupper($status)], 'TITLE' => $user->lang['FILES_' . strtoupper($status)], 'EXPLAIN' => $user->lang['FILES_' . strtoupper($status) . '_EXPLAIN'], ) );*/ foreach ($filelist as $file_struct) { $s_binary = !empty($this->update_info['binary']) && in_array($file_struct['filename'], $this->update_info['binary']) ? true : false; $filename = htmlspecialchars($file_struct['filename']); if (strrpos($filename, '/') !== false) { $dir_part = substr($filename, 0, strrpos($filename, '/') + 1); $file_part = substr($filename, strrpos($filename, '/') + 1); } else { $dir_part = ''; $file_part = $filename; } $diff_url = append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=file_check&action=diff&status={$status}&file=" . urlencode($file_struct['filename'])); if (isset($file_struct['as_expected']) && $file_struct['as_expected']) { $new_expected_files[$file_struct['filename']] = $expected_files[$file_struct['filename']]; } else { $template->assign_block_vars($status, array('STATUS' => $status, 'FILENAME' => $filename, 'DIR_PART' => $dir_part, 'FILE_PART' => $file_part, 'NUM_CONFLICTS' => isset($file_struct['conflicts']) ? $file_struct['conflicts'] : 0, 'S_CUSTOM' => $file_struct['custom'] ? true : false, 'S_BINARY' => $s_binary, 'CUSTOM_ORIGINAL' => $file_struct['custom'] ? $file_struct['original'] : '', 'U_SHOW_DIFF' => $diff_url, 'L_SHOW_DIFF' => $status != 'up_to_date' ? $user->lang['SHOW_DIFF_' . strtoupper($status)] : '', 'U_VIEW_MOD_FILE' => $diff_url . '&op=' . MERGE_MOD_FILE, 'U_VIEW_NEW_FILE' => $diff_url . '&op=' . MERGE_NEW_FILE, 'U_VIEW_NO_MERGE_MOD' => $diff_url . '&op=' . MERGE_NO_MERGE_MOD, 'U_VIEW_NO_MERGE_NEW' => $diff_url . '&op=' . MERGE_NO_MERGE_NEW)); } } } $cache->put('_expected_files', $new_expected_files); $all_up_to_date = true; foreach ($update_list as $status => $filelist) { if ($status != 'up_to_date' && $status != 'custom' && $status != 'status' && $status != 'status_deleted' && sizeof($filelist)) { $all_up_to_date = false; break; } } $template->assign_vars(array('S_FILE_CHECK' => true, 'S_ALL_UP_TO_DATE' => $all_up_to_date, 'S_VERSION_UP_TO_DATE' => $up_to_date, 'S_UP_TO_DATE' => $up_to_date, 'U_ACTION' => append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=file_check"), 'U_UPDATE_ACTION' => append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=update_files"), 'U_DB_UPDATE_ACTION' => append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=update_db"))); // Since some people try to update to RC releases, but phpBB.com tells them the last version is the version they currently run // we are faced with the updater thinking the database schema is up-to-date; which it is, but should be updated none-the-less // We now try to cope with this by triggering the update process if (version_compare(str_replace('rc', 'RC', strtolower($this->current_version)), str_replace('rc', 'RC', strtolower($this->update_info['version']['to'])), '<')) { $template->assign_vars(array('S_UP_TO_DATE' => false)); } if ($all_up_to_date) { global $phpbb_container; $phpbb_log = $phpbb_container->get('log'); // Add database update to log $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_UPDATE_PHPBB', time(), array($this->current_version, $this->update_to_version)); $db->sql_return_on_error(true); $db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'version_update_from'"); $db->sql_return_on_error(false); $cache->purge(); } break; case 'update_files': $this->page_title = 'STAGE_UPDATE_FILES'; $s_hidden_fields = ''; $params = array(); $conflicts = request_var('conflict', array('' => 0)); $modified = request_var('modified', array('' => 0)); foreach ($conflicts as $filename => $merge_option) { $s_hidden_fields .= '<input type="hidden" name="conflict[' . htmlspecialchars($filename) . ']" value="' . $merge_option . '" />'; $params[] = 'conflict[' . urlencode($filename) . ']=' . urlencode($merge_option); } foreach ($modified as $filename => $merge_option) { if (!$merge_option) { continue; } $s_hidden_fields .= '<input type="hidden" name="modified[' . htmlspecialchars($filename) . ']" value="' . $merge_option . '" />'; $params[] = 'modified[' . urlencode($filename) . ']=' . urlencode($merge_option); } $no_update = request_var('no_update', array(0 => '')); foreach ($no_update as $index => $filename) { $s_hidden_fields .= '<input type="hidden" name="no_update[]" value="' . htmlspecialchars($filename) . '" />'; $params[] = 'no_update[]=' . urlencode($filename); } // Before the user is choosing his preferred method, let's create the content list... $update_list = $cache->get('_update_list'); if ($update_list === false) { trigger_error($user->lang['NO_UPDATE_INFO'], E_USER_ERROR); } // Check if the conflicts data is valid if (sizeof($conflicts)) { $conflict_filenames = array(); foreach ($update_list['conflict'] as $files) { $conflict_filenames[] = $files['filename']; } $new_conflicts = array(); foreach ($conflicts as $filename => $diff_method) { if (in_array($filename, $conflict_filenames)) { $new_conflicts[$filename] = $diff_method; } } $conflicts = $new_conflicts; } // Build list for modifications if (sizeof($modified)) { $modified_filenames = array(); foreach ($update_list['modified'] as $files) { $modified_filenames[] = $files['filename']; } $new_modified = array(); foreach ($modified as $filename => $diff_method) { if (in_array($filename, $modified_filenames)) { $new_modified[$filename] = $diff_method; } } $modified = $new_modified; } // Check number of conflicting files, they need to be equal. For modified files the number can differ if (sizeof($update_list['conflict']) != sizeof($conflicts)) { trigger_error($user->lang['MERGE_SELECT_ERROR'], E_USER_ERROR); } // Before we do anything, let us diff the files and store the raw file information "somewhere" $get_files = false; $file_list = $cache->get('_diff_files'); $expected_files = $cache->get('_expected_files'); if ($file_list === false || $file_list['status'] != -1) { $get_files = true; } if ($get_files) { if ($file_list === false) { $file_list = array('status' => 0); } if (!isset($expected_files) || $expected_files === false) { $expected_files = array(); } $processed = 0; foreach ($update_list as $status => $files) { if (!is_array($files)) { continue; } foreach ($files as $file_struct) { // Skip this file if the user selected to not update it if (in_array($file_struct['filename'], $no_update)) { $expected_files[$file_struct['filename']] = false; continue; } // Already handled... then skip of course... if (isset($file_list[$file_struct['filename']])) { continue; } // Refresh if we reach 5 diffs... if ($processed >= 5) { $cache->put('_diff_files', $file_list); if ($request->variable('download', false)) { $params[] = 'download=1'; } $redirect_url = append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=update_files&" . implode('&', $params)); meta_refresh(3, $redirect_url); $template->assign_vars(array('S_IN_PROGRESS' => true, 'L_IN_PROGRESS' => $user->lang['MERGING_FILES'], 'L_IN_PROGRESS_EXPLAIN' => $user->lang['MERGING_FILES_EXPLAIN'])); return; } if (file_exists($phpbb_root_path . $file_struct['filename'])) { $contents = file_get_contents($phpbb_root_path . $file_struct['filename']); if (isset($expected_files[$file_struct['filename']]) && md5($contents) == $expected_files[$file_struct['filename']]) { continue; } } $original_filename = $file_struct['custom'] ? $file_struct['original'] : $file_struct['filename']; switch ($status) { case 'modified': $option = isset($modified[$file_struct['filename']]) ? $modified[$file_struct['filename']] : 0; switch ($option) { case MERGE_NO_MERGE_NEW: $contents = file_get_contents($this->new_location . $original_filename); break; case MERGE_NO_MERGE_MOD: $contents = file_get_contents($phpbb_root_path . $file_struct['filename']); break; default: $diff = $this->return_diff($this->old_location . $original_filename, $phpbb_root_path . $file_struct['filename'], $this->new_location . $original_filename); $contents = implode("\n", $diff->merged_output()); unset($diff); break; } $expected_files[$file_struct['filename']] = md5($contents); $file_list[$file_struct['filename']] = '_file_' . md5($file_struct['filename']); $cache->put($file_list[$file_struct['filename']], base64_encode($contents)); $file_list['status']++; $processed++; break; case 'conflict': $option = $conflicts[$file_struct['filename']]; $contents = ''; switch ($option) { case MERGE_NO_MERGE_NEW: $contents = file_get_contents($this->new_location . $original_filename); break; case MERGE_NO_MERGE_MOD: $contents = file_get_contents($phpbb_root_path . $file_struct['filename']); break; default: $diff = $this->return_diff($this->old_location . $original_filename, $phpbb_root_path . $file_struct['filename'], $this->new_location . $original_filename); if ($option == MERGE_NEW_FILE) { $contents = implode("\n", $diff->merged_new_output()); } else { if ($option == MERGE_MOD_FILE) { $contents = implode("\n", $diff->merged_orig_output()); } else { unset($diff); break 2; } } unset($diff); break; } $expected_files[$file_struct['filename']] = md5($contents); $file_list[$file_struct['filename']] = '_file_' . md5($file_struct['filename']); $cache->put($file_list[$file_struct['filename']], base64_encode($contents)); $file_list['status']++; $processed++; break; } } } $cache->put('_expected_files', $expected_files); } $file_list['status'] = -1; $cache->put('_diff_files', $file_list); if ($request->variable('download', false)) { $this->include_file('includes/functions_compress.' . $phpEx); $use_method = request_var('use_method', ''); $methods = array('.tar'); $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib'); foreach ($available_methods as $type => $module) { if (!@extension_loaded($module)) { continue; } $methods[] = $type; } // Let the user decide in which format he wants to have the pack if (!$use_method) { $this->page_title = 'SELECT_DOWNLOAD_FORMAT'; $radio_buttons = ''; foreach ($methods as $method) { $radio_buttons .= '<label><input type="radio"' . (!$radio_buttons ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>'; } $template->assign_vars(array('S_DOWNLOAD_FILES' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=update_files"), 'RADIO_BUTTONS' => $radio_buttons, 'S_HIDDEN_FIELDS' => $s_hidden_fields)); // To ease the update process create a file location map $update_list = $cache->get('_update_list'); $script_path = $config['force_server_vars'] ? $config['script_path'] == '/' ? '/' : $config['script_path'] . '/' : $user->page['root_script_path']; foreach ($update_list as $status => $files) { if ($status == 'up_to_date' || $status == 'no_update' || $status == 'status' || $status == 'status_deleted') { continue; } foreach ($files as $file_struct) { if (in_array($file_struct['filename'], $no_update)) { continue; } $template->assign_block_vars('location', array('SOURCE' => htmlspecialchars($file_struct['filename']), 'DESTINATION' => $script_path . htmlspecialchars($file_struct['filename']))); } } return; } if (!in_array($use_method, $methods)) { $use_method = '.tar'; } $update_mode = 'download'; } else { $this->include_file('includes/functions_transfer.' . $phpEx); // Choose FTP, if not available use fsock... $method = basename(request_var('method', '')); $submit = isset($_POST['submit']) ? true : false; $test_ftp_connection = request_var('test_connection', ''); if (!$method || !class_exists($method)) { $method = 'ftp'; $methods = transfer::methods(); if (!in_array('ftp', $methods)) { $method = $methods[0]; } } $test_connection = false; if ($test_ftp_connection || $submit) { $transfer = new $method(request_var('host', ''), request_var('username', ''), htmlspecialchars_decode($request->untrimmed_variable('password', '')), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); $test_connection = $transfer->open_session(); // Make sure that the directory is correct by checking for the existence of common.php if ($test_connection === true) { // Check for common.php file if (!$transfer->file_exists($phpbb_root_path, 'common.' . $phpEx)) { $test_connection = 'ERR_WRONG_PATH_TO_PHPBB'; } } $transfer->close_session(); // Make sure the login details are correct before continuing if ($submit && $test_connection !== true) { $submit = false; $test_ftp_connection = true; } } $s_hidden_fields .= build_hidden_fields(array('method' => $method)); if (!$submit) { $this->page_title = 'SELECT_FTP_SETTINGS'; if (!class_exists($method)) { trigger_error('Method does not exist.', E_USER_ERROR); } $requested_data = call_user_func(array($method, 'data')); foreach ($requested_data as $data => $default) { $template->assign_block_vars('data', array('DATA' => $data, 'NAME' => $user->lang[strtoupper($method . '_' . $data)], 'EXPLAIN' => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], 'DEFAULT' => $request->variable($data, (string) $default))); } $template->assign_vars(array('S_CONNECTION_SUCCESS' => $test_ftp_connection && $test_connection === true ? true : false, 'S_CONNECTION_FAILED' => $test_ftp_connection && $test_connection !== true ? true : false, 'ERROR_MSG' => $test_ftp_connection && $test_connection !== true ? $user->lang[$test_connection] : '', 'S_FTP_UPLOAD' => true, 'UPLOAD_METHOD' => $method, 'U_ACTION' => append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=update_files"), 'U_DOWNLOAD_METHOD' => append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=update_files&download=1"), 'S_HIDDEN_FIELDS' => $s_hidden_fields)); return; } $update_mode = 'upload'; } // Now update the installation or download the archive... $download_filename = 'update_' . $this->update_info['version']['from'] . '_to_' . $this->update_info['version']['to']; $archive_filename = $download_filename . '_' . time() . '_' . unique_id(); // Now init the connection if ($update_mode == 'download') { if (function_exists('phpbb_is_writable') && !phpbb_is_writable($phpbb_root_path . 'store/')) { trigger_error(sprintf('The directory “%s” is not writable.', $phpbb_root_path . 'store/'), E_USER_ERROR); } if ($use_method == '.zip') { $compress = new compress_zip('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method); } else { $compress = new compress_tar('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method, $use_method); } } else { $transfer = new $method(request_var('host', ''), request_var('username', ''), htmlspecialchars_decode($request->untrimmed_variable('password', '')), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); $transfer->open_session(); } // Ok, go through the update list and do the operations based on their status foreach ($update_list as $status => $files) { if (!is_array($files)) { continue; } foreach ($files as $file_struct) { // Skip this file if the user selected to not update it if (in_array($file_struct['filename'], $no_update)) { continue; } $original_filename = $file_struct['custom'] ? $file_struct['original'] : $file_struct['filename']; switch ($status) { case 'new': case 'new_conflict': case 'not_modified': if ($update_mode == 'download') { $compress->add_custom_file($this->new_location . $original_filename, $file_struct['filename']); } else { if ($status != 'new') { $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); } // New directory too? $dirname = dirname($file_struct['filename']); if ($dirname && !file_exists($phpbb_root_path . $dirname)) { $transfer->make_dir($dirname); } $transfer->copy_file($this->new_location . $original_filename, $file_struct['filename']); } break; case 'modified': $contents = base64_decode($cache->get($file_list[$file_struct['filename']])); if ($update_mode == 'download') { $compress->add_data($contents, $file_struct['filename']); } else { // @todo add option to specify if a backup file should be created? $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); $transfer->write_file($file_struct['filename'], $contents); } break; case 'conflict': $contents = base64_decode($cache->get($file_list[$file_struct['filename']])); if ($update_mode == 'download') { $compress->add_data($contents, $file_struct['filename']); } else { $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); $transfer->write_file($file_struct['filename'], $contents); } break; case 'deleted': if ($update_mode != 'download') { $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); } break; } } } if ($update_mode == 'download') { $compress->close(); $compress->download($archive_filename, $download_filename); @unlink($phpbb_root_path . 'store/' . $archive_filename . $use_method); exit; } else { $transfer->close_session(); $template->assign_vars(array('S_UPLOAD_SUCCESS' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "language={$language}&mode={$mode}&sub=file_check"))); return; } break; } }
function copy_dir($src, $trg, $copy_subdirs = true, $overwrite = false, $die_on_failure = true, $source_relative_path = true) { global $convert, $phpbb_root_path, $config, $user, $db; $dirlist = $filelist = $bad_dirs = array(); $src = path($src, $source_relative_path); $trg = path($trg); $src_path = relative_base($src, $source_relative_path, __LINE__, __FILE__); $trg_path = $phpbb_root_path . $trg; if (!is_dir($trg_path)) { @mkdir($trg_path, 0777); @chmod($trg_path, 0777); } if (!phpbb_is_writable($trg_path)) { $bad_dirs[] = path($config['script_path']) . $trg; } if ($handle = @opendir($src_path)) { while ($entry = readdir($handle)) { if ($entry[0] == '.' || $entry == 'CVS' || $entry == 'index.htm') { continue; } if (is_dir($src_path . $entry)) { $dirlist[] = $entry; } else { $filelist[] = $entry; } } closedir($handle); } else { if ($dir = @dir($src_path)) { while ($entry = $dir->read()) { if ($entry[0] == '.' || $entry == 'CVS' || $entry == 'index.htm') { continue; } if (is_dir($src_path . $entry)) { $dirlist[] = $entry; } else { $filelist[] = $entry; } } $dir->close(); } else { $convert->p_master->error(sprintf($user->lang['CONV_ERROR_COULD_NOT_READ'], relative_base($src, $source_relative_path)), __LINE__, __FILE__); } } if ($copy_subdirs) { for ($i = 0; $i < sizeof($dirlist); ++$i) { $dir = $dirlist[$i]; if ($dir == 'CVS') { continue; } if (!is_dir($trg_path . $dir)) { @mkdir($trg_path . $dir, 0777); @chmod($trg_path . $dir, 0777); } if (!phpbb_is_writable($trg_path . $dir)) { $bad_dirs[] = $trg . $dir; $bad_dirs[] = $trg_path . $dir; } if (!sizeof($bad_dirs)) { copy_dir($src . $dir, $trg . $dir, true, $overwrite, $die_on_failure, $source_relative_path); } } } if (sizeof($bad_dirs)) { $str = sizeof($bad_dirs) == 1 ? $user->lang['MAKE_FOLDER_WRITABLE'] : $user->lang['MAKE_FOLDERS_WRITABLE']; sort($bad_dirs); $convert->p_master->error(sprintf($str, implode('<br />', $bad_dirs)), __LINE__, __FILE__); } for ($i = 0; $i < sizeof($filelist); ++$i) { copy_file($src . $filelist[$i], $trg . $filelist[$i], $overwrite, $die_on_failure, $source_relative_path); } }
/** * Check if the avatar directory is writable and disable avatars * if it isn't writable. */ function disable_avatars_if_unwritable() { global $phpbb_root_path; if (!phpbb_is_writable($phpbb_root_path . 'images/avatars/upload/')) { set_config('allow_avatar', 0); set_config('allow_avatar_upload', 0); } }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; $user->add_lang('posting'); $preview = !empty($_POST['preview']) ? true : false; $submit = !empty($_POST['submit']) ? true : false; $delete = !empty($_POST['delete']) ? true : false; $error = $data = array(); $s_hidden_fields = ''; switch ($mode) { case 'reg_details': $data = array('username' => utf8_normalize_nfc(request_var('username', $user->data['username'], true)), 'email' => strtolower(request_var('email', $user->data['user_email'])), 'email_confirm' => strtolower(request_var('email_confirm', '')), 'new_password' => request_var('new_password', '', true), 'cur_password' => request_var('cur_password', '', true), 'password_confirm' => request_var('password_confirm', '', true)); add_form_key('ucp_reg_details'); if ($submit) { // Do not check cur_password, it is the old one. $check_ary = array('new_password' => array(array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), array('password')), 'password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'email' => array(array('string', false, 6, 60), array('email')), 'email_confirm' => array('string', true, 6, 60)); if ($auth->acl_get('u_chgname') && $config['allow_namechange']) { $check_ary['username'] = array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username')); } $error = validate_data($data, $check_ary); if ($auth->acl_get('u_chgemail') && $data['email'] != $user->data['user_email'] && $data['email_confirm'] != $data['email']) { $error[] = $data['email_confirm'] ? 'NEW_EMAIL_ERROR' : 'NEW_EMAIL_CONFIRM_EMPTY'; } if ($auth->acl_get('u_chgpasswd') && $data['new_password'] && $data['password_confirm'] != $data['new_password']) { $error[] = $data['password_confirm'] ? 'NEW_PASSWORD_ERROR' : 'NEW_PASSWORD_CONFIRM_EMPTY'; } // Only check the new password against the previous password if there have been no errors if (!sizeof($error) && $auth->acl_get('u_chgpasswd') && $data['new_password'] && phpbb_check_hash($data['new_password'], $user->data['user_password'])) { $error[] = 'SAME_PASSWORD_ERROR'; } if (!phpbb_check_hash($data['cur_password'], $user->data['user_password'])) { $error[] = $data['cur_password'] ? 'CUR_PASSWORD_ERROR' : 'CUR_PASSWORD_EMPTY'; } if (!check_form_key('ucp_reg_details')) { $error[] = 'FORM_INVALID'; } if (!sizeof($error)) { $sql_ary = array('username' => $auth->acl_get('u_chgname') && $config['allow_namechange'] ? $data['username'] : $user->data['username'], 'username_clean' => $auth->acl_get('u_chgname') && $config['allow_namechange'] ? utf8_clean_string($data['username']) : $user->data['username_clean'], 'user_email' => $auth->acl_get('u_chgemail') ? $data['email'] : $user->data['user_email'], 'user_email_hash' => $auth->acl_get('u_chgemail') ? phpbb_email_hash($data['email']) : $user->data['user_email_hash'], 'user_password' => $auth->acl_get('u_chgpasswd') && $data['new_password'] ? phpbb_hash($data['new_password']) : $user->data['user_password'], 'user_passchg' => $auth->acl_get('u_chgpasswd') && $data['new_password'] ? time() : 0); if ($auth->acl_get('u_chgname') && $config['allow_namechange'] && $data['username'] != $user->data['username']) { add_log('user', $user->data['user_id'], 'LOG_USER_UPDATE_NAME', $user->data['username'], $data['username']); } if ($auth->acl_get('u_chgpasswd') && $data['new_password'] && !phpbb_check_hash($data['new_password'], $user->data['user_password'])) { $user->reset_login_keys(); add_log('user', $user->data['user_id'], 'LOG_USER_NEW_PASSWORD', $data['username']); } if ($auth->acl_get('u_chgemail') && $data['email'] != $user->data['user_email']) { add_log('user', $user->data['user_id'], 'LOG_USER_UPDATE_EMAIL', $data['username'], $user->data['user_email'], $data['email']); } $message = 'PROFILE_UPDATED'; if ($auth->acl_get('u_chgemail') && $config['email_enable'] && $data['email'] != $user->data['user_email'] && $user->data['user_type'] != USER_FOUNDER && ($config['require_activation'] == USER_ACTIVATION_SELF || $config['require_activation'] == USER_ACTIVATION_ADMIN)) { $message = $config['require_activation'] == USER_ACTIVATION_SELF ? 'ACCOUNT_EMAIL_CHANGED' : 'ACCOUNT_EMAIL_CHANGED_ADMIN'; include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx; $server_url = generate_board_url(); $user_actkey = gen_rand_string(mt_rand(6, 10)); $messenger = new messenger(false); $template_file = $config['require_activation'] == USER_ACTIVATION_ADMIN ? 'user_activate_inactive' : 'user_activate'; $messenger->template($template_file, $user->data['user_lang']); $messenger->to($data['email'], $data['username']); $messenger->anti_abuse_headers($config, $user); $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($data['username']), 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user->data['user_id']}&k={$user_actkey}")); $messenger->send(NOTIFY_EMAIL); if ($config['require_activation'] == USER_ACTIVATION_ADMIN) { // Grab an array of user_id's with a_user permissions ... these users can activate a user $admin_ary = $auth->acl_get_list(false, 'a_user', false); $admin_ary = !empty($admin_ary[0]['a_user']) ? $admin_ary[0]['a_user'] : array(); // Also include founders $where_sql = ' WHERE user_type = ' . USER_FOUNDER; if (sizeof($admin_ary)) { $where_sql .= ' OR ' . $db->sql_in_set('user_id', $admin_ary); } $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type FROM ' . USERS_TABLE . ' ' . $where_sql; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $messenger->template('admin_activate', $row['user_lang']); $messenger->to($row['user_email'], $row['username']); $messenger->im($row['user_jabber'], $row['username']); $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($data['username']), 'U_USER_DETAILS' => "{$server_url}/memberlist.{$phpEx}?mode=viewprofile&u={$user->data['user_id']}", 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user->data['user_id']}&k={$user_actkey}")); $messenger->send($row['user_notify_type']); } $db->sql_freeresult($result); } user_active_flip('deactivate', $user->data['user_id'], INACTIVE_PROFILE); // Because we want the profile to be reactivated we set user_newpasswd to empty (else the reactivation will fail) $sql_ary['user_actkey'] = $user_actkey; $sql_ary['user_newpasswd'] = ''; } if (sizeof($sql_ary)) { $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $user->data['user_id']; $db->sql_query($sql); } // Need to update config, forum, topic, posting, messages, etc. if ($data['username'] != $user->data['username'] && $auth->acl_get('u_chgname') && $config['allow_namechange']) { user_update_name($user->data['username'], $data['username']); } // Now, we can remove the user completely (kill the session) - NOT BEFORE!!! if (!empty($sql_ary['user_actkey'])) { meta_refresh(5, append_sid($phpbb_root_path . 'index.' . $phpEx)); $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid($phpbb_root_path . 'index.' . $phpEx) . '">', '</a>'); // Because the user gets deactivated we log him out too, killing his session $user->session_kill(); } else { meta_refresh(3, $this->u_action); $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); } trigger_error($message); } // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); } $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'USERNAME' => $data['username'], 'EMAIL' => $data['email'], 'PASSWORD_CONFIRM' => $data['password_confirm'], 'NEW_PASSWORD' => $data['new_password'], 'CUR_PASSWORD' => '', 'L_USERNAME_EXPLAIN' => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']), 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($user->lang[$config['pass_complex'] . '_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']), 'S_FORCE_PASSWORD' => $auth->acl_get('u_chgpasswd') && $config['chg_passforce'] && $user->data['user_passchg'] < time() - $config['chg_passforce'] * 86400 ? true : false, 'S_CHANGE_USERNAME' => $config['allow_namechange'] && $auth->acl_get('u_chgname') ? true : false, 'S_CHANGE_EMAIL' => $auth->acl_get('u_chgemail') ? true : false, 'S_CHANGE_PASSWORD' => $auth->acl_get('u_chgpasswd') ? true : false)); break; case 'profile_info': include $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx; $cp = new custom_profile(); $cp_data = $cp_error = array(); $data = array('icq' => request_var('icq', $user->data['user_icq']), 'aim' => request_var('aim', $user->data['user_aim']), 'msn' => request_var('msn', $user->data['user_msnm']), 'yim' => request_var('yim', $user->data['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user->data['user_jabber'], true)), 'website' => request_var('website', $user->data['user_website']), 'location' => utf8_normalize_nfc(request_var('location', $user->data['user_from'], true)), 'occupation' => utf8_normalize_nfc(request_var('occupation', $user->data['user_occ'], true)), 'interests' => utf8_normalize_nfc(request_var('interests', $user->data['user_interests'], true))); if ($config['allow_birthdays']) { $data['bday_day'] = $data['bday_month'] = $data['bday_year'] = 0; if ($user->data['user_birthday']) { list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user->data['user_birthday']); } $data['bday_day'] = request_var('bday_day', $data['bday_day']); $data['bday_month'] = request_var('bday_month', $data['bday_month']); $data['bday_year'] = request_var('bday_year', $data['bday_year']); $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']); } add_form_key('ucp_profile_info'); if ($submit) { $validate_array = array('icq' => array(array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), 'msn' => array('string', true, 5, 255), 'jabber' => array(array('string', true, 5, 255), array('jabber')), 'yim' => array('string', true, 5, 255), 'website' => array(array('string', true, 12, 255), array('match', true, '#^http[s]?://(.*?\\.)*?[a-z0-9\\-]+\\.[a-z]{2,4}#i')), 'location' => array('string', true, 2, 100), 'occupation' => array('string', true, 2, 500), 'interests' => array('string', true, 2, 500)); if ($config['allow_birthdays']) { $validate_array = array_merge($validate_array, array('bday_day' => array('num', true, 1, 31), 'bday_month' => array('num', true, 1, 12), 'bday_year' => array('num', true, 1901, gmdate('Y', time()) + 50), 'user_birthday' => array('date', true))); } $error = validate_data($data, $validate_array); // validate custom profile fields $cp->submit_cp_field('profile', $user->get_iso_lang_id(), $cp_data, $cp_error); if (sizeof($cp_error)) { $error = array_merge($error, $cp_error); } if (!check_form_key('ucp_profile_info')) { $error[] = 'FORM_INVALID'; } if (!sizeof($error)) { $data['notify'] = $user->data['user_notify_type']; if ($data['notify'] == NOTIFY_IM && (!$config['jab_enable'] || !$data['jabber'] || !@extension_loaded('xml'))) { // User has not filled in a jabber address (Or one of the modules is disabled or jabber is disabled) // Disable notify by Jabber now for this user. $data['notify'] = NOTIFY_EMAIL; } $sql_ary = array('user_icq' => $data['icq'], 'user_aim' => $data['aim'], 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], 'user_from' => $data['location'], 'user_occ' => $data['occupation'], 'user_interests' => $data['interests'], 'user_notify_type' => $data['notify']); if ($config['allow_birthdays']) { $sql_ary['user_birthday'] = $data['user_birthday']; } $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $user->data['user_id']; $db->sql_query($sql); // Update Custom Fields $cp->update_profile_field_data($user->data['user_id'], $cp_data); meta_refresh(3, $this->u_action); $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); trigger_error($message); } // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); } if ($config['allow_birthdays']) { $s_birthday_day_options = '<option value="0"' . (!$data['bday_day'] ? ' selected="selected"' : '') . '>--</option>'; for ($i = 1; $i < 32; $i++) { $selected = $i == $data['bday_day'] ? ' selected="selected"' : ''; $s_birthday_day_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>"; } $s_birthday_month_options = '<option value="0"' . (!$data['bday_month'] ? ' selected="selected"' : '') . '>--</option>'; for ($i = 1; $i < 13; $i++) { $selected = $i == $data['bday_month'] ? ' selected="selected"' : ''; $s_birthday_month_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>"; } $s_birthday_year_options = ''; $now = getdate(); $s_birthday_year_options = '<option value="0"' . (!$data['bday_year'] ? ' selected="selected"' : '') . '>--</option>'; for ($i = $now['year'] - 100; $i <= $now['year']; $i++) { $selected = $i == $data['bday_year'] ? ' selected="selected"' : ''; $s_birthday_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>"; } unset($now); $template->assign_vars(array('S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options, 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options, 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options, 'S_BIRTHDAYS_ENABLED' => true)); } $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], 'OCCUPATION' => $data['occupation'], 'INTERESTS' => $data['interests'])); // Get additional profile fields and assign them to the template block var 'profile_fields' $user->get_profile_fields($user->data['user_id']); $cp->generate_profile_fields('profile', $user->get_iso_lang_id()); break; case 'signature': if (!$auth->acl_get('u_sig')) { trigger_error('NO_AUTH_SIGNATURE'); } include $phpbb_root_path . 'includes/functions_posting.' . $phpEx; include $phpbb_root_path . 'includes/functions_display.' . $phpEx; $enable_bbcode = $config['allow_sig_bbcode'] ? (bool) $user->optionget('sig_bbcode') : false; $enable_smilies = $config['allow_sig_smilies'] ? (bool) $user->optionget('sig_smilies') : false; $enable_urls = $config['allow_sig_links'] ? (bool) $user->optionget('sig_links') : false; $signature = utf8_normalize_nfc(request_var('signature', (string) $user->data['user_sig'], true)); add_form_key('ucp_sig'); if ($submit || $preview) { include $phpbb_root_path . 'includes/message_parser.' . $phpEx; $enable_bbcode = $config['allow_sig_bbcode'] ? request_var('disable_bbcode', false) ? false : true : false; $enable_smilies = $config['allow_sig_smilies'] ? request_var('disable_smilies', false) ? false : true : false; $enable_urls = $config['allow_sig_links'] ? request_var('disable_magic_url', false) ? false : true : false; if (!sizeof($error)) { $message_parser = new parse_message($signature); // Allowing Quote BBCode $message_parser->parse($enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, $config['allow_sig_links'], true, 'sig'); if (sizeof($message_parser->warn_msg)) { $error[] = implode('<br />', $message_parser->warn_msg); } if (!check_form_key('ucp_sig')) { $error[] = 'FORM_INVALID'; } if (!sizeof($error) && $submit) { $user->optionset('sig_bbcode', $enable_bbcode); $user->optionset('sig_smilies', $enable_smilies); $user->optionset('sig_links', $enable_urls); $sql_ary = array('user_sig' => (string) $message_parser->message, 'user_options' => $user->data['user_options'], 'user_sig_bbcode_uid' => (string) $message_parser->bbcode_uid, 'user_sig_bbcode_bitfield' => $message_parser->bbcode_bitfield); $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $user->data['user_id']; $db->sql_query($sql); $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); trigger_error($message); } } // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); } $signature_preview = ''; if ($preview) { // Now parse it for displaying $signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false); unset($message_parser); } decode_message($signature, $user->data['user_sig_bbcode_uid']); $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'SIGNATURE' => $signature, 'SIGNATURE_PREVIEW' => $signature_preview, 'S_BBCODE_CHECKED' => !$enable_bbcode ? ' checked="checked"' : '', 'S_SMILIES_CHECKED' => !$enable_smilies ? ' checked="checked"' : '', 'S_MAGIC_URL_CHECKED' => !$enable_urls ? ' checked="checked"' : '', 'BBCODE_STATUS' => $config['allow_sig_bbcode'] ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>'), 'SMILIES_STATUS' => $config['allow_sig_smilies'] ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'IMG_STATUS' => $config['allow_sig_img'] ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $config['allow_sig_flash'] ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'URL_STATUS' => $config['allow_sig_links'] ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], 'MAX_FONT_SIZE' => (int) $config['max_sig_font_size'], 'L_SIGNATURE_EXPLAIN' => sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']), 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'], 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies'], 'S_BBCODE_IMG' => $config['allow_sig_img'] ? true : false, 'S_BBCODE_FLASH' => $config['allow_sig_flash'] ? true : false, 'S_LINKS_ALLOWED' => $config['allow_sig_links'] ? true : false)); // Build custom bbcodes array display_custom_bbcodes(); break; case 'avatar': include $phpbb_root_path . 'includes/functions_display.' . $phpEx; $display_gallery = request_var('display_gallery', '0'); $avatar_select = basename(request_var('avatar_select', '')); $category = basename(request_var('category', '')); $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false; add_form_key('ucp_avatar'); if ($submit) { if (check_form_key('ucp_avatar')) { if (avatar_process_user($error, false, $can_upload)) { meta_refresh(3, $this->u_action); $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); trigger_error($message); } } else { $error[] = 'FORM_INVALID'; } // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); } if (!$config['allow_avatar'] && $user->data['user_avatar_type']) { $error[] = $user->lang['AVATAR_NOT_ALLOWED']; } else { if ($user->data['user_avatar_type'] == AVATAR_UPLOAD && !$config['allow_avatar_upload'] || $user->data['user_avatar_type'] == AVATAR_REMOTE && !$config['allow_avatar_remote'] || $user->data['user_avatar_type'] == AVATAR_GALLERY && !$config['allow_avatar_local']) { $error[] = $user->lang['AVATAR_TYPE_NOT_ALLOWED']; } } $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'AVATAR' => get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height'], 'USER_AVATAR', true), 'AVATAR_SIZE' => $config['avatar_filesize'], 'U_GALLERY' => append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=profile&mode=avatar&display_gallery=1'), 'S_FORM_ENCTYPE' => $can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload']) ? ' enctype="multipart/form-data"' : '', 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024))); if ($config['allow_avatar'] && $display_gallery && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) { avatar_gallery($category, $avatar_select, 4); } else { if ($config['allow_avatar']) { $avatars_enabled = $can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload']) || $auth->acl_get('u_chgavatar') && ($config['allow_avatar_local'] || $config['allow_avatar_remote']) ? true : false; $template->assign_vars(array('AVATAR_WIDTH' => request_var('width', $user->data['user_avatar_width']), 'AVATAR_HEIGHT' => request_var('height', $user->data['user_avatar_height']), 'S_AVATARS_ENABLED' => $avatars_enabled, 'S_UPLOAD_AVATAR_FILE' => $can_upload && $config['allow_avatar_upload'] ? true : false, 'S_UPLOAD_AVATAR_URL' => $can_upload && $config['allow_avatar_remote_upload'] ? true : false, 'S_LINK_AVATAR' => $auth->acl_get('u_chgavatar') && $config['allow_avatar_remote'] ? true : false, 'S_DISPLAY_GALLERY' => $auth->acl_get('u_chgavatar') && $config['allow_avatar_local'] ? true : false)); } } break; } $template->assign_vars(array('L_TITLE' => $user->lang['UCP_PROFILE_' . strtoupper($mode)], 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_UCP_ACTION' => $this->u_action)); // Set desired template $this->tpl_name = 'ucp_profile_' . $mode; $this->page_title = 'UCP_PROFILE_' . strtoupper($mode); }
/** * Moves a template set to the filesystem * * @access private * @param string $mode The component to move - only template is supported * @param int $id The template id * @param string $path The path to the template */ function _store_in_fs($mode, $id, $path) { global $phpbb_root_path, $db, $user, $safe_mode; $store_db = 0; $error = array(); if (!$safe_mode && phpbb_is_writable("{$phpbb_root_path}styles/{$path}/template")) { $sql = 'SELECT * FROM ' . STYLES_TEMPLATE_DATA_TABLE . "\n\t\t\t\t\tWHERE template_id = {$id}"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (!($fp = @fopen("{$phpbb_root_path}styles/{$path}/template/" . $row['template_filename'], 'wb'))) { $store_db = 1; $error[] = $user->lang['EDIT_TEMPLATE_STORED_DB']; break; } fwrite($fp, $row['template_data']); fclose($fp); } $db->sql_freeresult($result); if (!$store_db) { $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . "\n\t\t\t\t\t\tWHERE template_id = {$id}"; $db->sql_query($sql); } } if (sizeof($error)) { return $error; } $sql = 'UPDATE ' . STYLES_TEMPLATE_TABLE . ' SET template_storedb = 0 WHERE template_id = ' . $id; $db->sql_query($sql); return false; }
public function _is_writable($file, $path = 'gallery', $sub_directory = 'includes/') { return phpbb_is_writable($this->path($path) . $sub_directory . $this->phpEx_file($file)); }
/** * Test Settings */ function test_upload(&$error, $upload_dir, $create_directory = false) { global $user, $phpbb_root_path; // Does the target directory exist, is it a directory and writable. if ($create_directory) { if (!file_exists($phpbb_root_path . $upload_dir)) { @mkdir($phpbb_root_path . $upload_dir, 0777); phpbb_chmod($phpbb_root_path . $upload_dir, CHMOD_READ | CHMOD_WRITE); } } if (!file_exists($phpbb_root_path . $upload_dir)) { $error[] = sprintf($user->lang['NO_UPLOAD_DIR'], $upload_dir); return; } if (!is_dir($phpbb_root_path . $upload_dir)) { $error[] = sprintf($user->lang['UPLOAD_NOT_DIR'], $upload_dir); return; } if (!phpbb_is_writable($phpbb_root_path . $upload_dir)) { $error[] = sprintf($user->lang['NO_WRITE_UPLOAD'], $upload_dir); return; } }
function main($mode, $sub) { global $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth; $this->tpl_name = 'install_update'; $this->page_title = 'UPDATE_INSTALLATION'; $this->unequal_version = false; $this->old_location = $phpbb_root_path . 'install/update/old/'; $this->new_location = $phpbb_root_path . 'install/update/new/'; // Init DB require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); // Special options for conflicts/modified files define('MERGE_NO_MERGE_NEW', 1); define('MERGE_NO_MERGE_MOD', 2); define('MERGE_NEW_FILE', 3); define('MERGE_MOD_FILE', 4); $db = new $sql_db(); // Connect to DB $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false); // We do not need this any longer, unset for safety purposes unset($dbpasswd); $config = array(); $sql = 'SELECT config_name, config_value FROM ' . CONFIG_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $config[$row['config_name']] = $row['config_value']; } $db->sql_freeresult($result); // Force template recompile $config['load_tplcompile'] = 1; // First of all, init the user session $user->session_begin(); $auth->acl($user->data); $user->setup('install'); // If we are within the intro page we need to make sure we get up-to-date version info if ($sub == 'intro') { $cache->destroy('_version_info'); } // Set custom template again. ;) $template->set_custom_template('../adm/style', 'admin'); // still, the acp template is never stored in the database $user->theme['template_storedb'] = false; // Get current and latest version if (($latest_version = $cache->get('_version_info')) === false) { $this->latest_version = $this->get_file('version_info'); $cache->put('_version_info', $this->latest_version); } else { $this->latest_version = $latest_version; } // For the current version we trick a bit. ;) $this->current_version = (!empty($config['version_update_from'])) ? $config['version_update_from'] : $config['version']; $up_to_date = (version_compare(str_replace('rc', 'RC', strtolower($this->current_version)), str_replace('rc', 'RC', strtolower($this->latest_version)), '<')) ? false : true; // Check for a valid update directory, else point the user to the phpbb.com website if (!file_exists($phpbb_root_path . 'install/update') || !file_exists($phpbb_root_path . 'install/update/index.' . $phpEx) || !file_exists($this->old_location) || !file_exists($this->new_location)) { $template->assign_vars(array( 'S_ERROR' => true, 'ERROR_MSG' => ($up_to_date) ? $user->lang['NO_UPDATE_FILES_UP_TO_DATE'] : sprintf($user->lang['NO_UPDATE_FILES_OUTDATED'], $config['version'], $this->current_version, $this->latest_version)) ); return; } $this->update_info = $this->get_file('update_info'); // Make sure the update directory holds the correct information // Since admins are able to run the update/checks more than once we only check if the current version is lower or equal than the version to which we update to. if (version_compare(str_replace('rc', 'RC', strtolower($this->current_version)), str_replace('rc', 'RC', strtolower($this->update_info['version']['to'])), '>')) { $template->assign_vars(array( 'S_ERROR' => true, 'ERROR_MSG' => sprintf($user->lang['INCOMPATIBLE_UPDATE_FILES'], $config['version'], $this->update_info['version']['from'], $this->update_info['version']['to'])) ); return; } // Check if the update files stored are for the latest version... if ($this->latest_version != $this->update_info['version']['to']) { $this->unequal_version = true; $template->assign_vars(array( 'S_WARNING' => true, 'WARNING_MSG' => sprintf($user->lang['OLD_UPDATE_FILES'], $this->update_info['version']['from'], $this->update_info['version']['to'], $this->latest_version)) ); } // We store the "update to" version, because it is not always the latest. ;) $this->update_to_version = $this->update_info['version']['to']; // Fill DB version if (empty($config['dbms_version'])) { set_config('dbms_version', $db->sql_server_info(true)); } if ($this->test_update === false) { // Got the updater template itself updated? If so, we are able to directly use it - but only if all three files are present if (in_array('adm/style/install_update.html', $this->update_info['files'])) { $this->tpl_name = '../../install/update/new/adm/style/install_update'; } // What about the language file? Got it updated? if (in_array('language/en/install.' . $phpEx, $this->update_info['files'])) { $lang = array(); include($this->new_location . 'language/en/install.' . $phpEx); // only add new keys to user's language in english $new_keys = array_diff(array_keys($lang), array_keys($user->lang)); foreach ($new_keys as $i => $new_key) { $user->lang[$new_key] = $lang[$new_key]; } } } // Include renderer and engine $this->include_file('includes/diff/diff.' . $phpEx); $this->include_file('includes/diff/engine.' . $phpEx); $this->include_file('includes/diff/renderer.' . $phpEx); // Make sure we stay at the file check if checking the files again if (!empty($_POST['check_again'])) { $sub = $this->p_master->sub = 'file_check'; } switch ($sub) { case 'intro': $this->page_title = 'UPDATE_INSTALLATION'; $template->assign_vars(array( 'S_INTRO' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=version_check"), )); // Make sure the update list is destroyed. $cache->destroy('_update_list'); $cache->destroy('_diff_files'); break; case 'version_check': $this->page_title = 'STAGE_VERSION_CHECK'; $template->assign_vars(array( 'S_UP_TO_DATE' => $up_to_date, 'S_VERSION_CHECK' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check"), 'U_DB_UPDATE_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_db"), 'LATEST_VERSION' => $this->latest_version, 'CURRENT_VERSION' => $this->current_version) ); // Print out version the update package updates to if ($this->unequal_version) { $template->assign_var('PACKAGE_VERSION', $this->update_info['version']['to']); } // Since some people try to update to RC releases, but phpBB.com tells them the last version is the version they currently run // we are faced with the updater thinking the database schema is up-to-date; which it is, but should be updated none-the-less // We now try to cope with this by triggering the update process if (version_compare(str_replace('rc', 'RC', strtolower($this->current_version)), str_replace('rc', 'RC', strtolower($this->update_info['version']['to'])), '<')) { $template->assign_vars(array( 'S_UP_TO_DATE' => false, )); } break; case 'update_db': // Make sure the database update is valid for the latest version $valid = false; $updates_to_version = ''; if (file_exists($phpbb_root_path . 'install/database_update.' . $phpEx)) { include_once($phpbb_root_path . 'install/database_update.' . $phpEx); if ($updates_to_version === $this->update_info['version']['to']) { $valid = true; } } // Should not happen at all if (!$valid) { trigger_error($user->lang['DATABASE_UPDATE_INFO_OLD'], E_USER_ERROR); } // Just a precaution $cache->purge(); // Redirect the user to the database update script with some explanations... $template->assign_vars(array( 'S_DB_UPDATE' => true, 'S_DB_UPDATE_FINISHED' => ($config['version'] == $this->update_info['version']['to']) ? true : false, 'U_DB_UPDATE' => append_sid($phpbb_root_path . 'install/database_update.' . $phpEx, 'type=1&language=' . $user->data['user_lang']), 'U_DB_UPDATE_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_db"), 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check"), )); break; case 'file_check': // Make sure the previous file collection is no longer valid... $cache->destroy('_diff_files'); $this->page_title = 'STAGE_FILE_CHECK'; // Now make sure our update list is correct if the admin refreshes $action = request_var('action', ''); // We are directly within an update. To make sure our update list is correct we check its status. $update_list = (!empty($_POST['check_again'])) ? false : $cache->get('_update_list'); $modified = ($update_list !== false) ? @filemtime($cache->cache_dir . 'data_update_list.' . $phpEx) : 0; // Make sure the list is up-to-date if ($update_list !== false) { $get_new_list = false; foreach ($this->update_info['files'] as $file) { if (file_exists($phpbb_root_path . $file) && filemtime($phpbb_root_path . $file) > $modified) { $get_new_list = true; break; } } } else { $get_new_list = true; } if (!$get_new_list && $update_list['status'] != -1) { $get_new_list = true; } if ($get_new_list) { $this->get_update_structure($update_list); $cache->put('_update_list', $update_list); // Refresh the page if we are still not finished... if ($update_list['status'] != -1) { $refresh_url = append_sid($this->p_master->module_url, "mode=$mode&sub=file_check"); meta_refresh(2, $refresh_url); $template->assign_vars(array( 'S_IN_PROGRESS' => true, 'S_COLLECTED' => (int) $update_list['status'], 'S_TO_COLLECT' => sizeof($this->update_info['files']), 'L_IN_PROGRESS' => $user->lang['COLLECTING_FILE_DIFFS'], 'L_IN_PROGRESS_EXPLAIN' => sprintf($user->lang['NUMBER_OF_FILES_COLLECTED'], (int) $update_list['status'], sizeof($this->update_info['files'])), )); return; } } if ($action == 'diff') { $this->show_diff($update_list); return; } if (sizeof($update_list['no_update'])) { $template->assign_vars(array( 'S_NO_UPDATE_FILES' => true, 'NO_UPDATE_FILES' => implode(', ', array_map('htmlspecialchars', $update_list['no_update']))) ); } // Now assign the list to the template foreach ($update_list as $status => $filelist) { if ($status == 'no_update' || !sizeof($filelist) || $status == 'status') { continue; } /* $template->assign_block_vars('files', array( 'S_STATUS' => true, 'STATUS' => $status, 'L_STATUS' => $user->lang['STATUS_' . strtoupper($status)], 'TITLE' => $user->lang['FILES_' . strtoupper($status)], 'EXPLAIN' => $user->lang['FILES_' . strtoupper($status) . '_EXPLAIN'], ) );*/ foreach ($filelist as $file_struct) { $s_binary = (!empty($this->update_info['binary']) && in_array($file_struct['filename'], $this->update_info['binary'])) ? true : false; $filename = htmlspecialchars($file_struct['filename']); if (strrpos($filename, '/') !== false) { $dir_part = substr($filename, 0, strrpos($filename, '/') + 1); $file_part = substr($filename, strrpos($filename, '/') + 1); } else { $dir_part = ''; $file_part = $filename; } $diff_url = append_sid($this->p_master->module_url, "mode=$mode&sub=file_check&action=diff&status=$status&file=" . urlencode($file_struct['filename'])); $template->assign_block_vars($status, array( 'STATUS' => $status, 'FILENAME' => $filename, 'DIR_PART' => $dir_part, 'FILE_PART' => $file_part, 'NUM_CONFLICTS' => (isset($file_struct['conflicts'])) ? $file_struct['conflicts'] : 0, 'S_CUSTOM' => ($file_struct['custom']) ? true : false, 'S_BINARY' => $s_binary, 'CUSTOM_ORIGINAL' => ($file_struct['custom']) ? $file_struct['original'] : '', 'U_SHOW_DIFF' => $diff_url, 'L_SHOW_DIFF' => ($status != 'up_to_date') ? $user->lang['SHOW_DIFF_' . strtoupper($status)] : '', 'U_VIEW_MOD_FILE' => $diff_url . '&op=' . MERGE_MOD_FILE, 'U_VIEW_NEW_FILE' => $diff_url . '&op=' . MERGE_NEW_FILE, 'U_VIEW_NO_MERGE_MOD' => $diff_url . '&op=' . MERGE_NO_MERGE_MOD, 'U_VIEW_NO_MERGE_NEW' => $diff_url . '&op=' . MERGE_NO_MERGE_NEW, )); } } $all_up_to_date = true; foreach ($update_list as $status => $filelist) { if ($status != 'up_to_date' && $status != 'custom' && $status != 'status' && sizeof($filelist)) { $all_up_to_date = false; break; } } $template->assign_vars(array( 'S_FILE_CHECK' => true, 'S_ALL_UP_TO_DATE' => $all_up_to_date, 'S_VERSION_UP_TO_DATE' => $up_to_date, 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check"), 'U_UPDATE_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files"), 'U_DB_UPDATE_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_db"), )); if ($all_up_to_date) { // Add database update to log add_log('admin', 'LOG_UPDATE_PHPBB', $this->current_version, $this->update_to_version); // Refresh prosilver css data - this may cause some unhappy users, but $sql = 'SELECT * FROM ' . STYLES_THEME_TABLE . " WHERE LOWER(theme_name) = 'prosilver'"; $result = $db->sql_query($sql); $theme = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($theme) { $recache = (empty($theme['theme_data'])) ? true : false; $update_time = time(); // We test for stylesheet.css because it is faster and most likely the only file changed on common themes if (!$recache && $theme['theme_mtime'] < @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css')) { $recache = true; $update_time = @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'); } else if (!$recache) { $last_change = $theme['theme_mtime']; $dir = @opendir("{$phpbb_root_path}styles/{$theme['theme_path']}/theme"); if ($dir) { while (($entry = readdir($dir)) !== false) { if (substr(strrchr($entry, '.'), 1) == 'css' && $last_change < @filemtime("{$phpbb_root_path}styles/{$theme['theme_path']}/theme/{$entry}")) { $recache = true; break; } } closedir($dir); } } if ($recache) { // Instead of re-caching here, we simply remove theme_data... HAR HAR HAR (think about a carribean pirate) $sql = 'UPDATE ' . STYLES_THEME_TABLE . " SET theme_data = '' WHERE theme_id = " . $theme['theme_id']; $db->sql_query($sql); $cache->destroy('sql', STYLES_THEME_TABLE); $cache->destroy('sql', STYLES_TABLE); } } $db->sql_return_on_error(true); $db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'version_update_from'"); $db->sql_return_on_error(false); $cache->purge(); } break; case 'update_files': $this->page_title = 'STAGE_UPDATE_FILES'; $s_hidden_fields = ''; $params = array(); $conflicts = request_var('conflict', array('' => 0)); $modified = request_var('modified', array('' => 0)); foreach ($conflicts as $filename => $merge_option) { $s_hidden_fields .= '<input type="hidden" name="conflict[' . htmlspecialchars($filename) . ']" value="' . $merge_option . '" />'; $params[] = 'conflict[' . urlencode($filename) . ']=' . urlencode($merge_option); } foreach ($modified as $filename => $merge_option) { if (!$merge_option) { continue; } $s_hidden_fields .= '<input type="hidden" name="modified[' . htmlspecialchars($filename) . ']" value="' . $merge_option . '" />'; $params[] = 'modified[' . urlencode($filename) . ']=' . urlencode($merge_option); } $no_update = request_var('no_update', array(0 => '')); foreach ($no_update as $index => $filename) { $s_hidden_fields .= '<input type="hidden" name="no_update[]" value="' . htmlspecialchars($filename) . '" />'; $params[] = 'no_update[]=' . urlencode($filename); } // Before the user is choosing his preferred method, let's create the content list... $update_list = $cache->get('_update_list'); if ($update_list === false) { trigger_error($user->lang['NO_UPDATE_INFO'], E_USER_ERROR); } // Check if the conflicts data is valid if (sizeof($conflicts)) { $conflict_filenames = array(); foreach ($update_list['conflict'] as $files) { $conflict_filenames[] = $files['filename']; } $new_conflicts = array(); foreach ($conflicts as $filename => $diff_method) { if (in_array($filename, $conflict_filenames)) { $new_conflicts[$filename] = $diff_method; } } $conflicts = $new_conflicts; } // Build list for modifications if (sizeof($modified)) { $modified_filenames = array(); foreach ($update_list['modified'] as $files) { $modified_filenames[] = $files['filename']; } $new_modified = array(); foreach ($modified as $filename => $diff_method) { if (in_array($filename, $modified_filenames)) { $new_modified[$filename] = $diff_method; } } $modified = $new_modified; } // Check number of conflicting files, they need to be equal. For modified files the number can differ if (sizeof($update_list['conflict']) != sizeof($conflicts)) { trigger_error($user->lang['MERGE_SELECT_ERROR'], E_USER_ERROR); } // Before we do anything, let us diff the files and store the raw file information "somewhere" $get_files = false; $file_list = $cache->get('_diff_files'); if ($file_list === false || $file_list['status'] != -1) { $get_files = true; } if ($get_files) { if ($file_list === false) { $file_list = array( 'status' => 0, ); } $processed = 0; foreach ($update_list as $status => $files) { if (!is_array($files)) { continue; } foreach ($files as $file_struct) { // Skip this file if the user selected to not update it if (in_array($file_struct['filename'], $no_update)) { continue; } // Already handled... then skip of course... if (isset($file_list[$file_struct['filename']])) { continue; } // Refresh if we reach 5 diffs... if ($processed >= 5) { $cache->put('_diff_files', $file_list); if (!empty($_REQUEST['download'])) { $params[] = 'download=1'; } $redirect_url = append_sid($this->p_master->module_url, "mode=$mode&sub=update_files&" . implode('&', $params)); meta_refresh(3, $redirect_url); $template->assign_vars(array( 'S_IN_PROGRESS' => true, 'L_IN_PROGRESS' => $user->lang['MERGING_FILES'], 'L_IN_PROGRESS_EXPLAIN' => $user->lang['MERGING_FILES_EXPLAIN'], )); return; } $original_filename = ($file_struct['custom']) ? $file_struct['original'] : $file_struct['filename']; switch ($status) { case 'modified': $option = (isset($modified[$file_struct['filename']])) ? $modified[$file_struct['filename']] : 0; switch ($option) { case MERGE_NO_MERGE_NEW: $contents = file_get_contents($this->new_location . $original_filename); break; case MERGE_NO_MERGE_MOD: $contents = file_get_contents($phpbb_root_path . $file_struct['filename']); break; default: $diff = $this->return_diff($this->old_location . $original_filename, $phpbb_root_path . $file_struct['filename'], $this->new_location . $original_filename); $contents = implode("\n", $diff->merged_output()); unset($diff); break; } $file_list[$file_struct['filename']] = '_file_' . md5($file_struct['filename']); $cache->put($file_list[$file_struct['filename']], base64_encode($contents)); $file_list['status']++; $processed++; break; case 'conflict': $option = $conflicts[$file_struct['filename']]; $contents = ''; switch ($option) { case MERGE_NO_MERGE_NEW: $contents = file_get_contents($this->new_location . $original_filename); break; case MERGE_NO_MERGE_MOD: $contents = file_get_contents($phpbb_root_path . $file_struct['filename']); break; default: $diff = $this->return_diff($this->old_location . $original_filename, $phpbb_root_path . $file_struct['filename'], $this->new_location . $original_filename); if ($option == MERGE_NEW_FILE) { $contents = implode("\n", $diff->merged_new_output()); } else if ($option == MERGE_MOD_FILE) { $contents = implode("\n", $diff->merged_orig_output()); } else { unset($diff); break 2; } unset($diff); break; } $file_list[$file_struct['filename']] = '_file_' . md5($file_struct['filename']); $cache->put($file_list[$file_struct['filename']], base64_encode($contents)); $file_list['status']++; $processed++; break; } } } } $file_list['status'] = -1; $cache->put('_diff_files', $file_list); if (!empty($_REQUEST['download'])) { $this->include_file('includes/functions_compress.' . $phpEx); $use_method = request_var('use_method', ''); $methods = array('.tar'); $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib'); foreach ($available_methods as $type => $module) { if (!@extension_loaded($module)) { continue; } $methods[] = $type; } // Let the user decide in which format he wants to have the pack if (!$use_method) { $this->page_title = 'SELECT_DOWNLOAD_FORMAT'; $radio_buttons = ''; foreach ($methods as $method) { $radio_buttons .= '<label><input type="radio"' . ((!$radio_buttons) ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>'; } $template->assign_vars(array( 'S_DOWNLOAD_FILES' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files"), 'RADIO_BUTTONS' => $radio_buttons, 'S_HIDDEN_FIELDS' => $s_hidden_fields) ); // To ease the update process create a file location map $update_list = $cache->get('_update_list'); $script_path = ($config['force_server_vars']) ? (($config['script_path'] == '/') ? '/' : $config['script_path'] . '/') : $user->page['root_script_path']; foreach ($update_list as $status => $files) { if ($status == 'up_to_date' || $status == 'no_update' || $status == 'status') { continue; } foreach ($files as $file_struct) { if (in_array($file_struct['filename'], $no_update)) { continue; } $template->assign_block_vars('location', array( 'SOURCE' => htmlspecialchars($file_struct['filename']), 'DESTINATION' => $script_path . htmlspecialchars($file_struct['filename']), )); } } return; } if (!in_array($use_method, $methods)) { $use_method = '.tar'; } $update_mode = 'download'; } else { $this->include_file('includes/functions_transfer.' . $phpEx); // Choose FTP, if not available use fsock... $method = basename(request_var('method', '')); $submit = (isset($_POST['submit'])) ? true : false; $test_ftp_connection = request_var('test_connection', ''); if (!$method || !class_exists($method)) { $method = 'ftp'; $methods = transfer::methods(); if (!in_array('ftp', $methods)) { $method = $methods[0]; } } $test_connection = false; if ($test_ftp_connection || $submit) { $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); $test_connection = $transfer->open_session(); // Make sure that the directory is correct by checking for the existence of common.php if ($test_connection === true) { // Check for common.php file if (!$transfer->file_exists($phpbb_root_path, 'common.' . $phpEx)) { $test_connection = 'ERR_WRONG_PATH_TO_PHPBB'; } } $transfer->close_session(); // Make sure the login details are correct before continuing if ($submit && $test_connection !== true) { $submit = false; $test_ftp_connection = true; } } $s_hidden_fields .= build_hidden_fields(array('method' => $method)); if (!$submit) { $this->page_title = 'SELECT_FTP_SETTINGS'; if (!class_exists($method)) { trigger_error('Method does not exist.', E_USER_ERROR); } $requested_data = call_user_func(array($method, 'data')); foreach ($requested_data as $data => $default) { $template->assign_block_vars('data', array( 'DATA' => $data, 'NAME' => $user->lang[strtoupper($method . '_' . $data)], 'EXPLAIN' => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], 'DEFAULT' => (!empty($_REQUEST[$data])) ? request_var($data, '') : $default )); } $template->assign_vars(array( 'S_CONNECTION_SUCCESS' => ($test_ftp_connection && $test_connection === true) ? true : false, 'S_CONNECTION_FAILED' => ($test_ftp_connection && $test_connection !== true) ? true : false, 'ERROR_MSG' => ($test_ftp_connection && $test_connection !== true) ? $user->lang[$test_connection] : '', 'S_FTP_UPLOAD' => true, 'UPLOAD_METHOD' => $method, 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files"), 'U_DOWNLOAD_METHOD' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files&download=1"), 'S_HIDDEN_FIELDS' => $s_hidden_fields, )); return; } $update_mode = 'upload'; } // Now update the installation or download the archive... $download_filename = 'update_' . $this->update_info['version']['from'] . '_to_' . $this->update_info['version']['to']; $archive_filename = $download_filename . '_' . time() . '_' . unique_id(); // Now init the connection if ($update_mode == 'download') { if (function_exists('phpbb_is_writable') && !phpbb_is_writable($phpbb_root_path . 'store/')) { trigger_error(sprintf('The directory “%s” is not writable.', $phpbb_root_path . 'store/'), E_USER_ERROR); } if ($use_method == '.zip') { $compress = new compress_zip('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method); } else { $compress = new compress_tar('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method, $use_method); } } else { $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); $transfer->open_session(); } // Ok, go through the update list and do the operations based on their status foreach ($update_list as $status => $files) { if (!is_array($files)) { continue; } foreach ($files as $file_struct) { // Skip this file if the user selected to not update it if (in_array($file_struct['filename'], $no_update)) { continue; } $original_filename = ($file_struct['custom']) ? $file_struct['original'] : $file_struct['filename']; switch ($status) { case 'new': case 'new_conflict': case 'not_modified': if ($update_mode == 'download') { $compress->add_custom_file($this->new_location . $original_filename, $file_struct['filename']); } else { if ($status != 'new') { $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); } // New directory too? $dirname = dirname($file_struct['filename']); if ($dirname && !file_exists($phpbb_root_path . $dirname)) { $transfer->make_dir($dirname); } $transfer->copy_file($this->new_location . $original_filename, $file_struct['filename']); } break; case 'modified': $contents = base64_decode($cache->get($file_list[$file_struct['filename']])); if ($update_mode == 'download') { $compress->add_data($contents, $file_struct['filename']); } else { // @todo add option to specify if a backup file should be created? $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); $transfer->write_file($file_struct['filename'], $contents); } break; case 'conflict': $contents = base64_decode($cache->get($file_list[$file_struct['filename']])); if ($update_mode == 'download') { $compress->add_data($contents, $file_struct['filename']); } else { $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); $transfer->write_file($file_struct['filename'], $contents); } break; } } } if ($update_mode == 'download') { $compress->close(); $compress->download($archive_filename, $download_filename); @unlink($phpbb_root_path . 'store/' . $archive_filename . $use_method); exit; } else { $transfer->close_session(); $template->assign_vars(array( 'S_UPLOAD_SUCCESS' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check")) ); return; } break; } }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; $user->add_lang('acp/groups'); $this->tpl_name = 'acp_groups'; $this->page_title = 'ACP_GROUPS_MANAGE'; $form_key = 'acp_groups'; add_form_key($form_key); include $phpbb_root_path . 'includes/functions_user.' . $phpEx; // Check and set some common vars $action = isset($_POST['add']) ? 'add' : (isset($_POST['addusers']) ? 'addusers' : request_var('action', '')); $group_id = request_var('g', 0); $mark_ary = request_var('mark', array(0)); $name_ary = request_var('usernames', '', true); $leader = request_var('leader', 0); $default = request_var('default', 0); $start = request_var('start', 0); $update = isset($_POST['update']) ? true : false; // Clear some vars $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false; $group_row = array(); // Grab basic data for group, if group_id is set and exists if ($group_id) { $sql = 'SELECT * FROM ' . GROUPS_TABLE . "\n\t\t\t\tWHERE group_id = {$group_id}"; $result = $db->sql_query($sql); $group_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$group_row) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } // Check if the user is allowed to manage this group if set to founder only. if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage']) { trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } } // Which page? switch ($action) { case 'approve': case 'demote': case 'promote': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } // Approve, demote or promote $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; $error = group_user_attributes($action, $group_id, $mark_ary, false, $group_name); if (!$error) { switch ($action) { case 'demote': $message = 'GROUP_MODS_DEMOTED'; break; case 'promote': $message = 'GROUP_MODS_PROMOTED'; break; case 'approve': $message = 'USERS_APPROVED'; break; } trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else { trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } break; case 'default': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } if (confirm_box(true)) { $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; if (!sizeof($mark_ary)) { $start = 0; do { $sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\t\t\tORDER BY user_id"; $result = $db->sql_query_limit($sql, 200, $start); $mark_ary = array(); if ($row = $db->sql_fetchrow($result)) { do { $mark_ary[] = $row['user_id']; } while ($row = $db->sql_fetchrow($result)); group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); $start = sizeof($mark_ary) < 200 ? 0 : $start + 200; } else { $start = 0; } $db->sql_freeresult($result); } while ($start); } else { group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row); } trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action))); } break; case 'deleteusers': case 'delete': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } else { if ($action === 'delete' && $group_row['group_type'] == GROUP_SPECIAL) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } } if (confirm_box(true)) { $error = ''; switch ($action) { case 'delete': if (!$auth->acl_get('a_groupdel')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $error = group_delete($group_id, $group_row['group_name']); break; case 'deleteusers': $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; $error = group_user_del($group_id, $mark_ary, false, $group_name); break; } $back_link = $action == 'delete' ? $this->u_action : $this->u_action . '&action=list&g=' . $group_id; if ($error) { trigger_error($user->lang[$error] . adm_back_link($back_link), E_USER_WARNING); } $message = $action == 'delete' ? 'GROUP_DELETED' : 'GROUP_USERS_REMOVE'; trigger_error($user->lang[$message] . adm_back_link($back_link)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action))); } break; case 'addusers': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$name_ary) { trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } $name_ary = array_unique(explode("\n", $name_ary)); $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name']; // Add user/s to group if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, $leader, 0, $group_row)) { trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING); } $message = $leader ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED'; trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id)); break; case 'edit': case 'add': include $phpbb_root_path . 'includes/functions_display.' . $phpEx; $data = $submit_ary = array(); if ($action == 'edit' && !$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } if ($action == 'add' && !$auth->acl_get('a_groupadd')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $error = array(); $user->add_lang('ucp'); $avatar_select = basename(request_var('avatar_select', '')); $category = basename(request_var('category', '')); // Did we submit? if ($update) { if (!check_form_key($form_key)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $group_name = utf8_normalize_nfc(request_var('group_name', '', true)); $group_desc = utf8_normalize_nfc(request_var('group_desc', '', true)); $group_type = request_var('group_type', GROUP_FREE); $allow_desc_bbcode = request_var('desc_parse_bbcode', false); $allow_desc_urls = request_var('desc_parse_urls', false); $allow_desc_smilies = request_var('desc_parse_smilies', false); $data['uploadurl'] = request_var('uploadurl', ''); $data['remotelink'] = request_var('remotelink', ''); $data['width'] = request_var('width', ''); $data['height'] = request_var('height', ''); $delete = request_var('delete', ''); $submit_ary = array('colour' => request_var('group_colour', ''), 'rank' => request_var('group_rank', 0), 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0, 'legend' => isset($_REQUEST['group_legend']) ? 1 : 0, 'message_limit' => request_var('group_message_limit', 0), 'max_recipients' => request_var('group_max_recipients', 0), 'founder_manage' => 0, 'skip_auth' => request_var('group_skip_auth', 0)); if ($user->data['user_type'] == USER_FOUNDER) { $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0; } if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink']) { // Avatar stuff $var_ary = array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3)); if (!($error = validate_data($data, $var_ary))) { $data['user_id'] = "g{$group_id}"; if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload) { list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error); } else { if ($data['remotelink']) { list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error); } } } } else { if ($avatar_select && $config['allow_avatar_local']) { // check avatar gallery if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) { $submit_ary['avatar_type'] = AVATAR_GALLERY; list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select); $submit_ary['avatar'] = $category . '/' . $avatar_select; } } else { if ($delete) { $submit_ary['avatar'] = ''; $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0; } else { if ($data['width'] && $data['height']) { // Only update the dimensions? if ($config['avatar_max_width'] || $config['avatar_max_height']) { if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) { $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']); } } if (!sizeof($error)) { if ($config['avatar_min_width'] || $config['avatar_min_height']) { if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) { $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']); } } } if (!sizeof($error)) { $submit_ary['avatar_width'] = $data['width']; $submit_ary['avatar_height'] = $data['height']; } } } } } if (isset($submit_ary['avatar']) && $submit_ary['avatar'] && !isset($group_row['group_avatar']) || $delete) { if (isset($group_row['group_avatar']) && $group_row['group_avatar']) { avatar_delete('group', $group_row, true); } } // Validate the length of "Maximum number of allowed recipients per private message" setting. // We use 16777215 as a maximum because it matches MySQL unsigned mediumint maximum value // which is the lowest amongst DBMSes supported by phpBB3 if ($max_recipients_error = validate_data($submit_ary, array('max_recipients' => array('num', false, 0, 16777215)))) { // Replace "error" string with its real, localised form $error = array_merge($error, array_map(array(&$user, 'lang'), $max_recipients_error)); } if (!sizeof($error)) { // Only set the rank, colour, etc. if it's changed or if we're adding a new // group. This prevents existing group members being updated if no changes // were made. $group_attributes = array(); $test_variables = array('rank' => 'int', 'colour' => 'string', 'avatar' => 'string', 'avatar_type' => 'int', 'avatar_width' => 'int', 'avatar_height' => 'int', 'receive_pm' => 'int', 'legend' => 'int', 'message_limit' => 'int', 'max_recipients' => 'int', 'founder_manage' => 'int', 'skip_auth' => 'int'); foreach ($test_variables as $test => $type) { if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test])) { settype($submit_ary[$test], $type); $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test]; } } if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies))) { $group_perm_from = request_var('group_perm_from', 0); // Copy permissions? // If the user has the a_authgroups permission and at least one additional permission ability set the permissions are fully transferred. // We do not limit on one auth category because this can lead to incomplete permissions being tricky to fix for the admin, roles being assigned or added non-default permissions. // Since the user only has the option to copy permissions from non leader managed groups this seems to be a good compromise. if ($group_perm_from && $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) { $sql = 'SELECT group_founder_manage FROM ' . GROUPS_TABLE . ' WHERE group_id = ' . $group_perm_from; $result = $db->sql_query($sql); $check_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); // Check the group if non-founder if ($check_row && ($user->data['user_type'] == USER_FOUNDER || $check_row['group_founder_manage'] == 0)) { // From the mysql documentation: // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14. // Due to this we stay on the safe side if we do the insertion "the manual way" // Copy permisisons from/to the acl groups table (only group_id gets changed) $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' WHERE group_id = ' . $group_perm_from; $result = $db->sql_query($sql); $groups_sql_ary = array(); while ($row = $db->sql_fetchrow($result)) { $groups_sql_ary[] = array('group_id' => (int) $group_id, 'forum_id' => (int) $row['forum_id'], 'auth_option_id' => (int) $row['auth_option_id'], 'auth_role_id' => (int) $row['auth_role_id'], 'auth_setting' => (int) $row['auth_setting']); } $db->sql_freeresult($result); // Now insert the data $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary); $auth->acl_clear_prefetch(); } } $cache->destroy('sql', GROUPS_TABLE); $message = $action == 'edit' ? 'GROUP_UPDATED' : 'GROUP_CREATED'; trigger_error($user->lang[$message] . adm_back_link($this->u_action)); } } if (sizeof($error)) { $group_rank = $submit_ary['rank']; $group_desc_data = array('text' => $group_desc, 'allow_bbcode' => $allow_desc_bbcode, 'allow_smilies' => $allow_desc_smilies, 'allow_urls' => $allow_desc_urls); } } else { if (!$group_id) { $group_name = utf8_normalize_nfc(request_var('group_name', '', true)); $group_desc_data = array('text' => '', 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true); $group_rank = 0; $group_type = GROUP_OPEN; } else { $group_name = $group_row['group_name']; $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']); $group_type = $group_row['group_type']; $group_rank = $group_row['group_rank']; } } $sql = 'SELECT * FROM ' . RANKS_TABLE . ' WHERE rank_special = 1 ORDER BY rank_title'; $result = $db->sql_query($sql); $rank_options = '<option value="0"' . (!$group_rank ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>'; while ($row = $db->sql_fetchrow($result)) { $selected = $group_rank && $row['rank_id'] == $group_rank ? ' selected="selected"' : ''; $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>'; } $db->sql_freeresult($result); $type_free = $group_type == GROUP_FREE ? ' checked="checked"' : ''; $type_open = $group_type == GROUP_OPEN ? ' checked="checked"' : ''; $type_closed = $group_type == GROUP_CLOSED ? ' checked="checked"' : ''; $type_hidden = $group_type == GROUP_HIDDEN ? ' checked="checked"' : ''; $avatar_img = !empty($group_row['group_avatar']) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />'; $display_gallery = isset($_POST['display_gallery']) ? true : false; if ($config['allow_avatar_local'] && $display_gallery) { avatar_gallery($category, $avatar_select, 4); } $back_link = request_var('back_link', ''); switch ($back_link) { case 'acp_users_groups': $u_back = append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=users&mode=groups&u=' . request_var('u', 0)); break; default: $u_back = $this->u_action; break; } $template->assign_vars(array('S_EDIT' => true, 'S_ADD_GROUP' => $action == 'add' ? true : false, 'S_GROUP_PERM' => $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth') ? true : false, 'S_INCLUDE_SWATCH' => true, 'S_CAN_UPLOAD' => $can_upload, 'S_ERROR' => sizeof($error) ? true : false, 'S_SPECIAL_GROUP' => $group_type == GROUP_SPECIAL ? true : false, 'S_DISPLAY_GALLERY' => $config['allow_avatar_local'] && !$display_gallery ? true : false, 'S_IN_GALLERY' => $config['allow_avatar_local'] && $display_gallery ? true : false, 'S_USER_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : '', 'GROUP_NAME' => $group_type == GROUP_SPECIAL ? $user->lang['G_' . $group_name] : $group_name, 'GROUP_INTERNAL_NAME' => $group_name, 'GROUP_DESC' => $group_desc_data['text'], 'GROUP_RECEIVE_PM' => isset($group_row['group_receive_pm']) && $group_row['group_receive_pm'] ? ' checked="checked"' : '', 'GROUP_FOUNDER_MANAGE' => isset($group_row['group_founder_manage']) && $group_row['group_founder_manage'] ? ' checked="checked"' : '', 'GROUP_LEGEND' => isset($group_row['group_legend']) && $group_row['group_legend'] ? ' checked="checked"' : '', 'GROUP_MESSAGE_LIMIT' => isset($group_row['group_message_limit']) ? $group_row['group_message_limit'] : 0, 'GROUP_MAX_RECIPIENTS' => isset($group_row['group_max_recipients']) ? $group_row['group_max_recipients'] : 0, 'GROUP_COLOUR' => isset($group_row['group_colour']) ? $group_row['group_colour'] : '', 'GROUP_SKIP_AUTH' => !empty($group_row['group_skip_auth']) ? ' checked="checked"' : '', 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'], 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'], 'S_DESC_SMILIES_CHECKED' => $group_desc_data['allow_smilies'], 'S_RANK_OPTIONS' => $rank_options, 'S_GROUP_OPTIONS' => group_select_options(false, false, $user->data['user_type'] == USER_FOUNDER ? false : 0), 'AVATAR' => $avatar_img, 'AVATAR_IMAGE' => $avatar_img, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'AVATAR_WIDTH' => isset($group_row['group_avatar_width']) ? $group_row['group_avatar_width'] : '', 'AVATAR_HEIGHT' => isset($group_row['group_avatar_height']) ? $group_row['group_avatar_height'] : '', 'GROUP_TYPE_FREE' => GROUP_FREE, 'GROUP_TYPE_OPEN' => GROUP_OPEN, 'GROUP_TYPE_CLOSED' => GROUP_CLOSED, 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN, 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL, 'GROUP_FREE' => $type_free, 'GROUP_OPEN' => $type_open, 'GROUP_CLOSED' => $type_closed, 'GROUP_HIDDEN' => $type_hidden, 'U_BACK' => $u_back, 'U_SWATCH' => append_sid("{$phpbb_admin_path}swatch.{$phpEx}", 'form=settings&name=group_colour'), 'U_ACTION' => "{$this->u_action}&action={$action}&g={$group_id}", 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)))); return; break; case 'list': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); } $this->page_title = 'GROUP_MEMBERS'; // Grab the leaders - always, on every page... $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_colour, u.user_posts, u.group_id, ug.group_leader, ug.user_pending FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.group_id = {$group_id}\n\t\t\t\t\t\tAND u.user_id = ug.user_id\n\t\t\t\t\t\tAND ug.group_leader = 1\n\t\t\t\t\tORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $template->assign_block_vars('leader', array('U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&action=edit&u={$row['user_id']}"), 'USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id'])); } $db->sql_freeresult($result); // Total number of group members (non-leaders) $sql = 'SELECT COUNT(user_id) AS total_members FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\tAND group_leader = 0"; $result = $db->sql_query($sql); $total_members = (int) $db->sql_fetchfield('total_members'); $db->sql_freeresult($result); $s_action_options = ''; $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE'); foreach ($options as $option => $lang) { $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>'; } $template->assign_vars(array('S_LIST' => true, 'S_GROUP_SPECIAL' => $group_row['group_type'] == GROUP_SPECIAL ? true : false, 'S_ACTION_OPTIONS' => $s_action_options, 'S_ON_PAGE' => on_page($total_members, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&action={$action}&g={$group_id}", $total_members, $config['topics_per_page'], $start, true), 'GROUP_NAME' => $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'], 'U_ACTION' => $this->u_action . "&g={$group_id}", 'U_BACK' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=list&field=usernames'), 'U_DEFAULT_ALL' => "{$this->u_action}&action=default&g={$group_id}")); // Grab the members $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.group_id = {$group_id}\n\t\t\t\t\t\tAND u.user_id = ug.user_id\n\t\t\t\t\t\tAND ug.group_leader = 0\n\t\t\t\t\tORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean"; $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); $pending = false; while ($row = $db->sql_fetchrow($result)) { if ($row['user_pending'] && !$pending) { $template->assign_block_vars('member', array('S_PENDING' => true)); $pending = true; } $template->assign_block_vars('member', array('U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&action=edit&u={$row['user_id']}"), 'USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id'])); } $db->sql_freeresult($result); return; break; } $template->assign_vars(array('U_ACTION' => $this->u_action, 'S_GROUP_ADD' => $auth->acl_get('a_groupadd') ? true : false)); // Get us all the groups $sql = 'SELECT g.group_id, g.group_name, g.group_type FROM ' . GROUPS_TABLE . ' g ORDER BY g.group_type ASC, g.group_name'; $result = $db->sql_query($sql); $lookup = $cached_group_data = array(); while ($row = $db->sql_fetchrow($result)) { $type = $row['group_type'] == GROUP_SPECIAL ? 'special' : 'normal'; // used to determine what type a group is $lookup[$row['group_id']] = $type; // used for easy access to the data within a group $cached_group_data[$type][$row['group_id']] = $row; $cached_group_data[$type][$row['group_id']]['total_members'] = 0; } $db->sql_freeresult($result); // How many people are in which group? $sql = 'SELECT COUNT(ug.user_id) AS total_members, ug.group_id FROM ' . USER_GROUP_TABLE . ' ug WHERE ' . $db->sql_in_set('ug.group_id', array_keys($lookup)) . ' GROUP BY ug.group_id'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $type = $lookup[$row['group_id']]; $cached_group_data[$type][$row['group_id']]['total_members'] = $row['total_members']; } $db->sql_freeresult($result); // The order is... normal, then special ksort($cached_group_data); foreach ($cached_group_data as $type => $row_ary) { if ($type == 'special') { $template->assign_block_vars('groups', array('S_SPECIAL' => true)); } foreach ($row_ary as $group_id => $row) { $group_name = !empty($user->lang['G_' . $row['group_name']]) ? $user->lang['G_' . $row['group_name']] : $row['group_name']; $template->assign_block_vars('groups', array('U_LIST' => "{$this->u_action}&action=list&g={$group_id}", 'U_EDIT' => "{$this->u_action}&action=edit&g={$group_id}", 'U_DELETE' => $auth->acl_get('a_groupdel') ? "{$this->u_action}&action=delete&g={$group_id}" : '', 'S_GROUP_SPECIAL' => $row['group_type'] == GROUP_SPECIAL ? true : false, 'GROUP_NAME' => $group_name, 'TOTAL_MEMBERS' => $row['total_members'])); } } }
/** * Removes/unlinks file * * @param string $filename Filename to remove * @param bool $check Check file permissions * @return bool True if the file was successfully removed, otherwise false */ function remove_file($filename, $check = false) { if (!function_exists('phpbb_is_writable')) { global $phpbb_root_path, $phpEx; include $phpbb_root_path . 'includes/functions.' . $phpEx; } if ($check && !phpbb_is_writable($this->cache_dir)) { // E_USER_ERROR - not using language entry - intended. trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR); } return @unlink($filename); }
if ($config['avatar_filesize'] != '0') { echo 'Maximum avatar file size: ' . get_formatted_filesize($config['avatar_filesize']) . '<br />'; } else { echo 'Maximum avatar file size: PHP limit<br />'; } echo 'Minimum avatar dimensions: ' . $config['avatar_min_width'] . ' × ' . $config['avatar_min_height'] . ' px (width × height)<br />'; echo 'Maximum avatar dimensions: ' . $config['avatar_max_width'] . ' × ' . $config['avatar_max_height'] . ' px (width × height)<br />'; echo 'Avatar storage path: ' . $config['avatar_path'] . '<br />'; if ($config['avatar_path'] != '') { echo 'Avatar storage folder permissions: ' . substr(decoct(fileperms($phpbb_root_path . $config['avatar_path'])), 2) . ' <br />'; } echo 'Avatar gallery path: ' . $config['avatar_gallery_path'] . '<br />'; if ($config['avatar_gallery_path'] != '') { echo 'Avatar gallery folder permissions: ' . substr(decoct(fileperms($phpbb_root_path . $config['avatar_gallery_path'])), 2) . ' <br />'; } $can_upload = $config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? 'Yes' : 'No'; echo 'Can upload avatar: ' . $can_upload . '<br /><br />'; } if ($chk_cookies == 'Yes') { echo '<strong>[b]Cookie Settings[/b]</strong><br />'; echo 'Cookie domain: ' . $config['cookie_domain'] . '<br />'; echo 'Cookie name: ' . $config['cookie_name'] . '<br />'; echo 'Cookie path: ' . $config['cookie_path'] . '<br />'; echo 'Cookie secure: ' . ($config['cookie_secure'] ? 'Yes' : 'No') . '<br /><br />'; $sql = 'SELECT config_name, config_value FROM ' . CONFIG_TABLE . ' WHERE config_name = "cookie_domain" OR config_name = "cookie_name" OR config_name = "cookie_path" OR config_name = "cookie_secure"'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { echo 'DB ' . $row['config_name'] . ': ' . $row['config_value'] . '<br />'; } $db->sql_freeresult($result);
/** * Going through a config array and validate values, writing errors to $error. The validation method accepts parameters separated by ':' for string and int. * The first parameter defines the type to be used, the second the lower bound and the third the upper bound. Only the type is required. */ function validate_config_vars($config_vars, &$cfg_array, &$error) { global $phpbb_root_path, $user, $phpbb_dispatcher; $type = 0; $min = 1; $max = 2; foreach ($config_vars as $config_name => $config_definition) { if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) { continue; } if (!isset($config_definition['validate'])) { continue; } $validator = explode(':', $config_definition['validate']); // Validate a bit. ;) (0 = type, 1 = min, 2= max) switch ($validator[$type]) { case 'string': $length = utf8_strlen($cfg_array[$config_name]); // the column is a VARCHAR $validator[$max] = isset($validator[$max]) ? min(255, $validator[$max]) : 255; if (isset($validator[$min]) && $length < $validator[$min]) { $error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]); } else { if (isset($validator[$max]) && $length > $validator[2]) { $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]); } } break; case 'bool': $cfg_array[$config_name] = $cfg_array[$config_name] ? 1 : 0; break; case 'int': $cfg_array[$config_name] = (int) $cfg_array[$config_name]; if (isset($validator[$min]) && $cfg_array[$config_name] < $validator[$min]) { $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], $validator[$min]); } else { if (isset($validator[$max]) && $cfg_array[$config_name] > $validator[$max]) { $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$config_definition['lang']], $validator[$max]); } } if (strpos($config_name, '_max') !== false) { // Min/max pairs of settings should ensure that min <= max // Replace _max with _min to find the name of the minimum // corresponding configuration variable $min_name = str_replace('_max', '_min', $config_name); if (isset($cfg_array[$min_name]) && is_numeric($cfg_array[$min_name]) && $cfg_array[$config_name] < $cfg_array[$min_name]) { // A minimum value exists and the maximum value is less than it $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], (int) $cfg_array[$min_name]); } } break; case 'email': if (!preg_match('/^' . get_preg_expression('email') . '$/i', $cfg_array[$config_name])) { $error[] = $user->lang['EMAIL_INVALID_EMAIL']; } break; // Absolute path // Absolute path case 'script_path': if (!$cfg_array[$config_name]) { break; } $destination = str_replace('\\', '/', $cfg_array[$config_name]); if ($destination !== '/') { // Adjust destination path (no trailing slash) if (substr($destination, -1, 1) == '/') { $destination = substr($destination, 0, -1); } $destination = str_replace(array('../', './'), '', $destination); if ($destination[0] != '/') { $destination = '/' . $destination; } } $cfg_array[$config_name] = trim($destination); break; // Absolute path // Absolute path case 'lang': if (!$cfg_array[$config_name]) { break; } $cfg_array[$config_name] = basename($cfg_array[$config_name]); if (!file_exists($phpbb_root_path . 'language/' . $cfg_array[$config_name] . '/')) { $error[] = $user->lang['WRONG_DATA_LANG']; } break; // Relative path (appended $phpbb_root_path) // Relative path (appended $phpbb_root_path) case 'rpath': case 'rwpath': if (!$cfg_array[$config_name]) { break; } $destination = $cfg_array[$config_name]; // Adjust destination path (no trailing slash) if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') { $destination = substr($destination, 0, -1); } $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) { $destination = ''; } $cfg_array[$config_name] = trim($destination); // Absolute file path // Absolute file path case 'absolute_path': case 'absolute_path_writable': // Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir... // Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir... case 'path': case 'wpath': if (!$cfg_array[$config_name]) { break; } $cfg_array[$config_name] = trim($cfg_array[$config_name]); // Make sure no NUL byte is present... if (strpos($cfg_array[$config_name], "") !== false || strpos($cfg_array[$config_name], '%00') !== false) { $cfg_array[$config_name] = ''; break; } $path = in_array($config_definition['validate'], array('wpath', 'path', 'rpath', 'rwpath')) ? $phpbb_root_path . $cfg_array[$config_name] : $cfg_array[$config_name]; if (!file_exists($path)) { $error[] = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $cfg_array[$config_name]); } if (file_exists($path) && !is_dir($path)) { $error[] = sprintf($user->lang['DIRECTORY_NOT_DIR'], $cfg_array[$config_name]); } // Check if the path is writable if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath' || $config_definition['validate'] === 'absolute_path_writable') { if (file_exists($path) && !phpbb_is_writable($path)) { $error[] = sprintf($user->lang['DIRECTORY_NOT_WRITABLE'], $cfg_array[$config_name]); } } break; default: /** * Validate a config value * * @event core.validate_config_variable * @var array cfg_array Array with config values * @var string config_name Name of the config we validate * @var array config_definition Array with the options for * this config * @var array error Array of errors, the errors should * be strings only, language keys are * not replaced afterwards * @since 3.1.0-a1 */ $vars = array('cfg_array', 'config_name', 'config_definition', 'error'); extract($phpbb_dispatcher->trigger_event('core.validate_config_variable', compact($vars))); break; } } return; }
/** * Test if a file/directory is writable * * This function calls the native is_writable() when not running under * Windows and it is not disabled. * * @param string $file Path to perform write test on * @return bool True when the path is writable, otherwise false. */ function phpbb_is_writable($file) { if (strtolower(substr(PHP_OS, 0, 3)) === 'win' || !function_exists('is_writable')) { if (file_exists($file)) { // Canonicalise path to absolute path $file = phpbb_realpath($file); if (is_dir($file)) { // Test directory by creating a file inside the directory $result = @tempnam($file, 'i_w'); if (is_string($result) && file_exists($result)) { unlink($result); // Ensure the file is actually in the directory (returned realpathed) return strpos($result, $file) === 0 ? true : false; } } else { $handle = @fopen($file, 'r+'); if (is_resource($handle)) { fclose($handle); return true; } } } else { // file does not exist test if we can write to the directory $dir = dirname($file); if (file_exists($dir) && is_dir($dir) && phpbb_is_writable($dir)) { return true; } } return false; } else { return is_writable($file); } }
/** * Writes the config file to disk, or if unable to do so offers alternative methods */ function create_config_file($mode, $sub) { global $lang, $template, $phpbb_root_path, $phpEx; $this->page_title = $lang['STAGE_CONFIG_FILE']; // Obtain any submitted data $data = $this->get_submitted_data(); if ($data['dbms'] == '') { // Someone's been silly and tried calling this page direct // So we send them back to the start to do it again properly $this->p_master->redirect("index.$phpEx?mode=install"); } $s_hidden_fields = ($data['img_imagick']) ? '<input type="hidden" name="img_imagick" value="' . addslashes($data['img_imagick']) . '" />' : ''; $s_hidden_fields .= '<input type="hidden" name="language" value="' . $data['language'] . '" />'; $written = false; // Create a list of any PHP modules we wish to have loaded $load_extensions = array(); $available_dbms = get_available_dbms($data['dbms']); $check_exts = array_merge(array($available_dbms[$data['dbms']]['MODULE']), $this->php_dlls_other); foreach ($check_exts as $dll) { if (!@extension_loaded($dll)) { if (!can_load_dll($dll)) { continue; } $load_extensions[] = $dll . '.' . PHP_SHLIB_SUFFIX; } } // Create a lock file to indicate that there is an install in progress $fp = @fopen($phpbb_root_path . 'cache/install_lock', 'wb'); if ($fp === false) { // We were unable to create the lock file - abort $this->p_master->error($lang['UNABLE_WRITE_LOCK'], __LINE__, __FILE__); } @fclose($fp); @chmod($phpbb_root_path . 'cache/install_lock', 0777); $load_extensions = implode(',', $load_extensions); // Time to convert the data provided into a config file $config_data = "<?php\n"; $config_data .= "// phpBB 3.0.x auto-generated configuration file\n// Do not change anything in this file!\n"; $config_data_array = array( 'dbms' => $available_dbms[$data['dbms']]['DRIVER'], 'dbhost' => $data['dbhost'], 'dbport' => $data['dbport'], 'dbname' => $data['dbname'], 'dbuser' => $data['dbuser'], 'dbpasswd' => htmlspecialchars_decode($data['dbpasswd']), 'table_prefix' => $data['table_prefix'], 'acm_type' => 'file', 'load_extensions' => $load_extensions, ); foreach ($config_data_array as $key => $value) { $config_data .= "\${$key} = '" . str_replace("'", "\\'", str_replace('\\', '\\\\', $value)) . "';\n"; } unset($config_data_array); $config_data .= "\n@define('PHPBB_INSTALLED', true);\n"; $config_data .= "// @define('DEBUG', true);\n"; $config_data .= "// @define('DEBUG_EXTRA', true);\n"; $config_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused! // Attempt to write out the config file directly. If it works, this is the easiest way to do it ... if ((file_exists($phpbb_root_path . 'config.' . $phpEx) && phpbb_is_writable($phpbb_root_path . 'config.' . $phpEx)) || phpbb_is_writable($phpbb_root_path)) { // Assume it will work ... if nothing goes wrong below $written = true; if (!($fp = @fopen($phpbb_root_path . 'config.' . $phpEx, 'w'))) { // Something went wrong ... so let's try another method $written = false; } if (!(@fwrite($fp, $config_data))) { // Something went wrong ... so let's try another method $written = false; } @fclose($fp); if ($written) { // We may revert back to chmod() if we see problems with users not able to change their config.php file directly phpbb_chmod($phpbb_root_path . 'config.' . $phpEx, CHMOD_READ); } } if (isset($_POST['dldone'])) { // Do a basic check to make sure that the file has been uploaded // Note that all we check is that the file has _something_ in it // We don't compare the contents exactly - if they can't upload // a single file correctly, it's likely they will have other problems.... if (filesize($phpbb_root_path . 'config.' . $phpEx) > 10) { $written = true; } } $config_options = array_merge($this->db_config_options, $this->admin_config_options); foreach ($config_options as $config_key => $vars) { if (!is_array($vars)) { continue; } $s_hidden_fields .= '<input type="hidden" name="' . $config_key . '" value="' . $data[$config_key] . '" />'; } if (!$written) { // OK, so it didn't work let's try the alternatives if (isset($_POST['dlconfig'])) { // They want a copy of the file to download, so send the relevant headers and dump out the data header("Content-Type: text/x-delimtext; name=\"config.$phpEx\""); header("Content-disposition: attachment; filename=config.$phpEx"); echo $config_data; exit; } // The option to download the config file is always available, so output it here $template->assign_vars(array( 'BODY' => $lang['CONFIG_FILE_UNABLE_WRITE'], 'L_DL_CONFIG' => $lang['DL_CONFIG'], 'L_DL_CONFIG_EXPLAIN' => $lang['DL_CONFIG_EXPLAIN'], 'L_DL_DONE' => $lang['DONE'], 'L_DL_DOWNLOAD' => $lang['DL_DOWNLOAD'], 'S_HIDDEN' => $s_hidden_fields, 'S_SHOW_DOWNLOAD' => true, 'U_ACTION' => $this->p_master->module_url . "?mode=$mode&sub=config_file", )); return; } else { $template->assign_vars(array( 'BODY' => $lang['CONFIG_FILE_WRITTEN'], 'L_SUBMIT' => $lang['NEXT_STEP'], 'S_HIDDEN' => $s_hidden_fields, 'U_ACTION' => $this->p_master->module_url . "?mode=$mode&sub=advanced", )); return; } }
function tt_login_success() { global $config, $db, $user, $phpbb_root_path, $phpEx, $user_info, $auth, $register; header('Set-Cookie: mobiquo_a=0'); header('Set-Cookie: mobiquo_b=0'); header('Set-Cookie: mobiquo_c=0'); $result = $user->session_create($user_info['user_id'], 0, true, 1); if ($result) { $usergroup_id = array(); $auth->acl($user->data); //add tapatalk_users here,for push service if (push_table_exists()) { global $table_prefix; $sql = "SELECT * FROM " . $table_prefix . "tapatalk_users where userid = '" . $user->data['user_id'] . "'"; $result = $db->sql_query($sql); $userInfo = $db->sql_fetchrow($result); $db->sql_freeresult($result); $time = time(); if (empty($userInfo)) { $sql_data[$table_prefix . "tapatalk_users"]['sql'] = array('userid' => $user->data['user_id'], 'announcement' => 1, 'pm' => 1, 'subscribe' => 1, 'quote' => 1, 'tag' => 1, 'newtopic' => 1, 'updated' => time()); $sql = 'INSERT INTO ' . $table_prefix . "tapatalk_users" . ' ' . $db->sql_build_array('INSERT', $sql_data[$table_prefix . "tapatalk_users"]['sql']); $db->sql_query($sql); } } // Compatibility with mod NV who was here if (file_exists($phpbb_root_path . 'includes/mods/who_was_here.' . $phpEx)) { include_once $phpbb_root_path . 'includes/mods/who_was_here.' . $phpEx; if (class_exists('phpbb_mods_who_was_here') && method_exists('phpbb_mods_who_was_here', 'update_session')) { @phpbb_mods_who_was_here::update_session(); } } if ($config['max_attachments'] == 0) { $config['max_attachments'] = 100; } $usergroup_id[] = new xmlrpcval($user->data['group_id']); $can_readpm = $config['allow_privmsg'] && $auth->acl_get('u_readpm') && ($user->data['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')); $can_sendpm = $config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($user->data['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')); $can_upload = $config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && (function_exists('phpbb_is_writable') ? phpbb_is_writable($phpbb_root_path . $config['avatar_path']) : 1) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false; $can_search = $auth->acl_get('u_search') && $auth->acl_getf_global('f_search') && $config['load_search']; $can_whosonline = $auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'); $max_filesize = $config['max_filesize'] === '0' || $config['max_filesize'] > 10485760 ? 10485760 : $config['max_filesize']; $userPushType = array('pm' => 1, 'newtopic' => 1, 'sub' => 1, 'tag' => 1, 'quote' => 1); $push_type = array(); foreach ($userPushType as $name => $value) { $push_type[] = new xmlrpcval(array('name' => new xmlrpcval($name, 'string'), 'value' => new xmlrpcval($value, 'boolean')), 'struct'); } $response = new xmlrpcval(array('result' => new xmlrpcval(true, 'boolean'), 'user_id' => new xmlrpcval($user->data['user_id'], 'string'), 'username' => new xmlrpcval(basic_clean($user->data['username']), 'base64'), 'email' => new xmlrpcval($user->data['user_email'], 'base64'), 'user_type' => check_return_user_type($user->data['username']), 'usergroup_id' => new xmlrpcval($usergroup_id, 'array'), 'ignored_uids' => new xmlrpcval(implode(',', tt_get_ignore_users($user->data['user_id'])), 'string'), 'icon_url' => new xmlrpcval(get_user_avatar_url($user->data['user_avatar'], $user->data['user_avatar_type']), 'string'), 'post_count' => new xmlrpcval($user->data['user_posts'], 'int'), 'can_pm' => new xmlrpcval($can_readpm, 'boolean'), 'can_send_pm' => new xmlrpcval($can_sendpm, 'boolean'), 'can_moderate' => new xmlrpcval($auth->acl_get('m_') || $auth->acl_getf_global('m_'), 'boolean'), 'max_attachment' => new xmlrpcval($config['max_attachments'], 'int'), 'max_png_size' => new xmlrpcval($max_filesize, 'int'), 'max_jpg_size' => new xmlrpcval($max_filesize, 'int'), 'can_search' => new xmlrpcval($can_search, 'boolean'), 'can_whosonline' => new xmlrpcval($can_whosonline, 'boolean'), 'can_upload_avatar' => new xmlrpcval($can_upload, 'boolean'), 'register' => new xmlrpcval($register, "boolean"), 'push_type' => new xmlrpcval($push_type, 'array')), 'struct'); return new xmlrpcresp($response); } }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; $user->add_lang(array('posting', 'ucp', 'acp/users')); $this->tpl_name = 'acp_users'; $this->page_title = 'ACP_USER_' . strtoupper($mode); $error = array(); $username = utf8_normalize_nfc(request_var('username', '', true)); $user_id = request_var('u', 0); $action = request_var('action', ''); $submit = isset($_POST['update']) && !isset($_POST['cancel']) ? true : false; $form_name = 'acp_users'; add_form_key($form_name); // Whois (special case) if ($action == 'whois') { include $phpbb_root_path . 'includes/functions_user.' . $phpEx; $this->page_title = 'WHOIS'; $this->tpl_name = 'simple_body'; $user_ip = request_var('user_ip', ''); $domain = gethostbyaddr($user_ip); $ipwhois = user_ipwhois($user_ip); $template->assign_vars(array('MESSAGE_TITLE' => sprintf($user->lang['IP_WHOIS_FOR'], $domain), 'MESSAGE_TEXT' => nl2br($ipwhois))); return; } // Show user selection mask if (!$username && !$user_id) { $this->page_title = 'SELECT_USER'; $template->assign_vars(array('U_ACTION' => $this->u_action, 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_USER' => true, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=select_user&field=username&select_single=true'))); return; } if (!$user_id) { $sql = 'SELECT user_id FROM ' . USERS_TABLE . "\n\t\t\t\tWHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'"; $result = $db->sql_query($sql); $user_id = (int) $db->sql_fetchfield('user_id'); $db->sql_freeresult($result); if (!$user_id) { trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); } } // Generate content for all modes $sql = 'SELECT u.*, s.* FROM ' . USERS_TABLE . ' u LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id) WHERE u.user_id = ' . $user_id . ' ORDER BY s.session_time DESC'; $result = $db->sql_query_limit($sql, 1); $user_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$user_row) { trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); } // Generate overall "header" for user admin $s_form_options = ''; // Build modes dropdown list $sql = 'SELECT module_mode, module_auth FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_basename = 'users'\n\t\t\t\tAND module_enabled = 1\n\t\t\t\tAND module_class = 'acp'\n\t\t\tORDER BY left_id, module_mode"; $result = $db->sql_query($sql); $dropdown_modes = array(); while ($row = $db->sql_fetchrow($result)) { if (!$this->p_master->module_auth($row['module_auth'])) { continue; } $dropdown_modes[$row['module_mode']] = true; } $db->sql_freeresult($result); foreach ($dropdown_modes as $module_mode => $null) { $selected = $mode == $module_mode ? ' selected="selected"' : ''; $s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</option>'; } $template->assign_vars(array('U_BACK' => $this->u_action, 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$id}&u={$user_id}"), 'U_ACTION' => $this->u_action . '&u=' . $user_id, 'S_FORM_OPTIONS' => $s_form_options, 'MANAGED_USERNAME' => $user_row['username'])); // Prevent normal users/admins change/view founders if they are not a founder by themselves if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER) { trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action), E_USER_WARNING); } switch ($mode) { case 'overview': include $phpbb_root_path . 'includes/functions_user.' . $phpEx; $user->add_lang('acp/ban'); $delete = request_var('delete', 0); $delete_type = request_var('delete_type', ''); $ip = request_var('ip', 'ip'); if ($submit) { // You can't delete the founder if ($delete && $user_row['user_type'] != USER_FOUNDER) { if (!$auth->acl_get('a_userdel')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } // Check if the user wants to remove himself or the guest user account if ($user_id == ANONYMOUS) { trigger_error($user->lang['CANNOT_REMOVE_ANONYMOUS'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if ($user_id == $user->data['user_id']) { trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if ($delete_type) { if (confirm_box(true)) { user_delete($delete_type, $user_id, $user_row['username']); add_log('admin', 'LOG_USER_DELETED', $user_row['username']); trigger_error($user->lang['USER_DELETED'] . adm_back_link($this->u_action)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true, 'delete' => 1, 'delete_type' => $delete_type))); } } else { trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } } // Handle quicktool actions switch ($action) { case 'banuser': case 'banemail': case 'banip': if ($user_id == $user->data['user_id']) { trigger_error($user->lang['CANNOT_BAN_YOURSELF'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if ($user_id == ANONYMOUS) { trigger_error($user->lang['CANNOT_BAN_ANONYMOUS'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if ($user_row['user_type'] == USER_FOUNDER) { trigger_error($user->lang['CANNOT_BAN_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } $ban = array(); switch ($action) { case 'banuser': $ban[] = $user_row['username']; $reason = 'USER_ADMIN_BAN_NAME_REASON'; $log = 'LOG_USER_BAN_USER'; break; case 'banemail': $ban[] = $user_row['user_email']; $reason = 'USER_ADMIN_BAN_EMAIL_REASON'; $log = 'LOG_USER_BAN_EMAIL'; break; case 'banip': $ban[] = $user_row['user_ip']; $sql = 'SELECT DISTINCT poster_ip FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $ban[] = $row['poster_ip']; } $db->sql_freeresult($result); $reason = 'USER_ADMIN_BAN_IP_REASON'; $log = 'LOG_USER_BAN_IP'; break; } $ban_reason = utf8_normalize_nfc(request_var('ban_reason', $user->lang[$reason], true)); $ban_give_reason = utf8_normalize_nfc(request_var('ban_give_reason', '', true)); // Log not used at the moment, we simply utilize the ban function. $result = user_ban(substr($action, 3), $ban, 0, 0, 0, $ban_reason, $ban_give_reason); trigger_error(($result === false ? $user->lang['BAN_ALREADY_ENTERED'] : $user->lang['BAN_SUCCESSFUL']) . adm_back_link($this->u_action . '&u=' . $user_id)); break; case 'reactivate': if ($user_id == $user->data['user_id']) { trigger_error($user->lang['CANNOT_FORCE_REACT_YOURSELF'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if ($user_row['user_type'] == USER_FOUNDER) { trigger_error($user->lang['CANNOT_FORCE_REACT_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if ($user_row['user_type'] == USER_IGNORE) { trigger_error($user->lang['CANNOT_FORCE_REACT_BOT'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if ($config['email_enable']) { include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx; $server_url = generate_board_url(); $user_actkey = gen_rand_string(mt_rand(6, 10)); $email_template = $user_row['user_type'] == USER_NORMAL ? 'user_reactivate_account' : 'user_resend_inactive'; if ($user_row['user_type'] == USER_NORMAL) { user_active_flip('deactivate', $user_id, INACTIVE_REMIND); $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tSET user_actkey = '" . $db->sql_escape($user_actkey) . "'\n\t\t\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}"; $db->sql_query($sql); } else { // Grabbing the last confirm key - we only send a reminder $sql = 'SELECT user_actkey FROM ' . USERS_TABLE . ' WHERE user_id = ' . $user_id; $result = $db->sql_query($sql); $user_actkey = (string) $db->sql_fetchfield('user_actkey'); $db->sql_freeresult($result); } $messenger = new messenger(false); $messenger->template($email_template, $user_row['user_lang']); $messenger->to($user_row['user_email'], $user_row['username']); $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']); $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']); $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']); $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip); $messenger->assign_vars(array('WELCOME_MSG' => htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])), 'USERNAME' => htmlspecialchars_decode($user_row['username']), 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user_row['user_id']}&k={$user_actkey}")); $messenger->send(NOTIFY_EMAIL); add_log('admin', 'LOG_USER_REACTIVATE', $user_row['username']); add_log('user', $user_id, 'LOG_USER_REACTIVATE_USER'); trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&u=' . $user_id)); } break; case 'active': if ($user_id == $user->data['user_id']) { // It is only deactivation since the user is already activated (else he would not have reached this page) trigger_error($user->lang['CANNOT_DEACTIVATE_YOURSELF'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if ($user_row['user_type'] == USER_FOUNDER) { trigger_error($user->lang['CANNOT_DEACTIVATE_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if ($user_row['user_type'] == USER_IGNORE) { trigger_error($user->lang['CANNOT_DEACTIVATE_BOT'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } user_active_flip('flip', $user_id); if ($user_row['user_type'] == USER_INACTIVE) { if ($config['require_activation'] == USER_ACTIVATION_ADMIN) { include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx; $messenger = new messenger(false); $messenger->template('admin_welcome_activated', $user_row['user_lang']); $messenger->to($user_row['user_email'], $user_row['username']); $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']); $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']); $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']); $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip); $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($user_row['username']))); $messenger->send(NOTIFY_EMAIL); } } $message = $user_row['user_type'] == USER_INACTIVE ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED'; $log = $user_row['user_type'] == USER_INACTIVE ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE'; add_log('admin', $log, $user_row['username']); add_log('user', $user_id, $log . '_USER'); trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&u=' . $user_id)); break; case 'delsig': if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } $sql_ary = array('user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => ''); $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}"; $db->sql_query($sql); add_log('admin', 'LOG_USER_DEL_SIG', $user_row['username']); add_log('user', $user_id, 'LOG_USER_DEL_SIG_USER'); trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&u=' . $user_id)); break; case 'delavatar': if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } $sql_ary = array('user_avatar' => '', 'user_avatar_type' => 0, 'user_avatar_width' => 0, 'user_avatar_height' => 0); $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}"; $db->sql_query($sql); // Delete old avatar if present if ($user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY) { avatar_delete('user', $user_row); } add_log('admin', 'LOG_USER_DEL_AVATAR', $user_row['username']); add_log('user', $user_id, 'LOG_USER_DEL_AVATAR_USER'); trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&u=' . $user_id)); break; case 'delposts': if (confirm_box(true)) { // Delete posts, attachments, etc. delete_posts('poster_id', $user_id); add_log('admin', 'LOG_USER_DEL_POSTS', $user_row['username']); trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&u=' . $user_id)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true))); } break; case 'delattach': if (confirm_box(true)) { delete_attachments('user', $user_id); add_log('admin', 'LOG_USER_DEL_ATTACH', $user_row['username']); trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&u=' . $user_id)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true))); } break; case 'deloutbox': if (confirm_box(true)) { $msg_ids = array(); $lang = 'EMPTY'; $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TO_TABLE . "\n\t\t\t\t\t\t\t\t\tWHERE author_id = {$user_id}\n\t\t\t\t\t\t\t\t\t\tAND folder_id = " . PRIVMSGS_OUTBOX; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { if (!function_exists('delete_pm')) { include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx; } do { $msg_ids[] = (int) $row['msg_id']; } while ($row = $db->sql_fetchrow($result)); $db->sql_freeresult($result); delete_pm($user_id, $msg_ids, PRIVMSGS_OUTBOX); add_log('admin', 'LOG_USER_DEL_OUTBOX', $user_row['username']); $lang = 'EMPTIED'; } $db->sql_freeresult($result); trigger_error($user->lang['USER_OUTBOX_' . $lang] . adm_back_link($this->u_action . '&u=' . $user_id)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true))); } break; case 'moveposts': if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } $user->add_lang('acp/forums'); $new_forum_id = request_var('new_f', 0); if (!$new_forum_id) { $this->page_title = 'USER_ADMIN_MOVE_POSTS'; $template->assign_vars(array('S_SELECT_FORUM' => true, 'U_ACTION' => $this->u_action . "&action={$action}&u={$user_id}", 'U_BACK' => $this->u_action . "&u={$user_id}", 'S_FORUM_OPTIONS' => make_forum_select(false, false, false, true))); return; } // Is the new forum postable to? $sql = 'SELECT forum_name, forum_type FROM ' . FORUMS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE forum_id = {$new_forum_id}"; $result = $db->sql_query($sql); $forum_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$forum_info) { trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if ($forum_info['forum_type'] != FORUM_POST) { trigger_error($user->lang['MOVE_POSTS_NO_POSTABLE_FORUM'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } // Two stage? // Move topics comprising only posts from this user $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array(); $forum_id_ary = array($new_forum_id); $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\t\t\t\tAND forum_id <> {$new_forum_id}\n\t\t\t\t\t\t\t\tGROUP BY topic_id"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $topic_id_ary[$row['topic_id']] = $row['total_posts']; } $db->sql_freeresult($result); if (sizeof($topic_id_ary)) { $sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real, topic_attachment FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) { $move_topic_ary[] = $row['topic_id']; } else { $move_post_ary[$row['topic_id']]['title'] = $row['topic_title']; $move_post_ary[$row['topic_id']]['attach'] = $row['topic_attachment'] ? 1 : 0; } $forum_id_ary[] = $row['forum_id']; } $db->sql_freeresult($result); } // Entire topic comprises posts by this user, move these topics if (sizeof($move_topic_ary)) { move_topics($move_topic_ary, $new_forum_id, false); } if (sizeof($move_post_ary)) { // Create new topic // Update post_ids, report_ids, attachment_ids foreach ($move_post_ary as $topic_id => $post_ary) { // Create new topic $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array('topic_poster' => $user_id, 'topic_time' => time(), 'forum_id' => $new_forum_id, 'icon_id' => 0, 'topic_approved' => 1, 'topic_title' => $post_ary['title'], 'topic_first_poster_name' => $user_row['username'], 'topic_type' => POST_NORMAL, 'topic_time_limit' => 0, 'topic_attachment' => $post_ary['attach'])); $db->sql_query($sql); $new_topic_id = $db->sql_nextid(); // Move posts $sql = 'UPDATE ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tSET forum_id = {$new_forum_id}, topic_id = {$new_topic_id}\n\t\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\t\t\t\t\t\tAND poster_id = {$user_id}"; $db->sql_query($sql); if ($post_ary['attach']) { $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\tSET topic_id = {$new_topic_id}\n\t\t\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\t\t\t\t\t\t\tAND poster_id = {$user_id}"; $db->sql_query($sql); } $new_topic_id_ary[] = $new_topic_id; } } $forum_id_ary = array_unique($forum_id_ary); $topic_id_ary = array_unique(array_merge(array_keys($topic_id_ary), $new_topic_id_ary)); if (sizeof($topic_id_ary)) { sync('topic_reported', 'topic_id', $topic_id_ary); sync('topic', 'topic_id', $topic_id_ary); } if (sizeof($forum_id_ary)) { sync('forum', 'forum_id', $forum_id_ary, false, true); } add_log('admin', 'LOG_USER_MOVE_POSTS', $user_row['username'], $forum_info['forum_name']); add_log('user', $user_id, 'LOG_USER_MOVE_POSTS_USER', $forum_info['forum_name']); trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&u=' . $user_id)); break; case 'leave_nr': if (confirm_box(true)) { remove_newly_registered($user_id, $user_row); add_log('admin', 'LOG_USER_REMOVED_NR', $user_row['username']); trigger_error($user->lang['USER_LIFTED_NR'] . adm_back_link($this->u_action . '&u=' . $user_id)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true))); } break; } // Handle registration info updates $data = array('username' => utf8_normalize_nfc(request_var('user', $user_row['username'], true)), 'user_founder' => request_var('user_founder', $user_row['user_type'] == USER_FOUNDER ? 1 : 0), 'email' => strtolower(request_var('user_email', $user_row['user_email'])), 'email_confirm' => strtolower(request_var('email_confirm', '')), 'new_password' => request_var('new_password', '', true), 'password_confirm' => request_var('password_confirm', '', true)); // Validation data - we do not check the password complexity setting here $check_ary = array('new_password' => array(array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), array('password')), 'password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars'])); // Check username if altered if ($data['username'] != $user_row['username']) { $check_ary += array('username' => array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username', $user_row['username']))); } // Check email if altered if ($data['email'] != $user_row['user_email']) { $check_ary += array('email' => array(array('string', false, 6, 60), array('email', $user_row['user_email'])), 'email_confirm' => array('string', true, 6, 60)); } $error = validate_data($data, $check_ary); if ($data['new_password'] && $data['password_confirm'] != $data['new_password']) { $error[] = 'NEW_PASSWORD_ERROR'; } if ($data['email'] != $user_row['user_email'] && $data['email_confirm'] != $data['email']) { $error[] = 'NEW_EMAIL_ERROR'; } if (!check_form_key($form_name)) { $error[] = 'FORM_INVALID'; } // Which updates do we need to do? $update_username = $user_row['username'] != $data['username'] ? $data['username'] : false; $update_password = $data['new_password'] && !phpbb_check_hash($user_row['user_password'], $data['new_password']) ? true : false; $update_email = $data['email'] != $user_row['user_email'] ? $data['email'] : false; if (!sizeof($error)) { $sql_ary = array(); if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER) { // Only allow founders updating the founder status... if ($user->data['user_type'] == USER_FOUNDER) { // Setting a normal member to be a founder if ($data['user_founder'] && $user_row['user_type'] != USER_FOUNDER) { // Make sure the user is not setting an Inactive or ignored user to be a founder if ($user_row['user_type'] == USER_IGNORE) { trigger_error($user->lang['CANNOT_SET_FOUNDER_IGNORED'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if ($user_row['user_type'] == USER_INACTIVE) { trigger_error($user->lang['CANNOT_SET_FOUNDER_INACTIVE'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } $sql_ary['user_type'] = USER_FOUNDER; } else { if (!$data['user_founder'] && $user_row['user_type'] == USER_FOUNDER) { // Check if at least one founder is present $sql = 'SELECT user_id FROM ' . USERS_TABLE . ' WHERE user_type = ' . USER_FOUNDER . ' AND user_id <> ' . $user_id; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row) { $sql_ary['user_type'] = USER_NORMAL; } else { trigger_error($user->lang['AT_LEAST_ONE_FOUNDER'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } } } } } if ($update_username !== false) { $sql_ary['username'] = $update_username; $sql_ary['username_clean'] = utf8_clean_string($update_username); add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $user_row['username'], $update_username); } if ($update_email !== false) { $sql_ary += array('user_email' => $update_email, 'user_email_hash' => phpbb_email_hash($update_email)); add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email); } if ($update_password) { $sql_ary += array('user_password' => phpbb_hash($data['new_password']), 'user_passchg' => time(), 'user_pass_convert' => 0); $user->reset_login_keys($user_id); add_log('user', $user_id, 'LOG_USER_NEW_PASSWORD', $user_row['username']); } if (sizeof($sql_ary)) { $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $user_id; $db->sql_query($sql); } if ($update_username) { user_update_name($user_row['username'], $update_username); } // Let the users permissions being updated $auth->acl_clear_prefetch($user_id); add_log('admin', 'LOG_USER_USER_UPDATE', $data['username']); trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); } // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); } if ($user_id == $user->data['user_id']) { $quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX'); if ($user_row['user_new']) { $quick_tool_ary['leave_nr'] = 'LEAVE_NR'; } } else { $quick_tool_ary = array(); if ($user_row['user_type'] != USER_FOUNDER) { $quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP'); } if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE) { $quick_tool_ary += array('active' => $user_row['user_type'] == USER_INACTIVE ? 'ACTIVATE' : 'DEACTIVATE'); } $quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX'); if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE)) { $quick_tool_ary['reactivate'] = 'FORCE'; } if ($user_row['user_new']) { $quick_tool_ary['leave_nr'] = 'LEAVE_NR'; } } $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>'; foreach ($quick_tool_ary as $value => $lang) { $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>'; } if ($config['load_onlinetrack']) { $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline FROM ' . SESSIONS_TABLE . "\n\t\t\t\t\t\tWHERE session_user_id = {$user_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $user_row['session_time'] = isset($row['session_time']) ? $row['session_time'] : 0; $user_row['session_viewonline'] = isset($row['session_viewonline']) ? $row['session_viewonline'] : 0; unset($row); } $last_visit = !empty($user_row['session_time']) ? $user_row['session_time'] : $user_row['user_lastvisit']; $inactive_reason = ''; if ($user_row['user_type'] == USER_INACTIVE) { $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN']; switch ($user_row['user_inactive_reason']) { case INACTIVE_REGISTER: $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER']; break; case INACTIVE_PROFILE: $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE']; break; case INACTIVE_MANUAL: $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL']; break; case INACTIVE_REMIND: $inactive_reason = $user->lang['INACTIVE_REASON_REMIND']; break; } } // Posts in Queue $sql = 'SELECT COUNT(post_id) as posts_in_queue FROM ' . POSTS_TABLE . ' WHERE poster_id = ' . $user_id . ' AND post_approved = 0'; $result = $db->sql_query($sql); $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue'); $db->sql_freeresult($result); $template->assign_vars(array('L_NAME_CHARS_EXPLAIN' => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']), 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($user->lang[$config['pass_complex'] . '_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']), 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $user_row['posts_in_queue']), 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false, 'S_OVERVIEW' => true, 'S_USER_IP' => $user_row['user_ip'] ? true : false, 'S_USER_FOUNDER' => $user_row['user_type'] == USER_FOUNDER ? true : false, 'S_ACTION_OPTIONS' => $s_action_options, 'S_OWN_ACCOUNT' => $user_id == $user->data['user_id'] ? true : false, 'S_USER_INACTIVE' => $user_row['user_type'] == USER_INACTIVE ? true : false, 'U_SHOW_IP' => $this->u_action . "&u={$user_id}&ip=" . ($ip == 'ip' ? 'hostname' : 'ip'), 'U_WHOIS' => $this->u_action . "&action=whois&user_ip={$user_row['user_ip']}", 'U_MCP_QUEUE' => $auth->acl_getf_global('m_approve') ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue', true, $user->session_id) : '', 'U_SWITCH_PERMISSIONS' => $auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_row['user_id'] ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", "mode=switch_perm&u={$user_row['user_id']}&hash=" . generate_link_hash('switchperm')) : '', 'POSTS_IN_QUEUE' => $user_row['posts_in_queue'], 'USER' => $user_row['username'], 'USER_REGISTERED' => $user->format_date($user_row['user_regdate']), 'REGISTERED_IP' => $ip == 'hostname' ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'], 'USER_LASTACTIVE' => $last_visit ? $user->format_date($last_visit) : ' - ', 'USER_EMAIL' => $user_row['user_email'], 'USER_WARNINGS' => $user_row['user_warnings'], 'USER_POSTS' => $user_row['user_posts'], 'USER_INACTIVE_REASON' => $inactive_reason)); break; case 'feedback': $user->add_lang('mcp'); // Set up general vars $start = request_var('start', 0); $deletemark = isset($_POST['delmarked']) ? true : false; $deleteall = isset($_POST['delall']) ? true : false; $marked = request_var('mark', array(0)); $message = utf8_normalize_nfc(request_var('message', '', true)); // Sort keys $sort_days = request_var('st', 0); $sort_key = request_var('sk', 't'); $sort_dir = request_var('sd', 'd'); // Delete entries if requested and able if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) { if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } $where_sql = ''; if ($deletemark && $marked) { $sql_in = array(); foreach ($marked as $mark) { $sql_in[] = $mark; } $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in); unset($sql_in); } if ($where_sql || $deleteall) { $sql = 'DELETE FROM ' . LOG_TABLE . ' WHERE log_type = ' . LOG_USERS . "\n\t\t\t\t\t\t\tAND reportee_id = {$user_id}\n\t\t\t\t\t\t\t{$where_sql}"; $db->sql_query($sql); add_log('admin', 'LOG_CLEAR_USER', $user_row['username']); } } if ($submit && $message) { if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } add_log('admin', 'LOG_USER_FEEDBACK', $user_row['username']); add_log('mod', 0, 0, 'LOG_USER_FEEDBACK', $user_row['username']); add_log('user', $user_id, 'LOG_USER_GENERAL', $message); trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&u=' . $user_id)); } // Sorting $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']); $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation'); $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = ''; gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); // Define where and sort sql for use in displaying logs $sql_where = $sort_days ? time() - $sort_days * 86400 : 0; $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC'); // Grab log data $log_data = array(); $log_count = 0; view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort); $template->assign_vars(array('S_FEEDBACK' => true, 'S_ON_PAGE' => on_page($log_count, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&u={$user_id}&{$u_sort_param}", $log_count, $config['topics_per_page'], $start, true), 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs'))); foreach ($log_data as $row) { $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => nl2br($row['action']), 'ID' => $row['id'])); } break; case 'warnings': $user->add_lang('mcp'); // Set up general vars $start = request_var('start', 0); $deletemark = isset($_POST['delmarked']) ? true : false; $deleteall = isset($_POST['delall']) ? true : false; $confirm = isset($_POST['confirm']) ? true : false; $marked = request_var('mark', array(0)); $message = utf8_normalize_nfc(request_var('message', '', true)); // Sort keys $sort_days = request_var('st', 0); $sort_key = request_var('sk', 't'); $sort_dir = request_var('sd', 'd'); // Delete entries if requested and able if ($deletemark || $deleteall || $confirm) { if (confirm_box(true)) { $where_sql = ''; $deletemark = request_var('delmarked', 0); $deleteall = request_var('delall', 0); if ($deletemark && $marked) { $where_sql = ' AND ' . $db->sql_in_set('warning_id', array_values($marked)); } if ($where_sql || $deleteall) { $sql = 'DELETE FROM ' . WARNINGS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}\n\t\t\t\t\t\t\t\t\t{$where_sql}"; $db->sql_query($sql); if ($deleteall) { $log_warnings = $deleted_warnings = 0; } else { $num_warnings = (int) $db->sql_affectedrows(); $deleted_warnings = ' user_warnings - ' . $num_warnings; $log_warnings = $num_warnings > 2 ? 2 : $num_warnings; } $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\t\t\tSET user_warnings = {$deleted_warnings}\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}"; $db->sql_query($sql); switch ($log_warnings) { case 2: add_log('admin', 'LOG_WARNINGS_DELETED', $user_row['username'], $num_warnings); break; case 1: add_log('admin', 'LOG_WARNING_DELETED', $user_row['username']); break; default: add_log('admin', 'LOG_WARNINGS_DELETED_ALL', $user_row['username']); break; } } } else { $s_hidden_fields = array('i' => $id, 'mode' => $mode, 'u' => $user_id, 'mark' => $marked); if (isset($_POST['delmarked'])) { $s_hidden_fields['delmarked'] = 1; } if (isset($_POST['delall'])) { $s_hidden_fields['delall'] = 1; } if (isset($_POST['delall']) || isset($_POST['delmarked']) && sizeof($marked)) { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields)); } } } $sql = 'SELECT w.warning_id, w.warning_time, w.post_id, l.log_operation, l.log_data, l.user_id AS mod_user_id, m.username AS mod_username, m.user_colour AS mod_user_colour FROM ' . WARNINGS_TABLE . ' w LEFT JOIN ' . LOG_TABLE . ' l ON (w.log_id = l.log_id) LEFT JOIN ' . USERS_TABLE . ' m ON (l.user_id = m.user_id) WHERE w.user_id = ' . $user_id . ' ORDER BY w.warning_time DESC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (!$row['log_operation']) { // We do not have a log-entry anymore, so there is no data available $row['action'] = $user->lang['USER_WARNING_LOG_DELETED']; } else { $row['action'] = isset($user->lang[$row['log_operation']]) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}'; if (!empty($row['log_data'])) { $log_data_ary = @unserialize($row['log_data']); $log_data_ary = $log_data_ary === false ? array() : $log_data_ary; if (isset($user->lang[$row['log_operation']])) { // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array // It doesn't matter if we add more arguments than placeholders if (substr_count($row['action'], '%') - sizeof($log_data_ary) > 0) { $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($row['action'], '%') - sizeof($log_data_ary), '')); } $row['action'] = vsprintf($row['action'], $log_data_ary); $row['action'] = bbcode_nl2br(censor_text($row['action'])); } else { if (!empty($log_data_ary)) { $row['action'] .= '<br />' . implode('', $log_data_ary); } } } } $template->assign_block_vars('warn', array('ID' => $row['warning_id'], 'USERNAME' => $row['log_operation'] ? get_username_string('full', $row['mod_user_id'], $row['mod_username'], $row['mod_user_colour']) : '-', 'ACTION' => make_clickable($row['action']), 'DATE' => $user->format_date($row['warning_time']))); } $db->sql_freeresult($result); $template->assign_vars(array('S_WARNINGS' => true)); break; case 'profile': include $phpbb_root_path . 'includes/functions_user.' . $phpEx; include $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx; $cp = new custom_profile(); $cp_data = $cp_error = array(); $sql = 'SELECT lang_id FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $user_row['iso_lang_id'] = $row['lang_id']; $data = array('icq' => request_var('icq', $user_row['user_icq']), 'aim' => request_var('aim', $user_row['user_aim']), 'msn' => request_var('msn', $user_row['user_msnm']), 'yim' => request_var('yim', $user_row['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)), 'website' => request_var('website', $user_row['user_website']), 'location' => utf8_normalize_nfc(request_var('location', $user_row['user_from'], true)), 'occupation' => utf8_normalize_nfc(request_var('occupation', $user_row['user_occ'], true)), 'interests' => utf8_normalize_nfc(request_var('interests', $user_row['user_interests'], true)), 'bday_day' => 0, 'bday_month' => 0, 'bday_year' => 0); if ($user_row['user_birthday']) { list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']); } $data['bday_day'] = request_var('bday_day', $data['bday_day']); $data['bday_month'] = request_var('bday_month', $data['bday_month']); $data['bday_year'] = request_var('bday_year', $data['bday_year']); $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']); if ($submit) { $error = validate_data($data, array('icq' => array(array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), 'msn' => array('string', true, 5, 255), 'jabber' => array(array('string', true, 5, 255), array('jabber')), 'yim' => array('string', true, 5, 255), 'website' => array(array('string', true, 12, 255), array('match', true, '#^http[s]?://(.*?\\.)*?[a-z0-9\\-]+\\.[a-z]{2,4}#i')), 'location' => array('string', true, 2, 100), 'occupation' => array('string', true, 2, 500), 'interests' => array('string', true, 2, 500), 'bday_day' => array('num', true, 1, 31), 'bday_month' => array('num', true, 1, 12), 'bday_year' => array('num', true, 1901, gmdate('Y', time())), 'user_birthday' => array('date', true))); // validate custom profile fields $cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error); if (sizeof($cp_error)) { $error = array_merge($error, $cp_error); } if (!check_form_key($form_name)) { $error[] = 'FORM_INVALID'; } if (!sizeof($error)) { $sql_ary = array('user_icq' => $data['icq'], 'user_aim' => $data['aim'], 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], 'user_from' => $data['location'], 'user_occ' => $data['occupation'], 'user_interests' => $data['interests'], 'user_birthday' => $data['user_birthday']); $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE user_id = {$user_id}"; $db->sql_query($sql); // Update Custom Fields $cp->update_profile_field_data($user_id, $cp_data); trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); } // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); } $s_birthday_day_options = '<option value="0"' . (!$data['bday_day'] ? ' selected="selected"' : '') . '>--</option>'; for ($i = 1; $i < 32; $i++) { $selected = $i == $data['bday_day'] ? ' selected="selected"' : ''; $s_birthday_day_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>"; } $s_birthday_month_options = '<option value="0"' . (!$data['bday_month'] ? ' selected="selected"' : '') . '>--</option>'; for ($i = 1; $i < 13; $i++) { $selected = $i == $data['bday_month'] ? ' selected="selected"' : ''; $s_birthday_month_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>"; } $s_birthday_year_options = ''; $now = getdate(); $s_birthday_year_options = '<option value="0"' . (!$data['bday_year'] ? ' selected="selected"' : '') . '>--</option>'; for ($i = $now['year'] - 100; $i <= $now['year']; $i++) { $selected = $i == $data['bday_year'] ? ' selected="selected"' : ''; $s_birthday_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>"; } unset($now); $template->assign_vars(array('ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], 'OCCUPATION' => $data['occupation'], 'INTERESTS' => $data['interests'], 'S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options, 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options, 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options, 'S_PROFILE' => true)); // Get additional profile fields and assign them to the template block var 'profile_fields' $user->get_profile_fields($user_id); $cp->generate_profile_fields('profile', $user_row['iso_lang_id']); break; case 'prefs': include $phpbb_root_path . 'includes/functions_user.' . $phpEx; $data = array('dateformat' => utf8_normalize_nfc(request_var('dateformat', $user_row['user_dateformat'], true)), 'lang' => basename(request_var('lang', $user_row['user_lang'])), 'tz' => request_var('tz', (double) $user_row['user_timezone']), 'style' => request_var('style', $user_row['user_style']), 'dst' => request_var('dst', $user_row['user_dst']), 'viewemail' => request_var('viewemail', $user_row['user_allow_viewemail']), 'massemail' => request_var('massemail', $user_row['user_allow_massemail']), 'hideonline' => request_var('hideonline', !$user_row['user_allow_viewonline']), 'notifymethod' => request_var('notifymethod', $user_row['user_notify_type']), 'notifypm' => request_var('notifypm', $user_row['user_notify_pm']), 'popuppm' => request_var('popuppm', $this->optionget($user_row, 'popuppm')), 'allowpm' => request_var('allowpm', $user_row['user_allow_pm']), 'topic_sk' => request_var('topic_sk', $user_row['user_topic_sortby_type'] ? $user_row['user_topic_sortby_type'] : 't'), 'topic_sd' => request_var('topic_sd', $user_row['user_topic_sortby_dir'] ? $user_row['user_topic_sortby_dir'] : 'd'), 'topic_st' => request_var('topic_st', $user_row['user_topic_show_days'] ? $user_row['user_topic_show_days'] : 0), 'post_sk' => request_var('post_sk', $user_row['user_post_sortby_type'] ? $user_row['user_post_sortby_type'] : 't'), 'post_sd' => request_var('post_sd', $user_row['user_post_sortby_dir'] ? $user_row['user_post_sortby_dir'] : 'a'), 'post_st' => request_var('post_st', $user_row['user_post_show_days'] ? $user_row['user_post_show_days'] : 0), 'view_images' => request_var('view_images', $this->optionget($user_row, 'viewimg')), 'view_flash' => request_var('view_flash', $this->optionget($user_row, 'viewflash')), 'view_smilies' => request_var('view_smilies', $this->optionget($user_row, 'viewsmilies')), 'view_sigs' => request_var('view_sigs', $this->optionget($user_row, 'viewsigs')), 'view_avatars' => request_var('view_avatars', $this->optionget($user_row, 'viewavatars')), 'view_wordcensor' => request_var('view_wordcensor', $this->optionget($user_row, 'viewcensors')), 'bbcode' => request_var('bbcode', $this->optionget($user_row, 'bbcode')), 'smilies' => request_var('smilies', $this->optionget($user_row, 'smilies')), 'sig' => request_var('sig', $this->optionget($user_row, 'attachsig')), 'notify' => request_var('notify', $user_row['user_notify'])); if ($submit) { $error = validate_data($data, array('dateformat' => array('string', false, 1, 30), 'lang' => array('match', false, '#^[a-z_\\-]{2,}$#i'), 'tz' => array('num', false, -14, 14), 'topic_sk' => array('string', false, 1, 1), 'topic_sd' => array('string', false, 1, 1), 'post_sk' => array('string', false, 1, 1), 'post_sd' => array('string', false, 1, 1))); if (!check_form_key($form_name)) { $error[] = 'FORM_INVALID'; } if (!sizeof($error)) { $this->optionset($user_row, 'popuppm', $data['popuppm']); $this->optionset($user_row, 'viewimg', $data['view_images']); $this->optionset($user_row, 'viewflash', $data['view_flash']); $this->optionset($user_row, 'viewsmilies', $data['view_smilies']); $this->optionset($user_row, 'viewsigs', $data['view_sigs']); $this->optionset($user_row, 'viewavatars', $data['view_avatars']); $this->optionset($user_row, 'viewcensors', $data['view_wordcensor']); $this->optionset($user_row, 'bbcode', $data['bbcode']); $this->optionset($user_row, 'smilies', $data['smilies']); $this->optionset($user_row, 'attachsig', $data['sig']); $sql_ary = array('user_options' => $user_row['user_options'], 'user_allow_pm' => $data['allowpm'], 'user_allow_viewemail' => $data['viewemail'], 'user_allow_massemail' => $data['massemail'], 'user_allow_viewonline' => !$data['hideonline'], 'user_notify_type' => $data['notifymethod'], 'user_notify_pm' => $data['notifypm'], 'user_dst' => $data['dst'], 'user_dateformat' => $data['dateformat'], 'user_lang' => $data['lang'], 'user_timezone' => $data['tz'], 'user_style' => $data['style'], 'user_topic_sortby_type' => $data['topic_sk'], 'user_post_sortby_type' => $data['post_sk'], 'user_topic_sortby_dir' => $data['topic_sd'], 'user_post_sortby_dir' => $data['post_sd'], 'user_topic_show_days' => $data['topic_st'], 'user_post_show_days' => $data['post_st'], 'user_notify' => $data['notify']); $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE user_id = {$user_id}"; $db->sql_query($sql); // Check if user has an active session if ($user_row['session_id']) { // We'll update the session if user_allow_viewonline has changed and the user is a bot // Or if it's a regular user and the admin set it to hide the session if ($user_row['user_allow_viewonline'] != $sql_ary['user_allow_viewonline'] && $user_row['user_type'] == USER_IGNORE || $user_row['user_allow_viewonline'] && !$sql_ary['user_allow_viewonline']) { // We also need to check if the user has the permission to cloak. $user_auth = new auth(); $user_auth->acl($user_row); $session_sql_ary = array('session_viewonline' => $user_auth->acl_get('u_hideonline') ? $sql_ary['user_allow_viewonline'] : true); $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $session_sql_ary) . "\n\t\t\t\t\t\t\t\t\tWHERE session_user_id = {$user_id}"; $db->sql_query($sql); unset($user_auth); } } trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); } // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); } $dateformat_options = ''; foreach ($user->lang['dateformats'] as $format => $null) { $dateformat_options .= '<option value="' . $format . '"' . ($format == $data['dateformat'] ? ' selected="selected"' : '') . '>'; $dateformat_options .= $user->format_date(time(), $format, false) . (strpos($format, '|') !== false ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : ''); $dateformat_options .= '</option>'; } $s_custom = false; $dateformat_options .= '<option value="custom"'; if (!isset($user->lang['dateformats'][$data['dateformat']])) { $dateformat_options .= ' selected="selected"'; $s_custom = true; } $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>'; $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']); // Topic ordering options $limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']); // Post ordering options $limit_post_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']); $_options = array('topic', 'post'); foreach ($_options as $sort_option) { ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">'; foreach (${'limit_' . $sort_option . '_days'} as $day => $text) { $selected = $data[$sort_option . '_st'] == $day ? ' selected="selected"' : ''; ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>'; } ${'s_limit_' . $sort_option . '_days'} .= '</select>'; ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">'; foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text) { $selected = $data[$sort_option . '_sk'] == $key ? ' selected="selected"' : ''; ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>'; } ${'s_sort_' . $sort_option . '_key'} .= '</select>'; ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">'; foreach ($sort_dir_text as $key => $value) { $selected = $data[$sort_option . '_sd'] == $key ? ' selected="selected"' : ''; ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>'; } ${'s_sort_' . $sort_option . '_dir'} .= '</select>'; } $template->assign_vars(array('S_PREFS' => true, 'S_JABBER_DISABLED' => $config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml') ? false : true, 'VIEW_EMAIL' => $data['viewemail'], 'MASS_EMAIL' => $data['massemail'], 'ALLOW_PM' => $data['allowpm'], 'HIDE_ONLINE' => $data['hideonline'], 'NOTIFY_EMAIL' => $data['notifymethod'] == NOTIFY_EMAIL ? true : false, 'NOTIFY_IM' => $data['notifymethod'] == NOTIFY_IM ? true : false, 'NOTIFY_BOTH' => $data['notifymethod'] == NOTIFY_BOTH ? true : false, 'NOTIFY_PM' => $data['notifypm'], 'POPUP_PM' => $data['popuppm'], 'DST' => $data['dst'], 'BBCODE' => $data['bbcode'], 'SMILIES' => $data['smilies'], 'ATTACH_SIG' => $data['sig'], 'NOTIFY' => $data['notify'], 'VIEW_IMAGES' => $data['view_images'], 'VIEW_FLASH' => $data['view_flash'], 'VIEW_SMILIES' => $data['view_smilies'], 'VIEW_SIGS' => $data['view_sigs'], 'VIEW_AVATARS' => $data['view_avatars'], 'VIEW_WORDCENSOR' => $data['view_wordcensor'], 'S_TOPIC_SORT_DAYS' => $s_limit_topic_days, 'S_TOPIC_SORT_KEY' => $s_sort_topic_key, 'S_TOPIC_SORT_DIR' => $s_sort_topic_dir, 'S_POST_SORT_DAYS' => $s_limit_post_days, 'S_POST_SORT_KEY' => $s_sort_post_key, 'S_POST_SORT_DIR' => $s_sort_post_dir, 'DATE_FORMAT' => $data['dateformat'], 'S_DATEFORMAT_OPTIONS' => $dateformat_options, 'S_CUSTOM_DATEFORMAT' => $s_custom, 'DEFAULT_DATEFORMAT' => $config['default_dateformat'], 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']), 'S_LANG_OPTIONS' => language_select($data['lang']), 'S_STYLE_OPTIONS' => style_select($data['style']), 'S_TZ_OPTIONS' => tz_select($data['tz'], true))); break; case 'avatar': include $phpbb_root_path . 'includes/functions_display.' . $phpEx; include $phpbb_root_path . 'includes/functions_user.' . $phpEx; $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false; if ($submit) { if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if (avatar_process_user($error, $user_row, $can_upload)) { trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_row['user_id'])); } // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); } if (!$config['allow_avatar'] && $user_row['user_avatar_type']) { $error[] = $user->lang['USER_AVATAR_NOT_ALLOWED']; } else { if ($user_row['user_avatar_type'] == AVATAR_UPLOAD && !$config['allow_avatar_upload'] || $user_row['user_avatar_type'] == AVATAR_REMOTE && !$config['allow_avatar_remote'] || $user_row['user_avatar_type'] == AVATAR_GALLERY && !$config['allow_avatar_local']) { $error[] = $user->lang['USER_AVATAR_TYPE_NOT_ALLOWED']; } } // Generate users avatar $avatar_img = $user_row['user_avatar'] ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height'], 'USER_AVATAR', true) : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />'; $display_gallery = isset($_POST['display_gallery']) ? true : false; $avatar_select = basename(request_var('avatar_select', '')); $category = basename(request_var('category', '')); if ($config['allow_avatar_local'] && $display_gallery) { avatar_gallery($category, $avatar_select, 4); } $template->assign_vars(array('S_AVATAR' => true, 'S_CAN_UPLOAD' => $can_upload, 'S_UPLOAD_FILE' => $config['allow_avatar'] && $can_upload && $config['allow_avatar_upload'] ? true : false, 'S_REMOTE_UPLOAD' => $config['allow_avatar'] && $can_upload && $config['allow_avatar_remote_upload'] ? true : false, 'S_ALLOW_REMOTE' => $config['allow_avatar'] && $config['allow_avatar_remote'] ? true : false, 'S_DISPLAY_GALLERY' => $config['allow_avatar'] && $config['allow_avatar_local'] && !$display_gallery ? true : false, 'S_IN_GALLERY' => $config['allow_avatar'] && $config['allow_avatar_local'] && $display_gallery ? true : false, 'AVATAR_IMAGE' => $avatar_img, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'USER_AVATAR_WIDTH' => $user_row['user_avatar_width'], 'USER_AVATAR_HEIGHT' => $user_row['user_avatar_height'], 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)))); break; case 'rank': if ($submit) { if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } $rank_id = request_var('user_rank', 0); $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\tSET user_rank = {$rank_id}\n\t\t\t\t\t\tWHERE user_id = {$user_id}"; $db->sql_query($sql); trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); } $sql = 'SELECT * FROM ' . RANKS_TABLE . ' WHERE rank_special = 1 ORDER BY rank_title'; $result = $db->sql_query($sql); $s_rank_options = '<option value="0"' . (!$user_row['user_rank'] ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>'; while ($row = $db->sql_fetchrow($result)) { $selected = $user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank'] ? ' selected="selected"' : ''; $s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>'; } $db->sql_freeresult($result); $template->assign_vars(array('S_RANK' => true, 'S_RANK_OPTIONS' => $s_rank_options)); break; case 'sig': include_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx; include_once $phpbb_root_path . 'includes/functions_display.' . $phpEx; $enable_bbcode = $config['allow_sig_bbcode'] ? (bool) $this->optionget($user_row, 'sig_bbcode') : false; $enable_smilies = $config['allow_sig_smilies'] ? (bool) $this->optionget($user_row, 'sig_smilies') : false; $enable_urls = $config['allow_sig_links'] ? (bool) $this->optionget($user_row, 'sig_links') : false; $signature = utf8_normalize_nfc(request_var('signature', (string) $user_row['user_sig'], true)); $preview = isset($_POST['preview']) ? true : false; if ($submit || $preview) { include_once $phpbb_root_path . 'includes/message_parser.' . $phpEx; $enable_bbcode = $config['allow_sig_bbcode'] ? request_var('disable_bbcode', false) ? false : true : false; $enable_smilies = $config['allow_sig_smilies'] ? request_var('disable_smilies', false) ? false : true : false; $enable_urls = $config['allow_sig_links'] ? request_var('disable_magic_url', false) ? false : true : false; $message_parser = new parse_message($signature); // Allowing Quote BBCode $message_parser->parse($enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, $config['allow_sig_links'], true, 'sig'); if (sizeof($message_parser->warn_msg)) { $error[] = implode('<br />', $message_parser->warn_msg); } if (!check_form_key($form_name)) { $error = 'FORM_INVALID'; } if (!sizeof($error) && $submit) { $this->optionset($user_row, 'sig_bbcode', $enable_bbcode); $this->optionset($user_row, 'sig_smilies', $enable_smilies); $this->optionset($user_row, 'sig_links', $enable_urls); $sql_ary = array('user_sig' => (string) $message_parser->message, 'user_options' => $user_row['user_options'], 'user_sig_bbcode_uid' => (string) $message_parser->bbcode_uid, 'user_sig_bbcode_bitfield' => (string) $message_parser->bbcode_bitfield); $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $user_id; $db->sql_query($sql); trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_id)); } // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); } $signature_preview = ''; if ($preview) { // Now parse it for displaying $signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false); unset($message_parser); } decode_message($signature, $user_row['user_sig_bbcode_uid']); $template->assign_vars(array('S_SIGNATURE' => true, 'SIGNATURE' => $signature, 'SIGNATURE_PREVIEW' => $signature_preview, 'S_BBCODE_CHECKED' => !$enable_bbcode ? ' checked="checked"' : '', 'S_SMILIES_CHECKED' => !$enable_smilies ? ' checked="checked"' : '', 'S_MAGIC_URL_CHECKED' => !$enable_urls ? ' checked="checked"' : '', 'BBCODE_STATUS' => $config['allow_sig_bbcode'] ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>'), 'SMILIES_STATUS' => $config['allow_sig_smilies'] ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'IMG_STATUS' => $config['allow_sig_img'] ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $config['allow_sig_flash'] ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'URL_STATUS' => $config['allow_sig_links'] ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], 'L_SIGNATURE_EXPLAIN' => sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']), 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'], 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies'], 'S_BBCODE_IMG' => $config['allow_sig_img'] ? true : false, 'S_BBCODE_FLASH' => $config['allow_sig_flash'] ? true : false, 'S_LINKS_ALLOWED' => $config['allow_sig_links'] ? true : false)); // Assigning custom bbcodes display_custom_bbcodes(); break; case 'attach': $start = request_var('start', 0); $deletemark = isset($_POST['delmarked']) ? true : false; $marked = request_var('mark', array(0)); // Sort keys $sort_key = request_var('sk', 'a'); $sort_dir = request_var('sd', 'd'); if ($deletemark && sizeof($marked)) { $sql = 'SELECT attach_id FROM ' . ATTACHMENTS_TABLE . ' WHERE poster_id = ' . $user_id . ' AND is_orphan = 0 AND ' . $db->sql_in_set('attach_id', $marked); $result = $db->sql_query($sql); $marked = array(); while ($row = $db->sql_fetchrow($result)) { $marked[] = $row['attach_id']; } $db->sql_freeresult($result); } if ($deletemark && sizeof($marked)) { if (confirm_box(true)) { $sql = 'SELECT real_filename FROM ' . ATTACHMENTS_TABLE . ' WHERE ' . $db->sql_in_set('attach_id', $marked); $result = $db->sql_query($sql); $log_attachments = array(); while ($row = $db->sql_fetchrow($result)) { $log_attachments[] = $row['real_filename']; } $db->sql_freeresult($result); delete_attachments('attach', $marked); $message = sizeof($log_attachments) == 1 ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED']; add_log('admin', 'LOG_ATTACHMENTS_DELETED', implode(', ', $log_attachments)); trigger_error($message . adm_back_link($this->u_action . '&u=' . $user_id)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'delmarked' => true, 'mark' => $marked))); } } $sk_text = array('a' => $user->lang['SORT_FILENAME'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']); $sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title'); $sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']); $s_sort_key = ''; foreach ($sk_text as $key => $value) { $selected = $sort_key == $key ? ' selected="selected"' : ''; $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>'; } $s_sort_dir = ''; foreach ($sd_text as $key => $value) { $selected = $sort_dir == $key ? ' selected="selected"' : ''; $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>'; } if (!isset($sk_sql[$sort_key])) { $sort_key = 'a'; } $order_by = $sk_sql[$sort_key] . ' ' . ($sort_dir == 'a' ? 'ASC' : 'DESC'); $sql = 'SELECT COUNT(attach_id) as num_attachments FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\tAND is_orphan = 0"; $result = $db->sql_query_limit($sql, 1); $num_attachments = (int) $db->sql_fetchfield('num_attachments'); $db->sql_freeresult($result); $sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title FROM ' . ATTACHMENTS_TABLE . ' a LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id AND a.in_message = 0) LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id AND a.in_message = 1) WHERE a.poster_id = ' . $user_id . "\n\t\t\t\t\t\tAND a.is_orphan = 0\n\t\t\t\t\tORDER BY {$order_by}"; $result = $db->sql_query_limit($sql, $config['posts_per_page'], $start); while ($row = $db->sql_fetchrow($result)) { if ($row['in_message']) { $view_topic = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&p={$row['post_msg_id']}"); } else { $view_topic = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_id']}&p={$row['post_msg_id']}") . '#p' . $row['post_msg_id']; } $template->assign_block_vars('attach', array('REAL_FILENAME' => $row['real_filename'], 'COMMENT' => nl2br($row['attach_comment']), 'EXTENSION' => $row['extension'], 'SIZE' => get_formatted_filesize($row['filesize']), 'DOWNLOAD_COUNT' => $row['download_count'], 'POST_TIME' => $user->format_date($row['filetime']), 'TOPIC_TITLE' => $row['in_message'] ? $row['message_title'] : $row['topic_title'], 'ATTACH_ID' => $row['attach_id'], 'POST_ID' => $row['post_msg_id'], 'TOPIC_ID' => $row['topic_id'], 'S_IN_MESSAGE' => $row['in_message'], 'U_DOWNLOAD' => append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'mode=view&id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic)); } $db->sql_freeresult($result); $template->assign_vars(array('S_ATTACHMENTS' => true, 'S_ON_PAGE' => on_page($num_attachments, $config['topics_per_page'], $start), 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'PAGINATION' => generate_pagination($this->u_action . "&u={$user_id}&sk={$sort_key}&sd={$sort_dir}", $num_attachments, $config['topics_per_page'], $start, true))); break; case 'groups': include $phpbb_root_path . 'includes/functions_user.' . $phpEx; $user->add_lang(array('groups', 'acp/groups')); $group_id = request_var('g', 0); if ($group_id) { // Check the founder only entry for this group to make sure everything is well $sql = 'SELECT group_founder_manage FROM ' . GROUPS_TABLE . ' WHERE group_id = ' . $group_id; $result = $db->sql_query($sql); $founder_manage = (int) $db->sql_fetchfield('group_founder_manage'); $db->sql_freeresult($result); if ($user->data['user_type'] != USER_FOUNDER && $founder_manage) { trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } } else { $founder_manage = 0; } switch ($action) { case 'demote': case 'promote': case 'default': if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } group_user_attributes($action, $group_id, $user_id); if ($action == 'default') { $user_row['group_id'] = $group_id; } break; case 'delete': if (confirm_box(true)) { if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if ($error = group_user_del($group_id, $user_id)) { trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } $error = array(); // The delete action was successful - therefore update the user row... $sql = 'SELECT u.*, s.* FROM ' . USERS_TABLE . ' u LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id) WHERE u.user_id = ' . $user_id . ' ORDER BY s.session_time DESC'; $result = $db->sql_query_limit($sql, 1); $user_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'g' => $group_id))); } break; case 'approve': if (confirm_box(true)) { if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } group_user_attributes($action, $group_id, $user_id); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'g' => $group_id))); } break; } // Add user to group? if ($submit) { if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } if (!$group_id) { trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } // Add user/s to group if ($error = group_user_add($group_id, $user_id)) { trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING); } $error = array(); } $sql = 'SELECT ug.*, g.* FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.user_id = {$user_id}\n\t\t\t\t\t\tAND g.group_id = ug.group_id\n\t\t\t\t\tORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name"; $result = $db->sql_query($sql); $i = 0; $group_data = $id_ary = array(); while ($row = $db->sql_fetchrow($result)) { $type = $row['group_type'] == GROUP_SPECIAL ? 'special' : ($row['user_pending'] ? 'pending' : 'normal'); $group_data[$type][$i]['group_id'] = $row['group_id']; $group_data[$type][$i]['group_name'] = $row['group_name']; $group_data[$type][$i]['group_leader'] = $row['group_leader'] ? 1 : 0; $id_ary[] = $row['group_id']; $i++; } $db->sql_freeresult($result); // Select box for other groups $sql = 'SELECT group_id, group_name, group_type, group_founder_manage FROM ' . GROUPS_TABLE . ' ' . (sizeof($id_ary) ? 'WHERE ' . $db->sql_in_set('group_id', $id_ary, true) : '') . ' ORDER BY group_type DESC, group_name ASC'; $result = $db->sql_query($sql); $s_group_options = ''; while ($row = $db->sql_fetchrow($result)) { if (!$config['coppa_enable'] && $row['group_name'] == 'REGISTERED_COPPA') { continue; } // Do not display those groups not allowed to be managed if ($user->data['user_type'] != USER_FOUNDER && $row['group_founder_manage']) { continue; } $s_group_options .= '<option' . ($row['group_type'] == GROUP_SPECIAL ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . ($row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>'; } $db->sql_freeresult($result); $current_type = ''; foreach ($group_data as $group_type => $data_ary) { if ($current_type != $group_type) { $template->assign_block_vars('group', array('S_NEW_GROUP_TYPE' => true, 'GROUP_TYPE' => $user->lang['USER_GROUP_' . strtoupper($group_type)])); } foreach ($data_ary as $data) { $template->assign_block_vars('group', array('U_EDIT_GROUP' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=groups&mode=manage&action=edit&u={$user_id}&g={$data['group_id']}&back_link=acp_users_groups"), 'U_DEFAULT' => $this->u_action . "&action=default&u={$user_id}&g=" . $data['group_id'], 'U_DEMOTE_PROMOTE' => $this->u_action . '&action=' . ($data['group_leader'] ? 'demote' : 'promote') . "&u={$user_id}&g=" . $data['group_id'], 'U_DELETE' => $this->u_action . "&action=delete&u={$user_id}&g=" . $data['group_id'], 'U_APPROVE' => $group_type == 'pending' ? $this->u_action . "&action=approve&u={$user_id}&g=" . $data['group_id'] : '', 'GROUP_NAME' => $group_type == 'special' ? $user->lang['G_' . $data['group_name']] : $data['group_name'], 'L_DEMOTE_PROMOTE' => $data['group_leader'] ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'], 'S_IS_MEMBER' => $group_type != 'pending' ? true : false, 'S_NO_DEFAULT' => $user_row['group_id'] != $data['group_id'] ? true : false, 'S_SPECIAL_GROUP' => $group_type == 'special' ? true : false)); } } $template->assign_vars(array('S_GROUPS' => true, 'S_GROUP_OPTIONS' => $s_group_options)); break; case 'perm': include_once $phpbb_root_path . 'includes/acp/auth.' . $phpEx; $auth_admin = new auth_admin(); $user->add_lang('acp/permissions'); add_permission_language(); $forum_id = request_var('f', 0); // Global Permissions if (!$forum_id) { // Select auth options $sql = 'SELECT auth_option, is_local, is_global FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option ' . $db->sql_like_expression($db->any_char . '_') . ' AND is_global = 1 ORDER BY auth_option'; $result = $db->sql_query($sql); $hold_ary = array(); while ($row = $db->sql_fetchrow($result)) { $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NEVER); $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false); } $db->sql_freeresult($result); unset($hold_ary); } else { $sql = 'SELECT auth_option, is_local, is_global FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\t\t\t\tWHERE auth_option " . $db->sql_like_expression($db->any_char . '_') . "\n\t\t\t\t\t\t\tAND is_local = 1\n\t\t\t\t\t\tORDER BY is_global DESC, auth_option"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $hold_ary = $auth_admin->get_mask('view', $user_id, false, $forum_id, $row['auth_option'], 'local', ACL_NEVER); $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false); } $db->sql_freeresult($result); } $s_forum_options = '<option value="0"' . (!$forum_id ? ' selected="selected"' : '') . '>' . $user->lang['VIEW_GLOBAL_PERMS'] . '</option>'; $s_forum_options .= make_forum_select($forum_id, false, true, false, false, false); $template->assign_vars(array('S_PERMISSIONS' => true, 'S_GLOBAL' => !$forum_id ? true : false, 'S_FORUM_OPTIONS' => $s_forum_options, 'U_ACTION' => $this->u_action . '&u=' . $user_id, 'U_USER_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&mode=setting_user_global&user_id[]=' . $user_id), 'U_USER_FORUM_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&mode=setting_user_local&user_id[]=' . $user_id))); break; } // Assign general variables $template->assign_vars(array('S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : '')); }
/** * Going through a config array and validate values, writing errors to $error. The validation method accepts parameters separated by ':' for string and int. * The first parameter defines the type to be used, the second the lower bound and the third the upper bound. Only the type is required. */ function validate_config_vars($config_vars, &$cfg_array, &$error) { global $phpbb_root_path, $user; $type = 0; $min = 1; $max = 2; foreach ($config_vars as $config_name => $config_definition) { if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) { continue; } if (!isset($config_definition['validate'])) { continue; } $validator = explode(':', $config_definition['validate']); // Validate a bit. ;) (0 = type, 1 = min, 2= max) switch ($validator[$type]) { case 'string': $length = strlen($cfg_array[$config_name]); // the column is a VARCHAR $validator[$max] = isset($validator[$max]) ? min(255, $validator[$max]) : 255; if (isset($validator[$min]) && $length < $validator[$min]) { $error[] = sprintf($user->lang['SETTING_TOO_SHORT'], $user->lang[$config_definition['lang']], $validator[$min]); } else { if (isset($validator[$max]) && $length > $validator[2]) { $error[] = sprintf($user->lang['SETTING_TOO_LONG'], $user->lang[$config_definition['lang']], $validator[$max]); } } break; case 'bool': $cfg_array[$config_name] = $cfg_array[$config_name] ? 1 : 0; break; case 'int': $cfg_array[$config_name] = (int) $cfg_array[$config_name]; if (isset($validator[$min]) && $cfg_array[$config_name] < $validator[$min]) { $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], $validator[$min]); } else { if (isset($validator[$max]) && $cfg_array[$config_name] > $validator[$max]) { $error[] = sprintf($user->lang['SETTING_TOO_BIG'], $user->lang[$config_definition['lang']], $validator[$max]); } } if (strpos($config_name, '_max') !== false) { // Min/max pairs of settings should ensure that min <= max // Replace _max with _min to find the name of the minimum // corresponding configuration variable $min_name = str_replace('_max', '_min', $config_name); if (isset($cfg_array[$min_name]) && is_numeric($cfg_array[$min_name]) && $cfg_array[$config_name] < $cfg_array[$min_name]) { // A minimum value exists and the maximum value is less than it $error[] = sprintf($user->lang['SETTING_TOO_LOW'], $user->lang[$config_definition['lang']], (int) $cfg_array[$min_name]); } } break; // Absolute path // Absolute path case 'script_path': if (!$cfg_array[$config_name]) { break; } $destination = str_replace('\\', '/', $cfg_array[$config_name]); if ($destination !== '/') { // Adjust destination path (no trailing slash) if (substr($destination, -1, 1) == '/') { $destination = substr($destination, 0, -1); } $destination = str_replace(array('../', './'), '', $destination); if ($destination[0] != '/') { $destination = '/' . $destination; } } $cfg_array[$config_name] = trim($destination); break; // Absolute path // Absolute path case 'lang': if (!$cfg_array[$config_name]) { break; } $cfg_array[$config_name] = basename($cfg_array[$config_name]); if (!file_exists($phpbb_root_path . 'language/' . $cfg_array[$config_name] . '/')) { $error[] = $user->lang['WRONG_DATA_LANG']; } break; // Relative path (appended $phpbb_root_path) // Relative path (appended $phpbb_root_path) case 'rpath': case 'rwpath': if (!$cfg_array[$config_name]) { break; } $destination = $cfg_array[$config_name]; // Adjust destination path (no trailing slash) if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') { $destination = substr($destination, 0, -1); } $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) { $destination = ''; } $cfg_array[$config_name] = trim($destination); // Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir... // Path being relative (still prefixed by phpbb_root_path), but with the ability to escape the root dir... case 'path': case 'wpath': if (!$cfg_array[$config_name]) { break; } $cfg_array[$config_name] = trim($cfg_array[$config_name]); // Make sure no NUL byte is present... if (strpos($cfg_array[$config_name], "") !== false || strpos($cfg_array[$config_name], '%00') !== false) { $cfg_array[$config_name] = ''; break; } if (!file_exists($phpbb_root_path . $cfg_array[$config_name])) { $error[] = sprintf($user->lang['DIRECTORY_DOES_NOT_EXIST'], $cfg_array[$config_name]); } if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !is_dir($phpbb_root_path . $cfg_array[$config_name])) { $error[] = sprintf($user->lang['DIRECTORY_NOT_DIR'], $cfg_array[$config_name]); } // Check if the path is writable if ($config_definition['validate'] == 'wpath' || $config_definition['validate'] == 'rwpath') { if (file_exists($phpbb_root_path . $cfg_array[$config_name]) && !phpbb_is_writable($phpbb_root_path . $cfg_array[$config_name])) { $error[] = sprintf($user->lang['DIRECTORY_NOT_WRITABLE'], $cfg_array[$config_name]); } } break; } } return; }
function main($id, $mode) { global $config, $db, $cache, $user, $auth, $template, $request; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container, $phpbb_dispatcher; // Show restore permissions notice if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) { $this->tpl_name = 'acp_main'; $this->page_title = 'ACP_MAIN'; $sql = 'SELECT user_id, username, user_colour FROM ' . USERS_TABLE . ' WHERE user_id = ' . $user->data['user_perm_from']; $result = $db->sql_query($sql); $user_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $perm_from = get_username_string('full', $user_row['user_id'], $user_row['username'], $user_row['user_colour']); $template->assign_vars(array('S_RESTORE_PERMISSIONS' => true, 'U_RESTORE_PERMISSIONS' => append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'mode=restore_perm'), 'PERM_FROM' => $perm_from, 'L_PERMISSIONS_TRANSFERRED_EXPLAIN' => sprintf($user->lang['PERMISSIONS_TRANSFERRED_EXPLAIN'], $perm_from, append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'mode=restore_perm')))); return; } $action = request_var('action', ''); if ($action) { if ($action === 'admlogout') { $user->unset_admin(); redirect(append_sid("{$phpbb_root_path}index.{$phpEx}")); } if (!confirm_box(true)) { switch ($action) { case 'online': $confirm = true; $confirm_lang = 'RESET_ONLINE_CONFIRM'; break; case 'stats': $confirm = true; $confirm_lang = 'RESYNC_STATS_CONFIRM'; break; case 'user': $confirm = true; $confirm_lang = 'RESYNC_POSTCOUNTS_CONFIRM'; break; case 'date': $confirm = true; $confirm_lang = 'RESET_DATE_CONFIRM'; break; case 'db_track': $confirm = true; $confirm_lang = 'RESYNC_POST_MARKING_CONFIRM'; break; case 'purge_cache': $confirm = true; $confirm_lang = 'PURGE_CACHE_CONFIRM'; break; case 'purge_sessions': $confirm = true; $confirm_lang = 'PURGE_SESSIONS_CONFIRM'; break; default: $confirm = true; $confirm_lang = 'CONFIRM_OPERATION'; } if ($confirm) { confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action))); } } else { switch ($action) { case 'online': if (!$auth->acl_get('a_board')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } set_config('record_online_users', 1, true); set_config('record_online_date', time(), true); add_log('admin', 'LOG_RESET_ONLINE'); if ($request->is_ajax()) { trigger_error('RESET_ONLINE_SUCCESS'); } break; case 'stats': if (!$auth->acl_get('a_board')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $sql = 'SELECT COUNT(post_id) AS stat FROM ' . POSTS_TABLE . ' WHERE post_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); set_config('num_posts', (int) $db->sql_fetchfield('stat'), true); $db->sql_freeresult($result); $sql = 'SELECT COUNT(topic_id) AS stat FROM ' . TOPICS_TABLE . ' WHERE topic_visibility = ' . ITEM_APPROVED; $result = $db->sql_query($sql); set_config('num_topics', (int) $db->sql_fetchfield('stat'), true); $db->sql_freeresult($result); $sql = 'SELECT COUNT(user_id) AS stat FROM ' . USERS_TABLE . ' WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')'; $result = $db->sql_query($sql); set_config('num_users', (int) $db->sql_fetchfield('stat'), true); $db->sql_freeresult($result); $sql = 'SELECT COUNT(attach_id) as stat FROM ' . ATTACHMENTS_TABLE . ' WHERE is_orphan = 0'; $result = $db->sql_query($sql); set_config('num_files', (int) $db->sql_fetchfield('stat'), true); $db->sql_freeresult($result); $sql = 'SELECT SUM(filesize) as stat FROM ' . ATTACHMENTS_TABLE . ' WHERE is_orphan = 0'; $result = $db->sql_query($sql); set_config('upload_dir_size', (double) $db->sql_fetchfield('stat'), true); $db->sql_freeresult($result); if (!function_exists('update_last_username')) { include $phpbb_root_path . "includes/functions_user.{$phpEx}"; } update_last_username(); add_log('admin', 'LOG_RESYNC_STATS'); if ($request->is_ajax()) { trigger_error('RESYNC_STATS_SUCCESS'); } break; case 'user': if (!$auth->acl_get('a_board')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } // Resync post counts $start = $max_post_id = 0; // Find the maximum post ID, we can only stop the cycle when we've reached it $sql = 'SELECT MAX(forum_last_post_id) as max_post_id FROM ' . FORUMS_TABLE; $result = $db->sql_query($sql); $max_post_id = (int) $db->sql_fetchfield('max_post_id'); $db->sql_freeresult($result); // No maximum post id? :o if (!$max_post_id) { $sql = 'SELECT MAX(post_id) as max_post_id FROM ' . POSTS_TABLE; $result = $db->sql_query($sql); $max_post_id = (int) $db->sql_fetchfield('max_post_id'); $db->sql_freeresult($result); } // Still no maximum post id? Then we are finished if (!$max_post_id) { add_log('admin', 'LOG_RESYNC_POSTCOUNTS'); break; } $step = $config['num_posts'] ? max((int) ($config['num_posts'] / 5), 20000) : 20000; $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0'); while ($start < $max_post_id) { $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id FROM ' . POSTS_TABLE . ' WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . ' AND post_postcount = 1 AND post_visibility = ' . ITEM_APPROVED . ' GROUP BY poster_id'; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { do { $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}"; $db->sql_query($sql); } while ($row = $db->sql_fetchrow($result)); } $db->sql_freeresult($result); $start += $step; } add_log('admin', 'LOG_RESYNC_POSTCOUNTS'); if ($request->is_ajax()) { trigger_error('RESYNC_POSTCOUNTS_SUCCESS'); } break; case 'date': if (!$auth->acl_get('a_board')) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } set_config('board_startdate', time() - 1); add_log('admin', 'LOG_RESET_DATE'); if ($request->is_ajax()) { trigger_error('RESET_DATE_SUCCESS'); } break; case 'db_track': switch ($db->get_sql_layer()) { case 'sqlite': case 'sqlite3': $db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE); break; default: $db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE); break; } // This can get really nasty... therefore we only do the last six months $get_from_time = time() - 6 * 4 * 7 * 24 * 60 * 60; // Select forum ids, do not include categories $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE forum_type <> ' . FORUM_CAT; $result = $db->sql_query($sql); $forum_ids = array(); while ($row = $db->sql_fetchrow($result)) { $forum_ids[] = $row['forum_id']; } $db->sql_freeresult($result); // Any global announcements? ;) $forum_ids[] = 0; // Now go through the forums and get us some topics... foreach ($forum_ids as $forum_id) { $sql = 'SELECT p.poster_id, p.topic_id FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t WHERE t.forum_id = ' . $forum_id . ' AND t.topic_moved_id = 0 AND t.topic_last_post_time > ' . $get_from_time . ' AND t.topic_id = p.topic_id AND p.poster_id <> ' . ANONYMOUS . ' GROUP BY p.poster_id, p.topic_id'; $result = $db->sql_query($sql); $posted = array(); while ($row = $db->sql_fetchrow($result)) { $posted[$row['poster_id']][] = $row['topic_id']; } $db->sql_freeresult($result); $sql_ary = array(); foreach ($posted as $user_id => $topic_row) { foreach ($topic_row as $topic_id) { $sql_ary[] = array('user_id' => (int) $user_id, 'topic_id' => (int) $topic_id, 'topic_posted' => 1); } } unset($posted); if (sizeof($sql_ary)) { $db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary); } } add_log('admin', 'LOG_RESYNC_POST_MARKING'); if ($request->is_ajax()) { trigger_error('RESYNC_POST_MARKING_SUCCESS'); } break; case 'purge_cache': $config->increment('assets_version', 1); $cache->purge(); // Clear permissions $auth->acl_clear_prefetch(); phpbb_cache_moderators($db, $cache, $auth); add_log('admin', 'LOG_PURGE_CACHE'); if ($request->is_ajax()) { trigger_error('PURGE_CACHE_SUCCESS'); } break; case 'purge_sessions': if ((int) $user->data['user_type'] !== USER_FOUNDER) { trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } $tables = array(CONFIRM_TABLE, SESSIONS_TABLE); foreach ($tables as $table) { switch ($db->get_sql_layer()) { case 'sqlite': case 'sqlite3': $db->sql_query("DELETE FROM {$table}"); break; default: $db->sql_query("TRUNCATE TABLE {$table}"); break; } } // let's restore the admin session $reinsert_ary = array('session_id' => (string) $user->session_id, 'session_page' => (string) substr($user->page['page'], 0, 199), 'session_forum_id' => $user->page['forum'], 'session_user_id' => (int) $user->data['user_id'], 'session_start' => (int) $user->data['session_start'], 'session_last_visit' => (int) $user->data['session_last_visit'], 'session_time' => (int) $user->time_now, 'session_browser' => (string) trim(substr($user->browser, 0, 149)), 'session_forwarded_for' => (string) $user->forwarded_for, 'session_ip' => (string) $user->ip, 'session_autologin' => (int) $user->data['session_autologin'], 'session_admin' => 1, 'session_viewonline' => (int) $user->data['session_viewonline']); $sql = 'INSERT INTO ' . SESSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $reinsert_ary); $db->sql_query($sql); add_log('admin', 'LOG_PURGE_SESSIONS'); if ($request->is_ajax()) { trigger_error('PURGE_SESSIONS_SUCCESS'); } break; } } } // Version check $user->add_lang('install'); if ($auth->acl_get('a_server') && version_compare(PHP_VERSION, '5.3.3', '<')) { $template->assign_vars(array('S_PHP_VERSION_OLD' => true, 'L_PHP_VERSION_OLD' => sprintf($user->lang['PHP_VERSION_OLD'], '<a href="https://www.phpbb.com/community/viewtopic.php?f=14&t=2152375">', '</a>'))); } if ($auth->acl_get('a_board')) { $version_helper = $phpbb_container->get('version_helper'); try { $recheck = $request->variable('versioncheck_force', false); $updates_available = $version_helper->get_suggested_updates($recheck); $template->assign_var('S_VERSION_UP_TO_DATE', empty($updates_available)); } catch (\RuntimeException $e) { $template->assign_vars(array('S_VERSIONCHECK_FAIL' => true, 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : '')); } } else { // We set this template var to true, to not display an outdated version notice. $template->assign_var('S_VERSION_UP_TO_DATE', true); } /** * Notice admin * * @event core.acp_main_notice * @since 3.1.0-RC3 */ $phpbb_dispatcher->dispatch('core.acp_main_notice'); // Get forum statistics $total_posts = $config['num_posts']; $total_topics = $config['num_topics']; $total_users = $config['num_users']; $total_files = $config['num_files']; $start_date = $user->format_date($config['board_startdate']); $boarddays = (time() - $config['board_startdate']) / 86400; $posts_per_day = sprintf('%.2f', $total_posts / $boarddays); $topics_per_day = sprintf('%.2f', $total_topics / $boarddays); $users_per_day = sprintf('%.2f', $total_users / $boarddays); $files_per_day = sprintf('%.2f', $total_files / $boarddays); $upload_dir_size = get_formatted_filesize($config['upload_dir_size']); $avatar_dir_size = 0; if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path'])) { while (($file = readdir($avatar_dir)) !== false) { if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false) { $avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file); } } closedir($avatar_dir); $avatar_dir_size = get_formatted_filesize($avatar_dir_size); } else { // Couldn't open Avatar dir. $avatar_dir_size = $user->lang['NOT_AVAILABLE']; } if ($posts_per_day > $total_posts) { $posts_per_day = $total_posts; } if ($topics_per_day > $total_topics) { $topics_per_day = $total_topics; } if ($users_per_day > $total_users) { $users_per_day = $total_users; } if ($files_per_day > $total_files) { $files_per_day = $total_files; } if ($config['allow_attachments'] || $config['allow_pm_attach']) { $sql = 'SELECT COUNT(attach_id) AS total_orphan FROM ' . ATTACHMENTS_TABLE . ' WHERE is_orphan = 1 AND filetime < ' . (time() - 3 * 60 * 60); $result = $db->sql_query($sql); $total_orphan = (int) $db->sql_fetchfield('total_orphan'); $db->sql_freeresult($result); } else { $total_orphan = false; } $dbsize = get_database_size(); $template->assign_vars(array('TOTAL_POSTS' => $total_posts, 'POSTS_PER_DAY' => $posts_per_day, 'TOTAL_TOPICS' => $total_topics, 'TOPICS_PER_DAY' => $topics_per_day, 'TOTAL_USERS' => $total_users, 'USERS_PER_DAY' => $users_per_day, 'TOTAL_FILES' => $total_files, 'FILES_PER_DAY' => $files_per_day, 'START_DATE' => $start_date, 'AVATAR_DIR_SIZE' => $avatar_dir_size, 'DBSIZE' => $dbsize, 'UPLOAD_DIR_SIZE' => $upload_dir_size, 'TOTAL_ORPHAN' => $total_orphan, 'S_TOTAL_ORPHAN' => $total_orphan === false ? false : true, 'GZIP_COMPRESSION' => $config['gzip_compress'] && @extension_loaded('zlib') ? $user->lang['ON'] : $user->lang['OFF'], 'DATABASE_INFO' => $db->sql_server_info(), 'BOARD_VERSION' => $config['version'], 'U_ACTION' => $this->u_action, 'U_ADMIN_LOG' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=logs&mode=admin'), 'U_INACTIVE_USERS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=inactive&mode=list'), 'U_VERSIONCHECK' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=update&mode=version_check'), 'U_VERSIONCHECK_FORCE' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'versioncheck_force=1'), 'S_VERSIONCHECK' => $auth->acl_get('a_board') ? true : false, 'S_ACTION_OPTIONS' => $auth->acl_get('a_board') ? true : false, 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false)); $log_data = array(); $log_count = false; if ($auth->acl_get('a_viewlogs')) { view_log('admin', $log_data, $log_count, 5); foreach ($log_data as $row) { $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action'])); } } if ($auth->acl_get('a_user')) { $user->add_lang('memberlist'); $inactive = array(); $inactive_count = 0; view_inactive_users($inactive, $inactive_count, 10); foreach ($inactive as $row) { $template->assign_block_vars('inactive', array('INACTIVE_DATE' => $user->format_date($row['user_inactive_time']), 'REMINDED_DATE' => $user->format_date($row['user_reminded_time']), 'JOINED' => $user->format_date($row['user_regdate']), 'LAST_VISIT' => !$row['user_lastvisit'] ? ' - ' : $user->format_date($row['user_lastvisit']), 'REASON' => $row['inactive_reason'], 'USER_ID' => $row['user_id'], 'POSTS' => $row['user_posts'] ? $row['user_posts'] : 0, 'REMINDED' => $row['user_reminded'], 'REMINDED_EXPLAIN' => $user->lang('USER_LAST_REMINDED', (int) $row['user_reminded'], $user->format_date($row['user_reminded_time'])), 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=users&mode=overview')), 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), 'U_USER_ADMIN' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&mode=overview&u={$row['user_id']}"), 'U_SEARCH_USER' => $auth->acl_get('u_search') ? append_sid("{$phpbb_root_path}search.{$phpEx}", "author_id={$row['user_id']}&sr=posts") : '')); } $option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE'); if ($config['email_enable']) { $option_ary += array('remind' => 'REMIND'); } $template->assign_vars(array('S_INACTIVE_USERS' => true, 'S_INACTIVE_OPTIONS' => build_select($option_ary))); } // Warn if install is still present if (file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install')) { $template->assign_var('S_REMOVE_INSTALL', true); } // Warn if no search index is created if ($config['num_posts'] && class_exists($config['search_type'])) { $error = false; $search_type = $config['search_type']; $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher); if (!$search->index_created()) { $template->assign_vars(array('S_SEARCH_INDEX_MISSING' => true, 'L_NO_SEARCH_INDEX' => $user->lang('NO_SEARCH_INDEX', $search->get_name(), '<a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=acp_search&mode=index') . '">', '</a>'))); } } if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && phpbb_is_writable($phpbb_root_path . 'config.' . $phpEx)) { // World-Writable? (000x) $template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x2)); } if (extension_loaded('mbstring')) { $template->assign_vars(array('S_MBSTRING_LOADED' => true, 'S_MBSTRING_FUNC_OVERLOAD_FAIL' => intval(@ini_get('mbstring.func_overload')) & (MB_OVERLOAD_MAIL | MB_OVERLOAD_STRING), 'S_MBSTRING_ENCODING_TRANSLATION_FAIL' => @ini_get('mbstring.encoding_translation') != 0, 'S_MBSTRING_HTTP_INPUT_FAIL' => !in_array(@ini_get('mbstring.http_input'), array('pass', '')), 'S_MBSTRING_HTTP_OUTPUT_FAIL' => !in_array(@ini_get('mbstring.http_output'), array('pass', '')))); } // Fill dbms version if not yet filled if (empty($config['dbms_version'])) { set_config('dbms_version', $db->sql_server_info(true)); } $this->tpl_name = 'acp_main'; $this->page_title = 'ACP_MAIN'; }
/** * The function which does the actual work (or dispatches it to the relevant places) */ function convert_data($sub) { global $template, $user, $phpbb_root_path, $phpEx, $db, $lang, $config, $cache; global $convert, $convert_row, $message_parser, $skip_rows, $language; require $phpbb_root_path . 'config.' . $phpEx; require $phpbb_root_path . 'includes/constants.' . $phpEx; require $phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx; require $phpbb_root_path . 'includes/functions_convert.' . $phpEx; $db = new $sql_db(); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true); unset($dbpasswd); $sql = 'SELECT * FROM ' . CONFIG_TABLE; $result = $db->sql_query($sql); $config = array(); while ($row = $db->sql_fetchrow($result)) { $config[$row['config_name']] = $row['config_value']; } $db->sql_freeresult($result); // Override a couple of config variables for the duration $config['max_quote_depth'] = 0; // @todo Need to confirm that max post length in source is <= max post length in destination or there may be interesting formatting issues $config['max_post_chars'] = $config['min_post_chars'] = 0; // Set up a user as well. We _should_ have enough of a database here at this point to do this // and it helps for any core code we call $user->session_begin(); $user->page = $user->extract_current_page($phpbb_root_path); // This is a little bit of a fudge, but it allows the language entries to be available to the // core code without us loading them again $user->lang =& $lang; $this->page_title = $user->lang['STAGE_IN_PROGRESS']; $convert->options = array(); if (isset($config['convert_progress'])) { $convert->options = unserialize($config['convert_progress']); $convert->options = array_merge($convert->options, unserialize($config['convert_db_server']), unserialize($config['convert_db_user']), unserialize($config['convert_options'])); } // This information should have already been checked once, but do it again for safety if (empty($convert->options) || empty($convert->options['tag']) || !isset($convert->options['dbms']) || !isset($convert->options['dbhost']) || !isset($convert->options['dbport']) || !isset($convert->options['dbuser']) || !isset($convert->options['dbpasswd']) || !isset($convert->options['dbname']) || !isset($convert->options['table_prefix'])) { $this->p_master->error($user->lang['NO_CONVERT_SPECIFIED'], __LINE__, __FILE__); } // Make some short variables accessible, for easier referencing $convert->convertor_tag = basename($convert->options['tag']); $convert->src_dbms = $convert->options['dbms']; $convert->src_dbhost = $convert->options['dbhost']; $convert->src_dbport = $convert->options['dbport']; $convert->src_dbuser = $convert->options['dbuser']; $convert->src_dbpasswd = $convert->options['dbpasswd']; $convert->src_dbname = $convert->options['dbname']; $convert->src_table_prefix = $convert->options['table_prefix']; // initiate database connection to old db if old and new db differ global $src_db, $same_db; $src_db = $same_db = null; if ($convert->src_dbms != $dbms || $convert->src_dbhost != $dbhost || $convert->src_dbport != $dbport || $convert->src_dbname != $dbname || $convert->src_dbuser != $dbuser) { if ($convert->src_dbms != $dbms) { require $phpbb_root_path . 'includes/db/' . $convert->src_dbms . '.' . $phpEx; } $sql_db = 'dbal_' . $convert->src_dbms; $src_db = new $sql_db(); $src_db->sql_connect($convert->src_dbhost, $convert->src_dbuser, htmlspecialchars_decode($convert->src_dbpasswd), $convert->src_dbname, $convert->src_dbport, false, true); $same_db = false; } else { $src_db = $db; $same_db = true; } $convert->mysql_convert = false; switch ($src_db->sql_layer) { case 'sqlite': case 'firebird': $convert->src_truncate_statement = 'DELETE FROM '; break; // Thanks MySQL, for silently converting... // Thanks MySQL, for silently converting... case 'mysql': case 'mysql4': if (version_compare($src_db->sql_server_info(true, false), '4.1.3', '>=')) { $convert->mysql_convert = true; } $convert->src_truncate_statement = 'TRUNCATE TABLE '; break; case 'mysqli': $convert->mysql_convert = true; $convert->src_truncate_statement = 'TRUNCATE TABLE '; break; default: $convert->src_truncate_statement = 'TRUNCATE TABLE '; break; } if ($convert->mysql_convert && !$same_db) { $src_db->sql_query("SET NAMES 'binary'"); } switch ($db->sql_layer) { case 'sqlite': case 'firebird': $convert->truncate_statement = 'DELETE FROM '; break; default: $convert->truncate_statement = 'TRUNCATE TABLE '; break; } $get_info = false; // check security implications of direct inclusion if (!file_exists('./convertors/convert_' . $convert->convertor_tag . '.' . $phpEx)) { $this->p_master->error($user->lang['CONVERT_NOT_EXIST'], __LINE__, __FILE__); } if (file_exists('./convertors/functions_' . $convert->convertor_tag . '.' . $phpEx)) { include './convertors/functions_' . $convert->convertor_tag . '.' . $phpEx; } $get_info = true; include './convertors/convert_' . $convert->convertor_tag . '.' . $phpEx; // Map some variables... $convert->convertor_data = $convertor_data; $convert->tables = $tables; $convert->config_schema = $config_schema; // Now include the real data $get_info = false; include './convertors/convert_' . $convert->convertor_tag . '.' . $phpEx; $convert->convertor_data = $convertor_data; $convert->tables = $tables; $convert->config_schema = $config_schema; $convert->convertor = $convertor; // The test_file is a file that should be present in the location of the old board. if (!file_exists($convert->options['forum_path'] . '/' . $test_file)) { $this->p_master->error(sprintf($user->lang['COULD_NOT_FIND_PATH'], $convert->options['forum_path']), __LINE__, __FILE__); } $search_type = basename(trim($config['search_type'])); // For conversions we are a bit less strict and set to a search backend we know exist... if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx)) { $search_type = 'fulltext_native'; set_config('search_type', $search_type); } if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx)) { trigger_error('NO_SUCH_SEARCH_MODULE'); } require $phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx; $error = false; $convert->fulltext_search = new $search_type($error); if ($error) { trigger_error($error); } include $phpbb_root_path . 'includes/message_parser.' . $phpEx; $message_parser = new parse_message(); $jump = request_var('jump', 0); $final_jump = request_var('final_jump', 0); $sync_batch = request_var('sync_batch', -1); $last_statement = request_var('last', 0); // We are running sync... if ($sync_batch >= 0) { $this->sync_forums($sync_batch); return; } if ($jump) { $this->jump($jump, $last_statement); return; } if ($final_jump) { $this->final_jump($final_jump); return; } $current_table = request_var('current_table', 0); $old_current_table = min(-1, $current_table - 1); $skip_rows = request_var('skip_rows', 0); if (!$current_table && !$skip_rows) { if (empty($_REQUEST['confirm'])) { // If avatars / ranks / smilies folders are specified make sure they are writable $bad_folders = array(); $local_paths = array('avatar_path' => path($config['avatar_path']), 'avatar_gallery_path' => path($config['avatar_gallery_path']), 'icons_path' => path($config['icons_path']), 'ranks_path' => path($config['ranks_path']), 'smilies_path' => path($config['smilies_path'])); foreach ($local_paths as $folder => $local_path) { if (isset($convert->convertor[$folder])) { if (empty($convert->convertor['test_file'])) { // test_file is mandantory at the moment so this should never be reached, but just in case... $this->p_master->error($user->lang['DEV_NO_TEST_FILE'], __LINE__, __FILE__); } if (!$local_path || !phpbb_is_writable($phpbb_root_path . $local_path)) { if (!$local_path) { $bad_folders[] = sprintf($user->lang['CONFIG_PHPBB_EMPTY'], $folder); } else { $bad_folders[] = $local_path; } } } } if (sizeof($bad_folders)) { $msg = sizeof($bad_folders) == 1 ? $user->lang['MAKE_FOLDER_WRITABLE'] : $user->lang['MAKE_FOLDERS_WRITABLE']; sort($bad_folders); $this->p_master->error(sprintf($msg, implode('<br />', $bad_folders)), __LINE__, __FILE__, true); $template->assign_vars(array('L_SUBMIT' => $user->lang['INSTALL_TEST'], 'U_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&sub=in_progress&tag={$convert->convertor_tag}&language={$language}")); return; } // Grab all the tables used in convertor $missing_tables = $tables_list = $aliases = array(); foreach ($convert->convertor['schema'] as $schema) { // Skip those not used (because of addons/plugins not detected) if (!$schema['target']) { continue; } foreach ($schema as $key => $val) { // we're dealing with an array like: // array('forum_status', 'forums.forum_status', 'is_item_locked') if (is_int($key) && !empty($val[1])) { $temp_data = $val[1]; if (!is_array($temp_data)) { $temp_data = array($temp_data); } foreach ($temp_data as $val) { if (preg_match('/([a-z0-9_]+)\\.([a-z0-9_]+)\\)* ?A?S? ?([a-z0-9_]*?)\\.?([a-z0-9_]*)$/i', $val, $m)) { $table = $convert->src_table_prefix . $m[1]; $tables_list[$table] = $table; if (!empty($m[3])) { $aliases[] = $convert->src_table_prefix . $m[3]; } } } } else { if ($key == 'left_join') { // Convert the value if it wasn't an array already. if (!is_array($val)) { $val = array($val); } for ($j = 0; $j < sizeof($val); ++$j) { if (preg_match('/LEFT JOIN ([a-z0-9_]+) AS ([a-z0-9_]+)/i', $val[$j], $m)) { $table = $convert->src_table_prefix . $m[1]; $tables_list[$table] = $table; if (!empty($m[2])) { $aliases[] = $convert->src_table_prefix . $m[2]; } } } } } } } // Remove aliased tables from $tables_list foreach ($aliases as $alias) { unset($tables_list[$alias]); } // Check if the tables that we need exist $src_db->sql_return_on_error(true); foreach ($tables_list as $table => $null) { $sql = 'SELECT 1 FROM ' . $table; $_result = $src_db->sql_query_limit($sql, 1); if (!$_result) { $missing_tables[] = $table; } $src_db->sql_freeresult($_result); } $src_db->sql_return_on_error(false); // Throw an error if some tables are missing // We used to do some guessing here, but since we have a suggestion of possible values earlier, I don't see it adding anything here to do it again if (sizeof($missing_tables) == sizeof($tables_list)) { $this->p_master->error($user->lang['NO_TABLES_FOUND'] . ' ' . $user->lang['CHECK_TABLE_PREFIX'], __LINE__, __FILE__); } else { if (sizeof($missing_tables)) { $this->p_master->error(sprintf($user->lang['TABLES_MISSING'], implode(', ', $missing_tables)) . '<br /><br />' . $user->lang['CHECK_TABLE_PREFIX'], __LINE__, __FILE__); } } $url = $this->save_convert_progress('&confirm=1'); $msg = $user->lang['PRE_CONVERT_COMPLETE']; if ($convert->convertor_data['author_notes']) { $msg .= '</p><p>' . sprintf($user->lang['AUTHOR_NOTES'], $convert->convertor_data['author_notes']); } $template->assign_vars(array('L_SUBMIT' => $user->lang['CONTINUE_CONVERT'], 'L_MESSAGE' => $msg, 'U_ACTION' => $url)); return; } // if (empty($_REQUEST['confirm'])) $template->assign_block_vars('checks', array('S_LEGEND' => true, 'LEGEND' => $user->lang['STARTING_CONVERT'])); // Convert the config table and load the settings of the old board if (!empty($convert->config_schema)) { restore_config($convert->config_schema); // Override a couple of config variables for the duration $config['max_quote_depth'] = 0; // @todo Need to confirm that max post length in source is <= max post length in destination or there may be interesting formatting issues $config['max_post_chars'] = $config['min_post_chars'] = 0; } $template->assign_block_vars('checks', array('TITLE' => $user->lang['CONFIG_CONVERT'], 'RESULT' => $user->lang['DONE'])); // Now process queries and execute functions that have to be executed prior to the conversion if (!empty($convert->convertor['execute_first'])) { eval($convert->convertor['execute_first']); } if (!empty($convert->convertor['query_first'])) { if (!is_array($convert->convertor['query_first'])) { $convert->convertor['query_first'] = array('target', array($convert->convertor['query_first'])); } else { if (!is_array($convert->convertor['query_first'][0])) { $convert->convertor['query_first'] = array(array($convert->convertor['query_first'][0], $convert->convertor['query_first'][1])); } } foreach ($convert->convertor['query_first'] as $query_first) { if ($query_first[0] == 'src') { if ($convert->mysql_convert && $same_db) { $src_db->sql_query("SET NAMES 'binary'"); } $src_db->sql_query($query_first[1]); if ($convert->mysql_convert && $same_db) { $src_db->sql_query("SET NAMES 'utf8'"); } } else { $db->sql_query($query_first[1]); } } } $template->assign_block_vars('checks', array('TITLE' => $user->lang['PREPROCESS_STEP'], 'RESULT' => $user->lang['DONE'])); } // if (!$current_table && !$skip_rows) $template->assign_block_vars('checks', array('S_LEGEND' => true, 'LEGEND' => $user->lang['FILLING_TABLES'])); // This loop takes one target table and processes it while ($current_table < sizeof($convert->convertor['schema'])) { $schema = $convert->convertor['schema'][$current_table]; // The target table isn't set, this can be because a module (for example the attachement mod) is taking care of this. if (empty($schema['target'])) { $current_table++; continue; } $template->assign_block_vars('checks', array('TITLE' => sprintf($user->lang['FILLING_TABLE'], $schema['target']))); // This is only the case when we first start working on the tables. if (!$skip_rows) { // process execute_first and query_first for this table... if (!empty($schema['execute_first'])) { eval($schema['execute_first']); } if (!empty($schema['query_first'])) { if (!is_array($schema['query_first'])) { $schema['query_first'] = array('target', array($schema['query_first'])); } else { if (!is_array($schema['query_first'][0])) { $schema['query_first'] = array(array($schema['query_first'][0], $schema['query_first'][1])); } } foreach ($schema['query_first'] as $query_first) { if ($query_first[0] == 'src') { if ($convert->mysql_convert && $same_db) { $src_db->sql_query("SET NAMES 'binary'"); } $src_db->sql_query($query_first[1]); if ($convert->mysql_convert && $same_db) { $src_db->sql_query("SET NAMES 'utf8'"); } } else { $db->sql_query($query_first[1]); } } } if (!empty($schema['autoincrement'])) { switch ($db->sql_layer) { case 'postgres': $db->sql_query("SELECT SETVAL('" . $schema['target'] . "_seq',(select case when max(" . $schema['autoincrement'] . ")>0 then max(" . $schema['autoincrement'] . ")+1 else 1 end from " . $schema['target'] . '));'); break; case 'oracle': $result = $db->sql_query('SELECT MAX(' . $schema['autoincrement'] . ') as max_id FROM ' . $schema['target']); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $largest_id = (int) $row['max_id']; if ($largest_id) { $db->sql_query('DROP SEQUENCE ' . $schema['target'] . '_seq'); $db->sql_query('CREATE SEQUENCE ' . $schema['target'] . '_seq START WITH ' . ($largest_id + 1)); } break; } } } // Process execute_always for this table // This is for code which needs to be executed on every pass of this table if // it gets split because of time restrictions if (!empty($schema['execute_always'])) { eval($schema['execute_always']); } // // Set up some variables // // $waiting_rows holds rows for multirows insertion (MySQL only) // $src_tables holds unique tables with aliases to select from // $src_fields will quickly refer source fields (or aliases) corresponding to the current index // $select_fields holds the names of the fields to retrieve // $sql_data = array('source_fields' => array(), 'target_fields' => array(), 'source_tables' => array(), 'select_fields' => array()); // This statement is building the keys for later insertion. $insert_query = $this->build_insert_query($schema, $sql_data, $current_table); // If no source table is affected, we skip the table if (empty($sql_data['source_tables'])) { $skip_rows = 0; $current_table++; continue; } $distinct = !empty($schema['distinct']) ? 'DISTINCT ' : ''; $sql = 'SELECT ' . $distinct . implode(', ', $sql_data['select_fields']) . " \nFROM " . implode(', ', $sql_data['source_tables']); // Where $sql .= !empty($schema['where']) ? "\nWHERE (" . $schema['where'] . ')' : ''; // Group By if (!empty($schema['group_by'])) { $schema['group_by'] = array($schema['group_by']); foreach ($sql_data['select_fields'] as $select) { $alias = strpos(strtolower($select), ' as '); $select = $alias ? substr($select, 0, $alias) : $select; if (!in_array($select, $schema['group_by'])) { $schema['group_by'][] = $select; } } } $sql .= !empty($schema['group_by']) ? "\nGROUP BY " . implode(', ', $schema['group_by']) : ''; // Having $sql .= !empty($schema['having']) ? "\nHAVING " . $schema['having'] : ''; // Order By if (empty($schema['order_by']) && !empty($schema['primary'])) { $schema['order_by'] = $schema['primary']; } $sql .= !empty($schema['order_by']) ? "\nORDER BY " . $schema['order_by'] : ''; // Counting basically holds the amount of rows processed. $counting = -1; $batch_time = 0; while ($counting === -1 || $counting >= $convert->batch_size && still_on_time()) { $old_current_table = $current_table; $rows = ''; $waiting_rows = array(); if (!empty($batch_time)) { $mtime = explode(' ', microtime()); $mtime = $mtime[0] + $mtime[1]; $rows = ceil($counting / ($mtime - $batch_time)) . " rows/s ({$counting} rows) | "; } $template->assign_block_vars('checks', array('TITLE' => "skip_rows = {$skip_rows}", 'RESULT' => $rows . (defined('DEBUG_EXTRA') && function_exists('memory_get_usage') ? ceil(memory_get_usage() / 1024) . ' ' . $user->lang['KIB'] : ''))); $mtime = explode(' ', microtime()); $batch_time = $mtime[0] + $mtime[1]; if ($convert->mysql_convert && $same_db) { $src_db->sql_query("SET NAMES 'binary'"); } // Take skip rows into account and only fetch batch_size amount of rows $___result = $src_db->sql_query_limit($sql, $convert->batch_size, $skip_rows); if ($convert->mysql_convert && $same_db) { $src_db->sql_query("SET NAMES 'utf8'"); } // This loop processes each row $counting = 0; $convert->row = $convert_row = array(); if (!empty($schema['autoincrement'])) { switch ($db->sql_layer) { case 'mssql': case 'mssql_odbc': case 'mssqlnative': $db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' ON'); break; } } // Now handle the rows until time is over or no more rows to process... while ($counting === 0 || still_on_time()) { $convert_row = $src_db->sql_fetchrow($___result); if (!$convert_row) { // move to the next batch or table break; } // With this we are able to always save the last state $convert->row = $convert_row; // Increment the counting variable, it stores the number of rows we have processed $counting++; $insert_values = array(); $sql_flag = $this->process_row($schema, $sql_data, $insert_values); if ($sql_flag === true) { switch ($db->sql_layer) { // If MySQL, we'll wait to have num_wait_rows rows to submit at once case 'mysql': case 'mysql4': case 'mysqli': $waiting_rows[] = '(' . implode(', ', $insert_values) . ')'; if (sizeof($waiting_rows) >= $convert->num_wait_rows) { $errored = false; $db->sql_return_on_error(true); if (!$db->sql_query($insert_query . implode(', ', $waiting_rows))) { $errored = true; } $db->sql_return_on_error(false); if ($errored) { $db->sql_return_on_error(true); // Because it errored out we will try to insert the rows one by one... most of the time this // is caused by duplicate entries - but we also do not want to miss one... foreach ($waiting_rows as $waiting_sql) { if (!$db->sql_query($insert_query . $waiting_sql)) { $this->p_master->db_error($user->lang['DB_ERR_INSERT'], htmlspecialchars($insert_query . $waiting_sql) . '<br /><br />' . htmlspecialchars(print_r($db->_sql_error(), true)), __LINE__, __FILE__, true); } } $db->sql_return_on_error(false); } $waiting_rows = array(); } break; default: $insert_sql = $insert_query . '(' . implode(', ', $insert_values) . ')'; $db->sql_return_on_error(true); if (!$db->sql_query($insert_sql)) { $this->p_master->db_error($user->lang['DB_ERR_INSERT'], htmlspecialchars($insert_sql) . '<br /><br />' . htmlspecialchars(print_r($db->_sql_error(), true)), __LINE__, __FILE__, true); } $db->sql_return_on_error(false); $waiting_rows = array(); break; } } $skip_rows++; } $src_db->sql_freeresult($___result); // We might still have some rows waiting if (sizeof($waiting_rows)) { $errored = false; $db->sql_return_on_error(true); if (!$db->sql_query($insert_query . implode(', ', $waiting_rows))) { $errored = true; } $db->sql_return_on_error(false); if ($errored) { $db->sql_return_on_error(true); // Because it errored out we will try to insert the rows one by one... most of the time this // is caused by duplicate entries - but we also do not want to miss one... foreach ($waiting_rows as $waiting_sql) { $db->sql_query($insert_query . $waiting_sql); $this->p_master->db_error($user->lang['DB_ERR_INSERT'], htmlspecialchars($insert_query . $waiting_sql) . '<br /><br />' . htmlspecialchars(print_r($db->_sql_error(), true)), __LINE__, __FILE__, true); } $db->sql_return_on_error(false); } $waiting_rows = array(); } if (!empty($schema['autoincrement'])) { switch ($db->sql_layer) { case 'mssql': case 'mssql_odbc': case 'mssqlnative': $db->sql_query('SET IDENTITY_INSERT ' . $schema['target'] . ' OFF'); break; case 'postgres': $db->sql_query("SELECT SETVAL('" . $schema['target'] . "_seq',(select case when max(" . $schema['autoincrement'] . ")>0 then max(" . $schema['autoincrement'] . ")+1 else 1 end from " . $schema['target'] . '));'); break; case 'oracle': $result = $db->sql_query('SELECT MAX(' . $schema['autoincrement'] . ') as max_id FROM ' . $schema['target']); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $largest_id = (int) $row['max_id']; if ($largest_id) { $db->sql_query('DROP SEQUENCE ' . $schema['target'] . '_seq'); $db->sql_query('CREATE SEQUENCE ' . $schema['target'] . '_seq START WITH ' . ($largest_id + 1)); } break; } } } // When we reach this point, either the current table has been processed or we're running out of time. if (still_on_time() && $counting < $convert->batch_size) { $skip_rows = 0; $current_table++; } else { /* if (still_on_time() && $counting < $convert->batch_size) { $skip_rows = 0; $current_table++; }*/ // Looks like we ran out of time. $url = $this->save_convert_progress('&current_table=' . $current_table . '&skip_rows=' . $skip_rows); $current_table++; // $percentage = ($skip_rows == 0) ? 0 : floor(100 / ($total_rows / $skip_rows)); $msg = sprintf($user->lang['STEP_PERCENT_COMPLETED'], $current_table, sizeof($convert->convertor['schema'])); $template->assign_vars(array('L_MESSAGE' => $msg, 'L_SUBMIT' => $user->lang['CONTINUE_CONVERT'], 'U_ACTION' => $url)); $this->meta_refresh($url); return; } } // Process execute_last then we'll be done $url = $this->save_convert_progress('&jump=1'); $template->assign_vars(array('L_SUBMIT' => $user->lang['FINAL_STEP'], 'U_ACTION' => $url)); $this->meta_refresh($url); return; }
/** * Checks whether the chunk we are about to deal with was actually uploaded * by PHP and actually exists, if not, it generates an error * * @param string $form_name The name of the file in the form data * * @return null */ protected function integrate_uploaded_file($form_name, $chunk, $file_path) { $is_multipart = $this->is_multipart(); $upload = $this->request->file($form_name); if ($is_multipart && (!isset($upload['tmp_name']) || !is_uploaded_file($upload['tmp_name']))) { $this->emit_error(103, 'PLUPLOAD_ERR_MOVE_UPLOADED'); } $tmp_file = $this->temporary_filepath($upload['tmp_name']); if (!phpbb_is_writable($this->temporary_directory) || !move_uploaded_file($upload['tmp_name'], $tmp_file)) { $this->emit_error(103, 'PLUPLOAD_ERR_MOVE_UPLOADED'); } $out = fopen("{$file_path}.part", $chunk == 0 ? 'wb' : 'ab'); if (!$out) { $this->emit_error(102, 'PLUPLOAD_ERR_OUTPUT'); } $in = fopen($is_multipart ? $tmp_file : 'php://input', 'rb'); if (!$in) { $this->emit_error(101, 'PLUPLOAD_ERR_INPUT'); } while ($buf = fread($in, 4096)) { fwrite($out, $buf); } fclose($in); fclose($out); if ($is_multipart) { unlink($tmp_file); } }
public static function _is_writable($file, $path = 'gallery', $sub_directory = 'includes/') { return phpbb_is_writable(self::path($path) . $sub_directory . self::phpEx_file($file)); }