From f4d19a5697c49b14861c191930052aed9d172f15 Mon Sep 17 00:00:00 2001
From: dmzx
Date: Sun, 7 Feb 2016 14:57:51 +0100
Subject: [PATCH] Version 0.3.4
---
adm/style/acp_mchat.html | 24 +-
composer.json | 7 +-
controller/admin_controller.php | 12 +-
controller/main_controller.php | 1 +
core/functions_mchat.php | 20 +-
core/mchat.php | 235 +++++++++++-------
language/de/info_acp_mchat.php | 2 -
language/en/info_acp_mchat.php | 2 -
language/es/info_acp_mchat.php | 2 -
migrations/install_mchat.php | 5 +-
.../event/overall_header_head_append.html | 2 +-
styles/prosilver/template/mchat.js | 37 +--
styles/prosilver/template/mchat.min.js | 12 -
styles/prosilver/template/mchat_bbcodes.html | 1 -
styles/prosilver/template/mchat_body.html | 4 +-
styles/prosilver/template/ucp_mchat.html | 6 +-
ucp/ucp_mchat_module.php | 30 ++-
17 files changed, 234 insertions(+), 168 deletions(-)
delete mode 100644 styles/prosilver/template/mchat.min.js
diff --git a/adm/style/acp_mchat.html b/adm/style/acp_mchat.html
index 1b9bbd6..b19d7b1 100644
--- a/adm/style/acp_mchat.html
+++ b/adm/style/acp_mchat.html
@@ -49,31 +49,25 @@
-
- {L_MCHAT_NEW_POSTS_EXPLAIN}
- -
-
-
-
-
+
{L_MCHAT_NEW_POSTS_TOPIC_EXPLAIN}
-
-
+
{L_MCHAT_NEW_POSTS_REPLY_EXPLAIN}
-
-
+
{L_MCHAT_NEW_POSTS_EDIT_EXPLAIN}
-
-
+
{L_MCHAT_NEW_POSTS_QUOTE_EXPLAIN}
-
@@ -105,9 +99,9 @@
-
+
{L_MCHAT_MESSAGE_NUM_EXPLAIN}
-
+
@@ -196,7 +190,7 @@
-
{L_MCHAT_DATE_FORMAT_EXPLAIN}
+
{L_MCHAT_DATE_FORMAT_EXPLAIN}
-
-
\ No newline at end of file
+
diff --git a/composer.json b/composer.json
index 29f117d..d943eb3 100644
--- a/composer.json
+++ b/composer.json
@@ -3,7 +3,7 @@
"type": "phpbb-extension",
"description": "mChat Extension for phpbb 3.1.x",
"homepage": "http://www.dmzx-web.net",
- "version": "0.3.2",
+ "version": "0.3.4",
"time": "2015-03-10",
"keywords": ["phpbb", "extension", "mchat"],
"license": "GPL-2.0",
@@ -14,6 +14,11 @@
"email": "info@dmzx-web.net",
"role": "Extension Developer"
},
+ {
+ "name": "kasimi",
+ "homepage": "https://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=1330603",
+ "role": "Extension Co-Developer"
+ },
{
"name": "Rich McGirr",
"homepage": "http://rmcgirr83.org",
diff --git a/controller/admin_controller.php b/controller/admin_controller.php
index b8181f7..71967f6 100644
--- a/controller/admin_controller.php
+++ b/controller/admin_controller.php
@@ -93,7 +93,6 @@ class admin_controller
'mchat_message_limit' => array('default' => 10, 'validation' => array('num', false, 10, 30)),
'mchat_message_num' => array('default' => 10, 'validation' => array('num', false, 10, 50)),
'mchat_message_top' => array('default' => 1, 'validation' => array()),
- 'mchat_new_posts' => array('default' => 0, 'validation' => array()),
'mchat_new_posts_edit' => array('default' => 0, 'validation' => array()),
'mchat_new_posts_quote' => array('default' => 0, 'validation' => array()),
'mchat_new_posts_reply' => array('default' => 0, 'validation' => array()),
@@ -139,7 +138,16 @@ class admin_controller
}
// Replace "error" strings with their real, localised form
- $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$this->user->lang('\\1'))) ? \$this->user->lang('\\1') : '\\1'", $error);
+ // The /e modifier is deprecated since PHP 5.5.0
+ //$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$this->user->lang('\\1'))) ? \$this->user->lang('\\1') : '\\1'", $error);
+ foreach ($error as $i => $err)
+ {
+ $lang = $this->user->lang($err);
+ if (!empty($lang))
+ {
+ $error[$i] = $lang;
+ }
+ }
if (empty($error))
{
diff --git a/controller/main_controller.php b/controller/main_controller.php
index 10f84d7..418efd4 100644
--- a/controller/main_controller.php
+++ b/controller/main_controller.php
@@ -46,6 +46,7 @@ class main_controller
* Controller for mChat actions called with Ajax requests
*
* @param $action The action to perform, one of add|edit|del|clean|refresh|whois
+ * @return \Symfony\Component\HttpFoundation\JsonResponse A Symfony JsonResponse object
*/
public function action($action)
{
diff --git a/core/functions_mchat.php b/core/functions_mchat.php
index 945cb4e..51908a6 100644
--- a/core/functions_mchat.php
+++ b/core/functions_mchat.php
@@ -341,11 +341,6 @@ class functions_mchat
*/
public function mchat_insert_posting($mode, $data)
{
- if (!$this->config['mchat_new_posts'])
- {
- return;
- }
-
$mode_config = array(
'post' => $this->config['mchat_new_posts_topic'],
'quote' => $this->config['mchat_new_posts_quote'],
@@ -543,6 +538,19 @@ class functions_mchat
return;
}
- $this->db->sql_query($sql);
+ $result = $this->db->sql_query($sql);
+
+ if ($result !== false)
+ {
+ switch ($action)
+ {
+ case 'add':
+ if ($this->db->sql_nextid() == 1)
+ {
+ $this->cache->destroy('sql', $this->mchat_table);
+ }
+ break;
+ }
+ }
}
}
diff --git a/core/mchat.php b/core/mchat.php
index 0fdadfb..c149136 100644
--- a/core/mchat.php
+++ b/core/mchat.php
@@ -1,4 +1,5 @@
functions_mchat = $functions_mchat;
@@ -78,8 +79,8 @@ class mchat
}
/**
- * Render mChat on the index page
- */
+ * Render mChat on the index page
+ */
public function page_index()
{
if (!$this->auth->acl_get('u_mchat_view'))
@@ -94,6 +95,7 @@ class mchat
return;
}
+ // TODO This might be redundant
// If mChat is used on the index by a user without an avatar, a default avatar is used.
// However, T_THEME_PATH points to ./../styles/... because the controller at /mchat is called, but we need it to be ./styles...
// Setting this value to true solves this.
@@ -111,8 +113,10 @@ class mchat
}
/**
- * Render the mChat custom page
- */
+ * Render the mChat custom page
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
public function page_custom()
{
if (!$this->auth->acl_get('u_mchat_view') || !$this->config['mchat_custom_page'])
@@ -142,8 +146,10 @@ class mchat
}
/**
- * Render the mChat archive
- */
+ * Render the mChat archive
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
public function page_archive()
{
if (!$this->auth->acl_get('u_mchat_view') || !$this->auth->acl_get('u_mchat_archive'))
@@ -173,10 +179,10 @@ class mchat
}
/**
- * Controller for mChat IP WHOIS
- *
- * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
- */
+ * Controller for mChat IP WHOIS
+ *
+ * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
+ */
public function page_whois()
{
if (!$this->auth->acl_get('u_mchat_ip'))
@@ -195,10 +201,10 @@ class mchat
}
/**
- * Controller for mChat Rules page
- *
- * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
- */
+ * Controller for mChat Rules page
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
public function page_rules()
{
if (empty($this->config['mchat_rules']) && empty($this->user->lang['MCHAT_RULES']))
@@ -218,8 +224,10 @@ class mchat
}
/**
- *
- */
+ * User submits a message
+ *
+ * @return array data sent to client as JSON
+ */
public function action_add()
{
if (!$this->auth->acl_get('u_mchat_use') || !check_form_key('mchat', -1))
@@ -243,19 +251,21 @@ class mchat
$this->functions_mchat->mchat_action('add', $sql_ary);
/**
- * Event render_helper_add
- *
- * @event dmzx.mchat.core.render_helper_add
- * @since 0.1.2
- */
+ * Event render_helper_add
+ *
+ * @event dmzx.mchat.core.render_helper_add
+ * @since 0.1.2
+ */
$this->dispatcher->dispatch('dmzx.mchat.core.render_helper_add');
- return array('add' => true);
+ return $this->action_refresh();
}
/**
- *
- */
+ * User edits a message
+ *
+ * @return array data sent to client as JSON
+ */
public function action_edit()
{
if (!defined('PHPBB_USE_BOARD_URL_PATH'))
@@ -287,11 +297,11 @@ class mchat
$this->functions_mchat->mchat_action('edit', $sql_ary, $message_id, $author['username']);
/**
- * Event render_helper_edit
- *
- * @event dmzx.mchat.core.render_helper_edit
- * @since 0.1.4
- */
+ * Event render_helper_edit
+ *
+ * @event dmzx.mchat.core.render_helper_edit
+ * @since 0.1.4
+ */
$this->dispatcher->dispatch('dmzx.mchat.core.render_helper_edit');
$sql_where = 'm.message_id = ' . (int) $message_id;
@@ -304,8 +314,10 @@ class mchat
}
/**
- *
- */
+ * User deletes a message
+ *
+ * @return array data sent to client as JSON
+ */
public function action_del()
{
$message_id = $this->request->variable('message_id', 0);
@@ -323,11 +335,11 @@ class mchat
}
/**
- * Event render_helper_delete
- *
- * @event dmzx.mchat.core.render_helper_delete
- * @since 0.1.4
- */
+ * Event render_helper_delete
+ *
+ * @event dmzx.mchat.core.render_helper_delete
+ * @since 0.1.4
+ */
$this->dispatcher->dispatch('dmzx.mchat.core.render_helper_delete');
$this->functions_mchat->mchat_action('del', null, $message_id, $author['username']);
@@ -336,8 +348,10 @@ class mchat
}
/**
- *
- */
+ * User purges all messagas
+ *
+ * @return array data sent to client as JSON
+ */
public function action_clean()
{
if ($this->user->data['user_type'] != USER_FOUNDER || !check_form_key('mchat', -1))
@@ -351,8 +365,10 @@ class mchat
}
/**
- *
- */
+ * User checks for new messages
+ *
+ * @return array sent to client as JSON
+ */
public function action_refresh()
{
if (!defined('PHPBB_USE_BOARD_URL_PATH'))
@@ -400,7 +416,7 @@ class mchat
// Assign new messages
$this->assign_global_template_data();
$this->assign_messages($rows_refresh);
- $response = array('refresh' => $this->render_template('mchat_messages.html'));
+ $response = array('refresh' => true, 'add' => $this->render_template('mchat_messages.html'));
// Assign edited messages
if (!empty($rows_edit))
@@ -427,8 +443,10 @@ class mchat
}
/**
- *
- */
+ * User requests who is chatting
+ *
+ * @return array data sent to client as JSON
+ */
public function action_whois()
{
$this->assign_whois();
@@ -437,8 +455,8 @@ class mchat
}
/**
- *
- */
+ * Adds the template variables for the header link
+ */
public function render_page_header_link()
{
$this->template->assign_vars(array(
@@ -449,8 +467,11 @@ class mchat
}
/**
- *
- */
+ * Appends a condition to the WHERE key of the SQL array to not fetch disallowed BBCodes from the database
+ *
+ * @param $sql_ary array
+ * @return array
+ */
public function remove_disallowed_bbcodes($sql_ary)
{
// Add disallowed BBCodes to the template only if we're rendering for mChat
@@ -463,12 +484,10 @@ class mchat
}
/**
- * Method to render the page data
- *
- * @var page The page we are rendering for, one of index|custom|archive
- * @return null|array|string If we are rendering for the index, null is returned. For modes that are only
- * called via AJAX, an array is returned, otherwise the rendered content is returned.
- */
+ * Renders data for a page
+ *
+ * @param $page The page we are rendering for, one of index|custom|archive
+ */
protected function render_page($page)
{
// Add lang file
@@ -552,8 +571,8 @@ class mchat
}
/**
- * Assigns all message rows to the template
- */
+ * Assigns all message rows to the template
+ */
protected function assign_global_template_data()
{
$this->template->assign_vars(array(
@@ -564,15 +583,27 @@ class mchat
'MCHAT_EDIT_DELETE_LIMIT' => 1000 * $this->config['mchat_edit_delete_limit'],
'MCHAT_EDIT_DELETE_IGNORE' => $this->config['mchat_edit_delete_limit'] && $this->auth->acl_get('m_'),
'MCHAT_USER_TIMEOUT' => 1000 * $this->config['mchat_timeout'],
- 'S_MCHAT_AVATARS' => !empty($this->config['mchat_avatars']) && $this->user->optionget('viewavatars') && $this->user->data['user_mchat_avatars'],
+ 'S_MCHAT_AVATARS' => $this->display_avatars(),
'EXT_URL' => generate_board_url() . '/ext/dmzx/mchat/',
'STYLE_PATH' => generate_board_url() . '/styles/' . $this->user->style['style_path'],
));
}
/**
- * Assigns all message rows to the template
- */
+ * Returns true if we need do display avatars in the messages, otherwise false
+ *
+ * @return bool
+ */
+ protected function display_avatars()
+ {
+ return $this->config['mchat_avatars'] && $this->user->optionget('viewavatars') && $this->user->data['user_mchat_avatars'];
+ }
+
+ /**
+ * Assigns all message rows to the template
+ *
+ * @param $rows array
+ */
protected function assign_messages($rows)
{
if (empty($rows))
@@ -590,6 +621,22 @@ class mchat
$this->template->destroy_block_vars('mchatrow');
+ $user_avatars = array();
+
+ foreach ($rows as $i => $row)
+ {
+ if (!isset($user_avatars[$row['user_id']]))
+ {
+ $display_avatar = $this->display_avatars() && $row['user_avatar'];
+ $user_avatars[$row['user_id']] = !$display_avatar ? '' : phpbb_get_user_avatar(array(
+ 'avatar' => $row['user_avatar'],
+ 'avatar_type' => $row['user_avatar_type'],
+ 'avatar_width' => $row['user_avatar_width'] > $row['user_avatar_height'] ? 40 : (40 / $row['user_avatar_height']) * $row['user_avatar_width'],
+ 'avatar_height' => $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : (40 / $row['user_avatar_width']) * $row['user_avatar_height'],
+ ));
+ }
+ }
+
foreach ($rows as $i => $row)
{
// Auth checks
@@ -611,13 +658,6 @@ class mchat
$row['username'] = mb_ereg_replace("'", "", $row['username']);
$message = str_replace("'", '’', $row['message']);
- $user_avatar = !$row['user_avatar'] ? '' : phpbb_get_user_avatar(array(
- 'avatar' => $row['user_avatar'],
- 'avatar_type' => $row['user_avatar_type'],
- 'avatar_width' => $row['user_avatar_width'] > $row['user_avatar_height'] ? 40 : (40 / $row['user_avatar_height']) * $row['user_avatar_width'],
- 'avatar_height' => $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : (40 / $row['user_avatar_width']) * $row['user_avatar_height'],
- ));
-
$username_full = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang('GUEST'));
// Remove root path if we render messages for the index page
@@ -631,7 +671,7 @@ class mchat
'MCHAT_ALLOW_BAN' => $this->auth->acl_get('a_authusers'),
'MCHAT_ALLOW_EDIT' => $this->auth_message('u_mchat_edit', $row['user_id'], $row['message_time']),
'MCHAT_ALLOW_DEL' => $this->auth_message('u_mchat_delete', $row['user_id'], $row['message_time']),
- 'MCHAT_USER_AVATAR' => $user_avatar,
+ 'MCHAT_USER_AVATAR' => $user_avatars[$row['user_id']],
'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? generate_board_url() . append_sid("/{$this->root_path}memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $row['user_id']) : '',
'MCHAT_IS_POSTER' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] == $row['user_id'],
'MCHAT_PM' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? generate_board_url() . append_sid("/{$this->root_path}ucp.{$this->php_ext}", 'i=pm&mode=compose&u=' . $row['user_id']) : '',
@@ -652,8 +692,8 @@ class mchat
}
/**
- * Assigns BBCodes and smilies to the template
- */
+ * Assigns BBCodes and smilies to the template
+ */
protected function assign_bbcodes_smilies()
{
// Display custom bbcodes
@@ -695,8 +735,8 @@ class mchat
}
/**
- * Assigns whois and stats at the bottom of the index page
- */
+ * Assigns whois and stats at the bottom of the index page
+ */
protected function assign_whois()
{
if ($this->config['mchat_whois'] || $this->config['mchat_stats_index'] && $this->user->data['user_mchat_stats_index'])
@@ -712,8 +752,13 @@ class mchat
}
/**
- * Checks whether an author has edit or delete permissions for a message
- */
+ * Checks whether an author has edit or delete permissions for a message
+ *
+ * @param $permission string One of u_mchat_edit|u_mchat_delete
+ * @param $author_id int The user id of the message
+ * @param $message_time int The message created time
+ * @return bool
+ */
protected function auth_message($permission, $author_id, $message_time)
{
if (!$this->auth->acl_get($permission))
@@ -731,9 +776,13 @@ class mchat
}
/**
- * Performs bound checks on the message and returns an array containing the message,
- * BBCode options and additional data ready to be sent to the database
- */
+ * Performs bound checks on the message and returns an array containing the message,
+ * BBCode options and additional data ready to be sent to the database
+ *
+ * @param $message string
+ * @param $merge_ary array
+ * @return array
+ */
protected function process_message($message, $merge_ary)
{
// Must have something other than bbcode in the message
@@ -809,9 +858,11 @@ class mchat
}
/**
- * Renders a template file and returns it
- * @return string
- */
+ * Renders a template file and returns it
+ *
+ * @param $template_file string
+ * @return string
+ */
protected function render_template($template_file)
{
$this->template->set_filenames(array('body' => $template_file));
diff --git a/language/de/info_acp_mchat.php b/language/de/info_acp_mchat.php
index 7875855..0693b67 100644
--- a/language/de/info_acp_mchat.php
+++ b/language/de/info_acp_mchat.php
@@ -103,8 +103,6 @@ $lang = array_merge($lang, array(
'MCHAT_OVERRIDE_SMILIE_LIMIT_EXPLAIN' => 'Falls JA eingestellt ist, wird das eingestellte Limit im Forum für Smilies im mChat aufgehoben.',
'MCHAT_OVERRIDE_MIN_POST_CHARS' => 'Minimale Anzahl von Zeichen aufheben?',
'MCHAT_OVERRIDE_MIN_POST_CHARS_EXPLAIN' => 'Falls ja eingestellt ist, wird das Limit für die minimale Anzahl an Zeichen für mChat-Nachrichten aufgehoben.',
- 'MCHAT_NEW_POSTS' => 'Zeige aktivierte Beiträge an',
- 'MCHAT_NEW_POSTS_EXPLAIN' => 'Stelle auf Ja, und setze unter den Optionen, welche Nachricht im Chat-Nachrichtenbereich angezeigt werden können..',
'MCHAT_NEW_POSTS_TOPIC' => 'Zeige New Topic Beiträge an',
'MCHAT_NEW_POSTS_TOPIC_EXPLAIN' => 'Stelle auf Ja, damit neue Themen und Beiträge aus dem Forum im Chat Nachrichtenbereich angezeigt werden.',
'MCHAT_NEW_POSTS_REPLY' => 'Zeige neue Antworten in Beiträgen an',
diff --git a/language/en/info_acp_mchat.php b/language/en/info_acp_mchat.php
index 9c5f038..0d1c96a 100644
--- a/language/en/info_acp_mchat.php
+++ b/language/en/info_acp_mchat.php
@@ -103,8 +103,6 @@ $lang = array_merge($lang, array(
'MCHAT_OVERRIDE_SMILIE_LIMIT_EXPLAIN' => 'Set to yes to override the forums smilie limit setting for chat messages',
'MCHAT_OVERRIDE_MIN_POST_CHARS' => 'Override minimum characters limit',
'MCHAT_OVERRIDE_MIN_POST_CHARS_EXPLAIN' => 'Set to yes to override the forums minimum characters setting for chat messages',
- 'MCHAT_NEW_POSTS' => 'Enable Posts Display',
- 'MCHAT_NEW_POSTS_EXPLAIN' => 'Set to yes and you can set below the options what message to display in the chat message area.',
'MCHAT_NEW_POSTS_TOPIC' => 'Display New Topic Posts',
'MCHAT_NEW_POSTS_TOPIC_EXPLAIN' => 'Set to yes to allow new topic posts from the forum to be posted into the chat message area.',
'MCHAT_NEW_POSTS_REPLY' => 'Display New Replied Posts',
diff --git a/language/es/info_acp_mchat.php b/language/es/info_acp_mchat.php
index 1c58f19..4009d30 100644
--- a/language/es/info_acp_mchat.php
+++ b/language/es/info_acp_mchat.php
@@ -103,8 +103,6 @@ $lang = array_merge($lang, array(
'MCHAT_OVERRIDE_SMILIE_LIMIT_EXPLAIN' => 'Establezca en Sí, para anular el ajustes del límite de emoticonos en los foros, para mensajes del chat',
'MCHAT_OVERRIDE_MIN_POST_CHARS' => 'Anular límite mínimo caracteres',
'MCHAT_OVERRIDE_MIN_POST_CHARS_EXPLAIN' => 'Establezca en Sí, para anular el ajustes del límite mínimo de caracteres en los foros, para mensajes del chat',
- 'MCHAT_NEW_POSTS' => 'Habilitar mostrar mensajes',
- 'MCHAT_NEW_POSTS_EXPLAIN' => 'Establezca en Si, y podrá establecer debajo las opciones de cuál es el mensaje que se mostrará en el área de mensajes del chat.',
'MCHAT_NEW_POSTS_TOPIC' => 'Mostrar mensaje de Nuevo Tema',
'MCHAT_NEW_POSTS_TOPIC_EXPLAIN' => 'Establezca en Sí, para permitir que los nuevos temas del foro puedan ser publicados en el área de mensajes del chat.',
'MCHAT_NEW_POSTS_REPLY' => 'Mostrar mensaje de Nueva Respuesta',
diff --git a/migrations/install_mchat.php b/migrations/install_mchat.php
index 3739ad7..ca5bef2 100644
--- a/migrations/install_mchat.php
+++ b/migrations/install_mchat.php
@@ -13,7 +13,7 @@ class install_mchat extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
- return isset($this->config['mchat_version']) && version_compare($this->config['mchat_version'], '0.3.2', '>=');
+ return isset($this->config['mchat_version']) && version_compare($this->config['mchat_version'], '0.3.4', '>=');
}
static public function depends_on()
@@ -25,7 +25,7 @@ class install_mchat extends \phpbb\db\migration\migration
{
return array(
// Add configs
- array('config.add', array('mchat_version', '0.3.2')),
+ array('config.add', array('mchat_version', '0.3.4')),
array('config.add', array('mchat_archive_limit', 25)),
array('config.add', array('mchat_avatars', 1)),
array('config.add', array('mchat_bbcode_disallowed', '')),
@@ -41,7 +41,6 @@ class install_mchat extends \phpbb\db\migration\migration
array('config.add', array('mchat_message_limit', 10)),
array('config.add', array('mchat_message_num', 10)),
array('config.add', array('mchat_message_top', 1)),
- array('config.add', array('mchat_new_posts', 0)),
array('config.add', array('mchat_new_posts_edit', 0)),
array('config.add', array('mchat_new_posts_quote', 0)),
array('config.add', array('mchat_new_posts_reply', 0)),
diff --git a/styles/prosilver/template/event/overall_header_head_append.html b/styles/prosilver/template/event/overall_header_head_append.html
index be48246..d927c39 100644
--- a/styles/prosilver/template/event/overall_header_head_append.html
+++ b/styles/prosilver/template/event/overall_header_head_append.html
@@ -1,2 +1,2 @@
-
+
diff --git a/styles/prosilver/template/mchat.js b/styles/prosilver/template/mchat.js
index f5078a1..5beda7d 100644
--- a/styles/prosilver/template/mchat.js
+++ b/styles/prosilver/template/mchat.js
@@ -30,7 +30,7 @@ jQuery(function($) {
dataType: 'json',
data: data
}).success(function(json, status, xhr) {
- if (json.hasOwnProperty(mode)) {
+ if (json[mode]) {
deferred.resolve(json, status, xhr);
} else {
deferred.reject(xhr, status, xhr.responseJSON ? 'session' : 'format');
@@ -72,7 +72,7 @@ jQuery(function($) {
}
},
sound: function(file) {
- if (!Cookies.get('mchat_no_sound')) {
+ if (!mChat.pageIsUnloading && !Cookies.get('mchat_no_sound')) {
var audio = mChat.$$('sound-' + file).get(0);
audio.pause();
audio.currentTime = 0;
@@ -109,11 +109,8 @@ jQuery(function($) {
}
mChat.pauseSession();
mChat.$$('add').prop('disabled', true);
- ajaxRequest('add', true, {
- message: mChat.$$('input').val()
- }).done(function(json) {
+ mChat.refresh(mChat.$$('input').val()).done(function() {
mChat.$$('input').val('');
- mChat.refresh();
}).always(function() {
mChat.$$('input').focus();
mChat.$$('add').prop('disabled', false);
@@ -144,7 +141,7 @@ jQuery(function($) {
phpbb.confirm(mChat.$$('confirm'), function() {
ajaxRequest('del', true, {
message_id: $container.data('id')
- }).done(function(json) {
+ }).done(function() {
mChat.sound('del');
$container.fadeOut('slow', function() {
$container.remove();
@@ -153,11 +150,14 @@ jQuery(function($) {
});
});
},
- refresh: function() {
+ refresh: function(message) {
var $messages = mChat.$$('messages').children();
var data = {
message_last_id: $messages.filter(mChat.messageTop ? ':first' : ':last').data('id')
};
+ if (message) {
+ data.message = message;
+ }
if (mChat.liveUpdates) {
data.message_first_id = $messages.filter(mChat.messageTop ? ':last' : ':first').data('id');
data.message_edits = {};
@@ -172,8 +172,8 @@ jQuery(function($) {
}
mChat.$$('refresh-ok', 'refresh-error', 'refresh-paused').hide();
mChat.$$('refresh-load').show();
- ajaxRequest('refresh', false, data).done(function(json) {
- var $html = $(json.refresh);
+ return ajaxRequest(message ? 'add' : 'refresh', !!message, data).done(function(json) {
+ var $html = $(json.add);
if ($html.length) {
mChat.sound('add');
mChat.notice();
@@ -199,7 +199,7 @@ jQuery(function($) {
}
});
}
- if (json.hasOwnProperty('edit')) {
+ if (json.edit) {
var isFirstEdit = true;
$.each(json.edit, function(id, content) {
var $container = $('#mchat-message-' + id);
@@ -214,7 +214,7 @@ jQuery(function($) {
}
});
}
- if (json.hasOwnProperty('del')) {
+ if (json.del) {
var isFirstDelete = true;
$.each(json.del, function(i, id) {
var $container = $('#mchat-message-' + id);
@@ -263,6 +263,7 @@ jQuery(function($) {
mChat.$$('confirm').find('textarea').hide();
mChat.$$('confirm').find('p').text(mChat.cleanConfirm);
phpbb.confirm(mChat.$$('confirm'), function() {
+ mChat.pauseSession();
ajaxRequest('clean', true, {}).done(function() {
phpbb.alert('mChat', mChat.cleanDone);
setTimeout(function() {
@@ -376,7 +377,7 @@ jQuery(function($) {
mChat.$$('confirm').detach().show();
mChat.hiddenFields = {};
- $('#' + form_name).find('input[type=hidden]').each(function() {
+ $('#mchat-form').find('input[type=hidden]').each(function() {
mChat.hiddenFields[this.name] = this.value;
});
@@ -444,6 +445,10 @@ jQuery(function($) {
e.preventDefault();
});
+ if (!mChat.$$('user-sound').prop('checked')) {
+ Cookies.set('mchat_no_sound', 'yes');
+ }
+
mChat.$$('user-sound').change(function() {
if (this.checked) {
Cookies.remove('mchat_no_sound');
@@ -452,7 +457,7 @@ jQuery(function($) {
}
});
- $('#' + form_name).on('keypress', function(e) {
+ $('#mchat-form').on('keypress', function(e) {
if (e.which == 13) {
mChat.add();
e.preventDefault();
@@ -462,6 +467,10 @@ jQuery(function($) {
mChat.$$('input').autoGrowInput();
}
+ $(window).on('beforeunload', function() {
+ mChat.pageIsUnloading = true;
+ });
+
$('#phpbb').on('click', '[data-mchat-action]', function(e) {
var action = $(this).data('mchat-action');
mChat[action].call(this);
diff --git a/styles/prosilver/template/mchat.min.js b/styles/prosilver/template/mchat.min.js
deleted file mode 100644
index fe07130..0000000
--- a/styles/prosilver/template/mchat.min.js
+++ /dev/null
@@ -1,12 +0,0 @@
-/**
- *
- * @package mChat JavaScript Code mini
- * @version 1.5.1 of 2016-01-17
- * @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) 2015 By kasimi
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- *
- */
-"undefined"==typeof document.hasFocus&&(document.hasFocus=function(){return"visible"==document.visibilityState}),jQuery(function(e){var t=function(t,a,s){var o=e.Deferred(),n=o.promise();return a&&e.extend(s,mChat.hiddenFields),e.ajax({url:mChat.file.replace("mchat","mchat-"+t),timeout:5e3,type:"POST",dataType:"json",data:s}).success(function(e,a,s){e.hasOwnProperty(t)?o.resolve(e,a,s):o.reject(s,a,s.responseJSON?"session":"format")}).error(function(e,t,a){o.reject(e,t,a)}),n.fail(function(e,t,a){mChat.sound("error"),mChat.$$("refresh-load","refresh-ok","refresh-paused").hide(),mChat.$$("refresh-error").show(),"format"==a||("session"==a?(mChat.endSession(),alert(mChat.sessOut)):400==e.status?alert(mChat.flood):403==e.status?alert(mChat.noAccess):413==e.status?alert(mChat.mssgLngthLong):501==e.status?alert(mChat.noMessageInput):"undefined"!=typeof console&&console.log&&console.log("AJAX error. status: "+t+", message: "+a))})};e.extend(mChat,{clear:function(){""!==mChat.$$("input").val()&&(confirm(mChat.clearConfirm)&&(mChat.resetSession(!0),mChat.$$("input").val("")),mChat.$$("input").focus())},sound:function(e){if(!Cookies.get("mchat_no_sound")){var t=mChat.$$("sound-"+e).get(0);t.pause(),t.currentTime=0,t.play()}},notice:function(){document.hasFocus()||e.titleAlert(mChat.newMessageAlert,{interval:1e3})},toggle:function(e){var t=mChat.$$(e);t.stop().slideToggle(function(){var a="mchat_show_"+e;t.is(":visible")?Cookies.set(a,"yes"):Cookies.remove(a)})},add:function(){if(!mChat.$$("add").prop("disabled")&&""!==e.trim(mChat.$$("input").val())){var a=mChat.$$("input").val().replace(/\s/g,"");if(a.length>mChat.mssgLngth)return void alert(mChat.mssgLngthLong);mChat.pauseSession(),mChat.$$("add").prop("disabled",!0),t("add",!0,{message:mChat.$$("input").val()}).done(function(e){mChat.$$("input").val(""),mChat.refresh()}).always(function(){mChat.$$("input").focus(),mChat.$$("add").prop("disabled",!1),mChat.resetSession(!1)})}},edit:function(){var a=e(this).closest(".mchat-message"),s=mChat.$$("confirm").find("textarea").show().val(a.data("message"));mChat.$$("confirm").find("p").text(mChat.editInfo),phpbb.confirm(mChat.$$("confirm"),function(){t("edit",!0,{message_id:a.data("id"),message:s.val()}).done(function(t){mChat.sound("edit"),a.fadeOut("slow",function(){a.replaceWith(e(t.edit).hide().fadeIn("slow"))}),mChat.resetSession(!0)})})},del:function(){var a=e(this).closest(".mchat-message");mChat.$$("confirm").find("textarea").hide(),mChat.$$("confirm").find("p").text(mChat.delConfirm),phpbb.confirm(mChat.$$("confirm"),function(){t("del",!0,{message_id:a.data("id")}).done(function(e){mChat.sound("del"),a.fadeOut("slow",function(){a.remove()}),mChat.resetSession(!0)})})},refresh:function(){var a=mChat.$$("messages").children(),s={message_last_id:a.filter(mChat.messageTop?":first":":last").data("id")};if(mChat.liveUpdates){s.message_first_id=a.filter(mChat.messageTop?":last":":first").data("id"),s.message_edits={};var o=Math.floor(Date.now()/1e3);e.each(a,function(){var t=e(this),a=t.data("edit-time");a&&(!mChat.editDeleteLimit||t.data("message-time")>=o-mChat.editDeleteLimit/1e3)&&(s.message_edits[t.data("id")]=a)})}mChat.$$("refresh-ok","refresh-error","refresh-paused").hide(),mChat.$$("refresh-load").show(),t("refresh",!1,s).done(function(t){var a=e(t.refresh);if(a.length&&(mChat.sound("add"),mChat.notice(),mChat.$$("no-messages").remove(),a.hide().each(function(t){var a=e(this);if(setTimeout(function(){mChat.messageTop?mChat.$$("messages").prepend(a):mChat.$$("messages").append(a),a.css("opacity",0).slideDown("slow").animate({opacity:1},{queue:!1,duration:"slow"}),mChat.$$("main").animate({scrollTop:mChat.messageTop?0:mChat.$$("main")[0].scrollHeight},"slow")},600*t),mChat.editDeleteLimit&&a.data("edit-delete-limit")&&a.find('[data-mchat-action="edit"], [data-mchat-action="del"]').length>0){var s=a.attr("id");setTimeout(function(){e("#"+s).find('[data-mchat-action="edit"], [data-mchat-action="del"]').fadeOut("slow",function(){e(this).remove()})},mChat.editDeleteLimit)}})),t.hasOwnProperty("edit")){var s=!0;e.each(t.edit,function(t,a){var o=e("#mchat-message-"+t);o.length&&(s&&(s=!1,mChat.sound("edit")),o.fadeOut("slow",function(){o.replaceWith(e(a).hide().fadeIn("slow"))}))})}if(t.hasOwnProperty("del")){var o=!0;e.each(t.del,function(t,a){var s=e("#mchat-message-"+a);s.length&&(o&&(o=!1,mChat.sound("del")),s.fadeOut("slow",function(){s.remove()}))})}setTimeout(function(){mChat.refreshInterval&&(mChat.$$("refresh-load","refresh-error","refresh-paused").hide(),mChat.$$("refresh-ok").show())},250)})},whois:function(){mChat.customPage&&(mChat.$$("refresh-pending").show(),mChat.$$("refresh").hide()),t("whois",!1,{}).done(function(t){var a=e(t.whois),s=a.find("#mchat-userlist");Cookies.get("mchat_show_userlist")&&s.show(),mChat.$$("whois").replaceWith(a),mChat.cache.whois=a,mChat.cache.userlist=s,mChat.customPage&&setTimeout(function(){mChat.$$("refresh-pending").hide(),mChat.$$("refresh").show()},250)})},clean:function(){mChat.$$("confirm").find("textarea").hide(),mChat.$$("confirm").find("p").text(mChat.cleanConfirm),phpbb.confirm(mChat.$$("confirm"),function(){t("clean",!0,{}).done(function(){phpbb.alert("mChat",mChat.cleanDone),setTimeout(function(){location.reload()},2e3)})})},timeLeft:function(e){return new Date(1e3*e).toUTCString().match(/(\d\d:\d\d:\d\d)/)[0]},countDown:function(){mChat.sessionTime-=1,mChat.$$("session").html(mChat.sessEnds+" "+mChat.timeLeft(mChat.sessionTime)),mChat.sessionTime<1&&mChat.endSession()},pauseSession:function(){clearInterval(mChat.refreshInterval),mChat.userTimeout&&clearInterval(mChat.sessionCountdown),mChat.whoisRefresh&&clearInterval(mChat.whoisInterval)},resetSession:function(e){clearInterval(mChat.refreshInterval),mChat.refreshInterval=setInterval(mChat.refresh,mChat.refreshTime),mChat.userTimeout&&(mChat.sessionTime=mChat.userTimeout/1e3,clearInterval(mChat.sessionCountdown),mChat.$$("session").html(mChat.sessEnds+" "+mChat.timeLeft(mChat.sessionTime)),mChat.sessionCountdown=setInterval(mChat.countDown,1e3)),mChat.whoisRefresh&&(clearInterval(mChat.whoisInterval),mChat.whoisInterval=setInterval(mChat.whois,mChat.whoisRefresh)),mChat.pause&&mChat.$$("input").one("keypress",mChat.endSession),e&&(mChat.$$("refresh-ok").show(),mChat.$$("refresh-load","refresh-error","refresh-paused").hide(),mChat.$$("refresh-text").html(mChat.refreshYes))},endSession:function(){clearInterval(mChat.refreshInterval),mChat.refreshInterval=!1,mChat.userTimeout&&(clearInterval(mChat.sessionCountdown),mChat.$$("session").html(mChat.sessOut)),mChat.whoisRefresh&&(clearInterval(mChat.whoisInterval),mChat.whois()),mChat.$$("refresh-load","refresh-ok","refresh-error").hide(),mChat.$$("refresh-paused").show(),mChat.$$("refresh-text").html(mChat.refreshNo)},mention:function(){var t=e(this).closest(".mchat-message"),a=mChat.entityDecode(t.data("username")),s=t.data("usercolor");s?a="[b][color="+s+"]"+a+"[/color][/b]":mChat.allowBBCodes&&(a="[b]"+a+"[/b]"),insert_text("@ "+a+", ")},quote:function(){var t=e(this).closest(".mchat-message"),a=mChat.entityDecode(t.data("username")),s=mChat.entityDecode(t.data("message"));insert_text('[quote="'+a+'"] '+s+"[/quote]")},like:function(){var t=e(this).closest(".mchat-message"),a=mChat.entityDecode(t.data("username")),s=mChat.entityDecode(t.data("message"));insert_text(mChat.likes+'[quote="'+a+'"] '+s+"[/quote]")},entityDecode:function(e){var t=decodeURIComponent(e.toString().replace(/\+/g," "));return t=t.replace(/</g,"<"),t=t.replace(/>/g,">"),t=t.replace(/:/g,":"),t=t.replace(/./g,"."),t=t.replace(/&/g,"&"),t=t.replace(/"/g,"'")},$$:function(){return e(e.map(arguments,function(t){return mChat.cache[t]||(mChat.cache[t]=e("#mchat-"+t)),mChat.cache[t]})).map(function(){return this.toArray()})}}),mChat.cache={},mChat.$$("confirm").detach().show(),mChat.hiddenFields={},e("#"+form_name).find("input[type=hidden]").each(function(){mChat.hiddenFields[this.name]=this.value}),mChat.archiveMode||(e.fn.autoGrowInput=function(){return this.filter("input:text").each(function(){var t=20,a=e(this).width(),s="",o=e(this),n=e("").css({position:"absolute",top:-9999,left:-9999,width:"auto",fontSize:o.css("fontSize"),fontFamily:o.css("fontFamily"),fontWeight:o.css("fontWeight"),letterSpacing:o.css("letterSpacing"),whiteSpace:"nowrap"});n.insertAfter(o),e(this).on("keypress blur change submit focus",function(){if(s!==(s=o.val())){var h=s.replace(/&/g,"&").replace(/\s/g," ").replace(//g,">"),i=n.html(h).width(),r=i+t>=a?i+t:a;(r
=a||r>a&&r
-
diff --git a/styles/prosilver/template/mchat_body.html b/styles/prosilver/template/mchat_body.html
index 8bb2073..c53c5d0 100644
--- a/styles/prosilver/template/mchat_body.html
+++ b/styles/prosilver/template/mchat_body.html
@@ -4,7 +4,7 @@
-
+