From f4000150faa1d410678be719f23d9547b9646798 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sun, 23 Oct 2022 09:05:17 +0200 Subject: [PATCH] avoid cURL dependency, native functions should suffice for such a simple call --- lib/YourlsProxy.php | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/YourlsProxy.php b/lib/YourlsProxy.php index b5161103..dc19e24d 100644 --- a/lib/YourlsProxy.php +++ b/lib/YourlsProxy.php @@ -55,22 +55,24 @@ class YourlsProxy return; } - // Init the CURL session - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $conf->getKey("apiurl", "yourls")); - curl_setopt($ch, CURLOPT_HEADER, 0); // No header in the result - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result - curl_setopt($ch, CURLOPT_POST, 1); // This is a POST request - curl_setopt($ch, CURLOPT_POSTFIELDS, array( // Data to POST - 'signature' => $conf->getKey("signature", "yourls"), - 'format' => 'json', - 'action' => 'shorturl', - 'url' => $link - )); - // Fetch and return content - $data = curl_exec($ch); - curl_close($ch); - + $data = file_get_contents( + $conf->getKey('apiurl', 'yourls'), false, stream_context_create( + array( + 'http' => array( + 'method' => 'POST', + 'header' => "Content-Type: application/x-www-form-urlencoded\r\n", + 'content' => http_build_query( + array( + 'signature' => $conf->getKey('signature', 'yourls'), + 'format' => 'json', + 'action' => 'shorturl', + 'url' => $link + ) + ) + ) + ) + ) + ); if ($data === false || !is_string($data)) { $this->_error = 'Error calling YOURLS. Probably a configuration issue, like wrong or missing "apiurl" or "signature".'; return;