| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716 |
- <?php
- /**
- * Created by PhpStorm.
- * User: ywl
- * Date: 2020/2/26
- * Time: 下午4:48
- */
- /**
- * 强转UTF-8
- * @param $str
- * @return mixed|string
- */
- function mbEncodingUtf8($str)
- {
- if (isUTF8($str))
- return $str;
- else {
- return mb_convert_encoding($str, 'UTF-8', 'ascii,GB2312,UTF-8,gbk');
- }
- }
- /**
- * http请求
- * @param $method
- * @param $url
- * @param array $params
- * @param array $headers
- * @param int $timeout
- * @return string
- * @throws \App\Exceptions\ApiException
- */
- function httpClient($method, $url, $params = [], $headers = [], $timeout = 0)
- {
- $curl = new \Curl\Curl();
- $curl->setOpt(CURLOPT_FOLLOWLOCATION, 5);
- $curl->setUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36');
- //https 不验证ssl证书
- $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
- if ($timeout > 0) {
- $curl->setOpt(CURLOPT_TIMEOUT, $timeout);
- }
- if (is_array($headers) && !empty($headers)) {
- foreach ($headers as $key => $value) {
- $curl->setHeader($key, $value);
- }
- }
- $method = strtolower($method);
- $curl->$method($url, $params);
- $code = $curl->http_status_code;
- $response = $curl->response;
- $curl->close();
- if ($code != 200) {
- throw new \App\Exceptions\ApiException($curl->error_code);
- }
- return $response;
- }
- /**
- * 对象重组
- */
- function mapByKey(array $map, $key)
- {
- $data = [];
- foreach ($map as $item) {
- if (is_array($item)) {
- $data[$item[$key]] = $item;
- } else if (is_object($item)) {
- $data[$item->$key] = (array)$item;
- }
- }
- return $data;
- }
- /**
- * 当前时间
- * @param bool|int $ts
- * @return string
- */
- function nowTime($ts = false)
- {
- return $ts ? date('Y-m-d H:i:s', $ts) : date('Y-m-d H:i:s');
- }
- /**
- * 验证email格式
- * @param $email
- * @return bool
- */
- function validEmail($email)
- {
- $email = trim($email);
- $pattern = "/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/";
- if (preg_match($pattern, $email)) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * 加密解密函数
- * @param $string
- * @param string $operation
- * @param string $key
- * @param int $expiry
- * @return bool|string
- */
- function authCode($string, $operation = 'DECODE', $key = '', $expiry = 0)
- {
- $ckey_length = 4;
- $key = md5($key ? $key : 'share.matchpages.com');
- $keya = md5(substr($key, 0, 16));
- $keyb = md5(substr($key, 16, 16));
- $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
- $cryptkey = $keya . md5($keya . $keyc);
- $key_length = strlen($cryptkey);
- $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
- $string_length = strlen($string);
- $result = '';
- $box = range(0, 255);
- $rndkey = array();
- for ($i = 0; $i <= 255; $i++) {
- $rndkey[$i] = ord($cryptkey[$i % $key_length]);
- }
- for ($j = $i = 0; $i < 256; $i++) {
- $j = ($j + $box[$i] + $rndkey[$i]) % 256;
- $tmp = $box[$i];
- $box[$i] = $box[$j];
- $box[$j] = $tmp;
- }
- for ($a = $j = $i = 0; $i < $string_length; $i++) {
- $a = ($a + 1) % 256;
- $j = ($j + $box[$a]) % 256;
- $tmp = $box[$a];
- $box[$a] = $box[$j];
- $box[$j] = $tmp;
- $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
- }
- if ($operation == 'DECODE') {
- if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
- return substr($result, 26);
- } else {
- return '';
- }
- } else {
- return $keyc . str_replace('=', '', base64_encode($result));
- }
- }
- /**
- * html转为text
- * @param $str
- * @param int $formatText
- * @return mixed
- */
- function html2text($str, $formatText = 1)
- {
- $str = preg_replace("/<style .*?<\\/style>/is", "", $str);
- $str = preg_replace("/<script .*?<\\/script>/is", "", $str);
- $str = preg_replace("/<br \\s*\\/>/i", $formatText ? ">>>>" : "", $str);
- $str = preg_replace("/<\\/?p>/i", $formatText ? ">>>>" : "", $str);
- $str = preg_replace("/<\\/?td>/i", "", $str);
- $str = preg_replace("/<\\/?div>/i", $formatText ? ">>>>" : "", $str);
- $str = preg_replace("/<\\/?blockquote>/i", "", $str);
- $str = preg_replace("/<\\/?li>/i", $formatText ? ">>>>" : "", $str);
- $str = preg_replace("/ /i", " ", $str);
- $str = preg_replace("/ /i", " ", $str);
- $str = preg_replace("/&/i", "&", $str);
- $str = preg_replace("/&/i", "&", $str);
- $str = preg_replace("/</i", "<", $str);
- $str = preg_replace("/</i", "<", $str);
- $str = preg_replace("/“/i", '"', $str);
- $str = preg_replace("/&ldquo/i", '"', $str);
- $str = preg_replace("/‘/i", "'", $str);
- $str = preg_replace("/&lsquo/i", "'", $str);
- $str = preg_replace("/’/i", "'", $str);
- $str = preg_replace("/&rsquo/i", "'", $str);
- $str = preg_replace("/>/i", ">", $str);
- $str = preg_replace("/>/i", ">", $str);
- $str = preg_replace("/”/i", '"', $str);
- $str = preg_replace("/&rdquo/i", '"', $str);
- $str = strip_tags($str);
- $str = html_entity_decode($str, ENT_QUOTES, "utf-8");
- $str = preg_replace("/&#.*?;/i", "", $str);
- return $str;
- }
- /**
- * 去掉内容中的html代码
- */
- function strip($str)
- {
- $str = str_replace("<br>", "", $str);
- return strip_tags($str);
- }
- /**
- * 创建多级文件目录
- * @param $dir
- * @return bool
- */
- function mkDirs($dir)
- {
- if (!is_dir($dir)) {
- if (!mkdirs(dirname($dir))) {
- return false;
- }
- if (!mkdir($dir, 0777, true)) {
- return false;
- }
- }
- return true;
- }
- /**
- * 下载远程文件
- * @param $fileUrl
- * @param $saveTo
- * @param $fileContent
- */
- function downloadRemoteFile($fileUrl, $saveTo)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_POST, 0);
- curl_setopt($ch, CURLOPT_URL, $fileUrl);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 2);
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11");
- $fileContent = curl_exec($ch);
- curl_close($ch);
- $downloaded_file = fopen($saveTo, 'w');
- fwrite($downloaded_file, $fileContent);
- fclose($downloaded_file);
- }
- /**
- * 获取html的meta标签
- * @param $link
- * @return mixed
- */
- function getMetaOfLink($link)
- {
- if (!stristr($link, 'http')) {
- $link = 'http://' . $link;
- }
- $content = httpClient('get', $link);
- if (!$content) {
- $content = file_get_contents($link);
- }
- $encode = mb_detect_encoding($content, ['ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5']);
- $content = iconv($encode, 'utf-8', $content);
- $reg = "/<title>(.*?)<\/title>/s";
- preg_match($reg, $content, $arr);
- if ($arr[1]) $meta['title'] = $arr[1];
- preg_match_all("/<meta[^>]+name=\"([^\"]*)\"[^>]" . "+content=\"([^\"]*)\"[^>]*>/i", $content, $r, PREG_PATTERN_ORDER);
- for ($i = 0; $i < count($r[1]); $i++) {
- if (strtolower($r[1][$i]) == "keywords") $meta['keywords'] = $r[2][$i];
- if (strtolower($r[1][$i]) == "description") $meta['description'] = $r[2][$i];
- }
- return $meta;
- }
- /**
- * 是否为utf8编码
- * @param $str
- * @return bool
- */
- function isUTF8($str)
- {
- $encoding = mb_detect_encoding($str, 'GB2312,UTF-8');
- if ($encoding == 'UTF-8') {
- return true;
- } else {
- return false;
- }
- }
- //格式化url
- function completeUrl($url)
- {
- if ($url) {
- $url = trim($url);
- if ($url[strlen($url) - 1] == '/') {
- $url = substr($url, 0, strlen($url) - 1);
- }
- }
- return $url;
- }
- //去掉http、https以及www
- function parseUrl($url)
- {
- if ($url) {
- $url = trim($url);
- $reg = '/^((https|http)?:\/\/)/';
- $strs = preg_split($reg, $url);
- $url = $strs[count($strs) - 1];
- if (strpos($url, 'www.') === 0)
- $url = substr($url, 4);
- }
- return $url;
- }
- /**
- * 获取客户端IP地址
- * @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字
- * @param boolean $adv 是否进行高级模式获取(有可能被伪装)
- * @return mixed
- */
- function getClientIp($type = 0, $adv = false)
- {
- $type = $type ? 1 : 0;
- static $ip = NULL;
- if ($ip !== NULL) return $ip[$type];
- if ($adv) {
- if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
- $pos = array_search('unknown', $arr);
- if (false !== $pos) unset($arr[$pos]);
- $ip = trim($arr[0]);
- } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- } elseif (isset($_SERVER['REMOTE_ADDR'])) {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- } elseif (isset($_SERVER['REMOTE_ADDR'])) {
- $ip = $_SERVER['REMOTE_ADDR'];
- }
- // IP地址合法验证
- $long = sprintf("%u", ip2long($ip));
- $ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
- return $ip[$type];
- }
- /**
- * 其他时区时间转为北京时间 $timezone_time 时区时间,$timezone时区
- * @param $timezoneTime
- * @param $timezone
- * @param int $isDefault
- * @return false|string
- */
- function toTimezone($timezoneTime, $timezone, $isDefault = 0)
- {
- $beiJin = 8;
- if (!$isDefault) {
- $diffS = ($beiJin - $timezone) * 3600;//相差秒数
- } else {
- $diffS = ($timezone - $beiJin) * 3600;//相差秒数
- }
- $zoneTime = strtotime($timezoneTime);
- $time = date('Y-m-d H:i', $zoneTime + $diffS);
- return $time;
- }
- function toTimeAgo($time = '')
- {
- $currentDate = new DateTime();
- // 给定日期
- $givenDate = new DateTime($time);
- // 计算差值
- $interval = $currentDate->diff($givenDate);
- // 输出年、月、天
- $yearsAgo = $interval->y;
- $monthsAgo = $interval->m;
- $daysAgo = $interval->d;
- // 判断并返回信息
- if ($yearsAgo > 0) {
- return "Years ago {$yearsAgo}";
- } elseif ($monthsAgo > 0) {
- return "Months ago {$monthsAgo}";
- } elseif ($daysAgo > 0) {
- return "Days ago {$daysAgo}";
- } else {
- return "";
- }
- }
- /**
- * 时间显示格式
- * @param $theTime
- * @param int $isDay
- * @return false|string
- */
- function timeTran($theTime, $isDay = 0)
- {
- $nowTime = time();
- $showTime = $theTime;
- $dur = $nowTime - $showTime;
- if ($dur < 0) {
- return date('Y-m-d H:i:s', $theTime);
- } else {
- if ($dur < 60) {
- return $dur . '秒前';
- } else {
- if ($dur < 3600) {
- return floor($dur / 60) . '分钟前';
- } else {
- if ($dur < 86400) {
- return floor($dur / 3600) . '小时前';
- } else {
- if ($isDay) {
- return floor($dur / 86400) . '天前';
- } else {
- if ($dur < 86400 * 3) {//3天内
- return floor($dur / 86400) . '天前';
- } else {
- return date('Y-m-d H:i:s', $theTime);
- }
- }
- }
- }
- }
- }
- }
- /**
- * 根据数组某个字段排序
- * @param $array 待排序数组
- * @param $field 排序字段
- * @param bool $desc 是否降序
- */
- function sortArrByField(&$array, $field, $desc = false)
- {
- $fieldArr = array();
- foreach ($array as $k => $v) {
- $fieldArr[$k] = $v[$field];
- }
- $sort = $desc == false ? SORT_ASC : SORT_DESC;
- array_multisort($fieldArr, $sort, $array);
- }
- function MouthDataTimeArray($start_time, $end_time)
- {
- $start_date = new DateTime($start_time);
- $end_date = new DateTime($end_time);
- $start_date_year = $start_date->format('Y');
- $end_date_year = $end_date->format('Y');
- $start_date_m = $start_date->format('m');
- $end_date_m = $end_date->format('m');
- if ($start_date_year === $end_date_year && $start_date_m === $end_date_m) {
- return ($start_date->format('Y-m-d'));
- }
- if ($start_date_year === $end_date_year && $start_date_m !== $end_date_m) {
- return ($start_date->format('Y.m')) . '~' . ($end_date->format('m'));
- }
- if ($start_date_year !== $end_date_year) {
- return ($start_date->format('Y-m-d')) . '~' . ($end_date->format('Y-m-d'));
- }
- }
- //将查询字符中的特殊查询字符处理掉
- function formatQueryKey($key)
- {
- $key = str_replace('%', '\\%', $key);
- $key = str_replace('_', '\\_', $key);
- $key = str_replace("'", "\\'", $key);
- $key = str_replace('"', '\\"', $key);
- if (strstr($key, '[!')) {
- $key = str_replace('[!', '\\[\\!', $key);
- } elseif (strstr($key, '[^')) {
- $key = str_replace('[!', '\\[\\^', $key);
- } elseif (strstr($key, '[')) {
- $key = str_replace('[!', '\\[', $key);
- }
- return $key;
- }
- //图片转base64
- function base64EncodeImage($image_file)
- {
- $base64_image = '';
- $image_data = fread(fopen($image_file, 'r'), filesize($image_file));
- $base64_image = chunk_split(base64_encode($image_data));
- return $base64_image;
- }
- /*
- * 把数组转换成树
- */
- function listToTree($list, $root = 0, $pk = 'id', $pid = 'pid', $child = '_child')
- {
- // 创建Tree
- $tree = array();
- if (is_array($list)) {
- // 创建基于主键的数组引用
- $refer = array();
- foreach ($list as $key => $data) {
- $refer[$data[$pk]] = &$list[$key];
- }
- foreach ($list as $key => $data) {
- // 判断是否存在parent
- $parentId = 0;
- if (isset($data[$pid])) {
- $parentId = $data[$pid];
- }
- if ((string)$root == $parentId) {
- $tree[] = &$list[$key];
- } else {
- if (isset($refer[$parentId])) {
- $parent = &$refer[$parentId];
- $parent[$child][] = &$list[$key];
- } else {
- //如果找不到父项那么自己就是父项
- $tree[] =& $list[$key];
- }
- }
- }
- }
- return $tree;
- }
- /**
- * 过滤并返回整形数组
- * @param array $arr
- */
- function filterIntArray($arr)
- {
- if ($arr) {
- foreach ($arr as $k => $v) {
- $arr[$k] = (int)$v;
- if (!$arr[$k]) {
- unset($arr[$k]);
- }
- }
- }
- return $arr;
- }
- //合并查询结果数组(报表用)
- /**
- * @param $arr_master 主数组
- * @param $arr_attendants 要合并的从数组
- * @param multilist 是多表合并 默认fase
- * @param $key_field 作为判断合并的关键字段(必填)
- * @param $merge_fields 不要合并的字段(非必填)
- */
- function combineArray($arr_master, $arr_attendants = array(), $key_field, $merge_fields = array(), $multilist = false)
- {
- if (!empty($arr_attendants) && !empty($arr_master) && !empty($key_field)) {
- if ($multilist) {
- foreach ($arr_attendants as $value) {
- $arr_master = combineArray($arr_master, $value, $key_field, $merge_fields);
- }
- } else {
- if (is_array($arr_master)) {
- $arr_master = mapByKey($arr_master, $key_field);
- $arr_attendants = mapByKey($arr_attendants, $key_field);
- foreach ($arr_master as $key => $value) {
- if (isset($arr_attendants[$key])) {
- if ($merge_fields) {
- foreach ($merge_fields as $value) {
- unset($arr_attendants[$key][$value]);
- }
- }
- $arr_master[$key] = array_merge($arr_master[$key], $arr_attendants[$key]);
- }
- }
- }
- if (is_object($arr_master)) {
- $arr_attendants = mapByKey($arr_attendants, $key_field);
- foreach ($arr_master as &$value) {
- if (isset($arr_attendants[$value[$key_field]])) {
- if ($merge_fields) {
- foreach ($merge_fields as $value) {
- unset($arr_attendants[$value[$key_field]][$value]);
- }
- }
- foreach ($arr_attendants[$value[$key_field]] as $sub_key => $sub_val) {
- $value[$sub_key] = $sub_val;
- }
- }
- }
- }
- }
- }
- return $arr_master;
- }
- /**
- * 两个标量数组间的array_diff,数组值需为合法的键名
- * @param $b
- * @param $a
- * @return array
- */
- function flipArrayDiffKey($b, $a)
- {
- $at = array_flip($a);
- $bt = array_flip($b);
- $d = array_diff_key($bt, $at);
- return array_keys($d);
- }
- if (!function_exists('ftok')) {
- function ftok($filePath, $projectId)
- {
- $fileStats = stat($filePath);
- if (!$fileStats) {
- return -1;
- }
- return sprintf('%u',
- ($fileStats['ino'] & 0xffff) | (($fileStats['dev'] & 0xff) << 16) | ((ord($projectId) & 0xff) << 24)
- );
- }
- }
- /**
- * @param $request_uri
- * @return string
- */
- function currentUrl($request_uri)
- {
- if ($request_uri && strpos($request_uri, 'http') !== FALSE) {
- return $request_uri;
- }
- $protocol = 'http://';
- if (!empty($_SERVER['HTTPS']) || ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? 'http') === 'https') {
- $protocol = 'https://';
- }
- if (isset($_SERVER['HTTP_HOST'])) {
- $ret_url = $protocol . $_SERVER['HTTP_HOST'] . ($request_uri ?: $_SERVER['REQUEST_URI']);
- } else {
- $ret_url = 'https://api.kaihedh.com' . ($request_uri ?: $_SERVER['REQUEST_URI']);
- }
- return $ret_url;
- }
- /**
- * 使用方法赋值传递数组[key=>value] ,取值传key值即可
- * session
- * @param null $option
- * @param null $default
- * @return mixed
- */
- function session($option = null, $default = null)
- {
- $session = app('session');
- if (is_null($option)) {
- return $session;
- }
- if (is_array($option)) {
- return $session->put($option);
- }
- return $session->get($option, $default);
- }
- /**
- * 获取随机字符串
- * @param $prefix
- * @return string
- */
- function getRandomStr($prefix = 'WX')
- {
- $addHead = '';
- $addTail = '';
- $i = 0;
- while ($i < 3) {
- $addHead .= mt_rand(0, 9);
- $addTail .= mt_rand(0, 9);
- $i = $i + 1;
- }
- return $prefix . $addHead . time() . $addTail;
- }
- /**
- * 构造返回页面数据
- * @param $data //数据
- * @param $formNb //开始数量
- * @param $page //页数
- * @param $perPageSize //每页数量
- * @param $total //总数量
- * @return mixed
- */
- function buildPage($data = [], $formNb = 0, $page = 1, $perPageSize = 10, $total = 0)
- {
- $lastPage = ceil($total / $perPageSize);
- $toNb = $page * $perPageSize;
- if (empty($formNb)) {
- $formNb = $toNb - $perPageSize;
- }
- if ($toNb > $total) {
- $toNb = $total;
- }
- $resultDdata = array(
- 'current_page' => $page,
- 'data' => $data,
- 'from' => $formNb,
- 'last_page' => $lastPage,
- 'per_page' => $perPageSize,
- 'to' => $toNb,
- 'total' => $total,
- );
- return $resultDdata;
- }
- /**
- * php实现下载远程图片保存到本地
- **
- * $url 图片所在地址
- * $path 保存图片的路径
- * $filename 图片自定义命名
- * $type 使用什么方式下载
- * 0:curl方式,1:readfile方式,2file_get_contents方式
- *
- * return 文件名
- */
- function getFile($url, $path = '', $filename = '', $type = 0)
- {
- if ($url == '') {
- return false;
- }
- //获取远程文件数据
- if ($type === 0) {
- $ch = curl_init();
- $timeout = 5;
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);//最长执行时间
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);//最长等待时间
- $img = curl_exec($ch);
- curl_close($ch);
- }
- if ($type === 1) {
- ob_start();
- readfile($url);
- $img = ob_get_contents();
- ob_end_clean();
- }
- if ($type === 2) {
- $img = file_get_contents($url);
- }
- //判断下载的数据 是否为空 下载超时问题
- if (empty($img)) {
- throw new \Exception("下载错误,无法获取下载文件!");
- }
- //没有指定路径则默认当前路径
- if ($path === '') {
- $path = "./";
- }
- //如果命名为空
- if ($filename === "") {
- $filename = md5($img);
- }
- //获取后缀名
- $ext = substr($url, strrpos($url, '.'));
- if ($ext && strlen($ext) < 5) {
- $filename .= $ext;
- }
- //防止"/"没有添加
- $path = rtrim($path, "/") . "/";
- //var_dump($path.$filename);die();
- $fp2 = @fopen($path . $filename, 'a');
- fwrite($fp2, $img);
- fclose($fp2);
- //echo "finish";
- return $filename;
- }
- /**
- * 下载文件
- * @param $fileUrl 文件远程地址
- * @param $saveTo 保存地址
- */
- function downloadFile($fileUrl, $saveTo)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_POST, 0);
- curl_setopt($ch, CURLOPT_URL, $fileUrl);
- // curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:19180');
- // curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 2);
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11");
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
- 'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
- 'Connection: keep-alive'
- ));
- $fileContent = curl_exec($ch);
- curl_close($ch);
- $downloaded_file = fopen($saveTo, 'w');
- fwrite($downloaded_file, $fileContent);
- fclose($downloaded_file);
- }
- /**
- * 居中裁剪图片
- * @param string $source [原图路径]
- * @param int $width [设置宽度]
- * @param int $height [设置高度]
- * @param string $target [目标路径]
- * @return bool [裁剪结果]
- */
- function imageCenterCrop($source, $width, $height, $target)
- {
- //if (!file_exists($source)) return false;
- /* 根据类型载入图像 */
- switch (exif_imagetype($source)) {
- case IMAGETYPE_JPEG:
- $image = imagecreatefromjpeg($source);
- break;
- case IMAGETYPE_PNG:
- $image = imagecreatefrompng($source);
- break;
- case IMAGETYPE_GIF:
- $image = imagecreatefromgif($source);
- break;
- }
- if (!isset($image)) return false;
- /* 获取图像尺寸信息 */
- $target_w = $width;
- $target_h = $height;
- $source_w = imagesx($image);
- $source_h = imagesy($image);
- /* 计算裁剪宽度和高度 */
- $judge = (($source_w / $source_h) > ($target_w / $target_h));
- $resize_w = $judge ? ($source_w * $target_h) / $source_h : $target_w;
- $resize_h = !$judge ? ($source_h * $target_w) / $source_w : $target_h;
- $start_x = $judge ? ($resize_w - $target_w) / 2 : 0;
- $start_y = !$judge ? ($resize_h - $target_h) / 2 : 0;
- /* 绘制居中缩放图像 */
- $resize_img = imagecreatetruecolor($resize_w, $resize_h);
- imagecopyresampled($resize_img, $image, 0, 0, 0, 0, $resize_w, $resize_h, $source_w, $source_h);
- $target_img = imagecreatetruecolor($target_w, $target_h);
- imagecopy($target_img, $resize_img, 0, 0, $start_x, $start_y, $resize_w, $resize_h);
- /* 将图片保存至文件 */
- // if (!file_exists(dirname($target))) mkdir(dirname($target), 0777, true);
- switch (exif_imagetype($source)) {
- case IMAGETYPE_JPEG:
- imagejpeg($target_img, $target);
- break;
- case IMAGETYPE_PNG:
- imagepng($target_img, $target);
- break;
- case IMAGETYPE_GIF:
- imagegif($target_img, $target);
- break;
- }
- return boolval(file_exists($target));
- }
- //增加redis的连接判断,默认如果连接错误会抛出异常,这边捕获异常,下次会重新连接
- function checkRedisPing($config = null)
- {
- if ($config) {
- $redis = app('redis')->connection($config);
- } else {
- $redis = app('redis.connection');
- }
- try {
- $redis->ping();
- } catch (\Exception $e) {
- }
- }
- function returnAssetsPath()
- {
- return config('app.assets_path');
- }
- function getLanguagePath() {
- if (!empty(config('app.language_path')) && config('app.language_path')) {
- $language_path = config('app.language_path');
- return '/'.$language_path;
- }
- return '';
- }
- function getRouterPath($menu_data = [], $router = null): string
- {
- $language_path = getLanguagePath();
- if ($router) {
- if ($router === 'home') {
- return $language_path.'/';
- }
- if (empty($menu_data[$router . '.index'])) {
- return $language_path.'/' . $router;
- } else {
- return $language_path.'/' . $menu_data[$router . '.index'];
- }
- }
- return '/';
- }
- function getMenuRouterActive($list = null)
- {
- if ($list) {
- if (strpos($list, $_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] !== '/') {
- return 'menu_active';
- }
- }
- }
- function getRouterActive($menu_data = [], $router = null)
- {
- $language_path = getLanguagePath();
- if ($router) {
- if (!empty($menu_data[$router . '.index']) && (urldecode($_SERVER['REQUEST_URI']) === $language_path.'/' . $menu_data[$router . '.index'])) {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
- function getPageValue($page_content, $module_key, $page_key)
- {
- if (isset($page_content) && isset($page_content[$module_key]['module']) && isset($page_content[$module_key]['module'][$page_key])) {
- return $page_content[$module_key]['module'][$page_key]['value'];
- }
- return '';
- }
- function getPageItemHref($menu_data, $element_item, $tag_key)
- {
- $element = $element_item[$tag_key];
- $language_path = getLanguagePath();
- if (!empty($element['link_type']) && $element['link_type'] === '1') {
- if (!empty($element['href'])) {
- return $language_path.$element['href'];
- }
- } elseif (!empty($element['link_type']) && $element['link_type'] === '2') {
- return getRouterPath($menu_data, !empty($element['route']) ? $element['route'] : '');
- }
- return '';
- }
- function getElementClass($page_content, $module_key)
- {
- $result = '';
- if (isset($page_content) && isset($page_content[$module_key]) && !empty($page_content[$module_key]['class']) && count($page_content[$module_key]['class']) > 0) {
- foreach ($page_content[$module_key]['class'] as $item) {
- $result .= ' ' . $item;
- }
- }
- return $result;
- }
- function getElementData($page_content, $module_key, $page_key)
- {
- if (isset($page_content) && isset($page_content[$module_key]['module']) && isset($page_content[$module_key]['module'][$page_key])) {
- return $page_content[$module_key]['module'][$page_key];
- }
- return '';
- }
- function getPageContent($page_content, $module_key, $page_key, $type = '')
- {
- if (isset($page_content) && isset($page_content[$module_key]) && isset($page_content[$module_key]['module'][$page_key])) {
- if ($type === 'obj') {
- return $page_content[$module_key]['module'][$page_key];
- } else {
- return $page_content[$module_key]['module'][$page_key]['value'];
- }
- } else {
- return '';
- }
- }
- //适配旧项目方法
- function getPageData($page_content,$page_key) {
- if (!empty($page_content[$page_key])) {
- return $page_content[$page_key];
- } else {
- return '';
- }
- }
- //适配旧项目方法
- function getPageDataValue($page_content,$page_key) {
- if (!empty($page_content[$page_key]['value'])) {
- return $page_content[$page_key]['value'];
- } else {
- return '';
- }
- }
- function isShowElement($page_content, $module_key = '', $page_key = ''): bool
- {
- if (!empty($page_key)) {
- $data = getElementData($page_content, $module_key, $page_key);
- } else {
- $data = $page_content[$module_key] ?? [];
- $is_hide = false;
- }
- if (empty($data)) {
- return false;
- }
- if ((isset($data['is_hide']) && $data['is_hide'] === true) || (!isset($data['module']) && isset($data['value']) && empty($data['value']))) {
- $is_hide = true;
- } else {
- $is_hide = false;
- }
- return !$is_hide;
- }
- function isShowListItem($element_content, $page_key = ''): bool
- {
- $data = $element_content[$page_key];
- if (empty($data)) {
- return false;
- }
- if (isset($data['is_hide']) && $data['is_hide'] === true) {
- $is_hide = true;
- } else {
- $is_hide = false;
- }
- return !$is_hide;
- }
- function returnElementValue($menu_data, $page_content, $element_key,$tag_key): string {
- if (!empty($page_content[$element_key]['module'][$tag_key])) {
- $element = $page_content[$element_key]['module'][$tag_key];
- } else {
- return '';
- }
- if (!empty($element['value'])) {
- return $element['value'];
- } else {
- return '';
- }
- }
- function returnElementHref($menu_data, $page_content, $element_key,$tag_key): string {
- if (!empty($page_content[$element_key]['module'][$tag_key])) {
- $element = $page_content[$element_key]['module'][$tag_key];
- } else {
- return '';
- }
- if (!empty($element['href'])) {
- $href = $element['href'];
- } else {
- $href = '';
- }
- if (!empty($element['link_type']) && $element['link_type'] === '2') {
- return getRouterPath($menu_data, !empty($element['route']) ? $element['route'] : '');
- } else {
- return $href;
- }
- }
- function returnElement($menu_data, $content, $element_key, $tag, $class = '',$lazyType = true): string
- {
- if (!empty($content[$element_key])) {
- $element = $content[$element_key];
- } else {
- return '';
- }
- if (!empty($element['is_hide']) && $element['is_hide'] === true) {
- return '';
- }
- if (!empty($element['value'])) {
- $value = $element['value'];
- } else {
- $value = '';
- }
- if (isMediaUrl($value)) {
- $value = extractResourcePath($value);
- }
- if (!empty($element['href'])) {
- $href = $element['href'];
- } else {
- $href = '';
- }
- if (!empty($element['alt'])) {
- $alt = $element['alt'];
- } else {
- $alt = $element_key;
- }
- if (!empty($element['type'])) {
- $type = $element['type'];
- } else {
- $type = '0';
- }
- if ($type === '1') {
- if ($lazyType) {
- $html = '<img class="lazy-load" data-src="' . $value . '" alt="' . $alt . '" />';
- } else {
- $html = '<img src="' . $value . '" alt="' . $alt . '" />';
- }
- } elseif ($type === '4') {
- $html = '<video x5-playsinline="" playsinline="" webkit-playsinline="" src="' . $value . '" />';
- } else {
- $html = $value;
- }
- $element_key_str = '';
- if (!empty($element_key) && isEditWebsite()) {
- $element_key_str = ' data-key=' . $element_key . ' ';
- }
- $element_class_str = '';
- if (!empty($class)) {
- if (!empty($tag) && $tag === 'p') {
- $class .= ' module_desc';
- }
- $element_class_str = ' class="' . $class . '" ';
- } else {
- if (!empty($tag) && $tag === 'p') {
- $element_class_str = ' class="module_desc" ';
- }
- }
- if (!empty($tag) && $tag === 'p') {
- $tag = 'div';
- }
- $element_href = '';
- $link_type_str = '';
- if (!empty($element['link_type']) && $element['link_type'] === '1') {
- $element_href = ' href="' . $href . '" ';
- $link_type_str = 'target="_blank"';
- } elseif (!empty($element['link_type']) && $element['link_type'] === '2') {
- $element_href = ' href="' . getRouterPath($menu_data, !empty($element['route']) ? $element['route'] : '') . '" ';
- }
- if (!empty($element['link_type']) && ($element['link_type'] === '1' || $element['link_type'] === '2')) {
- $html = '<a ' . $element_class_str . $element_href . $link_type_str . $element_key_str . '>' . $html . '</a>';
- } else {
- if (!empty($tag)) {
- $html = '<' . $tag . $element_class_str . $element_href . $element_key_str . ' >' . $html . '</' . $tag . '>';
- }
- }
- return htmlspecialchars_decode($html);
- }
- function isMediaUrl($url)
- {
- $imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp','mp4','avi'];
- // 获取文件扩展名
- $extension = pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION);
- //不是本地 并且 检查扩展名是否在图片扩展名列表中
- return env('APP_NAME') !== 'website-dev' && in_array(strtolower($extension), $imageExtensions);
- }
- function extractResourcePath($url)
- {
- // 解析 URL
- /* $parsedUrl = parse_url($url);
- // 获取路径部分
- $path = $parsedUrl['path'];
- // 查找 "resources" 的位置
- $resourcesPos = strpos($path, '/resources/');
- // 如果找到了 "resources",提取其后面的部分
- if ($resourcesPos !== false) {
- if (env('WEB_URL')) {
- return env('WEB_URL') . '/resources/'.substr($path, $resourcesPos + strlen('/resources/'));
- } else {
- return '/resources/'.substr($path, $resourcesPos + strlen('/resources/'));
- }
- }*/
- return $url;
- }
- function createElement($menu_data, $data, $module_key, $key, $class, $type, $default_val, $tag_name = '',$lazyType=true)
- {
- if (empty($module_key)) {
- //适配旧项目方法
- $page_content = getPageData($data, $key);
- } else {
- $page_content = getPageContent($data, $module_key, $key, 'obj');
- if (!isShowElement($data, $module_key, $key)) {
- return '';
- }
- }
- if (!empty($page_content['value'])) {
- $value = $page_content['value'];
- } else {
- $value = '';
- }
- if (!empty($page_content['href'])) {
- $href = $page_content['href'];
- } else {
- $href = '';
- }
- if (!empty($page_content['alt'])) {
- $alt = $page_content['alt'];
- } else {
- $alt = $key;
- }
- $element_key_str = '';
- if (!empty($key) && isEditWebsite()) {
- $element_key_str = ' data-key=' . $key . ' ';
- }
- $element_class_str = '';
- if (!empty($class)) {
- if (!empty($tag_name) && $tag_name === 'p') {
- $class .= ' module_desc';
- }
- $element_class_str = ' class="' . $class . '" ';
- } else {
- if (!empty($tag_name) && $tag_name === 'p') {
- $element_class_str = ' class="module_desc" ';
- }
- }
- if (!empty($tag_name) && $tag_name === 'p') {
- $tag_name = 'div';
- }
- $element_href = '';
- $link_type_str = '';
- if (!empty($page_content['link_type']) && $page_content['link_type'] === '1') {
- $element_href = ' href="' . $href . '" ';
- $link_type_str = ' target="_blank"';
- } elseif (!empty($page_content['link_type']) && $page_content['link_type'] === '2') {
- $element_href = ' href="' . getRouterPath($menu_data, !empty($page_content['route']) ? $page_content['route'] : '') . '" ';
- }
- if (isMediaUrl($value)) {
- $value = extractResourcePath($value);
- }
- if ($type === 'image') {
- if ($lazyType) {
- $image_str = '<img class="lazy-load" data-src="' . $value . '" alt="' . $alt . '">';
- } else {
- $image_str = '<img src="' . $value . '" alt="' . $alt . '">';
- }
- if (!empty($element_href)) {
- return '<a ' . $element_class_str . $element_key_str . $element_href . $link_type_str.'><img src="' . $value . '" alt="' . $alt . '">' . $image_str . '</a>';
- } else {
- return '<'.$tag_name . $element_class_str . $element_key_str . '>' . $image_str . '</'.$tag_name.'>';
- }
- } elseif ($type === 'video') {
- if (!empty($element_href)) {
- return '<a ' . $element_class_str . $element_key_str . $element_href .$link_type_str. '><video x5-playsinline="" playsinline="" webkit-playsinline="" src="' . $value . '" /></a>';
- } else {
- return '<' . $tag_name . $element_class_str . $element_key_str . '><video x5-playsinline="" playsinline="" webkit-playsinline="" src="' . $value . '" /></' . $tag_name . '>';
- }
- } elseif ($type === 'text') {
- if (!empty($element_href)) {
- if ($tag_name === 'h2') {
- return '<h2><a ' . $element_class_str . $element_key_str . $element_href .$link_type_str. '>'. $value . '</a></h2>';
- } else {
- return '<a ' . $element_class_str . $element_key_str . $element_href .$link_type_str. '>'. $value . '</a>';
- }
- } else {
- return htmlspecialchars_decode('<' . $tag_name . $element_class_str . $element_key_str . ' >' . $value . '</' . $tag_name . '>');
- }
- } else {
- return $value;
- }
- }
- /**
- * 汉语 - 给用户自动生成昵称
- * @param int $type 1生成昵称,2生成姓名
- * @return mixed|string
- */
- if (!function_exists('randNickName')) {
- function randNickName($type = 1)
- {
- /**
- * 随机昵称 形容词
- */
- $nick_name_tou = ['迷你的', '鲜艳的', '飞快的', '真实的', '清新的', '幸福的', '可耐的', '快乐的', '冷静的', '醉熏的', '潇洒的', '糊涂的', '积极的', '冷酷的', '深情的', '粗暴的',
- '温柔的', '可爱的', '愉快的', '义气的', '认真的', '威武的', '帅气的', '传统的', '潇洒的', '漂亮的', '自然的', '专一的', '听话的', '昏睡的', '狂野的', '等待的', '搞怪的',
- '幽默的', '魁梧的', '活泼的', '开心的', '高兴的', '超帅的', '留胡子的', '坦率的', '直率的', '轻松的', '痴情的', '完美的', '精明的', '无聊的', '有魅力的', '丰富的', '繁荣的',
- '饱满的', '炙热的', '暴躁的', '碧蓝的', '俊逸的', '英勇的', '健忘的', '故意的', '无心的', '土豪的', '朴实的', '兴奋的', '幸福的', '淡定的', '不安的', '阔达的', '孤独的',
- '独特的', '疯狂的', '时尚的', '落后的', '风趣的', '忧伤的', '大胆的', '爱笑的', '矮小的', '健康的', '合适的', '玩命的', '沉默的', '斯文的', '香蕉', '苹果', '鲤鱼', '鳗鱼',
- '任性的', '细心的', '粗心的', '大意的', '甜甜的', '酷酷的', '健壮的', '英俊的', '霸气的', '阳光的', '默默的', '大力的', '孝顺的', '忧虑的', '着急的', '紧张的', '善良的',
- '凶狠的', '害怕的', '重要的', '危机的', '欢喜的', '欣慰的', '满意的', '跳跃的', '诚心的', '称心的', '如意的', '怡然的', '娇气的', '无奈的', '无语的', '激动的', '愤怒的',
- '美好的', '感动的', '激情的', '激昂的', '震动的', '虚拟的', '超级的', '寒冷的', '精明的', '明理的', '犹豫的', '忧郁的', '寂寞的', '奋斗的', '勤奋的', '现代的', '过时的',
- '稳重的', '热情的', '含蓄的', '开放的', '无辜的', '多情的', '纯真的', '拉长的', '热心的', '从容的', '体贴的', '风中的', '曾经的', '追寻的', '儒雅的', '优雅的', '开朗的',
- '外向的', '内向的', '清爽的', '文艺的', '长情的', '平常的', '单身的', '伶俐的', '高大的', '懦弱的', '柔弱的', '爱笑的', '乐观的', '耍酷的', '酷炫的', '神勇的', '年轻的',
- '唠叨的', '瘦瘦的', '无情的', '包容的', '顺心的', '畅快的', '舒适的', '靓丽的', '负责的', '背后的', '简单的', '谦让的', '彩色的', '缥缈的', '欢呼的', '生动的', '复杂的',
- '慈祥的', '仁爱的', '魔幻的', '虚幻的', '淡然的', '受伤的', '雪白的', '高高的', '糟糕的', '顺利的', '闪闪的', '羞涩的', '缓慢的', '迅速的', '优秀的', '聪明的', '含糊的',
- '俏皮的', '淡淡的', '坚强的', '平淡的', '欣喜的', '能干的', '灵巧的', '友好的', '机智的', '机灵的', '正直的', '谨慎的', '俭朴的', '殷勤的', '虚心的', '辛勤的', '自觉的',
- '无私的', '无限的', '踏实的', '老实的', '现实的', '可靠的', '务实的', '拼搏的', '个性的', '粗犷的', '活力的', '成就的', '勤劳的', '单纯的', '落寞的', '朴素的', '悲凉的',
- '忧心的', '洁净的', '清秀的', '自由的', '小巧的', '单薄的', '贪玩的', '刻苦的', '干净的', '壮观的', '和谐的', '文静的', '调皮的', '害羞的', '安详的', '自信的', '端庄的',
- '坚定的', '美满的', '舒心的', '温暖的', '专注的', '勤恳的', '美丽的', '腼腆的', '优美的', '甜美的', '甜蜜的', '整齐的', '动人的', '典雅的', '尊敬的', '舒服的', '妩媚的',
- '秀丽的', '喜悦的', '甜美的', '彪壮的', '强健的', '大方的', '俊秀的', '聪慧的', '迷人的', '陶醉的', '悦耳的', '动听的', '明亮的', '结实的', '魁梧的', '标致的', '清脆的',
- '敏感的', '光亮的', '大气的', '老迟到的', '知性的', '冷傲的', '呆萌的', '野性的', '隐形的', '笑点低的', '微笑的', '笨笨的', '难过的', '沉静的', '火星上的', '失眠的',
- '安静的', '纯情的', '要减肥的', '迷路的', '烂漫的', '哭泣的', '贤惠的', '苗条的', '温婉的', '发嗲的', '会撒娇的', '贪玩的', '执着的', '眯眯眼的', '花痴的', '想人陪的',
- '眼睛大的', '高贵的', '傲娇的', '心灵美的', '爱撒娇的', '细腻的', '天真的', '怕黑的', '感性的', '飘逸的', '怕孤独的', '忐忑的', '高挑的', '傻傻的', '冷艳的', '爱听歌的',
- '还单身的', '怕孤单的', '懵懂的'];
- $nick_name_wei = ['嚓茶', '皮皮虾', '皮卡丘', '马里奥', '小霸王', '凉面', '便当', '毛豆', '花生', '可乐', '灯泡', '哈密瓜', '野狼', '背包', '眼神', '缘分', '雪碧', '人生', '牛排',
- '蚂蚁', '飞鸟', '灰狼', '斑马', '汉堡', '悟空', '巨人', '绿茶', '自行车', '保温杯', '大碗', '墨镜', '魔镜', '煎饼', '月饼', '月亮', '星星', '芝麻', '啤酒', '玫瑰',
- '大叔', '小伙', '哈密瓜,数据线', '太阳', '树叶', '芹菜', '黄蜂', '蜜粉', '蜜蜂', '信封', '西装', '外套', '裙子', '大象', '猫咪', '母鸡', '路灯', '蓝天', '白云',
- '星月', '彩虹', '微笑', '摩托', '板栗', '高山', '大地', '大树', '电灯胆', '砖头', '楼房', '水池', '鸡翅', '蜻蜓', '红牛', '咖啡', '机器猫', '枕头', '大船', '诺言',
- '钢笔', '刺猬', '天空', '飞机', '大炮', '冬天', '洋葱', '春天', '夏天', '秋天', '冬日', '航空', '毛衣', '豌豆', '黑米', '玉米', '眼睛', '老鼠', '白羊', '帅哥', '美女',
- '季节', '鲜花', '服饰', '裙子', '白开水', '秀发', '大山', '火车', '汽车', '歌曲', '舞蹈', '老师', '导师', '方盒', '大米', '麦片', '水杯', '水壶', '手套', '鞋子', '自行车',
- '鼠标', '手机', '电脑', '书本', '奇迹', '身影', '香烟', '夕阳', '台灯', '宝贝', '未来', '皮带', '钥匙', '心锁', '故事', '花瓣', '滑板', '画笔', '画板', '学姐', '店员',
- '电源', '饼干', '宝马', '过客', '大白', '时光', '石头', '钻石', '河马', '犀牛', '西牛', '绿草', '抽屉', '柜子', '往事', '寒风', '路人', '橘子', '耳机', '鸵鸟', '朋友',
- '苗条', '铅笔', '钢笔', '硬币', '热狗', '大侠', '御姐', '萝莉', '毛巾', '期待', '盼望', '白昼', '黑夜', '大门', '黑裤', '钢铁侠', '哑铃', '板凳', '枫叶', '荷花', '乌龟',
- '仙人掌', '衬衫', '大神', '草丛', '早晨', '心情', '茉莉', '流沙', '蜗牛', '战斗机', '冥王星', '猎豹', '棒球', '篮球', '乐曲', '电话', '网络', '世界', '中心', '鱼', '鸡', '狗',
- '老虎', '鸭子', '雨', '羽毛', '翅膀', '外套', '火', '丝袜', '书包', '钢笔', '冷风', '八宝粥', '烤鸡', '大雁', '音响', '招牌', '胡萝卜', '冰棍', '帽子', '菠萝', '蛋挞', '香水',
- '泥猴桃', '吐司', '溪流', '黄豆', '樱桃', '小鸽子', '小蝴蝶', '爆米花', '花卷', '小鸭子', '小海豚', '日记本', '小熊猫', '小懒猪', '小懒虫', '荔枝', '镜子', '曲奇', '金针菇',
- '小松鼠', '小虾米', '酒窝', '紫菜', '金鱼', '柚子', '果汁', '百褶裙', '项链', '帆布鞋', '火龙果', '奇异果', '煎蛋', '唇彩', '小土豆', '高跟鞋', '戒指', '雪糕', '睫毛', '铃铛',
- '手链', '香氛', '红酒', '月光', '酸奶', '银耳汤', '咖啡豆', '小蜜蜂', '小蚂蚁', '蜡烛', '棉花糖', '向日葵', '水蜜桃', '小蝴蝶', '小刺猬', '小丸子', '指甲油', '康乃馨', '糖豆',
- '薯片', '口红', '超短裙', '乌冬面', '冰淇淋', '棒棒糖', '长颈鹿', '豆芽', '发箍', '发卡', '发夹', '发带', '铃铛', '小馒头', '小笼包', '小甜瓜', '冬瓜', '香菇', '小兔子',
- '含羞草', '短靴', '睫毛膏', '小蘑菇', '跳跳糖', '小白菜', '草莓', '柠檬', '月饼', '百合', '纸鹤', '小天鹅', '云朵', '芒果', '面包', '海燕', '小猫咪', '龙猫', '唇膏', '鞋垫',
- '羊', '黑猫', '白猫', '万宝路', '金毛', '山水', '音响', '纸飞机', '烧鹅'];
- /**
- * 百家姓
- */
- $arrXing = ['赵', '钱', '孙', '李', '周', '吴', '郑', '王', '冯', '陈', '褚', '卫', '蒋', '沈', '韩', '杨', '朱', '秦', '尤', '许', '何', '吕', '施', '张', '孔', '曹', '严', '华', '金', '魏', '陶', '姜', '戚', '谢', '邹',
- '喻', '柏', '水', '窦', '章', '云', '苏', '潘', '葛', '奚', '范', '彭', '郎', '鲁', '韦', '昌', '马', '苗', '凤', '花', '方', '任', '袁', '柳', '鲍', '史', '唐', '费', '薛', '雷', '贺', '倪', '汤', '滕', '殷', '罗',
- '毕', '郝', '安', '常', '傅', '卞', '齐', '元', '顾', '孟', '平', '黄', '穆', '萧', '尹', '姚', '邵', '湛', '汪', '祁', '毛', '狄', '米', '伏', '成', '戴', '谈', '宋', '茅', '庞', '熊', '纪', '舒', '屈', '项', '祝',
- '董', '梁', '杜', '阮', '蓝', '闵', '季', '贾', '路', '娄', '江', '童', '颜', '郭', '梅', '盛', '林', '钟', '徐', '邱', '骆', '高', '夏', '蔡', '田', '樊', '胡', '凌', '霍', '虞', '万', '支', '柯', '管', '卢', '莫',
- '柯', '房', '裘', '缪', '解', '应', '宗', '丁', '宣', '邓', '单', '杭', '洪', '包', '诸', '左', '石', '崔', '吉', '龚', '程', '嵇', '邢', '裴', '陆', '荣', '翁', '荀', '于', '惠', '甄', '曲', '封', '储', '仲', '伊',
- '宁', '仇', '甘', '武', '符', '刘', '景', '詹', '龙', '叶', '幸', '司', '黎', '溥', '印', '怀', '蒲', '邰', '从', '索', '赖', '卓', '屠', '池', '乔', '胥', '闻', '莘', '党', '翟', '谭', '贡', '劳', '逄', '姬', '申',
- '扶', '堵', '冉', '宰', '雍', '桑', '寿', '通', '燕', '浦', '尚', '农', '温', '别', '庄', '晏', '柴', '瞿', '阎', '连', '习', '容', '向', '古', '易', '廖', '庾', '终', '步', '都', '耿', '满', '弘', '匡', '国', '文',
- '寇', '广', '禄', '阙', '东', '欧', '利', '师', '巩', '聂', '关', '荆', '司马', '上官', '欧阳', '夏侯', '诸葛', '闻人', '东方', '赫连', '皇甫', '尉迟', '公羊', '澹台', '公冶', '宗政', '濮阳', '淳于', '单于', '太叔',
- '申屠', '公孙', '仲孙', '轩辕', '令狐', '徐离', '宇文', '长孙', '慕容', '司徒', '司空', '皮'];
- /**
- * 名
- */
- $arrMing = ['伟', '刚', '勇', '毅', '俊', '峰', '强', '军', '平', '保', '东', '文', '辉', '力', '明', '永', '健', '世', '广', '志', '义', '兴', '良', '海', '山', '仁', '波', '宁', '贵', '福', '生', '龙', '元', '全'
- , '国', '胜', '学', '祥', '才', '发', '武', '新', '利', '清', '飞', '彬', '富', '顺', '信', '子', '杰', '涛', '昌', '成', '康', '星', '光', '天', '达', '安', '岩', '中', '茂', '进', '林', '有', '坚', '和', '彪', '博', '诚'
- , '先', '敬', '震', '振', '壮', '会', '思', '群', '豪', '心', '邦', '承', '乐', '绍', '功', '松', '善', '厚', '庆', '磊', '民', '友', '裕', '河', '哲', '江', '超', '浩', '亮', '政', '谦', '亨', '奇', '固', '之', '轮', '翰'
- , '朗', '伯', '宏', '言', '若', '鸣', '朋', '斌', '梁', '栋', '维', '启', '克', '伦', '翔', '旭', '鹏', '泽', '晨', '辰', '士', '以', '建', '家', '致', '树', '炎', '德', '行', '时', '泰', '盛', '雄', '琛', '钧', '冠', '策'
- , '腾', '楠', '榕', '风', '航', '弘', '秀', '娟', '英', '华', '慧', '巧', '美', '娜', '静', '淑', '惠', '珠', '翠', '雅', '芝', '玉', '萍', '红', '娥', '玲', '芬', '芳', '燕', '彩', '春', '菊', '兰', '凤', '洁', '梅', '琳'
- , '素', '云', '莲', '真', '环', '雪', '荣', '爱', '妹', '霞', '香', '月', '莺', '媛', '艳', '瑞', '凡', '佳', '嘉', '琼', '勤', '珍', '贞', '莉', '桂', '娣', '叶', '璧', '璐', '娅', '琦', '晶', '妍', '茜', '秋', '珊', '莎'
- , '锦', '黛', '青', '倩', '婷', '姣', '婉', '娴', '瑾', '颖', '露', '瑶', '怡', '婵', '雁', '蓓', '纨', '仪', '荷', '丹', '蓉', '眉', '君', '琴', '蕊', '薇', '菁', '梦', '岚', '苑', '婕', '馨', '瑗', '琰', '韵', '融', '园'
- , '艺', '咏', '卿', '聪', '澜', '纯', '毓', '悦', '昭', '冰', '爽', '琬', '茗', '羽', '希', '欣', '飘', '育', '滢', '馥', '筠', '柔', '竹', '霭', '凝', '晓', '欢', '霄', '枫', '芸', '菲', '寒', '伊', '亚', '宜', '可', '姬'
- , '舒', '影', '荔', '枝', '丽', '阳', '妮', '宝', '贝', '初', '程', '梵', '罡', '恒', '鸿', '桦', '骅', '剑', '娇', '纪', '宽', '苛', '灵', '玛', '媚', '琪', '晴', '容', '睿', '烁', '堂', '唯', '威', '韦', '雯', '苇', '萱'
- , '阅', '彦', '宇', '雨', '洋', '忠', '宗', '曼', '紫', '逸', '贤', '蝶', '菡', '绿', '蓝', '儿', '翠', '烟'];
- $nick_name = '';
- switch ($type) {
- case 1:
- $tou_num = rand(0, count($nick_name_tou) - 1);
- $wei_num = rand(0, count($nick_name_wei) - 1);
- $nick_name = $nick_name_tou[$tou_num] . $nick_name_wei[$wei_num];
- break;
- case 2:
- $nick_name = $arrXing[mt_rand(0, count($arrXing) - 1)];
- for ($i = 1; $i <= 3; $i++) {
- $nick_name .= (mt_rand(0, 1) ? $arrMing[mt_rand(0, count($arrMing) - 1)] : $arrMing[mt_rand(0, count($arrMing) - 1)]);
- }
- break;
- case 3:
- $nick_name = rand(0, count($nick_name_tou) - 1);
- for ($i = 1; $i <= 3; $i++) {
- $nick_name .= (mt_rand(0, 1) ? $arrMing[mt_rand(0, count($arrMing) - 1)] : $arrMing[mt_rand(0, count($arrMing) - 1)]);
- }
- break;
- }
- return $nick_name;
- }
- }
- if (!function_exists('getExtFromUrl')) {
- function getExtFromUrl($url)
- {
- $ext = null;
- if (filter_var($url, FILTER_VALIDATE_URL) !== false) {
- $headers = get_headers($url);
- foreach ($headers as $header) {
- if (preg_match('/Content-Type: (.*)/', $header, $match) && !empty($match[1])) {
- $matchArr = explode('/', $match[1]);
- if (!empty($matchArr[1])) {
- $ext = $matchArr[1];
- }
- break;
- }
- }
- }
- if (empty($ext)) {
- $urlArr = parse_url($url);
- if (!empty($urlArr['scheme']) && !empty($urlArr['host'])) {
- $pureUrl = $urlArr['scheme'] . '://' . $urlArr['host'] . $urlArr['path'];
- $ext = pathinfo($pureUrl, PATHINFO_EXTENSION);
- }
- }
- return $ext;
- }
- }
- function isEditWebsite()
- {
- // 获取当前页面的URL
- $current_url = "$_SERVER[REQUEST_URI]";
- $needle = "website_type=edit";
- if (strpos($current_url, $needle) !== false) {
- return true;
- } else {
- return false;
- }
- }
- function returnDataModule($code,$dataType='data-module'): string
- {
- if (isEditWebsite()) {
- return $dataType.'=' . $code;
- } else {
- return '';
- }
- }
- //$format : Y=年 m=月 d=日
- function returnDateFormat($lang, $date, $format = 'Y-m-d') {
- // 验证输入日期是否有效
- if (!strtotime($date)) {
- return '';
- // throw new InvalidArgumentException("Invalid date format: $date");
- }
- // 处理中文和日文语言
- if ($lang === 'zh-cn' || $lang === 'ja-jp' || $lang === 'ja') {
- switch ($format) {
- case 'Y':
- return date("Y", strtotime($date));
- case 'm':
- return date("m", strtotime($date));
- case 'd':
- return date("d", strtotime($date));
- case 'Y-m':
- return date("Y年m月", strtotime($date));
- case 'm-d':
- return date("m月d日", strtotime($date));
- case 'Y-m-d':
- default:
- return date("Y年m月d日", strtotime($date));
- }
- }
- // 创建 DateTime 对象
- $date_obj = new DateTime($date);
- // 处理其他语言
- switch ($format) {
- case 'Y':
- return $date_obj->format('Y');
- case 'm':
- return $date_obj->format('F');
- case 'Y-m':
- return $date_obj->format('F, Y');
- case 'm-d':
- return $date_obj->format('F j');
- case 'd':
- return $date_obj->format('j');
- case 'Y-m-d':
- default:
- return $date_obj->format('F j, Y');
- }
- }
- function returnTimeFormat($start_time, $end_time, $lang = 'zh-cn'): string
- {
- // 创建 DateTime 对象
- $start_date = new DateTime($start_time);
- $end_date = new DateTime($end_time);
- // 判断日期关系
- $is_same_day = $start_date->format('Y-m-d') === $end_date->format('Y-m-d');
- $is_same_month = $start_date->format('Y-m') === $end_date->format('Y-m');
- $is_same_year = $start_date->format('Y') === $end_date->format('Y');
- // 根据语言选择格式化模板
- $templates = [
- 'zh-cn' => [
- 'same_day' => 'Y年m月d日 H:i - H:i',
- 'same_month' => 'Y年m月d日 H:i - m月d日 H:i',
- 'same_year' => 'Y年m月d日 H:i - m月d日 H:i',
- 'different' => 'Y年m月d日 H:i - Y年m月d日 H:i'
- ],
- 'ja-jp' => [
- 'same_day' => 'Y年m月d日 H:i - H:i',
- 'same_month' => 'Y年m月d日 H:i - m月d日 H:i',
- 'same_year' => 'Y年m月d日 H:i - m月d日 H:i',
- 'different' => 'Y年m月d日 H:i - Y年m月d日 H:i'
- ],
- 'ja' => [
- 'same_day' => 'Y年m月d日 H:i - H:i',
- 'same_month' => 'Y年m月d日 H:i - m月d日 H:i',
- 'same_year' => 'Y年m月d日 H:i - m月d日 H:i',
- 'different' => 'Y年m月d日 H:i - Y年m月d日 H:i'
- ],
- 'default' => [
- 'same_day' => 'l, F j, Y g:i A - g:i A',
- 'same_month' => 'l, F j, Y g:i A - l, j g:i A',
- 'same_year' => 'l, F j, Y g:i A - l, F j g:i A',
- 'different' => 'l, F j, Y g:i A - l, F j, Y g:i A'
- ]
- ];
- // 获取当前语言的模板
- $current_templates = $templates[$lang] ?? $templates['default'];
- // 根据日期关系选择模板
- if ($is_same_day) {
- $format = $current_templates['same_day'];
- } elseif ($is_same_month) {
- $format = $current_templates['same_month'];
- } elseif ($is_same_year) {
- $format = $current_templates['same_year'];
- } else {
- $format = $current_templates['different'];
- }
- // 格式化开始日期
- $start_formatted = $start_date->format(substr($format, 0, strpos($format, ' - ')));
- // 格式化结束日期
- $end_formatted = $end_date->format(substr($format, strpos($format, ' - ') + 3));
- // 返回最终结果
- return $start_formatted . ' - ' . $end_formatted;
- }
- function returnConciseFormat($start_time, $end_time): string
- {
- // 创建DateTime对象
- $start_date = new DateTime($start_time);
- $end_date = new DateTime($end_time);
- // 格式化输出
- return $start_date->format('F j') . '-' . $end_date->format('j, Y');
- }
- function returnUrlParams($name) {
- return isset($_GET[$name]) ? $_GET[$name] : null;
- }
- function initPageParams($page=1,$page_size=10,$keyword='')
- {
- if (!empty($_GET['page'])) {
- $page = $_GET['page'];
- }
- if (!empty($_GET['page_size'])) {
- $page_size = $_GET['page_size'];
- }
- if (!empty($_GET['keyword'])) {
- $keyword = $_GET['keyword'];
- }
- return [
- 'page' => $page,
- 'page_size' => $page_size,
- 'keyword' => $keyword,
- ];
- }
- function isMobile() {
- // 获取用户代理信息
- $userAgent = $_SERVER['HTTP_USER_AGENT'];
- // 定义常见的移动设备关键词
- $mobileKeywords = [
- 'Android', 'iPhone', 'iPod', 'iPad', 'Windows Phone',
- 'BlackBerry', 'Opera Mini', 'IEMobile', 'Mobile', 'Touch'
- ];
- // 检查用户代理中是否包含任何移动关键词
- foreach ($mobileKeywords as $keyword) {
- if (stripos($userAgent, $keyword) !== false) {
- return true;
- }
- }
- // 如果没有找到任何移动关键词,则认为是桌面端
- return false;
- }
- function isIframeUrl($string) {
- // 正则表达式匹配iframe标签及其中的src属性
- $pattern = '/<iframe\s+src=["\']([^"\']+)["\']/i';
- preg_match($pattern, $string, $matches);
- // 如果匹配成功,说明字符串中包含iframe地址
- if (!empty($matches)) {
- // $matches[1]将包含src属性中的地址
- return true;
- }
- return false;
- }
- function createGuid()
- {
- $charid = strtoupper(md5(uniqid(mt_rand(), true)));
- $hyphen = chr(45);// "-"
- $uuid = chr(123)// "{"
- . substr($charid, 0, 8) . $hyphen
- . substr($charid, 8, 4) . $hyphen
- . substr($charid, 12, 4) . $hyphen
- . substr($charid, 16, 4) . $hyphen
- . substr($charid, 20, 12)
- . chr(125);// "}"
- return $uuid;
- }
- function getFileName($url) {
- // 使用 parse_url 解析 URL
- $parsedUrl = parse_url($url);
- // 获取路径部分
- $path = $parsedUrl['path'];
- // 使用 basename 提取文件名
- $filename = basename($path);
- return $filename;
- }
- function commonWords($text,$lang='zh-cn')
- {
- if ($lang === 'zh-cn') {
- return $text;
- }
- if ($text === '了解更多') {
- switch ($lang) {
- case 'en-us':
- return 'Learn More';
- case 'ja':
- return 'もっと詳しく';
- case 'es':
- return 'Más información';
- case 'fr':
- return 'En savoir plus';
- case 'de':
- return 'Mehr erfahren';
- case 'it':
- return 'Scopri di più';
- default:
- return $text; // 如果没有匹配的语言,返回原始文本
- }
- }
- if ($text === '了解详情') {
- switch ($lang) {
- case 'en-us':
- return 'Learn Details';
- case 'ja':
- return '詳細を知る';
- case 'es':
- return 'Más detalles';
- case 'fr':
- return 'En savoir les détails';
- case 'de':
- return 'Details erfahren';
- case 'it':
- return 'Scopri i dettagli';
- default:
- return $text; // 如果没有匹配的语言,返回原始文本
- }
- }
- return $text; // 如果没有匹配的文本,返回原始文本
- }
- function quarterDate($text, $lang)
- {
- if (strpos($text, '-') !== false) {
- $mapZh = array(
- '1-3' => '1-3月',
- '4-6' => '4-6月',
- '7-9' => '7-9月',
- '10-12' => '10-12月'
- );
- $monthMap = array(
- '1-3' => 'from January to March',
- '4-6' => 'from April to June',
- '7-9' => 'from July to September',
- '10-12' => 'from October to December'
- );
- if ($lang === 'zh-cn') {
- return $mapZh[$text] ?? $text;
- } else {
- return $monthMap[$text] ?? $text;
- }
- } else {
- if ($lang === 'zh-cn') {
- return $text . '年';
- } else {
- return $text;
- }
- }
- }
- //旧项目
- function getPageDataHref($page_content,$page_key) {
- if(isset($page_content) && isset($page_content[$page_key]['href']) && !empty($page_content[$page_key]['href'])) {
- return $page_content[$page_key]['href'];
- } else {
- return 'javascript:void(0)';
- }
- }
- function determinePageData($page_content,$page_key) {
- if(isset($page_content) && isset($page_content[$page_key]) && !empty($page_content[$page_key])) {
- return true;
- } else {
- return false;
- }
- }
- function getPageDataAlt($page_content,$page_key) {
- if(isset($page_content) && isset($page_content[$page_key]['alt']) && !empty($page_content[$page_key]['alt'])) {
- return $page_content[$page_key]['alt'];
- } else {
- return '';
- }
- }
- function createElementOld($menu_data, $data, $module_key, $class, $type, $default_val, $tag_name = '') {
- return createElement($menu_data, $data, '', $module_key, $class, $type, $default_val, $tag_name);
- }
|