Merge pull request #312 from marc1706/ticket/289

[ticket/289] Removed duplicated code from attachments.php
This commit is contained in:
Marc Alexander
2014-07-24 20:02:16 +02:00
14 changed files with 223 additions and 276 deletions

View File

@@ -15,7 +15,7 @@ class portal_module
public $new_config = array(); public $new_config = array();
protected $c_class; protected $c_class;
protected $db, $user, $cache, $template, $display_vars, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container; protected $db, $user, $cache, $template, $display_vars, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container;
protected $root_path, $version_check, $request, $php_ext, $portal_helper; protected $root_path, $version_check, $request, $php_ext, $portal_helper, $modules_helper;
public $module_column = array(); public $module_column = array();
public function __construct() public function __construct()
@@ -41,6 +41,7 @@ class portal_module
$this->phpbb_container = $phpbb_container; $this->phpbb_container = $phpbb_container;
$this->version_check = $this->phpbb_container->get('board3.version.check'); $this->version_check = $this->phpbb_container->get('board3.version.check');
$this->portal_helper = $this->phpbb_container->get('board3.portal.helper'); $this->portal_helper = $this->phpbb_container->get('board3.portal.helper');
$this->modules_helper = $this->phpbb_container->get('board3.portal.modules_helper');
define('PORTAL_MODULES_TABLE', $this->phpbb_container->getParameter('board3.modules.table')); define('PORTAL_MODULES_TABLE', $this->phpbb_container->getParameter('board3.modules.table'));
define('PORTAL_CONFIG_TABLE', $this->phpbb_container->getParameter('board3.config.table')); define('PORTAL_CONFIG_TABLE', $this->phpbb_container->getParameter('board3.config.table'));
@@ -181,20 +182,28 @@ class portal_module
{ {
if ($submit && ((isset($null['type']) && $null['type'] == 'custom') || (isset($null['submit_type']) && $null['submit_type'] == 'custom'))) if ($submit && ((isset($null['type']) && $null['type'] == 'custom') || (isset($null['submit_type']) && $null['submit_type'] == 'custom')))
{ {
$func = array($this->c_class, $null['submit']); if (!is_array($null['submit']))
if(method_exists($this->c_class, $null['submit']))
{ {
$func = array($this->c_class, $null['submit']);
$args = ($module_id != 0) ? array($config_name, $module_id) : $config_name;
}
else
{
if ($null['submit'][0] == 'board3.portal.modules_helper')
{
$func = array($this->modules_helper, $null['submit'][1]);
$args = ($module_id != 0) ? array($config_name, $module_id) : $config_name; $args = ($module_id != 0) ? array($config_name, $module_id) : $config_name;
call_user_func_array($func, $args);
} }
else else
{ {
$args = ($module_id != 0) ? array($cfg_array[$config_name], $config_name, $module_id) : $config_name; $args = ($module_id != 0) ? array($cfg_array[$config_name], $config_name, $module_id) : $config_name;
call_user_func_array($null['submit'], $args); $func = $null['submit'];
} }
} }
call_user_func_array($func, $args);
}
if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false)
{ {
continue; continue;
@@ -330,9 +339,16 @@ class portal_module
$func = array($this->c_class, $vars['method']); $func = array($this->c_class, $vars['method']);
} }
else else
{
if ($vars['method'][0] == 'board3.portal.modules_helper')
{
$func = array($this->modules_helper, $vars['method'][1]);
}
else
{ {
$func = $vars['method']; $func = $vars['method'];
} }
}
$content = call_user_func_array($func, $args); $content = call_user_func_array($func, $args);
} }

View File

@@ -22,6 +22,7 @@ services:
arguments: arguments:
- @auth - @auth
- @config - @config
- @board3.portal.modules_helper
- @template - @template
- @dbal.conn - @dbal.conn
- @request - @request

View File

@@ -55,6 +55,8 @@ services:
class: board3\portal\includes\modules_helper class: board3\portal\includes\modules_helper
arguments: arguments:
- @auth - @auth
- @config
- @request
board3.portal.fetch_posts: board3.portal.fetch_posts:
class: board3\portal\portal\fetch_posts class: board3\portal\portal\fetch_posts

View File

@@ -17,15 +17,31 @@ class modules_helper
*/ */
protected $auth; protected $auth;
/**
* phpBB config
* @var \phpbb\config\config
*/
protected $config;
/**
* phpBB request
* @var \phpbb\request\request
*/
protected $request;
/** /**
* Constructor * Constructor
* NOTE: The parameters of this method must match in order and type with * NOTE: The parameters of this method must match in order and type with
* the dependencies defined in the services.yml file for this service. * the dependencies defined in the services.yml file for this service.
* @param \phpbb\auth\auth $auth Auth object * @param \phpbb\auth\auth $auth Auth object
* @param \phpbb\config\config $config phpBB config
* @param \phpbb\request\request $request phpBB request
*/ */
public function __construct($auth) public function __construct($auth, $config, $request)
{ {
$this->auth = $auth; $this->auth = $auth;
$this->config = $config;
$this->request = $request;
} }
/** /**
@@ -47,4 +63,76 @@ class modules_helper
return $disallow_access; return $disallow_access;
} }
/**
* Generate select box
*
* @param string $key Key of select box
* @param array $select_ary Array of select box options
* @param array $selected_options Array of selected options
*
* @return string HTML code of select box
* @access public
*/
public function generate_select_box($key, $select_ary, $selected_options)
{
// Build options
$options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
foreach ($select_ary as $id => $option)
{
$options .= '<option value="' . $option['value'] . '"' . ((in_array($option['value'], $selected_options)) ? ' selected="selected"' : '') . (!empty($option['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $option['title'] . '</option>';
}
$options .= '</select>';
return $options;
}
/**
* Generate forum select box
*
* @param string $value Value of select box
* @param string $key Key of select box
*
* @return string HTML code of select box
* @access public
*/
public function generate_forum_select($value, $key)
{
$forum_list = make_forum_select(false, false, true, true, true, false, true);
$selected_options = $select_ary = array();
if(isset($this->config[$key]) && strlen($this->config[$key]) > 0)
{
$selected_options = explode(',', $this->config[$key]);
}
// Build forum options
foreach ($forum_list as $f_id => $f_row)
{
$select_ary[] = array(
'value' => $f_id,
'title' => $f_row['padding'] . $f_row['forum_name'],
'disabled' => $f_row['disabled'],
);
}
return $this->generate_select_box($key, $select_ary, $selected_options);
}
/**
* Store selected forums
*
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
* @access public
*/
public function store_selected_forums($key)
{
// Get selected extensions
$values = $this->request->variable($key, array(0 => ''));
$news = implode(',', $values);
$this->config->set($key, $news);
}
} }

View File

@@ -457,7 +457,7 @@ class announcements extends module_base
'board3_number_of_announcements_' . $module_id => array('lang' => 'PORTAL_NUMBER_OF_ANNOUNCEMENTS' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), 'board3_number_of_announcements_' . $module_id => array('lang' => 'PORTAL_NUMBER_OF_ANNOUNCEMENTS' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
'board3_announcements_day_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_DAY' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), 'board3_announcements_day_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_DAY' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
'board3_announcements_length_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_LENGTH' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), 'board3_announcements_length_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_LENGTH' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
'board3_global_announcements_forum_' . $module_id => array('lang' => 'PORTAL_GLOBAL_ANNOUNCEMENTS_FORUM' , 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_forums', 'submit' => 'store_selected_forums'), 'board3_global_announcements_forum_' . $module_id => array('lang' => 'PORTAL_GLOBAL_ANNOUNCEMENTS_FORUM' , 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => array('board3.portal.modules_helper', 'generate_forum_select'), 'submit' => array('board3.portal.modules_helper', 'store_selected_forums')),
'board3_announcements_forum_exclude_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_FORUM_EXCLUDE', 'validate' => 'string', 'type' => 'radio:yes_no', 'explain' => true), 'board3_announcements_forum_exclude_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_FORUM_EXCLUDE', 'validate' => 'string', 'type' => 'radio:yes_no', 'explain' => true),
'board3_announcements_archive_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_ARCHIVE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'board3_announcements_archive_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_ARCHIVE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'board3_announcements_permissions_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_PERMISSIONS' , 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'board3_announcements_permissions_' . $module_id => array('lang' => 'PORTAL_ANNOUNCEMENTS_PERMISSIONS' , 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
@@ -504,50 +504,4 @@ class announcements extends module_base
WHERE ' . $db->sql_in_set('config_name', $del_config); WHERE ' . $db->sql_in_set('config_name', $del_config);
return $db->sql_query($sql); return $db->sql_query($sql);
} }
/**
* Create forum select box
*
* @param mixed $value Value of input
* @param string $key Key name
* @param int $module_id Module ID
*
* @return string Forum select box HTML
*/
public function select_forums($value, $key, $module_id)
{
$forum_list = make_forum_select(false, false, true, true, true, false, true);
$selected = array();
if(isset($this->config[$key]) && strlen($this->config[$key]) > 0)
{
$selected = explode(',', $this->config[$key]);
}
// Build forum options
$s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
foreach ($forum_list as $f_id => $f_row)
{
$s_forum_options .= '<option value="' . $f_id . '"' . ((in_array($f_id, $selected)) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>';
}
$s_forum_options .= '</select>';
return $s_forum_options;
}
/**
* Store selected forums
*
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
*/
public function store_selected_forums($key, $module_id)
{
// Get selected forums
$values = $this->request->variable($key, array(0 => ''));
$news = implode(',', $values);
set_config($key, $news);
}
} }

View File

@@ -47,6 +47,9 @@ class attachments extends module_base
/** @var \phpbb\config\config */ /** @var \phpbb\config\config */
protected $config; protected $config;
/** @var \board3\portal\includes\modules_helper */
protected $helper;
/** @var \phpbb\request\request */ /** @var \phpbb\request\request */
protected $request; protected $request;
@@ -70,6 +73,7 @@ class attachments extends module_base
* *
* @param \phpbb\auth\auth $auth phpBB auth service * @param \phpbb\auth\auth $auth phpBB auth service
* @param \phpbb\config\config $config phpBB config * @param \phpbb\config\config $config phpBB config
* @param \board3\portal\includes\modules_helper $helper Modules helper
* @param \phpbb\template $template phpBB template * @param \phpbb\template $template phpBB template
* @param \phpbb\db\driver $db Database driver * @param \phpbb\db\driver $db Database driver
* @param \phpbb\request\request $request phpBB request * @param \phpbb\request\request $request phpBB request
@@ -77,10 +81,11 @@ class attachments extends module_base
* @param string $phpbb_root_path phpBB root path * @param string $phpbb_root_path phpBB root path
* @param \phpbb\user $user phpBB user object * @param \phpbb\user $user phpBB user object
*/ */
public function __construct($auth, $config, $template, $db, $request, $phpEx, $phpbb_root_path, $user) public function __construct($auth, $config, $helper, $template, $db, $request, $phpEx, $phpbb_root_path, $user)
{ {
$this->auth = $auth; $this->auth = $auth;
$this->config = $config; $this->config = $config;
$this->helper = $helper;
$this->template = $template; $this->template = $template;
$this->db = $db; $this->db = $db;
$this->request = $request; $this->request = $request;
@@ -116,7 +121,7 @@ class attachments extends module_base
'legend1' => 'ACP_PORTAL_ATTACHMENTS_NUMBER_SETTINGS', 'legend1' => 'ACP_PORTAL_ATTACHMENTS_NUMBER_SETTINGS',
'board3_attachments_number_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_NUMBER' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), 'board3_attachments_number_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_NUMBER' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
'board3_attach_max_length_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_MAX_LENGTH' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), 'board3_attach_max_length_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_MAX_LENGTH' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
'board3_attachments_forum_ids_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_FORUM_IDS', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_forums', 'submit' => 'store_selected_forums'), 'board3_attachments_forum_ids_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_FORUM_IDS', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => array('board3.portal.modules_helper', 'generate_forum_select'), 'submit' => array('board3.portal.modules_helper', 'store_selected_forums')),
'board3_attachments_forum_exclude_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_FORUM_EXCLUDE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'board3_attachments_forum_exclude_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_FORUM_EXCLUDE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'board3_attachments_filetype_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_FILETYPE', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_filetype', 'submit' => 'store_filetypes'), 'board3_attachments_filetype_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_FILETYPE', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_filetype', 'submit' => 'store_filetypes'),
'board3_attachments_exclude_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_EXCLUDE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'board3_attachments_exclude_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_EXCLUDE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
@@ -167,6 +172,8 @@ class attachments extends module_base
*/ */
public function select_filetype($value, $key, $module_id) public function select_filetype($value, $key, $module_id)
{ {
$extensions = array();
// Get extensions // Get extensions
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . EXTENSIONS_TABLE . ' FROM ' . EXTENSIONS_TABLE . '
@@ -175,24 +182,15 @@ class attachments extends module_base
while ($row = $this->db->sql_fetchrow($result)) while ($row = $this->db->sql_fetchrow($result))
{ {
$extensions[] = $row; $extensions[] = array(
'value' => $row['extension'],
'title' => $row['extension'],
);
} }
$selected = array(); $selected = $this->get_selected_filetypes($module_id);
if(isset($this->config['board3_attachments_filetype_' . $module_id]) && strlen($this->config['board3_attachments_filetype_' . $module_id]) > 0)
{
$selected = explode(',', $this->config['board3_attachments_filetype_' . $module_id]);
}
// Build options return $this->helper->generate_select_box($key, $extensions, $selected);
$ext_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
foreach ($extensions as $id => $ext)
{
$ext_options .= '<option value="' . $ext['extension'] . '"' . ((in_array($ext['extension'], $selected)) ? ' selected="selected"' : '') . '>' . $ext['extension'] . '</option>';
}
$ext_options .= '</select>';
return $ext_options;
} }
/** /**
@@ -214,52 +212,6 @@ class attachments extends module_base
} }
/**
* Create forum select box
*
* @param mixed $value Value of input
* @param string $key Key name
* @param int $module_id Module ID
*
* @return string Forum select box HTML
*/
public function select_forums($value, $key)
{
$forum_list = make_forum_select(false, false, true, true, true, false, true);
$selected = array();
if(isset($this->config[$key]) && strlen($this->config[$key]) > 0)
{
$selected = explode(',', $this->config[$key]);
}
// Build forum options
$s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
foreach ($forum_list as $f_id => $f_row)
{
$s_forum_options .= '<option value="' . $f_id . '"' . ((in_array($f_id, $selected)) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>';
}
$s_forum_options .= '</select>';
return $s_forum_options;
}
/**
* Store selected forums
*
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
*/
public function store_selected_forums($key)
{
// Get selected extensions
$values = $this->request->variable($key, array(0 => ''));
$news = implode(',', $values);
set_config($key, $news);
}
/** /**
* Parse template variables for module * Parse template variables for module
* *
@@ -273,13 +225,9 @@ class attachments extends module_base
{ {
$attach_forums = false; $attach_forums = false;
$where = ''; $where = '';
$filetypes = array();
// Get filetypes and put them into an array // Get filetypes and put them into an array
if(isset($this->config['board3_attachments_filetype_' . $module_id]) && strlen($this->config['board3_attachments_filetype_' . $module_id]) > 0) $filetypes = $this->get_selected_filetypes($module_id);
{
$filetypes = explode(',', $this->config['board3_attachments_filetype_' . $module_id]);
}
if($this->config['board3_attachments_forum_ids_' . $module_id] !== '') if($this->config['board3_attachments_forum_ids_' . $module_id] !== '')
{ {
@@ -368,4 +316,22 @@ class attachments extends module_base
return 'attachments_' . $type . '.html'; return 'attachments_' . $type . '.html';
} }
/**
* Get the filetypes that were selected in the ACP
*
* @param int $module_id Module ID
*
* @return array An array with the selected filetypes
*/
protected function get_selected_filetypes($module_id)
{
$selected = array();
if(isset($this->config['board3_attachments_filetype_' . $module_id]) && strlen($this->config['board3_attachments_filetype_' . $module_id]) > 0)
{
$selected = explode(',', $this->config['board3_attachments_filetype_' . $module_id]);
}
return $selected;
}
} }

View File

@@ -436,7 +436,7 @@ class news extends module_base
'board3_show_all_news_' . $module_id => array('lang' => 'PORTAL_SHOW_ALL_NEWS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'board3_show_all_news_' . $module_id => array('lang' => 'PORTAL_SHOW_ALL_NEWS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'board3_number_of_news_' . $module_id => array('lang' => 'PORTAL_NUMBER_OF_NEWS', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), 'board3_number_of_news_' . $module_id => array('lang' => 'PORTAL_NUMBER_OF_NEWS', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
'board3_news_length_' . $module_id => array('lang' => 'PORTAL_NEWS_LENGTH', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), 'board3_news_length_' . $module_id => array('lang' => 'PORTAL_NEWS_LENGTH', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
'board3_news_forum_' . $module_id => array('lang' => 'PORTAL_NEWS_FORUM', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_forums', 'submit' => 'store_selected_forums'), 'board3_news_forum_' . $module_id => array('lang' => 'PORTAL_NEWS_FORUM', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => array('board3.portal.modules_helper', 'generate_forum_select'), 'submit' => array('board3.portal.modules_helper', 'store_selected_forums')),
'board3_news_exclude_' . $module_id => array('lang' => 'PORTAL_NEWS_EXCLUDE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'board3_news_exclude_' . $module_id => array('lang' => 'PORTAL_NEWS_EXCLUDE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'board3_news_show_last_' . $module_id => array('lang' => 'PORTAL_NEWS_SHOW_LAST', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'board3_news_show_last_' . $module_id => array('lang' => 'PORTAL_NEWS_SHOW_LAST', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'board3_news_archive_' . $module_id => array('lang' => 'PORTAL_NEWS_ARCHIVE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'board3_news_archive_' . $module_id => array('lang' => 'PORTAL_NEWS_ARCHIVE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
@@ -485,53 +485,4 @@ class news extends module_base
WHERE ' . $db->sql_in_set('config_name', $del_config); WHERE ' . $db->sql_in_set('config_name', $del_config);
return $db->sql_query($sql); return $db->sql_query($sql);
} }
/**
* Create forum select box
*
* @param mixed $value Value of input
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
*/
public function select_forums($value, $key, $module_id)
{
$forum_list = make_forum_select(false, false, true, true, true, false, true);
$selected = array();
if(isset($this->config[$key]) && strlen($this->config[$key]) > 0)
{
$selected = explode(',', $this->config[$key]);
}
// Build forum options
$s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
foreach ($forum_list as $f_id => $f_row)
{
$s_forum_options .= '<option value="' . $f_id . '"' . ((in_array($f_id, $selected)) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>';
}
$s_forum_options .= '</select>';
return $s_forum_options;
}
/**
* Store selected forums
*
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
*/
public function store_selected_forums($key, $module_id)
{
// Get selected extensions
$values = $this->request->variable($key, array(0 => ''));
$news = implode(',', $values);
set_config($key, $news);
}
} }

View File

@@ -120,7 +120,7 @@ class poll extends module_base
'title' => 'ACP_PORTAL_POLLS_SETTINGS', 'title' => 'ACP_PORTAL_POLLS_SETTINGS',
'vars' => array( 'vars' => array(
'legend1' => 'ACP_PORTAL_POLLS_SETTINGS', 'legend1' => 'ACP_PORTAL_POLLS_SETTINGS',
'board3_poll_topic_id_' . $module_id => array('lang' => 'PORTAL_POLL_TOPIC_ID' , 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_forums', 'submit' => 'store_selected_forums'), 'board3_poll_topic_id_' . $module_id => array('lang' => 'PORTAL_POLL_TOPIC_ID' , 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => array('board3.portal.modules_helper', 'generate_forum_select'), 'submit' => array('board3.portal.modules_helper', 'store_selected_forums')),
'board3_poll_exclude_id_' . $module_id => array('lang' => 'PORTAL_POLL_EXCLUDE_ID' , 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'board3_poll_exclude_id_' . $module_id => array('lang' => 'PORTAL_POLL_EXCLUDE_ID' , 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'board3_poll_limit_' . $module_id => array('lang' => 'PORTAL_POLL_LIMIT' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), 'board3_poll_limit_' . $module_id => array('lang' => 'PORTAL_POLL_LIMIT' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
'board3_poll_allow_vote_' . $module_id => array('lang' => 'PORTAL_POLL_ALLOW_VOTE' , 'validate' => 'ibool', 'type' => 'radio:yes_no', 'explain' => true), 'board3_poll_allow_vote_' . $module_id => array('lang' => 'PORTAL_POLL_ALLOW_VOTE' , 'validate' => 'ibool', 'type' => 'radio:yes_no', 'explain' => true),
@@ -159,54 +159,6 @@ class poll extends module_base
return $db->sql_query($sql); return $db->sql_query($sql);
} }
/**
* Create forum select box
*
* @param mixed $value Value of input
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
*/
public function select_forums($value, $key, $module_id)
{
$forum_list = make_forum_select(false, false, true, true, true, false, true);
$selected = array();
if(isset($this->config[$key]) && strlen($this->config[$key]) > 0)
{
$selected = explode(',', $this->config[$key]);
}
// Build forum options
$s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
foreach ($forum_list as $f_id => $f_row)
{
$s_forum_options .= '<option value="' . $f_id . '"' . ((in_array($f_id, $selected)) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>';
}
$s_forum_options .= '</select>';
return $s_forum_options;
}
/**
* Store selected forums
*
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
*/
public function store_selected_forums($key, $module_id)
{
// Get selected forums
$values = $this->request->variable($key, array(0 => ''));
$news = implode(',', $values);
set_config($key, $news);
}
/** /**
* Parse template variables for module * Parse template variables for module
* *

View File

@@ -219,7 +219,7 @@ class recent extends module_base
'legend1' => 'ACP_PORTAL_RECENT_SETTINGS', 'legend1' => 'ACP_PORTAL_RECENT_SETTINGS',
'board3_max_topics_' . $module_id => array('lang' => 'PORTAL_MAX_TOPIC', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), 'board3_max_topics_' . $module_id => array('lang' => 'PORTAL_MAX_TOPIC', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
'board3_recent_title_limit_' . $module_id => array('lang' => 'PORTAL_RECENT_TITLE_LIMIT', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), 'board3_recent_title_limit_' . $module_id => array('lang' => 'PORTAL_RECENT_TITLE_LIMIT', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
'board3_recent_forum_' . $module_id => array('lang' => 'PORTAL_RECENT_FORUM', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_forums', 'submit' => 'store_selected_forums'), 'board3_recent_forum_' . $module_id => array('lang' => 'PORTAL_RECENT_FORUM', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => array('board3.portal.modules_helper', 'generate_forum_select'), 'submit' => array('board3.portal.modules_helper', 'store_selected_forums')),
'board3_recent_exclude_forums_' . $module_id => array('lang' => 'PORTAL_EXCLUDE_FORUM', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'board3_recent_exclude_forums_' . $module_id => array('lang' => 'PORTAL_EXCLUDE_FORUM', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
) )
); );
@@ -252,52 +252,4 @@ class recent extends module_base
WHERE ' . $db->sql_in_set('config_name', $del_config); WHERE ' . $db->sql_in_set('config_name', $del_config);
return $db->sql_query($sql); return $db->sql_query($sql);
} }
/**
* Create forum select box
*
* @param mixed $value Value of input
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
*/
public function select_forums($value, $key, $module_id)
{
$forum_list = make_forum_select(false, false, true, true, true, false, true);
$selected = array();
if(isset($this->config[$key]) && strlen($this->config[$key]) > 0)
{
$selected = explode(',', $this->config[$key]);
}
// Build forum options
$s_forum_options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
foreach ($forum_list as $f_id => $f_row)
{
$s_forum_options .= '<option value="' . $f_id . '"' . ((in_array($f_id, $selected)) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>';
}
$s_forum_options .= '</select>';
return $s_forum_options;
}
/**
* Store selected forums
*
* @param string $key Key name
* @param int $module_id Module ID
*
* @return null
*/
public function store_selected_forums($key, $module_id)
{
// Get selected extensions
$values = $this->request->variable($key, array(0 => ''));
$news = implode(',', $values);
set_config($key, $news);
}
} }

View File

@@ -23,6 +23,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
parent::setUp(); parent::setUp();
global $db, $cache, $phpbb_root_path, $phpEx, $user, $phpbb_container, $request, $template, $table_prefix; global $db, $cache, $phpbb_root_path, $phpEx, $user, $phpbb_container, $request, $template, $table_prefix;
$user = new \board3\portal\tests\mock\user(); $user = new \board3\portal\tests\mock\user();
$request = new \phpbb_mock_request;
$phpbb_container = new \phpbb_mock_container_builder(); $phpbb_container = new \phpbb_mock_container_builder();
// Mock version check // Mock version check
$phpbb_container->set('board3.version.check', $phpbb_container->set('board3.version.check',
@@ -39,6 +40,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
new \board3\portal\modules\donation($config, $template, $user), new \board3\portal\modules\donation($config, $template, $user),
)); ));
$phpbb_container->set('board3.portal.helper', new \board3\portal\includes\helper($phpbb_container->get('board3.module_collection'))); $phpbb_container->set('board3.portal.helper', new \board3\portal\includes\helper($phpbb_container->get('board3.module_collection')));
$phpbb_container->set('board3.portal.modules_helper', new \board3\portal\includes\modules_helper(new \phpbb\auth\auth(), $config, $request));
$phpbb_container->setParameter('board3.modules.table', $table_prefix . 'portal_modules'); $phpbb_container->setParameter('board3.modules.table', $table_prefix . 'portal_modules');
$phpbb_container->setParameter('board3.config.table', $table_prefix . 'portal_config'); $phpbb_container->setParameter('board3.config.table', $table_prefix . 'portal_config');
$cache = $this->getMock('\phpbb\cache\cache', array('destroy', 'sql_exists', 'get', 'put')); $cache = $this->getMock('\phpbb\cache\cache', array('destroy', 'sql_exists', 'get', 'put'));
@@ -60,7 +62,6 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
'UNABLE_TO_MOVE' => 'UNABLE_TO_MOVE', 'UNABLE_TO_MOVE' => 'UNABLE_TO_MOVE',
'UNABLE_TO_MOVE_ROW' => 'UNABLE_TO_MOVE_ROW', 'UNABLE_TO_MOVE_ROW' => 'UNABLE_TO_MOVE_ROW',
)); ));
$request = new \phpbb_mock_request;
$this->portal_module = new \board3\portal\acp\portal_module(); $this->portal_module = new \board3\portal\acp\portal_module();
$this->update_portal_modules(); $this->update_portal_modules();
} }

View File

@@ -27,6 +27,7 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework
$user->timezone = new \DateTimeZone('UTC'); $user->timezone = new \DateTimeZone('UTC');
$user->add_lang('common'); $user->add_lang('common');
$user->add_lang('../../ext/board3/portal/language/en/portal'); $user->add_lang('../../ext/board3/portal/language/en/portal');
$request = new \phpbb_mock_request;
$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$cache = $this->getMock('\phpbb\cache\cache', array('obtain_word_list', 'get', 'sql_exists', 'put', 'obtain_attach_extensions')); $cache = $this->getMock('\phpbb\cache\cache', array('obtain_word_list', 'get', 'sql_exists', 'put', 'obtain_attach_extensions'));
$cache->expects($this->any()) $cache->expects($this->any())
@@ -51,7 +52,7 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework
$this->auth = $auth; $this->auth = $auth;
$this->user = $user; $this->user = $user;
$phpbb_container = new \phpbb_mock_container_builder(); $phpbb_container = new \phpbb_mock_container_builder();
$this->modules_helper = new \board3\portal\includes\modules_helper($auth); $this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $request);
$phpbb_container->set('board3.portal.modules_helper', $this->modules_helper); $phpbb_container->set('board3.portal.modules_helper', $this->modules_helper);
$phpbb_container->set('board3.portal.fetch_posts', new \board3\portal\portal\fetch_posts($auth, $cache, $this->config, $this->db, $this->modules_helper, $user)); $phpbb_container->set('board3.portal.fetch_posts', new \board3\portal\portal\fetch_posts($auth, $cache, $this->config, $this->db, $this->modules_helper, $user));
$template = $this->getMock('\phpbb\template', array('set_filenames', 'destroy_block_vars', 'assign_block_vars', 'assign_display')); $template = $this->getMock('\phpbb\template', array('set_filenames', 'destroy_block_vars', 'assign_block_vars', 'assign_display'));

View File

@@ -17,12 +17,14 @@
<table name="phpbb_forums"> <table name="phpbb_forums">
<column>forum_id</column> <column>forum_id</column>
<column>parent_id</column> <column>parent_id</column>
<column>forum_name</column>
<column>forum_parents</column> <column>forum_parents</column>
<column>forum_desc</column> <column>forum_desc</column>
<column>forum_rules</column> <column>forum_rules</column>
<row> <row>
<value>1</value> <value>1</value>
<value>0</value> <value>0</value>
<value>forum_one</value>
<value></value> <value></value>
<value></value> <value></value>
<value></value> <value></value>
@@ -30,6 +32,7 @@
<row> <row>
<value>2</value> <value>2</value>
<value>1</value> <value>1</value>
<value>forum_two</value>
<value></value> <value></value>
<value></value> <value></value>
<value></value> <value></value>

View File

@@ -14,6 +14,8 @@ class board3_includes_modules_helper_test extends \board3\portal\tests\testframe
protected $modules; protected $modules;
protected $config;
public function getDataSet() public function getDataSet()
{ {
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/auth.xml'); return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/auth.xml');
@@ -24,8 +26,10 @@ class board3_includes_modules_helper_test extends \board3\portal\tests\testframe
parent::setUp(); parent::setUp();
$auth = new \phpbb\auth\auth(); $auth = new \phpbb\auth\auth();
$this->config = new \phpbb\config\config(array());
$request = new \phpbb_mock_request(array('foo' => array('bar')));
$this->modules_helper = new \board3\portal\includes\modules_helper($auth); $this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $request);
} }
public function data_get_disallowed_forums() public function data_get_disallowed_forums()
@@ -43,4 +47,59 @@ class board3_includes_modules_helper_test extends \board3\portal\tests\testframe
{ {
$this->assertEquals($expected, $this->modules_helper->get_disallowed_forums($input)); $this->assertEquals($expected, $this->modules_helper->get_disallowed_forums($input));
} }
public function data_generate_select_box()
{
return array(
array('<select id="foobar" name="foobar[]" multiple="multiple"><option value="one">one</option><option value="two" selected="selected">two</option></select>',
'foobar',
array(
'1' => array(
'value' => 'one',
'title' => 'one',
),
'2' => array(
'value' => 'two',
'title' => 'two',
),
),
array('two')),
array('<select id="foobar" name="foobar[]" multiple="multiple"><option value="one" selected="selected">two</option><option value="two">three</option></select>',
'foobar',
array(
'1' => array(
'value' => 'one',
'title' => 'two',
),
'2' => array(
'value' => 'two',
'title' => 'three',
),
),
array('one')),
);
}
/**
* @dataProvider data_generate_select_box
*/
public function test_generate_select_box($expected, $key, $select_ary, $selected_options)
{
$this->assertEquals($expected, $this->modules_helper->generate_select_box($key, $select_ary, $selected_options));
}
public function test_generate_forum_select()
{
$this->assertEquals(
'<select id="bar" name="bar[]" multiple="multiple"><option value="1" disabled="disabled" class="disabled-option">forum_one</option><option value="2" disabled="disabled" class="disabled-option">forum_two</option></select>',
$this->modules_helper->generate_forum_select('foo', 'bar')
);
}
public function test_store_selected_forums()
{
$this->assertEmpty($this->config['foo']);
$this->modules_helper->store_selected_forums('foo');
$this->assertEquals('bar', $this->config['foo']);
}
} }

View File

@@ -50,7 +50,8 @@ class phpbb_portal_fetch_posts_test extends \board3\portal\tests\testframework\d
// Pretend to allow downloads in forum 1 // Pretend to allow downloads in forum 1
$auth->acl[1][0] = true; $auth->acl[1][0] = true;
$this->auth = $auth; $this->auth = $auth;
$this->modules_helper = new \board3\portal\includes\modules_helper($auth); $request = new \phpbb_mock_request;
$this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $request);
$this->user = $user; $this->user = $user;
$template = $this->getMock('\phpbb\template', array('set_filenames', 'destroy_block_vars', 'assign_block_vars', 'assign_display')); $template = $this->getMock('\phpbb\template', array('set_filenames', 'destroy_block_vars', 'assign_block_vars', 'assign_display'));
$this->fetch_posts = new \board3\portal\portal\fetch_posts($auth, $cache, $this->config, $this->db, $this->modules_helper, $user); $this->fetch_posts = new \board3\portal\portal\fetch_posts($auth, $cache, $this->config, $this->db, $this->modules_helper, $user);