events yogibook
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Bootstrap per gli endpoint PUBBLICI del modulo Eventi (cartella /api).
|
||||
* NON include headscript.php: niente login/redirect. Serve solo il DB.
|
||||
*
|
||||
* Posiziona la cartella /api allo stesso livello di events.php, class/, include/.
|
||||
* Requisito: class/db-functions.php (DBHandlerSelect) già presente e autonomo.
|
||||
*/
|
||||
|
||||
// Path assoluto a DBHandlerSelect (api/ -> ../class/db-functions.php)
|
||||
require_once dirname(__DIR__) . '/class/db-functions.php';
|
||||
|
||||
// URL pubblico di yogibook: usato per rendere assoluti i path delle immagini.
|
||||
if (!defined('YB_PUBLIC_BASE')) {
|
||||
define('YB_PUBLIC_BASE', 'https://yogibook.yogasoul.it/');
|
||||
}
|
||||
|
||||
// Domini WordPress autorizzati (per la prenotazione via browser).
|
||||
$YB_ALLOWED_ORIGINS = ['https://yogasoul.it', 'https://www.yogasoul.it'];
|
||||
|
||||
$origin = $_SERVER['HTTP_ORIGIN'] ?? '';
|
||||
if ($origin !== '' && in_array($origin, $YB_ALLOWED_ORIGINS, true)) {
|
||||
header('Access-Control-Allow-Origin: ' . $origin);
|
||||
header('Vary: Origin');
|
||||
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
||||
header('Access-Control-Allow-Headers: Content-Type');
|
||||
}
|
||||
|
||||
// Preflight CORS
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'OPTIONS') {
|
||||
http_response_code(204);
|
||||
exit();
|
||||
}
|
||||
|
||||
function pdo_conn(): PDO
|
||||
{
|
||||
return DBHandlerSelect::getInstance()->getConnection();
|
||||
}
|
||||
|
||||
/** Rende assoluto un path immagine relativo (es. assets/uploads/events/x.jpg). */
|
||||
function public_url(?string $rel): ?string
|
||||
{
|
||||
if ($rel === null || $rel === '') {
|
||||
return null;
|
||||
}
|
||||
if (preg_match('#^https?://#i', $rel)) {
|
||||
return $rel;
|
||||
}
|
||||
return YB_PUBLIC_BASE . ltrim($rel, '/');
|
||||
}
|
||||
|
||||
/** Risponde in JSON e termina. */
|
||||
function send_json($data, int $code = 200): void
|
||||
{
|
||||
if (function_exists('ob_get_level') && ob_get_level()) {
|
||||
ob_clean();
|
||||
}
|
||||
http_response_code($code);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit();
|
||||
}
|
||||
Reference in New Issue
Block a user