3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
22 // @todo FIXME: documentation needed.
23 class SupAction extends Action
25 function handle($args)
27 parent::handle($args);
29 $seconds = $this->trimmed('seconds');
35 $updates = $this->getUpdates($seconds);
37 header('Content-Type: application/json; charset=utf-8');
39 print json_encode(array('updated_time' => date('c'),
40 'since_time' => date('c', time() - $seconds),
41 'available_periods' => $this->availablePeriods(),
43 'updates' => $updates));
46 function availablePeriods()
48 static $periods = array(86400, 43200, 21600, 7200,
49 3600, 1800, 600, 300, 120,
52 foreach ($periods as $period) {
53 $available[$period] = common_local_url('sup',
54 array('seconds' => $period));
60 function getUpdates($seconds)
62 $notice = new Notice();
64 # XXX: cache this. Depends on how big this protocol becomes;
65 # Re-doing this query every 15 seconds isn't the end of the world.
67 $divider = common_sql_date(time() - $seconds);
69 $notice->query('SELECT profile_id, max(id) AS max_id ' .
71 'SELECT profile_id, id FROM notice ' .
72 ((common_config('db','type') == 'pgsql') ?
73 'WHERE extract(epoch from created) > (extract(epoch from now()) - ' . $seconds . ') ' :
74 'WHERE created > "'.$divider.'" ' ) .
76 'GROUP BY profile_id');
80 while ($notice->fetch()) {
81 $updates[] = array($notice->profile_id, $notice->max_id);
87 function isReadOnly($args)