commit
ff7703b6cc
7 changed files with 484 additions and 0 deletions
18
serendipity_plugin_piwik/ChangeLog
Normal file
18
serendipity_plugin_piwik/ChangeLog
Normal file
|
@ -0,0 +1,18 @@
|
|||
0.4.0
|
||||
* with Piwik v2 it is possible to use lsat x days for most
|
||||
read entries instead of current week
|
||||
* some optimizations for fetching most read entries (smaller arrays)
|
||||
|
||||
0.3.1
|
||||
* included some debug-logging
|
||||
* included "known bugs" into README.markdown
|
||||
|
||||
0.3
|
||||
* renaming of language strings
|
||||
* included some live-statistics
|
||||
|
||||
0.2
|
||||
* some changes and optimisations by mattsches, thanks!
|
||||
|
||||
0.1
|
||||
* first try, a lot of things could behave wrong
|
16
serendipity_plugin_piwik/README.markdown
Normal file
16
serendipity_plugin_piwik/README.markdown
Normal file
|
@ -0,0 +1,16 @@
|
|||
# serendipity_plugin_piwik
|
||||
|
||||
## Description
|
||||
|
||||
This is just a small sidebar-plugin which can connect to your Piwik-installation. If you want to
|
||||
use it, you have to set up an user who has at least read-access to piwik. Within user-managment of
|
||||
piwik you can create a new one, if you don't want to use admin.
|
||||
|
||||
If you don't need one part of the statistics, just disable it.
|
||||
|
||||
If you want to change the order of output, install the plugin twice, it's stackable :)
|
||||
Now, you can can enable or disable any part of every instance until you are happy ;)
|
||||
|
||||
## known bugs
|
||||
|
||||
In some cases (i think, it only happens if main/index-page is in the top xx-list) page-url and page-title of section "most read entries" are not for the same page. I don't know why, but Piwik gives different output for the fetching of url and title and at the moment i don't know how i could solve this problem.
|
38
serendipity_plugin_piwik/UTF-8/lang_de.inc.php
Executable file
38
serendipity_plugin_piwik/UTF-8/lang_de.inc.php
Executable file
|
@ -0,0 +1,38 @@
|
|||
<?php # $Id$
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_NAME', 'Piwik');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_DESC', 'zeigt Piwik-Statistiken an');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TITLE_NAME', 'Überschrift');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TITLE_DESC', 'die Überschrift des Abschnitts');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TOKEN_NAME','Token');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TOKEN_DESC','der geheime Token des Piwik-Nutzers');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_SITEID_NAME','Seiten-ID');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_SITEID_DESC','ID der Seite in Piwik');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_URL_NAME','URL');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_URL_DESC','die URL zur Piwik-Installation');
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_SHOW_NAME','Live-Statistiken: Anzeige');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_SHOW_DESC','Statistiken zu den Besuchern der letzten xx Minuten anzeigen');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_TITLE_NAME','Live-Statistiken: Überschrift');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_TITLE_DESC','Überschrift für die Live-Statistiken, leer lassen zum verstecken');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_MINUTES_NAME','Live-Statistiken: Zeitraum');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_MINUTES_DESC','Zeitraum in Minuten, der für die Live-Statistiken verwendet werden soll');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_VISITORS','eindeutige Besucher');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_VISITS','Besuche');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_ACTIONS','Seitenansichten');
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_SHOW_NAME','meistgelesene Beiträge: Anzeige');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_SHOW_DESC','die meistgelesenen Beiträge der aktuellen Woche anzeigen');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_TITLE_NAME','meistgelesene Beiträge: Überschrift');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_TITLE_DESC','Überschrift für die meistgelesenen Beiträge der Woche, leer lassen zum verstecken');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_DAYS_NAME','meistgelesene Beiträge: Zeitraum');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_DAYS_DESC','letzte X Tage, die berücksichtigt werden sollen (0 für aktuelle Woche)');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_MAX_NAME','meistgelesene Beiträge: Anzahl');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_MAX_DESC','maximale Anzahl der anzuzeigenden Einträge');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_REMOVE_NAME','meistgelesene Beiträge: zu entfernender Text');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_REMOVE_DESC','Text, der aus dem Seitennamen entfernt werden soll');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_VIEWS','Aufrufe');
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_DEBUG_NAME','Debug-Logging aktivieren:');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_DEBUG_DESC','wenn das Logging aktiviert ist, werden einige Ausgaben (z. B. die Piwik-Abfrage-URL nach ./templates_c/piwik_debug.log geschrieben');
|
||||
|
37
serendipity_plugin_piwik/UTF-8/lang_en.inc.php
Executable file
37
serendipity_plugin_piwik/UTF-8/lang_en.inc.php
Executable file
|
@ -0,0 +1,37 @@
|
|||
<?php # $Id$
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_NAME', 'Piwik');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_DESC', 'show statistics of Piwik in sidebar');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TITLE_NAME', 'Header');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TITLE_DESC', 'the header for this sidebar-plugin');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TOKEN_NAME','Token');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TOKEN_DESC','the token of Piwik-user who can read statistics');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_SITEID_NAME','Site-ID');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_SITEID_DESC','ID of your webpage within Piwik');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_URL_NAME','URL');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_URL_DESC','URL of your Piwik-installation');
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_SHOW_NAME','Live: Display');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_SHOW_DESC','show statistics of your visitors from the last xx minutes');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_TITLE_NAME','Live: Header');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_TITLE_DESC','header for live-section, leave empty for hiding');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_MINUTES_NAME','Live: Period');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_MINUTES_DESC','period in minutes which will be used for live-statistics');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_VISITORS','unique visitors');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_VISITS','visits');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_ACTIONS','page views');
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_SHOW_NAME','Entries: Display');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_SHOW_DESC','show most read entries of current week');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_TITLE_NAME','Entries: Header');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_TITLE_DESC','header for most read entries, leave empty for hiding');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_DAYS_NAME','Entries: Period');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_DAYS_DESC','last X days that should be considered (0 for current week)');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_MAX_NAME','Entries: Number');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_MAX_DESC','how many entries should be shown');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_REMOVE_NAME','Entries: String to remove');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_REMOVE_DESC','string that should be removed from page-title');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_VIEWS','views');
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_DEBUG_NAME','activate debug-logging:');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_DEBUG_DESC','if logging is enabled, some things will be written into ./templates_c/piwik_debug.log (for example the piwik-fetch-url');
|
38
serendipity_plugin_piwik/lang_de.inc.php
Executable file
38
serendipity_plugin_piwik/lang_de.inc.php
Executable file
|
@ -0,0 +1,38 @@
|
|||
<?php # $Id$
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_NAME', 'Piwik');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_DESC', 'zeigt Piwik-Statistiken an');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TITLE_NAME', 'Überschrift');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TITLE_DESC', 'die Überschrift des Abschnitts');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TOKEN_NAME','Token');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TOKEN_DESC','der geheime Token des Piwik-Nutzers');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_SITEID_NAME','Seiten-ID');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_SITEID_DESC','ID der Seite in Piwik');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_URL_NAME','URL');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_URL_DESC','die URL zur Piwik-Installation');
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_SHOW_NAME','Live-Statistiken: Anzeige');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_SHOW_DESC','Statistiken zu den Besuchern der letzten xx Minuten anzeigen');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_TITLE_NAME','Live-Statistiken: Überschrift');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_TITLE_DESC','Überschrift für die Live-Statistiken, leer lassen zum verstecken');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_MINUTES_NAME','Live-Statistiken: Zeitraum');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_MINUTES_DESC','Zeitraum in Minuten, der für die Live-Statistiken verwendet werden soll');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_VISITORS','eindeutige Besucher');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_VISITS','Besuche');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_ACTIONS','Seitenansichten');
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_SHOW_NAME','meistgelesene Beiträge: Anzeige');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_SHOW_DESC','die meistgelesenen Beiträge der aktuellen Woche anzeigen');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_TITLE_NAME','meistgelesene Beiträge: Überschrift');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_TITLE_DESC','Überschrift für die meistgelesenen Beiträge der Woche, leer lassen zum verstecken');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_DAYS_NAME','meistgelesene Beiträge: Zeitraum');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_DAYS_DESC','letzte X Tage, die berücksichtigt werden sollen (0 für aktuelle Woche)');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_MAX_NAME','meistgelesene Beiträge: Anzahl');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_MAX_DESC','maximale Anzahl der anzuzeigenden Einträge');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_REMOVE_NAME','meistgelesene Beiträge: zu entfernender Text');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_REMOVE_DESC','Text, der aus dem Seitennamen entfernt werden soll');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_VIEWS','Aufrufe');
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_DEBUG_NAME','Debug-Logging aktivieren:');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_DEBUG_DESC','wenn das Logging aktiviert ist, werden einige Ausgaben (z. B. die Piwik-Abfrage-URL nach ./templates_c/piwik_debug.log geschrieben');
|
||||
|
37
serendipity_plugin_piwik/lang_en.inc.php
Executable file
37
serendipity_plugin_piwik/lang_en.inc.php
Executable file
|
@ -0,0 +1,37 @@
|
|||
<?php # $Id$
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_NAME', 'Piwik');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_DESC', 'show statistics of Piwik in sidebar');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TITLE_NAME', 'Header');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TITLE_DESC', 'the header for this sidebar-plugin');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TOKEN_NAME','Token');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_TOKEN_DESC','the token of Piwik-user who can read statistics');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_SITEID_NAME','Site-ID');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_SITEID_DESC','ID of your webpage within Piwik');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_URL_NAME','URL');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_URL_DESC','URL of your Piwik-installation');
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_SHOW_NAME','Live: Display');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_SHOW_DESC','show statistics of your visitors from the last xx minutes');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_TITLE_NAME','Live: Header');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_TITLE_DESC','header for live-section, leave empty for hiding');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_MINUTES_NAME','Live: Period');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_MINUTES_DESC','period in minutes which will be used for live-statistics');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_VISITORS','unique visitors');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_VISITS','visits');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_LIVE_ACTIONS','page views');
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_SHOW_NAME','Entries: Display');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_SHOW_DESC','show most read entries of current week');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_TITLE_NAME','Entries: Header');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_TITLE_DESC','header for most read entries, leave empty for hiding');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_DAYS_NAME','Entries: Period');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_DAYS_DESC','last X days that should be considered (0 for current week)');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_MAX_NAME','Entries: Number');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_MAX_DESC','how many entries should be shown');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_REMOVE_NAME','Entries: String to remove');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_REMOVE_DESC','string that should be removed from page-title');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_ENTRIES_VIEWS','views');
|
||||
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_DEBUG_NAME','activate debug-logging:');
|
||||
@define('PLUGIN_SIDEBAR_PIWIK_DEBUG_DESC','if logging is enabled, some things will be written into ./templates_c/piwik_debug.log (for example the piwik-fetch-url');
|
300
serendipity_plugin_piwik/serendipity_plugin_piwik.php
Executable file
300
serendipity_plugin_piwik/serendipity_plugin_piwik.php
Executable file
|
@ -0,0 +1,300 @@
|
|||
<?php # $Id$
|
||||
|
||||
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
|
||||
|
||||
@serendipity_plugin_api::load_language(dirname(__FILE__));
|
||||
|
||||
class serendipity_plugin_piwik extends serendipity_plugin {
|
||||
public $title = PLUGIN_SIDEBAR_PIWIK_NAME;
|
||||
protected $token;
|
||||
protected $url;
|
||||
protected $live_show;
|
||||
protected $live_title;
|
||||
protected $live_minutes;
|
||||
protected $entries_show;
|
||||
protected $entries_title;
|
||||
protected $entries_days;
|
||||
protected $entries_max;
|
||||
protected $entries_remove;
|
||||
protected $debug;
|
||||
protected $dependencies;
|
||||
|
||||
/**
|
||||
* @param serendipity_property_bag $propbag
|
||||
* @return void
|
||||
*/
|
||||
public function introspect(&$propbag)
|
||||
{
|
||||
$this->title = $this->get_config('title', $this->title);
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_DESC);
|
||||
$propbag->add('stackable', true);
|
||||
$propbag->add('author', 'Bernd Distler');
|
||||
$propbag->add('version', '0.4.0');
|
||||
$propbag->add('requirements', array(
|
||||
'serendipity' => '1.3.1', // don't know about that
|
||||
'smarty' => '2.6.7',
|
||||
'php' => '5.1.0'
|
||||
));
|
||||
$propbag->add('configuration', array('title','token','site_id','url','live_show','live_title','live_minutes','entries_show','entries_title','entries_days','entries_max','entries_remove','debug'));
|
||||
$propbag->add('groups', array('FRONTEND_EXTERNAL_SERVICES'));
|
||||
$this->dependencies = array('serendipity_event_piwik' => 'remove');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param serendipity_property_bag $propbag
|
||||
* @return bool
|
||||
*/
|
||||
public function introspect_config_item($name, &$propbag)
|
||||
{
|
||||
switch($name) {
|
||||
case 'title':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_TITLE_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_TITLE_DESC);
|
||||
$propbag->add('default', '');
|
||||
break;
|
||||
case 'token':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_TOKEN_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_TOKEN_DESC);
|
||||
$propbag->add('default', '');
|
||||
break;
|
||||
case 'site_id':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_SITEID_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_SITEID_DESC);
|
||||
$propbag->add('default', '');
|
||||
break;
|
||||
case 'url':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_URL_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_URL_DESC);
|
||||
$propbag->add('default', 'http://example.org/piwik/');
|
||||
break;
|
||||
case 'live_show':
|
||||
$propbag->add('type', 'boolean');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_LIVE_SHOW_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_LIVE_SHOW_DESC);
|
||||
$propbag->add('default', 'true');
|
||||
break;
|
||||
case 'live_title':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_LIVE_TITLE_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_LIVE_TITLE_DESC);
|
||||
$propbag->add('default', '');
|
||||
break;
|
||||
case 'live_minutes':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_LIVE_MINUTES_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_LIVE_MINUTES_DESC);
|
||||
$propbag->add('default', '30');
|
||||
break;
|
||||
case 'entries_show':
|
||||
$propbag->add('type', 'boolean');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_ENTRIES_SHOW_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_ENTRIES_SHOW_DESC);
|
||||
$propbag->add('default', 'true');
|
||||
break;
|
||||
case 'entries_title':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_ENTRIES_TITLE_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_ENTRIES_TITLE_DESC);
|
||||
$propbag->add('default', '');
|
||||
break;
|
||||
case 'entries_days':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_ENTRIES_DAYS_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_ENTRIES_DAYS_DESC);
|
||||
$propbag->add('default', '7');
|
||||
break;
|
||||
case 'entries_max':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_ENTRIES_MAX_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_ENTRIES_MAX_DESC);
|
||||
$propbag->add('default', '5');
|
||||
break;
|
||||
case 'entries_remove':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_ENTRIES_REMOVE_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_ENTRIES_REMOVE_DESC);
|
||||
$propbag->add('default', '');
|
||||
break;
|
||||
case 'debug':
|
||||
$propbag->add('type', 'boolean');
|
||||
$propbag->add('name', PLUGIN_SIDEBAR_PIWIK_DEBUG_NAME);
|
||||
$propbag->add('description', PLUGIN_SIDEBAR_PIWIK_DEBUG_DESC);
|
||||
$propbag->add('default', 'false');
|
||||
break;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @return void
|
||||
*/
|
||||
public function generate_content(&$title) {
|
||||
$title = $this->get_config('title', $title ? $title : $this->title);
|
||||
$token = $this->get_config('token', $this->token);
|
||||
$site_id = $this->get_config('site_id', $this->site_id);
|
||||
$url = $this->get_config('url', $this->url);
|
||||
$live_show = $this->get_config('live_show', $this->live_show);
|
||||
$live_title = $this->get_config('live_title', $this->live_title);
|
||||
$live_minutes = $this->get_config('live_minutes', $this->live_minutes);
|
||||
$entries_show = $this->get_config('entries_show', $this->entries_show);
|
||||
$entries_title = $this->get_config('entries_title', $this->entries_title);
|
||||
$entries_days = $this->get_config('entries_days', $this->entries_days);
|
||||
$entries_max = $this->get_config('entries_max', $this->entries_max);
|
||||
$entries_remove = $this->get_config('entries_remove', $this->entries_remove);
|
||||
$debug = $this->get_config('debug', $this->debug);
|
||||
$error = false;
|
||||
$piwik_array_pagesurls = array();
|
||||
$piwik_array_pagestitles = array();
|
||||
$piwik_array_live = array();
|
||||
|
||||
/* live statistics from last xx minutes */
|
||||
if ($live_show) {
|
||||
|
||||
$api_url = $url;
|
||||
$api_url .= "?module=API&method=Live.getCounters";
|
||||
$api_url .= "&idSite=" . $site_id . "&lastMinutes=" . $live_minutes;
|
||||
$api_url .= "&format=PHP";
|
||||
$api_url .= "&token_auth=$token";
|
||||
if ($debug) {$this->debug_append('Live.getCounters - API-URL: '.$api_url);}
|
||||
try {
|
||||
$piwik_array_live = unserialize($this->requestPiwikData($api_url));
|
||||
} catch (Exception $e) {
|
||||
$error = true;
|
||||
}
|
||||
if ($error) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($live_title <> '') {echo "\n<h4>".$live_title."</h4>\n";}
|
||||
echo '<ul class="plainList" >';
|
||||
foreach ($piwik_array_live as $row) {
|
||||
$piwik_live_visits = htmlspecialchars(
|
||||
html_entity_decode(urldecode($row['visits']), ENT_QUOTES),
|
||||
ENT_QUOTES
|
||||
);
|
||||
$piwik_live_actions = htmlspecialchars(
|
||||
html_entity_decode(urldecode($row['actions']), ENT_QUOTES),
|
||||
ENT_QUOTES
|
||||
);
|
||||
$piwik_live_visitsConverted = htmlspecialchars(
|
||||
html_entity_decode(urldecode($row['visitsConverted']), ENT_QUOTES),
|
||||
ENT_QUOTES
|
||||
);
|
||||
$piwik_live_visitors = htmlspecialchars(
|
||||
html_entity_decode(urldecode($row['visitors']), ENT_QUOTES),
|
||||
ENT_QUOTES
|
||||
);
|
||||
|
||||
echo ' <li>'. PLUGIN_SIDEBAR_PIWIK_LIVE_VISITORS .': '. $piwik_live_visitors."</li>\n";
|
||||
echo ' <li>'. PLUGIN_SIDEBAR_PIWIK_LIVE_VISITS .': '. $piwik_live_visits."</li>\n";
|
||||
echo ' <li>'. PLUGIN_SIDEBAR_PIWIK_LIVE_ACTIONS .': '. $piwik_live_actions."</li>\n";
|
||||
}
|
||||
echo "\n</ul>\n";
|
||||
|
||||
}
|
||||
|
||||
/* most viewed entries of current week */
|
||||
if ($entries_show) {
|
||||
// read Actions.getPageUrls from Piwik
|
||||
$api_url = $url.'index.php';
|
||||
$api_url .= "?module=API&method=Actions.getPageUrls";
|
||||
$api_url .= "&idSite=" . $site_id;
|
||||
if ($entries_days == '0') {
|
||||
$api_url .= "&period=week&date=today";
|
||||
} else {
|
||||
$api_url .= "&period=range&date=previous".$entries_days;
|
||||
}
|
||||
$api_url .= "&format=PHP&filter_limit=" . $entries_max;
|
||||
$api_url .= "&flat=1&disableLink=1";
|
||||
$api_url .= "&showColumns=label,url,nb_visits";
|
||||
$api_url .= "&token_auth=$token";
|
||||
if ($debug) {$this->debug_append('Actions.getPageUrls - API-URL: '.$api_url);}
|
||||
try {
|
||||
$piwik_array_pagesurls = unserialize($this->requestPiwikData($api_url));
|
||||
} catch (Exception $e) {
|
||||
$error = true;
|
||||
}
|
||||
|
||||
// read Actions.getPageTitles from Piwik
|
||||
$api_url = $url.'index.php';
|
||||
$api_url .= "?module=API&method=Actions.getPageTitles";
|
||||
$api_url .= "&idSite=" . $site_id;
|
||||
if ($entries_days == '0') {
|
||||
$api_url .= "&period=week&date=today";
|
||||
} else {
|
||||
$api_url .= "&period=range&date=previous".$entries_days;
|
||||
}
|
||||
$api_url .= "&format=PHP&filter_limit=" . $entries_max;
|
||||
$api_url .= "&flat=1&disableLink=1";
|
||||
$api_url .= "&showColumns=label";
|
||||
$api_url .= "&token_auth=$token";
|
||||
if ($debug) {$this->debug_append('Actions.getPageTitles - API-URL: '.$api_url);}
|
||||
try {
|
||||
$piwik_array_pagestitles = unserialize($this->requestPiwikData($api_url));
|
||||
} catch (Exception $e) {
|
||||
$error = true;
|
||||
}
|
||||
if ($error) {
|
||||
return;
|
||||
}
|
||||
|
||||
// take pagetitles from seconed array and write it into first one
|
||||
for ($i = 0; $i < count($piwik_array_pagesurls); $i++) {
|
||||
$piwik_array_pagesurls[$i]['label'] = $piwik_array_pagestitles[$i]['label'];
|
||||
}
|
||||
|
||||
if ($entries_title <> '') {echo "\n<h4>".$entries_title."</h4>\n";}
|
||||
echo "\n<ol>\n";
|
||||
foreach ($piwik_array_pagesurls as $row) {
|
||||
$piwik_content_pageurl = htmlspecialchars(
|
||||
html_entity_decode(urldecode($row['url']), ENT_QUOTES),
|
||||
ENT_QUOTES
|
||||
);
|
||||
$piwik_content_pagelabel = htmlspecialchars(
|
||||
html_entity_decode(urldecode($row['label']), ENT_QUOTES),
|
||||
ENT_QUOTES
|
||||
);
|
||||
$piwik_content_pagelabel = str_replace($entries_remove, "", $piwik_content_pagelabel);
|
||||
$piwik_content_hits = $row['nb_visits'];
|
||||
echo ' <li><a href="' . $piwik_content_pageurl . '" title="' . $piwik_content_hits . ' ' . PLUGIN_SIDEBAR_PIWIK_ENTRIES_VIEWS . '">' . $piwik_content_pagelabel . "</a></li>\n";
|
||||
}
|
||||
echo "\n</ol>\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $api_url
|
||||
* @return bool|mixed|string
|
||||
*/
|
||||
protected function requestPiwikData($api_url)
|
||||
{
|
||||
serendipity_request_start();
|
||||
$req = new HTTP_Request($api_url);
|
||||
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
|
||||
$piwik_fetched = file_get_contents($api_url);
|
||||
} else {
|
||||
$piwik_fetched = $req->getResponseBody();
|
||||
}
|
||||
serendipity_request_end();
|
||||
return $piwik_fetched;
|
||||
}
|
||||
|
||||
|
||||
function debug_append ($debug_message)
|
||||
{
|
||||
$logfile = $serendipity['serendipityPath'] . 'templates_c/piwik_debug.log';
|
||||
$fp = @fopen($logfile, 'a+');
|
||||
fwrite($fp, "\n".date('Y-m-d H:i:s', serendipity_serverOffsetHour()).' '.$debug_message);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set sts=4 ts=4 expandtab : */
|
Loading…
Reference in a new issue