PDA

View Full Version : Birthday Conditional in Postbit


kyrnel
12-19-2004, 10:00 PM
I found a way to create a birthday conditional in the postbit template.
This will allow you to put an image of a birtday cake (or something else) next to a person's username in a thread when it is thier birthday.

I have to admit, my method is kind of a hack, but it works fine as far as I can tell.

WARNING: This hack will hijack an existing post array value ($post[age]). If you display age on your forum's postbit, this hack will break that functionality.
I am open to suggestions on how to do this another way.

NOTE: I only created the code to make this work in Linear Mode. If someone wants to help make this work in Hybrid and Threaded mode, I am open to suggestions.

In showthread.php:

Find: // get first and last post ids for this page (for big reply buttons)


Right before it place:// %%%%%%%%%%%%%%%%%%%%%%% Birthday Conditional Hack %%%%%%%%%%%%%%%%%%%%%%%%

$smonth = vbdate('n', TIMENOW, false, false);
$sday = vbdate('j', TIMENOW, false, false);
$sdate = explode('-', $post['birthday']);

if ($smonth == $sdate[0] AND $sday == $sdate[1])
{
$post['age'] = 'YES';
}
else
{
$post['age'] = 'NO';
}
// %%%%%%%%%%%%%%%%%%%% End Birthday Conditional Hack %%%%%%%%%%%%%%%%%%%%%%


Now in your postbit or postbit_legacy template, you can use the conditional:
<if condition="$post['age']=='YES'">

I just made it put a small birthday cake image next to their name with this code:
<if condition="$post['age']=='YES'"><img src="$stylevar[imgdir_misc]/birthday_small.gif" alt="IT'S MY BIRTHDAY!!"></if>

Below is a screencap..

[EDIT - You'll notice in the screen cap that Age is displayed as 'YES' or 'NO'. You will need to manually disable the display of age in the template since it was hijacked for another purpose. :)]

merk
12-19-2004, 11:33 PM
Just use a different name....

Ie, AGEDISPLAY, instead of AGE.


if ($smonth == $sdate[0] AND $sday == $sdate[1])
{
$post['agedisplay'] = 'YES';
}
else
{
$post['agedisplay'] = 'NO';
}

merk
12-20-2004, 06:57 AM
Taking the idea furthur, i have sucessfully gotten it working by adding a single line to adminfunctions_template.php, which adds the ability to use substr in templates.

Add to includes/adminfunctions_template.php (around line 1550, after

'is_member_of', // function to check if $user is member of $usergroupid

'substr', // substring function to compare parts of strings


Add to phpinclude_start

$birthdaytoday = vbdate('m-d-Y', TIMENOW, false, false);


Add to the location that you want the image to appear in the postbit,


<if condition="substr($post['birthday'], 0, 5) == substr($GLOBALS['todaysdateforbirthdays'], 0, 5)"><img class="inlineimg" src="$stylevar[imgdir_misc]/birthday_small.gif" border="0" alt="$post[username]'s birthday is today!" /></if>


I think its a nicer method, because it allows you to update everything without the hassle of having to hack each individual file. It is necessary to add substr to the allowed functions list, though.

Sorry if i should have made a new thread ;)

kyrnel
12-20-2004, 11:09 AM
No, this what I expected to happen. ;)

There have been numerous requests for this conditional for quite a while and I figured I would have to come out with a bad solution in order to inspire someone who knoew what they were doing to come out with a good solution. LOL

But, I suppose that if the solution already requires modification to PHP files, that it should probably be easier to use in the templates. The substr() function makes sense to me, but it may be difficult for other members to implement.

I didn't know that you could just add an element to an array by simply declaring a value for it.
I tried using just some variable name I made up, but that didnt work, so I figured that I had to use an existing value.

I think the simpler the conditional, the better.

Would it work like this?
if ($smonth == $sdate[0] AND $sday == $sdate[1])
{
$post['agedisplay'] = true;
}
else
{
$post['agedisplay'] = false;
}

Because then the conditional would just be <if condition="$post['agedisplay']">, right?

merk
12-21-2004, 05:25 AM
Yes, that is correct. You can just add another element to the array just by referencing it.

Your method will work, perfectly, i might add. However, it requires you modify a major function every time you upgrade.

With the method i wrote above, its less taxing, imo, to add a single allowance to the adminfunctions_template.php file, as it isnt necessary to re-add after an upgrade until you modify the postbit template again.

It is a shame that you need to add a function to the allow list, because there just wasnt enough allowed functions to work with to compare the strings. The $post['birthday'] field is MM-DD-YYYY (01-10-1980) of birth, whereas birthdaytoday is MM-DD-YYYY (01-10-2004), so you have to chop the end off. (You could reduce birthdaytoday to not have the year, but the compare still would be false without substr).

kyrnel
12-21-2004, 12:02 PM
That makes sense. So I guess it is a decision between a complex conditional or maintaining a modified showthread.php file.

My showthread.php was already modded before this, so I know which way I will go. But I think this could be written up both ways to allow people to decide which one they want to use. Do you think we should release these as two separate hacks or just combine them? If separate, then I will link to yours as an alternate method.

merk
12-21-2004, 09:38 PM
It doesnt bother me :)

Hopefully code will be added to construct_postbit() to work this out.

One hack is probably easier.

That Rob Guy
12-26-2004, 08:31 PM
Nice screenshot from mx6.com :-)

Great hack

/me installs hack.

BeatificFaith
01-12-2005, 04:54 AM
Does this hack work now with the age in the postbit? I'm asking because of the modified replies.

Thanks :)



WARNING: This hack will hijack an existing post array value ($post[age]). If you display age on your forum's postbit, this hack will break that functionality.

kyrnel
01-12-2005, 12:52 PM
Does this hack work now with the age in the postbit? I'm asking because of the modified replies.

Thanks :)Yep, Just be sure to use 'agedisplay' as the variable name instead of 'age'. That way it won't interfere with the Age in postbit. I will go ahead and write this up as a hack.

asasi
12-23-2005, 01:35 PM
in this hack displaye cake icon for a week?
or just in birhday date?