FeedPollerPlugin.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * GNU social feed polling plugin, to avoid using external PuSH hubs
  4. *
  5. * @category Feed
  6. * @package GNUsocial
  7. * @author Mikael Nordfeldth <mmn@hethane.se>
  8. * @copyright 2013 Free Software Foundation, Inc.
  9. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  10. * @link http://www.gnu.org/software/social/
  11. */
  12. if (!defined('GNUSOCIAL')) { exit(1); }
  13. class FeedPollerPlugin extends Plugin {
  14. public $interval = 5; // interval in minutes for feed checks
  15. public function onEndInitializeQueueManager(QueueManager $qm)
  16. {
  17. $qm->connect(FeedPoll::QUEUE_CHECK, 'FeedPollQueueHandler');
  18. return true;
  19. }
  20. public function onCronMinutely()
  21. {
  22. $args = array('interval'=>$this->interval);
  23. FeedPoll::enqueueNewFeeds($args);
  24. return true;
  25. }
  26. public function onFeedSubscribe(FeedSub $feedsub)
  27. {
  28. if (!$feedsub->isPuSH()) {
  29. FeedPoll::setupFeedSub($feedsub, $this->interval*60);
  30. return false; // We're polling this feed, so stop processing FeedSubscribe
  31. }
  32. return true;
  33. }
  34. public function onFeedUnsubscribe(FeedSub $feedsub)
  35. {
  36. if (!$feedsub->isPuSH()) {
  37. // removes sub_state setting and such
  38. $feedsub->confirmUnsubscribe();
  39. return false;
  40. }
  41. return true;
  42. }
  43. public function onPluginVersion(&$versions)
  44. {
  45. $versions[] = array('name' => 'FeedPoller',
  46. 'version' => GNUSOCIAL_VERSION,
  47. 'author' => 'Mikael Nordfeldth',
  48. 'homepage' => 'http://www.gnu.org/software/social/',
  49. 'description' =>
  50. // TRANS: Plugin description.
  51. _m('Feed polling plugin to avoid using external push hubs.'));
  52. return true;
  53. }
  54. }