'text_commentcount',
'show_monthvisitors',
'text_monthvisitors',
+ 'show_currentvisitors',
+ 'text_currentvisitors',
'cachetimeout'
));
}
$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);
return true;
}
+ function cleanup() {
+ global $serendipity;
+ @unlink($serendipity['serendipityPath'] . 'templates_c/statistics_cache.html');
+ }
+
function generate_content(&$title)
{
global $serendipity;
}
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 .= '<div class="stat_monthvisitors">' . sprintf($this->get_config('text_monthvisitors'), '<span class="stat_number">' . $res['monthvisitors'] . '</span>') . "</div>\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 .= '<div class="stat_currentvisitors">' . sprintf($this->get_config('text_currentvisitors'), '<span class="stat_number">' . $res['currentvisitors'] . '</span>') . "</div>\n";
+ }
+ }
+
// Write cache
$fp = @fopen($cachef, 'w');
if ($fp) {