?
| Current Path : /home/w/e/b/webyoo/www/nathan-ai/site/ |
| Current File : /home/w/e/b/webyoo/www/nathan-ai/site/lib.php |
<?php
/**
* lib.php â fonctions utilitaires partagĂ©es.
*/
function cfg() {
static $c = null;
if ($c === null) {
$path = __DIR__ . '/config.php';
if (!file_exists($path)) {
$msg = "config.php introuvable. Duplique config.sample.php en config.php (mĂȘme dossier) et remplis client_id, client_secret et redirect_uri.";
if (PHP_SAPI === 'cli') {
fwrite(STDERR, "Erreur: $msg\n");
} else {
header('Content-Type: text/html; charset=utf-8');
echo "<div style='font-family:sans-serif;max-width:640px;margin:40px auto;padding:24px;border:1px solid #ddd;border-radius:12px'>"
. "<h2>âïž Ătape manquante</h2><p><b>$msg</b></p>"
. "<p>Ensuite, reviens ici avec <code>?login=1</code> pour lancer la connexion LinkedIn.</p></div>";
}
exit(1);
}
$c = require $path;
}
return $c;
}
function logline($msg) {
$c = cfg();
$line = '[' . date('Y-m-d H:i:s') . '] ' . $msg . PHP_EOL;
file_put_contents($c['log_file'], $line, FILE_APPEND);
echo $line;
}
/**
* RequĂȘte HTTP simple via cURL. Retourne [code_http, corps_reponse].
*/
function http_request($method, $url, $headers = [], $body = null) {
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_TIMEOUT => 30,
]);
if ($body !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
}
$resp = curl_exec($ch);
if ($resp === false) {
$err = curl_error($ch);
curl_close($ch);
return [0, json_encode(['curl_error' => $err])];
}
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return [$code, $resp];
}