PageRenderTime 60ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/NukeViet3.3/includes/functions.php

http://nuke-viet.googlecode.com/
PHP | 1913 lines | 1325 code | 223 blank | 365 comment | 267 complexity | be2994cf3972cd6c95385a7259401c31 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.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES.,JSC. All rights reserved
  6. * @Createdate 1/9/2010, 23:48
  7. */
  8. if (!defined('NV_MAINFILE'))
  9. die('Stop!!!');
  10. require_once (NV_ROOTDIR . '/includes/utf8/' . $sys_info['string_handler'] . '_string_handler.php');
  11. require_once (NV_ROOTDIR . '/includes/utf8/utf8_functions.php');
  12. require_once (NV_ROOTDIR . '/includes/core/filesystem_functions.php');
  13. require_once (NV_ROOTDIR . '/includes/core/cache_functions.php');
  14. /**
  15. * array_intersect_key()
  16. *
  17. * @param mixed $a
  18. * @param mixed $b
  19. * @return
  20. */
  21. if (!function_exists('array_intersect_key'))
  22. {
  23. function array_intersect_key($a, $b)
  24. {
  25. $c = func_num_args();
  26. if ($c > 2)
  27. {
  28. for ($d = 1; !empty($a) && $d < $c; ++$d)
  29. {
  30. $e = func_get_arg($d);
  31. $array_keys = array_keys($a);
  32. foreach ($array_keys as $f)
  33. {
  34. if (!isset($e[$f]))
  35. unset($a[$f]);
  36. }
  37. }
  38. return $a;
  39. }
  40. $g = array();
  41. $array_keys = array_keys($a);
  42. foreach ($array_keys as $f)
  43. {
  44. if (isset($b[$f]))
  45. $g[$f] = $a[$f];
  46. }
  47. return $g;
  48. }
  49. }
  50. /**
  51. * array_diff_key()
  52. *
  53. * @return
  54. */
  55. if (!function_exists('array_diff_key'))
  56. {
  57. function array_diff_key()
  58. {
  59. $a = func_get_args();
  60. $b = array_shift($a);
  61. foreach ($a as $c)
  62. {
  63. foreach ($b as $d => $e)
  64. {
  65. if (array_key_exists($d, $c))
  66. unset($b[$d]);
  67. }
  68. }
  69. return $b;
  70. }
  71. }
  72. /**
  73. * nv_object2array()
  74. *
  75. * @param mixed $a
  76. * @return
  77. */
  78. function nv_object2array($a)
  79. {
  80. if (is_object($a))
  81. $a = get_object_vars($a);
  82. return is_array($a) ? array_map(__function__, $a) : $a;
  83. }
  84. /**
  85. * nv_getenv()
  86. *
  87. * @param mixed $a
  88. * @return
  89. */
  90. function nv_getenv($a)
  91. {
  92. if (!is_array($a))
  93. {
  94. $a = array($a);
  95. }
  96. foreach ($a as $b)
  97. {
  98. if (isset($_SERVER[$b]))
  99. return $_SERVER[$b];
  100. elseif (isset($_ENV[$b]))
  101. return $_ENV[$b];
  102. elseif (@getenv($b))
  103. return @getenv($b);
  104. elseif (function_exists('apache_getenv') && apache_getenv($b, true))
  105. return apache_getenv($b, true);
  106. }
  107. return "";
  108. }
  109. /**
  110. * nv_preg_quote()
  111. *
  112. * @param string $a
  113. * @return
  114. */
  115. function nv_preg_quote($a)
  116. {
  117. return preg_quote($a, "/");
  118. }
  119. /**
  120. * nv_is_myreferer()
  121. *
  122. * @param string $referer
  123. * @return
  124. */
  125. function nv_is_myreferer($referer = "")
  126. {
  127. if (empty($referer))
  128. $referer = urldecode(nv_getenv('HTTP_REFERER'));
  129. if (empty($referer))
  130. return 2;
  131. $server_name = preg_replace('/^[w]+\./e', '', nv_getenv("HTTP_HOST"));
  132. $referer = preg_replace(array('/^[a-zA-Z]+\:\/\/([w]+\.)?/e', '/^[w]+\./e'), '', $referer);
  133. if (preg_match("/^" . nv_preg_quote($server_name) . "/", $referer))
  134. return 1;
  135. return 0;
  136. }
  137. /**
  138. * nv_is_blocker_proxy()
  139. *
  140. * @param string $is_proxy
  141. * @param integer $proxy_blocker
  142. * @return
  143. */
  144. function nv_is_blocker_proxy($is_proxy, $proxy_blocker)
  145. {
  146. if ($proxy_blocker == 1 and $is_proxy == 'Strong')
  147. return true;
  148. if ($proxy_blocker == 2 and ($is_proxy == 'Strong' || $is_proxy == 'Mild'))
  149. return true;
  150. if ($proxy_blocker == 3 and $is_proxy != 'No')
  151. return true;
  152. return false;
  153. }
  154. /**
  155. * nv_is_banIp()
  156. *
  157. * @param string $ip
  158. * @return
  159. */
  160. function nv_is_banIp($ip)
  161. {
  162. $array_banip_site = $array_banip_admin = array();
  163. if (file_exists(NV_ROOTDIR . "/" . NV_DATADIR . "/banip.php"))
  164. include (NV_ROOTDIR . "/" . NV_DATADIR . "/banip.php");
  165. $banIp = ( defined('NV_ADMIN')) ? $array_banip_admin : $array_banip_site;
  166. if (empty($banIp))
  167. return false;
  168. foreach ($banIp as $e => $f)
  169. 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)))
  170. return true;
  171. return false;
  172. }
  173. /**
  174. * nv_checkagent()
  175. *
  176. * @param string $a
  177. * @return
  178. */
  179. function nv_checkagent($a)
  180. {
  181. $a = htmlspecialchars(substr($a, 0, 255));
  182. $a = str_replace(array(",", "<"), array("-", "("), $a);
  183. return ((!empty($a) and $a != "-") ? $a : "none");
  184. }
  185. /**
  186. * nv_check_bot()
  187. *
  188. * @return
  189. */
  190. function nv_check_bot()
  191. {
  192. global $client_info;
  193. $file_bots = NV_ROOTDIR . "/" . NV_DATADIR . "/bots.config";
  194. $bots = (file_exists($file_bots) and filesize($file_bots)) ? unserialize(file_get_contents($file_bots)) : array();
  195. if (empty($bots) and file_exists(NV_ROOTDIR . "/includes/bots.php"))
  196. include (NV_ROOTDIR . "/includes/bots.php");
  197. if (empty($bots))
  198. return array();
  199. foreach ($bots as $name => $values)
  200. {
  201. $is_bot = false;
  202. if ($values['agent'] and preg_match('#' . str_replace('\*', '.*?', nv_preg_quote($values['agent'], '#')) . '#i', $client_info['agent']))
  203. $is_bot = true;
  204. if (!empty($values['ips']) and ($is_bot or !$values['agent']))
  205. {
  206. $is_bot = false;
  207. $ips = implode("|", array_map("nv_preg_quote", explode("|", $values['ips'])));
  208. if (preg_match("/^" . $ips . "/", $client_info['ip']))
  209. $is_bot = true;
  210. }
  211. if ($is_bot)
  212. return array('name' => $name, 'agent' => $values['agent'], 'ip' => $client_info['ip'], 'allowed' => $values['allowed']);
  213. }
  214. return array();
  215. }
  216. /**
  217. * nv_checkmobile()
  218. *
  219. * @param string $inifile
  220. * @return
  221. */
  222. function nv_checkmobile($inifile)
  223. {
  224. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  225. if (preg_match("/Creative\ AutoUpdate/i", $user_agent))
  226. return array();
  227. $browsers = array();
  228. if (file_exists($inifile))
  229. $browsers = nv_parse_ini_file($inifile, true);
  230. if (!empty($browsers))
  231. {
  232. foreach ($browsers as $key => $info)
  233. if (preg_match($info['rule'], $user_agent))
  234. return array('key' => $key, 'name' => $info['name']);
  235. }
  236. if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", $user_agent, $matches))
  237. {
  238. if (stripos($user_agent, 'Series60') !== false || strpos($user_agent, 'S60') !== false)
  239. {
  240. return array('key' => 'nokia', 'name' => 'Nokia S60 V.' . $matches[2]);
  241. }
  242. else
  243. {
  244. return array('key' => 'nokia', 'name' => 'Nokia V.' . $matches[2]);
  245. }
  246. }
  247. if (isset($_SERVER['X-OperaMini-Features']))
  248. return array('key' => 'opera', 'name' => 'Opera Mini');
  249. if (isset($_SERVER['UA-pixels']))
  250. return array('key' => 'mobile', 'name' => 'UA-pixels');
  251. if (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE']))
  252. return array('key' => 'mobile', 'name' => 'Unknown');
  253. if (isset($_SERVER['HTTP_ACCEPT']) && preg_match("/wap\.|\.wap/i", $_SERVER["HTTP_ACCEPT"]))
  254. return array('key' => 'mobile', 'name' => 'Unknown');
  255. 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))
  256. return array('key' => 'mobile', 'name' => 'Unknown');
  257. $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-', );
  258. $user_agent = strtolower(substr($user_agent, 0, 4));
  259. if (in_array($user_agent, $mbs))
  260. return array('key' => 'mobile', 'name' => 'Unknown');
  261. return array();
  262. }
  263. /**
  264. * nv_getBrowser()
  265. *
  266. * @param string $agent
  267. * @param string $brinifile
  268. * @return
  269. */
  270. function nv_getBrowser($agent, $brinifile)
  271. {
  272. $browsers = nv_parse_ini_file($brinifile, true);
  273. foreach ($browsers as $key => $info)
  274. {
  275. if (preg_match("#" . $info['rule'] . "#i", $agent, $results))
  276. {
  277. if (isset($results[1]))
  278. return ($key . '|' . $info['name'] . ' v' . $results[1]);
  279. return ($key . '|' . $info['name']);
  280. }
  281. }
  282. return ("Unknown|Unknown");
  283. }
  284. /**
  285. * nv_getOs()
  286. *
  287. * @param string $agent
  288. * @param string $osinifile
  289. * @return
  290. */
  291. function nv_getOs($agent, $osinifile)
  292. {
  293. $os = nv_parse_ini_file($osinifile, true);
  294. foreach ($os as $key => $info)
  295. {
  296. if (preg_match("#" . $info['rule'] . "#i", $agent, $results))
  297. {
  298. if (strstr($key, "win"))
  299. return ($key . '|' . $info['name']);
  300. if (isset($results[1]))
  301. return ($key . '|' . $info['name'] . ' ' . $results[1]);
  302. return ($key . '|' . $info['name']);
  303. }
  304. }
  305. return ("Unspecified|Unspecified");
  306. }
  307. /**
  308. * nv_convertfromBytes()
  309. *
  310. * @param integer $size
  311. * @return
  312. */
  313. function nv_convertfromBytes($size)
  314. {
  315. if ($size <= 0)
  316. return '0 bytes';
  317. if ($size == 1)
  318. return '1 byte';
  319. if ($size < 1024)
  320. return $size . ' bytes';
  321. $i = 0;
  322. $iec = array("bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
  323. while (($size / 1024) > 1)
  324. {
  325. $size = $size / 1024;
  326. ++$i;
  327. }
  328. return number_format($size, 2) . ' ' . $iec[$i];
  329. }
  330. /**
  331. * nv_convertfromSec()
  332. *
  333. * @param integer $sec
  334. * @return
  335. */
  336. function nv_convertfromSec($sec = 0)
  337. {
  338. global $lang_global;
  339. $sec = intval($sec);
  340. $min = 60;
  341. $hour = 3600;
  342. $day = 86400;
  343. $year = 31536000;
  344. if ($sec == 0)
  345. return "";
  346. if ($sec < $min)
  347. return $sec . " " . $lang_global['sec'];
  348. if ($sec < $hour)
  349. return trim(floor($sec / $min) . " " . " " . $lang_global['min'] . (($sd = $sec % $min) ? " " . nv_convertfromSec($sd) : ""));
  350. if ($sec < $day)
  351. return trim(floor($sec / $hour) . " " . $lang_global['hour'] . (($sd = $sec % $hour) ? " " . nv_convertfromSec($sd) : ""));
  352. if ($sec < $year)
  353. return trim(floor($sec / $day) . " " . $lang_global['day'] . (($sd = $sec % $day) ? " " . nv_convertfromSec($sd) : ""));
  354. return trim(floor($sec / $year) . " " . $lang_global['year'] . (($sd = $sec % $year) ? " " . nv_convertfromSec($sd) : ""));
  355. }
  356. /**
  357. * nv_converttoBytes()
  358. *
  359. * @param string $string
  360. * @return
  361. */
  362. function nv_converttoBytes($string)
  363. {
  364. if (preg_match('/^([0-9\.]+)[ ]*([b|k|m|g|t|p|e|z|y]*)/i', $string, $matches))
  365. {
  366. if (empty($matches[2]))
  367. return $matches[1];
  368. $suffixes = array("B" => 0, "K" => 1, "M" => 2, "G" => 3, "T" => 4, "P" => 5, "E" => 6, "Z" => 7, "Y" => 8);
  369. if (isset($suffixes[strtoupper($matches[2])]))
  370. return round($matches[1] * pow(1024, $suffixes[strtoupper($matches[2])]));
  371. }
  372. return false;
  373. }
  374. /**
  375. * nv_base64_encode()
  376. *
  377. * @param string $input
  378. * @return
  379. */
  380. function nv_base64_encode($input)
  381. {
  382. return strtr(base64_encode($input), '+/=', '-_,');
  383. }
  384. /**
  385. * nv_base64_decode()
  386. *
  387. * @param string $input
  388. * @return
  389. */
  390. function nv_base64_decode($input)
  391. {
  392. return base64_decode(strtr($input, '-_,', '+/='));
  393. }
  394. /**
  395. * nv_function_exists()
  396. *
  397. * @param string $funcName
  398. * @return
  399. */
  400. function nv_function_exists($funcName)
  401. {
  402. global $sys_info;
  403. return (function_exists($funcName) and !in_array($funcName, $sys_info['disable_functions']));
  404. }
  405. /**
  406. * nv_class_exists()
  407. *
  408. * @param string $clName
  409. * @return
  410. */
  411. function nv_class_exists($clName)
  412. {
  413. global $sys_info;
  414. return (class_exists($clName) and !in_array($clName, $sys_info['disable_classes']));
  415. }
  416. /**
  417. * nv_check_valid_login()
  418. *
  419. * @param string $login
  420. * @param integer $max
  421. * @param integer $min
  422. * @return
  423. */
  424. function nv_check_valid_login($login, $max, $min)
  425. {
  426. global $lang_global;
  427. $login = strip_tags(trim($login));
  428. if (empty($login))
  429. return $lang_global['username_empty'];
  430. if (isset($login{$max}))
  431. return sprintf($lang_global['usernamelong'], $login, $max);
  432. if (!isset($login{$min - 1}))
  433. return sprintf($lang_global['usernameadjective'], $login, $min);
  434. return "";
  435. }
  436. /**
  437. * nv_check_valid_pass()
  438. *
  439. * @param string $pass
  440. * @param integer $max
  441. * @param integer $min
  442. * @return
  443. */
  444. function nv_check_valid_pass($pass, $max, $min)
  445. {
  446. global $lang_global;
  447. $pass = strip_tags(trim($pass));
  448. if (empty($pass))
  449. return $lang_global['password_empty'];
  450. if (isset($pass{$max}))
  451. return sprintf($lang_global['passwordlong'], $pass, $max);
  452. if (!isset($pass{$min - 1}))
  453. return sprintf($lang_global['passwordadjective'], $pass, $min);
  454. return "";
  455. }
  456. /**
  457. * nv_check_valid_email()
  458. *
  459. * @param string $mail
  460. * @return
  461. */
  462. function nv_check_valid_email($mail)
  463. {
  464. global $lang_global, $global_config;
  465. $mail = strip_tags(trim($mail));
  466. if (empty($mail))
  467. return $lang_global['email_empty'];
  468. if (function_exists('filter_var') and filter_var($mail, FILTER_VALIDATE_EMAIL) === false)
  469. return sprintf($lang_global['email_incorrect'], $mail);
  470. if (!preg_match($global_config['check_email'], $mail))
  471. return sprintf($lang_global['email_incorrect'], $mail);
  472. 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)$/", $mail))
  473. return sprintf($lang_global['email_incorrect'], $mail);
  474. return "";
  475. }
  476. /**
  477. * nv_capcha_txt()
  478. *
  479. * @param string $seccode
  480. * @param string $scaptcha
  481. * @return
  482. */
  483. function nv_capcha_txt($seccode, $scaptcha = "captcha")
  484. {
  485. global $sys_info, $global_config, $nv_Request;
  486. if (!$sys_info['gd_support'])
  487. return true;
  488. $scaptcha = preg_replace('/[^a-z0-9]/', '', $scaptcha);
  489. $skeycaptcha = ($scaptcha == "captcha") ? "random_num" : "random_" . substr($scaptcha, 0, 20);
  490. $seccode = strtoupper($seccode);
  491. $random_num = $nv_Request->get_string($skeycaptcha, 'session', 0);
  492. $datekey = date("F j");
  493. $rcode = strtoupper(md5(NV_USER_AGENT . $global_config['sitekey'] . $random_num . $datekey));
  494. mt_srand(( double )microtime() * 1000000);
  495. $maxran = 1000000;
  496. $random_num = mt_rand(0, $maxran);
  497. $nv_Request->set_Session($skeycaptcha, $random_num);
  498. return (preg_match("/^[a-zA-Z0-9]{" . NV_GFX_NUM . "}$/", $seccode) and $seccode == substr($rcode, 2, NV_GFX_NUM));
  499. }
  500. /**
  501. * nv_genpass()
  502. *
  503. * @param integer $length
  504. * @return
  505. */
  506. function nv_genpass($length = 8)
  507. {
  508. $pass = chr(mt_rand(65, 90));
  509. for ($k = 0; $k < $length - 1; ++$k)
  510. {
  511. $probab = mt_rand(1, 10);
  512. $pass .= ($probab <= 8) ? chr(mt_rand(97, 122)) : chr(mt_rand(48, 57));
  513. }
  514. return $pass;
  515. }
  516. /**
  517. * nv_EncodeEmail()
  518. *
  519. * @param string $strEmail
  520. * @param string $strDisplay
  521. * @param bool $blnCreateLink
  522. * @return
  523. */
  524. function nv_EncodeEmail($strEmail, $strDisplay = '', $blnCreateLink = true)
  525. {
  526. $strMailto = "&#109;&#097;&#105;&#108;&#116;&#111;&#058;";
  527. $strEncodedEmail = "";
  528. $strlen = strlen($strEmail);
  529. for ($i = 0; $i < $strlen; ++$i)
  530. {
  531. $strEncodedEmail .= "&#" . ord(substr($strEmail, $i)) . ";";
  532. }
  533. $strDisplay = trim($strDisplay);
  534. $strDisplay = !empty($strDisplay) ? $strDisplay : $strEncodedEmail;
  535. if ($blnCreateLink)
  536. return "<a href=\"" . $strMailto . $strEncodedEmail . "\">" . $strDisplay . "</a>";
  537. return $strDisplay;
  538. }
  539. /**
  540. * nv_user_groups()
  541. *
  542. * @param string $in_groups
  543. * @return
  544. */
  545. function nv_user_groups($in_groups)
  546. {
  547. global $db;
  548. if (empty($in_groups))
  549. return "";
  550. $query = "SELECT `group_id`, `title`, `exp_time`, `public` FROM `" . NV_GROUPS_GLOBALTABLE . "` WHERE `act`=1 ORDER BY `weight`";
  551. $list = nv_db_cache($query, '', 'users');
  552. if (empty($list))
  553. return "";
  554. $in_groups = explode(",", $in_groups);
  555. $groups = array();
  556. $reload = array();
  557. for ($i = 0, $count = sizeof($list); $i < $count; ++$i)
  558. {
  559. if ($list[$i]['exp_time'] != 0 and $list[$i]['exp_time'] <= NV_CURRENTTIME)
  560. {
  561. $reload[] = $list[$i]['group_id'];
  562. }
  563. elseif (in_array($list[$i]['group_id'], $in_groups))
  564. {
  565. $groups[] = $list[$i]['group_id'];
  566. }
  567. }
  568. if ($reload)
  569. {
  570. $sql = "UPDATE `" . NV_GROUPS_GLOBALTABLE . "` SET `act`='0' WHERE `group_id` IN (" . implode(",", $reload) . ")";
  571. $db->sql_query($sql);
  572. nv_del_moduleCache('users');
  573. }
  574. if (empty($groups))
  575. return "";
  576. return implode(",", $groups);
  577. }
  578. /**
  579. * nv_is_in_groups()
  580. *
  581. * @param string $in_groups
  582. * @param string $groups
  583. * @return
  584. */
  585. function nv_is_in_groups($in_groups, $groups)
  586. {
  587. if (empty($groups) || empty($in_groups))
  588. return false;
  589. $in_groups = explode(",", $in_groups);
  590. $groups = explode(",", $groups);
  591. return (array_intersect($in_groups, $groups) != array());
  592. }
  593. /**
  594. * nv_set_allow()
  595. *
  596. * @param integer $who
  597. * @param string $groups
  598. * @return
  599. */
  600. function nv_set_allow($who, $groups)
  601. {
  602. global $user_info;
  603. if (!$who or ($who == 1 and defined('NV_IS_USER')) or ($who == 2 and defined('NV_IS_ADMIN')))
  604. return true;
  605. if ($who == 3 and !empty($groups) and defined('NV_IS_USER') and nv_is_in_groups($user_info['in_groups'], $groups))
  606. return true;
  607. return false;
  608. }
  609. /**
  610. * nv_date()
  611. *
  612. * @param string $format
  613. * @param integer $time
  614. * @return
  615. */
  616. function nv_date($format, $time = 0)
  617. {
  618. global $lang_global;
  619. if (!$time)
  620. $time = NV_CURRENTTIME;
  621. $return = date($format, $time);
  622. $replaces = array('Sunday' => $lang_global['sunday'], 'Monday' => $lang_global['monday'], 'Tuesday' => $lang_global['tuesday'], 'Wednesday' => $lang_global['wednesday'], 'Thursday' => $lang_global['thursday'], 'Friday' => $lang_global['friday'], 'Saturday' => $lang_global['saturday'], 'January' => $lang_global['january'], 'February' => $lang_global['february'], 'March' => $lang_global['march'], 'April' => $lang_global['april'], 'May' => $lang_global['may'], 'June' => $lang_global['june'], 'July' => $lang_global['july'], 'August' => $lang_global['august'], 'September' => $lang_global['september'], 'October' => $lang_global['october'], 'November' => $lang_global['november'], 'December' => $lang_global['december']);
  623. $return = str_replace(array_keys($replaces), array_values($replaces), $return);
  624. $replaces = array('Sun' => $lang_global['sun'], 'Mon' => $lang_global['mon'], 'Tue' => $lang_global['tue'], 'Wed' => $lang_global['wed'], 'Thu' => $lang_global['thu'], 'Fri' => $lang_global['fri'], 'Sat' => $lang_global['sat'], 'Jan' => $lang_global['jan'], 'Feb' => $lang_global['feb'], 'Mar' => $lang_global['mar'], 'Apr' => $lang_global['apr'], 'May' => $lang_global['may2'], 'Jun' => $lang_global['jun'], 'Jul' => $lang_global['jul'], 'Aug' => $lang_global['aug'], 'Sep' => $lang_global['sep'], 'Oct' => $lang_global['oct'], 'Nov' => $lang_global['nov'], 'Dec' => $lang_global['dec']);
  625. return str_replace(array_keys($replaces), array_values($replaces), $return);
  626. }
  627. /**
  628. * nv_monthname()
  629. *
  630. * @param integer $i
  631. * @return
  632. */
  633. function nv_monthname($i)
  634. {
  635. global $lang_global;
  636. --$i;
  637. $month_names = array($lang_global['january'], $lang_global['february'], $lang_global['march'], $lang_global['april'], $lang_global['may'], $lang_global['june'], $lang_global['july'], $lang_global['august'], $lang_global['september'], $lang_global['october'], $lang_global['november'], $lang_global['december']);
  638. return (isset($month_names[$i]) ? $month_names[$i] : "");
  639. }
  640. /**
  641. * nv_unhtmlspecialchars()
  642. *
  643. * @param mixed $string
  644. * @return
  645. */
  646. function nv_unhtmlspecialchars($string)
  647. {
  648. if (empty($string))
  649. return $string;
  650. if (is_array($string))
  651. {
  652. $array_keys = array_keys($string);
  653. foreach ($array_keys as $key)
  654. {
  655. $string[$key] = nv_unhtmlspecialchars($string[$key]);
  656. }
  657. }
  658. else
  659. {
  660. $search = array('&amp;', '&#039;', '&quot;', '&lt;', '&gt;', '&#x005C;', '&#x002F;', '&#40;', '&#41;', '&#42;', '&#91;', '&#93;', '&#33;', '&#x3D;', '&#x23;', '&#x25;', '&#x5E;', '&#x3A;', '&#x7B;', '&#x7D;', '&#x60;', '&#x7E;');
  661. $replace = array('&', '\'', '"', '<', '>', '\\', '/', '(', ')', '*', '[', ']', '!', '=', '#', '%', '^', ':', '{', '}', '`', '~');
  662. $string = str_replace($search, $replace, $string);
  663. }
  664. return $string;
  665. }
  666. /**
  667. * nv_htmlspecialchars()
  668. *
  669. * @param mixed $string
  670. * @return
  671. */
  672. function nv_htmlspecialchars($string)
  673. {
  674. if (empty($string))
  675. return $string;
  676. if (is_array($string))
  677. {
  678. $array_keys = array_keys($string);
  679. foreach ($array_keys as $key)
  680. {
  681. $string[$key] = nv_htmlspecialchars($string[$key]);
  682. }
  683. }
  684. else
  685. {
  686. $search = array('&', '\'', '"', '<', '>', '\\', '/', '(', ')', '*', '[', ']', '!', '=', '%', '^', ':', '{', '}', '`', '~');
  687. $replace = array('&amp;', '&#039;', '&quot;', '&lt;', '&gt;', '&#x005C;', '&#x002F;', '&#40;', '&#41;', '&#42;', '&#91;', '&#93;', '&#33;', '&#x3D;', '&#x25;', '&#x5E;', '&#x3A;', '&#x7B;', '&#x7D;', '&#x60;', '&#x7E;');
  688. $string = str_replace($replace, $search, $string);
  689. $string = str_replace("&#x23;", "#", $string);
  690. $string = str_replace($search, $replace, $string);
  691. $string = preg_replace("/([^\&]+)\#/", "\\1&#x23;", $string);
  692. }
  693. return $string;
  694. }
  695. /**
  696. * strip_punctuation()
  697. *
  698. * @param mixed $text
  699. * @return
  700. */
  701. function strip_punctuation($text)
  702. {
  703. $urlbrackets = '\[\]\(\)';
  704. $urlspacebefore = ':;\'_\*%@&?!' . $urlbrackets;
  705. $urlspaceafter = '\.,:;\'\-_\*@&\/\\\\\?!#' . $urlbrackets;
  706. $urlall = '\.,:;\'\-_\*%@&\/\\\\\?!#' . $urlbrackets;
  707. $specialquotes = '\'"\*<>';
  708. $fullstop = '\x{002E}\x{FE52}\x{FF0E}';
  709. $comma = '\x{002C}\x{FE50}\x{FF0C}';
  710. $arabsep = '\x{066B}\x{066C}';
  711. $numseparators = $fullstop . $comma . $arabsep;
  712. $numbersign = '\x{0023}\x{FE5F}\x{FF03}';
  713. $percent = '\x{066A}\x{0025}\x{066A}\x{FE6A}\x{FF05}\x{2030}\x{2031}';
  714. $prime = '\x{2032}\x{2033}\x{2034}\x{2057}';
  715. $nummodifiers = $numbersign . $percent . $prime;
  716. return preg_replace(array(// Remove separator, control, formatting, surrogate, open/close quotes.
  717. '/[\p{Z}\p{Cc}\p{Cf}\p{Cs}\p{Pi}\p{Pf}]/u', // Remove other punctuation except special cases
  718. '/\p{Po}(?<![' . $specialquotes . $numseparators . $urlall . $nummodifiers . '])/u', // Remove non-URL open/close brackets, except URL brackets.
  719. '/[\p{Ps}\p{Pe}](?<![' . $urlbrackets . '])/u', // Remove special quotes, dashes, connectors, number separators, and URL characters followed by a space
  720. '/[' . $specialquotes . $numseparators . $urlspaceafter . '\p{Pd}\p{Pc}]+((?= )|$)/u', // Remove special quotes, connectors, and URL characters preceded by a space
  721. '/((?<= )|^)[' . $specialquotes . $urlspacebefore . '\p{Pc}]+/u', // Remove dashes preceded by a space, but not followed by a number
  722. '/((?<= )|^)\p{Pd}+(?![\p{N}\p{Sc}])/u', // Remove consecutive spaces
  723. '/ +/'), ' ', $text);
  724. }
  725. /**
  726. * nv_nl2br()
  727. *
  728. * @param string $text
  729. * @param string $replacement
  730. * @return
  731. */
  732. function nv_nl2br($text, $replacement = '<br />')
  733. {
  734. if (empty($text))
  735. return '';
  736. return strtr($text, array("\r\n" => $replacement, "\r" => $replacement, "\n" => $replacement));
  737. }
  738. /**
  739. * nv_br2nl()
  740. *
  741. * @param string $text
  742. * @return
  743. */
  744. function nv_br2nl($text)
  745. {
  746. if (empty($text))
  747. return '';
  748. return preg_replace('/\<br(\s*)?\/?(\s*)?\>/i', chr(13) . chr(10), $text);
  749. }
  750. /**
  751. * nv_editor_nl2br()
  752. *
  753. * @param string $text
  754. * @return
  755. */
  756. function nv_editor_nl2br($text)
  757. {
  758. if (empty($text))
  759. return '';
  760. $replacement = defined('NV_EDITOR') ? '' : '<br />';
  761. return nv_nl2br($text, (defined('NV_EDITOR') ? '' : '<br />'));
  762. }
  763. /**
  764. * nv_editor_br2nl()
  765. *
  766. * @param mixed $text
  767. * @return
  768. */
  769. function nv_editor_br2nl($text)
  770. {
  771. if (empty($text))
  772. return '';
  773. if (defined('NV_EDITOR'))
  774. return $text;
  775. return nv_br2nl($text);
  776. }
  777. /**
  778. * filter_text_input()
  779. *
  780. * @param string $inputname
  781. * @param string $mode
  782. * @param string $default
  783. * @param bool $specialchars
  784. * @param integer $maxlength
  785. * @param mixed $preg_replace
  786. * @return
  787. */
  788. function filter_text_input($inputname, $mode = 'request', $default = '', $specialchars = false, $maxlength = 0, $preg_replace = array())
  789. {
  790. global $nv_Request;
  791. $value = $nv_Request->get_string($inputname, $mode, $default);
  792. $value = strip_tags($value);
  793. if (( bool )$specialchars == true)
  794. {
  795. $value = nv_htmlspecialchars($value);
  796. }
  797. if (( int )$maxlength > 0)
  798. {
  799. $value = nv_substr($value, 0, $maxlength);
  800. }
  801. if (!empty($preg_replace))
  802. {
  803. if (isset($preg_replace['pattern']) and !empty($preg_replace['pattern']) and isset($preg_replace['replacement']))
  804. {
  805. $value = preg_replace($preg_replace['pattern'], $preg_replace['replacement'], $value);
  806. }
  807. }
  808. return trim($value);
  809. }
  810. /**
  811. * filter_text_textarea()
  812. *
  813. * @param string $inputname
  814. * @param string $default
  815. * @param string $allowed_html_tags
  816. * @param bool $save
  817. * @param string $nl2br_replacement
  818. * @return
  819. */
  820. function filter_text_textarea($inputname, $default = '', $allowed_html_tags = '', $save = false, $nl2br_replacement = '<br />')
  821. {
  822. global $nv_Request;
  823. $value = $nv_Request->get_string($inputname, 'post', $default);
  824. if (empty($value))
  825. return $value;
  826. if (!empty($allowed_html_tags))
  827. {
  828. $allowed_html_tags = array_map("trim", explode(",", $allowed_html_tags));
  829. $allowed_html_tags = "<" . implode("><", $allowed_html_tags) . ">";
  830. $value = strip_tags($value, $allowed_html_tags);
  831. }
  832. if (( bool )$save)
  833. $value = nv_nl2br($value, $nl2br_replacement);
  834. return $value;
  835. }
  836. /**
  837. * nv_editor_filter_textarea()
  838. *
  839. * @param string $inputname
  840. * @param string $default
  841. * @param string $allowed_html_tags
  842. * @param bool $save
  843. * @param string $nl2br_replacement
  844. * @return
  845. */
  846. function nv_editor_filter_textarea($inputname, $default = '', $allowed_html_tags = '', $save = false, $nl2br_replacement = '<br />')
  847. {
  848. global $nv_Request;
  849. $value = $nv_Request->get_string($inputname, 'post', $default);
  850. if (empty($value))
  851. return '';
  852. if (!empty($allowed_html_tags) and !defined('NV_EDITOR'))
  853. {
  854. $allowed_html_tags = array_map("trim", explode(",", $allowed_html_tags));
  855. $allowed_html_tags = "<" . implode("><", $allowed_html_tags) . ">";
  856. $value = strip_tags($value, $allowed_html_tags);
  857. }
  858. if (empty($value))
  859. return '';
  860. if (( bool )$save)
  861. {
  862. $value = nv_editor_nl2br($value, $nl2br_replacement);
  863. }
  864. return $value;
  865. }
  866. /**
  867. * nv_get_keywords()
  868. *
  869. * @param string $content
  870. * @return
  871. */
  872. function nv_get_keywords($content = "")
  873. {
  874. if (empty($content))
  875. return ("");
  876. $content = strip_tags($content);
  877. $content = nv_unhtmlspecialchars($content);
  878. $content = strip_punctuation($content);
  879. $content = trim($content);
  880. $content = nv_strtolower($content);
  881. $content = " " . $content . " ";
  882. $pattern_word = array();
  883. if (NV_SITEWORDS_MIN_3WORDS_LENGTH > 0 and NV_SITEWORDS_MIN_3WORDS_PHRASE_OCCUR > 0)
  884. {
  885. $pattern_word[] = "/[\s]+([\S]{" . NV_SITEWORDS_MIN_3WORDS_LENGTH . ",}\s[\S]{" . NV_SITEWORDS_MIN_3WORDS_LENGTH . ",}\s[\S]{" . NV_SITEWORDS_MIN_3WORDS_LENGTH . ",})(\s.*\\1){" . NV_SITEWORDS_MIN_3WORDS_PHRASE_OCCUR . ",}[\s]+/uis";
  886. }
  887. if (NV_SITEWORDS_MIN_2WORDS_LENGTH > 0 and NV_SITEWORDS_MIN_2WORDS_PHRASE_OCCUR > 0)
  888. {
  889. $pattern_word[] = "/[\s]+([\S]{" . NV_SITEWORDS_MIN_2WORDS_LENGTH . ",}\s[\S]{" . NV_SITEWORDS_MIN_2WORDS_LENGTH . ",})(\s.*\\1){" . NV_SITEWORDS_MIN_2WORDS_PHRASE_OCCUR . ",}[\s]+/uis";
  890. }
  891. if (NV_SITEWORDS_MIN_WORD_LENGTH > 0 and NV_SITEWORDS_MIN_WORD_OCCUR > 0)
  892. {
  893. $pattern_word[] = "/[\s]+([\S]{" . NV_SITEWORDS_MIN_WORD_LENGTH . ",})(\s.*\\1){" . NV_SITEWORDS_MIN_WORD_OCCUR . ",}[\s]+/uis";
  894. }
  895. if (empty($pattern_word))
  896. return ("");
  897. $keywords = array();
  898. $lenght = 0;
  899. $max_strlen = min(NV_SITEWORDS_MAX_STRLEN, 300);
  900. foreach ($pattern_word as $pattern)
  901. {
  902. while (preg_match($pattern, $content, $matches))
  903. {
  904. $keywords[] = $matches[1];
  905. $lenght += nv_strlen($matches[1]);
  906. $content = preg_replace("/[\s]+(" . preg_quote($matches[1]) . ")[\s]+/uis", " ", $content);
  907. if ($lenght >= $max_strlen)
  908. break;
  909. }
  910. if ($lenght >= $max_strlen)
  911. break;
  912. }
  913. $keywords = array_unique($keywords);
  914. return implode(",", $keywords);
  915. }
  916. /**
  917. * nv_sendmail()
  918. *
  919. * @param mixed $from
  920. * @param mixed $to
  921. * @param string $subject
  922. * @param string $message
  923. * @param string $files
  924. * @return
  925. */
  926. function nv_sendmail($from, $to, $subject, $message, $files = '')
  927. {
  928. global $global_config, $sys_info;
  929. $sendmail_from = ini_get('sendmail_from');
  930. require_once (NV_ROOTDIR . '/includes/phpmailer/class.phpmailer.php');
  931. try
  932. {
  933. $mail = new PHPMailer(true);
  934. $mail->CharSet = $global_config['site_charset'];
  935. $mailer_mode = strtolower($global_config['mailer_mode']);
  936. if ($mailer_mode == 'smtp')
  937. {
  938. $mail->IsSMTP();
  939. $mail->SMTPAuth = true;
  940. $mail->Port = $global_config['smtp_port'];
  941. $mail->Host = $global_config['smtp_host'];
  942. $mail->Username = $global_config['smtp_username'];
  943. $mail->Password = $global_config['smtp_password'];
  944. $SMTPSecure = intval($global_config['smtp_ssl']);
  945. switch ( $SMTPSecure )
  946. {
  947. case 1 :
  948. $mail->SMTPSecure = 'ssl';
  949. break;
  950. case 2 :
  951. $mail->SMTPSecure = 'tls';
  952. break;
  953. default :
  954. $mail->SMTPSecure = '';
  955. }
  956. }
  957. elseif ($mailer_mode == 'sendmail')
  958. {
  959. $mail->IsSendmail();
  960. }
  961. elseif (!in_array('mail', $sys_info['disable_functions']))
  962. {
  963. $mail->IsMail();
  964. }
  965. else
  966. {
  967. return false;
  968. }
  969. $message = nv_change_buffer($message);
  970. $message = nv_unhtmlspecialchars($message);
  971. $subject = nv_unhtmlspecialchars($subject);
  972. $mail->From = $sendmail_from;
  973. $mail->FromName = $global_config['site_name'];
  974. if (is_array($from))
  975. {
  976. $mail->AddReplyTo($from[1], $from[0]);
  977. }
  978. else
  979. {
  980. $mail->AddReplyTo($from);
  981. }
  982. if (empty($to))
  983. return false;
  984. if (!is_array($to))
  985. $to = array($to);
  986. foreach ($to as $_to)
  987. {
  988. $mail->AddAddress($_to);
  989. }
  990. $mail->Subject = $subject;
  991. $mail->WordWrap = 120;
  992. $mail->MsgHTML($message);
  993. $mail->IsHTML(true);
  994. if (!empty($files))
  995. {
  996. $files = array_map("trim", explode(",", $files));
  997. foreach ($files as $file)
  998. {
  999. $mail->AddAttachment($file);
  1000. }
  1001. }
  1002. $send = $mail->Send();
  1003. if (!$send)
  1004. {
  1005. trigger_error($mail->ErrorInfo, E_USER_WARNING);
  1006. }
  1007. return $send;
  1008. }
  1009. catch ( phpmailerException $e )
  1010. {
  1011. trigger_error($e->errorMessage(), E_USER_WARNING);
  1012. return false;
  1013. }
  1014. }
  1015. /**
  1016. * nv_generate_page()
  1017. *
  1018. * @param string $base_url
  1019. * @param integer $num_items
  1020. * @param integer $per_page
  1021. * @param integer $start_item
  1022. * @param bool $add_prevnext_text
  1023. * @param bool $onclick
  1024. * @param string $js_func_name
  1025. * @param string $containerid
  1026. * @return
  1027. */
  1028. 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')
  1029. {
  1030. global $lang_global;
  1031. $total_pages = ceil($num_items / $per_page);
  1032. if ($total_pages == 1)
  1033. return '';
  1034. $on_page = @floor($start_item / $per_page) + 1;
  1035. if (!is_array($base_url))
  1036. {
  1037. $amp = preg_match("/\?/", $base_url) ? "&amp;" : "?";
  1038. $amp .= "page=";
  1039. }
  1040. else
  1041. {
  1042. $amp = $base_url['amp'];
  1043. $base_url = $base_url['link'];
  1044. }
  1045. $page_string = "";
  1046. if ($total_pages > 10)
  1047. {
  1048. $init_page_max = ($total_pages > 3) ? 3 : $total_pages;
  1049. for ($i = 1; $i <= $init_page_max; ++$i)
  1050. {
  1051. $href = !$onclick ? "href=\"" . $base_url . $amp . (($i - 1) * $per_page) . "\"" : "href=\"javascript:void(0)\" onclick=\"" . $js_func_name . "('" . rawurlencode(nv_unhtmlspecialchars($base_url . $amp . (($i - 1) * $per_page))) . "','" . $containerid . "')\"";
  1052. $page_string .= ($i == $on_page) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  1053. if ($i < $init_page_max)
  1054. $page_string .= ", ";
  1055. }
  1056. if ($total_pages > 3)
  1057. {
  1058. if ($on_page > 1 && $on_page < $total_pages)
  1059. {
  1060. $page_string .= ($on_page > 5) ? " ... " : ", ";
  1061. $init_page_min = ($on_page > 4) ? $on_page : 5;
  1062. $init_page_max = ($on_page < $total_pages - 4) ? $on_page : $total_pages - 4;
  1063. for ($i = $init_page_min - 1; $i < $init_page_max + 2; ++$i)
  1064. {
  1065. $href = !$onclick ? "href=\"" . $base_url . $amp . (($i - 1) * $per_page) . "\"" : "href=\"javascript:void(0)\" onclick=\"" . $js_func_name . "('" . rawurlencode(nv_unhtmlspecialchars($base_url . $amp . (($i - 1) * $per_page))) . "','" . $containerid . "')\"";
  1066. $page_string .= ($i == $on_page) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  1067. if ($i < $init_page_max + 1)
  1068. {
  1069. $page_string .= ", ";
  1070. }
  1071. }
  1072. $page_string .= ($on_page < $total_pages - 4) ? " ... " : ", ";
  1073. }
  1074. else
  1075. {
  1076. $page_string .= " ... ";
  1077. }
  1078. for ($i = $total_pages - 2; $i < $total_pages + 1; ++$i)
  1079. {
  1080. $href = !$onclick ? "href=\"" . $base_url . $amp . (($i - 1) * $per_page) . "\"" : "href=\"javascript:void(0)\" onclick=\"" . $js_func_name . "('" . rawurlencode(nv_unhtmlspecialchars($base_url . $amp . (($i - 1) * $per_page))) . "','" . $containerid . "')\"";
  1081. $page_string .= ($i == $on_page) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  1082. if ($i < $total_pages)
  1083. {
  1084. $page_string .= ", ";
  1085. }
  1086. }
  1087. }
  1088. }
  1089. else
  1090. {
  1091. for ($i = 1; $i < $total_pages + 1; ++$i)
  1092. {
  1093. $href = !$onclick ? "href=\"" . $base_url . $amp . (($i - 1) * $per_page) . "\"" : "href=\"javascript:void(0)\" onclick=\"" . $js_func_name . "('" . rawurlencode(nv_unhtmlspecialchars($base_url . $amp . (($i - 1) * $per_page))) . "','" . $containerid . "')\"";
  1094. $page_string .= ($i == $on_page) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  1095. if ($i < $total_pages)
  1096. {
  1097. $page_string .= ", ";
  1098. }
  1099. }
  1100. }
  1101. if ($add_prevnext_text)
  1102. {
  1103. if ($on_page > 1)
  1104. {
  1105. $href = !$onclick ? "href=\"" . $base_url . $amp . (($on_page - 2) * $per_page) . "\"" : "href=\"javascript:void(0)\" onclick=\"" . $js_func_name . "('" . rawurlencode(nv_unhtmlspecialchars($base_url . $amp . (($on_page - 2) * $per_page))) . "','" . $containerid . "')\"";
  1106. $page_string = "&nbsp;&nbsp;<span><a " . $href . ">" . $lang_global['pageprev'] . "</a></span>&nbsp;&nbsp;" . $page_string;
  1107. }
  1108. if ($on_page < $total_pages)
  1109. {
  1110. $href = !$onclick ? "href=\"" . $base_url . $amp . ($on_page * $per_page) . "\"" : "href=\"javascript:void(0)\" onclick=\"" . $js_func_name . "('" . rawurlencode(nv_unhtmlspecialchars($base_url . $amp . ($on_page * $per_page))) . "','" . $containerid . "')\"";
  1111. $page_string .= "&nbsp;&nbsp;<span><a " . $href . ">" . $lang_global['pagenext'] . "</a></span>";
  1112. }
  1113. }
  1114. return $page_string;
  1115. }
  1116. function nv_news_page($base_url, $num_items, $per_page, $start_item, $add_prevnext_text = true)
  1117. {
  1118. global $lang_global;
  1119. $total_pages = ceil($num_items / $per_page);
  1120. if ($total_pages == 1)
  1121. return '';
  1122. @$on_page = floor($start_item / $per_page) + 1;
  1123. $page_string = "";
  1124. if ($total_pages > 10)
  1125. {
  1126. $init_page_max = ($total_pages > 3) ? 3 : $total_pages;
  1127. for ($i = 1; $i <= $init_page_max; ++$i)
  1128. {
  1129. $href = "href=\"" . $base_url . "/page-" . (($i - 1) * $per_page) . "\"";
  1130. $page_string .= ($i == $on_page) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  1131. if ($i < $init_page_max)
  1132. $page_string .= ", ";
  1133. }
  1134. if ($total_pages > 3)
  1135. {
  1136. if ($on_page > 1 && $on_page < $total_pages)
  1137. {
  1138. $page_string .= ($on_page > 5) ? " ... " : ", ";
  1139. $init_page_min = ($on_page > 4) ? $on_page : 5;
  1140. $init_page_max = ($on_page < $total_pages - 4) ? $on_page : $total_pages - 4;
  1141. for ($i = $init_page_min - 1; $i < $init_page_max + 2; ++$i)
  1142. {
  1143. $href = "href=\"" . $base_url . "/page-" . (($i - 1) * $per_page) . "\"";
  1144. $page_string .= ($i == $on_page) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  1145. if ($i < $init_page_max + 1)
  1146. {
  1147. $page_string .= ", ";
  1148. }
  1149. }
  1150. $page_string .= ($on_page < $total_pages - 4) ? " ... " : ", ";
  1151. }
  1152. else
  1153. {
  1154. $page_string .= " ... ";
  1155. }
  1156. for ($i = $total_pages - 2; $i < $total_pages + 1; ++$i)
  1157. {
  1158. $href = "href=\"" . $base_url . "/page-" . (($i - 1) * $per_page) . "\"";
  1159. $page_string .= ($i == $on_page) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  1160. if ($i < $total_pages)
  1161. {
  1162. $page_string .= ", ";
  1163. }
  1164. }
  1165. }
  1166. }
  1167. else
  1168. {
  1169. for ($i = 1; $i < $total_pages + 1; ++$i)
  1170. {
  1171. $href = "href=\"" . $base_url . "/page-" . (($i - 1) * $per_page) . "\"";
  1172. $page_string .= ($i == $on_page) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  1173. if ($i < $total_pages)
  1174. {
  1175. $page_string .= ", ";
  1176. }
  1177. }
  1178. }
  1179. if ($add_prevnext_text)
  1180. {
  1181. if ($on_page > 1)
  1182. {
  1183. $href = "href=\"" . $base_url . "/page-" . (($on_page - 2) * $per_page) . "\"";
  1184. $page_string = "&nbsp;&nbsp;<span><a " . $href . ">" . $lang_global['pageprev'] . "</a></span>&nbsp;&nbsp;" . $page_string;
  1185. }
  1186. if ($on_page < $total_pages)
  1187. {
  1188. $href = "href=\"" . $base_url . "/page-" . ($on_page * $per_page) . "\"";
  1189. $page_string .= "&nbsp;&nbsp;<span><a " . $href . ">" . $lang_global['pagenext'] . "</a></span>";
  1190. }
  1191. }
  1192. return $page_string;
  1193. }
  1194. /**
  1195. * nv_is_url()
  1196. *
  1197. * @param string $url
  1198. * @return
  1199. */
  1200. function nv_is_url($url)
  1201. {
  1202. global $ips;
  1203. if (empty($url))
  1204. return false;
  1205. $url = (($_url = substr($url, -1)) == "/") ? $_url : $url;
  1206. if (empty($url))
  1207. return false;
  1208. $url = nv_strtolower($url);
  1209. if (!($parts = @parse_url($url)))
  1210. return false;
  1211. if (!isset($parts['scheme']) or !isset($parts['host']) or (!in_array($parts['scheme'], array('http', 'https', 'ftp', 'gopher'))))
  1212. return false;
  1213. 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)$/", $parts['host']) and !$ips->nv_validip($parts['host']))
  1214. return false;
  1215. if (isset($parts['user']) and !preg_match("/^([0-9a-z\-]|[\_])*$/", $parts['user']))
  1216. return false;
  1217. if (isset($parts['pass']) and !preg_match("/^([0-9a-z\-]|[\_])*$/", $parts['pass']))
  1218. return false;
  1219. if (isset($parts['path']) and !preg_match("/^[0-9A-Za-z\/\_\.\@\~\-\%\\s]*$/", $parts['path']))
  1220. return false;
  1221. if (isset($parts['query']) and !preg_match("/^[0-9a-z\-\_\/\?\&\=\#\.\,\;\%\\s]*$/", $parts['query']))
  1222. return false;
  1223. return true;
  1224. }
  1225. /**
  1226. * nv_check_url()
  1227. *
  1228. * @param string $url
  1229. * @param bool $is_200
  1230. * @return
  1231. */
  1232. function nv_check_url($url, $is_200 = 0)
  1233. {
  1234. if (empty($url))
  1235. return false;
  1236. $url = str_replace(" ", "%20", $url);
  1237. $allow_url_fopen = (ini_get('allow_url_fopen') == '1' || strtolower(ini_get('allow_url_fopen')) == 'on') ? 1 : 0;
  1238. if (nv_function_exists('get_headers') and $allow_url_fopen == 1)
  1239. {
  1240. $res = get_headers($url);
  1241. }
  1242. elseif (nv_function_exists('curl_init') and nv_function_exists('curl_exec'))
  1243. {
  1244. $url_info = @parse_url($url);
  1245. $port = isset($url_info['port']) ? intval($url_info['port']) : 80;
  1246. $userAgents = array(//
  1247. 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0', //
  1248. 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', //
  1249. 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)', //
  1250. 'Mozilla/4.8 [en] (Windows NT 6.0; U)', //
  1251. 'Opera/9.25 (Windows NT 6.0; U; en)');
  1252. //
  1253. $safe_mode = (ini_get('safe_mode') == '1' || strtolower(ini_get('safe_mode')) == 'on') ? 1 : 0;
  1254. $open_basedir = (ini_get('open_basedir') == '1' || strtolower(ini_get('open_basedir')) == 'on') ? 1 : 0;
  1255. srand(( float )microtime() * 10000000);
  1256. $rand = array_rand($userAgents);
  1257. $agent = $userAgents[$rand];
  1258. $curl = curl_init($url);
  1259. curl_setopt($curl, CURLOPT_HEADER, true);
  1260. curl_setopt($curl, CURLOPT_NOBODY, true);
  1261. curl_setopt($curl, CURLOPT_PORT, $port);
  1262. if (!$safe_mode and $open_basedir)
  1263. {
  1264. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  1265. }
  1266. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  1267. curl_setopt($curl, CURLOPT_TIMEOUT, 15);
  1268. curl_setopt($curl, CURLOPT_USERAGENT, $agent);
  1269. $response = curl_exec($curl);
  1270. curl_close($curl);
  1271. if ($response === false)
  1272. {
  1273. trigger_error(curl_error($curl), E_USER_WARNING);
  1274. return false;
  1275. }
  1276. else
  1277. {
  1278. $res = explode("\n", $response);
  1279. }
  1280. }
  1281. elseif (nv_function_exists('fsockopen') and nv_function_exists('fgets'))
  1282. {
  1283. $res = array();
  1284. $url_info = parse_url($url);
  1285. $port = isset($url_info['port']) ? intval($url_info['port']) : 80;
  1286. $fp = fsockopen($url_info['host'], $port, $errno, $errstr, 15);
  1287. if (!$fp)
  1288. {
  1289. trigger_error($errstr, E_USER_WARNING);
  1290. return false;
  1291. }
  1292. $path = !empty($url_info['path']) ? $url_info['path'] : '/';
  1293. $path .= !empty($url_info['query']) ? '?' . $url_info['query'] : '';
  1294. fputs($fp, "HEAD " . $path . " HTTP/1.0\r\n");
  1295. fputs($fp, "Host: " . $url_info['host'] . ":" . $port . "\r\n");
  1296. fputs($fp, "Connection: close\r\n\r\n");
  1297. while (!feof($fp))
  1298. {
  1299. if ($header = trim(fgets($fp, 1024)))
  1300. {
  1301. $res[] = $header;
  1302. }
  1303. }
  1304. @fclose($fp);
  1305. }
  1306. else
  1307. {
  1308. trigger_error('error server no support check url', E_USER_WARNING);
  1309. return false;
  1310. }
  1311. if (empty($res))
  1312. return false;
  1313. if (preg_match("/(200)/", $res[0]))
  1314. return true;
  1315. if ($is_200 > 5)
  1316. return false;
  1317. if (preg_match("/(301)|(302)|(303)/", $res[0]))
  1318. {
  1319. fore

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