vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.0 Beta Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=34)
-   -   Birthday Conditional in Postbit (https://vborg.vbsupport.ru/showthread.php?t=73099)

kyrnel 12-19-2004 10:00 PM

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:

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

Right before it place:
PHP Code:

// %%%%%%%%%%%%%%%%%%%%%%% Birthday Conditional Hack %%%%%%%%%%%%%%%%%%%%%%%%

        
$smonth vbdate('n'TIMENOWfalsefalse);
        
$sday vbdate('j'TIMENOWfalsefalse);
        
$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:
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. :)]

merk 12-19-2004 11:33 PM

Just use a different name....

Ie, AGEDISPLAY, instead of AGE.

PHP Code:

        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
PHP Code:

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

PHP Code:

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

Add to phpinclude_start
PHP Code:

$birthdaytoday vbdate('m-d-Y'TIMENOWfalsefalse); 

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

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>
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?
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?

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 :)


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.

kyrnel 01-12-2005 12:52 PM

Quote:

Originally Posted by Tia
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?


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
  • Page Generation 0.01082 seconds
  • Memory Usage 1,763KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (2)bbcode_html_printable
  • (6)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (11)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete