Code is reformatted
This commit is contained in:
parent
eafe54f2dd
commit
aea3ed4548
6 changed files with 300 additions and 168 deletions
|
@ -223,15 +223,19 @@ class Item
|
|||
|
||||
// select someone by nick in the current network
|
||||
if (!DBA::isResult($contact) && ($network != '')) {
|
||||
$condition = ["`nick` = ? AND `network` = ? AND `uid` = ?",
|
||||
$name, $network, $profile_uid];
|
||||
$condition = [
|
||||
"`nick` = ? AND `network` = ? AND `uid` = ?",
|
||||
$name, $network, $profile_uid
|
||||
];
|
||||
$contact = DBA::selectFirst('contact', $fields, $condition);
|
||||
}
|
||||
|
||||
// select someone by attag in the current network
|
||||
if (!DBA::isResult($contact) && ($network != '')) {
|
||||
$condition = ["`attag` = ? AND `network` = ? AND `uid` = ?",
|
||||
$name, $network, $profile_uid];
|
||||
$condition = [
|
||||
"`attag` = ? AND `network` = ? AND `uid` = ?",
|
||||
$name, $network, $profile_uid
|
||||
];
|
||||
$contact = DBA::selectFirst('contact', $fields, $condition);
|
||||
}
|
||||
|
||||
|
@ -295,8 +299,10 @@ class Item
|
|||
$xmlhead = '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||
|
||||
if ($this->activity->match($item['verb'], Activity::TAG)) {
|
||||
$fields = ['author-id', 'author-link', 'author-name', 'author-network',
|
||||
'verb', 'object-type', 'resource-id', 'body', 'plink'];
|
||||
$fields = [
|
||||
'author-id', 'author-link', 'author-name', 'author-network',
|
||||
'verb', 'object-type', 'resource-id', 'body', 'plink'
|
||||
];
|
||||
$obj = Post::selectFirst($fields, ['uri' => $item['parent-uri']]);
|
||||
if (!DBA::isResult($obj)) {
|
||||
$this->profiler->stopRecording();
|
||||
|
@ -333,7 +339,8 @@ class Item
|
|||
default:
|
||||
if ($obj['resource-id']) {
|
||||
$post_type = $this->l10n->t('photo');
|
||||
$m=[]; preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
|
||||
$m = [];
|
||||
preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
|
||||
$rr['plink'] = $m[1];
|
||||
} else {
|
||||
$post_type = $this->l10n->t('status');
|
||||
|
@ -433,7 +440,8 @@ class Item
|
|||
}
|
||||
|
||||
if ((($cid == 0) || ($rel == Contact::FOLLOWER)) &&
|
||||
in_array($item['network'], Protocol::FEDERATED)) {
|
||||
in_array($item['network'], Protocol::FEDERATED)
|
||||
) {
|
||||
$menu[$this->l10n->t('Connect/Follow')] = 'contact/follow?url=' . urlencode($item['author-link']) . '&auto=1';
|
||||
}
|
||||
} else {
|
||||
|
@ -903,11 +911,17 @@ class Item
|
|||
if ($post['attach']) {
|
||||
$post['attach'] .= ',';
|
||||
}
|
||||
$post['attach'] .= Post\Media::getAttachElement($this->baseURL . '/attach/' . $attachment['id'],
|
||||
$attachment['filesize'], $attachment['filetype'], $attachment['filename'] ?? '');
|
||||
$post['attach'] .= Post\Media::getAttachElement(
|
||||
$this->baseURL . '/attach/' . $attachment['id'],
|
||||
$attachment['filesize'],
|
||||
$attachment['filetype'],
|
||||
$attachment['filename'] ?? ''
|
||||
);
|
||||
|
||||
$fields = ['allow_cid' => $post['allow_cid'], 'allow_gid' => $post['allow_gid'],
|
||||
'deny_cid' => $post['deny_cid'], 'deny_gid' => $post['deny_gid']];
|
||||
$fields = [
|
||||
'allow_cid' => $post['allow_cid'], 'allow_gid' => $post['allow_gid'],
|
||||
'deny_cid' => $post['deny_cid'], 'deny_gid' => $post['deny_gid']
|
||||
];
|
||||
$condition = ['id' => $attachment_id];
|
||||
Attach::update($fields, $condition);
|
||||
}
|
||||
|
@ -926,7 +940,8 @@ class Item
|
|||
// embedded bookmark or attachment in post? set bookmark flag
|
||||
$data = BBCode::getAttachmentData($post['body']);
|
||||
if ((preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $post['body'], $match, PREG_SET_ORDER) || !empty($data['type']))
|
||||
&& ($post['post-type'] != ItemModel::PT_PERSONAL_NOTE)) {
|
||||
&& ($post['post-type'] != ItemModel::PT_PERSONAL_NOTE)
|
||||
) {
|
||||
$post['post-type'] = ItemModel::PT_PAGE;
|
||||
$post['object-type'] = Activity\ObjectType::BOOKMARK;
|
||||
}
|
||||
|
@ -1029,8 +1044,14 @@ class Item
|
|||
continue;
|
||||
}
|
||||
|
||||
$this->emailer->send(new ItemCCEMail($this->app, $this->l10n, $this->baseURL,
|
||||
$post, $address, $author['thumb'] ?? ''));
|
||||
$this->emailer->send(new ItemCCEMail(
|
||||
$this->app,
|
||||
$this->l10n,
|
||||
$this->baseURL,
|
||||
$post,
|
||||
$address,
|
||||
$author['thumb'] ?? ''
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -191,7 +191,8 @@ class BBCode
|
|||
*/
|
||||
public static function replaceAttachment(string $body, bool $no_link_desc = false): string
|
||||
{
|
||||
return preg_replace_callback("/\s*\[attachment (.*?)\](.*?)\[\/attachment\]\s*/ism",
|
||||
return preg_replace_callback(
|
||||
"/\s*\[attachment (.*?)\](.*?)\[\/attachment\]\s*/ism",
|
||||
function ($match) use ($body, $no_link_desc) {
|
||||
$attach_data = self::getAttachmentData($match[0]);
|
||||
if (empty($attach_data['url'])) {
|
||||
|
@ -203,7 +204,9 @@ class BBCode
|
|||
} else {
|
||||
return " \n[url=" . $attach_data['url'] . ']' . $attach_data['title'] . "[/url]\n";
|
||||
}
|
||||
}, $body);
|
||||
},
|
||||
$body
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -708,8 +711,11 @@ class BBCode
|
|||
// We're depending on the property of 'foreach' (specified on the PHP website) that
|
||||
// it loops over the array starting from the first element and going sequentially
|
||||
// to the last element
|
||||
$newbody = str_replace('[$#saved_image' . $cnt . '#$]',
|
||||
'<img src="' . self::proxyUrl($image, self::INTERNAL, $uriid) . '" alt="' . DI::l10n()->t('Image/photo') . '" />', $newbody);
|
||||
$newbody = str_replace(
|
||||
'[$#saved_image' . $cnt . '#$]',
|
||||
'<img src="' . self::proxyUrl($image, self::INTERNAL, $uriid) . '" alt="' . DI::l10n()->t('Image/photo') . '" />',
|
||||
$newbody
|
||||
);
|
||||
$cnt++;
|
||||
}
|
||||
|
||||
|
@ -1252,8 +1258,7 @@ class BBCode
|
|||
* $match[1] = $url
|
||||
* $match[2] = $title or absent
|
||||
*/
|
||||
$try_oembed_callback = function (array $match)
|
||||
{
|
||||
$try_oembed_callback = function (array $match) {
|
||||
$url = $match[1];
|
||||
$title = $match[2] ?? '';
|
||||
|
||||
|
@ -1306,18 +1311,22 @@ class BBCode
|
|||
}
|
||||
|
||||
// Remove linefeeds inside of the table elements. See issue #6799
|
||||
$search = ["\n[th]", "[th]\n", " [th]", "\n[/th]", "[/th]\n", "[/th] ",
|
||||
$search = [
|
||||
"\n[th]", "[th]\n", " [th]", "\n[/th]", "[/th]\n", "[/th] ",
|
||||
"\n[td]", "[td]\n", " [td]", "\n[/td]", "[/td]\n", "[/td] ",
|
||||
"\n[tr]", "[tr]\n", " [tr]", "[tr] ", "\n[/tr]", "[/tr]\n", " [/tr]", "[/tr] ",
|
||||
"\n[hr]", "[hr]\n", " [hr]", "[hr] ",
|
||||
"\n[attachment ", " [attachment ", "\n[/attachment]", "[/attachment]\n", " [/attachment]", "[/attachment] ",
|
||||
"[table]\n", "[table] ", " [table]", "\n[/table]", " [/table]", "[/table] "];
|
||||
$replace = ["[th]", "[th]", "[th]", "[/th]", "[/th]", "[/th]",
|
||||
"[table]\n", "[table] ", " [table]", "\n[/table]", " [/table]", "[/table] "
|
||||
];
|
||||
$replace = [
|
||||
"[th]", "[th]", "[th]", "[/th]", "[/th]", "[/th]",
|
||||
"[td]", "[td]", "[td]", "[/td]", "[/td]", "[/td]",
|
||||
"[tr]", "[tr]", "[tr]", "[tr]", "[/tr]", "[/tr]", "[/tr]", "[/tr]",
|
||||
"[hr]", "[hr]", "[hr]", "[hr]",
|
||||
"[attachment ", "[attachment ", "[/attachment]", "[/attachment]", "[/attachment]", "[/attachment]",
|
||||
"[table]", "[table]", "[table]", "[/table]", "[/table]", "[/table]"];
|
||||
"[table]", "[table]", "[table]", "[/table]", "[/table]", "[/table]"
|
||||
];
|
||||
do {
|
||||
$oldtext = $text;
|
||||
$text = str_replace($search, $replace, $text);
|
||||
|
@ -1333,10 +1342,14 @@ class BBCode
|
|||
|
||||
// removing multiplicated newlines
|
||||
if (DI::config()->get('system', 'remove_multiplicated_lines')) {
|
||||
$search = ["\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[*]", "\n[ul]", "[/ul]\n", "\n\n[share ", "[/attachment]\n",
|
||||
"\n[h1]", "[/h1]\n", "\n[h2]", "[/h2]\n", "\n[h3]", "[/h3]\n", "\n[h4]", "[/h4]\n", "\n[h5]", "[/h5]\n", "\n[h6]", "[/h6]\n"];
|
||||
$replace = ["\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[*]", "[ul]", "[/ul]", "\n[share ", "[/attachment]",
|
||||
"[h1]", "[/h1]", "[h2]", "[/h2]", "[h3]", "[/h3]", "[h4]", "[/h4]", "[h5]", "[/h5]", "[h6]", "[/h6]"];
|
||||
$search = [
|
||||
"\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[*]", "\n[ul]", "[/ul]\n", "\n\n[share ", "[/attachment]\n",
|
||||
"\n[h1]", "[/h1]\n", "\n[h2]", "[/h2]\n", "\n[h3]", "[/h3]\n", "\n[h4]", "[/h4]\n", "\n[h5]", "[/h5]\n", "\n[h6]", "[/h6]\n"
|
||||
];
|
||||
$replace = [
|
||||
"\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[*]", "[ul]", "[/ul]", "\n[share ", "[/attachment]",
|
||||
"[h1]", "[/h1]", "[h2]", "[/h2]", "[h3]", "[/h3]", "[h4]", "[/h4]", "[h5]", "[/h5]", "[h6]", "[/h6]"
|
||||
];
|
||||
do {
|
||||
$oldtext = $text;
|
||||
$text = str_replace($search, $replace, $text);
|
||||
|
@ -1503,9 +1516,11 @@ class BBCode
|
|||
// handle nested quotes
|
||||
$endlessloop = 0;
|
||||
while ((strpos($text, "[/spoiler]") !== false) && (strpos($text, "[spoiler=") !== false) && (++$endlessloop < 20)) {
|
||||
$text = preg_replace("/\[spoiler=[\"\']*(.*?)[\"\']*\](.*?)\[\/spoiler\]/ism",
|
||||
$text = preg_replace(
|
||||
"/\[spoiler=[\"\']*(.*?)[\"\']*\](.*?)\[\/spoiler\]/ism",
|
||||
'<details class="spoiler"><summary>$1</summary>$2</details>',
|
||||
$text);
|
||||
$text
|
||||
);
|
||||
}
|
||||
|
||||
// Declare the format for [quote] layout
|
||||
|
@ -1525,9 +1540,11 @@ class BBCode
|
|||
// handle nested quotes
|
||||
$endlessloop = 0;
|
||||
while ((strpos($text, "[/quote]") !== false) && (strpos($text, "[quote=") !== false) && (++$endlessloop < 20)) {
|
||||
$text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism",
|
||||
$text = preg_replace(
|
||||
"/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism",
|
||||
"<p><strong class=" . '"author"' . ">" . $t_wrote . "</strong></p><blockquote>$2</blockquote>",
|
||||
$text);
|
||||
$text
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1548,13 +1565,15 @@ class BBCode
|
|||
$text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '<img src="$3" style="width: $1px;" >', $text);
|
||||
$text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '<img class="zrl" src="$3" style="width: $1px;" >', $text);
|
||||
|
||||
$text = preg_replace_callback("/\[img\=(.*?)\](.*?)\[\/img\]/ism",
|
||||
$text = preg_replace_callback(
|
||||
"/\[img\=(.*?)\](.*?)\[\/img\]/ism",
|
||||
function ($matches) use ($simple_html, $uriid) {
|
||||
$matches[1] = self::proxyUrl($matches[1], $simple_html, $uriid);
|
||||
$matches[2] = htmlspecialchars($matches[2], ENT_COMPAT);
|
||||
return '<img src="' . $matches[1] . '" alt="' . $matches[2] . '" title="' . $matches[2] . '">';
|
||||
},
|
||||
$text);
|
||||
$text
|
||||
);
|
||||
|
||||
// Images
|
||||
// [img]pathtoimage[/img]
|
||||
|
@ -1585,20 +1604,32 @@ class BBCode
|
|||
|
||||
if ($try_oembed) {
|
||||
// html5 video and audio
|
||||
$text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4).*?)\[\/video\]/ism",
|
||||
'<video src="$1" controls width="100%" height="auto"><a href="$1">$1</a></video>', $text);
|
||||
$text = preg_replace(
|
||||
"/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4).*?)\[\/video\]/ism",
|
||||
'<video src="$1" controls width="100%" height="auto"><a href="$1">$1</a></video>',
|
||||
$text
|
||||
);
|
||||
|
||||
$text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", $try_oembed_callback, $text);
|
||||
$text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", $try_oembed_callback, $text);
|
||||
|
||||
$text = preg_replace("/\[video\](.*?)\[\/video\]/ism",
|
||||
'<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $text);
|
||||
$text = preg_replace(
|
||||
"/\[video\](.*?)\[\/video\]/ism",
|
||||
'<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>',
|
||||
$text
|
||||
);
|
||||
$text = preg_replace("/\[audio\](.*?)\[\/audio\]/ism", '<audio src="$1" controls><a href="$1">$1</a></audio>', $text);
|
||||
} else {
|
||||
$text = preg_replace("/\[video\](.*?)\[\/video\]/ism",
|
||||
'<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $text);
|
||||
$text = preg_replace("/\[audio\](.*?)\[\/audio\]/ism",
|
||||
'<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $text);
|
||||
$text = preg_replace(
|
||||
"/\[video\](.*?)\[\/video\]/ism",
|
||||
'<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>',
|
||||
$text
|
||||
);
|
||||
$text = preg_replace(
|
||||
"/\[audio\](.*?)\[\/audio\]/ism",
|
||||
'<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>',
|
||||
$text
|
||||
);
|
||||
}
|
||||
|
||||
// Backward compatibility, [iframe] support has been removed in version 2020.12
|
||||
|
@ -1620,8 +1651,11 @@ class BBCode
|
|||
if ($try_oembed) {
|
||||
$text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '<iframe width="' . $a->getThemeInfoValue('videowidth') . '" height="' . $a->getThemeInfoValue('videoheight') . '" src="https://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $text);
|
||||
} else {
|
||||
$text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism",
|
||||
'<a href="https://www.youtube.com/watch?v=$1" target="_blank" rel="noopener noreferrer">https://www.youtube.com/watch?v=$1</a>', $text);
|
||||
$text = preg_replace(
|
||||
"/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism",
|
||||
'<a href="https://www.youtube.com/watch?v=$1" target="_blank" rel="noopener noreferrer">https://www.youtube.com/watch?v=$1</a>',
|
||||
$text
|
||||
);
|
||||
}
|
||||
|
||||
if ($try_oembed) {
|
||||
|
@ -1635,8 +1669,11 @@ class BBCode
|
|||
if ($try_oembed) {
|
||||
$text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '<iframe width="' . $a->getThemeInfoValue('videowidth') . '" height="' . $a->getThemeInfoValue('videoheight') . '" src="https://player.vimeo.com/video/$1" frameborder="0" ></iframe>', $text);
|
||||
} else {
|
||||
$text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism",
|
||||
'<a href="https://vimeo.com/$1" target="_blank" rel="noopener noreferrer">https://vimeo.com/$1</a>', $text);
|
||||
$text = preg_replace(
|
||||
"/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism",
|
||||
'<a href="https://vimeo.com/$1" target="_blank" rel="noopener noreferrer">https://vimeo.com/$1</a>',
|
||||
$text
|
||||
);
|
||||
}
|
||||
|
||||
// oembed tag
|
||||
|
@ -1672,27 +1709,39 @@ class BBCode
|
|||
// Handle mentions and hashtag links
|
||||
if ($simple_html == self::DIASPORA) {
|
||||
// The ! is converted to @ since Diaspora only understands the @
|
||||
$text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
$text = preg_replace(
|
||||
"/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
'@<a href="$2">$3</a>',
|
||||
$text);
|
||||
$text
|
||||
);
|
||||
} elseif (in_array($simple_html, [self::OSTATUS, self::ACTIVITYPUB])) {
|
||||
$text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
$text = preg_replace(
|
||||
"/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
'<span class="h-card"><a href="$2" class="u-url mention">$1<span>$3</span></a></span>',
|
||||
$text);
|
||||
$text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
$text
|
||||
);
|
||||
$text = preg_replace(
|
||||
"/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
'<a href="$2" class="mention hashtag" rel="tag">$1<span>$3</span></a>',
|
||||
$text);
|
||||
$text
|
||||
);
|
||||
} elseif (in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::TWITTER_API])) {
|
||||
$text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
$text = preg_replace(
|
||||
"/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
'<bdi>$1<a href="$2" class="userinfo mention" title="$3">$3</a></bdi>',
|
||||
$text);
|
||||
$text
|
||||
);
|
||||
} elseif ($simple_html == self::MASTODON_API) {
|
||||
$text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
$text = preg_replace(
|
||||
"/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
'<a class="u-url mention status-link" href="$2" rel="nofollow noopener noreferrer" target="_blank" title="$3">$1<span>$3</span></a>',
|
||||
$text);
|
||||
$text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
$text
|
||||
);
|
||||
$text = preg_replace(
|
||||
"/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
'<a class="mention hashtag status-link" href="$2" rel="tag">$1<span>$3</span></a>',
|
||||
$text);
|
||||
$text
|
||||
);
|
||||
} else {
|
||||
$text = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $text);
|
||||
}
|
||||
|
@ -1710,8 +1759,11 @@ class BBCode
|
|||
// Bookmarks in red - will be converted to bookmarks in friendica
|
||||
$text = preg_replace("/#\^\[url\](.*?)\[\/url\]/ism", '[bookmark=$1]$1[/bookmark]', $text);
|
||||
$text = preg_replace("/#\^\[url\=(.*?)\](.*?)\[\/url\]/ism", '[bookmark=$1]$2[/bookmark]', $text);
|
||||
$text = preg_replace("/#\[url\=.*?\]\^\[\/url\]\[url\=(.*?)\](.*?)\[\/url\]/i",
|
||||
"[bookmark=$1]$2[/bookmark]", $text);
|
||||
$text = preg_replace(
|
||||
"/#\[url\=.*?\]\^\[\/url\]\[url\=(.*?)\](.*?)\[\/url\]/i",
|
||||
"[bookmark=$1]$2[/bookmark]",
|
||||
$text
|
||||
);
|
||||
|
||||
if (in_array($simple_html, [self::OSTATUS, self::TWITTER])) {
|
||||
$text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", [self::class, 'expandLinksCallback'], $text);
|
||||
|
@ -1731,14 +1783,16 @@ class BBCode
|
|||
"&\[url=/?posts/([^\[\]]*)\](.*)\[\/url\]&Usi",
|
||||
function ($match) {
|
||||
return "[url=" . DI::baseUrl() . "/display/" . $match[1] . "]" . $match[2] . "[/url]";
|
||||
}, $text
|
||||
},
|
||||
$text
|
||||
);
|
||||
|
||||
$text = preg_replace_callback(
|
||||
"&\[url=/people\?q\=(.*)\](.*)\[\/url\]&Usi",
|
||||
function ($match) {
|
||||
return "[url=" . DI::baseUrl() . "/search?search=%40" . $match[1] . "]" . $match[2] . "[/url]";
|
||||
}, $text
|
||||
},
|
||||
$text
|
||||
);
|
||||
|
||||
// Server independent link to posts and comments
|
||||
|
@ -1801,10 +1855,15 @@ class BBCode
|
|||
// sanitizes src attributes (http and redir URLs for displaying in a web page, cid used for inline images in emails)
|
||||
$allowed_src_protocols = ['//', 'http://', 'https://', 'contact/redir/', 'cid:'];
|
||||
|
||||
array_walk($allowed_src_protocols, function(&$value) { $value = preg_quote($value, '#');});
|
||||
array_walk($allowed_src_protocols, function (&$value) {
|
||||
$value = preg_quote($value, '#');
|
||||
});
|
||||
|
||||
$text = preg_replace('#<([^>]*?)(src)="(?!' . implode('|', $allowed_src_protocols) . ')(.*?)"(.*?)>#ism',
|
||||
'<$1$2=""$4 data-original-src="$3" class="invalid-src" title="' . DI::l10n()->t('Invalid source protocol') . '">', $text);
|
||||
$text = preg_replace(
|
||||
'#<([^>]*?)(src)="(?!' . implode('|', $allowed_src_protocols) . ')(.*?)"(.*?)>#ism',
|
||||
'<$1$2=""$4 data-original-src="$3" class="invalid-src" title="' . DI::l10n()->t('Invalid source protocol') . '">',
|
||||
$text
|
||||
);
|
||||
|
||||
// sanitize href attributes (only allowlisted protocols URLs)
|
||||
// default value for backward compatibility
|
||||
|
@ -1816,7 +1875,9 @@ class BBCode
|
|||
$allowed_link_protocols[] = 'https://';
|
||||
$allowed_link_protocols[] = 'contact/redir/';
|
||||
|
||||
array_walk($allowed_link_protocols, function(&$value) { $value = preg_quote($value, '#');});
|
||||
array_walk($allowed_link_protocols, function (&$value) {
|
||||
$value = preg_quote($value, '#');
|
||||
});
|
||||
|
||||
$regex = '#<([^>]*?)(href)="(?!' . implode('|', $allowed_link_protocols) . ')(.*?)"(.*?)>#ism';
|
||||
$text = preg_replace($regex, '<$1$2="javascript:void(0)"$4 data-original-href="$3" class="invalid-href" title="' . DI::l10n()->t('Invalid link protocol') . '">', $text);
|
||||
|
@ -1826,7 +1887,8 @@ class BBCode
|
|||
$text,
|
||||
function (array $attributes, array $author_contact, $content, $is_quote_share) use ($simple_html) {
|
||||
return self::convertShareCallback($attributes, $author_contact, $content, $is_quote_share, $simple_html);
|
||||
}, $uriid
|
||||
},
|
||||
$uriid
|
||||
);
|
||||
|
||||
$text = self::interpolateSavedImagesIntoItemBody($uriid, $text, $saved_image);
|
||||
|
@ -1847,7 +1909,8 @@ class BBCode
|
|||
return $text;
|
||||
}); // Escaped code
|
||||
|
||||
$text = preg_replace_callback("#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#ism",
|
||||
$text = preg_replace_callback(
|
||||
"#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#ism",
|
||||
function ($matches) {
|
||||
if (strpos($matches[2], "\n") !== false) {
|
||||
$return = '<pre><code class="language-' . trim($matches[1]) . '">' . htmlentities(trim($matches[2], "\n\r"), ENT_NOQUOTES, 'UTF-8') . '</code></pre>';
|
||||
|
@ -1977,7 +2040,8 @@ class BBCode
|
|||
* Transform #tags, strip off the [url] and replace spaces with underscore
|
||||
*/
|
||||
$url_search_string = "^\[\]";
|
||||
$text = preg_replace_callback("/#\[url\=([$url_search_string]*)\](.*?)\[\/url\]/i",
|
||||
$text = preg_replace_callback(
|
||||
"/#\[url\=([$url_search_string]*)\](.*?)\[\/url\]/i",
|
||||
function ($matches) {
|
||||
return '#' . str_replace(' ', '_', $matches[2]);
|
||||
},
|
||||
|
@ -2112,7 +2176,8 @@ class BBCode
|
|||
*/
|
||||
public static function expandTags(string $body): string
|
||||
{
|
||||
return preg_replace_callback("/(?<=\W|^)([!#@])([^\^ \x0D\x0A,;:?'\"]*[^\^ \x0D\x0A,;:?!'\".])/",
|
||||
return preg_replace_callback(
|
||||
"/(?<=\W|^)([!#@])([^\^ \x0D\x0A,;:?'\"]*[^\^ \x0D\x0A,;:?!'\".])/",
|
||||
function (array $match) {
|
||||
switch ($match[1]) {
|
||||
case '!':
|
||||
|
@ -2129,7 +2194,9 @@ class BBCode
|
|||
default:
|
||||
return $match[1] . '[url=' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]';
|
||||
}
|
||||
}, $body);
|
||||
},
|
||||
$body
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -122,8 +122,11 @@ class Plaintext
|
|||
$body = preg_replace("/([#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $item['body']);
|
||||
|
||||
// Add an URL element if the text contains a raw link
|
||||
$body = preg_replace('/([^\]\=\'"]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism',
|
||||
'$1[url]$2[/url]', $body);
|
||||
$body = preg_replace(
|
||||
'/([^\]\=\'"]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism',
|
||||
'$1[url]$2[/url]',
|
||||
$body
|
||||
);
|
||||
|
||||
// Remove the abstract
|
||||
$body = BBCode::stripAbstract($body);
|
||||
|
|
|
@ -162,8 +162,10 @@ class Media
|
|||
*/
|
||||
public static function getAttachElement(string $href, int $length, string $type, string $title = ''): string
|
||||
{
|
||||
$media = self::fetchAdditionalData(['type' => self::DOCUMENT, 'url' => $href,
|
||||
'size' => $length, 'mimetype' => $type, 'description' => $title]);
|
||||
$media = self::fetchAdditionalData([
|
||||
'type' => self::DOCUMENT, 'url' => $href,
|
||||
'size' => $length, 'mimetype' => $type, 'description' => $title
|
||||
]);
|
||||
|
||||
return '[attach]href="' . $media['url'] . '" length="' . $media['size'] .
|
||||
'" type="' . $media['mimetype'] . '" title="' . $media['description'] . '"[/attach]';
|
||||
|
@ -263,8 +265,10 @@ class Media
|
|||
return $media;
|
||||
}
|
||||
|
||||
if (!empty($item['plink']) && Strings::compareLink($item['plink'], $media['url']) &&
|
||||
parse_url($item['plink'], PHP_URL_HOST) != parse_url($item['uri'], PHP_URL_HOST)) {
|
||||
if (
|
||||
!empty($item['plink']) && Strings::compareLink($item['plink'], $media['url']) &&
|
||||
parse_url($item['plink'], PHP_URL_HOST) != parse_url($item['uri'], PHP_URL_HOST)
|
||||
) {
|
||||
Logger::debug('Not a link to an activity', ['uri-id' => $media['uri-id'], 'url' => $media['url'], 'plink' => $item['plink'], 'uri' => $item['uri']]);
|
||||
return $media;
|
||||
}
|
||||
|
@ -483,8 +487,10 @@ class Media
|
|||
}
|
||||
$body = str_replace($picture[0], '', $body);
|
||||
$image = str_replace('-1.', '-0.', $picture[2]);
|
||||
$attachments[$image] = ['uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image,
|
||||
'preview' => $picture[2], 'description' => $picture[3]];
|
||||
$attachments[$image] = [
|
||||
'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image,
|
||||
'preview' => $picture[2], 'description' => $picture[3]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -502,8 +508,10 @@ class Media
|
|||
}
|
||||
$body = str_replace($picture[0], '', $body);
|
||||
$image = str_replace('-1.', '-0.', $picture[2]);
|
||||
$attachments[$image] = ['uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image,
|
||||
'preview' => $picture[2], 'description' => null];
|
||||
$attachments[$image] = [
|
||||
'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image,
|
||||
'preview' => $picture[2], 'description' => null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -803,8 +811,10 @@ class Media
|
|||
continue;
|
||||
}
|
||||
|
||||
if (in_array($medium['type'], [self::AUDIO, self::IMAGE]) ||
|
||||
in_array($filetype, ['audio', 'image'])) {
|
||||
if (
|
||||
in_array($medium['type'], [self::AUDIO, self::IMAGE]) ||
|
||||
in_array($filetype, ['audio', 'image'])
|
||||
) {
|
||||
$attachments['visual'][] = $medium;
|
||||
} elseif (($medium['type'] == self::VIDEO) || ($filetype == 'video')) {
|
||||
if (!empty($medium['height'])) {
|
||||
|
|
|
@ -83,14 +83,21 @@ class Diaspora
|
|||
return $contacts;
|
||||
}
|
||||
|
||||
$items = Post::select(['author-id', 'author-link', 'parent-author-link', 'parent-guid', 'guid'],
|
||||
['parent' => $item['parent'], 'gravity' => [Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY]]);
|
||||
$items = Post::select(
|
||||
['author-id', 'author-link', 'parent-author-link', 'parent-guid', 'guid'],
|
||||
['parent' => $item['parent'], 'gravity' => [Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY]]
|
||||
);
|
||||
while ($item = Post::fetch($items)) {
|
||||
$contact = DBA::selectFirst('contact', ['id', 'url', 'name', 'protocol', 'batch', 'network'],
|
||||
['id' => $item['author-id']]);
|
||||
if (!DBA::isResult($contact) || empty($contact['batch']) ||
|
||||
$contact = DBA::selectFirst(
|
||||
'contact',
|
||||
['id', 'url', 'name', 'protocol', 'batch', 'network'],
|
||||
['id' => $item['author-id']]
|
||||
);
|
||||
if (
|
||||
!DBA::isResult($contact) || empty($contact['batch']) ||
|
||||
($contact['network'] != Protocol::DIASPORA) ||
|
||||
Strings::compareLink($item['parent-author-link'], $item['author-link'])) {
|
||||
Strings::compareLink($item['parent-author-link'], $item['author-link'])
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -719,7 +726,8 @@ class Diaspora
|
|||
|
||||
$signed_data .= $entry;
|
||||
}
|
||||
if (!in_array($fieldname, ['parent_author_signature', 'target_author_signature'])
|
||||
if (
|
||||
!in_array($fieldname, ['parent_author_signature', 'target_author_signature'])
|
||||
|| ($orig_type == 'relayable_retraction')
|
||||
) {
|
||||
XML::copy($entry, $fields, $fieldname);
|
||||
|
@ -1185,9 +1193,11 @@ class Diaspora
|
|||
*/
|
||||
private static function parentItem(int $uid, string $guid, WebFingerUri $author, array $contact)
|
||||
{
|
||||
$fields = ['id', 'parent', 'body', 'wall', 'uri', 'guid', 'private', 'origin',
|
||||
$fields = [
|
||||
'id', 'parent', 'body', 'wall', 'uri', 'guid', 'private', 'origin',
|
||||
'author-name', 'author-link', 'author-avatar', 'gravity',
|
||||
'owner-name', 'owner-link', 'owner-avatar'];
|
||||
'owner-name', 'owner-link', 'owner-avatar'
|
||||
];
|
||||
|
||||
$condition = ['uid' => $uid, 'guid' => $guid];
|
||||
$item = Post::selectFirst($fields, $condition);
|
||||
|
@ -1472,7 +1482,6 @@ class Diaspora
|
|||
$contact = DI::dsprContact()->getByUrl(new Uri($match[3]));
|
||||
Tag::storeByHash($uriid, $match[1], $contact->name ?: $contact->nick, $contact->url);
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2013,8 +2022,10 @@ class Diaspora
|
|||
Logger::info('Participation stored', ['id' => $message_id, 'guid' => $guid, 'parent_guid' => $parent_guid, 'author' => $author]);
|
||||
|
||||
// Send all existing comments and likes to the requesting server
|
||||
$comments = Post::select(['id', 'uri-id', 'parent-author-network', 'author-network', 'verb', 'gravity'],
|
||||
['parent' => $toplevel_parent_item['id'], 'gravity' => [Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY]]);
|
||||
$comments = Post::select(
|
||||
['id', 'uri-id', 'parent-author-network', 'author-network', 'verb', 'gravity'],
|
||||
['parent' => $toplevel_parent_item['id'], 'gravity' => [Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY]]
|
||||
);
|
||||
while ($comment = Post::fetch($comments)) {
|
||||
if (($comment['gravity'] == Item::GRAVITY_ACTIVITY) && !in_array($comment['verb'], [Activity::LIKE, Activity::DISLIKE])) {
|
||||
Logger::info('Unsupported activities are not relayed', ['item' => $comment['id'], 'verb' => $comment['verb']]);
|
||||
|
@ -2136,10 +2147,12 @@ class Diaspora
|
|||
$birthday = $contact['bd'];
|
||||
}
|
||||
|
||||
$fields = ['name' => $name, 'location' => $location,
|
||||
$fields = [
|
||||
'name' => $name, 'location' => $location,
|
||||
'name-date' => DateTimeFormat::utcNow(), 'about' => $about,
|
||||
'addr' => $author->getAddr(), 'nick' => $author->getUser(), 'keywords' => $keywords,
|
||||
'unsearchable' => !$searchable, 'sensitive' => $nsfw];
|
||||
'unsearchable' => !$searchable, 'sensitive' => $nsfw
|
||||
];
|
||||
|
||||
if (!empty($birthday)) {
|
||||
$fields['bd'] = $birthday;
|
||||
|
@ -2931,7 +2944,6 @@ class Diaspora
|
|||
$target = DI::dsprContact()->getByAddr(WebFingerUri::fromString($contact['addr']));
|
||||
$dest_url = $public_batch ? $target->batch : $target->notify;
|
||||
} catch (HTTPException\NotFoundException | \InvalidArgumentException $e) {
|
||||
|
||||
}
|
||||
|
||||
if (empty($dest_url)) {
|
||||
|
@ -3012,7 +3024,6 @@ class Diaspora
|
|||
try {
|
||||
$pubkey = DI::dsprContact()->getByAddr(WebFingerUri::fromString($contact['addr']))->pubKey;
|
||||
} catch (HTTPException\NotFoundException | \InvalidArgumentException $e) {
|
||||
|
||||
}
|
||||
} else {
|
||||
// The "addr" field should always be filled.
|
||||
|
@ -3058,8 +3069,10 @@ class Diaspora
|
|||
// If the item belongs to a user, we take this user id.
|
||||
if ($item['uid'] == 0) {
|
||||
// @todo Possibly use an administrator account?
|
||||
$condition = ['verified' => true, 'blocked' => false,
|
||||
'account_removed' => false, 'account_expired' => false, 'account-type' => User::ACCOUNT_TYPE_PERSON];
|
||||
$condition = [
|
||||
'verified' => true, 'blocked' => false,
|
||||
'account_removed' => false, 'account_expired' => false, 'account-type' => User::ACCOUNT_TYPE_PERSON
|
||||
];
|
||||
$first_user = DBA::selectFirst('user', ['uid'], $condition, ['order' => ['uid']]);
|
||||
$owner = User::getOwnerDataById($first_user['uid']);
|
||||
} else {
|
||||
|
@ -3388,9 +3401,11 @@ class Diaspora
|
|||
if (count($event)) {
|
||||
$message['event'] = $event;
|
||||
|
||||
if (!empty($event['location']['address']) &&
|
||||
if (
|
||||
!empty($event['location']['address']) &&
|
||||
!empty($event['location']['lat']) &&
|
||||
!empty($event['location']['lng'])) {
|
||||
!empty($event['location']['lng'])
|
||||
) {
|
||||
$message['location'] = $event['location'];
|
||||
}
|
||||
|
||||
|
@ -3453,7 +3468,8 @@ class Diaspora
|
|||
private static function prependParentAuthorMention(string $body, string $profile_url): string
|
||||
{
|
||||
$profile = Contact::getByURL($profile_url, false, ['addr', 'name']);
|
||||
if (!empty($profile['addr'])
|
||||
if (
|
||||
!empty($profile['addr'])
|
||||
&& !strstr($body, $profile['addr'])
|
||||
&& !strstr($body, $profile_url)
|
||||
) {
|
||||
|
|
|
@ -384,8 +384,10 @@ class Feed
|
|||
}
|
||||
|
||||
if (!$dryRun) {
|
||||
$condition = ["`uid` = ? AND `uri` = ? AND `network` IN (?, ?)",
|
||||
$importer['uid'], $item['uri'], Protocol::FEED, Protocol::DFRN];
|
||||
$condition = [
|
||||
"`uid` = ? AND `uri` = ? AND `network` IN (?, ?)",
|
||||
$importer['uid'], $item['uri'], Protocol::FEED, Protocol::DFRN
|
||||
];
|
||||
$previous = Post::selectFirst(['id', 'created'], $condition);
|
||||
if (DBA::isResult($previous)) {
|
||||
// Use the creation date when the post had been stored. It can happen this date changes in the feed.
|
||||
|
@ -644,8 +646,10 @@ class Feed
|
|||
if (!$notify) {
|
||||
Post\Delayed::publish($item, $notify, $taglist, $attachments);
|
||||
} else {
|
||||
$postings[] = ['item' => $item, 'notify' => $notify,
|
||||
'taglist' => $taglist, 'attachments' => $attachments];
|
||||
$postings[] = [
|
||||
'item' => $item, 'notify' => $notify,
|
||||
'taglist' => $taglist, 'attachments' => $attachments
|
||||
];
|
||||
}
|
||||
} else {
|
||||
Logger::info('Post already created or exists in the delayed posts queue', ['uid' => $item['uid'], 'uri' => $item['uri']]);
|
||||
|
@ -953,11 +957,13 @@ class Feed
|
|||
$check_date = empty($last_update) ? '' : DateTimeFormat::utc($last_update);
|
||||
$authorid = Contact::getIdForURL($owner['url']);
|
||||
|
||||
$condition = ["`uid` = ? AND `received` > ? AND NOT `deleted` AND `gravity` IN (?, ?)
|
||||
$condition = [
|
||||
"`uid` = ? AND `received` > ? AND NOT `deleted` AND `gravity` IN (?, ?)
|
||||
AND `private` != ? AND `visible` AND `wall` AND `parent-network` IN (?, ?, ?, ?)",
|
||||
$owner['uid'], $check_date, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT,
|
||||
Item::PRIVATE, Protocol::ACTIVITYPUB,
|
||||
Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA];
|
||||
Protocol::OSTATUS, Protocol::DFRN, Protocol::DIASPORA
|
||||
];
|
||||
|
||||
if ($filter === 'comments') {
|
||||
$condition[0] .= " AND `gravity` = ? ";
|
||||
|
@ -1130,8 +1136,15 @@ class Feed
|
|||
|
||||
XML::addElement($doc, $entry, 'content', $body, ['type' => 'html']);
|
||||
|
||||
XML::addElement($doc, $entry, 'link', '', ['rel' => 'alternate', 'type' => 'text/html',
|
||||
'href' => DI::baseUrl() . '/display/' . $item['guid']]
|
||||
XML::addElement(
|
||||
$doc,
|
||||
$entry,
|
||||
'link',
|
||||
'',
|
||||
[
|
||||
'rel' => 'alternate', 'type' => 'text/html',
|
||||
'href' => DI::baseUrl() . '/display/' . $item['guid']
|
||||
]
|
||||
);
|
||||
|
||||
XML::addElement($doc, $entry, 'published', DateTimeFormat::utc($item['created'] . '+00:00', DateTimeFormat::ATOM));
|
||||
|
@ -1173,12 +1186,14 @@ class Feed
|
|||
if (isset($parent_plink)) {
|
||||
$attributes = [
|
||||
'ref' => $item['thr-parent'],
|
||||
'href' => $parent_plink];
|
||||
'href' => $parent_plink
|
||||
];
|
||||
XML::addElement($doc, $entry, 'thr:in-reply-to', '', $attributes);
|
||||
|
||||
$attributes = [
|
||||
'rel' => 'related',
|
||||
'href' => $parent_plink];
|
||||
'href' => $parent_plink
|
||||
];
|
||||
XML::addElement($doc, $entry, 'link', '', $attributes);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue