Gazelle/sections/ajax/news_ajax.php

42 lines
873 B
PHP
Raw Normal View History

2013-06-14 08:18:16 +00:00
<?php
//Don't allow bigger queries than specified below regardless of called function
$SizeLimit = 10;
$Count = (int) $_GET['count'];
$Offset = (int) $_GET['offset'];
if (!isset($_GET['count']) || !isset($_GET['offset']) || $Count <= 0 || $Offset < 0 || $Count > $SizeLimit) {
json_die('failure');
}
include(SERVER_ROOT . '/classes/text.class.php');
$Text = new TEXT(true);
global $DB;
$DB->query("
SELECT
ID,
Title,
Body,
Time
FROM news
ORDER BY Time DESC
LIMIT " . $Offset . "," . $Count);
$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,
$Text->full_format($Title),
time_diff($NewsTime),
$Text->full_format($Body)
)
);
}
json_die('success', json_encode($NewsResponse));