From 80f3b39502549328c738a872c33e58bb8126f807 Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Thu, 22 Sep 2016 14:26:59 +0200 Subject: [PATCH] forward compatibility to serendipity_request_url --- include/functions.inc.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/include/functions.inc.php b/include/functions.inc.php index a1710fb1..12dc33d6 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -1125,13 +1125,23 @@ function serendipity_request_end() { * @param $method string HTTP method (GET/POST/PUT/OPTIONS...) * @param $contenttype string optional HTTP content type * @param $contenttype string optional extra data (i.e. POST body) + * @param $extra_options array Extra options + * @param $addData string possible extra event addData declaration for 'backend_http_request' hook * @return $content string The URL contents */ -function serendipity_request_url($uri, $method = 'GET', $contenttype = null, $data = null) { +function serendipity_request_url($uri, $method = 'GET', $contenttype = null, $data = null, $extra_options = null, $addData = null) { + global $serendipity; + require_once S9Y_PEAR_PATH . 'HTTP/Request2.php'; $options = array('follow_redirects' => true, 'max_redirects' => 5); - serendipity_plugin_api::hook_event('backend_http_request', $options, 'trackback_send'); + + if (is_array($extra_options)) { + foreach($extra_options AS $okey => $oval) { + $options[$okey] = $oval; + } + } + serendipity_plugin_api::hook_event('backend_http_request', $options, $addData); serendipity_request_start(); if (version_compare(PHP_VERSION, '5.6.0', '<')) { // On earlier PHP versions, the certificate validation fails. We deactivate it on them to restore the functionality we had with HTTP/Request1 @@ -1192,6 +1202,17 @@ function serendipity_request_url($uri, $method = 'GET', $contenttype = null, $da $fContent = $res->getBody(); + $serendipity['last_http_request'] = array( + 'responseCode' => $res->getStatus(), + 'effectiveUrl' => $res->getEffectiveUrl(), + 'reasonPhrase' => $res->getReasonPhrase(), + 'isRedirect' => $res->isRedirect(), + 'cookies' => $res->getCookies(), + 'version' => $res->getVersion(), + + 'object' => $res // forward compatibility for possible other checks + ); + serendipity_request_end(); return $fContent; }