From 6caca4946bf4593e4c6d254e871d2783286eeb37 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sun, 25 Mar 2018 14:01:35 +0200 Subject: [PATCH] bridges: Fix bridges with custom headers and options This commit fixes bridges which called getContents, getSimpleHTMLDOM or getSimpleHTMLDOMCached with custom settings. --- bridges/Arte7Bridge.php | 8 +++----- bridges/FacebookBridge.php | 36 +++++++++++------------------------- bridges/VkBridge.php | 14 ++------------ bridges/YoutubeBridge.php | 4 ++-- 4 files changed, 18 insertions(+), 44 deletions(-) diff --git a/bridges/Arte7Bridge.php b/bridges/Arte7Bridge.php index 1162d174..16952dc3 100644 --- a/bridges/Arte7Bridge.php +++ b/bridges/Arte7Bridge.php @@ -64,13 +64,11 @@ class Arte7Bridge extends BridgeAbstract { . $lang . ($category != null ? '&category.code=' . $category : ''); - $context = array( - 'http' => array( - 'header' => 'Authorization: Bearer '. self::API_TOKEN - ) + $header = array( + 'Authorization: Bearer ' . self::API_TOKEN ); - $input = getContents($url, false, stream_context_create($context)) or die('Could not request ARTE.'); + $input = getContents($url, $header) or die('Could not request ARTE.'); $input_json = json_decode($input, true); foreach($input_json['videos'] as $element) { diff --git a/bridges/FacebookBridge.php b/bridges/FacebookBridge.php index b0b43249..7d6b2494 100644 --- a/bridges/FacebookBridge.php +++ b/bridges/FacebookBridge.php @@ -96,17 +96,15 @@ class FacebookBridge extends BridgeAbstract { $captcha_action = $_SESSION['captcha_action']; $captcha_fields = $_SESSION['captcha_fields']; $captcha_fields['captcha_response'] = preg_replace("/[^a-zA-Z0-9]+/", "", $_POST['captcha_response']); - $http_options = array( - 'http' => array( - 'method' => 'POST', - 'user_agent' => ini_get('user_agent'), - 'header' => array("Content-type: - application/x-www-form-urlencoded\r\nReferer: $captcha_action\r\nCookie: noscript=1\r\n"), - 'content' => http_build_query($captcha_fields) - ), + + $header = array("Content-type: +application/x-www-form-urlencoded\r\nReferer: $captcha_action\r\nCookie: noscript=1\r\n"); + $opts = array( + CURLOPT_POST => 1, + CURLOPT_POSTFIELDS => http_build_query($captcha_fields) ); - $context = stream_context_create($http_options); - $html = getContents($captcha_action, false, $context); + + $html = getContents($captcha_action, $header, $opts); if($html === false) { returnServerError('Failed to submit captcha response back to Facebook'); @@ -120,15 +118,7 @@ class FacebookBridge extends BridgeAbstract { //Retrieve page contents if(is_null($html)) { - $http_options = array( - 'http' => array( - 'method' => 'GET', - 'user_agent' => ini_get('user_agent'), - 'header' => 'Accept-Language: ' . getEnv('HTTP_ACCEPT_LANGUAGE') . "\r\n" - ) - ); - - $context = stream_context_create($http_options); + $header = array('Accept-Language: ' . getEnv('HTTP_ACCEPT_LANGUAGE') . "\r\n"); // First character cannot be a forward slash if(strpos($this->getInput('u'), "/") === 0) { @@ -136,14 +126,10 @@ class FacebookBridge extends BridgeAbstract { } if(!strpos($this->getInput('u'), "/")) { - $html = getSimpleHTMLDOM(self::URI . urlencode($this->getInput('u')) . '?_fb_noscript=1', - false, - $context) + $html = getSimpleHTMLDOM(self::URI . urlencode($this->getInput('u')) . '?_fb_noscript=1', $header) or returnServerError('No results for this query.'); } else { - $html = getSimpleHTMLDOM(self::URI . 'pages/' . $this->getInput('u') . '?_fb_noscript=1', - false, - $context) + $html = getSimpleHTMLDOM(self::URI . 'pages/' . $this->getInput('u') . '?_fb_noscript=1', $header) or returnServerError('No results for this query.'); } } diff --git a/bridges/VkBridge.php b/bridges/VkBridge.php index 4eba9610..d8099a5d 100644 --- a/bridges/VkBridge.php +++ b/bridges/VkBridge.php @@ -109,19 +109,9 @@ class VkBridge extends BridgeAbstract { ini_set('user-agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0'); - $opts = array( - 'http' => array( - 'method' => "GET", - 'user_agent' => ini_get('user_agent'), - 'accept_encoding' => 'gzip', - 'header' => "Accept-language: en\r\n - Cookie: remixlang=3\r\n" - ) - ); + $header = array("Accept-language: en\r\nCookie: remixlang=3\r\n"); - $context = stream_context_create($opts); - - return getContents($this->getURI(), false, $context); + return getContents($this->getURI(), $header); } diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index 8ec1f148..59236862 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -141,8 +141,8 @@ class YoutubeBridge extends BridgeAbstract { private function ytGetSimpleHTMLDOM($url){ return getSimpleHTMLDOM($url, $use_include_path = false, - $context = null, - $offset = 0, + $header = array(), + $opts = array(), $maxLen = null, $lowercase = true, $forceTagsClosed = true,