News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Problem with checking time() in an if statement (post.template.php)

Started by lax.slash, December 15, 2008, 04:54:33 PM

Previous topic - Next topic

lax.slash

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.

:)

lax.slash

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?

[SiNaN]

$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().
Former SMF Core Developer | My Mods | SimplePortal

lax.slash


Advertisement: