[use/request_class] Use request class in custom module

This commit is contained in:
Marc Alexander
2013-11-26 14:14:15 +01:00
parent 591e232650
commit 837e36eba6
2 changed files with 20 additions and 14 deletions

View File

@@ -62,6 +62,7 @@ services:
- @config - @config
- @template - @template
- @dbal.conn - @dbal.conn
- @request
- %core.root_path% - %core.root_path%
- %core.php_ext% - %core.php_ext%
- @user - @user

View File

@@ -56,6 +56,9 @@ class custom extends module_base
/** @var \phpbb\db\driver */ /** @var \phpbb\db\driver */
protected $db; protected $db;
/** @var \phpbb\request\request */
protected $request;
/** @var php file extension */ /** @var php file extension */
protected $php_ext; protected $php_ext;
@@ -71,15 +74,17 @@ class custom extends module_base
* @param \phpbb\config\config $config phpBB config * @param \phpbb\config\config $config phpBB config
* @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 string $phpEx php file extension * @param string $phpEx php file extension
* @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($config, $template, $db, $phpbb_root_path, $phpEx, $user) public function __construct($config, $template, $db, $request, $phpbb_root_path, $phpEx, $user)
{ {
$this->config = $config; $this->config = $config;
$this->template = $template; $this->template = $template;
$this->db = $db; $this->db = $db;
$this->request = $request;
$this->php_ext = $phpEx; $this->php_ext = $phpEx;
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->user = $user; $this->user = $user;
@@ -168,9 +173,9 @@ class custom extends module_base
*/ */
public function manage_custom($value, $key, $module_id) public function manage_custom($value, $key, $module_id)
{ {
$action = (isset($_POST['reset'])) ? 'reset' : ''; $action = ($this->request->is_set_post('reset')) ? 'reset' : '';
$action = (isset($_POST['submit'])) ? 'save' : $action; $action = ($this->request->is_set_post('submit')) ? 'save' : $action;
$action = (isset($_POST['preview'])) ? 'preview' : $action; $action = ($this->request->is_set_post('preview')) ? 'preview' : $action;
$portal_config = obtain_portal_config(); $portal_config = obtain_portal_config();
@@ -185,11 +190,11 @@ class custom extends module_base
trigger_error($this->user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING); trigger_error($this->user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING);
} }
$custom_code = utf8_normalize_nfc(request_var('custom_code', '', true)); $custom_code = $this->request->variable('custom_code', '', true);
$custom_bbcode = request_var('custom_use_bbcode', 1); // default to BBCode $custom_bbcode = $this->request->variable('custom_use_bbcode', 1); // default to BBCode
$custom_permission = request_var('permission-setting', array(0 => '')); $custom_permission = $this->request->variable('permission-setting', array(0 => ''));
$custom_title = utf8_normalize_nfc(request_var('module_name', '', true)); $custom_title = $this->request->variable('module_name', '', true);
$custom_image_src = utf8_normalize_nfc(request_var('module_image', '')); $custom_image_src = $this->request->variable('module_image', '', true);
$groups_ary = array(); $groups_ary = array();
$uid = $bitfield = $flags = ''; $uid = $bitfield = $flags = '';
$options = 7; $options = 7;
@@ -243,11 +248,11 @@ class custom extends module_base
break; break;
case 'preview': case 'preview':
$custom_code = $text = utf8_normalize_nfc(request_var('custom_code', '', true)); $custom_code = $text = $this->request->variable('custom_code', '', true);
$custom_bbcode = request_var('custom_use_bbcode', 1); // default to BBCode $custom_bbcode = $this->request->variable('custom_use_bbcode', 1); // default to BBCode
$custom_permission = request_var('permission-setting', array(0 => '')); $custom_permission = $this->request->variable('permission-setting', array(0 => ''));
$custom_title = utf8_normalize_nfc(request_var('module_name', '')); $custom_title = $this->request->variable('module_name', '', true);
$custom_image_src = utf8_normalize_nfc(request_var('module_image', '')); $custom_image_src = $this->request->variable('module_image', '', true);
$groups_ary = array(); $groups_ary = array();
// first check for obvious errors, we don't want to waste server resources // first check for obvious errors, we don't want to waste server resources