+ /**
+ * @brief Adds attachment data to the JSON document
+ *
+ * @param array $item Data of the item that is to be posted
+ * @param text $type Object type
+ *
+ * @return array with attachment data
+ */
+ private static function createAttachmentList($item, $type)
+ {
+ $attachments = [];
+
+ $arr = explode('[/attach],', $item['attach']);
+ if (count($arr)) {
+ foreach ($arr as $r) {
+ $matches = false;
+ $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|', $r, $matches);
+ if ($cnt) {
+ $attributes = ['type' => 'Document',
+ 'mediaType' => $matches[3],
+ 'url' => $matches[1],
+ 'name' => null];
+
+ if (trim($matches[4]) != '') {
+ $attributes['name'] = trim($matches[4]);
+ }
+
+ $attachments[] = $attributes;
+ }
+ }
+ }
+
+ if ($type != 'Note') {
+ return $attachments;
+ }
+
+ // Simplify image codes
+ $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $item['body']);
+
+ // Grab all pictures and create attachments out of them
+ if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures)) {
+ foreach ($pictures[1] as $picture) {
+ $imgdata = Image::getInfoFromURL($picture);
+ if ($imgdata) {
+ $attachments[] = ['type' => 'Document',
+ 'mediaType' => $imgdata['mime'],
+ 'url' => $picture,
+ 'name' => null];
+ }
+ }
+ }
+
+ return $attachments;
+ }
+
+ /**
+ * @brief Remove image elements and replaces them with links to the image
+ *
+ * @param string $body
+ *
+ * @return string with replaced elements
+ */
+ private static function removePictures($body)
+ {
+ // Simplify image codes
+ $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
+
+ $body = preg_replace("/\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]/Usi", '[url]$1[/url]', $body);
+ $body = preg_replace("/\[img\]([^\[\]]*)\[\/img\]/Usi", '[url]$1[/url]', $body);
+
+ return $body;
+ }
+