Skip to content

Commit

Permalink
ready for Contao 3.4 & Piwik 2.14
Browse files Browse the repository at this point in the history
Abwärtskompatibel bis Contao 2.11
fixed: Anzeige Statistiken auf Welcome-Page (betrifft Contao 3.4)
neu: Responsives Backend-Layout wird unterstützt
neu: Anzahl der ausgewerteten Tage ist in den Einstellungen einstellbar (default: 30 Tage)
geändert: Piwik-Logo
  • Loading branch information
math authored and math committed Jul 5, 2015
1 parent 7993e5d commit 6aef3e3
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 149 deletions.
Binary file removed assets/piwikicon.gif
Binary file not shown.
50 changes: 33 additions & 17 deletions bepiwikcharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ class bepiwikcharts extends BackendModule {
public $url = "http://demo.piwik.org/"; // inkl. http(s), mit / am Ende
public $piwik_IDsite = 3;
public $piwik_TOKENauth = "anonymous";
public $piwik_period = 30;
private $tableMaxRows = 10;
public $modus = 0; // 0 = Demo, 1 = normal
private $username = "";
private $password = "";
private $error = FALSE;
private $errorCode = 0;
private $version_installed = "";

public function compile() {

Expand All @@ -64,6 +66,9 @@ function __construct() {
$this->url = $GLOBALS["TL_CONFIG"]['piwikchartsURL'];
$this->piwik_IDsite = $GLOBALS["TL_CONFIG"]['piwikchartsSiteID'];
$this->piwik_TOKENauth = $GLOBALS["TL_CONFIG"]['piwikchartsAuthCode'];
if ($GLOBALS["TL_CONFIG"]['piwikchartsPeriod'] != "") {
$this->piwik_period = intval($GLOBALS["TL_CONFIG"]['piwikchartsPeriod']);
}
$this->username = $GLOBALS["TL_CONFIG"]['piwikchartsUsername'];
$this->password = $GLOBALS["TL_CONFIG"]['piwikchartsPassword'];
$this->modus = 1; //1 = Normalmodus;
Expand All @@ -72,19 +77,20 @@ function __construct() {

/**
* checkUpdate - prüft auf Updates
* @return wenn neue Version vorliegt: neue Versionsnummer. Wenn keine neue Version vorliegt: Leerstring
* @return String - wenn neue Version vorliegt: neue Versionsnummer. Wenn keine neue Version vorliegt: Leerstring
*/
function checkUpdate() {
if ($this->modus == 1) {
// nur im Produktivmodus nutzen. nicht im Demo-Modus
try {
// aktuelle Version vom Server lesen
$xml = new SimpleXMLElement($this->readfile($this->url . "index.php?module=API&method=API.getPiwikVersion&format=xml&token_auth=" . $this->piwik_TOKENauth));
$version_installed = trim($xml[0]);
$this->version_installed = trim($xml[0]);

// neuste Version vom Piwik-Server lesen
$version_newest = trim($this->readfile("http://api.piwik.org/1.0/getLatestVersion/"));

if ($version_newest == $version_installed) {
if ($version_newest == $this->version_installed) {
return "";
} else {
return $version_newest;
Expand Down Expand Up @@ -310,12 +316,13 @@ function dashboardWelcomePage() {
return "";
}

$strBuffer = '<div id="welcomepagePiwikcharts" style="margin:18px;">';
//$strBuffer = '<div id="welcomepagePiwikcharts" style="margin:18px;">';
$strBuffer = '<div id="welcomepagePiwikcharts">';

$objTemplate_head = new BackendTemplate('ce_headline');
$objTemplate_head->hl = 'h2';
$objTemplate_head->class = 'ce_headline';
$objTemplate_head->style = 'background:none repeat scroll 0 0 #F6F6F6;border: solid #E9E9E9; border-width: 1px 0px 1px 0px; margin:18px 0px 6px; padding: 2px 6px 3px;';
//$objTemplate_head->style = 'background:none repeat scroll 0 0 #F6F6F6;border: solid #E9E9E9; border-width: 1px 0px 1px 0px; margin:18px 0px 6px; padding: 2px 6px 3px;';
$objTemplate_head->headline = $GLOBALS['TL_LANG']['be_piwikcharts']['template']['dashboard']['headline'];

$strBuffer .= $objTemplate_head->parse();
Expand All @@ -341,8 +348,8 @@ function dashboardWelcomePage() {
$objTemplate_content->lang = (object) $GLOBALS['TL_LANG']['be_piwikcharts']['template']['dashboard'];

// Diagramme
$objTemplate_content->chart_evolutionVisitsSummaryDay .= $this->printChart("evolution", "VisitsSummary", "day", "previous30", 400, 180, 80, "get", "", "margin-right:20px;");
$objTemplate_content->chart_evolutionVisitsSummaryMonth .= $this->printChart("evolution", "VisitsSummary", "month", "previous24", 400, 100, 80, "get", "&colors=,,ff0000", "margin-bottom: 10px;");
$objTemplate_content->chart_evolutionVisitsSummaryDay .= $this->printChart("evolution", "VisitsSummary", "day", "previous".$this->piwik_period, 400, 180, 80, "get", "", "");
$objTemplate_content->chart_evolutionVisitsSummaryMonth .= $this->printChart("evolution", "VisitsSummary", "month", "previous24", 400, 100, 80, "get", "&colors=,,ff0000", "");

//im Demo-Modus (0) ist die Anzeige letzte 30Min/24h deaktivert
if ($this->modus > 0) {
Expand Down Expand Up @@ -416,6 +423,8 @@ public function generate() {
}

$objTemplate->link_server = $this->url;

$objTemplate->piwik_period = $this->piwik_period;


$objTemplate->piwik_IDsite = $this->piwik_IDsite;
Expand All @@ -424,28 +433,35 @@ public function generate() {
$objTemplate->showUpdate = $this->User->isAdmin || $GLOBALS["TL_CONFIG"]['piwikchartsWelcomePageUpdate'];

// 30 Tage Besuchergraf
$objTemplate->chart_evolutionVisitsSummaryDay = $this->printChart("evolution", "VisitsSummary", "day", "previous30", 400, 200, 80, "get");
$objTemplate->chart_evolutionVisitsSummaryDay = $this->printChart("evolution", "VisitsSummary", "day", "previous".$this->piwik_period, 400, 200, 80, "get");

// 24 Monate Besuchergraf
$objTemplate->chart_evolutionVisitsSummaryMonth = $this->printChart("evolution", "VisitsSummary", "month", "previous24", 400, 200, 80, "get", "&colors=,,ff0000");

// Diagramm Besuchszeiten
$objTemplate->chart_verticalBarVisitsPerServerTime = $this->printChart("verticalBar", "VisitTime", "range", "previous30", 400, 200, 80, "getVisitInformationPerServerTime");
$objTemplate->chart_verticalBarVisitsPerServerTime = $this->printChart("verticalBar", "VisitTime", "range", "previous".$this->piwik_period, 400, 200, 80, "getVisitInformationPerServerTime");

// Diagramm Besuchertage
$objTemplate->chart_verticalBarVisitTimeByDayOfWeek = $this->printChart("verticalBar", "VisitTime", "range", "previous30", 400, 200, 80, "getByDayOfWeek");
$objTemplate->chart_verticalBarVisitTimeByDayOfWeek = $this->printChart("verticalBar", "VisitTime", "range", "previous".$this->piwik_period, 400, 200, 80, "getByDayOfWeek");

// Diagramm Browser
$objTemplate->chart_horizontalBarUserBrowser = $this->printChart("horizontalBar", "UserSettings", "range", "previous30", 400, 200, 80, "getBrowser");

$objTemplate->chart_horizontalBarUserBrowser = $this->printChart("horizontalBar", "DevicesDetection", "range", "previous".$this->piwik_period, 400, 200, 80, "getBrowsers");

$version = explode(".", $this->version_installed);

if (intval($version[0])<2 || (intval($version[0])<2 && intval($version[1])<10) ) {
// in der Piwik Version 2.10 wurde die API angepasst. Ab Version 2.14 wurde "UserSettings" abgeschaltet. Fuer die Rueckwaertskompatibilitaet
$objTemplate->chart_horizontalBarUserBrowser = $this->printChart("horizontalBar", "UserSettings", "range", "previous".$this->piwik_period, 400, 200, 80, "getBrowser");
}

// Diagramm Länder
$objTemplate->chart_horizontalBarUserCountry = $this->printChart("horizontalBar", "UserCountry", "range", "previous30", 400, 200, 80, "getCountry");
$objTemplate->chart_horizontalBarUserCountry = $this->printChart("horizontalBar", "UserCountry", "range", "previous".$this->piwik_period, 400, 200, 80, "getCountry");

//Tabelle: Suchworte von Suchmaschinen
$objTemplate->table_keywords = $this->printTable(
$this->PHPload(
$this->buildURL(
"Referers.getKeywords", "range", "previous30", "&format=php&filter_limit=20"
"Referers.getKeywords", "range", "previous".$this->piwik_period, "&format=php&filter_limit=20"
), array("label", "nb_visits")
), array(
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['keywords_header_keyword'],
Expand All @@ -457,7 +473,7 @@ public function generate() {
$objTemplate->table_fromWebsite = $this->printTable(
$this->PHPload(
$this->buildURL(
"Referers.getWebsites", "range", "previous30", "&format=php&filter_limit=20"
"Referers.getWebsites", "range", "previous".$this->piwik_period, "&format=php&filter_limit=20"
), array("label", "nb_visits")
), array(
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['fromWebsite_header_website'],
Expand All @@ -469,7 +485,7 @@ public function generate() {
$objTemplate->table_visitedPages = $this->printTable(
$this->PHPload(
$this->buildURL(
"Actions.getPageUrls", "range", "previous30", "&format=php&filter_limit=20"
"Actions.getPageUrls", "range", "previous".$this->piwik_period, "&format=php&filter_limit=20"
), array("label", "nb_visits")
), array(
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['visitedPages_header_page'],
Expand All @@ -481,7 +497,7 @@ public function generate() {
$objTemplate->table_downloads = $this->printTable_downloads(
$this->PHPload(
$this->buildURL(
"Actions.getDownloads", "range", "previous30", "&format=php&filter_limit=20&expanded=1&filter_limit=10"
"Actions.getDownloads", "range", "previous".$this->piwik_period, "&format=php&filter_limit=20&expanded=1&filter_limit=10"
), array("label", "subtable")
), "downloads"
);
Expand Down
8 changes: 7 additions & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,21 @@
$GLOBALS['TL_CONFIG']['dashboardAccess'] = 'public';
$GLOBALS['TL_CONFIG']['dashboardLimit'] = '0';

/**
* Hooks
*/
$GLOBALS['TL_HOOKS']['getSystemMessages'][] = array('bepiwikcharts', 'dashboardWelcomePage');
$GLOBALS['TL_HOOKS']['addCustomRegexp'][] = array('bepiwikcharts', 'myRegexp_checkPiwikUrl');
$GLOBALS['TL_HOOKS']['addCustomRegexp'][] = array('bepiwikcharts', 'myRegexp_checkAuthCode');




array_insert($GLOBALS['BE_MOD']['system'], 98, array(
'be_piwikcharts' => array(
'callback' => 'bepiwikcharts',
'stylesheet' => 'system/modules/be_piwikcharts/assets/bepiwikcharts.css',
'icon' => 'system/modules/be_piwikcharts/assets/piwikicon.gif'
'icon' => 'system/modules/be_piwikcharts/assets/piwikicon.png'
)
));

Expand Down
14 changes: 11 additions & 3 deletions dca/tl_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Add to palette
*/
$GLOBALS['TL_DCA']['tl_settings']['palettes']['default'] .= ';{piwikcharts_legend:hide},piwikchartsURL,piwikchartsSiteID,piwikchartsAuthCode,piwikchartsUsername,piwikchartsPassword,piwikchartsWelcomePageAdmin,piwikchartsWelcomePage,piwikchartsWelcomePageUpdate,piwikchartsWelcomePageOptout,piwikchartsRedirect;';
$GLOBALS['TL_DCA']['tl_settings']['palettes']['default'] .= ';{piwikcharts_legend:hide},piwikchartsURL,piwikchartsSiteID,piwikchartsAuthCode,piwikchartsPeriod,piwikchartsUsername,piwikchartsPassword,piwikchartsWelcomePageAdmin,piwikchartsWelcomePage,piwikchartsWelcomePageUpdate,piwikchartsWelcomePageOptout,piwikchartsRedirect;';

$GLOBALS['TL_DCA']['tl_settings']['fields']['piwikchartsURL'] = array
(
Expand All @@ -56,7 +56,15 @@
'label' => &$GLOBALS['TL_LANG']['tl_settings']['be_piwikcharts']['authCode'],
'inputType' => 'text',
'exclude' => true,
'eval' => array('mandatory' => false, 'rgxp' => 'checkAuthCode', 'tl_class' => 'long clr')
'eval' => array('mandatory' => false, 'rgxp' => 'checkAuthCode', 'tl_class' => 'w50')
);

$GLOBALS['TL_DCA']['tl_settings']['fields']['piwikchartsPeriod'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_settings']['be_piwikcharts']['period'],
'inputType' => 'text',
'exclude' => true,
'eval' => array('mandatory' => false, 'rgxp' => 'natural', 'tl_class' => 'w50')
);

$GLOBALS['TL_DCA']['tl_settings']['fields']['piwikchartsUsername'] = array
Expand All @@ -72,7 +80,7 @@
'label' => &$GLOBALS['TL_LANG']['tl_settings']['be_piwikcharts']['password'],
'inputType' => 'text',
'exclude' => true,
'eval' => array('mandatory' => false, 'hideInput' => true, 'encrypt' => true)
'eval' => array('mandatory' => false, 'hideInput' => true, 'encrypt' => true, 'tl_class' => 'w50')
);

$GLOBALS['TL_DCA']['tl_settings']['fields']['piwikchartsWelcomePageAdmin'] = array
Expand Down
22 changes: 11 additions & 11 deletions languages/de/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,26 @@
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['menu']['update'] = "Update verfügbar";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['menu']['update_title'] = "Ein neues Update der Piwik-Software ist verfügbar";

$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['graph']['visitors_last30days_headline'] = "letzte 30 Tage";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['graph']['visitors_last30days_headline'] = "Zeitraum: letzte %d Tage";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['graph']['visitors_last24months_headline'] = "letzte 24 Monate";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['graph']['visitors_visitsPerServerTime_headline'] = "Besuchszeiten (Serverzeit)";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['graph']['visitors_visitTimeByDayOfWeek_headline'] = "Besuchertage";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['graph']['visitors_userBrowser_headline'] = "Browser";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['graph']['visitors_userCountry_headline'] = "Besucher aus";

$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['keywords_headline'] = "Top-Suchwörter, die auf die Webseite geführten hatten (Zeitraum: letzte 30 Tage)";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['keywords_headline'] = "Top-Suchwörter, die auf die Webseite geführten hatten";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['keywords_header_keyword'] = "Suchwort";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['keywords_header_count'] = "Aufrufe";

$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['fromWebsite_headline'] = "Von diesen Webseiten kamen Ihre Besucher auf Ihre Webseite (Zeitraum: letzte 30 Tage)";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['fromWebsite_headline'] = "Von diesen Webseiten kamen Ihre Besucher auf Ihre Webseite";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['fromWebsite_header_website'] = "Von Webseite";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['fromWebsite_header_count'] = "Aufrufe";

$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['visitedPages_headline'] = "Die am häufigsten besuchten Seiten (Zeitraum: letzte 30 Tage)";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['visitedPages_headline'] = "Die am häufigsten besuchten Seiten";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['visitedPages_header_page'] = "Seite";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['visitedPages_header_count'] = "Aufrufe";

$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['downloads_headline'] = "Die häufigsten Downloads (Zeitraum: letzte 30 Tage)";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['downloads_headline'] = "Die häufigsten Downloads";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['downloads_header_domain'] = "Domain";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['downloads_header_file'] = "Datei";
$GLOBALS['TL_LANG']['be_piwikcharts']['template']['sheet']['table']['downloads_header_count'] = "Downloads";
Expand All @@ -94,11 +94,11 @@
/**
* Load on be_welcome
*/
if (TL_MODE == 'BE') {
if (!strlen($_GET['do']) && ($GLOBALS['TL_LANGUAGE'] == "de") ) {
$bepiwikcharts = new bepiwikcharts();
$GLOBALS['TL_LANG']['MSC']['welcomeTo'] .= '</h1>' . $bepiwikcharts->dashboardWelcomePage() . '<h1 style="display:none">&nbsp;';
}
}
//if (TL_MODE == 'BE') {
// if (!strlen($_GET['do']) && ($GLOBALS['TL_LANGUAGE'] == "de") ) {
// $bepiwikcharts = new bepiwikcharts();
// $GLOBALS['TL_LANG']['MSC']['welcomeTo'] .= '</h1>' . $bepiwikcharts->dashboardWelcomePage() . '<h1 style="display:none">&nbsp;';
// }
//}


2 changes: 1 addition & 1 deletion languages/de/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/


$GLOBALS['TL_LANG']['MOD']['be_piwikcharts'] = array('Statistiken Besucher', 'Statistiken Besucher anzeigen');
$GLOBALS['TL_LANG']['MOD']['be_piwikcharts'] = array('Besucher-Statistiken', '[Piwik] Besucher-Statistiken anzeigen');


?>
1 change: 1 addition & 0 deletions languages/de/tl_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
$GLOBALS['TL_LANG']['tl_settings']['be_piwikcharts']['siteID'] = array("SiteID", "Webseiten-ID: idSite-Variable aus der Piwik-Installation. Bei Piwik-Installationen, die nur eine Webseite erfassen ist 1 der Standard. Den Wert der idSite-Variabe findet man in der URL, wenn man sich das Dashboards auf dem Piwik-Server anschaut.");
$GLOBALS['TL_LANG']['tl_settings']['be_piwikcharts']['authCode'] = array("AuthCode", "AuthCode für die Verbindung mit Piwik um die Statistiken im Backendmodul anzeigen zu können.");
$GLOBALS['TL_LANG']['tl_settings']['be_piwikcharts']['authCode']['rgxp'] = "Mit diesem AuthCode ist keine Verbindung mit der Piwik-Installation möglich.";
$GLOBALS['TL_LANG']['tl_settings']['be_piwikcharts']['period'] = array("Zeitraum", "Zeitaum in Tagen, der statistisch ausgewertet werden soll. (optional, default: 30 Tage)");
$GLOBALS['TL_LANG']['tl_settings']['be_piwikcharts']['username'] = array("Benutzername", "Benutzername für den Auto-Login in Piwik (optional)");
$GLOBALS['TL_LANG']['tl_settings']['be_piwikcharts']['password'] = array("Passwort", "Passwort für den Auto-Login mit Piwik (optional)");
$GLOBALS['TL_LANG']['tl_settings']['be_piwikcharts']['welcomePageAdmin'] = array("BE-Startseite: Statistiken anzeigen (nur für Admins)", "Nur für Admin-User: Zeigt eine Auswahl von Statistiken auf der ersten Seite nach dem Login an. Zusätzlich wird geprüft ob ein Update von Piwik bereit steht.");
Expand Down
Loading

0 comments on commit 6aef3e3

Please sign in to comment.