1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class FeedPoll {
- const DEFAULT_INTERVAL = 5;
- const QUEUE_CHECK = 'feedpoll-check';
-
-
- public static function enqueueNewFeeds(array $args=array()) {
- if (!isset($args['interval']) || !is_int($args['interval']) || $args['interval']<=0) {
- $args['interval'] = self::DEFAULT_INTERVAL;
- }
- $args['interval'] *= 60;
- $feedsub = new FeedSub();
- $feedsub->sub_state = 'nohub';
-
-
- $feedsub->whereAdd(sprintf('last_update < "%s"', common_sql_date(time()-$args['interval'])));
- $feedsub->find();
- $qm = QueueManager::get();
- while ($feedsub->fetch()) {
- $orig = clone($feedsub);
- $item = array('id' => $feedsub->id);
- $qm->enqueue($item, self::QUEUE_CHECK);
- $feedsub->last_update = common_sql_now();
- $feedsub->update($orig);
- }
- }
- public function setupFeedSub(FeedSub $feedsub, $interval=300)
- {
- $orig = clone($feedsub);
- $feedsub->sub_state = 'nohub';
- $feedsub->sub_start = common_sql_date(time());
- $feedsub->sub_end = '';
- $feedsub->last_update = common_sql_date(time()-$interval);
- $feedsub->update($orig);
- }
- public function checkUpdates(FeedSub $feedsub)
- {
- $request = new HTTPClient();
- $feed = $request->get($feedsub->uri);
- if (!$feed->isOk()) {
- throw new ServerException('FeedSub could not fetch id='.$feedsub->id.' (Error '.$feed->getStatus().': '.$feed->getBody());
- }
- $feedsub->receive($feed->getBody(), null);
- }
- }
|