From 1bcce756337bb1db81da4f8f3e2f938578ab30b2 Mon Sep 17 00:00:00 2001 From: brunoais Date: Sun, 8 Feb 2015 23:52:27 +0000 Subject: [PATCH 1/6] [ticket/13592] Allow changing get_visibility_sql's result PHPBB3-13592 --- phpBB/phpbb/content_visibility.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index c8516d6c85..03ffc0ceaf 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -143,12 +143,32 @@ class content_visibility */ public function get_visibility_sql($mode, $forum_id, $table_alias = '') { + $where_sql = ''; + + /** + * Allow changing the result of calling get_visibility_sql + * + * @event core.phpbb_content_visibility_get_forums_visibility_before + * @var string where_sql Extra visibility conditions. It must end with either an SQL "AND" or an "OR" + * @var string mode Either "topic" or "post" depending on the query this is being used in + * @var array forum_id The forum ids which the post/topic is from + * @var string table_alias Table alias to prefix in SQL queries + * @since 3.1.4-RC1 + */ + $vars = array( + 'where_sql', + 'mode', + 'forum_id', + 'table_alias', + ); + extract($this->phpbb_dispatcher->trigger_event('core.phpbb_content_visibility_get_forums_visibility_before', compact($vars))); + if ($this->auth->acl_get('m_approve', $forum_id)) { - return '1 = 1'; + return $where_sql . '1 = 1'; } - return $table_alias . $mode . '_visibility = ' . ITEM_APPROVED; + return $where_sql . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED; } /** From 8a4df90dac51a6232d9fccbd8ec1144cfabd83c0 Mon Sep 17 00:00:00 2001 From: brunoais Date: Mon, 9 Feb 2015 08:42:37 +0000 Subject: [PATCH 2/6] [ticket/13592] Allow changing get_visibility_sql's result PHPBB3-13592 --- phpBB/phpbb/content_visibility.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index 03ffc0ceaf..8db8bcc3be 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -148,10 +148,10 @@ class content_visibility /** * Allow changing the result of calling get_visibility_sql * - * @event core.phpbb_content_visibility_get_forums_visibility_before + * @event core.phpbb_content_get_visibility_sql_visibility_before * @var string where_sql Extra visibility conditions. It must end with either an SQL "AND" or an "OR" * @var string mode Either "topic" or "post" depending on the query this is being used in - * @var array forum_id The forum ids which the post/topic is from + * @var array forum_id The forum id in which the search is made. * @var string table_alias Table alias to prefix in SQL queries * @since 3.1.4-RC1 */ @@ -161,7 +161,7 @@ class content_visibility 'forum_id', 'table_alias', ); - extract($this->phpbb_dispatcher->trigger_event('core.phpbb_content_visibility_get_forums_visibility_before', compact($vars))); + extract($this->phpbb_dispatcher->trigger_event('core.phpbb_content_get_visibility_sql_visibility_before', compact($vars))); if ($this->auth->acl_get('m_approve', $forum_id)) { From bb7d294190fec9f0ef83787d6ae5a57266ad7091 Mon Sep 17 00:00:00 2001 From: brunoais Date: Mon, 9 Feb 2015 10:44:12 +0000 Subject: [PATCH 3/6] [ticket/13592] Allow full override of get_visibility_sql() PHPBB3-13592 --- phpBB/phpbb/content_visibility.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index 8db8bcc3be..a324c6b8b5 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -145,6 +145,7 @@ class content_visibility { $where_sql = ''; + $get_visibility_sql_overwrite = false; /** * Allow changing the result of calling get_visibility_sql * @@ -153,6 +154,9 @@ class content_visibility * @var string mode Either "topic" or "post" depending on the query this is being used in * @var array forum_id The forum id in which the search is made. * @var string table_alias Table alias to prefix in SQL queries + * @var mixed get_visibility_sql_overwrite If a string, forces the function to return get_forums_visibility_sql_overwrite after executing the event + * If false, get_visibility_sql continues normally + * It must be either boolean or string * @since 3.1.4-RC1 */ $vars = array( @@ -160,9 +164,15 @@ class content_visibility 'mode', 'forum_id', 'table_alias', + 'get_visibility_sql_overwrite', ); extract($this->phpbb_dispatcher->trigger_event('core.phpbb_content_get_visibility_sql_visibility_before', compact($vars))); + if ($get_visibility_sql_overwrite !== false) + { + return $get_visibility_sql_overwrite; + } + if ($this->auth->acl_get('m_approve', $forum_id)) { return $where_sql . '1 = 1'; From 6111f5fa74843888485201f69750d09605660678 Mon Sep 17 00:00:00 2001 From: brunoais Date: Mon, 9 Feb 2015 11:56:53 +0000 Subject: [PATCH 4/6] [ticket/13592] Removed unwanted space in self line. PHPBB3-13592 --- phpBB/phpbb/content_visibility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index a324c6b8b5..e5b0197f95 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -144,7 +144,7 @@ class content_visibility public function get_visibility_sql($mode, $forum_id, $table_alias = '') { $where_sql = ''; - + $get_visibility_sql_overwrite = false; /** * Allow changing the result of calling get_visibility_sql From 74385b8fce83c289e6ec3051c4f32547da06ae63 Mon Sep 17 00:00:00 2001 From: brunoais Date: Mon, 9 Feb 2015 11:58:35 +0000 Subject: [PATCH 5/6] [ticket/13592] Empty line before event comment block. I had forgotten this one PHPBB3-13592 --- phpBB/phpbb/content_visibility.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index e5b0197f95..05f0a59a90 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -146,6 +146,7 @@ class content_visibility $where_sql = ''; $get_visibility_sql_overwrite = false; + /** * Allow changing the result of calling get_visibility_sql * From bf20fb03ef0f7aa8456b2db8b41e72b385c494e8 Mon Sep 17 00:00:00 2001 From: brunoais Date: Wed, 11 Feb 2015 10:56:36 +0000 Subject: [PATCH 6/6] [ticket/13592] The name didn't make proper sense PHPBB3-13592 --- phpBB/phpbb/content_visibility.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php index 05f0a59a90..daebdd5573 100644 --- a/phpBB/phpbb/content_visibility.php +++ b/phpBB/phpbb/content_visibility.php @@ -150,7 +150,7 @@ class content_visibility /** * Allow changing the result of calling get_visibility_sql * - * @event core.phpbb_content_get_visibility_sql_visibility_before + * @event core.phpbb_content_visibility_get_visibility_sql_before * @var string where_sql Extra visibility conditions. It must end with either an SQL "AND" or an "OR" * @var string mode Either "topic" or "post" depending on the query this is being used in * @var array forum_id The forum id in which the search is made. @@ -167,7 +167,7 @@ class content_visibility 'table_alias', 'get_visibility_sql_overwrite', ); - extract($this->phpbb_dispatcher->trigger_event('core.phpbb_content_get_visibility_sql_visibility_before', compact($vars))); + extract($this->phpbb_dispatcher->trigger_event('core.phpbb_content_visibility_get_visibility_sql_before', compact($vars))); if ($get_visibility_sql_overwrite !== false) {