Skip to content

Commit

Permalink
Calc form submit time for Fast Reply form
Browse files Browse the repository at this point in the history
  • Loading branch information
psrustik committed Jan 14, 2015
1 parent 7e8db4b commit 6336614
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
30 changes: 22 additions & 8 deletions CleantalkMod.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ function cleantalk_check_register(&$regOptions, $theme_vars)

$ct_request->sender_nickname = isset($regOptions['username']) ? $regOptions['username'] : '';

if (isset($_SESSION['cleantalk_registration_form_start_time'])) {
$ct_request->submit_time = time() - $_SESSION['cleantalk_registration_form_start_time'];
}
$ct_request->submit_time = cleantalk_get_form_submit_time(-1);

if (isset($_POST['ct_checkjs'])) {
$ct_request->js_on = $_POST['ct_checkjs'] == cleantalk_get_checkjs_code() ? 1 : 0;
Expand Down Expand Up @@ -135,10 +133,7 @@ function cleantalk_check_message(&$msgOptions, $topicOptions, $posterOptions)
$ct_request->sender_nickname = isset($posterOptions['name']) ? $posterOptions['name'] : '';
$ct_request->message = $msgOptions['body'];

$formSeq = $_POST['seqnum'];
if (isset($_SESSION['cleantalk_post_form_start_time'][$formSeq])) {
$ct_request->submit_time = time() - $_SESSION['cleantalk_post_form_start_time'][$formSeq];
}
$ct_request->submit_time = cleantalk_get_form_submit_time($_POST['seqnum']);

if (isset($_POST['ct_checkjs'])) {
$ct_request->js_on = $_POST['ct_checkjs'] == cleantalk_get_checkjs_code() ? 1 : 0;
Expand Down Expand Up @@ -272,5 +267,24 @@ function cleantalk_print_js_input()
{
$id = uniqid('ct_checkjs');
echo '<input type="hidden" name="ct_checkjs" id="', $id, '" value="ok" />',
'<script type="text/javascript">document.getElementById("', $id, '").value ="', cleantalk_get_checkjs_code(), '</script>';
'<script type="text/javascript">document.getElementById("', $id, '").value ="', cleantalk_get_checkjs_code(), '"</script>';
}

/**
* Store form start time
* @param int $formSeq
*/
function cleantalk_store_form_start_time($formSeq)
{
$_SESSION['cleantalk_form_start_time'][$formSeq] = time();
}

/**
* Get form submit time
* @param int $formSeq
* @return int|null
*/
function cleantalk_get_form_submit_time($formSeq)
{
return isset($_SESSION['cleantalk_form_start_time'][$formSeq]) ? time() - $_SESSION['cleantalk_form_start_time'][$formSeq] : null;
}
14 changes: 8 additions & 6 deletions modification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@
<add><![CDATA[if (!isset($_POST['regSubmit']))
{
// cleantalk set start time of registration
$_SESSION['cleantalk_registration_form_start_time'] = time();
cleantalk_store_form_start_time(-1);
}
]]>
</add>
</operation>
</file>
<file name="$sourcedir/Security.php">
<operation>
<search position="before"><![CDATA[$context['form_sequence_number'] = mt_rand(1, 16000000);]]></search>
<add><![CDATA[cleantalk_store_form_start_time($context['form_sequence_number']);]]>
</add>
</operation>
</file>

<file name="$themedir/Register.template.php">
<operation>
Expand All @@ -30,11 +37,6 @@
<add><![CDATA[cleantalk_check_message($msgOptions, $topicOptions, $posterOptions);]]>
</add>
</operation>
<operation>
<search position="after"><![CDATA[// Finally, load the template.]]></search>
<add><![CDATA[/*For CleanTalk form submit time*/ if ($context['current_action'] == 'post'){ $_SESSION['cleantalk_post_form_start_time'][$context['form_sequence_number']] = time();}]]>
</add>
</operation>
</file>
<file name="$sourcedir/Subs-Post.php">
<operation>
Expand Down

0 comments on commit 6336614

Please sign in to comment.