Skip to content

Commit

Permalink
major update for validation
Browse files Browse the repository at this point in the history
almost all files have been changed
  • Loading branch information
LMOspaceace committed Jun 5, 2016
1 parent 5f3d426 commit 9ce13a0
Show file tree
Hide file tree
Showing 104 changed files with 2,905 additions and 3,586 deletions.
87 changes: 54 additions & 33 deletions acp/ajaxchat_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,27 @@ class ajaxchat_module
/** @var string */
protected $php_ext;

protected $phpbb_log;

protected $root_path;

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

// 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;
$this->phpbb_log = $phpbb_log;
$this->root_path = $root_path;

if (!defined('CHAT_TABLE'))
{
$chat_table = $table_prefix . 'ajax_chat';
Expand All @@ -57,20 +74,14 @@ public function main($id, $mode)
}
$this->id = $id;
$this->mode = $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;
if($this->request->variable('action', ''))
{
$this->action = $this->request->variable('action', '', true);
}

// 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;
$this->form_key = 'acp_ajax_chat';
add_form_key($this->form_key);
Expand All @@ -95,39 +106,42 @@ 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_LOCATION',
'legend2' => 'AJAX_CHAT_LAYOUT',
'ajax_chat_input_full' => ['lang' => 'AJAX_CHAT_INPUT_FULL', 'validate' => 'bool', 'type' => 'radio:enabled_enabled', 'explain' => true],
'ajax_chat_chatrow_full' => ['lang' => 'AJAX_CHAT_CHATROW_FULL', 'validate' => 'bool', 'type' => 'radio:enabled_enabled', 'explain' => true],
'legend3' => '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],
'legend3' => 'AJAX_CHAT_POSTS',
'legend4' => '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],
'legend4' => 'AJAX_CHAT_PRUNE',
'legend5' => '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'],
'legend5' => 'ACP_SUBMIT_CHANGES'
'legend6' => 'ACP_SUBMIT_CHANGES'
],
];

#region Submit
//region Submit
if ($submit)
{
$submit = $this->do_submit_stuff($display_vars);
$submit = $this->form_submition($display_vars);

// If the submit was valid, so still submitted
if ($submit)
{
trigger_error($this->user->lang('CONFIG_UPDATED') . adm_back_link($this->u_action), E_USER_NOTICE);
}
}
#endregion
//endregion

$this->generate_stuff_for_cfg_template($display_vars);

Expand Down Expand Up @@ -161,12 +175,12 @@ public function prune_chat($value, $key)
{
if (!confirm_box(true))
{
if ($this->u_action === 'prune_chat')
if (isset($this->action) && $this->action === 'prune_chat')
{
confirm_box(false, $this->user->lang['CONFIRM_PRUNE_AJAXCHAT'], build_hidden_fields([
'i' => $this->id,
'mode' => $this->mode,
'action' => $this->u_action,
'action' => $this->action,
]));
}
}
Expand All @@ -176,7 +190,7 @@ public function prune_chat($value, $key)
{
trigger_error($this->user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
}
if ($this->u_action === 'prune_chat')
if ($this->action === 'prune_chat')
{
$sql = 'SELECT message_id
FROM ' . CHAT_TABLE . '
Expand All @@ -185,8 +199,10 @@ public function prune_chat($value, $key)
$row = $this->db->sql_fetchfield('message_id');
$this->db->sql_freeresult($result);
$sql1 = 'DELETE FROM ' . CHAT_TABLE . '
WHERE `message_id` <= ' . (int) $row . '';
WHERE message_id <= ' . (int) $row;
$this->db->sql_query($sql1);
// Add the log to the ACP
$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'PRUNE_LOG_AJAXCHAT', time());

if ($this->request->is_ajax())
{
Expand All @@ -195,7 +211,8 @@ public function prune_chat($value, $key)
}
}
$this->id = str_replace("\\", "-", $this->id);
return '<a href="' . append_sid('?i=' . $this->id . '&mode=' . $this->mode . '&action=prune_chat') . '" data-ajax="true"><input class="button2" type="submit" id="' . $key . '_enable" name="' . $key . '_enable" value="' . $this->user->lang['PRUNE_NOW'] . '" /></a>';

return '<a href="' . append_sid($this->u_action . '&amp;action=prune_chat') . '" data-ajax="true"><input class="button2" type="submit" id="' . $key . '_enable" name="' . $key . '_enable" value="' . $this->user->lang['PRUNE_NOW'] . '" /></a>';
}

/**
Expand All @@ -209,12 +226,12 @@ public function truncate_chat($value, $key)
{
if (!confirm_box(true))
{
if ($this->u_action === 'truncate_chat')
if (isset($this->action) && $this->action === 'truncate_chat')
{
confirm_box(false, $this->user->lang['CONFIRM_TRUNCATE_AJAXCHAT'], build_hidden_fields([
'i' => $this->id,
'mode' => $this->mode,
'action' => $this->u_action,
'action' => $this->action,
]));
}
}
Expand All @@ -224,20 +241,22 @@ public function truncate_chat($value, $key)
{
trigger_error($this->user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
}
if ($this->u_action === 'truncate_chat')
if ($this->action === 'truncate_chat')
{
$sql1 = 'TRUNCATE ' . CHAT_TABLE . '';
$sql1 = 'TRUNCATE ' . CHAT_TABLE;
$this->db->sql_query($sql1);
// Add the log to the ACP
$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'TRUNCATE_LOG_AJAXCHAT', time());

if ($this->request->is_ajax())
{
trigger_error($this->user->lang['TRUNCATE_CHAT_SUCCESS']);
}
}
}
$this->id = str_replace("\\", "-", $this->id);
$action = append_sid('?i=' . $this->id . '&mode=' . $this->mode . '&action=truncate_chat');
return '<a href="' . $action . '" data-ajax="true"><input class="button2" type="submit" id="' . $key . '_enable" name="' . $key . '_enable" value="' . $this->user->lang['TRUNCATE_NOW'] . '" /></a>';
$this->id = str_replace("\\", "-", $this->id);

return '<a href="' . append_sid($this->u_action . '&amp;action=truncate_chat') . '" data-ajax="true"><input class="button2" type="submit" id="' . $key . '_enable" name="' . $key . '_enable" value="' . $this->user->lang['TRUNCATE_NOW'] . '" /></a>';
}

/**
Expand All @@ -249,7 +268,7 @@ public function truncate_chat($value, $key)
* @param array $special_functions Assoziative Array with config values where special functions should run on submit instead of simply save the config value. Array should contain 'config_value' => function ($this) { function code here }, or 'config_value' => null if no function should run.
* @return bool Submit valid or not.
*/
protected function do_submit_stuff($display_vars, $special_functions = [])
protected function form_submition($display_vars, $special_functions = [])
{
$this->new_config = $this->config;
$cfg_array = ($this->request->is_set('config')) ? $this->request->variable('config', ['' => ''], true) : $this->new_config;
Expand Down Expand Up @@ -314,6 +333,8 @@ protected function do_submit_stuff($display_vars, $special_functions = [])
$this->new_config[$config_name] = $cfg_array[$config_name];
$this->config->set($config_name, $cfg_array[$config_name]);
}
// Add the log to the ACP
$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'AJAX_CHAT_UPDATED_SETTINGS', time());
return true;
}

Expand Down
30 changes: 17 additions & 13 deletions adm/style/ajax_chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@

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

<h1>{L_ACP_AJAX_CHAT}</h1>
<h1>{{ lang('ACP_AJAX_CHAT') }}</h1>

<p>{L_ACP_AJAX_CHAT_EXPLAIN}</p>
<p>{{ lang('ACP_AJAX_CHAT_EXPLAIN') }}</p>

<!-- IF S_ERROR -->
<div class="errorbox">
<h3>{L_WARNING}</h3>
<h3>{{ lang('WARNING') }}</h3>
<p>{ERROR_MSG}</p>
</div>
<!-- ENDIF -->

<form id="ajax_chat" method="post" action="{U_ACTION}">

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

<fieldset>
<legend>{L_AJAX_CHAT_RULES}</legend>
<legend>{{ lang('AJAX_CHAT_RULES') }}</legend>

<p>{L_RULES_AJAX_CHAT_EXPLAIN}</p>
<p>{{ lang('RULES_AJAX_CHAT_EXPLAIN') }}</p>

<!-- INCLUDE acp_posting_buttons.html -->

Expand All @@ -39,17 +39,21 @@ <h3>{L_WARNING}</h3>
</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>
<label><input type="checkbox" class="radio" name="disable_bbcode"<!-- IF S_BBCODE_DISABLE_CHECKED --> checked="checked"<!-- ENDIF --> /> {{ lang('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>
<label><input type="checkbox" class="radio" name="disable_smilies"<!-- IF S_SMILIES_DISABLE_CHECKED --> checked="checked"<!-- ENDIF --> /> {{ lang('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>
<label><input type="checkbox" class="radio" name="disable_magic_url"<!-- IF S_MAGIC_URL_DISABLE_CHECKED --> checked="checked"<!-- ENDIF --> /> {{ lang('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>
<dd style="margin-{S_CONTENT_FLOW_BEGIN}: 90px; margin-top: 10px;"><strong>{{ lang('OPTIONS') }}{{ lang('COLON') }} </strong>{BBCODE_STATUS} :: {IMG_STATUS} :: {FLASH_STATUS} :: {URL_STATUS} :: {SMILIES_STATUS}</dd>
</dl>
<p class="submit-buttons">
<input class="button1" type="submit" id="submit" name="submit" value="{{ lang('SUBMIT') }}" />&nbsp;
<input class="button2" type="reset" id="reset" name="reset" value="{{ lang('RESET') }}" />
</p>
</fieldset>

<!-- BEGIN options -->
Expand All @@ -62,16 +66,16 @@ <h3>{L_WARNING}</h3>
<!-- ELSE -->

<dl>
<dt><label for="{options.KEY}">{options.TITLE}{L_COLON}</label><!-- IF options.S_EXPLAIN --><br /><span>{options.TITLE_EXPLAIN}</span><!-- ENDIF --></dt>
<dt><label for="{options.KEY}">{options.TITLE}{{ lang('COLON') }}</label><!-- IF options.S_EXPLAIN --><br /><span>{options.TITLE_EXPLAIN}</span><!-- ENDIF --></dt>
<dd>{options.CONTENT}</dd>
</dl>

<!-- ENDIF -->
<!-- END options -->

<p class="submit-buttons">
<input class="button1" type="submit" id="submit" name="submit" value="{L_SUBMIT}" />&nbsp;
<input class="button2" type="reset" id="reset" name="reset" value="{L_RESET}" />
<input class="button1" type="submit" id="submit" name="submit" value="{{ lang('SUBMIT') }}" />&nbsp;
<input class="button2" type="reset" id="reset" name="reset" value="{{ lang('RESET') }}" />
</p>
{S_FORM_TOKEN}
</fieldset>
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 -->
Loading

0 comments on commit 9ce13a0

Please sign in to comment.