Gazelle/sections/ajax/announcements.php

84 lines
1.8 KiB
PHP
Raw Normal View History

2011-11-26 08:00:20 +00:00
<?
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,
2014-04-19 08:00:50 +00:00
b.UserID,
2013-05-05 08:00:31 +00:00
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++) {
2014-04-19 08:00:50 +00:00
list($BlogID, $Author, $AuthorID, $Title, $Body, $BlogTime, $ThreadID) = $Blog[$i];
2011-11-26 08:00:20 +00:00
$JsonBlog[] = array(
2013-10-30 08:01:19 +00:00
'blogId' => (int)$BlogID,
2011-11-26 08:00:20 +00:00
'author' => $Author,
'title' => $Title,
2013-07-19 08:00:28 +00:00
'bbBody' => $Body,
2013-12-12 08:01:01 +00:00
'body' => Text::full_format($Body),
2011-11-26 08:00:20 +00:00
'blogTime' => $BlogTime,
2013-10-30 08:01:19 +00:00
'threadId' => (int)$ThreadID
2011-11-26 08:00:20 +00:00
);
}
$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(
2013-10-30 08:01:19 +00:00
'newsId' => (int)$NewsID,
2011-11-26 08:00:20 +00:00
'title' => $Title,
2013-07-19 08:00:28 +00:00
'bbBody' => $Body,
2013-12-12 08:01:01 +00:00
'body' => Text::full_format($Body),
2011-11-26 08:00:20 +00:00
'newsTime' => $NewsTime
);
2013-02-22 08:00:24 +00:00
2011-11-26 08:00:20 +00:00
if (++$Count > 4) {
break;
}
}
2015-01-28 08:00:26 +00:00
json_print("success", array(
2013-05-14 08:00:34 +00:00
'announcements' => $JsonAnnouncements,
'blogPosts' => $JsonBlog
2013-04-24 08:00:23 +00:00
));