'item', 'slug' => $slug, 'lang' => $L]), false, [], 8); $j = is_string($resp) ? json_decode($resp, true) : null; if (!is_array($j)) { error_log('product.php: could not reach the CRM for ' . $slug . ' (HTTP ' . $code . ')'); echo $html; exit; } if (empty($j['ok']) || empty($j['item']['seo'][$L])) { if ($code === 404) { http_response_code(404); echo preg_replace('~~', '', $html, 1); exit; } error_log('product.php: the CRM gave no page data for ' . $slug . ' (HTTP ' . $code . ')'); echo $html; exit; } $S = $j['item']['seo'][$L]; $SX = $j['item']['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('~~', '' . '' . ''); $meta('property', 'og:type', 'product'); $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']); if ((string)$S['image'] !== '') { $meta('property', 'og:image', $S['image']); $meta('name', 'twitter:image', $S['image']); /* مقاس صورة الموقع العامة (1200×630) مش مقاس صورة الصنف ⇐ بيتشال بدل ما يكدب */ $html = preg_replace('~\s*~', '', $html); } $ld = json_encode($S['ld'], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP); $put('~~', ''); /* ⚑ w1491 — المسار لجوجل (BreadcrumbList) — الرئيسية › المتجر › الأقسام › الصنف */ if (!empty($S['ld_crumbs'])) $put('~~', ''); /* نفس الـid اللي الجافاسكريبت بيكتب فيه ⇐ مافيش نسختين */ /* ── الصفحة نفسها (الجافاسكريبت بيكتب فوقها بعدين بنفس الكلام) ── */ $put('~

~', '

' . $h($S['name']) . '

'); $put('~
~', '
' . $h($S['cat']) . '
'); $put('~~', '' . $h($S['name']) . ''); /* ⚑ w1491 — رابط القسم في المسار الظاهر: قسم المتجر الأقرب للصنف (اللي قبل الصنف في المسار) — كان «products.html» من غير قسم */ $cr = (array)($S['crumbs'] ?? []); if (count($cr) >= 4) { $c = $cr[count($cr) - 2]; $put('~~', '' . $h($c[0]) . ''); } if ((string)$S['short'] !== '') $put('~~', '

' . $h($S['short']) . '

'); /* ⚑ w1487 — السعر (نص من النظام: الرقم من غير ضريبة، أو «عند الطلب») والوصف الطويل (HTML متنضّف من النظام) */ $put('~
~', '
' . $h($S['price_text'] ?? '') . '
'); if ((string)($S['desc_html'] ?? '') !== '') { $put('~