恋雾迷尘论坛's Archiver

爱雨冷雪 发表于 2005-6-13 16:40

会员生日优化版(一天只执行一句数据库查询)

从2.2开始使用老师的生日插件.
但每次打开index.php总是要进行一次数据库查询..
2.5版的也不例外..

我对这个插件进行了一个优化..

每天只执行一次数据库查询..
然后将查询保存到文件里..

这样不必每次打开index.php就执行一次数据库查询了..
从整体上对打开主页进行了一点小小的优化

安装方法:

修改index.php

找到

[code]        if($discuz_user && $newpm) {
                require $discuz_root.'./include/pmprompt.php';
        }[/code]

在后面加上..

[code]//生日插件开始
if (!file_exists("./forumdata/templates/birthday.php")){
        $birthfile=fopen("./forumdata/templates/birthday.php",w);
}
require_once DISCUZ_ROOT.'./forumdata/templates/birthday.php';

if ($birthday_time != date(Ymd)){
        $birthday_time = date(Ymd);
        $birthday_today = getdate();
        $birthday_month = $birthday_today['mon'];
        $birthday_day = $birthday_today['mday'];
        $birthday_year = $birthday_today['year'];
        $query = $db->query("SELECT username,bday,$birthday_year-YEAR(bday) as age FROM $table_members where MONTH(bday)='$birthday_month' and DAYOFMONTH(bday)='$birthday_day' ORDER BY bday DESC;");
        $birthday_list = '';
        $comma = '';
        $birthday_num =0;
        while ($temp = $db->fetch_array($query)) {
                $birthday_list .= "$comma <a href=\\\"viewpro.php?username=".rawurlencode($temp['username'])."\\\" title='生日:".$temp['bday']."\n虚度:".$temp['age']."年光阴'>".$temp['username']."</a>";
                $comma = "\n, \n";
                $birthday_num ++;
        }
        unset($temp,$birthday_today);
        $fp=fopen("./forumdata/templates/birthday.php",w);
        fwrite($fp,"<?php\r\n\$birthday_list=\"");
        fwrite($fp,$birthday_list);
        fwrite($fp,"\";\r\n");
        fwrite($fp,"\$birthday_num=".$birthday_num.";\r\n");
        fwrite($fp,"\$birthday_time=".$birthday_time.";\r\n");
        fwrite($fp,"?>");
}
//生日插件结束[/code]

修改index.htm

找到

[code]<!--{if empty($gid) && $whosonlinestatus}-->[/code]

在上面添加

[code]<!--{if empty($gid)}-->
        <tr><td colspan="6" class="header">
        <table cellspacing="0" cellpadding="0" border="0" width="100%" align="center">
        <tr class="smalltxt" style="color: {HEADERTEXT}"><td><img src="{IMGDIR}/indexicon.gif" align="absmiddle"> <span class="bold">每日庆典</span> -
                &nbsp;今天将有 <span class="bold">$birthday_num</span> 人收到
来自社区的生日祝福</td>
        </tr></table></tr><tr>
        <td bgcolor="{ALTBG1}" width="5%" align="center"><img src="{IMGDIR}/online.gif"></td>
        <td bgcolor="{ALTBG2}" colspan="5" onMouseOver ="this.style.backgroundColor='{ALTBG1}'" onMouseOut ="this.style.backgroundColor='{ALTBG2}'">
        <table cellspacing="0" cellpadding="0" border="0" width="98%" align="center" class="smalltxt">
        <tr><td valign="middle">
        <!--{if $birthday_num>'0' }-->
                $birthday_list
        <!--{else}-->
                如果今天的到访给你带来好心情,那么别忘了明天还来啊!        <!--{/if}-->
        </td></tr></table>
<!--{/if}-->[/code]

PS:
如果以前安装了生日插件.

那么把index.php
里的

[code]//开始
$birthday_today = getdate();
$birthday_month = $birthday_today['mon'];
$birthday_day = $birthday_today['mday'];
$birthday_year = $birthday_today['year'];
$birthday_to_show = 50; //改变这里,可以设置首页显示多少个生日会员名字。
$query = $db->query("SELECT username,bday,$birthday_year-YEAR(bday) as age FROM $table_members where MONTH(bday)='$birthday_month' and DAYOFMONTH(bday)='$birthday_day' ORDER BY bday DESC LIMIT 0,".$birthday_to_show);
$birthday_list = '';
$comma = '';
$birthday_num =0;
while ($temp = $db->fetch_array($query)) {
    if($birthday_num < $birthday_to_show) {
        $birthday_list .= "$comma <a href=\"viewpro.php?&username=".rawurlencode($temp['username'])."\" alt='生日:".$temp['bday']."\r\n虚度:".$temp['age']."年光阴'>".$temp['username']."</a>";
        $comma = ", ";
    }
    $birthday_num ++;
}
if($birthday_num > $birthday_to_show) $birthday_list .= '&nbsp;...';
unset($temp,$birthday_today);
//完毕[/code]

换一下就可以了.


只是进行了一下优化..

用不用随你..


再PS:如果那天,你想更新一下当天的生日列表.
那么删除
./forumdata/templates/birthday.php

这个文件,,就会自动更新了..

结束..

爱雨冷雪 发表于 2005-6-13 16:42

补充:

如果要向生日的会员发送短消息..
请在安装完上面后..做如下修改


直接在安装插件的基础上修改
修改index.php


声明:那样...第一次统计的时候..数据库查询次数...不会是一次了..
而是1+生日人数*2
有多少..根据你自己的论坛当天生日人数定..
当然..也只执行一次...


找到

[code]$query = $db->query("SELECT username,bday,$birthday_year-YEAR(bday) as age FROM $table_members where MONTH(bday)='$birthday_month' and DAYOFMONTH(bday)='$birthday_day' ORDER BY bday DESC;");[/code]

替换成

[code]$query = $db->query("SELECT uid,username,bday,$birthday_year-YEAR(bday) as age FROM $table_members where MONTH(bday)='$birthday_month' and DAYOFMONTH(bday)='$birthday_day' ORDER BY bday DESC;");[/code]

找到

[code]while ($temp = $db->fetch_array($query)) {[/code]

在下面添加.


[code]        $msgtext='祝你生日快乐';//自定义短消息内容
        $db->query("INSERT INTO $table_pms (msgfrom, msgfromid, msgtoid, folder, new, subject, dateline, message)VALUES('System Message', '0', '$temp[uid]', 'inbox', '1', '生日祝福', '$timestamp', '$msgtext')");
        $db->query("UPDATE $table_members SET newpm='1' WHERE uid='$temp[uid]'");[/code]

cloud 发表于 2005-10-30 00:19

请问一下,如果我只想发一次短信息通知生日的那个会员,要怎样修改次数?
刚才测试了一下,会不停地发出祝福

爱雨冷雪 发表于 2005-10-30 01:43

会不停?不可能吧?我这里好像没这情况...
明天测试一下.

cloud 发表于 2005-10-30 22:13

嗯,因为我自己亲自试过的,就是我收了一条后,点开看来,但是再回到论坛,又连接收到后续的,删掉,又来

爱雨冷雪 发表于 2005-10-31 01:52

晚上测试了,,就只收一条..没有问题的..

cloud 发表于 2005-11-20 15:24

汗……据收到祝贺的会员反应,收到600条……
不知那里出错,居然这么多……

甄爱嘉桦 发表于 2005-12-2 22:26

好复杂!!!!!!:Q

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.