Exemple #1
0
 function registerEventHooks()
 {
     parent::registerEventHooks();
     Idno::site()->addEventHook('plugins/loaded', function (Event $evt) {
         // make sure our content types are before IdnoPlugins\Like\ContentType
         $bookmarkType = '\\IdnoPlugins\\Like\\ContentType';
         if (class_exists($bookmarkType)) {
             $bookmarkIndex = -1;
             for ($ii = 0; $ii < count(ContentType::$registered); $ii++) {
                 $contentType = ContentType::$registered[$ii];
                 if ($contentType instanceof $bookmarkType) {
                     $bookmarkIndex = $ii;
                     break;
                 }
             }
             if ($bookmarkIndex > -1) {
                 foreach (['LikeContentType', 'RepostContentType'] as $targetType) {
                     $targetType = $this->getNamespace() . '\\' . $targetType;
                     for ($ii = 0; $ii < count(ContentType::$registered); $ii++) {
                         $contentType = ContentType::$registered[$ii];
                         if ($contentType instanceof $targetType) {
                             array_splice(ContentType::$registered, $ii, 1);
                             array_splice(ContentType::$registered, $bookmarkIndex, 0, [$contentType]);
                             $bookmarkIndex++;
                             break;
                         }
                     }
                 }
             }
         }
     });
     Idno::site()->addEventHook('share/types', function (Event $evt) {
         $types = $evt->data()['types'];
         $newTypes = ['like' => 'Like', 'repost' => 'Repost'];
         $evt->setResponse(array_merge($types, $newTypes));
     });
 }
Exemple #2
0
 function registerEventHooks()
 {
     parent::registerEventHooks();
     Idno::site()->syndication()->registerService('indiesyndicate', function () {
         return true;
     }, ['note', 'article', 'image', 'like', 'share']);
     Idno::site()->addEventHook('user/auth/success', function (Event $event) {
         $is = (array) Idno::site()->session()->currentUser()->indiesyndicate;
         foreach ($is as $url => $details) {
             Idno::site()->syndication()->registerServiceAccount('indiesyndicate', $url, $details['name'], $details);
         }
     });
     Idno::site()->addEventHook('post/note/indiesyndicate', function (Event $event) {
         $eventdata = $event->data();
         $sa = $eventdata['syndication_account'];
         $object = $eventdata['object'];
         if ($this->doWebmention($sa, $object)) {
             return;
         }
         $details = $this->getAccountDetails($sa);
         $style = isset($details['style']) ? $details['style'] : 'default';
         $params = ['h' => 'entry', 'content' => $object->body, 'url' => $object->getSyndicationURL()];
         if (is_array($object->inreplyto) && !empty($object->inreplyto)) {
             $params['in-reply-to'] = $object->inreplyto[0];
         }
         $this->doMicropub($sa, $object, $params);
     });
     Idno::site()->addEventHook('post/image/indiesyndicate', function (Event $event) {
         $eventdata = $event->data();
         $sa = $eventdata['syndication_account'];
         $object = $eventdata['object'];
         if ($this->doWebmention($sa, $object)) {
             return;
         }
         $details = $this->getAccountDetails($sa);
         $style = isset($details['style']) ? $details['style'] : 'default';
         if ($style === 'microblog') {
             // combine name and content for twitter
             $content = '';
             if ($object->title) {
                 $content .= strip_tags($object->title);
             }
             if ($object->body) {
                 if (!empty($content)) {
                     $content .= "\n";
                 }
                 $content .= trim(strip_tags($object->body));
             }
             $params = ['h' => 'entry', 'content' => $content, 'url' => $object->getSyndicationURL()];
         } else {
             $params = ['h' => 'entry', 'name' => $object->title ? strip_tags($object->title) : '', 'content' => $object->body ? strip_tags($object->body) : '', 'url' => $object->getSyndicationURL()];
         }
         foreach ($object->getAttachments() as $attachment) {
             if ($file = \Idno\Entities\File::getByID($attachment['_id'])) {
                 $photofile = tempnam(sys_get_temp_dir(), 'indiesyndicate_photo');
                 $file->write($photofile);
                 $params['photo'] = '@' . $photofile;
                 break;
             }
         }
         $this->doMicropub($sa, $object, $params);
         if (isset($photofile)) {
             unlink($photofile);
         }
     });
     Idno::site()->addEventHook('post/article/indiesyndicate', function (Event $event) {
         $eventdata = $event->data();
         $sa = $eventdata['syndication_account'];
         $object = $eventdata['object'];
         if ($this->doWebmention($sa, $object)) {
             return;
         }
         $details = $this->getAccountDetails($sa);
         $style = isset($details['style']) ? $details['style'] : 'default';
         if ($style === 'microblog') {
             $params = ['h' => 'entry', 'content' => strip_tags($object->title) . ': ' . $object->getSyndicationURL(), 'url' => $object->getSyndicationURL()];
         } else {
             $params = ['h' => 'entry', 'name' => strip_tags($object->title), 'content' => strip_tags($object->body), 'url' => $object->getSyndicationURL()];
         }
         $this->doMicropub($sa, $object, $params);
     });
     Idno::site()->addEventHook('post/like/indiesyndicate', function (Event $event) {
         $eventdata = $event->data();
         $sa = $eventdata['syndication_account'];
         $object = $eventdata['object'];
         if ($this->doWebmention($sa, $object)) {
             return;
         }
         $details = $this->getAccountDetails($sa);
         $style = isset($details['style']) ? $details['style'] : 'default';
         $params = ['h' => 'entry', 'like-of' => $object->likeof, 'url' => $object->getSyndicationURL()];
         $this->doMicropub($sa, $object, $params);
     });
     Idno::site()->addEventHook('post/repost/indiesyndicate', function (Event $event) {
         $eventdata = $event->data();
         $sa = $eventdata['syndication_account'];
         $object = $eventdata['object'];
         if ($this->doWebmention($sa, $object)) {
             return;
         }
         $details = $this->getAccountDetails($sa);
         $style = isset($details['style']) ? $details['style'] : 'default';
         $params = ['h' => 'entry', 'repost-of' => $object->repostof, 'url' => $object->getSyndicationURL()];
         $this->doMicropub($sa, $object, $params);
     });
 }