Skip to content

Commit

Permalink
chat rule input fixed
Browse files Browse the repository at this point in the history
chat rule input now supports bbcode, urls, smilies, etc.
  • Loading branch information
LMOspaceace committed Feb 21, 2016
1 parent 207cf19 commit 1bdc3f0
Show file tree
Hide file tree
Showing 23 changed files with 283 additions and 116 deletions.
92 changes: 80 additions & 12 deletions acp/ajaxchat_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class ajaxchat_module
/** @var \phpbb\config\config */
public $new_config = [];

/** @var string form key */
public $form_key;

/** @var \phpbb\config\config */
protected $config;

Expand All @@ -38,9 +35,15 @@ class ajaxchat_module
/** @var \phpbb\request\request */
protected $request;

/** @var string */
protected $phpbb_root_path;

/** @var string */
protected $php_ext;

public function main($id, $mode)
{
global $phpbb_container, $table_prefix;
global $phpbb_container, $table_prefix, $phpbb_root_path, $phpEx;

if (!defined('CHAT_TABLE'))
{
Expand All @@ -57,14 +60,18 @@ public function main($id, $mode)
// Initialization
$this->auth = $phpbb_container->get('auth');
$this->config = $phpbb_container->get('config');
$this->config_text = $phpbb_container->get('config_text');
$this->db = $phpbb_container->get('dbal.conn');
$this->user = $phpbb_container->get('user');
$this->template = $phpbb_container->get('template');
$this->request = $phpbb_container->get('request');

$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
// Add the posting lang file needed by BBCodes
$this->user->add_lang(array('posting'));
$this->u_action = $this->request->variable('action', '', true);

$submit = ($this->request->is_set_post('submit')) ? true : false;
$submit = ($this->request->is_set_post('submit')) ? true : false;
$this->form_key = 'acp_ajax_chat';
add_form_key($this->form_key);

Expand All @@ -88,26 +95,24 @@ public function main($id, $mode)
'status_online_chat' => ['lang' => 'STATUS_ONLINE_CHAT', 'validate' => 'int', 'type' => 'number:0:9999', 'explain' => true],
'status_idle_chat' => ['lang' => 'STATUS_IDLE_CHAT', 'validate' => 'int', 'type' => 'number:0:9999', 'explain' => true],
'status_offline_chat' => ['lang' => 'STATUS_OFFLINE_CHAT', 'validate' => 'int', 'type' => 'number:0:9999', 'explain' => true],
'legend2' => 'AJAX_CHAT_RULES',
'rule_ajax_chat' => ['lang' => 'RULES_AJAX_CHAT', 'validate' => 'string', 'type' => 'textarea:4:70', 'explain' => true],
'legend3' => 'AJAX_CHAT_LOCATION',
'legend2' => 'AJAX_CHAT_LOCATION',
'location_ajax_chat_override' => ['lang' => 'LOCATION_AJAX_CHAT_OVERRIDE', 'validate' => 'bool', 'type' => 'radio:enabled_enabled', 'explain' => true],
'location_ajax_chat' => ['lang' => 'LOCATION_AJAX_CHAT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
'viewforum_ajax_chat_override' => ['lang' => 'VIEWFORUM_AJAX_CHAT_OVERRIDE', 'validate' => 'bool', 'type' => 'radio:enabled_enabled', 'explain' => true],
'viewtopic_ajax_chat_override' => ['lang' => 'VIEWTOPIC_AJAX_CHAT_OVERRIDE', 'validate' => 'bool', 'type' => 'radio:enabled_enabled', 'explain' => true],
'legend4' => 'AJAX_CHAT_POSTS',
'legend3' => 'AJAX_CHAT_POSTS',
'ajax_chat_forum_posts' => ['lang' => 'FORUM_POSTS_AJAX_CHAT', 'validate' => 'bool', 'type' => 'radio:enabled_enabled', 'explain' => false],
'ajax_chat_forum_topic' => ['lang' => 'FORUM_POSTS_AJAX_CHAT_TOPIC', 'validate' => 'bool', 'type' => 'radio:enabled_enabled', 'explain' => false],
'ajax_chat_forum_reply' => ['lang' => 'FORUM_POSTS_AJAX_CHAT_REPLY', 'validate' => 'bool', 'type' => 'radio:enabled_enabled', 'explain' => false],
'ajax_chat_forum_edit' => ['lang' => 'FORUM_POSTS_AJAX_CHAT_EDIT', 'validate' => 'bool', 'type' => 'radio:enabled_enabled', 'explain' => false],
'ajax_chat_forum_quote' => ['lang' => 'FORUM_POSTS_AJAX_CHAT_QUOTE', 'validate' => 'bool', 'type' => 'radio:enabled_enabled', 'explain' => false],
'legend5' => 'AJAX_CHAT_PRUNE',
'legend4' => 'AJAX_CHAT_PRUNE',
'prune_ajax_chat' => ['lang' => 'PRUNE_AJAX_CHAT', 'validate' => 'bool', 'type' => 'radio:enabled_enabled', 'explain' => true],
'prune_keep_ajax_chat' => ['lang' => 'PRUNE_KEEP_AJAX_CHAT', 'validate' => 'int', 'type' => 'number', 'explain' => false],
'prune_now' => ['lang' => 'PRUNE_NOW', 'validate' => 'bool', 'type' => 'custom', 'explain' => false, 'method' => 'prune_chat'],
'truncate_now' => ['lang' => 'TRUNCATE_NOW', 'validate' => 'bool', 'type' => 'custom', 'explain' => false, 'method' => 'truncate_chat'],
'ajax_chat_counter' => ['lang' => 'CHAT_COUNTER', 'validate' => 'bool', 'type' => 'custom', 'explain' => false, 'method' => 'chat_counter'],
'legend6' => 'ACP_SUBMIT_CHANGES'
'legend5' => 'ACP_SUBMIT_CHANGES'
],
];

Expand Down Expand Up @@ -252,6 +257,21 @@ protected function do_submit_stuff($display_vars, $special_functions = [])

validate_config_vars($display_vars['vars'], $cfg_array, $error);

// Get new chat rules text from the form
$data['chat_rules_text'] = $this->request->variable('ajax_chat_rule_text', '', true);

// Prepare chat rules text for storage
generate_text_for_storage(
$data['chat_rules_text'],
$data['chat_rules_uid'],
$data['chat_rules_bitfield'],
$data['chat_rules_options'],
!$this->request->variable('disable_bbcode', false),
!$this->request->variable('disable_magic_url', false),
!$this->request->variable('disable_smilies', false)
);

// Test if form key is valid
if (!check_form_key($this->form_key))
{
$error[] = $this->user->lang['FORM_INVALID'];
Expand All @@ -264,6 +284,14 @@ protected function do_submit_stuff($display_vars, $special_functions = [])
return false;
}

// Store the chat rules settings to the config_table in the database
$this->config_text->set_array(array(
'chat_rules_text' => $data['chat_rules_text'],
'chat_rules_uid' => $data['chat_rules_uid'],
'chat_rules_bitfield' => $data['chat_rules_bitfield'],
'chat_rules_options' => $data['chat_rules_options'],
));

// We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
foreach ($display_vars['vars'] as $config_name => $null)
{
Expand Down Expand Up @@ -349,10 +377,50 @@ protected function generate_stuff_for_cfg_template($display_vars)
]);
}

// Chat rules functions for ACP
// Include files needed for displaying BBCodes
if (!function_exists('display_custom_bbcodes'))
{
include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext);
}

// Get chat rules data from the config_text table in the database
$data = $this->config_text->get_array(array(
'chat_rules_text',
'chat_rules_uid',
'chat_rules_bitfield',
'chat_rules_options',
));

// Prepare the chat rules text for editing inside the textbox
$ajax_chat_rule_text_edit = generate_text_for_edit($data['chat_rules_text'], $data['chat_rules_uid'], $data['chat_rules_options']);

// Output data to the template
$this->template->assign_vars([
'S_ERROR' => (sizeof($error)) ? true : false,
'ERROR_MSG' => implode('<br />', $error),

'AJAX_CHAT_RULE_TEXT' => $ajax_chat_rule_text_edit['text'],

'S_BBCODE_DISABLE_CHECKED' => !$ajax_chat_rule_text_edit['allow_bbcode'],
'S_SMILIES_DISABLE_CHECKED' => !$ajax_chat_rule_text_edit['allow_smilies'],
'S_MAGIC_URL_DISABLE_CHECKED' => !$ajax_chat_rule_text_edit['allow_urls'],

'BBCODE_STATUS' => $this->user->lang('BBCODE_IS_ON', '<a href="' . append_sid("{$this->phpbb_root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>'),
'SMILIES_STATUS' => $this->user->lang('SMILIES_ARE_ON'),
'IMG_STATUS' => $this->user->lang('IMAGES_ARE_ON'),
'FLASH_STATUS' => $this->user->lang('FLASH_IS_ON'),
'URL_STATUS' => $this->user->lang('URL_IS_ON'),

'S_BBCODE_ALLOWED' => true,
'S_SMILIES_ALLOWED' => true,
'S_BBCODE_IMG' => true,
'S_BBCODE_FLASH' => true,
'S_LINKS_ALLOWED' => true,
'U_ACTION' => $this->u_action]
);

// Assigning custom bbcodes
display_custom_bbcodes();
}
}
35 changes: 35 additions & 0 deletions adm/style/ajax_chat.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<!-- INCLUDE overall_header.html -->

<script>
var form_name = 'ajax_chat';
var text_name = 'ajax_chat_rule_text';
var load_draft = false;
var upload = false;
var imageTag = false;
</script>

<a id="maincontent"></a>

<h1>{L_ACP_AJAX_CHAT}</h1>
Expand All @@ -17,6 +25,33 @@ <h3>{L_WARNING}</h3>

<input class="button1" type="submit" id="submit_real" name="submit" value="{L_SUBMIT}" style="display:none;" />

<fieldset>
<legend>{L_AJAX_CHAT_RULES}</legend>

<p>{L_RULES_AJAX_CHAT_EXPLAIN}</p>

<!-- INCLUDE acp_posting_buttons.html -->

<dl class="responsive-columns">
<dt style="width: 90px;" id="color_palette_placeholder" data-orientation="v" data-height="12" data-width="15" data-bbcode="true"></dt>
<dd style="margin-{S_CONTENT_FLOW_BEGIN}: 90px;">
<textarea name="ajax_chat_rule_text" rows="10" cols="60" style="width: 95%;" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);" onfocus="initInsertions();" data-bbcode="true">{AJAX_CHAT_RULE_TEXT}</textarea>
</dd>
<dd style="margin-{S_CONTENT_FLOW_BEGIN}: 90px; margin-top: 5px;">
<!-- IF S_BBCODE_ALLOWED -->
<label><input type="checkbox" class="radio" name="disable_bbcode"<!-- IF S_BBCODE_DISABLE_CHECKED --> checked="checked"<!-- ENDIF --> /> {L_DISABLE_BBCODE}</label>
<!-- ENDIF -->
<!-- IF S_SMILIES_ALLOWED -->
<label><input type="checkbox" class="radio" name="disable_smilies"<!-- IF S_SMILIES_DISABLE_CHECKED --> checked="checked"<!-- ENDIF --> /> {L_DISABLE_SMILIES}</label>
<!-- ENDIF -->
<!-- IF S_LINKS_ALLOWED -->
<label><input type="checkbox" class="radio" name="disable_magic_url"<!-- IF S_MAGIC_URL_DISABLE_CHECKED --> checked="checked"<!-- ENDIF --> /> {L_DISABLE_MAGIC_URL}</label>
<!-- ENDIF -->
</dd>
<dd style="margin-{S_CONTENT_FLOW_BEGIN}: 90px; margin-top: 10px;"><strong>{L_OPTIONS}{L_COLON} </strong>{BBCODE_STATUS} :: {IMG_STATUS} :: {FLASH_STATUS} :: {URL_STATUS} :: {SMILIES_STATUS}</dd>
</dl>
</fieldset>

<!-- BEGIN options -->
<!-- IF options.S_LEGEND -->
<!-- IF not options.S_FIRST_ROW -->
Expand Down
2 changes: 1 addition & 1 deletion adm/style/event/acp_users_prefs_append.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- INCLUDE ucp_ajax_chat.html -->
<!-- INCLUDE ucp_ajax_chat.html -->
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"type": "phpbb-extension",
"description": "Chat for phpBB 3.1",
"homepage": "http://www.livemembersonly.com",
"version": "3.0.14-BETA",
"time": "2016-01-30",
"version": "3.0.15-BETA",
"time": "2016-02-21",
"license": "GPL-2.0",
"authors": [{
"name": "spaceace",
Expand Down
1 change: 1 addition & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ services:
- '@request'
- '@controller.helper'
- '@config'
- '@config_text'
- '@ext.manager'
- '@path_helper'
- '@service_container'
Expand Down
2 changes: 1 addition & 1 deletion controller/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function index()
'LAST_ID' => $this->last_id,
'LAST_POST' => $last_post,
'TIME' => time(),
'L_VERSION' => '3.0.14-BETA',
'L_VERSION' => '3.0.15-BETA',
'STYLE_PATH' => generate_board_url() . '/styles/' . $this->user->style['style_path'],
'EXT_STYLE_PATH' => '' . $this->ext_path_web . 'styles/',
'FILENAME' => $this->helper->route('spaceace_ajaxchat_chat'),
Expand Down
28 changes: 24 additions & 4 deletions event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class listener implements EventSubscriberInterface
/** @var \phpbb\config\db */
protected $config;

/** @var \phpbb\config\db_text */
protected $config_text;

/** @var \phpbb\extension\manager "Extension Manager" */
protected $ext_manager;

Expand Down Expand Up @@ -129,7 +132,7 @@ class listener implements EventSubscriberInterface
* @param string $root_path
* @param string $php_ext
*/
public function __construct(template $template, user $user, db_driver $db, auth $auth, request $request, helper $helper, db $config, manager $ext_manager, path_helper $path_helper, Container $container, $table_prefix, $root_path, $php_ext)
public function __construct(template $template, user $user, db_driver $db, auth $auth, request $request, helper $helper, db $config, $config_text, manager $ext_manager, path_helper $path_helper, Container $container, $table_prefix, $root_path, $php_ext)
{
$this->template = $template;
$this->user = $user;
Expand All @@ -138,6 +141,7 @@ public function __construct(template $template, user $user, db_driver $db, auth
$this->request = $request;
$this->helper = $helper;
$this->config = $config;
$this->config_text = $config_text;
$this->root_path = $root_path;
$this->php_ext = $php_ext;
$this->ext_manager = $ext_manager;
Expand Down Expand Up @@ -226,12 +230,28 @@ public function page_header()
$this->template->assign_var('S_AJAX_CHAT_VIEWTOPIC_OVERRIDE', true);
}

//Declaring a few UCP switches and basic values
// Get chat rules data from the config_text object
$chat_rules_data = $this->config_text->get_array(array(
'chat_rules_text',
'chat_rules_uid',
'chat_rules_bitfield',
'chat_rules_options',
));

// Prepare chat rules for display
$chat_rules = generate_text_for_display(
$chat_rules_data['chat_rules_text'],
$chat_rules_data['chat_rules_uid'],
$chat_rules_data['chat_rules_bitfield'],
$chat_rules_data['chat_rules_options']
);

// Declaring a few UCP switches and basic values
$this->template->assign_vars(
array(
'U_CHAT' => $this->helper->route('spaceace_ajaxchat_chat'),
'S_SHOUT' => true,
'CHAT_RULES' => htmlspecialchars_decode($this->config['rule_ajax_chat']),
'CHAT_RULES' => $chat_rules,
'SCRIPT_PATH' => $this->config['script_path'],
'COOKIE_NAME' => $this->config['cookie_name'].'_fonthold',
'EXT_PATH' => $this->ext_manager->get_extension_path('spaceace/ajaxchat', true),
Expand Down Expand Up @@ -491,7 +511,7 @@ public function index()
'LAST_ID' => $this->last_id,
'LAST_POST' => $last_post,
'TIME' => time(),
'L_VERSION' => '3.0.14-BETA',
'L_VERSION' => '3.0.15-BETA',
'STYLE_PATH' => generate_board_url() . '/styles/' . $this->user->style['style_path'],
'EXT_STYLE_PATH' => '' . $this->ext_path_web . 'styles/',
'FILENAME' => $this->helper->route('spaceace_ajaxchat_chat'),
Expand Down
5 changes: 4 additions & 1 deletion migrations/install_ajaxchat.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function update_data()
// Add configs
array('config.add', array('display_ajax_chat', '1')),
array('config.add', array('whois_chatting', '1')),
array('config.add', array('rule_ajax_chat', '')),
array('config.add', array('location_ajax_chat', '1')),
array('config.add', array('location_ajax_chat_override', '0')),
array('config.add', array('viewforum_ajax_chat', '1')),
Expand Down Expand Up @@ -52,6 +51,10 @@ public function update_data()
array('config.add', array('prune_keep_ajax_chat', '300')),
array('config.add', array('ajax_chat_nav_link', '1')),
array('config.add', array('ajax_chat_quick_link', '0')),
array('config_text.add', array('chat_rules_text', '')),
array('config_text.add', array('chat_rules_uid', '')),
array('config_text.add', array('chat_rules_bitfield', '')),
array('config_text.add', array('chat_rules_options', OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS)),
// Add chat bbcode part 1
array('custom', array(array($this, 'update_chat_bbcodes'))),
// Add the cron
Expand Down
2 changes: 1 addition & 1 deletion styles/Bluespace/template/chat_body.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
</div>
<!-- IF CHAT_RULES and SCRIPT_NAME neq 'app/chat/archive' -->
<div class="chat_rules">
<span class="span_chat_rule">{L_CHAT_RULE}</span><br /><span><b>{CHAT_RULES}</b></span>
<span class="span_chat_rule">{L_CHAT_RULE}</span><br /><span>{CHAT_RULES}</span>
</div>
<!-- ENDIF -->
<div class="<!-- IF S_WHOIS_CHATTING --><!-- IF S_AJAX_CHAT_ONLINELIST and SCRIPT_NAME neq 'app/chat/archive' --> shouts<!-- ENDIF --><!-- ENDIF --><!-- IF not S_AJAX_CHAT_ONLINELIST or SCRIPT_NAME == 'app/chat/archive' or not S_WHOIS_CHATTING --> chat_online_off<!-- ENDIF --><!-- IF S_CHAT or S_POPUP or SCRIPT_NAME == 'app/chat/archive' --> main<!-- ENDIF -->">
Expand Down
2 changes: 1 addition & 1 deletion styles/Deepspace/template/chat_body.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
</div>
<!-- IF CHAT_RULES and SCRIPT_NAME neq 'app/chat/archive' -->
<div class="chat_rules">
<span class="span_chat_rule">{L_CHAT_RULE}</span><br /><span><b>{CHAT_RULES}</b></span>
<span class="span_chat_rule">{L_CHAT_RULE}</span><br /><span>{CHAT_RULES}</span>
</div>
<!-- ENDIF -->
<div class="<!-- IF S_WHOIS_CHATTING --><!-- IF S_AJAX_CHAT_ONLINELIST and SCRIPT_NAME neq 'app/chat/archive' --> shouts<!-- ENDIF --><!-- ENDIF --><!-- IF not S_AJAX_CHAT_ONLINELIST or SCRIPT_NAME == 'app/chat/archive' or not S_WHOIS_CHATTING --> chat_online_off<!-- ENDIF --><!-- IF S_CHAT or S_POPUP or SCRIPT_NAME == 'app/chat/archive' --> main<!-- ENDIF -->">
Expand Down
Loading

0 comments on commit 1bdc3f0

Please sign in to comment.