From: garvinhicking Date: Thu, 8 Dec 2005 10:29:06 +0000 (+0000) Subject: show "visitors online" X-Git-Tag: 1.0~245 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e8dd678ed231a5a4151848870b0806fffcb71753;p=s9y.git show "visitors online" --- diff --git a/plugins/serendipity_event_statistics/lang_en.inc.php b/plugins/serendipity_event_statistics/lang_en.inc.php index f5864ae..1db1a59 100644 --- a/plugins/serendipity_event_statistics/lang_en.inc.php +++ b/plugins/serendipity_event_statistics/lang_en.inc.php @@ -85,3 +85,6 @@ @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'); + +@define('PLUGIN_EVENT_STATISTICS_SHOW_CURRENTVISITORS', 'Show number of current visitors (aggregate past 15 minutes)'); +@define('PLUGIN_EVENT_STATISTICS_TEXT_CURRENTVISITORS', '%s visitor(s) online'); diff --git a/plugins/serendipity_event_statistics/serendipity_event_statistics.php b/plugins/serendipity_event_statistics/serendipity_event_statistics.php index 810b036..b3e84b8 100644 --- a/plugins/serendipity_event_statistics/serendipity_event_statistics.php +++ b/plugins/serendipity_event_statistics/serendipity_event_statistics.php @@ -107,6 +107,9 @@ class serendipity_event_statistics extends serendipity_event if ($found == 'no'){ $this->countVisitor(); } + } else { + // Update visitor timestamp + $this->updateVisitor(); } break; @@ -467,8 +470,18 @@ class serendipity_event_statistics extends serendipity_event } } + function updateVisitor() { + global $serendipity; + + $time = date('H:i'); + $day = date('Y-m-d'); + return serendipity_db_query("UPDATE {$serendipity['dbPrefix']}visitors + SET time = '$time', + day = '$day' + WHERE sessID = '" . serendipity_db_escape_string(strip_tags(session_id())) . "'"); + } + function countVisitor(){ - global $serendipity; $referer = $_SERVER['HTTP_REFERER']; diff --git a/plugins/serendipity_event_statistics/serendipity_plugin_statistics.php b/plugins/serendipity_event_statistics/serendipity_plugin_statistics.php index 3bb0428..ccc6cf9 100644 --- a/plugins/serendipity_event_statistics/serendipity_plugin_statistics.php +++ b/plugins/serendipity_event_statistics/serendipity_plugin_statistics.php @@ -39,6 +39,8 @@ class serendipity_plugin_statistics extends serendipity_plugin 'text_commentcount', 'show_monthvisitors', 'text_monthvisitors', + 'show_currentvisitors', + 'text_currentvisitors', 'cachetimeout' )); } @@ -110,6 +112,20 @@ class serendipity_plugin_statistics extends serendipity_plugin $propbag->add('default', PLUGIN_EVENT_STATISTICS_TEXT_MONTHVISITORS); break; + case 'text_currentvisitors': + $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_CURRENTVISITORS); + break; + + case 'show_currentvisitors': + $propbag->add('type', 'boolean'); + $propbag->add('name', PLUGIN_EVENT_STATISTICS_SHOW_CURRENTVISITORS); + $propbag->add('description', ''); + $propbag->add('default', true); + break; + case 'title': $propbag->add('type', 'string'); $propbag->add('name', TITLE); @@ -123,6 +139,11 @@ class serendipity_plugin_statistics extends serendipity_plugin return true; } + function cleanup() { + global $serendipity; + @unlink($serendipity['serendipityPath'] . 'templates_c/statistics_cache.html'); + } + function generate_content(&$title) { global $serendipity; @@ -156,12 +177,26 @@ class serendipity_plugin_statistics extends serendipity_plugin } 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'); + $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"; } } + // This one is MySQL specific. Don't know how postgreSQL does it. + if (serendipity_db_bool($this->get_config('show_currentvisitors'))) { + $max = time(); + $min = $max - (15 * 60); + $max_ts = date('Hi', $max); + $min_ts = date('Hi', $min); + + $q = "SELECT count(counter_id) AS currentvisitors FROM {$serendipity['dbPrefix']}visitors WHERE day LIKE '" . date('Y-m-d') . "' AND (REPLACE(time, ':', '') BETWEEN $min_ts AND $max_ts)"; + $res = serendipity_db_query($q, true, 'assoc'); + if (is_array($res) && isset($res['currentvisitors'])) { + $content .= '
' . sprintf($this->get_config('text_currentvisitors'), '' . $res['currentvisitors'] . '') . "
\n"; + } + } + // Write cache $fp = @fopen($cachef, 'w'); if ($fp) {