Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
kasimi committed Apr 27, 2017
2 parents 2978185 + 81ab3c9 commit f659775
Show file tree
Hide file tree
Showing 46 changed files with 397 additions and 133 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ env:
branches:
only:
- master
- dev
- /^\d+(\.\d+)?\.x$/

install:
Expand Down
11 changes: 9 additions & 2 deletions adm/style/acp_mchat_globalsettings.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ <h3>{L_WARNING}</h3>
<!-- EVENT dmzx_mchat_acp_custom_page_before -->

<dl>
<dt><label for="mchat_custom_page">{L_MCHAT_CUSTOM_PAGE}{L_COLON}</label><br />
<span>{L_MCHAT_CUSTOM_PAGE_EXPLAIN}</span></dt>
<dt><label for="mchat_custom_page">{L_MCHAT_CUSTOM_PAGE}{L_COLON}</label></dt>
<dd><label><input type="radio" class="radio" name="mchat_custom_page" value="1"<!-- IF MCHAT_CUSTOM_PAGE --> id="mchat_custom_page" checked="checked"<!-- ENDIF --> /> {L_YES}</label>
<label><input type="radio" class="radio" name="mchat_custom_page" value="0"<!-- IF not MCHAT_CUSTOM_PAGE --> id="mchat_custom_page" checked="checked"<!-- ENDIF --> /> {L_NO}</label></dd>
</dl>
Expand Down Expand Up @@ -82,6 +81,14 @@ <h3>{L_WARNING}</h3>

<!-- EVENT dmzx_mchat_acp_message_num_archive_after -->

<dl>
<dt><label for="mchat_archive_sort">{L_MCHAT_ARCHIVE_SORT}{L_COLON}</label></dt>
<dd>
<label><input type="radio" class="radio" name="mchat_archive_sort" value="0"<!-- IF MCHAT_ARCHIVE_SORT == 0 --> id="mchat_archive_sort" checked="checked"<!-- ENDIF --> /> {L_MCHAT_ARCHIVE_SORT_TOP_BOTTOM}</label><br />
<label><input type="radio" class="radio" name="mchat_archive_sort" value="1"<!-- IF MCHAT_ARCHIVE_SORT == 1 --> id="mchat_archive_sort" checked="checked"<!-- ENDIF --> /> {L_MCHAT_ARCHIVE_SORT_BOTTOM_TOP}</label><br />
<label><input type="radio" class="radio" name="mchat_archive_sort" value="2"<!-- IF MCHAT_ARCHIVE_SORT == 2 --> id="mchat_archive_sort" checked="checked"<!-- ENDIF --> /> {L_MCHAT_ARCHIVE_SORT_USER}</label>
</dd>
</dl>
</fieldset>
<fieldset>
<legend>{L_MCHAT_SETTINGS_MESSAGES}</legend>
Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "dmzx/mchat",
"type": "phpbb-extension",
"description": "mChat Extension",
"description": "mChat",
"homepage": "https://github.com/kasimi/mChat",
"version": "2.0.0",
"time": "2016-10-20",
"version": "2.0.1",
"time": "2017-02-03",
"keywords": ["phpbb", "extension", "mchat"],
"license": "GPL-2.0",
"authors": [
Expand Down Expand Up @@ -39,10 +39,9 @@
"phpbb/phpbb": ">=3.1.8-RC1,<3.3.0@dev"
},
"version-check": {
"host": "kasimi.github.io",
"directory": "/mChat",
"filename": "mchat_version.json",
"ssl": true
"host": "www.phpbb.com",
"directory": "/customise/db/extension/mchat_extension",
"filename": "version_check"
}
}
}
1 change: 1 addition & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ services:
- '@request'
- '@user'
- '@dmzx.mchat.settings'
- '@dmzx.mchat.functions'
- '%core.root_path%'
- '%core.php_ext%'
tags:
Expand Down
10 changes: 7 additions & 3 deletions controller/acp_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ functions $functions,
settings $settings,
$mchat_table,
$mchat_log_table,
$root_path, $php_ext
$root_path,
$php_ext
)
{
$this->functions = $functions;
Expand Down Expand Up @@ -137,6 +138,9 @@ public function globalsettings($u_action)
}
}

// Remove leading & trailing | characters to not break allowed BBCodes
$mchat_new_config['mchat_bbcode_disallowed'] = trim($mchat_new_config['mchat_bbcode_disallowed'], '|');

// Don't allow changing pruning settings for non founders
if (!$is_founder)
{
Expand Down Expand Up @@ -194,8 +198,8 @@ public function globalsettings($u_action)
{
if ($is_founder && $this->request->is_set_post('mchat_purge') && $this->request->variable('mchat_purge_confirm', false) && check_form_key('acp_mchat'))
{
$this->db->sql_query('TRUNCATE TABLE ' . $this->mchat_table);
$this->db->sql_query('TRUNCATE TABLE ' . $this->mchat_log_table);
$this->db->sql_query('DELETE FROM ' . $this->mchat_table);
$this->db->sql_query('DELETE FROM ' . $this->mchat_log_table);
$this->cache->destroy('sql', $this->mchat_log_table);
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PURGED', false, array($this->user->data['username']));
trigger_error($this->user->lang('MCHAT_PURGED') . adm_back_link($u_action));
Expand Down
32 changes: 25 additions & 7 deletions core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,10 @@ public function mchat_session_gc()
/**
* Prune messages
*
* @param int|array $user_ids
* @return array
*/
public function mchat_prune()
public function mchat_prune($user_ids = array())
{
$prune_num = (int) $this->settings->cfg('mchat_prune_num');
$prune_mode = (int) $this->settings->cfg('mchat_prune_mode');
Expand All @@ -325,7 +326,17 @@ public function mchat_prune()
'FROM' => array($this->mchat_table => 'm'),
);

if ($this->settings->prune_modes[$prune_mode] === 'messages')
if ($user_ids)
{
if (!is_array($user_ids))
{
$user_ids = array($user_ids);
}

$sql_array['WHERE'] = $this->db->sql_in_set('m.user_id', $user_ids);
$offset = 0;
}
else if ($this->settings->prune_modes[$prune_mode] === 'messages')
{
// Skip fixed number of messages, delete all others
$sql_array['ORDER_BY'] = 'm.message_id DESC';
Expand Down Expand Up @@ -355,10 +366,13 @@ public function mchat_prune()
*
* @event dmzx.mchat.prune_before
* @var array prune_ids Array of message IDs that are about to be pruned
* @var array user_ids Array of user IDs that are being pruned
* @since 2.0.0-RC6
* @changed 2.0.1 Added user_ids
*/
$vars = array(
'prune_ids',
'user_ids',
);
extract($this->dispatcher->trigger_event('dmzx.mchat.prune_before', compact($vars)));

Expand All @@ -368,7 +382,11 @@ public function mchat_prune()
$this->db->sql_query('DELETE FROM ' . $this->mchat_log_table . ' WHERE ' . $this->db->sql_in_set('message_id', $prune_ids));
$this->cache->destroy('sql', $this->mchat_log_table);

$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED', false, array($this->user->data['username'], count($prune_ids)));
// Only add a log entry if message pruning was not triggered by user pruning
if (!$user_ids)
{
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED', false, array($this->user->data['username'], count($prune_ids)));
}
}

return $prune_ids;
Expand Down Expand Up @@ -672,7 +690,7 @@ public function mchat_get_post_data($post_ids)
return array();
}

$sql = 'SELECT p.post_id, p.post_subject, f.forum_name
$sql = 'SELECT p.post_id, p.post_subject, f.forum_id, f.forum_name
FROM ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . ' f
WHERE p.forum_id = f.forum_id
AND ' . $this->db->sql_in_set('p.post_id', $post_ids);
Expand All @@ -687,6 +705,7 @@ public function mchat_get_post_data($post_ids)
{
$post_subjects[$row['post_id']] = array(
'post_subject' => $row['post_subject'],
'forum_id' => $row['forum_id'],
'forum_name' => $row['forum_name'],
);
}
Expand Down Expand Up @@ -812,14 +831,13 @@ public function mchat_is_user_flooding()
/**
* Returns user ID & name of the specified message
*
* @param $message_id
* @param int $message_id
* @return array
*/
public function mchat_author_for_message($message_id)
{
$sql = 'SELECT u.user_id, u.username, m.message_time, m.forum_id, m.post_id
$sql = 'SELECT m.user_id, m.message_time, m.post_id
FROM ' . $this->mchat_table . ' m
LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id
WHERE m.message_id = ' . (int) $message_id;
$result = $this->db->sql_query($sql);
$row = $this->db->sql_fetchrow($result);
Expand Down
68 changes: 53 additions & 15 deletions core/mchat.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,13 @@ public function action_edit($return_raw = false)

$author = $this->functions->mchat_author_for_message($message_id);

if (!$author || $author['post_id'] || !$this->auth_message('edit', $author['user_id'], $author['message_time']))
if (!$author)
{
throw new http_exception(410, 'MCHAT_MESSAGE_DELETED');
}

// If post_id is not 0 it's a notification and notifications can't be edited
if ($author['post_id'] || !$this->auth_message('edit', $author['user_id'], $author['message_time']))
{
throw new http_exception(403, 'NO_AUTH_OPERATION');
}
Expand Down Expand Up @@ -483,7 +489,12 @@ public function action_del($return_raw = false)

$author = $this->functions->mchat_author_for_message($message_id);

if (!$author || !$this->auth_message('delete', $author['user_id'], $author['message_time']))
if (!$author)
{
throw new http_exception(410, 'MCHAT_MESSAGE_DELETED');
}

if (!$this->auth_message('delete', $author['user_id'], $author['message_time']))
{
throw new http_exception(403, 'NO_AUTH_OPERATION');
}
Expand Down Expand Up @@ -797,7 +808,7 @@ protected function render_page($page)
'MCHAT_ARCHIVE' => $this->auth->acl_get('u_mchat_archive'),
'MCHAT_RULES' => $this->user->lang('MCHAT_RULES_MESSAGE') || $this->settings->cfg('mchat_rules'),
'MCHAT_WHOIS_REFRESH_EXPLAIN' => $this->user->lang('MCHAT_WHO_IS_REFRESH_EXPLAIN', $this->settings->cfg('mchat_whois_refresh')),
'MCHAT_SESSION_TIMELEFT' => $this->user->lang('MCHAT_SESSION_ENDS', gmdate('H:i:s', (int) $this->settings->cfg('mchat_timeout'))),
'MCHAT_SESSION_TIMELEFT' => $this->user->lang('MCHAT_SESSION_ENDS', gmdate($this->settings->cfg('mchat_timeout') >= 3600 ? 'H:i:s' : 'i:s', $this->settings->cfg('mchat_timeout'))),
'MCHAT_LOG_ID' => $this->functions->get_latest_log_id(),
'MCHAT_STATIC_MESS' => htmlspecialchars_decode($static_message),
'A_MCHAT_MESS_LONG' => addslashes($this->user->lang('MCHAT_MESS_LONG', $this->settings->cfg('mchat_max_message_lngth'))),
Expand Down Expand Up @@ -835,7 +846,7 @@ protected function render_page($page)
{
$this->template->assign_block_vars('mchaturl', array(
'ACTION' => $action,
'URL' => $this->helper->route('dmzx_mchat_action_' . $action . '_controller'),
'URL' => $this->helper->route('dmzx_mchat_action_' . $action . '_controller', array(), false),
'IS_LAST' => $i + 1 === count($actions),
));
}
Expand Down Expand Up @@ -926,18 +937,15 @@ protected function assign_authors()
$md_manager = $this->extension_manager->create_extension_metadata_manager('dmzx/mchat', $this->template);
$meta = $md_manager->get_metadata();

$author_names = array();
$author_homepages = array();

foreach (array_slice($meta['authors'], 0, 2) as $author)
{
$author_names[] = $author['name'];
$author_homepages[] = sprintf('<a href="%1$s" title="%2$s">%2$s</a>', $author['homepage'], $author['name']);
}

$this->template->assign_vars(array(
'MCHAT_DISPLAY_NAME' => $meta['extra']['display-name'],
'MCHAT_AUTHOR_NAMES' => implode(' &amp; ', $author_names),
'MCHAT_AUTHOR_HOMEPAGES' => implode(' &amp; ', $author_homepages),
));
}
Expand Down Expand Up @@ -1004,8 +1012,24 @@ public function assign_messages($rows, $page = '')
return;
}

// Reverse the array if messages appear at the bottom
if ($page !== 'archive' && !$this->settings->cfg('mchat_message_top'))
// At this point the rows are sorted by ID bottom to top.
// We need to reverse the array if they need to be sorted top to bottom.
$reverse = false;
$mchat_message_top = $this->settings->cfg('mchat_message_top');
if ($page === 'archive')
{
$mchat_archive_sort = $this->settings->cfg('mchat_archive_sort');
if ($mchat_archive_sort == settings::ARCHIVE_SORT_TOP_BOTTOM || $mchat_archive_sort == settings::ARCHIVE_SORT_USER && !$mchat_message_top)
{
$reverse = true;
}
}
else if (!$mchat_message_top)
{
$reverse = true;
}

if ($reverse)
{
$rows = array_reverse($rows);
}
Expand All @@ -1021,12 +1045,12 @@ public function assign_messages($rows, $page = '')
$user_avatars = array();

// Cache avatars
$display_avatar = $this->display_avatars();
foreach ($rows as $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(
$user_avatars[$row['user_id']] = !$display_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 : 0,
Expand Down Expand Up @@ -1056,7 +1080,16 @@ public function assign_messages($rows, $page = '')

$message_age = time() - $row['message_time'];
$minutes_ago = $this->get_minutes_ago($message_age);
$datetime = $this->user->format_date($row['message_time'], $this->settings->cfg('mchat_date'), true);
$absolute_datetime = $this->user->format_date($row['message_time'], $this->settings->cfg('mchat_date'), true);
// If relative time is selected, also display "today" / "yesterday", else display absolute time.
if ($this->settings->cfg('mchat_relative_time'))
{
$datetime = $this->user->format_date($row['message_time'], $this->settings->cfg('mchat_date'), false);
}
else
{
$datetime = $this->user->format_date($row['message_time'], $this->settings->cfg('mchat_date'), true);
}

$is_poster = $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] == $row['user_id'];

Expand All @@ -1080,7 +1113,7 @@ public function assign_messages($rows, $page = '')
'MCHAT_U_PERMISSIONS' => append_sid("{$board_url}{$this->root_path}adm/index.{$this->php_ext}", 'i=permissions&amp;mode=setting_user_global&amp;user_id%5B0%5D=' . $row['user_id'], true, $this->user->session_id),
'MCHAT_MESSAGE' => generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']),
'MCHAT_TIME' => $minutes_ago === -1 ? $datetime : $this->user->lang('MCHAT_MINUTES_AGO', $minutes_ago),
'MCHAT_DATETIME' => $datetime,
'MCHAT_DATETIME' => $absolute_datetime,
'MCHAT_MINUTES_AGO' => $minutes_ago,
'MCHAT_RELATIVE_UPDATE' => 60 - $message_age % 60,
'MCHAT_MESSAGE_TIME' => $row['message_time'],
Expand Down Expand Up @@ -1215,8 +1248,12 @@ protected function process_notification($row, $board_url, $post_data = null)
'#' => 'p' . $row['post_id'],
));

// We prefer $post_data because it was fetched from the forums table just now.
// $row might contain outdated data if a post was moved to a new forum.
$forum_id = isset($post_data['forum_id']) ? $post_data['forum_id'] : $row['forum_id'];

$viewforum_url = append_sid($board_url . 'viewforum.' . $this->php_ext, array(
'f' => $row['forum_id'],
'f' => $forum_id,
));

if ($post_data)
Expand Down Expand Up @@ -1491,7 +1528,8 @@ protected function process_message($message)
// Must not exceed character limit
if ($this->settings->cfg('mchat_max_message_lngth'))
{
if (utf8_strlen($message) > $this->settings->cfg('mchat_max_message_lngth'))
$message_without_entities = htmlspecialchars_decode($message, ENT_COMPAT);
if (utf8_strlen($message_without_entities) > $this->settings->cfg('mchat_max_message_lngth'))
{
throw new http_exception(400, 'MCHAT_MESS_LONG', array($this->settings->cfg('mchat_max_message_lngth')));
}
Expand Down
8 changes: 8 additions & 0 deletions core/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ class settings
/** @var bool */
public $is_phpbb32;

/**
* Possible values of the global setting mchat_archive_sort
*/
const ARCHIVE_SORT_TOP_BOTTOM = 0;
const ARCHIVE_SORT_BOTTOM_TOP = 1;
const ARCHIVE_SORT_USER = 2;

/**
* Constructor
*
Expand Down Expand Up @@ -98,6 +105,7 @@ public function __construct(
public function initialize_global_settings()
{
$global_settings = array(
'mchat_archive_sort' => array('default' => self::ARCHIVE_SORT_BOTTOM_TOP),
'mchat_bbcode_disallowed' => array('default' => '', 'validation' => array('string', false, 0, 255)),
'mchat_custom_height' => array('default' => 350, 'validation' => array('num', false, 50, 1000)),
'mchat_custom_page' => array('default' => 1),
Expand Down
Loading

0 comments on commit f659775

Please sign in to comment.