1
0
قرینه از https://github.com/matomo-org/matomo.git synced 2025-08-21 22:47:43 +00:00
Files
matomo/plugins/SEO/API.php
Nathan Gavin 2a7934cc00 Update codebase to satisfy PHPStan level 1 (#23328)
* Update some errors picked up by PHPStan

* More PHPStan suggestions

* revisit logic around null coalescing and added phpstan ignore comment

* remove phpstan comment

* Update some errors picked up by PHPStan

* More PHPStan suggestions

* revisit logic around null coalescing and added phpstan ignore comment

* remove phpstan comment

* further fixes

* resolve merge conflicts

* reapply fixes

* small adjustments

---------

Co-authored-by: sgiehl <stefan@matomo.org>
2025-06-18 10:23:58 +02:00

87 خطوط
2.4 KiB
PHP

<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\SEO;
use Piwik\DataTable;
use Piwik\Piwik;
use Piwik\Plugins\SEO\Metric\Aggregator;
use Piwik\Plugins\SEO\Metric\Metric;
use Piwik\Plugins\SEO\Metric\ProviderCache;
use Piwik\Url;
/**
* @see plugins/Referrers/functions.php
* @method static API getInstance()
*/
require_once PIWIK_INCLUDE_PATH . '/plugins/Referrers/functions.php';
/**
* The SEO API lets you access a list of SEO metrics for the specified URL: Bing indexed pages and age of the Domain name.
*
* @method static API getInstance()
*/
class API extends \Piwik\Plugin\API
{
/**
* Returns SEO statistics for a URL.
*
* @param string $url URL to request SEO stats for
* @return DataTable
*/
public function getRank($url)
{
Piwik::checkUserHasSomeViewAccess();
$metricProvider = new ProviderCache(new Aggregator());
$domain = Url::getHostFromUrl($url) ?: '';
$metrics = $metricProvider->getMetrics($domain);
$dataTable = $this->toDataTable($metrics);
$dataTable->setMetadata(DataTable::COLUMN_AGGREGATION_OPS_METADATA_NAME, [
'id' => 'skip',
'rank' => 'skip',
'logo' => 'skip',
'logo_link' => 'skip',
'logo_tooltip' => 'skip',
'rank_suffix' => 'skip',
]);
$dataTable->disableFilter('Limit');
return $dataTable;
}
/**
* @param Metric[] $metrics
* @return DataTable
*/
private function toDataTable(array $metrics)
{
$translated = [];
foreach ($metrics as $metric) {
if (!$metric instanceof Metric) {
continue;
}
$label = Piwik::translate($metric->getName());
$translated[$label] = [
'id' => $metric->getId(),
'rank' => $metric->getValue(),
'logo' => $metric->getLogo(),
'logo_link' => $metric->getLogoLink(),
'logo_tooltip' => Piwik::translate($metric->getLogoTooltip()),
'rank_suffix' => Piwik::translate($metric->getValueSuffix()),
];
}
return DataTable::makeFromIndexedArray($translated);
}
}