]> git.mxchange.org Git - friendica.git/blobdiff - include/network.php
Removed many "limit 1" at update and delete queries since they were superflous und...
[friendica.git] / include / network.php
index d2732e0393796f9bd9abe80b22bfae347b5ec6c8..3bf2626424ca546f1f3dd65fe060716709f6bb7a 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,10 +99,10 @@ 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);
                }
        }
 
@@ -188,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);
@@ -777,7 +783,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']),