人人商城

global.func.php 36KB

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