aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions_admin.php
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2006-08-12 13:14:39 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2006-08-12 13:14:39 +0000
commit8405f0d324fd42bec2f775986e69e5d8cf548ebf (patch)
treeefa8caf14f78d67ece434c39e294532adbd20a8b /phpBB/includes/functions_admin.php
parent0c6bfcf4c715b64d8c971adb6077018994fe5ce9 (diff)
downloadforums-8405f0d324fd42bec2f775986e69e5d8cf548ebf.tar
forums-8405f0d324fd42bec2f775986e69e5d8cf548ebf.tar.gz
forums-8405f0d324fd42bec2f775986e69e5d8cf548ebf.tar.bz2
forums-8405f0d324fd42bec2f775986e69e5d8cf548ebf.tar.xz
forums-8405f0d324fd42bec2f775986e69e5d8cf548ebf.zip
sql_in_set changes
git-svn-id: file:///svn/phpbb/trunk@6271 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions_admin.php')
-rw-r--r--phpBB/includes/functions_admin.php171
1 files changed, 107 insertions, 64 deletions
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 0eec9a5114..3b039d110d 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -206,7 +206,7 @@ function group_select_options($group_id, $exclude_ids = false)
{
global $db, $user, $config;
- $exclude_sql = ($exclude_ids !== false && sizeof($exclude_ids)) ? 'WHERE group_id NOT IN (' . implode(', ', array_map('intval', $exclude_ids)) . ')' : '';
+ $exclude_sql = ($exclude_ids !== false && sizeof($exclude_ids)) ? 'WHERE ' . $db->sql_in_set('group_id', array_map('intval', $exclude_ids), true) : '';
$sql_and = (!$config['coppa_enable']) ? (($exclude_sql) ? ' AND ' : ' WHERE ') . "group_name NOT IN ('INACTIVE_COPPA', 'REGISTERED_COPPA')" : '';
$sql = 'SELECT group_id, group_name, group_type
@@ -376,7 +376,7 @@ function move_topics($topic_ids, $forum_id, $auto_sync = true)
}
$sql = 'DELETE FROM ' . TOPICS_TABLE . '
- WHERE topic_moved_id IN (' . implode(', ', $topic_ids) . ')
+ WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids) . '
AND forum_id = ' . $forum_id;
$db->sql_query($sql);
@@ -384,7 +384,7 @@ function move_topics($topic_ids, $forum_id, $auto_sync = true)
{
$sql = 'SELECT DISTINCT forum_id
FROM ' . TOPICS_TABLE . '
- WHERE topic_id IN (' . implode(', ', $topic_ids) . ')';
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -399,7 +399,7 @@ function move_topics($topic_ids, $forum_id, $auto_sync = true)
{
$sql = "UPDATE $table
SET forum_id = $forum_id
- WHERE topic_id IN (" . implode(', ', $topic_ids) . ')';
+ WHERE " . $db->sql_in_set('topic_id', $topic_ids);
$db->sql_query($sql);
}
unset($table_ary);
@@ -428,7 +428,7 @@ function move_posts($post_ids, $topic_id, $auto_sync = true)
$sql = 'SELECT DISTINCT topic_id, forum_id
FROM ' . POSTS_TABLE . '
- WHERE post_id IN (' . implode(', ', $post_ids) . ')';
+ WHERE ' . $db->sql_in_set('post_id', $post_ids);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -452,12 +452,12 @@ function move_posts($post_ids, $topic_id, $auto_sync = true)
$sql = 'UPDATE ' . POSTS_TABLE . '
SET forum_id = ' . $forum_row['forum_id'] . ", topic_id = $topic_id
- WHERE post_id IN (" . implode(', ', $post_ids) . ')';
+ WHERE " . $db->sql_in_set('post_id', $post_ids);
$db->sql_query($sql);
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
SET topic_id = $topic_id, in_message = 0
- WHERE post_msg_id IN (" . implode(', ', $post_ids) . ')';
+ WHERE " . $db->sql_in_set('post_msg_id', $post_ids);
$db->sql_query($sql);
if ($auto_sync)
@@ -487,6 +487,10 @@ function delete_topics($where_type, $where_ids, $auto_sync = true)
{
$where_ids = array_unique($where_ids);
}
+ else
+ {
+ $where_ids = array($where_ids);
+ }
if (!sizeof($where_ids))
{
@@ -498,8 +502,8 @@ function delete_topics($where_type, $where_ids, $auto_sync = true)
);
$sql = 'SELECT topic_id, forum_id
- FROM ' . TOPICS_TABLE . "
- WHERE $where_type " . ((!is_array($where_ids)) ? "= $where_ids" : 'IN (' . implode(', ', $where_ids) . ')');
+ FROM ' . TOPICS_TABLE . '
+ WHERE ' . $db->sql_in_set($where_type, $where_ids);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -516,8 +520,6 @@ function delete_topics($where_type, $where_ids, $auto_sync = true)
return $return;
}
- $sql_where = ' IN (' . implode(', ', $topic_ids) . ')';
-
$db->sql_transaction('begin');
$table_ary = array(TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, POLL_VOTES_TABLE, POLL_OPTIONS_TABLE, TOPICS_WATCH_TABLE, TOPICS_TABLE);
@@ -525,13 +527,13 @@ function delete_topics($where_type, $where_ids, $auto_sync = true)
foreach ($table_ary as $table)
{
$sql = "DELETE FROM $table
- WHERE topic_id $sql_where";
+ WHERE " . $db->sql_in_set('topic_id', $topic_ids);
$db->sql_query($sql);
}
unset($table_ary);
$sql = 'DELETE FROM ' . TOPICS_TABLE . '
- WHERE topic_moved_id' . $sql_where;
+ WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids);
$db->sql_query($sql);
$db->sql_transaction('commit');
@@ -558,8 +560,12 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =
{
$where_ids = array_unique($where_ids);
}
+ else
+ {
+ $where_ids = array($where_ids);
+ }
- if (empty($where_ids))
+ if (!sizeof($where_ids))
{
return false;
}
@@ -567,8 +573,8 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =
$post_ids = $topic_ids = $forum_ids = $post_counts = array();
$sql = 'SELECT post_id, poster_id, post_postcount, topic_id, forum_id
- FROM ' . POSTS_TABLE . "
- WHERE $where_type " . ((!is_array($where_ids)) ? '= ' . (int) $where_ids : 'IN (' . implode(', ', array_map('intval', $where_ids)) . ')');
+ FROM ' . POSTS_TABLE . '
+ WHERE ' . $db->sql_in_set($where_type, array_map('intval', $where_ids));
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -590,8 +596,6 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =
return false;
}
- $sql_where = implode(', ', $post_ids);
-
$db->sql_transaction('begin');
$table_ary = array(POSTS_TABLE, REPORTS_TABLE);
@@ -599,7 +603,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =
foreach ($table_ary as $table)
{
$sql = "DELETE FROM $table
- WHERE post_id IN ($sql_where)";
+ WHERE " . $db->sql_in_set('post_id', $post_ids);
$db->sql_query($sql);
}
unset($table_ary);
@@ -693,7 +697,7 @@ function delete_attachments($mode, $ids, $resync = true)
{
$sql = 'SELECT post_msg_id as post_id, topic_id, physical_filename, thumbnail, filesize
FROM ' . ATTACHMENTS_TABLE . '
- WHERE ' . $sql_id . ' IN (' . implode(', ', $ids) . ')';
+ WHERE ' . $db->sql_in_set($sql_id, $ids);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -709,7 +713,7 @@ function delete_attachments($mode, $ids, $resync = true)
{
$sql = 'SELECT topic_id, physical_filename, thumbnail, filesize
FROM ' . ATTACHMENTS_TABLE . '
- WHERE post_msg_id IN (' . implode(', ', $ids) . ')
+ WHERE ' . $db->sql_in_set('post_msg_id', $ids) . '
AND in_message = 0';
$result = $db->sql_query($sql);
@@ -723,7 +727,7 @@ function delete_attachments($mode, $ids, $resync = true)
// Delete attachments
$sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
- WHERE ' . $sql_id . ' IN (' . implode(', ', $ids) . ')';
+ WHERE ' . $db->sql_in_set($sql_id, $ids);
$db->sql_query($sql);
$num_deleted = $db->sql_affectedrows();
@@ -771,7 +775,7 @@ function delete_attachments($mode, $ids, $resync = true)
{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_attachment = 0
- WHERE post_id IN (' . implode(', ', $post_ids) . ')';
+ WHERE ' . $db->sql_in_set('post_id', $post_ids);
$db->sql_query($sql);
}
@@ -781,7 +785,7 @@ function delete_attachments($mode, $ids, $resync = true)
$sql = 'SELECT post_msg_id
FROM ' . ATTACHMENTS_TABLE . '
- WHERE post_msg_id IN (' . implode(', ', $post_ids) . ')
+ WHERE ' . $db->sql_in_set('post_msg_id', $post_ids) . '
AND in_message = 0';
$result = $db->sql_query($sql);
@@ -797,7 +801,7 @@ function delete_attachments($mode, $ids, $resync = true)
{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_attachment = 0
- WHERE post_id IN (' . implode(', ', $unset_ids) . ')';
+ WHERE ' . $db->sql_in_set('post_id', $unset_ids);
$db->sql_query($sql);
}
@@ -805,7 +809,7 @@ function delete_attachments($mode, $ids, $resync = true)
$sql = 'SELECT post_msg_id
FROM ' . ATTACHMENTS_TABLE . '
- WHERE post_msg_id IN (' . implode(', ', $post_ids) . ')
+ WHERE ' . $db->sql_in_set('post_msg_id', $post_ids) . '
AND in_message = 1';
$result = $db->sql_query($sql);
@@ -821,7 +825,7 @@ function delete_attachments($mode, $ids, $resync = true)
{
$sql = 'UPDATE ' . PRIVMSGS_TABLE . '
SET message_attachment = 0
- WHERE msg_id IN (' . implode(', ', $unset_ids) . ')';
+ WHERE ' . $db->sql_in_set('msg_id', $unset_ids);
$db->sql_query($sql);
}
}
@@ -834,7 +838,7 @@ function delete_attachments($mode, $ids, $resync = true)
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_attachment = 0
- WHERE topic_id IN (' . implode(', ', $topic_ids) . ')';
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
$db->sql_query($sql);
}
@@ -844,7 +848,7 @@ function delete_attachments($mode, $ids, $resync = true)
$sql = 'SELECT topic_id
FROM ' . ATTACHMENTS_TABLE . '
- WHERE topic_id IN (' . implode(', ', $topic_ids) . ')';
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
@@ -859,7 +863,7 @@ function delete_attachments($mode, $ids, $resync = true)
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_attachment = 0
- WHERE topic_id IN (' . implode(', ', $unset_ids) . ')';
+ WHERE ' . $db->sql_in_set('topic_id', $unset_ids);
$db->sql_query($sql);
}
}
@@ -873,7 +877,7 @@ function delete_attachments($mode, $ids, $resync = true)
*/
function delete_topic_shadows($max_age, $forum_id = '', $auto_sync = true)
{
- $where = (is_array($forum_id)) ? 'AND t.forum_id IN (' . implode(', ', array_map('intval', $forum_id)) . ')' : (($forum_id) ? 'AND t.forum_id = ' . (int) $forum_id : '');
+ $where = (is_array($forum_id)) ? 'AND ' . $db->sql_in_set('t.forum_id', array_map('intval', $forum_id)) : (($forum_id) ? 'AND t.forum_id = ' . (int) $forum_id : '');
switch (SQL_LAYER)
{
@@ -905,7 +909,7 @@ function delete_topic_shadows($max_age, $forum_id = '', $auto_sync = true)
if (sizeof($topic_ids))
{
$sql = 'DELETE FROM ' . TOPICS_TABLE . '
- WHERE topic_id IN (' . implode(',', $topic_ids) . ')';
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
$db->sql_query($sql);
}
break;
@@ -932,13 +936,13 @@ function update_posted_info(&$topic_ids)
// First of all, let us remove any posted information for these topics
$sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
- WHERE topic_id IN (' . implode(', ', $topic_ids) . ')';
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
$db->sql_query($sql);
// Now, let us collect the user/topic combos for rebuilding the information
$sql = 'SELECT poster_id, topic_id
FROM ' . POSTS_TABLE . '
- WHERE topic_id IN (' . implode(', ', $topic_ids) . ')
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
AND poster_id <> ' . ANONYMOUS . '
GROUP BY poster_id, topic_id';
$result = $db->sql_query($sql);
@@ -1058,7 +1062,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
// Limit the topics/forums we are syncing, use specific topic/forum IDs.
// $where_type contains the field for the where clause (forum_id, topic_id)
- $where_sql = 'WHERE ' . $mode{0} . ".$where_type IN (" . implode(', ', $where_ids) . ')';
+ $where_sql = 'WHERE ' . $db->sql_in_set($mode{0} . '.' . $where_type, $where_ids);
$where_sql_and = $where_sql . "\n\tAND";
}
}
@@ -1070,7 +1074,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
}
// $where_type contains the field for the where clause (forum_id, topic_id)
- $where_sql = 'WHERE ' . $mode{0} . ".$where_type IN (" . implode(', ', $where_ids) . ')';
+ $where_sql = 'WHERE ' . $db->sql_in_set($mode{0} . '.' . $where_type, $where_ids);
$where_sql_and = $where_sql . "\n\tAND";
}
@@ -1108,7 +1112,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
}
$sql = 'DELETE FROM ' . TOPICS_TABLE . '
- WHERE topic_id IN (' . implode(', ', $topic_id_ary) . ')';
+ WHERE ' . $db->sql_in_set('topic_id', $topic_id_ary);
$db->sql_query($sql);
break;
@@ -1147,7 +1151,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_approved = 1 - topic_approved
- WHERE topic_id IN (' . implode(', ', $topic_ids) . ')';
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
$db->sql_query($sql);
break;
}
@@ -1174,7 +1178,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$sql = 'SELECT DISTINCT(post_id)
FROM ' . REPORTS_TABLE . '
- WHERE post_id IN (' . implode(', ', $post_ids) . ')
+ WHERE ' . $db->sql_in_set('post_id', $post_ids) . '
AND report_closed = 0';
$result = $db->sql_query($sql);
@@ -1203,7 +1207,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_reported = 1 - post_reported
- WHERE post_id IN (' . implode(', ', $post_ids) . ')';
+ WHERE ' . $db->sql_in_set('post_id', $post_ids);
$db->sql_query($sql);
}
break;
@@ -1245,7 +1249,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_reported = 1 - topic_reported
- WHERE topic_id IN (' . implode(', ', $topic_ids) . ')';
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
$db->sql_query($sql);
}
break;
@@ -1271,7 +1275,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
$sql = 'SELECT DISTINCT(post_msg_id)
FROM ' . ATTACHMENTS_TABLE . '
- WHERE post_msg_id IN (' . implode(', ', $post_ids) . ')
+ WHERE ' . $db->sql_in_set('post_msg_id', $post_ids) . '
AND in_message = 0';
$result = $db->sql_query($sql);
@@ -1300,7 +1304,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_attachment = 1 - post_attachment
- WHERE post_id IN (' . implode(', ', $post_ids) . ')';
+ WHERE ' . $db->sql_in_set('post_id', $post_ids);
$db->sql_query($sql);
}
break;
@@ -1342,7 +1346,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_attachment = 1 - topic_attachment
- WHERE topic_id IN (' . implode(', ', $topic_ids) . ')';
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
$db->sql_query($sql);
}
break;
@@ -1385,7 +1389,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
// 2: Get topic counts for each forum
$sql = 'SELECT forum_id, topic_approved, COUNT(topic_id) AS forum_topics
FROM ' . TOPICS_TABLE . '
- WHERE forum_id IN (' . implode(', ', $forum_ids) . ')
+ WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . '
GROUP BY forum_id, topic_approved';
$result = $db->sql_query($sql);
@@ -1404,7 +1408,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
// 3: Get post count and last_post_id for each forum
$sql = 'SELECT forum_id, COUNT(post_id) AS forum_posts, MAX(post_id) AS last_post_id
FROM ' . POSTS_TABLE . '
- WHERE forum_id IN (' . implode(', ', $forum_ids) . ')
+ WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . '
AND post_approved = 1
GROUP BY forum_id';
$result = $db->sql_query($sql);
@@ -1425,7 +1429,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
{
$sql = 'SELECT p.post_id, p.poster_id, p.post_time, p.post_username, u.username
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
- WHERE p.post_id IN (' . implode(', ', $post_ids) . ')
+ WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
AND p.poster_id = u.user_id';
$result = $db->sql_query($sql);
@@ -1491,15 +1495,21 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
break;
case 'topic':
- $topic_data = $post_ids = $approved_unapproved_ids = $resync_forums = $delete_topics = $delete_posts = array();
+ $topic_data = $post_ids = $approved_unapproved_ids = $resync_forums = $delete_topics = $delete_posts = $moved_topics = array();
- $sql = 'SELECT t.topic_id, t.forum_id, t.topic_approved, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_last_post_id, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time
+ $sql = 'SELECT t.topic_id, t.forum_id, t.topic_moved_id, t.topic_approved, ' . (($sync_extra) ? 't.topic_attachment, t.topic_reported, ' : '') . 't.topic_poster, t.topic_time, t.topic_replies, t.topic_replies_real, t.topic_first_post_id, t.topic_first_poster_name, t.topic_last_post_id, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time
FROM ' . TOPICS_TABLE . " t
$where_sql";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
+ if ($row['topic_moved_id'])
+ {
+ $moved_topics[] = $row['topic_id'];
+ continue;
+ }
+
$topic_id = (int) $row['topic_id'];
$topic_data[$topic_id] = $row;
$topic_data[$topic_id]['replies_real'] = -1;
@@ -1603,9 +1613,34 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
unset($delete_topics, $delete_topic_ids);
}
+ // Make sure shadow topics do link to existing topics
+ if (sizeof($moved_topics))
+ {
+ $delete_topics = array();
+
+ $sql = 'SELECT t1.topic_id, t1.topic_moved_id
+ FROM ' . TOPICS_TABLE . ' t1
+ LEFT JOIN ' . TOPICS_TABLE . ' t2 ON (t2.topic_id = t1.topic_moved_id)
+ WHERE ' . $db->sql_in_set('t1.topic_id', $moved_topics) . '
+ AND t2.topic_id IS NULL';
+ $result = $db->sql_query($sql);
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $delete_topics[] = $row['topic_id'];
+ }
+ $db->sql_freeresult($result);
+
+ if (sizeof($delete_topics))
+ {
+ delete_topics('topic_id', $delete_topics, false);
+ }
+ unset($delete_topics);
+ }
+
$sql = 'SELECT p.post_id, p.topic_id, p.post_approved, p.poster_id, p.post_username, p.post_time, u.username
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
- WHERE p.post_id IN (' . implode(',', $post_ids) . ')
+ WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
AND u.user_id = p.poster_id';
$result = $db->sql_query($sql);
@@ -1639,7 +1674,7 @@ function sync($mode, $where_type = '', $where_ids = '', $resync_parents = false,
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_approved = 1 - topic_approved
- WHERE topic_id IN (' . implode(', ', $approved_unapproved_ids) . ')';
+ WHERE ' . $db->sql_in_set('topic_id', $approved_unapproved_ids);
$db->sql_query($sql);
}
unset($approved_unapproved_ids);
@@ -1726,9 +1761,18 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync
{
global $db;
- $sql_forum = (is_array($forum_id)) ? ' IN (' . implode(', ', array_map('intval', $forum_id)) . ')' : ' = ' . (int) $forum_id;
+ if (!is_array($forum_id))
+ {
+ $forum_id = array($forum_id);
+ }
+
+ if (!sizeof($forum_id))
+ {
+ return;
+ }
$sql_and = '';
+
if (!($prune_flags & 4))
{
$sql_and .= ' AND topic_type <> ' . POST_ANNOUNCE;
@@ -1750,8 +1794,8 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync
}
$sql = 'SELECT topic_id
- FROM ' . TOPICS_TABLE . "
- WHERE forum_id $sql_forum
+ FROM ' . TOPICS_TABLE . '
+ WHERE ' . $db->sql_in_set('forum_id', $forum_id) . "
AND poll_start = 0
$sql_and";
$result = $db->sql_query($sql);
@@ -1766,8 +1810,8 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync
if ($prune_flags & 2)
{
$sql = 'SELECT topic_id
- FROM ' . TOPICS_TABLE . "
- WHERE forum_id $sql_forum
+ FROM ' . TOPICS_TABLE . '
+ WHERE ' . $db->sql_in_set('forum_id', $forum_id) . "
AND poll_start > 0
AND poll_last_vote < $prune_date
$sql_and";
@@ -1934,7 +1978,7 @@ function cache_moderators()
AND ((a.auth_setting = ' . ACL_NEVER . ' AND r.auth_setting IS NULL)
OR r.auth_setting = ' . ACL_NEVER . ')
AND a.group_id = ug.group_id
- AND ug.user_id IN (' . implode(', ', $ug_id_ary) . ")
+ AND ' . $db->sql_in_set('ug.user_id', $ug_id_ary) . "
AND ug.user_pending = 0
AND o.auth_option LIKE 'm\_%'",
));
@@ -1954,7 +1998,7 @@ function cache_moderators()
// Get usernames...
$sql = 'SELECT user_id, username
FROM ' . USERS_TABLE . '
- WHERE user_id IN (' . implode(', ', array_keys($hold_ary)) . ')';
+ WHERE ' . $db->sql_in_set('user_id', array_keys($hold_ary));
$result = $db->sql_query($sql);
$usernames_ary = array();
@@ -1989,7 +2033,7 @@ function cache_moderators()
// Make sure not hidden or special groups are involved...
$sql = 'SELECT group_name, group_id, group_type
FROM ' . GROUPS_TABLE . '
- WHERE group_id IN (' . implode(', ', $ug_id_ary) . ')';
+ WHERE ' . $db->sql_in_set('group_id', $ug_id_ary);
$result = $db->sql_query($sql);
$groupnames_ary = array();
@@ -2082,7 +2126,7 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id
}
else if (is_array($forum_id))
{
- $sql_forum = 'AND l.forum_id IN (' . implode(', ', array_map('intval', $forum_id)) . ')';
+ $sql_forum = 'AND ' . $db->sql_in_set('l.forum_id', array_map('intval', $forum_id));
}
else
{
@@ -2174,7 +2218,7 @@ function view_log($mode, &$log, &$log_count, $limit = 0, $offset = 0, $forum_id
// although it's also used to determine if the topic still exists in the database
$sql = 'SELECT topic_id, forum_id
FROM ' . TOPICS_TABLE . '
- WHERE topic_id IN (' . implode(', ', array_map('intval', $topic_id_list)) . ')';
+ WHERE ' . $db->sql_in_set('topic_id', array_map('intval', $topic_id_list));
$result = $db->sql_query($sql);
$default_forum_id = 0;
@@ -2472,9 +2516,8 @@ function tidy_warnings()
{
$db->sql_transaction('begin');
- $sql_where = ' IN (' . implode(', ', $warning_list) . ')';
- $sql = 'DELETE FROM ' . WARNINGS_TABLE . "
- WHERE warning_id $sql_where";
+ $sql = 'DELETE FROM ' . WARNINGS_TABLE . '
+ WHERE ' . $db->sql_in_set('warning_id', $warning_list);
$db->sql_query($sql);
foreach ($user_list as $user_id => $value)