PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/nukeviet/includes/core/stat.php

http://nuke-viet.googlecode.com/
PHP | 84 lines | 65 code | 13 blank | 6 comment | 7 complexity | 418492746079802868613029ad83608c MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.x
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @copyright 2009
  6. * @createdate 12/29/2009 20:7
  7. */
  8. if( ! defined( 'NV_MAINFILE' ) ) die( 'Stop!!!' );
  9. function nv_stat_update()
  10. {
  11. global $db, $client_info, $global_config;
  12. list( $last_update ) = $db->sql_fetchrow( $db->sql_query( "SELECT `c_count` FROM `" . NV_COUNTER_TABLE . "` WHERE `c_type` = 'c_time' AND `c_val`= 'last'" ) );
  13. if( NV_SITE_TIMEZONE_NAME == $global_config['statistics_timezone'] )
  14. {
  15. $last_year = date( "Y", $last_update );
  16. $last_month = date( "M", $last_update );
  17. $last_day = date( "d", $last_update );
  18. $current_year = date( 'Y', NV_CURRENTTIME );
  19. $current_month = date( 'M', NV_CURRENTTIME );
  20. $current_day = date( 'd', NV_CURRENTTIME );
  21. $current_hour = date( 'H', NV_CURRENTTIME );
  22. $current_week = date( 'l', NV_CURRENTTIME );
  23. }
  24. else
  25. {
  26. date_default_timezone_set( $global_config['statistics_timezone'] );
  27. $last_year = date( "Y", $last_update );
  28. $last_month = date( "M", $last_update );
  29. $last_day = date( "d", $last_update );
  30. $current_year = date( 'Y', NV_CURRENTTIME );
  31. $current_month = date( 'M', NV_CURRENTTIME );
  32. $current_day = date( 'd', NV_CURRENTTIME );
  33. $current_hour = date( 'H', NV_CURRENTTIME );
  34. $current_week = date( 'l', NV_CURRENTTIME );
  35. date_default_timezone_set( NV_SITE_TIMEZONE_NAME );
  36. }
  37. if( $last_year != $current_year )
  38. {
  39. $query = "UPDATE `" . NV_COUNTER_TABLE . "` SET `c_count`= 0 WHERE (`c_type`='month' OR `c_type`='day' OR `c_type`='hour')";
  40. $db->sql_query( $query );
  41. }
  42. elseif( $last_month != $current_month )
  43. {
  44. $query = "UPDATE `" . NV_COUNTER_TABLE . "` SET `c_count`= 0 WHERE (`c_type`='day' OR `c_type`='hour')";
  45. $db->sql_query( $query );
  46. }
  47. elseif( $last_day != $current_day )
  48. {
  49. $query = "UPDATE `" . NV_COUNTER_TABLE . "` SET `c_count`= 0 WHERE `c_type`='hour'";
  50. $db->sql_query( $query );
  51. }
  52. $bot_name = ( $client_info['is_bot'] and ! empty( $client_info['bot_info']['name'] ) ) ? $client_info['bot_info']['name'] : "Not_bot";
  53. $browser = ( $client_info['is_mobile'] ) ? "Mobile" : $client_info['browser']['key'];
  54. $query = "UPDATE `" . NV_COUNTER_TABLE . "` SET `c_count`= c_count + 1, `last_update`=" . NV_CURRENTTIME . " WHERE
  55. (`c_type`='total' AND `c_val`='hits') OR
  56. (`c_type`='year' AND `c_val`='" . $current_year . "') OR
  57. (`c_type`='month' AND `c_val`='" . $current_month . "') OR
  58. (`c_type`='day' AND `c_val`='" . $current_day . "') OR
  59. (`c_type`='dayofweek' AND `c_val`='" . $current_week . "') OR
  60. (`c_type`='hour' AND `c_val`='" . $current_hour . "') OR
  61. (`c_type`='bot' AND `c_val`=" . $db->dbescape( $bot_name ) . ") OR
  62. (`c_type`='browser' AND `c_val`=" . $db->dbescape( $browser ) . ") OR
  63. (`c_type`='os' AND `c_val`=" . $db->dbescape( $client_info['client_os']['key'] ) . ") OR
  64. (`c_type`='country' AND `c_val`=" . $db->dbescape( $client_info['country'] ) . ")";
  65. $db->sql_query( $query );
  66. $query = "UPDATE `" . NV_COUNTER_TABLE . "` SET `c_count`= " . NV_CURRENTTIME . " WHERE `c_type`='c_time' AND `c_val`= 'last'";
  67. $db->sql_query( $query );
  68. }
  69. nv_stat_update();
  70. $nv_Request->set_Session( 'statistic_' . NV_LANG_DATA, NV_CURRENTTIME );
  71. ?>