]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post/Link.php
Just look at HTTP links
[friendica.git] / src / Model / Post / Link.php
index 0a593ddee8797078fd2b85e39330e5b34ee0eaaf..7cce4e206ba6f1402f9b92d7bb4b1db2f40f6360 100644 (file)
@@ -39,16 +39,21 @@ class Link
                        return $url;
                }
 
+               if (!in_array(parse_url($url, PHP_URL_SCHEME), ['http', 'https'])) {
+                       Logger::info('Bad URL, quitting', ['uri-id' => $uri_id, 'url' => $url]);
+                       return $url;
+               }
+
                $link = DBA::selectFirst('post-link', ['id'], ['uri-id' => $uri_id, 'url' => $url]);
                if (!empty($link['id'])) {
                        $id = $link['id'];
-                       Logger::info('Found', ['id' => $id, 'url' => $url]);
+                       Logger::info('Found', ['id' => $id, 'uri-id' => $uri_id, 'url' => $url]);
                } else {
                        $mime = self::fetchMimeType($url);
 
                        DBA::insert('post-link', ['uri-id' => $uri_id, 'url' => $url, 'mimetype' => $mime]);
                        $id = DBA::lastInsertId();
-                       Logger::info('Inserted', ['id' => $id, 'url' => $url]);
+                       Logger::info('Inserted', ['id' => $id, 'uri-id' => $uri_id, 'url' => $url]);
                }
 
                if (empty($id)) {
@@ -98,21 +103,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) {
-                               if (parse_url($picture[1], PHP_URL_SCHEME)) {
-                                       $body = str_replace($picture[1], self::getByLink($uriid, $picture[1]), $body);
-                               }
+                               $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);
                        }