Version 1.0.0-RC2

This commit is contained in:
dmzx
2016-03-06 16:06:56 +01:00
parent fdde6ee2b2
commit 7fc464ff17
92 changed files with 2909 additions and 1845 deletions

View File

@@ -3,14 +3,15 @@
/**
*
* @package phpBB Extension - mChat
* @copyright (c) 2015 dmzx - http://www.dmzx-web.net
* @copyright (c) 2016 dmzx - http://www.dmzx-web.net
* @copyright (c) 2016 kasimi
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace dmzx\mchat\controller;
class admin_controller
class acp_controller
{
/** @var \phpbb\config\config */
protected $config;
@@ -36,47 +37,51 @@ class admin_controller
/** @var string */
protected $mchat_table;
/** @var string */
protected $mchat_deleted_messages_table;
/** @var string */
protected $root_path;
/** @var string */
protected $php_ext;
/** @var string */
public $u_action;
/**
* Constructor
*
* @param \phpbb\config\config $config
* @param \phpbb\template\template $template
* @param \phpbb\log\log_interface $log
* @param \phpbb\user $user
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\service $cache
* @param \phpbb\request\request $request
* @param $mchat_table
* @param $root_path
* @param $php_ext
* @param \phpbb\config\config $config
* @param \phpbb\template\template $template
* @param \phpbb\log\log_interface $log
* @param \phpbb\user $user
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\cache\service $cache
* @param \phpbb\request\request $request
* @param string $mchat_table
* @param string $mchat_deleted_messages_table
* @param string $root_path
* @param string $php_ext
*/
public function __construct(\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, $mchat_table, $root_path, $php_ext)
public function __construct(\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, $mchat_table, $mchat_deleted_messages_table, $root_path, $php_ext)
{
$this->config = $config;
$this->template = $template;
$this->log = $log;
$this->user = $user;
$this->db = $db;
$this->cache = $cache;
$this->request = $request;
$this->mchat_table = $mchat_table;
$this->root_path = $root_path;
$this->php_ext = $php_ext;
$this->config = $config;
$this->template = $template;
$this->log = $log;
$this->user = $user;
$this->db = $db;
$this->cache = $cache;
$this->request = $request;
$this->mchat_table = $mchat_table;
$this->mchat_deleted_messages_table = $mchat_deleted_messages_table;
$this->root_path = $root_path;
$this->php_ext = $php_ext;
}
/**
* Display the options a user can configure for this extension
* Display the options the admin can configure for this extension
*
* @param $u_action
*/
public function display_options()
public function display_options($u_action)
{
add_form_key('acp_mchat');
@@ -86,6 +91,7 @@ class admin_controller
'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, 'validation' => array()),
'mchat_relative_time' => array('default' => 1, 'validation' => array()),
'mchat_date' => array('default' => 'D M d, Y g:i a', 'validation' => array('string', false, 0, 255)),
'mchat_edit_delete_limit' => array('default' => 0, 'validation' => array()),
'mchat_flood_time' => array('default' => 0, 'validation' => array('num', false, 0, 30)),
@@ -96,6 +102,7 @@ class admin_controller
'mchat_message_limit' => array('default' => 10, 'validation' => array('num', false, 10, 30)),
'mchat_message_num' => array('default' => 10, 'validation' => array('num', false, 10, 50)),
'mchat_message_top' => array('default' => 1, 'validation' => array()),
'mchat_navbar_link' => array('default' => 1, 'validation' => array()),
'mchat_new_posts_edit' => array('default' => 0, 'validation' => array()),
'mchat_new_posts_quote' => array('default' => 0, 'validation' => array()),
'mchat_new_posts_reply' => array('default' => 0, 'validation' => array()),
@@ -124,9 +131,10 @@ class admin_controller
if (check_form_key('acp_mchat') && $this->user->data['user_type'] == USER_FOUNDER)
{
$this->db->sql_query('TRUNCATE TABLE ' . $this->mchat_table);
$this->cache->destroy('sql', $this->mchat_table);
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED');
trigger_error($this->user->lang('LOG_MCHAT_TABLE_PRUNED') . adm_back_link($this->u_action));
$this->db->sql_query('TRUNCATE TABLE ' . $this->mchat_deleted_messages_table);
$this->cache->destroy('sql', $this->mchat_deleted_messages_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));
}
}
else if ($this->request->is_set_post('submit'))
@@ -154,18 +162,6 @@ class admin_controller
$error[] = 'FORM_INVALID';
}
// Replace "error" strings with their real, localised form
// The /e modifier is deprecated since PHP 5.5.0
//$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$this->user->lang('\\1'))) ? \$this->user->lang('\\1') : '\\1'", $error);
foreach ($error as $i => $err)
{
$lang = $this->user->lang($err);
if (!empty($lang))
{
$error[$i] = $lang;
}
}
if (empty($error))
{
// Set the options the user configured
@@ -175,10 +171,13 @@ class admin_controller
}
// Add an entry into the log table
$this->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', false, array($this->user->data['username']));
trigger_error($this->user->lang('MCHAT_CONFIG_SAVED') . adm_back_link($this->u_action));
trigger_error($this->user->lang('MCHAT_CONFIG_SAVED') . adm_back_link($u_action));
}
// Replace "error" strings with their real, localised form
$error = array_map(array($this->user, 'lang'), $error);
}
$dateformat_options = '';
@@ -198,31 +197,20 @@ class admin_controller
}
$dateformat_options .= '>' . $this->user->lang('MCHAT_CUSTOM_DATEFORMAT') . '</option>';
$template_variables = array();
foreach ($mchat_config as $key => $value)
foreach (array_keys($mchat_config) as $key)
{
$template_variables[strtoupper($key)] = $this->config[$key];
$this->template->assign_var(strtoupper($key), $this->config[$key]);
}
$this->template->assign_vars(array_merge($template_variables, array(
$this->template->assign_vars(array(
'MCHAT_ERROR' => !empty($error) ? implode('<br />', $error) : '',
'MCHAT_VERSION' => $this->config['mchat_version'],
'MCHAT_FOUNDER' => $this->user->data['user_type'] == USER_FOUNDER,
'L_MCHAT_BBCODES_DISALLOWED_EXPLAIN' => sprintf($this->user->lang('MCHAT_BBCODES_DISALLOWED_EXPLAIN'), '<a href="' . append_sid("{$this->root_path}adm/index.$this->php_ext", 'i=bbcodes', true, $this->user->session_id) . '">', '</a>'),
'L_MCHAT_TIMEOUT_EXPLAIN' => sprintf($this->user->lang('MCHAT_USER_TIMEOUT_EXPLAIN'),'<a href="' . append_sid("{$this->root_path}adm/index.$this->php_ext", 'i=board&amp;mode=load', true, $this->user->session_id) . '">', '</a>', $this->config['session_length']),
'L_MCHAT_BBCODES_DISALLOWED_EXPLAIN' => $this->user->lang('MCHAT_BBCODES_DISALLOWED_EXPLAIN', '<a href="' . append_sid("{$this->root_path}adm/index.$this->php_ext", 'i=bbcodes', true, $this->user->session_id) . '">', '</a>'),
'L_MCHAT_TIMEOUT_EXPLAIN' => $this->user->lang('MCHAT_USER_TIMEOUT_EXPLAIN','<a href="' . append_sid("{$this->root_path}adm/index.$this->php_ext", 'i=board&amp;mode=load', true, $this->user->session_id) . '">', '</a>', $this->config['session_length']),
'S_MCHAT_DATEFORMAT_OPTIONS' => $dateformat_options,
'S_CUSTOM_DATEFORMAT' => $s_custom,
'U_ACTION' => $this->u_action,
)));
}
/**
* Set page url
*
* @param string $u_action Custom form action
*/
public function set_page_url($u_action)
{
$this->u_action = $u_action;
'U_ACTION' => $u_action,
));
}
}

View File

@@ -3,7 +3,8 @@
/**
*
* @package phpBB Extension - mChat
* @copyright (c) 2015 dmzx - http://www.dmzx-web.net
* @copyright (c) 2016 dmzx - http://www.dmzx-web.net
* @copyright (c) 2016 kasimi
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
@@ -14,6 +15,9 @@ use \Symfony\Component\HttpFoundation\JsonResponse;
class main_controller
{
/** @var \phpbb\user */
protected $user;
/** @var \dmzx\mchat\core\mchat */
protected $mchat;
@@ -23,11 +27,13 @@ class main_controller
/**
* Constructor
*
* @param \phpbb\user $user
* @param \dmzx\mchat\core\mchat $mchat
* @param \phpbb\request\request $request
*/
public function __construct(\dmzx\mchat\core\mchat $mchat, \phpbb\request\request $request)
public function __construct(\phpbb\user $user, \dmzx\mchat\core\mchat $mchat, \phpbb\request\request $request)
{
$this->user = $user;
$this->mchat = $mchat;
$this->request = $request;
}
@@ -40,6 +46,7 @@ class main_controller
*/
public function page($page)
{
$this->user->add_lang_ext('dmzx/mchat', 'mchat');
return call_user_func(array($this->mchat, 'page_' . $page));
}
@@ -47,7 +54,7 @@ class main_controller
* Controller for mChat actions called with Ajax requests
*
* @param string $action The action to perform, one of add|edit|del|refresh|whois
* @return A Symfony JsonResponse object
* @return \Symfony\Component\HttpFoundation\JsonResponse A Symfony JsonResponse object
*/
public function action($action)
{
@@ -56,6 +63,13 @@ class main_controller
throw new \phpbb\exception\http_exception(403, 'NO_AUTH_OPERATION');
}
// Fix avatars & smilies
if (!defined('PHPBB_USE_BOARD_URL_PATH'))
{
define('PHPBB_USE_BOARD_URL_PATH', true);
}
$this->user->add_lang_ext('dmzx/mchat', 'mchat');
$data = call_user_func(array($this->mchat, 'action_' . $action));
return new JsonResponse($data);

View File

@@ -0,0 +1,109 @@
<?php
/**
*
* @package phpBB Extension - mChat
* @copyright (c) 2016 dmzx - http://www.dmzx-web.net
* @copyright (c) 2016 kasimi
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace dmzx\mchat\controller;
class ucp_controller
{
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\template\template */
protected $template;
/** @var \phpbb\user */
protected $user;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\request\request */
protected $request;
/** @var array */
protected $user_config_keys;
/**
* Constructor
*
* @param \phpbb\config\config $config
* @param \phpbb\template\template $template
* @param \phpbb\user $user
* @param \phpbb\db\driver\driver_interface $db
* @param \phpbb\request\request $request
* @param array $user_config_keys
*/
public function __construct(\phpbb\config\config $config, \phpbb\template\template $template, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\request\request $request, $user_config_keys)
{
$this->config = $config;
$this->template = $template;
$this->user = $user;
$this->db = $db;
$this->request = $request;
$this->user_config_keys = $user_config_keys;
}
/**
* Display the options a user can configure for this extension
*
* @param $u_action
*/
public function display_options($u_action)
{
add_form_key('ucp_mchat');
$error = array();
if ($this->request->is_set_post('submit'))
{
if (!check_form_key('ucp_mchat'))
{
$error[] = 'FORM_INVALID';
}
if (empty($error))
{
$data = array();
foreach ($this->user_config_keys as $config_key)
{
$data[$config_key] = $this->request->variable($config_key, (int) $this->user->data[$config_key]);
}
$sql = 'UPDATE ' . USERS_TABLE . '
SET ' . $this->db->sql_build_array('UPDATE', $data) . '
WHERE user_id = ' . (int) $this->user->data['user_id'];
$this->db->sql_query($sql);
meta_refresh(3, $u_action);
$message = $this->user->lang('PROFILE_UPDATED') . '<br /><br />' . $this->user->lang('RETURN_UCP', '<a href="' . $u_action . '">', '</a>');
trigger_error($message);
}
// Replace "error" strings with their real, localised form
$error = array_map(array($this->user, 'lang'), $error);
}
foreach ($this->user_config_keys as $config_key)
{
$this->template->assign_var(strtoupper($config_key), $this->user->data[$config_key]);
}
$this->template->assign_vars(array(
'ERROR' => sizeof($error) ? implode('<br />', $error) : '',
'S_UCP_ACTION' => $u_action,
'S_MCHAT_TOPICS' => $this->config['mchat_new_posts_edit'] || $this->config['mchat_new_posts_quote'] || $this->config['mchat_new_posts_reply'] || $this->config['mchat_new_posts_topic'],
'S_MCHAT_INDEX' => $this->config['mchat_on_index'],
'S_MCHAT_INDEX_STATS' => $this->config['mchat_stats_index'],
'S_MCHAT_AVATARS' => $this->config['mchat_avatars'],
));
}
}