* * * Разметка schema.org для звёзд в Google (если сайт не выводит её сам): * echo yezap_reviews('КЛЮЧ_САЙТА', 'tour-1', ['schema' => 'product', 'name' => 'Название тура']); * * Ответ кэшируется на 10 минут во временной папке. Если yezap недоступен — отдаётся старая копия, * а если её нет — пустой блок, который заполнит скрипт yezap.js. Сайт не тормозит дольше 3 секунд. */ function yezap_reviews($key, $object, array $opt = array()) { $q = array_merge(array('a' => 'html', 'key' => $key, 'object' => $object), $opt); $url = 'https://yezap.com/v1/?' . http_build_query($q); $file = sys_get_temp_dir() . '/yezap-' . md5($url) . '.html'; $ttl = isset($opt['ttl']) ? (int) $opt['ttl'] : 600; if (is_file($file) && filemtime($file) > time() - $ttl) { return (string) file_get_contents($file); } $ctx = stream_context_create(array('http' => array('timeout' => 3, 'ignore_errors' => true, 'header' => "User-Agent: yezap-ssr/1.0\r\n"))); $html = @file_get_contents($url, false, $ctx); $ok = is_string($html) && isset($http_response_header[0]) && strpos($http_response_header[0], ' 200') !== false && strpos($html, 'yezap-reviews') !== false; if ($ok) { @file_put_contents($file, $html, LOCK_EX); return $html; } if (is_file($file)) { @touch($file); // старая копия ещё на 10 минут, чтобы не долбить yezap при сбое return (string) file_get_contents($file); } $h = function ($s) { return htmlspecialchars((string) $s, ENT_QUOTES, 'UTF-8'); }; return '
'; }