functions.inc.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. <?php
  2. /**
  3. * 二维数组去重
  4. * @return array
  5. */
  6. if (! function_exists('array_unique_two_dimensional')) {
  7. function array_unique_multidimensional(array $input)
  8. {
  9. $unique = [];
  10. foreach ($input as $item) {
  11. if (! is_array($item)) {
  12. return $input;
  13. }
  14. $str = implode(',', $item); //利用implode,将二维数组中的下层数组变成字符串
  15. $strArr[] = $str;
  16. $unique = array_unique($strArr); //去掉重复的字符串,也就是生成一个干净的一维数组
  17. }
  18. $output = [];
  19. foreach ($unique as $item) {
  20. $output[] = explode(',', $item);
  21. }
  22. return $output;
  23. }
  24. }
  25. if (! function_exists('getUrlImage')) {
  26. /**
  27. * Get the image in the url.
  28. *
  29. * @param string $url
  30. * @param string $filename
  31. * @return string|boolean
  32. */
  33. function getUrlImage($url, $filename)
  34. {
  35. if (file_exists($filename)) {
  36. unlink($filename);
  37. }
  38. if (empty($url) || empty($filename)) {
  39. return false;
  40. }
  41. ob_start();//打开输出
  42. readfile($url);//输出图片文件
  43. $img = ob_get_contents();//得到浏览器输出
  44. ob_end_clean();//清除输出并关闭
  45. // $size = strlen($img);//得到图片大小
  46. $fp2 = @fopen($filename, "a");
  47. fwrite($fp2, $img);//向当前目录写入图片文件,并重新命名
  48. fclose($fp2);
  49. return $filename;
  50. }
  51. }
  52. if (! function_exists('imageToCircle')) {
  53. /**
  54. * Change the image to the circle.
  55. *
  56. * @param string $url
  57. * @return string
  58. */
  59. function imageToCircle($url)
  60. {
  61. $ext = pathinfo($url);
  62. // dd($ext);
  63. $src_img = null;
  64. switch ($ext['extension']) {
  65. case 'jpg':
  66. $src_img = imagecreatefromjpeg($url);
  67. break;
  68. case 'png':
  69. $src_img = imagecreatefrompng($url);
  70. break;
  71. }
  72. $wh = getimagesize($url);
  73. $w = $wh[0];
  74. $h = $wh[1];
  75. $w = min($w, $h);
  76. $h = $w;
  77. $img = imagecreatetruecolor($w, $h);
  78. //这一句一定要有
  79. imagesavealpha($img, true);
  80. //拾取一个完全透明的颜色,最后一个参数127为全透明
  81. $bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
  82. imagefill($img, 0, 0, $bg);
  83. $r = $w / 2; //圆半径
  84. $y_x = $r; //圆心X坐标
  85. $y_y = $r; //圆心Y坐标
  86. for ($x = 0; $x < $w; $x++) {
  87. for ($y = 0; $y < $h; $y++) {
  88. $rgbColor = imagecolorat($src_img, $x, $y);
  89. if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {
  90. imagesetpixel($img, $x, $y, $rgbColor);
  91. }
  92. }
  93. }
  94. //存储png
  95. imagepng($img, $url);
  96. //存储jpeg
  97. //imagejpeg($img, $url);
  98. return $url;
  99. }
  100. }
  101. if( ! function_exists('array_to_sort')) {
  102. /**
  103. * 对二维数组排序
  104. * @param string $arr old数组
  105. * @param string $keys 要排序的键
  106. * @param string $type 排序类型[asc,desc]
  107. * @param string $reset 重新排列数组key
  108. * @return string 返回排序之后的数组
  109. */
  110. function array_to_sort($arr, $keys, $type = 'asc', $reset = false)
  111. {
  112. $keysvalue = $new_array = array();
  113. foreach ($arr as $k => $v) {
  114. $keysvalue[$k] = $v[$keys];
  115. }
  116. if ($type == 'asc') {
  117. asort($keysvalue);
  118. } else {
  119. arsort($keysvalue);
  120. }
  121. reset($keysvalue);
  122. foreach ($keysvalue as $k => $v) {
  123. if ($reset) {
  124. $new_array[] = $arr[$k];
  125. } else {
  126. $new_array[$k] = $arr[$k];
  127. }
  128. }
  129. return $new_array;
  130. }
  131. }
  132. /**
  133. * 写作的时间人性化
  134. *
  135. * @param int $time 写作的时间
  136. * @return string
  137. */
  138. if( ! function_exists('showWriteTime'))
  139. {
  140. function showWriteTime($time)
  141. {
  142. $interval = time() - $time;
  143. $format = array(
  144. '31536000' => '年',
  145. '2592000' => '个月',
  146. '604800' => '星期',
  147. '86400' => '天',
  148. '3600' => '小时',
  149. '60' => '分钟',
  150. '1' => '秒'
  151. );
  152. foreach($format as $key => $value)
  153. {
  154. $match = floor($interval / (int) $key );
  155. if(0 != $match)
  156. {
  157. return $match . $value . '前';
  158. }
  159. }
  160. return date('Y-m-d', $time);
  161. }
  162. }
  163. if( ! function_exists('pairList'))
  164. {
  165. function pairList($list, $keyField, $valueField)
  166. {
  167. $pairList = array();
  168. foreach ($list as $one) {
  169. $pairList[$one[$keyField]] = $one[$valueField];
  170. }
  171. return $pairList;
  172. }
  173. }
  174. /**
  175. * 重新组装url ,如果没有host回自动添加当前host
  176. * @param string $url
  177. * @param array $query key=>val
  178. * @return string
  179. */
  180. function U ($url, $query = [])
  181. {
  182. $url = ltrim($url, '/');
  183. $urlInfo = parse_url($url);
  184. $aQuery = [];
  185. if (isset($urlInfo['query']) && $urlInfo['query'] !== '') {
  186. parse_str($urlInfo['query'],$aQuery);
  187. }
  188. $queryString = http_build_query(array_merge($aQuery, $query));
  189. if(isset($urlInfo['host'])) {
  190. $url = $urlInfo['scheme'] . '://' . $urlInfo['host'].'/admin/';
  191. }else{
  192. $url = request()->root() . '/admin/';
  193. }
  194. $url .= isset($urlInfo['path']) ? $urlInfo['path'] : '';
  195. $url .= $queryString === '' ? '' : ('?'.$queryString);
  196. return $url;
  197. }
  198. /**
  199. * 验证角色菜单权限
  200. *
  201. * @param string $route 路由
  202. * @param string $params 附带参数
  203. * @return bool
  204. */
  205. if( ! function_exists('role'))
  206. {
  207. function role($route, $params = [])
  208. {
  209. $user = \Auth::guard('admin')->user();
  210. $role = session()->get(LOGIN_MARK_SESSION_KEY);
  211. if($user['is_root'] ||$user['level'] >=0) {
  212. return true;
  213. }
  214. $route = trim($route);
  215. $roles = $role['role'];
  216. if(isset($roles[$route])){
  217. return true;
  218. }else{
  219. return false;
  220. }
  221. }
  222. }
  223. if( ! function_exists('dict'))
  224. {
  225. function dict()
  226. {
  227. return new App\Services\Base\Dictionary;
  228. }
  229. }
  230. /**
  231. * 隐藏部分手机号码
  232. * @param $mobile
  233. * @param $hide_length
  234. * @return string
  235. */
  236. if( ! function_exists('hidePartMobile'))
  237. {
  238. function hidePartMobile($mobile, $hide_length = 5){
  239. $hide_length = intval($hide_length);
  240. $hide = '';
  241. for($i = 0; $i < $hide_length; $i++){
  242. $hide .= '*';
  243. }
  244. $pattern = "/(1\d{1,2})([0-9]{". $hide_length .",". $hide_length ."})(\d+)/";
  245. $replacement = "\$1{$hide}\$3";
  246. return preg_replace($pattern, $replacement, $mobile);
  247. }
  248. }
  249. /**
  250. * Function echo_log
  251. * 输出调试日志
  252. * @param $content 输出内容
  253. */
  254. if( ! function_exists('echoLog'))
  255. {
  256. function echoLog($content, $filename = '')
  257. {
  258. if(is_object($content) || is_array($content)) {
  259. $content = var_export($content, true);
  260. }
  261. $log_path = storage_path() . DIRECTORY_SEPARATOR . "debug_log" . DIRECTORY_SEPARATOR;
  262. if($filename){
  263. $file_path = $log_path . $filename;
  264. }else{
  265. $file_path = $log_path . "debug_log_" . date("Ymd") . ".txt";
  266. }
  267. if(!file_exists($log_path)){
  268. mkdir($log_path,0777);
  269. }
  270. $fp = fopen($file_path, "a");
  271. flock($fp, LOCK_EX) ;
  272. fwrite($fp,"执行日期:".date("Y-m-d H:i:s",time())."\n".$content."\n\n");
  273. flock($fp, LOCK_UN);
  274. fclose($fp);
  275. }
  276. }
  277. if( ! function_exists('curlAjax'))
  278. {
  279. function curlAjax($url) {
  280. $cookieStr = '';
  281. if($_COOKIE) {
  282. foreach ($_COOKIE as $key=>$val) {
  283. $cookieStr .= $key . '=' . $val . ';';
  284. }
  285. $cookieStr = substr($cookieStr, 0,-1);
  286. }
  287. $headers = array(
  288. 'Content-Type' => 'text/json;charset=utf-8', // 设置为Ajax方式
  289. 'X-Requested-With' => 'XMLHttpRequest', // 设置为Ajax方式
  290. 'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36', // 设置为Ajax方式
  291. 'Referer' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
  292. 'Cookie' => $cookieStr
  293. );
  294. $headerArr = array();
  295. foreach( $headers as $n => $v ) {
  296. $headerArr[] = $n .':' . $v;
  297. }
  298. $ch = curl_init($url);
  299. curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
  300. curl_setopt($ch, CURLOPT_HEADER, 0);
  301. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  302. $return = curl_exec($ch);
  303. curl_close ( $ch );
  304. return $return;
  305. }
  306. }
  307. if( ! function_exists('img'))
  308. {
  309. function img($system, $system_primary = NULL, $system_key = NULL, $first = false, $pagesize = PAGE_MAX_NUMS)
  310. {
  311. $paramArgs = func_get_args();
  312. $key = "system_img" . md5(serialize($paramArgs));
  313. if(!Cache::has($key) || request('no_cache') === 'true') {
  314. $data = \App\Services\Base\Images::getSrc($system, $system_primary, $system_key, $first, $pagesize);
  315. \Cache::forever($key,$data);
  316. }
  317. $data = \Cache::get($key);
  318. return $data;
  319. }
  320. }
  321. /**
  322. * 字符截取 支持UTF8/GBK
  323. * @param $string
  324. * @param $length
  325. * @param $dot
  326. */
  327. if( ! function_exists('str_cut'))
  328. {
  329. function str_cut($string, $length, $dot = '...') {
  330. $strlen = strlen($string);
  331. if($strlen <= $length) return $string;
  332. $string = str_replace(array(' ','&nbsp;', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), array('∵',' ', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), $string);
  333. $strcut = '';
  334. if(strtolower('utf-8') == 'utf-8') {
  335. $length = intval($length-strlen($dot)-$length/3);
  336. $n = $tn = $noc = 0;
  337. while($n < strlen($string)) {
  338. $t = ord($string[$n]);
  339. if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
  340. $tn = 1; $n++; $noc++;
  341. } elseif(194 <= $t && $t <= 223) {
  342. $tn = 2; $n += 2; $noc += 2;
  343. } elseif(224 <= $t && $t <= 239) {
  344. $tn = 3; $n += 3; $noc += 2;
  345. } elseif(240 <= $t && $t <= 247) {
  346. $tn = 4; $n += 4; $noc += 2;
  347. } elseif(248 <= $t && $t <= 251) {
  348. $tn = 5; $n += 5; $noc += 2;
  349. } elseif($t == 252 || $t == 253) {
  350. $tn = 6; $n += 6; $noc += 2;
  351. } else {
  352. $n++;
  353. }
  354. if($noc >= $length) {
  355. break;
  356. }
  357. }
  358. if($noc > $length) {
  359. $n -= $tn;
  360. }
  361. $strcut = substr($string, 0, $n);
  362. $strcut = str_replace(array('∵', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), array(' ', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), $strcut);
  363. } else {
  364. $dotlen = strlen($dot);
  365. $maxi = $length - $dotlen - 1;
  366. $current_str = '';
  367. $search_arr = array('&',' ', '"', "'", '“', '”', '—', '<', '>', '·', '…','∵');
  368. $replace_arr = array('&amp;','&nbsp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;',' ');
  369. $search_flip = array_flip($search_arr);
  370. for ($i = 0; $i < $maxi; $i++) {
  371. $current_str = ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
  372. if (in_array($current_str, $search_arr)) {
  373. $key = $search_flip[$current_str];
  374. $current_str = str_replace($search_arr[$key], $replace_arr[$key], $current_str);
  375. }
  376. $strcut .= $current_str;
  377. }
  378. }
  379. return $strcut.$dot;
  380. }
  381. }
  382. /**
  383. * 取得文件扩展
  384. *
  385. * @param $filename 文件名
  386. * @return 扩展名
  387. */
  388. if( ! function_exists('fileExt'))
  389. {
  390. function fileExt($filename)
  391. {
  392. return strtolower(trim(substr(strrchr($filename, '.'), 1, 10)));
  393. }
  394. }
  395. /**
  396. * 过滤参数
  397. *
  398. * @param $param 参数数组
  399. * @param $allowKey 被允许的KEY集合数组
  400. * @return 扩展名
  401. */
  402. if( ! function_exists('filterParam'))
  403. {
  404. function filterParam(array $param, array $allowKey)
  405. {
  406. $data = array();
  407. foreach ($param AS $key => $val) {
  408. if(in_array($key, $allowKey)) $data[$key] = $val;
  409. }
  410. return $data;
  411. }
  412. }
  413. if(!function_exists('list_to_tree')) {
  414. function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0)
  415. {
  416. // 创建Tree
  417. $tree = array();
  418. if(is_array($list)) {
  419. // 创建基于主键的数组引用
  420. $refer = array();
  421. foreach ($list as $key => $data) {
  422. $refer[$data[$pk]] =& $list[$key];
  423. }
  424. foreach ($list as $key => $data) {
  425. // 判断是否存在parent
  426. $parentId = $data[$pid];
  427. if ($root == $parentId) {
  428. $tree[] =& $list[$key];
  429. }else{
  430. if (isset($refer[$parentId])) {
  431. $parent =& $refer[$parentId];
  432. $parent[$child][] =& $list[$key];
  433. }
  434. }
  435. }
  436. }
  437. return $tree;
  438. }
  439. }
  440. /**
  441. * 判断远程文件是否存在
  442. * @param unknown $url
  443. * @return boolean
  444. */
  445. function check_remote_file_exists($url)
  446. {
  447. $curl = curl_init($url);
  448. curl_setopt($curl, CURLOPT_NOBODY, true);
  449. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
  450. $result = curl_exec($curl);
  451. $found = false;
  452. if ($result !== false)
  453. {
  454. $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  455. if ($statusCode == 200)
  456. {
  457. $found = true;
  458. }
  459. }
  460. curl_close($curl);
  461. return $found;
  462. }
  463. if( ! function_exists('getCacheKey')) {
  464. /**
  465. * 更具参数获取一个唯一的缓存KEY
  466. * @param string $name 名称
  467. * @param obj|array|string $data 参数
  468. */
  469. function getCacheKey($name,$data) {
  470. return $name . md5(serialize($data));
  471. }
  472. }
  473. function isMobile()
  474. {
  475. // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
  476. if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
  477. {
  478. return true;
  479. }
  480. // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
  481. if (isset ($_SERVER['HTTP_VIA']))
  482. {
  483. // 找不到为false,否则为true
  484. return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
  485. }
  486. // 脑残法,判断手机发送的客户端标志,兼容性有待提高
  487. if (isset ($_SERVER['HTTP_USER_AGENT']))
  488. {
  489. $clientkeywords = array ('nokia',
  490. 'sony',
  491. 'ericsson',
  492. 'mot',
  493. 'samsung',
  494. 'htc',
  495. 'sgh',
  496. 'lg',
  497. 'sharp',
  498. 'sie-',
  499. 'philips',
  500. 'panasonic',
  501. 'alcatel',
  502. 'lenovo',
  503. 'iphone',
  504. 'ipod',
  505. 'blackberry',
  506. 'meizu',
  507. 'android',
  508. 'netfront',
  509. 'symbian',
  510. 'ucweb',
  511. 'windowsce',
  512. 'palm',
  513. 'operamini',
  514. 'operamobi',
  515. 'openwave',
  516. 'nexusone',
  517. 'cldc',
  518. 'midp',
  519. 'wap',
  520. 'mobile'
  521. );
  522. // 从HTTP_USER_AGENT中查找手机浏览器的关键字
  523. if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
  524. {
  525. return true;
  526. }
  527. }
  528. // 协议法,因为有可能不准确,放到最后判断
  529. if (isset ($_SERVER['HTTP_ACCEPT']))
  530. {
  531. // 如果只支持wml并且不支持html那一定是移动设备
  532. // 如果支持wml和html但是wml在html之前则是移动设备
  533. if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
  534. {
  535. return true;
  536. }
  537. }
  538. return false;
  539. }
  540. /**
  541. * post 提交
  542. * @param strint $url
  543. * @param array $post_data
  544. * @return mixed
  545. */
  546. function formPost($url, $post_data=array(), $timeout=60, $userpwd = null)
  547. {
  548. $ch = curl_init();
  549. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  550. curl_setopt($ch, CURLOPT_POST, 1);
  551. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  552. curl_setopt($ch, CURLOPT_HEADER, 0);
  553. curl_setopt($ch, CURLOPT_URL, $url);
  554. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // 设置超时限制防止死循环
  555. curl_setopt($ch, CURLOPT_POST, 1);
  556. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  557. // curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  558. if ($userpwd) {
  559. curl_setopt($ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC);
  560. curl_setopt($ch, CURLOPT_USERPWD , $userpwd);
  561. }
  562. $result = curl_exec($ch);
  563. if (curl_errno($ch)) {
  564. // echo curl_error($ch);exit;
  565. }
  566. curl_close($ch); // 关键CURL会话
  567. // CBase::write_log('formPost' . date("Ymd") . ".log", $result);
  568. return $result;
  569. }
  570. /**
  571. *
  572. * @param string $textareaid 编辑器ID
  573. * @param unknown $getParam 上传参数
  574. * @param unknown $options 编辑器自带参数,直接以php数组的形式传入即可,但不支持对象类型(eg.Function)
  575. * @return string
  576. */
  577. function editor($textareaid = 'content', $getParam = array(), $options = array()) {
  578. $getParam['_token'] = csrf_token();
  579. $getParam['elementid'] = isset($getParam['elementid'])?$getParam['elementid']:'elementid';
  580. $getParam['KindEditor'] = isset($getParam['KindEditor'])?$getParam['KindEditor']:true;
  581. $getParam['field'] = isset($getParam['field'])?$getParam['field']:'imgFile';
  582. $uploadUrl = U('Base/Attachment/upload', $getParam);
  583. if(isset($options['allowFileManager']) && $options['allowFileManager'] == true){
  584. echo "暂时不支持该功能!【allowFileManager】";exit;
  585. }
  586. //是否开启过滤模式
  587. //$options['filterMode'] = false;
  588. $options['urlType'] = 'domain';
  589. $options['uploadJson'] = isset($options['uploadJson'])?$options['uploadJson']:$uploadUrl;
  590. $options = json_encode($options);
  591. //SESSION_ID
  592. $session_id = session()->getId();
  593. $_csrf_token = csrf_token();
  594. $editer = <<<HTML
  595. <link rel="stylesheet" href="/base/kindeditor-4.1.10/themes/default/default.css" />
  596. <script charset="utf-8" src="/base/kindeditor-4.1.10/kindeditor-min.js"></script>
  597. <script charset="utf-8" src="/base/kindeditor-4.1.10/lang/zh_CN.js"></script>
  598. <script>
  599. var editor_{$textareaid};
  600. var options = '{$options}';
  601. options = eval('('+ options +')');
  602. options.extraFileUploadParams = {
  603. PHPSESSID : "$session_id",
  604. _token : "$_csrf_token"
  605. };
  606. //是否开启过滤模式
  607. KindEditor.options.filterMode = false;
  608. KindEditor.ready(function(K) {
  609. editor_{$textareaid} = K.create('#{$textareaid}', options);
  610. });
  611. </script>
  612. HTML;
  613. return $editer;
  614. }
  615. function ueditor() {
  616. $editer = <<<HTML
  617. <!-- 配置文件 -->
  618. <script type="text/javascript" src="/base/neditor-1.5.3/neditor.config.js"></script>
  619. <!-- 编辑器源码文件 -->
  620. <script type="text/javascript" src="/base/neditor-1.5.3/neditor.all.js"></script>
  621. <!-- 实例化编辑器 -->
  622. <script type="text/javascript">
  623. var ue = UE.getEditor('container',{
  624. toolbars: [
  625. ["fullscreen","source","autotypeset","bold", "italic","underline","forecolor", "paragraph","fontfamily","fontsize","indent","justifyleft", "justifycenter","justifyright","justifyjustify","link","unlink","insertimage","insertcode"
  626. ]],
  627. autoHeightEnabled: true,
  628. autoFloatEnabled: true,
  629. initialFrameHeight:320
  630. });
  631. ue.ready(function(){
  632. ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');
  633. })
  634. </script>
  635. HTML;
  636. return $editer;
  637. }
  638. if( ! function_exists('widget'))
  639. {
  640. function widget($widgetName)
  641. {
  642. $widgetNameEx = explode('.', $widgetName);
  643. if( ! isset($widgetNameEx[1])) return false;
  644. $widgetClass = 'App\\Widget\\'.$widgetNameEx[0].'\\'.$widgetNameEx[1];
  645. if(app()->bound($widgetName)) return app()->make($widgetName);
  646. app()->singleton($widgetName, function() use ($widgetClass)
  647. {
  648. return new $widgetClass();
  649. });
  650. return app()->make($widgetName);
  651. }
  652. }
  653. //
  654. //if( ! function_exists('sendSms')) {
  655. // // return string 'success' 为成功
  656. // function sendSms($msg, $mobile){
  657. // $post_data = array();
  658. // $post_data['un'] ="N9304000";
  659. // $post_data['pw'] = "Mask751002@";
  660. // $post_data['msg']="【小洲蔬菜】$msg";
  661. // $post_data['phone'] =$mobile;
  662. // $post_data['rd']=1;
  663. //
  664. // $post_data['needstatus']='true';
  665. // $url='https://sms.253.com/msg/send';
  666. // $data=http_build_query($post_data);
  667. //
  668. // if(function_exists('curl_init')){
  669. // $curl = curl_init();
  670. // curl_setopt($curl, CURLOPT_URL, $url);
  671. //
  672. // if (!empty($data)){
  673. // curl_setopt($curl, CURLOPT_POST, 1);
  674. // curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  675. // }
  676. // curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  677. // $output = curl_exec($curl);
  678. // curl_close($curl);
  679. // $result=preg_split("/[,\r\n]/",$output);
  680. // if($result[1]==0){
  681. // $res = "success";
  682. // }else{
  683. // $res = "curl error:".$result[1];
  684. // }
  685. // }elseif(function_exists('file_get_contents')){
  686. // $output=file_get_contents($url.$data);
  687. // $result=preg_split("/[,\r\n]/",$output);
  688. // if($result[1]==0){
  689. // $res = "success";
  690. // }else{
  691. // $res = "error:".$result[1];
  692. // }
  693. // }else{
  694. // $res="error";
  695. // }
  696. // return $res;
  697. // }
  698. //}
  699. //
  700. //if( ! function_exists('sendMultiSms')) {
  701. // // 群发短信 $mobiles电话号码之间用英文逗号分割
  702. // // return string 'success' 为成功
  703. // function sendMultiSms($msg, $mobiles){
  704. // $post_data = array();
  705. // $post_data['un'] ="M3512322";
  706. // $post_data['pw'] = "N8ecbXn0A7dc18";
  707. // $post_data['msg']="【小洲蔬菜】$msg 回复TD退订";
  708. // $post_data['phone'] =$mobiles;
  709. // $post_data['rd']=1;
  710. //
  711. // $post_data['needstatus']='true';
  712. // $url='https://sms.253.com/msg/send';
  713. // $data=http_build_query($post_data);
  714. //
  715. // if(function_exists('curl_init')){
  716. // $curl = curl_init();
  717. // curl_setopt($curl, CURLOPT_URL, $url);
  718. //
  719. // if (!empty($data)){
  720. // curl_setopt($curl, CURLOPT_POST, 1);
  721. // curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  722. // }
  723. // curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  724. // $output = curl_exec($curl);
  725. // curl_close($curl);
  726. // $result=preg_split("/[,\r\n]/",$output);
  727. // if($result[1]==0){
  728. // $res = "success";
  729. // }else{
  730. // $res = "curl error:".$result[1];
  731. // }
  732. // }elseif(function_exists('file_get_contents')){
  733. // $output=file_get_contents($url.$data);
  734. // $result=preg_split("/[,\r\n]/",$output);
  735. // if($result[1]==0){
  736. // $res = "success";
  737. // }else{
  738. // $res = "error:".$result[1];
  739. // }
  740. // }else{
  741. // $res="error";
  742. // }
  743. // return $res;
  744. // }
  745. //}
  746. //
  747. //
  748. //if( ! function_exists('sendCaixin')) {
  749. // //return true or false
  750. // function sendCaixin($mobile){
  751. //
  752. // $post_data =$data =$msgdata = array();
  753. //
  754. // $url ="http://www.baidu.com";//回调URL
  755. // $key ="6MG5jNK4Q15907";//密码
  756. ////文字body
  757. // $data['frame']="1"; //文字标识
  758. // $data['part'] ="1";//文字标识
  759. // $data['type']="1" ;
  760. // $data['content']=base64_encode('亲爱的朋友,“芜湖小洲蔬菜”,芜湖人的掌上菜篮子,已是我每天买菜必备工具。好东西首先想到了您,赶快关注使用吧!');
  761. //
  762. ////图片body
  763. // $msgdata['frame']="1";
  764. // $msgdata['part'] ="2";//图片标识
  765. // $msgdata['type']="2" ;//图片标识
  766. // $msgdata['content']=base64_encode(file_get_contents(public_path('app/wap/images/')."qrcode.jpg"));//图片
  767. //
  768. // $post_data['account'] ="C8636841";//账号
  769. // $post_data['ext_id']="72175534217316595927";//自传参数
  770. // $post_data['msg']=json_encode(array($data,$msgdata)) ;//json
  771. // $post_data['phones'] = $mobile;//手机
  772. // $post_data['timestamp'] = time();//时间戳
  773. //
  774. // $post_data['title']= '芜湖小洲蔬菜'; //标题
  775. //
  776. // $sign ='account=' . $post_data['account'].'ext_id=' . $post_data['ext_id'].'msg=' . $post_data['msg'].'phones=' . $post_data['phones'].'timestamp=' . $post_data['timestamp'].'title=' . $post_data['title'].'url=' . $url.'key=' . $key;
  777. // $sign=md5($sign); //加密
  778. // $post_data['sign']=$sign;
  779. // $post_data['url']=$url;
  780. //
  781. // $url='http://caixin.253.com/api/send?';
  782. // $data = http_build_query($post_data);
  783. //
  784. // if(function_exists('curl_init')){
  785. // $curl = curl_init();
  786. // curl_setopt($curl, CURLOPT_URL, $url);
  787. //
  788. // if (!empty($data)){
  789. // curl_setopt($curl, CURLOPT_POST, 1);
  790. // curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  791. // }
  792. // curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  793. // $output = curl_exec($curl);
  794. // curl_close($curl);
  795. // $res = json_decode($output);
  796. // if(is_array($res)&&$res['code']==1){
  797. // return true;
  798. // }
  799. //
  800. // }
  801. // return false;
  802. // }
  803. //}