1.0.0.rc1 update

This commit is contained in:
talonos
2016-02-18 19:54:39 +00:00
parent e26fc429f0
commit 6b9a7cf704
2 changed files with 132 additions and 157 deletions

View File

@@ -1,4 +1,5 @@
<?php
/**
*
* @package phpBB Extension - mChat
@@ -30,7 +31,7 @@ class functions_mchat
protected $cache;
/** @var string */
protected $phpbb_root_path;
protected $root_path;
/** @var string */
protected $php_ext;
@@ -53,12 +54,12 @@ class functions_mchat
* @param \phpbb\log\log_interface $log
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\driver\driver_interface $cache
* @param string $phpbb_root_path
* @param string $root_path
* @param string $php_ext
* @param string $mchat_table
* @param string $mchat_sessions_table
*/
function __construct(\phpbb\config\config $config, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, $phpbb_root_path, $php_ext, $mchat_table, $mchat_sessions_table)
function __construct(\phpbb\config\config $config, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\log\log_interface $log, \phpbb\db\driver\driver_interface $db, \phpbb\cache\driver\driver_interface $cache, $root_path, $php_ext, $mchat_table, $mchat_sessions_table)
{
$this->config = $config;
$this->user = $user;
@@ -66,7 +67,7 @@ class functions_mchat
$this->log = $log;
$this->db = $db;
$this->cache = $cache;
$this->phpbb_root_path = $phpbb_root_path;
$this->root_path = $root_path;
$this->php_ext = $php_ext;
$this->mchat_table = $mchat_table;
$this->mchat_sessions_table = $mchat_sessions_table;
@@ -74,6 +75,9 @@ class functions_mchat
/**
* Converts a number of seconds to a string in the format 'x hours y minutes z seconds'
*
* @param int $time
* @return string
*/
protected function mchat_format_seconds($time)
{
@@ -83,27 +87,29 @@ class functions_mchat
if ($hours)
{
$time -= $hours * 3600;
$times[] = $hours . '&nbsp;' . $this->user->lang($hours > 1 ? 'MCHAT_HOURS' : 'MCHAT_HOUR');
$times[] = $this->user->lang('MCHAT_HOURS', $hours);
}
$minutes = floor($time / 60);
if ($minutes)
{
$time -= $minutes * 60;
$times[] = $minutes . '&nbsp;' . $this->user->lang($minutes > 1 ? 'MCHAT_MINUTES' : 'MCHAT_MINUTE');
$times[] = $this->user->lang('MCHAT_MINUTES', $minutes);
}
$seconds = ceil($time);
if ($seconds)
{
$times[] = $seconds . '&nbsp;' . $this->user->lang($seconds > 1 ? 'MCHAT_SECONDS' : 'MCHAT_SECOND');
$times[] = $this->user->lang('MCHAT_SECONDS', $seconds);
}
return sprintf($this->user->lang('MCHAT_ONLINE_EXPLAIN'), implode('&nbsp;', $times));
return $this->user->lang('MCHAT_ONLINE_EXPLAIN', implode('&nbsp;', $times));
}
/**
* Returns the total session time in seconds
*
* @return string
*/
protected function mchat_session_time()
{
@@ -112,6 +118,8 @@ class functions_mchat
/**
* Returns data about users who are currently chatting
*
* @return array
*/
public function mchat_active_users()
{
@@ -146,7 +154,7 @@ class functions_mchat
return array(
'online_userlist' => implode($this->user->lang('COMMA_SEPARATOR'), $mchat_users),
'mchat_users_count' => count($mchat_users) ? $this->user->lang(count($mchat_users) > 1 ? 'MCHAT_ONLINE_USERS_TOTAL' : 'MCHAT_ONLINE_USER_TOTAL', count($mchat_users)) : $this->user->lang('MCHAT_NO_CHATTERS'),
'mchat_users_count' => $this->user->lang('MCHAT_ONLINE_USERS_TOTAL', count($mchat_users)),
'refresh_message' => $this->mchat_format_seconds($this->mchat_session_time()),
);
}
@@ -219,6 +227,8 @@ class functions_mchat
/**
* Returns the total number of messages
*
* @return string
*/
public function mchat_total_message_count()
{
@@ -227,6 +237,11 @@ class functions_mchat
/**
* Fetch messages from the database
*
* @param $sql_where
* @param int $total
* @param int $offset
* @return array
*/
public function mchat_get_messages($sql_where, $total = 0, $offset = 0)
{
@@ -253,6 +268,8 @@ class functions_mchat
/**
* Generates the user legend markup
*
* @return array Array of HTML markup for each group
*/
public function mchat_legend()
{
@@ -290,7 +307,7 @@ class functions_mchat
}
else
{
$legend[] = '<a' . $colour_text . ' href="' . append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=group&amp;g='.$row['group_id']) . '">' . $group_name . '</a>';
$legend[] = '<a' . $colour_text . ' href="' . append_sid("{$this->root_path}memberlist.{$this->php_ext}", 'mode=group&amp;g='. $row['group_id']) . '">' . $group_name . '</a>';
}
}
@@ -299,6 +316,8 @@ class functions_mchat
/**
* Returns a list of all foes of the current user
*
* @return array Array of user IDs
*/
public function mchat_foes()
{
@@ -323,6 +342,9 @@ class functions_mchat
/**
* Adds forbidden BBCodes to the passed SQL where statement
*
* @param string $sql_where
* @return string
*/
public function mchat_sql_append_forbidden_bbcodes($sql_where)
{
@@ -338,6 +360,9 @@ class functions_mchat
/**
* Inserts a message with posting information into the database
*
* @param string $mode One of post|quote|edit|reply
* @param $data The post data
*/
public function mchat_insert_posting($mode, $data)
{
@@ -353,9 +378,10 @@ class functions_mchat
return;
}
$mchat_new_data = $this->user->lang('MCHAT_NEW_' . strtoupper($mode));
$message = utf8_normalize_nfc($mchat_new_data . ': [url=' . generate_board_url() . '/viewtopic.' . $this->php_ext . '?p=' . $data['post_id'] . '#p' . $data['post_id'] . ']' . $data['post_subject'] . '[/url] '. $this->user->lang('MCHAT_IN') . ' [url=' . generate_board_url() . '/viewforum.' . $this->php_ext . '?f=' . $data['forum_id'] . ']' . $data['forum_name'] . ' [/url] ' . $this->user->lang('MCHAT_IN_SECTION'));
$board_url = generate_board_url();
$topic_url = '[url=' . $board_url . '/viewtopic.' . $this->php_ext . '?p=' . $data['post_id'] . '#p' . $data['post_id'] . ']' . $data['post_subject'] . '[/url]';
$forum_url = '[url=' . $board_url . '/viewforum.' . $this->php_ext . '?f=' . $data['forum_id'] . ']' . $data['forum_name'] . '[/url]';
$message = $this->user->lang('MCHAT_NEW_' . strtoupper($mode), $topic_url, $forum_url);
$uid = $bitfield = $options = ''; // will be modified by generate_text_for_storage
generate_text_for_storage($message, $uid, $bitfield, $options, true, false, false);
@@ -364,7 +390,7 @@ class functions_mchat
'post_id' => $data['post_id'],
'user_id' => $this->user->data['user_id'],
'user_ip' => $this->user->data['session_ip'],
'message' => $message,
'message' => utf8_normalize_nfc($message),
'bbcode_bitfield' => $bitfield,
'bbcode_uid' => $uid,
'bbcode_options' => $options,
@@ -376,6 +402,8 @@ class functions_mchat
/**
* Checks if the current user is flooding the chat
*
* @return bool
*/
public function mchat_is_user_flooding()
{
@@ -397,6 +425,9 @@ class functions_mchat
/**
* Returns user ID & name of the specified message
*
* @param $message_id
* @return array
*/
public function mchat_author_for_message($message_id)
{
@@ -413,6 +444,10 @@ class functions_mchat
/**
* Returns an array of message IDs that have been deleted from the message table
*
* @param $start_id
* @param $end_id
* @return array
*/
public function mchat_missing_ids($start_id, $end_id)
{
@@ -498,7 +533,12 @@ class functions_mchat
}
/**
* Performs add|edit|del|clean|prune actions
* Performs AJAX actions
*
* @param string $action One of add|edit|del|clean|prune
* @param array $sql_ary
* @param int $message_id
* @param string $log_username
*/
public function mchat_action($action, $sql_ary = null, $message_id = 0, $log_username = '')
{
@@ -522,12 +562,6 @@ class functions_mchat
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DELETED_MCHAT', false, array($log_username));
$this->cache->destroy('sql', $this->mchat_table);
break;
// Founder purges all messages
case 'clean':
$sql = 'TRUNCATE TABLE ' . $this->mchat_table;
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED');
$this->cache->destroy('sql', $this->mchat_table);
break;
// User triggers messages to be pruned
case 'prune':
$sql = 'DELETE FROM ' . $this->mchat_table . ' WHERE message_id < ' . (int) $message_id;

View File

@@ -89,41 +89,13 @@ class mchat
}
$this->assign_whois();
$this->assign_bbcodes_smilies();
if ($this->config['mchat_on_index'])
{
// 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.
if (!defined('PHPBB_USE_BOARD_URL_PATH'))
{
define('PHPBB_USE_BOARD_URL_PATH', true);
}
global $root_path;
$root_path = './';
$this->assign_bbcodes_smilies();
$this->render_page('index');
}
if ($this->config['mchat_on_portal'])
{
// 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.
if (!defined('PHPBB_USE_BOARD_URL_PATH'))
{
define('PHPBB_USE_BOARD_URL_PATH', true);
}
global $root_path;
$root_path = './';
$this->assign_bbcodes_smilies();
$this->render_page('index');
}
}
@@ -223,20 +195,21 @@ class mchat
*/
public function page_rules()
{
if (empty($this->config['mchat_rules']) && empty($this->user->lang['MCHAT_RULES']))
if (empty($this->config['mchat_rules']) && !$this->user->lang('MCHAT_RULES_MESSAGE'))
{
throw new \phpbb\exception\http_exception(404, 'MCHAT_NO_RULES');
}
// If the rules are defined in the language file use them, else just use the entry in the database
$mchat_rules = isset($this->user->lang['MCHAT_RULES']) ? $this->user->lang('MCHAT_RULES') : $this->config['mchat_rules'];
$mchat_rules = $this->user->lang('MCHAT_RULES_MESSAGE');
$mchat_rules = !empty($mchat_rules) ? $mchat_rules : $this->config['mchat_rules'];
$mchat_rules = explode("\n", $mchat_rules);
$mchat_rules = array_map('utf8_htmlspecialchars', $mchat_rules);
$mchat_rules = array_map('htmlspecialchars_decode', $mchat_rules);
$mchat_rules = implode('<br />', $mchat_rules);
$this->template->assign_var('MCHAT_RULES', $mchat_rules);
return $this->helper->render('mchat_rules.html', $this->user->lang('MCHAT_HELP'));
return $this->helper->render('mchat_rules.html', $this->user->lang('MCHAT_RULES'));
}
/**
@@ -284,6 +257,7 @@ class mchat
*/
public function action_edit()
{
// Fix avatar path when editing archived messages
if (!defined('PHPBB_USE_BOARD_URL_PATH'))
{
define('PHPBB_USE_BOARD_URL_PATH', true);
@@ -363,23 +337,6 @@ class mchat
return array('del' => true);
}
/**
* 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))
{
throw new \phpbb\exception\http_exception(403, 'MCHAT_NOACCESS');
}
$this->functions_mchat->mchat_action('clean');
return array('clean' => true);
}
/**
* User checks for new messages
*
@@ -387,11 +344,6 @@ class mchat
*/
public function action_refresh()
{
if (!defined('PHPBB_USE_BOARD_URL_PATH'))
{
define('PHPBB_USE_BOARD_URL_PATH', true);
}
$message_first_id = $this->request->variable('message_first_id', 0);
$message_last_id = $this->request->variable('message_last_id', 0);
$message_edits = $this->request->variable('message_edits', array(0));
@@ -485,7 +437,7 @@ 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
* @param array $sql_ary
* @return array
*/
public function remove_disallowed_bbcodes($sql_ary)
@@ -502,7 +454,7 @@ class mchat
/**
* Renders data for a page
*
* @param $page The page we are rendering for, one of index|custom|archive
* @param string $page The page we are rendering for, one of index|custom|archive
*/
protected function render_page($page)
{
@@ -510,10 +462,9 @@ class mchat
$this->user->add_lang('posting');
// If the static message is defined in the language file use it, else the entry in the database is used
if (isset($this->user->lang['STATIC_MESSAGE']))
{
$this->config['mchat_static_message'] = $this->user->lang('STATIC_MESSAGE');
}
$lang_static_message = $this->user->lang('MCHAT_STATIC_MESSAGE');
$static_message = !empty($lang_static_message) ? $lang_static_message : $this->config['mchat_static_message'];
$pagelocsource = $this->user->page['page'];
$pagelocremove = "?";
if (strpbrk($pagelocremove,$pagelocsource) !== false)
@@ -525,12 +476,11 @@ class mchat
{
$pageloc = $this->user->page['page'];
}
$this->template->assign_vars(array(
'MCHAT_FILE_NAME' => $this->helper->route('dmzx_mchat_controller'),
'MCHAT_REFRESH_JS' => 1000 * $this->config['mchat_refresh'],
'MCHAT_INPUT_TYPE' => $this->user->data['user_mchat_input_area'],
'MCHAT_RULES' => !empty($this->user->lang['MCHAT_RULES']) || !empty($this->config['mchat_rules']),
'MCHAT_RULES' => $this->user->lang('MCHAT_RULES_MESSAGE') || !empty($this->config['mchat_rules']),
'MCHAT_ALLOW_USE' => $this->auth->acl_get('u_mchat_use'),
'MCHAT_ALLOW_SMILES' => $this->config['allow_smilies'] && $this->auth->acl_get('u_mchat_smilies'),
'MCHAT_ALLOW_BBCODES' => $this->config['allow_bbcode'] && $this->auth->acl_get('u_mchat_bbcode'),
@@ -539,8 +489,7 @@ class mchat
'MCHAT_INDEX_HEIGHT' => $this->config['mchat_index_height'],
'MCHAT_CUSTOM_HEIGHT' => $this->config['mchat_custom_height'],
'MCHAT_READ_ARCHIVE_BUTTON' => $this->auth->acl_get('u_mchat_archive'),
'MCHAT_FOUNDER' => $this->user->data['user_type'] == USER_FOUNDER,
'MCHAT_STATIC_MESS' => !empty($this->config['mchat_static_message']) ? htmlspecialchars_decode($this->config['mchat_static_message']) : '',
'MCHAT_STATIC_MESS' => htmlspecialchars_decode($static_message),
'L_MCHAT_COPYRIGHT' => base64_decode('PGEgaHJlZj0iaHR0cDovL3JtY2dpcnI4My5vcmciPlJNY0dpcnI4MzwvYT4gJmNvcHk7IDxhIGhyZWY9Imh0dHA6Ly93d3cuZG16eC13ZWIubmV0IiB0aXRsZT0id3d3LmRtengtd2ViLm5ldCI+ZG16eDwvYT4='),
'MCHAT_MESSAGE_LNGTH' => $this->config['mchat_max_message_lngth'],
'MCHAT_MESS_LONG' => sprintf($this->user->lang('MCHAT_MESS_LONG'), $this->config['mchat_max_message_lngth']),
@@ -555,7 +504,7 @@ class mchat
'U_MORE_SMILIES' => generate_board_url() . append_sid("/{$this->root_path}/posting.{$this->php_ext}", 'mode=smilies'),
'U_MCHAT_RULES' => $this->helper->route('dmzx_mchat_page_controller', array('page' => 'rules')),
'S_MCHAT_ON_INDEX' => $this->config['mchat_on_index'] && !empty($this->user->data['user_mchat_index']),
'S_DISPLAY_MCHAT_PORTAL' => $this->config['mchat_on_portal'],
'S_DISPLAY_MCHAT_PORTAL' => $this->config['mchat_on_portal'] && !empty($this->user->data['user_mchat_index']),
'U_MCHATLOC' => $pageloc,
));
@@ -631,7 +580,7 @@ class mchat
/**
* Assigns all message rows to the template
*
* @param $rows array
* @param array $rows
*/
protected function assign_messages($rows)
{
@@ -660,8 +609,8 @@ class mchat
$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'],
'avatar_width' => $row['user_avatar_width'] >= $row['user_avatar_height'] ? 40 : 0,
'avatar_height' => $row['user_avatar_width'] >= $row['user_avatar_height'] ? 0 : 40,
));
}
}
@@ -687,14 +636,6 @@ class mchat
$row['username'] = mb_ereg_replace("'", "&#146;", $row['username']);
$message = str_replace("'", '&rsquo;', $row['message']);
$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
if (strpos($this->user->data['session_page'], 'app.' . $this->php_ext) === false)
{
$username_full = str_replace('.' . $this->root_path, '', $username_full);
}
$this->template->assign_block_vars('mchatrow', array(
'S_ROW_COUNT' => $i,
'MCHAT_ALLOW_BAN' => $this->auth->acl_get('a_authusers'),
@@ -706,10 +647,10 @@ class mchat
'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&amp;mode=compose&amp;u=' . $row['user_id']) : '',
'MCHAT_MESSAGE_EDIT' => $message_edit,
'MCHAT_MESSAGE_ID' => $row['message_id'],
'MCHAT_USERNAME_FULL' => $username_full,
'MCHAT_USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang('GUEST')),
'MCHAT_USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang('GUEST')),
'MCHAT_USERNAME_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang('GUEST')),
'MCHAT_USER_IP' => $row['user_ip'],
'MCHAT_WHOIS_USER' => $this->user->lang('MCHAT_WHOIS_USER', $row['user_ip']),
'MCHAT_U_IP' => $this->helper->route('dmzx_mchat_page_controller', array('page' => 'whois', 'ip' => $row['user_ip'])),
'MCHAT_U_BAN' => generate_board_url() . append_sid("/{$this->root_path}adm/index.{$this->php_ext}" ,'i=permissions&amp;mode=setting_user_global&amp;user_id[0]=' . $row['user_id'], true, $this->user->session_id),
'MCHAT_MESSAGE' => censor_text(generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options'])),
@@ -783,9 +724,9 @@ class mchat
/**
* 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
* @param string $permission One of u_mchat_edit|u_mchat_delete
* @param int $author_id The user id of the message
* @param int $message_time The message created time
* @return bool
*/
protected function auth_message($permission, $author_id, $message_time)
@@ -808,8 +749,8 @@ 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
*
* @param $message string
* @param $merge_ary array
* @param string $message
* @param array $merge_ary
* @return array
*/
protected function process_message($message, $merge_ary)
@@ -889,7 +830,7 @@ class mchat
/**
* Renders a template file and returns it
*
* @param $template_file string
* @param string $template_file
* @return string
*/
protected function render_template($template_file)