// 本程序版本:SaBlog-X Ver 2.0 // --------------------------------------------------------------// // 本程序主页:http://www.sablog.net // ==============================================================// require_once 'global.php'; if (!$options['sitemap']) { exit('Sitemap is not available.'); } //读取缓存文件 $cachefile = SABLOG_ROOT . 'data/cache/cache_sitemap.php'; //如果读取失败或缓存过期则从新读取数据库 if (@(!(include $cachefile)) || $expiration < $timestamp) { $mapdb = array(); $query = $DB->query("SELECT articleid,dateline,alias FROM {$db_prefix}articles WHERE visible='1' ORDER BY dateline DESC LIMIT 1000"); while ($article = $DB->fetch_array($query)) { $article['url'] = getpermalink($article['articleid'], $article['alias']); $article['dateline'] = sadate('Y-m-d\\TH:i:s\\Z', $article['dateline']); $mapdb[$article['articleid']] = $article; } //end while unset($article); $DB->free_result($query); $cachedata = "<?php\r\nif(!defined('SABLOG_ROOT')) exit('Access Denied');\r\n\$expiration='" . ($timestamp + 86400) . "';\r\n\$mapdb = unserialize('" . addcslashes(serialize($mapdb), '\\\'') . "');\r\n?>"; if (!writefile($cachefile, $cachedata)) { exit('Can not write to cache files, please check directory ./data/cache/ .'); } } header("Content-Type: application/xml"); echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; if (is_array($mapdb)) { foreach ($mapdb as $article) {
function newcomments_recache() { global $DB, $db_prefix, $options; $query = $DB->query("SELECT * FROM {$db_prefix}settings WHERE title IN ('recentcomment_num','recentcomment_limit')"); $set = array(); while ($r = $DB->fetch_array($query)) { $set[$r['title']] = $r['value']; } unset($r); $article_comment_num = (int) $options['article_comment_num']; $commentdb = array(); if ($set['recentcomment_num']) { $newcomments = $DB->query("SELECT c.commentid, c.articleid, c.author, c.email, c.url, c.dateline, c.content, a.title, a.alias FROM {$db_prefix}comments c LEFT JOIN {$db_prefix}articles a ON (a.articleid=c.articleid) WHERE a.readpassword = '' AND a.visible='1' AND c.visible='1' ORDER BY commentid DESC LIMIT " . intval($set['recentcomment_num'])); $i = 0; while ($newcomment = $DB->fetch_array($newcomments)) { $newcomment['avatardb'] = get_avatar($newcomment['email'], 32); $newcomment['content'] = preg_replace("/\\[quote=(.*?)\\]\\s*(.+?)\\s*\\[\\/quote\\]/is", "", $newcomment['content']); if (empty($newcomment['content'])) { $newcomment['content'] = '......'; } //处理链接 if ($article_comment_num) { $cpost = $DB->result($DB->query("SELECT COUNT(commentid) FROM {$db_prefix}comments WHERE articleid='" . $newcomment['articleid'] . "' AND visible='1' AND commentid<='" . $newcomment['commentid'] . "'"), 0); if ($cpost / $article_comment_num <= 1) { $page = 1; } else { $page = @ceil($cpost / $article_comment_num); } } else { $page = 1; } $newcomment['dateline'] = sadate('m-d', $newcomment['dateline']); $newcomment['content'] = trimmed_title(htmlspecialchars(sax_addslashes(str_replace(array("\r\n", "\n", "\r"), '', $newcomment['content']))), $set['recentcomment_limit']); $cmnum = '#cm' . $newcomment['commentid']; $newcomment['article_url'] = getpermalink($newcomment['articleid'], $newcomment['alias'], $page > 1 ? $page : 0) . $cmnum; $commentdb[$newcomment['commentid']] = $newcomment; } unset($newcomment); } $contents = "\$newcommentcache = unserialize('" . addcslashes(serialize($commentdb), '\\\'') . "');"; writetocache('newcomments', $contents); }
$query = '+'; } $DB->unbuffered_query("UPDATE {$db_prefix}statistics SET article_count=article_count" . $query . "1"); $DB->unbuffered_query("UPDATE {$db_prefix}users SET articles=articles" . $query . "1 WHERE userid='{$sax_uid}'"); } archives_recache(); hottags_recache(); categories_recache(); statistics_recache(); newarticles_recache(); if ($pingurl && $pingagain) { $pingurldb = explode("\n", $pingurl); foreach ($pingurldb as $pingurl) { $pingurl = trim($pingurl); if ($pingurl) { $url = str_replace('show&id', 'show&id', getpermalink($article['articleid'], $article['alias'])); $data = 'url=' . rawurlencode($url) . '&title=' . rawurlencode($article['title']) . '&blog_name=' . rawurlencode($options['name']) . '&excerpt=' . rawurlencode($article['content']); $result = sendpacket($pingurl, $data); /* if (strpos($result, 'error>0</error')) { //succ } else { //fa }*/ } } } if ($article['stick'] != $stick) { stick_recache(); } $location = getlink('article', 'mod', array('message' => 13, 'articleid' => $articleid));
function get_rand_article() { global $DB, $db_prefix, $options, $allarticleids; $articledb = array(); $options['randarticle_num'] = (int) $options['randarticle_num']; if ($options['randarticle_num'] && $allarticleids) { $idnum = count($allarticleids); if ($options['randarticle_num'] > $idnum) { $options['randarticle_num'] = $idnum; } $allarticleids = array_rand($allarticleids, $options['randarticle_num']); $query = $DB->query("SELECT articleid, title, alias FROM {$db_prefix}articles WHERE visible='1' AND articleid IN (" . implode(',', array_values($allarticleids)) . ")"); while ($article = $DB->fetch_array($query)) { $article['url'] = getpermalink($article['articleid'], $article['alias']); $articledb[$article['articleid']] = $article; } } return $articledb; }
require_once 'global.php'; if ($_GET['action'] == 'tag') { $tag = sax_addslashes($_GET['tag']); $html = '<h2><a href="javascript:;" onclick="document.getElementById(\'ajax-div\').style.display=\'none\';">关闭</a>相关文章</h2><div>'; if ($tag) { $r = $DB->fetch_one_array("SELECT mid, name, slug, count FROM {$db_prefix}metas WHERE type='tag' AND name='{$tag}' LIMIT 1"); if (!$r) { $html .= 'TAG记录不存在'; } else { $aids = get_cids($r['mid']); if ($aids) { $total = $r['count']; $query = $DB->query("SELECT articleid, title, alias FROM {$db_prefix}articles WHERE visible='1' AND articleid IN ({$aids}) ORDER BY dateline DESC LIMIT 10"); $html .= '<ul>'; while ($article = $DB->fetch_array($query)) { $html .= '<li><a href="' . getpermalink($article['articleid'], $article['alias']) . '">' . $article['title'] . '</a></li>'; } $html .= '</ul>'; if ($total > 10) { $html .= '<div style="padding-top:20px;text-align:right;"><a href="' . gettaglink($r['slug']) . '">更多相关文章</a></p>'; } } else { $html .= '没有相关文章'; } } } else { $html .= '没有相关文章'; } $html .= '</div>'; xmlmsg($html); }
function redirect_permalink($articleid, $alias = '', $page = 0) { return str_replace('&', '&', getpermalink($articleid, $alias = '', $page)); }