]> git.mxchange.org Git - friendica.git/blobdiff - include/network.php
add fetaure switch for acl-automention
[friendica.git] / include / network.php
index e4d01c00fb46ea1a2cc3064a7da72ff809c3a746..a663a6d94283ad896139315423c250b0c7d17a1a 100644 (file)
@@ -4,8 +4,10 @@
 // curl wrapper. If binary flag is true, return binary
 // results. 
 
+// Set the cookiejar argument to a string (e.g. "/tmp/friendica-cookies.txt")
+// to preserve cookies from one request to the next.
 if(! function_exists('fetch_url')) {
-function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_content=Null) {
+function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_content=Null, $cookiejar = 0) {
 
        $stamp1 = microtime(true);
 
@@ -17,6 +19,10 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
 
        @curl_setopt($ch, CURLOPT_HEADER, true);
 
+       if($cookiejar) {
+               curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
+               curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar);
+       }
 
 //  These settings aren't needed. We're following the location already. 
 //     @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
@@ -93,14 +99,15 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
                        $newurl = trim(array_pop($matches));
                }
                if(strpos($newurl,'/') === 0)
-                       $newurl = $url . $newurl;
+                       $newurl = $old_location_info["scheme"]."://".$old_location_info["host"].$newurl;
                if (filter_var($newurl, FILTER_VALIDATE_URL)) {
                        $redirects++;
-                       return fetch_url($newurl,$binary,$redirects,$timeout);
+                       return fetch_url($newurl,$binary,$redirects,$timeout,$accept_content,$cookiejar);
                }
        }
 
        $a->set_curl_code($http_code);
+       $a->set_curl_content_type($curl_info['content_type']);
 
        $body = substr($s,strlen($header));
        $a->set_curl_headers($header);
@@ -187,7 +194,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
         preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
         $newurl = trim(array_pop($matches));
                if(strpos($newurl,'/') === 0)
-                       $newurl = $url . $newurl;
+                       $newurl = $old_location_info["scheme"] . "://" . $old_location_info["host"] . $newurl;
         if (filter_var($newurl, FILTER_VALIDATE_URL)) {
             $redirects++;
             return fetch_url($newurl,false,$redirects,$timeout);
@@ -542,7 +549,7 @@ function fetch_lrdd_template($host) {
        }
        if(count($links)) {
                foreach($links as $link)
-                       if($link['@attributes']['rel'] && $link['@attributes']['rel'] === 'lrdd')
+                       if($link['@attributes']['rel'] && $link['@attributes']['rel'] === 'lrdd' && (!$link['@attributes']['type'] || $link['@attributes']['type'] === 'application/xrd+xml'))
                                $tpl = $link['@attributes']['template'];
        }
        if(! strpos($tpl,'{uri}'))
@@ -559,7 +566,7 @@ function fetch_xrd_links($url) {
 
        $xrd_timeout = intval(get_config('system','xrd_timeout'));
        $redirects = 0;
-       $xml = fetch_url($url,false,$redirects,(($xrd_timeout) ? $xrd_timeout : 20));
+       $xml = fetch_url($url,false,$redirects,(($xrd_timeout) ? $xrd_timeout : 20), "application/xrd+xml");
 
        logger('fetch_xrd_links: ' . $xml, LOGGER_DATA);
 
@@ -610,7 +617,6 @@ function fetch_xrd_links($url) {
 
 if(! function_exists('validate_url')) {
 function validate_url(&$url) {
-
        // no naked subdomains (allow localhost for tests)
        if(strpos($url,'.') === false && strpos($url,'/localhost/') === false)
                return false;
@@ -776,7 +782,7 @@ function add_fcontact($arr,$update = false) {
                        `alias` = '%s',
                        `pubkey` = '%s',
                        `updated` = '%s'
-                       WHERE `url` = '%s' AND `network` = '%s' LIMIT 1", 
+                       WHERE `url` = '%s' AND `network` = '%s'",
                        dbesc($arr['name']),
                        dbesc($arr['photo']),
                        dbesc($arr['request']),
@@ -818,12 +824,12 @@ function add_fcontact($arr,$update = false) {
 }
 
 
-function scale_external_images($s, $include_link = true, $scale_replace = false) {
+function scale_external_images($srctext, $include_link = true, $scale_replace = false) {
 
        $a = get_app();
 
        // Picture addresses can contain special characters
-       $s = htmlspecialchars_decode($s);
+       $s = htmlspecialchars_decode($srctext);
 
        $matches = null;
        $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism',$s,$matches,PREG_SET_ORDER);
@@ -845,7 +851,9 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
                                $scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[1]);
                        else
                                $scaled = $mtch[1];
-                       $i = fetch_url($scaled);
+                       $i = @fetch_url($scaled);
+                       if(! $i)
+                               return $srctext;
 
                        $cachefile = get_cachefile(hash("md5", $scaled));
                        if ($cachefile != '') {