![]() |
Birthday Conditional in Postbit
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:
PHP Code:
HTML Code:
<if condition="$post['age']=='YES'"> HTML Code:
<if condition="$post['age']=='YES'"><img src="$stylevar[imgdir_misc]/birthday_small.gif" alt="IT'S MY BIRTHDAY!!"></if> [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. :)] |
Just use a different name....
Ie, AGEDISPLAY, instead of AGE. PHP Code:
|
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:
PHP Code:
PHP Code:
Code:
<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> Sorry if i should have made a new thread ;) |
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? Code:
if ($smonth == $sdate[0] AND $sday == $sdate[1]) |
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. |
It doesnt bother me :)
Hopefully code will be added to construct_postbit() to work this out. One hack is probably easier. |
Nice screenshot from mx6.com :-)
Great hack /me installs hack. |
Does this hack work now with the age in the postbit? I'm asking because of the modified replies.
Thanks :) Quote:
|
Quote:
|
in this hack displaye cake icon for a week?
or just in birhday date? |
All times are GMT. The time now is 05:02 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|