Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: lax.slash on December 15, 2008, 04:54:33 PM

Title: Problem with checking time() in an if statement (post.template.php)
Post by: lax.slash on December 15, 2008, 04:54:33 PM
I'm writing a mod as part of a mod request. The mod basically shows a warning message if a post is being modified after a certain amount of time, asking the user to post in a new post if there is new information to add. I got to the point where the message displays, and everything. The only problem is, the error shows even before it needs to. I wrote an if statement in post.template.php, that looks like this:

Quote
   if ((!$context['is_new_post']) && (time() - $row['posterTime'] < ($modSettings['EditTimeWarningAmt'])*60))
      echo '                     
                           <tr>
                               <td></td>
                              <td align="center" class="error">
                                 <B>'. $txt['modEditTimeWarningMsg'] .'</B>
                              </td>
                           </tr>';

I've tried numerous ways of writing it, but nothing works. Unless I'm supposed to put it in a different file...  ??? The * 60 is so that it converts the seconds to minutes.


BTW - I'm writing this mod for both 1.1.x and 2.0, in case that matters.

:)
Title: Re: Problem with checking time() in an if statement (post.template.php)
Post by: lax.slash on December 16, 2008, 06:38:47 PM
OK. Now it's not showing up at all!


if (!$context['is_new_post'] && ($message['posterTime'] + $modSettings['EditTimeWarningAmt'] * 60 >= time()))
echo '                     
<tr>
    <td></td>
<td align="center" class="error">
<B>'. $txt['modEditTimeWarningMsg'] .'</B>
</td>
</tr>';


Anyone?
Title: Re: Problem with checking time() in an if statement (post.template.php)
Post by: [SiNaN] on December 17, 2008, 07:48:13 AM
$row variable in template file is empty. You need to put that value to the context array in source file.

Post.php

Find:

$context['icon'] = $row['icon'];

Replace:

$context['icon'] = $row['icon'];
$context['posterTime'] = $row['posterTime'];


Then you can use $context['posterTime'] instead of $row['posterTime']. But make sure variable is set, before using it with empty() or isset().
Title: Re: Problem with checking time() in an if statement (post.template.php)
Post by: lax.slash on December 17, 2008, 10:10:48 PM
It worked!

THANK YOU BLUE DREAM! :) :) :)