X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FBookmark%2FBookmarkPlugin.php;h=319366c19bae017ce8b427cae98d0f63a7904630;hb=7a9777df053a9007b5eaa71f5437584065b615a5;hp=3166b9ee30c6a7d0868499fb9b379f6b2f1b74d7;hpb=25a037ba9cea2cad9b1e6bd26b192e7c8943e6f8;p=quix0rs-gnu-social.git diff --git a/plugins/Bookmark/BookmarkPlugin.php b/plugins/Bookmark/BookmarkPlugin.php index 3166b9ee30..319366c19b 100644 --- a/plugins/Bookmark/BookmarkPlugin.php +++ b/plugins/Bookmark/BookmarkPlugin.php @@ -159,6 +159,7 @@ class BookmarkPlugin extends MicroAppPlugin case 'Bookmark': include_once $dir.'/'.$cls.'.php'; return false; + case 'BookmarkListItem': case 'BookmarkForm': case 'InitialBookmarkForm': case 'DeliciousBackupImporter': @@ -291,19 +292,27 @@ class BookmarkPlugin extends MicroAppPlugin function onStartOpenNoticeListItemElement($nli) { + if (!$this->isMyNotice($nli->notice)) { + return true; + } + $nb = Bookmark::getByNotice($nli->notice); - if (!empty($nb)) { - $id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id; - $class = 'hentry notice bookmark'; - if ($nli->notice->scope != 0 && $nli->notice->scope != 1) { - $class .= ' limited-scope'; - } - $nli->out->elementStart('li', array('class' => $class, - 'id' => 'notice-' . $id)); - Event::handle('EndOpenNoticeListItemElement', array($nli)); - return false; + + if (empty($nb)) { + $this->log(LOG_INFO, "Notice {$nli->notice->id} has bookmark class but no matching Bookmark record."); + return true; } - return true; + + $id = (empty($nli->repeat)) ? $nli->notice->id : $nli->repeat->id; + $class = 'hentry notice bookmark'; + if ($nli->notice->scope != 0 && $nli->notice->scope != 1) { + $class .= ' limited-scope'; + } + $nli->out->elementStart('li', array('class' => $class, + 'id' => 'notice-' . $id)); + + Event::handle('EndOpenNoticeListItemElement', array($nli)); + return false; } /** @@ -321,7 +330,7 @@ class BookmarkPlugin extends MicroAppPlugin $options = array('uri' => $bookmark->id, 'url' => $bookmark->link, - 'is_local' => Notice::REMOTE_OMB, + 'is_local' => Notice::REMOTE, 'source' => 'ostatus'); return self::_postBookmark($author->localProfile(), $activity, $options); @@ -354,12 +363,15 @@ class BookmarkPlugin extends MicroAppPlugin */ function deleteRelated($notice) { - $nb = Bookmark::getByNotice($notice); - - if (!empty($nb)) { - $nb->delete(); - } - + if ($this->isMyNotice($notice)) { + + $nb = Bookmark::getByNotice($notice); + + if (!empty($nb)) { + $nb->delete(); + } + } + return true; } @@ -521,7 +533,7 @@ class BookmarkPlugin extends MicroAppPlugin */ function adaptNoticeListItem($nli) { - return new BookmarkNoticeListItemAdapter($nli); + return new BookmarkListItem($nli); } function entryForm($out) @@ -539,4 +551,41 @@ class BookmarkPlugin extends MicroAppPlugin // TRANS: Application title. return _m('TITLE','Bookmark'); } + + function onEndUpgrade() + { + // Version 0.9.x of the plugin didn't stamp notices + // with verb and object-type (for obvious reasons). Update + // those notices here. + + $notice = new Notice(); + + $notice->whereAdd('exists (select uri from bookmark where bookmark.uri = notice.uri)'); + $notice->whereAdd('((object_type is null) or (object_type = "' .ActivityObject::NOTE.'"))'); + + $notice->find(); + + while ($notice->fetch()) { + $original = clone($notice); + $notice->verb = ActivityVerb::POST; + $notice->object_type = ActivityObject::BOOKMARK; + $notice->update($original); + } + } + + public function activityObjectOutputJson(ActivityObject $obj, array &$out) + { + assert($obj->type == ActivityObject::BOOKMARK); + + $bm = Bookmark::staticGet('uri', $obj->id); + + if (empty($bm)) { + throw new ServerException("Unknown bookmark: " . $obj->id); + } + + $out['displayName'] = $bm->title; + $out['targetUrl'] = $bm->url; + + return true; + } }