Gazelle/sections/ajax/news_ajax.php

41 lines
803 B
PHP
Raw Permalink Normal View History

2013-12-12 08:01:01 +00:00
<?
2013-06-14 08:18:16 +00:00
//Don't allow bigger queries than specified below regardless of called function
$SizeLimit = 10;
2013-10-30 08:01:19 +00:00
$Count = (int)$_GET['count'];
$Offset = (int)$_GET['offset'];
2013-06-14 08:18:16 +00:00
if (!isset($_GET['count']) || !isset($_GET['offset']) || $Count <= 0 || $Offset < 0 || $Count > $SizeLimit) {
json_die('failure');
}
2013-12-12 08:01:01 +00:00
Text::$TOC = true;
2013-06-14 08:18:16 +00:00
global $DB;
$DB->query("
SELECT
ID,
Title,
Body,
Time
FROM news
ORDER BY Time DESC
2013-06-22 08:01:03 +00:00
LIMIT $Offset, $Count");
2013-06-14 08:18:16 +00:00
$News = $DB->to_array(false, MYSQLI_NUM, false);
$NewsResponse = array();
foreach ($News as $NewsItem) {
list($NewsID, $Title, $Body, $NewsTime) = $NewsItem;
array_push(
$NewsResponse,
array(
$NewsID,
2013-12-12 08:01:01 +00:00
Text::full_format($Title),
2013-06-14 08:18:16 +00:00
time_diff($NewsTime),
2013-12-12 08:01:01 +00:00
Text::full_format($Body)
2013-06-14 08:18:16 +00:00
)
);
}
2015-01-28 08:00:26 +00:00
json_print('success', json_encode($NewsResponse));