diff --git a/phpBB/adm/admin_attachments.php b/phpBB/adm/admin_attachments.php
index 07dbc6df3e..41d206f3fb 100644
--- a/phpBB/adm/admin_attachments.php
+++ b/phpBB/adm/admin_attachments.php
@@ -38,13 +38,13 @@ if (!$auth->acl_get('a_attach'))
trigger_error($user->lang['NO_ADMIN']);
}
-$mode = (isset($_REQUEST['mode'])) ? htmlspecialchars($_REQUEST['mode']) : '';
+$mode = (isset($_REQUEST['mode'])) ? trim(htmlspecialchars($_REQUEST['mode'])) : '';
$config_sizes = array('max_filesize' => 'size', 'attachment_quota' => 'quota_size', 'max_filesize_pm' => 'pm_size');
foreach ($config_sizes as $cfg_key => $var)
{
- $$var = (isset($_REQUEST[$var])) ? htmlspecialchars($_REQUEST[$var]) : '';
+ $$var = (isset($_REQUEST[$var])) ? trim(htmlspecialchars($_REQUEST[$var])) : '';
}
$submit = (isset($_POST['submit'])) ? TRUE : FALSE;
@@ -54,8 +54,8 @@ $error = $notify = false;
$error_msg = $notify_msg = '';
// Pull all config data
-$sql = "SELECT *
- FROM " . CONFIG_TABLE;
+$sql = 'SELECT *
+ FROM ' . CONFIG_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -92,7 +92,7 @@ while ($row = $db->sql_fetchrow($result))
}
}
- if ($submit && $mode == 'manage')
+ if ($submit && ($mode == 'manage' || $mode == 'cats'))
{
// Update Extension Group Filesizes
if ($config_name == 'max_filesize')
@@ -103,14 +103,14 @@ while ($row = $db->sql_fetchrow($result))
if ($old_size != $new_size)
{
// See, if we have a similar value of old_size in Extension Groups. If so, update these values.
- $sql = "UPDATE " . EXTENSION_GROUPS_TABLE . "
- SET max_filesize = " . $new_size . "
- WHERE max_filesize = " . $old_size;
+ $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
+ SET max_filesize = $new_size
+ WHERE max_filesize = $old_size";
$db->sql_query($sql);
}
}
- set_config($config_name, stripslashes($new[$config_name]));
+ set_config($config_name, str_replace('\\\\', '\\', addslashes($new[$config_name])));
if (in_array($config_name, array('max_filesize', 'attachment_quota', 'max_filesize_pm')))
{
@@ -129,14 +129,7 @@ if ($submit && ($mode == 'manage' || $mode == 'cats'))
// Adjust the Upload Directory
if (!$new['use_ftp_upload'])
{
- if ( ($new['upload_dir'][0] == '/') || ( ($new['upload_dir'][0] != '/') && ($new['upload_dir'][1] == ':') ) )
- {
- $upload_dir = $new['upload_dir'];
- }
- else
- {
- $upload_dir = $phpbb_root_path . $new['upload_dir'];
- }
+ $upload_dir = ($new['upload_dir'][0] == '/' || ($new['upload_dir'][0] != '/' && $new['upload_dir'][1] == ':')) ? $new['upload_dir'] : $phpbb_root_path . $new['upload_dir'];
}
else
{
@@ -170,63 +163,47 @@ if ($search_imagick)
{
$imagick = '';
- if (eregi('convert', $imagick))
- {
- continue;
- }
- else if ($imagick != 'none')
- {
- if (!eregi('WIN', PHP_OS))
- {
- $retval = @exec('whereis convert');
- $paths = explode(' ', $retval);
+ $exe = ((defined('PHP_OS')) && (preg_match('#win#i', PHP_OS))) ? '.exe' : '';
- if (is_array($paths))
+ if (empty($_ENV['MAGICK_HOME']))
+ {
+ $locations = array('C:/WINDOWS/', 'C:/WINNT/', 'C:/WINDOWS/SYSTEM/', 'C:/WINNT/SYSTEM/', 'C:/WINDOWS/SYSTEM32/', 'C:/WINNT/SYSTEM32/', '/usr/bin/', '/usr/sbin/', '/usr/local/bin/', '/usr/local/sbin/', '/opt/', '/usr/imagemagick/', '/usr/bin/imagemagick/');
+
+ foreach ($locations as $location)
+ {
+ if (file_exists($location . 'convert' . $exe) && is_executable($location . 'convert' . $exe))
{
- foreach($paths as $path)
- {
- if (basename($path) == 'convert')
- {
- $imagick = $path;
- }
- }
+ $imagick = str_replace('\\', '/', $location);
+ continue;
}
}
- else if (eregi('WIN', PHP_OS))
- {
- $path = 'c:/imagemagick/convert.exe';
+ }
+ else
+ {
+ $imagick = str_replace('\\', '/', $_ENV['MAGICK_HOME']);
+ }
- if (@file_exists($path))
- {
- $imagick = $path;
- }
- }
- }
-
- $new['img_imagick'] = (@file_exists(trim($imagick))) ? trim($imagick) : '';
+ $new['img_imagick'] = $imagick . 'convert' . $exe;
}
// Check Settings
if ($submit && $mode == 'manage')
{
- $upload_dir = ( ($new['upload_dir'][0] == '/') || ($new['upload_dir'][0] != '/' && $new['upload_dir'][1] == ':') ) ? $new['upload_dir'] : $phpbb_root_path . $new['upload_dir'];
-
test_upload($error, $error_msg, $upload_dir, $new['ftp_path'], $new['use_ftp_upload'], false);
}
if ($submit && $mode == 'cats')
{
- $upload_dir = ( ($new['upload_dir'][0] == '/') || ($new['upload_dir'][0] != '/' && $new['upload_dir'][1] == ':') ) ? $new['upload_dir'] . '/thumbs' : $phpbb_root_path . $new['upload_dir'] . '/thumbs';
test_upload($error, $error_msg, $upload_dir, $new['ftp_path'] . '/thumbs', $new['use_ftp_upload'], true);
}
if ($submit && $mode == 'extensions')
{
// Change Extensions ?
- $extension_change_list = ( isset($_POST['extension_change_list']) ) ? $_POST['extension_change_list'] : array();
- $extension_explain_list = ( isset($_POST['extension_explain_list']) ) ? $_POST['extension_explain_list'] : array();
- $group_select_list = ( isset($_POST['group_select']) ) ? $_POST['group_select'] : array();
+ $extension_change_list = (isset($_POST['extension_change_list'])) ? $_POST['extension_change_list'] : array();
+ $extension_explain_list = (isset($_POST['extension_explain_list'])) ? $_POST['extension_explain_list'] : array();
+ $group_select_list = (isset($_POST['group_select'])) ? $_POST['group_select'] : array();
// Generate correct Change List
$extensions = array();
@@ -244,54 +221,68 @@ if ($submit && $mode == 'extensions')
while ($row = $db->sql_fetchrow($result))
{
- if ( ($row['comment'] != $extensions[$row['extension_id']]['comment']) || (intval($row['group_id']) != intval($extensions[$row['extension_id']]['group_id'])) )
+ if ($row['comment'] != $extensions[$row['extension_id']]['comment'] || intval($row['group_id']) != intval($extensions[$row['extension_id']]['group_id']))
{
$sql = "UPDATE " . EXTENSIONS_TABLE . "
SET comment = '" . $extensions[$row['extension_id']]['comment'] . "', group_id = " . $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 = ( isset($_POST['extension_id_list']) ) ? $_POST['extension_id_list'] : array();
-
+ $extension_id_list = (isset($_POST['extension_id_list'])) ? $_POST['extension_id_list'] : array();
$extension_id_sql = implode(', ', $extension_id_list);
if ($extension_id_sql != '')
{
$sql = 'DELETE
- FROM ' . EXTENSIONS_TABLE . '
- WHERE extension_id IN (' . $extension_id_sql . ')';
+ FROM ' . EXTENSIONS_TABLE . "
+ WHERE extension_id IN ($extension_id_sql)";
$db->sql_query($sql);
+
+ $sql = 'SELECT extension
+ FROM ' . EXTENSIONS_TABLE . "
+ WHERE extension_id IN ($extension_id_sql)";
+ $result = $db->sql_query($sql);
+
+ $extension_list = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $extension_list[] = $row['extension'];
+ }
+ $db->sql_freeresult($result);
+
+ add_log('admin', 'LOG_ATTACH_EXT_DEL', implode(', ', $extension_list));
}
// Add Extension ?
- $add_extension = ( isset($_POST['add_extension']) ) ? trim(strip_tags($_POST['add_extension'])) : '';
- $add_extension_explain = ( isset($_POST['add_extension_explain']) ) ? trim(strip_tags($_POST['add_extension_explain'])) : '';
- $add_extension_group = ( isset($_POST['add_group_select']) ) ? intval($_POST['add_group_select']) : '';
- $add = ( isset($_POST['add_extension_check']) ) ? TRUE : FALSE;
+ $add_extension = (isset($_POST['add_extension'])) ? strtolower(trim(strip_tags($_POST['add_extension']))) : '';
+ $add_extension_explain = (isset($_POST['add_extension_explain'])) ? trim(strip_tags($_POST['add_extension_explain'])) : '';
+ $add_extension_group = (isset($_POST['add_group_select'])) ? intval($_POST['add_group_select']) : '';
+ $add = (isset($_POST['add_extension_check'])) ? TRUE : FALSE;
if ($add_extension != '' && $add)
{
if (!$error)
{
// check extension
- $sql = "SELECT extension
- FROM " . EXTENSIONS_TABLE;
+ $sql = 'SELECT extension
+ FROM ' . EXTENSIONS_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
- if (strtolower(trim($row['extension'])) == strtolower(trim($add_extension)))
+ if ($row['extension'] == $add_extension)
{
$error = TRUE;
if( isset($error_msg) )
{
$error_msg .= '
';
}
- $error_msg .= sprintf($user->lang['EXTENSION_EXIST'], strtolower(trim($add_extension)));
+ $error_msg .= sprintf($user->lang['EXTENSION_EXIST'], $add_extension);
}
}
$db->sql_freeresult($result);
@@ -299,29 +290,30 @@ if ($submit && $mode == 'extensions')
// Extension Forbidden ?
if (!$error)
{
- $sql = "SELECT extension
- FROM " . FORBIDDEN_EXTENSIONS_TABLE;
+ $sql = 'SELECT extension
+ FROM ' . FORBIDDEN_EXTENSIONS_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
- if (strtolower(trim($row['extension'])) == strtolower(trim($add_extension)))
+ if ($row['extension'] == $add_extension)
{
$error = TRUE;
if( isset($error_msg) )
{
$error_msg .= '
';
}
- $error_msg .= sprintf($user->lang['CANNOT_ADD_FORBIDDEN_EXTENSION'], strtolower(trim($add_extension)));
+ $error_msg .= sprintf($user->lang['CANNOT_ADD_FORBIDDEN_EXTENSION'], $add_extension);
}
}
}
if (!$error)
{
- $sql = "INSERT INTO " . EXTENSIONS_TABLE . " (group_id, extension, comment)
- VALUES (" . $add_extension_group . ", '" . strtolower(trim($add_extension)) . "', '" . trim($add_extension_explain) . "')";
+ $sql = 'INSERT INTO ' . EXTENSIONS_TABLE . " (group_id, extension, comment)
+ VALUES ($add_extension_group, '" . $add_extension . "', '" . trim($add_extension_explain) . "')";
$db->sql_query($sql);
+ add_log('admin', 'LOG_ATTACH_EXT_ADD', $add_extension);
}
}
}
@@ -336,14 +328,14 @@ if ($submit && $mode == 'extensions')
if ($submit && $mode == 'ext_groups')
{
// Change Extension Groups ?
- $group_change_list = ( isset($_POST['group_change_list']) ) ? $_POST['group_change_list'] : array();
- $extension_group_list = ( isset($_POST['extension_group_list']) ) ? $_POST['extension_group_list'] : array();
- $group_allowed_list = ( isset($_POST['allowed_list']) ) ? $_POST['allowed_list'] : array();
- $download_mode_list = ( isset($_POST['download_mode_list']) ) ? $_POST['download_mode_list'] : array();
- $category_list = ( isset($_POST['category_list']) ) ? $_POST['category_list'] : array();
- $upload_icon_list = ( isset($_POST['upload_icon_list']) ) ? $_POST['upload_icon_list'] : array();
- $filesize_list = ( isset($_POST['max_filesize_list']) ) ? $_POST['max_filesize_list'] : array();
- $size_select_list = ( isset($_POST['size_select_list']) ) ? $_POST['size_select_list'] : array();
+ $group_change_list = (isset($_POST['group_change_list'])) ? $_POST['group_change_list'] : array();
+ $extension_group_list = (isset($_POST['extension_group_list'])) ? $_POST['extension_group_list'] : array();
+ $group_allowed_list = (isset($_POST['allowed_list'])) ? $_POST['allowed_list'] : array();
+ $download_mode_list = (isset($_POST['download_mode_list'])) ? $_POST['download_mode_list'] : array();
+ $category_list = (isset($_POST['category_list'])) ? $_POST['category_list'] : array();
+ $upload_icon_list = (isset($_POST['upload_icon_list'])) ? $_POST['upload_icon_list'] : array();
+ $filesize_list = (isset($_POST['max_filesize_list'])) ? $_POST['max_filesize_list'] : array();
+ $size_select_list = (isset($_POST['size_select_list'])) ? $_POST['size_select_list'] : array();
$allowed_list = array();
@@ -360,33 +352,35 @@ if ($submit && $mode == 'ext_groups')
for ($i = 0; $i < count($group_change_list); $i++)
{
- $allowed = ( isset($allowed_list[$i]) ) ? 1 : 0;
+ $allowed = (isset($allowed_list[$i])) ? 1 : 0;
- $filesize_list[$i] = ( $size_select_list[$i] == 'kb' ) ? round($filesize_list[$i] * 1024) : ( ($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i] );
+ $filesize_list[$i] = ($size_select_list[$i] == 'kb') ? round($filesize_list[$i] * 1024) : (($size_select_list[$i] == 'mb') ? round($filesize_list[$i] * 1048576) : $filesize_list[$i]);
$group_sql = array(
- 'group_name' => $extension_group_list[$i],
- 'cat_id' => $category_list[$i],
- 'allow_group' => $allowed,
- 'download_mode' => $download_mode_list[$i],
- 'upload_icon' => ($upload_icon_list[$i] == 'no_image') ? '' : $upload_icon_list[$i],
- 'max_filesize' => $filesize_list[$i]
+ 'group_name' => $extension_group_list[$i],
+ 'cat_id' => $category_list[$i],
+ 'allow_group' => $allowed,
+ 'download_mode' => $download_mode_list[$i],
+ 'upload_icon' => ($upload_icon_list[$i] == 'no_image') ? '' : $upload_icon_list[$i],
+ 'max_filesize' => $filesize_list[$i]
);
- $sql = "UPDATE " . EXTENSION_GROUPS_TABLE . " SET " . $db->sql_build_array('UPDATE', $group_sql) . " WHERE group_id = " . $group_change_list[$i];
+ $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
+ SET " . $db->sql_build_array('UPDATE', $group_sql) . "
+ WHERE group_id = " . $group_change_list[$i];
$db->sql_query($sql);
}
// Delete Extension Groups
- $group_id_list = ( isset($_POST['group_id_list']) ) ? $_POST['group_id_list'] : array();
+ $group_id_list = (isset($_POST['group_id_list'])) ? $_POST['group_id_list'] : array();
if (count($group_id_list))
{
$l_group_list = '';
- $sql = "SELECT group_name
- FROM " . EXTENSION_GROUPS_TABLE . "
- WHERE group_id IN (" . implode(', ', $group_id_list) . ")";
+ $sql = 'SELECT group_name
+ FROM ' . EXTENSION_GROUPS_TABLE . '
+ WHERE group_id IN (' . implode(', ', $group_id_list) . ')';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -395,9 +389,9 @@ if ($submit && $mode == 'ext_groups')
}
$db->sql_freeresult($result);
- $sql = "DELETE
- FROM " . EXTENSION_GROUPS_TABLE . "
- WHERE group_id IN (" . implode(', ', $group_id_list) . ")";
+ $sql = 'DELETE
+ FROM ' . EXTENSION_GROUPS_TABLE . '
+ WHERE group_id IN (' . implode(', ', $group_id_list) . ')';
$db->sql_query($sql);
// Set corresponding Extensions to a pending Group
@@ -410,20 +404,20 @@ if ($submit && $mode == 'ext_groups')
}
// Add Extensions Group ?
- $extension_group = ( isset($_POST['add_extension_group']) ) ? trim(strip_tags($_POST['add_extension_group'])) : '';
- $download_mode = ( isset($_POST['add_download_mode']) ) ? $_POST['add_download_mode'] : '';
- $cat_id = ( isset($_POST['add_category']) ) ? $_POST['add_category'] : '';
- $upload_icon = ( isset($_POST['add_upload_icon']) ) ? $_POST['add_upload_icon'] : '';
- $filesize = ( isset($_POST['add_max_filesize']) ) ? $_POST['add_max_filesize'] : '';
- $size_select = ( isset($_POST['add_size_select']) ) ? $_POST['add_size_select'] : '';
- $is_allowed = ( isset($_POST['add_allowed']) ) ? 1 : 0;
- $add = ( isset($_POST['add_extension_group_check']) ) ? TRUE : FALSE;
+ $extension_group = (isset($_POST['add_extension_group'])) ? trim(strip_tags($_POST['add_extension_group'])) : '';
+ $download_mode = (isset($_POST['add_download_mode'])) ? $_POST['add_download_mode'] : '';
+ $cat_id = (isset($_POST['add_category'])) ? $_POST['add_category'] : '';
+ $upload_icon = (isset($_POST['add_upload_icon'])) ? $_POST['add_upload_icon'] : '';
+ $filesize = (isset($_POST['add_max_filesize'])) ? $_POST['add_max_filesize'] : '';
+ $size_select = (isset($_POST['add_size_select'])) ? $_POST['add_size_select'] : '';
+ $is_allowed = (isset($_POST['add_allowed'])) ? 1 : 0;
+ $add = (isset($_POST['add_extension_group_check'])) ? TRUE : FALSE;
if ($extension_group != '' && $add)
{
// check Extension Group
- $sql = "SELECT group_name
- FROM " . EXTENSION_GROUPS_TABLE;
+ $sql = 'SELECT group_name
+ FROM ' . EXTENSION_GROUPS_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -445,37 +439,38 @@ if ($submit && $mode == 'ext_groups')
$filesize = ($size_select == 'kb') ? round($filesize * 1024) : (($size_select == 'mb') ? round($filesize * 1048576) : $filesize);
$group_sql = array(
- 'group_name' => $extension_group,
- 'cat_id' => $cat_id,
- 'allow_group' => $is_allowed,
- 'download_mode' => $download_mode,
- 'upload_icon' => ($upload_icon == 'no_image') ? '' : $upload_icon,
- 'max_filesize' => $filesize
+ 'group_name' => $extension_group,
+ 'cat_id' => $cat_id,
+ 'allow_group' => $is_allowed,
+ 'download_mode' => $download_mode,
+ 'upload_icon' => ($upload_icon == 'no_image') ? '' : $upload_icon,
+ 'max_filesize' => $filesize
);
- $sql = "INSERT INTO " . EXTENSION_GROUPS_TABLE . " " . $db->sql_build_array('INSERT', $group_sql);
+ $sql = 'INSERT INTO ' . EXTENSION_GROUPS_TABLE . ' ' .
+ $db->sql_build_array('INSERT', $group_sql);
$db->sql_query($sql);
add_log('admin', 'LOG_ATTACH_EXTGROUP_ADD', $extension_group);
}
}
- $sql = "SELECT e.extension, g.*
- FROM " . EXTENSIONS_TABLE . " e, " . EXTENSION_GROUPS_TABLE . " g
+ $sql = 'SELECT e.extension, g.*
+ FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
WHERE e.group_id = g.group_id
- AND g.allow_group = 1";
+ AND g.allow_group = 1';
$result = $db->sql_query($sql);
$extensions = array();
while ($row = $db->sql_fetchrow($result))
{
- $extension = strtolower(trim($row['extension']));
+ $extension = $row['extension'];
- $extensions['_allowed_'][] = $extension;
- $extensions[$extension]['display_cat'] = intval($row['cat_id']);
- $extensions[$extension]['download_mode'] = intval($row['download_mode']);
- $extensions[$extension]['upload_icon'] = trim($row['upload_icon']);
- $extensions[$extension]['max_filesize'] = intval($row['max_filesize']);
+ $extensions['_allowed_'][] = $extension;
+ $extensions[$extension]['display_cat'] = intval($row['cat_id']);
+ $extensions[$extension]['download_mode']= intval($row['download_mode']);
+ $extensions[$extension]['upload_icon'] = trim($row['upload_icon']);
+ $extensions[$extension]['max_filesize'] = intval($row['max_filesize']);
}
$db->sql_freeresult($result);
@@ -680,10 +675,10 @@ if ($mode == 'manage')
if ($mode == 'cats')
{
- $sql = "SELECT group_name, cat_id
- FROM " . EXTENSION_GROUPS_TABLE . "
+ $sql = 'SELECT group_name, cat_id
+ FROM ' . EXTENSION_GROUPS_TABLE . '
WHERE cat_id > 0
- ORDER BY cat_id";
+ ORDER BY cat_id';
$result = $db->sql_query($sql);
$s_assigned_groups = array();
@@ -717,7 +712,7 @@ if ($mode == 'cats')
= 1048576) ? 'mb' : ( ($max_add_filesize >= 1024) ? 'kb' : 'b' );
+ $size = ($max_add_filesize >= 1048576) ? 'mb' : (($max_add_filesize >= 1024) ? 'kb' : 'b');
}
if ($max_add_filesize >= 1048576)
@@ -865,8 +861,8 @@ if ($mode == 'ext_groups')
- $sql = "SELECT *
- FROM " . EXTENSION_GROUPS_TABLE;
+ $sql = 'SELECT *
+ FROM ' . EXTENSION_GROUPS_TABLE;
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -931,9 +927,9 @@ if ($mode == 'ext_groups')
if ($viewgroup != -1 && $viewgroup == $row['group_id'])
{
- $sql = "SELECT comment, extension
- FROM " . EXTENSIONS_TABLE . "
- WHERE group_id = " . intval($viewgroup);
+ $sql = 'SELECT comment, extension
+ FROM ' . EXTENSIONS_TABLE . '
+ WHERE group_id = ' . intval($viewgroup);
$e_result = $db->sql_query($sql);
while ($e_row = $db->sql_fetchrow($e_result))
@@ -1183,19 +1179,12 @@ function category_select($select_name, $group_id = -1)
if ($group_id != -1)
{
- $sql = "SELECT cat_id
- FROM " . EXTENSION_GROUPS_TABLE . "
- WHERE group_id = " . intval($group_id);
+ $sql = 'SELECT cat_id
+ FROM ' . EXTENSION_GROUPS_TABLE . '
+ WHERE group_id = ' . intval($group_id);
$result = $db->sql_query($sql);
- if (!($row = $db->sql_fetchrow($result)))
- {
- $cat_type = NONE_CAT;
- }
- else
- {
- $cat_type = $row['cat_id'];
- }
+ $cat_type = (!($row = $db->sql_fetchrow($result))) ? NONE_CAT : $row['cat_id'];
$db->sql_freeresult($result);
}
@@ -1276,14 +1265,7 @@ function download_select($select_name, $group_id = -1)
WHERE group_id = " . intval($group_id);
$result = $db->sql_query($sql);
- if (!($row = $db->sql_fetchrow($result)))
- {
- $download_mode = INLINE_LINK;
- }
- else
- {
- $download_mode = $row['download_mode'];
- }
+ $download_mode = (!($row = $db->sql_fetchrow($result))) ? INLINE_LINK : $row['download_mode'];
$db->sql_freeresult($result);
}
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index aa4376a960..b5e5792d44 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -211,7 +211,7 @@ function update_last_post_information($type, $id)
return;
}
- $sql = "SELECT p.post_id, p.poster_id, p.post_time, u.username, p.post_username " . $sql_select_add . "
+ $sql = "SELECT p.post_id, p.poster_id, p.post_time, u.username, p.post_username " . $sql_select_add . "
FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . TOPICS_TABLE . " t " . $sql_table_add . "
WHERE p.post_approved = 1
AND t.topic_approved = 1
@@ -546,7 +546,7 @@ function upload_attachment($filename)
$filedata = array();
$filedata['error'] = array();
- $filedata['post_attach'] = ($filename != '') ? true : false;
+ $filedata['post_attach'] = ($filename != '') ? TRUE : FALSE;
if (!$filedata['post_attach'])
{
@@ -558,9 +558,9 @@ function upload_attachment($filename)
$filedata['mimetype'] = $_FILES['fileupload']['type'];
// Opera add the name to the mime type
- $filedata['mimetype'] = ( strstr($filedata['mimetype'], '; name') ) ? str_replace(strstr($filedata['mimetype'], '; name'), '', $filedata['mimetype']) : $filedata['mimetype'];
- $filedata['extension'] = array_pop(explode('.', strtolower($filename)));
- $filedata['filesize'] = (!@filesize($file)) ? intval($_FILES['size']) : @filesize($file);
+ $filedata['mimetype'] = ( strstr($filedata['mimetype'], '; name') ) ? str_replace(strstr($filedata['mimetype'], '; name'), '', $filedata['mimetype']) : $filedata['mimetype'];
+ $filedata['extension'] = array_pop(explode('.', strtolower($filename)));
+ $filedata['filesize'] = (!@filesize($file)) ? intval($_FILES['size']) : @filesize($file);
$extensions = array();
obtain_attach_extensions($extensions);
@@ -569,7 +569,7 @@ function upload_attachment($filename)
if (!in_array($filedata['extension'], $extensions['_allowed_']))
{
$filedata['error'][] = sprintf($user->lang['DISALLOWED_EXTENSION'], $filedata['extension']);
- $filedata['post_attach'] = false;
+ $filedata['post_attach'] = FALSE;
return $filedata;
}
@@ -580,7 +580,7 @@ function upload_attachment($filename)
if ( preg_match("/[\\/:*?\"<>|]/i", $filename) )
{
$filedata['error'][] = sprintf($user->lang['INVALID_FILENAME'], $filename);
- $filedata['post_attach'] = false;
+ $filedata['post_attach'] = FALSE;
return $filedata;
}
@@ -588,7 +588,7 @@ function upload_attachment($filename)
if ( ($file == 'none') )
{
$filedata['error'][] = (@ini_get('upload_max_filesize') == '') ? $user->lang['ATTACHMENT_PHP_SIZE_NA'] : sprintf($user->lang['ATTACHMENT_PHP_SIZE_OVERRUN'], @ini_get('upload_max_filesize'));
- $filedata['post_attach'] = false;
+ $filedata['post_attach'] = FALSE;
return $filedata;
}
@@ -702,13 +702,11 @@ function upload_attachment($filename)
$filedata['filename'] = str_replace("'", "\'", $filedata['filename']);
-/*
// Do we have to create a thumbnail ?
if ($cat_id == IMAGE_CAT && $config['img_create_thumbnail'])
{
$filedata['thumbnail'] = 1;
}
-*/
// Upload Attachment
if (!$config['use_ftp_upload'])
@@ -801,20 +799,17 @@ function move_uploaded_attachment($upload_mode, $source_filename, &$filedata)
*/
}
- $filedata['thumbnail'] = 0;
-/* if ($filedata['thumbnail'])
+ if ($filedata['thumbnail'])
{
- if ($upload_mode == 'ftp')
+/* if ($upload_mode == 'ftp')
{
$source = $source_filename;
$destination = 'thumbs/t_' . $destination_filename;
}
else
- {
- $source = $config['upload_dir'] . '/' . $destination_filename;
- $destination = phpbb_realpath($config['upload_dir']);
- $destination .= '/thumbs/t_' . $destination_filename;
- }
+ {*/
+ $source = $config['upload_dir'] . '/' . $destination_filename;
+ $destination = $config['upload_dir'] . '/thumbs/t_' . $destination_filename;
if (!create_thumbnail($source, $destination, $filedata['mimetype']))
{
@@ -823,7 +818,7 @@ function move_uploaded_attachment($upload_mode, $source_filename, &$filedata)
$filedata['thumbnail'] = 0;
}
}
- }*/
+ }
return '';
}
@@ -1461,4 +1456,459 @@ function user_notification($mode, $subject, $forum_id, $topic_id, $post_id)
}
}
+// Read DWord (4 Bytes) from File
+function read_dword($fp)
+{
+ $data = fread($fp, 4);
+ $value = ord($data[0]) + (ord($data[1])<<8)+(ord($data[2])<<16)+(ord($data[3])<<24);
+ if ($value >= 4294967294)
+ {
+ $value -= 4294967296;
+ }
+ return $value;
+}
+
+// Read Word (2 Bytes) from File - Note: It's an Intel Word
+function read_word($fp)
+{
+ $data = fread($fp, 2);
+ return ord($data[1]) * 256 + ord($data[0]);
+}
+
+// Read Byte
+function read_byte($fp)
+{
+ $data = fread($fp, 1);
+ return ord($data);
+}
+
+
+// Get Image Dimensions... only a test for now, used within create_thumbnail
+function image_getdimension($file)
+{
+ $size = @getimagesize($file);
+
+ if ($size[0] != 0 || $size[1] != 0)
+ {
+ return $size;
+ }
+
+ // Try to get the Dimension manually, depending on the mimetype
+ $fp = @fopen($file, 'rb');
+ if (!$fp)
+ {
+ return $size;
+ }
+
+ $error = FALSE;
+
+ // BMP - IMAGE
+ $tmp_str = fread($fp, 2);
+ if ($tmp_str == 'BM')
+ {
+ $length = read_dword($fp);
+
+ if ($length <= 6)
+ {
+ $error = TRUE;
+ }
+
+ if (!$error)
+ {
+ $i = read_dword($fp);
+ if ($i != 0)
+ {
+ $error = TRUE;
+ }
+ }
+
+ if (!$error)
+ {
+ $i = read_dword($fp);
+
+ if ($i != 0x3E && $i != 0x76 && $i != 0x436 && $i != 0x36)
+ {
+ $error = TRUE;
+ }
+ }
+
+ if (!$error)
+ {
+ $tmp_str = fread($fp, 4);
+ $width = read_dword($fp);
+ $height = read_dword($fp);
+
+ if ($width > 3000 || $height > 3000)
+ {
+ $error = TRUE;
+ }
+ }
+ }
+ else
+ {
+ $error = TRUE;
+ }
+
+ if (!$error)
+ {
+ fclose($fp);
+ return array(
+ $width,
+ $height,
+ '6'
+ );
+ }
+
+ $error = FALSE;
+ fclose($fp);
+
+ // GIF - IMAGE
+ $fp = @fopen($file, 'rb');
+
+ $tmp_str = fread($fp, 3);
+
+ if ($tmp_str == 'GIF')
+ {
+ $tmp_str = fread($fp, 3);
+ $width = read_word($fp);
+ $height = read_word($fp);
+
+ $info_byte = fread($fp, 1);
+ $info_byte = ord($info_byte);
+ if (($info_byte & 0x80) != 0x80 && ($info_byte & 0x80) != 0)
+ {
+ $error = TRUE;
+ }
+
+ if (!$error)
+ {
+ if (($info_byte & 8) != 0)
+ {
+ $error = TRUE;
+ }
+
+ }
+ }
+ else
+ {
+ $error = TRUE;
+ }
+
+ if (!$error)
+ {
+ fclose($fp);
+ return array(
+ $width,
+ $height,
+ '1'
+ );
+ }
+
+ $error = FALSE;
+ fclose($fp);
+
+ // JPG - IMAGE
+ $fp = @fopen($file, 'rb');
+
+ $tmp_str = fread($fp, 4);
+ $w1 = read_word($fp);
+ if (intval($w1) < 16)
+ {
+ $error = TRUE;
+ }
+
+ if (!$error)
+ {
+ $tmp_str = fread($fp, 4);
+ if ($tmp_str == 'JFIF')
+ {
+ $o_byte = fread($fp, 1);
+ if (intval($o_byte) != 0)
+ {
+ $error = TRUE;
+ }
+
+ if (!$error)
+ {
+ $str = fread($fp, 2);
+ $b = read_byte($fp);
+
+ if ($b != 0 && $b != 1 && $b != 2)
+ {
+ $error = TRUE;
+ }
+ }
+
+ if (!$error)
+ {
+ $width = read_word($fp);
+ $height = read_word($fp);
+
+ if ($width <= 0 || $height <= 0)
+ {
+ $error = TRUE;
+ }
+ }
+ }
+ }
+ else
+ {
+ $error = TRUE;
+ }
+
+ if (!$error)
+ {
+ fclose($fp);
+ return array(
+ $width,
+ $height,
+ '2'
+ );
+ }
+
+ $error = FALSE;
+ fclose($fp);
+
+ // PCX - IMAGE - I do not think we need this, does browser actually support this imagetype? ;)
+ // But let me have the fun...
+/*
+ $fp = @fopen($file, 'rb');
+
+ $tmp_str = fread($fp, 3);
+
+ if (((ord($tmp_str[0]) == 10)) && ( (ord($tmp_str[1]) == 0) || (ord($tmp_str[1]) == 2) || (ord($tmp_str[1]) == 3) || (ord($tmp_str[1]) == 4) || (ord($tmp_str[1]) == 5) ) && ( (ord($tmp_str[2]) == 1) ) )
+ {
+ $b = fread($fp, 1);
+
+ if (ord($b) != 1 && ord($b) != 2 && ord($b) != 4 && ord($b) != 8 && ord($b) != 24)
+ {
+ $error = TRUE;
+ }
+
+ if (!$error)
+ {
+ $xmin = read_word($fp);
+ $ymin = read_word($fp);
+ $xmax = read_word($fp);
+ $ymax = read_word($fp);
+ $tmp_str = fread($fp, 52);
+
+ $b = fread($fp, 1);
+ if ($b != 0)
+ {
+ $error = TRUE;
+ }
+ }
+
+ if (!$error)
+ {
+ $width = $xmax - $xmin + 1;
+ $height = $ymax - $ymin + 1;
+ }
+ }
+ else
+ {
+ $error = TRUE;
+ }
+
+ if (!$error)
+ {
+ fclose($fp);
+ return array(
+ $width,
+ $height,
+ '7'
+ );
+ }
+
+ fclose($fp);
+*/
+ return $size;
+}
+
+// Calculate the needed size for Thumbnail
+// I am sure i had this grabbed from some site... source: unknown
+function get_img_size_format($width, $height)
+{
+ // Change these two values to define the Thumbnail Size
+ $max_width = 300;
+ $max_height = 85;
+
+ if ($height > $max_height)
+ {
+ $new_width = ($max_height / $height) * $width;
+ $new_height = $max_height;
+
+ if ($new_width > $max_width)
+ {
+ $new_height = ($max_width / $new_width) * $new_height;
+ $new_width = $max_width;
+ }
+ }
+ else if ($width > $max_width)
+ {
+ $new_height = ($max_width / $width) * $height;
+ $new_width = $max_width;
+
+ if ($new_height > $max_height)
+ {
+ $new_width = ($max_height / $new_height) * $new_width;
+ $new_height = $max_height;
+ }
+ }
+ else
+ {
+ $new_width = $width;
+ $new_height = $height;
+ }
+
+ return array(
+ round($new_width),
+ round($new_height)
+ );
+}
+
+function get_supported_image_types()
+{
+ $types = array();
+
+ if (@extension_loaded('gd'))
+ {
+ if (@function_exists('imagegif'))
+ {
+ $types[] = '1';
+ }
+ if (@function_exists('imagejpeg'))
+ {
+ $types[] = '2';
+ }
+ if (@function_exists('imagepng'))
+ {
+ $types[] = '3';
+ }
+ }
+ return $types;
+}
+
+// Create Thumbnail
+function create_thumbnail($source, $new_file, $mimetype)
+{
+ global $config;
+
+ $source = realpath($source);
+ $min_filesize = intval($config['img_min_thumb_filesize']);
+
+ $img_filesize = (file_exists($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($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 ($config['img_imagick'] != '')
+ {
+ if (is_array($size) && count($size) > 0)
+ {
+ @exec($config['img_imagick'] . ' -quality 75 -antialias -sample ' . $new_size[0] . 'x' . $new_size[1] . ' ' . $source . ' +profile "*" ' . $new_file);
+ if (file_exists($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' :
+ $image = imagecreatefromgif($source);
+ $new_image = imagecreate($new_size[0], $new_size[1]);
+ imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
+ imagegif($new_image, $new_file);
+ break;
+
+ case '2' :
+ $image = imagecreatefromjpeg($source);
+ $new_image = imagecreate($new_size[0], $new_size[1]);
+ imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
+ imagejpeg($new_image, $new_file, 90);
+ break;
+
+ case '3' :
+ $image = imagecreatefrompng($source);
+ $new_image = imagecreate($new_size[0], $new_size[1]);
+ imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);
+ imagepng($new_image, $new_file);
+ break;
+ }
+ }
+ }
+
+ if (!file_exists($new_file))
+ {
+ return FALSE;
+ }
+
+/* if (intval($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, 0666);
+
+ return TRUE;
+}
+
+
?>
\ No newline at end of file
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index 81f67f533d..4e04cec0e8 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -644,7 +644,7 @@ class parse_message
function emoticons($smile)
{
- global $db, $user;
+ global $db, $user, $phpbb_root_path;
$sql = "SELECT *
FROM " . SMILIES_TABLE;
@@ -656,7 +656,7 @@ class parse_message
do
{
$match[] = "#(?<=.\W|\W.|^\W)" . preg_quote($row['code'], '#') . "(?=.\W|\W.|\W$)#";
- $replace[] = '
';
+ $replace[] = '
';
}
while ($row = $db->sql_fetchrow($result));
@@ -672,33 +672,33 @@ class parse_message
$error = array();
$num_attachments = count($this->attachment_data);
- $this->filename_data['filecomment'] = ( isset($_POST['filecomment']) ) ? trim( strip_tags($_POST['filecomment'])) : '';
- $this->filename_data['filename'] = ( $_FILES['fileupload']['name'] != 'none' ) ? trim($_FILES['fileupload']['name']) : '';
+ $this->filename_data['filecomment'] = (isset($_POST['filecomment'])) ? trim( strip_tags($_POST['filecomment'])) : '';
+ $this->filename_data['filename'] = ($_FILES['fileupload']['name'] != 'none') ? trim($_FILES['fileupload']['name']) : '';
- $add_file = ( isset($_POST['add_file']) ) ? true : false;
- $delete_file = ( isset($_POST['delete_file']) ) ? true : false;
- $edit_comment = ( isset($_POST['edit_comment']) ) ? true : false;
+ $add_file = (isset($_POST['add_file'])) ? TRUE : FALSE;
+ $delete_file = (isset($_POST['delete_file'])) ? TRUE : FALSE;
+ $edit_comment = (isset($_POST['edit_comment'])) ? TRUE : FALSE;
- if ( $submit && ($mode == 'post' || $mode == 'reply' || $mode == 'edit') && $this->filename_data['filename'] != '')
+ if ($submit && ($mode == 'post' || $mode == 'reply' || $mode == 'edit') && $this->filename_data['filename'] != '')
{
- if ( $num_attachments < $config['max_attachments'] ) //|| $auth->acl_gets('m_', 'a_', $forum_id) )
+ if ($num_attachments < $config['max_attachments'] || $auth->acl_gets('m_', 'a_'))
{
$filedata = upload_attachment($this->filename_data['filename']);
$error = $filedata['error'];
- if (($filedata['post_attach']) && (!count($error)))
+ if ($filedata['post_attach'] && !count($error))
{
$new_entry = array(
- 'physical_filename' => $filedata['destination_filename'],
- 'comment' => $this->filename_data['filecomment'],
- 'real_filename' => $filedata['filename'],
- 'extension' => $filedata['extension'],
- 'mimetype' => $filedata['mimetype'],
- 'filesize' => $filedata['filesize'],
- 'filetime' => $filedata['filetime'],
- 'attach_id' => '-1',
- 'thumbnail' => $filedata['thumbnail']
+ 'physical_filename' => $filedata['destination_filename'],
+ 'comment' => $this->filename_data['filecomment'],
+ 'real_filename' => $filedata['filename'],
+ 'extension' => $filedata['extension'],
+ 'mimetype' => $filedata['mimetype'],
+ 'filesize' => $filedata['filesize'],
+ 'filetime' => $filedata['filetime'],
+ 'attach_id' => '-1',
+ 'thumbnail' => $filedata['thumbnail']
);
$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
@@ -712,7 +712,7 @@ class parse_message
// This is very relevant, because it could happen that the post got not submitted, but we do not
// know this circumstance here. We could be at the posting page or we could be redirected to the entered
// post. :)
- $filedata['post_attach'] = false;
+ $filedata['post_attach'] = FALSE;
}
}
else
@@ -748,11 +748,11 @@ class parse_message
// a quick way to reindex the array. :)
$this->attachment_data = array_merge($this->attachment_data);
}
- else if ( ($edit_comment) || ($add_file) || ($preview) )
+ else if ($edit_comment || $add_file || $preview)
{
if ($edit_comment)
{
- $actual_comment_list = ( isset($_POST['comment_list']) ) ? $_POST['comment_list'] : '';
+ $actual_comment_list = (isset($_POST['comment_list'])) ? $_POST['comment_list'] : '';
foreach ($actual_comment_list as $index => $entry)
{
@@ -760,7 +760,7 @@ class parse_message
}
}
- if ((($add_file) || ($preview) ) && ($this->filename_data['filename'] != '') )
+ if (($add_file || $preview) && $this->filename_data['filename'] != '')
{
if ($num_attachments < $config['max_attachments'] || $auth->acl_gets('m_', 'a_'))
{
@@ -771,15 +771,15 @@ class parse_message
if (!count($error))
{
$new_entry = array(
- 'physical_filename' => $filedata['destination_filename'],
- 'comment' => $this->filename_data['filecomment'],
- 'real_filename' => $filedata['filename'],
- 'extension' => $filedata['extension'],
- 'mimetype' => $filedata['mimetype'],
- 'filesize' => $filedata['filesize'],
- 'filetime' => $filedata['filetime'],
- 'attach_id' => '-1',
- 'thumbnail' => $filedata['thumbnail']
+ 'physical_filename' => $filedata['destination_filename'],
+ 'comment' => $this->filename_data['filecomment'],
+ 'real_filename' => $filedata['filename'],
+ 'extension' => $filedata['extension'],
+ 'mimetype' => $filedata['mimetype'],
+ 'filesize' => $filedata['filesize'],
+ 'filetime' => $filedata['filetime'],
+ 'attach_id' => '-1',
+ 'thumbnail' => $filedata['thumbnail']
);
$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
diff --git a/phpBB/language/en/lang_admin.php b/phpBB/language/en/lang_admin.php
index d0354d2677..af07bbf6bf 100644
--- a/phpBB/language/en/lang_admin.php
+++ b/phpBB/language/en/lang_admin.php
@@ -156,6 +156,7 @@ $lang = array_merge($lang, array(
'LOG_ACL_PRESET_DEL' => 'Deleted permission preset
» %s',
'LOG_ATTACH_EXT_ADD' => 'Added or edited attachment extension
» %s',
'LOG_ATTACH_EXT_DEL' => 'Removed attachment extension
» %s',
+ 'LOG_ATTACH_EXT_UPDATE' => 'Updated attachment extension
» %s',
'LOG_ATTACH_EXTGROUP_ADD' => 'Added or edited extension group
» %s',
'LOG_ATTACH_EXTGROUP_DEL' => 'Removed extension group
» %s',