Need a little help showing User's Age in view_forum.html

Discussion forum for MOD Writers regarding MOD Development.
Locked
User avatar
Dangerell
Registered User
Posts: 89
Joined: Mon Oct 13, 2008 7:05 am
Location: Romania
Name: Cristi
Contact:

Need a little help showing User's Age in view_forum.html

Post by Dangerell »

Hi,

Can someone please tell me how to define the user's age variable in view_forum.php so i can use it in view_forum.html?
I want to use it in view_forum.html like this:

Code: Select all

 <!-- IF AGE > 5 --> x <-- ELSE --> y -->
Thanks in advance.
User avatar
JimA
Community Team Leader
Community Team Leader
Posts: 7819
Joined: Thu Jul 31, 2008 5:54 am
Location: The Netherlands
Name: Jim Mossing Holsteyn
Contact:

Re: Need a little help showing User's Age in view_forum.html

Post by JimA »

The calculation of the age is done within the memberlist.php file, in the show_profile function.

Code: Select all

    $age = '';

    if ($config['allow_birthdays'] && $data['user_birthday'])
    {
        list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $data['user_birthday']));

        if ($bday_year)
        {
            $now = getdate(time() + $user->timezone + $user->dst - date('Z'));

            $diff = $now['mon'] - $bday_month;
            if ($diff == 0)
            {
                $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
            }
            else
            {
                $diff = ($diff < 0) ? 1 : 0;
            }

            $age = (int) ($now['year'] - $bday_year - $diff);
        }
    } 
After that calculation is done, the $age variable has the value of the age of the user that you are visiting the profile of. All you need to do then, is assigning the $age variable, to a template variable. :)

Moving this to MOD Writers Discussion
Jim Mossing Holsteyn - Community Team Leader
Knowledge Base | Documentation | Board rules

If you're having any questions about the rules/customs of this website, feel free to drop me a PM.
User avatar
Dangerell
Registered User
Posts: 89
Joined: Mon Oct 13, 2008 7:05 am
Location: Romania
Name: Cristi
Contact:

Re: Need a little help showing User's Age in view_forum.html

Post by Dangerell »

JimA wrote:The calculation of the age is done within the memberlist.php file, in the show_profile function.

After that calculation is done, the $age variable has the value of the age of the user that you are visiting the profile of. All you need to do then, is assigning the $age variable, to a template variable. :)

Moving this to MOD Writers Discussion
Yes thank you, but were exactly i have to assign it and how do i do that so i can use it in view_forum? :roll:
comkidwizzer3
Registered User
Posts: 375
Joined: Fri Jul 13, 2007 8:24 am
Location: $user->data['user_location'];
Contact:

Re: Need a little help showing User's Age in view_forum.html

Post by comkidwizzer3 »

OPEN: viewforum.php

FIND:

Code: Select all

$s_display_active = ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false; 
ADD AFTER:

Code: Select all

$age = '';

    if ($config['allow_birthdays'] && $data['user_birthday'])
    {
        list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $data['user_birthday']));

        if ($bday_year)
        {
            $now = getdate(time() + $user->timezone + $user->dst - date('Z'));

            $diff = $now['mon'] - $bday_month;
            if ($diff == 0)
            {
                $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
            }
            else
            {
                $diff = ($diff < 0) ? 1 : 0;
            }

            $age = (int) ($now['year'] - $bday_year - $diff);
        }
    } 
FIND:

Code: Select all

'MODERATORS'    => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '', 
ADD AFTER:

Code: Select all

'AGE'            => $age, 
~My MODs~
Login After Register - v1.0.0 | Custom Ranks MOD - RC

~!Hasher!~
User avatar
Dangerell
Registered User
Posts: 89
Joined: Mon Oct 13, 2008 7:05 am
Location: Romania
Name: Cristi
Contact:

Re: Need a little help showing User's Age in view_forum.html

Post by Dangerell »

Thank you very much for your quick reply! :idea:
comkidwizzer3
Registered User
Posts: 375
Joined: Fri Jul 13, 2007 8:24 am
Location: $user->data['user_location'];
Contact:

Re: Need a little help showing User's Age in view_forum.html

Post by comkidwizzer3 »

No problems ;)
~My MODs~
Login After Register - v1.0.0 | Custom Ranks MOD - RC

~!Hasher!~
User avatar
Dangerell
Registered User
Posts: 89
Joined: Mon Oct 13, 2008 7:05 am
Location: Romania
Name: Cristi
Contact:

Re: Need a little help showing User's Age in view_forum.html

Post by Dangerell »

Whats the call in view_forum.html to show the age?

I tried to see what values returns.. by simply calling:

{AGE} in view_forum template and doesnt work

and tried it in a if statement:

<!-- IF AGE > 20 --> aaa <!-- ENDIF -->

and still doesn't work.

What am i missing ?
comkidwizzer3
Registered User
Posts: 375
Joined: Fri Jul 13, 2007 8:24 am
Location: $user->data['user_location'];
Contact:

Re: Need a little help showing User's Age in view_forum.html

Post by comkidwizzer3 »

Code: Select all

<!-- IF AGE > 20 -->{AGE}<!-- ENDIF -->
There you go ;)
~My MODs~
Login After Register - v1.0.0 | Custom Ranks MOD - RC

~!Hasher!~
User avatar
Dangerell
Registered User
Posts: 89
Joined: Mon Oct 13, 2008 7:05 am
Location: Romania
Name: Cristi
Contact:

Re: Need a little help showing User's Age in view_forum.html

Post by Dangerell »

comkidwizzer3 wrote:

Code: Select all

<!-- IF AGE > 20 -->{AGE}<!-- ENDIF -->
There you go ;)
Well this is exactly how i called it first time and it doesn't shows nothing. I tried simple: {AGE} without any if and i doesn't show my age.. which is supposed to.

Something is not right..
Locked

Return to “[3.0.x] MOD Writers Discussion”