38 lines
1,010 B
PHP
38 lines
1,010 B
PHP
<?php
|
|
|
|
namespace Piwik\Plugins\ExportImportTool;
|
|
|
|
use Piwik\API\Request;
|
|
|
|
class API
|
|
{
|
|
public function exportSite($idSite)
|
|
{
|
|
$request = new Request("module=API&method=SitesManager.getSiteFromId&idSite=".$idSite."&format=json");
|
|
$result = $request->process();
|
|
$site = json_decode($result, true);
|
|
|
|
if (!$site) {
|
|
throw new \Exception('Site with ID ' . $idSite . ' does not exist.');
|
|
}
|
|
|
|
$request = new Request("module=API&method=Live.getLastVisitsDetails&idSite=".$idSite."&period=date&date=1992-01-01,today&filter_limit=-1&format=json");
|
|
$result = $request->process();
|
|
|
|
$visits = json_decode($result, true);
|
|
|
|
$data = [
|
|
'site' => $site,
|
|
'visits' => $visits,
|
|
];
|
|
|
|
$jsonData = json_encode($data, JSON_PRETTY_PRINT);
|
|
|
|
$filePath = '/tmp/' . $idSite . '.json';
|
|
file_put_contents($filePath, $jsonData);
|
|
|
|
return "Export succeeded, file path: " . $filePath;
|
|
}
|
|
|
|
}
|
|
|