aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/feed.php10
-rw-r--r--phpBB/includes/class_visibility.php87
-rw-r--r--phpBB/includes/functions_posting.php6
-rw-r--r--phpBB/includes/mcp/mcp_forum.php2
-rw-r--r--phpBB/includes/mcp/mcp_topic.php2
-rw-r--r--phpBB/posting.php4
-rw-r--r--phpBB/search.php2
-rw-r--r--phpBB/viewforum.php4
-rw-r--r--phpBB/viewtopic.php10
9 files changed, 83 insertions, 44 deletions
diff --git a/phpBB/feed.php b/phpBB/feed.php
index a806cdd608..89ee5a3bbe 100644
--- a/phpBB/feed.php
+++ b/phpBB/feed.php
@@ -760,7 +760,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base
FROM ' . TOPICS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_ids) . '
AND topic_moved_id = 0
- AND ' . topic_visibility::get_visibility_sql_global('topic') . '
+ AND ' . phpbb_visibility::get_visibility_sql_global('topic') . '
ORDER BY topic_last_post_time DESC';
$result = $db->sql_query_limit($sql, $this->num_items);
@@ -795,7 +795,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base
),
),
'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . '
- AND ' . topic_visibility::get_visibility_sql('post', array(), 'p.') . '
+ AND ' . phpbb_visibility::get_visibility_sql('post', array(), 'p.') . '
AND p.post_time >= ' . $min_post_time . '
AND u.user_id = p.poster_id',
'ORDER_BY' => 'p.post_time DESC',
@@ -892,7 +892,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base
FROM ' . TOPICS_TABLE . '
WHERE forum_id = ' . $this->forum_id . '
AND topic_moved_id = 0
- AND ' . topic_visibility::get_visibility_sql('topic', $this->forum_id) . '
+ AND ' . phpbb_visibility::get_visibility_sql('topic', $this->forum_id) . '
ORDER BY topic_last_post_time DESC';
$result = $db->sql_query_limit($sql, $this->num_items);
@@ -919,7 +919,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base
USERS_TABLE => 'u',
),
'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . '
- AND ' . topic_visibility::get_visibility_sql('post', $this->forum_id, 'p.') . '
+ AND ' . phpbb_visibility::get_visibility_sql('post', $this->forum_id, 'p.') . '
AND p.post_time >= ' . $min_post_time . '
AND p.poster_id = u.user_id',
'ORDER_BY' => 'p.post_time DESC',
@@ -1025,7 +1025,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base
USERS_TABLE => 'u',
),
'WHERE' => 'p.topic_id = ' . $this->topic_id . '
- AND ' . topic_visibility::get_visibility_sql('post', $this->forum_id, 'p.') . '
+ AND ' . phpbb_visibility::get_visibility_sql('post', $this->forum_id, 'p.') . '
AND p.poster_id = u.user_id',
'ORDER_BY' => 'p.post_time DESC',
);
diff --git a/phpBB/includes/class_visibility.php b/phpBB/includes/class_visibility.php
index 28fc584b76..46f188d833 100644
--- a/phpBB/includes/class_visibility.php
+++ b/phpBB/includes/class_visibility.php
@@ -1,7 +1,35 @@
<?php
+/**
+*
+* @package phpbb
+* @version $Id$
+* @copyright (c) 2010 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
-class topic_visibility
+/**
+* phpbb_visibility
+* Handle fetching and setting the visibility for topics and posts
+* @package phpbb
+*/
+class phpbb_visibility
{
+ /**
+ * Create topic/post visibility SQL for a given forum ID
+ * @param $mode string - either "topic" or "post"
+ * @param $forum_id int - current forum ID
+ * @param $table_alias string - Table alias to prefix in SQL queries
+ * @return string with the appropriate combination SQL logic for topic/post_visibility
+ */
public function get_visibility_sql($mode, $forum_id, $table_alias = '')
{
global $auth, $db, $user;
@@ -31,6 +59,13 @@ class topic_visibility
return $clause;
}
+ /**
+ * Fetch visibility SQL for all forums on the board.
+ * @param $mode string - either "topic" or "post"
+ * @param $exclude_forum_ids - int array -
+ * @param $table_alias string - Table alias to prefix in SQL queries
+ * @return string with the appropriate combination SQL logic for topic/post_visibility
+ */
public function get_visibility_sql_global($mode, $exclude_forum_ids = array(), $table_alias = '')
{
global $auth, $db, $user;
@@ -70,6 +105,14 @@ class topic_visibility
return $where_sql;
}
+ /**
+ * Description: Allows approving (which is akin to undeleting), unapproving (!) or soft deleting an entire topic.
+ * Calls set_post_visibility as needed.
+ * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED}
+ * @param $topic_id - int - topic ID to act on
+ * @param $forum_id - int - forum ID where $topic_id resides
+ * @return bool true = success, false = fail
+ */
public function set_topic_visibility($visibility, $topic_id, $forum_id)
{
global $db;
@@ -78,31 +121,32 @@ class topic_visibility
WHERE topic_id = ' . (int) $topic_id;
$db->sql_query($sql);
- if ($visibility != ITEM_APPROVED)
- {
- $sql = 'SELECT post_id FROM ' . POSTS_TABLE . '
- WHERE topic_id = ' . (int) $topic_id;
- $result = $db->sql_query($sql);
-
- $status = true;
- while ($row = $db->sql_fetchrow($result))
- {
- $status = min($status, self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true));
- }
- }
- else
- {
- // TOOD: figure out which posts we actually care about
- $status = self::set_post_visibility($visibility, 0, false, $forum_id, true, true);
- }
+ // if we're approving, disapproving, or deleteing a topic, assume that
+ // we are adjusting _all_ posts in that topic.
+ $status = self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true);
+
return $status;
}
+ /**
+ * @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED}
+ * @param $post_id - int - the post ID to act on
+ * @param $topic_id - int - forum where $post_id is found
+ * @param $forum_id - int - forum ID where $topic_id resides
+ * @param $is_starter - bool - is this the first post of the topic
+ * @param $is_latest - bool - is this the last post of the topic
+ */
public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest)
{
global $db;
+ // if we're changing the starter, we need to change the rest of the topic
+ if ($is_starter && !$is_latest)
+ {
+ return self::set_topic_visibility($visibility, $topic_id, $forum_id);
+ }
+
if ($post_id)
{
$where_sql = 'post_id = ' . (int) $post_id;
@@ -121,17 +165,12 @@ class topic_visibility
WHERE ' . $where_sql;
$db->sql_query($sql);
+ // Sync the first/last topic information if needed
if ($is_starter || $is_latest)
{
update_post_information('topic', $topic_id, false);
update_post_information('forum', $forum_id, false);
}
-
- // if we're changing the starter, we need to change the rest of the topic
- if ($is_starter && !$is_latest)
- {
- self::set_topic_visibility($visibility, $topic_id, $forum_id);
- }
}
}
?>
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index 2f51200b48..12448ea0ce 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -993,7 +993,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id
$sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p' . "
WHERE p.topic_id = $topic_id
- AND " . topic_visibility::get_visibility_sql('post', $forum_id, 'p.') . '
+ AND " . phpbb_visibility::get_visibility_sql('post', $forum_id, 'p.') . '
' . (($mode == 'post_review') ? " AND p.post_id > $cur_post_id" : '') . '
' . (($mode == 'post_review_edit') ? " AND p.post_id = $cur_post_id" : '') . '
ORDER BY p.post_time ';
@@ -1542,7 +1542,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
$sql = 'SELECT MAX(post_id) as last_post_id
FROM ' . POSTS_TABLE . "
WHERE topic_id = $topic_id
- AND " . topic_visibility::get_visibility_sql('post', $forum_id);
+ AND " . phpbb_visibility::get_visibility_sql('post', $forum_id);
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
@@ -1555,7 +1555,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data)
$sql = 'SELECT post_id
FROM ' . POSTS_TABLE . "
WHERE topic_id = $topic_id
- AND " . topic_visibility::get_visibility_sql('post', $forum_id) . '
+ AND " . phpbb_visibility::get_visibility_sql('post', $forum_id) . '
AND post_time > ' . $data['post_time'] . '
ORDER BY post_time ASC';
$result = $db->sql_query_limit($sql, 1);
diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php
index 48b9c7c2d3..90c0224b40 100644
--- a/phpBB/includes/mcp/mcp_forum.php
+++ b/phpBB/includes/mcp/mcp_forum.php
@@ -154,7 +154,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
$sql = 'SELECT t.topic_id
FROM ' . TOPICS_TABLE . ' t
WHERE t.forum_id = ' . $forum_id . '
- ' . topic_visibility::get_visibility_sql('topic', $forum_id, 't.') . "
+ ' . phpbb_visibility::get_visibility_sql('topic', $forum_id, 't.') . "
$limit_time_sql
ORDER BY t.topic_type DESC, $sort_order_sql";
$result = $db->sql_query_limit($sql, $topics_per_page, $start);
diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php
index f6fd12f0c4..5c25da7a9d 100644
--- a/phpBB/includes/mcp/mcp_topic.php
+++ b/phpBB/includes/mcp/mcp_topic.php
@@ -146,7 +146,7 @@ function mcp_topic_view($id, $mode, $action)
FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
WHERE ' . (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . '
p.topic_id = ' . $topic_id . '
- AND ' . topic_visibility::get_visibility_sql('post', $topic_info['forum_id'], 'p.') . '
+ AND ' . phpbb_visibility::get_visibility_sql('post', $topic_info['forum_id'], 'p.') . '
AND p.poster_id = u.user_id ' .
$limit_time_sql . '
ORDER BY ' . $sort_order_sql;
diff --git a/phpBB/posting.php b/phpBB/posting.php
index 273499c1e4..30b897c068 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -87,7 +87,7 @@ switch ($mode)
FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f
WHERE t.topic_id = $topic_id
AND f.forum_id = t.forum_id
- AND " . topic_visibility::get_visibility_sql('topic', $forum_id, 't.');
+ AND " . phpbb_visibility::get_visibility_sql('topic', $forum_id, 't.');
break;
case 'quote':
@@ -115,7 +115,7 @@ switch ($mode)
AND t.topic_id = p.topic_id
AND u.user_id = p.poster_id
AND f.forum_id = t.forum_id
- AND " . topic_visibility::get_visibility_sql('topic', $forum_id, 't.');
+ AND " . phpbb_visibility::get_visibility_sql('topic', $forum_id, 't.');
break;
case 'smilies':
diff --git a/phpBB/search.php b/phpBB/search.php
index 7bf941f127..9ff3c2e027 100644
--- a/phpBB/search.php
+++ b/phpBB/search.php
@@ -266,7 +266,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
$m_approve_fid_sql = ' AND p.post_approved = 1';
}
*/
- $m_approve_fid_sql = ' AND ' . topic_visibility::get_visibility_sql_global('post', $ex_fid_ary, 'p.');
+ $m_approve_fid_sql = ' AND ' . phpbb_visibility::get_visibility_sql_global('post', $ex_fid_ary, 'p.');
if ($reset_search_forum)
{
diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php
index 2c29d92cd8..c775d33631 100644
--- a/phpBB/viewforum.php
+++ b/phpBB/viewforum.php
@@ -241,7 +241,7 @@ if ($sort_days)
AND (topic_last_post_time >= $min_post_time
OR topic_type = " . POST_ANNOUNCE . '
OR topic_type = ' . POST_GLOBAL . ')
- AND ' . topic_visibility::get_visibility_sql('topic', $forum_id);
+ AND ' . phpbb_visibility::get_visibility_sql('topic', $forum_id);
$result = $db->sql_query($sql);
$topics_count = (int) $db->sql_fetchfield('num_topics');
$db->sql_freeresult($result);
@@ -353,7 +353,7 @@ $sql_array = array(
'LEFT_JOIN' => array(),
);
-$sql_approved = 'AND ' . topic_visibility::get_visibility_sql('topic', $forum_id, 't.');
+$sql_approved = 'AND ' . phpbb_visibility::get_visibility_sql('topic', $forum_id, 't.');
if ($user->data['is_registered'])
{
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index 282c23cd70..b6c47211f7 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -83,7 +83,7 @@ if ($view && !$post_id)
$sql = 'SELECT post_id, topic_id, forum_id
FROM ' . POSTS_TABLE . "
WHERE topic_id = $topic_id
- AND " . topic_visibility::get_visibility_sql('post', $forum_id) . "
+ AND " . phpbb_visibility::get_visibility_sql('post', $forum_id) . "
AND post_time > $topic_last_read
AND forum_id = $forum_id
ORDER BY post_time ASC";
@@ -137,7 +137,7 @@ if ($view && !$post_id)
WHERE forum_id = ' . $row['forum_id'] . "
AND topic_moved_id = 0
AND topic_last_post_time $sql_condition {$row['topic_last_post_time']}
- AND" . topic_visibility::get_visibility_sql('topic', $row['forum_id']) . "
+ AND" . phpbb_visibility::get_visibility_sql('topic', $row['forum_id']) . "
ORDER BY topic_last_post_time $sql_ordering";
$result = $db->sql_query_limit($sql, 1);
$row = $db->sql_fetchrow($result);
@@ -277,7 +277,7 @@ if ($post_id)
$sql = 'SELECT COUNT(p.post_id) AS prev_posts
FROM ' . POSTS_TABLE . " p
WHERE p.topic_id = {$topic_data['topic_id']}
- " . topic_visibility::get_visibility_sql('post', $forum_id, 'p');
+ " . phpbb_visibility::get_visibility_sql('post', $forum_id, 'p');
if ($sort_dir == 'd')
{
@@ -408,7 +408,7 @@ if ($sort_days)
FROM ' . POSTS_TABLE . "
WHERE topic_id = $topic_id
AND post_time >= $min_post_time
- AND " . topic_visibility::get_visibility_sql('post', $forum_id);
+ AND " . phpbb_visibility::get_visibility_sql('post', $forum_id);
$result = $db->sql_query($sql);
$total_posts = (int) $db->sql_fetchfield('num_posts');
$db->sql_freeresult($result);
@@ -944,7 +944,7 @@ $i = $i_total = 0;
$sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p' . (($join_user_sql[$sort_key]) ? ', ' . USERS_TABLE . ' u': '') . "
WHERE p.topic_id = $topic_id
- AND " . topic_visibility::get_visibility_sql('post', $forum_id, 'p.') . "
+ AND " . phpbb_visibility::get_visibility_sql('post', $forum_id, 'p.') . "
" . (($join_user_sql[$sort_key]) ? 'AND u.user_id = p.poster_id': '') . "
$limit_posts_time
ORDER BY $sql_sort_order";