1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
- class SupAction extends Action
- {
- function handle($args)
- {
- parent::handle($args);
- $seconds = $this->trimmed('seconds');
- if (!$seconds) {
- $seconds = 15;
- }
- $updates = $this->getUpdates($seconds);
- header('Content-Type: application/json; charset=utf-8');
- print json_encode(array('updated_time' => date('c'),
- 'since_time' => date('c', time() - $seconds),
- 'available_periods' => $this->availablePeriods(),
- 'period' => $seconds,
- 'updates' => $updates));
- }
- function availablePeriods()
- {
- static $periods = array(86400, 43200, 21600, 7200,
- 3600, 1800, 600, 300, 120,
- 60, 30, 15);
- $available = array();
- foreach ($periods as $period) {
- $available[$period] = common_local_url('sup',
- array('seconds' => $period));
- }
- return $available;
- }
- function getUpdates($seconds)
- {
- $notice = new Notice();
-
-
- $divider = common_sql_date(time() - $seconds);
- $notice->query('SELECT profile_id, max(id) AS max_id ' .
- 'FROM ( ' .
- 'SELECT profile_id, id FROM notice ' .
- ((common_config('db','type') == 'pgsql') ?
- 'WHERE extract(epoch from created) > (extract(epoch from now()) - ' . $seconds . ') ' :
- 'WHERE created > "'.$divider.'" ' ) .
- ') AS latest ' .
- 'GROUP BY profile_id');
- $updates = array();
- while ($notice->fetch()) {
- $updates[] = array($notice->profile_id, $notice->max_id);
- }
- return $updates;
- }
- function isReadOnly($args)
- {
- return true;
- }
- }
|