From 872eaf8dd000caa9428f961d91ba35f610f60370 Mon Sep 17 00:00:00 2001 From: Anaggh S Date: Mon, 3 Sep 2018 18:15:13 +0530 Subject: [PATCH] Add optional content stats feature to simple-stats plugin --- bl-plugins/simple-stats/languages/en.json | 7 +- bl-plugins/simple-stats/plugin.php | 94 ++++++++++++++++++++--- 2 files changed, 89 insertions(+), 12 deletions(-) diff --git a/bl-plugins/simple-stats/languages/en.json b/bl-plugins/simple-stats/languages/en.json index 490d7226..36aeb21b 100644 --- a/bl-plugins/simple-stats/languages/en.json +++ b/bl-plugins/simple-stats/languages/en.json @@ -6,5 +6,8 @@ }, "visits": "Visits", "visits-today": "Visits today", - "unique-visitors-today": "Unique visitors today" -} \ No newline at end of file + "unique-visitors-today": "Unique visitors today", + "statistics": "Statistics", + "chart": "Chart", + "table": "Table" +} diff --git a/bl-plugins/simple-stats/plugin.php b/bl-plugins/simple-stats/plugin.php index 5802cf79..fc2baaa5 100644 --- a/bl-plugins/simple-stats/plugin.php +++ b/bl-plugins/simple-stats/plugin.php @@ -1,6 +1,6 @@ dbFields = array( 'label'=>$L->g('Visits'), 'numberOfDays'=>7, - 'excludeAdmins'=>false + 'excludeAdmins'=>false, + 'showContentStats'=>false ); } @@ -34,6 +35,14 @@ class pluginSimpleStats extends Plugin { $html .= ''.$L->get('This title is almost always used in the sidebar of the site').''; $html .= ''; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= '
'; + if (defined('BLUDIT_PRO')) { $html .= '
'; $html .= ''; @@ -73,18 +82,15 @@ class pluginSimpleStats extends Plugin { $html = << -
+

{$L->get('Visits')}

-
-
-
-

{$L->g('Visits today')}: $visitsToday

-

{$L->g('Unique visitors today')}: $uniqueVisitors

-
-
+
+

{$L->g('Visits today')}: $visitsToday

+

{$L->g('Unique visitors today')}: $uniqueVisitors

EOF; + $numberOfDays = $this->getValue('numberOfDays'); $numberOfDays = $numberOfDays - 1; for ($i=$numberOfDays; $i >= 0 ; $i--) { @@ -119,6 +125,26 @@ EOF; $this->deleteOldLogs(); + /** + * Optional Content Stats Feature + */ + if ($this->getValue('showContentStats')) { + + global $pages, $categories, $tags; + + $data['title'] = $L->get('Statistics'); + $data['tabTitleChart'] = $L->get('Chart'); + $data['tabTitleTable'] = $L->get('Table'); + $data['data'][$L->get('published')] = count($pages->getPublishedDB()); + $data['data'][$L->get('static')] = count($pages->getStaticDB()); + $data['data'][$L->get('drafts')] = count($pages->getDraftDB()); + $data['data'][$L->get('scheduled')] = count($pages->getScheduledDB()); + $data['data'][$L->get('sticky')] = count($pages->getStickyDB()); + $data['data'][$L->get('categories')]= count($categories->keys()); + $data['data'][$L->get('tags')] = count($tags->keys()); + $html .= $this->renderContentStatistics($data); + } + return $html.PHP_EOL.$script.PHP_EOL; } @@ -192,4 +218,52 @@ EOF; return file_put_contents($logFile, $line.PHP_EOL, FILE_APPEND | LOCK_EX)!==false; } + public function renderContentStatistics($data) + { + $html = '
'; + $html .= "

{$data['title']}

"; + $html .= ' + + + +
+ + '; + + return $html; + } + }