123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <?php
- defined('GNUSOCIAL') || die();
- define('RSSCLOUDPLUGIN_VERSION', '0.1.0');
- class RSSCloudPlugin extends Plugin
- {
-
- public function __construct()
- {
- parent::__construct();
- }
-
- public function onInitializePlugin(): void
- {
- $this->domain = common_config('rsscloud', 'domain');
- $this->port = common_config('rsscloud', 'port');
- $this->path = common_config('rsscloud', 'path');
- $this->funct = common_config('rsscloud', 'function');
- $this->protocol = common_config('rsscloud', 'protocol');
-
- $local_server = parse_url(common_path('main/rsscloud/request_notify'));
- if (empty($this->domain)) {
- $this->domain = $local_server['host'];
- }
- if (empty($this->port)) {
- $this->port = '80';
- }
- if (empty($this->path)) {
- $this->path = $local_server['path'];
- }
- if (empty($this->funct)) {
- $this->funct = '';
- }
- if (empty($this->protocol)) {
- $this->protocol = 'http-post';
- }
- }
-
- public function onRouterInitialized(URLMapper $m): bool
- {
- $m->connect(
- 'main/rsscloud/request_notify',
- ['action' => 'RSSCloudRequestNotify']
- );
-
-
-
-
-
-
- return true;
- }
-
- public function onStartApiRss(Action $action): void
- {
- if (get_class($action) == 'ApiTimelineUserAction') {
- $attrs = [
- 'domain' => $this->domain,
- 'port' => $this->port,
- 'path' => $this->path,
- 'registerProcedure' => $this->funct,
- 'protocol' => $this->protocol,
- ];
-
- $action->xw->startElement('cloud');
- foreach ($attrs as $name => $value) {
- $action->xw->writeAttribute($name, $value);
- }
- $action->xw->endElement();
- }
- }
-
- public function onStartEnqueueNotice(
- Notice $notice,
- array &$transports
- ): bool {
- if ($notice->isLocal()) {
- array_push($transports, 'rsscloud');
- }
- return true;
- }
-
- public function onCheckSchema(): bool
- {
- $schema = Schema::get();
- $schema->ensureTable(
- 'rsscloud_subscription',
- RSSCloudSubscription::schemaDef()
- );
- return true;
- }
-
- public function onEndInitializeQueueManager(QueueManager $manager): bool
- {
- $manager->connect('rsscloud', 'RSSCloudQueueHandler');
- return true;
- }
-
- public function onUserDeleteRelated(User $user, array &$related): bool
- {
- $sub = new RSSCloudSubscription();
- $sub->subscribed = $user->id;
- if ($sub->find()) {
- while ($sub->fetch()) {
- $sub->delete();
- }
- }
- $sub->free();
- return true;
- }
- public function onPluginVersion(array &$versions): bool
- {
- $versions[] = [
- 'name' => 'RSSCloud',
- 'version' => RSSCLOUDPLUGIN_VERSION,
- 'author' => 'Zach Copley',
- 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/RSSCloud',
- 'rawdescription' =>
-
- _m('The RSSCloud plugin enables your GNU social instance to '
- . 'publish real-time updates for profile RSS feeds using the '
- . '<a href="http://rsscloud.co/">rssCloud protocol</a>.'),
- ];
- return true;
- }
- }
|