]> git.mjollnir.org Git - s9y.git/commitdiff
Fix by roti
authorgarvinhicking <garvinhicking>
Tue, 4 Mar 2008 09:44:35 +0000 (09:44 +0000)
committergarvinhicking <garvinhicking>
Tue, 4 Mar 2008 09:44:35 +0000 (09:44 +0000)
plugins/serendipity_event_statistics/serendipity_plugin_statistics.php

index 3efb53c1eeeeee360bea350f8328ee2b873a5f4e..02d0f09b1ebd1ad6c83e0de6d6d4ca997f0c79f8 100644 (file)
@@ -44,6 +44,10 @@ class serendipity_plugin_statistics extends serendipity_plugin
                                              'text_commentcount',
                                              'show_monthvisitors',
                                              'text_monthvisitors',
+                                             'show_dayvisitors',
+                                             'text_dayvisitors',
+                                             'show_weekvisitors',
+                                             'text_weekvisitors',
                                              'show_currentvisitors',
                                              'text_currentvisitors',
                                              'cachetimeout'
@@ -89,6 +93,20 @@ class serendipity_plugin_statistics extends serendipity_plugin
                 $propbag->add('default',     true);
                 break;
 
+            case 'show_dayvisitors':
+                $propbag->add('type',        'boolean');
+                $propbag->add('name',        PLUGIN_EVENT_STATISTICS_SHOW_DAYVISITORS);
+                $propbag->add('description', '');
+                $propbag->add('default',     true);
+                break;
+
+            case 'show_weekvisitors':
+                $propbag->add('type',        'boolean');
+                $propbag->add('name',        PLUGIN_EVENT_STATISTICS_SHOW_WEEKVISITORS);
+                $propbag->add('description', '');
+                $propbag->add('default',     true);
+                break;
+
             case 'text_lastentry':
                 $propbag->add('type',        'string');
                 $propbag->add('name',        PLUGIN_EVENT_STATISTICS_TEXT);
@@ -117,6 +135,20 @@ class serendipity_plugin_statistics extends serendipity_plugin
                 $propbag->add('default',     PLUGIN_EVENT_STATISTICS_TEXT_MONTHVISITORS);
                 break;
 
+            case 'text_dayvisitors':
+                $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_DAYVISITORS);
+                break;
+
+            case 'text_weekvisitors':
+                $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_WEEKVISITORS);
+                break;
+
             case 'text_currentvisitors':
                 $propbag->add('type',        'string');
                 $propbag->add('name',        PLUGIN_EVENT_STATISTICS_TEXT);
@@ -158,7 +190,14 @@ class serendipity_plugin_statistics extends serendipity_plugin
 
         if (!file_exists($cachef) || filesize($cachef) == 0 || filemtime($cachef) < (time() - $cachetime)) {
             // Create statistics
-                       list($year, $month, $day) = split('-', date('Y-m-d'));
+            list($year, $month, $day) = split('-', date('Y-m-d'));
+            $lastmonday = date('Ymd', strtotime('last monday'));
+            $nextsunday = date('Ymd', strtotime('next sunday'));
+            if (date('w', strtotime('today') ) == "1" ) { // now it is monday
+                $lastmonday = date('Ymd', strtotime('today'));
+            } else if (date('w', strtotime('today') ) == "0" ) { // now it is sunday
+                $nextsunday = date('Ymd', strtotime('today'));
+            }             
 
             $content = '';
             if (serendipity_db_bool($this->get_config('show_lastentry'))) {
@@ -189,14 +228,34 @@ class serendipity_plugin_statistics extends serendipity_plugin
                 }
             }
 
+            if (serendipity_db_bool($this->get_config('show_dayvisitors'))) {
+                $res = serendipity_db_query("SELECT sum(visits) AS dayvisitors FROM {$serendipity['dbPrefix']}visitors_count WHERE year='".$year."' AND month='".$month."' AND day='".$day."'", true, 'assoc');
+                if (is_array($res) && isset($res['dayvisitors'])) {
+                    $content .= '<div class="stat_dayhvisitors">' . sprintf($this->get_config('text_dayvisitors'), '<span class="stat_number">' . $res['dayvisitors'] . '</span>') . "</div>\n";
+                }
+            }
+
+            if (serendipity_db_bool($this->get_config('show_weekvisitors'))) {
+                $res = serendipity_db_query("SELECT sum(visits) AS weekvisitors FROM {$serendipity['dbPrefix']}visitors_count WHERE year || month || day >= '".$lastmonday."' AND year || month || day <= '".$nextsunday."'", true, 'assoc');
+                if (is_array($res) && isset($res['weekvisitors'])) {
+                    $content .= '<div class="stat_weekhvisitors">' . sprintf($this->get_config('text_weekvisitors'), '<span class="stat_number">' . $res['weekvisitors'] . '</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)";
+                if ($serendipity['dbType'] == 'sqlite') {
+                    $max_ts = date('H:i', $max);
+                    $min_ts = date('H:i', $min);
+                    $q   = "SELECT count(counter_id) AS currentvisitors FROM {$serendipity['dbPrefix']}visitors WHERE day LIKE '" . date('Y-m-d') . "' AND (time BETWEEN '$min_ts' AND '$max_ts')";
+                } else {
+                    $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";
@@ -218,4 +277,4 @@ class serendipity_plugin_statistics extends serendipity_plugin
     }
 }
 
-/* vim: set sts=4 ts=4 expandtab : */
\ No newline at end of file
+/* vim: set sts=4 ts=4 expandtab : */