if ($archivesdb[$setdate]) {
         $total = (int) $archivesdb[$setdate];
     } else {
         $getnum = true;
     }
     // 检查是否设置$setday参数
     $setday = (int) $_GET['setday'];
     if ($setday && is_numeric($setday)) {
         $getnum = true;
         if ($setday > 31 || $setday < 1) {
             $setday = sadate('d');
         }
         $navtext = $setyear . '年' . $setmonth . '月' . $setday . '日的文章';
         $start = strtotime($setyear . '-' . $setmonth . '-' . $setday);
         $end = $start + 86400;
         $pageurl = getdaylink($setdate, $setday);
     }
     $options['title'] = settitle($navtext);
     $indexpage = 0;
 }
 //*******************************//
 $startadd = $start ? " AND a.dateline >= '" . correcttime($start) . "' " : '';
 $endadd = $end ? " AND a.dateline < '" . correcttime($end) . "' " : '';
 //*******************************//
 if ($getnum) {
     $query = $DB->query("SELECT COUNT(articleid) FROM {$db_prefix}articles a WHERE a.visible='1' " . $startadd . $endadd);
     $total = $DB->result($query, 0);
 }
 //置顶文章
 if (!$startadd && !$endadd && !$r['cid'] && !$stickycount) {
     $stickycount = $stickids['count'];
function calendar($y, $m)
{
    global $DB, $db_prefix, $options, $timestamp, $timeoffset;
    !$y && ($y = sadate('Y'));
    !$m && ($m = sadate('m'));
    //当前月等于1
    if ($m == 1) {
        $lastyear = $y - 1;
        $lastmonth = 12;
        $nextmonth = $m + 1;
        $nextyear = $y;
    } elseif ($m == 12) {
        $lastyear = $y;
        $lastmonth = $m - 1;
        $nextyear = $y + 1;
        $nextmonth = 1;
    } else {
        $lastmonth = $m - 1;
        $nextmonth = $m + 1;
        $lastyear = $nextyear = $y;
    }
    if ($nextmonth < 10) {
        $nextmonth = '0' . $nextmonth;
    }
    if ($lastmonth < 10) {
        $lastmonth = '0' . $lastmonth;
    }
    $weekday = sadate('w', mktime(0, 0, 0, $m, 1, $y));
    $totalday = sadate('t', mktime(0, 0, 0, $m, 1, $y));
    list($start, $end) = explode('-', gettimestamp($y, $m));
    // 动态缓存
    $expiration = 0;
    $cachefile = SABLOG_ROOT . 'data/cache/cache_calendar.php';
    if ($m != sadate('m') || $y != sadate('Y') || !@(include $cachefile) || $expiration < $timestamp) {
        $query = $DB->query("SELECT dateline FROM {$db_prefix}articles WHERE visible='1' AND dateline >= '" . correcttime($start) . "' AND dateline < '" . correcttime($end) . "'");
        $datelines = array();
        $articledb = array();
        while ($article = $DB->fetch_array($query)) {
            $datelines[] = sadate('Y-m-j', $article['dateline']);
            $day = sadate('j', $article['dateline']);
            if (!isset($articledb[$day])) {
                $articledb[$day]['num'] = 1;
            } else {
                $articledb[$day]['num']++;
            }
        }
        $br = 0;
        $ret['html'] = "<tr>\n";
        for ($i = 1; $i <= $weekday; $i++) {
            $ret['html'] .= "<td class=\"cal_day1\"></td>\n";
            $br++;
        }
        for ($i = 1; $i <= $totalday; $i++) {
            $br++;
            if (in_array($y . '-' . $m . '-' . $i, $datelines)) {
                $td = '<a title="' . $i . '日内发表了' . $articledb[$i]['num'] . '篇文章" href="' . getdaylink($y . $m, $i) . '">' . $i . '</a>';
            } else {
                $td = $i;
            }
            if ($i == sadate('d') && $m == sadate('m') && $y == sadate('Y')) {
                $class = 'cal_day2';
            } else {
                $class = 'cal_day1';
            }
            $ret['html'] .= "<td class=\"" . $class . "\">" . $td . "</td>\n";
            if ($br >= 7) {
                $ret['html'] .= "</tr>\n<tr>\n";
                $br = 0;
            }
        }
        if ($br != 0) {
            for ($i = $br; $i < 7; $i++) {
                $ret['html'] .= "<td class=\"cal_day1\"></td>\n";
            }
        }
        $ret['html'] .= "</tr>\n";
        if ($y . $m == sadate('Ym')) {
            $cachedata = "<?php\r\nif(!defined('SABLOG_ROOT')) exit('Access Denied');\r\n\$expiration='" . ($timestamp + 300) . "';\r\n\$ret = unserialize('" . addcslashes(serialize($ret), '\\\'') . "');\r\n?>";
            if (!writefile($cachefile, $cachedata)) {
                exit('Can not write to calendar cache files, please check directory ./data/cache/ .');
            }
        }
    }
    $ret['prevmonth'] = $lastyear . $lastmonth;
    $ret['nextmonth'] = $nextyear . $nextmonth;
    $ret['cur_month'] = $m;
    $e_month = $m < 10 ? str_replace('0', '', $m) : $m;
    $ret['cur_date'] = $y . '年' . $m . '月';
    return $ret;
}