aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2012-12-26 16:51:18 -0800
committerfriendica <info@friendica.com>2012-12-26 16:51:18 -0800
commit7a257a66c3e10870dd263209149c9ea42169c7d4 (patch)
tree313b8ccfff528e837abdd8d155b7bf0a96206782
parenta162b204375dd8d4b5a86fc36a4e9f2305c3115a (diff)
parent91dac0f18a10d04bd2fcce935612999966c098a0 (diff)
downloadvolse-hubzilla-7a257a66c3e10870dd263209149c9ea42169c7d4.tar.gz
volse-hubzilla-7a257a66c3e10870dd263209149c9ea42169c7d4.tar.bz2
volse-hubzilla-7a257a66c3e10870dd263209149c9ea42169c7d4.zip
Merge https://github.com/friendica/red into zpull
-rw-r--r--include/network.php54
-rw-r--r--mod/magic.php2
2 files changed, 34 insertions, 22 deletions
diff --git a/include/network.php b/include/network.php
index 333e0e83f..321eb375f 100644
--- a/include/network.php
+++ b/include/network.php
@@ -72,7 +72,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
$base = substr($base,strlen($chunk));
}
- if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) {
+ if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) {
$matches = array();
preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
$newurl = trim(array_pop($matches));
@@ -81,6 +81,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
$url_parsed = @parse_url($newurl);
if (isset($url_parsed)) {
$redirects++;
+ @curl_close($ch);
return fetch_url($newurl,$binary,$redirects,$timeout);
}
}
@@ -161,18 +162,23 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
$base = substr($base,strlen($chunk));
}
- if($http_code == 301 || $http_code == 302 || $http_code == 303) {
- $matches = array();
- preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
- $newurl = trim(array_pop($matches));
+ if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) {
+ $matches = array();
+ preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
+ $newurl = trim(array_pop($matches));
if(strpos($newurl,'/') === 0)
$newurl = $url . $newurl;
- $url_parsed = @parse_url($newurl);
- if (isset($url_parsed)) {
- $redirects++;
- return fetch_url($newurl,false,$redirects,$timeout);
- }
- }
+ $url_parsed = @parse_url($newurl);
+ if (isset($url_parsed)) {
+ $redirects++;
+ @curl_close($ch);
+ if($http_code == 303) {
+ return fetch_url($newurl,false,$redirects,$timeout);
+ } else {
+ return post_url($newurl,$params,$redirects,$timeout);
+ }
+ }
+ }
$a->set_curl_code($http_code);
$body = substr($s,strlen($header));
@@ -247,7 +253,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accep
$base = substr($base,strlen($chunk));
}
- if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) {
+ if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) {
$matches = array();
preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
$newurl = trim(array_pop($matches));
@@ -339,19 +345,23 @@ function z_post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0
$base = substr($base,strlen($chunk));
}
- if($http_code == 301 || $http_code == 302 || $http_code == 303) {
- $matches = array();
- preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
- $newurl = trim(array_pop($matches));
+ if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) {
+ $matches = array();
+ preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
+ $newurl = trim(array_pop($matches));
if(strpos($newurl,'/') === 0)
$newurl = $url . $newurl;
- $url_parsed = @parse_url($newurl);
- if (isset($url_parsed)) {
- $redirects++;
+ $url_parsed = @parse_url($newurl);
+ if (isset($url_parsed)) {
+ $redirects++;
curl_close($ch);
- return z_post_url($newurl,$params,$headers,$redirects,$timeout);
- }
- }
+ if($http_code == 303) {
+ return z_fetch_url($newurl,false,$headers,$redirects,$timeout);
+ } else {
+ return z_post_url($newurl,$params,$headers,$redirects,$timeout);
+ }
+ }
+ }
$rc = intval($http_code);
$ret['return_code'] = $rc;
$ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false);
diff --git a/mod/magic.php b/mod/magic.php
index b48e2b8c9..b74130005 100644
--- a/mod/magic.php
+++ b/mod/magic.php
@@ -1,5 +1,7 @@
<?php
+@require_once('include/zot.php');
+
function magic_init(&$a) {
$url = ((x($_REQUEST,'url')) ? $_REQUEST['url'] : '');