FeedPollerPlugin.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * GNU social feed polling plugin, to avoid using external WebSub 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. const PLUGIN_VERSION = '2.0.0';
  15. public $interval = 5; // interval in minutes for feed checks
  16. public function onEndInitializeQueueManager(QueueManager $qm)
  17. {
  18. $qm->connect(FeedPoll::QUEUE_CHECK, 'FeedPollQueueHandler');
  19. return true;
  20. }
  21. public function onCronMinutely()
  22. {
  23. $args = array('interval'=>$this->interval);
  24. FeedPoll::enqueueNewFeeds($args);
  25. return true;
  26. }
  27. public function onFeedSubscribe(FeedSub $feedsub)
  28. {
  29. if (!$feedsub->isWebSub()) {
  30. FeedPoll::setupFeedSub($feedsub, $this->interval*60);
  31. return false; // We're polling this feed, so stop processing FeedSubscribe
  32. }
  33. return true;
  34. }
  35. public function onFeedUnsubscribe(FeedSub $feedsub)
  36. {
  37. if (!$feedsub->isWebSub()) {
  38. // removes sub_state setting and such
  39. $feedsub->confirmUnsubscribe();
  40. return false;
  41. }
  42. return true;
  43. }
  44. public function onPluginVersion(array &$versions): bool
  45. {
  46. $versions[] = array('name' => 'FeedPoller',
  47. 'version' => self::PLUGIN_VERSION,
  48. 'author' => 'Mikael Nordfeldth',
  49. 'homepage' => GNUSOCIAL_ENGINE_URL,
  50. 'description' =>
  51. // TRANS: Plugin description.
  52. _m('Feed polling plugin to avoid using external push hubs.'));
  53. return true;
  54. }
  55. }