global.func.php 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. function ver_compare($version1, $version2) {
  8. $version1 = str_replace('.', '', $version1);
  9. $version2 = str_replace('.', '', $version2);
  10. $oldLength = istrlen($version1);
  11. $newLength = istrlen($version2);
  12. if (is_numeric($version1) && is_numeric($version2)) {
  13. if ($oldLength > $newLength) {
  14. $version2 .= str_repeat('0', $oldLength - $newLength);
  15. }
  16. if ($newLength > $oldLength) {
  17. $version1 .= str_repeat('0', $newLength - $oldLength);
  18. }
  19. $version1 = intval($version1);
  20. $version2 = intval($version2);
  21. }
  22. return version_compare($version1, $version2);
  23. }
  24. function iget_headers($url, $format = 0) {
  25. $result = @get_headers($url, $format);
  26. if (empty($result)) {
  27. stream_context_set_default(array(
  28. 'ssl' => array(
  29. 'verify_peer' => false,
  30. 'verify_peer_name' => false,
  31. ),
  32. ));
  33. $result = get_headers($url, $format);
  34. }
  35. return $result;
  36. }
  37. function igetimagesize($filename, $imageinfo = array()) {
  38. $result = @getimagesize($filename, $imageinfo);
  39. if (empty($result)) {
  40. $file_content = ihttp_request($filename);
  41. $content = $file_content['content'];
  42. $result = getimagesize('data://image/jpeg;base64,' . base64_encode($content), $imageinfo);
  43. }
  44. return $result;
  45. }
  46. function istripslashes($var) {
  47. if (is_array($var)) {
  48. foreach ($var as $key => $value) {
  49. $var[stripslashes($key)] = istripslashes($value);
  50. }
  51. } else {
  52. $var = stripslashes($var);
  53. }
  54. return $var;
  55. }
  56. function ihtmlspecialchars($var) {
  57. if (is_array($var)) {
  58. foreach ($var as $key => $value) {
  59. $var[htmlspecialchars($key)] = ihtmlspecialchars($value);
  60. }
  61. } else {
  62. $var = str_replace('&amp;', '&', htmlspecialchars($var, ENT_QUOTES));
  63. }
  64. return $var;
  65. }
  66. function isetcookie($key, $value, $expire = 0, $httponly = false) {
  67. global $_W;
  68. $expire = 0 != $expire ? (TIMESTAMP + $expire) : 0;
  69. if (!empty($_W['ishttps'])) {
  70. header('Set-Cookie: ' . ($_W['config']['cookie']['pre'] . $key . '=' . rawurlencode($value))
  71. . (!empty($expire) ? ('; expires=' . $expire) : '')
  72. . (!empty($_W['config']['cookie']['path']) ? ('; Path=' . $_W['config']['cookie']['path']) : '')
  73. . (!empty($_W['config']['cookie']['domain']) ? ('; Domain=' . $_W['config']['cookie']['domain']) : '')
  74. . '; SameSite=None; Secure'
  75. . (!$httponly ? '' : '; HttpOnly'), false);
  76. } else {
  77. $secure = (!empty($_SERVER['SERVER_PORT']) && 443 == $_SERVER['SERVER_PORT']) ? 1 : 0;
  78. setcookie($_W['config']['cookie']['pre'] . $key, $value, $expire, $_W['config']['cookie']['path'], $_W['config']['cookie']['domain'], $secure, $httponly);
  79. }
  80. return true;
  81. }
  82. function igetcookie($key) {
  83. global $_W;
  84. $key = $_W['config']['cookie']['pre'] . $key;
  85. return isset($_COOKIE[$key]) ? $_COOKIE[$key] : '';
  86. }
  87. function getip() {
  88. static $ip = '';
  89. if (isset($_SERVER['REMOTE_ADDR'])) {
  90. $ip = $_SERVER['REMOTE_ADDR'];
  91. }
  92. if (isset($_SERVER['HTTP_CDN_SRC_IP'])) {
  93. $ip = $_SERVER['HTTP_CDN_SRC_IP'];
  94. } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
  95. $ip = $_SERVER['HTTP_CLIENT_IP'];
  96. } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
  97. foreach ($matches[0] as $xip) {
  98. if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
  99. $ip = $xip;
  100. break;
  101. }
  102. }
  103. }
  104. if (preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $ip)) {
  105. return $ip;
  106. } else {
  107. return '127.0.0.1';
  108. }
  109. }
  110. function token($specialadd = '') {
  111. global $_W;
  112. if (!defined('IN_MOBILE')) {
  113. $key = complex_authkey();
  114. return substr(md5($key . $specialadd), 8, 8);
  115. } else {
  116. if (!empty($_SESSION['token'])) {
  117. $count = count($_SESSION['token']) - 5;
  118. asort($_SESSION['token']);
  119. foreach ($_SESSION['token'] as $k => $v) {
  120. if (TIMESTAMP - $v > 300 || $count > 0) {
  121. unset($_SESSION['token'][$k]);
  122. --$count;
  123. }
  124. }
  125. }
  126. $key = substr(random(20), 0, 4);
  127. $_SESSION['token'][$key] = TIMESTAMP;
  128. return $key;
  129. }
  130. }
  131. function random($length, $numeric = false) {
  132. $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  133. $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
  134. if ($numeric) {
  135. $hash = '';
  136. } else {
  137. $hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64);
  138. --$length;
  139. }
  140. $max = strlen($seed) - 1;
  141. for ($i = 0; $i < $length; ++$i) {
  142. $hash .= $seed[mt_rand(0, $max)];
  143. }
  144. return $hash;
  145. }
  146. function checksubmit($var = 'submit', $allowget = false) {
  147. global $_W, $_GPC;
  148. if (empty($_GPC[$var])) {
  149. return false;
  150. }
  151. if (defined('IN_SYS')) {
  152. if ($allowget || (($_W['ispost'] && !empty($_W['token']) && $_W['token'] == $_GPC['token']) && (empty($_SERVER['HTTP_REFERER']) || preg_replace("/https?:\/\/([^\:\/]+).*/i", '\\1', $_SERVER['HTTP_REFERER']) == preg_replace("/([^\:]+).*/", '\\1', $_SERVER['HTTP_HOST'])))) {
  153. return true;
  154. }
  155. } else {
  156. if (empty($_W['isajax']) && empty($_SESSION['token'][$_GPC['token']])) {
  157. exit('<script type="text/javascript">history.go(-1);</script>');
  158. } else {
  159. unset($_SESSION['token'][$_GPC['token']]);
  160. }
  161. return true;
  162. }
  163. return false;
  164. }
  165. function complex_authkey() {
  166. global $_W;
  167. $key = (array) $_W['setting']['site'];
  168. $key['authkey'] = $_W['config']['setting']['authkey'];
  169. return implode('', $key);
  170. }
  171. function checkcaptcha($code) {
  172. global $_GPC;
  173. session_start();
  174. $key = complex_authkey();
  175. $codehash = md5(strtolower($code) . $key);
  176. if (!empty($_GPC['__code']) && ($codehash == $_SESSION['__code'] || $codehash == igetcookie('__code'))) {
  177. $return = true;
  178. } else {
  179. $return = false;
  180. }
  181. $_SESSION['__code'] = '';
  182. isetcookie('__code', '');
  183. return $return;
  184. }
  185. function tablename($table) {
  186. if (empty($GLOBALS['_W']['config']['db']['master'])) {
  187. return "`{$GLOBALS['_W']['config']['db']['tablepre']}{$table}`";
  188. }
  189. return "`{$GLOBALS['_W']['config']['db']['master']['tablepre']}{$table}`";
  190. }
  191. function array_elements($keys, $src, $default = false) {
  192. $return = array();
  193. if (!is_array($keys)) {
  194. $keys = array($keys);
  195. }
  196. foreach ($keys as $key) {
  197. if (isset($src[$key])) {
  198. $return[$key] = $src[$key];
  199. } else {
  200. $return[$key] = $default;
  201. }
  202. }
  203. return $return;
  204. }
  205. function iarray_sort($array, $keys, $type = 'asc') {
  206. $keysvalue = $new_array = array();
  207. foreach ($array as $k => $v) {
  208. $keysvalue[$k] = $v[$keys];
  209. }
  210. if ('asc' == $type) {
  211. asort($keysvalue);
  212. } else {
  213. arsort($keysvalue);
  214. }
  215. reset($keysvalue);
  216. foreach ($keysvalue as $k => $v) {
  217. $new_array[$k] = $array[$k];
  218. }
  219. return $new_array;
  220. }
  221. function range_limit($num, $downline, $upline, $returnNear = true) {
  222. $num = intval($num);
  223. $downline = intval($downline);
  224. $upline = intval($upline);
  225. if ($num < $downline) {
  226. return empty($returnNear) ? false : $downline;
  227. } elseif ($num > $upline) {
  228. return empty($returnNear) ? false : $upline;
  229. } else {
  230. return empty($returnNear) ? true : $num;
  231. }
  232. }
  233. function ijson_encode($value, $options = 0) {
  234. if (empty($value)) {
  235. return false;
  236. }
  237. if (version_compare(PHP_VERSION, '5.4.0', '<') && JSON_UNESCAPED_UNICODE == $options) {
  238. $str = json_encode($value);
  239. $json_str = preg_replace_callback("#\\\u([0-9a-f]{4})#i", function ($matchs) {
  240. return iconv('UCS-2BE', 'UTF-8', pack('H4', $matchs[1]));
  241. }, $str);
  242. } else {
  243. $json_str = json_encode($value, $options);
  244. }
  245. return addslashes($json_str);
  246. }
  247. function iserializer($value) {
  248. return serialize($value);
  249. }
  250. function iunserializer($value) {
  251. if (empty($value)) {
  252. return array();
  253. }
  254. if (is_array($value)) {
  255. return $value;
  256. }
  257. if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
  258. $result = unserialize($value, array('allowed_classes' => false));
  259. } else {
  260. $result = unserialize($value);
  261. }
  262. return $result;
  263. }
  264. function is_base64($str) {
  265. if (!is_string($str)) {
  266. return false;
  267. }
  268. return $str == base64_encode(base64_decode($str));
  269. }
  270. function is_serialized($data, $strict = true) {
  271. if (!is_string($data)) {
  272. return false;
  273. }
  274. $data = trim($data);
  275. if ('N;' == $data) {
  276. return true;
  277. }
  278. if (strlen($data) < 4) {
  279. return false;
  280. }
  281. if (':' !== $data[1]) {
  282. return false;
  283. }
  284. if ($strict) {
  285. $lastc = substr($data, -1);
  286. if (';' !== $lastc && '}' !== $lastc) {
  287. return false;
  288. }
  289. } else {
  290. $semicolon = strpos($data, ';');
  291. $brace = strpos($data, '}');
  292. if (false === $semicolon && false === $brace) {
  293. return false;
  294. }
  295. if (false !== $semicolon && $semicolon < 3) {
  296. return false;
  297. }
  298. if (false !== $brace && $brace < 4) {
  299. return false;
  300. }
  301. }
  302. $token = $data[0];
  303. switch ($token) {
  304. case 's':
  305. if ($strict) {
  306. if ('"' !== substr($data, -2, 1)) {
  307. return false;
  308. }
  309. } elseif (false === strpos($data, '"')) {
  310. return false;
  311. }
  312. case 'a':
  313. return (bool) preg_match("/^{$token}:[0-9]+:/s", $data);
  314. case 'O':
  315. return false;
  316. case 'b':
  317. case 'i':
  318. case 'd':
  319. $end = $strict ? '$' : '';
  320. return (bool) preg_match("/^{$token}:[0-9.E-]+;$end/", $data);
  321. }
  322. return false;
  323. }
  324. function wurl($segment, $params = array(), $contain_domain = false) {
  325. global $_W;
  326. if (empty($params)) {
  327. $params = array();
  328. }
  329. $cad = explode('/', $segment);
  330. $controller = empty($cad[0]) ? '' : $cad[0];
  331. $action = empty($cad[1]) ? '' : $cad[1];
  332. $do = empty($cad[2]) ? '' : $cad[2];
  333. if ($contain_domain) {
  334. $url = $_W['siteroot'] . 'web/index.php?';
  335. } else {
  336. $url = './index.php?';
  337. }
  338. if (!empty($controller)) {
  339. $url .= "c={$controller}&";
  340. }
  341. if (!empty($action)) {
  342. $url .= "a={$action}&";
  343. }
  344. if (!empty($do)) {
  345. $url .= "do={$do}&";
  346. }
  347. if (empty($params['uniacid'])) {
  348. $url .= "w7i={$_W['uniacid']}&";
  349. }
  350. if (!empty($params)) {
  351. $queryString = http_build_query($params, '', '&');
  352. $url .= $queryString;
  353. }
  354. return $url;
  355. }
  356. if (!function_exists('murl')) {
  357. function murl($segment, $params = array(), $noredirect = true, $addhost = false) {
  358. global $_W;
  359. $cad = explode('/', $segment);
  360. $controller = empty($cad[0]) ? '' : $cad[0];
  361. $action = empty($cad[1]) ? '' : $cad[1];
  362. $do = empty($cad[2]) ? '' : $cad[2];
  363. if (!empty($addhost)) {
  364. $url = $_W['siteroot'] . 'app/';
  365. } else {
  366. $url = './';
  367. }
  368. $str = '';
  369. if (!empty($_W['account']) && $_W['account']['type'] == ACCOUNT_TYPE_WEBAPP_NORMAL) {
  370. $str .= '&a=webapp';
  371. }
  372. if (!empty($_W['account']) && $_W['account']['type'] == ACCOUNT_TYPE_PHONEAPP_NORMAL) {
  373. $str .= '&a=phoneapp';
  374. }
  375. $url .= "index.php?i={$_W['uniacid']}{$str}&";
  376. if (!empty($controller)) {
  377. $url .= "c={$controller}&";
  378. }
  379. if (!empty($action)) {
  380. $url .= "a={$action}&";
  381. }
  382. if (!empty($do)) {
  383. $url .= "do={$do}&";
  384. }
  385. if (!empty($params)) {
  386. $queryString = http_build_query($params, '', '&');
  387. $url .= $queryString;
  388. if (false === $noredirect) {
  389. $url .= '&wxref=mp.weixin.qq.com#wechat_redirect';
  390. }
  391. }
  392. return $url;
  393. }
  394. }
  395. function pagination($total, $pageIndex, $pageSize = 15, $url = '', $context = array('before' => 5, 'after' => 4, 'ajaxcallback' => '', 'callbackfuncname' => '')) {
  396. global $_W;
  397. $pdata = array(
  398. 'tcount' => 0,
  399. 'tpage' => 0,
  400. 'cindex' => 0,
  401. 'findex' => 0,
  402. 'pindex' => 0,
  403. 'nindex' => 0,
  404. 'lindex' => 0,
  405. 'options' => '',
  406. );
  407. if (empty($context['before'])) {
  408. $context['before'] = 5;
  409. }
  410. if (empty($context['after'])) {
  411. $context['after'] = 4;
  412. }
  413. if (!empty($context['ajaxcallback'])) {
  414. $context['isajax'] = true;
  415. }
  416. if (!empty($context['callbackfuncname'])) {
  417. $callbackfunc = $context['callbackfuncname'];
  418. }
  419. $pdata['tcount'] = $total;
  420. $pdata['tpage'] = (empty($pageSize) || $pageSize < 0) ? 1 : ceil($total / $pageSize);
  421. if ($pdata['tpage'] <= 1) {
  422. return '';
  423. }
  424. $cindex = $pageIndex;
  425. $cindex = min($cindex, $pdata['tpage']);
  426. $cindex = max($cindex, 1);
  427. $pdata['cindex'] = $cindex;
  428. $pdata['findex'] = 1;
  429. $pdata['pindex'] = $cindex > 1 ? $cindex - 1 : 1;
  430. $pdata['nindex'] = $cindex < $pdata['tpage'] ? $cindex + 1 : $pdata['tpage'];
  431. $pdata['lindex'] = $pdata['tpage'];
  432. if (!empty($context['isajax'])) {
  433. if (empty($url)) {
  434. $url = $_W['script_name'] . '?' . http_build_query($_GET);
  435. }
  436. $pdata['faa'] = 'href="javascript:;" page="' . $pdata['findex'] . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['findex'] . '\', this);"' : '');
  437. $pdata['paa'] = 'href="javascript:;" page="' . $pdata['pindex'] . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['pindex'] . '\', this);"' : '');
  438. $pdata['naa'] = 'href="javascript:;" page="' . $pdata['nindex'] . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['nindex'] . '\', this);"' : '');
  439. $pdata['laa'] = 'href="javascript:;" page="' . $pdata['lindex'] . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $pdata['lindex'] . '\', this);"' : '');
  440. } else {
  441. if ($url) {
  442. $pdata['faa'] = 'href="?' . str_replace('*', $pdata['findex'], $url) . '"';
  443. $pdata['paa'] = 'href="?' . str_replace('*', $pdata['pindex'], $url) . '"';
  444. $pdata['naa'] = 'href="?' . str_replace('*', $pdata['nindex'], $url) . '"';
  445. $pdata['laa'] = 'href="?' . str_replace('*', $pdata['lindex'], $url) . '"';
  446. } else {
  447. $_GET['page'] = $pdata['findex'];
  448. $pdata['faa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"';
  449. $_GET['page'] = $pdata['pindex'];
  450. $pdata['paa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"';
  451. $_GET['page'] = $pdata['nindex'];
  452. $pdata['naa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"';
  453. $_GET['page'] = $pdata['lindex'];
  454. $pdata['laa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"';
  455. }
  456. }
  457. $html = '<div><ul class="pagination pagination-centered">';
  458. $html .= "<li><a {$pdata['faa']} class=\"pager-nav\">首页</a></li>";
  459. empty($callbackfunc) && $html .= "<li><a {$pdata['paa']} class=\"pager-nav\">&laquo;上一页</a></li>";
  460. if (!$context['before'] && 0 != $context['before']) {
  461. $context['before'] = 5;
  462. }
  463. if (!$context['after'] && 0 != $context['after']) {
  464. $context['after'] = 4;
  465. }
  466. if (0 != $context['after'] && 0 != $context['before']) {
  467. $range = array();
  468. $range['start'] = max(1, $pdata['cindex'] - $context['before']);
  469. $range['end'] = min($pdata['tpage'], $pdata['cindex'] + $context['after']);
  470. if ($range['end'] - $range['start'] < $context['before'] + $context['after']) {
  471. $range['end'] = min($pdata['tpage'], $range['start'] + $context['before'] + $context['after']);
  472. $range['start'] = max(1, $range['end'] - $context['before'] - $context['after']);
  473. }
  474. for ($i = $range['start']; $i <= $range['end']; ++$i) {
  475. if (!empty($context['isajax'])) {
  476. $aa = 'href="javascript:;" page="' . $i . '" ' . ($callbackfunc ? 'ng-click="' . $callbackfunc . '(\'' . $url . '\', \'' . $i . '\', this);"' : '');
  477. } else {
  478. if ($url) {
  479. $aa = 'href="?' . str_replace('*', $i, $url) . '"';
  480. } else {
  481. $_GET['page'] = $i;
  482. $aa = 'href="?' . http_build_query($_GET) . '"';
  483. }
  484. }
  485. if (!empty($context['isajax'])) {
  486. $html .= ($i == $pdata['cindex'] ? '<li class="active">' : '<li>') . "<a {$aa}>" . $i . '</a></li>';
  487. } else {
  488. $html .= ($i == $pdata['cindex'] ? '<li class="active"><a href="javascript:;">' . $i . '</a></li>' : "<li><a {$aa}>" . $i . '</a></li>');
  489. }
  490. }
  491. }
  492. if ($pdata['cindex'] < $pdata['tpage']) {
  493. empty($callbackfunc) && $html .= "<li><a {$pdata['naa']} class=\"pager-nav\">下一页&raquo;</a></li>";
  494. $html .= "<li><a {$pdata['laa']} class=\"pager-nav\">尾页</a></li>";
  495. }
  496. $html .= '</ul></div>';
  497. return $html;
  498. }
  499. function tomedia($src, $local_path = false, $is_cahce = false) {
  500. global $_W;
  501. $src = trim($src);
  502. if (empty($src)) {
  503. return '';
  504. }
  505. if ($is_cahce) {
  506. $src .= '?v=' . time();
  507. }
  508. if (strexists($src, 'c=utility&a=wxcode&do=image&attach=')) {
  509. return $src;
  510. }
  511. $t = strtolower($src);
  512. if (strexists($t, '//mmbiz.qlogo.cn') || strexists($t, '//mmbiz.qpic.cn')) {
  513. $url = url('utility/wxcode/image', array('attach' => $src));
  514. return $_W['siteroot'] . 'web' . ltrim($url, '.');
  515. }
  516. if ('//' == substr($src, 0, 2)) {
  517. return 'http:' . $src;
  518. }
  519. if (('http://' == substr($src, 0, 7)) || ('https://' == substr($src, 0, 8))) {
  520. return $src;
  521. }
  522. if (strexists($src, 'addons/')) {
  523. return $_W['siteroot'] . substr($src, strpos($src, 'addons/'));
  524. }
  525. if (strexists($src, 'app/themes/')) {
  526. return $_W['siteroot'] . substr($src, strpos($src, 'app/themes/'));
  527. }
  528. if (strexists($src, $_W['siteroot']) && !strexists($src, '/addons/')) {
  529. $urls = parse_url($src);
  530. $src = $t = substr($urls['path'], strpos($urls['path'], 'images'));
  531. }
  532. $uni_remote_setting = uni_setting_load('remote');
  533. if ($local_path || empty($_W['setting']['remote']['type']) && (empty($_W['uniacid']) || !empty($_W['uniacid']) && empty($uni_remote_setting['remote']['type'])) || file_exists(IA_ROOT . '/' . $_W['config']['upload']['attachdir'] . '/' . $src)) {
  534. $src = $_W['siteroot'] . $_W['config']['upload']['attachdir'] . '/' . $src;
  535. } else {
  536. if (!empty($uni_remote_setting['remote']['type'])) {
  537. if (ATTACH_FTP == $uni_remote_setting['remote']['type']) {
  538. $src = $uni_remote_setting['remote']['ftp']['url'] . '/' . $src;
  539. } elseif (ATTACH_OSS == $uni_remote_setting['remote']['type']) {
  540. $src = $uni_remote_setting['remote']['alioss']['url'] . '/' . $src;
  541. } elseif (ATTACH_QINIU == $uni_remote_setting['remote']['type']) {
  542. $src = $uni_remote_setting['remote']['qiniu']['url'] . '/' . $src;
  543. } elseif (ATTACH_COS == $uni_remote_setting['remote']['type']) {
  544. $src = $uni_remote_setting['remote']['cos']['url'] . '/' . $src;
  545. }
  546. } else {
  547. $src = $_W['attachurl_remote'] . $src;
  548. }
  549. }
  550. return $src;
  551. }
  552. function to_global_media($src) {
  553. global $_W;
  554. $lower_src = strtolower($src);
  555. if (('http://' == substr($lower_src, 0, 7)) || ('https://' == substr($lower_src, 0, 8)) || ('//' == substr($lower_src, 0, 2))) {
  556. return $src;
  557. }
  558. $remote = setting_load('remote');
  559. $remote = empty($remote) ? array() : $remote['remote'];
  560. if (empty($remote['type']) || file_exists(IA_ROOT . '/' . $_W['config']['upload']['attachdir'] . '/' . $src)) {
  561. $src = $_W['siteroot'] . $_W['config']['upload']['attachdir'] . '/' . $src;
  562. } else {
  563. if (ATTACH_FTP == $remote['type']) {
  564. $attach_url = $remote['ftp']['url'] . '/';
  565. } elseif (ATTACH_OSS == $remote['type']) {
  566. $attach_url = $remote['alioss']['url'] . '/';
  567. } elseif (ATTACH_QINIU == $remote['type']) {
  568. $attach_url = $remote['qiniu']['url'] . '/';
  569. } elseif (ATTACH_COS == $remote['type']) {
  570. $attach_url = $remote['cos']['url'] . '/';
  571. }
  572. $src = $attach_url . $src;
  573. }
  574. return $src;
  575. }
  576. function error($errno, $message = '') {
  577. return array(
  578. 'errno' => $errno,
  579. 'message' => $message,
  580. );
  581. }
  582. function is_error($data) {
  583. if (empty($data) || !is_array($data) || !array_key_exists('errno', $data) || (array_key_exists('errno', $data) && 0 == $data['errno'])) {
  584. return false;
  585. } else {
  586. return true;
  587. }
  588. }
  589. function detect_sensitive_word($string) {
  590. $setting = setting_load('sensitive_words');
  591. if (empty($setting['sensitive_words'])) {
  592. return false;
  593. }
  594. $sensitive_words = $setting['sensitive_words'];
  595. $blacklist = '/' . implode('|', $sensitive_words) . '/';
  596. if (preg_match($blacklist, $string, $matches)) {
  597. return $matches[0];
  598. }
  599. return false;
  600. }
  601. function referer($default = '') {
  602. global $_GPC, $_W;
  603. $_SERVER['HTTP_REFERER'] = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
  604. $_W['referer'] = !empty($_GPC['referer']) ? $_GPC['referer'] : $_SERVER['HTTP_REFERER'];
  605. $_W['referer'] = '?' == substr($_W['referer'], -1) ? substr($_W['referer'], 0, -1) : $_W['referer'];
  606. if (strpos($_W['referer'], 'member.php?act=login')) {
  607. $_W['referer'] = $default;
  608. }
  609. $_W['referer'] = str_replace('&amp;', '&', $_W['referer']);
  610. $reurl = parse_url($_W['referer']);
  611. if (!empty($reurl['host']) && !in_array($reurl['host'], array($_SERVER['HTTP_HOST'], 'www.' . $_SERVER['HTTP_HOST'])) && !in_array($_SERVER['HTTP_HOST'], array($reurl['host'], 'www.' . $reurl['host']))) {
  612. $_W['referer'] = $_W['siteroot'];
  613. } elseif (empty($reurl['host'])) {
  614. $_W['referer'] = $_W['siteroot'] . './' . $_W['referer'];
  615. }
  616. return strip_tags($_W['referer']);
  617. }
  618. function strexists($string, $find) {
  619. return !(false === strpos($string, $find));
  620. }
  621. function cutstr($string, $length, $havedot = false, $charset = '') {
  622. global $_W;
  623. if (empty($charset)) {
  624. $charset = $_W['charset'];
  625. }
  626. if ('gbk' == strtolower($charset)) {
  627. $charset = 'gbk';
  628. } else {
  629. $charset = 'utf8';
  630. }
  631. if (istrlen($string, $charset) <= $length) {
  632. return $string;
  633. }
  634. if (function_exists('mb_strcut')) {
  635. $string = mb_substr($string, 0, $length, $charset);
  636. } else {
  637. $pre = '{%';
  638. $end = '%}';
  639. $string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array($pre . '&' . $end, $pre . '"' . $end, $pre . '<' . $end, $pre . '>' . $end), $string);
  640. $strlen = strlen($string);
  641. $n = $tn = $noc = 0;
  642. if ('utf8' == $charset) {
  643. while ($n < $strlen) {
  644. $t = ord($string[$n]);
  645. if (9 == $t || 10 == $t || (32 <= $t && $t <= 126)) {
  646. $tn = 1;
  647. ++$n;
  648. ++$noc;
  649. } elseif (194 <= $t && $t <= 223) {
  650. $tn = 2;
  651. $n += 2;
  652. ++$noc;
  653. } elseif (224 <= $t && $t <= 239) {
  654. $tn = 3;
  655. $n += 3;
  656. ++$noc;
  657. } elseif (240 <= $t && $t <= 247) {
  658. $tn = 4;
  659. $n += 4;
  660. ++$noc;
  661. } elseif (248 <= $t && $t <= 251) {
  662. $tn = 5;
  663. $n += 5;
  664. ++$noc;
  665. } elseif (252 == $t || 253 == $t) {
  666. $tn = 6;
  667. $n += 6;
  668. ++$noc;
  669. } else {
  670. ++$n;
  671. }
  672. if ($noc >= $length) {
  673. break;
  674. }
  675. }
  676. if ($noc > $length) {
  677. $n -= $tn;
  678. }
  679. $strcut = substr($string, 0, $n);
  680. } else {
  681. while ($n < $strlen) {
  682. $t = ord($string[$n]);
  683. if ($t > 127) {
  684. $tn = 2;
  685. $n += 2;
  686. ++$noc;
  687. } else {
  688. $tn = 1;
  689. ++$n;
  690. ++$noc;
  691. }
  692. if ($noc >= $length) {
  693. break;
  694. }
  695. }
  696. if ($noc > $length) {
  697. $n -= $tn;
  698. }
  699. $strcut = substr($string, 0, $n);
  700. }
  701. $string = str_replace(array($pre . '&' . $end, $pre . '"' . $end, $pre . '<' . $end, $pre . '>' . $end), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut);
  702. }
  703. if ($havedot) {
  704. $string = $string . '...';
  705. }
  706. return $string;
  707. }
  708. function istrlen($string, $charset = '') {
  709. global $_W;
  710. if (empty($charset)) {
  711. $charset = $_W['charset'];
  712. }
  713. if ('gbk' == strtolower($charset)) {
  714. $charset = 'gbk';
  715. } else {
  716. $charset = 'utf8';
  717. }
  718. if (function_exists('mb_strlen') && extension_loaded('mbstring')) {
  719. return mb_strlen($string, $charset);
  720. } else {
  721. $n = $noc = 0;
  722. $strlen = strlen($string);
  723. if ('utf8' == $charset) {
  724. while ($n < $strlen) {
  725. $t = ord($string[$n]);
  726. if (9 == $t || 10 == $t || (32 <= $t && $t <= 126)) {
  727. ++$n;
  728. ++$noc;
  729. } elseif (194 <= $t && $t <= 223) {
  730. $n += 2;
  731. ++$noc;
  732. } elseif (224 <= $t && $t <= 239) {
  733. $n += 3;
  734. ++$noc;
  735. } elseif (240 <= $t && $t <= 247) {
  736. $n += 4;
  737. ++$noc;
  738. } elseif (248 <= $t && $t <= 251) {
  739. $n += 5;
  740. ++$noc;
  741. } elseif (252 == $t || 253 == $t) {
  742. $n += 6;
  743. ++$noc;
  744. } else {
  745. ++$n;
  746. }
  747. }
  748. } else {
  749. while ($n < $strlen) {
  750. $t = ord($string[$n]);
  751. if ($t > 127) {
  752. $n += 2;
  753. ++$noc;
  754. } else {
  755. ++$n;
  756. ++$noc;
  757. }
  758. }
  759. }
  760. return $noc;
  761. }
  762. }
  763. function emotion($message = '', $size = '24px') {
  764. $emotions = array(
  765. '/::)', '/::~', '/::B', '/::|', '/:8-)', '/::<', '/::$', '/::X', '/::Z', "/::'(",
  766. '/::-|', '/::@', '/::P', '/::D', '/::O', '/::(', '/::+', '/:--b', '/::Q', '/::T',
  767. '/:,@P', '/:,@-D', '/::d', '/:,@o', '/::g', '/:|-)', '/::!', '/::L', '/::>', '/::,@',
  768. '/:,@f', '/::-S', '/:?', '/:,@x', '/:,@@', '/::8', '/:,@!', '/:!!!', '/:xx', '/:bye',
  769. '/:wipe', '/:dig', '/:handclap', '/:&-(', '/:B-)', '/:<@', '/:@>', '/::-O', '/:>-|',
  770. '/:P-(', "/::'|", '/:X-)', '/::*', '/:@x', '/:8*', '/:pd', '/:<W>', '/:beer', '/:basketb',
  771. '/:oo', '/:coffee', '/:eat', '/:pig', '/:rose', '/:fade', '/:showlove', '/:heart',
  772. '/:break', '/:cake', '/:li', '/:bome', '/:kn', '/:footb', '/:ladybug', '/:shit', '/:moon',
  773. '/:sun', '/:gift', '/:hug', '/:strong', '/:weak', '/:share', '/:v', '/:@)', '/:jj', '/:@@',
  774. '/:bad', '/:lvu', '/:no', '/:ok', '/:love', '/:<L>', '/:jump', '/:shake', '/:<O>', '/:circle',
  775. '/:kotow', '/:turn', '/:skip', '/:oY', '/:#-0', '/:hiphot', '/:kiss', '/:<&', '/:&>',
  776. );
  777. foreach ($emotions as $index => $emotion) {
  778. $message = str_replace($emotion, '<img style="width:' . $size . ';vertical-align:middle;" src="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/' . $index . '.gif" />', $message);
  779. }
  780. return $message;
  781. }
  782. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  783. if (empty($string)) {
  784. return '';
  785. }
  786. $ckey_length = 4;
  787. $key = md5('' != $key ? $key : $GLOBALS['_W']['config']['setting']['authkey']);
  788. $keya = md5(substr($key, 0, 16));
  789. $keyb = md5(substr($key, 16, 16));
  790. $keyc = $ckey_length ? ('DECODE' == $operation ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
  791. $cryptkey = $keya . md5($keya . $keyc);
  792. $key_length = strlen($cryptkey);
  793. $string = 'DECODE' == $operation ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
  794. $string_length = strlen($string);
  795. $result = '';
  796. $box = range(0, 255);
  797. $rndkey = array();
  798. for ($i = 0; $i <= 255; ++$i) {
  799. $rndkey[$i] = ord($cryptkey[$i % $key_length]);
  800. }
  801. for ($j = $i = 0; $i < 256; ++$i) {
  802. $j = ($j + $box[$i] + $rndkey[$i]) % 256;
  803. $tmp = $box[$i];
  804. $box[$i] = $box[$j];
  805. $box[$j] = $tmp;
  806. }
  807. for ($a = $j = $i = 0; $i < $string_length; ++$i) {
  808. $a = ($a + 1) % 256;
  809. $j = ($j + $box[$a]) % 256;
  810. $tmp = $box[$a];
  811. $box[$a] = $box[$j];
  812. $box[$j] = $tmp;
  813. $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
  814. }
  815. if ('DECODE' == $operation) {
  816. if ((0 == substr($result, 0, 10) || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
  817. return substr($result, 26);
  818. } else {
  819. return '';
  820. }
  821. } else {
  822. return $keyc . str_replace('=', '', base64_encode($result));
  823. }
  824. }
  825. function sizecount($size, $unit = false) {
  826. if ($size >= 1073741824) {
  827. $size = round($size / 1073741824 * 100) / 100 . ' GB';
  828. } elseif ($size >= 1048576) {
  829. $size = round($size / 1048576 * 100) / 100 . ' MB';
  830. } elseif ($size >= 1024) {
  831. $size = round($size / 1024 * 100) / 100 . ' KB';
  832. } else {
  833. $size = $size . ' Bytes';
  834. }
  835. if ($unit) {
  836. $size = preg_replace('/[^0-9\.]/', '', $size);
  837. }
  838. return $size;
  839. }
  840. function bytecount($str) {
  841. $unit = strtolower(substr($str, -1));
  842. if ('b' == $unit) {
  843. $str = substr($str, 0, -1);
  844. }
  845. if ('k' == $unit) {
  846. return floatval($str) * 1024;
  847. }
  848. if ('m' == $unit) {
  849. return floatval($str) * 1048576;
  850. }
  851. if ('g' == $unit) {
  852. return floatval($str) * 1073741824;
  853. }
  854. }
  855. function array2xml($arr, $level = 1) {
  856. $s = 1 == $level ? '<xml>' : '';
  857. foreach ($arr as $tagname => $value) {
  858. if (is_numeric($tagname)) {
  859. $tagname = $value['TagName'];
  860. unset($value['TagName']);
  861. }
  862. if (!is_array($value)) {
  863. $s .= "<{$tagname}>" . (!is_numeric($value) ? '<![CDATA[' : '') . $value . (!is_numeric($value) ? ']]>' : '') . "</{$tagname}>";
  864. } else {
  865. $s .= "<{$tagname}>" . array2xml($value, $level + 1) . "</{$tagname}>";
  866. }
  867. }
  868. $s = preg_replace("/([\x01-\x08\x0b-\x0c\x0e-\x1f])+/", ' ', $s);
  869. return 1 == $level ? $s . '</xml>' : $s;
  870. }
  871. function xml2array($xml) {
  872. if (empty($xml)) {
  873. return array();
  874. }
  875. $result = array();
  876. $xmlobj = isimplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
  877. if ($xmlobj instanceof SimpleXMLElement) {
  878. $result = json_decode(json_encode($xmlobj), true);
  879. if (is_array($result)) {
  880. return $result;
  881. } else {
  882. return '';
  883. }
  884. } else {
  885. return $result;
  886. }
  887. }
  888. function scriptname() {
  889. $script_name = basename($_SERVER['SCRIPT_FILENAME']);
  890. if (basename($_SERVER['SCRIPT_NAME']) === $script_name) {
  891. $script_name = $_SERVER['SCRIPT_NAME'];
  892. } else {
  893. if (basename($_SERVER['PHP_SELF']) === $script_name) {
  894. $script_name = $_SERVER['PHP_SELF'];
  895. } else {
  896. if (isset($_SERVER['ORIG_SCRIPT_NAME']) && basename($_SERVER['ORIG_SCRIPT_NAME']) === $script_name) {
  897. $script_name = $_SERVER['ORIG_SCRIPT_NAME'];
  898. } else {
  899. if (false !== ($pos = strpos($_SERVER['PHP_SELF'], '/'))) {
  900. $script_name = substr($_SERVER['SCRIPT_NAME'], 0, $pos) . '/' . $script_name;
  901. } else {
  902. if (isset($_SERVER['DOCUMENT_ROOT']) && 0 === strpos($_SERVER['SCRIPT_FILENAME'], $_SERVER['DOCUMENT_ROOT'])) {
  903. $script_name = str_replace('\\', '/', str_replace($_SERVER['DOCUMENT_ROOT'], '', $_SERVER['SCRIPT_FILENAME']));
  904. } else {
  905. $script_name = 'unknown';
  906. }
  907. }
  908. }
  909. }
  910. }
  911. return $script_name;
  912. }
  913. function utf8_bytes($cp) {
  914. if ($cp > 0x10000) {
  915. return chr(0xF0 | (($cp & 0x1C0000) >> 18)) .
  916. chr(0x80 | (($cp & 0x3F000) >> 12)) .
  917. chr(0x80 | (($cp & 0xFC0) >> 6)) .
  918. chr(0x80 | ($cp & 0x3F));
  919. } elseif ($cp > 0x800) {
  920. return chr(0xE0 | (($cp & 0xF000) >> 12)) .
  921. chr(0x80 | (($cp & 0xFC0) >> 6)) .
  922. chr(0x80 | ($cp & 0x3F));
  923. } elseif ($cp > 0x80) {
  924. return chr(0xC0 | (($cp & 0x7C0) >> 6)) .
  925. chr(0x80 | ($cp & 0x3F));
  926. } else {
  927. return chr($cp);
  928. }
  929. }
  930. function media2local($media_id, $all = false) {
  931. global $_W;
  932. load()->model('material');
  933. $data = material_get($media_id);
  934. if (!is_error($data)) {
  935. $data['attachment'] = tomedia($data['attachment'], true);
  936. if (!$all) {
  937. return $data['attachment'];
  938. }
  939. return $data;
  940. } else {
  941. return '';
  942. }
  943. }
  944. function aes_decode($message, $encodingaeskey = '', $appid = '') {
  945. $key = base64_decode($encodingaeskey . '=');
  946. $ciphertext_dec = base64_decode($message);
  947. $iv = substr($key, 0, 16);
  948. $decrypted = openssl_decrypt($ciphertext_dec, 'AES-256-CBC', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
  949. $pad = ord(substr($decrypted, -1));
  950. if ($pad < 1 || $pad > 32) {
  951. $pad = 0;
  952. }
  953. $result = substr($decrypted, 0, (strlen($decrypted) - $pad));
  954. if (strlen($result) < 16) {
  955. return '';
  956. }
  957. $content = substr($result, 16, strlen($result));
  958. $len_list = unpack('N', substr($content, 0, 4));
  959. $contentlen = $len_list[1];
  960. $content = substr($content, 4, $contentlen);
  961. $from_appid = substr($content, 4);
  962. if (!empty($appid) && $appid != $from_appid) {
  963. return '';
  964. }
  965. return $content;
  966. }
  967. function aes_encode($message, $encodingaeskey = '', $appid = '') {
  968. $key = base64_decode($encodingaeskey . '=');
  969. $text = random(16) . pack('N', strlen($message)) . $message . $appid;
  970. $iv = substr($key, 0, 16);
  971. $block_size = 32;
  972. $text_length = strlen($text);
  973. $amount_to_pad = $block_size - ($text_length % $block_size);
  974. if (0 == $amount_to_pad) {
  975. $amount_to_pad = $block_size;
  976. }
  977. $pad_chr = chr($amount_to_pad);
  978. $tmp = '';
  979. for ($index = 0; $index < $amount_to_pad; ++$index) {
  980. $tmp .= $pad_chr;
  981. }
  982. $text = $text . $tmp;
  983. $encrypted = openssl_encrypt($text, 'AES-256-CBC', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
  984. $encrypt_msg = base64_encode($encrypted);
  985. return $encrypt_msg;
  986. }
  987. function aes_pkcs7_decode($encrypt_data, $key, $iv = false) {
  988. load()->library('pkcs7');
  989. $encrypt_data = base64_decode($encrypt_data);
  990. if (!empty($iv)) {
  991. $iv = base64_decode($iv);
  992. }
  993. $pc = new Prpcrypt($key);
  994. $result = $pc->decrypt($encrypt_data, $iv);
  995. if (0 != $result[0]) {
  996. return error($result[0], '解密失败');
  997. }
  998. return $result[1];
  999. }
  1000. function isimplexml_load_string($string, $class_name = 'SimpleXMLElement', $options = 0, $ns = '', $is_prefix = false) {
  1001. libxml_disable_entity_loader(true);
  1002. if (preg_match('/(\<\!DOCTYPE|\<\!ENTITY)/i', $string)) {
  1003. return false;
  1004. }
  1005. $string = preg_replace('/[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f\\x7f]/', '', $string);
  1006. return simplexml_load_string($string, $class_name, $options, $ns, $is_prefix);
  1007. }
  1008. function ihtml_entity_decode($str) {
  1009. $str = str_replace('&nbsp;', '#nbsp;', $str);
  1010. return str_replace('#nbsp;', '&nbsp;', html_entity_decode(urldecode($str)));
  1011. }
  1012. function iarray_change_key_case($array, $case = CASE_LOWER) {
  1013. if (!is_array($array) || empty($array)) {
  1014. return array();
  1015. }
  1016. $array = array_change_key_case($array, $case);
  1017. foreach ($array as $key => $value) {
  1018. if (empty($value) && is_array($value)) {
  1019. $array[$key] = '';
  1020. }
  1021. if (!empty($value) && is_array($value)) {
  1022. $array[$key] = iarray_change_key_case($value, $case);
  1023. }
  1024. }
  1025. return $array;
  1026. }
  1027. function parse_path($path) {
  1028. $danger_char = array('../', '{php', '<?php', '<%', '<?', '..\\', '\\\\', '\\', '..\\\\', '%00', '\0', '\r');
  1029. foreach ($danger_char as $char) {
  1030. if (strexists($path, $char)) {
  1031. return false;
  1032. }
  1033. }
  1034. return $path;
  1035. }
  1036. function dir_size($dir) {
  1037. $size = 0;
  1038. if (is_dir($dir)) {
  1039. $handle = opendir($dir);
  1040. while (false !== ($entry = readdir($handle))) {
  1041. if ('.' != $entry && '..' != $entry) {
  1042. if (is_dir("{$dir}/{$entry}")) {
  1043. $size += dir_size("{$dir}/{$entry}");
  1044. } else {
  1045. $size += filesize("{$dir}/{$entry}");
  1046. }
  1047. }
  1048. }
  1049. closedir($handle);
  1050. }
  1051. return $size;
  1052. }
  1053. function get_first_pinyin($str) {
  1054. static $pinyin;
  1055. $first_char = '';
  1056. $str = trim($str);
  1057. if (empty($str)) {
  1058. return $first_char;
  1059. }
  1060. if (empty($pinyin)) {
  1061. load()->library('pinyin');
  1062. $pinyin = new Pinyin_Pinyin();
  1063. }
  1064. $first_char = $pinyin->get_first_char($str);
  1065. return $first_char;
  1066. }
  1067. function strip_emoji($nickname) {
  1068. $clean_text = '';
  1069. $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
  1070. $clean_text = preg_replace($regexEmoticons, '_', $nickname);
  1071. $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
  1072. $clean_text = preg_replace($regexSymbols, '_', $clean_text);
  1073. $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
  1074. $clean_text = preg_replace($regexTransport, '_', $clean_text);
  1075. $regexMisc = '/[\x{2600}-\x{26FF}]/u';
  1076. $clean_text = preg_replace($regexMisc, '_', $clean_text);
  1077. $regexDingbats = '/[\x{2700}-\x{27BF}]/u';
  1078. $clean_text = preg_replace($regexDingbats, '_', $clean_text);
  1079. $clean_text = str_replace("'", '_', $clean_text);
  1080. $clean_text = str_replace('"', '_', $clean_text);
  1081. $clean_text = str_replace('“', '_', $clean_text);
  1082. $clean_text = str_replace('゛', '_', $clean_text);
  1083. $search = array(' ', ' ', "\n", "\r", "\t");
  1084. $replace = array('_', '_', '_', '_', '_');
  1085. return str_replace($search, $replace, $clean_text);
  1086. }
  1087. function emoji_unicode_decode($string) {
  1088. preg_match_all('/\[U\+(\\w{4,})\]/i', $string, $match);
  1089. if (!empty($match[1])) {
  1090. foreach ($match[1] as $emojiUSB) {
  1091. $string = str_ireplace("[U+{$emojiUSB}]", utf8_bytes(hexdec($emojiUSB)), $string);
  1092. }
  1093. }
  1094. return $string;
  1095. }
  1096. function emoji_unicode_encode($string) {
  1097. $ranges = array(
  1098. '\\\\ud83c[\\\\udf00-\\\\udfff]',
  1099. '\\\\ud83d[\\\\udc00-\\\\ude4f]',
  1100. '\\\\ud83d[\\\\ude80-\\\\udeff]',
  1101. );
  1102. preg_match_all('/' . implode('|', $ranges) . '/i', $string, $match);
  1103. print_r($match);
  1104. exit;
  1105. }
  1106. if (!function_exists('starts_with')) {
  1107. function starts_with($haystack, $needles) {
  1108. foreach ((array) $needles as $needle) {
  1109. if ('' != $needle && substr($haystack, 0, strlen($needle)) === (string) $needle) {
  1110. return true;
  1111. }
  1112. }
  1113. return false;
  1114. }
  1115. }
  1116. function ierror_page($message, $redirect_url = '') {
  1117. $image_url = !empty($redirect_url) ? '../web/resource/images/loading.gif' : '//cdn.w7.cc/ued/jump/image/jump-logo.png';
  1118. $html = '<!DOCTYPE html>
  1119. <html lang="zh-cn">
  1120. <head>
  1121. <meta charset="utf-8">
  1122. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  1123. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  1124. <title>错误页提示</title>
  1125. </head>
  1126. <style>
  1127. html,body,.jump{height:100vh;width:100vw;overflow:hidden;background-color:#fff}.jump{position:relative;text-align:center}.center-box{margin:280px auto 0;height:230px;width:600px;display:inline-block;text-align:center}.jump-content{font-size:18px;line-height:30px;color:#666;font-weight:300}.jump-tips{font-size:14px;line-height:30px;color:#999}
  1128. </style>
  1129. <body>
  1130. <div class="jump">
  1131. <div class="center-box">
  1132. <img src="' . $image_url . '" alt="" style="margin-bottom:10px;width:40px">
  1133. <div class="jump-content">' . $message . '</div>
  1134. </div>
  1135. </div>
  1136. </body>';
  1137. if (!empty($redirect_url)) {
  1138. $html .= '<script>
  1139. window.onload = function() {
  1140. var count = 3
  1141. var i = setInterval(function() {
  1142. count--
  1143. clearInterval(i)
  1144. location.href = "' . $redirect_url . '";
  1145. },2000)
  1146. }
  1147. </script>';
  1148. }
  1149. $html .= '</html>';
  1150. return $html;
  1151. }
  1152. function iconsole_log($data) {
  1153. echo '<script>';
  1154. echo 'console.log(' . json_encode($data) . ')';
  1155. echo '</script>';
  1156. }
  1157. load()->func('safe');
  1158. load()->func('system');