1 (11.03.2009 01:19 отредактировано atyten)

Тема: Birthdays

Установил это раасширение и заметил что когда выставляешь дату рождения (в данном случае 17.05.1985), то в просмотре профиля дата отображается на день раньше т.е. 16.05.1985. sad И это не тока с маем smile

Как можно это исправить? Спасибо

Вот пример кода из файла manifest.xml


<?xml version="1.0" encoding="utf-8"?>

<extension engine="1.0">
    <id>birthdays</id>
    <title>Birthdays</title>
    <version>1.2.1</version>
    <description>Adds Birthday field to users profile.</description>
    <author>Gizzmo</author>
    <minversion>1.3 Beta</minversion>
    <maxtestedon>1.3 Beta</maxtestedon>

    <note type="install">Options are on Settings->Features under 'User avatars'</note>

    <install><![CDATA[
        $forum_db->add_field("users", "birthday", "VARCHAR(10)", TRUE);
        $forum_db->add_field("users", "bday_email", "TINYINT(2)", FALSE, '0');

        $options = array();
        if (!array_key_exists('o_birthday_age_limit', $forum_config))
        {
            $options = array(
                '\'o_birthday_age_limit\', \'13\'',
                '\'o_birthday_index\', \'1\'',
                '\'o_birthday_email\', \'0\''
            );
        }

        if (!array_key_exists('o_birthday_upcoming_range', $forum_config))
            $options[] = '\'o_birthday_upcoming_range\', \'7\'';

        if (!empty($options))
        {
            $query = array(
                'INSERT'    => 'conf_name, conf_value',
                'INTO'        => 'config',
                'VALUES'    => $options
            );
            $forum_db->query_build($query) or error(__FILE__, __LINE__);
        }
    ]]></install>

    <uninstall><![CDATA[
        $forum_db->drop_field("users", "birthday");
        $forum_db->drop_field("users", "bday_email");

        $query = array(
            'DELETE'    =>    'config',
            'WHERE'        =>    'conf_name = \'o_birthday_age_limit\' OR
                conf_name = \'o_birthday_index\' OR
                conf_name = \'o_birthday_email\' OR
                conf_name = \'o_birthday_upcoming_range\''
        );
        $forum_db->query_build($query);
    ]]></uninstall>
    <hooks>
        <hook id="pf_start,in_start,vt_start,aop_start"><![CDATA[
            // Load the extention language file
            if (file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'.php'))
                require $ext_info['path'].'/lang/'.$forum_user['language'].'.php';
            else
                require $ext_info['path'].'/lang/English.php';
        ]]></hook>

<!--
=================================================
    Start Admin Hooks
=================================================
-->
        <hook id="aop_features_validation"><![CDATA[
            if (!isset($form['birthday_index']) || $form['birthday_index'] != '1') $form['birthday_index'] = '0';
            if (!isset($form['birthday_email']) || $form['birthday_email'] != '1') $form['birthday_email'] = '0';
            $form['birthday_age_limit'] = (is_numeric($form['birthday_age_limit']))? $form['birthday_age_limit']: '13';
        ]]></hook>
        <!-- add to the page -->
        <hook id="aop_features_avatars_fieldset_end"><![CDATA[
            // Reset counter
            $forum_page['group_count'] = $forum_page['item_count'] = 0;

            for($x=1; $x<=80; $x++)
                $lowest_age_options[] = '<option value="'.$x.'"'.(($forum_config['o_birthday_age_limit'] == $x)? ' selected="selected"': '').'>'.$x.'</option>';
            for($x=0; $x<=15; $x++)
                $upcoming_range_options[] = '<option value="'.$x.'"'.(($forum_config['o_birthday_upcoming_range'] == $x)? ' selected="selected"': '').'>'.$x.'</option>';

?>
            <div class="content-head">
                <h2 class="hn"><span><?php printf($lang_birthdays['Features head'], $lang_birthdays['User birthdays']) ?></span></h2>
            </div>
            <fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
                <legend class="group-legend"><span><?php echo $lang_birthdays['User birthdays legend']?></span></legend>
                <div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
                    <div class="sf-box checkbox">
                        <span class="fld-input"><input type="checkbox" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="form[birthday_index]" value="1"<?php if ($forum_config['o_birthday_index'] == '1') echo ' checked="checked"' ?> /></span>
                        <label for="fld<?php echo $forum_page['fld_count'] ?>"><span><?php echo $lang_birthdays['Birthdays on index']?></span> <?php echo $lang_birthdays['Birthdays on index info']?></label>
                    </div>
                    <div class="sf-box checkbox">
                        <span class="fld-input"><input type="checkbox" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="form[birthday_email]" value="1"<?php if ($forum_config['o_birthday_email'] == '1') echo ' checked="checked"' ?> /></span>
                        <label for="fld<?php echo $forum_page['fld_count'] ?>"><span><?php echo $lang_birthdays['Happy birthday email']?></span> <?php echo $lang_birthdays['Happy birthday email info']?></label>
                    </div>
                    <div class="sf-box select">
                        <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_birthdays['Age limit']?></span> <small><?php echo $lang_birthdays['Age limit info']?></small></label><br />
                        <span class="fld-input">
                            <select id="fld<?php echo $forum_page['fld_count'] ?>" name="form[birthday_age_limit]">
                                <?php echo implode("\n\t\t\t\t\t\t\t\t", $lowest_age_options)."\n" ?>
                            </select>
                        </span>
                    </div>
                    <div class="sf-box select">
                        <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_birthdays['Upcoming range']?></span> <small><?php echo $lang_birthdays['Upcoming range info']?></small></label><br />
                        <span class="fld-input">
                            <select id="fld<?php echo $forum_page['fld_count'] ?>" name="form[birthday_upcoming_range]">
                                <?php echo implode("\n\t\t\t\t\t\t\t\t", $upcoming_range_options)."\n" ?>
                            </select>
                        </span>
                    </div>
                </div>
            </fieldset>
<?php
        ]]></hook>
<!--
=================================================
    Start Profile Hooks
=================================================
-->
        <!-- after i hit submit -->
        <hook id="pf_change_details_identity_validation"><![CDATA[
            if((($_POST['bday_month'] != '0' || $_POST['bday_day'] != '0') && ($_POST['bday_month'] == '0' || $_POST['bday_day'] == '0')) || ($_POST['bday_month'] == '0' && $_POST['bday_day'] == '0' && $_POST['bday_year'] != '0000'))
                message($lang_birthdays['Submit error']);

            $form['birthday'] = ($_POST['bday_month'] != '0' && $_POST['bday_day'] != '0')? $_POST['bday_year'].'-'.$_POST['bday_month'].'-'.$_POST['bday_day']: '';
        ]]></hook>

        <!-- add to the page -->
        <hook id="pf_view_details_pre_header_load,pf_change_details_about_pre_header_load"><![CDATA[
            if($user['birthday'] != null)
            {
                list($year,$month,$day) = explode('-', $user['birthday']);
                $dayofyear = date('z', mktime(0,0,0,$month,$day,($year == 0)?date('Y'):$year));
                $forum_page['user_info']['birthday'] = '<li><span>'.$lang_birthdays['Birthday'].' <strong>'.format_time(mktime(0,0,0,$month,$day,($year == 0)?date('Y'):$year), 1, ($year == 0)?'j.m ':'j.m.Y', NULL, TRUE).'</strong></span></li>';
                $forum_page['user_info']['age'] = ($year == 0)? NULL: '<li><span>'.$lang_birthdays['Age'].' <strong>'.(date('Y')-$year-((date('z')<$dayofyear)?1:0)).'</strong></span></li>';
            }
        ]]></hook>
        <hook id="pf_change_details_identity_pre_num_posts"><![CDATA[
            $birthday = ($user['birthday'] == NULL)? '0000-0-0': $user['birthday'];
            list($bday_year,$bday_month,$bday_day) = explode('-', $birthday);
            $month_options = $day_options = $year_options = array();

            for($x=1; $x<=12; $x++)
                $month_options[] = '<option value="'.$x.'"'.(($bday_month == $x)? ' selected="selected"': '').'>'.$lang_birthdays['Month names'][$x].'</option>';
            for($x=1; $x<=31; $x++)
                $day_options[] = '<option value="'.$x.'"'.(($bday_day == $x)? ' selected="selected"': '').'>'.$x.'</option>';
            for($x=date("Y")-intval($forum_config['o_birthday_age_limit']); $x>=date("Y")-80; $x--)
                $year_options[] = '<option value="'.$x.'"'.(($bday_year == $x)? ' selected="selected"': '').'>'.$x.'</option>';
?>
                <div class="sf-set set<?php echo ++$forum_page['item_count']?>">
                    <div class="sf-box select">
                        <label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_birthdays['Birthday']?></span></label><br />
                        <span class="fld-input">
                            <select name="bday_month" id="fld<?php echo $forum_page['fld_count'] ?>">
                                <option value="0"<?php if($bday_month == '0') echo ' selected="selected"';?>><?php echo $lang_birthdays['Month']?></option>
                                <?php echo implode("\n\t\t\t\t\t\t\t\t", $month_options)."\n" ?>
                            </select>
                            <select name="bday_day">
                                <option value="0"<?php if($bday_day == '0') echo ' selected="selected"';?>><?php echo $lang_birthdays['Day']?></option>
                                <?php echo implode("\n\t\t\t\t\t\t\t\t", $day_options)."\n" ?>
                            </select>
                            <select name="bday_year">
                                <option value="0000"<?php if($bday_year == '0000') echo ' selected="selected"';?>><?php echo $lang_birthdays['Year']?></option>
                                <?php echo implode("\n\t\t\t\t\t\t\t\t", $year_options)."\n" ?>
                            </select>
                        </span>
                    </div>
                </div>

<?php
        ]]></hook>
<!--
=================================================
    Start Index Hooks
=================================================
-->
        <hook id="hd_head"><![CDATA[
            if(FORUM_PAGE == 'index')
                $forum_head['birthday'] = '<link rel="stylesheet" type="text/css" media="screen" href="'.$ext_info['url'].'/style.css" />';
        ]]></hook>
        <hook id="in_users_online_start"><![CDATA[
            if($forum_config['o_birthday_index'] != '0')
            {
                $bdays = array();
                $now = getdate(time());
                $query = array(
                    'SELECT'    => 'id, username, birthday',
                    'FROM'        => 'users',
                    'WHERE'        => 'birthday LIKE \'%-'.$now['mon'].'-'.$now['mday'].'\'',
                    'ORDER BY'    => 'username ASC',
                );

                $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);

                if ($forum_db->num_rows($result) >0)
                {
                    while($rows = $forum_db->fetch_assoc($result))
                    {
                        list($year) = explode('-', $rows['birthday']);
                        $bdays[] = '<a href="'.forum_link($forum_url['user'], $rows['id']).'">'.$rows['username'].'</a>'.(($year != 0)? ' ('.(date('Y')-$year).')':'');
                    }
?>
<div id="birthdays_today" class="gen-content">
    <h3 class="hn"><span><?php printf(((count($bdays) == 1)? $lang_birthdays['Birthdays today single']: $lang_birthdays['Birthdays today plural']), forum_number_format(count($bdays))) ?></span></h3>
    <p><?php echo implode($lang_index['Online list separator'], $bdays)?></p>
</div>

<?php

                }
                
                if ($forum_config['o_birthday_upcoming_range'] > 0)
                {
                    $bdays = array();
                    $query = array(
                        'SELECT'    => 'id, username, birthday',
                        'FROM'        => 'users',
                        'ORDER BY'    => 'username ASC',
                    );
                    for ($x=1;$x<=$forum_config['o_birthday_upcoming_range'];$x++)
                    {
                        $now = getdate(strtotime('+'.$x.' day'));
                        $where[] = 'birthday LIKE \'%-'.$now['mon'].'-'.$now['mday'].'\'';
                    }
                    $query['WHERE'] = implode(' OR ', $where);

                    $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);

                    if ($forum_db->num_rows($result) >0)
                    {
                        while($rows = $forum_db->fetch_assoc($result))
                        {
                            list($year) = explode('-', $rows['birthday']);
                            $bdays[] = '<a href="'.forum_link($forum_url['user'], $rows['id']).'">'.$rows['username'].'</a>'.(($year != 0)? ' ('.(date('Y')-$year).')':'');
                        }

?>
<div id="birthdays_soon" class="gen-content">
    <h3 class="hn"><span><?php printf(((count($bdays) == 1)? $lang_birthdays['Birthdays soon single']: $lang_birthdays['Birthdays soon plural']), forum_number_format(count($bdays)), $forum_config['o_birthday_upcoming_range']) ?></span></h3>
    <p><?php echo implode($lang_index['Online list separator'], $bdays)?></p>
</div>
<?php

                    }
                }
            }
        ]]></hook>
<!--
=================================================
    Start Email Hooks
=================================================
-->
        <hook id="co_common"><![CDATA[
            if($forum_config['o_birthday_email'] != '0')
            {
                $bdays = array();
                $now = getdate(time() + (($forum_user['timezone'] + $forum_user['dst']) * 3600));
                $query = array(
                    'SELECT'    => 'id, username, email, birthday, bday_email, language',
                    'FROM'        => 'users',
                    'WHERE'        => 'bday_email != \''.date('y').'\' AND birthday LIKE \'%-'.$now['mon'].'-'.$now['mday'].'\'',
                );
                $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);

                if ($forum_db->num_rows($result))
                {
                    if (!defined('FORUM_EMAIL_FUNCTIONS_LOADED'))
                        require FORUM_ROOT.'include/email.php';

                    // loop though the users and send emails
                    while($cur_birthday = $forum_db->fetch_assoc($result))
                    {
                        if (file_exists($ext_info['path'].'/lang/'.$cur_birthday['language'].'.tpl'))
                        {
                            // Load the template
                            $mail_tpl = forum_trim(file_get_contents($ext_info['path'].'/lang/'.$cur_birthday['language'].'.tpl'));

                            // The first row contains the subject (it also starts with "Subject:")
                            $first_crlf = strpos($mail_tpl, "\n");
                            $mail_subject = forum_trim(substr($mail_tpl, 8, $first_crlf-8));
                            $mail_message = forum_trim(substr($mail_tpl, $first_crlf));

                            list($year) = explode('-', $cur_birthday['birthday']);
                            $mail_message = str_replace('<age>', (($year !=0)?date('Y')-$year:''), $mail_message);

                            $mail_message = str_replace('<username>', $cur_birthday['username'], $mail_message);
                            $mail_message = str_replace('<board_title>', $forum_config['o_board_title'], $mail_message);
                            $mail_message = str_replace('<board_mailer>', sprintf($lang_common['Forum mailer'], $forum_config['o_board_title']), $mail_message);

                            forum_mail($cur_birthday['email'], $mail_subject, $mail_message);

                            // set the user's last bday_email sent time
                            $query = array(
                                'UPDATE'    => 'users',
                                'SET'        => 'bday_email='.date('y'),
                                'WHERE'        => 'id='.$cur_birthday['id'],
                            );

                            $forum_db->query_build($query) or error(__FILE__, __LINE__);

                            $mail_subject = $mail_message = $year = null;
                        }
                    }
                }
                unset($query);
            }
        ]]></hook>
    </hooks>
</extension>

Поделиться

2

Re: Birthdays

По моему, проблема не в расширении, а с настройками времени на форуме. У тебя время нормально отображается?

PunBB.Ru ☭

Сайт nobody

Поделиться

3 (11.03.2009 08:59 отредактировано atyten)

Re: Birthdays

http://s52.radikal.ru/i138/0903/70/4215266b479e.jpg

Имеете ввиду это?

Поделиться

4

Re: Birthdays

Ну да, просто у меня время на форуме косячно отображается, и некоторые пользователи рапортовали о том, что дни рождения съзжают на день назад. Но у меня такое было замечено и на ветке 1.2.x, поэтому я грешу на свои кривые руки big_smile
Хотя, сейчас вроде все норм, главное, чтобы у пользователей временная зона была правильно выставлена, чтобы время сообщений реальное отображалось. Короче, решения проблемы у меня нет, только догадки.

PunBB.Ru ☭

Сайт nobody

Поделиться

5

Re: Birthdays

все даты на форуме выводятся через format_time(). а он использует смещение по часовому поясу. для дней рождений надо делать исключение — свою функцию без timezone

выполню сложную работу, от $10/час - пишите в ЛС. рефссылка: VPS за $5/мес. бонус за регистрацию $10.

Сайт artoodetoo

Поделиться

6

Re: Birthdays

А можно чуть подробнее описать как нужно делать исключения и где? Спасибо.

Поделиться

7

Re: Birthdays

Возможно в format_time(mktime(0,0,0,$month,$day,($year == 0)?date('Y'):$year), 1, ($year == 0)?'j.m ':'j.m.Y', NULL, TRUE)
не хватает текущего времени, и происходит смещение относительно нуля часов.

Поделиться

8

Re: Birthdays

никто, случайно, не победил ошибку с выводом ДР в профиле ?
время на форуме корректное

Сайт Zevs

Поделиться