[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id: serendipity_plugin_comments.php 691 2005-11-13 06:58:40Z elf2000 $ 2 3 if (IN_serendipity !== true) { 4 die ("Don't hack!"); 5 } 6 7 8 // Probe for a language include with constants. Still include defines later on, if some constants were missing 9 $probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php'; 10 if (file_exists($probelang)) { 11 include $probelang; 12 } 13 14 include dirname(__FILE__) . '/lang_en.inc.php'; 15 16 class serendipity_plugin_statistics extends serendipity_plugin 17 { 18 var $title = PLUGIN_EVENT_STATISTICS_NAME; 19 20 function introspect(&$propbag) 21 { 22 global $serendipity; 23 24 $this->title = $this->get_config('title', $this->title); 25 26 $propbag->add('name', PLUGIN_EVENT_STATISTICS_NAME); 27 $propbag->add('description', PLUGIN_EVENT_STATISTICS_NAME); 28 $propbag->add('stackable', true); 29 $propbag->add('author', 'Arnan de Gans, Garvin Hicking'); 30 $propbag->add('version', '1.3'); 31 $propbag->add('requirements', array( 32 'serendipity' => '0.8', 33 'smarty' => '2.6.7', 34 'php' => '4.1.0' 35 )); 36 $propbag->add('groups', array('STATISTICS')); 37 $propbag->add('configuration', array( 38 'title', 39 'show_lastentry', 40 'text_lastentry', 41 'show_entrycount', 42 'text_entrycount', 43 'show_commentcount', 44 'text_commentcount', 45 'show_monthvisitors', 46 'text_monthvisitors', 47 'show_currentvisitors', 48 'text_currentvisitors', 49 'cachetimeout' 50 )); 51 } 52 53 function introspect_config_item($name, &$propbag) 54 { 55 switch($name) { 56 57 case 'cachetimeout': 58 $propbag->add('type', 'string'); 59 $propbag->add('name', PLUGIN_EVENT_STATISTICS_SHOW_CACHETIMEOUT); 60 $propbag->add('description', PLUGIN_EVENT_STATISTICS_SHOW_CACHETIMEOUT_DESC); 61 $propbag->add('default', 60); 62 break; 63 64 case 'show_lastentry': 65 $propbag->add('type', 'boolean'); 66 $propbag->add('name', PLUGIN_EVENT_STATISTICS_SHOW_LASTENTRY); 67 $propbag->add('description', ''); 68 $propbag->add('default', true); 69 break; 70 71 case 'show_entrycount': 72 $propbag->add('type', 'boolean'); 73 $propbag->add('name', PLUGIN_EVENT_STATISTICS_SHOW_ENTRYCOUNT); 74 $propbag->add('description', ''); 75 $propbag->add('default', true); 76 break; 77 78 case 'show_commentcount': 79 $propbag->add('type', 'boolean'); 80 $propbag->add('name', PLUGIN_EVENT_STATISTICS_SHOW_COMMENTCOUNT); 81 $propbag->add('description', ''); 82 $propbag->add('default', true); 83 break; 84 85 case 'show_monthvisitors': 86 $propbag->add('type', 'boolean'); 87 $propbag->add('name', PLUGIN_EVENT_STATISTICS_SHOW_MONTHVISITORS); 88 $propbag->add('description', ''); 89 $propbag->add('default', true); 90 break; 91 92 case 'text_lastentry': 93 $propbag->add('type', 'string'); 94 $propbag->add('name', PLUGIN_EVENT_STATISTICS_TEXT); 95 $propbag->add('description', PLUGIN_EVENT_STATISTICS_TEXT_DESC); 96 $propbag->add('default', PLUGIN_EVENT_STATISTICS_TEXT_LASTENTRY); 97 break; 98 99 case 'text_entrycount': 100 $propbag->add('type', 'string'); 101 $propbag->add('name', PLUGIN_EVENT_STATISTICS_TEXT); 102 $propbag->add('description', PLUGIN_EVENT_STATISTICS_TEXT_DESC); 103 $propbag->add('default', PLUGIN_EVENT_STATISTICS_TEXT_ENTRYCOUNT); 104 break; 105 106 case 'text_commentcount': 107 $propbag->add('type', 'string'); 108 $propbag->add('name', PLUGIN_EVENT_STATISTICS_TEXT); 109 $propbag->add('description', PLUGIN_EVENT_STATISTICS_TEXT_DESC); 110 $propbag->add('default', PLUGIN_EVENT_STATISTICS_TEXT_COMMENTCOUNT); 111 break; 112 113 case 'text_monthvisitors': 114 $propbag->add('type', 'string'); 115 $propbag->add('name', PLUGIN_EVENT_STATISTICS_TEXT); 116 $propbag->add('description', PLUGIN_EVENT_STATISTICS_TEXT_DESC); 117 $propbag->add('default', PLUGIN_EVENT_STATISTICS_TEXT_MONTHVISITORS); 118 break; 119 120 case 'text_currentvisitors': 121 $propbag->add('type', 'string'); 122 $propbag->add('name', PLUGIN_EVENT_STATISTICS_TEXT); 123 $propbag->add('description', PLUGIN_EVENT_STATISTICS_TEXT_DESC); 124 $propbag->add('default', PLUGIN_EVENT_STATISTICS_TEXT_CURRENTVISITORS); 125 break; 126 127 case 'show_currentvisitors': 128 $propbag->add('type', 'boolean'); 129 $propbag->add('name', PLUGIN_EVENT_STATISTICS_SHOW_CURRENTVISITORS); 130 $propbag->add('description', ''); 131 $propbag->add('default', true); 132 break; 133 134 case 'title': 135 $propbag->add('type', 'string'); 136 $propbag->add('name', TITLE); 137 $propbag->add('description', ''); 138 $propbag->add('default', PLUGIN_EVENT_STATISTICS_NAME); 139 break; 140 141 default: 142 return false; 143 } 144 return true; 145 } 146 147 function cleanup() { 148 global $serendipity; 149 @unlink($serendipity['serendipityPath'] . 'templates_c/statistics_cache.html'); 150 } 151 152 function generate_content(&$title) 153 { 154 global $serendipity; 155 $title = $this->get_config('title', $this->title); 156 $cachetime = $this->get_config('cachetimeout', 60) * 60; // turn to seconds 157 $cachef = $serendipity['serendipityPath'] . 'templates_c/statistics_cache.html'; 158 159 if (!file_exists($cachef) || filesize($cachef) == 0 || filemtime($cachef) < (time() - $cachetime)) { 160 // Create statistics 161 list($year, $month, $day) = split('-', date('Y-m-d')); 162 163 $content = ''; 164 if (serendipity_db_bool($this->get_config('show_lastentry'))) { 165 $res = serendipity_db_query("SELECT timestamp FROM {$serendipity['dbPrefix']}entries WHERE isdraft = 'false' AND timestamp <= " . time() . " ORDER BY timestamp DESC LIMIT 1", true, 'assoc'); 166 if (is_array($res) && isset($res['timestamp'])) { 167 $content .= '<div class="stat_lastentry">' . sprintf($this->get_config('text_lastentry'), '<span class="stat_string">' . htmlspecialchars(serendipity_strftime(DATE_FORMAT_SHORT, $res['timestamp'])) . '</span>') . "</div>\n"; 168 } 169 } 170 171 if (serendipity_db_bool($this->get_config('show_entrycount'))) { 172 $res = serendipity_db_query("SELECT count(id) as entrycount FROM {$serendipity['dbPrefix']}entries WHERE isdraft = 'false' AND timestamp <= " . time(), true, 'assoc'); 173 if (is_array($res) && isset($res['entrycount'])) { 174 $content .= '<div class="stat_entrycount">' . sprintf($this->get_config('text_entrycount'), '<span class="stat_number">' . $res['entrycount'] . '</span>') . "</div>\n"; 175 } 176 } 177 178 if (serendipity_db_bool($this->get_config('show_commentcount'))) { 179 $res = serendipity_db_query("SELECT count(id) AS commentcount FROM {$serendipity['dbPrefix']}comments WHERE type = 'NORMAL' AND status = 'approved'", true, 'assoc'); 180 if (is_array($res) && isset($res['commentcount'])) { 181 $content .= '<div class="stat_commentcount">' . sprintf($this->get_config('text_commentcount'), '<span class="stat_number">' . $res['commentcount'] . '</span>') . "</div>\n"; 182 } 183 } 184 185 if (serendipity_db_bool($this->get_config('show_monthvisitors'))) { 186 $res = serendipity_db_query("SELECT sum(visits) AS monthvisitors FROM {$serendipity['dbPrefix']}visitors_count WHERE year='".$year."' AND month='".$month."'", true, 'assoc'); 187 if (is_array($res) && isset($res['monthvisitors'])) { 188 $content .= '<div class="stat_monthvisitors">' . sprintf($this->get_config('text_monthvisitors'), '<span class="stat_number">' . $res['monthvisitors'] . '</span>') . "</div>\n"; 189 } 190 } 191 192 // This one is MySQL specific. Don't know how postgreSQL does it. 193 if (serendipity_db_bool($this->get_config('show_currentvisitors'))) { 194 $max = time(); 195 $min = $max - (15 * 60); 196 $max_ts = date('Hi', $max); 197 $min_ts = date('Hi', $min); 198 199 $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)"; 200 $res = serendipity_db_query($q, true, 'assoc'); 201 if (is_array($res) && isset($res['currentvisitors'])) { 202 $content .= '<div class="stat_currentvisitors">' . sprintf($this->get_config('text_currentvisitors'), '<span class="stat_number">' . $res['currentvisitors'] . '</span>') . "</div>\n"; 203 } 204 } 205 206 // Write cache 207 $fp = @fopen($cachef, 'w'); 208 if ($fp) { 209 fwrite($fp, $content); 210 fclose($fp); 211 } 212 } else { 213 // Read from cache 214 $content = @file_get_contents($cachef); 215 } 216 217 echo $content; 218 } 219 } 220 221 /* vim: set sts=4 ts=4 expandtab : */
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |