From e679c3da01825e8ccfe2da0224fbdd02226254fd Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Wed, 7 Dec 2005 10:08:14 +0000 Subject: [PATCH] commit statistical sidebar plugin --- docs/NEWS | 2 + .../lang_en.inc.php | 15 +- .../serendipity_plugin_statistics.php | 180 ++++++++++++++++++ 3 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 plugins/serendipity_event_statistics/serendipity_plugin_statistics.php diff --git a/docs/NEWS b/docs/NEWS index fdde1bf..7196729 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,8 @@ Version 1.0 () ------------------------------------------------------------------------ + * Added sidebar plugin to show statistical data (garvinhicking) + * Changed detection of "last_modified" timestamp, so that the date only gets bumped in case of real updates. Thanks to Ivan Cenov! diff --git a/plugins/serendipity_event_statistics/lang_en.inc.php b/plugins/serendipity_event_statistics/lang_en.inc.php index b68a8c0..f5864ae 100644 --- a/plugins/serendipity_event_statistics/lang_en.inc.php +++ b/plugins/serendipity_event_statistics/lang_en.inc.php @@ -65,7 +65,7 @@ @define('PLUGIN_EVENT_STATISTICS_EXT_VISITORS', 'Nr of vistors'); @define('PLUGIN_EVENT_STATISTICS_EXT_VISTODAY', 'Nr of vistors today'); @define('PLUGIN_EVENT_STATISTICS_EXT_VISTOTAL', 'Total nr of vistors'); -@define('PLUGIN_EVENT_STATISTICS_EXT_VISSINCE', 'The extended visitorï½´s statistic feature has collected data since'); +@define('PLUGIN_EVENT_STATISTICS_EXT_VISSINCE', 'The extended visitors statistic feature has collected data since'); @define('PLUGIN_EVENT_STATISTICS_EXT_VISLATEST', 'Latest Visitors'); @define('PLUGIN_EVENT_STATISTICS_EXT_TOPREFS', 'Top Referrers'); @define('PLUGIN_EVENT_STATISTICS_EXT_TOPREFS_NONE', 'No referrers has yet been registered.'); @@ -73,4 +73,15 @@ @define('PLUGIN_EVENT_STATISTICS_BANNED_HOSTS', 'Ban browsers from beeing counted'); @define('PLUGIN_EVENT_STATISTICS_BANNED_HOSTS_DESC', 'Insert browsers that should be excluded from counting, separated by "|"'); -?> +@define('PLUGIN_EVENT_STATISTICS_SHOW_LASTENTRY', 'Show date of last entry'); +@define('PLUGIN_EVENT_STATISTICS_SHOW_ENTRYCOUNT', 'Show number of entries'); +@define('PLUGIN_EVENT_STATISTICS_SHOW_COMMENTCOUNT', 'Show number of comments'); +@define('PLUGIN_EVENT_STATISTICS_SHOW_MONTHVISITORS', 'Show visitors this month'); +@define('PLUGIN_EVENT_STATISTICS_SHOW_CACHETIMEOUT', 'Cache timeout'); +@define('PLUGIN_EVENT_STATISTICS_SHOW_CACHETIMEOUT_DESC', 'How long may the statistics be shown before they get refreshed? Setting this to a high number of minutes will improve performance, but might not reflect the actual data if set too high.'); +@define('PLUGIN_EVENT_STATISTICS_TEXT', 'Formatting text'); +@define('PLUGIN_EVENT_STATISTICS_TEXT_DESC', 'Use %s as placeholder for the number/text'); +@define('PLUGIN_EVENT_STATISTICS_TEXT_LASTENTRY', 'Last entry: %s'); +@define('PLUGIN_EVENT_STATISTICS_TEXT_ENTRYCOUNT', '%s entries written'); +@define('PLUGIN_EVENT_STATISTICS_TEXT_COMMENTCOUNT', '%s comments have been made'); +@define('PLUGIN_EVENT_STATISTICS_TEXT_MONTHVISITORS', '%s visitor(s) this month'); diff --git a/plugins/serendipity_event_statistics/serendipity_plugin_statistics.php b/plugins/serendipity_event_statistics/serendipity_plugin_statistics.php new file mode 100644 index 0000000..3bb0428 --- /dev/null +++ b/plugins/serendipity_event_statistics/serendipity_plugin_statistics.php @@ -0,0 +1,180 @@ +title = $this->get_config('title', $this->title); + + $propbag->add('name', PLUGIN_EVENT_STATISTICS_NAME); + $propbag->add('description', PLUGIN_EVENT_STATISTICS_NAME); + $propbag->add('stackable', true); + $propbag->add('author', 'Garvin Hicking'); + $propbag->add('version', '1.0'); + $propbag->add('requirements', array( + 'serendipity' => '0.8', + 'smarty' => '2.6.7', + 'php' => '4.1.0' + )); + $propbag->add('groups', array('STATISTICS')); + $propbag->add('configuration', array( + 'title', + 'show_lastentry', + 'text_lastentry', + 'show_entrycount', + 'text_entrycount', + 'show_commentcount', + 'text_commentcount', + 'show_monthvisitors', + 'text_monthvisitors', + 'cachetimeout' + )); + } + + function introspect_config_item($name, &$propbag) + { + switch($name) { + + case 'cachetimeout': + $propbag->add('type', 'string'); + $propbag->add('name', PLUGIN_EVENT_STATISTICS_SHOW_CACHETIMEOUT); + $propbag->add('description', PLUGIN_EVENT_STATISTICS_SHOW_CACHETIMEOUT_DESC); + $propbag->add('default', 60); + break; + + case 'show_lastentry': + $propbag->add('type', 'boolean'); + $propbag->add('name', PLUGIN_EVENT_STATISTICS_SHOW_LASTENTRY); + $propbag->add('description', ''); + $propbag->add('default', true); + break; + + case 'show_entrycount': + $propbag->add('type', 'boolean'); + $propbag->add('name', PLUGIN_EVENT_STATISTICS_SHOW_ENTRYCOUNT); + $propbag->add('description', ''); + $propbag->add('default', true); + break; + + case 'show_commentcount': + $propbag->add('type', 'boolean'); + $propbag->add('name', PLUGIN_EVENT_STATISTICS_SHOW_COMMENTCOUNT); + $propbag->add('description', ''); + $propbag->add('default', true); + break; + + case 'show_monthvisitors': + $propbag->add('type', 'boolean'); + $propbag->add('name', PLUGIN_EVENT_STATISTICS_SHOW_MONTHVISITORS); + $propbag->add('description', ''); + $propbag->add('default', true); + break; + + case 'text_lastentry': + $propbag->add('type', 'string'); + $propbag->add('name', PLUGIN_EVENT_STATISTICS_TEXT); + $propbag->add('description', PLUGIN_EVENT_STATISTICS_TEXT_DESC); + $propbag->add('default', PLUGIN_EVENT_STATISTICS_TEXT_LASTENTRY); + break; + + case 'text_entrycount': + $propbag->add('type', 'string'); + $propbag->add('name', PLUGIN_EVENT_STATISTICS_TEXT); + $propbag->add('description', PLUGIN_EVENT_STATISTICS_TEXT_DESC); + $propbag->add('default', PLUGIN_EVENT_STATISTICS_TEXT_ENTRYCOUNT); + break; + + case 'text_commentcount': + $propbag->add('type', 'string'); + $propbag->add('name', PLUGIN_EVENT_STATISTICS_TEXT); + $propbag->add('description', PLUGIN_EVENT_STATISTICS_TEXT_DESC); + $propbag->add('default', PLUGIN_EVENT_STATISTICS_TEXT_COMMENTCOUNT); + break; + + case 'text_monthvisitors': + $propbag->add('type', 'string'); + $propbag->add('name', PLUGIN_EVENT_STATISTICS_TEXT); + $propbag->add('description', PLUGIN_EVENT_STATISTICS_TEXT_DESC); + $propbag->add('default', PLUGIN_EVENT_STATISTICS_TEXT_MONTHVISITORS); + break; + + case 'title': + $propbag->add('type', 'string'); + $propbag->add('name', TITLE); + $propbag->add('description', ''); + $propbag->add('default', PLUGIN_EVENT_STATISTICS_NAME); + break; + + default: + return false; + } + return true; + } + + function generate_content(&$title) + { + global $serendipity; + $title = $this->get_config('title', $this->title); + $cachetime = $this->get_config('cachetimeout', 60) * 60; // turn to seconds + $cachef = $serendipity['serendipityPath'] . 'templates_c/statistics_cache.html'; + + if (!file_exists($cachef) || filesize($cachef) == 0 || filemtime($cachef) < (time() - $cachetime)) { + // Create statistics + + $content = ''; + if (serendipity_db_bool($this->get_config('show_lastentry'))) { + $res = serendipity_db_query("SELECT timestamp FROM {$serendipity['dbPrefix']}entries WHERE isdraft = 'false' AND timestamp <= " . time() . " ORDER BY timestamp DESC LIMIT 1", true, 'assoc'); + if (is_array($res) && isset($res['timestamp'])) { + $content .= '
' . sprintf($this->get_config('text_lastentry'), '' . htmlspecialchars(serendipity_strftime(DATE_FORMAT_SHORT, $res['timestamp'])) . '') . "
\n"; + } + } + + if (serendipity_db_bool($this->get_config('show_entrycount'))) { + $res = serendipity_db_query("SELECT count(id) as entrycount FROM {$serendipity['dbPrefix']}entries WHERE isdraft = 'false' AND timestamp <= " . time(), true, 'assoc'); + if (is_array($res) && isset($res['entrycount'])) { + $content .= '
' . sprintf($this->get_config('text_entrycount'), '' . $res['entrycount'] . '') . "
\n"; + } + } + + if (serendipity_db_bool($this->get_config('show_commentcount'))) { + $res = serendipity_db_query("SELECT count(id) AS commentcount FROM {$serendipity['dbPrefix']}comments WHERE type = 'NORMAL' AND status = 'approved'", true, 'assoc'); + if (is_array($res) && isset($res['commentcount'])) { + $content .= '
' . sprintf($this->get_config('text_commentcount'), '' . $res['commentcount'] . '') . "
\n"; + } + } + + if (serendipity_db_bool($this->get_config('show_monthvisitors'))) { + $res = serendipity_db_query("SELECT count(counter_id) AS monthvisitors FROM {$serendipity['dbPrefix']}visitors WHERE day LIKE '" . date('%Y-%m') . "-%'", true, 'assoc'); + if (is_array($res) && isset($res['monthvisitors'])) { + $content .= '
' . sprintf($this->get_config('text_monthvisitors'), '' . $res['monthvisitors'] . '') . "
\n"; + } + } + + // Write cache + $fp = @fopen($cachef, 'w'); + if ($fp) { + fwrite($fp, $content); + fclose($fp); + } + } else { + // Read from cache + $content = @file_get_contents($cachef); + } + + echo $content; + } +} + +/* vim: set sts=4 ts=4 expandtab : */ -- 2.39.5