]> git.mxchange.org Git - friendica.git/blobdiff - include/network.php
remove now-unnecessary line in text.php
[friendica.git] / include / network.php
index a95dde535c9fa967156b28806f9c508b9ed1b064..f6e6cc2a30825c189ab77f196f0780b39ac80586 100644 (file)
@@ -15,6 +15,9 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
 
        @curl_setopt($ch, CURLOPT_HEADER, true);
 
+       @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+       @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
+
        if (!is_null($accept_content)){
                curl_setopt($ch,CURLOPT_HTTPHEADER, array (
                        "Accept: " . $accept_content
@@ -99,7 +102,7 @@ if(! function_exists('post_url')) {
 function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) {
        $a = get_app();
        $ch = curl_init($url);
-       if(($redirects > 8) || (! $ch)) 
+       if(($redirects > 8) || (! $ch))
                return false;
 
        curl_setopt($ch, CURLOPT_HEADER, true);
@@ -802,7 +805,7 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
        $s = htmlspecialchars_decode($s);
 
        $matches = null;
-       $c = preg_match_all('/\[img\](.*?)\[\/img\]/ism',$s,$matches,PREG_SET_ORDER);
+       $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism',$s,$matches,PREG_SET_ORDER);
        if($c) {
                require_once('include/Photo.php');
                foreach($matches as $mtch) {
@@ -823,9 +826,13 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
                                $scaled = $mtch[1];
                        $i = fetch_url($scaled);
 
+                       $cachefile = get_cachefile(hash("md5", $scaled));
+                       if ($cachefile != '')
+                               file_put_contents($cachefile, $i);
+
                        // guess mimetype from headers or filename
                        $type = guess_image_type($mtch[1],true);
-                       
+
                        if($i) {
                                $ph = new Photo($i, $type);
                                if($ph->is_valid()) {
@@ -848,6 +855,9 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
                        }
                }
        }
+
+       // replace the special char encoding
+       $s = htmlspecialchars($s,ENT_NOQUOTES,'UTF-8');
        return $s;
 }