2011-11-26 08:00:20 +00:00
|
|
|
<?
|
2013-05-27 08:00:58 +00:00
|
|
|
include(SERVER_ROOT.'/classes/text.class.php');
|
2011-11-26 08:00:20 +00:00
|
|
|
$Text = new TEXT;
|
|
|
|
|
|
|
|
if (!$News = $Cache->get_value('news')) {
|
2013-05-05 08:00:31 +00:00
|
|
|
$DB->query("
|
|
|
|
SELECT
|
|
|
|
ID,
|
|
|
|
Title,
|
|
|
|
Body,
|
|
|
|
Time
|
2011-11-26 08:00:20 +00:00
|
|
|
FROM news
|
|
|
|
ORDER BY Time DESC
|
|
|
|
LIMIT 5");
|
2013-07-10 00:08:53 +00:00
|
|
|
$News = $DB->to_array(false, MYSQLI_NUM, false);
|
|
|
|
$Cache->cache_value('news', $News, 3600 * 24 * 30);
|
2011-11-26 08:00:20 +00:00
|
|
|
$Cache->cache_value('news_latest_id', $News[0][0], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($LoggedUser['LastReadNews'] != $News[0][0]) {
|
2013-07-10 00:08:53 +00:00
|
|
|
$Cache->begin_transaction("user_info_heavy_$UserID");
|
2011-11-26 08:00:20 +00:00
|
|
|
$Cache->update_row(false, array('LastReadNews' => $News[0][0]));
|
|
|
|
$Cache->commit_transaction(0);
|
2013-07-10 00:08:53 +00:00
|
|
|
$DB->query("
|
|
|
|
UPDATE users_info
|
|
|
|
SET LastReadNews = '".$News[0][0]."'
|
|
|
|
WHERE UserID = $UserID");
|
2011-11-26 08:00:20 +00:00
|
|
|
$LoggedUser['LastReadNews'] = $News[0][0];
|
|
|
|
}
|
|
|
|
|
2013-05-05 08:00:31 +00:00
|
|
|
if (($Blog = $Cache->get_value('blog')) === false) {
|
|
|
|
$DB->query("
|
|
|
|
SELECT
|
|
|
|
b.ID,
|
|
|
|
um.Username,
|
|
|
|
b.Title,
|
|
|
|
b.Body,
|
|
|
|
b.Time,
|
|
|
|
b.ThreadID
|
|
|
|
FROM blog AS b
|
2013-07-10 00:08:53 +00:00
|
|
|
LEFT JOIN users_main AS um ON b.UserID = um.ID
|
2011-11-26 08:00:20 +00:00
|
|
|
ORDER BY Time DESC
|
|
|
|
LIMIT 20");
|
|
|
|
$Blog = $DB->to_array();
|
2013-07-10 00:08:53 +00:00
|
|
|
$Cache->cache_value('blog', $Blog, 1209600);
|
2011-11-26 08:00:20 +00:00
|
|
|
}
|
|
|
|
$JsonBlog = array();
|
2012-12-01 08:00:18 +00:00
|
|
|
for ($i = 0; $i < 5; $i++) {
|
2011-11-26 08:00:20 +00:00
|
|
|
list($BlogID, $Author, $Title, $Body, $BlogTime, $ThreadID) = $Blog[$i];
|
|
|
|
$JsonBlog[] = array(
|
|
|
|
'blogId' => (int) $BlogID,
|
|
|
|
'author' => $Author,
|
|
|
|
'title' => $Title,
|
|
|
|
'body' => $Text->full_format($Body),
|
|
|
|
'blogTime' => $BlogTime,
|
|
|
|
'threadId' => (int) $ThreadID
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$JsonAnnouncements = array();
|
|
|
|
$Count = 0;
|
|
|
|
foreach ($News as $NewsItem) {
|
2013-07-10 00:08:53 +00:00
|
|
|
list($NewsID, $Title, $Body, $NewsTime) = $NewsItem;
|
2011-11-26 08:00:20 +00:00
|
|
|
if (strtotime($NewsTime) > time()) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-11-26 08:00:20 +00:00
|
|
|
$JsonAnnouncements[] = array(
|
|
|
|
'newsId' => (int) $NewsID,
|
|
|
|
'title' => $Title,
|
|
|
|
'body' => $Text->full_format($Body),
|
|
|
|
'newsTime' => $NewsTime
|
|
|
|
);
|
2013-02-22 08:00:24 +00:00
|
|
|
|
2011-11-26 08:00:20 +00:00
|
|
|
if (++$Count > 4) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-24 08:00:23 +00:00
|
|
|
json_die("success", array(
|
2013-05-14 08:00:34 +00:00
|
|
|
'announcements' => $JsonAnnouncements,
|
|
|
|
'blogPosts' => $JsonBlog
|
2013-04-24 08:00:23 +00:00
|
|
|
));
|
2011-11-26 08:00:20 +00:00
|
|
|
|
2012-07-07 08:00:11 +00:00
|
|
|
?>
|