1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-18 14:48:28 +01:00

- check for array [lang]

- admin_forums delete routine updated
- added extension groups per forum


git-svn-id: file:///svn/phpbb/trunk@4861 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2004-03-10 20:30:26 +00:00
parent c235dced70
commit 7487bfce48
20 changed files with 162 additions and 54 deletions

View File

@ -104,6 +104,7 @@ if ($mode == 'attach')
if ($submit)
{
/*
// Update Extension Group Filesizes
if ($config_name == 'max_filesize')
{
@ -119,7 +120,7 @@ if ($mode == 'attach')
$db->sql_query($sql);
}
}
*/
set_config($config_name, $new[$config_name]);
if (in_array($config_name, array('max_filesize', 'attachment_quota', 'max_filesize_pm')))
@ -300,6 +301,8 @@ if ($submit && $mode == 'ext_groups')
// 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 = isset($_REQUEST['allowed_forums']) ? array_map('intval', array_values($_REQUEST['allowed_forums'])) : array();
$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);
@ -308,13 +311,19 @@ if ($submit && $mode == 'ext_groups')
$max_filesize = 0;
}
if (!sizeof($allowed_forums))
{
$forum_select = false;
}
$group_ary = array(
'group_name' => $group_name,
'cat_id' => request_var('special_category', NONE_CAT),
'allow_group' => (isset($_REQUEST['allow_group'])) ? 1 : 0,
'download_mode' => request_var('download_mode', INLINE_LINK),
'upload_icon' => ($upload_icon == 'no_image') ? '' : $upload_icon,
'max_filesize' => $max_filesize
'max_filesize' => $max_filesize,
'allowed_forums'=> ($forum_select) ? serialize($allowed_forums) : ''
);
$sql = ($action == 'add') ? 'INSERT INTO ' . EXTENSION_GROUPS_TABLE . ' ' : 'UPDATE ' . EXTENSION_GROUPS_TABLE . ' SET ';
@ -784,6 +793,8 @@ if ($mode == 'ext_groups')
extract($db->sql_fetchrow($result));
$db->sql_freeresult($result);
$forum_ids = (!$allowed_forums) ? array() : unserialize(trim($allowed_forums));
case 'add':
if ($action == 'add')
@ -794,6 +805,7 @@ if ($mode == 'ext_groups')
$download_mode = 1;
$upload_icon = '';
$max_filesize = 0;
$forum_ids = array();
}
$extensions = array();
@ -956,6 +968,70 @@ if ($mode == 'ext_groups')
{
echo '<option' . ((!$row['group_id']) ? ' class="blue"' : '') . ' value="' . $row['extension_id'] . '"' . (($row['group_id'] == $group_id && $group_id) ? ' selected="selected"' : '') . '>' . $row['extension'] . '</option>';
}
?>
</select></td>
</tr>
<tr>
<td class="row1" valign="top"><b><?php echo $user->lang['ALLOWED_FORUMS']; ?></b>:<br /><span class="gensmall"><?php echo $user->lang['ALLOWED_FORUMS_EXPLAIN']; ?></span></td>
<td class="row2"><input type="radio" name="forum_select" value="0"<?php echo (!sizeof($forum_ids)) ? ' checked="checked"' : ''; ?> />&nbsp;<?php echo $user->lang['ALLOW_ALL_FORUMS']; ?>&nbsp;&nbsp;<input type="radio" name="forum_select" value="1"<?php echo (sizeof($forum_ids)) ? ' checked="checked"' : ''; ?> />&nbsp;<?php echo $user->lang['ALLOW_SELECTED_FORUMS']; ?><br /><br />
<select name="allowed_forums[]" multiple="true" size="8">
<?php
$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);
$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 = $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)
{
$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="blue"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
}
else
{
echo $holding . '<option value="' . $row['forum_id'] . '"' . (($row['forum_type'] == FORUM_POST) ? ' class="blue"' : '') . $selected . '>' . $padding . $row['forum_name'] . '</option>';
$holding = '';
}
}
$db->sql_freeresult($result);
unset($padding_store);
?>
</select></td>
</tr>
@ -1335,7 +1411,7 @@ function upload_file($post_id, $topic_id, $forum_id, $upload_dir, $filename)
$message_parser->filename_data['filecomment'] = '';
$message_parser->filename_data['filename'] = $upload_dir . '/' . $filename;
$filedata = upload_attachment($filename, true, $upload_dir . '/' . $filename);
$filedata = upload_attachment($forum_id, $filename, true, $upload_dir . '/' . $filename);
if ($filedata['post_attach'] && !sizeof($filedata['error']))
{
@ -1644,11 +1720,13 @@ function rewrite_extensions()
{
$extension = $row['extension'];
$extensions['_allowed_'][] = $extension;
$extensions[$extension]['display_cat'] = (int) $row['cat_id'];
$extensions[$extension]['download_mode']= (int) $row['download_mode'];
$extensions[$extension]['upload_icon'] = (string) $row['upload_icon'];
$extensions[$extension]['max_filesize'] = (int) $row['max_filesize'];
// Store allowed extensions forum wise
$extensions['_allowed_'][$extension] = (!$row['allowed_forums']) ? 0 : unserialize(trim($row['allowed_forums']));
}
$db->sql_freeresult($result);

View File

@ -1134,7 +1134,7 @@ function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = '
if ($action_posts == 'delete')
{
$log_action_posts = 'POSTS';
$errors += delete_forum_content($forum_id);
$errors = array_merge($errors, delete_forum_content($forum_id));
}
elseif ($action_posts == 'move')
{
@ -1160,7 +1160,7 @@ function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = '
$posts_to_name = $row['forum_name'];
unset($row);
$errors += move_forum_content($forum_id, $subforums_to_id);
$errors = array_merge($errors, move_forum_content($forum_id, $subforums_to_id));
}
}
}
@ -1180,7 +1180,7 @@ function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = '
foreach ($rows as $row)
{
$forum_ids[] = $row['forum_id'];
$errors += delete_forum_content($row['forum_id']);
$errors = array_merge($errors, delete_forum_content($row['forum_id']));
}
if (count($errors))
@ -1265,6 +1265,27 @@ function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = '
WHERE left_id > $right_id";
$db->sql_query($sql);
if (!is_array($forum_ids))
{
$forum_ids = array($forum_id);
}
// Delete forum ids from extension groups table
$sql = 'SELECT group_id, allowed_forums
FROM ' . EXTENSION_GROUPS_TABLE . "
WHERE allowed_forums <> ''";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$allowed_forums = unserialize(trim($row['allowed_forums']));
$allowed_forums = array_diff($allowed_forums, $forum_ids);
$sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
WHERE group_id = {$row['group_id']}";
$db->sql_query($sql);
}
$log_action = implode('_', array($log_action_posts, $log_action_forums));
switch ($log_action)
@ -1311,11 +1332,10 @@ function delete_forum_content($forum_id)
// Use delete_attachments('topic', $ids, false) here...
// Select then delete all attachments
$sql = 'SELECT d.physical_filename, d.thumbnail
FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_DESC_TABLE . ' d, ' . ATTACHMENTS_TABLE . " a
$sql = 'SELECT a.physical_filename, a.thumbnail
FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_TABLE . " a
WHERE p.forum_id = $forum_id
AND a.post_id = p.post_id
AND d.attach_id = a.attach_id";
AND a.post_id = p.post_id";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@ -1340,10 +1360,10 @@ function delete_forum_content($forum_id)
POLL_VOTES_TABLE => 'pv.post_id'
);
$sql = 'DELETE QUICK FROM ' . POSTS_TABLE . ', ' . ATTACHMENTS_DESC_TABLE;
$sql_using = "\nUSING " . POSTS_TABLE . ' p, ' . ATTACHMENTS_DESC_TABLE . ' d';
$sql_where = "\nWHERE p.forum_id = $forum_id\nAND d.attach_id = a.attach_id";
$sql_optimise = 'OPTIMIZE TABLE . ' . POSTS_TABLE . ', ' . ATTACHMENTS_DESC_TABLE;
$sql = 'DELETE QUICK FROM ' . POSTS_TABLE;
$sql_using = "\nUSING " . POSTS_TABLE . ' p';
$sql_where = "\nWHERE p.forum_id = $forum_id\n";
$sql_optimise = 'OPTIMIZE TABLE . ' . POSTS_TABLE;
foreach ($tables_ary as $table => $field)
{
@ -1368,11 +1388,10 @@ function delete_forum_content($forum_id)
default:
// Select then delete all attachments
$sql = 'SELECT d.attach_id, d.physical_filename, d.thumbnail
FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_TABLE . ' a, ' . ATTACHMENTS_DESC_TABLE . " d
$sql = 'SELECT a.attach_id, a.physical_filename, a.thumbnail
FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_TABLE . " a
WHERE p.forum_id = $forum_id
AND a.post_id = p.post_id
AND d.attach_id = a.attach_id";
AND a.post_id = p.post_id";
$result = $db->sql_query($sql);
$attach_ids = array();
@ -1391,10 +1410,7 @@ function delete_forum_content($forum_id)
if (count($attach_ids))
{
$attach_id_list = implode(',', array_unique($attach_ids));
$db->sql_query('DELETE FROM ' . ATTACHMENTS_TABLE . " WHERE attach_id IN ($attach_id_list)");
$db->sql_query('DELETE FROM ' . ATTACHMENTS_DESC_TABLE . " WHERE attach_id IN ($attach_id_list)");
unset($attach_ids, $attach_id_list);
}
@ -1404,13 +1420,13 @@ function delete_forum_content($forum_id)
SEARCH_MATCH_TABLE,
RATINGS_TABLE,
REPORTS_TABLE,
POLL_OPTIONS_TABLE,
POLL_VOTES_TABLE
),
'topic_id' => array(
TOPICS_WATCH_TABLE,
TOPICS_TRACK_TABLE
TOPICS_TRACK_TABLE,
POLL_OPTIONS_TABLE,
POLL_VOTES_TABLE
)
);
@ -1446,7 +1462,7 @@ function delete_forum_content($forum_id)
}
unset($ids, $id_list);
$table_ary = array('phpbb_forum_access', POSTS_TABLE, TOPICS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, ACL_GROUPS_TABLE, ACL_USERS_TABLE, MODERATOR_TABLE, LOG_TABLE);
$table_ary = array('phpbb_forum_access', TOPICS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, ACL_GROUPS_TABLE, ACL_USERS_TABLE, MODERATOR_TABLE, LOG_TABLE);
foreach ($table_ary as $table)
{
$db->sql_query("DELETE FROM $table WHERE forum_id = $forum_id");
@ -1456,7 +1472,7 @@ function delete_forum_content($forum_id)
switch (SQL_LAYER)
{
case 'mysql':
$sql = 'OPTIMIZE TABLE ' . POSTS_TABLE . ', ' . ATTACHMENTS_TABLE . ', ' . ATTACHMENTS_DESC_TABLE . ', ' . implode(', ', $tables_ary['post_id']) . ', ' . implode(', ', $tables_ary['topic_id']) . ', ' . implode(', ', $table_ary);
$sql = 'OPTIMIZE TABLE ' . POSTS_TABLE . ', ' . ATTACHMENTS_TABLE . ', ' . implode(', ', $tables_ary['post_id']) . ', ' . implode(', ', $tables_ary['topic_id']) . ', ' . implode(', ', $table_ary);
$db->sql_query($sql);
break;

View File

@ -73,7 +73,7 @@ $extensions = array();
obtain_attach_extensions($extensions);
// disallowed ?
if (!in_array($attachment['extension'], $extensions['_allowed_']))
if ((is_array($extensions['_allowed_'][$attachment['extension']]) && !in_array($row['forum_id'], $extensions['_allowed_'][$attachment['extension']])) || !isset($extensions['_allowed_'][$attachment['extension']]))
{
trigger_error(sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']));
}

View File

@ -883,11 +883,13 @@ function obtain_attach_extensions(&$extensions)
{
$extension = strtolower(trim($row['extension']));
$extensions['_allowed_'][] = $extension;
$extensions[$extension]['display_cat'] = (int) $row['cat_id'];
$extensions[$extension]['download_mode'] = (int) $row['download_mode'];
$extensions[$extension]['upload_icon'] = trim($row['upload_icon']);
$extensions[$extension]['max_filesize'] = (int) $row['max_filesize'];
// Store allowed extensions forum wise
$extensions['_allowed_'][$extension] = (!$row['allowed_forums']) ? 0 : unserialize(trim($row['allowed_forums']));
}
$db->sql_freeresult($result);

View File

@ -331,7 +331,7 @@ function display_forums($root_data = '', $display_moderators = TRUE)
}
// Display Attachments
function display_attachments($blockname, $attachment_data, &$update_count, $force_physical = false, $return = false)
function display_attachments($forum_id, $blockname, $attachment_data, &$update_count, $force_physical = false, $return = false)
{
global $extensions, $template, $cache, $attachment_tpl;
global $config, $user, $phpbb_root_path, $phpEx, $SID;
@ -409,11 +409,11 @@ function display_attachments($blockname, $attachment_data, &$update_count, $forc
$display_name = $attachment['real_filename'];
$comment = str_replace("\n", '<br />', censor_text($attachment['comment']));
$denied = FALSE;
$denied = false;
if (!in_array($attachment['extension'], $extensions['_allowed_']))
if ((is_array($extensions['_allowed_'][$attachment['extension']]) && !in_array($forum_id, $extensions['_allowed_'][$attachment['extension']])) || !isset($extensions['_allowed_'][$attachment['extension']]))
{
$denied = TRUE;
$denied = true;
$template_array['VAR'] = array('{L_DENIED}');
$template_array['VAL'] = array(sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension']));
@ -423,9 +423,16 @@ function display_attachments($blockname, $attachment_data, &$update_count, $forc
// Replace {L_*} lang strings
$tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $tpl);
$template->assign_block_vars($blockname, array(
'SHOW_ATTACHMENT' => $tpl)
);
if (!$return)
{
$template->assign_block_vars($blockname, array(
'DISPLAY_ATTACHMENT' => $tpl)
);
}
else
{
$return_tpl[] = $tpl;
}
}
if (!$denied)

View File

@ -162,7 +162,7 @@ function update_last_post_information($type, $id)
}
// Upload Attachment - filedata is generated here
function upload_attachment($filename, $local = false, $local_storage = '')
function upload_attachment($forum_id, $filename, $local = false, $local_storage = '')
{
global $auth, $user, $config, $db;
@ -188,7 +188,7 @@ function upload_attachment($filename, $local = false, $local_storage = '')
obtain_attach_extensions($extensions);
// Check Extension
if (!in_array($filedata['extension'], $extensions['_allowed_']))
if ((is_array($extensions['_allowed_'][$filedata['extension']]) && !in_array($forum_id, $extensions['_allowed_'][$filedata['extension']])) || !isset($extensions['_allowed_'][$filedata['extension']]))
{
$filedata['error'][] = sprintf($user->lang['DISALLOWED_EXTENSION'], $filedata['extension']);
$filedata['post_attach'] = false;

View File

@ -706,7 +706,7 @@ class parse_message
// Parse Attachments
function parse_attachments($mode, $post_id, $submit, $preview, $refresh)
{
global $config, $auth, $user;
global $config, $auth, $user, $forum_id;
global $_FILES, $_POST;
$error = array();
@ -723,7 +723,7 @@ class parse_message
{
if ($num_attachments < $config['max_attachments'] || $auth->acl_gets('m_', 'a_'))
{
$filedata = upload_attachment($this->filename_data['filename']);
$filedata = upload_attachment($forum_id, $this->filename_data['filename']);
$error = $filedata['error'];
@ -807,7 +807,7 @@ class parse_message
{
if ($num_attachments < $config['max_attachments'] || $auth->acl_gets('m_', 'a_'))
{
$filedata = upload_attachment($this->filename_data['filename']);
$filedata = upload_attachment($forum_id, $this->filename_data['filename']);
$error = array_merge($error, $filedata['error']);

View File

@ -171,6 +171,7 @@ CREATE TABLE phpbb_extension_groups (
download_mode tinyint(1) UNSIGNED DEFAULT '1' NOT NULL,
upload_icon varchar(100) DEFAULT '' NOT NULL,
max_filesize int(20) DEFAULT '0' NOT NULL,
allowed_forums text NOT NULL,
PRIMARY KEY (group_id)
);

View File

@ -12,7 +12,7 @@
// -------------------------------------------------------------
// DO NOT CHANGE
if (empty($lang))
if (empty($lang) || !is_array($lang))
{
$lang = array();
}
@ -1757,6 +1757,10 @@ $lang += array(
'SUCCESS_EXTENSION_GROUP_EDIT' => 'Extension Group successfully updated',
'EXTENSION_GROUP_EXIST' => 'The Extension Group %s already exist',
'EXTENSION_GROUP_DELETED' => 'Extension Group successfully deleted',
'ALLOWED_FORUMS' => 'Allowed Forums',
'ALLOWED_FORUMS_EXPLAIN' => 'Able to post the assigned extensions at the following forums',
'ALLOW_ALL_FORUMS' => 'Allow All Forums',
'ALLOW_SELECTED_FORUMS' => 'Only Forums selected below',
'CAT_IMAGES' => 'Images',
'CAT_WM_FILES' => 'Win Media Streams',

View File

@ -12,7 +12,7 @@
// -------------------------------------------------------------
// DO NOT CHANGE
if (empty($lang))
if (empty($lang) || !is_array($lang))
{
$lang = array();
}
@ -89,7 +89,7 @@ $lang += array(
'EMAIL' => 'Email',
'EMAIL_ADDRESS' => 'Email address',
'EMPTY_SUBJECT' => 'You must specify a subject when posting a new topic.',
'EXTENSION_DISABLED_AFTER_POSTING' => 'The extension <b>%s</b> has been deactivated and can no longer be displayed.',
'EXTENSION_DISABLED_AFTER_POSTING' => 'The extension <b>%s</b> has been deactivated and can no longer be displayed',
'FAQ' => 'FAQ',
'FILENAME' => 'Filename',

View File

@ -12,7 +12,7 @@
// -------------------------------------------------------------
// DO NOT CHANGE
if (empty($lang))
if (empty($lang) || !is_array($lang))
{
$lang = array();
}

View File

@ -12,7 +12,7 @@
// -------------------------------------------------------------
// DO NOT CHANGE
if (empty($lang))
if (empty($lang) || !is_array($lang))
{
$lang = array();
}

View File

@ -12,7 +12,7 @@
// -------------------------------------------------------------
// DO NOT CHANGE
if (empty($lang))
if (empty($lang) || !is_array($lang))
{
$lang = array();
}

View File

@ -12,7 +12,7 @@
// -------------------------------------------------------------
// DO NOT CHANGE
if (empty($lang))
if (empty($lang) || !is_array($lang))
{
$lang = array();
}

View File

@ -12,7 +12,7 @@
// -------------------------------------------------------------
// DO NOT CHANGE
if (empty($lang))
if (empty($lang) || !is_array($lang))
{
$lang = array();
}

View File

@ -12,7 +12,7 @@
// -------------------------------------------------------------
// DO NOT CHANGE
if (empty($lang))
if (empty($lang) || !is_array($lang))
{
$lang = array();
}

View File

@ -12,7 +12,7 @@
// -------------------------------------------------------------
// DO NOT CHANGE
if (empty($lang))
if (empty($lang) || !is_array($lang))
{
$lang = array();
}

View File

@ -12,7 +12,7 @@
// -------------------------------------------------------------
// DO NOT CHANGE
if (empty($lang))
if (empty($lang) || !is_array($lang))
{
$lang = array();
}

View File

@ -826,7 +826,7 @@ if (!sizeof($error) && $preview)
$extensions = $update_count = array();
$template->assign_var('S_HAS_ATTACHMENTS', true);
display_attachments('attachment', $message_parser->attachment_data, $update_count, true);
display_attachments($forum_id, 'attachment', $message_parser->attachment_data, $update_count, true);
}
}

View File

@ -1179,7 +1179,7 @@ for ($i = 0; $i < count($post_list); ++$i)
if (sizeof($attachments[$row['post_id']]))
{
$tpl = &$attachments[$row['post_id']];
$tpl = display_attachments(NULL, $tpl, $update_count, false, true);
$tpl = display_attachments($forum_id, NULL, $tpl, $update_count, false, true);
$tpl_size = sizeof($tpl);
$unset_tpl = array();