Version 2.0.0-RC7
This commit is contained in:
@@ -4,33 +4,44 @@
|
||||
*
|
||||
* @package phpBB Extension - mChat
|
||||
* @copyright (c) 2016 dmzx - http://www.dmzx-web.net
|
||||
* @copyright (c) 2016 kasimi
|
||||
* @copyright (c) 2016 kasimi - https://kasimi.net
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace dmzx\mchat\controller;
|
||||
|
||||
use dmzx\mchat\core\settings;
|
||||
use phpbb\auth\auth;
|
||||
use phpbb\db\driver\driver_interface as db_interface;
|
||||
use phpbb\event\dispatcher_interface;
|
||||
use phpbb\request\request_interface;
|
||||
use phpbb\template\template;
|
||||
use phpbb\user;
|
||||
|
||||
class ucp_controller
|
||||
{
|
||||
/** @var \phpbb\template\template */
|
||||
/** @var template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
/** @var user */
|
||||
protected $user;
|
||||
|
||||
/** @var \phpbb\auth\auth */
|
||||
/** @var auth */
|
||||
protected $auth;
|
||||
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
/** @var db_interface */
|
||||
protected $db;
|
||||
|
||||
/** @var \phpbb\request\request */
|
||||
/** @var request_interface */
|
||||
protected $request;
|
||||
|
||||
/** @var \dmzx\mchat\core\settings */
|
||||
/** @var settings */
|
||||
protected $settings;
|
||||
|
||||
/** @var dispatcher_interface */
|
||||
protected $dispatcher;
|
||||
|
||||
/** @var string */
|
||||
protected $root_path;
|
||||
|
||||
@@ -40,16 +51,27 @@ class ucp_controller
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\template\template $template
|
||||
* @param \phpbb\user $user
|
||||
* @param \phpbb\auth\auth $auth
|
||||
* @param \phpbb\db\driver\driver_interface $db
|
||||
* @param \phpbb\request\request $request
|
||||
* @param \dmzx\mchat\core\settings $settings
|
||||
* @param string $root_path
|
||||
* @param string $php_ext
|
||||
* @param template $template
|
||||
* @param user $user
|
||||
* @param auth $auth
|
||||
* @param db_interface $db
|
||||
* @param request_interface $request
|
||||
* @param settings $settings
|
||||
* @param dispatcher_interface $dispatcher
|
||||
* @param string $root_path
|
||||
* @param string $php_ext
|
||||
*/
|
||||
public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\request\request $request, \dmzx\mchat\core\settings $settings, $root_path, $php_ext)
|
||||
public function __construct(
|
||||
template $template,
|
||||
user $user,
|
||||
auth $auth,
|
||||
db_interface $db,
|
||||
request_interface $request,
|
||||
settings $settings,
|
||||
dispatcher_interface $dispatcher,
|
||||
$root_path,
|
||||
$php_ext
|
||||
)
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
@@ -57,6 +79,7 @@ class ucp_controller
|
||||
$this->db = $db;
|
||||
$this->request = $request;
|
||||
$this->settings = $settings;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->root_path = $root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
}
|
||||
@@ -76,7 +99,7 @@ class ucp_controller
|
||||
{
|
||||
$mchat_new_config = array();
|
||||
$validation = array();
|
||||
foreach ($this->settings->ucp as $config_name => $config_data)
|
||||
foreach ($this->settings->ucp_settings() as $config_name => $config_data)
|
||||
{
|
||||
if ($this->auth->acl_get('u_' . $config_name))
|
||||
{
|
||||
@@ -103,6 +126,20 @@ class ucp_controller
|
||||
$error[] = 'FORM_INVALID';
|
||||
}
|
||||
|
||||
/**
|
||||
* Event to modify UCP settings data before they are updated
|
||||
*
|
||||
* @event dmzx.mchat.ucp_update_data
|
||||
* @var array mchat_new_config Array containing the user settings data that are about to be sent to the database
|
||||
* @var array error Array with error lang keys
|
||||
* @since 2.0.0-RC7
|
||||
*/
|
||||
$vars = array(
|
||||
'mchat_new_config',
|
||||
'error',
|
||||
);
|
||||
extract($this->dispatcher->trigger_event('dmzx.mchat.ucp_update_data', compact($vars)));
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
$sql = 'UPDATE ' . USERS_TABLE . '
|
||||
@@ -119,17 +156,18 @@ class ucp_controller
|
||||
$error = array_map(array($this->user, 'lang'), $error);
|
||||
}
|
||||
|
||||
$selected_date = $this->settings->cfg('mchat_date');
|
||||
$template_data = $this->settings->get_date_template_data($selected_date);
|
||||
|
||||
$auth_count = 0;
|
||||
|
||||
foreach (array_keys($this->settings->ucp) as $config_name)
|
||||
foreach (array_keys($this->settings->ucp_settings()) as $config_name)
|
||||
{
|
||||
$upper = strtoupper($config_name);
|
||||
$auth = $this->auth->acl_get('u_' . $config_name);
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
$upper => $this->settings->cfg($config_name),
|
||||
$upper . '_AUTH' => $auth,
|
||||
));
|
||||
$template_data[$upper] = $this->settings->cfg($config_name);
|
||||
$template_data[$upper . '_AUTH'] = $auth;
|
||||
|
||||
if ($auth)
|
||||
{
|
||||
@@ -137,17 +175,29 @@ class ucp_controller
|
||||
}
|
||||
}
|
||||
|
||||
$selected = $this->settings->cfg('mchat_date');
|
||||
$date_template_data = $this->settings->get_date_template_data($selected);
|
||||
$this->template->assign_vars($date_template_data);
|
||||
|
||||
$notifications_template_data = $this->settings->get_enabled_post_notifications_lang();
|
||||
$this->template->assign_var('MCHAT_POSTS_ENABLED_LANG', $notifications_template_data);
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
$template_data = array_merge($template_data, array(
|
||||
'MCHAT_POSTS_ENABLED_LANG' => $this->settings->get_enabled_post_notifications_lang(),
|
||||
'ERROR' => sizeof($error) ? implode('<br />', $error) : '',
|
||||
'MCHAT_AUTH_COUNT' => $auth_count,
|
||||
'S_UCP_ACTION' => $u_action,
|
||||
));
|
||||
|
||||
/**
|
||||
* Event to modify UCP settings template data
|
||||
*
|
||||
* @event dmzx.mchat.ucp_modify_template_data
|
||||
* @var array template_data Array containing the template data for the UCP settings
|
||||
* @var int auth_count Number of settings the user is authorized do see & adjust
|
||||
* @var array error Array with error lang keys
|
||||
* @since 2.0.0-RC7
|
||||
*/
|
||||
$vars = array(
|
||||
'template_data',
|
||||
'auth_count',
|
||||
'error',
|
||||
);
|
||||
extract($this->dispatcher->trigger_event('dmzx.mchat.ucp_modify_template_data', compact($vars)));
|
||||
|
||||
$this->template->assign_vars($template_data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user