Version: 1.00, by kyrnel
Developer Last Online: Jun 2013
Version: 3.0.3
Rating:
Released: 12-19-2004
Last Update: Never
Installs: 3
Is in Beta Stage
No support by the author.
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:
PHP Code:
// get first and last post ids for this page (for big reply buttons)
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:
HTML Code:
<if condition="$post['age']=='YES'">
I just made it put a small birthday cake image next to their name with this code:
HTML 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. ]
Show Your Support
This modification may not be copied, reproduced or published elsewhere without author's permission.
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
PHP Code:
'is_member_of', // function to check if $user is member of $usergroupid
PHP Code:
'substr', // substring function to compare parts of strings
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.
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?
Code:
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?
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).
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.
Does this hack work now with the age in the postbit? I'm asking because of the modified replies.
Thanks
Quote:
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.
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.