X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FActivityPub%2FProcessor.php;h=9b6dd4d1a6c1a91af4e798f6100c355ae625d967;hb=5ec1891e0abc5ad4d1cecb1627af8e68ba6d1df8;hp=cde70c0d7cf504576ba91a23ddc71746ad7d393b;hpb=4829c240e9fde18fa1c61113adac716f970e66da;p=friendica.git diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index cde70c0d7c..9b6dd4d1a6 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -27,6 +27,7 @@ use Friendica\Content\Text\Markdown; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; +use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\APContact; @@ -46,6 +47,7 @@ use Friendica\Protocol\Relay; use Friendica\Util\DateTimeFormat; use Friendica\Util\JsonLD; use Friendica\Util\Strings; +use Friendica\Worker\Delivery; /** * ActivityPub Processor Protocol class @@ -480,8 +482,8 @@ class Processor /** * Fetch the Uri-Id of a post for the "featured" collection * - * @param array $activity - * @return null|int + * @param array $activity + * @return null|int */ private static function getUriIdForFeaturedCollection(array $activity) { @@ -519,7 +521,7 @@ class Processor /** * Add a post to the "Featured" collection * - * @param array $activity + * @param array $activity */ public static function addToFeaturedCollection(array $activity) { @@ -536,7 +538,7 @@ class Processor /** * Remove a post to the "Featured" collection * - * @param array $activity + * @param array $activity */ public static function removeFromFeaturedCollection(array $activity) { @@ -606,7 +608,7 @@ class Processor private static function processContent($activity, $item) { if (!empty($activity['mediatype']) && ($activity['mediatype'] == 'text/markdown')) { - $item['title'] = Markdown::toBBCode($activity['name']); + $item['title'] = strip_tags($activity['name']); $content = Markdown::toBBCode($activity['content']); } elseif (!empty($activity['mediatype']) && ($activity['mediatype'] == 'text/bbcode')) { $item['title'] = $activity['name']; @@ -617,6 +619,8 @@ class Processor $content = HTML::toBBCode($activity['content']); } + $item['title'] = trim(BBCode::toPlaintext($item['title'])); + if (!empty($activity['languages'])) { $item['language'] = self::processLanguages($activity['languages']); } @@ -1025,8 +1029,8 @@ class Processor /** * Fetch featured posts from a contact with the given url * - * @param string $url - * @return void + * @param string $url + * @return void */ public static function fetchFeaturedPosts(string $url) { @@ -1277,6 +1281,10 @@ class Processor return; } + if ($result && DI::config()->get('system', 'transmit_pending_events') && ($owner['contact-type'] == Contact::TYPE_COMMUNITY)) { + self::transmitPendingEvents($cid, $owner['uid']); + } + if (empty($contact)) { Contact::update(['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]); } @@ -1284,6 +1292,33 @@ class Processor Logger::notice('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']); } + /** + * Transmit pending events to the new follower + * + * @param integer $cid + * @param integer $uid + * @return void + */ + private static function transmitPendingEvents(int $cid, int $uid) + { + $account = DBA::selectFirst('account-user-view', ['ap-inbox', 'ap-sharedinbox'], ['id' => $cid]); + $inbox = $account['ap-sharedinbox'] ?: $account['ap-inbox']; + + $events = DBA::select('event', ['id'], ["`uid` = ? AND `start` > ? AND `type` != ?", $uid, DateTimeFormat::utcNow(), 'birthday']); + while ($event = DBA::fetch($events)) { + $post = Post::selectFirst(['id', 'uri-id', 'created'], ['event-id' => $event['id']]); + if (empty($post)) { + continue; + } + if (DI::config()->get('system', 'bulk_delivery')) { + Post\Delivery::add($post['uri-id'], $uid, $inbox, $post['created'], Delivery::POST, [$cid]); + Worker::add(PRIORITY_HIGH, 'APDelivery', '', 0, $inbox, 0); + } else { + Worker::add(PRIORITY_HIGH, 'APDelivery', Delivery::POST, $post['id'], $inbox, $uid, [$cid], $post['uri-id']); + } + } + } + /** * Update the given profile * @@ -1342,7 +1377,7 @@ class Processor $uid = User::getIdForURL($activity['object_id']); if (empty($uid)) { - return; + return; } Contact\User::setIsBlocked($cid, $uid, true); @@ -1365,7 +1400,7 @@ class Processor $uid = User::getIdForURL($activity['object_object']); if (empty($uid)) { - return; + return; } Contact\User::setIsBlocked($cid, $uid, false);