PageRenderTime 33ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 1ms

/nukeviet/includes/functions.php

http://nuke-viet.googlecode.com/
PHP | 1813 lines | 1182 code | 296 blank | 335 comment | 237 complexity | 2fffe9d8e9ace1ed4ed85555ba814481 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.x
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2012 VINADES.,JSC. All rights reserved
  6. * @Createdate 1/9/2010, 23:48
  7. */
  8. if( ! defined( 'NV_MAINFILE' ) ) die( 'Stop!!!' );
  9. require_once ( NV_ROOTDIR . '/includes/utf8/' . $sys_info['string_handler'] . '_string_handler.php' );
  10. require_once ( NV_ROOTDIR . '/includes/utf8/utf8_functions.php' );
  11. require_once ( NV_ROOTDIR . '/includes/core/filesystem_functions.php' );
  12. require_once ( NV_ROOTDIR . '/includes/core/cache_functions.php' );
  13. /**
  14. * nv_object2array()
  15. *
  16. * @param mixed $a
  17. * @return
  18. */
  19. function nv_object2array( $a )
  20. {
  21. if( is_object( $a ) ) $a = get_object_vars( $a );
  22. return is_array( $a ) ? array_map( __function__, $a ) : $a;
  23. }
  24. /**
  25. * nv_getenv()
  26. *
  27. * @param mixed $a
  28. * @return
  29. */
  30. function nv_getenv( $a )
  31. {
  32. if( ! is_array( $a ) )
  33. {
  34. $a = array( $a );
  35. }
  36. foreach( $a as $b )
  37. {
  38. if( isset( $_SERVER[$b] ) ) return $_SERVER[$b];
  39. elseif( isset( $_ENV[$b] ) ) return $_ENV[$b];
  40. elseif( @getenv( $b ) ) return @getenv( $b );
  41. elseif( function_exists( 'apache_getenv' ) && apache_getenv( $b, true ) ) return apache_getenv( $b, true );
  42. }
  43. return "";
  44. }
  45. /**
  46. * nv_preg_quote()
  47. *
  48. * @param string $a
  49. * @return
  50. */
  51. function nv_preg_quote( $a )
  52. {
  53. return preg_quote( $a, "/" );
  54. }
  55. /**
  56. * nv_is_myreferer()
  57. *
  58. * @param string $referer
  59. * @return
  60. */
  61. function nv_is_myreferer( $referer = "" )
  62. {
  63. if( empty( $referer ) ) $referer = urldecode( nv_getenv( 'HTTP_REFERER' ) );
  64. if( empty( $referer ) ) return 2;
  65. $server_name = preg_replace( '/^[w]+\./e', '', nv_getenv( "HTTP_HOST" ) );
  66. $referer = preg_replace( array( '/^[a-zA-Z]+\:\/\/([w]+\.)?/e', '/^[w]+\./e' ), '', $referer );
  67. if( preg_match( "/^" . nv_preg_quote( $server_name ) . "/", $referer ) ) return 1;
  68. return 0;
  69. }
  70. /**
  71. * nv_is_blocker_proxy()
  72. *
  73. * @param string $is_proxy
  74. * @param integer $proxy_blocker
  75. * @return
  76. */
  77. function nv_is_blocker_proxy( $is_proxy, $proxy_blocker )
  78. {
  79. if( $proxy_blocker == 1 and $is_proxy == 'Strong' ) return true;
  80. if( $proxy_blocker == 2 and ( $is_proxy == 'Strong' || $is_proxy == 'Mild' ) ) return true;
  81. if( $proxy_blocker == 3 and $is_proxy != 'No' ) return true;
  82. return false;
  83. }
  84. /**
  85. * nv_is_banIp()
  86. *
  87. * @param string $ip
  88. * @return
  89. */
  90. function nv_is_banIp( $ip )
  91. {
  92. $array_banip_site = $array_banip_admin = array();
  93. if( file_exists( NV_ROOTDIR . "/" . NV_DATADIR . "/banip.php" ) ) include ( NV_ROOTDIR . "/" . NV_DATADIR . "/banip.php" );
  94. $banIp = ( defined( 'NV_ADMIN' ) ) ? $array_banip_admin : $array_banip_site;
  95. if( empty( $banIp ) ) return false;
  96. foreach( $banIp as $e => $f )
  97. {
  98. if( $f['begintime'] < NV_CURRENTTIME and ( $f['endtime'] == 0 or $f['endtime'] > NV_CURRENTTIME ) and ( preg_replace( $f['mask'], "", $ip ) == preg_replace( $f['mask'], "", $e ) ) ) return true;
  99. }
  100. return false;
  101. }
  102. /**
  103. * nv_checkagent()
  104. *
  105. * @param string $a
  106. * @return
  107. */
  108. function nv_checkagent( $a )
  109. {
  110. $a = htmlspecialchars( substr( $a, 0, 255 ) );
  111. $a = str_replace( array( ",", "<" ), array( "-", "(" ), $a );
  112. return ( ( ! empty( $a ) and $a != "-" ) ? $a : "none" );
  113. }
  114. /**
  115. * nv_check_bot()
  116. *
  117. * @return
  118. */
  119. function nv_check_bot()
  120. {
  121. global $client_info;
  122. $file_bots = NV_ROOTDIR . "/" . NV_DATADIR . "/bots.config";
  123. $bots = ( file_exists( $file_bots ) and filesize( $file_bots ) ) ? unserialize( file_get_contents( $file_bots ) ) : array();
  124. if( empty( $bots ) and file_exists( NV_ROOTDIR . "/includes/bots.php" ) ) include ( NV_ROOTDIR . "/includes/bots.php" );
  125. if( empty( $bots ) ) return array();
  126. foreach( $bots as $name => $values )
  127. {
  128. $is_bot = false;
  129. if( $values['agent'] and preg_match( '#' . str_replace( '\*', '.*?', nv_preg_quote( $values['agent'], '#' ) ) . '#i', $client_info['agent'] ) ) $is_bot = true;
  130. if( ! empty( $values['ips'] ) and ( $is_bot or ! $values['agent'] ) )
  131. {
  132. $is_bot = false;
  133. $ips = implode( "|", array_map( "nv_preg_quote", explode( "|", $values['ips'] ) ) );
  134. if( preg_match( "/^" . $ips . "/", $client_info['ip'] ) ) $is_bot = true;
  135. }
  136. if( $is_bot ) return array(
  137. 'name' => $name,
  138. 'agent' => $values['agent'],
  139. 'ip' => $client_info['ip'],
  140. 'allowed' => $values['allowed']
  141. );
  142. }
  143. return array();
  144. }
  145. /**
  146. * nv_checkmobile()
  147. *
  148. * @param string $inifile
  149. * @return
  150. */
  151. function nv_checkmobile( $inifile )
  152. {
  153. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  154. if( preg_match( "/Creative\ AutoUpdate/i", $user_agent ) ) return array();
  155. $browsers = array();
  156. if( file_exists( $inifile ) ) $browsers = nv_parse_ini_file( $inifile, true );
  157. if( ! empty( $browsers ) )
  158. {
  159. foreach( $browsers as $key => $info )
  160. {
  161. if( preg_match( $info['rule'], $user_agent ) ) return array( 'key' => $key, 'name' => $info['name'] );
  162. }
  163. }
  164. if( preg_match( "/Nokia([^\/]+)\/([^ SP]+)/i", $user_agent, $matches ) )
  165. {
  166. if( stripos( $user_agent, 'Series60' ) !== false || strpos( $user_agent, 'S60' ) !== false )
  167. {
  168. return array( 'key' => 'nokia', 'name' => 'Nokia S60 V.' . $matches[2] );
  169. }
  170. else
  171. {
  172. return array( 'key' => 'nokia', 'name' => 'Nokia V.' . $matches[2] );
  173. }
  174. }
  175. if( isset( $_SERVER['X-OperaMini-Features'] ) ) return array( 'key' => 'opera', 'name' => 'Opera Mini' );
  176. if( isset( $_SERVER['UA-pixels'] ) ) return array( 'key' => 'mobile', 'name' => 'UA-pixels' );
  177. if( isset( $_SERVER['HTTP_X_WAP_PROFILE'] ) || isset( $_SERVER['HTTP_PROFILE'] ) ) return array( 'key' => 'mobile', 'name' => 'Unknown' );
  178. if( isset( $_SERVER['HTTP_ACCEPT'] ) && preg_match( "/wap\.|\.wap/i", $_SERVER["HTTP_ACCEPT"] ) ) return array( 'key' => 'mobile', 'name' => 'Unknown' );
  179. if( preg_match( '/(mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|samu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w398samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|myx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp|treo)/i', $user_agent ) )
  180. {
  181. return array( 'key' => 'mobile', 'name' => 'Unknown' );
  182. }
  183. $mbs = array('1207', '3gso', '4thp', '501i', '502i', '503i', '504i', '505i', '506i', '6310', '6590', '770s', '802s', 'a wa', 'acer', 'acs-', 'airn', 'alav', 'asus', 'attw', 'au-m', 'aur ', 'aus ', 'abac', 'acoo', 'aiko', 'alco', 'alca', 'amoi', 'anex', 'anny', 'anyw', 'aptu', 'arch', 'argo', 'bell', 'bird', 'bw-n', 'bw-u', 'beck', 'benq', 'bilb', 'blac', 'c55/', 'cdm-', 'chtm', 'capi', 'cond', 'craw', 'dall', 'dbte', 'dc-s', 'dica', 'ds-d', 'ds12', 'dait', 'devi', 'dmob', 'doco', 'dopo', 'el49', 'erk0', 'esl8', 'ez40', 'ez60', 'ez70', 'ezos', 'ezze', 'elai', 'emul', 'eric', 'ezwa', 'fake', 'fly-', 'fly_', 'g-mo', 'g1 u', 'g560', 'gf-5', 'grun', 'gene', 'go.w', 'good', 'grad', 'hcit', 'hd-m', 'hd-p', 'hd-t', 'hei-', 'hp i', 'hpip', 'hs-c', 'htc ', 'htc-', 'htca', 'htcg', 'htcp', 'htcs', 'htct', 'htc_', 'haie', 'hita', 'huaw', 'hutc', 'i-20', 'i-go', 'i-ma', 'i230', 'iac', 'iac-', 'iac/', 'ig01', 'im1k', 'inno', 'iris', 'jata', 'java', 'kddi', 'kgt', 'kgt/', 'kpt ', 'kwc-', 'klon', 'lexi', 'lg g', 'lg-a', 'lg-b', 'lg-c', 'lg-d', 'lg-f', 'lg-g', 'lg-k', 'lg-l', 'lg-m', 'lg-o', 'lg-p', 'lg-s', 'lg-t', 'lg-u', 'lg-w', 'lg/k', 'lg/l', 'lg/u', 'lg50', 'lg54', 'lge-', 'lge/', 'lynx', 'leno', 'm1-w', 'm3ga', 'm50/', 'maui', 'mc01', 'mc21', 'mcca', 'medi', 'meri', 'mio8', 'mioa', 'mo01', 'mo02', 'mode', 'modo', 'mot ', 'mot-', 'mt50', 'mtp1', 'mtv ', 'mate', 'maxo', 'merc', 'mits', 'mobi', 'motv', 'mozz', 'n100', 'n101', 'n102', 'n202', 'n203', 'n300', 'n302', 'n500', 'n502', 'n505', 'n700', 'n701', 'n710', 'nec-', 'nem-', 'newg', 'neon', 'netf', 'noki', 'nzph', 'o2 x', 'o2-x', 'opwv', 'owg1', 'opti', 'oran', 'p800', 'pand', 'pg-1', 'pg-2', 'pg-3', 'pg-6', 'pg-8', 'pg-c', 'pg13', 'phil', 'pn-2', 'pt-g', 'palm', 'pana', 'pire', 'pock', 'pose', 'psio', 'qa-a', 'qc-2', 'qc-3', 'qc-5', 'qc-7', 'qc07', 'qc12', 'qc21', 'qc32', 'qc60', 'qci-', 'qwap', 'qtek', 'r380', 'r600', 'raks', 'rim9', 'rove', 's55/', 'sage', 'sams', 'sc01', 'sch-', 'scp-', 'sdk/', 'se47', 'sec-', 'sec0', 'sec1', 'semc', 'sgh-', 'shar', 'sie-', 'sk-0', 'sl45', 'slid', 'smb3', 'smt5', 'sp01', 'sph-', 'spv ', 'spv-', 'sy01', 'samm', 'sany', 'sava', 'scoo', 'send', 'siem', 'smar', 'smit', 'soft', 'sony', 't-mo', 't218', 't250', 't600', 't610', 't618', 'tcl-', 'tdg-', 'telm', 'tim-', 'ts70', 'tsm-', 'tsm3', 'tsm5', 'tx-9', 'tagt', 'talk', 'teli', 'topl', 'hiba', 'up.b', 'upg1', 'utst', 'v400', 'v750', 'veri', 'vk-v', 'vk40', 'vk50', 'vk52', 'vk53', 'vm40', 'vx98', 'virg', 'vite', 'voda', 'vulc', 'w3c ', 'w3c-', 'wapj', 'wapp', 'wapu', 'wapm', 'wig ', 'wapi', 'wapr', 'wapv', 'wapy', 'wapa', 'waps', 'wapt', 'winc', 'winw', 'wonu', 'x700', 'xda2', 'xdag', 'yas-', 'your', 'zte-', 'zeto', 'acs-', 'alav', 'alca', 'amoi', 'aste', 'audi', 'avan', 'benq', 'bird', 'blac', 'blaz', 'brew', 'brvw', 'bumb', 'ccwa', 'cell', 'cldc', 'cmd-', 'dang', 'doco', 'eml2', 'eric', 'fetc', 'hipt', 'http', 'ibro', 'idea', 'ikom', 'inno', 'ipaq', 'jbro', 'jemu', 'java', 'jigs', 'kddi', 'keji', 'kyoc', 'kyok', 'leno', 'lg-c', 'lg-d', 'lg-g', 'lge-', 'libw', 'm-cr', 'maui', 'maxo', 'midp', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'mwbp', 'mywa', 'nec-', 'newt', 'nok6', 'noki', 'o2im', 'opwv', 'palm', 'pana', 'pant', 'pdxg', 'phil', 'play', 'pluc', 'port', 'prox', 'qtek', 'qwap', 'rozo', 'sage', 'sama', 'sams', 'sany', 'sch-', 'sec-', 'send', 'seri', 'sgh-', 'shar', 'sie-', 'siem', 'smal', 'smar', 'sony', 'sph-', 'symb', 't-mo', 'teli', 'tim-', 'tosh', 'treo', 'tsm-', 'upg1', 'upsi', 'vk-v', 'voda', 'vx52', 'vx53', 'vx60', 'vx61', 'vx70', 'vx80', 'vx81', 'vx83', 'vx85', 'wap-', 'wapa', 'wapi', 'wapp', 'wapr', 'webc', 'whit', 'winw', 'wmlb', 'xda-', );
  184. $user_agent = strtolower( substr( $user_agent, 0, 4 ) );
  185. if( in_array( $user_agent, $mbs ) ) return array( 'key' => 'mobile', 'name' => 'Unknown' );
  186. return array();
  187. }
  188. /**
  189. * nv_getBrowser()
  190. *
  191. * @param string $agent
  192. * @param string $brinifile
  193. * @return
  194. */
  195. function nv_getBrowser( $agent, $brinifile )
  196. {
  197. $browsers = nv_parse_ini_file( $brinifile, true );
  198. foreach( $browsers as $key => $info )
  199. {
  200. if( preg_match( "#" . $info['rule'] . "#i", $agent, $results ) )
  201. {
  202. if( isset( $results[1] ) ) return ( $key . '|' . $info['name'] . ' v' . $results[1] );
  203. return ( $key . '|' . $info['name'] );
  204. }
  205. }
  206. return ( "Unknown|Unknown" );
  207. }
  208. /**
  209. * nv_getOs()
  210. *
  211. * @param string $agent
  212. * @param string $osinifile
  213. * @return
  214. */
  215. function nv_getOs( $agent, $osinifile )
  216. {
  217. $os = nv_parse_ini_file( $osinifile, true );
  218. foreach( $os as $key => $info )
  219. {
  220. if( preg_match( "#" . $info['rule'] . "#i", $agent, $results ) )
  221. {
  222. if( strstr( $key, "win" ) ) return ( $key . '|' . $info['name'] );
  223. if( isset( $results[1] ) ) return ( $key . '|' . $info['name'] . ' ' . $results[1] );
  224. return ( $key . '|' . $info['name'] );
  225. }
  226. }
  227. return ( "Unspecified|Unspecified" );
  228. }
  229. /**
  230. * nv_convertfromBytes()
  231. *
  232. * @param integer $size
  233. * @return
  234. */
  235. function nv_convertfromBytes( $size )
  236. {
  237. if( $size <= 0 ) return '0 bytes';
  238. if( $size == 1 ) return '1 byte';
  239. if( $size < 1024 ) return $size . ' bytes';
  240. $i = 0;
  241. $iec = array( "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" );
  242. while( ( $size / 1024 ) > 1 )
  243. {
  244. $size = $size / 1024;
  245. ++$i;
  246. }
  247. return number_format( $size, 2 ) . ' ' . $iec[$i];
  248. }
  249. /**
  250. * nv_convertfromSec()
  251. *
  252. * @param integer $sec
  253. * @return
  254. */
  255. function nv_convertfromSec( $sec = 0 )
  256. {
  257. global $lang_global;
  258. $sec = intval( $sec );
  259. $min = 60;
  260. $hour = 3600;
  261. $day = 86400;
  262. $year = 31536000;
  263. if( $sec == 0 ) return "";
  264. if( $sec < $min ) return $sec . " " . $lang_global['sec'];
  265. if( $sec < $hour ) return trim( floor( $sec / $min ) . " " . " " . $lang_global['min'] . ( ( $sd = $sec % $min ) ? " " . nv_convertfromSec( $sd ) : "" ) );
  266. if( $sec < $day ) return trim( floor( $sec / $hour ) . " " . $lang_global['hour'] . ( ( $sd = $sec % $hour ) ? " " . nv_convertfromSec( $sd ) : "" ) );
  267. if( $sec < $year ) return trim( floor( $sec / $day ) . " " . $lang_global['day'] . ( ( $sd = $sec % $day ) ? " " . nv_convertfromSec( $sd ) : "" ) );
  268. return trim( floor( $sec / $year ) . " " . $lang_global['year'] . ( ( $sd = $sec % $year ) ? " " . nv_convertfromSec( $sd ) : "" ) );
  269. }
  270. /**
  271. * nv_converttoBytes()
  272. *
  273. * @param string $string
  274. * @return
  275. */
  276. function nv_converttoBytes( $string )
  277. {
  278. if( preg_match( '/^([0-9\.]+)[ ]*([b|k|m|g|t|p|e|z|y]*)/i', $string, $matches ) )
  279. {
  280. if( empty( $matches[2] ) ) return $matches[1];
  281. $suffixes = array( "B" => 0, "K" => 1, "M" => 2, "G" => 3, "T" => 4, "P" => 5, "E" => 6, "Z" => 7, "Y" => 8 );
  282. if( isset( $suffixes[strtoupper( $matches[2] )] ) ) return round( $matches[1] * pow( 1024, $suffixes[strtoupper( $matches[2] )] ) );
  283. }
  284. return false;
  285. }
  286. /**
  287. * nv_base64_encode()
  288. *
  289. * @param string $input
  290. * @return
  291. */
  292. function nv_base64_encode( $input )
  293. {
  294. return strtr( base64_encode( $input ), '+/=', '-_,' );
  295. }
  296. /**
  297. * nv_base64_decode()
  298. *
  299. * @param string $input
  300. * @return
  301. */
  302. function nv_base64_decode( $input )
  303. {
  304. return base64_decode( strtr( $input, '-_,', '+/=' ) );
  305. }
  306. /**
  307. * nv_function_exists()
  308. *
  309. * @param string $funcName
  310. * @return
  311. */
  312. function nv_function_exists( $funcName )
  313. {
  314. global $sys_info;
  315. return ( function_exists( $funcName ) and ! in_array( $funcName, $sys_info['disable_functions'] ) );
  316. }
  317. /**
  318. * nv_class_exists()
  319. *
  320. * @param string $clName
  321. * @return
  322. */
  323. function nv_class_exists( $clName )
  324. {
  325. global $sys_info;
  326. return ( class_exists( $clName ) and ! in_array( $clName, $sys_info['disable_classes'] ) );
  327. }
  328. /**
  329. * nv_check_valid_login()
  330. *
  331. * @param string $login
  332. * @param integer $max
  333. * @param integer $min
  334. * @return
  335. */
  336. function nv_check_valid_login( $login, $max, $min )
  337. {
  338. global $lang_global;
  339. $login = strip_tags( trim( $login ) );
  340. if( empty( $login ) ) return $lang_global['username_empty'];
  341. if( isset( $login{$max} ) ) return sprintf( $lang_global['usernamelong'], $login, $max );
  342. if( ! isset( $login{$min - 1} ) ) return sprintf( $lang_global['usernameadjective'], $login, $min );
  343. return "";
  344. }
  345. /**
  346. * nv_check_valid_pass()
  347. *
  348. * @param string $pass
  349. * @param integer $max
  350. * @param integer $min
  351. * @return
  352. */
  353. function nv_check_valid_pass( $pass, $max, $min )
  354. {
  355. global $lang_global;
  356. $pass = strip_tags( trim( $pass ) );
  357. if( empty( $pass ) ) return $lang_global['password_empty'];
  358. if( isset( $pass{$max} ) ) return sprintf( $lang_global['passwordlong'], $pass, $max );
  359. if( ! isset( $pass{$min - 1} ) ) return sprintf( $lang_global['passwordadjective'], $pass, $min );
  360. return "";
  361. }
  362. /**
  363. * nv_check_valid_email()
  364. *
  365. * @param string $mail
  366. * @return
  367. */
  368. function nv_check_valid_email( $mail )
  369. {
  370. global $lang_global, $global_config;
  371. $mail = strip_tags( trim( $mail ) );
  372. if( empty( $mail ) ) return $lang_global['email_empty'];
  373. if( function_exists( 'filter_var' ) and filter_var( $mail, FILTER_VALIDATE_EMAIL ) === false ) return sprintf( $lang_global['email_incorrect'], $mail );
  374. if( ! preg_match( $global_config['check_email'], $mail ) ) return sprintf( $lang_global['email_incorrect'], $mail );
  375. if( ! preg_match( "/\.(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|asia|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|ke|kg|kh|ki|km|kn|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw|xxx)$/", $mail ) ) return sprintf( $lang_global['email_incorrect'], $mail );
  376. return "";
  377. }
  378. /**
  379. * nv_capcha_txt()
  380. *
  381. * @param string $seccode
  382. * @param string $scaptcha
  383. * @return
  384. */
  385. function nv_capcha_txt( $seccode )
  386. {
  387. global $sys_info, $global_config, $nv_Request;
  388. mt_srand( ( double )microtime() * 1000000 );
  389. $maxran = 1000000;
  390. $random = mt_rand( 0, $maxran );
  391. if( $global_config['captcha_type'] == 1 )
  392. {
  393. $scaptcha = isset( $_SESSION['scaptcha'] ) ? $_SESSION['scaptcha'] : '';
  394. $_SESSION['scaptcha'] = $random;
  395. if( !empty( $scaptcha ) AND strtolower( $scaptcha ) == strtolower( $seccode ) ) return true;
  396. return false;
  397. }
  398. else
  399. {
  400. $seccode = strtoupper( $seccode );
  401. $random_num = $nv_Request->get_string( 'random_num', 'session', 0 );
  402. $datekey = date( "F j" );
  403. $rcode = strtoupper( md5( NV_USER_AGENT . $global_config['sitekey'] . $random_num . $datekey ) );
  404. $nv_Request->set_Session( 'random_num', $random );
  405. return ( preg_match( "/^[a-zA-Z0-9]{" . NV_GFX_NUM . "}$/", $seccode ) and $seccode == substr( $rcode, 2, NV_GFX_NUM ) );
  406. }
  407. }
  408. /**
  409. * nv_genpass()
  410. *
  411. * @param integer $length
  412. * @return
  413. */
  414. function nv_genpass( $length = 8 )
  415. {
  416. $pass = chr( mt_rand( 65, 90 ) );
  417. for( $k = 0; $k < $length - 1; ++$k )
  418. {
  419. $probab = mt_rand( 1, 10 );
  420. $pass .= ( $probab <= 8 ) ? chr( mt_rand( 97, 122 ) ) : chr( mt_rand( 48, 57 ) );
  421. }
  422. return $pass;
  423. }
  424. /**
  425. * nv_EncodeEmail()
  426. *
  427. * @param string $strEmail
  428. * @param string $strDisplay
  429. * @param bool $blnCreateLink
  430. * @return
  431. */
  432. function nv_EncodeEmail( $strEmail, $strDisplay = '', $blnCreateLink = true )
  433. {
  434. $strMailto = "&#109;&#097;&#105;&#108;&#116;&#111;&#058;";
  435. $strEncodedEmail = "";
  436. $strlen = strlen( $strEmail );
  437. for( $i = 0; $i < $strlen; ++$i )
  438. {
  439. $strEncodedEmail .= "&#" . ord( substr( $strEmail, $i ) ) . ";";
  440. }
  441. $strDisplay = trim( $strDisplay );
  442. $strDisplay = ! empty( $strDisplay ) ? $strDisplay : $strEncodedEmail;
  443. if( $blnCreateLink ) return "<a href=\"" . $strMailto . $strEncodedEmail . "\">" . $strDisplay . "</a>";
  444. return $strDisplay;
  445. }
  446. /**
  447. * nv_user_groups()
  448. *
  449. * @param string $in_groups
  450. * @return
  451. */
  452. function nv_user_groups( $in_groups )
  453. {
  454. global $db;
  455. if( empty( $in_groups ) ) return "";
  456. $query = "SELECT `group_id`, `title`, `exp_time`, `public` FROM `" . NV_GROUPS_GLOBALTABLE . "` WHERE `act`=1 ORDER BY `weight`";
  457. $list = nv_db_cache( $query, '', 'users' );
  458. if( empty( $list ) ) return "";
  459. $in_groups = explode( ",", $in_groups );
  460. $groups = array();
  461. $reload = array();
  462. for( $i = 0, $count = sizeof( $list ); $i < $count; ++$i )
  463. {
  464. if( $list[$i]['exp_time'] != 0 and $list[$i]['exp_time'] <= NV_CURRENTTIME )
  465. {
  466. $reload[] = $list[$i]['group_id'];
  467. }
  468. elseif( in_array( $list[$i]['group_id'], $in_groups ) )
  469. {
  470. $groups[] = $list[$i]['group_id'];
  471. }
  472. }
  473. if( $reload )
  474. {
  475. $sql = "UPDATE `" . NV_GROUPS_GLOBALTABLE . "` SET `act`='0' WHERE `group_id` IN (" . implode( ",", $reload ) . ")";
  476. $db->sql_query( $sql );
  477. nv_del_moduleCache( 'users' );
  478. }
  479. if( empty( $groups ) ) return "";
  480. return implode( ",", $groups );
  481. }
  482. /**
  483. * nv_is_in_groups()
  484. *
  485. * @param string $in_groups
  486. * @param string $groups
  487. * @return
  488. */
  489. function nv_is_in_groups( $in_groups, $groups )
  490. {
  491. if( empty( $groups ) || empty( $in_groups ) ) return false;
  492. $in_groups = explode( ",", $in_groups );
  493. $groups = explode( ",", $groups );
  494. return ( array_intersect( $in_groups, $groups ) != array() );
  495. }
  496. /**
  497. * nv_set_allow()
  498. *
  499. * @param integer $who
  500. * @param string $groups
  501. * @return
  502. */
  503. function nv_set_allow( $who, $groups )
  504. {
  505. global $user_info;
  506. if( ! $who or ( $who == 1 and defined( 'NV_IS_USER' ) ) or ( $who == 2 and defined( 'NV_IS_ADMIN' ) ) ) return true;
  507. if( $who == 3 and ! empty( $groups ) and defined( 'NV_IS_USER' ) and nv_is_in_groups( $user_info['in_groups'], $groups ) ) return true;
  508. return false;
  509. }
  510. /**
  511. * nv_date()
  512. *
  513. * @param string $format
  514. * @param integer $time
  515. * @return
  516. */
  517. function nv_date( $format, $time = 0 )
  518. {
  519. global $lang_global;
  520. if( ! $time ) $time = NV_CURRENTTIME;
  521. $return = date( $format, $time );
  522. $replaces = array(
  523. 'Sunday' => $lang_global['sunday'],
  524. 'Monday' => $lang_global['monday'],
  525. 'Tuesday' => $lang_global['tuesday'],
  526. 'Wednesday' => $lang_global['wednesday'],
  527. 'Thursday' => $lang_global['thursday'],
  528. 'Friday' => $lang_global['friday'],
  529. 'Saturday' => $lang_global['saturday'],
  530. 'January' => $lang_global['january'],
  531. 'February' => $lang_global['february'],
  532. 'March' => $lang_global['march'],
  533. 'April' => $lang_global['april'],
  534. 'May' => $lang_global['may'],
  535. 'June' => $lang_global['june'],
  536. 'July' => $lang_global['july'],
  537. 'August' => $lang_global['august'],
  538. 'September' => $lang_global['september'],
  539. 'October' => $lang_global['october'],
  540. 'November' => $lang_global['november'],
  541. 'December' => $lang_global['december']
  542. );
  543. $return = str_replace( array_keys( $replaces ), array_values( $replaces ), $return );
  544. $replaces = array(
  545. 'Sun' => $lang_global['sun'],
  546. 'Mon' => $lang_global['mon'],
  547. 'Tue' => $lang_global['tue'],
  548. 'Wed' => $lang_global['wed'],
  549. 'Thu' => $lang_global['thu'],
  550. 'Fri' => $lang_global['fri'],
  551. 'Sat' => $lang_global['sat'],
  552. 'Jan' => $lang_global['jan'],
  553. 'Feb' => $lang_global['feb'],
  554. 'Mar' => $lang_global['mar'],
  555. 'Apr' => $lang_global['apr'],
  556. 'May' => $lang_global['may2'],
  557. 'Jun' => $lang_global['jun'],
  558. 'Jul' => $lang_global['jul'],
  559. 'Aug' => $lang_global['aug'],
  560. 'Sep' => $lang_global['sep'],
  561. 'Oct' => $lang_global['oct'],
  562. 'Nov' => $lang_global['nov'],
  563. 'Dec' => $lang_global['dec']
  564. );
  565. return str_replace( array_keys( $replaces ), array_values( $replaces ), $return );
  566. }
  567. /**
  568. * nv_monthname()
  569. *
  570. * @param integer $i
  571. * @return
  572. */
  573. function nv_monthname( $i )
  574. {
  575. global $lang_global;
  576. --$i;
  577. $month_names = array(
  578. $lang_global['january'],
  579. $lang_global['february'],
  580. $lang_global['march'],
  581. $lang_global['april'],
  582. $lang_global['may'],
  583. $lang_global['june'],
  584. $lang_global['july'],
  585. $lang_global['august'],
  586. $lang_global['september'],
  587. $lang_global['october'],
  588. $lang_global['november'],
  589. $lang_global['december']
  590. );
  591. return ( isset( $month_names[$i] ) ? $month_names[$i] : "" );
  592. }
  593. /**
  594. * nv_unhtmlspecialchars()
  595. *
  596. * @param mixed $string
  597. * @return
  598. */
  599. function nv_unhtmlspecialchars( $string )
  600. {
  601. if( empty( $string ) ) return $string;
  602. if( is_array( $string ) )
  603. {
  604. $array_keys = array_keys( $string );
  605. foreach( $array_keys as $key )
  606. {
  607. $string[$key] = nv_unhtmlspecialchars( $string[$key] );
  608. }
  609. }
  610. else
  611. {
  612. $search = array('&amp;', '&#039;', '&quot;', '&lt;', '&gt;', '&#x005C;', '&#x002F;', '&#40;', '&#41;', '&#42;', '&#91;', '&#93;', '&#33;', '&#x3D;', '&#x23;', '&#x25;', '&#x5E;', '&#x3A;', '&#x7B;', '&#x7D;', '&#x60;', '&#x7E;');
  613. $replace = array('&', '\'', '"', '<', '>', '\\', '/', '(', ')', '*', '[', ']', '!', '=', '#', '%', '^', ':', '{', '}', '`', '~');
  614. $string = str_replace( $search, $replace, $string );
  615. }
  616. return $string;
  617. }
  618. /**
  619. * nv_htmlspecialchars()
  620. *
  621. * @param mixed $string
  622. * @return
  623. */
  624. function nv_htmlspecialchars( $string )
  625. {
  626. if( empty( $string ) ) return $string;
  627. if( is_array( $string ) )
  628. {
  629. $array_keys = array_keys( $string );
  630. foreach( $array_keys as $key )
  631. {
  632. $string[$key] = nv_htmlspecialchars( $string[$key] );
  633. }
  634. }
  635. else
  636. {
  637. $search = array('&', '\'', '"', '<', '>', '\\', '/', '(', ')', '*', '[', ']', '!', '=', '%', '^', ':', '{', '}', '`', '~');
  638. $replace = array('&amp;', '&#039;', '&quot;', '&lt;', '&gt;', '&#x005C;', '&#x002F;', '&#40;', '&#41;', '&#42;', '&#91;', '&#93;', '&#33;', '&#x3D;', '&#x25;', '&#x5E;', '&#x3A;', '&#x7B;', '&#x7D;', '&#x60;', '&#x7E;');
  639. $string = str_replace( $replace, $search, $string );
  640. $string = str_replace( "&#x23;", "#", $string );
  641. $string = str_replace( $search, $replace, $string );
  642. $string = preg_replace( "/([^\&]+)\#/", "\\1&#x23;", $string );
  643. }
  644. return $string;
  645. }
  646. /**
  647. * strip_punctuation()
  648. *
  649. * @param mixed $text
  650. * @return
  651. */
  652. function strip_punctuation( $text )
  653. {
  654. $urlbrackets = '\[\]\(\)';
  655. $urlspacebefore = ':;\'_\*%@&?!' . $urlbrackets;
  656. $urlspaceafter = '\.,:;\'\-_\*@&\/\\\\\?!#' . $urlbrackets;
  657. $urlall = '\.,:;\'\-_\*%@&\/\\\\\?!#' . $urlbrackets;
  658. $specialquotes = '\'"\*<>';
  659. $fullstop = '\x{002E}\x{FE52}\x{FF0E}';
  660. $comma = '\x{002C}\x{FE50}\x{FF0C}';
  661. $arabsep = '\x{066B}\x{066C}';
  662. $numseparators = $fullstop . $comma . $arabsep;
  663. $numbersign = '\x{0023}\x{FE5F}\x{FF03}';
  664. $percent = '\x{066A}\x{0025}\x{066A}\x{FE6A}\x{FF05}\x{2030}\x{2031}';
  665. $prime = '\x{2032}\x{2033}\x{2034}\x{2057}';
  666. $nummodifiers = $numbersign . $percent . $prime;
  667. return preg_replace(
  668. array( // Remove separator, control, formatting, surrogate, open/close quotes.
  669. '/[\p{Z}\p{Cc}\p{Cf}\p{Cs}\p{Pi}\p{Pf}]/u', // Remove other punctuation except special cases
  670. '/\p{Po}(?<![' . $specialquotes . $numseparators . $urlall . $nummodifiers . '])/u', // Remove non-URL open/close brackets, except URL brackets.
  671. '/[\p{Ps}\p{Pe}](?<![' . $urlbrackets . '])/u', // Remove special quotes, dashes, connectors, number separators, and URL characters followed by a space
  672. '/[' . $specialquotes . $numseparators . $urlspaceafter . '\p{Pd}\p{Pc}]+((?= )|$)/u', // Remove special quotes, connectors, and URL characters preceded by a space
  673. '/((?<= )|^)[' . $specialquotes . $urlspacebefore . '\p{Pc}]+/u', // Remove dashes preceded by a space, but not followed by a number
  674. '/((?<= )|^)\p{Pd}+(?![\p{N}\p{Sc}])/u', // Remove consecutive spaces
  675. '/ +/'
  676. ),
  677. ' ',
  678. $text
  679. );
  680. }
  681. /**
  682. * nv_nl2br()
  683. *
  684. * @param string $text
  685. * @param string $replacement
  686. * @return
  687. */
  688. function nv_nl2br( $text, $replacement = '<br />' )
  689. {
  690. if( empty( $text ) ) return '';
  691. return strtr( $text, array(
  692. "\r\n" => $replacement,
  693. "\r" => $replacement,
  694. "\n" => $replacement
  695. )
  696. );
  697. }
  698. /**
  699. * nv_br2nl()
  700. *
  701. * @param string $text
  702. * @return
  703. */
  704. function nv_br2nl( $text )
  705. {
  706. if( empty( $text ) ) return '';
  707. return preg_replace( '/\<br(\s*)?\/?(\s*)?\>/i', chr( 13 ) . chr( 10 ), $text );
  708. }
  709. /**
  710. * nv_editor_nl2br()
  711. *
  712. * @param string $text
  713. * @return
  714. */
  715. function nv_editor_nl2br( $text )
  716. {
  717. if( empty( $text ) ) return '';
  718. $replacement = defined( 'NV_EDITOR' ) ? '' : '<br />';
  719. return nv_nl2br( $text, ( defined( 'NV_EDITOR' ) ? '' : '<br />' ) );
  720. }
  721. /**
  722. * nv_editor_br2nl()
  723. *
  724. * @param mixed $text
  725. * @return
  726. */
  727. function nv_editor_br2nl( $text )
  728. {
  729. if( empty( $text ) ) return '';
  730. if( defined( 'NV_EDITOR' ) ) return $text;
  731. return nv_br2nl( $text );
  732. }
  733. /**
  734. * filter_text_input()
  735. *
  736. * @param string $inputname
  737. * @param string $mode
  738. * @param string $default
  739. * @param bool $specialchars
  740. * @param integer $maxlength
  741. * @param mixed $preg_replace
  742. * @return
  743. */
  744. function filter_text_input( $inputname, $mode = 'request', $default = '', $specialchars = false, $maxlength = 0, $preg_replace = array() )
  745. {
  746. global $nv_Request;
  747. $value = $nv_Request->get_string( $inputname, $mode, $default );
  748. $value = strip_tags( $value );
  749. if( ( bool )$specialchars == true )
  750. {
  751. $value = nv_htmlspecialchars( $value );
  752. }
  753. if( ( int )$maxlength > 0 )
  754. {
  755. $value = nv_substr( $value, 0, $maxlength );
  756. }
  757. if( ! empty( $preg_replace ) )
  758. {
  759. if( isset( $preg_replace['pattern'] ) and ! empty( $preg_replace['pattern'] ) and isset( $preg_replace['replacement'] ) )
  760. {
  761. $value = preg_replace( $preg_replace['pattern'], $preg_replace['replacement'], $value );
  762. }
  763. }
  764. return trim( $value );
  765. }
  766. /**
  767. * filter_text_textarea()
  768. *
  769. * @param string $inputname
  770. * @param string $default
  771. * @param string $allowed_html_tags
  772. * @param bool $save
  773. * @param string $nl2br_replacement
  774. * @return
  775. */
  776. function filter_text_textarea( $inputname, $default = '', $allowed_html_tags = '', $save = false, $nl2br_replacement = '<br />' )
  777. {
  778. global $nv_Request;
  779. $value = $nv_Request->get_string( $inputname, 'post', $default );
  780. if( empty( $value ) ) return $value;
  781. if( ! empty( $allowed_html_tags ) )
  782. {
  783. $allowed_html_tags = array_map( "trim", explode( ",", $allowed_html_tags ) );
  784. $allowed_html_tags = "<" . implode( "><", $allowed_html_tags ) . ">";
  785. $value = strip_tags( $value, $allowed_html_tags );
  786. }
  787. if( ( bool )$save ) $value = nv_nl2br( $value, $nl2br_replacement );
  788. return $value;
  789. }
  790. /**
  791. * nv_editor_filter_textarea()
  792. *
  793. * @param string $inputname
  794. * @param string $default
  795. * @param string $allowed_html_tags
  796. * @param bool $save
  797. * @param string $nl2br_replacement
  798. * @return
  799. */
  800. function nv_editor_filter_textarea( $inputname, $default = '', $allowed_html_tags = '', $save = false, $nl2br_replacement = '<br />' )
  801. {
  802. global $nv_Request;
  803. $value = $nv_Request->get_string( $inputname, 'post', $default );
  804. if( empty( $value ) ) return '';
  805. if( ! empty( $allowed_html_tags ) and ! defined( 'NV_EDITOR' ) )
  806. {
  807. $allowed_html_tags = array_map( "trim", explode( ",", $allowed_html_tags ) );
  808. $allowed_html_tags = "<" . implode( "><", $allowed_html_tags ) . ">";
  809. $value = strip_tags( $value, $allowed_html_tags );
  810. }
  811. if( empty( $value ) ) return '';
  812. if( ( bool )$save )
  813. {
  814. $value = nv_editor_nl2br( $value, $nl2br_replacement );
  815. }
  816. return $value;
  817. }
  818. /**
  819. * nv_get_keywords()
  820. *
  821. * @param string $content
  822. * @return
  823. */
  824. function nv_get_keywords( $content = "" )
  825. {
  826. if( empty( $content ) ) return ( "" );
  827. $content = strip_tags( $content );
  828. $content = nv_unhtmlspecialchars( $content );
  829. $content = strip_punctuation( $content );
  830. $content = trim( $content );
  831. $content = nv_strtolower( $content );
  832. $content = " " . $content . " ";
  833. $keywords_return = array();
  834. $memoryLimitMB = ( integer )ini_get( 'memory_limit' );
  835. if( $memoryLimitMB > 60 and file_exists( NV_ROOTDIR . "/includes/keywords/" . NV_LANG_DATA . ".php" ) )
  836. {
  837. require ( NV_ROOTDIR . "/includes/keywords/" . NV_LANG_DATA . ".php" );
  838. $content_array = explode( " ", $content );
  839. $a = 0;
  840. $b = sizeof( $content_array );
  841. for( $i = 0; $i < $b - 3; ++$i )
  842. {
  843. $key3 = $content_array[$i] . ' ' . $content_array[$i + 1] . ' ' . $content_array[$i + 2];
  844. $key2 = $content_array[$i] . ' ' . $content_array[$i + 1];
  845. if( array_search( $key3, $array_keywords_3 ) )
  846. {
  847. $keywords_return[] = $key3;
  848. $i = $i + 2;
  849. }
  850. elseif( array_search( $key2, $array_keywords_2 ) )
  851. {
  852. $keywords_return[] = $key2;
  853. $i = $i + 1;
  854. }
  855. $keywords_return = array_unique( $keywords_return );
  856. if( sizeof( $keywords_return ) > 20 )
  857. {
  858. break;
  859. }
  860. }
  861. }
  862. else
  863. {
  864. $pattern_word = array();
  865. if( NV_SITEWORDS_MIN_3WORDS_LENGTH > 0 and NV_SITEWORDS_MIN_3WORDS_PHRASE_OCCUR > 0 )
  866. {
  867. $pattern_word[] = "/[\s]+([\S]{" . NV_SITEWORDS_MIN_3WORDS_LENGTH . ",}\s[\S]{" . NV_SITEWORDS_MIN_3WORDS_LENGTH . ",}\s[\S]{" . NV_SITEWORDS_MIN_3WORDS_LENGTH . ",})[\s]+/uis";
  868. }
  869. if( NV_SITEWORDS_MIN_2WORDS_LENGTH > 0 and NV_SITEWORDS_MIN_2WORDS_PHRASE_OCCUR > 0 )
  870. {
  871. $pattern_word[] = "/[\s]+([\S]{" . NV_SITEWORDS_MIN_2WORDS_LENGTH . ",}\s[\S]{" . NV_SITEWORDS_MIN_2WORDS_LENGTH . ",})[\s]+/uis";
  872. }
  873. if( NV_SITEWORDS_MIN_WORD_LENGTH > 0 and NV_SITEWORDS_MIN_WORD_OCCUR > 0 )
  874. {
  875. $pattern_word[] = "/[\s]+([\S]{" . NV_SITEWORDS_MIN_WORD_LENGTH . ",})[\s]+/uis";
  876. }
  877. if( empty( $pattern_word ) ) return ( "" );
  878. $lenght = 0;
  879. $max_strlen = min( NV_SITEWORDS_MAX_STRLEN, 300 );
  880. foreach( $pattern_word as $pattern )
  881. {
  882. while( preg_match( $pattern, $content, $matches ) )
  883. {
  884. $keywords_return[] = $matches[1];
  885. $lenght += nv_strlen( $matches[1] );
  886. $content = preg_replace( "/[\s]+(" . preg_quote( $matches[1] ) . ")[\s]+/uis", " ", $content );
  887. if( $lenght >= $max_strlen ) break;
  888. }
  889. if( $lenght >= $max_strlen ) break;
  890. }
  891. $keywords_return = array_unique( $keywords_return );
  892. }
  893. return implode( ",", $keywords_return );
  894. }
  895. /**
  896. * nv_sendmail()
  897. *
  898. * @param mixed $from
  899. * @param mixed $to
  900. * @param string $subject
  901. * @param string $message
  902. * @param string $files
  903. * @return
  904. */
  905. function nv_sendmail( $from, $to, $subject, $message, $files = '' )
  906. {
  907. global $global_config, $sys_info;
  908. $sendmail_from = ini_get( 'sendmail_from' );
  909. require_once ( NV_ROOTDIR . '/includes/phpmailer/class.phpmailer.php' );
  910. try
  911. {
  912. $mail = new PHPMailer( true );
  913. $mail->SetLanguage(NV_LANG_INTERFACE, NV_ROOTDIR . '/includes/phpmailer/language/');
  914. $mail->CharSet = $global_config['site_charset'];
  915. $mailer_mode = strtolower( $global_config['mailer_mode'] );
  916. if( $mailer_mode == 'smtp' )
  917. {
  918. $mail->IsSMTP();
  919. $mail->SMTPAuth = true;
  920. $mail->Port = $global_config['smtp_port'];
  921. $mail->Host = $global_config['smtp_host'];
  922. $mail->Username = $global_config['smtp_username'];
  923. $mail->Password = $global_config['smtp_password'];
  924. $SMTPSecure = intval( $global_config['smtp_ssl'] );
  925. switch( $SMTPSecure )
  926. {
  927. case 1:
  928. $mail->SMTPSecure = 'ssl';
  929. break;
  930. case 2:
  931. $mail->SMTPSecure = 'tls';
  932. break;
  933. default:
  934. $mail->SMTPSecure = '';
  935. }
  936. }
  937. elseif( $mailer_mode == 'sendmail' )
  938. {
  939. $mail->IsSendmail();
  940. }
  941. elseif( ! in_array( 'mail', $sys_info['disable_functions'] ) )
  942. {
  943. $mail->IsMail();
  944. }
  945. else
  946. {
  947. return false;
  948. }
  949. $message = nv_change_buffer( $message );
  950. $message = nv_unhtmlspecialchars( $message );
  951. $subject = nv_unhtmlspecialchars( $subject );
  952. $mail->From = $sendmail_from;
  953. $mail->FromName = $global_config['site_name'];
  954. if( is_array( $from ) )
  955. {
  956. $mail->AddReplyTo( $from[1], $from[0] );
  957. }
  958. else
  959. {
  960. $mail->AddReplyTo( $from );
  961. }
  962. if( empty( $to ) ) return false;
  963. if( ! is_array( $to ) ) $to = array( $to );
  964. foreach( $to as $_to )
  965. {
  966. $mail->AddAddress( $_to );
  967. }
  968. $mail->Subject = $subject;
  969. $mail->WordWrap = 120;
  970. $mail->MsgHTML( $message );
  971. $mail->IsHTML( true );
  972. if( ! empty( $files ) )
  973. {
  974. $files = array_map( "trim", explode( ",", $files ) );
  975. foreach( $files as $file )
  976. {
  977. $mail->AddAttachment( $file );
  978. }
  979. }
  980. $send = $mail->Send();
  981. if( ! $send )
  982. {
  983. trigger_error( $mail->ErrorInfo, E_USER_WARNING );
  984. }
  985. return $send;
  986. }
  987. catch ( phpmailerException $e )
  988. {
  989. trigger_error( $e->errorMessage(), E_USER_WARNING );
  990. return false;
  991. }
  992. }
  993. /**
  994. * nv_generate_page()
  995. *
  996. * @param string $base_url
  997. * @param integer $num_items
  998. * @param integer $per_page
  999. * @param integer $start_item
  1000. * @param bool $add_prevnext_text
  1001. * @param bool $onclick
  1002. * @param string $js_func_name
  1003. * @param string $containerid
  1004. * @return
  1005. */
  1006. function nv_generate_page( $base_url, $num_items, $per_page, $start_item, $add_prevnext_text = true, $onclick = false, $js_func_name = 'nv_urldecode_ajax', $containerid = 'generate_page' )
  1007. {
  1008. global $lang_global;
  1009. $total_pages = ceil( $num_items / $per_page );
  1010. if( $total_pages == 1 ) return '';
  1011. $on_page = @floor( $start_item / $per_page ) + 1;
  1012. if( ! is_array( $base_url ) )
  1013. {
  1014. $amp = preg_match( "/\?/", $base_url ) ? "&amp;" : "?";
  1015. $amp .= "page=";
  1016. }
  1017. else
  1018. {
  1019. $amp = $base_url['amp'];
  1020. $base_url = $base_url['link'];
  1021. }
  1022. $page_string = "";
  1023. if( $total_pages > 10 )
  1024. {
  1025. $init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;
  1026. for( $i = 1; $i <= $init_page_max; ++$i )
  1027. {
  1028. $href = ( $i - 1 ) * $per_page;
  1029. $href = $href ? $base_url . $amp . $href : $base_url;
  1030. $href = ! $onclick ? "href=\"" . $href . "\"" : "href=\"javascript:void(0)\" onclick=\"" . $js_func_name . "('" . rawurlencode( nv_unhtmlspecialchars( $href ) ) . "','" . $containerid . "')\"";
  1031. $page_string .= ( $i == $on_page ) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  1032. if( $i < $init_page_max ) $page_string .= ", ";
  1033. }
  1034. if( $total_pages > 3 )
  1035. {
  1036. if( $on_page > 1 && $on_page < $total_pages )
  1037. {
  1038. $page_string .= ( $on_page > 5 ) ? " ... " : ", ";
  1039. $init_page_min = ( $on_page > 4 ) ? $on_page : 5;
  1040. $init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;
  1041. for( $i = $init_page_min - 1; $i < $init_page_max + 2; ++$i )
  1042. {
  1043. $href = ( $i - 1 ) * $per_page;
  1044. $href = $href ? $base_url . $amp . $href : $base_url;
  1045. $href = ! $onclick ? "href=\"" . $href . "\"" : "href=\"javascript:void(0)\" onclick=\"" . $js_func_name . "('" . rawurlencode( nv_unhtmlspecialchars( $href ) ) . "','" . $containerid . "')\"";
  1046. $page_string .= ( $i == $on_page ) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  1047. if( $i < $init_page_max + 1 )
  1048. {
  1049. $page_string .= ", ";
  1050. }
  1051. }
  1052. $page_string .= ( $on_page < $total_pages - 4 ) ? " ... " : ", ";
  1053. }
  1054. else
  1055. {
  1056. $page_string .= " ... ";
  1057. }
  1058. for( $i = $total_pages - 2; $i < $total_pages + 1; ++$i )
  1059. {
  1060. $href = ( $i - 1 ) * $per_page;
  1061. $href = $href ? $base_url . $amp . $href : $base_url;
  1062. $href = ! $onclick ? "href=\"" . $href . "\"" : "href=\"javascript:void(0)\" onclick=\"" . $js_func_name . "('" . rawurlencode( nv_unhtmlspecialchars( $href ) ) . "','" . $containerid . "')\"";
  1063. $page_string .= ( $i == $on_page ) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  1064. if( $i < $total_pages )
  1065. {
  1066. $page_string .= ", ";
  1067. }
  1068. }
  1069. }
  1070. }
  1071. else
  1072. {
  1073. for( $i = 1; $i < $total_pages + 1; ++$i )
  1074. {
  1075. $href = ( $i - 1 ) * $per_page;
  1076. $href = $href ? $base_url . $amp . $href : $base_url;
  1077. $href = ! $onclick ? "href=\"" . $href . "\"" : "href=\"javascript:void(0)\" onclick=\"" . $js_func_name . "('" . rawurlencode( nv_unhtmlspecialchars( $href ) ) . "','" . $containerid . "')\"";
  1078. $page_string .= ( $i == $on_page ) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  1079. if( $i < $total_pages )
  1080. {
  1081. $page_string .= ", ";
  1082. }
  1083. }
  1084. }
  1085. if( $add_prevnext_text )
  1086. {
  1087. if( $on_page > 1 )
  1088. {
  1089. $href = ( $on_page - 2 ) * $per_page;
  1090. $href = $href ? $base_url . $amp . $href : $base_url;
  1091. $href = ! $onclick ? "href=\"" . $href . "\"" : "href=\"javascript:void(0)\" onclick=\"" . $js_func_name . "('" . rawurlencode( nv_unhtmlspecialchars( $href ) ) . "','" . $containerid . "')\"";
  1092. $page_string = "&nbsp;&nbsp;<span><a " . $href . ">" . $lang_global['pageprev'] . "</a></span>&nbsp;&nbsp;" . $page_string;
  1093. }
  1094. if( $on_page < $total_pages )
  1095. {
  1096. $href = $on_page * $per_page;
  1097. $href = $href ? $base_url . $amp . $href : $base_url;
  1098. $href = ! $onclick ? "href=\"" . $href . "\"" : "href=\"javascript:void(0)\" onclick=\"" . $js_func_name . "('" . rawurlencode( nv_unhtmlspecialchars( $href ) ) . "','" . $containerid . "')\"";
  1099. $page_string .= "&nbsp;&nbsp;<span><a " . $href . ">" . $lang_global['pagenext'] . "</a></span>";
  1100. }
  1101. }
  1102. return $page_string;
  1103. }
  1104. function nv_alias_page( $title, $base_url, $num_items, $per_page, $on_page, $add_prevnext_text = true )
  1105. {
  1106. global $lang_global;
  1107. $total_pages = ceil( $num_items / $per_page );
  1108. if( $total_pages < 2 ) return '';
  1109. $title .= ' ' . NV_TITLEBAR_DEFIS . ' ' . $lang_global['page'];
  1110. $page_string = ( $on_page == 1 ) ? "<strong>1</strong> " : "<a title=\"" . $title . " 1\" href=\"" . $base_url . "\">1</a> ";
  1111. if( $total_pages > 10 )
  1112. {
  1113. $init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;
  1114. for( $i = 2; $i <= $init_page_max; ++$i )
  1115. {
  1116. $page_string .= ( $i == $on_page ) ? "<strong>" . $i . "</strong>" : "<a title=\"" . $title . " " . $i . "\" href=\"" . $base_url . "/page-" . $i . "\">" . $i . "</a>";
  1117. if( $i < $init_page_max ) $page_string .= " ";
  1118. }
  1119. if( $total_pages > 3 )
  1120. {
  1121. if( $on_page > 1 && $on_page < $total_pages )
  1122. {
  1123. $page_string .= ( $on_page > 5 ) ? " ... " : " ";
  1124. $init_page_min = ( $on_page > 4 ) ? $on_page : 5;
  1125. $init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;
  1126. for( $i = $init_page_min - 1; $i < $init_page_max + 2; ++$i )
  1127. {
  1128. $page_string .= ( $i == $on_page ) ? "<strong>" . $i . "</strong>" : "<a title=\"" . $title . " " . $i . "\" href=\"" . $base_url . "/page-" . $i . "\">" . $i . "</a>";
  1129. if( $i < $init_page_max + 1 )
  1130. {
  1131. $page_string .= " ";
  1132. }
  1133. }
  1134. $page_string .= ( $on_page < $total_pages - 4 ) ? " ... " : " ";
  1135. }
  1136. else
  1137. {
  1138. $page_string .= " ... ";
  1139. }
  1140. for( $i = $total_pages - 2; $i < $total_pages + 1; ++$i )
  1141. {
  1142. $page_string .= ( $i == $on_page ) ? "<strong>" . $i . "</strong>" : "<a title=\"" . $title . " " . $i . "\" href=\"" . $base_url . "/page-" . $i . "\">" . $i . "</a>";
  1143. if( $i < $total_pages )
  1144. {
  1145. $page_string .= " ";
  1146. }
  1147. }
  1148. }
  1149. }
  1150. else
  1151. {
  1152. for( $i = 2; $i < $total_pages + 1; ++$i )
  1153. {
  1154. $page_string .= ( $i == $on_page ) ? "<strong>" . $i . "</strong>" : "<a title=\"" . $title . " " . $i . "\" href=\"" . $base_url . "/page-" . $i . "\">" . $i . "</a>";
  1155. if( $i < $total_pages )
  1156. {
  1157. $page_string .= " ";
  1158. }
  1159. }
  1160. }
  1161. if( $add_prevnext_text )
  1162. {
  1163. if( $on_page > 1 )
  1164. {
  1165. $page_string = "&nbsp;&nbsp;<span><a title=\"" . $title . " " . ( $on_page - 1 ) . "\" href=\"" . $base_url . "/page-" . ( $on_page - 1 ) . "\">" . $lang_global['pageprev'] . "</a></span>&nbsp;&nbsp;" . $page_string;
  1166. }
  1167. if( $on_page < $total_pages )
  1168. {
  1169. $page_string .= "&nbsp;&nbsp;<span><a title=\"" . $title . " " . ( $on_page + 1 ) . "\" href=\"" . $base_url . "/page-" . ( $on_page + 1 ) . "\">" . $lang_global['pagenext'] . "</a></span>";
  1170. }
  1171. }
  1172. return $page_string;
  1173. }
  1174. /**
  1175. * nv_is_url()
  1176. *
  1177. * @param string $url
  1178. * @return
  1179. */
  1180. function nv_is_url( $url )
  1181. {
  1182. if( empty( $url ) ) return false;
  1183. $url = nv_strtolower( $url );
  1184. if( ! ( $parts = @parse_url( $url ) ) ) return false;
  1185. if( ! isset( $parts['scheme'] ) or ! isset( $parts['host'] ) or ( ! in_array( $parts['scheme'], array( 'http', 'https', 'ftp', 'gopher' ) ) ) ) return false;
  1186. if( ! preg_match( "/^[0-9a-z]([\-\.]?[0-9a-z])*\.(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|asia|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|ke|kg|kh|ki|km|kn|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw|xxx)$/", $parts['host'] ) )
  1187. {
  1188. if( $parts['host'] != 'localhost' and ! filter_var($parts['host'], FILTER_VALIDATE_IP) )
  1189. {
  1190. return false;
  1191. }
  1192. }
  1193. if( isset( $parts['user'] ) and ! preg_match( "/^([0-9a-z\-]|[\_])*$/", $parts['user'] ) ) return false;
  1194. if( isset( $parts['pass'] ) and ! preg_match( "/^([0-9a-z\-]|[\_])*$/", $parts['pass'] ) ) return false;
  1195. if( isset( $parts['path'] ) and ! preg_match( "/^[0-9A-Za-z\/\_\.\@\~\-\%\\s]*$/", $parts['path'] ) ) return false;
  1196. if( isset( $parts['query'] ) and ! preg_match( "/^[0-9a-z\-\_\/\?\&\=\#\.\,\;\%\\s]*$/", $parts['query'] ) ) return false;
  1197. return true;
  1198. }
  1199. /**
  1200. * nv_check_url()
  1201. *
  1202. * @param string $url
  1203. * @param bool $is_200
  1204. * @return
  1205. */
  1206. function nv_check_url( $url, $is_200 = 0 )
  1207. {
  1208. if( empty( $url ) ) return false;
  1209. $url = str_replace( " ", "%20", $url );
  1210. $allow_url_fopen = ( ini_get( 'allow_url_fopen' ) == '1' || strtolower( ini_get( 'allow_url_fopen' ) ) == 'on' ) ? 1 : 0;
  1211. if( nv_function_exists( 'get_headers' ) and $allow_url_fopen == 1 )
  1212. {
  1213. $res = get_headers( $url );
  1214. }
  1215. elseif( nv_function_exists( 'curl_init' ) and nv_function_exists( 'curl_exec' ) )
  1216. {
  1217. $url_info = @parse_url( $url );
  1218. $port = isset( $url_info['port'] ) ? intval( $url_info['port'] ) : 80;
  1219. $userAgents = array( //
  1220. 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0', //
  1221. 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', //
  1222. 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)', //
  1223. 'Mozilla/4.8 [en] (Windows NT 6.0; U)', //
  1224. 'Opera/9.25 (Windows NT 6.0; U; en)'
  1225. );
  1226. $safe_mode = ( ini_get( 'safe_mode' ) == '1' || strtolower( ini_get( 'safe_mode' ) ) == 'on' ) ? 1 : 0;
  1227. $open_basedir = ( ini_get( 'open_basedir' ) == '1' || strtolower( ini_get( 'open_basedir' ) ) == 'on' ) ? 1 : 0;
  1228. srand( ( float )microtime() * 10000000 );
  1229. $rand = array_rand( $userAgents );
  1230. $agent = $userAgents[$rand];
  1231. $curl = curl_init( $url );
  1232. curl_setopt( $curl, CURLOPT_HEADER, true );
  1233. curl_setopt( $curl, CURLOPT_NOBODY, true );
  1234. curl_setopt( $curl, CURLOPT_PORT, $port );
  1235. if( ! $safe_mode and $open_basedir )
  1236. {
  1237. curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
  1238. }
  1239. curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
  1240. curl_setopt( $curl, CURLOPT_TIMEOUT, 15 );
  1241. curl_setopt( $curl, CURLOPT_USERAGENT, $agent );
  1242. $response = curl_exec( $curl );
  1243. curl_close( $curl );
  1244. if( $response === false )
  1245. {
  1246. trigger_error( curl_error( $curl ), E_USER_WARNING );
  1247. return false;
  1248. }
  1249. else
  1250. {
  1251. $res = explode( "\n", $response );
  1252. }
  1253. }
  1254. elseif( nv_function_exists( 'fsockopen' ) and nv_function_exists( 'fgets' ) )
  1255. {
  1256. $res = array();
  1257. $url_info = parse_url( $url );
  1258. $port = isset( $url_info['port'] ) ? intval( $url_info['port'] ) : 80;
  1259. $fp = fsockopen( $url_info['host'], $port, $errno, $errstr, 15 );
  1260. if( ! $fp )
  1261. {
  1262. trigger_error( $errstr, E_USER_WARNING );
  1263. return false;
  1264. }
  1265. $path = ! empty( $url_info['path'] ) ? $url_info['path'] : '/';
  1266. $path .= ! empty( $url_info['query'] ) ? '?' . $url_info['query'] : '';
  1267. fputs( $fp, "HEAD " . $path . " HTTP/1.0\r\n" );
  1268. fputs( $fp, "Host: " . $url_info['host'] . ":" . $port . "\r\n" );
  1269. fputs( $fp, "Connection: close\r\n\r\n" );
  1270. while( ! feof( $fp ) )
  1271. {
  1272. if( $header = trim( fgets( $fp, 1024 ) ) )
  1273. {
  1274. $res[] = $header;
  1275. }
  1276. }
  1277. @fclose( $fp );
  1278. }
  1279. else
  1280. {
  1281. trigger_error( 'error server no support check url', E_USER_WARNING );
  1282. return false;
  1283. }
  1284. if( empty( $res ) ) return false;
  1285. if( preg_match( "/(200)/", $res[0] ) ) return true;
  1286. if( $is_200 > 5 ) return false;
  1287. if( preg_match( "/(301)|(302)|(303)/", $res[0] ) )
  1288. {
  1289. foreach( $res as $k => $v )
  1290. {
  1291. if( preg_match( "/location:\s(.*?)$/is", $v, $matches ) )
  1292. {
  1293. ++$is_200;
  1294. $location = trim( $matches[1] );
  1295. return nv_check_url( $location, $is_200 );
  1296. }
  1297. }
  1298. }
  1299. return false;
  1300. }
  1301. /**
  1302. * nv_check_rewrite_file()
  1303. *
  1304. * @return
  1305. */
  1306. function nv_check_rewrite_file()
  1307. {
  1308. global $sys_info;
  1309. if( $sys_info['supports_rewrite'] == 'rewrite_mode_apache' )
  1310. {
  1311. if( ! file_exists( NV_ROOTDIR . '/.htaccess' ) ) return false;
  1312. $htaccess = @file_get_contents( NV_ROOTDIR . '/.htaccess' );
  1313. return ( preg_match( "/\#nukeviet\_rewrite\_start(.*)\#nukeviet\_rewrite\_end/s", $htaccess ) );
  1314. }
  1315. if( $sys_info['supports_rewrite'] == 'rewrite_mode_iis' )
  1316. {
  1317. if( ! file_exists( NV_ROOTDIR . '/web.config' ) ) return false;
  1318. $web_config = @file_get_contents( NV_ROOTDIR . '/web.config' );
  1319. return ( preg_match( "/<rule name=\"nv_rule_rewrite\">(.*)<\/rule>/s", $web_config ) );
  1320. }
  1321. return false;
  1322. }
  1323. /**
  1324. * nv_url_rewrite()
  1325. *
  1326. * @param string $buffer
  1327. * @param bool $is_url
  1328. * @return
  1329. */
  1330. function nv_url_rewrite( $buffer, $is_url = false )
  1331. {
  1332. global $rewrite;
  1333. if( ! empty( $rewrite ) )
  1334. {
  1335. if( $is_url ) $buffer = "\"" . $buffer . "\"";
  1336. $buffer = preg_replace( array_keys( $rewrite ), array_values( $rewrite ), $buffer );
  1337. if( $is_url ) $buffer = substr( $buffer, 1, -1 );
  1338. }
  1339. return $buffer;
  1340. }
  1341. /**
  1342. * nv_valid_html()
  1343. *
  1344. * @param string $html
  1345. * @param mixed $config
  1346. * @param string $encoding
  1347. * @return
  1348. */
  1349. function nv_valid_html( $html, $config, $encoding = 'utf8' )
  1350. {
  1351. global $sys_info;
  1352. if( $sys_info['supports_tidy'] == "class" )
  1353. {
  1354. $tidy = new tidy();
  1355. $tidy->parseString( $html, $config, $encoding );
  1356. $tidy->cleanRepair();
  1357. return $tidy;
  1358. }
  1359. if( $sys_info['supports_tidy'] == "func" )
  1360. {
  1361. $tidy = tidy_parse_string( $html, $config, $encoding );
  1362. tidy_clean_repair();
  1363. return $tidy;
  1364. }
  1365. return $html;
  1366. }
  1367. /**
  1368. * nv_change_buffer()
  1369. *
  1370. * @param mixed $buffer
  1371. * @return
  1372. */
  1373. function nv_change_buffer( $buffer )
  1374. {
  1375. global $db, $sys_info, $global_config;
  1376. $buffer = $db->unfixdb( $buffer );
  1377. $buffer = nv_url_rewrite( $buffer );
  1378. if( defined( "NV_ANTI_IFRAME" ) and NV_ANTI_IFRAME ) $buffer = preg_replace( "/(<body[^>]*>)/", "$1\r\n<script type=\"text/javascript\">if(window.top!==window.self){document.write=\"\";window.top.location=window.self.location;setTimeout(function(){document.body.innerHTML=\"\"},1);window.self.onload=function(){document.body.innerHTML=\"\"}};</script>", $buffer, 1 );
  1379. if( ! empty( $global_config['googleAnalyticsID'] ) and preg_match( '/^UA-\d{4,}-\d+$/', $global_config['googleAnalyticsID'] ) )
  1380. {
  1381. $dp = "";
  1382. if( $global_config['googleAnalyticsSetDomainName'] == 1 )
  1383. {
  1384. $dp .= "_gaq.push([\"_setDomainName\",\"" . $global_config['cookie_domain'] . "\"]);";
  1385. }
  1386. elseif( $global_config['googleAnalyticsSetDomainName'] == 2 )
  1387. {
  1388. $dp .= "_gaq.push([\"_setDomainName\",\"none\"]);_gaq.push([\"_setAllowLinker\",true]);";
  1389. }
  1390. $googleAnalytics = "<script type=\"text/javascript\">\r\n";
  1391. $googleAnalytics .= "//<![CDATA[\r\n";
  1392. $googleAnalytics .= "var _gaq=_gaq||[];_gaq.push([\"_setAccount\",\"" . $global_config['googleAnalyticsID'] . "\"]);" . $dp . "_gaq.push([\"_trackPageview\"]);(function(){var a=document.createE…

Large files files are truncated, but you can click here to view the full file