[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id: serendipity_event_statistics.php 1801 2007-07-26 10:10:27Z garvinhicking $ 2 3 if (IN_serendipity !== true) { 4 die ("Don't hack!"); 5 } 6 7 // Probe for a language include with constants. Still include defines later on, if some constants were missing 8 $probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php'; 9 if (file_exists($probelang)) { 10 include $probelang; 11 } 12 13 include dirname(__FILE__) . '/lang_en.inc.php'; 14 15 class serendipity_event_statistics extends serendipity_event 16 { 17 var $title = PLUGIN_EVENT_STATISTICS_NAME; 18 19 function introspect(&$propbag) 20 { 21 global $serendipity; 22 23 $propbag->add('name', PLUGIN_EVENT_STATISTICS_NAME); 24 $propbag->add('description', PLUGIN_EVENT_STATISTICS_DESC); 25 $propbag->add('stackable', false); 26 $propbag->add('author', 'Arnan de Gans, Garvin Hicking, Fredrik Sandberg, kalkin'); 27 $propbag->add('version', '1.48'); 28 $propbag->add('requirements', array( 29 'serendipity' => '0.8', 30 'smarty' => '2.6.7', 31 'php' => '4.1.0' 32 )); 33 $propbag->add('groups', array('STATISTICS')); 34 $propbag->add('event_hooks', array( 35 'backend_sidebar_entries' => true, 36 'backend_sidebar_entries_event_display_statistics' => true, 37 'frontend_configure' => true 38 )); 39 40 $propbag->add('configuration', array('max_items','ext_vis_stat','stat_all','banned_bots')); 41 } 42 43 function introspect_config_item($name, &$propbag) 44 { 45 switch($name) { 46 case 'max_items': 47 $propbag->add('type', 'string'); 48 $propbag->add('name', PLUGIN_EVENT_STATISTICS_MAX_ITEMS); 49 $propbag->add('description', PLUGIN_EVENT_STATISTICS_MAX_ITEMS_DESC); 50 $propbag->add('default', 20); 51 break; 52 53 54 case 'ext_vis_stat': 55 $select = array('no' => PLUGIN_EVENT_STATISTICS_EXT_OPT1, 56 'yesBot' => PLUGIN_EVENT_STATISTICS_EXT_OPT2, 57 'yesTop' => PLUGIN_EVENT_STATISTICS_EXT_OPT3); 58 59 $propbag->add('type', 'select'); 60 $propbag->add('name', PLUGIN_EVENT_STATISTICS_EXT_ADD); 61 $propbag->add('description', PLUGIN_EVENT_STATISTICS_EXT_ADD_DESC); 62 $propbag->add('select_values', $select); 63 $propbag->add('default', 'no'); 64 65 break; 66 67 case 'stat_all': 68 $select = array('no' => PLUGIN_EVENT_STATISTICS_EXT_ALL1, 69 'yes' => PLUGIN_EVENT_STATISTICS_EXT_ALL2); 70 71 $propbag->add('type', 'select'); 72 $propbag->add('name', PLUGIN_EVENT_STATISTICS_EXT_ALL); 73 $propbag->add('description', PLUGIN_EVENT_STATISTICS_EXT_ALL_DESC); 74 $propbag->add('select_values', $select); 75 $propbag->add('default', 'yes'); 76 77 break; 78 79 case 'banned_bots': 80 $select = array('yes' => PLUGIN_EVENT_STATISTICS_BANNED_HOSTS1, 81 'no' => PLUGIN_EVENT_STATISTICS_BANNED_HOSTS2); 82 83 $propbag->add('type', 'select'); 84 $propbag->add('name', PLUGIN_EVENT_STATISTICS_BANNED_HOSTS); 85 $propbag->add('description', PLUGIN_EVENT_STATISTICS_BANNED_HOSTS_DESC); 86 $propbag->add('select_values', $select); 87 $propbag->add('default', 'yes'); 88 89 break; 90 } 91 92 return true; 93 } 94 95 function generate_content(&$title) { 96 $title = $this->title; 97 } 98 99 function event_hook($event, &$bag, &$eventData) { 100 global $serendipity; 101 102 $hooks = &$bag->get('event_hooks'); 103 104 if (isset($hooks[$event])) { 105 switch($event) { 106 107 case 'frontend_configure': 108 if ($this->get_config('ext_vis_stat') == 'no') { 109 return; 110 } 111 112 //checking if db tables exists, otherwise install them 113 $tableChecker = serendipity_db_query("SELECT counter_id FROM {$serendipity['dbPrefix']}visitors LIMIT 1", true); 114 if (!is_array($tableChecker)) { 115 $this->createTables(); 116 } 117 118 if ($this->get_config('db_indices_created', 'false') !== '1') { 119 $this->updateTables(); 120 } 121 122 //Unique visitors are beeing registered and counted here. Calling function below. 123 $sessionChecker = serendipity_db_query("SELECT count(sessID) FROM {$serendipity['dbPrefix']}visitors WHERE '".serendipity_db_escape_string(session_id())."' = sessID GROUP BY sessID", true); 124 if (!is_array($sessionChecker) || (is_array($sessionChecker)) && ($sessionChecker[0] == 0)) { 125 126 $referer = $useragent = $remoteaddr = 'unknown'; 127 128 // gathering intel 129 if ($_SERVER['REMOTE_ADDR']) { 130 $remoteaddr = $_SERVER['REMOTE_ADDR']; 131 } 132 if ($_SERVER['HTTP_USER_AGENT']) { 133 $useragent = substr($_SERVER['HTTP_USER_AGENT'], 0, 255); 134 } 135 if ($_SERVER['HTTP_REFERER']) { 136 $referer = substr($_SERVER['HTTP_REFERER'], 0, 255); 137 } 138 139 $found = 0; 140 141 // avoiding banned browsers 142 if ($this->get_config('banned_bots') == 'yes') { 143 // excludelist botagents 144 $banned_array = array( 145 '1' => "unknown", 146 '2' => "bot", 147 '3' => "slurpy", 148 '4' => "agent 007", 149 '5' => "ichiro", 150 '6' => "ia_archiver", 151 '7' => "zyborg", 152 '8' => "linkwalker", 153 '9' => "crawler", 154 '10' => "python", 155 '11' => "w3c_validator", 156 '12' => "almaden", 157 '13' => "topicspy", 158 '14' => "poodle predictor", 159 '15' => "link checker pro", 160 '16' => "xenu link sleuth", 161 '17' => "iconsurf", 162 '18' => "zoe indexer", 163 '19' => "grub-client", 164 '20' => "spider", 165 '21' => "pompos", 166 '22' => "virus_detector", 167 '23' => "bot", 168 '24' => "Wells Search II", 169 '25' => "Dumbot", 170 '26' => "GeoBot", 171 '27' => "DigExt", 172 '28' => "Jeeves/Teoma", 173 '29' => "FeedBurner", 174 '30' => "Technorati", 175 '31' => "Java/1.5.0_10", 176 '32' => "Java/1.5.0_06", 177 '33' => "MarsEdit", 178 '34' => "Blogslive", 179 '35' => "XMLRPCCocoa", 180 '36' => "Google", 181 '37' => "MagpieRSS", 182 '38' => "Sphere Scout", 183 '39' => "BlogCorpusReader", 184 '41' => "libwww-perl", 185 '42' => "WordPress", 186 '43' => "ping.wordblog.de", 187 '44' => "PEAR HTTP_Request", 188 '45' => "Java/1.5.0_07", 189 '46' => "BlogPulseLive(support@blogpulse.com)", 190 '47' => "TrackBack", 191 '48' => "Blogdimension", 192 '49' => "Yahoo" 193 ); 194 195 foreach($banned_array AS $ban) { 196 if (stristr($useragent, $ban) !== false) { 197 $found = 1; 198 break; 199 } 200 } 201 } 202 203 if ($found == 0){ 204 $this->countVisitor($useragent, $remoteaddr, $referer); 205 } 206 } else { 207 // Update visitor timestamp 208 $this->updateVisitor(); 209 } 210 211 break; 212 case 'backend_sidebar_entries': 213 ?> 214 <li class="serendipitySideBarMenuLink serendipitySideBarMenuEntryLinks"><a href="?serendipity[adminModule]=event_display&serendipity[adminAction]=statistics"><?php echo PLUGIN_EVENT_STATISTICS_NAME; ?></a></li> 215 <?php 216 217 break; 218 219 case 'backend_sidebar_entries_event_display_statistics': 220 $max_items = $this->get_config('max_items'); 221 $ext_vis_stat = $this->get_config('ext_vis_stat'); 222 223 if (!$max_items || !is_numeric($max_items) || $max_items < 1) { 224 $max_items = 20; 225 } 226 227 if ($ext_vis_stat == 'yesTop') { 228 $this->extendedVisitorStatistics($max_items); 229 } 230 231 232 if ($this->get_config('stat_all') == 'yes') { 233 $first_entry = serendipity_db_query("SELECT timestamp FROM {$serendipity['dbPrefix']}entries ORDER BY timestamp ASC limit 1", true); 234 $last_entry = serendipity_db_query("SELECT timestamp FROM {$serendipity['dbPrefix']}entries ORDER BY timestamp DESC limit 1", true); 235 $total_count = serendipity_db_query("SELECT count(id) FROM {$serendipity['dbPrefix']}entries", true); 236 $draft_count = serendipity_db_query("SELECT count(id) FROM {$serendipity['dbPrefix']}entries WHERE isdraft = 'true'", true); 237 $publish_count = serendipity_db_query("SELECT count(id) FROM {$serendipity['dbPrefix']}entries WHERE isdraft = 'false'", true); 238 $author_rows = serendipity_db_query("SELECT author, count(author) as entries FROM {$serendipity['dbPrefix']}entries GROUP BY author ORDER BY author"); 239 $category_count = serendipity_db_query("SELECT count(categoryid) FROM {$serendipity['dbPrefix']}category", true); 240 $cat_sql = "SELECT c.category_name, count(e.id) as postings 241 FROM {$serendipity['dbPrefix']}entrycat ec, 242 {$serendipity['dbPrefix']}category c, 243 {$serendipity['dbPrefix']}entries e 244 WHERE ec.categoryid = c.categoryid AND ec.entryid = e.id 245 GROUP BY ec.categoryid, c.category_name 246 ORDER BY postings DESC"; 247 $category_rows = serendipity_db_query($cat_sql); 248 249 $image_count = serendipity_db_query("SELECT count(id) FROM {$serendipity['dbPrefix']}images", true); 250 $image_rows = serendipity_db_query("SELECT extension, count(id) AS images FROM {$serendipity['dbPrefix']}images GROUP BY extension ORDER BY images DESC"); 251 252 $subscriber_count = count(serendipity_db_query("SELECT count(id) FROM {$serendipity['dbPrefix']}comments WHERE type = 'NORMAL' AND subscribed = 'true' GROUP BY email")); 253 $subscriber_rows = serendipity_db_query("SELECT e.timestamp, e.id, e.title, count(c.id) as postings 254 FROM {$serendipity['dbPrefix']}comments c, 255 {$serendipity['dbPrefix']}entries e 256 WHERE e.id = c.entry_id AND type = 'NORMAL' AND subscribed = 'true' 257 GROUP BY e.id, c.email, e.title, e.timestamp 258 ORDER BY postings DESC 259 LIMIT $max_items"); 260 261 $comment_count = serendipity_db_query("SELECT count(id) FROM {$serendipity['dbPrefix']}comments WHERE type = 'NORMAL'", true); 262 $comment_rows = serendipity_db_query("SELECT e.timestamp, e.id, e.title, count(c.id) as postings 263 FROM {$serendipity['dbPrefix']}comments c, 264 {$serendipity['dbPrefix']}entries e 265 WHERE e.id = c.entry_id AND type = 'NORMAL' 266 GROUP BY e.id, e.title, e.timestamp 267 ORDER BY postings DESC 268 LIMIT $max_items"); 269 270 $commentor_rows = serendipity_db_query("SELECT author, max(email) as email, max(url) as url, count(id) as postings 271 FROM {$serendipity['dbPrefix']}comments c 272 WHERE type = 'NORMAL' 273 GROUP BY author 274 ORDER BY postings DESC 275 LIMIT $max_items"); 276 277 $tb_count = serendipity_db_query("SELECT count(id) FROM {$serendipity['dbPrefix']}comments WHERE type = 'TRACKBACK'", true); 278 $tb_rows = serendipity_db_query("SELECT e.timestamp, e.id, e.title, count(c.id) as postings 279 FROM {$serendipity['dbPrefix']}comments c, 280 {$serendipity['dbPrefix']}entries e 281 WHERE e.id = c.entry_id AND type = 'TRACKBACK' 282 GROUP BY e.timestamp, e.id, e.title 283 ORDER BY postings DESC 284 LIMIT $max_items"); 285 286 $tbr_rows = serendipity_db_query("SELECT author, max(email) as email, max(url) as url, count(id) as postings 287 FROM {$serendipity['dbPrefix']}comments c 288 WHERE type = 'TRACKBACK' 289 GROUP BY author 290 ORDER BY postings DESC 291 LIMIT $max_items"); 292 293 $length = serendipity_db_query("SELECT SUM(LENGTH(body) + LENGTH(extended)) FROM {$serendipity['dbPrefix']}entries", true); 294 $length_rows = serendipity_db_query("SELECT id, title, (LENGTH(body) + LENGTH(extended)) as full_length FROM {$serendipity['dbPrefix']}entries ORDER BY full_length DESC LIMIT $max_items"); 295 ?> 296 <h3><?php echo PLUGIN_EVENT_STATISTICS_OUT_STATISTICS; ?></h3> 297 298 <div style="margin: 5px; padding: 5px"> 299 <dl> 300 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_FIRST_ENTRY; ?></strong></dt> 301 <dd><?php echo serendipity_formatTime(DATE_FORMAT_ENTRY . ' %H:%m', $first_entry[0]); ?></dd> 302 <br /> 303 304 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_LAST_ENTRY; ?></strong></dt> 305 <dd><?php echo serendipity_formatTime(DATE_FORMAT_ENTRY . ' %H:%m', $last_entry[0]); ?></dd> 306 <br /> 307 <hr /> 308 <br /> 309 310 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_TOTAL_ENTRIES; ?></strong></dt> 311 <dd><?php echo $total_count[0]; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_ENTRIES; ?></dd> 312 <br /> 313 <dl> 314 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_TOTAL_PUBLIC; ?></strong></dt> 315 <dd><?php echo $publish_count[0]; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_ENTRIES; ?></dd> 316 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_TOTAL_DRAFTS; ?></strong></dt> 317 <dd><?php echo $draft_count[0]; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_ENTRIES; ?></dd> 318 </dl> 319 <br /> 320 <hr /> 321 <br /> 322 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_PER_AUTHOR; ?></strong></dt> 323 <br /> 324 <dl> 325 <?php 326 if (is_array($author_rows)) { 327 foreach($author_rows AS $author => $author_stat) { 328 ?> 329 <dt><strong><?php echo $author_stat['author']; ?></strong></dt> 330 <dd><?php echo $author_stat['entries']; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_ENTRIES; ?> (<?php echo 100*round($author_stat['entries'] / max($total_count[0], 1), 3); ?>%)</dd> 331 <?php 332 } 333 } 334 ?> 335 </dl> 336 <br /> 337 <hr /> 338 <br /> 339 340 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_CATEGORIES; ?></strong></dt> 341 <dd><?php echo $category_count[0]; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_CATEGORIES2; ?></dd> 342 <br /> 343 344 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_DISTRIBUTION_CATEGORIES; ?></strong></dt> 345 <dl> 346 <?php 347 if (is_array($category_rows)) { 348 foreach($category_rows AS $category => $cat_stat) { 349 ?> 350 <dt><strong><?php echo $cat_stat['category_name']; ?></strong></dt> 351 <dd><?php echo $cat_stat['postings']; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_DISTRIBUTION_CATEGORIES2; ?></dd> 352 <?php 353 } 354 } 355 ?> 356 </dl> 357 <br /> 358 <hr /> 359 <br /> 360 361 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_UPLOADED_IMAGES; ?></strong></dt> 362 <dd><?php echo $image_count[0]; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_UPLOADED_IMAGES2; ?></dd> 363 <br /> 364 365 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_DISTRIBUTION_IMAGES; ?></strong></dt> 366 <dl> 367 <?php 368 if (is_array($image_rows)) { 369 foreach($image_rows AS $image => $image_stat) { 370 ?> 371 <dt><strong><?php echo $image_stat['extension']; ?></strong></dt> 372 <dd><?php echo $image_stat['images']; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_DISTRIBUTION_IMAGES2; ?></dd> 373 <?php 374 } 375 } 376 ?> 377 </dl> 378 <br /> 379 <hr /> 380 <br /> 381 382 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_COMMENTS; ?></strong></dt> 383 <dd><?php echo $comment_count[0]; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_COMMENTS2; ?></dd> 384 <br /> 385 386 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_COMMENTS3; ?></strong></dt> 387 <dl> 388 <?php 389 if (is_array($comment_rows)) { 390 foreach($comment_rows AS $comment => $com_stat) { 391 ?> 392 <dt><strong><a href="<?php echo serendipity_archiveURL($com_stat['id'], $com_stat['title'], 'serendipityHTTPPath', true, array('timestamp' => $com_stat['timestamp'])); ?>"><?php echo $com_stat['title']; ?></a></strong></dt> 393 <dd><?php echo $com_stat['postings']; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_COMMENTS2; ?></dd> 394 <?php 395 } 396 } 397 ?> 398 </dl> 399 <br /> 400 401 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_TOPCOMMENTS; ?></strong></dt> 402 <dl> 403 <?php 404 if (is_array($commentor_rows)) { 405 foreach($commentor_rows AS $comment => $com_stat) { 406 $link_start = ''; 407 $link_end = ''; 408 $link_url = ''; 409 410 if (!empty($com_stat['email'])) { 411 $link_start = '<a href="mailto:' . htmlspecialchars($com_stat['email']) . '">'; 412 $link_end = '</a>'; 413 } 414 415 if (!empty($com_stat['url'])) { 416 $link_url = ' (<a href="' . htmlspecialchars($com_stat['url']) . '">' . PLUGIN_EVENT_STATISTICS_OUT_LINK . '</a>)'; 417 } 418 419 if (empty($com_stat['author'])) { 420 $com_stat['author'] = ANONYMOUS; 421 } 422 ?> 423 <dt><strong><?php echo $link_start . $com_stat['author'] . $link_end . $link_url; ?> </strong></dt> 424 <dd><?php echo $com_stat['postings']; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_COMMENTS2; ?></dd> 425 <?php 426 } 427 } 428 ?> 429 </dl> 430 <br /> 431 <hr /> 432 <br /> 433 434 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_SUBSCRIBERS; ?></strong></dt> 435 <dd><?php echo $subscriber_count; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_SUBSCRIBERS2; ?></dd> 436 <br /> 437 438 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_TOPSUBSCRIBERS; ?></strong></dt> 439 <dl> 440 <?php 441 if (is_array($subscriber_rows)) { 442 foreach($subscriber_rows AS $subscriber => $subscriber_stat) { 443 ?> 444 <dt><strong><a href="<?php echo serendipity_archiveURL($subscriber_stat['id'], $subscriber_stat['title'], 'serendipityHTTPPath', true, array('timestamp' => $subscriber_stat['timestamp'])); ?>"><?php echo $subscriber_stat['title']; ?></a></strong></dt> 445 <dd><?php echo $subscriber_stat['postings']; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_TOPSUBSCRIBERS2; ?></dd> 446 <?php 447 } 448 } 449 ?> 450 </dl> 451 <br /> 452 <hr /> 453 <br /> 454 455 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_TRACKBACKS; ?></strong></dt> 456 <dd><?php echo $tb_count[0]; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_TRACKBACKS2; ?></dd> 457 <br /> 458 459 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_TOPTRACKBACK; ?></strong></dt> 460 <dl> 461 <?php 462 if (is_array($tb_rows)) { 463 foreach($tb_rows AS $tb => $tb_stat) { 464 ?> 465 <dt><strong><a href="<?php echo serendipity_archiveURL($tb_stat['id'], $tb_stat['title'], 'serendipityHTTPPath', true, array('timestamp' => $tb_stat['timestamp'])); ?>"><?php echo $tb_stat['title']; ?></a></strong></dt> 466 <dd><?php echo $tb_stat['postings']; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_TOPTRACKBACK2; ?></dd> 467 <?php 468 } 469 } 470 ?> 471 </dl> 472 <br /> 473 474 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_TOPTRACKBACKS3; ?></strong></dt> 475 <dl> 476 <?php 477 if (is_array($tbr_rows)) { 478 foreach($tbr_rows AS $tb => $tb_stat) { 479 if (empty($tb_stat['author'])) { 480 $tb_stat['author'] = ANONYMOUS; 481 } 482 ?> 483 <dt><strong><a href="<?php echo htmlspecialchars($tb_stat['url']); ?>"><?php echo htmlspecialchars($tb_stat['author']); ?></a></strong></dt> 484 <dd><?php echo $tb_stat['postings']; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_TOPTRACKBACK2; ?></dd> 485 <?php 486 } 487 } 488 ?> 489 </dl> 490 <br /> 491 <hr /> 492 <br /> 493 494 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_COMMENTS_PER_ARTICLE; ?></strong></dt> 495 <dd><?php echo round($comment_count[0] / max($publish_count[0], 1), 2); ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_COMMENTS_PER_ARTICLE2; ?></dd> 496 <br /> 497 498 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_TRACKBACKS_PER_ARTICLE; ?></strong></dt> 499 <dd><?php echo round($tb_count[0] / max($publish_count[0], 1), 2); ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_TRACKBACKS_PER_ARTICLE2; ?></dd> 500 <br /> 501 502 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_ARTICLES_PER_DAY; ?></strong></dt> 503 <dd><?php echo round($publish_count[0] / ((time() - $first_entry[0]) / (60*60*24)), 2);?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_ARTICLES_PER_DAY2; ?></dd> 504 <br /> 505 506 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_ARTICLES_PER_WEEK; ?></strong></dt> 507 <dd><?php echo round($publish_count[0] / ((time() - $first_entry[0]) / (60*60*24*7)), 2);?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_ARTICLES_PER_WEEK2; ?></dd> 508 <br /> 509 510 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_ARTICLES_PER_MONTH; ?></strong></dt> 511 <dd><?php echo round($publish_count[0] / ((time() - $first_entry[0]) / (60*60*24*31)), 2);?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_ARTICLES_PER_MONTH2; ?></dd> 512 <br /> 513 <hr /> 514 <br /> 515 516 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_CHARS; ?></strong></dt> 517 <dd><?php echo $length[0]; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_CHARS2; ?></dd> 518 <br /> 519 520 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_OUT_CHARS_PER_ARTICLE; ?></strong></dt> 521 <dd><?php echo round($length[0] / max($publish_count[0], 1), 2); ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_CHARS_PER_ARTICLE2; ?></dd> 522 <br /> 523 524 <dt><strong><?php printf(PLUGIN_EVENT_STATISTICS_OUT_LONGEST_ARTICLES, $max_items); ?></strong></dt> 525 <br /> 526 <dl> 527 <?php 528 if (is_array($length_rows)) { 529 foreach($length_rows AS $tb => $length_stat) { 530 ?> 531 <dt><strong><a href="<?php echo serendipity_archiveURL($length_stat['id'], $length_stat['title'], 'serendipityHTTPPath', true, array('timestamp' => $length_stat['timestamp'])); ?>"><?php echo $length_stat['title']; ?></a></strong></dt> 532 <dd><?php echo $length_stat['full_length']; ?> <?php echo PLUGIN_EVENT_STATISTICS_OUT_CHARS2; ?></dd> 533 <?php 534 } 535 } 536 ?> 537 </dl> 538 539 <br /> 540 <dt><strong><?php echo TOP_REFERRER; ?></strong></dt> 541 <dd><?php echo serendipity_displayTopReferrers($max_items, true); ?></dd> 542 543 <br /> 544 <dt><strong><?php echo TOP_EXITS; ?></strong></dt> 545 <dd><?php echo serendipity_displayTopExits($max_items, true); ?></dd> 546 </dl> 547 <hr /> 548 <?php serendipity_plugin_api::hook_event('event_additional_statistics', $eventData, array('maxitems' => $max_items)); ?> 549 </div> 550 551 <?php 552 } 553 554 if ($ext_vis_stat == 'yesBot') { 555 $this->extendedVisitorStatistics($max_items); 556 } 557 558 return true; 559 break; 560 561 default: 562 return false; 563 break; 564 } 565 } else { 566 return false; 567 } 568 } 569 570 //Statistics 571 function updatestats($action) { 572 global $serendipity; 573 574 list($year, $month, $day) = split('-', date('Y-m-d')); 575 $sql = serendipity_db_query("SELECT COUNT(year) AS result FROM {$serendipity['dbPrefix']}visitors_count WHERE year='$year' AND month='$month' AND day='$day'", true); 576 577 $sql_hit_update = "UPDATE {$serendipity['dbPrefix']}visitors_count SET hits = hits+1 WHERE year='$year' AND month='$month' AND day='$day'"; 578 $sql_day_new = "INSERT INTO {$serendipity['dbPrefix']}visitors_count (year, month, day, visits, hits) VALUES ('$year','$month','$day',1,1)"; 579 $sql_day_update = "UPDATE {$serendipity['dbPrefix']}visitors_count SET visits = visits+1, hits = hits+1 WHERE year='$year' AND month='$month' AND day='$day'"; 580 switch($action) { 581 case "update": 582 if($sql['result'] >= 1) { 583 serendipity_db_query($sql_hit_update); 584 } else { 585 serendipity_db_query($sql_day_new); 586 } 587 break; 588 case "new": 589 if($sql['result'] >= 1) { 590 serendipity_db_query($sql_day_update); 591 } else { 592 serendipity_db_query($sql_day_new); 593 } 594 break; 595 } 596 } 597 598 function updateVisitor() { 599 global $serendipity; 600 601 $this->updatestats('update'); 602 603 $time = date('H:i'); 604 $day = date('Y-m-d'); 605 return serendipity_db_query("UPDATE {$serendipity['dbPrefix']}visitors SET time = '$time', day = '$day' WHERE sessID = '" . serendipity_db_escape_string(strip_tags(session_id())) . "'"); 606 } 607 608 function countVisitor($useragent, $remoteaddr, $referer){ 609 global $serendipity; 610 $thedate = date('Y-m-d'); 611 $ip=strip_tags($remoteaddr); 612 $ip_how_often = serendipity_db_query("SELECT COUNT(ip) AS result FROM {$serendipity['dbPrefix']}visitors WHERE ip ='$ip' and day='$thedate'", true); 613 614 if($ip_how_often['result'] >=1){ 615 $this->updatestats('update'); 616 } else { 617 $this->updatestats('new'); 618 } 619 $values = array( 620 'sessID' => strip_tags(session_id()), 621 'day' => $thedate, 622 'time' => date('H:i'), 623 'ref' => strip_tags($referer), 624 'browser'=> strip_tags($useragent), 625 'ip' => strip_tags($remoteaddr) 626 ); 627 628 serendipity_db_insert('visitors', $values); 629 630 // updating the referrer-table 631 if (strlen($referer) >= 1) { 632 633 //retrieving the referrer base URL 634 $temp_array = explode('?', $referer); 635 $urlA = $temp_array[0]; 636 637 //removing "http://" & trailing subdirectories 638 $temp_array3 = explode('//', $urlA); 639 $urlB = $temp_array3[1]; 640 $temp_array4 = explode('/', $urlB); 641 $urlB = $temp_array4[0]; 642 643 //removing www 644 $urlC = serendipity_db_escape_string(str_replace('www.', '', $urlB)); 645 646 if(strlen($urlC) < 1) { 647 $urlC = 'unknown'; 648 } 649 650 //updating db 651 $q = serendipity_db_query("SELECT count(refs) AS referrer FROM {$serendipity['dbPrefix']}refs WHERE refs = '$urlC' GROUP BY refs", true); 652 if ($q['referrer'] >= 1){ 653 serendipity_db_query("UPDATE {$serendipity['dbPrefix']}refs SET count=count+1 WHERE (refs = '$urlC')"); 654 } else { 655 serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}refs (refs, count) VALUES ('$urlC', 1)"); 656 } 657 } 658 659 } //end of function countVisitor 660 661 // Calculate daily stats 662 function statistics_getdailystats($day, $amount) { 663 global $serendipity; 664 665 list($year, $month) = split('[-]', date("Y-m")); 666 if ($day > 0 && $day <32) { 667 $sql = "SELECT SUM(visits) AS dailyvisit FROM {$serendipity['dbPrefix']}visitors_count WHERE day"; 668 for ($i=1; $i<32; $i++) { 669 $sqlfire = $sql . " = '$i' AND year = '$year' AND month = '$month'"; 670 $res = serendipity_db_query($sqlfire, true); 671 $container[$i] = $res['dailyvisit']; 672 } 673 return $container; 674 } else if (!is_integer($day)) { 675 echo "Daycount failed - You've gotta specify a correct date(read: integer!)"; 676 return "failure"; 677 } else if ($day < 0 || $day > 32) { 678 echo "Daycount failed - Days only go from 1 to 31"; 679 return "failure"; 680 } 681 682 if (! isset($container)) { 683 $sql = "SELECT SUM(visits) FROM {$serendipity['dbPrefix']}visitors_count WHERE day = '$day' AND month = '$month' AND year = '$year'"; 684 $res = serendipity_db_query($sql, true); 685 return $res; 686 } 687 } 688 689 // Calculate monthly stats 690 function statistics_getmonthlystats($month, $amount) { 691 global $serendipity; 692 693 $year = date("Y"); 694 if ($month > 0 && $month < 13) { 695 $sql = "SELECT SUM(visits) AS monthlyvisit FROM {$serendipity['dbPrefix']}visitors_count WHERE month"; 696 for ($i=1; $i<13; $i++) { 697 $sqlfire = $sql . " = '$i' AND year = '$year'"; 698 $res = serendipity_db_query($sqlfire, true); 699 $container[$i] = $res['monthlyvisit']; 700 } 701 return $container; 702 } else if (!is_integer($month)) { 703 echo "Monthcount failed - You've gotta specify a correct month(read: integer!)"; 704 return "failure"; 705 } else if ($month < 0 || $month > 13) { 706 echo "Monthcount failed - Months only go from 1 to 12"; 707 return "failure"; 708 } 709 710 if (!isset($container)) { 711 $sql = "SELECT SUM(visits) FROM {$serendipity['dbPrefix']}visitors_count WHERE month = '$month' AND year = '$year'"; 712 $res = serendipity_db_query($sql, true); 713 return $res; 714 } 715 } 716 717 function extendedVisitorStatistics($max_items){ 718 719 global $serendipity; 720 721 // ---------------QUERIES for Viewing statistics ---------------------------------------------- 722 $day = date('Y-m-d'); 723 list($year, $month, $day) = split('-', $day); 724 725 $visitors_count_firstday = serendipity_db_query("SELECT day FROM {$serendipity['dbPrefix']}visitors ORDER BY counter_id ASC LIMIT 1", true); 726 $visitors_count_today = serendipity_db_query("SELECT visits FROM {$serendipity['dbPrefix']}visitors_count WHERE year = '".$year."' AND month = '".$month."' AND day = '".$day."'", true); 727 $visitors_count = serendipity_db_query("SELECT SUM(visits) FROM {$serendipity['dbPrefix']}visitors_count", true); 728 $hits_count_today = serendipity_db_query("SELECT hits FROM {$serendipity['dbPrefix']}visitors_count WHERE year = '".$year."' AND month = '".$month."' AND day = '".$day."'", true); 729 $hits_count = serendipity_db_query("SELECT SUM(hits) FROM {$serendipity['dbPrefix']}visitors_count", true); 730 $visitors_latest = serendipity_db_query("SELECT counter_id, day, time, ref, browser, ip FROM {$serendipity['dbPrefix']}visitors ORDER BY counter_id DESC LIMIT ".$max_items.""); 731 $top_refs = serendipity_db_query("SELECT refs, count FROM {$serendipity['dbPrefix']}refs ORDER BY count DESC LIMIT 20"); 732 733 // ---------------STYLES for Viewing statistics ---------------------------------------------- 734 echo "<style type='text/css'>"; 735 echo ".colVis {text-align: center; width:600px; font-size: 10px; background-color:#dddddd;} "; 736 echo ".col1 {text-align: center; width:150px; font-size: 10px; background-color:#dddddd;} "; 737 echo ".col2 {text-align: center; width:150px; font-size: 10px; background-color:#CCCCFF;} "; 738 echo ".col4 {text-align: center; width:600px; font-size: 10px; background-color:#dddddd;} "; 739 echo ".col5 {text-align: center; width:600px; font-size: 10px; background-color:#CCCCFF;} "; 740 echo "</style>"; 741 742 ?> 743 <h3><?php echo PLUGIN_EVENT_STATISTICS_OUT_EXT_STATISTICS; ?></h3> 744 <div style="margin: 5px; padding: 5px"> 745 <dl> 746 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_EXT_VISITORS; ?></strong></dt> 747 <table width="100%" cellpadding="3" cellspacing="3"> 748 <tr> 749 <td colspan="4" align="center"> 750 <?php echo PLUGIN_EVENT_STATISTICS_EXT_VISSINCE." ".$visitors_count_firstday[0]; ?> 751 </td> 752 </tr> 753 <tr> 754 <td colspan="4" align="center"><?php echo PLUGIN_EVENT_STATISTICS_EXT_COUNTDESC; ?></td> 755 </tr> 756 <tr> 757 <td width="25%" align="center"> 758 <?php echo PLUGIN_EVENT_STATISTICS_EXT_VISTODAY; ?><br /><strong><?php echo $visitors_count_today[0]; ?></strong> 759 </td> 760 <td width="25%" align="center"> 761 <?php echo PLUGIN_EVENT_STATISTICS_EXT_VISTOTAL; ?><br /><strong><?php echo $visitors_count[0]; ?> 762 </td> 763 <td width="25%" align="center"> 764 <?php echo PLUGIN_EVENT_STATISTICS_EXT_HITSTODAY; ?><br /><strong><?php echo $hits_count_today[0]; ?> 765 </td> 766 <td width="25%" align="center"> 767 <?php echo PLUGIN_EVENT_STATISTICS_EXT_HITSTOTAL; ?><br /><strong><?php echo $hits_count[0]; ?> 768 </td> 769 </tr> 770 </table> 771 <dd> 772 <div class="colVis"> 773 </div> 774 </dd> 775 </dl> 776 777 <!-- Visitor graphs --> 778 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_EXT_MONTHGRAPH;?></strong></dt> 779 <?php if ($visitors_count[0] > 0) { ?> 780 <table width="100%" cellpadding="0" cellspacing="0"><tr> 781 <?php 782 $color = "col2"; 783 for ($i=1; $i < 13; $i++) { 784 if ($color == "col1") { 785 $color ="col2"; 786 } else { 787 $color ="col1"; 788 } 789 790 $num = $this->statistics_getmonthlystats($i, $visitors_count[0]); 791 $rep = $num; 792 rsort($rep); 793 $maxVisHeigh = 100/$rep[0]*2; 794 echo '<td class="'.$color.'" width="8%" align="center" valign="bottom"><small>' . $num[$i]; 795 echo '<br /><img src="plugins/serendipity_event_statistics/'; 796 if ($num[$i]*$maxVisHeigh/2 <= 33) { 797 echo 'red.png'; 798 } else if ($num[$i]*$maxVisHeigh/2 > 33 && $num[$i]*$maxVisHeigh/2 < 66) { 799 echo 'yellow.png'; 800 } else { 801 echo 'green.png'; 802 } 803 echo '" width="8" alt="" align="bottom" height="'.round($num[$i]*$maxVisHeigh).'" />'; 804 echo '<br /></small></td>'; 805 } ?> 806 </tr><tr> 807 <?php 808 $mon = array('1' => 'Jan', '2' => 'Feb', '3' => 'Mar', '4' => 'Apr', '5' => 'May', '6' => 'Jun', 809 '7' => 'Jul', '8' => 'Aug', '9' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec'); 810 $color = "col2"; 811 for ($i = 1; $i < 13; $i++) { 812 if ($color == "col1") { 813 $color ="col2"; 814 } else { 815 $color ="col1"; 816 } 817 echo '<td class="'.$color.'" width="8%" align="center"><small><b>'. serendipity_strftime('%b', mktime(0, 0, 0, $i, 1, 2000)) .'</b></small></td>'; 818 } 819 ?> 820 </tr></table> 821 <?php } ?> 822 823 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_EXT_DAYGRAPH;?></strong></dt> 824 <?php if ($visitors_count[0] > 0) { ?> 825 <table width="100%" cellpadding="0" cellspacing="0"><tr> 826 <?php 827 $color = "col2"; 828 for ($i=1; $i < 32; $i++) { 829 if ($color == "col1") { 830 $color ="col2"; 831 } else { 832 $color ="col1"; 833 } 834 835 $num = $this->statistics_getdailystats($i, $visitors_count[0]); 836 $rep = $num; 837 rsort($rep); 838 $maxVisHeigh = 100/$rep[0]*2; 839 echo '<td class="'.$color.'" width="3%" align="center" valign="bottom"><small>' . $num[$i]; 840 echo '<br /><img src="plugins/serendipity_event_statistics/'; 841 if ($num[$i]*$maxVisHeigh/2 <= 33) { 842 echo 'red.png'; 843 } else if ($num[$i]*$maxVisHeigh/2 > 33 && $num[$i]*$maxVisHeigh/2 < 66) { 844 echo 'yellow.png'; 845 } else { 846 echo 'green.png'; 847 } 848 echo '" width="8" alt="" align="bottom" height="'.round($num[$i]*$maxVisHeigh).'" />'; 849 echo '<br /></small></td>'; 850 } 851 ?> 852 </tr><tr> 853 <?php 854 $color = "col2"; 855 for ($i=1; $i < 32; $i++) { 856 if ($color == "col1") { 857 $color ="col2"; 858 } else { 859 $color ="col1"; 860 } 861 echo '<td class="'.$color.'" width="3%" align="center"><small><b>'. $i .'</b></small></td>'; 862 } ?> 863 </tr></table> 864 <?php } ?> 865 <!-- End visitor graphs --> 866 867 <br /><br /> 868 869 <dl> 870 871 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_EXT_VISLATEST;?></strong></dt> 872 <dd> 873 <table width="100%" cellpadding="0" cellspacing="0"> 874 <?php 875 $i=1; 876 $color = "col2"; 877 if (is_array($visitors_latest)) { 878 foreach($visitors_latest AS $key => $row) { 879 if ($color == "col1"){$color ="col2";}else{$color ="col1";} 880 echo "<tr>"; 881 echo "<td class = \"".$color."\">".$row['day']." ".$row['time']."</td>\n"; 882 if($row['ref']!='unknown'){ 883 echo "<td class = \"".$color."\"><a 884 href=\"".$row['ref']."\">".wordwrap($row['ref'], 25, "<br />", 1)."</a></td>\n"; 885 } 886 if($row['ref']=='unknown'){ 887 echo "<td class = \"".$color."\">".wordwrap($row['ref'], 25, "<br />", 1)."</td>\n"; 888 } 889 echo "<td class = \"".$color."\">".wordwrap($row['browser'], 25, "<br />", 1)."</td>\n"; 890 echo "<td class = \"".$color."\">"; 891 if ($row['ip']){ 892 echo wordwrap(gethostbyaddr($row['ip']), 25, "\n", 1); 893 } else { 894 echo "--"; 895 } 896 echo "</td>\n"; 897 echo "</tr>\n"; 898 } 899 } 900 ?> 901 </table><br /> 902 </dd> 903 </dl> 904 <dl> 905 <dt><strong><?php echo PLUGIN_EVENT_STATISTICS_EXT_TOPREFS; ?></strong></dt> 906 <dd> 907 <table width="100%" cellpadding="0" cellspacing="0"> 908 <?php 909 $i=1; 910 if (is_array($top_refs)) { 911 foreach($top_refs AS $key => $row) { 912 if ($color == "col4") { 913 $color ="col5"; 914 } else { 915 $color ="col4"; 916 } 917 echo '<tr><td class="'.$color.'">'.$i++.'. <a href="http://'.$row['refs'].'" target="_blank">'.$row['refs'].'</a> (<strong>'.$row['count'].'</strong>)</td></tr>'; 918 } 919 } else { 920 echo PLUGIN_EVENT_STATISTICS_EXT_TOPREFS_NONE; 921 } 922 ?> 923 </table> 924 </dd> 925 </dl> 926 927 <?php 928 } //end of function extendedVisitorStatistics() 929 930 function createTables() { 931 global $serendipity; 932 933 //create table xxxx_visitors 934 $q = "CREATE TABLE {$serendipity['dbPrefix']}visitors ( 935 counter_id {AUTOINCREMENT} {PRIMARY}, 936 sessID varchar(35) not null default '', 937 day varchar(10) not null default '', 938 time varchar(5) not null default '', 939 ref varchar(255) default null, 940 browser varchar(255) default null, 941 ip varchar(15) default null 942 )"; 943 944 serendipity_db_schema_import($q); 945 946 //create table xxxx_visitors_counts 947 $q = "CREATE TABLE {$serendipity['dbPrefix']}visitors_count ( 948 year int(4) not null, 949 month int(2) not null, 950 day int(2) not null, 951 visits int(11) not null, 952 hits int(11) not null 953 )"; 954 955 serendipity_db_schema_import($q); 956 957 //create table xxxx_refs 958 $q = "CREATE TABLE {$serendipity['dbPrefix']}refs ( 959 id {AUTOINCREMENT} {PRIMARY}, 960 refs varchar(255) not null default '', 961 count int(11) not null default '0' 962 )"; 963 serendipity_db_schema_import($q); 964 965 $this->updateTables(); 966 } //end of function createTables() 967 968 function updateTables() { 969 //create indices 970 $q = "CREATE INDEX visitorses ON {$serendipity['dbPrefix']}visitors(sessID);"; 971 serendipity_db_schema_import($q); 972 $q = "CREATE INDEX visitorday ON {$serendipity['dbPrefix']}visitors(day);"; 973 serendipity_db_schema_import($q); 974 $q = "CREATE INDEX visitortime ON {$serendipity['dbPrefix']}visitors(time);"; 975 serendipity_db_schema_import($q); 976 $q = "CREATE INDEX visitortimeb ON {$serendipity['dbPrefix']}visitors_count(year, month, day);"; 977 serendipity_db_schema_import($q); 978 $this->set_config('db_indices_created', '1'); 979 } 980 981 982 function dropTables() { 983 984 global $serendipity; 985 986 // Drop tables 987 $q = "DROP TABLE ".$serendipity['dbPrefix']."visitors"; 988 $sql = serendipity_db_schema_import($q); 989 $q = "DROP TABLE ".$serendipity['dbPrefix']."visitors_count"; 990 $sql = serendipity_db_schema_import($q); 991 $q = "DROP TABLE ".$serendipity['dbPrefix']."refs"; 992 $sql = serendipity_db_schema_import($q); 993 994 } //end of function dropTables 995 996 function install(){ 997 998 $this->createTables(); 999 1000 } 1001 1002 function uninstall(){ 1003 1004 $this->dropTables(); 1005 1006 } 1007 1008 } 1009 1010 /* 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 |
![]() |