PDA

View Full Version : Template Hook help in Plugins


TheSupportForum
10-31-2012, 05:32 PM
Hi guys

im in a little need of support

this is my php script

$date1 = '2007-11-20 08:00:00';
$date2 = date('Y-m-d H:i:s');
$ts1 = strtotime($date1);
$ts2 = strtotime($date2);
$seconds_diff = $ts2 - $ts1;
$seconds_diff = floor($seconds_diff/3600/24); echo " Day " . $seconds_diff; echo " of the new world "
and i need to use $template_hook[forumhome_above_forums]

i have tried


$template_hook[forumhome_above_forums] .='
$date1 = '2007-11-20 08:00:00';
$date2 = date('Y-m-d H:i:s');
$ts1 = strtotime($date1);
$ts2 = strtotime($date2);
$seconds_diff = $ts2 - $ts1;
$seconds_diff = floor($seconds_diff/3600/24); echo " Day " . $seconds_diff; echo " of the new world "
';
i get the following error

Parse error: syntax error, unexpected T_LNUMBER in /includes/class_bootstrap.php(430) : eval()'d code on line 10

but can't see where i have gone wrong, can someone help ?

kh99
10-31-2012, 06:24 PM
Just do this in place of the echo calls at the end:
$template_hook[forumhome_above_forums] .= " Day " . $seconds_diff . " of the new world ";


and if you want newlines before or after, insert <br /> in the string.

BTW, you don't need to make a string for the current date then convert it to a timestamp, you can just call time(), or use the vb constant TIMENOW (which is just set from time()). So you could do this:
$seconds_diff = TIMENOW - strtotime('2007-11-20 08:00:00');
$seconds_diff = floor($seconds_diff/3600/24);


and if you wanted to be a little more efficient, you could find out what the value of strtotime('2007-11-20 08:00:00') is and use it as a constant.

TheSupportForum
10-31-2012, 06:30 PM
Just do this in place of the echo calls at the end:
$template_hook[forumhome_above_forums] .= " Day " . $seconds_diff . " of the new world ";
and if you want newlines before or after, insert <br /> in the string.

BTW, you don't need to make a string for the current date then convert it to a timestamp, you can just call time(), or use the vb constant TIMENOW (which is just set from time()). So you could do this:
$seconds_diff = TIMENOW - strtotime('2007-11-20 08:00:00');
$seconds_diff = floor($seconds_diff/3600/24);
and if you wanted to be a little more efficient, you could find out what the value of strtotime('2007-11-20 08:00:00') is and use it as a constant.

Thank you, it worked a dream :)