Inserting php into my album.tpl - Its breaking my template.

nonamer69

Joined: 2005-09-09
Posts: 21
Posted: Thu, 2007-07-19 23:12

I'm trying to include this php code into my site.
http://www.scriptygoddess.com/archives/2002/05/23/count-up-timer-in-php/

while understanding how the smarty engine works I've changed the code to the below.

{php}
$start = "June 6, 2007";
$now = strtotime ("now");
$then = strtotime ("$start");
$difference = $now - $then ;
$num = $difference/86400;
$num1 = $num/7;
$weeks = intval($num1);
$num1a = $difference/86400 - $weeks*7;
$days = intval($num1a);
$num2 = ($difference/86400 - intval($difference/86400))*24;
$hours = intval($num2);
$num3 = ($num2 - $hours)*60;
$mins = intval($num3);
$num4 = ($num3 - $mins)*60;
$secs = intval($num4);
?>
<p>
<? echo $weeks ?> weeks,
<? echo $days ?> days.
</p>
{/php}

the end result causes some kind of issue with the echo tags. When this php code is inserted it results in killing my customfields. If I remove the above code my template looks just fine and the customfields work again.

Any suggestions because I'm new to the smarty crap.

its a work in progress and I need your help. here yah go...
[url]LINK REMOVED[/url]

all help is appreciated,
nonamer69

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Fri, 2007-07-20 00:40
{php}
$start = "June 6, 2007";
$now = strtotime ("now");
$then = strtotime ("$start");
$difference = $now - $then ;
$num = $difference/86400;
$num1 = $num/7;
$weeks = intval($num1);
$num1a = $difference/86400 - $weeks*7;
$days = intval($num1a);
$num2 = ($difference/86400 - intval($difference/86400))*24;
$hours = intval($num2);
$num3 = ($num2 - $hours)*60;
$mins = intval($num3);
$num4 = ($num3 - $mins)*60;
$secs = intval($num4);
{/php}
<p>
{php} echo $weeks {/php}
 weeks,
{php} echo $days {/php} days.
</p>

I bet there is a way to do all that with a build in smarty function.
I would look through:
http://www.phpinsider.com/smarty-forum/index.php
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
nonamer69

Joined: 2005-09-09
Posts: 21
Posted: Fri, 2007-07-20 01:09

unfortunately that code didn't work. I was over at phpinsider earlier trying to search down the echo tags in smarty but I'm really thrown for a loop on what to ask or to even what to search over there. I'm not familiar at all with what you mean a build in smarty function.

thanks dave for your help.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Fri, 2007-07-20 03:50

Try:

{php}
$start = "June 6, 2007";
$now = strtotime ("now");
$then = strtotime ("$start");
$difference = $now - $then ;
$num = $difference/86400;
$num1 = $num/7;
$weeks = intval($num1);
$num1a = $difference/86400 - $weeks*7;
$days = intval($num1a);
$num2 = ($difference/86400 - intval($difference/86400))*24;
$hours = intval($num2);
$num3 = ($num2 - $hours)*60;
$mins = intval($num3);
$num4 = ($num3 - $mins)*60;
$secs = intval($num4);
echo $weeks;
echo "weeks ";
echo $days;
echo " days";
{/php}

Looks funny so you might have to do some spaces and it still says days if the value is one day.
If you find similar code in the smarty forum then I can help you get it working.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
nonamer69

Joined: 2005-09-09
Posts: 21
Posted: Fri, 2007-07-20 21:08

that worked great Dave until I placed a customfield for the $start. Would you happen to know how I could insert a customfield within php tags because now when I replace the date with a custom field it won't accept it. see below.

{php}
$start = "{$block.customfield.LoadCustomFields.fields.born}";
$now = strtotime ("now");
$then = strtotime ("$start");
$difference = $now - $then ;
$num = $difference/86400;
$num1 = $num/7;
$weeks = intval($num1);
$num1a = $difference/86400 - $weeks*7;
$days = intval($num1a);
$num2 = ($difference/86400 - intval($difference/86400))*24;
$hours = intval($num2);
$num3 = ($num2 - $hours)*60;
$mins = intval($num3);
$num4 = ($num3 - $mins)*60;
$secs = intval($num4);
echo $weeks;
echo " weeks ";
echo $days;
echo ", days";
{/php}

thanks Dave for all your help. it means so much.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sat, 2007-07-21 02:13

When you add {$block.customfield.LoadCustomFields.fields.born} does the text show?

I tried somthing like:

{assign var='name' value='June 16, 2005'}
{php}
$start = $name;
....
....
....

and it seems to work.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
nonamer69

Joined: 2005-09-09
Posts: 21
Posted: Sat, 2007-07-21 02:46

it breaks the whole page and doesn't generate the albums at all when I just simply insert the customfield inside the php tags.

I tried every combination to make that sample code you posted work but appears the customfield is not penetrating the php tags.

any other suggestions?

 
nonamer69

Joined: 2005-09-09
Posts: 21
Posted: Mon, 2007-07-23 02:55

Okay, to anyone who can either build a gallery module to do what I need or make this php script work with custom fields I will paypal them $100 buckaroos. Please anyone.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Mon, 2007-07-23 21:30

save this:

<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty strip modifier plugin
 *
 * Type:     modifier
 * Name:     date_lapse
 * Purpose:  Replace date with the difference between now
 *           and the date
 * Example:  {$date|date_lapse} 
 * Date:     July 23th, 2007
 * @author   floridave 
 * @version  1.0
 * @param string
 * @param string
 * @return string
 */
function smarty_modifier_date_lapse($date)
{
	$now = strtotime ("now");
	$then = strtotime ("$date");
	$difference = $now - $then ;
	$num = $difference/86400;
	$num1 = $num/7;
	$weeks = intval($num1);
	$num1a = $difference/86400 - $weeks*7;
	$days = intval($num1a);
	$num2 = ($difference/86400 - intval($difference/86400))*24;
	$hours = intval($num2);
	$num3 = ($num2 - $hours)*60;
	$mins = intval($num3);
	$num4 = ($num3 - $mins)*60;
	$secs = intval($num4);
	$date_lapse = $weeks . 'weeks ' . $days . 'days ';
    return $date_lapse;
}
?>

As gallery2/lib/smarty/plugins/modifier.date_lapse.php

Then you can use it like:
{$block.customfield.LoadCustomFields.fields.born|date_lapse}

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
nonamer69

Joined: 2005-09-09
Posts: 21
Posted: Mon, 2007-07-23 21:49

still getting 0 weeks 0 days? Is it possible I need extra quotations somewhere in that code because the start date does carry quotations in the original php script?

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Mon, 2007-07-23 22:06

In album.tpl I have

 {g->callback type="customfield.LoadCustomFields" itemId=$theme.item.id}

 Original date: {$block.customfield.LoadCustomFields.fields.born} :<br>
 Lapsed time: {$block.customfield.LoadCustomFields.fields.born|date_lapse}

I set a custom field for the album as:
born:June 29, 2005

works on my test album:
http://langleycom.com/gallery2/main.php

perhaps you di not load the custom fields to the template?

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

 
nonamer69

Joined: 2005-09-09
Posts: 21
Posted: Wed, 2007-07-25 23:16

it does work on photos within albums but doesn't work for the main albums. any fix for that and whats your paypal address by the way. :D

[url]LINK REMOVED[/url]

thanks,
nonamer69

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Mon, 2007-07-23 23:29
Quote:
it does work on photos within albums but doesn't work for the main albums

Then you have to add a custom field to the album as well as the photo.

It would be good the wrap it all in a {if isset($block.customfield.LoadCustomFields.fields.born)}........{/if} so nothing is displayed if the field is not set.

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

 
nonamer69

Joined: 2005-09-09
Posts: 21
Posted: Mon, 2007-07-23 23:48

the born field is in the album fields. You can see it listed down the list of that album on my page but its not generating the script.

 
nonamer69

Joined: 2005-09-09
Posts: 21
Posted: Mon, 2007-07-23 23:58

I figured it out. had to change itemId=$theme.item.id to itemId=$child.id and now it works.

thanks Dave for your help.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2007-07-24 00:13

Glad you got it sorted.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
nonamer

Joined: 2007-03-28
Posts: 63
Posted: Tue, 2007-12-11 20:56

Hi floridave. could you help me with another script? I want to do really the same thing with this one making it a modifier named modifier.add_weeks.php to call from a customfield. I tried to read between the lines of what you did to convert the script above but I'm just not getting anywhere doing this one myself :(

I need this script to work with the date format of "F j, Y" calling from a customfield. Also need it to use weeks instead of months to generate the future date.

I'll even dish out $50 bucks to whoever can help me get it going.

Quote:
<?php
$start_date="DATE HERE"; //start date from the table
$todays_date=date("Y-m-d");
$expiry_months=6; //expiry months from the table
$expiry_date=date("Y-m-d",mktime(0,0,0,date("m")+$expiry_months,date("d"),date("Y")));
if($todays_date < $expiry_date){
print "Valid. The expiry date is $expiry_date.";
} else {
print "Expired.The expiry date was $expiry_date.";
}
?>

You've been such a great help.

thanks again,
nonamer66

EDIT:I MADE AN ERROR IN POSTING THE SCRIPT.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2007-12-11 23:07

Have you tested the above code by itself with values you will give it?
What values do you give it and what is expected? Need this before I start to make a new modifier.

Dave

_____________________________________________
Blog & G2 || floridave - Gallery Team

 
nonamer

Joined: 2007-03-28
Posts: 63
Posted: Wed, 2007-12-12 01:12

Hey Dave, I just figured it out. I found another script and following along the lines of what you did in the date_lapse modifier I was able to get it. Thanks for getting back with me. This probably won't be the last time you hear from me ;)

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2007-12-12 01:24

Glad you sorted it out. Please post your results for others to benefit.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
nonamer

Joined: 2007-03-28
Posts: 63
Posted: Wed, 2007-12-12 01:47

okay, here it is.

create php file named: modifier.add_lapse.php

<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty strip modifier plugin
 *
 * Type:     modifier
 * Name:     add_lapse
 * Purpose:  Generates Future Date using the format "January 1, 2007".
 * Example:  {$date|add_lapse} Adds 56 days (8weeks) to date.
 * Date:     December 11th, 2007
 * @author   nonamer66 
 * @version  1.0
 * @param string
 * @param string
 * @return string
 */
function smarty_modifier_add_lapse($adding)
{
$ts = getdate(strtotime("$adding"));
$newTs = mktime(0, 0, 0, $ts["mon"], $ts["mday"] + 56, $ts["year"]);
$add_lapse = date("F j, Y", $newTs);

    return $add_lapse;
}
?>

example use...
{$child.originationTimestamp|date_format|add_lapse}

 
LionUk

Joined: 2008-04-02
Posts: 1
Posted: Thu, 2008-04-03 00:17

HELP!
i am newies, i am deaf too...
i trying hard find for code in .tpl from html or php,
which i use javascripts count up from any date...
that i found your scripts nearly right for me...
but...
i dont need weeks on it..
i only just days.

like my age is "days" old

i try hard find about remove weeks and just in days
i been try find eg march 30 2008
that show 0 weeks 3 days old
so i change is march 30 2007 (1 year ago)
i find that look bug is 52 weeks 5 days...
why 2 days add in 1 years... BUG SMARTY SCRIPTS?

try fix smarty scripts, and find scripts for me just days

thank cheerio

NOTE
its ok now i got it.....
might anyone want better scripts, let me know...

cheerio

 
spex

Joined: 2008-05-26
Posts: 1
Posted: Sat, 2008-11-22 15:52

Welcome

I need help with small modifications to the template siriux. I need to add
separator to group the delimiters albums. I know that I can do this by using multilevel directories.

For example, I have such directories:
bus1, bus2, bus3, tram1, tram2, tram3

I can prepare this:

Quote:
Bus
+ bus1
+ bus2
+ bus3
tram
+ tram1
+ tram2
+ tram3

However, I need to do is this:
http://www.bankfotek.pl/view/155891

I thought that used to empty the folder with a special name. If the name of the directory will be normal or "Bus2" is the script will go normally. But if it is "___Bus" will be replaced by a decimal point.

Disinterested code checking the names of the categories. Unfortunately, it can not implement the skin. I need help with that.

Quote:
<?php
if (substr($title, 1, 3) == '___') //checking whether in the name of the category is'___'
{
echo substr($title, 3) //code responsible for display only separator
}
else
{
echo $title // All the code responsible for displaying thumbnails category
}
?>

Maybe you know a better solution?