getChunk($tpl) : '';
$tpl = ($tpl != '') ? $tpl : '[+keyword+] ([+hits+] hits)
';
// Get the token on the API page inside your Piwik interface
$token_auth = '12345678991234567890123456789012';
$url = 'http://url.der.piwik.installation/';
$url .= '?module=API&method=Actions.getPageTitles';
$url .= '&idSite=1&period=month&date=yesterday';
$url .= '&format=PHP';
$url .= '&token_auth=' . $token_auth;
$fetched = file_get_contents($url);
$content = unserialize($fetched);
// case error
if (!$content) {
return 'Error, content fetched = ' . $fetched;
}
$seiten = $modx->runSnippet('Ditto', array('tpl' => '@CODE:[+pagetitle+]|[+id+],', 'tplLast' => '@CODE:[+pagetitle+]|[+id+]', 'sortBy' => 'menuindex ASC', 'level' => '10'));
$seiten = explode(',', $seiten);
$check = array();
foreach ($seiten as $seite) {
$seite = explode('|', $seite);
$check[$seite[0]] = $seite[1];
}
$output = '';
$i = 1;
foreach ($content as $row) {
$keyword = trim(urldecode($row['label']));
$hits = $row['nb_visits'];
if (array_key_exists($keyword, $check)) {
$chunk = str_replace('[+keyword+]', $keyword, $tpl);
$chunk = str_replace('[+id+]', $check[$keyword], $chunk);
$output .= str_replace('[+hits+]', $hits, $chunk);
if ($i++ == $limit) {
return $output;
}
}
}
return $output;