2016-10-28 10:03:32 +02:00
|
|
|
<?php
|
2020-09-22 20:25:47 +02:00
|
|
|
|
2016-10-28 10:03:32 +02:00
|
|
|
/**
|
|
|
|
* Piwik plugin.
|
|
|
|
* Adds tracking code on each page.
|
|
|
|
*/
|
|
|
|
|
2018-12-04 00:26:50 +01:00
|
|
|
use Shaarli\Plugin\PluginManager;
|
|
|
|
|
2016-10-28 10:03:32 +02:00
|
|
|
/**
|
|
|
|
* Initialization function.
|
|
|
|
* It will be called when the plugin is loaded.
|
|
|
|
* This function can be used to return a list of initialization errors.
|
|
|
|
*
|
|
|
|
* @param $conf ConfigManager instance.
|
|
|
|
*
|
|
|
|
* @return array List of errors (optional).
|
|
|
|
*/
|
|
|
|
function piwik_init($conf)
|
|
|
|
{
|
|
|
|
$piwikUrl = $conf->get('plugins.PIWIK_URL');
|
|
|
|
$piwikSiteid = $conf->get('plugins.PIWIK_SITEID');
|
|
|
|
if (empty($piwikUrl) || empty($piwikSiteid)) {
|
2017-05-09 18:12:15 +02:00
|
|
|
$error = t('Piwik plugin error: ' .
|
|
|
|
'Please define PIWIK_URL and PIWIK_SITEID in the plugin administration page.');
|
2020-09-22 20:25:47 +02:00
|
|
|
return [$error];
|
2016-10-28 10:03:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook render_footer.
|
|
|
|
* Executed on every page redering.
|
|
|
|
*
|
|
|
|
* Template placeholders:
|
|
|
|
* - text
|
|
|
|
* - endofpage
|
|
|
|
* - js_files
|
|
|
|
*
|
|
|
|
* Data:
|
|
|
|
* - _PAGE_: current page
|
|
|
|
* - _LOGGEDIN_: true/false
|
|
|
|
*
|
|
|
|
* @param array $data data passed to plugin
|
|
|
|
*
|
|
|
|
* @return array altered $data.
|
|
|
|
*/
|
|
|
|
function hook_piwik_render_footer($data, $conf)
|
|
|
|
{
|
|
|
|
$piwikUrl = $conf->get('plugins.PIWIK_URL');
|
|
|
|
$piwikSiteid = $conf->get('plugins.PIWIK_SITEID');
|
|
|
|
if (empty($piwikUrl) || empty($piwikSiteid)) {
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Free elements at the end of the page.
|
2017-03-09 20:51:28 +01:00
|
|
|
$data['endofpage'][] = sprintf(
|
|
|
|
file_get_contents(PluginManager::$PLUGINS_PATH . '/piwik/piwik.html'),
|
|
|
|
$piwikUrl,
|
|
|
|
$piwikSiteid,
|
|
|
|
$piwikUrl,
|
|
|
|
$piwikSiteid
|
|
|
|
);
|
2016-10-28 10:03:32 +02:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2017-05-09 18:12:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is never called, but contains translation calls for GNU gettext extraction.
|
|
|
|
*/
|
|
|
|
function piwik_dummy_translation()
|
|
|
|
{
|
|
|
|
// meta
|
|
|
|
t('A plugin that adds Piwik tracking code to Shaarli pages.');
|
|
|
|
t('Piwik URL');
|
|
|
|
t('Piwik site ID');
|
|
|
|
}
|