forked from lincanbin/Carbon-Forum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.php
44 lines (44 loc) · 2.21 KB
/
tag.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require(dirname(__FILE__) . '/common.php');
require(dirname(__FILE__) . '/language/' . ForumLanguage . '/tag.php');
$TagName = Request('Get', 'name');
$Page = Request('Get', 'page');
$TagInfo = array();
if ($TagName)
$TagInfo = $DB->row('SELECT * FROM ' . $Prefix . 'tags force index(TagName) Where Name=:Name', array(
'Name' => $TagName
));
if (!$TagInfo)
AlertMsg('404 Not Found', '404 Not Found', 404);
$TotalPage = ceil($TagInfo['TotalPosts'] / $Config['TopicsPerPage']);
if ($Page < 0 || $Page == 1) {
header('location: ' . $Config['WebsitePath'] . '/tag/' . $TagInfo['Name']);
exit;
}
if ($Page > $TotalPage) {
header('location: ' . $Config['WebsitePath'] . '/tag/' . $TagInfo['Name'] . '/page/' . $TotalPage);
exit;
}
if ($Page == 0)
$Page = 1;
if ($Page <= 10)
$TagIDArray = $DB->column('SELECT TopicID FROM ' . $Prefix . 'posttags force index(TagsIndex) Where TagID=:TagID ORDER BY TopicID DESC LIMIT ' . ($Page - 1) * $Config['TopicsPerPage'] . ',' . $Config['TopicsPerPage'], array(
'TagID' => $TagInfo['ID']
));
else
$TagIDArray = $DB->column('SELECT TopicID FROM ' . $Prefix . 'posttags force index(TagsIndex) Where TagID=:TagID and TopicID<=(SELECT TopicID FROM ' . $Prefix . 'posttags force index(TagsIndex) Where TagID=:TagID2 ORDER BY TopicID DESC LIMIT ' . ($Page - 1) * $Config['TopicsPerPage'] . ',1) ORDER BY TopicID DESC LIMIT ' . $Config['TopicsPerPage'], array(
'TagID' => $TagInfo['ID'],
'TagID2' => $TagInfo['ID']
));
$TopicsArray = $DB->query('SELECT `ID`, `Topic`, `Tags`, `UserID`, `UserName`, `LastName`, `LastTime`, `Replies` FROM ' . $Prefix . 'topics force index(PRI) Where ID in (?) and IsDel=0 ORDER BY LastTime DESC', $TagIDArray);
if ($CurUserID)
$IsFavorite = $DB->single("SELECT ID FROM " . $Prefix . "favorites Where UserID=:UserID and Type=2 and FavoriteID=:FavoriteID", array(
'UserID' => $CurUserID,
'FavoriteID' => $TagInfo['ID']
));
$DB->CloseConnection();
$PageTitle = $TagInfo['Name'];
$PageTitle .= $Page > 1 ? ' Page' . $Page : '';
$PageMetaDesc = $TagInfo['Name'] . ' - ' . htmlspecialchars(strip_tags(mb_substr($TagInfo['Description'], 0, 150, 'utf-8')));
$ContentFile = $TemplatePath . 'tag.php';
include($TemplatePath . 'layout.php');