[ticket/291] Add modules_helper and use for permission checks

B3P-291
This commit is contained in:
Marc Alexander
2014-07-07 15:16:29 +02:00
parent 0ae979e34a
commit 40f630a55d
10 changed files with 125 additions and 115 deletions

View File

@@ -93,7 +93,7 @@ function obtain_portal_modules()
// fetch post for news & announce
function phpbb_fetch_posts($module_id, $forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start = 0, $invert = false)
{
global $db, $phpbb_root_path, $auth, $user, $bbcode_bitfield, $bbcode, $portal_config, $config, $cache;
global $db, $phpbb_root_path, $auth, $user, $bbcode_bitfield, $bbcode, $portal_config, $config, $cache, $phpbb_container;
$posts = $update_count = array();
$post_time = ($time == 0) ? '' : 'AND t.topic_time > ' . (time() - $time * 86400);
@@ -101,15 +101,10 @@ function phpbb_fetch_posts($module_id, $forum_from, $permissions, $number_of_pos
$str_where = '';
$topic_icons = array(0);
$have_icons = 0;
$modules_helper = $phpbb_container->get('board3.portal.modules_helper');
if ($permissions == true)
{
$disallow_access = array_unique(array_keys($auth->acl_getf('!f_read', true)));
}
else
{
$disallow_access = array();
}
// Get disallowed forums
$disallow_access = $modules_helper->get_disallowed_forums($permissions);
if ($invert == true)
{

View File

@@ -11,12 +11,6 @@ namespace board3\portal\includes;
class helper
{
/**
* Auth object
* @var \phpbb\auth\auth
*/
private $auth;
/**
* Board3 Modules service collection
* @var \phpbb\di\service_collection
@@ -27,13 +21,11 @@ class helper
* Constructor
* NOTE: The parameters of this method must match in order and type with
* the dependencies defined in the services.yml file for this service.
* @param \phpbb\auth\auth $auth Auth object
* @param \phpbb\di\service_collection $modules Board3 Modules service
* collection
*/
public function __construct($auth, $modules)
public function __construct($modules)
{
$this->auth = $auth;
$this->register_modules($modules);
}
@@ -72,24 +64,4 @@ class helper
return false;
}
}
/**
* Get an array of disallowed forums
*
* @param bool $disallow_access Whether the array for disallowing access
* should be filled
*/
public function get_disallowed_forums($disallow_access)
{
if ($disallow_access == true)
{
$disallow_access = array_unique(array_keys($this->auth->acl_getf('!f_read', true)));
}
else
{
$disallow_access = array();
}
return $disallow_access;
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
*
* @package Board3 Portal v2.1
* @copyright (c) 2014 Board3 Group ( www.board3.de )
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace board3\portal\includes;
class modules_helper
{
/**
* Auth object
* @var \phpbb\auth\auth
*/
protected $auth;
/**
* Constructor
* NOTE: The parameters of this method must match in order and type with
* the dependencies defined in the services.yml file for this service.
* @param \phpbb\auth\auth $auth Auth object
*/
public function __construct($auth)
{
$this->auth = $auth;
}
/**
* Get an array of disallowed forums
*
* @param bool $disallow_access Whether the array for disallowing access
* should be filled
*/
public function get_disallowed_forums($disallow_access)
{
if ($disallow_access == true)
{
$disallow_access = array_unique(array_keys($this->auth->acl_getf('!f_read', true)));
}
else
{
$disallow_access = array();
}
return $disallow_access;
}
}