From 159d1d25b87506d86eb718c7a777ac33de16d7dd Mon Sep 17 00:00:00 2001 From: dmzx Date: Sun, 16 Oct 2016 17:25:31 +0200 Subject: [PATCH] Version 2.0.0-RC7 --- .travis.yml | 60 ----- acp/acp_mchat_info.php | 2 +- acp/acp_mchat_module.php | 2 +- adm/style/acp_mchat_globalsettings.html | 83 +++++-- adm/style/acp_mchat_globalusersettings.html | 2 +- .../acp_mchat_globalusersettings_content.html | 18 +- adm/style/event/acp_users_prefs_append.html | 2 +- composer.json | 14 +- config/services.yml | 6 +- controller/acp_controller.php | 223 +++++++++++++----- controller/ucp_controller.php | 110 ++++++--- core/functions.php | 191 +++++++++------ core/mchat.php | 168 ++++++++----- core/settings.php | 136 +++++++++-- cron/mchat_prune.php | 25 +- event/acp_listener.php | 46 ++-- event/main_listener.php | 32 ++- ext.php | 9 +- language/en/common.php | 6 +- language/en/info_acp_mchat.php | 3 +- language/en/info_ucp_mchat.php | 2 +- language/en/mchat.php | 3 +- language/en/mchat_acp.php | 15 +- language/en/mchat_ucp.php | 4 +- language/en/permissions_mchat.php | 2 +- migrations/mchat_2_0_0_rc3.php | 6 +- migrations/mchat_2_0_0_rc4.php | 6 +- migrations/mchat_2_0_0_rc5.php | 6 +- migrations/mchat_2_0_0_rc6.php | 6 +- migrations/mchat_2_0_0_rc7.php | 67 ++++++ styles/Subway/theme/mchat_custom.css | 2 +- styles/all/template/javascript/mchat.js | 106 +++++---- styles/all/template/mchat_script_data.html | 6 +- styles/basic/theme/mchat_custom.css | 2 +- styles/black/theme/mchat_custom.css | 2 +- .../index_body_forumlist_body_before.html | 3 + .../event/index_body_markforums_before.html | 1 + styles/canvas/theme/mchat_custom.css | 6 +- styles/elegance/theme/mchat_custom.css | 2 +- styles/latte/theme/mchat_custom.css | 2 +- styles/metro_blue/theme/mchat_custom.css | 2 +- .../event/index_body_markforums_after.html | 4 +- styles/pbtech/theme/mchat_custom.css | 7 +- styles/pbwow3/theme/mchat_custom.css | 2 +- .../event/dmzx_mchat_custom_include.html | 3 - .../index_body_forumlist_body_after.html | 4 +- .../event/index_body_markforums_before.html | 4 +- .../overall_header_navigation_append.html | 2 +- .../overall_header_stylesheets_after.html | 7 + styles/prosilver/template/mchat_body.html | 26 +- styles/prosilver/template/mchat_messages.html | 2 +- .../template/mchat_messages_icons.html | 11 +- styles/prosilver/template/mchat_navlink.html | 5 +- styles/prosilver/template/mchat_panel.html | 6 +- styles/prosilver/template/ucp_mchat.html | 20 +- styles/prosilver/theme/mchat.css | 86 ++++--- styles/simplicity/theme/mchat_custom.css | 7 +- ucp/ucp_mchat_info.php | 2 +- ucp/ucp_mchat_module.php | 2 +- 59 files changed, 1096 insertions(+), 493 deletions(-) delete mode 100644 .travis.yml create mode 100644 migrations/mchat_2_0_0_rc7.php create mode 100644 styles/canvas/template/event/index_body_forumlist_body_before.html create mode 100644 styles/canvas/template/event/index_body_markforums_before.html delete mode 100644 styles/prosilver/template/event/dmzx_mchat_custom_include.html create mode 100644 styles/prosilver/template/event/overall_header_stylesheets_after.html diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7b91926..0000000 --- a/.travis.yml +++ /dev/null @@ -1,60 +0,0 @@ -language: php - -matrix: - include: - - php: 5.4 - env: DB=mysqli - - php: 5.4 - env: DB=mysql - - php: 5.4 - env: DB=mariadb - - php: 5.4 - env: DB=postgres - - php: 5.4 - env: DB=sqlite3 - - php: 5.5 - env: DB=mysqli - - php: 5.6 - env: DB=mysqli - - php: hhvm - env: DB=mysqli - allow_failures: - - php: hhvm - fast_finish: true - -env: - global: - - EXTNAME="dmzx/mChat-Extension" # CHANGE name of the extension HERE - - SNIFF="1" # Should we run code sniffer on your code? - - IMAGE_ICC="0" # Should we run icc profile sniffer on your images? - - EPV="1" # Should we run EPV (Extension Pre Validator) on your code? - - PHPBB_BRANCH="3.1.x" - -branches: - only: - - master - - develop - - /^develop-.*$/ - -before_install: - - sudo mkdir travis - - git clone "https://github.com/nickvergessen/phpbb-ext-acme-demo.git" - - sudo cp phpbb-ext-acme-demo/phpunit.xml.dist ./ - - sudo cp phpbb-ext-acme-demo/travis/prepare-phpbb.sh travis - - sudo rm -rf phpbb-ext-acme-demo - -install: - - composer install --dev --no-interaction --prefer-source - - travis/prepare-phpbb.sh $EXTNAME $PHPBB_BRANCH - - cd ../../phpBB3 - - travis/prepare-extension.sh $EXTNAME $PHPBB_BRANCH - - travis/setup-phpbb.sh $DB $TRAVIS_PHP_VERSION - -before_script: - - travis/setup-database.sh $DB $TRAVIS_PHP_VERSION - -script: - - sh -c "if [ '$SNIFF' != '0' ]; then travis/ext-sniff.sh $DB $TRAVIS_PHP_VERSION $EXTNAME; fi" - - sh -c "if [ '$IMAGE_ICC' != '0' ]; then travis/check-image-icc-profiles.sh $DB $TRAVIS_PHP_VERSION; fi" - - phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/travis/phpunit-$DB-travis.xml --bootstrap ./tests/bootstrap.php - - sh -c "if [ '$EPV' != '0' ] && [ '$TRAVIS_PHP_VERSION' = '5.3.3' ] && [ '$DB' = 'mysqli' ]; then phpBB/ext/$EXTNAME/vendor/bin/EPV.php run --dir='phpBB/ext/$EXTNAME/'; fi" diff --git a/acp/acp_mchat_info.php b/acp/acp_mchat_info.php index 2777549..0d05d94 100644 --- a/acp/acp_mchat_info.php +++ b/acp/acp_mchat_info.php @@ -4,7 +4,7 @@ * * @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 * */ diff --git a/acp/acp_mchat_module.php b/acp/acp_mchat_module.php index 7d062eb..52fcf45 100644 --- a/acp/acp_mchat_module.php +++ b/acp/acp_mchat_module.php @@ -4,7 +4,7 @@ * * @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 * */ diff --git a/adm/style/acp_mchat_globalsettings.html b/adm/style/acp_mchat_globalsettings.html index ecd9660..4418b95 100644 --- a/adm/style/acp_mchat_globalsettings.html +++ b/adm/style/acp_mchat_globalsettings.html @@ -14,20 +14,31 @@
{L_MCHAT_SETTINGS_INDEX} + + +

{L_MCHAT_INDEX_HEIGHT_EXPLAIN}
-
+
 {L_PIXEL}

{L_MCHAT_MESSAGE_NUM_INDEX_EXPLAIN}
-
+
 {L_MCHAT_ACP_MESSAGES}
+ + +
+ +
{L_MCHAT_SETTINGS_CUSTOM} + + +

{L_MCHAT_CUSTOM_PAGE_EXPLAIN}
@@ -37,12 +48,12 @@

{L_MCHAT_CUSTOM_HEIGHT_EXPLAIN}
-
+
 {L_PIXEL}

{L_MCHAT_MESSAGE_NUM_CUSTOM_EXPLAIN}
-
+
 {L_MCHAT_ACP_MESSAGES}
@@ -54,31 +65,43 @@
+ + +
{L_MCHAT_SETTINGS_ARCHIVE} + + +

{L_MCHAT_MESSAGE_NUM_ARCHIVE_EXPLAIN}
-
+
 {L_MCHAT_ACP_MESSAGES}
+ + +
{L_MCHAT_SETTINGS_MESSAGES} + + +

{L_MCHAT_TIMEOUT_EXPLAIN}
-
+
 {L_MCHAT_ACP_SECONDS}

{L_MCHAT_REFRESH_EXPLAIN}
-
+
 {L_MCHAT_ACP_SECONDS}

{L_MCHAT_EDIT_DELETE_LIMIT_EXPLAIN} -
+
 {L_MCHAT_ACP_SECONDS}

@@ -89,12 +112,12 @@

{L_MCHAT_FLOOD_TIME_EXPLAIN}
-
+
 {L_MCHAT_ACP_SECONDS}

{L_MCHAT_MAX_MESSAGE_LENGTH_EXPLAIN}
-
+
 {L_MCHAT_ACP_CHARACTERS}

@@ -123,9 +146,15 @@ {L_MCHAT_STATIC_MESSAGE_EXPLAIN}
+ + +
{L_MCHAT_SETTINGS_POSTS} + + +
@@ -161,28 +190,49 @@
+ + +
{L_MCHAT_SETTINGS_STATS} + + +

{L_MCHAT_WHOIS_REFRESH_EXPLAIN}
-
+
 {L_MCHAT_ACP_SECONDS}
+ + +
{L_MCHAT_SETTINGS_PRUNE} + + +
-

- {L_MCHAT_PRUNE_EXPLAIN}
+
+
+

+ {L_MCHAT_PRUNE_GC_EXPLAIN}
+
 {L_MCHAT_ACP_SECONDS}
+

{L_MCHAT_PRUNE_NUM_EXPLAIN}
-
+
+ + +
@@ -202,9 +252,14 @@
+ + +
+ +

  diff --git a/adm/style/acp_mchat_globalusersettings.html b/adm/style/acp_mchat_globalusersettings.html index 332b413..2301dba 100644 --- a/adm/style/acp_mchat_globalusersettings.html +++ b/adm/style/acp_mchat_globalusersettings.html @@ -16,7 +16,7 @@

{L_ACP_MCHAT_GLOBALUSERSETTINGS} - +
{L_MCHAT_GLOBALUSERSETTINGS_OVERWRITE} diff --git a/adm/style/acp_mchat_globalusersettings_content.html b/adm/style/acp_mchat_globalusersettings_content.html index 899e7b2..cbb764e 100644 --- a/adm/style/acp_mchat_globalusersettings_content.html +++ b/adm/style/acp_mchat_globalusersettings_content.html @@ -1,3 +1,5 @@ + +
@@ -26,7 +28,13 @@
+ + +
+ + +

{L_MCHAT_MESSAGE_TOP_EXPLAIN}
@@ -63,7 +71,7 @@
-
+
@@ -92,7 +100,13 @@
+ + +
+ + +
@@ -100,3 +114,5 @@
+ + diff --git a/adm/style/event/acp_users_prefs_append.html b/adm/style/event/acp_users_prefs_append.html index 44f9033..42b4a32 100644 --- a/adm/style/event/acp_users_prefs_append.html +++ b/adm/style/event/acp_users_prefs_append.html @@ -1,5 +1,5 @@

{L_MCHAT_ACP_USER_PREFS_EXPLAIN}

{L_MCHAT_PREFERENCES} - +
diff --git a/composer.json b/composer.json index 5bb982a..bcb8f7e 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,8 @@ "type": "phpbb-extension", "description": "mChat", "homepage": "https://github.com/kasimi/mChat", - "version": "2.0.0-RC6", - "time": "2016-09-18", + "version": "2.0.0-RC7", + "time": "2016-10-16", "keywords": ["phpbb", "extension", "mchat"], "license": "GPL-2.0", "authors": [ @@ -28,7 +28,7 @@ ], "require": { "php": ">=5.3.3", - "phpbb/phpbb": ">=3.1.7-PL1,<3.3.0@dev" + "phpbb/phpbb": ">=3.1.8-RC1,<3.3.0@dev" }, "require-dev": { "phpbb/epv": "dev-master" @@ -36,7 +36,13 @@ "extra": { "display-name": "mChat", "soft-require": { - "phpbb/phpbb": ">=3.1.7-PL1,<3.3.0@dev" + "phpbb/phpbb": ">=3.1.8-RC1,<3.3.0@dev" + }, + "version-check": { + "host": "kasimi.github.io", + "directory": "/mChat", + "filename": "mchat_version.json", + "ssl": true } } } diff --git a/config/services.yml b/config/services.yml index fdf49be..f992450 100644 --- a/config/services.yml +++ b/config/services.yml @@ -10,8 +10,9 @@ services: - '@log' - '@user' - '@dbal.conn' - - '@cache' + - '@cache.driver' - '@request' + - '@dispatcher' - '@dmzx.mchat.settings' - '%dmzx.mchat.table.mchat%' - '%dmzx.mchat.table.mchat_log%' @@ -26,6 +27,7 @@ services: - '@dbal.conn' - '@request' - '@dmzx.mchat.settings' + - '@dispatcher' - '%core.root_path%' - '%core.php_ext%' dmzx.mchat.core: @@ -43,6 +45,7 @@ services: - '@ext.manager' - '%core.root_path%' - '%core.php_ext%' + - '@?text_formatter.s9e.parser' - '@?phpbb.collapsiblecategories.operator' dmzx.mchat.functions: class: dmzx\mchat\core\functions @@ -65,6 +68,7 @@ services: - '@user' - '@config' - '@auth' + - '@dispatcher' dmzx.mchat.acp.listener: class: dmzx\mchat\event\acp_listener arguments: diff --git a/controller/acp_controller.php b/controller/acp_controller.php index 40e84bf..2bc97ee 100644 --- a/controller/acp_controller.php +++ b/controller/acp_controller.php @@ -4,37 +4,50 @@ * * @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\functions; +use dmzx\mchat\core\settings; +use phpbb\cache\driver\driver_interface as cache_interface; +use phpbb\db\driver\driver_interface as db_interface; +use phpbb\event\dispatcher_interface; +use phpbb\log\log_interface; +use phpbb\request\request_interface; +use phpbb\template\template; +use phpbb\user; + class acp_controller { - /** @var \dmzx\mchat\core\functions */ + /** @var functions */ protected $functions; - /** @var \phpbb\template\template */ + /** @var template */ protected $template; - /** @var \phpbb\log\log_interface */ + /** @var log_interface */ protected $log; - /** @var \phpbb\user */ + /** @var user */ protected $user; - /** @var \phpbb\db\driver\driver_interface */ + /** @var db_interface */ protected $db; - /** @var \phpbb\cache\service */ + /** @var cache_interface */ protected $cache; - /** @var \phpbb\request\request */ + /** @var request_interface */ protected $request; - /** @var \dmzx\mchat\core\settings */ + /** @var dispatcher_interface */ + protected $dispatcher; + + /** @var settings */ protected $settings; /** @var string */ @@ -52,20 +65,34 @@ class acp_controller /** * Constructor * - * @param \dmzx\mchat\core\functions $functions - * @param \phpbb\template\template $template - * @param \phpbb\log\log_interface $log - * @param \phpbb\user $user - * @param \phpbb\db\driver\driver_interface $db - * @param \phpbb\cache\service $cache - * @param \phpbb\request\request $request - * @param \dmzx\mchat\core\settings $settings - * @param string $mchat_table - * @param string $mchat_log_table - * @param string $root_path - * @param string $php_ext + * @param functions $functions + * @param template $template + * @param log_interface $log + * @param user $user + * @param db_interface $db + * @param cache_interface $cache + * @param request_interface $request + * @param dispatcher_interface $dispatcher + * @param settings $settings + * @param string $mchat_table + * @param string $mchat_log_table + * @param string $root_path + * @param string $php_ext */ - public function __construct(\dmzx\mchat\core\functions $functions, \phpbb\template\template $template, \phpbb\log\log_interface $log, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\request\request $request, \dmzx\mchat\core\settings $settings, $mchat_table, $mchat_log_table, $root_path, $php_ext) + public function __construct( + functions $functions, + template $template, + log_interface $log, + user $user, + db_interface $db, + cache_interface $cache, + request_interface $request, + dispatcher_interface $dispatcher, + settings $settings, + $mchat_table, + $mchat_log_table, + $root_path, $php_ext + ) { $this->functions = $functions; $this->template = $template; @@ -74,6 +101,7 @@ class acp_controller $this->db = $db; $this->cache = $cache; $this->request = $request; + $this->dispatcher = $dispatcher; $this->settings = $settings; $this->mchat_table = $mchat_table; $this->mchat_log_table = $mchat_log_table; @@ -98,7 +126,7 @@ class acp_controller { $mchat_new_config = array(); $validation = array(); - foreach ($this->settings->global as $config_name => $config_data) + foreach ($this->settings->global_settings() as $config_name => $config_data) { $default = $this->settings->cfg($config_name); settype($default, gettype($config_data['default'])); @@ -113,6 +141,8 @@ class acp_controller if (!$is_founder) { unset($mchat_new_config['mchat_prune']); + unset($mchat_new_config['mchat_prune_gc']); + unset($mchat_new_config['mchat_prune_mode']); unset($mchat_new_config['mchat_prune_num']); } @@ -128,6 +158,20 @@ class acp_controller $error[] = 'FORM_INVALID'; } + /** + * Event to modify ACP global settings data before they are updated + * + * @event dmzx.mchat.acp_globalsettings_update_data + * @var array mchat_new_config Array containing the ACP settings data that is 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.acp_globalsettings_update_data', compact($vars))); + if (!$error) { // Set the options the user configured @@ -163,19 +207,36 @@ class acp_controller } } - foreach (array_keys($this->settings->global) as $key) - { - $this->template->assign_var(strtoupper($key), $this->settings->cfg($key)); - } - - $this->template->assign_vars(array( + $template_data = array( 'MCHAT_ERROR' => implode('
', $error), 'MCHAT_VERSION' => $this->settings->cfg('mchat_version'), 'MCHAT_FOUNDER' => $is_founder, + 'S_MCHAT_PRUNE_MODE_OPTIONS' => $this->get_prune_mode_options($this->settings->cfg('mchat_prune_mode')), 'L_MCHAT_BBCODES_DISALLOWED_EXPLAIN' => $this->user->lang('MCHAT_BBCODES_DISALLOWED_EXPLAIN', 'root_path}adm/index.$this->php_ext", 'i=bbcodes', true, $this->user->session_id) . '">', ''), 'L_MCHAT_TIMEOUT_EXPLAIN' => $this->user->lang('MCHAT_TIMEOUT_EXPLAIN','root_path}adm/index.$this->php_ext", 'i=board&mode=load', true, $this->user->session_id) . '">', '', $this->settings->cfg('session_length')), 'U_ACTION' => $u_action, - )); + ); + + foreach (array_keys($this->settings->global_settings()) as $key) + { + $template_data[strtoupper($key)] = $this->settings->cfg($key); + } + + /** + * Event to modify ACP global settings template data + * + * @event dmzx.mchat.acp_globalsettings_modify_template_data + * @var array template_data Array containing the template data for the ACP settings + * @var array error Array with error lang keys + * @since 2.0.0-RC7 + */ + $vars = array( + 'template_data', + 'error', + ); + extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalsettings_modify_template_data', compact($vars))); + + $this->template->assign_vars($template_data); } /** @@ -185,15 +246,13 @@ class acp_controller { add_form_key('acp_mchat'); - $this->user->add_lang_ext('dmzx/mchat', 'mchat_ucp'); - $error = array(); if ($this->request->is_set_post('submit')) { $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) { $default = $this->settings->cfg($config_name, true); settype($default, gettype($config_data['default'])); @@ -217,16 +276,36 @@ class acp_controller $error[] = 'FORM_INVALID'; } + $mchat_new_user_config = array(); + + if ($this->request->variable('mchat_overwrite', 0) && $this->request->variable('mchat_overwrite_confirm', 0)) + { + foreach ($mchat_new_config as $config_name => $config_value) + { + $mchat_new_user_config['user_' . $config_name] = $config_value; + } + } + + /** + * Event to modify ACP global user settings data before they are updated + * + * @event dmzx.mchat.acp_globalusersettings_update_data + * @var array mchat_new_config Array containing the ACP global user settings data that is about to be sent to the database + * @var array mchat_new_user_config Array containing the user settings data when overwriting all user settings + * @var array error Array with error lang keys + * @since 2.0.0-RC7 + */ + $vars = array( + 'mchat_new_config', + 'mchat_new_user_config', + 'error', + ); + extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalusersettings_update_data', compact($vars))); + if (!$error) { - if ($this->request->variable('mchat_overwrite', 0) && $this->request->variable('mchat_overwrite_confirm', 0)) + if ($mchat_new_user_config) { - $mchat_new_user_config = array(); - foreach ($mchat_new_config as $config_name => $config_value) - { - $mchat_new_user_config['user_' . $config_name] = $config_value; - } - $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $mchat_new_user_config); $this->db->sql_query($sql); } @@ -247,23 +326,59 @@ class acp_controller $error = array_map(array($this->user, 'lang'), $error); } - foreach (array_keys($this->settings->ucp) as $key) + // Force global date format for $selected_date value, not user-specific + $selected_date = $this->settings->cfg('mchat_date', true); + $template_data = $this->settings->get_date_template_data($selected_date); + + foreach (array_keys($this->settings->ucp_settings()) as $key) { - $this->template->assign_var(strtoupper($key), $this->settings->cfg($key, true)); + $template_data[strtoupper($key)] = $this->settings->cfg($key, true); } - // Force global date format for $selected value, not user-specific - $selected = $this->settings->cfg('mchat_date', true); - $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( - 'MCHAT_ERROR' => implode('
', $error), - 'MCHAT_VERSION' => $this->settings->cfg('mchat_version'), - 'U_ACTION' => $u_action, + $template_data = array_merge($template_data, array( + 'MCHAT_POSTS_ENABLED_LANG' => $this->settings->get_enabled_post_notifications_lang(), + 'MCHAT_ERROR' => implode('
', $error), + 'MCHAT_VERSION' => $this->settings->cfg('mchat_version'), + 'U_ACTION' => $u_action, )); + + /** + * Event to modify ACP global user settings template data + * + * @event dmzx.mchat.acp_globalusersettings_modify_template_data + * @var array template_data Array containing the template data for the ACP user settings + * @var array error Array with error lang keys + * @since 2.0.0-RC7 + */ + $vars = array( + 'template_data', + 'error', + ); + extract($this->dispatcher->trigger_event('dmzx.mchat.acp_globalusersettings_modify_template_data', compact($vars))); + + $this->template->assign_vars($template_data); + } + + /** + * @param $selected + * @return array + */ + protected function get_prune_mode_options($selected) + { + if (empty($this->settings->prune_modes[$selected])) + { + $selected = 0; + } + + $prune_mode_options = ''; + + foreach ($this->settings->prune_modes as $i => $prune_mode) + { + $prune_mode_options .= ''; + } + + return $prune_mode_options; } } diff --git a/controller/ucp_controller.php b/controller/ucp_controller.php index 37a4db4..eaf07f5 100644 --- a/controller/ucp_controller.php +++ b/controller/ucp_controller.php @@ -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('
', $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); } } diff --git a/core/functions.php b/core/functions.php index 6421281..fe186d7 100644 --- a/core/functions.php +++ b/core/functions.php @@ -4,34 +4,41 @@ * * @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\core; +use phpbb\auth\auth; +use phpbb\cache\driver\driver_interface as cache_interface; +use phpbb\db\driver\driver_interface as db_interface; +use phpbb\event\dispatcher_interface; +use phpbb\log\log_interface; +use phpbb\user; + class functions { - /** @var \dmzx\mchat\core\settings */ + /** @var settings */ protected $settings; - /** @var \phpbb\user */ + /** @var user */ protected $user; - /** @var \phpbb\auth\auth */ + /** @var auth */ protected $auth; - /** @var \phpbb\log\log */ + /** @var log_interface */ protected $log; - /** @var \phpbb\db\driver\driver_interface */ + /** @var db_interface */ protected $db; - /** @var \phpbb\cache\driver\driver_interface */ + /** @var cache_interface */ protected $cache; - /** @var \phpbb\event\dispatcher_interface */ + /** @var dispatcher_interface */ protected $dispatcher; /** @var string */ @@ -70,33 +77,46 @@ class functions /** * Constructor * - * @param \dmzx\mchat\core\settings $settings - * @param \phpbb\user $user - * @param \phpbb\auth\auth $auth - * @param \phpbb\log\log_interface $log - * @param \phpbb\db\driver\driver_interface $db - * @param \phpbb\cache\driver\driver_interface $cache - * @param \phpbb\event\dispatcher_interface $dispatcher - * @param string $root_path - * @param string $php_ext - * @param string $mchat_table - * @param string $mchat_log_table - * @param string $mchat_sessions_table + * @param settings $settings + * @param user $user + * @param auth $auth + * @param log_interface $log + * @param db_interface $db + * @param cache_interface $cache + * @param dispatcher_interface $dispatcher + * @param string $root_path + * @param string $php_ext + * @param string $mchat_table + * @param string $mchat_log_table + * @param string $mchat_sessions_table */ - function __construct(\dmzx\mchat\core\settings $settings, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, \phpbb\event\dispatcher_interface $dispatcher, $root_path, $php_ext, $mchat_table, $mchat_log_table, $mchat_sessions_table) + function __construct( + settings $settings, + user $user, + auth $auth, + log_interface $log, + db_interface $db, + cache_interface $cache, + dispatcher_interface $dispatcher, + $root_path, + $php_ext, + $mchat_table, + $mchat_log_table, + $mchat_sessions_table + ) { - $this->settings = $settings; - $this->user = $user; - $this->auth = $auth; - $this->log = $log; - $this->db = $db; - $this->cache = $cache; - $this->dispatcher = $dispatcher; - $this->root_path = $root_path; - $this->php_ext = $php_ext; - $this->mchat_table = $mchat_table; - $this->mchat_log_table = $mchat_log_table; - $this->mchat_sessions_table = $mchat_sessions_table; + $this->settings = $settings; + $this->user = $user; + $this->auth = $auth; + $this->log = $log; + $this->db = $db; + $this->cache = $cache; + $this->dispatcher = $dispatcher; + $this->root_path = $root_path; + $this->php_ext = $php_ext; + $this->mchat_table = $mchat_table; + $this->mchat_log_table = $mchat_log_table; + $this->mchat_sessions_table = $mchat_sessions_table; } /** @@ -292,35 +312,33 @@ class functions */ public function mchat_prune() { - $sql_aray = array( + $prune_num = (int) $this->settings->cfg('mchat_prune_num'); + $prune_mode = (int) $this->settings->cfg('mchat_prune_mode'); + + if (empty($this->settings->prune_modes[$prune_mode])) + { + return array(); + } + + $sql_array = array( 'SELECT' => 'message_id', 'FROM' => array($this->mchat_table => 'm'), ); - $prune_num = $this->settings->cfg('mchat_prune_num'); - - if (ctype_digit($prune_num)) + if ($this->settings->prune_modes[$prune_mode] === 'messages') { - // Retain fixed number of messages + // Skip fixed number of messages, delete all others + $sql_array['ORDER_BY'] = 'm.message_id DESC'; $offset = $prune_num; - $sql_aray['ORDER_BY'] = 'message_id DESC'; } else { - // Retain messages of a time period - $time_period = strtotime($prune_num, 0); - - if ($time_period === false) - { - $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNE_FAIL', false, array($this->user->data['username'])); - return false; - } - + // Delete messages older than time period + $sql_array['WHERE'] = 'm.message_time < ' . (int) strtotime($prune_num * $prune_mode . ' hours ago'); $offset = 0; - $sql_aray['WHERE'] = 'message_time < ' . (int) (time() - $time_period); } - $sql = $this->db->sql_build_query('SELECT', $sql_aray); + $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query_limit($sql, 0, $offset); $rows = $this->db->sql_fetchrowset(); $this->db->sql_freeresult($result); @@ -349,9 +367,9 @@ class functions $this->db->sql_query('DELETE FROM ' . $this->mchat_table . ' WHERE ' . $this->db->sql_in_set('message_id', $prune_ids)); $this->db->sql_query('DELETE FROM ' . $this->mchat_log_table . ' WHERE ' . $this->db->sql_in_set('message_id', $prune_ids)); $this->cache->destroy('sql', $this->mchat_log_table); - } - $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED', false, array($this->user->data['username'], count($prune_ids))); + $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED', false, array($this->user->data['username'], count($prune_ids))); + } return $prune_ids; } @@ -363,9 +381,12 @@ class functions */ public function mchat_total_message_count() { + $sql_where_ary = $this->get_sql_where_for_notifcation_messages(); + $sql_array = array( 'SELECT' => 'COUNT(*) AS rows_total', 'FROM' => array($this->mchat_table => 'm'), + 'WHERE' => $sql_where_ary ? $this->db->sql_escape('(' . implode(') AND (', $sql_where_ary) . ')') : '', ); /** @@ -418,22 +439,11 @@ class functions $sql_where_message_id[] = $this->db->sql_in_set('m.message_id', array_map('intval', $message_ids)); } - $sql_where_ary = $sql_where_message_id ? array(implode(' OR ', $sql_where_message_id)) : array(); + $sql_where_ary = $this->get_sql_where_for_notifcation_messages(); - if ($this->settings->cfg('mchat_posts')) + if ($sql_where_message_id) { - // If the current user doesn't have permission to see hidden users, exclude their login posts - if (!$this->auth->acl_get('u_viewonline')) - { - $sql_where_ary[] = 'm.post_id <> ' . (int) self::LOGIN_HIDDEN . // Exclude all notifications that were created by hidden users ... - ' OR m.user_id = ' . (int) $this->user->data['user_id'] . // ... but include all login notifications of the current user - ' OR m.forum_id <> 0'; // ... and include all post notifications - } - } - else - { - // Exclude all post notifications - $sql_where_ary[] = 'm.post_id = 0'; + $sql_where_ary[] = implode(' OR ', $sql_where_message_id); } $sql_array = array( @@ -490,6 +500,35 @@ class functions return $rows; } + /** + * Generates SQL where conditions to include or exlude notifacation + * messages based on the current user's settings and permissions + * + * @return array + */ + protected function get_sql_where_for_notifcation_messages() + { + $sql_where_ary = array(); + + if ($this->settings->cfg('mchat_posts')) + { + // If the current user doesn't have permission to see hidden users, exclude their login posts + if (!$this->auth->acl_get('u_viewonline')) + { + $sql_where_ary[] = 'm.post_id <> ' . (int) self::LOGIN_HIDDEN . // Exclude all notifications that were created by hidden users ... + ' OR m.user_id = ' . (int) $this->user->data['user_id'] . // ... but include all login notifications of the current user + ' OR m.forum_id <> 0'; // ... and include all post notifications + } + } + else + { + // Exclude all post notifications + $sql_where_ary[] = 'm.post_id = 0'; + } + + return $sql_where_ary; + } + /** * Fetches log entries from the database and sorts them * @@ -646,14 +685,18 @@ class functions foreach ($rows as $row) { - // Skip deleted posts - if (isset($row['post_subject'])) - { - $post_subjects[$row['post_id']] = array( - 'post_subject' => $row['post_subject'], - 'forum_name' => $row['forum_name'], - ); - } + $post_subjects[$row['post_id']] = array( + 'post_subject' => $row['post_subject'], + 'forum_name' => $row['forum_name'], + ); + } + + // Handle deleted posts + $non_existent_post_ids = array_diff($post_ids, array_keys($post_subjects)); + + foreach ($non_existent_post_ids as $post_id) + { + $post_subjects[$post_id] = null; } return $post_subjects; diff --git a/core/mchat.php b/core/mchat.php index 2bb6741..1008def 100644 --- a/core/mchat.php +++ b/core/mchat.php @@ -4,46 +4,56 @@ * * @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\core; -use Symfony\Component\HttpFoundation\JsonResponse; +use phpbb\auth\auth; +use phpbb\collapsiblecategories\operator\operator as cc_operator; +use phpbb\controller\helper; +use phpbb\event\dispatcher_interface; use phpbb\exception\http_exception; +use phpbb\extension\manager; +use phpbb\pagination; +use phpbb\request\request_interface; +use phpbb\template\template; +use phpbb\textformatter\parser_interface; +use phpbb\user; +use Symfony\Component\HttpFoundation\JsonResponse; class mchat { - /** @var \dmzx\mchat\core\functions */ + /** @var functions */ protected $functions; - /** @var \dmzx\mchat\core\settings */ + /** @var settings */ protected $settings; - /** @var \phpbb\controller\helper */ + /** @var helper */ protected $helper; - /** @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\pagination */ + /** @var pagination */ protected $pagination; - /** @var \phpbb\request\request */ + /** @var request_interface */ protected $request; - /** @var \phpbb\event\dispatcher_interface */ + /** @var dispatcher_interface */ protected $dispatcher; - /** @var \phpbb\extension\manager */ + /** @var manager */ protected $extension_manager; /** @var string */ @@ -52,7 +62,10 @@ class mchat /** @var string */ protected $php_ext; - /** @var \phpbb\collapsiblecategories\operator\operator */ + /** @var parser_interface */ + protected $parser; + + /** @var cc_operator */ protected $cc_operator; /** @var boolean */ @@ -67,21 +80,37 @@ class mchat /** * Constructor * - * @param \dmzx\mchat\core\functions $functions - * @param \dmzx\mchat\core\settings $settings - * @param \phpbb\controller\helper $helper - * @param \phpbb\template\template $template - * @param \phpbb\user $user - * @param \phpbb\auth\auth $auth - * @param \phpbb\pagination $pagination - * @param \phpbb\request\request $request - * @param \phpbb\event\dispatcher_interface $dispatcher - * @param \phpbb\extension\manager $extension_manager - * @param string $root_path - * @param string $php_ext - * @param \phpbb\collapsiblecategories\operator\operator $cc_operator + * @param functions $functions + * @param settings $settings + * @param helper $helper + * @param template $template + * @param user $user + * @param auth $auth + * @param pagination $pagination + * @param request_interface $request + * @param dispatcher_interface $dispatcher + * @param manager $extension_manager + * @param string $root_path + * @param string $php_ext + * @param parser_interface $parser + * @param cc_operator $cc_operator */ - public function __construct(\dmzx\mchat\core\functions $functions, \dmzx\mchat\core\settings $settings, \phpbb\controller\helper $helper, \phpbb\template\template $template, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\pagination $pagination, \phpbb\request\request $request, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\extension\manager $extension_manager, $root_path, $php_ext, \phpbb\collapsiblecategories\operator\operator $cc_operator = null) + public function __construct( + functions $functions, + settings $settings, + helper $helper, + template $template, + user $user, + auth $auth, + pagination $pagination, + request_interface $request, + dispatcher_interface $dispatcher, + manager $extension_manager, + $root_path, + $php_ext, + parser_interface $parser = null, + cc_operator $cc_operator = null + ) { $this->functions = $functions; $this->settings = $settings; @@ -95,6 +124,7 @@ class mchat $this->extension_manager = $extension_manager; $this->root_path = $root_path; $this->php_ext = $php_ext; + $this->parser = $parser; $this->cc_operator = $cc_operator; $this->template->assign_vars(array( @@ -315,11 +345,18 @@ class mchat $message = $this->request->variable('message', '', true); - $message_data = array( - 'user_id' => $this->user->data['user_id'], - 'user_ip' => $this->user->data['session_ip'], - 'message_time' => time(), - ); + if ($this->settings->cfg('mchat_capital_letter')) + { + $message = utf8_ucfirst($message); + } + + $message_data = $this->process_message($message); + + $message_data = array_merge($message_data, array( + 'user_id' => $this->user->data['user_id'], + 'user_ip' => $this->user->data['session_ip'], + 'message_time' => time(), + )); /** * Event to modify a new message before it is inserted in the database @@ -335,14 +372,7 @@ class mchat ); extract($this->dispatcher->trigger_event('dmzx.mchat.action_add_before', compact($vars))); - $sql_ary = array_merge($this->process_message($message), $message_data); - - if ($this->settings->cfg('mchat_capital_letter')) - { - $sql_ary['message'] = utf8_ucfirst($sql_ary['message']); - } - - $is_new_session = $this->functions->mchat_action('add', $sql_ary); + $is_new_session = $this->functions->mchat_action('add', $message_data); $response = $this->action_refresh(true); @@ -815,7 +845,7 @@ class mchat $rows = $this->functions->mchat_get_messages(array(), 0, $limit, $start); $this->assign_global_template_data(); - $this->assign_messages($rows); + $this->assign_messages($rows, $page); // Render pagination if ($page === 'archive') @@ -907,8 +937,8 @@ class mchat $this->template->assign_vars(array( 'MCHAT_DISPLAY_NAME' => $meta['extra']['display-name'], - 'MCHAT_AUTHOR_NAMES' => implode(' • ', $author_names), - 'MCHAT_AUTHOR_HOMEPAGES' => implode(' • ', $author_homepages), + 'MCHAT_AUTHOR_NAMES' => implode(' & ', $author_names), + 'MCHAT_AUTHOR_HOMEPAGES' => implode(' & ', $author_homepages), )); } @@ -963,8 +993,9 @@ class mchat * Assigns all message rows to the template * * @param array $rows + * @param string $page */ - public function assign_messages($rows) + public function assign_messages($rows, $page = '') { $rows = array_filter($rows, array($this, 'has_read_auth')); @@ -974,7 +1005,7 @@ class mchat } // Reverse the array if messages appear at the bottom - if (!$this->settings->cfg('mchat_message_top')) + if ($page !== 'archive' && !$this->settings->cfg('mchat_message_top')) { $rows = array_reverse($rows); } @@ -1188,8 +1219,15 @@ class mchat 'f' => $row['forum_id'], )); - $args[] = '[url=' . $viewtopic_url . ']' . $post_data['post_subject'] . '[/url]'; - $args[] = '[url=' . $viewforum_url . ']' . $post_data['forum_name'] . '[/url]'; + if ($post_data) + { + $args[] = '[url=' . $viewtopic_url . ']' . $post_data['post_subject'] . '[/url]'; + $args[] = '[url=' . $viewforum_url . ']' . $post_data['forum_name'] . '[/url]'; + } + else + { + $args[0] .= '_DELETED'; + } } else if ($row['post_id'] == functions::LOGIN_HIDDEN) { @@ -1328,7 +1366,7 @@ class mchat */ public function set_user_default_values($sql_ary) { - foreach (array_keys($this->settings->ucp) as $config_name) + foreach (array_keys($this->settings->ucp_settings()) as $config_name) { $sql_ary['user_' . $config_name] = $this->settings->cfg($config_name, true); } @@ -1469,22 +1507,34 @@ class mchat $this->settings->set_cfg('max_post_smilies', 0, true); } - $mchat_bbcode = $this->settings->cfg('allow_bbcode') && $this->auth->acl_get('u_mchat_bbcode'); - $mchat_urls = $this->settings->cfg('allow_post_links') && $this->auth->acl_get('u_mchat_urls'); - $mchat_smilies = $this->settings->cfg('allow_smilies') && $this->auth->acl_get('u_mchat_smilies'); + $disallowed_bbcodes = array_filter(explode('|', $this->settings->cfg('mchat_bbcode_disallowed'))); - // Add function part code from http://wiki.phpbb.com/Parsing_text - $uid = $bitfield = $options = ''; - generate_text_for_storage($message, $uid, $bitfield, $options, $mchat_bbcode, $mchat_urls, $mchat_smilies); + $mchat_bbcode = $this->settings->cfg('allow_bbcode') && $this->auth->acl_get('u_mchat_bbcode'); + $mchat_magic_urls = $this->settings->cfg('allow_post_links') && $this->auth->acl_get('u_mchat_urls'); + $mchat_smilies = $this->settings->cfg('allow_smilies') && $this->auth->acl_get('u_mchat_smilies'); - // Not allowed bbcodes - if (!$mchat_bbcode) + // These arguments for generate_text_for_storage() are ignored in 3.1.x + $mchat_img = $mchat_flash = $mchat_quote = $mchat_url = $mchat_bbcode; + + // Disallowed bbcodes for 3.2.x + if ($disallowed_bbcodes && $this->parser !== null) { - $message = preg_replace('#\[/?[^\[\]]+\]#Usi', '', $message); + $mchat_img &= !in_array('img', $disallowed_bbcodes); + $mchat_flash &= !in_array('flash', $disallowed_bbcodes); + $mchat_quote &= !in_array('quote', $disallowed_bbcodes); + $mchat_url &= !in_array('url', $disallowed_bbcodes); + + foreach ($disallowed_bbcodes as $bbcode) + { + $this->parser->disable_bbcode($bbcode); + } } - // Disallowed bbcodes - if ($this->settings->cfg('mchat_bbcode_disallowed')) + $uid = $bitfield = $options = ''; + generate_text_for_storage($message, $uid, $bitfield, $options, $mchat_bbcode, $mchat_magic_urls, $mchat_smilies, $mchat_img, $mchat_flash, $mchat_quote, $mchat_url); + + // Disallowed bbcodes for 3.1.x + if ($disallowed_bbcodes && $this->parser === null) { $bbcode_replace = array( '#\[(' . str_replace('*', '\*', $this->settings->cfg('mchat_bbcode_disallowed')) . ')[^\[\]]+\]#Usi', diff --git a/core/settings.php b/core/settings.php index 8dff910..24b9e64 100644 --- a/core/settings.php +++ b/core/settings.php @@ -4,31 +4,39 @@ * * @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\core; +use phpbb\auth\auth; +use phpbb\config\config; +use phpbb\event\dispatcher_interface; +use phpbb\user; + class settings { - /** @var \phpbb\user */ + /** @var user */ protected $user; - /** @var \phpbb\config\config */ + /** @var config */ protected $config; - /** @var \phpbb\auth\auth */ + /** @var auth */ protected $auth; + /** @var dispatcher_interface */ + protected $dispatcher; + /** * Keys for global settings that only the administrator is allowed to modify. * The values are stored in the phpbb_config table. * * @var array */ - public $global; + protected $global_settings; /** * Keys for user-specific settings for which the administrator can set default @@ -39,7 +47,20 @@ class settings * * @var array */ - public $ucp; + protected $ucp_settings; + + /** + * Prune modes listed in the ACP. For values other than messages the key is the + * amount of hours that is later multiplied with the value that is set in the ACP. + * + * @var array + */ + public $prune_modes = array( + 0 => 'messages', + 1 => 'hours', + 24 => 'days', + 168 => 'weeks', + ); /** @var bool */ public $is_phpbb31; @@ -50,17 +71,33 @@ class settings /** * Constructor * - * @param \phpbb\user $user - * @param \phpbb\config\config $config - * @param \phpbb\auth\auth $auth + * @param user $user + * @param config $config + * @param auth $auth + * @param dispatcher_interface $dispatcher */ - public function __construct(\phpbb\user $user, \phpbb\config\config $config, \phpbb\auth\auth $auth) + public function __construct( + user $user, + config $config, + auth $auth, + dispatcher_interface $dispatcher + ) { $this->user = $user; $this->config = $config; $this->auth = $auth; + $this->dispatcher = $dispatcher; - $this->global = array( + $this->is_phpbb31 = phpbb_version_compare(PHPBB_VERSION, '3.1.0@dev', '>=') && phpbb_version_compare(PHPBB_VERSION, '3.2.0@dev', '<'); + $this->is_phpbb32 = phpbb_version_compare(PHPBB_VERSION, '3.2.0@dev', '>=') && phpbb_version_compare(PHPBB_VERSION, '3.3.0@dev', '<'); + } + + /** + * @return array + */ + public function initialize_global_settings() + { + $global_settings = array( 'mchat_bbcode_disallowed' => array('default' => '', 'validation' => array('string', false, 0, 255)), 'mchat_custom_height' => array('default' => 350, 'validation' => array('num', false, 50, 1000)), 'mchat_custom_page' => array('default' => 1), @@ -82,7 +119,9 @@ class settings 'mchat_posts_topic' => array('default' => 0), 'mchat_posts_login' => array('default' => 0), 'mchat_prune' => array('default' => 0), - 'mchat_prune_num' => array('default' => '0'), + 'mchat_prune_gc' => array('default' => strtotime('1 day', 0)), + 'mchat_prune_mode' => array('default' => 0), + 'mchat_prune_num' => array('default' => 0), 'mchat_refresh' => array('default' => 10, 'validation' => array('num', false, 5, 60)), 'mchat_rules' => array('default' => '', 'validation' => array('string', false, 0, 255)), 'mchat_static_message' => array('default' => '', 'validation' => array('string', false, 0, 255)), @@ -90,7 +129,27 @@ class settings 'mchat_whois_refresh' => array('default' => 60, 'validation' => array('num', false, 10, 300)), ); - $this->ucp = array( + /** + * Event to modify global settings data + * + * @event dmzx.mchat.global_settings_modify + * @var array global_settings Array containing global settings data + * @since 2.0.0-RC7 + */ + $vars = array( + 'global_settings', + ); + extract($this->dispatcher->trigger_event('dmzx.mchat.global_settings_modify', compact($vars))); + + return $global_settings; + } + + /** + * @return array + */ + public function initialize_ucp_settings() + { + $ucp_settings = array( 'mchat_avatars' => array('default' => 1), 'mchat_capital_letter' => array('default' => 1), 'mchat_character_count' => array('default' => 1), @@ -107,8 +166,45 @@ class settings 'mchat_whois_index' => array('default' => 1), ); - $this->is_phpbb31 = phpbb_version_compare(PHPBB_VERSION, '3.1.0@dev', '>=') && phpbb_version_compare(PHPBB_VERSION, '3.2.0@dev', '<'); - $this->is_phpbb32 = phpbb_version_compare(PHPBB_VERSION, '3.2.0@dev', '>=') && phpbb_version_compare(PHPBB_VERSION, '3.3.0@dev', '<'); + /** + * Event to modify UCP settings data + * + * @event dmzx.mchat.ucp_settings_modify + * @var array ucp_settings Array containing UCP settings data + * @since 2.0.0-RC7 + */ + $vars = array( + 'ucp_settings', + ); + extract($this->dispatcher->trigger_event('dmzx.mchat.ucp_settings_modify', compact($vars))); + + return $ucp_settings; + } + + /** + * @return array + */ + public function global_settings() + { + if (empty($this->global_settings)) + { + $this->global_settings = $this->initialize_global_settings(); + } + + return $this->global_settings; + } + + /** + * @return array + */ + public function ucp_settings() + { + if (empty($this->ucp_settings)) + { + $this->ucp_settings = $this->initialize_ucp_settings(); + } + + return $this->ucp_settings; } /** @@ -124,13 +220,15 @@ class settings /** * @param string $config * @param array $user_data - * @param \phpbb\auth\auth $auth + * @param auth $auth * @param bool $force_global * @return string */ public function cfg_user($config, $user_data, $auth, $force_global = false) { - if (!$force_global && isset($this->ucp[$config]) && $auth->acl_get('u_' . $config)) + $ucp_settings = $this->ucp_settings(); + + if (!$force_global && isset($ucp_settings[$config]) && $auth->acl_get('u_' . $config)) { return $user_data['user_' . $config]; } @@ -180,9 +278,11 @@ class settings } $dateformat_options .= '>' . $this->user->lang('MCHAT_CUSTOM_DATEFORMAT') . ''; + $ucp_settings = $this->ucp_settings(); + return array( 'S_MCHAT_DATEFORMAT_OPTIONS' => $dateformat_options, - 'A_MCHAT_DEFAULT_DATEFORMAT' => addslashes($this->ucp['mchat_date']['default']), + 'A_MCHAT_DEFAULT_DATEFORMAT' => addslashes($ucp_settings['mchat_date']['default']), 'S_MCHAT_CUSTOM_DATEFORMAT' => $s_custom, ); } diff --git a/cron/mchat_prune.php b/cron/mchat_prune.php index 2c3f087..11bcc31 100644 --- a/cron/mchat_prune.php +++ b/cron/mchat_prune.php @@ -4,31 +4,38 @@ * * @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\cron; -class mchat_prune extends \phpbb\cron\task\base +use dmzx\mchat\core\functions; +use dmzx\mchat\core\settings; +use phpbb\cron\task\base; + +class mchat_prune extends base { - /** @var \dmzx\mchat\core\functions */ + /** @var functions */ protected $functions; - /** @var \dmzx\mchat\core\settings */ + /** @var settings */ protected $settings; /** * Constructor * - * @param \dmzx\mchat\core\functions $functions - * @param \dmzx\mchat\core\settings $settings + * @param functions $functions + * @param settings $settings */ - public function __construct(\dmzx\mchat\core\functions $functions, \dmzx\mchat\core\settings $settings) + public function __construct( + functions $functions, + settings $settings + ) { - $this->functions = $functions; - $this->settings = $settings; + $this->functions = $functions; + $this->settings = $settings; } /** diff --git a/event/acp_listener.php b/event/acp_listener.php index b5a655f..e5369ca 100644 --- a/event/acp_listener.php +++ b/event/acp_listener.php @@ -4,28 +4,33 @@ * * @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\event; +use dmzx\mchat\core\settings; +use phpbb\auth\auth; +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 { - /** @var \phpbb\template\template */ + /** @var template */ protected $template; - /** @var \phpbb\request\request */ + /** @var request_interface */ protected $request; - /** @var \phpbb\user */ + /** @var user */ protected $user; - /** @var \dmzx\mchat\core\settings */ + /** @var settings */ protected $settings; /** @var string */ @@ -37,14 +42,21 @@ class acp_listener implements EventSubscriberInterface /** * Constructor * - * @param \phpbb\template\template $template - * @param \phpbb\request\request $request - * @param \phpbb\user $user - * @param \dmzx\mchat\core\settings $settings - * @param string $root_path - * @param string $php_ext + * @param template $template + * @param request_interface $request + * @param user $user + * @param settings $settings + * @param string $root_path + * @param string $php_ext */ - public function __construct(\phpbb\template\template $template, \phpbb\request\request $request, \phpbb\user $user, \dmzx\mchat\core\settings $settings, $root_path, $php_ext) + public function __construct( + template $template, + request_interface $request, + user $user, + settings $settings, + $root_path, + $php_ext + ) { $this->template = $template; $this->request = $request; @@ -73,7 +85,7 @@ class acp_listener implements EventSubscriberInterface { $ucp_configs = array(); - foreach (array_keys($this->settings->ucp) as $config_name) + foreach (array_keys($this->settings->ucp_settings()) as $config_name) { $ucp_configs[] = 'u_' . $config_name; } @@ -131,11 +143,11 @@ class acp_listener implements EventSubscriberInterface $user_id = $event['user_row']['user_id']; - $auth = new \phpbb\auth\auth(); + $auth = new auth(); $userdata = $auth->obtain_user_data($user_id); $auth->acl($userdata); - foreach ($this->settings->ucp as $config_name => $config_data) + foreach ($this->settings->ucp_settings() as $config_name => $config_data) { if ($auth->acl_get('u_' . $config_name)) { @@ -168,7 +180,7 @@ class acp_listener implements EventSubscriberInterface $user_id = $event['user_row']['user_id']; - $auth = new \phpbb\auth\auth(); + $auth = new auth(); $userdata = $auth->obtain_user_data($user_id); $auth->acl($userdata); @@ -179,7 +191,7 @@ class acp_listener implements EventSubscriberInterface $notifications_template_data = $this->settings->get_enabled_post_notifications_lang(); $this->template->assign_var('MCHAT_POSTS_ENABLED_LANG', $notifications_template_data); - foreach (array_keys($this->settings->ucp) as $config_name) + foreach (array_keys($this->settings->ucp_settings()) as $config_name) { $upper = strtoupper($config_name); $this->template->assign_vars(array( diff --git a/event/main_listener.php b/event/main_listener.php index 000a120..7b912b0 100644 --- a/event/main_listener.php +++ b/event/main_listener.php @@ -4,28 +4,32 @@ * * @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\event; +use dmzx\mchat\core\mchat; +use phpbb\controller\helper; +use phpbb\request\request_interface; +use phpbb\user; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class main_listener implements EventSubscriberInterface { - /** @var \dmzx\mchat\core\mchat */ + /** @var mchat */ protected $mchat; - /** @var \phpbb\controller\helper */ + /** @var helper */ protected $helper; - /** @var \phpbb\user */ + /** @var user */ protected $user; - /** @var \phpbb\request\request */ + /** @var request_interface */ protected $request; /** @var string */ @@ -34,13 +38,19 @@ class main_listener implements EventSubscriberInterface /** * Constructor * - * @param \dmzx\mchat\core\mchat $mchat - * @param \phpbb\controller\helper $helper - * @param \phpbb\user $user - * @param \phpbb\request\request $request - * @param string $php_ext + * @param mchat $mchat + * @param helper $helper + * @param user $user + * @param request_interface $request + * @param string $php_ext */ - public function __construct(\dmzx\mchat\core\mchat $mchat, \phpbb\controller\helper $helper, \phpbb\user $user, \phpbb\request\request $request, $php_ext) + public function __construct( + mchat $mchat, + helper $helper, + user $user, + request_interface $request, + $php_ext + ) { $this->mchat = $mchat; $this->helper = $helper; diff --git a/ext.php b/ext.php index 6fed5ca..99c1f06 100644 --- a/ext.php +++ b/ext.php @@ -4,7 +4,7 @@ * * @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 * */ @@ -15,6 +15,7 @@ class ext extends \phpbb\extension\base { /** * Requires phpBB 3.1.7-PL1 due to usage of \phpbb\session:update_session_infos() + * Requires phpBB 3.1.8-RC1 due to HTTPS in version check * * @return bool * @access public @@ -36,9 +37,9 @@ class ext extends \phpbb\extension\base if ($module_ids) { - if (phpbb_version_compare($config['version'], '3.2.0-dev', '>=')) + if (phpbb_version_compare(PHPBB_VERSION, '3.2.0-dev', '>=')) { - // For phpBB 3.2.x + // For phpBB >= 3.2.x $lang = $this->container->get('language'); $lang->add_lang('mchat_acp', 'dmzx/mchat'); } @@ -57,7 +58,7 @@ class ext extends \phpbb\extension\base } } - return phpbb_version_compare($config['version'], '3.1.7-PL1', '>='); + return phpbb_version_compare(PHPBB_VERSION, '3.1.8-RC1', '>='); } /** diff --git a/language/en/common.php b/language/en/common.php index cbbd80f..1367e4d 100644 --- a/language/en/common.php +++ b/language/en/common.php @@ -4,7 +4,7 @@ * * @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 * */ @@ -61,8 +61,12 @@ $lang = array_merge($lang, array( // Post notification messages (%1$s is replaced with a link to the new/edited post, %2$s is replaced with a link to the forum) 'MCHAT_NEW_POST' => 'posted a new topic: %1$s in %2$s', + 'MCHAT_NEW_POST_DELETED' => 'posted a new topic that was deleted', 'MCHAT_NEW_REPLY' => 'posted a reply: %1$s in %2$s', + 'MCHAT_NEW_REPLY_DELETED' => 'posted a reply that was deleted', 'MCHAT_NEW_QUOTE' => 'replied with a quote: %1$s in %2$s', + 'MCHAT_NEW_QUOTE_DELETED' => 'posted a reply that was deleted', 'MCHAT_NEW_EDIT' => 'edited a post: %1$s in %2$s', + 'MCHAT_NEW_EDIT_DELETED' => 'edited a post that was deleted', 'MCHAT_NEW_LOGIN' => 'just logged in', )); diff --git a/language/en/info_acp_mchat.php b/language/en/info_acp_mchat.php index e05eca2..8a4d407 100644 --- a/language/en/info_acp_mchat.php +++ b/language/en/info_acp_mchat.php @@ -4,7 +4,7 @@ * * @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 * */ @@ -44,7 +44,6 @@ $lang = array_merge($lang, array( // Log entries (%1$s is replaced with the user name who triggered the event) 'LOG_MCHAT_CONFIG_UPDATE' => 'mChat configuration updated
» %1$s', 'LOG_MCHAT_TABLE_PRUNED' => 'mChat messages pruned: %2$d
» %1$s', - 'LOG_MCHAT_TABLE_PRUNE_FAIL' => 'mChat pruning failed: invalid time period
» %1$s', 'LOG_MCHAT_TABLE_PURGED' => 'mChat messages purged
» %1$s', 'LOG_DELETED_MCHAT' => 'mChat message deleted
» %1$s', 'LOG_EDITED_MCHAT' => 'mChat message edited
» %1$s', diff --git a/language/en/info_ucp_mchat.php b/language/en/info_ucp_mchat.php index 17189b8..74477c8 100644 --- a/language/en/info_ucp_mchat.php +++ b/language/en/info_ucp_mchat.php @@ -4,7 +4,7 @@ * * @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 * */ diff --git a/language/en/mchat.php b/language/en/mchat.php index d73561f..a5b3b48 100644 --- a/language/en/mchat.php +++ b/language/en/mchat.php @@ -4,7 +4,7 @@ * * @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 * */ @@ -38,6 +38,7 @@ $lang = array_merge($lang, array( 'MCHAT_ADD' => 'Send', 'MCHAT_ARCHIVE' => 'Archive', 'MCHAT_ARCHIVE_PAGE' => 'mChat Archive', + 'MCHAT_CUSTOM_PAGE' => 'mChat', 'MCHAT_BBCODES' => 'BBCodes', 'MCHAT_CUSTOM_BBCODES' => 'Custom BBCodes', 'MCHAT_DELCONFIRM' => 'Are you sure you want to delete this message?', diff --git a/language/en/mchat_acp.php b/language/en/mchat_acp.php index 8be7605..9b1db64 100644 --- a/language/en/mchat_acp.php +++ b/language/en/mchat_acp.php @@ -4,7 +4,7 @@ * * @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 * */ @@ -52,6 +52,12 @@ $lang = array_merge($lang, array( 'MCHAT_ACP_USER_PREFS_EXPLAIN' => 'Below are listed all mChat preferences of the selected user. Settings for which the selected user does not have permission to customise are disabled. These settings can be changed in the Global user settings mChat configuration section.', // ACP settings + 'MCHAT_ACP_CHARACTERS' => 'characters', + 'MCHAT_ACP_MESSAGES' => 'messages', + 'MCHAT_ACP_SECONDS' => 'seconds', + 'MCHAT_ACP_HOURS' => 'hours', + 'MCHAT_ACP_DAYS' => 'days', + 'MCHAT_ACP_WEEKS' => 'weeks', 'MCHAT_ACP_GLOBALSETTINGS_TITLE' => 'mChat Global settings', 'MCHAT_ACP_GLOBALUSERSETTINGS_TITLE' => 'mChat Global user settings', 'MCHAT_VERSION' => 'Version', @@ -70,9 +76,10 @@ $lang = array_merge($lang, array( 'MCHAT_LIVE_UPDATES' => 'Live updates of edited and deleted messages', 'MCHAT_LIVE_UPDATES_EXPLAIN' => 'When a user edits or deletes messages, the changes are updated live for all others, without them having to refresh the page. Disable this if you experience performance issues.', 'MCHAT_PRUNE' => 'Enable message pruning', - 'MCHAT_PRUNE_EXPLAIN' => 'The messages table is pruned every 24 hours.', + 'MCHAT_PRUNE_GC' => 'Message prune task interval', + 'MCHAT_PRUNE_GC_EXPLAIN' => 'The time in seconds that needs to pass before the next message pruning is triggered. Note: this setting controls when messages are checked if they can be deleted. It does not control which messages are deleted. Default is 86400 = 24 hours.', 'MCHAT_PRUNE_NUM' => 'Messages to retain when pruning', - 'MCHAT_PRUNE_NUM_EXPLAIN' => 'You can specify either a number to keep a fixed number of messages (example: 42) or a time period (examples: 24 hours, 5 days, 2 weeks, 1 month). All messages older than the time period at the time of pruning will be deleted.', + 'MCHAT_PRUNE_NUM_EXPLAIN' => 'When using ’messages’ a fixed number of messages will be kept. When using ’hours’, ’days’ or ’weeks’ all messages older than the specified time period at the time of pruning will be deleted.', 'MCHAT_PRUNE_NOW' => 'Prune messages now', 'MCHAT_PRUNE_NOW_CONFIRM' => 'Confirm pruning messages', 'MCHAT_PRUNED' => '%1$d mChat messages have been pruned', @@ -85,7 +92,7 @@ $lang = array_merge($lang, array( 'MCHAT_MESSAGE_NUM_ARCHIVE' => 'Number of messages to display on the archive page', 'MCHAT_MESSAGE_NUM_ARCHIVE_EXPLAIN' => 'The maximum number of messages to show per page on the archive page.
You are limited from 10 to 100. Default is 25.', 'MCHAT_FLOOD_TIME' => 'Flood time', - 'MCHAT_FLOOD_TIME_EXPLAIN' => 'The number of seconds a user must wait before posting another message in the chat.
You are limited from 5 to 60 seconds. Default is 0. Set to 0 to disable.', + 'MCHAT_FLOOD_TIME_EXPLAIN' => 'The number of seconds a user must wait before posting another message in the chat.
You are limited from 0 to 60 seconds. Default is 0. Set to 0 to disable.', 'MCHAT_EDIT_DELETE_LIMIT' => 'Time limit for editing and deleting messages', 'MCHAT_EDIT_DELETE_LIMIT_EXPLAIN' => 'Messages older than the specified number of seconds cannot be edited or deleted by the author any more.
Users who have edit/delete permission as well as moderator permission are exempt from this time limit.
Set to 0 to allow unlimited editing and deleting.', 'MCHAT_MAX_MESSAGE_LENGTH' => 'Maximum message length', diff --git a/language/en/mchat_ucp.php b/language/en/mchat_ucp.php index 446268b..9165668 100644 --- a/language/en/mchat_ucp.php +++ b/language/en/mchat_ucp.php @@ -4,7 +4,7 @@ * * @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 * */ @@ -49,7 +49,7 @@ $lang = array_merge($lang, array( 'MCHAT_INPUT_AREA' => 'Input field', 'MCHAT_TEXT_AREA' => 'Text area', 'MCHAT_POSTS' => 'Display new posts (currently all disabled, can be enabled in the mChat Global Settings section in the ACP)', - 'MCHAT_CHARACTER_COUNT' => 'Display number of characters when typing a message', + 'MCHAT_DISPLAY_CHARACTER_COUNT' => 'Display number of characters when typing a message', 'MCHAT_RELATIVE_TIME' => 'Display relative time for new messages', 'MCHAT_RELATIVE_TIME_EXPLAIN' => 'Displays “just now”, “1 minute ago” and so on for each message. Set to No to always display the full date.', 'MCHAT_PAUSE_ON_INPUT' => 'Pause on input', diff --git a/language/en/permissions_mchat.php b/language/en/permissions_mchat.php index b646078..7b5767f 100644 --- a/language/en/permissions_mchat.php +++ b/language/en/permissions_mchat.php @@ -4,7 +4,7 @@ * * @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 * */ diff --git a/migrations/mchat_2_0_0_rc3.php b/migrations/mchat_2_0_0_rc3.php index 0eb085d..57eb5b3 100644 --- a/migrations/mchat_2_0_0_rc3.php +++ b/migrations/mchat_2_0_0_rc3.php @@ -4,14 +4,16 @@ * * @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\migrations; -class mchat_2_0_0_rc3 extends \phpbb\db\migration\migration +use phpbb\db\migration\migration; + +class mchat_2_0_0_rc3 extends migration { static public function depends_on() { diff --git a/migrations/mchat_2_0_0_rc4.php b/migrations/mchat_2_0_0_rc4.php index 78dee38..194f5d2 100644 --- a/migrations/mchat_2_0_0_rc4.php +++ b/migrations/mchat_2_0_0_rc4.php @@ -4,14 +4,16 @@ * * @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\migrations; -class mchat_2_0_0_rc4 extends \phpbb\db\migration\migration +use phpbb\db\migration\migration; + +class mchat_2_0_0_rc4 extends migration { static public function depends_on() { diff --git a/migrations/mchat_2_0_0_rc5.php b/migrations/mchat_2_0_0_rc5.php index e7dcbe1..03f14c3 100644 --- a/migrations/mchat_2_0_0_rc5.php +++ b/migrations/mchat_2_0_0_rc5.php @@ -4,14 +4,16 @@ * * @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\migrations; -class mchat_2_0_0_rc5 extends \phpbb\db\migration\migration +use phpbb\db\migration\migration; + +class mchat_2_0_0_rc5 extends migration { static public function depends_on() { diff --git a/migrations/mchat_2_0_0_rc6.php b/migrations/mchat_2_0_0_rc6.php index 7448621..6fe5eee 100644 --- a/migrations/mchat_2_0_0_rc6.php +++ b/migrations/mchat_2_0_0_rc6.php @@ -4,14 +4,16 @@ * * @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\migrations; -class mchat_2_0_0_rc6 extends \phpbb\db\migration\migration +use phpbb\db\migration\migration; + +class mchat_2_0_0_rc6 extends migration { static public function depends_on() { diff --git a/migrations/mchat_2_0_0_rc7.php b/migrations/mchat_2_0_0_rc7.php new file mode 100644 index 0000000..3a28d23 --- /dev/null +++ b/migrations/mchat_2_0_0_rc7.php @@ -0,0 +1,67 @@ +config['mchat_prune_num']; + + if (false === filter_var($prune_num, FILTER_VALIDATE_INT)) + { + $time_span = strtotime($prune_num, 0); + + if ($time_span !== false) + { + // A time span is specified. Convert it to number of hours. + $hours = ceil($time_span / 60 / 60); + + $sql = 'UPDATE ' . CONFIG_TABLE . ' + SET config_value = ' . (int) $hours . " + WHERE config_name = 'mchat_prune_num'"; + $this->sql_query($sql); + + // Set to 'hours' mode + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = 1 + WHERE config_name = 'mchat_prune_mode'"; + $this->sql_query($sql); + } + } + } +} diff --git a/styles/Subway/theme/mchat_custom.css b/styles/Subway/theme/mchat_custom.css index 7f475ec..eee2e0f 100644 --- a/styles/Subway/theme/mchat_custom.css +++ b/styles/Subway/theme/mchat_custom.css @@ -2,7 +2,7 @@ * * @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 * */ diff --git a/styles/all/template/javascript/mchat.js b/styles/all/template/javascript/mchat.js index e9228b2..160a8f2 100644 --- a/styles/all/template/javascript/mchat.js +++ b/styles/all/template/javascript/mchat.js @@ -1,10 +1,10 @@ /** * * @package phpBB Extension - mChat - * @copyright (c) 2009 By Shapoval Andrey Vladimirovich (AllCity) ~ http://allcity.net.ru/ - * @copyright (c) 2013 By Rich McGirr (RMcGirr83) http://rmcgirr83.org - * @copyright (c) 2015 By dmzx - http://www.dmzx-web.net - * @copyright (c) 2016 By kasimi + * @copyright (c) 2009 Shapoval Andrey Vladimirovich (AllCity) ~ http://allcity.net.ru/ + * @copyright (c) 2013 Rich McGirr (RMcGirr83) http://rmcgirr83.org + * @copyright (c) 2015 dmzx - http://www.dmzx-web.net + * @copyright (c) 2016 kasimi - mail@kasimi.net * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ @@ -105,9 +105,7 @@ jQuery(function($) { deferred.reject(data.xhr, data.status, mChat.lang.parserErr); } } - }).fail(function(xhr, status, error) { - deferred.reject(xhr, status, error); - }); + }).fail(deferred.reject); return deferred.promise().fail(function(xhr, textStatus, errorThrown) { if (mChat.pageIsUnloading) { return; @@ -120,10 +118,10 @@ jQuery(function($) { xhr: xhr, textStatus: textStatus, errorThrown: errorThrown, - updateSession: function(xhr) { - if (xhr.status == 403) { + updateSession: function() { + if (this.xhr.status == 403) { mChat.endSession(true); - } else if (xhr.status == 400) { + } else if (this.xhr.status == 400) { mChat.resetSession(); } } @@ -134,12 +132,14 @@ jQuery(function($) { mChat.cached('status-error').show(); var responseText; try { - responseText = xhr.responseJSON.message || errorThrown; + responseText = data.xhr.responseJSON.message || data.errorThrown; } catch (e) { - responseText = errorThrown; + responseText = data.errorThrown; } - phpbb.alert(mChat.lang.err, responseText); - data.updateSession(data.xhr); + if (responseText && responseText !== 'timeout') { + phpbb.alert(mChat.lang.err, responseText); + } + data.updateSession(); }); }, sound: function(file) { @@ -169,7 +169,7 @@ jQuery(function($) { }, toggle: function(name) { var $elem = mChat.cached(name); - $elem.stop().slideToggle('fast', function() { + $elem.stop().slideToggle(200, function() { if ($elem.is(':visible')) { localStorage.setItem(mChat.cookie + 'mchat_show_' + name, 'yes'); } else { @@ -218,17 +218,11 @@ jQuery(function($) { if (color && inputValue.indexOf('[color=') === -1) { inputValue = '[color=#' + color + '] ' + inputValue + ' [/color]'; } - mChat.cached('input').val(''); - if (mChat.showCharCount) { - mChat.updateCharCount(); - } + mChat.cached('input').val('').focus(); mChat.refresh(inputValue).done(function() { mChat.resetSession(); }).fail(function() { mChat.cached('input').val(originalInputValue); - if (mChat.showCharCount) { - mChat.updateCharCount(); - } }).always(function() { mChat.cached('add').prop('disabled', false); setTimeout(function() { @@ -348,26 +342,25 @@ jQuery(function($) { mChat.cached('messages').find('.mchat-no-messages').remove(); $messages.reverse(mChat.messageTop).hide().each(function(i) { var $message = $(this); - var data = { + var dataAddMessageBefore = { message: $message, delay: mChat.refreshInterval ? 400 : 0, abort: $.inArray($message.data('mchat-id'), mChat.messageIds) !== -1, playSound: playSound }; - $(mChat).trigger('mchat_add_message_before', [data]); - if (data.abort) { + $(mChat).trigger('mchat_add_message_before', [dataAddMessageBefore]); + if (dataAddMessageBefore.abort) { return; } - if (data.playSound) { + if (dataAddMessageBefore.playSound) { mChat.sound('add'); mChat.titleAlert(); playSound = false; } mChat.messageIds.push($message.data('mchat-id')); setTimeout(function() { - var $container = mChat.cached('messages'); - var data = { - container: $container, + var dataAddMessageAnimateBefore = { + container: mChat.cached('messages'), message: $message, add: function() { if (mChat.messageTop) { @@ -377,26 +370,38 @@ jQuery(function($) { } }, show: function() { - var scrollTop, scrollHeight = mChat.messageTop ? 0 : $container.get(0).scrollHeight; - if (mChat.messageTop && (scrollTop = this.container.scrollTop()) > 0) { - this.message.show(); - this.container.scrollTop(scrollTop + this.message.outerHeight()); + var container = this.container; + var scrollTop = container.scrollTop(); + var scrollLeeway = 20; + if (mChat.messageTop && scrollTop <= scrollLeeway || !mChat.messageTop && scrollTop >= container.get(0).scrollHeight - container.height() - scrollLeeway) { + var animateOptions = { + duration: dataAddMessageBefore.delay - 10, + easing: 'swing' + }; + this.message.slideDown(animateOptions); + if (mChat.messageTop) { + container.animate({scrollTop: 0}, animateOptions); + } else { + (animateOptions.complete = function() { + var scrollHeight = container.get(0).scrollHeight; + if (container.scrollTop() + container.height() < scrollHeight) { + container.animate({scrollTop: scrollHeight}, animateOptions); + } + })(); + } } else { - this.message.css('opacity', 0).slideDown('fast').animate({opacity: 1}, {duration: 'fast', queue: false}); - } - if (!mChat.messageTop && this.container.scrollTop() >= scrollHeight - this.container.height()) { - this.container.animate({ - scrollTop: scrollHeight, - easing: 'swing', - duration: 'slow' - }); + this.message.show(); + if (mChat.messageTop) { + this.container.scrollTop(scrollTop + this.message.outerHeight()); + } } + this.message.addClass('mchat-message-flash'); } }; - $(mChat).trigger('mchat_add_message_animate_before', [data]); - data.add(); - data.show(); - }, i * data.delay); + $(mChat).trigger('mchat_add_message_animate_before', [dataAddMessageAnimateBefore]); + dataAddMessageAnimateBefore.add(); + dataAddMessageAnimateBefore.show(); + }, i * dataAddMessageBefore.delay); if (mChat.editDeleteLimit && $message.data('mchat-edit-delete-limit') && $message.find('[data-mchat-action="edit"], [data-mchat-action="del"]').length > 0) { var id = $message.prop('id'); setTimeout(function() { @@ -549,7 +554,7 @@ jQuery(function($) { updateCharCount: function() { var count = mChat.cached('input').val().length; var charCount = mChat.lang.charCount.format({current: count, max: mChat.mssgLngth}); - var $elem = mChat.cached('character-count').html(charCount).toggleClass('hidden', count === 0); + var $elem = mChat.cached('character-count').html(charCount).toggleClass('invisible', count === 0); if (mChat.mssgLngth) { $elem.toggleClass('error', count > mChat.mssgLngth); } @@ -608,7 +613,9 @@ jQuery(function($) { mChat.resetSession(); if (!mChat.messageTop) { - mChat.cached('messages').animate({scrollTop: mChat.cached('messages')[0].scrollHeight, easing: 'swing', duration: 'slow'}); + setTimeout(function() { + mChat.cached('messages').scrollTop(mChat.cached('messages')[0].scrollHeight); + }, 1); } mChat.cached('user-sound').prop('checked', mChat.playSound && !localStorage.getItem(mChat.cookie + 'mchat_no_sound')).change(function() { @@ -661,6 +668,11 @@ jQuery(function($) { if (mChat.showCharCount) { mChat.cached('form').on('input', mChat.updateCharCount); + mChat.cached('input').on('focus', function() { + setTimeout(function() { + mChat.updateCharCount(); + }, 1); + }); } mChat.cached('input').autogrow({ diff --git a/styles/all/template/mchat_script_data.html b/styles/all/template/mchat_script_data.html index df1fcfc..9767783 100644 --- a/styles/all/template/mchat_script_data.html +++ b/styles/all/template/mchat_script_data.html @@ -2,9 +2,9 @@ - - - + + +