Правдоподобный генератор рейтинга сайта

Последнее обновление: 29 ноября, 2020

Без рубрики

Пример кода генератора:

<?php
$rate = random_int(0, 2);
if ( $rate != 0 ) {
    echo $r_value = file('value')[0];
    echo ' | ';
    echo $r_count = file('count')[0];
    echo ' | '.round($r_value/$r_count, 1);
} else {
    echo $r_value = file('value')[0];
    echo ' | ';
    echo $r_count = file('count')[0];
    echo ' | '.round($r_value/$r_count, 1);
    $rate = random_int(0, 2);
    if ( $rate != 0 ) {
        $r_value_upd = $r_value + 5;
            $f_r_value = fopen("value", 'a');
            ftruncate($f_r_value, 0);
            fwrite($f_r_value, $r_value_upd);
        $r_count_upd = ++$r_count;
            $f_r_count = fopen("count", 'a');
            ftruncate($f_r_count, 0);
            fwrite($f_r_count, $r_count_upd);
    } else {
        $r_value_upd = $r_value + 4;
            $f_r_value = fopen("value", 'a');
            ftruncate($f_r_value, 0);
            fwrite($f_r_value, $r_value_upd);
        $r_count_upd = ++$r_count;
            $f_r_count = fopen("count", 'a');
            ftruncate($f_r_count, 0);
            fwrite($f_r_count, $r_count_upd);
    }
    fclose($f_r_value);
    fclose($f_r_count);
}

Пример кода вывода рейтинга (рейтинг + цены):

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Product",
  "aggregateRating":
  {
    "@type": "AggregateRating",
    "ratingValue": "4.5",
    "bestRating": "5",
    "reviewCount": "5867"
  },
  "name": "site page title",
  "description": "site page description"
  ,"offers":
  {
    "@type": "AggregateOffer",
    "lowPrice": "600",
    "highPrice": "8000",
    "priceCurrency": "USD",
    "offerCount": "4"
  }
}
</script>

Пример кода вывода рейтинга (только рейтинг):

<script type="application/ld+json">{
"@context": "https://schema.org/",
"@type": "Product",
"name": "Service (page) name",
"brand": "Brand name",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "4.8",
"bestRating": "5",
"ratingCount": "21"
}}
</script>