Ejemplo n.º 1
0
/**
* Create Thumbnail
*/
function create_thumbnail($source, $destination, $mimetype)
{
    global $config, $phpbb_filesystem;
    $min_filesize = (int) $config['img_min_thumb_filesize'];
    $img_filesize = file_exists($source) ? @filesize($source) : false;
    if (!$img_filesize || $img_filesize <= $min_filesize) {
        return false;
    }
    $dimension = @getimagesize($source);
    if ($dimension === false) {
        return false;
    }
    list($width, $height, $type, ) = $dimension;
    if (empty($width) || empty($height)) {
        return false;
    }
    list($new_width, $new_height) = get_img_size_format($width, $height);
    // Do not create a thumbnail if the resulting width/height is bigger than the original one
    if ($new_width >= $width && $new_height >= $height) {
        return false;
    }
    $used_imagick = false;
    // Only use imagemagick if defined and the passthru function not disabled
    if ($config['img_imagick'] && function_exists('passthru')) {
        if (substr($config['img_imagick'], -1) !== '/') {
            $config['img_imagick'] .= '/';
        }
        @passthru(escapeshellcmd($config['img_imagick']) . 'convert' . (defined('PHP_OS') && preg_match('#^win#i', PHP_OS) ? '.exe' : '') . ' -quality 85 -geometry ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" "' . str_replace('\\', '/', $destination) . '"');
        if (file_exists($destination)) {
            $used_imagick = true;
        }
    }
    if (!$used_imagick) {
        $type = get_supported_image_types($type);
        if ($type['gd']) {
            // If the type is not supported, we are not able to create a thumbnail
            if ($type['format'] === false) {
                return false;
            }
            switch ($type['format']) {
                case IMG_GIF:
                    $image = @imagecreatefromgif($source);
                    break;
                case IMG_JPG:
                    @ini_set('gd.jpeg_ignore_warning', 1);
                    $image = @imagecreatefromjpeg($source);
                    break;
                case IMG_PNG:
                    $image = @imagecreatefrompng($source);
                    break;
                case IMG_WBMP:
                    $image = @imagecreatefromwbmp($source);
                    break;
            }
            if (empty($image)) {
                return false;
            }
            if ($type['version'] == 1) {
                $new_image = imagecreate($new_width, $new_height);
                if ($new_image === false) {
                    return false;
                }
                imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            } else {
                $new_image = imagecreatetruecolor($new_width, $new_height);
                if ($new_image === false) {
                    return false;
                }
                // Preserve alpha transparency (png for example)
                @imagealphablending($new_image, false);
                @imagesavealpha($new_image, true);
                imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            }
            // If we are in safe mode create the destination file prior to using the gd functions to circumvent a PHP bug
            if (@ini_get('safe_mode') || @strtolower(ini_get('safe_mode')) == 'on') {
                @touch($destination);
            }
            switch ($type['format']) {
                case IMG_GIF:
                    imagegif($new_image, $destination);
                    break;
                case IMG_JPG:
                    imagejpeg($new_image, $destination, 90);
                    break;
                case IMG_PNG:
                    imagepng($new_image, $destination);
                    break;
                case IMG_WBMP:
                    imagewbmp($new_image, $destination);
                    break;
            }
            imagedestroy($new_image);
        } else {
            return false;
        }
    }
    if (!file_exists($destination)) {
        return false;
    }
    try {
        $phpbb_filesystem->phpbb_chmod($destination, CHMOD_READ | CHMOD_WRITE);
    } catch (\phpbb\filesystem\exception\filesystem_exception $e) {
        // Do nothing
    }
    return true;
}
Ejemplo n.º 2
0
    function main($id, $mode)
    {
        global $db, $user, $auth, $template, $cache;
        global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
        $user->add_lang(array('posting', 'viewtopic', 'acp/attachments'));
        $error = $notify = array();
        $submit = isset($_POST['submit']) ? true : false;
        $action = request_var('action', '');
        $form_key = 'acp_attach';
        add_form_key($form_key);
        if ($submit && !check_form_key($form_key)) {
            trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
        }
        switch ($mode) {
            case 'attach':
                $l_title = 'ACP_ATTACHMENT_SETTINGS';
                break;
            case 'extensions':
                $l_title = 'ACP_MANAGE_EXTENSIONS';
                break;
            case 'ext_groups':
                $l_title = 'ACP_EXTENSION_GROUPS';
                break;
            case 'orphan':
                $l_title = 'ACP_ORPHAN_ATTACHMENTS';
                break;
            default:
                trigger_error('NO_MODE', E_USER_ERROR);
                break;
        }
        $this->tpl_name = 'acp_attachments';
        $this->page_title = $l_title;
        $template->assign_vars(array('L_TITLE' => $user->lang[$l_title], 'L_TITLE_EXPLAIN' => $user->lang[$l_title . '_EXPLAIN'], 'U_ACTION' => $this->u_action));
        switch ($mode) {
            case 'attach':
                include_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
                $sql = 'SELECT group_name, cat_id
					FROM ' . EXTENSION_GROUPS_TABLE . '
					WHERE cat_id > 0
					ORDER BY cat_id';
                $result = $db->sql_query($sql);
                $s_assigned_groups = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $s_assigned_groups[$row['cat_id']][] = $row['group_name'];
                }
                $db->sql_freeresult($result);
                $l_legend_cat_images = $user->lang['SETTINGS_CAT_IMAGES'] . ' [' . $user->lang['ASSIGNED_GROUP'] . ': ' . (!empty($s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE]) ? implode(', ', $s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE]) : $user->lang['NO_EXT_GROUP']) . ']';
                $display_vars = array('title' => 'ACP_ATTACHMENT_SETTINGS', 'vars' => array('legend1' => 'ACP_ATTACHMENT_SETTINGS', 'img_max_width' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'img_max_height' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'img_link_width' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'img_link_height' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'allow_attachments' => array('lang' => 'ALLOW_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'allow_pm_attach' => array('lang' => 'ALLOW_PM_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'upload_path' => array('lang' => 'UPLOAD_DIR', 'validate' => 'wpath', 'type' => 'text:25:100', 'explain' => true), 'display_order' => array('lang' => 'DISPLAY_ORDER', 'validate' => 'bool', 'type' => 'custom', 'method' => 'display_order', 'explain' => true), 'attachment_quota' => array('lang' => 'ATTACH_QUOTA', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_filesize' => array('lang' => 'ATTACH_MAX_FILESIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_filesize_pm' => array('lang' => 'ATTACH_MAX_PM_FILESIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_attachments' => array('lang' => 'MAX_ATTACHMENTS', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => false), 'max_attachments_pm' => array('lang' => 'MAX_ATTACHMENTS_PM', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => false), 'secure_downloads' => array('lang' => 'SECURE_DOWNLOADS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true), 'secure_allow_empty_referer' => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'check_attachment_content' => array('lang' => 'CHECK_CONTENT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'legend2' => $l_legend_cat_images, 'img_display_inlined' => array('lang' => 'DISPLAY_INLINED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'img_create_thumbnail' => array('lang' => 'CREATE_THUMBNAIL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'img_max_thumb_width' => array('lang' => 'MAX_THUMB_WIDTH', 'validate' => 'int', 'type' => 'text:7:15', 'explain' => true, 'append' => ' px'), 'img_min_thumb_filesize' => array('lang' => 'MIN_THUMB_FILESIZE', 'validate' => 'int', 'type' => 'text:7:15', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']), 'img_imagick' => array('lang' => 'IMAGICK_PATH', 'validate' => 'string', 'type' => 'text:20:200', 'explain' => true, 'append' => '&nbsp;&nbsp;<span>[ <a href="' . $this->u_action . '&amp;action=imgmagick">' . $user->lang['SEARCH_IMAGICK'] . '</a> ]</span>'), 'img_max' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px'), 'img_link' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int', 'type' => 'dimension:3:4', 'explain' => true, 'append' => ' px')));
                $this->new_config = $config;
                $cfg_array = isset($_REQUEST['config']) ? request_var('config', array('' => '')) : $this->new_config;
                $error = array();
                // We validate the complete config if whished
                validate_config_vars($display_vars['vars'], $cfg_array, $error);
                // Do not write values if there is an error
                if (sizeof($error)) {
                    $submit = false;
                }
                // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
                foreach ($display_vars['vars'] as $config_name => $null) {
                    if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) {
                        continue;
                    }
                    $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
                    if (in_array($config_name, array('attachment_quota', 'max_filesize', 'max_filesize_pm'))) {
                        $size_var = request_var($config_name, '');
                        $this->new_config[$config_name] = $config_value = $size_var == 'kb' ? round($config_value * 1024) : ($size_var == 'mb' ? round($config_value * 1048576) : $config_value);
                    }
                    if ($submit) {
                        set_config($config_name, $config_value);
                    }
                }
                $this->perform_site_list();
                if ($submit) {
                    add_log('admin', 'LOG_CONFIG_ATTACH');
                    // Check Settings
                    $this->test_upload($error, $this->new_config['upload_path'], false);
                    if (!sizeof($error)) {
                        trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
                    }
                }
                $template->assign_var('S_ATTACHMENT_SETTINGS', true);
                if ($action == 'imgmagick') {
                    $this->new_config['img_imagick'] = $this->search_imagemagick();
                }
                // We strip eventually manual added convert program, we only want the patch
                if ($this->new_config['img_imagick']) {
                    // Change path separator
                    $this->new_config['img_imagick'] = str_replace('\\', '/', $this->new_config['img_imagick']);
                    $this->new_config['img_imagick'] = str_replace(array('convert', '.exe'), array('', ''), $this->new_config['img_imagick']);
                    // Check for trailing slash
                    if (substr($this->new_config['img_imagick'], -1) !== '/') {
                        $this->new_config['img_imagick'] .= '/';
                    }
                }
                $supported_types = get_supported_image_types();
                // Check Thumbnail Support
                if (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format']))) {
                    $this->new_config['img_create_thumbnail'] = 0;
                }
                $template->assign_vars(array('U_SEARCH_IMAGICK' => $this->u_action . '&amp;action=imgmagick', 'S_THUMBNAIL_SUPPORT' => !$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format'])) ? false : true));
                // Secure Download Options - Same procedure as with banning
                $allow_deny = $this->new_config['secure_allow_deny'] ? 'ALLOWED' : 'DISALLOWED';
                $sql = 'SELECT *
					FROM ' . SITELIST_TABLE;
                $result = $db->sql_query($sql);
                $defined_ips = '';
                $ips = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $value = $row['site_ip'] ? $row['site_ip'] : $row['site_hostname'];
                    if ($value) {
                        $defined_ips .= '<option' . ($row['ip_exclude'] ? ' class="sep"' : '') . ' value="' . $row['site_id'] . '">' . $value . '</option>';
                        $ips[$row['site_id']] = $value;
                    }
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_SECURE_DOWNLOADS' => $this->new_config['secure_downloads'], 'S_DEFINED_IPS' => $defined_ips != '' ? true : false, 'S_WARNING' => sizeof($error) ? true : false, 'WARNING_MSG' => implode('<br />', $error), 'DEFINED_IPS' => $defined_ips, 'L_SECURE_TITLE' => $user->lang['DEFINE_' . $allow_deny . '_IPS'], 'L_IP_EXCLUDE' => $user->lang['EXCLUDE_FROM_' . $allow_deny . '_IP'], 'L_REMOVE_IPS' => $user->lang['REMOVE_' . $allow_deny . '_IPS']));
                // Output relevant options
                foreach ($display_vars['vars'] as $config_key => $vars) {
                    if (!is_array($vars) && strpos($config_key, 'legend') === false) {
                        continue;
                    }
                    if (strpos($config_key, 'legend') !== false) {
                        $template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => isset($user->lang[$vars]) ? $user->lang[$vars] : $vars));
                        continue;
                    }
                    $type = explode(':', $vars['type']);
                    $l_explain = '';
                    if ($vars['explain'] && isset($vars['lang_explain'])) {
                        $l_explain = isset($user->lang[$vars['lang_explain']]) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
                    } else {
                        if ($vars['explain']) {
                            $l_explain = isset($user->lang[$vars['lang'] . '_EXPLAIN']) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
                        }
                    }
                    $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars);
                    if (empty($content)) {
                        continue;
                    }
                    $template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => $user->lang[$vars['lang']], 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $l_explain, 'CONTENT' => $content));
                    unset($display_vars['vars'][$config_key]);
                }
                break;
            case 'extensions':
                if ($submit || isset($_POST['add_extension_check'])) {
                    if ($submit) {
                        // Change Extensions ?
                        $extension_change_list = request_var('extension_change_list', array(0));
                        $group_select_list = request_var('group_select', array(0));
                        // Generate correct Change List
                        $extensions = array();
                        for ($i = 0, $size = sizeof($extension_change_list); $i < $size; $i++) {
                            $extensions[$extension_change_list[$i]]['group_id'] = $group_select_list[$i];
                        }
                        $sql = 'SELECT *
							FROM ' . EXTENSIONS_TABLE . '
							ORDER BY extension_id';
                        $result = $db->sql_query($sql);
                        while ($row = $db->sql_fetchrow($result)) {
                            if ($row['group_id'] != $extensions[$row['extension_id']]['group_id']) {
                                $sql = 'UPDATE ' . EXTENSIONS_TABLE . '
									SET group_id = ' . (int) $extensions[$row['extension_id']]['group_id'] . '
									WHERE extension_id = ' . $row['extension_id'];
                                $db->sql_query($sql);
                                add_log('admin', 'LOG_ATTACH_EXT_UPDATE', $row['extension']);
                            }
                        }
                        $db->sql_freeresult($result);
                        // Delete Extension?
                        $extension_id_list = request_var('extension_id_list', array(0));
                        if (sizeof($extension_id_list)) {
                            $sql = 'SELECT extension
								FROM ' . EXTENSIONS_TABLE . '
								WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
                            $result = $db->sql_query($sql);
                            $extension_list = '';
                            while ($row = $db->sql_fetchrow($result)) {
                                $extension_list .= $extension_list == '' ? $row['extension'] : ', ' . $row['extension'];
                            }
                            $db->sql_freeresult($result);
                            $sql = 'DELETE
								FROM ' . EXTENSIONS_TABLE . '
								WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
                            $db->sql_query($sql);
                            add_log('admin', 'LOG_ATTACH_EXT_DEL', $extension_list);
                        }
                    }
                    // Add Extension?
                    $add_extension = strtolower(request_var('add_extension', ''));
                    $add_extension_group = request_var('add_group_select', 0);
                    $add = isset($_POST['add_extension_check']) ? true : false;
                    if ($add_extension && $add) {
                        if (!sizeof($error)) {
                            $sql = 'SELECT extension_id
								FROM ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE extension = '" . $db->sql_escape($add_extension) . "'";
                            $result = $db->sql_query($sql);
                            if ($row = $db->sql_fetchrow($result)) {
                                $error[] = sprintf($user->lang['EXTENSION_EXIST'], $add_extension);
                            }
                            $db->sql_freeresult($result);
                            if (!sizeof($error)) {
                                $sql_ary = array('group_id' => $add_extension_group, 'extension' => $add_extension);
                                $db->sql_query('INSERT INTO ' . EXTENSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                                add_log('admin', 'LOG_ATTACH_EXT_ADD', $add_extension);
                            }
                        }
                    }
                    if (!sizeof($error)) {
                        $notify[] = $user->lang['EXTENSIONS_UPDATED'];
                    }
                    $cache->destroy('_extensions');
                }
                $template->assign_vars(array('S_EXTENSIONS' => true, 'ADD_EXTENSION' => isset($add_extension) ? $add_extension : '', 'GROUP_SELECT_OPTIONS' => isset($_POST['add_extension_check']) ? $this->group_select('add_group_select', $add_extension_group, 'extension_group') : $this->group_select('add_group_select', false, 'extension_group')));
                $sql = 'SELECT *
					FROM ' . EXTENSIONS_TABLE . '
					ORDER BY group_id, extension';
                $result = $db->sql_query($sql);
                if ($row = $db->sql_fetchrow($result)) {
                    $old_group_id = $row['group_id'];
                    do {
                        $s_spacer = false;
                        $current_group_id = $row['group_id'];
                        if ($old_group_id != $current_group_id) {
                            $s_spacer = true;
                            $old_group_id = $current_group_id;
                        }
                        $template->assign_block_vars('extensions', array('S_SPACER' => $s_spacer, 'EXTENSION_ID' => $row['extension_id'], 'EXTENSION' => $row['extension'], 'GROUP_OPTIONS' => $this->group_select('group_select[]', $row['group_id'])));
                    } while ($row = $db->sql_fetchrow($result));
                }
                $db->sql_freeresult($result);
                break;
            case 'ext_groups':
                $template->assign_var('S_EXTENSION_GROUPS', true);
                if ($submit) {
                    $action = request_var('action', '');
                    $group_id = request_var('g', 0);
                    if ($action != 'add' && $action != 'edit') {
                        trigger_error('NO_MODE', E_USER_ERROR);
                    }
                    if (!$group_id && $action == 'edit') {
                        trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
                    }
                    if ($group_id) {
                        $sql = 'SELECT *
							FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}";
                        $result = $db->sql_query($sql);
                        $ext_row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        if (!$ext_row) {
                            trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                    } else {
                        $ext_row = array();
                    }
                    $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
                    $new_group_name = $action == 'add' ? $group_name : ($ext_row['group_name'] != $group_name ? $group_name : '');
                    if (!$group_name) {
                        $error[] = $user->lang['NO_EXT_GROUP_NAME'];
                    }
                    // Check New Group Name
                    if ($new_group_name) {
                        $sql = 'SELECT group_id
							FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\tWHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($new_group_name)) . "'";
                        $result = $db->sql_query($sql);
                        if ($db->sql_fetchrow($result)) {
                            $error[] = sprintf($user->lang['EXTENSION_GROUP_EXIST'], $new_group_name);
                        }
                        $db->sql_freeresult($result);
                    }
                    if (!sizeof($error)) {
                        // Ok, build the update/insert array
                        $upload_icon = request_var('upload_icon', 'no_image');
                        $size_select = request_var('size_select', 'b');
                        $forum_select = request_var('forum_select', false);
                        $allowed_forums = request_var('allowed_forums', array(0));
                        $allow_in_pm = isset($_POST['allow_in_pm']) ? true : false;
                        $max_filesize = request_var('max_filesize', 0);
                        $max_filesize = $size_select == 'kb' ? round($max_filesize * 1024) : ($size_select == 'mb' ? round($max_filesize * 1048576) : $max_filesize);
                        $allow_group = isset($_POST['allow_group']) ? true : false;
                        if ($max_filesize == $config['max_filesize']) {
                            $max_filesize = 0;
                        }
                        if (!sizeof($allowed_forums)) {
                            $forum_select = false;
                        }
                        $group_ary = array('group_name' => $group_name, 'cat_id' => request_var('special_category', ATTACHMENT_CATEGORY_NONE), 'allow_group' => $allow_group ? 1 : 0, 'upload_icon' => $upload_icon == 'no_image' ? '' : $upload_icon, 'max_filesize' => $max_filesize, 'allowed_forums' => $forum_select ? serialize($allowed_forums) : '', 'allow_in_pm' => $allow_in_pm ? 1 : 0);
                        if ($action == 'add') {
                            $group_ary['download_mode'] = INLINE_LINK;
                        }
                        $sql = $action == 'add' ? 'INSERT INTO ' . EXTENSION_GROUPS_TABLE . ' ' : 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' SET ';
                        $sql .= $db->sql_build_array($action == 'add' ? 'INSERT' : 'UPDATE', $group_ary);
                        $sql .= $action == 'edit' ? " WHERE group_id = {$group_id}" : '';
                        $db->sql_query($sql);
                        if ($action == 'add') {
                            $group_id = $db->sql_nextid();
                        }
                        add_log('admin', 'LOG_ATTACH_EXTGROUP_' . strtoupper($action), $group_name);
                    }
                    $extension_list = request_var('extensions', array(0));
                    if ($action == 'edit' && sizeof($extension_list)) {
                        $sql = 'UPDATE ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\tSET group_id = 0\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}";
                        $db->sql_query($sql);
                    }
                    if (sizeof($extension_list)) {
                        $sql = 'UPDATE ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\tSET group_id = {$group_id}\n\t\t\t\t\t\t\tWHERE " . $db->sql_in_set('extension_id', $extension_list);
                        $db->sql_query($sql);
                    }
                    $cache->destroy('_extensions');
                    if (!sizeof($error)) {
                        $notify[] = $user->lang['SUCCESS_EXTENSION_GROUP_' . strtoupper($action)];
                    }
                }
                $cat_lang = array(ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'], ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'], ATTACHMENT_CATEGORY_WM => $user->lang['CAT_WM_FILES'], ATTACHMENT_CATEGORY_RM => $user->lang['CAT_RM_FILES'], ATTACHMENT_CATEGORY_FLASH => $user->lang['CAT_FLASH_FILES'], ATTACHMENT_CATEGORY_QUICKTIME => $user->lang['CAT_QUICKTIME_FILES']);
                $group_id = request_var('g', 0);
                $action = isset($_POST['add']) ? 'add' : $action;
                switch ($action) {
                    case 'delete':
                        if (confirm_box(true)) {
                            $sql = 'SELECT group_name
								FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}";
                            $result = $db->sql_query($sql);
                            $group_name = (string) $db->sql_fetchfield('group_name');
                            $db->sql_freeresult($result);
                            $sql = 'DELETE
								FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}";
                            $db->sql_query($sql);
                            // Set corresponding Extensions to a pending Group
                            $sql = 'UPDATE ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\t\tSET group_id = 0\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}";
                            $db->sql_query($sql);
                            add_log('admin', 'LOG_ATTACH_EXTGROUP_DEL', $group_name);
                            $cache->destroy('_extensions');
                            trigger_error($user->lang['EXTENSION_GROUP_DELETED'] . adm_back_link($this->u_action));
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'group_id' => $group_id, 'action' => 'delete')));
                        }
                        break;
                    case 'edit':
                        if (!$group_id) {
                            trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        $sql = 'SELECT *
							FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}";
                        $result = $db->sql_query($sql);
                        $ext_group_row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        $forum_ids = !$ext_group_row['allowed_forums'] ? array() : unserialize(trim($ext_group_row['allowed_forums']));
                        // no break;
                    // no break;
                    case 'add':
                        if ($action == 'add') {
                            $ext_group_row = array('group_name' => utf8_normalize_nfc(request_var('group_name', '', true)), 'cat_id' => 0, 'allow_group' => 1, 'allow_in_pm' => 1, 'upload_icon' => '', 'max_filesize' => 0);
                            $forum_ids = array();
                        }
                        $extensions = array();
                        $sql = 'SELECT *
							FROM ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\t\t\tOR group_id = 0\n\t\t\t\t\t\t\tORDER BY extension";
                        $result = $db->sql_query($sql);
                        $extensions = $db->sql_fetchrowset($result);
                        $db->sql_freeresult($result);
                        if ($ext_group_row['max_filesize'] == 0) {
                            $ext_group_row['max_filesize'] = (int) $config['max_filesize'];
                        }
                        $size_format = $ext_group_row['max_filesize'] >= 1048576 ? 'mb' : ($ext_group_row['max_filesize'] >= 1024 ? 'kb' : 'b');
                        $ext_group_row['max_filesize'] = get_formatted_filesize($ext_group_row['max_filesize'], false);
                        $img_path = $config['upload_icons_path'];
                        $filename_list = '';
                        $no_image_select = false;
                        $imglist = filelist($phpbb_root_path . $img_path);
                        if (sizeof($imglist)) {
                            $imglist = array_values($imglist);
                            $imglist = $imglist[0];
                            foreach ($imglist as $key => $img) {
                                if (!$ext_group_row['upload_icon']) {
                                    $no_image_select = true;
                                    $selected = '';
                                } else {
                                    $selected = $ext_group_row['upload_icon'] == $img ? ' selected="selected"' : '';
                                }
                                if (strlen($img) > 255) {
                                    continue;
                                }
                                $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . htmlspecialchars($img) . '</option>';
                            }
                        }
                        $i = 0;
                        $assigned_extensions = '';
                        foreach ($extensions as $num => $row) {
                            if ($row['group_id'] == $group_id && $group_id) {
                                $assigned_extensions .= $i ? ', ' . $row['extension'] : $row['extension'];
                                $i++;
                            }
                        }
                        $s_extension_options = '';
                        foreach ($extensions as $row) {
                            $s_extension_options .= '<option' . (!$row['group_id'] ? ' class="disabled"' : '') . ' value="' . $row['extension_id'] . '"' . ($row['group_id'] == $group_id && $group_id ? ' selected="selected"' : '') . '>' . $row['extension'] . '</option>';
                        }
                        $template->assign_vars(array('PHPBB_ROOT_PATH' => $phpbb_root_path, 'IMG_PATH' => $img_path, 'ACTION' => $action, 'GROUP_ID' => $group_id, 'GROUP_NAME' => $ext_group_row['group_name'], 'ALLOW_GROUP' => $ext_group_row['allow_group'], 'ALLOW_IN_PM' => $ext_group_row['allow_in_pm'], 'UPLOAD_ICON_SRC' => $phpbb_root_path . $img_path . '/' . $ext_group_row['upload_icon'], 'EXTGROUP_FILESIZE' => $ext_group_row['max_filesize'], 'ASSIGNED_EXTENSIONS' => $assigned_extensions, 'S_CATEGORY_SELECT' => $this->category_select('special_category', $group_id, 'category'), 'S_EXT_GROUP_SIZE_OPTIONS' => size_select_options($size_format), 'S_EXTENSION_OPTIONS' => $s_extension_options, 'S_FILENAME_LIST' => $filename_list, 'S_EDIT_GROUP' => true, 'S_NO_IMAGE' => $no_image_select, 'S_FORUM_IDS' => sizeof($forum_ids) ? true : false, 'U_EXTENSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$id}&amp;mode=extensions"), 'U_BACK' => $this->u_action, 'L_LEGEND' => $user->lang[strtoupper($action) . '_EXTENSION_GROUP']));
                        $s_forum_id_options = '';
                        /** @todo use in-built function **/
                        $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
							FROM ' . FORUMS_TABLE . '
							ORDER BY left_id ASC';
                        $result = $db->sql_query($sql, 600);
                        $right = $cat_right = $padding_inc = 0;
                        $padding = $forum_list = $holding = '';
                        $padding_store = array('0' => '');
                        while ($row = $db->sql_fetchrow($result)) {
                            if ($row['forum_type'] == FORUM_CAT && $row['left_id'] + 1 == $row['right_id']) {
                                // Non-postable forum with no subforums, don't display
                                continue;
                            }
                            if (!$auth->acl_get('f_list', $row['forum_id'])) {
                                // if the user does not have permissions to list this forum skip
                                continue;
                            }
                            if ($row['left_id'] < $right) {
                                $padding .= '&nbsp; &nbsp;';
                                $padding_store[$row['parent_id']] = $padding;
                            } else {
                                if ($row['left_id'] > $right + 1) {
                                    $padding = empty($padding_store[$row['parent_id']]) ? '' : $padding_store[$row['parent_id']];
                                }
                            }
                            $right = $row['right_id'];
                            $selected = in_array($row['forum_id'], $forum_ids) ? ' selected="selected"' : '';
                            if ($row['left_id'] > $cat_right) {
                                // make sure we don't forget anything
                                $s_forum_id_options .= $holding;
                                $holding = '';
                            }
                            if ($row['right_id'] - $row['left_id'] > 1) {
                                $cat_right = max($cat_right, $row['right_id']);
                                $holding .= '<option value="' . $row['forum_id'] . '"' . ($row['forum_type'] == FORUM_POST ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
                            } else {
                                $s_forum_id_options .= $holding . '<option value="' . $row['forum_id'] . '"' . ($row['forum_type'] == FORUM_POST ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
                                $holding = '';
                            }
                        }
                        if ($holding) {
                            $s_forum_id_options .= $holding;
                        }
                        $db->sql_freeresult($result);
                        unset($padding_store);
                        $template->assign_vars(array('S_FORUM_ID_OPTIONS' => $s_forum_id_options));
                        break;
                }
                $sql = 'SELECT *
					FROM ' . EXTENSION_GROUPS_TABLE . '
					ORDER BY allow_group DESC, allow_in_pm DESC, group_name';
                $result = $db->sql_query($sql);
                $old_allow_group = $old_allow_pm = 1;
                while ($row = $db->sql_fetchrow($result)) {
                    $s_add_spacer = $old_allow_group != $row['allow_group'] || $old_allow_pm != $row['allow_in_pm'] ? true : false;
                    $template->assign_block_vars('groups', array('S_ADD_SPACER' => $s_add_spacer, 'S_ALLOWED_IN_PM' => $row['allow_in_pm'] ? true : false, 'S_GROUP_ALLOWED' => $row['allow_group'] ? true : false, 'U_EDIT' => $this->u_action . "&amp;action=edit&amp;g={$row['group_id']}", 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;g={$row['group_id']}", 'GROUP_NAME' => $row['group_name'], 'CATEGORY' => $cat_lang[$row['cat_id']]));
                    $old_allow_group = $row['allow_group'];
                    $old_allow_pm = $row['allow_in_pm'];
                }
                $db->sql_freeresult($result);
                break;
            case 'orphan':
                if ($submit) {
                    $delete_files = isset($_POST['delete']) ? array_keys(request_var('delete', array('' => 0))) : array();
                    $add_files = isset($_POST['add']) ? array_keys(request_var('add', array('' => 0))) : array();
                    $post_ids = request_var('post_id', array('' => 0));
                    if (sizeof($delete_files)) {
                        $sql = 'SELECT *
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
								AND is_orphan = 1';
                        $result = $db->sql_query($sql);
                        $delete_files = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            phpbb_unlink($row['physical_filename'], 'file');
                            if ($row['thumbnail']) {
                                phpbb_unlink($row['physical_filename'], 'thumbnail');
                            }
                            $delete_files[$row['attach_id']] = $row['real_filename'];
                        }
                        $db->sql_freeresult($result);
                    }
                    if (sizeof($delete_files)) {
                        $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', array_keys($delete_files));
                        $db->sql_query($sql);
                        add_log('admin', 'LOG_ATTACH_ORPHAN_DEL', implode(', ', $delete_files));
                        $notify[] = sprintf($user->lang['LOG_ATTACH_ORPHAN_DEL'], implode(', ', $delete_files));
                    }
                    $upload_list = array();
                    foreach ($add_files as $attach_id) {
                        if (!isset($delete_files[$attach_id]) && !empty($post_ids[$attach_id])) {
                            $upload_list[$attach_id] = $post_ids[$attach_id];
                        }
                    }
                    unset($add_files);
                    if (sizeof($upload_list)) {
                        $template->assign_var('S_UPLOADING_FILES', true);
                        $sql = 'SELECT forum_id, forum_name
							FROM ' . FORUMS_TABLE;
                        $result = $db->sql_query($sql);
                        $forum_names = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $forum_names[$row['forum_id']] = $row['forum_name'];
                        }
                        $db->sql_freeresult($result);
                        $sql = 'SELECT forum_id, topic_id, post_id, poster_id
							FROM ' . POSTS_TABLE . '
							WHERE ' . $db->sql_in_set('post_id', $upload_list);
                        $result = $db->sql_query($sql);
                        $post_info = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $post_info[$row['post_id']] = $row;
                        }
                        $db->sql_freeresult($result);
                        // Select those attachments we want to change...
                        $sql = 'SELECT *
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', array_keys($upload_list)) . '
								AND is_orphan = 1';
                        $result = $db->sql_query($sql);
                        $files_added = $space_taken = 0;
                        while ($row = $db->sql_fetchrow($result)) {
                            $post_row = $post_info[$upload_list[$row['attach_id']]];
                            $template->assign_block_vars('upload', array('FILE_INFO' => sprintf($user->lang['UPLOADING_FILE_TO'], $row['real_filename'], $post_row['post_id']), 'S_DENIED' => !$auth->acl_get('f_attach', $post_row['forum_id']) ? true : false, 'L_DENIED' => !$auth->acl_get('f_attach', $post_row['forum_id']) ? sprintf($user->lang['UPLOAD_DENIED_FORUM'], $forum_names[$row['forum_id']]) : ''));
                            if (!$auth->acl_get('f_attach', $post_row['forum_id'])) {
                                continue;
                            }
                            // Adjust attachment entry
                            $sql_ary = array('in_message' => 0, 'is_orphan' => 0, 'poster_id' => $post_row['poster_id'], 'post_msg_id' => $post_row['post_id'], 'topic_id' => $post_row['topic_id']);
                            $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE attach_id = ' . $row['attach_id'];
                            $db->sql_query($sql);
                            $sql = 'UPDATE ' . POSTS_TABLE . '
								SET post_attachment = 1
								WHERE post_id = ' . $post_row['post_id'];
                            $db->sql_query($sql);
                            $sql = 'UPDATE ' . TOPICS_TABLE . '
								SET topic_attachment = 1
								WHERE topic_id = ' . $post_row['topic_id'];
                            $db->sql_query($sql);
                            $space_taken += $row['filesize'];
                            $files_added++;
                            add_log('admin', 'LOG_ATTACH_FILEUPLOAD', $post_row['post_id'], $row['real_filename']);
                        }
                        $db->sql_freeresult($result);
                        if ($files_added) {
                            set_config('upload_dir_size', $config['upload_dir_size'] + $space_taken, true);
                            set_config('num_files', $config['num_files'] + $files_added, true);
                        }
                    }
                }
                $template->assign_vars(array('S_ORPHAN' => true));
                // Just get the files with is_orphan set and older than 3 hours
                $sql = 'SELECT *
					FROM ' . ATTACHMENTS_TABLE . '
					WHERE is_orphan = 1
						AND filetime < ' . (time() - 3 * 60 * 60) . '
					ORDER BY filetime DESC';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('orphan', array('FILESIZE' => get_formatted_filesize($row['filesize']), 'FILETIME' => $user->format_date($row['filetime']), 'REAL_FILENAME' => basename($row['real_filename']), 'PHYSICAL_FILENAME' => basename($row['physical_filename']), 'ATTACH_ID' => $row['attach_id'], 'POST_IDS' => !empty($post_ids[$row['attach_id']]) ? $post_ids[$row['attach_id']] : '', 'U_FILE' => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id'])));
                }
                $db->sql_freeresult($result);
                break;
        }
        if (sizeof($error)) {
            $template->assign_vars(array('S_WARNING' => true, 'WARNING_MSG' => implode('<br />', $error)));
        }
        if (sizeof($notify)) {
            $template->assign_vars(array('S_NOTIFY' => true, 'NOTIFY_MSG' => implode('<br />', $notify)));
        }
    }
Ejemplo n.º 3
0
function create_thumbnail($source, $new_file, $mimetype)
{
    global $attach_config, $imagick;
    $source = amod_realpath($source);
    $min_filesize = intval($attach_config['img_min_thumb_filesize']);
    $img_filesize = @file_exists(@amod_realpath($source)) ? filesize($source) : false;
    if (!$img_filesize || $img_filesize <= $min_filesize) {
        return FALSE;
    }
    $size = image_getdimension($source);
    if ($size[0] == 0 && $size[1] == 0) {
        return FALSE;
    }
    $new_size = get_img_size_format($size[0], $size[1]);
    $tmp_path = '';
    $old_file = '';
    if (intval($attach_config['allow_ftp_upload'])) {
        $old_file = $new_file;
        $tmp_path = explode('/', $source);
        $tmp_path[count($tmp_path) - 1] = '';
        $tmp_path = implode('/', $tmp_path);
        if ($tmp_path == '') {
            $tmp_path = '/tmp';
        }
        $value = trim($tmp_path);
        if ($value[strlen($value) - 1] == '/') {
            $value[strlen($value) - 1] = ' ';
        }
        $new_file = trim($value) . '/t00000';
    }
    $used_imagick = FALSE;
    if (is_imagick()) {
        if (is_array($size) && count($size) > 0) {
            passthru($imagick . ' -quality 85 -antialias -sample ' . $new_size[0] . 'x' . $new_size[1] . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $new_file) . '"');
            if (@file_exists(@amod_realpath($new_file))) {
                $used_imagick = TRUE;
            }
        }
    }
    if (!$used_imagick) {
        $type = $size[2];
        $supported_types = get_supported_image_types();
        if (in_array($type, $supported_types)) {
            switch ($type) {
                case '1':
                    $im = imagecreatefromgif($source);
                    $new_im = imagecreate($new_size[0], $new_size[1]);
                    imagecopyresized($new_im, $im, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
                    imagegif($new_im, $new_file);
                    break;
                case '2':
                    $im = imagecreatefromjpeg($source);
                    $new_im = intval($attach_config['use_gd2']) ? @imagecreatetruecolor($new_size[0], $new_size[1]) : imagecreate($new_size[0], $new_size[1]);
                    imagecopyresized($new_im, $im, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
                    imagejpeg($new_im, $new_file, 90);
                    break;
                case '3':
                    $im = imagecreatefrompng($source);
                    $new_im = intval($attach_config['use_gd2']) ? @imagecreatetruecolor($new_size[0], $new_size[1]) : imagecreate($new_size[0], $new_size[1]);
                    imagecopyresized($new_im, $im, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
                    imagepng($new_im, $new_file);
                    break;
            }
        }
    }
    if (!@file_exists(@amod_realpath($new_file))) {
        return FALSE;
    }
    if (intval($attach_config['allow_ftp_upload'])) {
        $result = ftp_file($new_file, $old_file, $this->type, TRUE);
        // True for disable error-mode
        if (!$result) {
            return FALSE;
        }
    } else {
        @chmod($new_file, 0664);
    }
    return TRUE;
}
Ejemplo n.º 4
0
/**
* Create thumbnail
*/
function create_thumbnail($source, $new_file, $mimetype)
{
    global $attach_config, $imagick;
    $source = amod_realpath($source);
    $min_filesize = (int) $attach_config['img_min_thumb_filesize'];
    $img_filesize = @file_exists($source) ? @filesize($source) : false;
    if (!$img_filesize || $img_filesize <= $min_filesize) {
        return false;
    }
    list($width, $height, $type, ) = getimagesize($source);
    if (!$width || !$height) {
        return false;
    }
    list($new_width, $new_height) = get_img_size_format($width, $height);
    $tmp_path = $old_file = '';
    if (intval($attach_config['allow_ftp_upload'])) {
        $old_file = $new_file;
        $tmp_path = explode('/', $source);
        $tmp_path[count($tmp_path) - 1] = '';
        $tmp_path = implode('/', $tmp_path);
        if ($tmp_path == '') {
            $tmp_path = '/tmp';
        }
        $value = trim($tmp_path);
        if ($value[strlen($value) - 1] == '/') {
            $value[strlen($value) - 1] = ' ';
        }
        //
        $new_file = tempnam(trim($value), 't00000');
        // We remove it now because it gets created again later
        @unlink($new_file);
    }
    $used_imagick = false;
    if (is_imagick()) {
        passthru($imagick . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $new_file) . '"');
        if (@file_exists($new_file)) {
            $used_imagick = true;
        }
    }
    if (!$used_imagick) {
        $type = get_supported_image_types($type);
        if ($type['gd']) {
            switch ($type['format']) {
                case IMG_GIF:
                    $image = imagecreatefromgif($source);
                    break;
                case IMG_JPG:
                    $image = imagecreatefromjpeg($source);
                    break;
                case IMG_PNG:
                    $image = imagecreatefrompng($source);
                    break;
                case IMG_WBMP:
                    $image = imagecreatefromwbmp($source);
                    break;
            }
            if ($type['version'] == 1 || !$attach_config['use_gd2']) {
                $new_image = imagecreate($new_width, $new_height);
                imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            } else {
                $new_image = imagecreatetruecolor($new_width, $new_height);
                imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            }
            switch ($type['format']) {
                case IMG_GIF:
                    imagegif($new_image, $new_file);
                    break;
                case IMG_JPG:
                    imagejpeg($new_image, $new_file, 90);
                    break;
                case IMG_PNG:
                    imagepng($new_image, $new_file);
                    break;
                case IMG_WBMP:
                    imagewbmp($new_image, $new_file);
                    break;
            }
            imagedestroy($new_image);
        }
    }
    if (!@file_exists($new_file)) {
        return false;
    }
    if (intval($attach_config['allow_ftp_upload'])) {
        $result = ftp_file($new_file, $old_file, $mimetype, true);
        // True for disable error-mode
        @unlink($new_file);
        if (!$result) {
            return false;
        }
    } else {
        @chmod($new_file, 0664);
    }
    return true;
}
function create_thumbnail($source, $destination, $mimetype)
{
    global $config;
    $min_filesize = (int) $config['img_min_thumb_filesize'];
    $img_filesize = file_exists($source) ? @filesize($source) : false;
    if (!$img_filesize || $img_filesize <= $min_filesize) {
        return false;
    }
    list($width, $height, $type, ) = getimagesize($source);
    if (!$width || !$height) {
        return false;
    }
    list($new_width, $new_height) = get_img_size_format($width, $height);
    if ($width < $new_width && $height < $new_height) {
        return false;
    }
    $used_imagick = false;
    if (file_exists($destination)) {
        passthru($config['img_imagick'] . 'convert' . (defined('PHP_OS') && preg_match('#win#i', PHP_OS) ? '.exe' : '') . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $destination) . '"');
        if (file_exists($new_file)) {
            $used_imagick = true;
        }
    }
    if (!$used_imagick) {
        $type = get_supported_image_types($type);
        if ($type['gd']) {
            switch ($type['format']) {
                case IMG_GIF:
                    $image = imagecreatefromgif($source);
                    break;
                case IMG_JPG:
                    $image = imagecreatefromjpeg($source);
                    break;
                case IMG_PNG:
                    $image = imagecreatefrompng($source);
                    break;
                case IMG_WBMP:
                    $image = imagecreatefromwbmp($source);
                    break;
            }
            if ($type['version'] == 1) {
                $new_image = imagecreate($new_width, $new_height);
                imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            } else {
                $new_image = imagecreatetruecolor($new_width, $new_height);
                imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            }
            switch ($type['format']) {
                case IMG_GIF:
                    imagegif($new_image, $destination);
                    break;
                case IMG_JPG:
                    imagejpeg($new_image, $destination, 90);
                    break;
                case IMG_PNG:
                    imagepng($new_image, $destination);
                    break;
                case IMG_WBMP:
                    imagewbmp($new_image, $destination);
                    break;
            }
            imagedestroy($new_image);
        }
    }
    if (!file_exists($destination)) {
        return false;
    }
    @chmod($destination, 0666);
    return true;
}
Ejemplo n.º 6
0
/**
* Create thumbnail
*/
function create_thumbnail($source, $new_file, $mimetype)
{
    global $attach_config, $imagick;
    $source = amod_realpath($source);
    $min_filesize = (int) $attach_config['img_min_thumb_filesize'];
    $img_filesize = @file_exists($source) ? @filesize($source) : false;
    if (!$img_filesize || $img_filesize <= $min_filesize) {
        return false;
    }
    list($width, $height, $type, ) = getimagesize($source);
    if (!$width || !$height) {
        return false;
    }
    list($new_width, $new_height) = get_img_size_format($width, $height);
    $tmp_path = $old_file = '';
    $used_imagick = false;
    if (is_imagick()) {
        passthru($imagick . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $new_file) . '"');
        if (@file_exists($new_file)) {
            $used_imagick = true;
        }
    }
    if (!$used_imagick) {
        $type = get_supported_image_types($type);
        if ($type['gd']) {
            switch ($type['format']) {
                case IMG_GIF:
                    $image = imagecreatefromgif($source);
                    break;
                case IMG_JPG:
                    $image = imagecreatefromjpeg($source);
                    break;
                case IMG_PNG:
                    $image = imagecreatefrompng($source);
                    break;
                case IMG_WBMP:
                    $image = imagecreatefromwbmp($source);
                    break;
            }
            if ($type['version'] == 1 || !$attach_config['use_gd2']) {
                $new_image = imagecreate($new_width, $new_height);
                imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            } else {
                $new_image = imagecreatetruecolor($new_width, $new_height);
                imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
            }
            switch ($type['format']) {
                case IMG_GIF:
                    imagegif($new_image, $new_file);
                    break;
                case IMG_JPG:
                    imagejpeg($new_image, $new_file, 90);
                    break;
                case IMG_PNG:
                    imagepng($new_image, $new_file);
                    break;
                case IMG_WBMP:
                    imagewbmp($new_image, $new_file);
                    break;
            }
            imagedestroy($new_image);
        }
    }
    if (!@file_exists($new_file)) {
        return false;
    }
    @chmod($new_file, 0664);
    return true;
}
	<tr>
		<td class="row1"><b><?php echo $_CLASS['core_user']->lang['SECURE_EMPTY_REFERER']; ?>: </b><br /><span class="gensmall"><?php echo $_CLASS['core_user']->lang['SECURE_EMPTY_REFERER_EXPLAIN']; ?></span></td>
		<td class="row2"><input type="radio" name="secure_allow_empty_referer" value="1" <?php echo $secure_allow_empty_referer_yes ?> /> <?php echo $_CLASS['core_user']->lang['YES']; ?>&nbsp;&nbsp;<input type="radio" name="secure_allow_empty_referer" value="0" <?php echo $secure_allow_empty_referer_no ?> /> <?php echo $_CLASS['core_user']->lang['NO']; ?></td>
	</tr>
	<tr>
	  <th align="center" colspan="2"><?php echo $_CLASS['core_user']->lang['SETTINGS_CAT_IMAGES']; ?></th>
	</tr>
	<tr>
		<td class="row3" colspan="2" align="center"><?php echo $_CLASS['core_user']->lang['ASSIGNED_GROUP']; ?>: <?php echo ((sizeof($s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE])) ? implode(', ', $s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE]) : $_CLASS['core_user']->lang['NONE']); ?></td>
	</tr>
	<tr>
		<td class="row1"><b><?php echo $_CLASS['core_user']->lang['DISPLAY_INLINED']; ?>: </b><br /><span class="gensmall"><?php echo $_CLASS['core_user']->lang['DISPLAY_INLINED_EXPLAIN']; ?></span></td>
		<td class="row2"><input type="radio" name="img_display_inlined" value="1" <?php echo $display_inlined_yes ?> /> <?php echo $_CLASS['core_user']->lang['YES']; ?>&nbsp;&nbsp;<input type="radio" name="img_display_inlined" value="0" <?php echo $display_inlined_no ?> /> <?php echo $_CLASS['core_user']->lang['NO']; ?></td>
	</tr>
<?php
	$supported_types = get_supported_image_types();
	
	// Check Thumbnail Support
	if (!$new['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format'])))
	{
		$new['img_create_thumbnail'] = '0';
	}
	else
	{

?>
	<tr>
		<td class="row1"><b><?php echo $_CLASS['core_user']->lang['CREATE_THUMBNAIL']; ?>: </b><br /><span class="gensmall"><?php echo $_CLASS['core_user']->lang['CREATE_THUMBNAIL_EXPLAIN']; ?></span></td>
		<td class="row2"><input type="radio" name="img_create_thumbnail" value="1" <?php echo $create_thumbnail_yes; ?> /> <?php echo $_CLASS['core_user']->lang['YES']; ?>&nbsp;&nbsp;<input type="radio" name="img_create_thumbnail" value="0" <?php echo $create_thumbnail_no; ?> /> <?php echo $_CLASS['core_user']->lang['NO']; ?></td>
	</tr>
	<tr>
Ejemplo n.º 8
0
    function main($id, $mode)
    {
        global $db, $user, $auth, $template, $cache, $phpbb_container, $phpbb_filesystem, $phpbb_dispatcher;
        global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx, $phpbb_log, $request;
        $this->id = $id;
        $this->db = $db;
        $this->config = $config;
        $this->template = $template;
        $this->user = $user;
        $this->phpbb_container = $phpbb_container;
        $this->filesystem = $phpbb_filesystem;
        $this->attachment_manager = $phpbb_container->get('attachment.manager');
        $user->add_lang(array('posting', 'viewtopic', 'acp/attachments'));
        $error = $notify = array();
        $submit = isset($_POST['submit']) ? true : false;
        $action = $request->variable('action', '');
        $form_key = 'acp_attach';
        add_form_key($form_key);
        if ($submit && !check_form_key($form_key)) {
            trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
        }
        switch ($mode) {
            case 'attach':
                $l_title = 'ACP_ATTACHMENT_SETTINGS';
                break;
            case 'extensions':
                $l_title = 'ACP_MANAGE_EXTENSIONS';
                break;
            case 'ext_groups':
                $l_title = 'ACP_EXTENSION_GROUPS';
                break;
            case 'orphan':
                $l_title = 'ACP_ORPHAN_ATTACHMENTS';
                break;
            case 'manage':
                $l_title = 'ACP_MANAGE_ATTACHMENTS';
                break;
            default:
                trigger_error('NO_MODE', E_USER_ERROR);
                break;
        }
        $this->tpl_name = 'acp_attachments';
        $this->page_title = $l_title;
        $template->assign_vars(array('L_TITLE' => $user->lang[$l_title], 'L_TITLE_EXPLAIN' => $user->lang[$l_title . '_EXPLAIN'], 'U_ACTION' => $this->u_action));
        switch ($mode) {
            case 'attach':
                if (!function_exists('get_supported_image_types')) {
                    include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
                }
                $sql = 'SELECT group_name, cat_id
					FROM ' . EXTENSION_GROUPS_TABLE . '
					WHERE cat_id > 0
					ORDER BY cat_id';
                $result = $db->sql_query($sql);
                $s_assigned_groups = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $row['group_name'] = isset($user->lang['EXT_GROUP_' . $row['group_name']]) ? $user->lang['EXT_GROUP_' . $row['group_name']] : $row['group_name'];
                    $s_assigned_groups[$row['cat_id']][] = $row['group_name'];
                }
                $db->sql_freeresult($result);
                $l_legend_cat_images = $user->lang['SETTINGS_CAT_IMAGES'] . ' [' . $user->lang['ASSIGNED_GROUP'] . ': ' . (!empty($s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE]) ? implode($user->lang['COMMA_SEPARATOR'], $s_assigned_groups[ATTACHMENT_CATEGORY_IMAGE]) : $user->lang['NO_EXT_GROUP']) . ']';
                $display_vars = array('title' => 'ACP_ATTACHMENT_SETTINGS', 'vars' => array('legend1' => 'ACP_ATTACHMENT_SETTINGS', 'img_max_width' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'img_max_height' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'img_link_width' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'img_link_height' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false), 'allow_attachments' => array('lang' => 'ALLOW_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'allow_pm_attach' => array('lang' => 'ALLOW_PM_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'upload_path' => array('lang' => 'UPLOAD_DIR', 'validate' => 'wpath', 'type' => 'text:25:100', 'explain' => true), 'display_order' => array('lang' => 'DISPLAY_ORDER', 'validate' => 'bool', 'type' => 'custom', 'method' => 'display_order', 'explain' => true), 'attachment_quota' => array('lang' => 'ATTACH_QUOTA', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_filesize' => array('lang' => 'ATTACH_MAX_FILESIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_filesize_pm' => array('lang' => 'ATTACH_MAX_PM_FILESIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_attachments' => array('lang' => 'MAX_ATTACHMENTS', 'validate' => 'int:0:999', 'type' => 'number:0:999', 'explain' => false), 'max_attachments_pm' => array('lang' => 'MAX_ATTACHMENTS_PM', 'validate' => 'int:0:999', 'type' => 'number:0:999', 'explain' => false), 'secure_downloads' => array('lang' => 'SECURE_DOWNLOADS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true), 'secure_allow_empty_referer' => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'check_attachment_content' => array('lang' => 'CHECK_CONTENT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'legend2' => $l_legend_cat_images, 'img_display_inlined' => array('lang' => 'DISPLAY_INLINED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'img_create_thumbnail' => array('lang' => 'CREATE_THUMBNAIL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'img_max_thumb_width' => array('lang' => 'MAX_THUMB_WIDTH', 'validate' => 'int:0:999999999999999', 'type' => 'number:0:999999999999999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']), 'img_min_thumb_filesize' => array('lang' => 'MIN_THUMB_FILESIZE', 'validate' => 'int:0:999999999999999', 'type' => 'number:0:999999999999999', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']), 'img_imagick' => array('lang' => 'IMAGICK_PATH', 'validate' => 'absolute_path', 'type' => 'text:20:200', 'explain' => true, 'append' => '&nbsp;&nbsp;<span>[ <a href="' . $this->u_action . '&amp;action=imgmagick">' . $user->lang['SEARCH_IMAGICK'] . '</a> ]</span>'), 'img_max' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0:9999', 'type' => 'dimension:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']), 'img_link' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0:9999', 'type' => 'dimension:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL'])));
                /**
                 * Event to add and/or modify acp_attachement configurations
                 *
                 * @event core.acp_attachments_config_edit_add
                 * @var	array	display_vars	Array of config values to display and process
                 * @var	string	mode			Mode of the config page we are displaying
                 * @var	boolean	submit			Do we display the form or process the submission
                 * @since 3.1.11-RC1
                 */
                $vars = array('display_vars', 'mode', 'submit');
                extract($phpbb_dispatcher->trigger_event('core.acp_attachments_config_edit_add', compact($vars)));
                $this->new_config = $config;
                $cfg_array = isset($_REQUEST['config']) ? $request->variable('config', array('' => '')) : $this->new_config;
                $error = array();
                // We validate the complete config if whished
                validate_config_vars($display_vars['vars'], $cfg_array, $error);
                // Do not write values if there is an error
                if (sizeof($error)) {
                    $submit = false;
                }
                // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
                foreach ($display_vars['vars'] as $config_name => $null) {
                    if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) {
                        continue;
                    }
                    $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
                    if (in_array($config_name, array('attachment_quota', 'max_filesize', 'max_filesize_pm'))) {
                        $size_var = $request->variable($config_name, '');
                        $this->new_config[$config_name] = $config_value = $size_var == 'kb' ? round($config_value * 1024) : ($size_var == 'mb' ? round($config_value * 1048576) : $config_value);
                    }
                    if ($submit) {
                        $config->set($config_name, $config_value);
                    }
                }
                $this->perform_site_list();
                if ($submit) {
                    $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CONFIG_ATTACH');
                    // Check Settings
                    $this->test_upload($error, $this->new_config['upload_path'], false);
                    if (!sizeof($error)) {
                        trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
                    }
                }
                $template->assign_var('S_ATTACHMENT_SETTINGS', true);
                if ($action == 'imgmagick') {
                    $this->new_config['img_imagick'] = $this->search_imagemagick();
                }
                // We strip eventually manual added convert program, we only want the patch
                if ($this->new_config['img_imagick']) {
                    // Change path separator
                    $this->new_config['img_imagick'] = str_replace('\\', '/', $this->new_config['img_imagick']);
                    $this->new_config['img_imagick'] = str_replace(array('convert', '.exe'), array('', ''), $this->new_config['img_imagick']);
                    // Check for trailing slash
                    if (substr($this->new_config['img_imagick'], -1) !== '/') {
                        $this->new_config['img_imagick'] .= '/';
                    }
                }
                $supported_types = get_supported_image_types();
                // Check Thumbnail Support
                if (!$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format']))) {
                    $this->new_config['img_create_thumbnail'] = 0;
                }
                $template->assign_vars(array('U_SEARCH_IMAGICK' => $this->u_action . '&amp;action=imgmagick', 'S_THUMBNAIL_SUPPORT' => !$this->new_config['img_imagick'] && (!isset($supported_types['format']) || !sizeof($supported_types['format'])) ? false : true));
                // Secure Download Options - Same procedure as with banning
                $allow_deny = $this->new_config['secure_allow_deny'] ? 'ALLOWED' : 'DISALLOWED';
                $sql = 'SELECT *
					FROM ' . SITELIST_TABLE;
                $result = $db->sql_query($sql);
                $defined_ips = '';
                $ips = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $value = $row['site_ip'] ? $row['site_ip'] : $row['site_hostname'];
                    if ($value) {
                        $defined_ips .= '<option' . ($row['ip_exclude'] ? ' class="sep"' : '') . ' value="' . $row['site_id'] . '">' . $value . '</option>';
                        $ips[$row['site_id']] = $value;
                    }
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_SECURE_DOWNLOADS' => $this->new_config['secure_downloads'], 'S_DEFINED_IPS' => $defined_ips != '' ? true : false, 'S_WARNING' => sizeof($error) ? true : false, 'WARNING_MSG' => implode('<br />', $error), 'DEFINED_IPS' => $defined_ips, 'L_SECURE_TITLE' => $user->lang['DEFINE_' . $allow_deny . '_IPS'], 'L_IP_EXCLUDE' => $user->lang['EXCLUDE_FROM_' . $allow_deny . '_IP'], 'L_REMOVE_IPS' => $user->lang['REMOVE_' . $allow_deny . '_IPS']));
                // Output relevant options
                foreach ($display_vars['vars'] as $config_key => $vars) {
                    if (!is_array($vars) && strpos($config_key, 'legend') === false) {
                        continue;
                    }
                    if (strpos($config_key, 'legend') !== false) {
                        $template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => isset($user->lang[$vars]) ? $user->lang[$vars] : $vars));
                        continue;
                    }
                    $type = explode(':', $vars['type']);
                    $l_explain = '';
                    if ($vars['explain'] && isset($vars['lang_explain'])) {
                        $l_explain = isset($user->lang[$vars['lang_explain']]) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
                    } else {
                        if ($vars['explain']) {
                            $l_explain = isset($user->lang[$vars['lang'] . '_EXPLAIN']) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
                        }
                    }
                    $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars);
                    if (empty($content)) {
                        continue;
                    }
                    $template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => $user->lang[$vars['lang']], 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $l_explain, 'CONTENT' => $content));
                    unset($display_vars['vars'][$config_key]);
                }
                break;
            case 'extensions':
                if ($submit || isset($_POST['add_extension_check'])) {
                    if ($submit) {
                        // Change Extensions ?
                        $extension_change_list = $request->variable('extension_change_list', array(0));
                        $group_select_list = $request->variable('group_select', array(0));
                        // Generate correct Change List
                        $extensions = array();
                        for ($i = 0, $size = sizeof($extension_change_list); $i < $size; $i++) {
                            $extensions[$extension_change_list[$i]]['group_id'] = $group_select_list[$i];
                        }
                        $sql = 'SELECT *
							FROM ' . EXTENSIONS_TABLE . '
							ORDER BY extension_id';
                        $result = $db->sql_query($sql);
                        while ($row = $db->sql_fetchrow($result)) {
                            if ($row['group_id'] != $extensions[$row['extension_id']]['group_id']) {
                                $sql = 'UPDATE ' . EXTENSIONS_TABLE . '
									SET group_id = ' . (int) $extensions[$row['extension_id']]['group_id'] . '
									WHERE extension_id = ' . $row['extension_id'];
                                $db->sql_query($sql);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_EXT_UPDATE', false, array($row['extension']));
                            }
                        }
                        $db->sql_freeresult($result);
                        // Delete Extension?
                        $extension_id_list = $request->variable('extension_id_list', array(0));
                        if (sizeof($extension_id_list)) {
                            $sql = 'SELECT extension
								FROM ' . EXTENSIONS_TABLE . '
								WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
                            $result = $db->sql_query($sql);
                            $extension_list = '';
                            while ($row = $db->sql_fetchrow($result)) {
                                $extension_list .= $extension_list == '' ? $row['extension'] : ', ' . $row['extension'];
                            }
                            $db->sql_freeresult($result);
                            $sql = 'DELETE
								FROM ' . EXTENSIONS_TABLE . '
								WHERE ' . $db->sql_in_set('extension_id', $extension_id_list);
                            $db->sql_query($sql);
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_EXT_DEL', false, array($extension_list));
                        }
                    }
                    // Add Extension?
                    $add_extension = strtolower($request->variable('add_extension', ''));
                    $add_extension_group = $request->variable('add_group_select', 0);
                    $add = isset($_POST['add_extension_check']) ? true : false;
                    if ($add_extension && $add) {
                        if (!sizeof($error)) {
                            $sql = 'SELECT extension_id
								FROM ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE extension = '" . $db->sql_escape($add_extension) . "'";
                            $result = $db->sql_query($sql);
                            if ($row = $db->sql_fetchrow($result)) {
                                $error[] = sprintf($user->lang['EXTENSION_EXIST'], $add_extension);
                            }
                            $db->sql_freeresult($result);
                            if (!sizeof($error)) {
                                $sql_ary = array('group_id' => $add_extension_group, 'extension' => $add_extension);
                                $db->sql_query('INSERT INTO ' . EXTENSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_EXT_ADD', false, array($add_extension));
                            }
                        }
                    }
                    if (!sizeof($error)) {
                        $notify[] = $user->lang['EXTENSIONS_UPDATED'];
                    }
                    $cache->destroy('_extensions');
                }
                $template->assign_vars(array('S_EXTENSIONS' => true, 'ADD_EXTENSION' => isset($add_extension) ? $add_extension : '', 'GROUP_SELECT_OPTIONS' => isset($_POST['add_extension_check']) ? $this->group_select('add_group_select', $add_extension_group, 'extension_group') : $this->group_select('add_group_select', false, 'extension_group')));
                $sql = 'SELECT *
					FROM ' . EXTENSIONS_TABLE . '
					ORDER BY group_id, extension';
                $result = $db->sql_query($sql);
                if ($row = $db->sql_fetchrow($result)) {
                    $old_group_id = $row['group_id'];
                    do {
                        $s_spacer = false;
                        $current_group_id = $row['group_id'];
                        if ($old_group_id != $current_group_id) {
                            $s_spacer = true;
                            $old_group_id = $current_group_id;
                        }
                        $template->assign_block_vars('extensions', array('S_SPACER' => $s_spacer, 'EXTENSION_ID' => $row['extension_id'], 'EXTENSION' => $row['extension'], 'GROUP_OPTIONS' => $this->group_select('group_select[]', $row['group_id'])));
                    } while ($row = $db->sql_fetchrow($result));
                }
                $db->sql_freeresult($result);
                break;
            case 'ext_groups':
                $template->assign_var('S_EXTENSION_GROUPS', true);
                if ($submit) {
                    $action = $request->variable('action', '');
                    $group_id = $request->variable('g', 0);
                    if ($action != 'add' && $action != 'edit') {
                        trigger_error('NO_MODE', E_USER_ERROR);
                    }
                    if (!$group_id && $action == 'edit') {
                        trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
                    }
                    if ($group_id) {
                        $sql = 'SELECT *
							FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}";
                        $result = $db->sql_query($sql);
                        $ext_row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        if (!$ext_row) {
                            trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                    } else {
                        $ext_row = array();
                    }
                    $group_name = $request->variable('group_name', '', true);
                    $new_group_name = $action == 'add' ? $group_name : ($ext_row['group_name'] != $group_name ? $group_name : '');
                    if (!$group_name) {
                        $error[] = $user->lang['NO_EXT_GROUP_NAME'];
                    }
                    // Check New Group Name
                    if ($new_group_name) {
                        $sql = 'SELECT group_id
							FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\tWHERE LOWER(group_name) = '" . $db->sql_escape(utf8_strtolower($new_group_name)) . "'";
                        if ($group_id) {
                            $sql .= ' AND group_id <> ' . $group_id;
                        }
                        $result = $db->sql_query($sql);
                        if ($db->sql_fetchrow($result)) {
                            $error[] = sprintf($user->lang['EXTENSION_GROUP_EXIST'], $new_group_name);
                        }
                        $db->sql_freeresult($result);
                    }
                    if (!sizeof($error)) {
                        // Ok, build the update/insert array
                        $upload_icon = $request->variable('upload_icon', 'no_image');
                        $size_select = $request->variable('size_select', 'b');
                        $forum_select = $request->variable('forum_select', false);
                        $allowed_forums = $request->variable('allowed_forums', array(0));
                        $allow_in_pm = isset($_POST['allow_in_pm']) ? true : false;
                        $max_filesize = $request->variable('max_filesize', 0);
                        $max_filesize = $size_select == 'kb' ? round($max_filesize * 1024) : ($size_select == 'mb' ? round($max_filesize * 1048576) : $max_filesize);
                        $allow_group = isset($_POST['allow_group']) ? true : false;
                        if ($max_filesize == $config['max_filesize']) {
                            $max_filesize = 0;
                        }
                        if (!sizeof($allowed_forums)) {
                            $forum_select = false;
                        }
                        $group_ary = array('group_name' => $group_name, 'cat_id' => $request->variable('special_category', ATTACHMENT_CATEGORY_NONE), 'allow_group' => $allow_group ? 1 : 0, 'upload_icon' => $upload_icon == 'no_image' ? '' : $upload_icon, 'max_filesize' => $max_filesize, 'allowed_forums' => $forum_select ? serialize($allowed_forums) : '', 'allow_in_pm' => $allow_in_pm ? 1 : 0);
                        if ($action == 'add') {
                            $group_ary['download_mode'] = INLINE_LINK;
                        }
                        $sql = $action == 'add' ? 'INSERT INTO ' . EXTENSION_GROUPS_TABLE . ' ' : 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' SET ';
                        $sql .= $db->sql_build_array($action == 'add' ? 'INSERT' : 'UPDATE', $group_ary);
                        $sql .= $action == 'edit' ? " WHERE group_id = {$group_id}" : '';
                        $db->sql_query($sql);
                        if ($action == 'add') {
                            $group_id = $db->sql_nextid();
                        }
                        $group_name = isset($user->lang['EXT_GROUP_' . $group_name]) ? $user->lang['EXT_GROUP_' . $group_name] : $group_name;
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_EXTGROUP_' . strtoupper($action), false, array($group_name));
                    }
                    $extension_list = $request->variable('extensions', array(0));
                    if ($action == 'edit' && sizeof($extension_list)) {
                        $sql = 'UPDATE ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\tSET group_id = 0\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}";
                        $db->sql_query($sql);
                    }
                    if (sizeof($extension_list)) {
                        $sql = 'UPDATE ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\tSET group_id = {$group_id}\n\t\t\t\t\t\t\tWHERE " . $db->sql_in_set('extension_id', $extension_list);
                        $db->sql_query($sql);
                    }
                    $cache->destroy('_extensions');
                    if (!sizeof($error)) {
                        $notify[] = $user->lang['SUCCESS_EXTENSION_GROUP_' . strtoupper($action)];
                    }
                }
                $cat_lang = array(ATTACHMENT_CATEGORY_NONE => $user->lang['NO_FILE_CAT'], ATTACHMENT_CATEGORY_IMAGE => $user->lang['CAT_IMAGES'], ATTACHMENT_CATEGORY_FLASH => $user->lang['CAT_FLASH_FILES']);
                $group_id = $request->variable('g', 0);
                $action = isset($_POST['add']) ? 'add' : $action;
                switch ($action) {
                    case 'delete':
                        if (confirm_box(true)) {
                            $sql = 'SELECT group_name
								FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}";
                            $result = $db->sql_query($sql);
                            $group_name = (string) $db->sql_fetchfield('group_name');
                            $db->sql_freeresult($result);
                            $sql = 'DELETE
								FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}";
                            $db->sql_query($sql);
                            // Set corresponding Extensions to a pending Group
                            $sql = 'UPDATE ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\t\tSET group_id = 0\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}";
                            $db->sql_query($sql);
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_EXTGROUP_DEL', false, array($group_name));
                            $cache->destroy('_extensions');
                            trigger_error($user->lang['EXTENSION_GROUP_DELETED'] . adm_back_link($this->u_action));
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'group_id' => $group_id, 'action' => 'delete')));
                        }
                        break;
                    case 'edit':
                        if (!$group_id) {
                            trigger_error($user->lang['NO_EXT_GROUP_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        $sql = 'SELECT *
							FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}";
                        $result = $db->sql_query($sql);
                        $ext_group_row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        $forum_ids = !$ext_group_row['allowed_forums'] ? array() : unserialize(trim($ext_group_row['allowed_forums']));
                        // no break;
                    // no break;
                    case 'add':
                        if ($action == 'add') {
                            $ext_group_row = array('group_name' => $request->variable('group_name', '', true), 'cat_id' => 0, 'allow_group' => 1, 'allow_in_pm' => 1, 'upload_icon' => '', 'max_filesize' => 0);
                            $forum_ids = array();
                        }
                        $sql = 'SELECT *
							FROM ' . EXTENSIONS_TABLE . "\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\t\t\tOR group_id = 0\n\t\t\t\t\t\t\tORDER BY extension";
                        $result = $db->sql_query($sql);
                        $extensions = $db->sql_fetchrowset($result);
                        $db->sql_freeresult($result);
                        if ($ext_group_row['max_filesize'] == 0) {
                            $ext_group_row['max_filesize'] = (int) $config['max_filesize'];
                        }
                        $max_filesize = get_formatted_filesize($ext_group_row['max_filesize'], false, array('mb', 'kb', 'b'));
                        $size_format = $max_filesize['si_identifier'];
                        $ext_group_row['max_filesize'] = $max_filesize['value'];
                        $img_path = $config['upload_icons_path'];
                        $filename_list = '';
                        $no_image_select = false;
                        $imglist = filelist($phpbb_root_path . $img_path);
                        if (!empty($imglist[''])) {
                            $imglist = array_values($imglist);
                            $imglist = $imglist[0];
                            foreach ($imglist as $key => $img) {
                                if (!$ext_group_row['upload_icon']) {
                                    $no_image_select = true;
                                    $selected = '';
                                } else {
                                    $selected = $ext_group_row['upload_icon'] == $img ? ' selected="selected"' : '';
                                }
                                if (strlen($img) > 255) {
                                    continue;
                                }
                                $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . htmlspecialchars($img) . '</option>';
                            }
                        }
                        $i = 0;
                        $assigned_extensions = '';
                        foreach ($extensions as $num => $row) {
                            if ($row['group_id'] == $group_id && $group_id) {
                                $assigned_extensions .= $i ? ', ' . $row['extension'] : $row['extension'];
                                $i++;
                            }
                        }
                        $s_extension_options = '';
                        foreach ($extensions as $row) {
                            $s_extension_options .= '<option' . (!$row['group_id'] ? ' class="disabled"' : '') . ' value="' . $row['extension_id'] . '"' . ($row['group_id'] == $group_id && $group_id ? ' selected="selected"' : '') . '>' . $row['extension'] . '</option>';
                        }
                        $template->assign_vars(array('IMG_PATH' => $img_path, 'ACTION' => $action, 'GROUP_ID' => $group_id, 'GROUP_NAME' => $ext_group_row['group_name'], 'ALLOW_GROUP' => $ext_group_row['allow_group'], 'ALLOW_IN_PM' => $ext_group_row['allow_in_pm'], 'UPLOAD_ICON_SRC' => $phpbb_root_path . $img_path . '/' . $ext_group_row['upload_icon'], 'EXTGROUP_FILESIZE' => $ext_group_row['max_filesize'], 'ASSIGNED_EXTENSIONS' => $assigned_extensions, 'S_CATEGORY_SELECT' => $this->category_select('special_category', $group_id, 'category'), 'S_EXT_GROUP_SIZE_OPTIONS' => size_select_options($size_format), 'S_EXTENSION_OPTIONS' => $s_extension_options, 'S_FILENAME_LIST' => $filename_list, 'S_EDIT_GROUP' => true, 'S_NO_IMAGE' => $no_image_select, 'S_FORUM_IDS' => sizeof($forum_ids) ? true : false, 'U_EXTENSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$id}&amp;mode=extensions"), 'U_BACK' => $this->u_action, 'L_LEGEND' => $user->lang[strtoupper($action) . '_EXTENSION_GROUP']));
                        $s_forum_id_options = '';
                        /** @todo use in-built function **/
                        $sql = 'SELECT forum_id, forum_name, parent_id, forum_type, left_id, right_id
							FROM ' . FORUMS_TABLE . '
							ORDER BY left_id ASC';
                        $result = $db->sql_query($sql, 600);
                        $right = $cat_right = $padding_inc = 0;
                        $padding = $forum_list = $holding = '';
                        $padding_store = array('0' => '');
                        while ($row = $db->sql_fetchrow($result)) {
                            if ($row['forum_type'] == FORUM_CAT && $row['left_id'] + 1 == $row['right_id']) {
                                // Non-postable forum with no subforums, don't display
                                continue;
                            }
                            if (!$auth->acl_get('f_list', $row['forum_id'])) {
                                // if the user does not have permissions to list this forum skip
                                continue;
                            }
                            if ($row['left_id'] < $right) {
                                $padding .= '&nbsp; &nbsp;';
                                $padding_store[$row['parent_id']] = $padding;
                            } else {
                                if ($row['left_id'] > $right + 1) {
                                    $padding = empty($padding_store[$row['parent_id']]) ? '' : $padding_store[$row['parent_id']];
                                }
                            }
                            $right = $row['right_id'];
                            $selected = in_array($row['forum_id'], $forum_ids) ? ' selected="selected"' : '';
                            if ($row['left_id'] > $cat_right) {
                                // make sure we don't forget anything
                                $s_forum_id_options .= $holding;
                                $holding = '';
                            }
                            if ($row['right_id'] - $row['left_id'] > 1) {
                                $cat_right = max($cat_right, $row['right_id']);
                                $holding .= '<option value="' . $row['forum_id'] . '"' . ($row['forum_type'] == FORUM_POST ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
                            } else {
                                $s_forum_id_options .= $holding . '<option value="' . $row['forum_id'] . '"' . ($row['forum_type'] == FORUM_POST ? ' class="sep"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
                                $holding = '';
                            }
                        }
                        if ($holding) {
                            $s_forum_id_options .= $holding;
                        }
                        $db->sql_freeresult($result);
                        unset($padding_store);
                        $template->assign_vars(array('S_FORUM_ID_OPTIONS' => $s_forum_id_options));
                        break;
                }
                $sql = 'SELECT *
					FROM ' . EXTENSION_GROUPS_TABLE . '
					ORDER BY allow_group DESC, allow_in_pm DESC, group_name';
                $result = $db->sql_query($sql);
                $old_allow_group = $old_allow_pm = 1;
                while ($row = $db->sql_fetchrow($result)) {
                    $s_add_spacer = $old_allow_group != $row['allow_group'] || $old_allow_pm != $row['allow_in_pm'] ? true : false;
                    $template->assign_block_vars('groups', array('S_ADD_SPACER' => $s_add_spacer, 'S_ALLOWED_IN_PM' => $row['allow_in_pm'] ? true : false, 'S_GROUP_ALLOWED' => $row['allow_group'] ? true : false, 'U_EDIT' => $this->u_action . "&amp;action=edit&amp;g={$row['group_id']}", 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;g={$row['group_id']}", 'GROUP_NAME' => isset($user->lang['EXT_GROUP_' . $row['group_name']]) ? $user->lang['EXT_GROUP_' . $row['group_name']] : $row['group_name'], 'CATEGORY' => $cat_lang[$row['cat_id']]));
                    $old_allow_group = $row['allow_group'];
                    $old_allow_pm = $row['allow_in_pm'];
                }
                $db->sql_freeresult($result);
                break;
            case 'orphan':
                if ($submit) {
                    $delete_files = isset($_POST['delete']) ? array_keys($request->variable('delete', array('' => 0))) : array();
                    $add_files = isset($_POST['add']) ? array_keys($request->variable('add', array('' => 0))) : array();
                    $post_ids = $request->variable('post_id', array('' => 0));
                    if (sizeof($delete_files)) {
                        $sql = 'SELECT *
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
								AND is_orphan = 1';
                        $result = $db->sql_query($sql);
                        $delete_files = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $this->attachment_manager->unlink($row['physical_filename'], 'file');
                            if ($row['thumbnail']) {
                                $this->attachment_manager->unlink($row['physical_filename'], 'thumbnail');
                            }
                            $delete_files[$row['attach_id']] = $row['real_filename'];
                        }
                        $db->sql_freeresult($result);
                    }
                    if (sizeof($delete_files)) {
                        $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', array_keys($delete_files));
                        $db->sql_query($sql);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_ORPHAN_DEL', false, array(implode(', ', $delete_files)));
                        $notify[] = sprintf($user->lang['LOG_ATTACH_ORPHAN_DEL'], implode($user->lang['COMMA_SEPARATOR'], $delete_files));
                    }
                    $upload_list = array();
                    foreach ($add_files as $attach_id) {
                        if (!isset($delete_files[$attach_id]) && !empty($post_ids[$attach_id])) {
                            $upload_list[$attach_id] = $post_ids[$attach_id];
                        }
                    }
                    unset($add_files);
                    if (sizeof($upload_list)) {
                        $template->assign_var('S_UPLOADING_FILES', true);
                        $sql = 'SELECT forum_id, forum_name
							FROM ' . FORUMS_TABLE;
                        $result = $db->sql_query($sql);
                        $forum_names = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $forum_names[$row['forum_id']] = $row['forum_name'];
                        }
                        $db->sql_freeresult($result);
                        $sql = 'SELECT forum_id, topic_id, post_id, poster_id
							FROM ' . POSTS_TABLE . '
							WHERE ' . $db->sql_in_set('post_id', $upload_list);
                        $result = $db->sql_query($sql);
                        $post_info = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $post_info[$row['post_id']] = $row;
                        }
                        $db->sql_freeresult($result);
                        // Select those attachments we want to change...
                        $sql = 'SELECT *
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', array_keys($upload_list)) . '
								AND is_orphan = 1';
                        $result = $db->sql_query($sql);
                        $files_added = $space_taken = 0;
                        while ($row = $db->sql_fetchrow($result)) {
                            $post_row = $post_info[$upload_list[$row['attach_id']]];
                            $template->assign_block_vars('upload', array('FILE_INFO' => sprintf($user->lang['UPLOADING_FILE_TO'], $row['real_filename'], $post_row['post_id']), 'S_DENIED' => !$auth->acl_get('f_attach', $post_row['forum_id']) ? true : false, 'L_DENIED' => !$auth->acl_get('f_attach', $post_row['forum_id']) ? sprintf($user->lang['UPLOAD_DENIED_FORUM'], $forum_names[$row['forum_id']]) : ''));
                            if (!$auth->acl_get('f_attach', $post_row['forum_id'])) {
                                continue;
                            }
                            // Adjust attachment entry
                            $sql_ary = array('in_message' => 0, 'is_orphan' => 0, 'poster_id' => $post_row['poster_id'], 'post_msg_id' => $post_row['post_id'], 'topic_id' => $post_row['topic_id']);
                            $sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE attach_id = ' . $row['attach_id'];
                            $db->sql_query($sql);
                            $sql = 'UPDATE ' . POSTS_TABLE . '
								SET post_attachment = 1
								WHERE post_id = ' . $post_row['post_id'];
                            $db->sql_query($sql);
                            $sql = 'UPDATE ' . TOPICS_TABLE . '
								SET topic_attachment = 1
								WHERE topic_id = ' . $post_row['topic_id'];
                            $db->sql_query($sql);
                            $space_taken += $row['filesize'];
                            $files_added++;
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACH_FILEUPLOAD', false, array($post_row['post_id'], $row['real_filename']));
                        }
                        $db->sql_freeresult($result);
                        if ($files_added) {
                            $config->increment('upload_dir_size', $space_taken, false);
                            $config->increment('num_files', $files_added, false);
                        }
                    }
                }
                $template->assign_vars(array('S_ORPHAN' => true));
                // Just get the files with is_orphan set and older than 3 hours
                $sql = 'SELECT *
					FROM ' . ATTACHMENTS_TABLE . '
					WHERE is_orphan = 1
						AND filetime < ' . (time() - 3 * 60 * 60) . '
					ORDER BY filetime DESC';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('orphan', array('FILESIZE' => get_formatted_filesize($row['filesize']), 'FILETIME' => $user->format_date($row['filetime']), 'REAL_FILENAME' => utf8_basename($row['real_filename']), 'PHYSICAL_FILENAME' => utf8_basename($row['physical_filename']), 'ATTACH_ID' => $row['attach_id'], 'POST_IDS' => !empty($post_ids[$row['attach_id']]) ? $post_ids[$row['attach_id']] : '', 'U_FILE' => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id'])));
                }
                $db->sql_freeresult($result);
                break;
            case 'manage':
                if ($submit) {
                    $delete_files = isset($_POST['delete']) ? array_keys($request->variable('delete', array('' => 0))) : array();
                    if (sizeof($delete_files)) {
                        // Select those attachments we want to delete...
                        $sql = 'SELECT real_filename
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', $delete_files) . '
								AND is_orphan = 0';
                        $result = $db->sql_query($sql);
                        while ($row = $db->sql_fetchrow($result)) {
                            $deleted_filenames[] = $row['real_filename'];
                        }
                        $db->sql_freeresult($result);
                        if ($num_deleted = $this->attachment_manager->delete('attach', $delete_files)) {
                            if (sizeof($delete_files) != $num_deleted) {
                                $error[] = $user->lang['FILES_GONE'];
                            }
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACHMENTS_DELETED', false, array(implode(', ', $deleted_filenames)));
                            $notify[] = sprintf($user->lang['LOG_ATTACHMENTS_DELETED'], implode($user->lang['COMMA_SEPARATOR'], $deleted_filenames));
                        } else {
                            $error[] = $user->lang['NO_FILES_TO_DELETE'];
                        }
                    }
                }
                if ($action == 'stats') {
                    $this->handle_stats_resync();
                }
                $stats_error = $this->check_stats_accuracy();
                if ($stats_error) {
                    $error[] = $stats_error;
                }
                $template->assign_vars(array('S_MANAGE' => true));
                $start = $request->variable('start', 0);
                // Sort keys
                $sort_days = $request->variable('st', 0);
                $sort_key = $request->variable('sk', 't');
                $sort_dir = $request->variable('sd', 'd');
                // 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('f' => $user->lang['FILENAME'], 't' => $user->lang['FILEDATE'], 's' => $user->lang['FILESIZE'], 'x' => $user->lang['EXTENSION'], 'd' => $user->lang['DOWNLOADS'], 'p' => $user->lang['ATTACH_POST_TYPE'], 'u' => $user->lang['AUTHOR']);
                $sort_by_sql = array('f' => 'a.real_filename', 't' => 'a.filetime', 's' => 'a.filesize', 'x' => 'a.extension', 'd' => 'a.download_count', 'p' => 'a.in_message', 'u' => 'u.username');
                $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);
                $min_filetime = $sort_days ? time() - $sort_days * 86400 : '';
                $limit_filetime = $min_filetime ? " AND a.filetime >= {$min_filetime} " : '';
                $start = $sort_days && isset($_POST['sort']) ? 0 : $start;
                $attachments_per_page = (int) $config['topics_per_page'];
                $stats = $this->get_attachment_stats($limit_filetime);
                $num_files = $stats['num_files'];
                $total_size = $stats['upload_dir_size'];
                // Make sure $start is set to the last page if it exceeds the amount
                /* @var $pagination \phpbb\pagination */
                $pagination = $phpbb_container->get('pagination');
                $start = $pagination->validate_start($start, $attachments_per_page, $num_files);
                // If the user is trying to reach the second half of the attachments list, fetch it starting from the end
                $store_reverse = false;
                $sql_limit = $attachments_per_page;
                if ($start > $num_files / 2) {
                    $store_reverse = true;
                    // Select the sort order. Add time sort anchor for non-time sorting cases
                    $sql_sort_anchor = $sort_key != 't' ? ', a.filetime ' . ($sort_dir == 'd' ? 'ASC' : 'DESC') : '';
                    $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'ASC' : 'DESC') . $sql_sort_anchor;
                    $sql_limit = $pagination->reverse_limit($start, $sql_limit, $num_files);
                    $sql_start = $pagination->reverse_start($start, $sql_limit, $num_files);
                } else {
                    // Select the sort order. Add time sort anchor for non-time sorting cases
                    $sql_sort_anchor = $sort_key != 't' ? ', a.filetime ' . ($sort_dir == 'd' ? 'DESC' : 'ASC') : '';
                    $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC') . $sql_sort_anchor;
                    $sql_start = $start;
                }
                $attachments_list = array();
                // Just get the files
                $sql = 'SELECT a.*, u.username, u.user_colour, t.topic_title
					FROM ' . ATTACHMENTS_TABLE . ' a
					LEFT JOIN ' . USERS_TABLE . ' u ON (u.user_id = a.poster_id)
					LEFT JOIN ' . TOPICS_TABLE . " t ON (a.topic_id = t.topic_id)\n\t\t\t\t\tWHERE a.is_orphan = 0\n\t\t\t\t\t\t{$limit_filetime}\n\t\t\t\t\tORDER BY {$sql_sort_order}";
                $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
                $i = $store_reverse ? $sql_limit - 1 : 0;
                // Store increment value in a variable to save some conditional calls
                $i_increment = $store_reverse ? -1 : 1;
                while ($attachment_row = $db->sql_fetchrow($result)) {
                    $attachments_list[$i] = $attachment_row;
                    $i = $i + $i_increment;
                }
                $db->sql_freeresult($result);
                $base_url = $this->u_action . "&amp;{$u_sort_param}";
                $pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_files, $attachments_per_page, $start);
                $template->assign_vars(array('TOTAL_FILES' => $num_files, 'TOTAL_SIZE' => get_formatted_filesize($total_size), 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir));
                // Grab extensions
                $extensions = $cache->obtain_attach_extensions(true);
                for ($i = 0, $end = sizeof($attachments_list); $i < $end; ++$i) {
                    $row = $attachments_list[$i];
                    $row['extension'] = strtolower(trim((string) $row['extension']));
                    $comment = $row['attach_comment'] && !$row['in_message'] ? str_replace(array("\n", "\r"), array('<br />', "\n"), $row['attach_comment']) : '';
                    $display_cat = $extensions[$row['extension']]['display_cat'];
                    $l_downloaded_viewed = $display_cat == ATTACHMENT_CATEGORY_NONE ? 'DOWNLOAD_COUNTS' : 'VIEWED_COUNTS';
                    $template->assign_block_vars('attachments', array('ATTACHMENT_POSTER' => get_username_string('full', (int) $row['poster_id'], (string) $row['username'], (string) $row['user_colour'], (string) $row['username']), 'FILESIZE' => get_formatted_filesize((int) $row['filesize']), 'FILETIME' => $user->format_date((int) $row['filetime']), 'REAL_FILENAME' => !$row['in_message'] ? utf8_basename((string) $row['real_filename']) : '', 'PHYSICAL_FILENAME' => utf8_basename((string) $row['physical_filename']), 'EXT_GROUP_NAME' => !empty($extensions[$row['extension']]['group_name']) ? $user->lang['EXT_GROUP_' . $extensions[$row['extension']]['group_name']] : '', 'COMMENT' => $comment, 'TOPIC_TITLE' => !$row['in_message'] ? (string) $row['topic_title'] : '', 'ATTACH_ID' => (int) $row['attach_id'], 'POST_ID' => (int) $row['post_msg_id'], 'TOPIC_ID' => (int) $row['topic_id'], 'POST_IDS' => !empty($post_ids[$row['attach_id']]) ? (int) $post_ids[$row['attach_id']] : '', 'L_DOWNLOAD_COUNT' => $user->lang($l_downloaded_viewed, (int) $row['download_count']), 'S_IN_MESSAGE' => (bool) $row['in_message'], 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . "#p{$row['post_msg_id']}", 'U_FILE' => append_sid($phpbb_root_path . 'download/file.' . $phpEx, 'mode=view&amp;id=' . $row['attach_id'])));
                }
                break;
        }
        if (sizeof($error)) {
            $template->assign_vars(array('S_WARNING' => true, 'WARNING_MSG' => implode('<br />', $error)));
        }
        if (sizeof($notify)) {
            $template->assign_vars(array('S_NOTIFY' => true, 'NOTIFY_MSG' => implode('<br />', $notify)));
        }
    }
Ejemplo n.º 9
0
function create_thumbnail($source, $destination, $mimetype) 
{
	global $config;

	$min_filesize = (int) $config['img_min_thumb_filesize'];
	$img_filesize = (file_exists($source)) ? @filesize($source) : false;

	$dimension = @getimagesize($source);

	if ($dimension === false)
	{
		return false;
	}

	list($width, $height, $type, ) = $dimension;

	if (empty($width) || empty($height))
	{
		return false;
	}

	if ($width <= $config['photo_thumb_width'] && $height <= $config['photo_thumb_height'])
	{
		return false;
	}

	list($new_width, $new_height) = get_img_size_format($width, $height);

	// Do not create a thumbnail if the resulting width/height is bigger than the original one
	if ($new_width > $width && $new_height > $height)
	{
		return false;
	}

	$used_imagick = false;

	// Only use imagemagick if defined and the passthru function not disabled
	if ($config['img_imagick'] && function_exists('passthru'))
	{
		@passthru(escapeshellcmd($config['img_imagick']) . 'convert' . ((defined('PHP_OS') && preg_match('#^win#i', PHP_OS)) ? '.exe' : '') . ' -quality 85 -antialias -sample ' . $new_width . 'x' . $new_height . ' "' . str_replace('\\', '/', $source) . '" +profile "*" "' . str_replace('\\', '/', $destination) . '"');

		if (file_exists($destination))
		{
			$used_imagick = true;
		}
	}

	if (!$used_imagick) 
	{
		$type = get_supported_image_types($type);

		if ($type['gd'])
		{
			// If the type is not supported, we are not able to create a thumbnail
			if ($type['format'] === false)
			{
				return false;
			}

			switch ($type['format']) 
			{
				case IMG_GIF:
					$image = @imagecreatefromgif($source);
				break;

				case IMG_JPG:
					$image = @imagecreatefromjpeg($source);
				break;

				case IMG_PNG:
					$image = @imagecreatefrompng($source);
				break;

				case IMG_WBMP:
					$image = @imagecreatefromwbmp($source);
				break;
			}

			if ($type['version'] == 1)
			{
				$new_image = imagecreate($new_width, $new_height);
				imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
			}
			else
			{
				$new_image = imagecreatetruecolor($new_width, $new_height);
				imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
			}

			// If we are in safe mode create the destination file prior to using the gd functions to circumvent a PHP bug
			if (@ini_get('safe_mode') || @strtolower(ini_get('safe_mode')) == 'on')
			{
				@touch($destination);
			}

			switch ($type['format'])
			{
				case IMG_GIF:
					imagegif($new_image, $destination);
				break;

				case IMG_JPG:
					imagejpeg($new_image, $destination, 90);
				break;

				case IMG_PNG:
					imagepng($new_image, $destination);
				break;

				case IMG_WBMP:
					imagewbmp($new_image, $destination);
				break;
			}

			imagedestroy($new_image);
		}
		else
		{
			return false;
		}
	}

	if (!file_exists($destination))
	{
		return false;
	}

	@chmod($destination, 0666);

	return true;
}
Ejemplo n.º 10
0
                if ($row[$i]['cat_id'] == SWF_CAT) {
                    $s_assigned_group_flash[] = $row[$i]['group_name'];
                }
            }
        }
    }
    $display_inlined_yes = $new_attach['img_display_inlined'] != '0' ? 'checked="checked"' : '';
    $display_inlined_no = $new_attach['img_display_inlined'] == '0' ? 'checked="checked"' : '';
    $create_thumbnail_yes = $new_attach['img_create_thumbnail'] != '0' ? 'checked="checked"' : '';
    $create_thumbnail_no = $new_attach['img_create_thumbnail'] == '0' ? 'checked="checked"' : '';
    $use_gd2_yes = $new_attach['use_gd2'] != '0' ? 'checked="checked"' : '';
    $use_gd2_no = $new_attach['use_gd2'] == '0' ? 'checked="checked"' : '';
    //
    // Check Thumbnail Support
    //
    if (!is_imagick() && count(get_supported_image_types()) == 0) {
        $new_attach['img_create_thumbnail'] = '0';
    } else {
        $template->assign_block_vars('switch_thumbnail_support', array());
    }
    $template->assign_vars(array('L_MANAGE_CAT_TITLE' => $lang['Manage_categories'], 'L_MANAGE_CAT_EXPLAIN' => $lang['Manage_categories_explain'], 'L_SETTINGS_CAT_IMAGES' => $lang['Settings_cat_images'], 'L_SETTINGS_CAT_STREAM' => $lang['Settings_cat_streams'], 'L_SETTINGS_CAT_FLASH' => $lang['Settings_cat_flash'], 'L_ASSIGNED_GROUP' => $lang['Assigned_group'], 'L_DISPLAY_INLINED' => $lang['Display_inlined'], 'L_DISPLAY_INLINED_EXPLAIN' => $lang['Display_inlined_explain'], 'L_MAX_IMAGE_SIZE' => $lang['Max_image_size'], 'L_MAX_IMAGE_SIZE_EXPLAIN' => $lang['Max_image_size_explain'], 'L_IMAGE_LINK_SIZE' => $lang['Image_link_size'], 'L_IMAGE_LINK_SIZE_EXPLAIN' => $lang['Image_link_size_explain'], 'L_CREATE_THUMBNAIL' => $lang['Image_create_thumbnail'], 'L_CREATE_THUMBNAIL_EXPLAIN' => $lang['Image_create_thumbnail_explain'], 'L_MIN_THUMB_FILESIZE' => $lang['Image_min_thumb_filesize'], 'L_MIN_THUMB_FILESIZE_EXPLAIN' => $lang['Image_min_thumb_filesize_explain'], 'L_IMAGICK_PATH' => $lang['Image_imagick_path'], 'L_IMAGICK_PATH_EXPLAIN' => $lang['Image_imagick_path_explain'], 'L_SEARCH_IMAGICK' => $lang['Image_search_imagick'], 'L_BYTES' => $lang['Bytes'], 'L_TEST_SETTINGS' => $lang['Test_settings'], 'L_YES' => $lang['Yes'], 'L_NO' => $lang['No'], 'L_SUBMIT' => $lang['Submit'], 'L_RESET' => $lang['Reset'], 'L_USE_GD2' => $lang['Use_gd2'], 'L_USE_GD2_EXPLAIN' => $lang['Use_gd2_explain'], 'IMAGE_MAX_HEIGHT' => $new_attach['img_max_height'], 'IMAGE_MAX_WIDTH' => $new_attach['img_max_width'], 'IMAGE_LINK_HEIGHT' => $new_attach['img_link_height'], 'IMAGE_LINK_WIDTH' => $new_attach['img_link_width'], 'IMAGE_MIN_THUMB_FILESIZE' => $new_attach['img_min_thumb_filesize'], 'IMAGE_IMAGICK_PATH' => $new_attach['img_imagick'], 'DISPLAY_INLINED_YES' => $display_inlined_yes, 'DISPLAY_INLINED_NO' => $display_inlined_no, 'CREATE_THUMBNAIL_YES' => $create_thumbnail_yes, 'CREATE_THUMBNAIL_NO' => $create_thumbnail_no, 'USE_GD2_YES' => $use_gd2_yes, 'USE_GD2_NO' => $use_gd2_no, 'S_ASSIGNED_GROUP_IMAGES' => implode(', ', $s_assigned_group_images), 'S_ATTACH_ACTION' => append_sid('admin_attachments.' . $phpEx . '?mode=cats')));
}
//
// Check Cat Settings
//
if ($check_image_cat) {
    //
    // Some tests...
    //
    $attach_config = array();
    $sql = 'SELECT *