avoid cURL dependency, native functions should suffice for such a simple call

This commit is contained in:
El RIDO 2022-10-23 09:05:17 +02:00
parent b768a2e8cb
commit f4000150fa
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92

View file

@ -55,22 +55,24 @@ class YourlsProxy
return; return;
} }
// Init the CURL session $data = file_get_contents(
$ch = curl_init(); $conf->getKey('apiurl', 'yourls'), false, stream_context_create(
curl_setopt($ch, CURLOPT_URL, $conf->getKey("apiurl", "yourls")); array(
curl_setopt($ch, CURLOPT_HEADER, 0); // No header in the result 'http' => array(
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result 'method' => 'POST',
curl_setopt($ch, CURLOPT_POST, 1); // This is a POST request 'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
curl_setopt($ch, CURLOPT_POSTFIELDS, array( // Data to POST 'content' => http_build_query(
'signature' => $conf->getKey("signature", "yourls"), array(
'format' => 'json', 'signature' => $conf->getKey('signature', 'yourls'),
'action' => 'shorturl', 'format' => 'json',
'url' => $link 'action' => 'shorturl',
)); 'url' => $link
// Fetch and return content )
$data = curl_exec($ch); )
curl_close($ch); )
)
)
);
if ($data === false || !is_string($data)) { if ($data === false || !is_string($data)) {
$this->_error = 'Error calling YOURLS. Probably a configuration issue, like wrong or missing "apiurl" or "signature".'; $this->_error = 'Error calling YOURLS. Probably a configuration issue, like wrong or missing "apiurl" or "signature".';
return; return;