+ /**
+ * @param string $body
+ * @param array $data
+ * @param bool $no_photos
+ * @return string
+ * @throws HTTPException\InternalServerErrorException
+ */
+ public static function appendDataToBody(string $body, array $data, bool $no_photos = false)
+ {
+ // Only one [attachment] tag per body is allowed
+ $existingAttachmentPos = strpos($body, '[attachment');
+ if ($existingAttachmentPos !== false) {
+ $linkTitle = $data['title'] ?: $data['url'];
+ // Additional link attachments are prepended before the existing [attachment] tag
+ $body = substr_replace($body, "\n[bookmark=" . $data['url'] . ']' . $linkTitle . "[/bookmark]\n", $existingAttachmentPos, 0);
+ } else {
+ $footer = self::getFooterFromData($data, $no_photos);
+ $body = self::stripTrailingUrlFromBody($body, $data['url']);
+ $body .= "\n" . $footer;
+ }