'YOUR_API_KEY']; $domain = !empty($_POST['domain']) ? $_POST['domain'] : ''; if (!empty($domain)) { try { $data = @file_get_contents("{$url}/{$domain}&" . http_build_query($params)); $data = @json_decode($data, true); } catch (Exception $e) { $data = []; } // echo "
"; print_r($data); die();
}
function formatValue($rows, $key, $showHistroy = false) {
if (empty($rows) || empty($rows[$key]) || empty($rows[$key][$key])) {
return "—";
}
$val = $rows[$key][$key];
$values = [number_format($val)];
if ($showHistroy && !empty($rows[$key]["{$key}History"])) {
$prevValue = array_slice($rows[$key]["{$key}History"]['days'], -2, 1)[0];
$values[] = history($val, $prevValue);
}
return implode($values, " ");
}
function history($val, $history) {
if ($val == $history) {
return;
}
$sign = '';
$class = '';
if ($val < $history) {
$class = 'text-danger';
} elseif ($val > $history) {
$sign = '+';
$class = 'text-success';
}
$diff = $val - $history;
$diff = number_format($diff);
return "{$sign}{$diff}";
}
$tableMapping = [
'days' => 'История по дням',
'weeks' => 'История по неделям',
'months' => 'История по годам',
];
?>
Api Test
- Яндекс ТИЦ
-
= formatValue($data, 'yandexCitation') ?>
- Яндекс Rank
-
= formatValue($data, 'yandexRank') ?>
- Индексация Яндекс
-
= formatValue($data, 'yandexIndex', true) ?>
if (!empty($data['yandexCitation']) && !empty($data['yandexCitation']['yandexCitationHistory'])): ?>
foreach ($data['yandexCitation']['yandexCitationHistory'] as $type => $histories): ?>
- = $tableMapping[$type] ?>
-
Дата
Значение
foreach ($histories as $date => $value): ?>
= date('Y-m-d', strtotime($date)) ?>
= number_format($value) ?>
endforeach ?>
endforeach ?>
endif ?>
- Индексация Google
-
= formatValue($data, 'googleIndex', true) ?>
if (!empty($data['googleIndex']) && !empty($data['googleIndex']['googleIndexHistory'])): ?>
foreach ($data['googleIndex']['googleIndexHistory'] as $type => $histories): ?>
- = $tableMapping[$type] ?>
-
Дата
Значение
foreach ($histories as $date => $value): ?>
= date('Y-m-d', strtotime($date)) ?>
= number_format($value) ?>
endforeach ?>
endforeach ?>
endif ?>
if (!empty($data['yandexCatalog']) && !empty($data['yandexCatalog']['yandexCategories'])): ?>
- Яндекс.Каталог
-
foreach ($data['yandexCatalog']['yandexCategories'] as $path => $category): ?>
endforeach ?>
endif ?>