1
0
Fork 0
mirror of https://github.com/Findus23/plugin-ClassicCounter.git synced 2024-09-19 15:23:45 +02:00

initial version

This commit is contained in:
Lukas Winkler 2019-03-10 22:26:25 +01:00
commit d9c14e70c8
Signed by: lukas
GPG key ID: 54DE4D798D244853
8 changed files with 214 additions and 0 deletions

5
CHANGELOG.md Normal file
View file

@ -0,0 +1,5 @@
## Changelog
### 0.1.0
first version

26
ClassicCounter.php Normal file
View file

@ -0,0 +1,26 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\ClassicCounter;
use Piwik\Access;
class ClassicCounter extends \Piwik\Plugin
{
public static function getVisitorCount($idSite) {
$visitsCount = Access::getInstance()->doAsSuperUser(function () use ($idSite) {
return \Piwik\API\Request::processRequest('VisitsSummary.getVisits', array(
'idSite' => $idSite,
'period' => "range",
'date' => "2000-01-01,2030-01-01",
))->getFirstRow()["nb_visits"];
});
return (int)$visitsCount;
}
}

57
Controller.php Normal file
View file

@ -0,0 +1,57 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\ClassicCounter;
use Piwik\Cache;
use Piwik\Common;
use Piwik\View;
class Controller extends \Piwik\Plugin\Controller
{
private $sevenSegment = [
"0" => [true, true, true, true, true, true, false],
"1" => [false, true, true, false, false, false, false],
"2" => [true, true, false, true, true, false, true],
"3" => [true, true, true, true, false, false, true],
"4" => [false, true, true, false, false, true, true],
"5" => [true, false, true, true, false, true, true],
"6" => [true, false, true, true, true, true, true],
"7" => [true, true, true, false, false, false, false],
"8" => [true, true, true, true, true, true, true],
"9" => [true, true, true, true, false, true, true]
];
public function svg() {
$idSite = Common::getRequestVar('idSite', $this->idSite, 'int');
$cache = Cache::getLazyCache();
$cacheKey = "ClassicCounter_Visits_" . $idSite;
if ($cache->contains($cacheKey)) {
$visitCount = $cache->fetch($cacheKey);
} else {
$visitCount = ClassicCounter::getVisitorCount($idSite);
$cache->save($cacheKey, $visitCount, 60);
}
$view = new View("@ClassicCounter/svg");
$view->setContentType("image/svg+xml");
$view->number = $visitCount;
$chars = str_split($visitCount);
foreach ($chars as $char) {
if (empty($this->sevenSegment[$char])) {
throw new \Exception("character can't be shown on seven segment display");
}
$view->digits[] = $this->sevenSegment[$char];
}
$view->length = strlen($visitCount);
return $view->render();
}
}

13
README.md Normal file
View file

@ -0,0 +1,13 @@
# Matomo ClassicCounter Plugin
## Description
No website is complete without a nostalgic view counter at the bottom!
This plugin allows you to add an image showing the total amount of visits per `idSite`.
```html
<img src="https://yourmatomoinstance.example/index.php?module=ClassicCounter&action=svg&idSite=1&period=day">
```
<img src="./screenshots/4909.png" height="80">

36
Tasks.php Normal file
View file

@ -0,0 +1,36 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\ClassicCounter;
use Piwik\Cache;
use Piwik\FrontController;
use Piwik\Plugins\ClassicCounter\Controller;
use Piwik\Plugins\SitesManager\API as SitesManagerApi;
class Tasks extends \Piwik\Plugin\Tasks
{
public function schedule() {
$this->hourly('updateCache', null, self::LOW_PRIORITY);
}
public function updateCache() {
$cache = Cache::getLazyCache();
$bla=new Controller();
$siteIds = SitesManagerApi::getInstance()->getAllSitesId();
foreach ($siteIds as $idSite) {
$cacheKey = "ClassicCounter_Visits_" . $idSite;
$visitCount = ClassicCounter::getVisitorCount($idSite);
$cache->save($cacheKey, $visitCount, 60);
}
}
}

27
plugin.json Normal file
View file

@ -0,0 +1,27 @@
{
"name": "ClassicCounter",
"description": "Embed a view counter in the style of classic CGI scripts into your website",
"version": "0.1.0",
"theme": false,
"require": {
"piwik": ">=3.8.0,<4.0.0-b1"
},
"authors": [
{
"name": "Lukas Winkler",
"email": "lukas@matomo.org",
"homepage": "https://lw1.at"
}
],
"support": {
"email": "lukas@matomo.org",
"issues": "https://github.com/Findus23/plugin-ClassicCounter/issues",
"forum": "https://forum.matomo.org",
"source": "https://github.com/Findus23/plugin-ClassicCounter"
},
"homepage": "https://lw1.at",
"license": "GPL v3+",
"keywords": [
"nostalgia"
]
}

BIN
screenshots/4909.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

50
templates/svg.twig Normal file
View file

@ -0,0 +1,50 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
baseProfile="full"
viewBox="-1 -1 {{ length*12 }} 20">
<title>{{ number }}</title>
<style>
svg {
background-color: black;
}
polygon {
fill-opacity: 0.75;
fill-rule: evenodd;
stroke: black;
stroke-width: 0.25;
stroke-opacity: 1.0;
stroke-linecap: butt;
stroke-linejoin: miter;
}
.on {
fill: red;
}
use {
fill: #222222;
}
</style>
<defs id="defs">
<polygon id="a" points=" 1, 1 2, 0 8, 0 9, 1 8, 2 2, 2"></polygon><!-- top -->
<polygon id="b" points=" 9, 1 10, 2 10, 8 9, 9 8, 8 8, 2"></polygon><!-- right top -->
<polygon id="c" points=" 9, 9 10,10 10,16 9,17 8,16 8,10"></polygon><!-- right bottom -->
<polygon id="d" points=" 9,17 8,18 2,18 1,17 2,16 8,16"></polygon><!-- bottom -->
<polygon id="e" points=" 1,17 0,16 0,10 1, 9 2,10 2,16"></polygon><!-- left bottom -->
<polygon id="f" points=" 1, 9 0, 8 0, 2 1, 1 2, 2 2, 8"></polygon><!-- left top -->
<polygon id="g" points=" 1, 9 2, 8 8, 8 9, 9 8,10 2,10"></polygon><!-- center -->
</defs>
{% for digit in digits %}
<g transform="translate({{ loop.index0*12 }},0)">
<use xlink:href="#a"{{ digit[0] ? " class=\"on\"":"" }}/>
<use xlink:href="#b"{{ digit[1] ? " class=\"on\"":"" }}/>
<use xlink:href="#c"{{ digit[2] ? " class=\"on\"":"" }}/>
<use xlink:href="#d"{{ digit[3] ? " class=\"on\"":"" }}/>
<use xlink:href="#e"{{ digit[4] ? " class=\"on\"":"" }}/>
<use xlink:href="#f"{{ digit[5] ? " class=\"on\"":"" }}/>
<use xlink:href="#g"{{ digit[6] ? " class=\"on\"":"" }}/>
</g>
{% endfor %}
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB