Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
floviolleau committed Aug 21, 2023
2 parents 5cf7df5 + 959dd93 commit e0af345
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion bridges/MastodonBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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');
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion bridges/VkBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private function getTitle($content)
{
$content = explode('<br>', $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';
}
Expand Down

0 comments on commit e0af345

Please sign in to comment.