NineChime forum

Furry stuff, oekaki stuff, and other stuff.

You are not logged in.

Post a reply

Write your message and submit
Options
Humanity test

What is four + three?

Go back

Topic review (newest first)

rainbow
09-21-2008 21:32:38

Waccoon wrote:

Redeclaration happens when you're defining a function call twice.  Make sure there is only one definition of function ymd($in) {

I'd recommend putting it in your common.php file, because the function is commonly used, and you won't have to copy/paste the function into different files.  Any functions you use regularly should be in common.php, because that file is included on every single page, and it is also included after all the constant definitions in the boot.php file (constants look like this: define ('name', 'value');).

The reason why date layouts are getting messed up is because the $datef[] array is being wiped out in the ymd() function.  So long as you have the birthday formats defined in boot.php (not in your hacks.php file), you can replace the following code:

Code:

        if (!isset ($_GLOBALS['datef'])) {
            $datef = array();
            $datef['birthdate'] = 'Y/n/j';
            $datef['birthmonth'] = 'Y/n';
        } else {
            global $datef;
        }

REPLACE WITH:

        global $datef;

It looks like the birthdate functionality in the profile.php, memberlist.php and addusr.php files are all working properly now. big_smile

Waccoon
09-21-2008 19:39:06

Redeclaration happens when you're defining a function call twice.  Make sure there is only one definition of function ymd($in) {

I'd recommend putting it in your common.php file, because the function is commonly used, and you won't have to copy/paste the function into different files.  Any functions you use regularly should be in common.php, because that file is included on every single page, and it is also included after all the constant definitions in the boot.php file (constants look like this: define ('name', 'value');).

The reason why date layouts are getting messed up is because the $datef[] array is being wiped out in the ymd() function.  So long as you have the birthday formats defined in boot.php (not in your hacks.php file), you can replace the following code:

Code:

        if (!isset ($_GLOBALS['datef'])) {
            $datef = array();
            $datef['birthdate'] = 'Y/n/j';
            $datef['birthmonth'] = 'Y/n';
        } else {
            global $datef;
        }

REPLACE WITH:

        global $datef;
rainbow
09-21-2008 08:57:37

It worked. The birthdate is displayed properly, but only in the profile.php file.

I got these fatal errors in the memberlist.php and addusr.php files:

Fatal error: Cannot redeclare ymd() (previously declared in /home/rainbow/public_html/memberlist.php:413) in /home/rainbow/public_html/memberlist.php on line 414
Fatal error: Cannot redeclare ymd() (previously declared in /home/rainbow/public_html/addusr.php:178) in /home/rainbow/public_html/addusr.php on line 178

The problem references the ymd() variable on line 414 in the memberlist.php file and on line 178 in the addusr.php file.

I put the code that you mentioned in the memberlist.php file and the addusr.php files and that what might be causing the problem. Here's a snippet from the memberlist.php file:

Code:

function ymd($in) {
        if (!isset ($_GLOBALS['datef'])) {
            $datef = array();
            $datef['birthdate'] = 'Y/n/j';
            $datef['birthmonth'] = 'Y/n';
        } else {
            global $datef;
        }
        if (empty ($in)) {
            return '';
        }
        if (strpos ($in, '-') === FALSE) {
            // Old "age" format will not work at all.
            return '';
        }

        list ($year, $month, $day) = explode ('-', $in);
        $filter = $datef['birthdate'];
        if ($day == '??') {
            $month = intval ($month);
            $day = 6;
            $filter = $datef['birthmonth'];
        }

        if ($month == '??') {
            $month = 15;
            $filter = '';
        }

        return date ($filter, strtotime ($year.'/'.$month.'/'.intval($day)));
    }

    // The n/j date PHP values of the $date string must match today's date ($today) in order to produce a happy birthday message
    $date = substr(ymd($the_user['age']), 5);

    $today = date("n/y");
    $datestamp = ymd($the_user['age']);

    $age = get_age($the_user['age']);
    echo "<div style=\"font-size: 12px\">{$age}&nbsp;";

    if (!empty ($datestamp)) {
        if ($date != $today) {
            echo "<small>({$datestamp})</div></small>";
        } else {
            echo "<small>(Happy Birthday!)&nbsp;</div></small>";
        }
    }

    if ($date == $today) {
        echo "<img src=\"birthday.gif\">";
    }

Not only the error occoured when trying to get the correct values for the member's birthdate in the memberlist.php file, it even messed up the layout upon searching for the member's current age and birthdate. sad

How can I get this redeclaration problem fixed? sad

Waccoon
09-20-2008 23:11:17

OK, try this:

Code:

function age_to_date($in) {
    if (!isset ($_GLOBALS['datef'])) {
        $datef = array();
        $datef['birthdate'] = 'Y/n/j';
        $datef['birthmonth'] = 'Y/n';
        $datef['birthyear'] = 'Y';
    } else {
        global $datef;
    }

    if (empty ($in)) {
        return '';
    }
    if (strpos ($in, '-') === FALSE) {
        // Old "age" format will not work at all.
        return '';
    }

    list ($year, $month, $day) = explode ('-', $in);
    $my_filter = $datef['birthdate'];
    if ($day == '??') {
        $month = intval ($month);
        $day = 15;
        $my_filter = $datef['birthmonth'];
    }
    if ($month == '??') {
        $month = 6;
        $my_filter = $datef['birthyear'];
    }

    return date ($my_filter, strtotime ($year.'/'.$month.'/'.intval($day)));
}


// USAGE:
$birthday = age_to_date('2004-06-??');
if (!empty ($birthday)) {
    echo ("Your birthday: {$birthday}<br />\n");
}
rainbow
09-20-2008 10:35:03

Well...I got the birthyear to display correctly, however upon entering only the year and month of birth, it's displaying the first day of the month and upon leaving the month and day blank, it's showing today's date. Here's what the snippet of the birthdate feature looks like so far:

Code:

<?
    function birthdate($in) {
        if (empty ($in)) {
            return '';
        }
        if (strpos ($in, '-') === FALSE) {
            // Old "age" format will not work at all.
            return '';
        }
        list ($year, $month, $day) = explode ('-', $in);
        if ($month == '??') {
            return strtotime ($year); 
        }
        if ($day == '??') {
            $day = '1';
        }
        return strtotime ($year.'/'.intval($month).'/'.intval($day));
    }
    $age = get_age($row['age']);
    echo $age.'&nbsp';
    if ($day == '??') {
        $datestamp_ym = $row['age'];
        echo '<small>('.date($datef['birthmonth'], birthdate($datestamp_ym)).')</small>';
    } else {
        $datestamp_ymd = $row['age'];
        echo '<small>('.date($datef['birthdate'], birthdate($datestamp_ymd)).')</small>';
    }
?>

How do I fix it to a point where the $day variable is left blank if the user did not enter the day of birth and that the current birthdate is not shown if someone has either left both the day and month values or not enter the month of their birth?

Waccoon
09-20-2008 09:05:34

You can't use the strtotime() function to decode the date format stored in the database, as it expects a format compatible with GNU.  You need a wrapper to decode it properly.

Try something like this:

Code:

function age_to_time($in) {
    if (empty ($in)) {
        return '';
    }
    if (strpos ($in, '-') === FALSE) {
        // Old "age" format will not work at all.
        return '';
    }

    list ($year, $month, $day) = explode ('-', $in);
    if ($month == '??') {
        return strtotime ($year);
    }
    if ($day == '??') {
        $day = '1';
    }

    return strtotime ($year.'/'.intval($month).'/'.intval($day));
}


$my_date = '2001-04-??';
echo date('Y/n/j', age_to_time($my_date));

The only major problem is that whatever is printed will default to the first month and first day of the year.  You're dealing with a timestamp format, not a date, so using the date format string and date() function will always give some wonky results.  It's possible to make an age_to_date() function that will only print what information is available, but that requires a lot of string mashing to make it work with all possible date string formats, or it would have to import the entire $datef[] array and branch appropriately to use the correct format.

rainbow
09-19-2008 16:22:58

I've got a bit of a problem here. I've noticed that someone registered my oekaki and entered only their birthyear. When someone enters only the year of their birth and either the month number or day in which they were born on, the birthdate shows up as "1969/12/31" when I looked at the database and the true date shows the actual year as well as the ??-?? (no month or day selected). I'm using a custom date format to determine the birthdate in the addusr.php, memberlist.php and profile.php files.

So here is the snippet of what I got in the profile.php file so far:

Code:

    <? if (!empty ($row['age'])) { ?>
            <tr>
                <td>
                    <div align="right">
                        <font size="-2"><strong><?=$langop_word_age?>:</strong></font>
                    </div>
                </td>


                <td>
                    <font size="-2">
                    <?
                        $the_date = $row['age'];
                        $the_age = get_age($row['age']);

                        $month = date("n",strtotime($row['age']));
                        $day = date("j",strtotime($row['age']));

                        if (strpos ($the_date, '-') === FALSE) {
                            // No birthday
                            $the_b_day = '';
                        } else {
                            $the_b_day = ' <small>('.date($datef['birthdate'], strtotime($row['age'])).')</small>';
                        }
                        echo $the_age.$the_b_day."\n";
                    ?>
                    </font>
                </td>
            </tr>
        <? } ?>

The $datef['birthdate'] attributes to the custom birthdate format in the boot.php file:

Code:

// Dates
$datef = array();
$datef['birthdate'] = 'Y/n/j';
$datef['birthmonth'] = 'Y/n';
$datef['birthyear'] = 'Y';

The birthdate variable is for a user who entered the year, month and the day as their birthdate. The birthmonth variable would be for someone who entered only the year and month and the birthyear is for someone who only entered the year of birth.


If I use a custom date format for the birthdate, how can I get it to show the correct birthdate without having to make modifications to the database where the original year-mm-dd value is stored in?

Board footer

Yep, still running PunBB
© Copyright 2002–2008 PunBB