aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/db/mysql.php2
-rw-r--r--phpBB/includes/functions_admin.php267
-rw-r--r--phpBB/includes/functions_display.php8
-rw-r--r--phpBB/includes/message_parser.php2
-rw-r--r--phpBB/includes/ucp/ucp_main.php4
5 files changed, 110 insertions, 173 deletions
diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php
index f5f89e3d1e..82eef2290b 100644
--- a/phpBB/includes/db/mysql.php
+++ b/phpBB/includes/db/mysql.php
@@ -381,7 +381,7 @@ class sql_db
// DEBUG
function sql_report($mode, $query = '')
{
- if (empty($_GET['explain']))
+ if (empty($_REQUEST['explain']))
{
return;
}
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 9eac5d44ce..3faef1a8de 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -431,7 +431,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = TRUE)
}
unset($table_ary);
- delete_attachments($post_ids);
+ delete_attachments('post', $post_ids, FALSE);
$db->sql_transaction('commit');
@@ -466,215 +466,152 @@ function delete_posts($where_type, $where_ids, $auto_sync = TRUE)
}
// Delete Attachments
-function delete_attachments($post_id_array = -1, $attach_id_array = -1, $page = 'post', $user_id = -1)
+// mode => (post, topic, attach, user)
+// ids => (post_ids, topic_ids, attach_ids, user_ids)
+// resync => set this to false if you are deleting posts or topics...
+function delete_attachments($mode, $ids, $resync = TRUE)
{
global $db;
- if ($post_id_array == -1 && $attach_id_array == -1 && $page == -1)
+ if (is_array($ids))
{
- return;
+ $ids = array_unique($ids);
}
-
- // Generate Array, if it's not an array
- if ($post_id_array == -1 && $attach_id_array != -1)
+
+ if (!sizeof($ids))
{
- $post_id_array = array();
+ return false;
+ }
- if (!is_array($attach_id_array))
- {
- $attach_id_array = (strstr($attach_id_array, ',')) ? explode(',', str_replace(', ', ',', $attach_id_array)) : array((int) $attach_id_array);
- }
-
- // Get the post_ids to fill the array
- $sql = 'SELECT ' . (($page == 'privmsgs') ? 'privmsgs_id' : 'post_id') . ' as id
- FROM ' . ATTACHMENTS_TABLE . '
- WHERE attach_id IN (' . implode(', ', $attach_id_array) . ')
- GROUP BY id';
- $result = $db->sql_query($sql);
+ $sql_id = ($mode == 'user') ? 'poster_id' : (($mode == 'post') ? 'post_id' : (($mode == 'topic') ? 'topic_id' : 'attach_id'));
+
+ $post_ids = $topic_ids = $physical = array();
- if (!($row = $db->sql_fetchrow($result)))
+ // Collect post and topics ids for later use
+ if ($mode == 'attach' || $mode == 'user' || ($mode == 'topic' && $resync))
+ {
+ $sql = 'SELECT post_id, topic_id, physical_filename, thumbnail
+ FROM ' . ATTACHMENTS_TABLE . '
+ WHERE ' . $sql_id . ' IN (' . implode(', ', $ids) . ')';
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
{
- return;
+ $post_ids[] = $row['post_id'];
+ $topic_ids[] = $row['topic_id'];
+ $physical[] = array('filename' => $row['physical_filename'], 'thumbnail' => $row['thumbnail']);
}
+ $db->sql_freeresult($result);
+ }
- do
+ if ($mode == 'post')
+ {
+ $sql = 'SELECT topic_id, physical_filename, thumbnail
+ FROM ' . ATTACHMENTS_TABLE . '
+ WHERE post_id IN (' . implode(', ', $ids) . ')';
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
{
- $post_id_array[] = $row['id'];
+ $topic_ids[] = $row['topic_id'];
+ $physical[] = array('filename' => $row['physical_filename'], 'thumbnail' => $row['thumbnail']);
}
- while ($row = $db->sql_fetchrow($result));
$db->sql_freeresult($result);
}
-
- if (!is_array($post_id_array))
+
+ // Delete attachments
+ $db->sql_query('DELETE FROM ' . ATTACHMENTS_TABLE . ' WHERE ' . $sql_id . ' IN (' . implode(', ', $ids) . ')');
+ $num_deleted = $db->sql_affectedrows();
+
+ // Delete attachments from filesystem
+ foreach ($physical as $file_ary)
{
- if (trim($post_id_array) == '')
+ phpbb_unlink($file_ary['filename'], 'file');
+ if ($file_ary['thumbnail'])
{
- return;
+ phpbb_unlink($file_ary['filename'], 'thumbnail');
}
+ }
- $post_id_array = (strstr($post_id_array, ',')) ? explode(',', str_replace(', ', ',', $attach_id_array)) : array((int) $post_id_array);
+ if ($mode == 'topic' && !$resync)
+ {
+ return $num_deleted;
}
-
- if (!count($post_id_array))
+
+ if ($mode == 'post')
{
- return;
+ $post_ids = $ids;
}
+ unset($ids);
+
+ $post_ids = array_unique($post_ids);
+ $topic_ids = array_unique($topic_ids);
- // First of all, determine the post id and attach_id
- if ($attach_id_array == -1)
+ // Update post indicators
+ if ($mode == 'post' || $mode == 'topic')
{
- $attach_id_array = array();
+ $db->sql_query('UPDATE ' . POSTS_TABLE . '
+ SET post_attachment = 0
+ WHERE post_id IN (' . implode(', ', $post_ids) . ')');
+ }
- // Get the attach_ids to fill the array
- $sql = 'SELECT attach_id
- FROM ' . ATTACHMENTS_TABLE . '
- WHERE ' . (($page == 'privmsgs') ? 'privmsgs_id' : 'post_id') . ' IN (' . implode(', ', $post_id_array) . ')
- GROUP BY attach_id';
- $result = $db->sql_query($sql);
+ if ($mode == 'user' || $mode == 'attach')
+ {
+ $remaining = array();
- if (!($row = $db->sql_fetchrow($result)))
+ $sql = 'SELECT post_id
+ FROM ' . ATTACHMENTS_TABLE . '
+ WHERE post_id IN (' . implode(', ', $post_ids) . ')';
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
{
- return;
+ $remaining[] = $row['post_id'];
}
+ $db->sql_fetchrow($result);
- do
+ $unset_ids = array_diff($post_ids, $remaining);
+ if (sizeof($delete_ids))
{
- $attach_id_array[] = $row['attach_id'];
+ $db->sql_query('UPDATE ' . POSTS_TABLE . '
+ SET post_attachment = 0
+ WHERE post_id IN (' . implode(', ', $unset_ids) . ')');
}
- while ($row = $db->sql_fetchrow($result));
- $db->sql_freeresult($result);
- }
-
- if (!is_array($attach_id_array))
- {
- $attach_id_array = (strstr($post_id_array, ',')) ? explode(',', str_replace(', ', ',', $attach_id_array)) : array((int) $attach_id_array);
}
- if (!count($attach_id_array))
+ // Update topic indicator
+ if ($mode == 'topic')
{
- return;
+ $db->sql_query('UPDATE ' . TOPICS_TABLE . '
+ SET topic_attachment = 0
+ WHERE topic_id IN (' . implode(', ', $topic_ids) . ')');
}
- $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
- WHERE attach_id IN (' . implode(', ', $attach_id_array) . ')
- AND post_id IN (' . implode(', ', $post_id_array) . ')';
- $db->sql_query($sql);
-
- foreach ($attach_id_array as $attach_id)
+ if ($mode == 'post' || $mode == 'user' || $mode == 'attach')
{
- $sql = 'SELECT attach_id
- FROM ' . ATTACHMENTS_TABLE . "
- WHERE attach_id = $attach_id";
- $select_result = $db->sql_query($sql);
+ $remaining = array();
- if (!is_array($db->sql_fetchrow($select_result)))
- {
- $sql = 'SELECT attach_id, physical_filename, thumbnail
- FROM ' . ATTACHMENTS_DESC_TABLE . "
- WHERE attach_id = $attach_id";
- $result = $db->sql_query($sql);
-
- // delete attachments
- while ($row = $db->sql_fetchrow($result))
- {
- phpbb_unlink($row['physical_filename'], 'file');
- if ($row['thumbnail'])
- {
- phpbb_unlink($row['physical_filename'], 'thumbnail');
- }
-
- $sql = 'DELETE FROM ' . ATTACHMENTS_DESC_TABLE . '
- WHERE attach_id = ' . $row['attach_id'];
- $db->sql_query($sql);
- }
- $db->sql_freeresult($result);
- }
- $db->sql_freeresult($select_result);
- }
-
- // Now Sync the Topic/PM
- if ($page == 'privmsgs')
- {
- foreach ($post_id_array as $privmsgs_id)
- {
- $sql = 'SELECT attach_id
+ $sql = 'SELECT topic_id
FROM ' . ATTACHMENTS_TABLE . '
- WHERE privmsgs_id = ' . $privmsgs_id;
- $select_result = $db->sql_query($sql);
-
- if (!is_array($db->sql_fetchrow($select_result)))
- {
- $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
- SET privmsgs_attachment = 0
- WHERE privmsgs_id = ' . $privmsgs_id;
- $db->sql_query($sql);
- }
- $db->sql_freeresult($select_result);
- }
- }
- else
- {
- $sql = 'SELECT topic_id
- FROM ' . POSTS_TABLE . '
- WHERE post_id IN (' . implode(', ', $post_id_array) . ')
- GROUP BY topic_id';
+ WHERE topic_id IN (' . implode(', ', $topic_ids) . ')';
$result = $db->sql_query($sql);
-
+
while ($row = $db->sql_fetchrow($result))
{
- $topic_id = $row['topic_id'];
-
- $sql = 'SELECT post_id
- FROM ' . POSTS_TABLE . "
- WHERE topic_id = $topic_id
- GROUP BY post_id";
- $result2 = $db->sql_query($sql);
-
- $post_ids = array();
-
- while ($post_row = $db->sql_fetchrow($result2))
- {
- $post_ids[] = $post_row['post_id'];
- }
- $db->sql_freeresult($result2);
+ $remaining[] = $row['topic_id'];
+ }
+ $db->sql_fetchrow($result);
- if (count($post_ids))
- {
- $post_id_sql = implode(', ', $post_ids);
-
- $sql = 'SELECT attach_id
- FROM ' . ATTACHMENTS_TABLE . "
- WHERE post_id IN ($post_id_sql)";
- $select_result = $db->sql_query_limit($sql, 1);
- $set_id = (!is_array($db->sql_fetchrow($select_result))) ? 0 : 1;
- $db->sql_freeresult($select_result);
-
- $sql = 'UPDATE ' . TOPICS_TABLE . "
- SET topic_attachment = $set_id
- WHERE topic_id = $topic_id";
- $db->sql_query($sql);
-
- foreach ($post_ids as $post_id)
- {
- $sql = 'SELECT attach_id
- FROM ' . ATTACHMENTS_TABLE . "
- WHERE post_id = $post_id";
- $select_result = $db->sql_query_limit($sql, 1);
- $set_id = (!is_array($db->sql_fetchrow($select_result))) ? 0 : 1;
- $db->sql_freeresult($select_result);
-
- $sql = 'UPDATE ' . POSTS_TABLE . "
- SET post_attachment = $set_id
- WHERE post_id = $post_id";
- $db->sql_query($sql);
- }
- }
+ $unset_ids = array_diff($topic_ids, $remaining);
+ if (sizeof($unset_ids))
+ {
+ $db->sql_query('UPDATE ' . TOPICS_TABLE . '
+ SET topic_attachment = 0
+ WHERE topic_id IN (' . implode(', ', $unset_ids) . ')');
}
- $db->sql_freeresult($result);
}
-
- // TODO
- // Return number of deleted attachments
+
+ return $num_deleted;
}
function delete_topic_shadows($max_age, $forum_id = '', $auto_sync = TRUE)
diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php
index 17ba765b8f..d96f2cb9c9 100644
--- a/phpBB/includes/functions_display.php
+++ b/phpBB/includes/functions_display.php
@@ -292,6 +292,8 @@ function display_attachments($attachment_data, &$update_count, $force_physical =
global $extensions, $template;
global $config, $user, $phpbb_root_path, $phpEx, $SID, $censors;
+ $upload_dir = ($config['upload_dir'][0] == '/' || ($config['upload_dir'][0] != '/' && $config['upload_dir'][1] == ':')) ? $config['upload_dir'] : $phpbb_root_path . $config['upload_dir'];
+
if (empty($censors))
{
$censors = array();
@@ -304,14 +306,12 @@ function display_attachments($attachment_data, &$update_count, $force_physical =
obtain_attach_extensions($extensions);
}
- $update_count = array();
-
foreach ($attachment_data as $attachment)
{
// Some basics...
$attachment['extension'] = strtolower(trim($attachment['extension']));
- $filename = $config['upload_dir'] . '/' . $attachment['physical_filename'];
- $thumbnail_filename = $config['upload_dir'] . '/thumbs/t_' . $attachment['physical_filename'];
+ $filename = $upload_dir . '/' . $attachment['physical_filename'];
+ $thumbnail_filename = $upload_dir . '/thumbs/t_' . $attachment['physical_filename'];
$upload_image = '';
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index 92557fbb78..2de8b424c3 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -746,7 +746,7 @@ class parse_message
}
else
{
- delete_attachments($post_id, intval($this->attachment_data[$index]['attach_id']));
+ delete_attachments('attach', array(intval($this->attachment_data[$index]['attach_id'])));
}
unset($this->attachment_data[$index]);
diff --git a/phpBB/includes/ucp/ucp_main.php b/phpBB/includes/ucp/ucp_main.php
index ccaf4beca7..bcaabdceb8 100644
--- a/phpBB/includes/ucp/ucp_main.php
+++ b/phpBB/includes/ucp/ucp_main.php
@@ -133,7 +133,7 @@ class ucp_main extends module
'LAST_POST_IMG' => $last_post_img,
'NEWEST_POST_IMG' => $newest_post_img,
'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
- 'ATTACH_ICON_IMG' => ($auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_attach', '') : '',
+ 'ATTACH_ICON_IMG' => ($auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_attach', '') : '',
'S_ROW_COUNT' => $i,
'S_USER_POSTED' => (!empty($row['mark_type'])) ? true : false,
@@ -487,7 +487,7 @@ class ucp_main extends module
'LAST_POST_IMG' => $last_post_img,
'NEWEST_POST_IMG' => $newest_post_img,
'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
- 'ATTACH_ICON_IMG' => ($auth->acl_get('f_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_attach', '') : '',
+ 'ATTACH_ICON_IMG' => ($auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_attach', '') : '',
'S_ROW_COUNT' => $i++,
'S_USER_POSTED' => (!empty($row['mark_type'])) ? true : false,