'catpage', 'cat' => $cat, 'page' => $pg, 'lang' => $L]), false, [], 8);
$j = is_string($resp) ? json_decode($resp, true) : null;
if (!is_array($j)) { error_log('products.php: could not reach the CRM for category ' . $cat . ' (HTTP ' . $code . ')'); echo $html; exit; }
if (empty($j['ok']) || empty($j['seo'][$L])) {
if ($code === 404) { http_response_code(404); echo preg_replace('~~', '', $html, 1); exit; }
error_log('products.php: the CRM gave no page data for category ' . $cat . ' (HTTP ' . $code . ')'); echo $html; exit;
}
$S = $j['seo'][$L]; $SX = $j['seo'];
$h = fn($s) => htmlspecialchars((string)$s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$miss = [];
$put = function (string $re, string $to) use (&$html, &$miss) {
$n = 0; $html = preg_replace($re, str_replace(['\\', '$'], ['\\\\', '\\$'], $to), $html, 1, $n);
if ($n !== 1) $miss[] = $re;
};
$meta = fn($attr, $key, $val) => $put('~~', '');
$put('~
.*?~s', '' . $h($S['title']) . '');
$meta('name', 'description', $S['desc']);
$put('~~', ''
. ''
. ''
. ((string)($S['prev'] ?? '') !== '' ? '' : '')
. ((string)($S['next'] ?? '') !== '' ? '' : ''));
$meta('property', 'og:title', $S['title']);
$meta('property', 'og:description', $S['desc']);
$meta('property', 'og:url', $S['url']);
$meta('property', 'og:locale', $L === 'ar' ? 'ar_EG' : 'en_US');
$meta('property', 'og:locale:alternate', $L === 'ar' ? 'en_US' : 'ar_EG');
$meta('name', 'twitter:title', $S['title']);
$meta('name', 'twitter:description', $S['desc']);
$put('~~', '');
/* ⚑ w1491 — المسار كامل (الرئيسية / المتجر / القسم الأب / القسم) — والأخير span زي ما الجافاسكريبت مستنيه */
$cr = (array)($S['crumbs'] ?? []);
if (count($cr) >= 3) {
$bc = '';
foreach ($cr as $i => $c) {
$last = ($i === count($cr) - 1); $di = $i === 0 ? ' data-i18n="crumb.home"' : ($i === 1 ? ' data-i18n="crumb.shop"' : '');
$bc .= ($i ? '/' : '') . ($last ? '' . $h($c[0]) . '' : '' . $h($c[0]) . '');
}
$put('~.*?[^<]*
~s', '' . $bc . '
');
$put('~~', '');
} else $put('~[^<]*~', '' . $h($S['name']) . '');
$put('~~', '' . $h($S['name']) . '
');
$cards = '';
foreach ((array)$j['items'] as $it) {
$nm = $L === 'ar' ? $it['name_ar'] : $it['name_en']; $u = 'product.html?slug=' . rawurlencode((string)$it['slug']) . ($lang !== '' ? '&lang=' . $L : '');
$cards .= '' . ((string)$it['image'] !== '' ? '
' : '') . ''
. '' . $h($L === 'ar' ? $it['price_ar'] : $it['price_en']) . '
';
}
/* ⚑ w1491 — روابط الصفحات جوّه الشبكة (جوجل بيمشي فيها لكل أصناف القسم، والجافاسكريبت بيرسم صفحاته فوقها) */
$pager = '';
foreach ((array)($S['pager'] ?? []) as $p) $pager .= ((int)$p[0] === (int)($j['page'] ?? 1) ? '' . (int)$p[0] . ' ' : '' . (int)$p[0] . ' ');
if ($pager !== '') $cards .= '';
$put('~~', '' . $cards . '
');
if ($miss) error_log('products.php: these tags were not found in products.html: ' . implode(' | ', $miss));
echo $html;