diff --git a/bridges/MastodonBridge.php b/bridges/MastodonBridge.php index 372838cabfe..855aae08047 100644 --- a/bridges/MastodonBridge.php +++ b/bridges/MastodonBridge.php @@ -35,6 +35,11 @@ class MastodonBridge extends BridgeAbstract 'exampleValue' => '@sebsauvage@framapiaf.org', 'required' => true, ], + 'noregular' => [ + 'name' => 'Without regular statuses', + 'type' => 'checkbox', + 'title' => 'Hide regular statuses (i.e. non-boosts, replies, etc.)', + ], 'norep' => [ 'name' => 'Without replies', 'type' => 'checkbox', @@ -61,6 +66,10 @@ class MastodonBridge extends BridgeAbstract public function collectData() { + if ($this->getInput('norep') && $this->getInput('noboost') && $this->getInput('noregular')) { + throw new \Exception('replies, boosts, or regular statuses must be allowed'); + } + $user = $this->fetchAP($this->getURI()); if (!isset($user['outbox'])) { throw new \Exception('Unable to find the outbox'); @@ -115,6 +124,9 @@ protected function parseItem($content) if ($this->getInput('norep') && isset($content['inReplyTo'])) { return null; } + if ($this->getInput('noregular') && !isset($content['inReplyTo'])) { + return null; + } $item['title'] = ''; $item['author'] = $this->getInput('canusername'); $item = $this->parseObject($content, $item); @@ -123,6 +135,9 @@ protected function parseItem($content) if ($this->getInput('norep') && isset($content['object']['inReplyTo'])) { return null; } + if ($this->getInput('noregular') && !isset($content['object']['inReplyTo'])) { + return null; + } $item['title'] = ''; $item['author'] = $this->getInput('canusername'); $item = $this->parseObject($content['object'], $item); @@ -147,7 +162,7 @@ protected function parseObject($object, $item) if (isset($object['name'])) { $item['title'] = $object['name']; - } else if (mb_strlen($strippedContent) > 75) { + } elseif (mb_strlen($strippedContent) > 75) { $contentSubstring = mb_substr($strippedContent, 0, mb_strpos(wordwrap($strippedContent, 75), "\n")); $item['title'] .= $contentSubstring . '...'; } else { diff --git a/bridges/VkBridge.php b/bridges/VkBridge.php index 8c18f26af25..90b2586e2c1 100644 --- a/bridges/VkBridge.php +++ b/bridges/VkBridge.php @@ -453,7 +453,7 @@ private function getTitle($content) { $content = explode('
', $content)[0]; $content = strip_tags($content); - preg_match('/^[:,"\w\ \p{L}\(\)\?#«»-]+/mu', htmlspecialchars_decode($content), $result); + preg_match('/.+?(?=[\.\n])/mu', htmlspecialchars_decode($content), $result); if (count($result) == 0) { return 'untitled'; }