aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorJosh Woody <a_jelly_doughnut@phpbb.com>2010-06-20 15:01:26 -0500
committerJoas Schilling <nickvergessen@gmx.de>2012-08-29 17:49:38 +0200
commitc32d76080605f843bb23e9a608c368d4b5dc55d8 (patch)
treed179da9973265432acf4c5ab11eefc5229653b65 /phpBB/includes
parent244f6e2ddc7818125edc273be1d83a5298ce6589 (diff)
downloadforums-c32d76080605f843bb23e9a608c368d4b5dc55d8.tar
forums-c32d76080605f843bb23e9a608c368d4b5dc55d8.tar.gz
forums-c32d76080605f843bb23e9a608c368d4b5dc55d8.tar.bz2
forums-c32d76080605f843bb23e9a608c368d4b5dc55d8.tar.xz
forums-c32d76080605f843bb23e9a608c368d4b5dc55d8.zip
[feature/soft-delete] I told you I was going to rename the class!
Rename topic_visibility class to phpbb_visibility. Also a bit of work to the class itself, mostly cleanup and adding the comments that I'd previously written. PHPBB3-9657
Diffstat (limited to 'phpBB/includes')
-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
4 files changed, 68 insertions, 29 deletions
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;