functions.inc.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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. if ($user['is_root']) {
  213. return true;
  214. }
  215. $route = trim($route);
  216. $roles = $role['role'];
  217. if(isset($roles[$route])){
  218. return true;
  219. }else{
  220. return false;
  221. }
  222. }
  223. }
  224. if( ! function_exists('dict'))
  225. {
  226. function dict()
  227. {
  228. return new App\Services\Base\Dictionary;
  229. }
  230. }
  231. /**
  232. * 隐藏部分手机号码
  233. * @param $mobile
  234. * @param $hide_length
  235. * @return string
  236. */
  237. if( ! function_exists('hidePartMobile'))
  238. {
  239. function hidePartMobile($mobile, $hide_length = 5){
  240. $hide_length = intval($hide_length);
  241. $hide = '';
  242. for($i = 0; $i < $hide_length; $i++){
  243. $hide .= '*';
  244. }
  245. $pattern = "/(1\d{1,2})([0-9]{". $hide_length .",". $hide_length ."})(\d+)/";
  246. $replacement = "\$1{$hide}\$3";
  247. return preg_replace($pattern, $replacement, $mobile);
  248. }
  249. }
  250. /**
  251. * Function echo_log
  252. * 输出调试日志
  253. * @param $content 输出内容
  254. */
  255. if( ! function_exists('echoLog'))
  256. {
  257. function echoLog($content, $filename = '')
  258. {
  259. if(is_object($content) || is_array($content)) {
  260. $content = var_export($content, true);
  261. }
  262. $log_path = storage_path() . DIRECTORY_SEPARATOR . "debug_log" . DIRECTORY_SEPARATOR;
  263. if($filename){
  264. $file_path = $log_path . $filename;
  265. }else{
  266. $file_path = $log_path . "debug_log_" . date("Ymd") . ".txt";
  267. }
  268. if(!file_exists($log_path)){
  269. mkdir($log_path,0777);
  270. }
  271. $fp = fopen($file_path, "a");
  272. flock($fp, LOCK_EX) ;
  273. fwrite($fp,"执行日期:".date("Y-m-d H:i:s",time())."\n".$content."\n\n");
  274. flock($fp, LOCK_UN);
  275. fclose($fp);
  276. }
  277. }
  278. if( ! function_exists('curlAjax'))
  279. {
  280. function curlAjax($url) {
  281. $cookieStr = '';
  282. if($_COOKIE) {
  283. foreach ($_COOKIE as $key=>$val) {
  284. $cookieStr .= $key . '=' . $val . ';';
  285. }
  286. $cookieStr = substr($cookieStr, 0,-1);
  287. }
  288. $headers = array(
  289. 'Content-Type' => 'text/json;charset=utf-8', // 设置为Ajax方式
  290. 'X-Requested-With' => 'XMLHttpRequest', // 设置为Ajax方式
  291. '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方式
  292. 'Referer' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
  293. 'Cookie' => $cookieStr
  294. );
  295. $headerArr = array();
  296. foreach( $headers as $n => $v ) {
  297. $headerArr[] = $n .':' . $v;
  298. }
  299. $ch = curl_init($url);
  300. curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
  301. curl_setopt($ch, CURLOPT_HEADER, 0);
  302. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  303. $return = curl_exec($ch);
  304. curl_close ( $ch );
  305. return $return;
  306. }
  307. }
  308. if( ! function_exists('img'))
  309. {
  310. function img($system, $system_primary = NULL, $system_key = NULL, $first = false, $pagesize = PAGE_MAX_NUMS)
  311. {
  312. $paramArgs = func_get_args();
  313. $key = "system_img" . md5(serialize($paramArgs));
  314. if(!Cache::has($key) || request('no_cache') === 'true') {
  315. $data = \App\Services\Base\Images::getSrc($system, $system_primary, $system_key, $first, $pagesize);
  316. \Cache::forever($key,$data);
  317. }
  318. $data = \Cache::get($key);
  319. return $data;
  320. }
  321. }
  322. /**
  323. * 字符截取 支持UTF8/GBK
  324. * @param $string
  325. * @param $length
  326. * @param $dot
  327. */
  328. if( ! function_exists('str_cut'))
  329. {
  330. function str_cut($string, $length, $dot = '...') {
  331. $strlen = strlen($string);
  332. if($strlen <= $length) return $string;
  333. $string = str_replace(array(' ','&nbsp;', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), array('∵',' ', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), $string);
  334. $strcut = '';
  335. if(strtolower('utf-8') == 'utf-8') {
  336. $length = intval($length-strlen($dot)-$length/3);
  337. $n = $tn = $noc = 0;
  338. while($n < strlen($string)) {
  339. $t = ord($string[$n]);
  340. if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
  341. $tn = 1; $n++; $noc++;
  342. } elseif(194 <= $t && $t <= 223) {
  343. $tn = 2; $n += 2; $noc += 2;
  344. } elseif(224 <= $t && $t <= 239) {
  345. $tn = 3; $n += 3; $noc += 2;
  346. } elseif(240 <= $t && $t <= 247) {
  347. $tn = 4; $n += 4; $noc += 2;
  348. } elseif(248 <= $t && $t <= 251) {
  349. $tn = 5; $n += 5; $noc += 2;
  350. } elseif($t == 252 || $t == 253) {
  351. $tn = 6; $n += 6; $noc += 2;
  352. } else {
  353. $n++;
  354. }
  355. if($noc >= $length) {
  356. break;
  357. }
  358. }
  359. if($noc > $length) {
  360. $n -= $tn;
  361. }
  362. $strcut = substr($string, 0, $n);
  363. $strcut = str_replace(array('∵', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), array(' ', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), $strcut);
  364. } else {
  365. $dotlen = strlen($dot);
  366. $maxi = $length - $dotlen - 1;
  367. $current_str = '';
  368. $search_arr = array('&',' ', '"', "'", '“', '”', '—', '<', '>', '·', '…','∵');
  369. $replace_arr = array('&amp;','&nbsp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;',' ');
  370. $search_flip = array_flip($search_arr);
  371. for ($i = 0; $i < $maxi; $i++) {
  372. $current_str = ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
  373. if (in_array($current_str, $search_arr)) {
  374. $key = $search_flip[$current_str];
  375. $current_str = str_replace($search_arr[$key], $replace_arr[$key], $current_str);
  376. }
  377. $strcut .= $current_str;
  378. }
  379. }
  380. return $strcut.$dot;
  381. }
  382. }
  383. /**
  384. * 取得文件扩展
  385. *
  386. * @param $filename 文件名
  387. * @return 扩展名
  388. */
  389. if( ! function_exists('fileExt'))
  390. {
  391. function fileExt($filename)
  392. {
  393. return strtolower(trim(substr(strrchr($filename, '.'), 1, 10)));
  394. }
  395. }
  396. /**
  397. * 过滤参数
  398. *
  399. * @param $param 参数数组
  400. * @param $allowKey 被允许的KEY集合数组
  401. * @return 扩展名
  402. */
  403. if( ! function_exists('filterParam'))
  404. {
  405. function filterParam(array $param, array $allowKey)
  406. {
  407. $data = array();
  408. foreach ($param AS $key => $val) {
  409. if(in_array($key, $allowKey)) $data[$key] = $val;
  410. }
  411. return $data;
  412. }
  413. }
  414. if(!function_exists('list_to_tree')) {
  415. function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0)
  416. {
  417. // 创建Tree
  418. $tree = array();
  419. if(is_array($list)) {
  420. // 创建基于主键的数组引用
  421. $refer = array();
  422. foreach ($list as $key => $data) {
  423. $refer[$data[$pk]] =& $list[$key];
  424. }
  425. foreach ($list as $key => $data) {
  426. // 判断是否存在parent
  427. $parentId = $data[$pid];
  428. if ($root == $parentId) {
  429. $tree[] =& $list[$key];
  430. }else{
  431. if (isset($refer[$parentId])) {
  432. $parent =& $refer[$parentId];
  433. $parent[$child][] =& $list[$key];
  434. }
  435. }
  436. }
  437. }
  438. return $tree;
  439. }
  440. }
  441. /**
  442. * 判断远程文件是否存在
  443. * @param unknown $url
  444. * @return boolean
  445. */
  446. function check_remote_file_exists($url)
  447. {
  448. $curl = curl_init($url);
  449. curl_setopt($curl, CURLOPT_NOBODY, true);
  450. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
  451. $result = curl_exec($curl);
  452. $found = false;
  453. if ($result !== false)
  454. {
  455. $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  456. if ($statusCode == 200)
  457. {
  458. $found = true;
  459. }
  460. }
  461. curl_close($curl);
  462. return $found;
  463. }
  464. if( ! function_exists('getCacheKey')) {
  465. /**
  466. * 更具参数获取一个唯一的缓存KEY
  467. * @param string $name 名称
  468. * @param obj|array|string $data 参数
  469. */
  470. function getCacheKey($name,$data) {
  471. return $name . md5(serialize($data));
  472. }
  473. }
  474. function isMobile()
  475. {
  476. // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
  477. if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
  478. {
  479. return true;
  480. }
  481. // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
  482. if (isset ($_SERVER['HTTP_VIA']))
  483. {
  484. // 找不到为false,否则为true
  485. return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
  486. }
  487. // 脑残法,判断手机发送的客户端标志,兼容性有待提高
  488. if (isset ($_SERVER['HTTP_USER_AGENT']))
  489. {
  490. $clientkeywords = array ('nokia',
  491. 'sony',
  492. 'ericsson',
  493. 'mot',
  494. 'samsung',
  495. 'htc',
  496. 'sgh',
  497. 'lg',
  498. 'sharp',
  499. 'sie-',
  500. 'philips',
  501. 'panasonic',
  502. 'alcatel',
  503. 'lenovo',
  504. 'iphone',
  505. 'ipod',
  506. 'blackberry',
  507. 'meizu',
  508. 'android',
  509. 'netfront',
  510. 'symbian',
  511. 'ucweb',
  512. 'windowsce',
  513. 'palm',
  514. 'operamini',
  515. 'operamobi',
  516. 'openwave',
  517. 'nexusone',
  518. 'cldc',
  519. 'midp',
  520. 'wap',
  521. 'mobile'
  522. );
  523. // 从HTTP_USER_AGENT中查找手机浏览器的关键字
  524. if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
  525. {
  526. return true;
  527. }
  528. }
  529. // 协议法,因为有可能不准确,放到最后判断
  530. if (isset ($_SERVER['HTTP_ACCEPT']))
  531. {
  532. // 如果只支持wml并且不支持html那一定是移动设备
  533. // 如果支持wml和html但是wml在html之前则是移动设备
  534. 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'))))
  535. {
  536. return true;
  537. }
  538. }
  539. return false;
  540. }
  541. /**
  542. * post 提交
  543. * @param strint $url
  544. * @param array $post_data
  545. * @return mixed
  546. */
  547. function formPost($url, $post_data=array(), $timeout=60, $userpwd = null)
  548. {
  549. $ch = curl_init();
  550. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  551. curl_setopt($ch, CURLOPT_POST, 1);
  552. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  553. curl_setopt($ch, CURLOPT_HEADER, 0);
  554. curl_setopt($ch, CURLOPT_URL, $url);
  555. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // 设置超时限制防止死循环
  556. curl_setopt($ch, CURLOPT_POST, 1);
  557. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  558. // curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  559. if ($userpwd) {
  560. curl_setopt($ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC);
  561. curl_setopt($ch, CURLOPT_USERPWD , $userpwd);
  562. }
  563. $result = curl_exec($ch);
  564. if (curl_errno($ch)) {
  565. // echo curl_error($ch);exit;
  566. }
  567. curl_close($ch); // 关键CURL会话
  568. // CBase::write_log('formPost' . date("Ymd") . ".log", $result);
  569. return $result;
  570. }
  571. /**
  572. *
  573. * @param string $textareaid 编辑器ID
  574. * @param unknown $getParam 上传参数
  575. * @param unknown $options 编辑器自带参数,直接以php数组的形式传入即可,但不支持对象类型(eg.Function)
  576. * @return string
  577. */
  578. function editor($textareaid = 'content', $getParam = array(), $options = array()) {
  579. $getParam['_token'] = csrf_token();
  580. $getParam['elementid'] = isset($getParam['elementid'])?$getParam['elementid']:'elementid';
  581. $getParam['KindEditor'] = isset($getParam['KindEditor'])?$getParam['KindEditor']:true;
  582. $getParam['field'] = isset($getParam['field'])?$getParam['field']:'imgFile';
  583. $uploadUrl = U('Base/Attachment/upload', $getParam);
  584. if(isset($options['allowFileManager']) && $options['allowFileManager'] == true){
  585. echo "暂时不支持该功能!【allowFileManager】";exit;
  586. }
  587. //是否开启过滤模式
  588. //$options['filterMode'] = false;
  589. $options['urlType'] = 'domain';
  590. $options['uploadJson'] = isset($options['uploadJson'])?$options['uploadJson']:$uploadUrl;
  591. $options = json_encode($options);
  592. //SESSION_ID
  593. $session_id = session()->getId();
  594. $_csrf_token = csrf_token();
  595. $editer = <<<HTML
  596. <link rel="stylesheet" href="/base/kindeditor-4.1.10/themes/default/default.css" />
  597. <script charset="utf-8" src="/base/kindeditor-4.1.10/kindeditor-min.js"></script>
  598. <script charset="utf-8" src="/base/kindeditor-4.1.10/lang/zh_CN.js"></script>
  599. <script>
  600. var editor_{$textareaid};
  601. var options = '{$options}';
  602. options = eval('('+ options +')');
  603. options.extraFileUploadParams = {
  604. PHPSESSID : "$session_id",
  605. _token : "$_csrf_token"
  606. };
  607. //是否开启过滤模式
  608. KindEditor.options.filterMode = false;
  609. KindEditor.ready(function(K) {
  610. editor_{$textareaid} = K.create('#{$textareaid}', options);
  611. });
  612. </script>
  613. HTML;
  614. return $editer;
  615. }
  616. function ueditor() {
  617. $editer = <<<HTML
  618. <!-- 配置文件 -->
  619. <script type="text/javascript" src="/base/neditor-1.5.3/neditor.config.js"></script>
  620. <!-- 编辑器源码文件 -->
  621. <script type="text/javascript" src="/base/neditor-1.5.3/neditor.all.js"></script>
  622. <!-- 实例化编辑器 -->
  623. <script type="text/javascript">
  624. var ue = UE.getEditor('container',{
  625. toolbars: [
  626. ["fullscreen","source","autotypeset","bold", "italic","underline","forecolor", "paragraph","fontfamily","fontsize","indent","justifyleft", "justifycenter","justifyright","justifyjustify","link","unlink","insertimage","insertcode"
  627. ]],
  628. autoHeightEnabled: true,
  629. autoFloatEnabled: true,
  630. initialFrameHeight:320
  631. });
  632. ue.ready(function(){
  633. ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');
  634. })
  635. </script>
  636. HTML;
  637. return $editer;
  638. }
  639. if( ! function_exists('widget'))
  640. {
  641. function widget($widgetName)
  642. {
  643. $widgetNameEx = explode('.', $widgetName);
  644. if( ! isset($widgetNameEx[1])) return false;
  645. $widgetClass = 'App\\Widget\\'.$widgetNameEx[0].'\\'.$widgetNameEx[1];
  646. if(app()->bound($widgetName)) return app()->make($widgetName);
  647. app()->singleton($widgetName, function() use ($widgetClass)
  648. {
  649. return new $widgetClass();
  650. });
  651. return app()->make($widgetName);
  652. }
  653. }
  654. //
  655. //if( ! function_exists('sendSms')) {
  656. // // return string 'success' 为成功
  657. // function sendSms($msg, $mobile){
  658. // $post_data = array();
  659. // $post_data['un'] ="N9304000";
  660. // $post_data['pw'] = "Mask751002@";
  661. // $post_data['msg']="【小洲蔬菜】$msg";
  662. // $post_data['phone'] =$mobile;
  663. // $post_data['rd']=1;
  664. //
  665. // $post_data['needstatus']='true';
  666. // $url='https://sms.253.com/msg/send';
  667. // $data=http_build_query($post_data);
  668. //
  669. // if(function_exists('curl_init')){
  670. // $curl = curl_init();
  671. // curl_setopt($curl, CURLOPT_URL, $url);
  672. //
  673. // if (!empty($data)){
  674. // curl_setopt($curl, CURLOPT_POST, 1);
  675. // curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  676. // }
  677. // curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  678. // $output = curl_exec($curl);
  679. // curl_close($curl);
  680. // $result=preg_split("/[,\r\n]/",$output);
  681. // if($result[1]==0){
  682. // $res = "success";
  683. // }else{
  684. // $res = "curl error:".$result[1];
  685. // }
  686. // }elseif(function_exists('file_get_contents')){
  687. // $output=file_get_contents($url.$data);
  688. // $result=preg_split("/[,\r\n]/",$output);
  689. // if($result[1]==0){
  690. // $res = "success";
  691. // }else{
  692. // $res = "error:".$result[1];
  693. // }
  694. // }else{
  695. // $res="error";
  696. // }
  697. // return $res;
  698. // }
  699. //}
  700. //
  701. //if( ! function_exists('sendMultiSms')) {
  702. // // 群发短信 $mobiles电话号码之间用英文逗号分割
  703. // // return string 'success' 为成功
  704. // function sendMultiSms($msg, $mobiles){
  705. // $post_data = array();
  706. // $post_data['un'] ="M3512322";
  707. // $post_data['pw'] = "N8ecbXn0A7dc18";
  708. // $post_data['msg']="【小洲蔬菜】$msg 回复TD退订";
  709. // $post_data['phone'] =$mobiles;
  710. // $post_data['rd']=1;
  711. //
  712. // $post_data['needstatus']='true';
  713. // $url='https://sms.253.com/msg/send';
  714. // $data=http_build_query($post_data);
  715. //
  716. // if(function_exists('curl_init')){
  717. // $curl = curl_init();
  718. // curl_setopt($curl, CURLOPT_URL, $url);
  719. //
  720. // if (!empty($data)){
  721. // curl_setopt($curl, CURLOPT_POST, 1);
  722. // curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  723. // }
  724. // curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  725. // $output = curl_exec($curl);
  726. // curl_close($curl);
  727. // $result=preg_split("/[,\r\n]/",$output);
  728. // if($result[1]==0){
  729. // $res = "success";
  730. // }else{
  731. // $res = "curl error:".$result[1];
  732. // }
  733. // }elseif(function_exists('file_get_contents')){
  734. // $output=file_get_contents($url.$data);
  735. // $result=preg_split("/[,\r\n]/",$output);
  736. // if($result[1]==0){
  737. // $res = "success";
  738. // }else{
  739. // $res = "error:".$result[1];
  740. // }
  741. // }else{
  742. // $res="error";
  743. // }
  744. // return $res;
  745. // }
  746. //}
  747. //
  748. //
  749. //if( ! function_exists('sendCaixin')) {
  750. // //return true or false
  751. // function sendCaixin($mobile){
  752. //
  753. // $post_data =$data =$msgdata = array();
  754. //
  755. // $url ="http://www.baidu.com";//回调URL
  756. // $key ="6MG5jNK4Q15907";//密码
  757. ////文字body
  758. // $data['frame']="1"; //文字标识
  759. // $data['part'] ="1";//文字标识
  760. // $data['type']="1" ;
  761. // $data['content']=base64_encode('亲爱的朋友,“芜湖小洲蔬菜”,芜湖人的掌上菜篮子,已是我每天买菜必备工具。好东西首先想到了您,赶快关注使用吧!');
  762. //
  763. ////图片body
  764. // $msgdata['frame']="1";
  765. // $msgdata['part'] ="2";//图片标识
  766. // $msgdata['type']="2" ;//图片标识
  767. // $msgdata['content']=base64_encode(file_get_contents(public_path('app/wap/images/')."qrcode.jpg"));//图片
  768. //
  769. // $post_data['account'] ="C8636841";//账号
  770. // $post_data['ext_id']="72175534217316595927";//自传参数
  771. // $post_data['msg']=json_encode(array($data,$msgdata)) ;//json
  772. // $post_data['phones'] = $mobile;//手机
  773. // $post_data['timestamp'] = time();//时间戳
  774. //
  775. // $post_data['title']= '芜湖小洲蔬菜'; //标题
  776. //
  777. // $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;
  778. // $sign=md5($sign); //加密
  779. // $post_data['sign']=$sign;
  780. // $post_data['url']=$url;
  781. //
  782. // $url='http://caixin.253.com/api/send?';
  783. // $data = http_build_query($post_data);
  784. //
  785. // if(function_exists('curl_init')){
  786. // $curl = curl_init();
  787. // curl_setopt($curl, CURLOPT_URL, $url);
  788. //
  789. // if (!empty($data)){
  790. // curl_setopt($curl, CURLOPT_POST, 1);
  791. // curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  792. // }
  793. // curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  794. // $output = curl_exec($curl);
  795. // curl_close($curl);
  796. // $res = json_decode($output);
  797. // if(is_array($res)&&$res['code']==1){
  798. // return true;
  799. // }
  800. //
  801. // }
  802. // return false;
  803. // }
  804. //}