Removed unused dependencies & code cleanup
This commit is contained in:
@@ -48,4 +48,4 @@
|
||||
<input class="button1" type="submit" name="update" value="{L_SUBMIT}" />
|
||||
{S_FORM_TOKEN}
|
||||
</fieldset>
|
||||
</form>
|
||||
</form>
|
||||
|
||||
@@ -8,15 +8,14 @@ services:
|
||||
- @dmzx.mchat.functions_mchat
|
||||
- @config
|
||||
- @template
|
||||
- @log
|
||||
- @user
|
||||
- @service_container
|
||||
- @dbal.conn
|
||||
- @cache
|
||||
- @request
|
||||
- @ext.manager
|
||||
- %core.root_path%
|
||||
- %core.php_ext%
|
||||
- %core.table_prefix%
|
||||
- %dmzx.mchat.table.mchat_config%
|
||||
dmzx.mchat.controller:
|
||||
class: dmzx\mchat\controller\mchat
|
||||
@@ -35,13 +34,11 @@ services:
|
||||
- @user
|
||||
- @auth
|
||||
- @dbal.conn
|
||||
- @cache
|
||||
- @pagination
|
||||
- @request
|
||||
- @dispatcher
|
||||
- %core.root_path%
|
||||
- %core.php_ext%
|
||||
- %core.table_prefix%
|
||||
- %dmzx.mchat.table.mchat%
|
||||
dmzx.mchat.functions_mchat:
|
||||
class: dmzx\mchat\core\functions_mchat
|
||||
@@ -52,7 +49,6 @@ services:
|
||||
- @log
|
||||
- @dbal.conn
|
||||
- @cache
|
||||
- %core.table_prefix%
|
||||
- %dmzx.mchat.table.mchat%
|
||||
- %dmzx.mchat.table.mchat_config%
|
||||
- %dmzx.mchat.table.mchat_sessions%
|
||||
@@ -66,9 +62,7 @@ services:
|
||||
- @template
|
||||
- @user
|
||||
- @dbal.conn
|
||||
- @service_container
|
||||
- %core.php_ext%
|
||||
- %core.table_prefix%
|
||||
- %dmzx.mchat.table.mchat%
|
||||
tags:
|
||||
- { name: event.listener }
|
||||
@@ -20,12 +20,12 @@ class admin_controller
|
||||
/** @var \phpbb\template\template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb\log\log_interface */
|
||||
protected $log;
|
||||
|
||||
/** @var \phpbb\user */
|
||||
protected $user;
|
||||
|
||||
/** @var ContainerInterface */
|
||||
protected $container;
|
||||
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
protected $db;
|
||||
|
||||
@@ -45,57 +45,41 @@ class admin_controller
|
||||
protected $phpEx;
|
||||
|
||||
/** @var string */
|
||||
protected $table_prefix;
|
||||
protected $mchat_config_table;
|
||||
|
||||
/** @var string */
|
||||
public $u_action;
|
||||
|
||||
/**
|
||||
* The database table
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mchat_config_table;
|
||||
|
||||
/** @var \phpbb\config\db_text */
|
||||
protected $config_text;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \dmzx\mchat\core\functions_mchat $functions_mchat
|
||||
* @param \phpbb\config\config $config
|
||||
* @param \phpbb\template\template $template
|
||||
* @param \phpbb\log\log_interface $log
|
||||
* @param \phpbb\user $user
|
||||
* @param ContainerInterface $container
|
||||
* @param \phpbb\db\driver\driver_interface $db
|
||||
* @param \phpbb\cache\service $cache
|
||||
* @param \phpbb\request\request $request
|
||||
* @param \phpbb\extension\manager $phpbb_extension_manager
|
||||
* @param $phpbb_root_path
|
||||
* @param $phpEx
|
||||
* @param $table_prefix
|
||||
* @param $mchat_config_table
|
||||
* @param \phpbb\config\db_text $config_text
|
||||
*
|
||||
* @param string $phpbb_root_path
|
||||
* @param string $phpEx
|
||||
* @param string $mchat_config_table
|
||||
*/
|
||||
|
||||
public function __construct(\dmzx\mchat\core\functions_mchat $functions_mchat, \phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, $container, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, \phpbb\request\request $request, \phpbb\extension\manager $phpbb_extension_manager, $phpbb_root_path, $phpEx, $table_prefix, $mchat_config_table)
|
||||
public function __construct(\dmzx\mchat\core\functions_mchat $functions_mchat, \phpbb\config\config $config, \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, \phpbb\extension\manager $phpbb_extension_manager, $phpbb_root_path, $phpEx, $mchat_config_table)
|
||||
{
|
||||
$this->functions_mchat = $container->get('dmzx.mchat.functions_mchat');
|
||||
$this->functions_mchat = $functions_mchat;
|
||||
$this->config = $config;
|
||||
$this->template = $template;
|
||||
$this->log = $log;
|
||||
$this->user = $user;
|
||||
$this->container = $container;
|
||||
$this->db = $db;
|
||||
$this->cache = $cache;
|
||||
$this->request = $request;
|
||||
$this->phpbb_extension_manager = $phpbb_extension_manager;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $phpEx;
|
||||
$this->table_prefix = $container->getParameter('core.table_prefix');
|
||||
$this->mchat_config_table = $mchat_config_table;
|
||||
$this->config_text = $container->get('config_text');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,8 +165,7 @@ class admin_controller
|
||||
$this->set_options();
|
||||
|
||||
// and an entry into the log table
|
||||
$log = $this->container->get('log');
|
||||
$log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE');
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE');
|
||||
|
||||
// purge the cache
|
||||
$this->cache->destroy('_mchat_config');
|
||||
|
||||
@@ -11,24 +11,22 @@ namespace dmzx\mchat\controller;
|
||||
|
||||
class mchat
|
||||
{
|
||||
/** @var \dmzx\mchat\core\render_helper */
|
||||
/** @var \dmzx\mchat\core\render_helper*/
|
||||
protected $render_helper;
|
||||
|
||||
/** @var \phpbb\controller\helper */
|
||||
/** @var \phpbb\controller\helper*/
|
||||
protected $helper;
|
||||
|
||||
/** @var \phpbb\request\request */
|
||||
/** @var \phpbb\request\request*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \dmzx\mchat\core\render_helper $render_helper
|
||||
* @param \dmzx\mchat\core\render_helper $render_helper
|
||||
* @param \phpbb\controller\helper $helper
|
||||
* @param \phpbb\request\request $request
|
||||
*
|
||||
* @param \phpbb\request\request $request
|
||||
*/
|
||||
|
||||
public function __construct(\dmzx\mchat\core\render_helper $render_helper, \phpbb\controller\helper $helper, \phpbb\request\request $request)
|
||||
{
|
||||
$this->render_helper = $render_helper;
|
||||
@@ -43,7 +41,7 @@ class mchat
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$ret = $this->render_helper->render_data_for_page();
|
||||
$ret = $this->render_helper->render_data_for_page(false);
|
||||
|
||||
// If this was an ajax request, we just create an json_response and return that. It's not ours to handle here.
|
||||
if ($this->request->is_ajax() && is_array($ret) && isset($ret['json']) && $ret['json'] === true)
|
||||
|
||||
@@ -30,17 +30,12 @@ class functions_mchat
|
||||
protected $cache;
|
||||
|
||||
/** @var string */
|
||||
protected $table_prefix;
|
||||
|
||||
/**
|
||||
* The database tables
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mchat_table;
|
||||
|
||||
/** @var string */
|
||||
protected $mchat_config_table;
|
||||
|
||||
/** @var string */
|
||||
protected $mchat_sessions_table;
|
||||
|
||||
/**
|
||||
@@ -52,74 +47,57 @@ class functions_mchat
|
||||
* @param \phpbb\log\log_interface $log
|
||||
* @param \phpbb\db\driver\driver_interface $db
|
||||
* @param \phpbb\cache\service $cache
|
||||
* @param $table_prefix
|
||||
* @param $mchat_table
|
||||
* @param $mchat_config_table
|
||||
* @param $mchat_sessions_table
|
||||
*
|
||||
* @param string $mchat_table
|
||||
* @param string $mchat_config_table
|
||||
* @param string $mchat_sessions_table
|
||||
*/
|
||||
|
||||
public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $table_prefix, $mchat_table, $mchat_config_table, $mchat_sessions_table)
|
||||
function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $mchat_table, $mchat_config_table, $mchat_sessions_table)
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->user = $user;
|
||||
$this->auth = $auth;
|
||||
$this->phpbb_log = $log;
|
||||
$this->log = $log;
|
||||
$this->db = $db;
|
||||
$this->cache = $cache;
|
||||
$this->table_prefix = $table_prefix;
|
||||
$this->mchat_table = $mchat_table;
|
||||
$this->mchat_config_table = $mchat_config_table;
|
||||
$this->mchat_sessions_table = $mchat_sessions_table;
|
||||
}
|
||||
|
||||
// mchat_cache
|
||||
/**
|
||||
* builds the cache if it doesn't exist
|
||||
*/
|
||||
* Builds the cache if it doesn't exist
|
||||
*/
|
||||
function mchat_cache()
|
||||
{
|
||||
// Grab the config entries in the ACP...and cache em :P
|
||||
if (($config_mchat = $this->cache->get('_mchat_config')) === false)
|
||||
$config_mchat = $this->cache->get('_mchat_config');
|
||||
|
||||
if ($config_mchat === false)
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM ' . $this->mchat_config_table;
|
||||
$result = $this->db->sql_query($sql);
|
||||
$rows = $this->db->sql_fetchrowset($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$config_mchat = array();
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$config_mchat[$row['config_name']] = $row['config_value'];
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$this->cache->put('_mchat_config', $config_mchat);
|
||||
}
|
||||
|
||||
return $config_mchat;
|
||||
}
|
||||
|
||||
// mchat_user_fix
|
||||
/**
|
||||
* @param $user_id the id of the user being deleted from the forum
|
||||
*
|
||||
*/
|
||||
function mchat_user_fix($user_id)
|
||||
{
|
||||
$sql = 'UPDATE ' . $this->mchat_table . '
|
||||
SET user_id = ' . ANONYMOUS . '
|
||||
WHERE user_id = ' . (int) $user_id;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// mchat_session_time
|
||||
/**
|
||||
* @param $time the amount of time to display
|
||||
*
|
||||
*/
|
||||
* @param $time the amount of time to display
|
||||
*/
|
||||
function mchat_session_time($time)
|
||||
{
|
||||
// fix the display of the time limit
|
||||
// hours, minutes, seconds
|
||||
// Fix the display of the time limit
|
||||
$chat_session = '';
|
||||
$chat_timeout = (int) $time;
|
||||
$hours = $minutes = $seconds = 0;
|
||||
@@ -130,6 +108,7 @@ class functions_mchat
|
||||
$chat_timeout = $chat_timeout - ($hours * 3600);
|
||||
$chat_session .= $hours > 1 ? ($hours . ' ' . $this->user->lang['MCHAT_HOURS']) : ($hours . ' ' . $this->user->lang['MCHAT_HOUR']);
|
||||
}
|
||||
|
||||
$minutes = floor($chat_timeout / 60);
|
||||
if ($minutes)
|
||||
{
|
||||
@@ -137,20 +116,21 @@ class functions_mchat
|
||||
$chat_timeout = $chat_timeout - ($minutes * 60);
|
||||
$chat_session .= $minutes;
|
||||
}
|
||||
|
||||
$seconds = ceil($chat_timeout);
|
||||
if ($seconds)
|
||||
{
|
||||
$seconds = $seconds > 1 ? ($seconds . ' ' . $this->user->lang['MCHAT_SECONDS']) : ($seconds . ' ' . $this->user->lang['MCHAT_SECOND']);
|
||||
$chat_session .= $seconds;
|
||||
}
|
||||
|
||||
return sprintf($this->user->lang['MCHAT_ONLINE_EXPLAIN'], $chat_session);
|
||||
}
|
||||
|
||||
// mchat_users
|
||||
/**
|
||||
* @param $session_time amount of time before a users session times out
|
||||
*/
|
||||
function mchat_users($session_time, $on_page = false)
|
||||
* @param $session_time amount of time before a users session times out
|
||||
*/
|
||||
function mchat_users($session_time, $on_page)
|
||||
{
|
||||
$check_time = time() - (int) $session_time;
|
||||
|
||||
@@ -158,8 +138,8 @@ class functions_mchat
|
||||
WHERE user_lastupdate < ' . $check_time;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
// add the user into the sessions upon first visit
|
||||
if($on_page && ($this->user->data['user_id'] != ANONYMOUS && !$this->user->data['is_bot']))
|
||||
// Add the user into the sessions upon first visit
|
||||
if ($on_page && ($this->user->data['user_id'] != ANONYMOUS && !$this->user->data['is_bot']))
|
||||
{
|
||||
$this->mchat_sessions($session_time);
|
||||
}
|
||||
@@ -173,8 +153,11 @@ class functions_mchat
|
||||
WHERE m.user_lastupdate > ' . $check_time . '
|
||||
ORDER BY u.username ASC';
|
||||
$result = $this->db->sql_query($sql);
|
||||
$rows = $this->db->sql_fetchrowset($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$can_view_hidden = $this->auth->acl_get('u_viewonline');
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
if (!$row['user_allow_viewonline'])
|
||||
{
|
||||
@@ -187,13 +170,14 @@ class functions_mchat
|
||||
$row['username'] = '<em>' . $row['username'] . '</em>';
|
||||
}
|
||||
}
|
||||
|
||||
$mchat_user_count++;
|
||||
$mchat_user_online_link = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']);
|
||||
$mchat_user_list .= ($mchat_user_list != '') ? $this->user->lang['COMMA_SEPARATOR'] . $mchat_user_online_link : $mchat_user_online_link;
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$refresh_message = $this->mchat_session_time($session_time);
|
||||
|
||||
if (!$mchat_user_count)
|
||||
{
|
||||
return array(
|
||||
@@ -212,17 +196,17 @@ class functions_mchat
|
||||
}
|
||||
}
|
||||
|
||||
// mchat_sessions
|
||||
/**
|
||||
* @param mixed $session_time amount of time before a user is not shown as being in the chat
|
||||
*/
|
||||
* @param mixed $session_time amount of time before a user is not shown as being in the chat
|
||||
*/
|
||||
function mchat_sessions($session_time)
|
||||
{
|
||||
$check_time = time() - (int) $session_time;
|
||||
$sql = 'DELETE FROM ' . $this->mchat_sessions_table . ' WHERE user_lastupdate <' . $check_time;
|
||||
$sql = 'DELETE FROM ' . $this->mchat_sessions_table . '
|
||||
WHERE user_lastupdate <' . $check_time;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
// insert user into the mChat sessions table
|
||||
// Insert user into the mChat sessions table
|
||||
if ($this->user->data['user_type'] == USER_FOUNDER || $this->user->data['user_type'] == USER_NORMAL)
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
@@ -232,163 +216,116 @@ class functions_mchat
|
||||
$row = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (!$row)
|
||||
$sql_ary = array('user_lastupdate' => time());
|
||||
|
||||
if ($row)
|
||||
{
|
||||
$sql_ary = array(
|
||||
'user_id' => $this->user->data['user_id'],
|
||||
'user_lastupdate' => time(),
|
||||
);
|
||||
$sql = 'INSERT INTO ' . $this->mchat_sessions_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
|
||||
$this->db->sql_query($sql);
|
||||
$sql = 'UPDATE ' . $this->mchat_sessions_table . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
|
||||
WHERE user_id =' . (int) $this->user->data['user_id'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql_ary = array(
|
||||
'user_lastupdate' => time(),
|
||||
);
|
||||
$sql = 'UPDATE ' . $this->mchat_sessions_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id =' . (int) $this->user->data['user_id'];
|
||||
$this->db->sql_query($sql);
|
||||
$sql_ary['user_id'] = $this->user->data['user_id'];
|
||||
$sql = 'INSERT INTO ' . $this->mchat_sessions_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
|
||||
}
|
||||
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// mChat add-on Topic Notification
|
||||
/**
|
||||
* @param mixed $post_id limits deletion to a post_id in the forum
|
||||
*/
|
||||
* mChat add-on Topic Notification
|
||||
*
|
||||
* @param mixed $post_id limits deletion to a post_id in the forum
|
||||
*/
|
||||
function mchat_delete_topic($post_id)
|
||||
{
|
||||
if (!isset($post_id) || empty($post_id))
|
||||
if ($post_id)
|
||||
{
|
||||
$sql = 'DELETE FROM ' . $this->mchat_table . '
|
||||
WHERE post_id = ' . (int) $post_id;
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AutoPrune Chats
|
||||
*
|
||||
* @param mixed $mchat_prune_amount set from mchat config entry
|
||||
*/
|
||||
function mchat_prune($mchat_prune_amount)
|
||||
{
|
||||
// How many chats do we have?
|
||||
$sql = 'SELECT COUNT(message_id) AS messages
|
||||
FROM ' . $this->mchat_table;
|
||||
$result = $this->db->sql_query($sql);
|
||||
$mchat_total_messages = (int) $this->db->sql_fetchfield('messages');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($mchat_total_messages <= $mchat_prune_amount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'DELETE FROM ' . $this->mchat_table . '
|
||||
WHERE post_id = ' . (int) $post_id;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// mchat_prune
|
||||
// AutoPrune Chats
|
||||
/**
|
||||
* @param mixed $mchat_prune_amount set from mchat config entry
|
||||
*/
|
||||
function mchat_prune($mchat_prune_amount)
|
||||
{
|
||||
// Run query to get the total message rows...
|
||||
$sql = 'SELECT COUNT(message_id) AS total_messages
|
||||
FROM ' . $this->mchat_table;
|
||||
$result = $this->db->sql_query($sql);
|
||||
$mchat_total_messages = (int) $this->db->sql_fetchfield('total_messages');
|
||||
$result = $this->db->sql_query_limit('SELECT message_id
|
||||
FROM '. $this->mchat_table . '
|
||||
ORDER BY message_id ASC', 1);
|
||||
$first_id = (int) $this->db->sql_fetchfield('message_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// count is below prune amount?
|
||||
// do nothing
|
||||
$prune = true;
|
||||
if ($mchat_total_messages <= $mchat_prune_amount)
|
||||
{
|
||||
$prune = false;
|
||||
}
|
||||
// Compute the delete id
|
||||
$delete_id = $mchat_total_messages - $mchat_prune_amount + $first_id;
|
||||
|
||||
if ($prune)
|
||||
{
|
||||
|
||||
$result = $this->db->sql_query_limit('SELECT *
|
||||
FROM '. $this->mchat_table . '
|
||||
ORDER BY message_id ASC', 1);
|
||||
$row = $this->db->sql_fetchrow($result);
|
||||
$first_id = (int) $row['message_id'];
|
||||
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// compute the delete id
|
||||
$delete_id = $mchat_total_messages - $mchat_prune_amount + $first_id;
|
||||
|
||||
// let's go delete them...if the message id is less than the delete id
|
||||
$sql = 'DELETE FROM ' . $this->mchat_table . '
|
||||
WHERE message_id < ' . (int) $delete_id;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED');
|
||||
|
||||
}
|
||||
// free up some memory...variable(s) are no longer needed.
|
||||
unset($mchat_total_messages);
|
||||
|
||||
// return to what we were doing
|
||||
return;
|
||||
$sql = 'DELETE FROM ' . $this->mchat_table . '
|
||||
WHERE message_id < ' . (int) $delete_id;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED');
|
||||
}
|
||||
// display_mchat_bbcodes
|
||||
// can't use the default phpBB one but
|
||||
// most of code is from similar function
|
||||
|
||||
/**
|
||||
* @param mixed $mchat_prune_amount set from mchat config entry
|
||||
*/
|
||||
* @param mixed $mchat_prune_amount set from mchat config entry
|
||||
*/
|
||||
function display_mchat_bbcodes()
|
||||
{
|
||||
// grab the bbcodes that aren't allowed
|
||||
$config_mchat = $this->cache->get('_mchat_config');
|
||||
|
||||
$disallowed_bbcode_array = explode('|', strtoupper($config_mchat['bbcode_disallowed']));
|
||||
preg_replace('#^(.*?)=#si','$1',$disallowed_bbcode_array);
|
||||
$default_bbcodes = array('b','i','u','quote','code','list','img','url','size','color','email','flash');
|
||||
|
||||
// let's remove the default bbcodes
|
||||
if (sizeof($disallowed_bbcode_array))
|
||||
$default_bbcodes = array('B', 'I', 'U', 'QUOTE', 'CODE', 'LIST', 'IMG', 'URL', 'SIZE', 'COLOR', 'EMAIL', 'FLASH');
|
||||
$disallowed_bbcode_array = $this->get_disallowed_bbcodes();
|
||||
|
||||
// Let's remove the default bbcodes
|
||||
if (!empty($disallowed_bbcode_array))
|
||||
{
|
||||
$disallowed_bbcode_array = array_map('strtoupper', $disallowed_bbcode_array);
|
||||
foreach ($default_bbcodes as $default_bbcode)
|
||||
{
|
||||
$default_bbcode = strtoupper($default_bbcode);
|
||||
if (!in_array($default_bbcode, $disallowed_bbcode_array))
|
||||
{
|
||||
$this->template->assign_vars(array(
|
||||
'S_MCHAT_BBCODE_'.$default_bbcode => true,
|
||||
'S_MCHAT_BBCODE_' . $default_bbcode => true,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now for the custom bbcodes
|
||||
// Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
|
||||
$num_predefined_bbcodes = 22;
|
||||
|
||||
$sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
|
||||
FROM ' . BBCODES_TABLE . '
|
||||
WHERE display_on_posting = 1
|
||||
ORDER BY bbcode_tag';
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$i = 0;
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$bbcode_tag_name = strtoupper($row['bbcode_tag']);
|
||||
if (sizeof($disallowed_bbcode_array))
|
||||
{
|
||||
if (in_array($bbcode_tag_name, $disallowed_bbcode_array))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
|
||||
if (isset($this->user->lang[strtoupper($row['bbcode_helpline'])]))
|
||||
{
|
||||
$row['bbcode_helpline'] = $this->user->lang[strtoupper($row['bbcode_helpline'])];
|
||||
}
|
||||
|
||||
$this->template->assign_block_vars('custom_tags', array(
|
||||
'BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
|
||||
'BBCODE_ID' => $num_predefined_bbcodes + ($i * 2),
|
||||
'BBCODE_TAG' => $row['bbcode_tag'],
|
||||
'BBCODE_HELPLINE' => $row['bbcode_helpline'],
|
||||
'A_BBCODE_HELPLINE' => str_replace(array('&', '"', "'", '<', '>'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
|
||||
));
|
||||
|
||||
$i++;
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
// From /includes/functions_display.php
|
||||
display_custom_bbcodes();
|
||||
}
|
||||
|
||||
public function get_disallowed_bbcodes()
|
||||
{
|
||||
$config_mchat = $this->mchat_cache();
|
||||
$disallowed_bbcode = $config_mchat['bbcode_disallowed'];
|
||||
$disallowed_bbcode_array = explode('|', $disallowed_bbcode);
|
||||
return $disallowed_bbcode_array;
|
||||
}
|
||||
|
||||
function mchat_avatar($row)
|
||||
{
|
||||
return 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'],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -34,40 +34,27 @@ class listener implements EventSubscriberInterface
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
protected $db;
|
||||
|
||||
/** @var ContainerInterface */
|
||||
protected $phpbb_container;
|
||||
|
||||
/** @var string */
|
||||
protected $phpEx;
|
||||
|
||||
/** @var string */
|
||||
protected $table_prefix;
|
||||
|
||||
/**
|
||||
* The database tables
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mchat_table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \dmzx\mchat\core\render_helper $render_helper
|
||||
* @param \dmzx\mchat\core\render_helper $render_helper
|
||||
* @param \phpbb\auth\auth $auth
|
||||
* @param \phpbb\config\config $config
|
||||
* @param \phpbb\controller\helper $controller_helper
|
||||
* @param \phpbb\template\template $template
|
||||
* @param \phpbb\user $user
|
||||
* @param \phpbb\db\driver\driver_interface $db
|
||||
* @param ContainerInterface $phpbb_container
|
||||
* @param $phpEx
|
||||
* @param $table_prefix
|
||||
* @param $mchat_table
|
||||
* @param string $phpEx
|
||||
* @param string $mchat_table
|
||||
*
|
||||
*/
|
||||
|
||||
public function __construct(\dmzx\mchat\core\render_helper $render_helper, \phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\controller\helper $controller_helper, \phpbb\template\template $template, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, $phpbb_container, $phpEx, $table_prefix, $mchat_table)
|
||||
public function __construct(\dmzx\mchat\core\render_helper $render_helper, \phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\controller\helper $controller_helper, \phpbb\template\template $template, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, $phpEx, $mchat_table)
|
||||
{
|
||||
$this->render_helper = $render_helper;
|
||||
$this->auth = $auth;
|
||||
@@ -76,21 +63,20 @@ class listener implements EventSubscriberInterface
|
||||
$this->controller_helper = $controller_helper;
|
||||
$this->user = $user;
|
||||
$this->db = $db;
|
||||
$this->phpbb_container = $phpbb_container;
|
||||
$this->phpEx = $phpEx;
|
||||
$this->table_prefix = $table_prefix;
|
||||
$this->mchat_table = $mchat_table;
|
||||
}
|
||||
|
||||
static public function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'core.viewonline_overwrite_location' => 'add_page_viewonline',
|
||||
'core.user_setup' => 'load_language_on_setup',
|
||||
'core.page_header' => 'add_page_header_link',
|
||||
'core.index_modify_page_title' => 'display_mchat_on_index',
|
||||
'core.posting_modify_submit_post_after' => 'posting_modify_submit_post_after',
|
||||
'core.permissions' => 'permissions',
|
||||
'core.viewonline_overwrite_location' => 'add_page_viewonline',
|
||||
'core.user_setup' => 'load_language_on_setup',
|
||||
'core.page_header' => 'add_page_header_link',
|
||||
'core.index_modify_page_title' => 'display_mchat_on_index',
|
||||
'core.posting_modify_submit_post_after' => 'posting_modify_submit_post_after',
|
||||
'core.permissions' => 'permissions',
|
||||
'core.display_custom_bbcodes_modify_sql' => 'display_custom_bbcodes_modify_sql',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -99,7 +85,7 @@ class listener implements EventSubscriberInterface
|
||||
if (strrpos($event['row']['session_page'], 'app.' . $this->phpEx . '/chat') === 0)
|
||||
{
|
||||
$event['location'] = $this->user->lang('MCHAT_TITLE');
|
||||
$event['location_url'] = $this->phpbb_container->get('controller.helper')->route('dmzx_mchat_controller');
|
||||
$event['location_url'] = $this->controller_helper->route('dmzx_mchat_controller');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +175,7 @@ class listener implements EventSubscriberInterface
|
||||
'bbcode_bitfield' => $bitfield,
|
||||
'bbcode_uid' => $uid,
|
||||
'bbcode_options' => $options,
|
||||
'message_time' => time()
|
||||
'message_time' => time(),
|
||||
);
|
||||
$sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
|
||||
$this->db->sql_query($sql);
|
||||
@@ -198,8 +184,7 @@ class listener implements EventSubscriberInterface
|
||||
|
||||
public function permissions($event)
|
||||
{
|
||||
$permissions = $event['permissions'];
|
||||
$permissions += array(
|
||||
$event['permissions'] = array_merge($event['permissions'], array(
|
||||
'u_mchat_use' => array(
|
||||
'lang' => 'ACL_U_MCHAT_USE',
|
||||
'cat' => 'mChat'
|
||||
@@ -256,9 +241,27 @@ class listener implements EventSubscriberInterface
|
||||
'lang' => 'ACL_A_MCHAT',
|
||||
'cat' => 'mChat'
|
||||
),
|
||||
);
|
||||
$event['permissions'] = $permissions;
|
||||
$categories['mChat'] = 'ACP_CAT_MCHAT';
|
||||
$event['categories'] = array_merge($event['categories'], $categories);
|
||||
));
|
||||
|
||||
$event['categories'] = array_merge($event['categories'], array(
|
||||
'mChat' => 'ACP_CAT_MCHAT',
|
||||
));
|
||||
}
|
||||
|
||||
public function display_custom_bbcodes_modify_sql($event)
|
||||
{
|
||||
// Prevent disallowed BBCodes from being added to the template only if we're rendering for mChat
|
||||
if ($this->render_helper->initialized)
|
||||
{
|
||||
$disallowed_bbcode_array = $this->render_helper->get_disallowed_bbcodes();
|
||||
|
||||
if (!empty($disallowed_bbcode_array))
|
||||
{
|
||||
$disallowed_bbcode_array = array_map('strtoupper', $disallowed_bbcode_array);
|
||||
$sql_ary = $event['sql_ary'];
|
||||
$sql_ary['WHERE'] .= " AND UPPER(b.bbcode_tag) NOT IN ('" . implode("','", $disallowed_bbcode_array) . "')";
|
||||
$event['sql_ary'] = $sql_ary;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<!-- IF S_MCHAT_MESSAGE -->
|
||||
<!-- IF S_MCHAT_DISABLED -->
|
||||
<div id="information_mchat" class="rules">
|
||||
<div class="inner">
|
||||
<strong>{L_INFORMATION}{L_COLON}</strong> {L_MCHAT_DISABLE}
|
||||
<strong>{L_INFORMATION}{L_COLON}</strong> {L_MCHAT_ENABLE}
|
||||
</div>
|
||||
</div>
|
||||
<!-- ENDIF -->
|
||||
<!-- ENDIF -->
|
||||
|
||||
@@ -177,7 +177,7 @@
|
||||
<!-- ENDIF -->
|
||||
</div>
|
||||
<!-- ENDIF -->
|
||||
<!-- IF MCHAT_CUSTOM_PAGE and MCHAT_WHOIS -->
|
||||
<!-- IF not S_MCHAT_DISABLED and MCHAT_CUSTOM_PAGE and MCHAT_WHOIS -->
|
||||
<h3>{L_WHO_IS_CHATTING}</h3>
|
||||
<div class="mChatStats" id="mChatStats"><!-- IF MCHAT_USERS_LIST --><a href="#" onclick="mChat.toggle('UserList'); return false;">{MCHAT_USERS_COUNT}</a><!-- ELSE -->{MCHAT_USERS_COUNT}<!-- ENDIF --> {L_MCHAT_ONLINE_EXPLAIN}<br /><span id="mChatUserList">{MCHAT_USERS_LIST}</span></div>
|
||||
<div class="mChatRefresh"><span id="mChatRefresh">{L_MCHAT_WHOIS_REFRESH_EXPLAIN}</span><span id="mChatRefreshN" style="display: none;">{L_MCHAT_REFRESHING}</span>
|
||||
|
||||
Reference in New Issue
Block a user