global.func.php 35 KB

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