diff options
author | Josh Woody <a_jelly_doughnut@phpbb.com> | 2010-06-18 08:29:53 -0500 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2012-08-29 17:49:37 +0200 |
commit | 244f6e2ddc7818125edc273be1d83a5298ce6589 (patch) | |
tree | 68a9034279bbf0fb20a3d5bb7a480f8342374efd /phpBB/includes | |
parent | b8c55291ed7ed86565be2bc651bf20eb1a9ed4dd (diff) | |
download | forums-244f6e2ddc7818125edc273be1d83a5298ce6589.tar forums-244f6e2ddc7818125edc273be1d83a5298ce6589.tar.gz forums-244f6e2ddc7818125edc273be1d83a5298ce6589.tar.bz2 forums-244f6e2ddc7818125edc273be1d83a5298ce6589.tar.xz forums-244f6e2ddc7818125edc273be1d83a5298ce6589.zip |
[feature/soft-delete] Correct some mistakes in e8d47
Notably: Uncomment the die() in create_schema_files, and add the class that makes everything tick.
PHPBB3-9657
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/class_visibility.php | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/phpBB/includes/class_visibility.php b/phpBB/includes/class_visibility.php new file mode 100644 index 0000000000..28fc584b76 --- /dev/null +++ b/phpBB/includes/class_visibility.php @@ -0,0 +1,137 @@ +<?php + +class topic_visibility +{ + public function get_visibility_sql($mode, $forum_id, $table_alias = '') + { + global $auth, $db, $user; + + $status_ary = array(ITEM_APPROVED); + if ($auth->acl_get('m_approve', $forum_id)) + { + $status_ary[] = ITEM_UNAPPROVED; + } + + if ($auth->acl_get('m_restore', $forum_id)) + { + $status_ary[] = ITEM_DELETED; + } + + $clause = $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); + + // only allow the user to view deleted posts he himself made + if ($auth->acl_get('f_restore', $forum_id)) + { + $clause = 'AND (' . $clause . " + OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . " + AND {$table_alias}poster_id = " . $user->data['user_id'] . '))'; + + } + + return $clause; + } + + public function get_visibility_sql_global($mode, $exclude_forum_ids = array(), $table_alias = '') + { + global $auth, $db, $user; + + // users can always see approved posts + $where_sql = "($table_alias{$mode}_visibility = " . ITEM_APPROVED; + + // in set notation: {approve_forums} = {m_approve} - {exclude_forums} + $approve_forums = array_diff(array_keys($auth->acl_getf('m_approve', true)), $exclude_forum_ids); + if (sizeof($approve_forums)) + { + // users can view unapproved topics in certain forums. specify them. + $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_UNAPPROVED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $approve_forums) . ')'; + } + + // this is exactly the same logic as for approve forums, above + $restore_forums = array_diff(array_keys($auth->acl_getf('m_restore', true)), $exclude_forum_ids); + if (sizeof($restore_forums)) + { + $where_sql .= " OR ($table_alias{$mode}_visibility = " . ITEM_DELETED . ' + AND ' . $db->sql_in_set($table_alias . 'forum_id', $restore_forums) . ')'; + } + + // we also allow the user to view deleted posts he himself made + $user_restore_forums = array_diff(array_keys($auth->acl_getf('f_restore', true)), $exclude_forum_ids); + if (sizeof($user_restore_forums)) + { + // specify the poster ID, the visibility type, and the forums we're interested in + $where_sql .= " OR ($table_alias{$mode}poster_id = " . $user->data['user_id'] . " + AND $table_alias{$mode}_visibility = " . ITEM_DELETED . " + AND " . $db->sql_in_set($table_alias . 'forum_id', $user_restore_forums) . ')'; + } + + $where_sql .= ')'; + + return $where_sql; + } + + public function set_topic_visibility($visibility, $topic_id, $forum_id) + { + global $db; + + $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_visibility = ' . (int) $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); + } + + return $status; + } + + public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest) + { + global $db; + + if ($post_id) + { + $where_sql = 'post_id = ' . (int) $post_id; + } + else if ($topic_id) + { + $where_sql = 'topic_id = ' . (int) $topic_id; + } + else + { + // throw new MissingArgumentsException(); <-- a nice idea + return false; + } + + $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_visibility = ' . (int) $visibility . ' + WHERE ' . $where_sql; + $db->sql_query($sql); + + 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); + } + } +} +?> |