commit d9c14e70c84b49cfab22e7f764d6c6dabdea6b52 Author: Lukas Winkler Date: Sun Mar 10 22:26:25 2019 +0100 initial version diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1ad0e2b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## Changelog + +### 0.1.0 + +first version \ No newline at end of file diff --git a/ClassicCounter.php b/ClassicCounter.php new file mode 100644 index 0000000..916a9ba --- /dev/null +++ b/ClassicCounter.php @@ -0,0 +1,26 @@ +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; + } + +} diff --git a/Controller.php b/Controller.php new file mode 100644 index 0000000..ea9ebb3 --- /dev/null +++ b/Controller.php @@ -0,0 +1,57 @@ + [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(); + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..84e8ad1 --- /dev/null +++ b/README.md @@ -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 + +``` + + \ No newline at end of file diff --git a/Tasks.php b/Tasks.php new file mode 100644 index 0000000..4b922c8 --- /dev/null +++ b/Tasks.php @@ -0,0 +1,36 @@ +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); + + } + } + +} diff --git a/plugin.json b/plugin.json new file mode 100644 index 0000000..a875b73 --- /dev/null +++ b/plugin.json @@ -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" + ] +} diff --git a/screenshots/4909.png b/screenshots/4909.png new file mode 100644 index 0000000..3cf3569 Binary files /dev/null and b/screenshots/4909.png differ diff --git a/templates/svg.twig b/templates/svg.twig new file mode 100644 index 0000000..327f0cb --- /dev/null +++ b/templates/svg.twig @@ -0,0 +1,50 @@ + + {{ number }} + + + + + + + + + + + + {% for digit in digits %} + + + + + + + + + + {% endfor %} + \ No newline at end of file