function list_status($start = NULL, $limit = 50) { $last = last_post_id(); if ($limit > 0) { if (!$start) { $start = $last + 1; } $step = -1; } else { $limit = -$limit; if (!$start) { $start = $last - $limit; } if ($start < 0) { $start = 0; } $n = $last - $start; if ($limit > $n) { $limit = $n; } $step = 1; } $start += $step; $ret = array(); $id = $start; while ($limit > 0 && $id > 0 && $id <= $last) { if (data_exists("status/post_{$id}")) { $item = json_decode(data_read("status/post_{$id}"), true); $item['id'] = $id; $item['type_lang'] = LANG($item['type']); $item['human_time'] = human_time($item['date']); $ret[] = $item; $limit--; } $id += $step; } if ($step > 0) { $ret = array_reverse($ret); } return $ret; }
<?php if (!isset($_GET['action'])) { die; } import('model/status.php'); if ($_GET['action'] == 'delete') { remove_status($_POST['id'] * 1, true); } elseif ($_GET['action'] == 'post') { if (user() && posted('content')) { if (trim($_POST['content'])) { post_status($_POST['content'], 'say'); } } } elseif ($_GET['action'] == 'fetch') { die(json_encode(list_status($_GET['start'] * 1, $_GET['limit'] * 1))); } elseif ($_GET['action'] == 'querynew') { $id = $_GET['id'] * 1; if ($id < last_post_id()) { die('new'); } die('none'); }