Version 2.1.0
This commit is contained in:
@@ -14,10 +14,10 @@ namespace dmzx\mchat\event;
|
||||
use dmzx\mchat\core\functions;
|
||||
use dmzx\mchat\core\settings;
|
||||
use phpbb\auth\auth;
|
||||
use phpbb\event\data;
|
||||
use phpbb\language\language;
|
||||
use phpbb\request\request_interface;
|
||||
use phpbb\template\template;
|
||||
use phpbb\user;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
class acp_listener implements EventSubscriberInterface
|
||||
@@ -28,79 +28,67 @@ class acp_listener implements EventSubscriberInterface
|
||||
/** @var request_interface */
|
||||
protected $request;
|
||||
|
||||
/** @var user */
|
||||
protected $user;
|
||||
/** @var language */
|
||||
protected $lang;
|
||||
|
||||
/** @var settings */
|
||||
protected $settings;
|
||||
protected $mchat_settings;
|
||||
|
||||
/** @var functions */
|
||||
protected $functions;
|
||||
|
||||
/** @var string */
|
||||
protected $root_path;
|
||||
|
||||
/** @var string */
|
||||
protected $php_ext;
|
||||
protected $mchat_functions;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param template $template
|
||||
* @param request_interface $request
|
||||
* @param user $user
|
||||
* @param settings $settings
|
||||
* @param functions $functions
|
||||
* @param string $root_path
|
||||
* @param string $php_ext
|
||||
* @param language $lang
|
||||
* @param settings $mchat_settings
|
||||
* @param functions $mchat_functions
|
||||
*/
|
||||
public function __construct(
|
||||
template $template,
|
||||
request_interface $request,
|
||||
user $user,
|
||||
settings $settings,
|
||||
functions $functions,
|
||||
$root_path,
|
||||
$php_ext
|
||||
language $lang,
|
||||
settings $mchat_settings,
|
||||
functions $mchat_functions
|
||||
)
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->request = $request;
|
||||
$this->user = $user;
|
||||
$this->settings = $settings;
|
||||
$this->functions = $functions;
|
||||
$this->root_path = $root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
$this->template = $template;
|
||||
$this->request = $request;
|
||||
$this->lang = $lang;
|
||||
$this->mchat_settings = $mchat_settings;
|
||||
$this->mchat_functions = $mchat_functions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
static public function getSubscribedEvents()
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'core.permissions' => 'permissions',
|
||||
'core.acp_users_prefs_modify_sql' => 'acp_users_prefs_modify_sql',
|
||||
'core.acp_users_prefs_modify_template_data' => 'acp_users_prefs_modify_template_data',
|
||||
'core.acp_users_overview_before' => 'acp_users_overview_before',
|
||||
'core.delete_user_after' => 'delete_user_after',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Event $event
|
||||
* @param data $event
|
||||
*/
|
||||
public function permissions($event)
|
||||
public function permissions(data $event)
|
||||
{
|
||||
$ucp_configs = array();
|
||||
$ucp_configs = [];
|
||||
|
||||
foreach (array_keys($this->settings->ucp_settings()) as $config_name)
|
||||
foreach (array_keys($this->mchat_settings->ucp_settings()) as $config_name)
|
||||
{
|
||||
$ucp_configs[] = 'u_' . $config_name;
|
||||
}
|
||||
|
||||
$permission_categories = array(
|
||||
'mchat' => array(
|
||||
$permission_categories = [
|
||||
'mchat' => [
|
||||
'u_mchat_use',
|
||||
'u_mchat_view',
|
||||
'u_mchat_edit',
|
||||
@@ -117,38 +105,38 @@ class acp_listener implements EventSubscriberInterface
|
||||
'u_mchat_smilies',
|
||||
'u_mchat_urls',
|
||||
'a_mchat',
|
||||
),
|
||||
],
|
||||
'mchat_user_config' => $ucp_configs,
|
||||
);
|
||||
];
|
||||
|
||||
$mchat_permissions = array();
|
||||
$mchat_permissions = [];
|
||||
|
||||
foreach ($permission_categories as $cat => $permissions)
|
||||
{
|
||||
foreach ($permissions as $permission)
|
||||
{
|
||||
$mchat_permissions[$permission] = array(
|
||||
$mchat_permissions[$permission] = [
|
||||
'lang' => 'ACL_' . strtoupper($permission),
|
||||
'cat' => $cat,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$event['permissions'] = array_merge($event['permissions'], $mchat_permissions);
|
||||
|
||||
$event['categories'] = array_merge($event['categories'], array(
|
||||
$event['categories'] = array_merge($event['categories'], [
|
||||
'mchat' => 'ACP_CAT_MCHAT',
|
||||
'mchat_user_config' => 'ACP_CAT_MCHAT_USER_CONFIG',
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Event $event
|
||||
* @param data $event
|
||||
*/
|
||||
public function acp_users_prefs_modify_sql($event)
|
||||
public function acp_users_prefs_modify_sql(data $event)
|
||||
{
|
||||
$sql_ary = array();
|
||||
$validation = array();
|
||||
$sql_ary = [];
|
||||
$validation = [];
|
||||
|
||||
$user_id = $event['user_row']['user_id'];
|
||||
|
||||
@@ -156,7 +144,7 @@ class acp_listener implements EventSubscriberInterface
|
||||
$userdata = $auth->obtain_user_data($user_id);
|
||||
$auth->acl($userdata);
|
||||
|
||||
foreach ($this->settings->ucp_settings() as $config_name => $config_data)
|
||||
foreach ($this->mchat_settings->ucp_settings() as $config_name => $config_data)
|
||||
{
|
||||
if ($auth->acl_get('u_' . $config_name))
|
||||
{
|
||||
@@ -171,21 +159,18 @@ class acp_listener implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('validate_data'))
|
||||
{
|
||||
include($this->root_path . 'includes/functions_user.' . $this->php_ext);
|
||||
}
|
||||
$this->mchat_settings->include_functions('user', 'validate_data');
|
||||
|
||||
$event['error'] = array_merge($event['error'], validate_data($sql_ary, $validation));
|
||||
$event['sql_ary'] = array_merge($event['sql_ary'], $sql_ary);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Event $event
|
||||
* @param data $event
|
||||
*/
|
||||
public function acp_users_prefs_modify_template_data($event)
|
||||
public function acp_users_prefs_modify_template_data(data $event)
|
||||
{
|
||||
$this->user->add_lang_ext('dmzx/mchat', array('mchat_acp', 'mchat_ucp'));
|
||||
$this->lang->add_lang(['mchat_acp', 'mchat_ucp'], 'dmzx/mchat');
|
||||
|
||||
$user_id = (int) $event['user_row']['user_id'];
|
||||
|
||||
@@ -193,44 +178,44 @@ class acp_listener implements EventSubscriberInterface
|
||||
$userdata = $auth->obtain_user_data($user_id);
|
||||
$auth->acl($userdata);
|
||||
|
||||
$selected = $this->settings->cfg_user('mchat_date', $event['user_row'], $auth);
|
||||
$date_template_data = $this->settings->get_date_template_data($selected);
|
||||
$selected = $this->mchat_settings->cfg_user('mchat_date', $event['user_row'], $auth);
|
||||
$date_template_data = $this->mchat_settings->get_date_template_data($selected);
|
||||
$this->template->assign_vars($date_template_data);
|
||||
|
||||
$notifications_template_data = $this->settings->get_enabled_post_notifications_lang();
|
||||
$notifications_template_data = $this->mchat_settings->get_enabled_post_notifications_lang();
|
||||
$this->template->assign_var('MCHAT_POSTS_ENABLED_LANG', $notifications_template_data);
|
||||
|
||||
foreach (array_keys($this->settings->ucp_settings()) as $config_name)
|
||||
foreach (array_keys($this->mchat_settings->ucp_settings()) as $config_name)
|
||||
{
|
||||
$upper = strtoupper($config_name);
|
||||
$this->template->assign_vars(array(
|
||||
$upper => $this->settings->cfg_user($config_name, $event['user_row'], $auth),
|
||||
$this->template->assign_vars([
|
||||
$upper => $this->mchat_settings->cfg_user($config_name, $event['user_row'], $auth),
|
||||
$upper . '_NOAUTH' => !$auth->acl_get('u_' . $config_name, $user_id),
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Event $event
|
||||
*
|
||||
*/
|
||||
public function acp_users_overview_before($event)
|
||||
public function acp_users_overview_before()
|
||||
{
|
||||
$this->user->add_lang_ext('dmzx/mchat', 'mchat_acp');
|
||||
$this->lang->add_lang('mchat_acp', 'dmzx/mchat');
|
||||
|
||||
$this->template->assign_vars(array(
|
||||
'L_RETAIN_POSTS' => $this->user->lang('MCHAT_RETAIN_MESSAGES', $this->user->lang('RETAIN_POSTS')),
|
||||
'L_DELETE_POSTS' => $this->user->lang('MCHAT_DELETE_MESSAGES', $this->user->lang('DELETE_POSTS')),
|
||||
));
|
||||
$this->template->assign_vars([
|
||||
'L_RETAIN_POSTS' => $this->lang->lang('MCHAT_RETAIN_MESSAGES', $this->lang->lang('RETAIN_POSTS')),
|
||||
'L_DELETE_POSTS' => $this->lang->lang('MCHAT_DELETE_MESSAGES', $this->lang->lang('DELETE_POSTS')),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Event $event
|
||||
* @param data $event
|
||||
*/
|
||||
public function delete_user_after($event)
|
||||
public function delete_user_after(data $event)
|
||||
{
|
||||
if ($event['mode'] == 'remove')
|
||||
{
|
||||
$this->functions->mchat_prune($event['user_ids']);
|
||||
$this->mchat_functions->mchat_prune($event['user_ids']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,10 @@
|
||||
namespace dmzx\mchat\event;
|
||||
|
||||
use dmzx\mchat\core\mchat;
|
||||
use dmzx\mchat\core\notifications;
|
||||
use phpbb\controller\helper;
|
||||
use phpbb\event\data;
|
||||
use phpbb\language\language;
|
||||
use phpbb\request\request_interface;
|
||||
use phpbb\user;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
@@ -23,12 +25,18 @@ class main_listener implements EventSubscriberInterface
|
||||
/** @var mchat */
|
||||
protected $mchat;
|
||||
|
||||
/** @var notifications */
|
||||
protected $mchat_notifications;
|
||||
|
||||
/** @var helper */
|
||||
protected $helper;
|
||||
|
||||
/** @var user */
|
||||
protected $user;
|
||||
|
||||
/** @var language */
|
||||
protected $lang;
|
||||
|
||||
/** @var request_interface */
|
||||
protected $request;
|
||||
|
||||
@@ -39,52 +47,59 @@ class main_listener implements EventSubscriberInterface
|
||||
* Constructor
|
||||
*
|
||||
* @param mchat $mchat
|
||||
* @param notifications $mchat_notifications
|
||||
* @param helper $helper
|
||||
* @param user $user
|
||||
* @param language $lang
|
||||
* @param request_interface $request
|
||||
* @param string $php_ext
|
||||
*/
|
||||
public function __construct(
|
||||
mchat $mchat,
|
||||
notifications $mchat_notifications,
|
||||
helper $helper,
|
||||
user $user,
|
||||
language $lang,
|
||||
request_interface $request,
|
||||
$php_ext
|
||||
)
|
||||
{
|
||||
$this->mchat = $mchat;
|
||||
$this->helper = $helper;
|
||||
$this->user = $user;
|
||||
$this->request = $request;
|
||||
$this->php_ext = $php_ext;
|
||||
$this->mchat = $mchat;
|
||||
$this->mchat_notifications = $mchat_notifications;
|
||||
$this->helper = $helper;
|
||||
$this->user = $user;
|
||||
$this->lang = $lang;
|
||||
$this->request = $request;
|
||||
$this->php_ext = $php_ext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
static public function getSubscribedEvents()
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'core.viewonline_overwrite_location' => 'add_page_viewonline',
|
||||
'core.user_setup' => 'load_language_on_setup',
|
||||
'core.page_header' => 'add_page_header_link',
|
||||
'core.index_modify_page_title' => 'display_mchat_on_index',
|
||||
'core.submit_post_end' => 'insert_posting',
|
||||
'core.display_custom_bbcodes_modify_sql' => array(array('remove_disallowed_bbcodes'), array('pm_compose_add_quote')),
|
||||
'core.display_custom_bbcodes_modify_sql' => [['remove_disallowed_bbcodes'], ['pm_compose_add_quote']],
|
||||
'core.generate_smilies_after' => 'generate_smilies_after',
|
||||
'core.user_add_modify_data' => 'user_registration_set_default_values',
|
||||
'core.login_box_redirect' => 'user_login_success',
|
||||
'core.session_gc_after' => 'session_gc',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data $event
|
||||
*/
|
||||
public function add_page_viewonline($event)
|
||||
public function add_page_viewonline(data $event)
|
||||
{
|
||||
if (strrpos($event['row']['session_page'], 'app.' . $this->php_ext . '/mchat') === 0)
|
||||
{
|
||||
$event['location'] = $this->user->lang('MCHAT_TITLE');
|
||||
$event['location'] = $this->lang->lang('MCHAT_TITLE');
|
||||
$event['location_url'] = $this->helper->route('dmzx_mchat_page_custom_controller');
|
||||
}
|
||||
}
|
||||
@@ -92,13 +107,13 @@ class main_listener implements EventSubscriberInterface
|
||||
/**
|
||||
* @param data $event
|
||||
*/
|
||||
public function load_language_on_setup($event)
|
||||
public function load_language_on_setup(data $event)
|
||||
{
|
||||
$lang_set_ext = $event['lang_set_ext'];
|
||||
$lang_set_ext[] = array(
|
||||
$lang_set_ext[] = [
|
||||
'ext_name' => 'dmzx/mchat',
|
||||
'lang_set' => 'common',
|
||||
);
|
||||
];
|
||||
$event['lang_set_ext'] = $lang_set_ext;
|
||||
}
|
||||
|
||||
@@ -121,23 +136,33 @@ class main_listener implements EventSubscriberInterface
|
||||
/**
|
||||
* @param data $event
|
||||
*/
|
||||
public function insert_posting($event)
|
||||
public function insert_posting(data $event)
|
||||
{
|
||||
$this->mchat->insert_posting($event['mode'], $event['data']['forum_id'], $event['data']['post_id']);
|
||||
$this->mchat_notifications->insert_post($event['mode'], $event['data']['forum_id'], $event['data']['post_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data $event
|
||||
*/
|
||||
public function remove_disallowed_bbcodes($event)
|
||||
public function remove_disallowed_bbcodes(data $event)
|
||||
{
|
||||
$event['sql_ary'] = $this->mchat->remove_disallowed_bbcodes($event['sql_ary']);
|
||||
|
||||
$this->mchat->set_custom_bbcodes_generated(true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function generate_smilies_after()
|
||||
{
|
||||
$this->mchat->set_smilies_generated(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data $event
|
||||
*/
|
||||
public function user_registration_set_default_values($event)
|
||||
public function user_registration_set_default_values(data $event)
|
||||
{
|
||||
$event['sql_ary'] = $this->mchat->set_user_default_values($event['sql_ary']);
|
||||
}
|
||||
@@ -145,11 +170,12 @@ class main_listener implements EventSubscriberInterface
|
||||
/**
|
||||
* @param data $event
|
||||
*/
|
||||
public function user_login_success($event)
|
||||
public function user_login_success(data $event)
|
||||
{
|
||||
if (!$event['admin'])
|
||||
{
|
||||
$this->mchat->insert_posting('login');
|
||||
$is_hidden = $this->request->is_set_post('viewonline') || !$this->user->data['user_allow_viewonline'];
|
||||
$this->mchat_notifications->insert_login($is_hidden);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user