avoid cURL dependency, native functions should suffice for such a simple call
This commit is contained in:
parent
b768a2e8cb
commit
f4000150fa
1 changed files with 18 additions and 16 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue