Merge pull request #38 from kasimi/php-cleanup

Remove unused dependencies & code cleanup
This commit is contained in:
dmzx
2015-12-19 23:37:05 +01:00
9 changed files with 574 additions and 721 deletions

View File

@@ -48,4 +48,4 @@
<input class="button1" type="submit" name="update" value="{L_SUBMIT}" /> <input class="button1" type="submit" name="update" value="{L_SUBMIT}" />
{S_FORM_TOKEN} {S_FORM_TOKEN}
</fieldset> </fieldset>
</form> </form>

View File

@@ -8,15 +8,14 @@ services:
- @dmzx.mchat.functions_mchat - @dmzx.mchat.functions_mchat
- @config - @config
- @template - @template
- @log
- @user - @user
- @service_container
- @dbal.conn - @dbal.conn
- @cache - @cache
- @request - @request
- @ext.manager - @ext.manager
- %core.root_path% - %core.root_path%
- %core.php_ext% - %core.php_ext%
- %core.table_prefix%
- %dmzx.mchat.table.mchat_config% - %dmzx.mchat.table.mchat_config%
dmzx.mchat.controller: dmzx.mchat.controller:
class: dmzx\mchat\controller\mchat class: dmzx\mchat\controller\mchat
@@ -35,13 +34,11 @@ services:
- @user - @user
- @auth - @auth
- @dbal.conn - @dbal.conn
- @cache
- @pagination - @pagination
- @request - @request
- @dispatcher - @dispatcher
- %core.root_path% - %core.root_path%
- %core.php_ext% - %core.php_ext%
- %core.table_prefix%
- %dmzx.mchat.table.mchat% - %dmzx.mchat.table.mchat%
dmzx.mchat.functions_mchat: dmzx.mchat.functions_mchat:
class: dmzx\mchat\core\functions_mchat class: dmzx\mchat\core\functions_mchat
@@ -52,7 +49,6 @@ services:
- @log - @log
- @dbal.conn - @dbal.conn
- @cache - @cache
- %core.table_prefix%
- %dmzx.mchat.table.mchat% - %dmzx.mchat.table.mchat%
- %dmzx.mchat.table.mchat_config% - %dmzx.mchat.table.mchat_config%
- %dmzx.mchat.table.mchat_sessions% - %dmzx.mchat.table.mchat_sessions%
@@ -66,9 +62,7 @@ services:
- @template - @template
- @user - @user
- @dbal.conn - @dbal.conn
- @service_container
- %core.php_ext% - %core.php_ext%
- %core.table_prefix%
- %dmzx.mchat.table.mchat% - %dmzx.mchat.table.mchat%
tags: tags:
- { name: event.listener } - { name: event.listener }

View File

@@ -20,12 +20,12 @@ class admin_controller
/** @var \phpbb\template\template */ /** @var \phpbb\template\template */
protected $template; protected $template;
/** @var \phpbb\log\log_interface */
protected $log;
/** @var \phpbb\user */ /** @var \phpbb\user */
protected $user; protected $user;
/** @var ContainerInterface */
protected $container;
/** @var \phpbb\db\driver\driver_interface */ /** @var \phpbb\db\driver\driver_interface */
protected $db; protected $db;
@@ -45,57 +45,41 @@ class admin_controller
protected $phpEx; protected $phpEx;
/** @var string */ /** @var string */
protected $table_prefix; protected $mchat_config_table;
/** @var string */ /** @var string */
public $u_action; public $u_action;
/**
* The database table
*
* @var string
*/
protected $mchat_config_table;
/** @var \phpbb\config\db_text */
protected $config_text;
/** /**
* Constructor * Constructor
* *
* @param \dmzx\mchat\core\functions_mchat $functions_mchat * @param \dmzx\mchat\core\functions_mchat $functions_mchat
* @param \phpbb\config\config $config * @param \phpbb\config\config $config
* @param \phpbb\template\template $template * @param \phpbb\template\template $template
* @param \phpbb\log\log_interface $log
* @param \phpbb\user $user * @param \phpbb\user $user
* @param ContainerInterface $container
* @param \phpbb\db\driver\driver_interface $db * @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\service $cache * @param \phpbb\cache\service $cache
* @param \phpbb\request\request $request * @param \phpbb\request\request $request
* @param \phpbb\extension\manager $phpbb_extension_manager * @param \phpbb\extension\manager $phpbb_extension_manager
* @param $phpbb_root_path * @param string $phpbb_root_path
* @param $phpEx * @param string $phpEx
* @param $table_prefix * @param string $mchat_config_table
* @param $mchat_config_table
* @param \phpbb\config\db_text $config_text
*
*/ */
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)
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)
{ {
$this->functions_mchat = $container->get('dmzx.mchat.functions_mchat'); $this->functions_mchat = $functions_mchat;
$this->config = $config; $this->config = $config;
$this->template = $template; $this->template = $template;
$this->log = $log;
$this->user = $user; $this->user = $user;
$this->container = $container;
$this->db = $db; $this->db = $db;
$this->cache = $cache; $this->cache = $cache;
$this->request = $request; $this->request = $request;
$this->phpbb_extension_manager = $phpbb_extension_manager; $this->phpbb_extension_manager = $phpbb_extension_manager;
$this->phpbb_root_path = $phpbb_root_path; $this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx; $this->php_ext = $phpEx;
$this->table_prefix = $container->getParameter('core.table_prefix');
$this->mchat_config_table = $mchat_config_table; $this->mchat_config_table = $mchat_config_table;
$this->config_text = $container->get('config_text');
} }
/** /**
@@ -181,8 +165,7 @@ class admin_controller
$this->set_options(); $this->set_options();
// and an entry into the log table // and an entry into the log table
$log = $this->container->get('log'); $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE');
$log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE');
// purge the cache // purge the cache
$this->cache->destroy('_mchat_config'); $this->cache->destroy('_mchat_config');

View File

@@ -11,24 +11,22 @@ namespace dmzx\mchat\controller;
class mchat class mchat
{ {
/** @var \dmzx\mchat\core\render_helper */ /** @var \dmzx\mchat\core\render_helper*/
protected $render_helper; protected $render_helper;
/** @var \phpbb\controller\helper */ /** @var \phpbb\controller\helper*/
protected $helper; protected $helper;
/** @var \phpbb\request\request */ /** @var \phpbb\request\request*/
protected $request; protected $request;
/** /**
* Constructor * Constructor
* *
* @param \dmzx\mchat\core\render_helper $render_helper * @param \dmzx\mchat\core\render_helper $render_helper
* @param \phpbb\controller\helper $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) public function __construct(\dmzx\mchat\core\render_helper $render_helper, \phpbb\controller\helper $helper, \phpbb\request\request $request)
{ {
$this->render_helper = $render_helper; $this->render_helper = $render_helper;
@@ -43,7 +41,7 @@ class mchat
*/ */
public function handle() 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 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) if ($this->request->is_ajax() && is_array($ret) && isset($ret['json']) && $ret['json'] === true)

View File

@@ -30,17 +30,12 @@ class functions_mchat
protected $cache; protected $cache;
/** @var string */ /** @var string */
protected $table_prefix;
/**
* The database tables
*
* @var string
*/
protected $mchat_table; protected $mchat_table;
/** @var string */
protected $mchat_config_table; protected $mchat_config_table;
/** @var string */
protected $mchat_sessions_table; protected $mchat_sessions_table;
/** /**
@@ -52,74 +47,57 @@ class functions_mchat
* @param \phpbb\log\log_interface $log * @param \phpbb\log\log_interface $log
* @param \phpbb\db\driver\driver_interface $db * @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\service $cache * @param \phpbb\cache\service $cache
* @param $table_prefix * @param string $mchat_table
* @param $mchat_table * @param string $mchat_config_table
* @param $mchat_config_table * @param string $mchat_sessions_table
* @param $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)
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)
{ {
$this->template = $template; $this->template = $template;
$this->user = $user; $this->user = $user;
$this->auth = $auth; $this->auth = $auth;
$this->phpbb_log = $log; $this->log = $log;
$this->db = $db; $this->db = $db;
$this->cache = $cache; $this->cache = $cache;
$this->table_prefix = $table_prefix;
$this->mchat_table = $mchat_table; $this->mchat_table = $mchat_table;
$this->mchat_config_table = $mchat_config_table; $this->mchat_config_table = $mchat_config_table;
$this->mchat_sessions_table = $mchat_sessions_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() function mchat_cache()
{ {
// Grab the config entries in the ACP...and cache em :P // 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 * $sql = 'SELECT *
FROM ' . $this->mchat_config_table; FROM ' . $this->mchat_config_table;
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
$rows = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
$config_mchat = array(); $config_mchat = array();
while ($row = $this->db->sql_fetchrow($result)) foreach ($rows as $row)
{ {
$config_mchat[$row['config_name']] = $row['config_value']; $config_mchat[$row['config_name']] = $row['config_value'];
} }
$this->db->sql_freeresult($result);
$this->cache->put('_mchat_config', $config_mchat); $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 * @param $time the amount of time to display
* */
*/
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
*
*/
function mchat_session_time($time) function mchat_session_time($time)
{ {
// fix the display of the time limit // Fix the display of the time limit
// hours, minutes, seconds
$chat_session = ''; $chat_session = '';
$chat_timeout = (int) $time; $chat_timeout = (int) $time;
$hours = $minutes = $seconds = 0; $hours = $minutes = $seconds = 0;
@@ -130,6 +108,7 @@ class functions_mchat
$chat_timeout = $chat_timeout - ($hours * 3600); $chat_timeout = $chat_timeout - ($hours * 3600);
$chat_session .= $hours > 1 ? ($hours . '&nbsp;' . $this->user->lang['MCHAT_HOURS']) : ($hours . '&nbsp;' . $this->user->lang['MCHAT_HOUR']); $chat_session .= $hours > 1 ? ($hours . '&nbsp;' . $this->user->lang['MCHAT_HOURS']) : ($hours . '&nbsp;' . $this->user->lang['MCHAT_HOUR']);
} }
$minutes = floor($chat_timeout / 60); $minutes = floor($chat_timeout / 60);
if ($minutes) if ($minutes)
{ {
@@ -137,20 +116,21 @@ class functions_mchat
$chat_timeout = $chat_timeout - ($minutes * 60); $chat_timeout = $chat_timeout - ($minutes * 60);
$chat_session .= $minutes; $chat_session .= $minutes;
} }
$seconds = ceil($chat_timeout); $seconds = ceil($chat_timeout);
if ($seconds) if ($seconds)
{ {
$seconds = $seconds > 1 ? ($seconds . '&nbsp;' . $this->user->lang['MCHAT_SECONDS']) : ($seconds . '&nbsp;' . $this->user->lang['MCHAT_SECOND']); $seconds = $seconds > 1 ? ($seconds . '&nbsp;' . $this->user->lang['MCHAT_SECONDS']) : ($seconds . '&nbsp;' . $this->user->lang['MCHAT_SECOND']);
$chat_session .= $seconds; $chat_session .= $seconds;
} }
return sprintf($this->user->lang['MCHAT_ONLINE_EXPLAIN'], $chat_session); return sprintf($this->user->lang['MCHAT_ONLINE_EXPLAIN'], $chat_session);
} }
// mchat_users
/** /**
* @param $session_time amount of time before a users session times out * @param $session_time amount of time before a users session times out
*/ */
function mchat_users($session_time, $on_page = false) function mchat_users($session_time, $on_page)
{ {
$check_time = time() - (int) $session_time; $check_time = time() - (int) $session_time;
@@ -158,8 +138,8 @@ class functions_mchat
WHERE user_lastupdate < ' . $check_time; WHERE user_lastupdate < ' . $check_time;
$this->db->sql_query($sql); $this->db->sql_query($sql);
// add the user into the sessions upon first visit // Add the user into the sessions upon first visit
if($on_page && ($this->user->data['user_id'] != ANONYMOUS && !$this->user->data['is_bot'])) if ($on_page && ($this->user->data['user_id'] != ANONYMOUS && !$this->user->data['is_bot']))
{ {
$this->mchat_sessions($session_time); $this->mchat_sessions($session_time);
} }
@@ -173,8 +153,11 @@ class functions_mchat
WHERE m.user_lastupdate > ' . $check_time . ' WHERE m.user_lastupdate > ' . $check_time . '
ORDER BY u.username ASC'; ORDER BY u.username ASC';
$result = $this->db->sql_query($sql); $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'); $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']) if (!$row['user_allow_viewonline'])
{ {
@@ -187,13 +170,14 @@ class functions_mchat
$row['username'] = '<em>' . $row['username'] . '</em>'; $row['username'] = '<em>' . $row['username'] . '</em>';
} }
} }
$mchat_user_count++; $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_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; $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); $refresh_message = $this->mchat_session_time($session_time);
if (!$mchat_user_count) if (!$mchat_user_count)
{ {
return array( 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) function mchat_sessions($session_time)
{ {
$check_time = time() - (int) $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); $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) if ($this->user->data['user_type'] == USER_FOUNDER || $this->user->data['user_type'] == USER_NORMAL)
{ {
$sql = 'SELECT * $sql = 'SELECT *
@@ -232,163 +216,116 @@ class functions_mchat
$row = $this->db->sql_fetchrow($result); $row = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
if (!$row) $sql_ary = array('user_lastupdate' => time());
if ($row)
{ {
$sql_ary = array( $sql = 'UPDATE ' . $this->mchat_sessions_table . '
'user_id' => $this->user->data['user_id'], SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
'user_lastupdate' => time(), WHERE user_id =' . (int) $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);
} }
else else
{ {
$sql_ary = array( $sql_ary['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);
);
$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);
} }
$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) 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; return;
} }
$sql = 'DELETE FROM ' . $this->mchat_table . ' $result = $this->db->sql_query_limit('SELECT message_id
WHERE post_id = ' . (int) $post_id; FROM '. $this->mchat_table . '
$this->db->sql_query($sql); ORDER BY message_id ASC', 1);
$first_id = (int) $this->db->sql_fetchfield('message_id');
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');
$this->db->sql_freeresult($result); $this->db->sql_freeresult($result);
// count is below prune amount? // Compute the delete id
// do nothing $delete_id = $mchat_total_messages - $mchat_prune_amount + $first_id;
$prune = true;
if ($mchat_total_messages <= $mchat_prune_amount)
{
$prune = false;
}
if ($prune) $sql = 'DELETE FROM ' . $this->mchat_table . '
{ WHERE message_id < ' . (int) $delete_id;
$this->db->sql_query($sql);
$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;
$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() function display_mchat_bbcodes()
{ {
// grab the bbcodes that aren't allowed $default_bbcodes = array('B', 'I', 'U', 'QUOTE', 'CODE', 'LIST', 'IMG', 'URL', 'SIZE', 'COLOR', 'EMAIL', 'FLASH');
$config_mchat = $this->cache->get('_mchat_config'); $disallowed_bbcode_array = $this->get_disallowed_bbcodes();
$disallowed_bbcode_array = explode('|', strtoupper($config_mchat['bbcode_disallowed'])); // Let's remove the default bbcodes
preg_replace('#^(.*?)=#si','$1',$disallowed_bbcode_array); if (!empty($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))
{ {
$disallowed_bbcode_array = array_map('strtoupper', $disallowed_bbcode_array);
foreach ($default_bbcodes as $default_bbcode) foreach ($default_bbcodes as $default_bbcode)
{ {
$default_bbcode = strtoupper($default_bbcode);
if (!in_array($default_bbcode, $disallowed_bbcode_array)) if (!in_array($default_bbcode, $disallowed_bbcode_array))
{ {
$this->template->assign_vars(array( $this->template->assign_vars(array(
'S_MCHAT_BBCODE_'.$default_bbcode => true, 'S_MCHAT_BBCODE_' . $default_bbcode => true,
)); ));
} }
} }
} }
// now for the custom bbcodes // From /includes/functions_display.php
// Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing) display_custom_bbcodes();
$num_predefined_bbcodes = 22; }
$sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline public function get_disallowed_bbcodes()
FROM ' . BBCODES_TABLE . ' {
WHERE display_on_posting = 1 $config_mchat = $this->mchat_cache();
ORDER BY bbcode_tag'; $disallowed_bbcode = $config_mchat['bbcode_disallowed'];
$result = $this->db->sql_query($sql); $disallowed_bbcode_array = explode('|', $disallowed_bbcode);
return $disallowed_bbcode_array;
$i = 0; }
while ($row = $this->db->sql_fetchrow($result))
{ function mchat_avatar($row)
$bbcode_tag_name = strtoupper($row['bbcode_tag']); {
if (sizeof($disallowed_bbcode_array)) return phpbb_get_user_avatar(array(
{ 'avatar' => $row['user_avatar'],
if (in_array($bbcode_tag_name, $disallowed_bbcode_array)) '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'],
continue; 'avatar_height' => $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : (40 / $row['user_avatar_width']) * $row['user_avatar_height'],
} ));
}
// 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('&amp;', '&quot;', "'", '&lt;', '&gt;'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
));
$i++;
}
$this->db->sql_freeresult($result);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -34,40 +34,27 @@ class listener implements EventSubscriberInterface
/** @var \phpbb\db\driver\driver_interface */ /** @var \phpbb\db\driver\driver_interface */
protected $db; protected $db;
/** @var ContainerInterface */
protected $phpbb_container;
/** @var string */ /** @var string */
protected $phpEx; protected $phpEx;
/** @var string */ /** @var string */
protected $table_prefix;
/**
* The database tables
*
* @var string
*/
protected $mchat_table; protected $mchat_table;
/** /**
* Constructor * Constructor
* *
* @param \dmzx\mchat\core\render_helper $render_helper * @param \dmzx\mchat\core\render_helper $render_helper
* @param \phpbb\auth\auth $auth * @param \phpbb\auth\auth $auth
* @param \phpbb\config\config $config * @param \phpbb\config\config $config
* @param \phpbb\controller\helper $controller_helper * @param \phpbb\controller\helper $controller_helper
* @param \phpbb\template\template $template * @param \phpbb\template\template $template
* @param \phpbb\user $user * @param \phpbb\user $user
* @param \phpbb\db\driver\driver_interface $db * @param \phpbb\db\driver\driver_interface $db
* @param ContainerInterface $phpbb_container * @param string $phpEx
* @param $phpEx * @param string $mchat_table
* @param $table_prefix
* @param $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)
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)
{ {
$this->render_helper = $render_helper; $this->render_helper = $render_helper;
$this->auth = $auth; $this->auth = $auth;
@@ -76,21 +63,20 @@ class listener implements EventSubscriberInterface
$this->controller_helper = $controller_helper; $this->controller_helper = $controller_helper;
$this->user = $user; $this->user = $user;
$this->db = $db; $this->db = $db;
$this->phpbb_container = $phpbb_container;
$this->phpEx = $phpEx; $this->phpEx = $phpEx;
$this->table_prefix = $table_prefix;
$this->mchat_table = $mchat_table; $this->mchat_table = $mchat_table;
} }
static public function getSubscribedEvents() static public function getSubscribedEvents()
{ {
return array( return array(
'core.viewonline_overwrite_location' => 'add_page_viewonline', 'core.viewonline_overwrite_location' => 'add_page_viewonline',
'core.user_setup' => 'load_language_on_setup', 'core.user_setup' => 'load_language_on_setup',
'core.page_header' => 'add_page_header_link', 'core.page_header' => 'add_page_header_link',
'core.index_modify_page_title' => 'display_mchat_on_index', 'core.index_modify_page_title' => 'display_mchat_on_index',
'core.posting_modify_submit_post_after' => 'posting_modify_submit_post_after', 'core.posting_modify_submit_post_after' => 'posting_modify_submit_post_after',
'core.permissions' => 'permissions', '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) if (strrpos($event['row']['session_page'], 'app.' . $this->phpEx . '/chat') === 0)
{ {
$event['location'] = $this->user->lang('MCHAT_TITLE'); $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_bitfield' => $bitfield,
'bbcode_uid' => $uid, 'bbcode_uid' => $uid,
'bbcode_options' => $options, 'bbcode_options' => $options,
'message_time' => time() 'message_time' => time(),
); );
$sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
$this->db->sql_query($sql); $this->db->sql_query($sql);
@@ -198,8 +184,7 @@ class listener implements EventSubscriberInterface
public function permissions($event) public function permissions($event)
{ {
$permissions = $event['permissions']; $event['permissions'] = array_merge($event['permissions'], array(
$permissions += array(
'u_mchat_use' => array( 'u_mchat_use' => array(
'lang' => 'ACL_U_MCHAT_USE', 'lang' => 'ACL_U_MCHAT_USE',
'cat' => 'mChat' 'cat' => 'mChat'
@@ -256,9 +241,27 @@ class listener implements EventSubscriberInterface
'lang' => 'ACL_A_MCHAT', 'lang' => 'ACL_A_MCHAT',
'cat' => 'mChat' 'cat' => 'mChat'
), ),
); ));
$event['permissions'] = $permissions;
$categories['mChat'] = 'ACP_CAT_MCHAT'; $event['categories'] = array_merge($event['categories'], array(
$event['categories'] = array_merge($event['categories'], $categories); '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;
}
}
} }
} }

View File

@@ -1,7 +1,7 @@
<!-- IF S_MCHAT_MESSAGE --> <!-- IF S_MCHAT_DISABLED -->
<div id="information_mchat" class="rules"> <div id="information_mchat" class="rules">
<div class="inner"> <div class="inner">
<strong>{L_INFORMATION}{L_COLON}</strong> {L_MCHAT_DISABLE} <strong>{L_INFORMATION}{L_COLON}</strong> {L_MCHAT_ENABLE}
</div> </div>
</div> </div>
<!-- ENDIF --> <!-- ENDIF -->

View File

@@ -177,7 +177,7 @@
<!-- ENDIF --> <!-- ENDIF -->
</div> </div>
<!-- ENDIF --> <!-- 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> <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 -->&nbsp;{L_MCHAT_ONLINE_EXPLAIN}<br /><span id="mChatUserList">{MCHAT_USERS_LIST}</span></div> <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 -->&nbsp;{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> <div class="mChatRefresh"><span id="mChatRefresh">{L_MCHAT_WHOIS_REFRESH_EXPLAIN}</span><span id="mChatRefreshN" style="display: none;">{L_MCHAT_REFRESHING}</span>