PageRenderTime 88ms CodeModel.GetById 23ms RepoModel.GetById 2ms app.codeStats 0ms

/Quản lý website trường trung học phổ thông PHP/lc1/includes/timezone.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 132 lines | 113 code | 12 blank | 7 comment | 24 complexity | 58eb2adb814a462ceedc28f76c57dc60 MD5 | raw file
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES.,JSC. All rights reserved
  6. * @Createdate 31/05/2010, 00:36
  7. */
  8. if ( ! defined( 'NV_MAINFILE' ) ) die( 'Stop!!!' );
  9. //Xac dinh ten mui gio
  10. function nv_getTimezoneName_from_cookie ( $cookie )
  11. {
  12. unset( $matches );
  13. if ( preg_match( "/^([\-]*\d+)\.([\-]*\d+)\.([\-]*\d+)\|(.*)$/", rawurldecode( $cookie ), $matches ) )
  14. {
  15. $ini = file( NV_ROOTDIR . '/includes/ini/timezone.ini' );
  16. $timezones = array();
  17. foreach ( $ini as $i )
  18. {
  19. unset( $ms );
  20. if ( @preg_match( '/\[(.+)\]/', $i, $ms ) )
  21. {
  22. $last = trim( $ms[1] );
  23. }
  24. elseif ( @preg_match( '/(.+)[ ]*=[ ]*[\"|\'](.+)[\"|\']/', $i, $ms ) )
  25. {
  26. $timezones[$last][trim( $ms[1] )] = trim( $ms[2] );
  27. }
  28. }
  29. foreach ( $timezones as $name => $offset )
  30. {
  31. if ( $offset['winter_offset'] == intval( $matches[2] ) * 60 && $offset['summer_offset'] == intval( $matches[2] ) * 60 ) return $name;
  32. }
  33. }
  34. return '';
  35. }
  36. unset( $matches, $matches2 );
  37. $global_config['cookie_prefix'] = ( empty( $global_config['cookie_prefix'] ) ) ? "nv3" : $global_config['cookie_prefix'];
  38. if ( isset( $_COOKIE[$global_config['cookie_prefix'] . '_cltn'] ) )
  39. {
  40. $nv_cltn = base64_decode( $_COOKIE[$global_config['cookie_prefix'] . '_cltn'] );
  41. if ( preg_match( "/^([^\.]+)\.([\-]*\d+)\.(\d{1})$/", $nv_cltn, $matches ) )
  42. {
  43. define( 'NV_CLIENT_TIMEZONE_NAME', $matches[1] );
  44. define( 'NV_CLIENT_TIMEZONE_OFFSET', $matches[2] );
  45. define( 'NV_CLIENT_TIMEZONE_DST', $matches[3] );
  46. }
  47. else
  48. {
  49. setcookie( $global_config['cookie_prefix'] . '_cltn', false, time() - 86400 );
  50. }
  51. }
  52. if ( ! defined( 'NV_CLIENT_TIMEZONE_NAME' ) and isset( $_COOKIE[$global_config['cookie_prefix'] . '_cltz'] ) and preg_match( "/^([\-]*\d+)\.([\-]*\d+)\.([\-]*\d+)\|(.*)$/", rawurldecode( $_COOKIE[$global_config['cookie_prefix'] . '_cltz'] ), $matches2 ) )
  53. {
  54. $client_timezone_name = nv_getTimezoneName_from_cookie( $_COOKIE[$global_config['cookie_prefix'] . '_cltz'] );
  55. if ( ! empty( $client_timezone_name ) )
  56. {
  57. define( 'NV_CLIENT_TIMEZONE_NAME', $client_timezone_name );
  58. define( 'NV_CLIENT_TIMEZONE_OFFSET', $matches2[3] * 60 );
  59. }
  60. else
  61. {
  62. $sd = floor( $matches2[2] >= 0 ? $matches2[2] / 60 : - $matches2[2] / 60 );
  63. define( 'NV_CLIENT_TIMEZONE_NAME', ( $matches2[2] >= 0 ? "+" : "-" ) . str_pad( $sd, 2, '0', STR_PAD_LEFT ) . ":00" );
  64. define( 'NV_CLIENT_TIMEZONE_OFFSET', floor( $matches2[3] / 60 ) * 3600 );
  65. }
  66. define( 'NV_CLIENT_TIMEZONE_DST', $matches2[1] != $matches2[2] ? 1 : 0 );
  67. $client_timezone_name = base64_encode( NV_CLIENT_TIMEZONE_NAME . '.' . NV_CLIENT_TIMEZONE_OFFSET . '.' . NV_CLIENT_TIMEZONE_DST );
  68. setcookie( $global_config['cookie_prefix'] . '_cltn', $client_timezone_name, 0, $matches2[4], '', 0 );
  69. unset( $client_timezone_name, $sd );
  70. }
  71. if ( empty( $global_config['site_timezone'] ) and defined( 'NV_CLIENT_TIMEZONE_NAME' ) ) $global_config['site_timezone'] = NV_CLIENT_TIMEZONE_NAME;
  72. if ( ! empty( $global_config['site_timezone'] ) )
  73. {
  74. $ok = false;
  75. if ( ! $ok and $sys_info['ini_set_support'] and ! function_exists( 'date_default_timezone_set' ) )
  76. {
  77. ini_set( 'date.timezone', $global_config['site_timezone'] );
  78. if ( strcasecmp( ini_get( 'date.timezone' ), $global_config['site_timezone'] ) == 0 )
  79. {
  80. define( 'NV_SITE_TIMEZONE_GMT_NAME', preg_replace( "/^([\+|\-]{1}\d{2})(\d{2})$/", "$1:$2", date( "O" ) ) );
  81. define( 'NV_SITE_TIMEZONE_NAME', $global_config['site_timezone'] );
  82. $ok = true;
  83. }
  84. }
  85. if ( ! $ok and function_exists( 'date_default_timezone_set' ) )
  86. {
  87. date_default_timezone_set( $global_config['site_timezone'] );
  88. if ( strcasecmp( date_default_timezone_get(), $global_config['site_timezone'] ) == 0 )
  89. {
  90. define( 'NV_SITE_TIMEZONE_GMT_NAME', preg_replace( "/^([\+|\-]{1}\d{2})(\d{2})$/", "$1:$2", date( "O" ) ) );
  91. define( 'NV_SITE_TIMEZONE_NAME', $global_config['site_timezone'] );
  92. $ok = true;
  93. }
  94. }
  95. if ( ! $ok and function_exists( 'putenv' ) and ! in_array( 'putenv', $sys_info['disable_functions'] ) )
  96. {
  97. putenv( "TZ=" . $global_config['site_timezone'] );
  98. if ( strcasecmp( getenv( "TZ" ), $global_config['site_timezone'] ) == 0 )
  99. {
  100. define( 'NV_SITE_TIMEZONE_GMT_NAME', preg_replace( "/^([\+|\-]{1}\d{2})(\d{2})$/", "$1:$2", date( "O" ) ) );
  101. define( 'NV_SITE_TIMEZONE_NAME', $global_config['site_timezone'] );
  102. $ok = true;
  103. }
  104. }
  105. if ( ! $ok )
  106. {
  107. define( 'NV_SITE_TIMEZONE_GMT_NAME', preg_replace( "/^([\+|\-]{1}\d{2})(\d{2})$/", "$1:$2", date( "O" ) ) );
  108. define( 'NV_SITE_TIMEZONE_NAME', NV_SITE_TIMEZONE_GMT_NAME );
  109. }
  110. unset( $ok );
  111. $global_config['site_timezone'] = NV_SITE_TIMEZONE_NAME;
  112. }
  113. else
  114. {
  115. $global_config['site_timezone'] = preg_replace( "/^([\+|\-]{1}\d{2})(\d{2})$/", "$1:$2", date( "O" ) );
  116. define( 'NV_SITE_TIMEZONE_GMT_NAME', $global_config['site_timezone'] );
  117. define( 'NV_SITE_TIMEZONE_NAME', $global_config['site_timezone'] );
  118. }
  119. define( 'NV_SITE_TIMEZONE_OFFSET', date( "Z" ) ); //Mui gio, da tu dong them vao gio mua he doi voi nhung mui gio co che do nay
  120. ?>