]> git.mxchange.org Git - friendica-addons.git/blobdiff - mailstream/mailstream.php
moved HTML stuff into template
[friendica-addons.git] / mailstream / mailstream.php
index 8f99fd9e089f19c4d9f3cda05379b9e759f62ce4..a58dfc1cde33af486096a579e4a20b9c752c3174 100644 (file)
@@ -102,19 +102,28 @@ function mailstream_generate_id($a, $uri) {
 
 function mailstream_post_hook(&$a, &$item) {
        if (!PConfig::get($item['uid'], 'mailstream', 'enabled')) {
+               Logger::debug('mailstream: not enabled for item ' . $item['id']);
                return;
        }
        if (!$item['uid']) {
+               Logger::debug('mailstream: no uid for item ' . $item['id']);
                return;
        }
        if (!$item['contact-id']) {
+               Logger::debug('mailstream: no contact-id for item ' . $item['id']);
                return;
        }
        if (!$item['uri']) {
+               Logger::debug('mailstream: no uri for item ' . $item['id']);
+               return;
+       }
+       if (!$item['plink']) {
+               Logger::debug('mailstream: no plink for item ' . $item['id']);
                return;
        }
        if (PConfig::get($item['uid'], 'mailstream', 'nolikes')) {
                if ($item['verb'] == ACTIVITY_LIKE) {
+                       Logger::debug('mailstream: like item ' . $item['id']);
                        return;
                }
        }
@@ -154,13 +163,18 @@ function mailstream_do_images($a, &$item, &$attachments) {
        $attachments = [];
        preg_match_all("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", $item["body"], $matches1);
        preg_match_all("/\[img\](.*?)\[\/img\]/ism", $item["body"], $matches2);
-       foreach (array_merge($matches1[3], $matches2[1]) as $url) {
+       preg_match_all("/\[img\=([^\]]*)\]([^[]*)\[\/img\]/ism", $item["body"], $matches3);
+       foreach (array_merge($matches1[3], $matches2[1], $matches3[1]) as $url) {
+               $components = parse_url($url);
+               if (!$components) {
+                       continue;
+               }
                $cookiejar = tempnam(get_temppath(), 'cookiejar-mailstream-');
                $curlResult = Network::fetchUrlFull($url, true, 0, '', $cookiejar);
                $attachments[$url] = [
                        'data' => $curlResult->getBody(),
                        'guid' => hash("crc32", $url),
-                       'filename' => basename($url),
+                       'filename' => basename($components['path']),
                        'type' => $curlResult->getContentType()
                ];
 
@@ -289,6 +303,7 @@ function mailstream_send(\Friendica\App $a, $message_id, $item, $user) {
                $mail->IsHTML(true);
                $mail->CharSet = 'utf-8';
                $template = Renderer::getMarkupTemplate('mail.tpl', 'addon/mailstream/');
+               $mail->AltBody = BBCode::toPlaintext($item['body']);
                $item['body'] = BBCode::convert($item['body']);
                $item['url'] = $a->getBaseURL() . '/display/' . $item['guid'];
                $mail->Body = Renderer::replaceMacros($template, [