Browse Source

Evitons une notice si l'appel à l'API ne retourne rien.

master
Eric Lupinacci 8 months ago
parent
commit
73021d88ba
  1. 49
      mirror.php

49
mirror.php

@ -236,6 +236,8 @@ function debardeur_json_api_extract_links($headers) {
* @return array
*/
function debardeur_json_api_call_raw($type, $endpoint, $method, $query, $last_modified_time = null){
$res = '';
$dir_cache = sous_repertoire(_DIR_DEBARDEUR_TMP, 'cache');
$dir_cache = sous_repertoire($dir_cache, $type);
@ -279,30 +281,35 @@ function debardeur_json_api_call_raw($type, $endpoint, $method, $query, $last_mo
curl_close($ch);
list($header, $content) = explode("\r\n\r\n", $output, 2);
$headers = [];
$header_lines = explode("\n", $header);
foreach ($header_lines as $header_line){
$header_line = explode(':', $header_line, 2);
if (count($header_line)==2){
list($k, $v) = $header_line;
$headers[$k] = trim($v);
if ($output) {
list($header, $content) = explode("\r\n\r\n", $output, 2);
$headers = [];
$header_lines = explode("\n", $header);
foreach ($header_lines as $header_line){
$header_line = explode(':', $header_line, 2);
if (count($header_line)==2){
list($k, $v) = $header_line;
$headers[$k] = trim($v);
}
}
}
$json = json_decode($content, true);
$res = [
'status' => false,
'header' => $headers,
'content' => $json,
'last_modified' => time(),
];
if ($httpCode==200 and $json!==false and !is_null($json)){
$res['status'] = true;
file_put_contents($file_cache, json_encode($res));
$json = json_decode($content, true);
$res = [
'status' => false,
'header' => $headers,
'content' => $json,
'last_modified' => time(),
];
if ($httpCode==200 and $json!==false and !is_null($json)){
$res['status'] = true;
file_put_contents($file_cache, json_encode($res));
} else {
spip_log("Echec call API $url:" . json_encode($res), 'debardeur_call_api' . _LOG_ERREUR);
}
} else {
spip_log("Echec call API $url:" . json_encode($res), 'debardeur_call_api' . _LOG_ERREUR);
echo "API non accessible (url: $url)";
spip_log("Echec call API $url pas accessible", 'debardeur_call_api' . _LOG_ERREUR);
}
return $res;

Loading…
Cancel
Save