]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post/Link.php
Merge pull request #10619 from nupplaphil/task/guzzlehttp
[friendica.git] / src / Model / Post / Link.php
index 3bd92bfe346f230b73b29b47e60dfcee8c3ed2a5..edd3411624802a7495f92c218f8f2f297e2b4138 100644 (file)
@@ -22,6 +22,8 @@
 namespace Friendica\Model\Post;
 
 use Friendica\Core\Logger;
+use Friendica\Core\System;
+use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Util\Proxy;
@@ -40,7 +42,7 @@ class Link
                }
 
                if (!in_array(parse_url($url, PHP_URL_SCHEME), ['http', 'https'])) {
-                       Logger::info('Bad URL, quitting', ['uri-id' => $uri_id, 'url' => $url]);
+                       Logger::info('Bad URL, quitting', ['uri-id' => $uri_id, 'url' => $url, 'callstack' => System::callstack(20)]);
                        return $url;
                }
 
@@ -51,7 +53,7 @@ class Link
                } else {
                        $mime = self::fetchMimeType($url);
 
-                       DBA::insert('post-link', ['uri-id' => $uri_id, 'url' => $url, 'mimetype' => $mime]);
+                       DBA::insert('post-link', ['uri-id' => $uri_id, 'url' => $url, 'mimetype' => $mime], Database::INSERT_IGNORE);
                        $id = DBA::lastInsertId();
                        Logger::info('Inserted', ['id' => $id, 'uri-id' => $uri_id, 'url' => $url]);
                }
@@ -88,7 +90,7 @@ class Link
                $curlResult = DI::httpRequest()->head($url, ['timeout' => $timeout]);
                if ($curlResult->isSuccess()) {
                        if (empty($media['mimetype'])) {
-                               return $curlResult->getHeader('Content-Type');
+                               return $curlResult->getHeader('Content-Type')[0] ?? '';
                        }
                }
                return '';
@@ -103,19 +105,19 @@ class Link
         */
        public static function insertFromBody(int $uriid, string $body)
        {
-               if (preg_match_all("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", $body, $pictures, PREG_SET_ORDER)) {
+               if (preg_match_all("/\[img\=([0-9]*)x([0-9]*)\](http.*?)\[\/img\]/ism", $body, $pictures, PREG_SET_ORDER)) {
                        foreach ($pictures as $picture) {
                                $body = str_replace($picture[3], self::getByLink($uriid, $picture[3]), $body);
                        }
                }
 
-               if (preg_match_all("/\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) {
+               if (preg_match_all("/\[img=(http[^\[\]]*)\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) {
                        foreach ($pictures as $picture) {
                                $body = str_replace($picture[1], self::getByLink($uriid, $picture[1]), $body);
                        }
                }
 
-               if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]/ism", $body, $pictures, PREG_SET_ORDER)) {
+               if (preg_match_all("/\[img\](http[^\[\]]*)\[\/img\]/ism", $body, $pictures, PREG_SET_ORDER)) {
                        foreach ($pictures as $picture) {
                                $body = str_replace($picture[1], self::getByLink($uriid, $picture[1]), $body);
                        }