function hottags_recache() { global $DB, $db_prefix, $options; $setting = $DB->fetch_one_array("SELECT value FROM {$db_prefix}settings WHERE title='hottags_shownum'"); $limit = $setting['value'] ? (int) $setting['value'] : 0; $tagdb = $counts = array(); if ($limit) { $smallest = 14; $largest = 28; $query = $DB->query("SELECT mid, name, slug, description, count FROM {$db_prefix}metas WHERE type='tag' ORDER BY count DESC LIMIT " . $limit); while ($tag = $DB->fetch_array($query)) { $tag['counts'] = tag_count_scale($tag['count'] ? $tag['count'] : 1); $counts[$tag['mid']] = $tag['counts']; $tag['url'] = gettaglink($tag['slug']); $tagdb[$tag['mid']] = $tag; } if ($counts) { //字体大小 $min_count = @min($counts); $spread = @max($counts) - $min_count; if ($spread <= 0) { $spread = 1; } $font_spread = $largest - $smallest; if ($font_spread < 0) { $font_spread = 1; } $font_step = $font_spread / $spread; foreach ($tagdb as $mid => $tag) { $tagdb[$mid]['fontsize'] = $smallest + ($tag['counts'] - $min_count) * $font_step; } } } $contents = "\$tagcache = unserialize('" . addcslashes(serialize($tagdb), '\\\'') . "');"; writetocache('hottags', $contents); }
if ($article['description']) { $article['content'] = $article['description']; } } $articledb[$article['articleid']] = $article; } unset($article); $DB->free_result($query); //设置一个时间戳,一定时间内该时间戳有效.用于COOKIE防盗链 scookie('viewarticle', $timestamp); $metadb = array(); if ($aids) { $query = $DB->query("SELECT m.mid, m.name, m.slug, m.type, r.cid FROM {$db_prefix}metas m\r\n\t\t\tINNER JOIN {$db_prefix}relationships r ON r.mid = m.mid\r\n\t\t\tWHERE m.type IN ('category', 'tag') AND r.cid IN ({$aids})\r\n\t\t\tORDER BY m.displayorder ASC, m.mid DESC"); while ($meta = $DB->fetch_array($query)) { if ($meta['type'] == 'tag') { $meta['url'] = gettaglink($meta['slug']); $articledb[$meta['cid']]['content'] = highlight_tag($articledb[$meta['cid']]['content'], $meta['name']); } else { $meta['url'] = getcatelink($meta['mid'], $meta['slug']); } $metadb[$meta['cid']][$meta['type']][] = $meta; } unset($meta); $DB->free_result($query); if ($haveattach) { require_once SABLOG_ROOT . 'include/func/attachment.func.php'; $attachdb = array(); $query = $DB->query("SELECT attachmentid, articleid, dateline, filename, filetype, filesize, downloads, filepath, thumb_filepath, thumb_width, thumb_height, isimage FROM {$db_prefix}attachments WHERE articleid IN ({$aids}) ORDER BY attachmentid"); $size = explode('x', strtolower($options['attachments_thumbs_size'])); while ($attach = $DB->fetch_array($query)) { $attach['filesize'] = sizecount($attach['filesize']);
} $arttotal = $DB->result($DB->query("SELECT COUNT(articleid) FROM {$db_prefix}articles a WHERE 1 {$addquery}"), 0); $hiddenarttotal = $DB->result($DB->query("SELECT COUNT(articleid) FROM {$db_prefix}articles a WHERE visible='0' {$addquery}"), 0); $displayarttotal = $arttotal - $hiddenarttotal; $stickarttotal = $DB->result($DB->query("SELECT COUNT(articleid) FROM {$db_prefix}articles a WHERE stick='1' {$addquery}"), 0); if ($mid) { $r = $DB->fetch_one_array("SELECT mid, name, slug, count, type FROM {$db_prefix}metas WHERE mid='{$mid}'"); if (!$r) { redirect('记录不存在.', './'); } $aids = get_cids($r['mid']); $total = $r['count']; if ($total && $aids) { $addquery .= " AND a.articleid IN ({$aids})"; } $pageurl = gettaglink($r['slug']); $pagelink .= '&mid=' . $mid; if ($r['type'] == 'category') { $subnav = '分类:' . $r['name']; } else { $subnav = 'Tags:' . $r['name']; } } if ($view == 'stick') { $addquery .= " AND a.stick='1'"; $subnav = '置顶的日志'; $pagelink .= '&view=stick'; } elseif ($view == 'hidden') { $addquery .= " AND a.visible='0'"; $subnav = '隐藏的日志'; $pagelink .= '&view=hidden';
function highlight_tag($content, $tag) { global $options; $tag = trim($tag); if (preg_match('/<a[^>]+?' . preg_quote($tag) . '[^>]+?>/i', $content)) { return $content; } if (preg_match('/<img[^>]+?' . preg_quote($tag) . '[^>]+?>/i', $content)) { return $content; } //有次数的替换 $content = preg_replace('/' . $tag . '/i', '<a href="' . gettaglink(urlencode($tag)) . '" onclick="javascript:tagshow(\'' . $tag . '\');return false;">' . htmlspecialchars($tag) . '</a>', $content, 1); /* 替换所有 if(function_exists('eregi_replace')) { $content = eregi_replace($tag, '<a href="'.$tagurl.'" onclick="tagshow(\''.$tag.'\');return false;" class="tagshow">'.htmlspecialchars($tag).'</a>', $content); } else { $content = str_replace($tag, '<a href="'.$tagurl.'" onclick="tagshow(\''.$tag.'\');return false;" class="tagshow">'.htmlspecialchars($tag).'</a>', $content); } */ return $content; }
$pagenum = 400; if ($page) { $start_limit = ($page - 1) * $pagenum; } else { $start_limit = 0; $page = 1; } $smallest = 14; $largest = 28; $multipage = multi($stats['tag_count'], $pagenum, $page, $tagslist_url, '', $maxpages); $query = $DB->query("SELECT mid, name, slug, type, count FROM {$db_prefix}metas WHERE type = 'tag' ORDER BY mid DESC LIMIT {$start_limit}, " . $pagenum); $tagdb = $counts = array(); while ($tag = $DB->fetch_array($query)) { $tag['counts'] = tag_count_scale($tag['count'] ? $tag['count'] : 1); $counts[$tag['mid']] = $tag['counts']; $tag['url'] = gettaglink($tag['slug']); $tagdb[$tag['mid']] = $tag; } unset($tag); $DB->free_result($query); //字体大小 if ($counts) { $min_count = @min($counts); $spread = @max($counts) - $min_count; if ($spread <= 0) { $spread = 1; } $font_spread = $largest - $smallest; if ($font_spread < 0) { $font_spread = 1; }
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); } if ($_GET['action'] == 'getalltag') { $html = '<h2><a href="javascript:;" onclick="document.getElementById(\'ajax-div\').style.display=\'none\';">关闭</a>插入已有的标签</h2>'; $total = $DB->result($DB->query("SELECT COUNT(mid) FROM {$db_prefix}metas WHERE type IN ('tag')"), 0); $html .= '<div class="alltag">';