Exemple #1
0
/**
* Main file
*
* @package mpv_server
* @version $Id$
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*
*/
function end_output()
{
    global $starttime, $lang;
    // Some debug stuff.
    $mtime = explode(' ', microtime());
    $totaltime = $mtime[0] + $mtime[1] - $starttime;
    if (is_array($lang)) {
        $debug_output = "\n" . sprintf($lang['TOTAL_TIME'], $totaltime);
    } else {
        $debug_output = "\n" . sprintf('Time : %.3fs', $totaltime);
    }
    if (function_exists('memory_get_usage') && is_array($lang)) {
        if ($memory_usage = memory_get_usage()) {
            global $base_memory_usage;
            $memory_usage -= $base_memory_usage;
            $memory_usage = get_formatted_filesize($memory_usage);
            $debug_output .= ' | ' . $lang['MEM_USE'] . ' ' . $memory_usage;
        }
    }
    print $debug_output . "\n" . (HTML_HEADERS ? "</body></html>" : "");
}
Exemple #2
0
 /**
  * Adjust all three max_filesize config vars for display
  */
 function max_filesize($value, $key = '')
 {
     // Determine size var and adjust the value accordingly
     $filesize = get_formatted_filesize($value, false, array('mb', 'kb', 'b'));
     $size_var = $filesize['si_identifier'];
     $value = $filesize['value'];
     // size and maxlength must not be specified for input of type number
     return '<input type="number" id="' . $key . '" min="0" max="999999999999999" step="any" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
 }
Exemple #3
0
 $size = $item instanceof steam_document ? $data_result[$data_tnr[$item->get_id()]["contentsize"]] : 0;
 if ($item instanceof steam_container || $item instanceof steam_room) {
     $content->setVariable("LINK_ITEM", $base_url . $item->get_id());
     $edit_link = $base_url . $item->get_id() . "/" . "edit";
     $delete_link = $base_url . $item->get_id() . "/" . "delete";
 } else {
     if ($item instanceof steam_docextern) {
         $content->setVariable("LINK_ITEM", $attributes[DOC_EXTERN_URL]);
         $edit_link = PATH_URL . "doc/" . $item->get_id() . "/" . "edit";
         $delete_link = PATH_URL . "doc/" . $item->get_id() . "/" . "delete";
     } else {
         // Document
         //      $content->setVariable( "LINK_ITEM", PATH_URL . "get_document.php?id=" . $item->get_id() );
         $content->setVariable("LINK_ITEM", PATH_URL . "download/" . $item->get_id() . "/" . rawurlencode($attributes[OBJ_NAME]));
         //$content->setVariable( "LINK_ITEM", PATH_URL . "doc/" . $item->get_id() . "/");
         $content->setVariable("SIZE_ITEM", get_formatted_filesize($size));
         $last_modified = $attributes[DOC_LAST_MODIFIED];
         $edit_link = PATH_URL . "doc/" . $item->get_id() . "/edit";
         $delete_link = PATH_URL . "doc/" . $item->get_id() . "/delete";
     }
 }
 if (!isset($last_modified) || $last_modified == 0) {
     $last_modified = $attributes[OBJ_CREATION_TIME];
 }
 if ($last_modified != 0) {
     $authorname = $author_result[$author_tnr[$item->get_id()]["authorname"]];
     $authorstring = "<a href=\"" . PATH_URL . "user/" . $authorname . "/\">" . $authorname . "</a>";
     $modifiedstring = $authorstring . "<br />" . "<small>" . strftime("%x", $last_modified) . strftime(", %R", $last_modified) . "</small>";
     $content->setVariable("MODIFIED_ITEM", $modifiedstring);
 }
 $content->setVariable("VALUE_COMMENTS", str_replace("%NO_COMMENTS", count($data_result[$data_tnr[$item->get_id()]["annotations"]]), gettext("%NO_COMMENTS comments")));
Exemple #4
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx;
        global $phpbb_dispatcher, $request;
        global $phpbb_container, $phpbb_log;
        $user->add_lang(array('posting', 'ucp', 'acp/users'));
        $this->tpl_name = 'acp_users';
        $error = array();
        $username = $request->variable('username', '', true);
        $user_id = $request->variable('u', 0);
        $action = $request->variable('action', '');
        // Get referer to redirect user to the appropriate page after delete action
        $redirect = $request->variable('redirect', '');
        $redirect_tag = "redirect={$redirect}";
        $redirect_url = append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$redirect}");
        $submit = isset($_POST['update']) && !isset($_POST['cancel']) ? true : false;
        $form_name = 'acp_users';
        add_form_key($form_name);
        // Whois (special case)
        if ($action == 'whois') {
            if (!function_exists('user_get_id_name')) {
                include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
            }
            $this->page_title = 'WHOIS';
            $this->tpl_name = 'simple_body';
            $user_ip = phpbb_ip_normalise($request->variable('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&amp;form=select_user&amp;field=username&amp;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 = 'acp_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_self($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' => empty($redirect) ? $this->u_action : $redirect_url, 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$id}&amp;u={$user_id}"), 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id . (empty($redirect) ? '' : '&amp;' . $redirect_tag), '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);
        }
        $this->page_title = $user_row['username'] . ' :: ' . $user->lang('ACP_USER_' . strtoupper($mode));
        switch ($mode) {
            case 'overview':
                if (!function_exists('user_get_id_name')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                $user->add_lang('acp/ban');
                $delete = $request->variable('delete', 0);
                $delete_type = $request->variable('delete_type', '');
                $ip = $request->variable('ip', 'ip');
                /**
                 * Run code at beginning of ACP users overview
                 *
                 * @event core.acp_users_overview_before
                 * @var	array   user_row    Current user data
                 * @var	string  mode        Active module
                 * @var	string  action      Module that should be run
                 * @var	bool    submit      Do we display the form only
                 *                          or did the user press submit
                 * @var	array   error       Array holding error messages
                 * @since 3.1.3-RC1
                 */
                $vars = array('user_row', 'mode', 'action', 'submit', 'error');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_before', compact($vars)));
                if ($submit) {
                    if ($delete) {
                        if (!$auth->acl_get('a_userdel')) {
                            send_status_line(403, 'Forbidden');
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . '&amp;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 . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        // Founders can not be deleted.
                        if ($user_row['user_type'] == USER_FOUNDER) {
                            trigger_error($user->lang['CANNOT_REMOVE_FOUNDER'] . adm_back_link($this->u_action . '&amp;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 . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        if ($delete_type) {
                            if (confirm_box(true)) {
                                user_delete($delete_type, $user_id, $user_row['username']);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DELETED', false, array($user_row['username']));
                                trigger_error($user->lang['USER_DELETED'] . adm_back_link(empty($redirect) ? $this->u_action : $redirect_url));
                            } else {
                                $delete_confirm_hidden_fields = array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true, 'delete' => 1, 'delete_type' => $delete_type);
                                // Checks if the redirection page is specified
                                if (!empty($redirect)) {
                                    $delete_confirm_hidden_fields['redirect'] = $redirect;
                                }
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($delete_confirm_hidden_fields));
                            }
                        } else {
                            trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action . '&amp;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 . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_id == ANONYMOUS) {
                                trigger_error($user->lang['CANNOT_BAN_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;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 . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $ban = array();
                            switch ($action) {
                                case 'banuser':
                                    $ban[] = $user_row['username'];
                                    $reason = 'USER_ADMIN_BAN_NAME_REASON';
                                    break;
                                case 'banemail':
                                    $ban[] = $user_row['user_email'];
                                    $reason = 'USER_ADMIN_BAN_EMAIL_REASON';
                                    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';
                                    break;
                            }
                            $ban_reason = $request->variable('ban_reason', $user->lang[$reason], true);
                            $ban_give_reason = $request->variable('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 . '&amp;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 . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;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 . '&amp;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 . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($config['email_enable']) {
                                if (!class_exists('messenger')) {
                                    include $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->set_addresses($user_row);
                                $messenger->anti_abuse_headers($config, $user);
                                $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);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_REACTIVATE', false, array($user_row['username']));
                                $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_REACTIVATE_USER', false, array('reportee_id' => $user_id));
                                trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&amp;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 . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;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 . '&amp;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 . '&amp;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) {
                                    /* @var $phpbb_notifications \phpbb\notification\manager */
                                    $phpbb_notifications = $phpbb_container->get('notification_manager');
                                    $phpbb_notifications->delete_notifications('notification.type.admin_activate_user', $user_row['user_id']);
                                    if (!class_exists('messenger')) {
                                        include $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                                    }
                                    $messenger = new messenger(false);
                                    $messenger->template('admin_welcome_activated', $user_row['user_lang']);
                                    $messenger->set_addresses($user_row);
                                    $messenger->anti_abuse_headers($config, $user);
                                    $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';
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, $log, false, array($user_row['username']));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, $log . '_USER', false, array('reportee_id' => $user_id));
                            trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delsig':
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;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);
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_SIG', false, array($user_row['username']));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_SIG_USER', false, array('reportee_id' => $user_id));
                            trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delavatar':
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            // Delete old avatar if present
                            /* @var $phpbb_avatar_manager \phpbb\avatar\manager */
                            $phpbb_avatar_manager = $phpbb_container->get('avatar.manager');
                            $phpbb_avatar_manager->handle_avatar_delete($db, $user, $phpbb_avatar_manager->clean_row($user_row, 'user'), USERS_TABLE, 'user_');
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_AVATAR', false, array($user_row['username']));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_AVATAR_USER', false, array('reportee_id' => $user_id));
                            trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delposts':
                            if (confirm_box(true)) {
                                // Delete posts, attachments, etc.
                                delete_posts('poster_id', $user_id);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_POSTS', false, array($user_row['username']));
                                trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&amp;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)) {
                                /** @var \phpbb\attachment\manager $attachment_manager */
                                $attachment_manager = $phpbb_container->get('attachment.manager');
                                $attachment_manager->delete('user', $user_id);
                                unset($attachment_manager);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_ATTACH', false, array($user_row['username']));
                                trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&amp;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);
                                    $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_OUTBOX', false, array($user_row['username']));
                                    $lang = 'EMPTIED';
                                }
                                $db->sql_freeresult($result);
                                trigger_error($user->lang['USER_OUTBOX_' . $lang] . adm_back_link($this->u_action . '&amp;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 . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $user->add_lang('acp/forums');
                            $new_forum_id = $request->variable('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 . "&amp;action={$action}&amp;u={$user_id}", 'U_BACK' => $this->u_action . "&amp;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 . '&amp;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 . '&amp;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, post_visibility, 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, post_visibility";
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                $topic_id_ary[$row['topic_id']][$row['post_visibility']] = $row['total_posts'];
                            }
                            $db->sql_freeresult($result);
                            if (sizeof($topic_id_ary)) {
                                $sql = 'SELECT topic_id, forum_id, topic_title, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, 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 ($topic_id_ary[$row['topic_id']][ITEM_APPROVED] == $row['topic_posts_approved'] && $topic_id_ary[$row['topic_id']][ITEM_UNAPPROVED] == $row['topic_posts_unapproved'] && $topic_id_ary[$row['topic_id']][ITEM_REAPPROVE] == $row['topic_posts_unapproved'] && $topic_id_ary[$row['topic_id']][ITEM_DELETED] == $row['topic_posts_softdeleted']) {
                                        $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_visibility' => ITEM_APPROVED, '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);
                            }
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_MOVE_POSTS', false, array($user_row['username'], $forum_info['forum_name']));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_MOVE_POSTS_USER', false, array('reportee_id' => $user_id, $forum_info['forum_name']));
                            trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'leave_nr':
                            if (confirm_box(true)) {
                                remove_newly_registered($user_id, $user_row);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_REMOVED_NR', false, array($user_row['username']));
                                trigger_error($user->lang['USER_LIFTED_NR'] . adm_back_link($this->u_action . '&amp;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;
                        default:
                            /**
                             * Run custom quicktool code
                             *
                             * @event core.acp_users_overview_run_quicktool
                             * @var	array	user_row	Current user data
                             * @var	string	action		Quick tool that should be run
                             * @since 3.1.0-a1
                             */
                            $vars = array('action', 'user_row');
                            extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_run_quicktool', compact($vars)));
                            break;
                    }
                    // Handle registration info updates
                    $data = array('username' => $request->variable('user', $user_row['username'], true), 'user_founder' => $request->variable('user_founder', $user_row['user_type'] == USER_FOUNDER ? 1 : 0), 'email' => strtolower($request->variable('user_email', $user_row['user_email'])), 'new_password' => $request->variable('new_password', '', true), 'password_confirm' => $request->variable('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('user_email', $user_row['user_email'])));
                    }
                    $error = validate_data($data, $check_ary);
                    if ($data['new_password'] && $data['password_confirm'] != $data['new_password']) {
                        $error[] = 'NEW_PASSWORD_ERROR';
                    }
                    if (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                    // Instantiate passwords manager
                    /* @var $passwords_manager \phpbb\passwords\manager */
                    $passwords_manager = $phpbb_container->get('passwords.manager');
                    // Which updates do we need to do?
                    $update_username = $user_row['username'] != $data['username'] ? $data['username'] : false;
                    $update_password = $data['new_password'] && !$passwords_manager->check($data['new_password'], $user_row['user_password']);
                    $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 . '&amp;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 . '&amp;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 . '&amp;u=' . $user_id), E_USER_WARNING);
                                        }
                                    }
                                }
                            }
                        }
                        /**
                         * Modify user data before we update it
                         *
                         * @event core.acp_users_overview_modify_data
                         * @var	array	user_row	Current user data
                         * @var	array	data		Submitted user data
                         * @var	array	sql_ary		User data we udpate
                         * @since 3.1.0-a1
                         */
                        $vars = array('user_row', 'data', 'sql_ary');
                        extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_modify_data', compact($vars)));
                        if ($update_username !== false) {
                            $sql_ary['username'] = $update_username;
                            $sql_ary['username_clean'] = utf8_clean_string($update_username);
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_NAME', false, array('reportee_id' => $user_id, $user_row['username'], $update_username));
                        }
                        if ($update_email !== false) {
                            $sql_ary += array('user_email' => $update_email, 'user_email_hash' => phpbb_email_hash($update_email));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_EMAIL', false, array('reportee_id' => $user_id, $user_row['username'], $user_row['user_email'], $update_email));
                        }
                        if ($update_password) {
                            $sql_ary += array('user_password' => $passwords_manager->hash($data['new_password']), 'user_passchg' => time());
                            $user->reset_login_keys($user_id);
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_NEW_PASSWORD', false, array('reportee_id' => $user_id, $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);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_USER_UPDATE', false, array($data['username']));
                        trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = array_map(array($user, 'lang'), $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';
                    }
                }
                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);
                }
                /**
                 * Add additional quick tool options and overwrite user data
                 *
                 * @event core.acp_users_display_overview
                 * @var	array	user_row			Array with user data
                 * @var	array	quick_tool_ary		Ouick tool options
                 * @since 3.1.0-a1
                 */
                $vars = array('user_row', 'quick_tool_ary');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_display_overview', compact($vars)));
                $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>';
                }
                $last_active = !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 ' . $db->sql_in_set('post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE));
                $result = $db->sql_query($sql);
                $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
                $db->sql_freeresult($result);
                $sql = 'SELECT post_id
					FROM ' . POSTS_TABLE . '
					WHERE poster_id = ' . $user_id;
                $result = $db->sql_query_limit($sql, 1);
                $user_row['user_has_posts'] = (bool) $db->sql_fetchfield('post_id');
                $db->sql_freeresult($result);
                $template->assign_vars(array('L_NAME_CHARS_EXPLAIN' => $user->lang($config['allow_name_chars'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_name_chars']), $user->lang('CHARACTERS', (int) $config['max_name_chars'])), 'L_CHANGE_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars']), $user->lang('CHARACTERS', (int) $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 . "&amp;u={$user_id}&amp;ip=" . ($ip == 'ip' ? 'hostname' : 'ip'), 'U_WHOIS' => $this->u_action . "&amp;action=whois&amp;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_SEARCH_USER' => $config['load_search'] && $auth->acl_get('u_search') ? append_sid("{$phpbb_root_path}search.{$phpEx}", "author_id={$user_row['user_id']}&amp;sr=posts") : '', '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&amp;u={$user_row['user_id']}&amp;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_active ? $user->format_date($last_active) : ' - ', 'USER_EMAIL' => $user_row['user_email'], 'USER_WARNINGS' => $user_row['user_warnings'], 'USER_POSTS' => $user_row['user_posts'], 'USER_HAS_POSTS' => $user_row['user_has_posts'], 'USER_INACTIVE_REASON' => $inactive_reason));
                break;
            case 'feedback':
                $user->add_lang('mcp');
                // Set up general vars
                $start = $request->variable('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $deleteall = isset($_POST['delall']) ? true : false;
                $marked = $request->variable('mark', array(0));
                $message = $request->variable('message', '', true);
                /* @var $pagination \phpbb\pagination */
                $pagination = $phpbb_container->get('pagination');
                // Sort keys
                $sort_days = $request->variable('st', 0);
                $sort_key = $request->variable('sk', 't');
                $sort_dir = $request->variable('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 . '&amp;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);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CLEAR_USER', false, array($user_row['username']));
                    }
                }
                if ($submit && $message) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_FEEDBACK', false, array($user_row['username']));
                    $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_USER_FEEDBACK', false, array('forum_id' => 0, 'topic_id' => 0, $user_row['username']));
                    $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_GENERAL', false, array('reportee_id' => $user_id, $message));
                    trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&amp;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;
                $start = view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
                $base_url = $this->u_action . "&amp;u={$user_id}&amp;{$u_sort_param}";
                $pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
                $template->assign_vars(array('S_FEEDBACK' => 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
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $deleteall = isset($_POST['delall']) ? true : false;
                $confirm = isset($_POST['confirm']) ? true : false;
                $marked = $request->variable('mark', array(0));
                // Delete entries if requested and able
                if ($deletemark || $deleteall || $confirm) {
                    if (confirm_box(true)) {
                        $where_sql = '';
                        $deletemark = $request->variable('delmarked', 0);
                        $deleteall = $request->variable('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);
                            if ($log_warnings) {
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WARNINGS_DELETED', false, array($user_row['username'], $num_warnings));
                            } else {
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WARNINGS_DELETED_ALL', false, array($user_row['username']));
                            }
                        }
                    } 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':
                if (!function_exists('user_get_id_name')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                /* @var $cp \phpbb\profilefields\manager */
                $cp = $phpbb_container->get('profilefields.manager');
                $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('jabber' => $request->variable('jabber', $user_row['user_jabber'], 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->variable('bday_day', $data['bday_day']);
                $data['bday_month'] = $request->variable('bday_month', $data['bday_month']);
                $data['bday_year'] = $request->variable('bday_year', $data['bday_year']);
                $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
                /**
                 * Modify user data on editing profile in ACP
                 *
                 * @event core.acp_users_modify_profile
                 * @var	array	data		Array with user profile data
                 * @var	bool	submit		Flag indicating if submit button has been pressed
                 * @var	int		user_id		The user id
                 * @var	array	user_row	Array with the full user data
                 * @since 3.1.4-RC1
                 */
                $vars = array('data', 'submit', 'user_id', 'user_row');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_modify_profile', compact($vars)));
                if ($submit) {
                    $error = validate_data($data, array('jabber' => array(array('string', true, 5, 255), array('jabber')), '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';
                    }
                    /**
                     * Validate profile data in ACP before submitting to the database
                     *
                     * @event core.acp_users_profile_validate
                     * @var	bool	submit		Flag indicating if submit button has been pressed
                     * @var	array	data		Array with user profile data
                     * @var	array	error		Array with the form errors
                     * @since 3.1.4-RC1
                     */
                    $vars = array('submit', 'data', 'error');
                    extract($phpbb_dispatcher->trigger_event('core.acp_users_profile_validate', compact($vars)));
                    if (!sizeof($error)) {
                        $sql_ary = array('user_jabber' => $data['jabber'], 'user_birthday' => $data['user_birthday']);
                        /**
                         * Modify profile data in ACP before submitting to the database
                         *
                         * @event core.acp_users_profile_modify_sql_ary
                         * @var	array	cp_data		Array with the user custom profile fields data
                         * @var	array	data		Array with user profile data
                         * @var	int		user_id		The user id
                         * @var	array	user_row	Array with the full user data
                         * @var	array	sql_ary		Array with sql data
                         * @since 3.1.4-RC1
                         */
                        $vars = array('cp_data', 'data', 'user_id', 'user_row', 'sql_ary');
                        extract($phpbb_dispatcher->trigger_event('core.acp_users_profile_modify_sql_ary', compact($vars)));
                        $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 . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = array_map(array($user, 'lang'), $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>";
                }
                $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('JABBER' => $data['jabber'], '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':
                if (!function_exists('user_get_id_name')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                $data = array('dateformat' => $request->variable('dateformat', $user_row['user_dateformat'], true), 'lang' => basename($request->variable('lang', $user_row['user_lang'])), 'tz' => $request->variable('tz', $user_row['user_timezone']), 'style' => $request->variable('style', $user_row['user_style']), 'viewemail' => $request->variable('viewemail', $user_row['user_allow_viewemail']), 'massemail' => $request->variable('massemail', $user_row['user_allow_massemail']), 'hideonline' => $request->variable('hideonline', !$user_row['user_allow_viewonline']), 'notifymethod' => $request->variable('notifymethod', $user_row['user_notify_type']), 'notifypm' => $request->variable('notifypm', $user_row['user_notify_pm']), 'allowpm' => $request->variable('allowpm', $user_row['user_allow_pm']), 'topic_sk' => $request->variable('topic_sk', $user_row['user_topic_sortby_type'] ? $user_row['user_topic_sortby_type'] : 't'), 'topic_sd' => $request->variable('topic_sd', $user_row['user_topic_sortby_dir'] ? $user_row['user_topic_sortby_dir'] : 'd'), 'topic_st' => $request->variable('topic_st', $user_row['user_topic_show_days'] ? $user_row['user_topic_show_days'] : 0), 'post_sk' => $request->variable('post_sk', $user_row['user_post_sortby_type'] ? $user_row['user_post_sortby_type'] : 't'), 'post_sd' => $request->variable('post_sd', $user_row['user_post_sortby_dir'] ? $user_row['user_post_sortby_dir'] : 'a'), 'post_st' => $request->variable('post_st', $user_row['user_post_show_days'] ? $user_row['user_post_show_days'] : 0), 'view_images' => $request->variable('view_images', $this->optionget($user_row, 'viewimg')), 'view_flash' => $request->variable('view_flash', $this->optionget($user_row, 'viewflash')), 'view_smilies' => $request->variable('view_smilies', $this->optionget($user_row, 'viewsmilies')), 'view_sigs' => $request->variable('view_sigs', $this->optionget($user_row, 'viewsigs')), 'view_avatars' => $request->variable('view_avatars', $this->optionget($user_row, 'viewavatars')), 'view_wordcensor' => $request->variable('view_wordcensor', $this->optionget($user_row, 'viewcensors')), 'bbcode' => $request->variable('bbcode', $this->optionget($user_row, 'bbcode')), 'smilies' => $request->variable('smilies', $this->optionget($user_row, 'smilies')), 'sig' => $request->variable('sig', $this->optionget($user_row, 'attachsig')), 'notify' => $request->variable('notify', $user_row['user_notify']));
                /**
                 * Modify users preferences data
                 *
                 * @event core.acp_users_prefs_modify_data
                 * @var	array	data			Array with users preferences data
                 * @var	array	user_row		Array with user data
                 * @since 3.1.0-b3
                 */
                $vars = array('data', 'user_row');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_data', compact($vars)));
                if ($submit) {
                    $error = validate_data($data, array('dateformat' => array('string', false, 1, 64), 'lang' => array('match', false, '#^[a-z_\\-]{2,}$#i'), 'tz' => array('timezone'), '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, '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_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']);
                        /**
                         * Modify SQL query before users preferences are updated
                         *
                         * @event core.acp_users_prefs_modify_sql
                         * @var	array	data			Array with users preferences data
                         * @var	array	user_row		Array with user data
                         * @var	array	sql_ary			SQL array with users preferences data to update
                         * @var	array	error			Array with errors data
                         * @since 3.1.0-b3
                         */
                        $vars = array('data', 'user_row', 'sql_ary', 'error');
                        extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_sql', compact($vars)));
                        if (!sizeof($error)) {
                            $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);
                            // 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 \phpbb\auth\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\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 . '&amp;u=' . $user_id));
                        }
                    }
                    // Replace "error" strings with their real, localised form
                    $error = array_map(array($user, 'lang'), $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>';
                }
                phpbb_timezone_select($template, $user, $data['tz'], true);
                $user_prefs_data = 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'], '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']));
                /**
                 * Modify users preferences data before assigning it to the template
                 *
                 * @event core.acp_users_prefs_modify_template_data
                 * @var	array	data				Array with users preferences data
                 * @var	array	user_row			Array with user data
                 * @var	array	user_prefs_data		Array with users preferences data to be assigned to the template
                 * @since 3.1.0-b3
                 */
                $vars = array('data', 'user_row', 'user_prefs_data');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_template_data', compact($vars)));
                $template->assign_vars($user_prefs_data);
                break;
            case 'avatar':
                $avatars_enabled = false;
                /** @var \phpbb\avatar\manager $phpbb_avatar_manager */
                $phpbb_avatar_manager = $phpbb_container->get('avatar.manager');
                if ($config['allow_avatar']) {
                    $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers();
                    // This is normalised data, without the user_ prefix
                    $avatar_data = \phpbb\avatar\manager::clean_row($user_row, 'user');
                    if ($submit) {
                        if (check_form_key($form_name)) {
                            $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', ''));
                            if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) {
                                $driver = $phpbb_avatar_manager->get_driver($driver_name);
                                $result = $driver->process_form($request, $template, $user, $avatar_data, $error);
                                if ($result && empty($error)) {
                                    // Success! Lets save the result in the database
                                    $result = array('user_avatar_type' => $driver_name, 'user_avatar' => $result['avatar'], 'user_avatar_width' => $result['avatar_width'], 'user_avatar_height' => $result['avatar_height']);
                                    $sql = 'UPDATE ' . USERS_TABLE . '
										SET ' . $db->sql_build_array('UPDATE', $result) . '
										WHERE user_id = ' . (int) $user_id;
                                    $db->sql_query($sql);
                                    trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                                }
                            }
                        } else {
                            trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                    }
                    // Handle deletion of avatars
                    if ($request->is_set_post('avatar_delete')) {
                        if (!confirm_box(true)) {
                            confirm_box(false, $user->lang('CONFIRM_AVATAR_DELETE'), build_hidden_fields(array('avatar_delete' => true)));
                        } else {
                            $phpbb_avatar_manager->handle_avatar_delete($db, $user, $avatar_data, USERS_TABLE, 'user_');
                            trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                    }
                    $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type']));
                    // Assign min and max values before generating avatar driver html
                    $template->assign_vars(array('AVATAR_MIN_WIDTH' => $config['avatar_min_width'], 'AVATAR_MAX_WIDTH' => $config['avatar_max_width'], 'AVATAR_MIN_HEIGHT' => $config['avatar_min_height'], 'AVATAR_MAX_HEIGHT' => $config['avatar_max_height']));
                    foreach ($avatar_drivers as $current_driver) {
                        $driver = $phpbb_avatar_manager->get_driver($current_driver);
                        $avatars_enabled = true;
                        $template->set_filenames(array('avatar' => $driver->get_acp_template_name()));
                        if ($driver->prepare_form($request, $template, $user, $avatar_data, $error)) {
                            $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver);
                            $driver_upper = strtoupper($driver_name);
                            $template->assign_block_vars('avatar_drivers', array('L_TITLE' => $user->lang($driver_upper . '_TITLE'), 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar')));
                        }
                    }
                }
                // Avatar manager is not initialized if avatars are disabled
                if (isset($phpbb_avatar_manager)) {
                    // Replace "error" strings with their real, localised form
                    $error = $phpbb_avatar_manager->localize_errors($user, $error);
                }
                $avatar = phpbb_get_user_avatar($user_row, 'USER_AVATAR', true);
                $template->assign_vars(array('S_AVATAR' => true, 'ERROR' => !empty($error) ? implode('<br />', $error) : '', 'AVATAR' => empty($avatar) ? '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />' : $avatar, 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024), 'S_AVATARS_ENABLED' => $config['allow_avatar'] && $avatars_enabled));
                break;
            case 'rank':
                if ($submit) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $rank_id = $request->variable('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 . '&amp;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':
                if (!function_exists('display_custom_bbcodes')) {
                    include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                }
                $enable_bbcode = $config['allow_sig_bbcode'] ? $this->optionget($user_row, 'sig_bbcode') : false;
                $enable_smilies = $config['allow_sig_smilies'] ? $this->optionget($user_row, 'sig_smilies') : false;
                $enable_urls = $config['allow_sig_links'] ? $this->optionget($user_row, 'sig_links') : false;
                $decoded_message = generate_text_for_edit($user_row['user_sig'], $user_row['user_sig_bbcode_uid'], $user_row['user_sig_bbcode_bitfield']);
                $signature = $request->variable('signature', $decoded_message['text'], true);
                $signature_preview = '';
                if ($submit || $request->is_set_post('preview')) {
                    $enable_bbcode = $config['allow_sig_bbcode'] ? !$request->variable('disable_bbcode', false) : false;
                    $enable_smilies = $config['allow_sig_smilies'] ? !$request->variable('disable_smilies', false) : false;
                    $enable_urls = $config['allow_sig_links'] ? !$request->variable('disable_magic_url', false) : false;
                    if (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                }
                $bbcode_uid = $bbcode_bitfield = $bbcode_flags = '';
                $warn_msg = generate_text_for_storage($signature, $bbcode_uid, $bbcode_bitfield, $bbcode_flags, $enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, $config['allow_sig_links'], 'sig');
                if (sizeof($warn_msg)) {
                    $error += $warn_msg;
                }
                if (!$submit) {
                    // Parse it for displaying
                    $signature_preview = generate_text_for_display($signature, $bbcode_uid, $bbcode_bitfield, $bbcode_flags);
                } else {
                    if (!sizeof($error)) {
                        $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' => $signature, 'user_options' => $user_row['user_options'], 'user_sig_bbcode_uid' => $bbcode_uid, 'user_sig_bbcode_bitfield' => $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 . '&amp;u=' . $user_id));
                    }
                }
                // Replace "error" strings with their real, localised form
                $error = array_map(array($user, 'lang'), $error);
                if ($request->is_set_post('preview')) {
                    $decoded_message = generate_text_for_edit($signature, $bbcode_uid, $bbcode_bitfield);
                }
                /** @var \phpbb\controller\helper $controller_helper */
                $controller_helper = $phpbb_container->get('controller.helper');
                $template->assign_vars(array('S_SIGNATURE' => true, 'SIGNATURE' => $decoded_message['text'], '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' => $user->lang($config['allow_sig_bbcode'] ? 'BBCODE_IS_ON' : 'BBCODE_IS_OFF', '<a href="' . $controller_helper->route('phpbb_help_bbcode_controller') . '">', '</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' => $user->lang('SIGNATURE_EXPLAIN', (int) $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':
                /* @var $pagination \phpbb\pagination */
                $pagination = $phpbb_container->get('pagination');
                $start = $request->variable('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $marked = $request->variable('mark', array(0));
                // Sort keys
                $sort_key = $request->variable('sk', 'a');
                $sort_dir = $request->variable('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);
                        /** @var \phpbb\attachment\manager $attachment_manager */
                        $attachment_manager = $phpbb_container->get('attachment.manager');
                        $attachment_manager->delete('attach', $marked);
                        unset($attachment_manager);
                        $message = sizeof($log_attachments) == 1 ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACHMENTS_DELETED', false, array(implode($user->lang['COMMA_SEPARATOR'], $log_attachments)));
                        trigger_error($message . adm_back_link($this->u_action . '&amp;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['topics_per_page'], $start);
                while ($row = $db->sql_fetchrow($result)) {
                    if ($row['in_message']) {
                        $view_topic = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&amp;p={$row['post_msg_id']}");
                    } else {
                        $view_topic = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_id']}&amp;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&amp;id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic));
                }
                $db->sql_freeresult($result);
                $base_url = $this->u_action . "&amp;u={$user_id}&amp;sk={$sort_key}&amp;sd={$sort_dir}";
                $pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start);
                $template->assign_vars(array('S_ATTACHMENTS' => true, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir));
                break;
            case 'groups':
                if (!function_exists('group_user_attributes')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                $user->add_lang(array('groups', 'acp/groups'));
                $group_id = $request->variable('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 . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                }
                switch ($action) {
                    case 'demote':
                    case 'promote':
                    case 'default':
                        if (!$group_id) {
                            trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;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 . '&amp;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 . '&amp;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 . '&amp;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 . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    if (!$group_id) {
                        trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;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 . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $error = array();
                }
                /** @var \phpbb\group\helper $group_helper */
                $group_helper = $phpbb_container->get('group_helper');
                $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'] . '">' . $group_helper->get_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&amp;mode=manage&amp;action=edit&amp;u={$user_id}&amp;g={$data['group_id']}&amp;back_link=acp_users_groups"), 'U_DEFAULT' => $this->u_action . "&amp;action=default&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_DEMOTE_PROMOTE' => $this->u_action . '&amp;action=' . ($data['group_leader'] ? 'demote' : 'promote') . "&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_APPROVE' => $group_type == 'pending' ? $this->u_action . "&amp;action=approve&amp;u={$user_id}&amp;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':
                if (!class_exists('auth_admin')) {
                    include $phpbb_root_path . 'includes/acp/auth.' . $phpEx;
                }
                $auth_admin = new auth_admin();
                $user->add_lang('acp/permissions');
                add_permission_language();
                $forum_id = $request->variable('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->get_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->get_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 . '&amp;u=' . $user_id, 'U_USER_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&amp;mode=setting_user_global&amp;user_id[]=' . $user_id), 'U_USER_FORUM_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&amp;mode=setting_user_local&amp;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) : ''));
    }
/**
* Generate inline attachment entry
*/
function posting_gen_attachment_entry($attachment_data, &$filename_data, $show_attach_box = true)
{
    global $template, $config, $phpbb_root_path, $phpEx, $user;
    // Some default template variables
    $template->assign_vars(array('S_SHOW_ATTACH_BOX' => $show_attach_box, 'S_HAS_ATTACHMENTS' => sizeof($attachment_data), 'FILESIZE' => $config['max_filesize'], 'FILE_COMMENT' => isset($filename_data['filecomment']) ? $filename_data['filecomment'] : ''));
    if (sizeof($attachment_data)) {
        // We display the posted attachments within the desired order.
        $config['display_order'] ? krsort($attachment_data) : ksort($attachment_data);
        foreach ($attachment_data as $count => $attach_row) {
            $hidden = '';
            $attach_row['real_filename'] = utf8_basename($attach_row['real_filename']);
            foreach ($attach_row as $key => $value) {
                $hidden .= '<input type="hidden" name="attachment_data[' . $count . '][' . $key . ']" value="' . $value . '" />';
            }
            $download_link = append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'mode=view&amp;id=' . (int) $attach_row['attach_id'], true, $attach_row['is_orphan'] ? $user->session_id : false);
            $template->assign_block_vars('attach_row', array('FILENAME' => utf8_basename($attach_row['real_filename']), 'A_FILENAME' => addslashes(utf8_basename($attach_row['real_filename'])), 'FILE_COMMENT' => $attach_row['attach_comment'], 'ATTACH_ID' => $attach_row['attach_id'], 'S_IS_ORPHAN' => $attach_row['is_orphan'], 'ASSOC_INDEX' => $count, 'FILESIZE' => get_formatted_filesize($attach_row['filesize']), 'U_VIEW_ATTACHMENT' => $download_link, 'S_HIDDEN' => $hidden));
        }
    }
    return sizeof($attachment_data);
}
Exemple #6
0
    function main($id, $mode)
    {
        global $template, $user, $db, $config, $phpEx, $phpbb_root_path, $phpbb_container, $request;
        $start = $request->variable('start', 0);
        $sort_key = $request->variable('sk', 'a');
        $sort_dir = $request->variable('sd', 'a');
        $delete = isset($_POST['delete']) ? true : false;
        $delete_ids = array_keys($request->variable('attachment', array(0)));
        if ($delete && sizeof($delete_ids)) {
            // Validate $delete_ids...
            $sql = 'SELECT attach_id
				FROM ' . ATTACHMENTS_TABLE . '
				WHERE poster_id = ' . $user->data['user_id'] . '
					AND is_orphan = 0
					AND ' . $db->sql_in_set('attach_id', $delete_ids);
            $result = $db->sql_query($sql);
            $delete_ids = array();
            while ($row = $db->sql_fetchrow($result)) {
                $delete_ids[] = $row['attach_id'];
            }
            $db->sql_freeresult($result);
        }
        if ($delete && sizeof($delete_ids)) {
            $s_hidden_fields = array('delete' => 1);
            foreach ($delete_ids as $attachment_id) {
                $s_hidden_fields['attachment'][$attachment_id] = 1;
            }
            if (confirm_box(true)) {
                /** @var \phpbb\attachment\manager $attachment_manager */
                $attachment_manager = $phpbb_container->get('attachment.manager');
                $attachment_manager->delete('attach', $delete_ids);
                unset($attachment_manager);
                meta_refresh(3, $this->u_action);
                $message = (sizeof($delete_ids) == 1 ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED']) . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                trigger_error($message);
            } else {
                confirm_box(false, sizeof($delete_ids) == 1 ? 'DELETE_ATTACHMENT' : 'DELETE_ATTACHMENTS', build_hidden_fields($s_hidden_fields));
            }
        }
        // Select box eventually
        $sort_key_text = array('a' => $user->lang['SORT_FILENAME'], 'b' => $user->lang['SORT_COMMENT'], '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']);
        $sort_key_sql = array('a' => 'a.real_filename', 'b' => 'a.attach_comment', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
        $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
        $s_sort_key = '';
        foreach ($sort_key_text as $key => $value) {
            $selected = $sort_key == $key ? ' selected="selected"' : '';
            $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
        }
        $s_sort_dir = '';
        foreach ($sort_dir_text as $key => $value) {
            $selected = $sort_dir == $key ? ' selected="selected"' : '';
            $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
        }
        if (!isset($sort_key_sql[$sort_key])) {
            $sort_key = 'a';
        }
        $order_by = $sort_key_sql[$sort_key] . ' ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
        $sql = 'SELECT COUNT(attach_id) as num_attachments
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE poster_id = ' . $user->data['user_id'] . '
				AND is_orphan = 0';
        $result = $db->sql_query($sql);
        $num_attachments = $db->sql_fetchfield('num_attachments');
        $db->sql_freeresult($result);
        // Ensure start is a valid value
        /* @var $pagination \phpbb\pagination */
        $pagination = $phpbb_container->get('pagination');
        $start = $pagination->validate_start($start, $config['topics_per_page'], $num_attachments);
        $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->data['user_id'] . "\n\t\t\t\tAND a.is_orphan = 0\n\t\t\tORDER BY {$order_by}";
        $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
        $row_count = 0;
        if ($row = $db->sql_fetchrow($result)) {
            $template->assign_var('S_ATTACHMENT_ROWS', true);
            do {
                if ($row['in_message']) {
                    $view_topic = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&amp;p={$row['post_msg_id']}");
                } else {
                    $view_topic = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}";
                }
                $template->assign_block_vars('attachrow', array('ROW_NUMBER' => $row_count + ($start + 1), 'FILENAME' => $row['real_filename'], 'COMMENT' => bbcode_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_VIEW_ATTACHMENT' => append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic));
                $row_count++;
            } while ($row = $db->sql_fetchrow($result));
        }
        $db->sql_freeresult($result);
        $base_url = $this->u_action . "&amp;sk={$sort_key}&amp;sd={$sort_dir}";
        $pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start);
        $template->assign_vars(array('TOTAL_ATTACHMENTS' => $num_attachments, 'NUM_ATTACHMENTS' => $user->lang('NUM_ATTACHMENTS', $num_attachments), 'L_TITLE' => $user->lang['UCP_ATTACHMENTS'], 'U_SORT_FILENAME' => $this->u_action . "&amp;sk=a&amp;sd=" . ($sort_key == 'a' && $sort_dir == 'a' ? 'd' : 'a'), 'U_SORT_FILE_COMMENT' => $this->u_action . "&amp;sk=b&amp;sd=" . ($sort_key == 'b' && $sort_dir == 'a' ? 'd' : 'a'), 'U_SORT_EXTENSION' => $this->u_action . "&amp;sk=c&amp;sd=" . ($sort_key == 'c' && $sort_dir == 'a' ? 'd' : 'a'), 'U_SORT_FILESIZE' => $this->u_action . "&amp;sk=d&amp;sd=" . ($sort_key == 'd' && $sort_dir == 'a' ? 'd' : 'a'), 'U_SORT_DOWNLOADS' => $this->u_action . "&amp;sk=e&amp;sd=" . ($sort_key == 'e' && $sort_dir == 'a' ? 'd' : 'a'), 'U_SORT_POST_TIME' => $this->u_action . "&amp;sk=f&amp;sd=" . ($sort_key == 'f' && $sort_dir == 'a' ? 'd' : 'a'), 'U_SORT_TOPIC_TITLE' => $this->u_action . "&amp;sk=g&amp;sd=" . ($sort_key == 'g' && $sort_dir == 'a' ? 'd' : 'a'), 'S_DISPLAY_MARK_ALL' => $num_attachments ? true : false, 'S_DISPLAY_PAGINATION' => $num_attachments ? true : false, 'S_UCP_ACTION' => $this->u_action, 'S_SORT_OPTIONS' => $s_sort_key, 'S_ORDER_SELECT' => $s_sort_dir));
        $this->tpl_name = 'ucp_attachments';
        $this->page_title = 'UCP_ATTACHMENTS';
    }
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx;
        // 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 = '<strong' . ($user_row['user_colour'] ? ' style="color: #' . $user_row['user_colour'] . '">' : '>');
            $perm_from .= $user_row['user_id'] != ANONYMOUS ? '<a href="' . append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&amp;u=' . $user_row['user_id']) . '">' : '';
            $perm_from .= $user_row['username'];
            $perm_from .= $user_row['user_id'] != ANONYMOUS ? '</a>' : '';
            $perm_from .= '</strong>';
            $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_url = append_sid("{$phpbb_root_path}index.{$phpEx}");
                meta_refresh(3, $redirect_url);
                trigger_error($user->lang['ADM_LOGGED_OUT'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect_url . '">', '</a>'));
            }
            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;
                    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');
                        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_approved = 1';
                        $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_approved = 1';
                        $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');
                        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)
								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_approved = 1
								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');
                        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');
                        break;
                    case 'db_track':
                        switch ($db->sql_layer) {
                            case 'sqlite':
                            case 'firebird':
                                $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');
                        break;
                    case 'purge_cache':
                        if ((int) $user->data['user_type'] !== USER_FOUNDER) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        global $cache;
                        $cache->purge();
                        // Clear permissions
                        $auth->acl_clear_prefetch();
                        cache_moderators();
                        add_log('admin', 'LOG_PURGE_CACHE');
                        break;
                }
            }
        }
        // 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'] ? $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&amp;mode=admin'), 'U_INACTIVE_USERS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=inactive&amp;mode=list'), '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 = 0;
        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')) {
            $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']), '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'], 'USERNAME' => $row['username'], 'U_USER_ADMIN' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&amp;mode=overview&amp;u={$row['user_id']}")));
            }
            $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')) {
            $template->assign_var('S_REMOVE_INSTALL', true);
        }
        if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && is_writable($phpbb_root_path . 'config.' . $phpEx)) {
            // World-Writable? (000x)
            $template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x2));
        }
        $this->tpl_name = 'acp_main';
        $this->page_title = 'ACP_MAIN';
    }
    /**
     * Allows the admin to view cached versions of template files and clear single template cache files
     *
     * @param int $template_id specifies which template's cache is shown
     */
    function template_cache($template_id)
    {
        global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template;
        $source = str_replace('/', '.', request_var('source', ''));
        $file_ary = array_diff(request_var('delete', array('')), array(''));
        $submit = isset($_POST['submit']) ? true : false;
        $sql = 'SELECT *
			FROM ' . STYLES_TEMPLATE_TABLE . "\n\t\t\tWHERE template_id = {$template_id}";
        $result = $db->sql_query($sql);
        $template_row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$template_row) {
            trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING);
        }
        // User wants to delete one or more files ...
        if ($submit && $file_ary) {
            $this->clear_template_cache($template_row, $file_ary);
            trigger_error($user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action . "&amp;action=cache&amp;id={$template_id}"));
        }
        $cache_prefix = 'tpl_' . str_replace('_', '-', $template_row['template_path']);
        // Someone wants to see the cached source ... so we'll highlight it,
        // add line numbers and indent it appropriately. This could be nasty
        // on larger source files ...
        if ($source && file_exists("{$phpbb_root_path}cache/{$cache_prefix}_{$source}.html.{$phpEx}")) {
            adm_page_header($user->lang['TEMPLATE_CACHE']);
            $template->set_filenames(array('body' => 'viewsource.html'));
            $template->assign_vars(array('FILENAME' => str_replace('.', '/', $source) . '.html'));
            $code = str_replace(array("\r\n", "\r"), array("\n", "\n"), file_get_contents("{$phpbb_root_path}cache/{$cache_prefix}_{$source}.html.{$phpEx}"));
            $conf = array('highlight.bg', 'highlight.comment', 'highlight.default', 'highlight.html', 'highlight.keyword', 'highlight.string');
            foreach ($conf as $ini_var) {
                @ini_set($ini_var, str_replace('highlight.', 'syntax', $ini_var));
            }
            $marker = 'MARKER' . time();
            $code = highlight_string(str_replace("\n", $marker, $code), true);
            $code = str_replace($marker, "\n", $code);
            $str_from = array('<span style="color: ', '<font color="syntax', '</font>', '<code>', '</code>', '[', ']', '.', ':');
            $str_to = array('<span class="', '<span class="syntax', '</span>', '', '', '&#91;', '&#93;', '&#46;', '&#58;');
            $code = str_replace($str_from, $str_to, $code);
            $code = preg_replace('#^(<span class="[a-z_]+">)\\n?(.*?)\\n?(</span>)$#ism', '$1$2$3', $code);
            $code = substr($code, strlen('<span class="syntaxhtml">'));
            $code = substr($code, 0, -1 * strlen('</ span>'));
            $code = explode("\n", $code);
            foreach ($code as $key => $line) {
                $template->assign_block_vars('source', array('LINENUM' => $key + 1, 'LINE' => preg_replace('#([^ ;])&nbsp;([^ &])#', '$1 $2', $line)));
                unset($code[$key]);
            }
            adm_page_footer();
        }
        $filemtime = array();
        if ($template_row['template_storedb']) {
            $ids = array();
            if (isset($template_row['template_inherits_id']) && $template_row['template_inherits_id']) {
                $ids[] = $template_row['template_inherits_id'];
            }
            $ids[] = $template_row['template_id'];
            $filemtime = array();
            $file_template_db = array();
            foreach ($ids as $id) {
                $sql = 'SELECT template_filename, template_mtime
					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)) {
                    $filemtime[$row['template_filename']] = $row['template_mtime'];
                    $file_template_db[$row['template_filename']] = $id;
                }
                $db->sql_freeresult($result);
            }
        }
        // Get a list of cached template files and then retrieve additional information about them
        $file_ary = $this->template_cache_filelist($template_row['template_path']);
        foreach ($file_ary as $file) {
            $file = str_replace('/', '.', $file);
            // perform some dirty guessing to get the path right.
            // We assume that three dots in a row were '../'
            $tpl_file = str_replace('.', '/', $file);
            $tpl_file = str_replace('///', '../', $tpl_file);
            $filename = "{$cache_prefix}_{$file}.html.{$phpEx}";
            if (!file_exists("{$phpbb_root_path}cache/{$filename}")) {
                continue;
            }
            $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_path']}/template/{$tpl_file}.html";
            $inherited = false;
            if (isset($template_row['template_inherits_id']) && $template_row['template_inherits_id']) {
                if (!$template_row['template_storedb']) {
                    if (!file_exists($file_tpl)) {
                        $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_inherit_path']}/template/{$tpl_file}.html";
                        $inherited = true;
                    }
                } else {
                    if ($file_template_db[$file . '.html'] == $template_row['template_inherits_id']) {
                        $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_inherit_path']}/template/{$tpl_file}.html";
                        $inherited = true;
                    }
                }
            }
            // Correct the filename if it is stored in database and the file is in a subfolder.
            if ($template_row['template_storedb']) {
                $file = str_replace('.', '/', $file);
            }
            $template->assign_block_vars('file', array('U_VIEWSOURCE' => $this->u_action . "&amp;action=cache&amp;id={$template_id}&amp;source={$file}", 'CACHED' => $user->format_date(filemtime("{$phpbb_root_path}cache/{$filename}")), 'FILENAME' => $file, 'FILENAME_PATH' => $file_tpl, 'FILESIZE' => get_formatted_filesize(filesize("{$phpbb_root_path}cache/{$filename}")), 'MODIFIED' => $user->format_date(!$template_row['template_storedb'] ? filemtime($file_tpl) : $filemtime[$file . '.html'])));
        }
        unset($filemtime);
        $template->assign_vars(array('S_CACHE' => true, 'S_TEMPLATE' => true, 'U_ACTION' => $this->u_action . "&amp;action=cache&amp;id={$template_id}", 'U_BACK' => $this->u_action));
    }
 /**
  * Adjust all three max_filesize config vars for display
  */
 function max_filesize($value, $key = '')
 {
     // Determine size var and adjust the value accordingly
     $filesize = get_formatted_filesize($value, false, array('mb', 'kb', 'b'));
     $size_var = $filesize['si_identifier'];
     $value = $filesize['value'];
     return '<input type="text" id="' . $key . '" size="8" maxlength="15" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
 }
Exemple #10
0
    public function main($album_id)
    {
        $this->user->add_lang_ext('phpbbgallery/core', array('gallery'));
        $album_data = $this->album->get_info($album_id);
        $this->display->generate_navigation($album_data);
        add_form_key('gallery');
        $album_backlink = $this->helper->route('phpbbgallery_album', array('album_id' => $album_id));
        $album_loginlink = 'ucp.php?mode=login';
        $error = '';
        //Let's get authorization
        $this->auth->load_user_premissions($this->user->data['user_id']);
        if (!$this->auth->acl_check('i_upload', $album_id, $album_data['album_user_id']) || $album_data['album_status'] == $this->album->status_locked()) {
            $this->misc->not_authorised($album_backlink, $album_loginlink, 'LOGIN_EXPLAIN_UPLOAD');
        }
        $page_title = 'Upload to "' . $album_data['album_name'] . '"';
        // Before all
        if (!$this->check_fs()) {
            trigger_error('NO_WRITE_ACCESS');
        }
        $submit = $this->request->variable('submit', false);
        $mode = $this->request->variable('mode', 'upload');
        if ($mode == 'upload') {
            // Upload Quota Check
            // 1. Check album-configuration Quota
            if ($this->gallery_config->get('album_images') >= 0 && $album_data['album_images'] >= $this->gallery_config->get('album_images')) {
                //@todo: Add return link
                trigger_error('ALBUM_REACHED_QUOTA');
            }
            // 2. Check user-limit, if he is not allowed to go unlimited
            if (!$this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id'])) {
                $sql = 'SELECT COUNT(image_id) count
					FROM ' . $this->images_table . '
					WHERE image_user_id = ' . $this->user->data['user_id'] . '
						AND image_status <> ' . $this->image->get_status_orphan() . '
						AND image_album_id = ' . $album_id;
                $result = $this->db->sql_query($sql);
                $own_images = (int) $this->db->sql_fetchfield('count');
                $this->db->sql_freeresult($result);
                if ($own_images >= $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id'])) {
                    //@todo: Add return link
                    trigger_error($this->user->lang('USER_REACHED_QUOTA', $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id'])));
                }
            }
            if ($this->misc->display_captcha('upload')) {
                phpbb_gallery_url::_include('captcha/captcha_factory', 'phpbb');
                $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
                $captcha->init(CONFIRM_POST);
                $s_captcha_hidden_fields = '';
            }
            $upload_files_limit = $this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id']) ? $this->gallery_config->get('num_uploads') : min($this->auth->acl_check('i_count', $album_id, $album_data['album_user_id']) - $own_images, $this->gallery_config->get('num_uploads'));
            $process = new \phpbbgallery\core\upload($album_id, $upload_files_limit);
            if ($submit) {
                if (!check_form_key('gallery')) {
                    trigger_error('FORM_INVALID');
                }
                //$process = new \phpbbgallery\core\upload($album_id, $upload_files_limit);
                $process->set_rotating($this->request->variable('rotate', array(0)));
                $process->set_allow_comments($this->request->variable('allow_comments', false));
                /*if ($this->misc->display_captcha('upload'))
                		{
                			$captcha_error = $captcha->validate();
                			if ($captcha_error !== false)
                			{
                				$process->new_error($captcha_error);
                			}
                		}
                		*/
                if (!$this->user->data['is_registered']) {
                    $username = $this->request->variable('username', $user->data['username']);
                    if ($result = validate_username($username)) {
                        $this->user->add_lang('ucp');
                        $error_array[] = $this->user->lang[$result . '_USERNAME'];
                    } else {
                        $process->set_username($username);
                    }
                }
                if (empty($process->errors)) {
                    for ($file_count = 0; $file_count < $upload_files_limit; $file_count++) {
                        /**
                         * Upload an image from the FILES-array,
                         * call some functions (rotate, resize, ...)
                         * and store the image to the database
                         */
                        $file = $this->request->file('image_file_' . $file_count, '');
                        if (isset($file['size'])) {
                            if ($file['size'] > 0) {
                                $process->upload_file($file_count);
                            }
                        }
                    }
                }
                if (!$process->uploaded_files) {
                    $process->new_error($this->user->lang['UPLOAD_NO_FILE']);
                } else {
                    $mode = 'upload_edit';
                    // Remove submit, so we get the first screen of step 2.
                    $submit = false;
                }
                $error = implode('<br />', $process->errors);
                /*if (phpbb_gallery_misc::display_captcha('upload'))
                		{
                			$captcha->reset();
                		}*/
            }
            if (!$submit || isset($process) && !$process->uploaded_files) {
                for ($i = 0; $i < $upload_files_limit; $i++) {
                    $this->template->assign_block_vars('upload_image', array());
                }
            }
            if ($mode == 'upload') {
                $this->template->assign_vars(array('ERROR' => $error, 'S_MAX_FILESIZE' => get_formatted_filesize($this->gallery_config->get('max_filesize')), 'S_MAX_WIDTH' => $this->gallery_config->get('max_width'), 'S_MAX_HEIGHT' => $this->gallery_config->get('max_height'), 'S_ALLOWED_FILETYPES' => implode(', ', $process->get_allowed_types(true)), 'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_album_upload', array('album_id' => $album_id)), 'S_UPLOAD' => true, 'S_ALLOW_ROTATE' => $this->gallery_config->get('allow_rotate') && function_exists('imagerotate'), 'S_UPLOAD_LIMIT' => $upload_files_limit, 'S_COMMENTS_ENABLED' => $this->gallery_config->get('allow_comments') && $this->gallery_config->get('comment_user_control'), 'S_ALLOW_COMMENTS' => true, 'L_ALLOW_COMMENTS' => $this->user->lang('ALLOW_COMMENTS_ARY', $upload_files_limit)));
                /*if (phpbb_gallery_misc::display_captcha('upload'))
                		{
                			if (!$submit || !$captcha->is_solved())
                			{
                				$template->assign_vars(array(
                					'S_CONFIRM_CODE'			=> true,
                					'CAPTCHA_TEMPLATE'			=> $captcha->get_template(),
                				));
                			}
                			$template->assign_vars(array(
                				'S_CAPTCHA_HIDDEN_FIELDS'	=> $s_captcha_hidden_fields,
                			));
                		}*/
            }
        }
        if ($mode == 'upload_edit') {
            if ($submit) {
                // Upload Quota Check
                // 1. Check album-configuration Quota
                if ($this->gallery_config->get('album_images') >= 0 && $album_data['album_images'] >= $this->gallery_config->get('album_images')) {
                    //@todo: Add return link
                    trigger_error('ALBUM_REACHED_QUOTA');
                }
                // 2. Check user-limit, if he is not allowed to go unlimited
                if (!$this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id'])) {
                    $sql = 'SELECT COUNT(image_id) count
						FROM ' . $this->images_table . '
						WHERE image_user_id = ' . $this->user->data['user_id'] . '
							AND image_status <> ' . $this->image->get_status_orphan() . '
							AND image_album_id = ' . $album_id;
                    $result = $this->db->sql_query($sql);
                    $own_images = (int) $this->db->sql_fetchfield('count');
                    $this->db->sql_freeresult($result);
                    if ($own_images >= $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id'])) {
                        //@todo: Add return link
                        trigger_error($this->user->lang('USER_REACHED_QUOTA', $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id'])));
                    }
                }
                $description_array = $this->request->variable('message', array(''), true);
                foreach ($description_array as $var) {
                    if (strlen($var) > $this->gallery_config->get('description_length')) {
                        trigger_error($this->user->lang('DESC_TOO_LONG'));
                    }
                }
                $upload_files_limit = $this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id']) ? $this->gallery_config->get('num_uploads') : min($this->auth->acl_check('i_count', $album_id, $album_data['album_user_id']) - $own_images, $this->gallery_config->get('num_uploads'));
                $upload_ids = $this->request->variable('upload_ids', array(''));
                $process = new \phpbbgallery\core\upload($album_id, $upload_files_limit);
                $process->set_rotating($this->request->variable('rotate', array(0)));
                $process->get_images($upload_ids);
                $image_names = $this->request->variable('image_name', array(''), true);
                $process->set_names($image_names);
                $process->set_descriptions($description_array);
                $process->set_image_num($this->request->variable('image_num', 0));
                $process->use_same_name($this->request->variable('same_name', false));
                $success = true;
                $phpbb_gallery_notification = new \phpbbgallery\core\notification();
                foreach ($process->images as $image_id) {
                    $success = $success && $process->update_image($image_id, !$this->auth->acl_check('i_approve', $album_id, $album_data['album_user_id']), $album_data['album_contest']);
                    if ($this->gallery_user->get_data('watch_own')) {
                        $phpbb_gallery_notification->add($image_id);
                    }
                }
                $message = '';
                $error = implode('<br />', $process->errors);
                if ($this->auth->acl_check('i_approve', $album_id, $album_data['album_user_id'])) {
                    $message .= !$error ? $this->user->lang['ALBUM_UPLOAD_SUCCESSFUL'] : $this->user->lang('ALBUM_UPLOAD_SUCCESSFUL_ERROR', $error);
                    $meta_refresh_time = $success ? 3 : 20;
                    //$this->notification_helper->notify_album($album_id, $this->user->data['user_id']);
                    $data = array('targets' => array($this->user->data['user_id']), 'album_id' => $album_id, 'last_image' => end($process->images));
                    $this->notification_helper->new_image($data);
                } else {
                    $target = array('album_id' => $album_id, 'last_image' => end($process->images), 'uploader' => $this->user->data['user_id']);
                    $this->notification_helper->notify('approval', $target);
                    $message .= !$error ? $this->user->lang['ALBUM_UPLOAD_NEED_APPROVAL'] : $this->user->lang('ALBUM_UPLOAD_NEED_APPROVAL_ERROR', $error);
                    $meta_refresh_time = 20;
                }
                $message .= '<br /><br />' . sprintf($this->user->lang['CLICK_RETURN_ALBUM'], '<a href="' . $album_backlink . '">', '</a>');
                // ToDo - notifications!!!
                //$phpbb_gallery_notification->send_notification('album', $album_id, $image_names[0]);
                $this->image->handle_counter($process->images, true);
                $this->album->update_info($album_id);
                $this->url->meta_refresh($meta_refresh_time, $album_backlink);
                trigger_error($message);
            }
            $num_images = 0;
            foreach ($process->images as $image_id) {
                $data = $process->image_data[$image_id];
                $this->template->assign_block_vars('image', array('U_IMAGE' => $this->image->generate_link('thumbnail', 'plugin', $image_id, $data['image_name'], $album_id), 'IMAGE_NAME' => $data['image_name'], 'IMAGE_DESC' => $data['image_desc']));
                $num_images++;
            }
            $s_hidden_fields = build_hidden_fields(array('upload_ids' => $process->generate_hidden_fields()));
            $s_can_rotate = $this->gallery_config->get('allow_rotate') && function_exists('imagerotate');
            $this->template->assign_vars(array('ERROR' => $error, 'S_UPLOAD_EDIT' => true, 'S_ALLOW_ROTATE' => $s_can_rotate, 'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_album_upload', array('album_id' => $album_id)), 'S_USERNAME' => !$this->user->data['is_registered'] ? $username : '', 'NUM_IMAGES' => $num_images, 'COLOUR_ROWSPAN' => $s_can_rotate ? $num_images * 3 : $num_images * 2, 'L_DESCRIPTION_LENGTH' => $this->user->lang('DESCRIPTION_LENGTH', $this->gallery_config->get('description_length')), 'S_HIDDEN_FIELDS' => $s_hidden_fields));
        }
        return $this->helper->render('gallery/posting_body.html', $page_title);
    }
    /**
     * Display phpBB Directory statistics
     *
     * @return null
     */
    public function display_stats()
    {
        // Count number of categories
        $sql = 'SELECT COUNT(cat_id) AS nb_cats
			FROM ' . DIR_CAT_TABLE;
        $result = $this->db->sql_query($sql);
        $total_cats = (int) $this->db->sql_fetchfield('nb_cats');
        $this->db->sql_freeresult($result);
        // Cont number of links
        $sql = 'SELECT link_id, link_active
			FROM ' . DIR_LINK_TABLE;
        $result = $this->db->sql_query($sql);
        $total_links = $waiting_links = 0;
        while ($row = $this->db->sql_fetchrow($result)) {
            $total_links++;
            if (!$row['link_active']) {
                $waiting_links++;
            }
        }
        $this->db->sql_freeresult($result);
        // Comments number calculating
        $sql = 'SELECT COUNT(comment_id) AS nb_comments
			FROM ' . DIR_COMMENT_TABLE;
        $result = $this->db->sql_query($sql);
        $total_comments = (int) $this->db->sql_fetchfield('nb_comments');
        $this->db->sql_freeresult($result);
        // Votes number calculating
        $sql = 'SELECT COUNT(vote_id) AS nb_votes
			FROM ' . DIR_VOTE_TABLE;
        $result = $this->db->sql_query($sql);
        $total_votes = (int) $this->db->sql_fetchfield('nb_votes');
        $this->db->sql_freeresult($result);
        // Click number calculating
        $sql = 'SELECT SUM(link_view) AS nb_clicks
			FROM ' . DIR_LINK_TABLE;
        $result = $this->db->sql_query($sql);
        $total_clicks = (int) $this->db->sql_fetchfield('nb_clicks');
        $this->db->sql_freeresult($result);
        $banners_dir_size = 0;
        $banners_path = $this->dir_helper->get_banner_path();
        if ($banners_dir = @opendir($banners_path)) {
            while (($file = readdir($banners_dir)) !== false) {
                if ($file[0] != '.' && $file[0] != '..' && strpos($file, 'index.') === false && strpos($file, '.db') === false) {
                    $banners_dir_size += filesize($banners_path . $file);
                }
            }
            closedir($banners_dir);
            $banners_dir_size = get_formatted_filesize($banners_dir_size);
        } else {
            // Couldn't open banners dir.
            $banners_dir_size = $this->user->lang['NOT_AVAILABLE'];
        }
        $total_orphan = $this->_orphan_files();
        $this->template->assign_vars(array('U_ACTION' => $this->u_action, 'TOTAL_CATS' => $total_cats, 'TOTAL_LINKS' => $total_links - $waiting_links, 'WAITING_LINKS' => $waiting_links, 'TOTAL_COMMENTS' => $total_comments, 'TOTAL_VOTES' => $total_votes, 'TOTAL_CLICKS' => $total_clicks, 'TOTAL_ORPHANS' => $total_orphan, 'BANNERS_DIR_SIZE' => $banners_dir_size));
    }
Exemple #12
0
            $rows = $db->sql_fetchrowset($result);
            $rows[] = false;
            // indicate end of array for while loop below
            $db->sql_freeresult($result);
        }
        $i = 0;
        while ($row = $buffer ? $rows[$i++] : $db->sql_fetchrow($result)) {
            // Indexing enabled for this forum or global announcement?
            // Global announcements get indexed by default.
            if (!$row['forum_id'] || !empty($forums[$row['forum_id']])) {
                ++$row_count;
                $search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']);
                if ($row_count % 10 == 0) {
                    echo '.';
                }
            }
        }
        $delta = time() - $time;
        $delta = $delta <= 0 ? 1 : $delta;
        printf(" %d posts/sec\n", $row_count / $delta);
        if (!$buffer) {
            $db->sql_freeresult($result);
        }
        $post_counter += $batch_size;
    }
}
$search->tidy();
add_log('admin', 'LOG_SEARCH_INDEX_CREATED', $search_name);
echo $user->lang['SEARCH_INDEX_CREATED'] . "\n";
echo 'Peak Memory Usage: ' . get_formatted_filesize(memory_get_peak_usage()) . "\n";
exit(0);
 // --------------------------------
 // Cache is empty. Try to re-generate!
 // --------------------------------
 if ($pic_width > $pic_height) {
     $thumbnail_width = $config['thumbnail_size'];
     $thumbnail_height = $config['thumbnail_size'] * ($pic_height / $pic_width);
 } else {
     $thumbnail_height = $config['thumbnail_size'];
     $thumbnail_width = $config['thumbnail_size'] * ($pic_width / $pic_height);
 }
 $Image = new ImgObj();
 $Image->JPGQuality = $config['thumbnail_quality'];
 $Image->ReadSourceFile($pic_fullpath);
 $Image->Resize($thumbnail_width, $thumbnail_height);
 if ($config['show_pic_size_on_thumb'] == 1) {
     $image_filesize = get_formatted_filesize(filesize($pic_fullpath));
     $image_dimension = intval($pic_width) . "x" . intval($pic_height);
     $image_text_output = $image_dimension . ($thumbnail_width >= 360 ? ' - ' . $image_filesize : '');
     if ($thumbnail_width >= 260) {
         $image_exif_data = $Image->ExifData;
         if (!empty($image_exif_data)) {
             $image_exif_data_short = $Image->exif_get_data_short($image_exif_data);
             $exif_data_key_array = array('MODEL', 'FOCAL_LENGTH', 'EXPOSURE', 'APERTURE', 'ISO');
             $exif_data_array = array();
             foreach ($exif_data_key_array as $exif_key) {
                 if ($image_exif_data_short[$exif_key] != 'EXIF_UNKNOWN') {
                     $process_tag = true;
                     if ($exif_key == 'ISO') {
                         $image_exif_data_short[$exif_key] = 'ISO ' . $image_exif_data_short[$exif_key];
                     } elseif ($exif_key == 'MODEL') {
                         if ($thumbnail_width >= 320) {
Exemple #14
0
    private function view($cat_id, $topic_id = 0)
    {
        $start = $this->request->variable('start', 0);
        $sort_key = $this->request->variable('sk', 'a');
        $sort_dir = $this->request->variable('sd', 'a');
        // Select box eventually
        $sort_key_text = array('a' => $this->user->lang['SORT_FILENAME'], 'b' => $this->user->lang['SORT_COMMENT'], 'c' => $this->user->lang['SORT_EXTENSION'], 'd' => $this->user->lang['SORT_SIZE'], 'e' => $this->user->lang['SORT_DOWNLOADS'], 'f' => $this->user->lang['SORT_POST_TIME'], 'g' => $this->user->lang['SORT_TOPIC_TITLE']);
        $sort_key_sql = array('a' => 'a.real_filename', 'b' => 'a.attach_comment', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
        $sort_dir_text = array('a' => $this->user->lang['ASCENDING'], 'd' => $this->user->lang['DESCENDING']);
        $s_sort_key = '';
        foreach ($sort_key_text as $key => $value) {
            $selected = $sort_key == $key ? ' selected="selected"' : '';
            $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
        }
        $s_sort_dir = '';
        foreach ($sort_dir_text as $key => $value) {
            $selected = $sort_dir == $key ? ' selected="selected"' : '';
            $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
        }
        if (!isset($sort_key_sql[$sort_key])) {
            $sort_key = 'a';
        }
        $order_by = $sort_key_sql[$sort_key] . ' ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
        if ($cat_id) {
            $sql_topic = $topic_id ? " AND a.topic_id = " . (int) $topic_id : '';
            $sql = "SELECT e.extension, COUNT(a.attach_id) AS num_attachments\n\t\t\t\tFROM " . EXTENSIONS_TABLE . " e, " . ATTACHMENTS_TABLE . " a\n\t\t\t\tWHERE e.group_id = " . (int) $cat_id . "\n\t\t\t\t\t{$sql_topic}\n\t\t\t\t\tAND a.extension = e.extension\n\t\t\t\t\tAND a.is_orphan = 0\n\t\t\t\t\tAND a.in_message = 0\n\t\t\t\tGROUP BY a.extension";
            $result = $this->db->sql_query($sql);
            $extension = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $extension[] = $row['extension'];
                $num_attachments = isset($num_attachments) ? $num_attachments + $row['num_attachments'] : $row['num_attachments'];
            }
            $this->db->sql_freeresult($result);
            if (!sizeof($extension)) {
                return;
            }
            $sql_where = 'WHERE ' . $this->db->sql_in_set('a.extension', $extension);
            $sql_where .= $sql_topic . ' AND a.in_message = 0';
        } else {
            $sql_where = $topic_id ? "WHERE a.topic_id = " . (int) $topic_id . " AND " : "WHERE ";
            $sql_where = "{$sql_where} a.in_message = 0";
            $sql = 'SELECT COUNT(attach_id) as num_attachments
				FROM ' . ATTACHMENTS_TABLE . " a\n\t\t\t\t{$sql_where}\n\t\t\t\t\tAND a.is_orphan = 0";
            $result = $this->db->sql_query($sql);
            $num_attachments = $this->db->sql_fetchfield('num_attachments');
            $this->db->sql_freeresult($result);
        }
        // Ensure start is a valid value
        $start = $this->pagination->validate_start($start, $this->config['topics_per_page'], $num_attachments);
        $sql = 'SELECT a.*, t.forum_id, t.topic_title
			FROM ' . ATTACHMENTS_TABLE . ' a
				LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id AND a.in_message = 0)
			' . $sql_where . "\n\t\t\t\tAND a.is_orphan = 0\n\t\t\tORDER BY {$order_by}";
        $result = $this->db->sql_query_limit($sql, $this->config['topics_per_page'], $start);
        $row_count = 0;
        while ($row = $this->db->sql_fetchrow($result)) {
            $view_topic = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}";
            $this->template->assign_block_vars('attachrow', array('ROW_NUMBER' => $row_count + ($start + 1), 'FILENAME' => $row['real_filename'], 'COMMENT' => bbcode_nl2br($row['attach_comment']), 'EXTENSION' => $row['extension'], 'SIZE' => get_formatted_filesize($row['filesize']), 'DOWNLOAD_COUNT' => $row['download_count'], 'POST_TIME' => $this->user->format_date($row['filetime']), 'TOPIC_TITLE' => $row['topic_title'], 'ATTACH_ID' => $row['attach_id'], 'POST_ID' => $row['post_msg_id'], 'TOPIC_ID' => $row['topic_id'], 'AUTH_DOWNLOAD' => $this->auth->acl_get('f_download', $row['forum_id']), 'U_VIEW_ATTACHMENT' => $this->helper->route("bb3mobi_attach_file", array('attach_id' => $row['attach_id'])), 'U_DOWN_ATTACHMENT' => append_sid("{$this->phpbb_root_path}download/file.{$this->php_ext}", 'id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic));
            $row_count++;
        }
        $this->db->sql_freeresult($result);
        if ($cat_id) {
            $route = "bb3mobi_attach_view";
            $view_ary = array('cat_id' => $cat_id);
            $view_ary += $topic_id ? array('t' => $topic_id) : array();
        } else {
            $route = "bb3mobi_attach_cat";
            $view_ary = $topic_id ? array('t' => $topic_id) : array();
        }
        $base_url = $this->helper->route($route, array_merge($view_ary, array('sk' => $sort_key, 'sd' => $sort_dir)));
        $this->pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $this->config['topics_per_page'], $start);
        if ($start) {
            $view_ary = array_merge($view_ary, array('start' => $start));
        }
        $this->template->assign_vars(array('DESCRIPTION' => $this->user->lang('ATTACHMENTS_EXPLAIN'), 'NUM_ATTACHMENTS' => $this->user->lang('NUM_ATTACHMENTS', $num_attachments), 'ATTACHMENTS_BY' => $row_count ? $this->user->lang('ATTACHMENTS_BY', '<a href="http://bb3.mobi">Download by</a>') : '', 'CAT_ID' => $cat_id, 'U_CANONICAL' => $this->helper->route($route, $view_ary, false, '', true), 'U_SORT_FILENAME' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'a', 'sd' => $sort_key == 'a' && $sort_dir == 'a' ? 'd' : 'a'))), 'U_SORT_FILE_COMMENT' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'b', 'sd' => $sort_key == 'b' && $sort_dir == 'a' ? 'd' : 'a'))), 'U_SORT_EXTENSION' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'c', 'sd' => $sort_key == 'c' && $sort_dir == 'a' ? 'd' : 'a'))), 'U_SORT_FILESIZE' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'd', 'sd' => $sort_key == 'd' && $sort_dir == 'a' ? 'd' : 'a'))), 'U_SORT_DOWNLOADS' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'e', 'sd' => $sort_key == 'e' && $sort_dir == 'a' ? 'd' : 'a'))), 'U_SORT_POST_TIME' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'f', 'sd' => $sort_key == 'f' && $sort_dir == 'a' ? 'd' : 'a'))), 'U_SORT_TOPIC_TITLE' => $this->helper->route($route, array_merge($view_ary, array('sk' => 'g', 'sd' => $sort_key == 'g' && $sort_dir == 'a' ? 'd' : 'a'))), 'S_DISPLAY_MARK_ALL' => $num_attachments ? true : false, 'S_DISPLAY_PAGINATION' => $num_attachments ? true : false, 'S_ATTACH_ACTION' => $this->helper->route($route, $view_ary), 'S_SORT_OPTIONS' => $s_sort_key, 'S_ORDER_SELECT' => $s_sort_dir));
        return $start ? ' - ' . $this->user->lang('PAGE_TITLE_NUMBER', $this->pagination->get_on_page($this->config['topics_per_page'], $start)) : '';
    }
Exemple #15
0
 /**
  * General attachment parsing
  * From phpBB (includes/functions_content.php)
  *
  * @param string &$message The message
  * @param string $tpl The template file to use
  * @param bool $preview true if previewing from the posting page
  * @param string|bool $template_block If not false we will output the parsed attachments to this template block
  *
  * @return array the parsed attachments
  */
 public function parse_attachments(&$message, $tpl = 'common/attachment.html', $preview = false, $template_block = false)
 {
     if (!sizeof($this->attachments)) {
         return array();
     }
     phpbb::$user->add_lang('viewtopic');
     $compiled_attachments = array();
     if ($tpl !== false && !isset(phpbb::$template->filename['titania_attachment_tpl'])) {
         phpbb::$template->set_filenames(array('titania_attachment_tpl' => $tpl));
     }
     // Sort correctly
     if (phpbb::$config['display_order']) {
         // Ascending sort
         krsort($this->attachments);
     } else {
         // Descending sort
         ksort($this->attachments);
     }
     foreach ($this->attachments as $attachment_id => $attachment) {
         if (!sizeof($attachment)) {
             continue;
         }
         // We need to reset/empty the _file block var, because this function might be called more than once
         phpbb::$template->destroy_block_vars('_file');
         $block_array = array();
         // Some basics...
         $attachment['extension'] = strtolower(trim($attachment['extension']));
         $filename = titania::$config->upload_path . $attachment['attachment_directory'] . '/' . utf8_basename($attachment['attachment_directory']) . '/' . utf8_basename($attachment['physical_filename']);
         $thumbnail_filename = titania::$config->upload_path . $attachment['attachment_directory'] . '/' . utf8_basename($attachment['attachment_directory']) . '/thumb_' . utf8_basename($attachment['physical_filename']);
         $filesize = get_formatted_filesize($attachment['filesize'], false);
         if ($preview) {
             $comment = bbcode_nl2br(censor_text(utf8_normalize_nfc(request_var('attachment_comment_' . $attachment_id, (string) $attachment['attachment_comment'], true))));
         } else {
             $comment = bbcode_nl2br(censor_text($attachment['attachment_comment']));
         }
         $block_array += array('FILESIZE' => $filesize['value'], 'SIZE_LANG' => $filesize['unit'], 'DOWNLOAD_NAME' => utf8_basename($attachment['real_filename']), 'COMMENT' => $comment);
         $l_downloaded_viewed = $download_link = '';
         $display_cat = strpos($attachment['mimetype'], 'image') === 0 ? ATTACHMENT_CATEGORY_IMAGE : ATTACHMENT_CATEGORY_NONE;
         // @todo Probably should add support for more types...
         if ($display_cat == ATTACHMENT_CATEGORY_IMAGE) {
             if ($attachment['thumbnail']) {
                 $display_cat = ATTACHMENT_CATEGORY_THUMB;
             } else {
                 if (phpbb::$config['img_display_inlined']) {
                     if (phpbb::$config['img_link_width'] || phpbb::$config['img_link_height']) {
                         $dimension = @getimagesize($filename);
                         // If the dimensions could not be determined or the image being 0x0 we display it as a link for safety purposes
                         if ($dimension === false || empty($dimension[0]) || empty($dimension[1])) {
                             $display_cat = ATTACHMENT_CATEGORY_NONE;
                         } else {
                             $display_cat = $dimension[0] <= phpbb::$config['img_link_width'] && $dimension[1] <= phpbb::$config['img_link_height'] ? ATTACHMENT_CATEGORY_IMAGE : ATTACHMENT_CATEGORY_NONE;
                         }
                     }
                 } else {
                     $display_cat = ATTACHMENT_CATEGORY_NONE;
                 }
             }
         }
         // Make some descisions based on user options being set.
         if (($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !phpbb::$user->optionget('viewimg')) {
             $display_cat = ATTACHMENT_CATEGORY_NONE;
         }
         if ($display_cat == ATTACHMENT_CATEGORY_FLASH && !phpbb::$user->optionget('viewflash')) {
             $display_cat = ATTACHMENT_CATEGORY_NONE;
         }
         $download_link = titania_url::build_url('download', array('id' => $attachment['attachment_id']));
         switch ($display_cat) {
             // Images
             case ATTACHMENT_CATEGORY_IMAGE:
                 $l_downloaded_viewed = 'VIEWED_COUNT';
                 $download_link = titania_url::append_url($download_link, array('mode' => 'view'));
                 $block_array += array('S_IMAGE' => true, 'U_INLINE_LINK' => titania_url::append_url($download_link, array('mode' => 'view')));
                 break;
                 // Images, but display Thumbnail
             // Images, but display Thumbnail
             case ATTACHMENT_CATEGORY_THUMB:
                 $l_downloaded_viewed = 'VIEWED_COUNT';
                 $download_link = titania_url::append_url($download_link, array('mode' => 'view'));
                 $block_array += array('S_THUMBNAIL' => true, 'THUMB_IMAGE' => titania_url::append_url($download_link, array('mode' => 'view', 'thumb' => 1)));
                 break;
                 // Windows Media Streams
             // Windows Media Streams
             case ATTACHMENT_CATEGORY_WM:
                 $l_downloaded_viewed = 'VIEWED_COUNT';
                 // Giving the filename directly because within the wm object all variables are in local context making it impossible
                 // to validate against a valid session (all params can differ)
                 // $download_link = $filename;
                 $block_array += array('ATTACH_ID' => $attachment['attachment_id'], 'S_WM_FILE' => true);
                 break;
                 // Real Media Streams
             // Real Media Streams
             case ATTACHMENT_CATEGORY_RM:
             case ATTACHMENT_CATEGORY_QUICKTIME:
                 $l_downloaded_viewed = 'VIEWED_COUNT';
                 $block_array += array('S_RM_FILE' => $display_cat == ATTACHMENT_CATEGORY_RM ? true : false, 'S_QUICKTIME_FILE' => $display_cat == ATTACHMENT_CATEGORY_QUICKTIME ? true : false, 'ATTACH_ID' => $attachment['attachment_id']);
                 break;
                 // Macromedia Flash Files
             // Macromedia Flash Files
             case ATTACHMENT_CATEGORY_FLASH:
                 list($width, $height) = @getimagesize($filename);
                 $l_downloaded_viewed = 'VIEWED_COUNT';
                 $block_array += array('S_FLASH_FILE' => true, 'WIDTH' => $width, 'HEIGHT' => $height, 'U_VIEW_LINK' => titania_url::append_url($download_link, array('view' => 1)));
                 break;
             default:
                 $l_downloaded_viewed = 'DOWNLOAD_COUNT';
                 $block_array += array('S_FILE' => true);
                 break;
         }
         $l_download_count = !isset($attachment['download_count']) || $attachment['download_count'] == 0 ? phpbb::$user->lang[$l_downloaded_viewed . '_NONE'] : ($attachment['download_count'] == 1 ? sprintf(phpbb::$user->lang[$l_downloaded_viewed], $attachment['download_count']) : sprintf(phpbb::$user->lang[$l_downloaded_viewed . 'S'], $attachment['download_count']));
         $block_array += array('U_DOWNLOAD_LINK' => $download_link, 'L_DOWNLOAD_COUNT' => $l_download_count);
         // If a template block is specified, output to that also
         if ($template_block) {
             phpbb::$template->assign_block_vars($template_block, $block_array);
         }
         if ($tpl !== false) {
             phpbb::$template->assign_block_vars('_file', $block_array);
             $compiled_attachments[] = phpbb::$template->assign_display('titania_attachment_tpl');
         }
     }
     $tpl_size = sizeof($compiled_attachments);
     $unset_tpl = array();
     // For inline attachments
     if ($message) {
         preg_match_all('#<!\\-\\- ia([0-9]+) \\-\\->(.*?)<!\\-\\- ia\\1 \\-\\->#', $message, $matches, PREG_PATTERN_ORDER);
         $replace = array();
         foreach ($matches[0] as $num => $capture) {
             // Flip index if we are displaying the reverse way
             $index = phpbb::$config['display_order'] ? $tpl_size - ($matches[1][$num] + 1) : $matches[1][$num];
             $replace['from'][] = $matches[0][$num];
             $replace['to'][] = isset($compiled_attachments[$index]) ? $compiled_attachments[$index] : sprintf(phpbb::$user->lang['MISSING_INLINE_ATTACHMENT'], $matches[2][array_search($index, $matches[1])]);
             $unset_tpl[] = $index;
         }
         if (isset($replace['from'])) {
             $message = str_replace($replace['from'], $replace['to'], $message);
         }
         $unset_tpl = array_unique($unset_tpl);
         // Needed to let not display the inlined attachments at the end of the post again
         foreach ($unset_tpl as $index) {
             unset($compiled_attachments[$index]);
         }
     }
     return $compiled_attachments;
 }
Exemple #16
0
     } else {
         echo 'store/mods/ not found<br /><br />';
     }
 }
 if ($chk_php == 'Yes') {
     echo '<strong>[b]PHP Values[/b]</strong><br />';
     echo 'PHP version: ' . PHP_VERSION . '<br />';
     echo 'PHP safe mode: ' . (@ini_get('safe_mode') == '1' || strtolower(@ini_get('safe_mode')) == 'on' ? 'On' : 'Off') . '<br />';
     echo 'zlib.output_compression: ' . (@ini_get('zlib.output_compression') ? 'On' : 'Off') . '<br />';
     if (@ini_get('open_basedir')) {
         echo 'open_basedir restrictions: ' . ini_get('open_basedir') . '<br />';
     }
     echo 'upload_max_filesize: ' . get_formatted_filesize($u_m_f) . '<br />';
     echo 'post_max_size: ' . get_formatted_filesize($p_m_s) . '<br />';
     echo 'memory_limit: ' . get_formatted_filesize($m_l) . '<br />';
     echo '&#8756; Estimated maximum file upload size: &#8804; ' . get_formatted_filesize(min($u_m_f, $p_m_s, $m_l)) . '<br />';
     echo 'max_file_uploads: ' . ini_get('max_file_uploads') . '<br />';
     echo 'Max execution time: ' . (int) ini_get('max_execution_time') . ' secs<br />';
     echo 'Max input time: ' . (int) ini_get('max_input_time') . ' secs<br />';
     echo 'max_input_vars: ' . (int) ini_get('max_input_vars') . '<br />';
     echo 'file_uploads: ' . (@ini_get('file_uploads') == '1' || strtolower(@ini_get('file_uploads')) == 'on' ? 'Enabled' : 'Disabled') . '<br />';
     echo 'allow_url_fopen: ' . (@ini_get('allow_url_fopen') == '1' || strtolower(@ini_get('allow_url_fopen')) == 'on' ? 'Enabled' : 'Disabled') . '<br />';
     // Check if some PHP extensions are available
     $loaded_ext = get_loaded_extensions();
     $modules_maybe = array('curl', 'ftp', 'pcre', 'zlib', 'mbstring', 'libxml', 'gd', 'mysqli', 'imagick', 'json');
     $compared = array_diff($modules_maybe, $loaded_ext);
     foreach ($compared as $not_loaded) {
         echo $not_loaded . ' PHP extension not available<br />';
     }
     unset($not_loaded);
     // Quick check if ImageMagick "convert" program exists.
 /**
  * Perform common checks
  */
 function common_checks(&$file)
 {
     global $user;
     // Filesize is too big or it's 0 if it was larger than the maxsize in the upload form
     if ($this->max_filesize && ($file->get('filesize') > $this->max_filesize || $file->get('filesize') == 0)) {
         $max_filesize = get_formatted_filesize($this->max_filesize, false);
         $file->error[] = sprintf($user->lang[$this->error_prefix . 'WRONG_FILESIZE'], $max_filesize['value'], $max_filesize['unit']);
     }
     // check Filename
     if (preg_match("#[\\/:*?\"<>|]#i", $file->get('realname'))) {
         $file->error[] = sprintf($user->lang[$this->error_prefix . 'INVALID_FILENAME'], $file->get('realname'));
     }
     // Invalid Extension
     if (!$this->valid_extension($file)) {
         $file->error[] = sprintf($user->lang[$this->error_prefix . 'DISALLOWED_EXTENSION'], $file->get('extension'));
     }
     // MIME Sniffing
     if (!$this->valid_content($file)) {
         $file->error[] = sprintf($user->lang[$this->error_prefix . 'DISALLOWED_CONTENT']);
     }
 }
 /**
  * @dataProvider get_formatted_filesize_test_data
  */
 public function test_get_formatted_filesize($input, $expected)
 {
     $output = get_formatted_filesize($input);
     $this->assertEquals($expected, $output);
 }
/**
* General attachment parsing
*
* @param mixed $forum_id The forum id the attachments are displayed in (false if in private message)
* @param string &$message The post/private message
* @param array &$attachments The attachments to parse for (inline) display. The attachments array will hold templated data after parsing.
* @param array &$update_count The attachment counts to be updated - will be filled
* @param bool $preview If set to true the attachments are parsed for preview. Within preview mode the comments are fetched from the given $attachments array and not fetched from the database.
*/
function parse_attachments($forum_id, &$message, &$attachments, &$update_count, $preview = false)
{
    if (!sizeof($attachments)) {
        return;
    }
    global $template, $cache, $user, $phpbb_dispatcher;
    global $extensions, $config, $phpbb_root_path, $phpEx;
    //
    $compiled_attachments = array();
    if (!isset($template->filename['attachment_tpl'])) {
        $template->set_filenames(array('attachment_tpl' => 'attachment.html'));
    }
    if (empty($extensions) || !is_array($extensions)) {
        $extensions = $cache->obtain_attach_extensions($forum_id);
    }
    // Look for missing attachment information...
    $attach_ids = array();
    foreach ($attachments as $pos => $attachment) {
        // If is_orphan is set, we need to retrieve the attachments again...
        if (!isset($attachment['extension']) && !isset($attachment['physical_filename'])) {
            $attach_ids[(int) $attachment['attach_id']] = $pos;
        }
    }
    // Grab attachments (security precaution)
    if (sizeof($attach_ids)) {
        global $db;
        $new_attachment_data = array();
        $sql = 'SELECT *
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE ' . $db->sql_in_set('attach_id', array_keys($attach_ids));
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            if (!isset($attach_ids[$row['attach_id']])) {
                continue;
            }
            // If we preview attachments we will set some retrieved values here
            if ($preview) {
                $row['attach_comment'] = $attachments[$attach_ids[$row['attach_id']]]['attach_comment'];
            }
            $new_attachment_data[$attach_ids[$row['attach_id']]] = $row;
        }
        $db->sql_freeresult($result);
        $attachments = $new_attachment_data;
        unset($new_attachment_data);
    }
    // Sort correctly
    if ($config['display_order']) {
        // Ascending sort
        krsort($attachments);
    } else {
        // Descending sort
        ksort($attachments);
    }
    foreach ($attachments as $attachment) {
        if (!sizeof($attachment)) {
            continue;
        }
        // We need to reset/empty the _file block var, because this function might be called more than once
        $template->destroy_block_vars('_file');
        $block_array = array();
        // Some basics...
        $attachment['extension'] = strtolower(trim($attachment['extension']));
        $filename = $phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($attachment['physical_filename']);
        $thumbnail_filename = $phpbb_root_path . $config['upload_path'] . '/thumb_' . utf8_basename($attachment['physical_filename']);
        $upload_icon = '';
        if (isset($extensions[$attachment['extension']])) {
            if ($user->img('icon_topic_attach', '') && !$extensions[$attachment['extension']]['upload_icon']) {
                $upload_icon = $user->img('icon_topic_attach', '');
            } else {
                if ($extensions[$attachment['extension']]['upload_icon']) {
                    $upload_icon = '<img src="' . $phpbb_root_path . $config['upload_icons_path'] . '/' . trim($extensions[$attachment['extension']]['upload_icon']) . '" alt="" />';
                }
            }
        }
        $filesize = get_formatted_filesize($attachment['filesize'], false);
        $comment = bbcode_nl2br(censor_text($attachment['attach_comment']));
        $block_array += array('UPLOAD_ICON' => $upload_icon, 'FILESIZE' => $filesize['value'], 'SIZE_LANG' => $filesize['unit'], 'DOWNLOAD_NAME' => utf8_basename($attachment['real_filename']), 'COMMENT' => $comment);
        $denied = false;
        if (!extension_allowed($forum_id, $attachment['extension'], $extensions)) {
            $denied = true;
            $block_array += array('S_DENIED' => true, 'DENIED_MESSAGE' => sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']));
        }
        if (!$denied) {
            $l_downloaded_viewed = $download_link = '';
            $display_cat = $extensions[$attachment['extension']]['display_cat'];
            if ($display_cat == ATTACHMENT_CATEGORY_IMAGE) {
                if ($attachment['thumbnail']) {
                    $display_cat = ATTACHMENT_CATEGORY_THUMB;
                } else {
                    if ($config['img_display_inlined']) {
                        if ($config['img_link_width'] || $config['img_link_height']) {
                            $dimension = @getimagesize($filename);
                            // If the dimensions could not be determined or the image being 0x0 we display it as a link for safety purposes
                            if ($dimension === false || empty($dimension[0]) || empty($dimension[1])) {
                                $display_cat = ATTACHMENT_CATEGORY_NONE;
                            } else {
                                $display_cat = $dimension[0] <= $config['img_link_width'] && $dimension[1] <= $config['img_link_height'] ? ATTACHMENT_CATEGORY_IMAGE : ATTACHMENT_CATEGORY_NONE;
                            }
                        }
                    } else {
                        $display_cat = ATTACHMENT_CATEGORY_NONE;
                    }
                }
            }
            // Make some descisions based on user options being set.
            if (($display_cat == ATTACHMENT_CATEGORY_IMAGE || $display_cat == ATTACHMENT_CATEGORY_THUMB) && !$user->optionget('viewimg')) {
                $display_cat = ATTACHMENT_CATEGORY_NONE;
            }
            if ($display_cat == ATTACHMENT_CATEGORY_FLASH && !$user->optionget('viewflash')) {
                $display_cat = ATTACHMENT_CATEGORY_NONE;
            }
            $download_link = append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'id=' . $attachment['attach_id']);
            $l_downloaded_viewed = 'VIEWED_COUNTS';
            switch ($display_cat) {
                // Images
                case ATTACHMENT_CATEGORY_IMAGE:
                    $inline_link = append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'id=' . $attachment['attach_id']);
                    $download_link .= '&amp;mode=view';
                    $block_array += array('S_IMAGE' => true, 'U_INLINE_LINK' => $inline_link);
                    $update_count[] = $attachment['attach_id'];
                    break;
                    // Images, but display Thumbnail
                // Images, but display Thumbnail
                case ATTACHMENT_CATEGORY_THUMB:
                    $thumbnail_link = append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'id=' . $attachment['attach_id'] . '&amp;t=1');
                    $download_link .= '&amp;mode=view';
                    $block_array += array('S_THUMBNAIL' => true, 'THUMB_IMAGE' => $thumbnail_link);
                    $update_count[] = $attachment['attach_id'];
                    break;
                    // Windows Media Streams
                // Windows Media Streams
                case ATTACHMENT_CATEGORY_WM:
                    // Giving the filename directly because within the wm object all variables are in local context making it impossible
                    // to validate against a valid session (all params can differ)
                    // $download_link = $filename;
                    $block_array += array('U_FORUM' => generate_board_url(), 'ATTACH_ID' => $attachment['attach_id'], 'S_WM_FILE' => true);
                    // Viewed/Heared File ... update the download count
                    $update_count[] = $attachment['attach_id'];
                    break;
                    // Real Media Streams
                // Real Media Streams
                case ATTACHMENT_CATEGORY_RM:
                case ATTACHMENT_CATEGORY_QUICKTIME:
                    $block_array += array('S_RM_FILE' => $display_cat == ATTACHMENT_CATEGORY_RM ? true : false, 'S_QUICKTIME_FILE' => $display_cat == ATTACHMENT_CATEGORY_QUICKTIME ? true : false, 'U_FORUM' => generate_board_url(), 'ATTACH_ID' => $attachment['attach_id']);
                    // Viewed/Heared File ... update the download count
                    $update_count[] = $attachment['attach_id'];
                    break;
                    // Macromedia Flash Files
                // Macromedia Flash Files
                case ATTACHMENT_CATEGORY_FLASH:
                    list($width, $height) = @getimagesize($filename);
                    $block_array += array('S_FLASH_FILE' => true, 'WIDTH' => $width, 'HEIGHT' => $height, 'U_VIEW_LINK' => $download_link . '&amp;view=1');
                    // Viewed/Heared File ... update the download count
                    $update_count[] = $attachment['attach_id'];
                    break;
                default:
                    $l_downloaded_viewed = 'DOWNLOAD_COUNTS';
                    $block_array += array('S_FILE' => true);
                    break;
            }
            if (!isset($attachment['download_count'])) {
                $attachment['download_count'] = 0;
            }
            $block_array += array('U_DOWNLOAD_LINK' => $download_link, 'L_DOWNLOAD_COUNT' => $user->lang($l_downloaded_viewed, (int) $attachment['download_count']));
        }
        /**
         * Use this event to modify the attachment template data.
         *
         * This event is triggered once per attachment.
         *
         * @event core.parse_attachments_modify_template_data
         * @var array	attachment		Array with attachment data
         * @var array	block_array		Template data of the attachment
         * @var int		display_cat		Attachment category data
         * @var string	download_link	Attachment download link
         * @var array	extensions		Array with attachment extensions data
         * @var mixed 	forum_id 		The forum id the attachments are displayed in (false if in private message)
         * @var bool		preview			Flag indicating if we are in post preview mode
         * @var array	update_count	Array with attachment ids to update download count
         * @since 3.1.0-RC5
         */
        $vars = array('attachment', 'block_array', 'display_cat', 'download_link', 'extensions', 'forum_id', 'preview', 'update_count');
        extract($phpbb_dispatcher->trigger_event('core.parse_attachments_modify_template_data', compact($vars)));
        $template->assign_block_vars('_file', $block_array);
        $compiled_attachments[] = $template->assign_display('attachment_tpl');
    }
    $attachments = $compiled_attachments;
    unset($compiled_attachments);
    $tpl_size = sizeof($attachments);
    $unset_tpl = array();
    preg_match_all('#<!\\-\\- ia([0-9]+) \\-\\->(.*?)<!\\-\\- ia\\1 \\-\\->#', $message, $matches, PREG_PATTERN_ORDER);
    $replace = array();
    foreach ($matches[0] as $num => $capture) {
        // Flip index if we are displaying the reverse way
        $index = $config['display_order'] ? $tpl_size - ($matches[1][$num] + 1) : $matches[1][$num];
        $replace['from'][] = $matches[0][$num];
        $replace['to'][] = isset($attachments[$index]) ? $attachments[$index] : sprintf($user->lang['MISSING_INLINE_ATTACHMENT'], $matches[2][array_search($index, $matches[1])]);
        $unset_tpl[] = $index;
    }
    if (isset($replace['from'])) {
        $message = str_replace($replace['from'], $replace['to'], $message);
    }
    $unset_tpl = array_unique($unset_tpl);
    // Needed to let not display the inlined attachments at the end of the post again
    foreach ($unset_tpl as $index) {
        unset($attachments[$index]);
    }
}
Exemple #20
0
 /**
  * Parse the uploader
  *
  * @param string $tpl_file The name of the template file to use to create the uploader
  * @param bool $custom_sort Function used to sort the attachments
  * @return string The parsed HTML code ready for output
  */
 public function parse_uploader($tpl_file = 'posting/attachments/default.html', $custom_sort = false)
 {
     // If the upload max filesize is less than 0, do not show the uploader (0 = unlimited)
     if (!$this->access->is_team()) {
         if (isset($this->ext_config->upload_max_filesize[$this->object_type]) && $this->ext_config->upload_max_filesize[$this->object_type] < 0) {
             return '';
         }
     }
     $this->template->assign_vars(array('FORM_NAME' => $this->form_name, 'MAX_LENGTH' => $this->access->is_team() ? $this->config['max_filesize'] : false, 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', 'S_INLINE_ATTACHMENT_OPTIONS' => true, 'S_PLUPLOAD_ENABLED' => $this->use_plupload, 'S_SET_CUSTOM_ORDER' => $this->set_custom_order, 'S_UPLOADER_KEY' => generate_link_hash('uploader_key'), 'SELECT_PREVIEW' => $this->object_type == TITANIA_SCREENSHOT, 'SELECT_REVIEW_VAR' => 'set_preview_file' . $this->object_type));
     $index_dir = '-';
     $index = $this->operator->get_count() - 1;
     if ($custom_sort == false && !$this->config['display_order']) {
         $index_dir = '+';
         $index = 0;
     }
     $this->operator->sort($custom_sort);
     // Delete previous attachments list
     $this->template->destroy_block_vars('attach_row');
     $base_url = $this->controller_helper->get_current_url();
     $hash = generate_link_hash('attach_manage');
     $comments = $this->get_request_comments();
     $hidden_data = $this->get_basic_attachment_data();
     $index_prefix = $this->use_plupload ? '' : $this->form_name . '_';
     foreach ($this->operator->get_all() as $attachment_id => $attach) {
         $params = array('a' => $attachment_id, 'hash' => $hash);
         $_hidden_data = array();
         foreach ($hidden_data[$attachment_id] as $property => $value) {
             $_hidden_data["attachment_data[{$index_prefix}{$index}][{$property}]"] = $value;
         }
         $output = array_merge($attach->get_display_vars(''), array('FILENAME' => $attach->get_filename(), 'FILE_COMMENT' => isset($comments[$attachment_id]) ? $comments[$attachment_id] : $attach->get('attachment_comment'), 'ATTACH_ID' => $attachment_id, 'INDEX' => $index_prefix . $index, 'FILESIZE' => get_formatted_filesize($attach->get('filesize')), 'S_HIDDEN' => build_hidden_fields($_hidden_data), 'S_PREVIEW' => $attach->is_preview(), 'U_VIEW_ATTACHMENT' => $attach->get_url(), 'U_DELETE' => $this->path_helper->append_url_params($base_url, array_merge($params, array('action' => 'delete_attach')))));
         if ($attach->is_type(TITANIA_SCREENSHOT)) {
             $output = array_merge($output, array('U_MOVE_UP' => $this->path_helper->append_url_params($base_url, array_merge($params, array('action' => 'attach_up'))), 'U_MOVE_DOWN' => $this->path_helper->append_url_params($base_url, array_merge($params, array('action' => 'attach_down')))));
         }
         $index += $index_dir == '+' ? 1 : -1;
         $this->template->assign_block_vars('attach_row', $output);
     }
     $this->template->assign_var('S_ATTACH_DATA', json_encode(array_values($hidden_data)));
     $this->template->set_filenames(array($tpl_file => $tpl_file));
     return $this->template->assign_display($tpl_file);
 }
Exemple #21
0
 /**
  * Adjust all three max_filesize config vars for display
  */
 function max_filesize($value, $key = '')
 {
     // Determine size var and adjust the value accordingly
     $size_var = $value >= 1048576 ? 'mb' : ($value >= 1024 ? 'kb' : 'b');
     $value = get_formatted_filesize($value, false);
     return '<input type="text" id="' . $key . '" size="8" maxlength="15" name="config[' . $key . ']" value="' . $value . '" /> <select name="' . $key . '">' . size_select_options($size_var) . '</select>';
 }
Exemple #22
0
/**
* Page footer for acp pages
*/
function adm_page_footer($copyright_html = true)
{
    global $db, $config, $template, $user, $auth, $cache;
    global $starttime, $phpbb_root_path, $phpbb_admin_path, $phpEx;
    // Output page creation time
    if (defined('DEBUG')) {
        $mtime = explode(' ', microtime());
        $totaltime = $mtime[0] + $mtime[1] - $starttime;
        if (!empty($_REQUEST['explain']) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report')) {
            $db->sql_report('display');
        }
        $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . ($config['gzip_compress'] ? 'On' : 'Off') . ($user->load ? ' | Load : ' . $user->load : ''), $totaltime);
        if ($auth->acl_get('a_') && defined('DEBUG_EXTRA')) {
            if (function_exists('memory_get_usage')) {
                if ($memory_usage = memory_get_usage()) {
                    global $base_memory_usage;
                    $memory_usage -= $base_memory_usage;
                    $memory_usage = get_formatted_filesize($memory_usage);
                    $debug_output .= ' | Memory Usage: ' . $memory_usage;
                }
            }
            $debug_output .= ' | <a href="' . build_url() . '&amp;explain=1">Explain</a>';
        }
    }
    $template->assign_vars(array('DEBUG_OUTPUT' => defined('DEBUG') ? $debug_output : '', 'TRANSLATION_INFO' => !empty($user->lang['TRANSLATION_INFO']) ? $user->lang['TRANSLATION_INFO'] : '', 'S_COPYRIGHT_HTML' => $copyright_html, 'CREDIT_LINE' => $user->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Group'), 'VERSION' => $config['version']));
    $template->display('body');
    garbage_collection();
    exit_handler();
}
Exemple #23
0
 /**
  * Remote upload method
  * Uploads file from given url
  *
  * @param string $upload_url URL pointing to file to upload, for example http://www.foobar.com/example.gif
  * @return filespec $file Object "filespec" is returned, all further operations can be done with this object
  * @access public
  */
 protected function remote_upload($upload_url)
 {
     $upload_ary = array();
     $upload_ary['local_mode'] = true;
     if (!preg_match('#^(https?://).*?\\.(' . implode('|', $this->upload->allowed_extensions) . ')$#i', $upload_url, $match)) {
         return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'URL_INVALID'));
     }
     $url = parse_url($upload_url);
     $host = $url['host'];
     $path = $url['path'];
     $port = !empty($url['port']) ? (int) $url['port'] : 80;
     $upload_ary['type'] = 'application/octet-stream';
     $url['path'] = explode('.', $url['path']);
     $ext = array_pop($url['path']);
     $url['path'] = implode('', $url['path']);
     $upload_ary['name'] = utf8_basename($url['path']) . ($ext ? '.' . $ext : '');
     $filename = $url['path'];
     $filesize = 0;
     $remote_max_filesize = $this->get_max_file_size();
     $errno = 0;
     $errstr = '';
     if (!($fsock = @fsockopen($host, $port, $errno, $errstr))) {
         return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED'));
     }
     // Make sure $path not beginning with /
     if (strpos($path, '/') === 0) {
         $path = substr($path, 1);
     }
     fputs($fsock, 'GET /' . $path . " HTTP/1.1\r\n");
     fputs($fsock, "HOST: " . $host . "\r\n");
     fputs($fsock, "Connection: close\r\n\r\n");
     // Set a proper timeout for the socket
     socket_set_timeout($fsock, $this->upload->upload_timeout);
     $get_info = false;
     $data = '';
     $length = false;
     $timer_stop = time() + $this->upload->upload_timeout;
     while ((!$length || $filesize < $length) && !@feof($fsock)) {
         if ($get_info) {
             if ($length) {
                 // Don't attempt to read past end of file if server indicated length
                 $block = @fread($fsock, min($length - $filesize, 1024));
             } else {
                 $block = @fread($fsock, 1024);
             }
             $filesize += strlen($block);
             if ($remote_max_filesize && $filesize > $remote_max_filesize) {
                 $max_filesize = get_formatted_filesize($remote_max_filesize, false);
                 return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'WRONG_FILESIZE', $max_filesize['value'], $max_filesize['unit']));
             }
             $data .= $block;
         } else {
             $line = @fgets($fsock, 1024);
             if ($line == "\r\n") {
                 $get_info = true;
             } else {
                 if (stripos($line, 'content-type: ') !== false) {
                     $upload_ary['type'] = rtrim(str_replace('content-type: ', '', strtolower($line)));
                 } else {
                     if ($this->upload->max_filesize && stripos($line, 'content-length: ') !== false) {
                         $length = (int) str_replace('content-length: ', '', strtolower($line));
                         if ($remote_max_filesize && $length && $length > $remote_max_filesize) {
                             $max_filesize = get_formatted_filesize($remote_max_filesize, false);
                             return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'WRONG_FILESIZE', $max_filesize['value'], $max_filesize['unit']));
                         }
                     } else {
                         if (stripos($line, '404 not found') !== false) {
                             return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'URL_NOT_FOUND');
                         }
                     }
                 }
             }
         }
         $stream_meta_data = stream_get_meta_data($fsock);
         // Cancel upload if we exceed timeout
         if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop) {
             return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'REMOTE_UPLOAD_TIMEOUT');
         }
     }
     @fclose($fsock);
     if (empty($data)) {
         return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'EMPTY_REMOTE_DATA');
     }
     $filename = tempnam(sys_get_temp_dir(), unique_id() . '-');
     if (!($fp = @fopen($filename, 'wb'))) {
         return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'NOT_UPLOADED');
     }
     $upload_ary['size'] = fwrite($fp, $data);
     fclose($fp);
     unset($data);
     $upload_ary['tmp_name'] = $filename;
     /** @var filespec $file */
     $file = $this->factory->get('filespec')->set_upload_ary($upload_ary)->set_upload_namespace($this->upload);
     $this->upload->common_checks($file);
     return $file;
 }
 /**
  * Remote upload method
  * Uploads file from given url
  *
  * @param string $upload_url URL pointing to file to upload, for example http://www.foobar.com/example.gif
  * @param \phpbb\mimetype\guesser $mimetype_guesser Mimetype guesser
  * @return object $file Object "filespec" is returned, all further operations can be done with this object
  * @access public
  */
 function remote_upload($files, $upload_url, \phpbb\mimetype\guesser $mimetype_guesser = null)
 {
     global $user, $phpbb_root_path;
     $upload_ary = array();
     $upload_ary['local_mode'] = true;
     $upload_from_phpbb = preg_match('#^(https://)www.phpbb.com/customise/db/download/([0-9]*?)$#i', $upload_url, $match_phpbb);
     if (!preg_match('#^(https?://).*?\\.(' . implode('|', $files->allowed_extensions) . ')$#i', $upload_url, $match) && !$upload_from_phpbb) {
         $file = new \fileerror($user->lang[$files->error_prefix . 'URL_INVALID']);
         return $file;
     }
     if (empty($match[2]) && empty($match_phpbb[2])) {
         $file = new \fileerror($user->lang[$files->error_prefix . 'URL_INVALID']);
         return $file;
     }
     $url = parse_url($upload_url);
     $host = $url['host'];
     $path = $url['path'];
     $port = !empty($url['port']) ? (int) $url['port'] : 80;
     $upload_ary['type'] = 'application/octet-stream';
     $url['path'] = explode('.', $url['path']);
     $ext = array_pop($url['path']);
     $url['path'] = implode('', $url['path']);
     $upload_ary['name'] = utf8_basename($url['path']) . ($ext ? '.' . $ext : '');
     $filename = $url['path'];
     $filesize = 0;
     $remote_max_filesize = $files->max_filesize;
     if (!$remote_max_filesize) {
         $max_filesize = @ini_get('upload_max_filesize');
         if (!empty($max_filesize)) {
             $unit = strtolower(substr($max_filesize, -1, 1));
             $remote_max_filesize = (int) $max_filesize;
             switch ($unit) {
                 case 'g':
                     $remote_max_filesize *= 1024;
                     // no break
                 // no break
                 case 'm':
                     $remote_max_filesize *= 1024;
                     // no break
                 // no break
                 case 'k':
                     $remote_max_filesize *= 1024;
                     // no break
             }
         }
     }
     $errno = 0;
     $errstr = '';
     if (!($fsock = @fopen($upload_url, "r"))) {
         $file = new \fileerror($user->lang[$files->error_prefix . 'NOT_UPLOADED']);
         return $file;
     }
     // Make sure $path not beginning with /
     if (strpos($path, '/') === 0) {
         $path = substr($path, 1);
     }
     $get_info = false;
     $data = '';
     $length = false;
     $timer_stop = time() + $files->upload_timeout;
     while (!@feof($fsock)) {
         if ($length) {
             // Don't attempt to read past end of file if server indicated length
             $block = @fread($fsock, min($length - $filesize, 1024));
         } else {
             $block = @fread($fsock, 1024);
         }
         $filesize += strlen($block);
         if ($remote_max_filesize && $filesize > $remote_max_filesize) {
             $max_filesize = get_formatted_filesize($remote_max_filesize, false);
             $file = new \fileerror(sprintf($user->lang[$files->error_prefix . 'WRONG_FILESIZE'], $max_filesize['value'], $max_filesize['unit']));
             return $file;
         }
         $data .= $block;
         // Cancel upload if we exceed timeout
         if (time() >= $timer_stop) {
             $file = new \fileerror($user->lang[$files->error_prefix . 'REMOTE_UPLOAD_TIMEOUT']);
             return $file;
         }
     }
     @fclose($fsock);
     if (empty($data)) {
         $file = new \fileerror($user->lang[$files->error_prefix . 'EMPTY_REMOTE_DATA']);
         return $file;
     }
     $tmp_path = !@ini_get('safe_mode') || strtolower(@ini_get('safe_mode')) == 'off' ? false : $phpbb_root_path . 'cache';
     $filename = tempnam($tmp_path, unique_id() . '-');
     if (!($fp = @fopen($filename, 'wb'))) {
         $file = new \fileerror($user->lang[$files->error_prefix . 'NOT_UPLOADED']);
         return $file;
     }
     $upload_ary['size'] = fwrite($fp, $data);
     fclose($fp);
     unset($data);
     $upload_ary['tmp_name'] = $filename;
     $file = new \filespec($upload_ary, $files, $mimetype_guesser);
     if ($upload_from_phpbb) {
         $file->extension = 'zip';
     }
     $files->common_checks($file);
     return $file;
 }
Exemple #25
0
    function main($id, $mode)
    {
        global $config, $db, $cache, $user, $auth, $template, $request, $phpbb_log;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container, $phpbb_dispatcher, $phpbb_filesystem;
        // 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->variable('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);
                        }
                        $config->set('record_online_users', 1, false);
                        $config->set('record_online_date', time(), false);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, '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);
                        $config->set('num_posts', (int) $db->sql_fetchfield('stat'), false);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT COUNT(topic_id) AS stat
							FROM ' . TOPICS_TABLE . '
							WHERE topic_visibility = ' . ITEM_APPROVED;
                        $result = $db->sql_query($sql);
                        $config->set('num_topics', (int) $db->sql_fetchfield('stat'), false);
                        $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);
                        $config->set('num_users', (int) $db->sql_fetchfield('stat'), false);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT COUNT(attach_id) as stat
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE is_orphan = 0';
                        $result = $db->sql_query($sql);
                        $config->set('num_files', (int) $db->sql_fetchfield('stat'), false);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT SUM(filesize) as stat
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE is_orphan = 0';
                        $result = $db->sql_query($sql);
                        $config->set('upload_dir_size', (double) $db->sql_fetchfield('stat'), false);
                        $db->sql_freeresult($result);
                        if (!function_exists('update_last_username')) {
                            include $phpbb_root_path . "includes/functions_user.{$phpEx}";
                        }
                        update_last_username();
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, '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) {
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, '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;
                        }
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, '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);
                        }
                        $config->set('board_startdate', time() - 1);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, '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);
                            }
                        }
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, '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();
                        // Remove old renderers from the text_formatter service. Since this
                        // operation is performed after the cache is purged, there is not "current"
                        // renderer and in effect all renderers will be purged
                        $phpbb_container->get('text_formatter.cache')->tidy();
                        // Clear permissions
                        $auth->acl_clear_prefetch();
                        phpbb_cache_moderators($db, $cache, $auth);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, '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);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, '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.4', '<')) {
            $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&amp;t=2152375">', '</a>')));
        }
        if ($auth->acl_get('a_board')) {
            /* @var $version_helper \phpbb\version_helper */
            $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&amp;mode=admin'), 'U_INACTIVE_USERS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=inactive&amp;mode=list'), 'U_VERSIONCHECK' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=update&amp;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&amp;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&amp;mode=overview&amp;u={$row['user_id']}"), 'U_SEARCH_USER' => $auth->acl_get('u_search') ? append_sid("{$phpbb_root_path}search.{$phpEx}", "author_id={$row['user_id']}&amp;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&amp;mode=index') . '">', '</a>')));
            }
        }
        if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && $phpbb_filesystem->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'])) {
            $config->set('dbms_version', $db->sql_server_info(true));
        }
        $this->tpl_name = 'acp_main';
        $this->page_title = 'ACP_MAIN';
    }
    function overview()
    {
        global $auth, $config, $db, $template, $user, $phpbb_ext_gallery, $table_prefix, $phpbb_dispatcher, $phpbb_root_path;
        global $phpbb_container, $request;
        $phpbbgallery_core_file = $phpbb_root_path . 'files/phpbbgallery/core';
        $phpbbgallery_core_file_medium = $phpbb_root_path . 'files/phpbbgallery/core/medium';
        $phpbbgallery_core_file_mini = $phpbb_root_path . 'files/phpbbgallery/core/mini';
        $phpbbgallery_core_file_source = $phpbb_root_path . 'files/phpbbgallery/core/source';
        $albums_table = $table_prefix . 'gallery_albums';
        $roles_table = $table_prefix . 'gallery_roles';
        $permissions_table = $table_prefix . 'gallery_permissions';
        $modscache_table = $table_prefix . 'gallery_modscache';
        $contests_table = $table_prefix . 'gallery_contests';
        $users_table = $table_prefix . 'gallery_users';
        $images_table = $table_prefix . 'gallery_images';
        // Init album
        $phpbb_ext_gallery_core_album = $phpbb_container->get('phpbbgallery.core.album');
        // init users
        $phpbb_gallery_user = $phpbb_container->get('phpbbgallery.core.user');
        // init image
        $phpbb_gallery_image = $phpbb_container->get('phpbbgallery.core.image');
        // init config
        $phpbb_ext_gallery_config = $phpbb_container->get('phpbbgallery.core.config');
        $action = $request->variable('action', '');
        $id = $request->variable('i', '');
        $mode = 'overview';
        // before we start let's check if directory structure is OK
        if (!is_writable($phpbb_root_path . 'files')) {
            $template->assign_vars(array('U_FILE_DIR_STATE' => $user->lang['NO_WRITE_ACCESS'], 'U_FILE_DIR_STATE_ERROR' => 1, 'U_CORE_DIR_STATE' => $user->lang['NO_WRITE_ACCESS'], 'U_CORE_DIR_STATE_ERROR' => 1, 'U_MEDIUM_DIR_STATE' => $user->lang['NO_WRITE_ACCESS'], 'U_MEDIUM_DIR_STATE_ERROR' => 1, 'U_MINI_DIR_STATE' => $user->lang['NO_WRITE_ACCESS'], 'U_MINI_DIR_STATE_ERROR' => 1, 'U_SOURCE_DIR_STATE' => $user->lang['NO_WRITE_ACCESS'], 'U_SOURCE_DIR_STATE_ERROR' => 1));
        } else {
            $template->assign_vars(array('U_FILE_DIR_STATE' => $user->lang['WRITE_ACCESS'], 'U_FILE_DIR_STATE_ERROR' => 0));
            if (!file_exists($phpbbgallery_core_file)) {
                mkdir($phpbbgallery_core_file, 0755, true);
                $template->assign_vars(array('U_CORE_DIR_STATE' => $user->lang['DIR_CREATED'], 'U_CORE_DIR_STATE_ERROR' => 0));
            } else {
                if (is_writable($phpbbgallery_core_file)) {
                    $template->assign_vars(array('U_CORE_DIR_STATE' => $user->lang['WRITE_ACCESS'], 'U_CORE_DIR_STATE_ERROR' => 0));
                } else {
                    $template->assign_vars(array('U_CORE_DIR_STATE' => $user->lang['NO_WRITE_ACCESS'], 'U_CORE_DIR_STATE_ERROR' => 1));
                }
            }
            if (!file_exists($phpbbgallery_core_file_medium)) {
                mkdir($phpbbgallery_core_file_medium, 0755, true);
                $template->assign_vars(array('U_MEDIUM_DIR_STATE' => $user->lang['DIR_CREATED'], 'U_MEDIUM_DIR_STATE_ERROR' => 0));
            } else {
                if (is_writable($phpbbgallery_core_file_medium)) {
                    $template->assign_vars(array('U_MEDIUM_DIR_STATE' => $user->lang['WRITE_ACCESS'], 'U_MEDIUM_DIR_STATE_ERROR' => 0));
                } else {
                    $template->assign_vars(array('U_MEDIUM_DIR_STATE' => $user->lang['NO_WRITE_ACCESS'], 'U_MEDIUM_DIR_STATE_ERROR' => 1));
                }
            }
            if (!file_exists($phpbbgallery_core_file_mini)) {
                mkdir($phpbbgallery_core_file_mini, 0755, true);
                $template->assign_vars(array('U_MINI_DIR_STATE' => $user->lang['DIR_CREATED'], 'U_MINI_DIR_STATE_ERROR' => 0));
            } else {
                if (is_writable($phpbbgallery_core_file_mini)) {
                    $template->assign_vars(array('U_MINI_DIR_STATE' => $user->lang['WRITE_ACCESS'], 'U_MINI_DIR_STATE_ERROR' => 0));
                } else {
                    $template->assign_vars(array('U_MINI_DIR_STATE' => $user->lang['NO_WRITE_ACCESS'], 'U_MINI_DIR_STATE_ERROR' => 1));
                }
            }
            if (!file_exists($phpbbgallery_core_file_source)) {
                mkdir($phpbbgallery_core_file_source, 0755, true);
                $template->assign_vars(array('U_SOURCE_DIR_STATE' => $user->lang['DIR_CREATED'], 'U_SOURCE_DIR_STATE_ERROR' => 0));
            } else {
                if (is_writable($phpbbgallery_core_file_source)) {
                    $template->assign_vars(array('U_SOURCE_DIR_STATE' => $user->lang['WRITE_ACCESS'], 'U_SOURCE_DIR_STATE_ERROR' => 0));
                } else {
                    $template->assign_vars(array('U_SOURCE_DIR_STATE' => $user->lang['NO_WRITE_ACCESS'], 'U_SOURCE_DIR_STATE_ERROR' => 1));
                }
            }
        }
        if (!confirm_box(true)) {
            $confirm = false;
            $album_id = 0;
            switch ($action) {
                case 'images':
                    $confirm = true;
                    $confirm_lang = 'RESYNC_IMAGECOUNTS_CONFIRM';
                    break;
                case 'personals':
                    $confirm = true;
                    $confirm_lang = 'CONFIRM_OPERATION';
                    break;
                case 'stats':
                    $confirm = true;
                    $confirm_lang = 'CONFIRM_OPERATION';
                    break;
                case 'last_images':
                    $confirm = true;
                    $confirm_lang = 'CONFIRM_OPERATION';
                    break;
                case 'reset_rating':
                    $album_id = $request->variable('reset_album_id', 0);
                    $album_data = $phpbb_ext_gallery_core_album->get_info($album_id);
                    $confirm = true;
                    $confirm_lang = sprintf($user->lang['RESET_RATING_CONFIRM'], $album_data['album_name']);
                    break;
                case 'purge_cache':
                    $confirm = true;
                    $confirm_lang = 'GALLERY_PURGE_CACHE_EXPLAIN';
                    break;
                case 'create_pega':
                    $confirm = false;
                    if (!$auth->acl_get('a_board')) {
                        trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                    }
                    $username = $request->variable('username', '', true);
                    $user_id = 0;
                    if ($username) {
                        if (!function_exists('user_get_id_name')) {
                            $phpbb_ext_gallery->url->_include('functions_user', 'phpbb');
                        }
                        user_get_id_name($user_id, $username);
                    }
                    if (is_array($user_id)) {
                        $user_id = isset($user_id[0]) ? $user_id[0] : 0;
                    }
                    $sql = 'SELECT username, user_colour, user_id
						FROM ' . USERS_TABLE . '
						WHERE user_id = ' . $user_id;
                    $result = $db->sql_query($sql);
                    $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);
                    }
                    $image_user = $phpbb_gallery_user->set_user_id($user_row['user_id']);
                    $album_id = $phpbb_gallery_user->get_data('personal_album_id');
                    if ($album_id) {
                        trigger_error($user->lang('PEGA_ALREADY_EXISTS', $user_row['username']) . adm_back_link($this->u_action), E_USER_WARNING);
                    }
                    $phpbb_ext_gallery_core_album->generate_personal_album($user_row['username'], $user_row['user_id'], $user_row['user_colour'], $phpbb_gallery_user);
                    trigger_error($user->lang('PEGA_CREATED', $user_row['username']) . adm_back_link($this->u_action));
                    break;
            }
            if ($confirm) {
                confirm_box(false, $album_id ? $confirm_lang : $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action, 'reset_album_id' => $album_id)));
            }
        } else {
            switch ($action) {
                case 'images':
                    if (!$auth->acl_get('a_board')) {
                        trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                    }
                    $total_images = $total_comments = 0;
                    $phpbb_gallery_user->update_users('all', array('user_images' => 0));
                    $sql = 'SELECT COUNT(image_id) AS num_images, image_user_id AS user_id, SUM(image_comments) AS num_comments
						FROM ' . $images_table . '
						WHERE image_status <> ' . $phpbb_gallery_image::STATUS_UNAPPROVED . '
							AND image_status <> ' . $phpbb_gallery_image::STATUS_ORPHAN . '
						GROUP BY image_user_id';
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        $total_images += $row['num_images'];
                        $total_comments += $row['num_comments'];
                        $image_user = $phpbb_container->get('phpbbgallery.core.user');
                        $image_user->set_user_id($row['user_id'], false);
                        $image_user->update_data(array('user_images' => $row['num_images']));
                    }
                    $db->sql_freeresult($result);
                    $phpbb_ext_gallery_config->set('num_images', $total_images);
                    $phpbb_ext_gallery_config->set('num_comments', $total_comments);
                    trigger_error($user->lang['RESYNCED_IMAGECOUNTS'] . adm_back_link($this->u_action));
                    break;
                case 'personals':
                    if (!$auth->acl_get('a_board')) {
                        trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                    }
                    $phpbb_gallery_user->update_users('all', array('personal_album_id' => 0));
                    $sql = 'SELECT album_id, album_user_id
						FROM ' . $albums_table . '
						WHERE album_user_id <> ' . $phpbb_ext_gallery_core_album::PUBLIC_ALBUM . '
							AND parent_id = 0
						GROUP BY album_user_id, album_id';
                    $result = $db->sql_query($sql);
                    $number_of_personals = 0;
                    while ($row = $db->sql_fetchrow($result)) {
                        $image_user = $phpbb_gallery_user->set_user_id($row['album_user_id'], false);
                        $phpbb_gallery_user->update_data(array('personal_album_id' => $row['album_id']));
                        $number_of_personals++;
                    }
                    $db->sql_freeresult($result);
                    $phpbb_ext_gallery_config->set('num_pegas', $number_of_personals);
                    // Update the config for the statistic on the index
                    $sql_array = array('SELECT' => 'a.album_id, u.user_id, u.username, u.user_colour', 'FROM' => array($albums_table => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = a.album_user_id')), 'WHERE' => 'a.album_user_id <> ' . $phpbb_ext_gallery_core_album::PUBLIC_ALBUM . ' AND a.parent_id = 0', 'ORDER_BY' => 'a.album_id DESC');
                    $sql = $db->sql_build_query('SELECT', $sql_array);
                    $result = $db->sql_query_limit($sql, 1);
                    $newest_pgallery = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                    $phpbb_ext_gallery_config->set('newest_pega_user_id', $newest_pgallery['user_id']);
                    $phpbb_ext_gallery_config->set('newest_pega_username', $newest_pgallery['username']);
                    $phpbb_ext_gallery_config->set('newest_pega_user_colour', $newest_pgallery['user_colour']);
                    $phpbb_ext_gallery_config->set('newest_pega_album_id', $newest_pgallery['album_id']);
                    trigger_error($user->lang['RESYNCED_PERSONALS'] . adm_back_link($this->u_action));
                    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);
                    }
                    // Hopefully this won't take to long! >> I think we must make it batchwise
                    $sql = 'SELECT image_id, image_filename
						FROM ' . $images_table . '
						WHERE filesize_upload = 0';
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        $sql_ary = array('filesize_upload' => @filesize($phpbb_ext_gallery->url->path('upload') . $row['image_filename']), 'filesize_medium' => @filesize($phpbb_ext_gallery->url->path('medium') . $row['image_filename']), 'filesize_cache' => @filesize($phpbb_ext_gallery->url->path('thumbnail') . $row['image_filename']));
                        $sql = 'UPDATE ' . $images_table . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
							WHERE ' . $db->sql_in_set('image_id', $row['image_id']);
                        $db->sql_query($sql);
                    }
                    $db->sql_freeresult($result);
                    redirect($this->u_action);
                    break;
                case 'last_images':
                    $sql = 'SELECT album_id
						FROM ' . $albums_table;
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        // 5 sql's per album, but you don't run this daily ;)
                        $phpbb_ext_gallery_core_album::update_info($row['album_id']);
                    }
                    $db->sql_freeresult($result);
                    trigger_error($user->lang['RESYNCED_LAST_IMAGES'] . adm_back_link($this->u_action));
                    break;
                case 'reset_rating':
                    $album_id = $request->variable('reset_album_id', 0);
                    $image_ids = array();
                    $sql = 'SELECT image_id
						FROM ' . $images_table . '
						WHERE image_album_id = ' . $album_id;
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        $image_ids[] = $row['image_id'];
                    }
                    $db->sql_freeresult($result);
                    if (!empty($image_ids)) {
                        phpbb_gallery_image_rating::delete_ratings($image_ids, true);
                    }
                    trigger_error($user->lang['RESET_RATING_COMPLETED'] . adm_back_link($this->u_action));
                    break;
                case 'purge_cache':
                    if ($user->data['user_type'] != USER_FOUNDER) {
                        trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                    }
                    $cache_dir = @opendir($phpbb_ext_gallery->url->path('thumbnail'));
                    while ($cache_file = @readdir($cache_dir)) {
                        if (preg_match('/(\\.gif$|\\.png$|\\.jpg|\\.jpeg)$/is', $cache_file)) {
                            @unlink($phpbb_ext_gallery->url->path('thumbnail') . $cache_file);
                        }
                    }
                    @closedir($cache_dir);
                    $medium_dir = @opendir($phpbb_ext_gallery->url->path('medium'));
                    while ($medium_file = @readdir($medium_dir)) {
                        if (preg_match('/(\\.gif$|\\.png$|\\.jpg|\\.jpeg)$/is', $medium_file)) {
                            @unlink($phpbb_ext_gallery->url->path('medium') . $medium_file);
                        }
                    }
                    @closedir($medium_dir);
                    for ($i = 1; $i <= $phpbb_ext_gallery_config->get('current_upload_dir'); $i++) {
                        $cache_dir = @opendir($phpbb_ext_gallery->url->path('thumbnail') . $i . '/');
                        while ($cache_file = @readdir($cache_dir)) {
                            if (preg_match('/(\\.gif$|\\.png$|\\.jpg|\\.jpeg)$/is', $cache_file)) {
                                @unlink($phpbb_ext_gallery->url->path('thumbnail') . $i . '/' . $cache_file);
                            }
                        }
                        @closedir($cache_dir);
                        $medium_dir = @opendir($phpbb_ext_gallery->url->path('medium') . $i . '/');
                        while ($medium_file = @readdir($medium_dir)) {
                            if (preg_match('/(\\.gif$|\\.png$|\\.jpg|\\.jpeg)$/is', $medium_file)) {
                                @unlink($phpbb_ext_gallery->url->path('medium') . $i . '/' . $medium_file);
                            }
                        }
                        @closedir($medium_dir);
                    }
                    $sql_ary = array('filesize_medium' => 0, 'filesize_cache' => 0);
                    $sql = 'UPDATE ' . $images_table . '
						SET ' . $db->sql_build_array('UPDATE', $sql_ary);
                    $db->sql_query($sql);
                    trigger_error($user->lang['PURGED_CACHE'] . adm_back_link($this->u_action));
                    break;
            }
        }
        //@todo: phpbb_gallery_modversioncheck::check();
        $boarddays = (time() - $config['board_startdate']) / 86400;
        $images_per_day = sprintf('%.2f', $config['num_images'] / $boarddays);
        $sql = 'SELECT COUNT(album_user_id) AS num_albums
			FROM ' . $albums_table . '
			WHERE album_user_id = 0';
        $result = $db->sql_query($sql);
        $num_albums = (int) $db->sql_fetchfield('num_albums');
        $db->sql_freeresult($result);
        $sql = 'SELECT SUM(filesize_upload) AS stat, SUM(filesize_medium) AS stat_medium, SUM(filesize_cache) AS stat_cache
			FROM ' . $images_table;
        $result = $db->sql_query($sql);
        $dir_sizes = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        $template->assign_vars(array('S_GALLERY_OVERVIEW' => true, 'ACP_GALLERY_TITLE' => $user->lang['ACP_GALLERY_OVERVIEW'], 'ACP_GALLERY_TITLE_EXPLAIN' => $user->lang['ACP_GALLERY_OVERVIEW_EXPLAIN'], 'TOTAL_IMAGES' => $config['phpbb_gallery_num_images'], 'IMAGES_PER_DAY' => $images_per_day, 'TOTAL_ALBUMS' => $num_albums, 'TOTAL_PERSONALS' => $config['phpbb_gallery_num_pegas'], 'GUPLOAD_DIR_SIZE' => get_formatted_filesize($dir_sizes['stat']), 'MEDIUM_DIR_SIZE' => get_formatted_filesize($dir_sizes['stat_medium']), 'CACHE_DIR_SIZE' => get_formatted_filesize($dir_sizes['stat_cache']), 'GALLERY_VERSION' => $config['phpbb_gallery_version'], 'U_FIND_USERNAME' => $phpbb_ext_gallery->url->append_sid('phpbb', 'memberlist', 'mode=searchuser&amp;form=action_create_pega_form&amp;field=username&amp;select_single=true'), 'S_SELECT_ALBUM' => $phpbb_ext_gallery_core_album->get_albumbox(false, 'reset_album_id', false, false, false, $phpbb_ext_gallery_core_album::PUBLIC_ALBUM, $phpbb_ext_gallery_core_album::TYPE_UPLOAD), 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false, 'U_ACTION' => $this->u_action));
    }
Exemple #27
0
/**
* Generate page footer
*/
function page_footer($run_cron = true)
{
    global $db, $config, $template, $user, $auth, $cache, $starttime, $phpbb_root_path, $phpEx;
    // Output page creation time
    if (defined('DEBUG')) {
        $mtime = explode(' ', microtime());
        $totaltime = $mtime[0] + $mtime[1] - $starttime;
        if (!empty($_REQUEST['explain']) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report')) {
            $db->sql_report('display');
        }
        $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . ($config['gzip_compress'] ? 'On' : 'Off') . ($user->load ? ' | Load : ' . $user->load : ''), $totaltime);
        if ($auth->acl_get('a_') && defined('DEBUG_EXTRA')) {
            if (function_exists('memory_get_usage')) {
                if ($memory_usage = memory_get_usage()) {
                    global $base_memory_usage;
                    $memory_usage -= $base_memory_usage;
                    $memory_usage = get_formatted_filesize($memory_usage);
                    $debug_output .= ' | Memory Usage: ' . $memory_usage;
                }
            }
            $debug_output .= ' | <a href="' . build_url() . '&amp;explain=1">Explain</a>';
        }
    }
    $template->assign_vars(array('DEBUG_OUTPUT' => defined('DEBUG') ? $debug_output : '', 'TRANSLATION_INFO' => !empty($user->lang['TRANSLATION_INFO']) ? $user->lang['TRANSLATION_INFO'] : '', 'U_ACP' => $auth->acl_get('a_') && !empty($user->data['is_registered']) ? append_sid("{$phpbb_root_path}adm/index.{$phpEx}", false, true, $user->session_id) : ''));
    // Call cron-type script
    if (!defined('IN_CRON') && $run_cron && !$config['board_disable']) {
        $cron_type = '';
        if (time() - $config['queue_interval'] > $config['last_queue_run'] && !defined('IN_ADMIN') && file_exists($phpbb_root_path . 'cache/queue.' . $phpEx)) {
            // Process email queue
            $cron_type = 'queue';
        } else {
            if (method_exists($cache, 'tidy') && time() - $config['cache_gc'] > $config['cache_last_gc']) {
                // Tidy the cache
                $cron_type = 'tidy_cache';
            } else {
                if (time() - $config['warnings_gc'] > $config['warnings_last_gc']) {
                    $cron_type = 'tidy_warnings';
                } else {
                    if (time() - $config['database_gc'] > $config['database_last_gc']) {
                        // Tidy the database
                        $cron_type = 'tidy_database';
                    } else {
                        if (time() - $config['search_gc'] > $config['search_last_gc']) {
                            // Tidy the search
                            $cron_type = 'tidy_search';
                        } else {
                            if (time() - $config['session_gc'] > $config['session_last_gc']) {
                                $cron_type = 'tidy_sessions';
                            }
                        }
                    }
                }
            }
        }
        if ($cron_type) {
            $template->assign_var('RUN_CRON_TASK', '<img src="' . append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=' . $cron_type) . '" width="1" height="1" alt="cron" />');
        }
    }
    $template->display('body');
    garbage_collection();
    exit_handler();
}
Exemple #28
0
if ( DEBUG && RSS_DEBUG_MODE )
{
	$mtime = explode(' ', microtime());
	$totaltime = $mtime[0] + $mtime[1] - $starttime;

	$debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries(false) . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime);

	if ($auth->acl_get('a_') && defined('DEBUG_EXTRA'))
	{
		if (function_exists('memory_get_usage'))
		{
			if ($memory_usage = memory_get_usage())
			{
				global $base_memory_usage;
				$memory_usage -= $base_memory_usage;
				$memory_usage = get_formatted_filesize($memory_usage);
				$debug_output .= ' | Memory Usage: ' . $memory_usage;
			}
		}
	}

	if ( RSS_DEBUG_SQL )
	{
		$debug_output .= "<br /><strong>SQL : </strong>$sql";
	}

	$template->assign_vars(array(
		'DEBUG_OUTPUT'		=> $debug_output,
	));
}
Exemple #29
0
/**
* Get database size
* Currently only mysql and mssql are supported
*/
function get_database_size()
{
    global $db, $user, $table_prefix;
    $database_size = false;
    // This code is heavily influenced by a similar routine in phpMyAdmin 2.2.0
    switch ($db->get_sql_layer()) {
        case 'mysql':
        case 'mysql4':
        case 'mysqli':
            $sql = 'SELECT VERSION() AS mysql_version';
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if ($row) {
                $version = $row['mysql_version'];
                if (preg_match('#(3\\.23|[45]\\.|10\\.[0-9]\\.[0-9]{1,2}-+Maria)#', $version)) {
                    $db_name = preg_match('#^(?:3\\.23\\.(?:[6-9]|[1-9]{2}))|[45]\\.|10\\.[0-9]\\.[0-9]{1,2}-+Maria#', $version) ? "`{$db->get_db_name()}`" : $db->get_db_name();
                    $sql = 'SHOW TABLE STATUS
						FROM ' . $db_name;
                    $result = $db->sql_query($sql, 7200);
                    $database_size = 0;
                    while ($row = $db->sql_fetchrow($result)) {
                        if (isset($row['Type']) && $row['Type'] != 'MRG_MyISAM' || isset($row['Engine']) && ($row['Engine'] == 'MyISAM' || $row['Engine'] == 'InnoDB')) {
                            if ($table_prefix != '') {
                                if (strpos($row['Name'], $table_prefix) !== false) {
                                    $database_size += $row['Data_length'] + $row['Index_length'];
                                }
                            } else {
                                $database_size += $row['Data_length'] + $row['Index_length'];
                            }
                        }
                    }
                    $db->sql_freeresult($result);
                }
            }
            break;
        case 'sqlite':
        case 'sqlite3':
            global $dbhost;
            if (file_exists($dbhost)) {
                $database_size = filesize($dbhost);
            }
            break;
        case 'mssql':
        case 'mssql_odbc':
        case 'mssqlnative':
            $sql = 'SELECT @@VERSION AS mssql_version';
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            $sql = 'SELECT ((SUM(size) * 8.0) * 1024.0) as dbsize
				FROM sysfiles';
            if ($row) {
                // Azure stats are stored elsewhere
                if (strpos($row['mssql_version'], 'SQL Azure') !== false) {
                    $sql = 'SELECT ((SUM(reserved_page_count) * 8.0) * 1024.0) as dbsize
					FROM sys.dm_db_partition_stats';
                }
            }
            $result = $db->sql_query($sql, 7200);
            $database_size = ($row = $db->sql_fetchrow($result)) ? $row['dbsize'] : false;
            $db->sql_freeresult($result);
            break;
        case 'postgres':
            $sql = "SELECT proname\n\t\t\t\tFROM pg_proc\n\t\t\t\tWHERE proname = 'pg_database_size'";
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if ($row['proname'] == 'pg_database_size') {
                $database = $db->get_db_name();
                if (strpos($database, '.') !== false) {
                    list($database, ) = explode('.', $database);
                }
                $sql = "SELECT oid\n\t\t\t\t\tFROM pg_database\n\t\t\t\t\tWHERE datname = '{$database}'";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $oid = $row['oid'];
                $sql = 'SELECT pg_database_size(' . $oid . ') as size';
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $database_size = $row['size'];
            }
            break;
        case 'oracle':
            $sql = 'SELECT SUM(bytes) as dbsize
				FROM user_segments';
            $result = $db->sql_query($sql, 7200);
            $database_size = ($row = $db->sql_fetchrow($result)) ? $row['dbsize'] : false;
            $db->sql_freeresult($result);
            break;
    }
    $database_size = $database_size !== false ? get_formatted_filesize($database_size) : $user->lang['NOT_AVAILABLE'];
    return $database_size;
}
/**
* Generate the debug output string
*
* @param \phpbb\db\driver\driver_interface	$db			Database connection
* @param \phpbb\config\config				$config		Config object
* @param \phpbb\auth\auth					$auth		Auth object
* @param \phpbb\user						$user		User object
* @param \phpbb\event\dispatcher_interface	$phpbb_dispatcher	Event dispatcher
* @return string
*/
function phpbb_generate_debug_output(\phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\auth\auth $auth, \phpbb\user $user, \phpbb\event\dispatcher_interface $phpbb_dispatcher)
{
    $debug_info = array();
    // Output page creation time
    if (defined('PHPBB_DISPLAY_LOAD_TIME')) {
        if (isset($GLOBALS['starttime'])) {
            $totaltime = microtime(true) - $GLOBALS['starttime'];
            $debug_info[] = sprintf('<abbr title="SQL time: %.3fs / PHP time: %.3fs">Time: %.3fs</abbr>', $db->get_sql_time(), $totaltime - $db->get_sql_time(), $totaltime);
        }
        $debug_info[] = sprintf('<abbr title="Cached: %d">Queries: %d</abbr>', $db->sql_num_queries(true), $db->sql_num_queries());
        $memory_usage = memory_get_peak_usage();
        if ($memory_usage) {
            $memory_usage = get_formatted_filesize($memory_usage);
            $debug_info[] = 'Peak Memory Usage: ' . $memory_usage;
        }
    }
    if (defined('DEBUG')) {
        $debug_info[] = 'GZIP: ' . ($config['gzip_compress'] && @extension_loaded('zlib') ? 'On' : 'Off');
        if ($user->load) {
            $debug_info[] = 'Load: ' . $user->load;
        }
        if ($auth->acl_get('a_')) {
            $debug_info[] = '<a href="' . build_url() . '&amp;explain=1">SQL Explain</a>';
        }
    }
    /**
     * Modify debug output information
     *
     * @event core.phpbb_generate_debug_output
     * @var	array	debug_info		Array of strings with debug information
     *
     * @since 3.1.0-RC3
     */
    $vars = array('debug_info');
    extract($phpbb_dispatcher->trigger_event('core.phpbb_generate_debug_output', compact($vars)));
    return implode(' | ', $debug_info);
}