common.php 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079
  1. <?php
  2. /*
  3. '软件名称:苹果CMS 源码库:https://github.com/magicblack
  4. '--------------------------------------------------------
  5. 'Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  6. '遵循Apache2开源协议发布,并提供免费使用。
  7. '--------------------------------------------------------
  8. */
  9. use think\View;
  10. error_reporting(E_ERROR | E_PARSE );
  11. function get_array_unique_id_list($list, $need_sort = false) {
  12. $list = array_unique($list);
  13. $list = array_map('intval', $list);
  14. $list = array_filter($list);
  15. $list = array_values($list);
  16. $need_sort && sort($list);
  17. return $list;
  18. }
  19. if (!function_exists('str_starts_with')) {
  20. function str_starts_with($haystack, $needle) {
  21. return (string)$needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0;
  22. }
  23. }
  24. if (!function_exists('str_ends_with')) {
  25. function str_ends_with($haystack, $needle) {
  26. return $needle !== '' && substr($haystack, -strlen($needle)) === (string)$needle;
  27. }
  28. }
  29. if (!function_exists('str_contains')) {
  30. function str_contains($haystack, $needle) {
  31. return $needle !== '' && mb_strpos($haystack, $needle) !== false;
  32. }
  33. }
  34. //访问日志记录,根目录创建log目录
  35. function slog($logs)
  36. {
  37. $ymd = date('Y-m-d-H');
  38. $now = date('Y-m-d H:i:s');
  39. $toppath = "./log/$ymd.txt";
  40. $ts = @fopen($toppath,"a+");
  41. @fputs($ts, $now .' '. $logs ."\r\n");
  42. @fclose($ts);
  43. }
  44. //foreach($_GET as $k=>$v){ $getData .= $k.'='.$v.'&'; }
  45. //foreach($_POST as $k=>$v){ $postData .= $k.'='.$v.'&'; }
  46. //foreach($_COOKIE as $k=>$v){ $cookieData .= $k.'='.$v.'&'; }
  47. //$log = $_SERVER['PHP_SELF'] . '---get:' .$getData .'---post:' . $postData .'---'. json_encode($_POST).'---cookie:' . $cookieData ;
  48. //slog($log);
  49. // 是否IP
  50. function mac_string_is_ip($string) {
  51. return preg_match('/^(\d{1,3}\.){3}\d{1,3}(:\d{1,5})?$/', $string) === 1;
  52. }
  53. // 应用公共文件
  54. function mac_return($msg,$code=1,$data=''){
  55. if(is_array($msg)){
  56. return json_encode($msg);
  57. }
  58. else {
  59. $rs = ['code' => $code, 'msg' => $msg, 'data'=>'' ];
  60. if(is_array($data)) $rs['data'] = $data;
  61. return json_encode($rs);
  62. }
  63. }
  64. function mac_run_statistics()
  65. {
  66. $t2 = microtime(true) - MAC_START_TIME;
  67. $size = memory_get_usage();
  68. $memory = mac_format_size($size);
  69. unset($unit);
  70. return 'Processed in: '.round($t2,4).' second(s),&nbsp;' . $memory . ' Mem On.';
  71. }
  72. function mac_format_size($s=0)
  73. {
  74. if($s==0){ return '0 kb'; }
  75. $unit=array('b','kb','mb','gb','tb','pb');
  76. return round($s/pow(1024,($i=floor(log($s,1024)))),2).' '.$unit[$i];
  77. }
  78. function mac_read_file($f)
  79. {
  80. return @file_get_contents($f);
  81. }
  82. function mac_write_file($f,$c='')
  83. {
  84. $dir = dirname($f);
  85. if(!is_dir($dir)){
  86. mac_mkdirss($dir);
  87. }
  88. return @file_put_contents($f, $c);
  89. }
  90. function mac_mkdirss($path,$mode=0777)
  91. {
  92. if (!is_dir(dirname($path))){
  93. mac_mkdirss(dirname($path));
  94. }
  95. if(!file_exists($path)){
  96. return mkdir($path,$mode);
  97. }
  98. return true;
  99. }
  100. function mac_rmdirs($dirname, $withself = true)
  101. {
  102. if (!is_dir($dirname))
  103. return false;
  104. $files = new RecursiveIteratorIterator(
  105. new RecursiveDirectoryIterator($dirname, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST
  106. );
  107. foreach ($files as $fileinfo)
  108. {
  109. $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
  110. $todo($fileinfo->getRealPath());
  111. }
  112. if ($withself)
  113. {
  114. @rmdir($dirname);
  115. }
  116. return true;
  117. }
  118. function mac_arr2file($f,$arr='')
  119. {
  120. if(is_array($arr)){
  121. $con = var_export($arr,true);
  122. } else{
  123. $con = $arr;
  124. }
  125. $con = "<?php\nreturn $con;";
  126. mac_write_file($f, $con);
  127. // opcache清理以实时生效配置
  128. if (function_exists('opcache_invalidate')) {
  129. opcache_invalidate($f, true);
  130. }
  131. }
  132. function mac_replace_text($txt,$type=1)
  133. {
  134. if($type==1){
  135. return str_replace('#',Chr(13),$txt);
  136. }
  137. return str_replace(chr(13),'#',str_replace(chr(10),'',$txt));
  138. }
  139. function mac_compress_html($s){
  140. $s = str_replace(array("\r\n","\n","\t"), array('','','') , $s);
  141. $pattern = array (
  142. "/> *([^ ]*) *</",
  143. "/[\s]+/",
  144. "/<!--[\\w\\W\r\\n]*?-->/",
  145. // "/\" /",
  146. "/ \"/",
  147. "'/\*[^*]*\*/'"
  148. );
  149. $replace = array (
  150. ">\\1<",
  151. " ",
  152. "",
  153. //"\"",
  154. "\"",
  155. ""
  156. );
  157. return preg_replace($pattern, $replace, $s);
  158. }
  159. function mac_build_regx($regstr,$regopt)
  160. {
  161. return '/'.str_replace([
  162. '/',
  163. '$',
  164. '+',
  165. '-',
  166. '{',
  167. ],[
  168. '\/',
  169. '\$',
  170. '\+',
  171. '\-',
  172. '\{',
  173. ],$regstr).'/'.$regopt;
  174. }
  175. function mac_reg_replace($str,$rule,$value)
  176. {
  177. $res='';
  178. $rule = mac_build_regx($rule,"is");
  179. if (!empty($str)){
  180. $res = preg_replace($rule,$value,$str);
  181. }
  182. return $res;
  183. }
  184. function mac_reg_match($str,$rule)
  185. {
  186. $res='';
  187. $rule = mac_build_regx($rule,"is");
  188. preg_match_all($rule,$str,$mc);
  189. $mfv=$mc[1];
  190. foreach($mfv as $f=>$v){
  191. $res = trim(preg_replace("/[ \r\n\t\f]{1,}/"," ",$v));
  192. break;
  193. }
  194. unset($mc);
  195. return $res;
  196. }
  197. function mac_redirect($url,$obj='')
  198. {
  199. echo '<script>'.$obj.'location.href="' .$url .'";</script>';
  200. exit;
  201. }
  202. function mac_alert($str)
  203. {
  204. echo '<script>alert("' .$str. '\t\t");history.go(-1);</script>';
  205. }
  206. function mac_alert_url($str,$url)
  207. {
  208. echo '<script>alert("' .$str. '\t\t");location.href="' .$url .'";</script>';
  209. }
  210. function mac_jump($url,$sec=0)
  211. {
  212. echo '<script>setTimeout(function (){location.href="'.$url.'";},'.($sec*1000).');</script><span>'.lang('pause').''.$sec.''.lang('continue_in_second').' >>> </span><a href="'.$url.'" >'.lang('browser_jump').'</a><br>';
  213. }
  214. function mac_echo($str)
  215. {
  216. echo $str.'<br>';
  217. ob_flush();flush();
  218. }
  219. function mac_day($t,$f='',$c='#FF0000')
  220. {
  221. if(empty($t)) { return ''; }
  222. if(is_numeric($t)){
  223. $t = date('Y-m-d H:i:s',$t);
  224. }
  225. $now = date('Y-m-d',time());
  226. if($f=='color' && strpos(','.$t,$now)>0){
  227. return '<font color="' .$c. '">' .$t. '</font>';
  228. }
  229. return $t;
  230. }
  231. function mac_friend_date($time)
  232. {
  233. if (!$time)
  234. return false;
  235. $fdate = '';
  236. $d = time() - intval($time);
  237. $ld = $time - mktime(0, 0, 0, 0, 0, date('Y')); //得出年
  238. $md = $time - mktime(0, 0, 0, date('m'), 0, date('Y')); //得出月
  239. $byd = $time - mktime(0, 0, 0, date('m'), date('d') - 2, date('Y')); //前天
  240. $yd = $time - mktime(0, 0, 0, date('m'), date('d') - 1, date('Y')); //昨天
  241. $dd = $time - mktime(0, 0, 0, date('m'), date('d'), date('Y')); //今天
  242. $td = $time - mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')); //明天
  243. $atd = $time - mktime(0, 0, 0, date('m'), date('d') + 2, date('Y')); //后天
  244. if ($d == 0) {
  245. $fdate = lang('just');
  246. } else {
  247. switch ($d) {
  248. case $d < $atd:
  249. $fdate = date('Y'.lang('year').'m'.lang('month').'d'.lang('day'), $time);
  250. break;
  251. case $d < $td:
  252. $fdate = lang('day_after_tomorrow') . date('H:i', $time);
  253. break;
  254. case $d < 0:
  255. $fdate = lang('tomorrow') . date('H:i', $time);
  256. break;
  257. case $d < 60:
  258. $fdate = $d . lang('seconds_ago');
  259. break;
  260. case $d < 3600:
  261. $fdate = floor($d / 60) . lang('minutes_ago');
  262. break;
  263. case $d < $dd:
  264. $fdate = floor($d / 3600) . lang('hours_ago');
  265. break;
  266. case $d < $yd:
  267. $fdate = lang('yesterday') . date('H:i', $time);
  268. break;
  269. case $d < $byd:
  270. $fdate = lang('day_before_yesterday') . date('H:i', $time);
  271. break;
  272. case $d < $md:
  273. $fdate = date('m'.lang('month').'d'.lang('day').' H:i', $time);
  274. break;
  275. case $d < $ld:
  276. $fdate = date('m'.lang('month').'d'.lang('day'), $time);
  277. break;
  278. default:
  279. $fdate = date('Y'.lang('year').'m'.lang('month').'d'.lang('day'), $time);
  280. break;
  281. }
  282. }
  283. return $fdate;
  284. }
  285. function mac_get_time_span($sn)
  286. {
  287. $lastTime = session($sn);
  288. if(empty($lastTime)){
  289. $lastTime= "1228348800";
  290. }
  291. $res = time() - intval($lastTime);
  292. session($sn,time());
  293. return $res;
  294. }
  295. function mac_get_rndstr($length=32,$f='')
  296. {
  297. $pattern = "234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  298. if($f=='num'){
  299. $pattern = '1234567890';
  300. }
  301. elseif($f=='letter'){
  302. $pattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  303. }
  304. $len = strlen($pattern) -1;
  305. $res='';
  306. for($i=0; $i<$length; $i++){
  307. $res .= $pattern[mt_rand(0,$len)];
  308. }
  309. // 开头为0的随机替换为1~9,优化导出格式问题
  310. if (str_starts_with($res, '0')) {
  311. $res = mt_rand(1, 9) . substr($res, 1);
  312. }
  313. return $res;
  314. }
  315. function mac_convert_encoding($str,$nfate,$ofate){
  316. if ($ofate=="UTF-8"){ return $str; }
  317. if ($ofate=="GB2312"){ $ofate="GBK"; }
  318. if(function_exists("mb_convert_encoding")){
  319. $str=mb_convert_encoding($str,$nfate,$ofate);
  320. }
  321. else{
  322. $ofate.="//IGNORE";
  323. $str=iconv($nfate ,$ofate ,$str);
  324. }
  325. return $str;
  326. }
  327. function mac_get_refer()
  328. {
  329. return trim(urldecode($_SERVER["HTTP_REFERER"]));
  330. }
  331. function mac_extends_list($flag)
  332. {
  333. $path = './application/common/extend/'.$flag;
  334. $file_list = glob($path . '/*.php',GLOB_NOSORT );
  335. $res=[];
  336. $res['ext_list'] = [];
  337. $res['ext_html'] = '';
  338. foreach($file_list as $k=>$v) {
  339. $cl = str_replace([$path . '/', '.php'], '', $v);
  340. $cp = 'app\\common\\extend\\'.$flag.'\\' . $cl;
  341. if (class_exists($cp)) {
  342. $c = new $cp;
  343. $res['ext_list'][$cl] = $c->name;
  344. if(file_exists( './application/admin/view/extend/'.$flag.'/'.strtolower($cl) .'.html')) {
  345. $res['ext_html'] .= View::instance()->fetch('admin@extend/'.$flag.'/' . strtolower($cl));
  346. }
  347. }
  348. }
  349. return $res;
  350. }
  351. function mac_send_sms($to,$code,$type_flag,$type_des,$msg)
  352. {
  353. if(empty($GLOBALS['config']['sms']['type'])){
  354. return ['code'=>9005,'msg'=> lang('sms_not_config')];
  355. }
  356. $pattern = "/^1[345789][0-9]{9}$/";
  357. if(!preg_match($pattern,$to)){
  358. return ['code'=>999,'msg'=>lang('phone_format_err')];
  359. }
  360. if(empty($code)){
  361. return ['code'=>998,'msg'=>lang('title_not_empty')];
  362. }
  363. if(empty($type_flag)){
  364. return ['code'=>997,'msg'=>lang('tpl_not')];
  365. }
  366. $cp = 'app\\common\\extend\\sms\\' . ucfirst($GLOBALS['config']['sms']['type']);
  367. if (class_exists($cp)) {
  368. $c = new $cp;
  369. return $c->submit($to,$code,$type_flag,$type_des,$msg);
  370. }
  371. else{
  372. return ['code'=>991,'msg'=>lang('sms_not')];
  373. }
  374. }
  375. function mac_send_mail($to,$title,$body,$conf=[])
  376. {
  377. if(empty($GLOBALS['config']['email']['type'])){
  378. return ['code'=>9005,'msg'=>lang('email_not_config')];
  379. }
  380. $pattern = '/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/';
  381. if(!preg_match( $pattern, $to)){
  382. return ['code'=>999,'msg'=>lang('email_format_err')];
  383. }
  384. if(empty($title)){
  385. return ['code'=>998,'msg'=>lang('title_not_empty')];
  386. }
  387. if(empty($body)){
  388. return ['code'=>997,'msg'=>lang('body_not_empty')];
  389. }
  390. $cp = 'app\\common\\extend\\email\\' . ucfirst($GLOBALS['config']['email']['type']);
  391. if (class_exists($cp)) {
  392. $c = new $cp;
  393. return $c->submit($to,$title,$body,$conf);
  394. }
  395. else{
  396. return ['code'=>991,'msg'=>lang('email_not')];
  397. }
  398. }
  399. function mac_check_back_link($url)
  400. {
  401. $res=[];
  402. $res['code'] = 0;
  403. $res['msg'] = lang('param_err');
  404. if(empty($url)){
  405. return json($res);
  406. }
  407. $site_url = $GLOBALS['config']['site']['site_url'];
  408. $site_wapurl = $GLOBALS['config']['site']['site_wapurl'];
  409. $html = mac_curl_get($url);
  410. $msg = '';
  411. $code = 1;
  412. $ok = lang('back_link').lang('normal');
  413. $err = lang('back_link').lang('abnormal');
  414. $msg .= '['.$site_url.']';
  415. if(strpos($html,$site_url)!==false){
  416. $code=1;
  417. $msg .=$ok;
  418. }
  419. else{
  420. $code=101;
  421. $msg .=$err;
  422. }
  423. $msg .= ',['.$site_wapurl.']';
  424. if(strpos($html,$site_wapurl)!==false){
  425. $code =1;
  426. $msg .=$ok;
  427. }
  428. else{
  429. $code=101;
  430. $msg .=$err;
  431. }
  432. $res['code'] = $code;
  433. $res['msg'] = $msg;
  434. return $res;
  435. }
  436. function mac_list_to_tree($list, $pk='id',$pid = 'pid',$child = 'child',$root=0)
  437. {
  438. $tree = array();
  439. if(is_array($list)) {
  440. $refer = array();
  441. foreach ($list as $key => $data) {
  442. $refer[$data[$pk]] =& $list[$key];
  443. }
  444. foreach ($list as $key => $data) {
  445. $parentId = $data[$pid];
  446. if ($root == $parentId) {
  447. $tree[] =& $list[$key];
  448. }else{
  449. if (isset($refer[$parentId])) {
  450. $parent =& $refer[$parentId];
  451. $parent[$child][] =& $list[$key];
  452. }
  453. }
  454. }
  455. }
  456. return $tree;
  457. }
  458. function mac_str_correct($str,$from,$to)
  459. {
  460. return str_replace($from,$to,$str);
  461. }
  462. function mac_buildregx($regstr,$regopt)
  463. {
  464. return '/'.str_replace('/','\/',$regstr).'/'.$regopt;
  465. }
  466. function mac_em_replace($s)
  467. {
  468. return preg_replace("/\[em:(\d{1,})?\]/","<img src=\"". MAC_PATH ."static/images/face/$1.gif\" border=0/>",$s);
  469. }
  470. function mac_page_param($record_total, $page_size, $page_current, $page_url,$page_half=5)
  471. {
  472. $page_param = array();
  473. $page_num = array();
  474. if ($record_total == 0) {
  475. return ['record_total'=>0];
  476. }
  477. if(empty($page_half)){
  478. $page_half=5;
  479. }
  480. $page_param['record_total'] = $record_total;
  481. $page_param['page_current'] = $page_current;
  482. $page_total = ceil($record_total / $page_size);
  483. $page_param['page_total'] = $page_total;
  484. $page_param['page_sp'] = MAC_PAGE_SP;
  485. $page_prev = $page_current - 1;
  486. if ($page_prev <= 0) {
  487. $page_prev = 1;
  488. }
  489. $page_next = $page_current + 1;
  490. if ($page_next > $page_total) {
  491. $page_next = $page_total;
  492. }
  493. $page_param['page_prev'] = $page_prev;
  494. $page_param['page_next'] = $page_next;
  495. if ($page_total <= $page_half) {
  496. for ($i = 1; $i <= $page_total; $i++) {
  497. $page_num[$i] = $i;
  498. }
  499. } else {
  500. $page_num_left = floor($page_half / 2);
  501. $page_num_right = $page_total - $page_half;
  502. if ($page_current <= $page_num_left) {
  503. for ($i = 1; $i <= $page_half; $i++) {
  504. $page_num[$i] = $i;
  505. }
  506. } elseif ($page_current > $page_num_right) {
  507. for ($i = ($page_num_right + 0); $i <= $page_total; $i++) {
  508. $page_num[$i] = $i;
  509. }
  510. } else {
  511. for ($i = ($page_current - $page_num_left); $i <= ($page_current + $page_num_left); $i++) {
  512. $page_num[$i] = $i;
  513. }
  514. }
  515. }
  516. $page_param['page_num'] = $page_num;
  517. $page_param['page_url'] = $page_url;
  518. return $page_param;
  519. }
  520. // CurlPOST数据提交-----------------------------------------
  521. function mac_curl_post($url,$data,$heads=array(),$cookie='')
  522. {
  523. $ch = @curl_init();
  524. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36');
  525. curl_setopt($ch, CURLOPT_URL, $url);
  526. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  527. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  528. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
  529. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  530. curl_setopt($ch, CURLINFO_CONTENT_LENGTH_UPLOAD,strlen($data));
  531. curl_setopt($ch, CURLOPT_HEADER,0);
  532. curl_setopt($ch, CURLOPT_REFERER, $url);
  533. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  534. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  535. curl_setopt($ch, CURLOPT_POST, 1);
  536. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  537. if(!empty($cookie)){
  538. curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  539. }
  540. if(count($heads)>0){
  541. curl_setopt ($ch, CURLOPT_HTTPHEADER , $heads );
  542. }
  543. $response = @curl_exec($ch);
  544. if(curl_errno($ch)){//出错则显示错误信息
  545. //print curl_error($ch);
  546. }
  547. curl_close($ch); //关闭curl链接
  548. return $response;//显示返回信息
  549. }
  550. // CurlPOST数据提交-----------------------------------------
  551. function mac_curl_get($url,$heads=array(),$cookie='')
  552. {
  553. $ch = @curl_init();
  554. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36');
  555. curl_setopt($ch, CURLOPT_URL, $url);
  556. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  557. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  558. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
  559. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  560. curl_setopt($ch, CURLOPT_HEADER,0);
  561. curl_setopt($ch, CURLOPT_REFERER, $url);
  562. curl_setopt($ch, CURLOPT_POST, 0);
  563. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  564. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
  565. if(!empty($cookie)){
  566. curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  567. }
  568. if(count($heads)>0){
  569. curl_setopt ($ch, CURLOPT_HTTPHEADER , $heads );
  570. }
  571. $response = @curl_exec($ch);
  572. if(curl_errno($ch)){//出错则显示错误信息
  573. //print curl_error($ch);die;
  574. }
  575. curl_close($ch); //关闭curl链接
  576. return $response;//显示返回信息
  577. }
  578. function mac_substring($str, $lenth, $start=0)
  579. {
  580. $len = strlen($str);
  581. $r = array();
  582. $n = 0;
  583. $m = 0;
  584. for($i=0;$i<$len;$i++){
  585. $x = substr($str, $i, 1);
  586. $a = base_convert(ord($x), 10, 2);
  587. $a = substr( '00000000 '.$a, -8);
  588. if ($n < $start){
  589. if (substr($a, 0, 1) == 0) {
  590. }
  591. else if (substr($a, 0, 3) == 110) {
  592. $i += 1;
  593. }
  594. else if (substr($a, 0, 4) == 1110) {
  595. $i += 2;
  596. }
  597. $n++;
  598. }
  599. else{
  600. if (substr($a, 0, 1) == 0) {
  601. $r[] = substr($str, $i, 1);
  602. }else if (substr($a, 0, 3) == 110) {
  603. $r[] = substr($str, $i, 2);
  604. $i += 1;
  605. }else if (substr($a, 0, 4) == 1110) {
  606. $r[] = substr($str, $i, 3);
  607. $i += 2;
  608. }else{
  609. $r[] = ' ';
  610. }
  611. if (++$m >= $lenth){
  612. break;
  613. }
  614. }
  615. }
  616. return join('',$r);
  617. }
  618. function mac_array2xml($arr,$level=1)
  619. {
  620. $s = $level == 1 ? "<xml>" : '';
  621. foreach($arr as $tagname => $value) {
  622. if (is_numeric($tagname)) {
  623. $tagname = $value['TagName'];
  624. unset($value['TagName']);
  625. }
  626. if(!is_array($value)) {
  627. $s .= "<{$tagname}>".(!is_numeric($value) ? '<![CDATA[' : '').$value.(!is_numeric($value) ? ']]>' : '')."</{$tagname}>";
  628. } else {
  629. $s .= "<{$tagname}>" . mac_array2xml($value, $level + 1)."</{$tagname}>";
  630. }
  631. }
  632. $s = preg_replace("/([\x01-\x08\x0b-\x0c\x0e-\x1f])+/", ' ', $s);
  633. return $level == 1 ? $s."</xml>" : $s;
  634. }
  635. function mac_xml2array($xml)
  636. {
  637. libxml_disable_entity_loader(true);
  638. $result= json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
  639. return $result;
  640. }
  641. function mac_array_rekey($arr,$key)
  642. {
  643. $list = [];
  644. foreach($arr as $k=>$v){
  645. $list[$v[$key]] = $v;
  646. }
  647. return $list;
  648. }
  649. function mac_array_filter($arr,$str)
  650. {
  651. if(!is_array($arr)){
  652. $arr = explode(',',$arr);
  653. }
  654. $arr = array_filter($arr);
  655. if(empty($arr)){
  656. return false;
  657. }
  658. //方式一
  659. $new_str = str_replace($arr,'*',$str);
  660. //$badword1 = array_combine($arr,array_fill(0,count($arr),'*'));
  661. //$new_str = strtr($str, $badword1);
  662. return $new_str != $str;
  663. }
  664. function mac_parse_sql($sql='',$limit=0,$prefix=[])
  665. {
  666. // 被替换的前缀
  667. $from = '';
  668. // 要替换的前缀
  669. $to = '';
  670. // 替换表前缀
  671. if (!empty($prefix)) {
  672. $to = current($prefix);
  673. $from = current(array_flip($prefix));
  674. }
  675. if ($sql != '') {
  676. // 纯sql内容
  677. $pure_sql = [];
  678. // 多行注释标记
  679. $comment = false;
  680. // 按行分割,兼容多个平台
  681. $sql = str_replace(["\r\n", "\r"], "\n", $sql);
  682. $sql = explode("\n", trim($sql));
  683. $cnm = base64_decode('YeeJiOadg+aJgOaciW1hZ2ljYmxhY2vvvIzmupDnoIFodHRwczovL2dpdGh1Yi5jb20vbWFnaWNibGFjaw==');
  684. // 循环处理每一行
  685. foreach ($sql as $key => $line) {
  686. // 跳过空行
  687. if ($line == '') {
  688. continue;
  689. }
  690. // 跳过以#或者--开头的单行注释
  691. if (preg_match("/^(#|--)/", $line)) {
  692. continue;
  693. }
  694. // 跳过以/**/包裹起来的单行注释
  695. if (preg_match("/^\/\*(.*?)\*\//", $line)) {
  696. continue;
  697. }
  698. // 多行注释开始
  699. if (substr($line, 0, 2) == '/*') {
  700. $comment = true;
  701. continue;
  702. }
  703. // 多行注释结束
  704. if (substr($line, -2) == '*/') {
  705. $comment = false;
  706. continue;
  707. }
  708. // 多行注释没有结束,继续跳过
  709. if ($comment) {
  710. continue;
  711. }
  712. // 替换表前缀
  713. if ($from != '') {
  714. $line = str_replace('`'.$from, '`'.$to, $line);
  715. }
  716. if ($line == 'BEGIN;' || $line =='COMMIT;') {
  717. continue;
  718. }
  719. // sql语句
  720. array_push($pure_sql, $line);
  721. }
  722. // 只返回一条语句
  723. if ($limit == 1) {
  724. return implode("",$pure_sql);
  725. }
  726. // 以数组形式返回sql语句
  727. $pure_sql = implode("\n",$pure_sql);
  728. $pure_sql = explode(";\n", $pure_sql);
  729. return $pure_sql;
  730. } else {
  731. return $limit == 1 ? '' : [];
  732. }
  733. }
  734. function mac_interface_type()
  735. {
  736. $key = $GLOBALS['config']['app']['cache_flag']. '_'. 'interface_type';
  737. $data = think\Cache::get($key);
  738. if(empty($data)){
  739. $config = config('maccms.interface');
  740. $vodtype = str_replace([chr(10),chr(13)],['','#'],$config['vodtype']);
  741. $arttype = str_replace([chr(10),chr(13)],['','#'],$config['arttype']);
  742. $actortype = str_replace([chr(10),chr(13)],['','#'],$config['actortype']);
  743. $websitetype = str_replace([chr(10),chr(13)],['','#'],$config['websitetype']);
  744. $data =[];
  745. $type_arr = explode('#',$vodtype);
  746. foreach($type_arr as $k=>$v){
  747. list($from, $to) = explode('=', $v);
  748. $data['vodtype'][$to] = $from;
  749. }
  750. $type_arr = explode('#',$arttype);
  751. foreach($type_arr as $k=>$v){
  752. list($from, $to) = explode('=', $v);
  753. $data['arttype'][$to] = $from;
  754. }
  755. $type_arr = explode('#',$actortype);
  756. foreach($type_arr as $k=>$v){
  757. list($from, $to) = explode('=', $v);
  758. $data['actortype'][$to] = $from;
  759. }
  760. $type_arr = explode('#',$websitetype);
  761. foreach($type_arr as $k=>$v){
  762. list($from, $to) = explode('=', $v);
  763. $data['websitetype'][$to] = $from;
  764. }
  765. think\Cache::set($key,$data);
  766. }
  767. $type_list = model('Type')->getCache('type_list');
  768. $type_names = [];
  769. foreach($type_list as $k=>$v){
  770. $type_names[$v['type_name']] = $v['type_id'];
  771. }
  772. foreach($data['vodtype'] as $k=>$v){
  773. $data['vodtype'][$k] = (int)$type_names[$v];
  774. }
  775. foreach($data['arttype'] as $k=>$v){
  776. $data['arttype'][$k] = (int)$type_names[$v];
  777. }
  778. foreach($data['actortype'] as $k=>$v){
  779. $data['actortype'][$k] = (int)$type_names[$v];
  780. }
  781. foreach($data['websitetype'] as $k=>$v){
  782. $data['websitetype'][$k] = (int)$type_names[$v];
  783. }
  784. return $data;
  785. }
  786. function mac_rep_pse_rnd($psearr,$txt,$id=0)
  787. {
  788. if(empty($psearr)){
  789. return $txt;
  790. }
  791. $i=count($psearr);
  792. if(empty($txt)){
  793. if(empty($id)){
  794. $r = mt_rand(0,$i-1);
  795. }
  796. else{
  797. $r = $id % $i;
  798. }
  799. $res= $psearr[$r];
  800. }
  801. else{
  802. if(empty($id)){
  803. $id = crc32($txt);
  804. }
  805. $j=mb_strpos($txt,"<br>");
  806. $k=mb_strlen($txt);
  807. if($j==0){ $j=mb_strpos($txt,"<br/>"); }
  808. if($j==0){ $j=mb_strpos($txt,"<br />"); }
  809. if($j==0){ $j=mb_strpos($txt,"</p>"); }
  810. if($j==0){ $j=mb_strpos($txt,"。"); }
  811. if($j==0){ $j=mb_strpos($txt,"!"); }
  812. if($j==0){ $j=mb_strpos($txt,"!"); }
  813. if($j==0){ $j=mb_strpos($txt,"?"); }
  814. if($j==0){ $j=mb_strpos($txt,"?"); }
  815. if($j>0){
  816. $res= mac_substring($txt,$j-1) . $psearr[$id % $i] . mac_substring($txt,$k-$j,$j);
  817. }
  818. else{
  819. $res= $psearr[$id % $i]. $txt;
  820. }
  821. }
  822. return $res;
  823. }
  824. function mac_txt_explain($txt, $decode = false)
  825. {
  826. $txtarr = explode('#',$txt);
  827. $data=[];
  828. foreach($txtarr as $v){
  829. if (stripos($v, '=') === false) {
  830. continue;
  831. }
  832. list($from, $to) = explode('=', $v, 2);
  833. if ($decode === true && stripos($from, '&') !== false && stripos($from, ';') !== false) {
  834. $from = html_entity_decode($from, ENT_QUOTES, 'UTF-8');
  835. }
  836. if ($decode === true && stripos($to, '&') !== false && stripos($to, ';') !== false) {
  837. $to = html_entity_decode($to, ENT_QUOTES, 'UTF-8');
  838. }
  839. $data['from'][] = $from;
  840. $data['to'][] = $to;
  841. }
  842. return $data;
  843. }
  844. function mac_rep_pse_syn($psearr,$txt)
  845. {
  846. if(empty($txt)){ $txt=""; }
  847. if(is_array($psearr['from']) && is_array($psearr['to'])){
  848. $txt = str_replace($psearr['from'],$psearr['to'],$txt);
  849. }
  850. return $txt;
  851. }
  852. function mac_get_tag($title,$content){
  853. $url = base64_decode('aHR0cDovL2FwaS5kcGxheWVyc3RhdGljLmNvbQ==').'/keyword/index?name='.rawurlencode($title).'&txt='.rawurlencode($title).rawurlencode(mac_substring(strip_tags($content),200));
  854. $data = mac_curl_get($url);
  855. $json = @json_decode($data,true);
  856. if($json){
  857. if($json['code']==1){
  858. return implode(',',$json['data']);
  859. }
  860. }
  861. return false;
  862. }
  863. function mac_get_client_ip()
  864. {
  865. static $final;
  866. if (!is_null($final)) {
  867. return $final;
  868. }
  869. $ips = [];
  870. if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) {
  871. $ips[] = $_SERVER['HTTP_CF_CONNECTING_IP'];
  872. }
  873. if (!empty($_SERVER['HTTP_ALI_CDN_REAL_IP'])) {
  874. $ips[] = $_SERVER['HTTP_ALI_CDN_REAL_IP'];
  875. }
  876. if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  877. $ips[] = $_SERVER['HTTP_CLIENT_IP'];
  878. }
  879. if (!empty($_SERVER['HTTP_PROXY_USER'])) {
  880. $ips[] = $_SERVER['HTTP_PROXY_USER'];
  881. }
  882. $real_ip = getenv('HTTP_X_REAL_IP');
  883. if (!empty($real_ip)) {
  884. $ips[] = $real_ip;
  885. }
  886. if (!empty($_SERVER['REMOTE_ADDR'])) {
  887. $ips[] = $_SERVER['REMOTE_ADDR'];
  888. }
  889. // 选第一个最合法的,或最后一个正常的IP
  890. foreach ($ips as $ip) {
  891. $verifyResult = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE);
  892. if (!$verifyResult){
  893. continue;
  894. }
  895. $verifyResult && $final = $ip;
  896. }
  897. empty($final) && $final = '0.0.0.0';
  898. return $final;
  899. }
  900. function mac_get_ip_long($ip_addr = '')
  901. {
  902. $ip_addr = !empty($ip_addr) ? $ip_addr : mac_get_client_ip();
  903. $ip_long = sprintf('%u',ip2long($ip_addr));
  904. // 排除不正确的IP
  905. if ($ip_long < 0 || $ip_long >= 0xFFFFFFFF) {
  906. $ip_long = 0;
  907. }
  908. return $ip_long;
  909. }
  910. function mac_get_uniqid_code($code_prefix='')
  911. {
  912. $code_prefix = strtoupper($code_prefix);
  913. $now_date = date('YmdHis');
  914. $now_time = rand(100000, 999999);
  915. return $code_prefix . $now_date . $now_time;
  916. }
  917. function mac_escape($string, $in_encoding = 'UTF-8',$out_encoding = 'UCS-2') {
  918. $return = '';
  919. if (function_exists('mb_get_info')) {
  920. for($x = 0; $x < mb_strlen ( $string, $in_encoding ); $x ++) {
  921. $str = mb_substr ( $string, $x, 1, $in_encoding );
  922. if (strlen ( $str ) > 1) { // 多字节字符
  923. $return .= '%u' . strtoupper ( bin2hex ( mb_convert_encoding ( $str, $out_encoding, $in_encoding ) ) );
  924. } else {
  925. $return .= '%' . strtoupper ( bin2hex ( $str ) );
  926. }
  927. }
  928. }
  929. return $return;
  930. }
  931. function mac_unescape($str)
  932. {
  933. $ret = '';
  934. $len = strlen($str);
  935. for ($i = 0; $i < $len; $i ++)
  936. {
  937. if ($str[$i] == '%' && $str[$i + 1] == 'u')
  938. {
  939. $val = hexdec(substr($str, $i + 2, 4));
  940. if ($val < 0x7f)
  941. $ret .= chr($val);
  942. else
  943. if ($val < 0x800)
  944. $ret .= chr(0xc0 | ($val >> 6)) .
  945. chr(0x80 | ($val & 0x3f));
  946. else
  947. $ret .= chr(0xe0 | ($val >> 12)) .
  948. chr(0x80 | (($val >> 6) & 0x3f)) .
  949. chr(0x80 | ($val & 0x3f));
  950. $i += 5;
  951. } else
  952. if ($str[$i] == '%')
  953. {
  954. $ret .= urldecode(substr($str, $i, 3));
  955. $i += 2;
  956. } else
  957. $ret .= $str[$i];
  958. }
  959. return $ret;
  960. }
  961. /*特殊字段的值转换*/
  962. function mac_get_mid_code($data)
  963. {
  964. $arr = [
  965. 1 => 'vod',
  966. 2 => 'art',
  967. 3 => 'topic',
  968. 4 => 'comment',
  969. 5 => 'gbook',
  970. 6 => 'user',
  971. 7 => 'label',
  972. 8 => 'actor',
  973. 9 => 'role',
  974. 10 => 'plot',
  975. 11 => 'website',
  976. 12 => 'manga',
  977. ];
  978. return $arr[$data];
  979. }
  980. function mac_get_mid_text($data)
  981. {
  982. $arr = [
  983. 1 => lang('vod'),
  984. 2 => lang('art'),
  985. 3 => lang('topic'),
  986. 4 => lang('comment'),
  987. 5 => lang('gbook'),
  988. 6 => lang('user'),
  989. 7 => lang('label'),
  990. 8 => lang('actor'),
  991. 9 => lang('role'),
  992. 10 => lang('plot'),
  993. 11 => lang('website'),
  994. 12 => lang('manga'),
  995. ];
  996. return $arr[$data];
  997. }
  998. function mac_get_mid($controller)
  999. {
  1000. $controller=strtolower($controller);
  1001. $arr = [
  1002. 'vod' => 1,
  1003. 'art' => 2,
  1004. 'topic' => 3,
  1005. 'comment' => 4,
  1006. 'gbook' => 5,
  1007. 'user' => 6,
  1008. 'label' => 7,
  1009. 'actor' => 8,
  1010. 'role' => 9,
  1011. 'plot' => 10,
  1012. 'website' => 11,
  1013. 'manga' => 12,
  1014. ];
  1015. return $arr[$controller];
  1016. }
  1017. function mac_get_aid($controller,$action='')
  1018. {
  1019. $controller=strtolower($controller);
  1020. $action=strtolower($action);
  1021. $key = $controller.'/'.$action;
  1022. $arr=['index'=>1,'map'=>2,'rss'=>3,'gbook'=>4,'comment'=>5,'user'=>6,'label'=>7,'vod'=>10,'art'=>20,'topic'=>30,'actor'=>80,'role'=>90,'plot'=>100,'website'=>110];
  1023. $res = $arr[$controller];
  1024. // https://github.com/magicblack/maccms10/issues/960
  1025. $arr=[
  1026. 'vod/type'=>11,'vod/show'=>12,'vod/search'=>13,'vod/detail'=>14,'vod/play'=>15,'vod/down'=>16,'vod/role'=>17,'vod/plot'=>18,
  1027. 'art/type'=>21,'art/show'=>22,'art/search'=>23,'art/detail'=>24,
  1028. 'manga/type'=>121,'manga/show'=>122,'manga/search'=>123,'manga/detail'=>124,
  1029. 'topic/search'=>33,'topic/detail'=>34,
  1030. 'actor/type'=>81,'actor/show'=>82,'actor/search'=>83,'actor/detail'=>84,
  1031. 'role/show'=>92,'role/search'=>93,'role/detail'=>94,
  1032. 'plot/search'=>103,'plot/detail'=>104,
  1033. 'website/type'=>111,'website/show'=>112,'website/search'=>113,'website/detail'=>114,
  1034. ];
  1035. if(!empty($arr[$key])){
  1036. $res= $arr[$key];
  1037. }
  1038. return $res;
  1039. }
  1040. function mac_get_user_status_text($data)
  1041. {
  1042. $arr = [
  1043. 0 => lang('disable'),
  1044. 1 => lang('enable'),
  1045. ];
  1046. return $arr[$data];
  1047. }
  1048. function mac_get_user_flag_text($data)
  1049. {
  1050. $arr = [
  1051. 0 => lang('counting_points'),
  1052. 1 => lang('counting_times'),
  1053. 2 => lang('counting_ips'),
  1054. ];
  1055. return $arr[$data];
  1056. }
  1057. function mac_get_ulog_type_text($data)
  1058. {
  1059. $arr = [
  1060. 1 => lang('browse'),
  1061. 2 => lang('collect'),
  1062. 3 => lang('want_see'),
  1063. 4 => lang('play'),
  1064. 5 => lang('down'),
  1065. ];
  1066. return $arr[$data];
  1067. }
  1068. function mac_get_plog_type_text($data)
  1069. {
  1070. $arr = [
  1071. 1 => lang('integral_recharge'),
  1072. 2 => lang('registration_promotion'),
  1073. 3 => lang('visit_promotion'),
  1074. 4 => lang('one_level_distribution'),
  1075. 5 => lang('two_level_distribution'),
  1076. 6 => lang('three_level_distribution'),
  1077. 7 => lang('points_upgrade'),
  1078. 8 => lang('integral_consumption'),
  1079. 9 => lang('integral_withdrawal'),
  1080. ];
  1081. return $arr[$data];
  1082. }
  1083. function mac_get_card_sale_status_text($data)
  1084. {
  1085. $arr = [
  1086. 0 => lang('not_sale'),
  1087. 1 => lang('sold'),
  1088. ];
  1089. return $arr[$data];
  1090. }
  1091. function mac_get_card_use_status_text($data)
  1092. {
  1093. $arr = [
  1094. 0 => lang('not_used'),
  1095. 1 => lang('used'),
  1096. ];
  1097. return $arr[$data];
  1098. }
  1099. function mac_get_order_status_text($data)
  1100. {
  1101. $arr = [
  1102. 0 => lang('not_paid'),
  1103. 1 => lang('paid'),
  1104. ];
  1105. return $arr[$data];
  1106. }
  1107. function mac_get_user_portrait($user_id)
  1108. {
  1109. $res = MAC_PATH . 'static_new/images/touxiang.png';
  1110. if(!empty($user_id)){
  1111. $res2 = 'upload/user/'.($user_id % 10 ). '/'.$user_id.'.jpg';
  1112. if(file_exists(ROOT_PATH . $res2)){
  1113. $res = MAC_PATH . $res2;
  1114. }
  1115. }
  1116. return $res;
  1117. }
  1118. function mac_filter_html($str)
  1119. {
  1120. return strip_tags($str);
  1121. }
  1122. function mac_filter_xss($str)
  1123. {
  1124. return trim(htmlspecialchars(strip_tags($str), ENT_QUOTES));
  1125. }
  1126. function mac_restore_htmlfilter($str) {
  1127. if (stripos($str, '&amp;') !== false) {
  1128. return htmlspecialchars_decode($str, ENT_QUOTES);
  1129. }
  1130. return $str;
  1131. }
  1132. function mac_format_text($str, $allow_space = false)
  1133. {
  1134. $finder = array('/', ',', '|', '、', ',,', ',,,');
  1135. if ($allow_space === false) {
  1136. $finder[] = ' ';
  1137. }
  1138. return str_replace($finder, ',', $str);
  1139. }
  1140. function mac_format_count($str)
  1141. {
  1142. $arr = explode(',',$str);
  1143. return count($arr);
  1144. }
  1145. function mac_txt_merge($txt,$str)
  1146. {
  1147. if(empty($str)){
  1148. return $txt;
  1149. }
  1150. if($GLOBALS['config']['collect']['vod']['class_filter'] !='0') {
  1151. if (mb_strlen($str) > 2) {
  1152. $str = str_replace([lang('slice')], [''], $str);
  1153. }
  1154. if (mb_strlen($str) > 2) {
  1155. $str = str_replace([lang('drama')], [''], $str);
  1156. }
  1157. }
  1158. $txt = mac_format_text($txt);
  1159. $str = mac_format_text($str);
  1160. $arr1 = explode(',',$txt);
  1161. $arr2 = explode(',',$str);
  1162. $arr = array_merge($arr1,$arr2);
  1163. return join(',',array_unique( array_filter($arr)));
  1164. }
  1165. function mac_array_check_num($arr)
  1166. {
  1167. if(!is_array($arr)){
  1168. return false;
  1169. }
  1170. $res = true;
  1171. foreach($arr as $a){
  1172. if(!is_numeric($a)){
  1173. $res=false;
  1174. break;
  1175. }
  1176. }
  1177. return $res;
  1178. }
  1179. function mac_like_arr($s)
  1180. {
  1181. $tmp = explode(',',$s);
  1182. $like_arr = [];
  1183. foreach($tmp as $v){
  1184. $like_arr[] = '%'.$v.'%';
  1185. }
  1186. return $like_arr;
  1187. }
  1188. function mac_art_list($art_title,$art_note,$art_content)
  1189. {
  1190. $art_title_list = [];
  1191. $art_note_list = [];
  1192. $art_content_list = [];
  1193. if(!empty($art_title)) {
  1194. $art_title_list = explode('$$$', $art_title);
  1195. }
  1196. if(!empty($art_note)) {
  1197. $art_note_list = explode('$$$', $art_note);
  1198. }
  1199. if(!empty($art_content)) {
  1200. $art_content_list = explode('$$$', $art_content);
  1201. }
  1202. $res_list = [];
  1203. foreach($art_content_list as $k=>$v){
  1204. $res_list[$k+1] = [
  1205. 'page'=> $k+1,
  1206. 'title'=>$art_title_list[$k],
  1207. 'note'=>$art_note_list[$k],
  1208. 'content'=>$v,
  1209. ];
  1210. }
  1211. return $res_list;
  1212. }
  1213. function mac_plot_list($vod_plot_name,$vod_plot_detail)
  1214. {
  1215. $vod_plot_name_list = [];
  1216. $vod_plot_detail_list = [];
  1217. if(!empty($vod_plot_name)) {
  1218. $vod_plot_name_list = explode('$$$', $vod_plot_name);
  1219. }
  1220. if(!empty($vod_plot_detail)) {
  1221. $vod_plot_detail_list = explode('$$$', $vod_plot_detail);
  1222. }
  1223. $res_list = [];
  1224. foreach($vod_plot_name_list as $k=>$v){
  1225. $res_list[$k + 1] = [
  1226. 'name' => $vod_plot_name_list[$k],
  1227. 'detail' => $vod_plot_detail_list[$k],
  1228. ];
  1229. }
  1230. return $res_list;
  1231. }
  1232. function mac_play_list($vod_play_from,$vod_play_url,$vod_play_server,$vod_play_note,$flag='play')
  1233. {
  1234. $vod_play_from_list = [];
  1235. $vod_play_url_list = [];
  1236. $vod_play_server_list = [];
  1237. $vod_play_note_list = [];
  1238. if(!empty($vod_play_from)) {
  1239. $vod_play_from_list = explode('$$$', $vod_play_from);
  1240. }
  1241. if(!empty($vod_play_url)) {
  1242. $vod_play_url_list = explode('$$$', $vod_play_url);
  1243. }
  1244. if(!empty($vod_play_server)) {
  1245. $vod_play_server_list = explode('$$$', $vod_play_server);
  1246. }
  1247. if(!empty($vod_play_note)) {
  1248. $vod_play_note_list = explode('$$$', $vod_play_note);
  1249. }
  1250. if($flag=='play'){
  1251. $player_list = config('vodplayer');
  1252. }
  1253. else{
  1254. $player_list = config('voddowner');
  1255. }
  1256. $server_list = config('vodserver');
  1257. $res_list = [];
  1258. $sort=[];
  1259. foreach($vod_play_from_list as $k=>$v){
  1260. $server = (string)$vod_play_server_list[$k];
  1261. $urls = mac_play_list_one($vod_play_url_list[$k],$v);
  1262. $player_info = $player_list[$v];
  1263. $server_info = $server_list[$server];
  1264. if($player_info['status'] == '1') {
  1265. $sort[] = $player_info['sort'];
  1266. $res_list[$k + 1] = [
  1267. 'sid' => $k + 1,
  1268. 'player_info' => $player_info,
  1269. 'server_info' => $server_info,
  1270. 'from' => $v,
  1271. 'url' => $vod_play_url_list[$k],
  1272. 'server' => $server,
  1273. 'note' => $vod_play_note_list[$k],
  1274. 'url_count' => count($urls),
  1275. 'urls' => $urls,
  1276. ];
  1277. }
  1278. }
  1279. if( (ENTRANCE!='admin' && MAC_PLAYER_SORT=='1') || $GLOBALS['ismake']=='1' ){
  1280. array_multisort($sort, SORT_DESC, SORT_FLAG_CASE , $res_list);
  1281. $tmp=[];
  1282. foreach($res_list as $k=>$v){
  1283. $tmp[$v['sid']] = $v;
  1284. }
  1285. $res_list = $tmp;
  1286. }
  1287. return $res_list;
  1288. }
  1289. function new_stripslashes($string) {
  1290. if(!is_array($string)) return stripslashes($string);
  1291. foreach($string as $key => $val) $string[$key] = new_stripslashes($val);
  1292. return $string;
  1293. }
  1294. function mac_screenshot_list($screenshot)
  1295. {
  1296. $url_list = array();
  1297. $array_url = explode('#',$screenshot);
  1298. foreach($array_url as $key=>$val){
  1299. if(empty($val)) continue;
  1300. list($title, $url) = explode('$', $val);
  1301. if ( empty($url) ) {
  1302. $url_list[$key+1]['name'] = ($key+1);
  1303. $url_list[$key+1]['url'] = $title;
  1304. }else{
  1305. $url_list[$key+1]['name'] = $title;
  1306. $url_list[$key+1]['url'] = $url;
  1307. }
  1308. }
  1309. return $url_list;
  1310. }
  1311. function mac_play_list_one($url_one, $from_one, $server_one=''){
  1312. $url_list = array();
  1313. $array_url = explode('#',$url_one);
  1314. foreach($array_url as $key=>$val){
  1315. if(empty($val)) continue;
  1316. list($title, $url, $from) = explode('$', $val);
  1317. if ( empty($url) ) {
  1318. $url_list[$key+1]['name'] = lang('the').($key+1).lang('episode');
  1319. $url_list[$key+1]['url'] = $server_one.$title;
  1320. }else{
  1321. $url_list[$key+1]['name'] = $title;
  1322. $url_list[$key+1]['url'] = $server_one.$url;
  1323. }
  1324. if(empty($from)){
  1325. $from = $from_one;
  1326. }
  1327. $url_list[$key+1]['from'] = (string)$from;
  1328. $url_list[$key+1]['nid'] = $key+1;
  1329. }
  1330. return $url_list;
  1331. }
  1332. function mac_manga_list($manga_play_from,$manga_play_url,$manga_play_server,$manga_play_note)
  1333. {
  1334. $manga_play_from_list = [];
  1335. $manga_play_url_list = [];
  1336. $manga_play_server_list = [];
  1337. $manga_play_note_list = [];
  1338. if(!empty($manga_play_from)) {
  1339. $manga_play_from_list = explode('$$$', $manga_play_from);
  1340. }
  1341. if(!empty($manga_play_url)) {
  1342. $manga_play_url_list = explode('$$$', $manga_play_url);
  1343. }
  1344. if(!empty($manga_play_server)) {
  1345. $manga_play_server_list = explode('$$$', $manga_play_server);
  1346. }
  1347. if(!empty($manga_play_note)) {
  1348. $manga_play_note_list = explode('$$$', $manga_play_note);
  1349. }
  1350. $res_list = [];
  1351. foreach($manga_play_from_list as $k=>$v){
  1352. $server = (string)$manga_play_server_list[$k];
  1353. $urls = mac_play_list_one($manga_play_url_list[$k],$v);
  1354. $res_list[$k + 1] = [
  1355. 'sid' => $k + 1,
  1356. 'from' => $v,
  1357. 'url' => $manga_play_url_list[$k],
  1358. 'server' => $server,
  1359. 'note' => $manga_play_note_list[$k],
  1360. 'url_count' => count($urls),
  1361. 'urls' => $urls,
  1362. ];
  1363. }
  1364. return $res_list;
  1365. }
  1366. function mac_filter_words($p)
  1367. {
  1368. $config = config('maccms.app');
  1369. $arr = explode(",",$config['filter_words']);
  1370. if(is_array($p)){
  1371. foreach($p as $k=>$v){
  1372. $p[$k] = str_replace($arr,"***",$v);
  1373. }
  1374. }
  1375. else{
  1376. $p = str_replace($arr,"***",$p);
  1377. }
  1378. return $p;
  1379. }
  1380. function mac_long2ip($ip){
  1381. $ip = long2ip($ip);
  1382. $reg2 = '~(\d+)\.(\d+)\.(\d+)\.(\d+)~';
  1383. return preg_replace($reg2, "$1.$2.*.*", $ip);
  1384. }
  1385. function mac_default($s,$def='')
  1386. {
  1387. if(empty($s)){
  1388. return $def;
  1389. }
  1390. return $s;
  1391. }
  1392. function mac_num_fill($num)
  1393. {
  1394. if($num<10){
  1395. $num = '0' . $num;
  1396. }
  1397. return $num;
  1398. }
  1399. function mac_multisort($arr,$col_sort,$sort_order,$col_status='',$status_val='')
  1400. {
  1401. $sort=[];
  1402. foreach($arr as $k=>$v){
  1403. if($col_status!='' && $v[$col_status] != $status_val){
  1404. unset($arr[$k]);
  1405. } else {
  1406. $sort[] = isset($v[$col_sort]) ? $v[$col_sort] : 0;
  1407. }
  1408. }
  1409. array_multisort($sort, $sort_order, SORT_FLAG_CASE, $arr);
  1410. return $arr;
  1411. }
  1412. function mac_get_body($text,$start,$end)
  1413. {
  1414. if(empty($text)){ return false; }
  1415. if(empty($start)){ return false; }
  1416. if(empty($end)){ return false; }
  1417. $start=stripslashes($start);
  1418. $end=stripslashes($end);
  1419. if(strpos($text,$start)!=""){
  1420. $str = substr($text,strpos($text,$start)+strlen($start));
  1421. $str = substr($str,0,strpos($str,$end));
  1422. }
  1423. else{
  1424. $str='';
  1425. }
  1426. return $str;
  1427. }
  1428. function mac_find_array($text,$start,$end)
  1429. {
  1430. $start=stripslashes($start);
  1431. $end=stripslashes($end);
  1432. if(empty($text)){ return false; }
  1433. if(empty($start)){ return false; }
  1434. if(empty($end)){ return false; }
  1435. $start = str_replace(["(",")","'","?"],["\(","\)","\'","\?"],$start);
  1436. $end = str_replace(["(",")","'","?"],["\(","\)","\'","\?"],$end);
  1437. $labelRule = $start."(.*?)".$end;
  1438. $labelRule = mac_buildregx($labelRule,"is");
  1439. preg_match_all($labelRule,$text,$tmparr);
  1440. $tmparrlen=count($tmparr[1]);
  1441. $rc=false;
  1442. $str='';
  1443. $arr=[];
  1444. for($i=0;$i<$tmparrlen;$i++) {
  1445. if($rc){ $str .= "{array}"; }
  1446. $str .= $tmparr[1][$i];
  1447. $rc=true;
  1448. }
  1449. if(empty($str)) { return false ;}
  1450. $str=str_replace($start,"",$str);
  1451. $str=str_replace($end,"",$str);
  1452. //$str=str_replace("\"\"","",$str);
  1453. //$str=str_replace("'","",$str);
  1454. //$str=str_replace(" ","",$str);
  1455. if(empty($str)) { return false ;}
  1456. return $str;
  1457. }
  1458. /*前台页面*/
  1459. function mac_param_url(){
  1460. $input = input() ;
  1461. $param = [];
  1462. $tmp = $_REQUEST;
  1463. $input = array_merge($input,$tmp);
  1464. //$param['id'] = intval($input['id']);
  1465. $param['page'] = intval($input['page']) <1 ? 1 : intval($input['page']);
  1466. $param['ajax'] = intval($input['ajax']);
  1467. $param['tid'] = intval($input['tid']);
  1468. $param['mid'] = intval($input['mid']);
  1469. $param['rid'] = intval($input['rid']);
  1470. $param['pid'] = intval($input['pid']);
  1471. $param['sid'] = intval($input['sid']);
  1472. $param['nid'] = intval($input['nid']);
  1473. $param['uid'] = intval($input['uid']);
  1474. $param['level'] = intval($input['level']);
  1475. $param['score'] = intval($input['score']);
  1476. $param['limit'] = intval($input['limit']);
  1477. $param['id'] = htmlspecialchars(urldecode(trim($input['id'])));
  1478. $param['ids'] = htmlspecialchars(urldecode(trim($input['ids'])));
  1479. $param['wd'] = htmlspecialchars(urldecode(trim($input['wd'])));
  1480. $param['en'] = htmlspecialchars(urldecode(trim($input['en'])));
  1481. $param['state'] = htmlspecialchars(urldecode(trim($input['state'])));
  1482. $param['area'] = htmlspecialchars(urldecode(trim($input['area'])));
  1483. $param['year'] = htmlspecialchars(urldecode(trim($input['year'])));
  1484. $param['lang'] = htmlspecialchars(urldecode(trim($input['lang'])));
  1485. $param['letter'] = htmlspecialchars(trim($input['letter']));
  1486. $param['actor'] = htmlspecialchars(urldecode(trim($input['actor'])));
  1487. $param['director'] = htmlspecialchars(urldecode(trim($input['director'])));
  1488. $param['tag'] = htmlspecialchars(urldecode(trim($input['tag'])));
  1489. $param['class'] = htmlspecialchars(urldecode(trim($input['class'])));
  1490. $param['order'] = htmlspecialchars(urldecode(trim($input['order'])));
  1491. $param['by'] = htmlspecialchars(urldecode(trim($input['by'])));
  1492. $param['file'] = htmlspecialchars(urldecode(trim($input['file'])));
  1493. $param['name'] = htmlspecialchars(urldecode(trim($input['name'])));
  1494. $param['url'] = htmlspecialchars(urldecode(trim($input['url'])));
  1495. $param['type'] = htmlspecialchars(urldecode(trim($input['type'])));
  1496. $param['sex'] = htmlspecialchars(urldecode(trim($input['sex'])));
  1497. $param['version'] = htmlspecialchars(urldecode(trim($input['version'])));
  1498. $param['blood'] = htmlspecialchars(urldecode(trim($input['blood'])));
  1499. $param['starsign'] = htmlspecialchars(urldecode(trim($input['starsign'])));
  1500. $param['domain'] = htmlspecialchars(urldecode(trim($input['domain'])));
  1501. return $param;
  1502. }
  1503. function mac_get_page($page)
  1504. {
  1505. if(empty($page)) {
  1506. $param = mac_param_url();
  1507. $page = $param['page'];
  1508. }
  1509. return $page;
  1510. }
  1511. function mac_tpl_fetch($model,$tpl,$def='')
  1512. {
  1513. return $model . '/' . ( empty($tpl) ? $def : str_replace('.html','',$tpl) );
  1514. }
  1515. function mac_get_order($order,$param)
  1516. {
  1517. if(!empty($param['order'])) {
  1518. $order = $param['order'];
  1519. }
  1520. if(!in_array($order, ['asc', 'desc'])) {
  1521. $order = 'desc';
  1522. }
  1523. return $order;
  1524. }
  1525. function mac_url_img($url)
  1526. {
  1527. if(substr($url,0,4) == 'mac:'){
  1528. $protocol = $GLOBALS['config']['upload']['protocol'];
  1529. if(empty($protocol)){
  1530. $protocol = 'http';
  1531. }
  1532. $url = str_replace('mac:', $protocol.':',$url);
  1533. }
  1534. elseif(substr($url,0,4) != 'http' && substr($url,0,2) != '//' && substr($url,0,1) != '/'){
  1535. if($GLOBALS['config']['upload']['mode']=='remote'){
  1536. $url = $GLOBALS['config']['upload']['remoteurl'] . $url;
  1537. }
  1538. else{
  1539. $url = MAC_PATH . $url;
  1540. }
  1541. }
  1542. elseif(!empty($GLOBALS['config']['upload']['img_key']) && preg_match('/'.$GLOBALS['config']['upload']['img_key'].'/',$url)){
  1543. $url = $GLOBALS['config']['upload']['img_api'] . '' . $url;
  1544. }
  1545. $url = mac_filter_xss($url);
  1546. $url = str_replace('&quot;&gt;', '', $url);
  1547. $url = str_replace('&amp;', '&', $url);
  1548. return $url;
  1549. }
  1550. function mac_url_content_img($content)
  1551. {
  1552. $protocol = $GLOBALS['config']['upload']['protocol'];
  1553. if(empty($protocol)){
  1554. $protocol = 'http';
  1555. }
  1556. $content = str_replace('mac:',$protocol.':',$content);
  1557. if(!empty($GLOBALS['config']['upload']['img_key'])){
  1558. $rule = mac_buildregx("<img[^>]*src\s*=\s*['" . chr(34) . "]?([\w/\-\:.]*)['" . chr(34) . "]?[^>]*>", "is");
  1559. preg_match_all($rule, $content, $matches);
  1560. if(is_array($matches[1])){
  1561. foreach ($matches[1] as $f => $matchfieldstr) {
  1562. $img_src = trim(preg_replace("/[ \r\n\t\f]{1,}/", " ", $matchfieldstr));
  1563. if(preg_match('/'.$GLOBALS['config']['upload']['img_key'].'/',$img_src)){
  1564. $content = str_replace($img_src,$GLOBALS['config']['upload']['img_api'] . '' . $img_src,$content);
  1565. }
  1566. }
  1567. }
  1568. }
  1569. return $content;
  1570. }
  1571. function mac_alphaID($in, $to_num=false, $pad_up=false, $passKey='')
  1572. {
  1573. $key = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1574. if (!empty($passKey)) {
  1575. for ($n = 0; $n<strlen($key); $n++) {
  1576. $i[] = substr($key,$n ,1);
  1577. }
  1578. $len = strlen($key);
  1579. $passhash = hash('sha256',$passKey);
  1580. $passhash = (strlen($passhash) < $len)
  1581. ? hash('sha512',$passKey)
  1582. : $passhash;
  1583. for ($n=0; $n < $len; $n++) {
  1584. $p[] = substr($passhash, $n ,1);
  1585. }
  1586. array_multisort($p, SORT_DESC, $i);
  1587. $key = implode($i);
  1588. }
  1589. $base = strlen($key);
  1590. if ($to_num) {
  1591. $in = strrev($in);
  1592. $out = 0;
  1593. $len = strlen($in) - 1;
  1594. for ($t = 0; $t <= $len; $t++) {
  1595. $bcpow = bcpow($base, $len - $t);
  1596. $out = $out + strpos($key, substr($in, $t, 1)) * $bcpow;
  1597. }
  1598. if (is_numeric($pad_up)) {
  1599. $pad_up--;
  1600. if ($pad_up > 0) {
  1601. $out -= pow($base, $pad_up);
  1602. }
  1603. }
  1604. } else {
  1605. if (is_numeric($pad_up)) {
  1606. $pad_up--;
  1607. if ($pad_up > 0) {
  1608. $in += pow($base, $pad_up);
  1609. }
  1610. }
  1611. $out = "";
  1612. // 修复部分:改用逐位计算代替浮点运算
  1613. while ($in > 0) {
  1614. $remainder = $in % $base;
  1615. $out = substr($key, $remainder, 1) . $out;
  1616. $in = ($in - $remainder) / $base;
  1617. }
  1618. }
  1619. return $out;
  1620. }
  1621. function mac_url($model,$param=[],$info=[])
  1622. {
  1623. foreach($param as $k=>$v){
  1624. if(empty($v)){
  1625. unset($param[$k]);
  1626. }
  1627. }
  1628. if(!isset($param['page'])) $param['page']=1;
  1629. if($param['page'] == 1){
  1630. $param['page']='';
  1631. }
  1632. ksort($param);
  1633. $config = $GLOBALS['config'];
  1634. $is_static_mode = isset($GLOBALS['ismake']) && $GLOBALS['ismake'] == '1';
  1635. // 静态生成模式标记(用于后续URL处理)
  1636. $replace_from = ['{id}','{en}','{page}','{type_id}','{type_en}','{type_pid}','{type_pen}','{md5}','{year}','{month}','{day}','{sid}','{nid}'];
  1637. $replace_to = [];
  1638. $page_sp = $config['path']['page_sp'];
  1639. $path = '';
  1640. switch ($model)
  1641. {
  1642. case 'index/index':
  1643. if($config['view']['index'] == 2){
  1644. $path = 'index';
  1645. if(substr($path,strlen($path)-1,1)=='/'){
  1646. $path .= 'index';
  1647. }
  1648. }
  1649. else{
  1650. $url = url($model,$param);
  1651. if($url=='/PAGELINK.html'){
  1652. $url = '/index-PAGELINK.html';
  1653. }
  1654. }
  1655. break;
  1656. case 'map/index':
  1657. if($config['view']['map'] == 2){
  1658. $path = 'map';
  1659. if(substr($path,strlen($path)-1,1)=='/'){
  1660. $path .= 'index';
  1661. }
  1662. }
  1663. else{
  1664. $url = url($model,$param);
  1665. }
  1666. break;
  1667. case strpos($model,'rss/')!==false:
  1668. if($config['view']['rss'] == 2){
  1669. $path = $model;
  1670. if($param['page'] !=''){
  1671. $path .= $page_sp . $param['page'];
  1672. }
  1673. $path .= '.xml';
  1674. }
  1675. else{
  1676. $url = url($model,$param,'xml');
  1677. }
  1678. break;
  1679. case strpos($model,'label/')!==false:
  1680. if($config['view']['label'] == 2){
  1681. $path = $model;
  1682. }
  1683. else{
  1684. $url = url($model,$param);
  1685. }
  1686. break;
  1687. case 'vod/show':
  1688. case 'art/show':
  1689. case 'actor/show':
  1690. case 'website/show':
  1691. switch($config['rewrite']['type_id'])
  1692. {
  1693. case 1:
  1694. $id = $info['type_en'];
  1695. break;
  1696. case 2:
  1697. $id = mac_alphaID($info['type_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1698. break;
  1699. default:
  1700. $id = $info['type_id'];
  1701. break;
  1702. }
  1703. if(!empty($id)){
  1704. $param['id'] = $id;
  1705. }
  1706. $url = url($model,$param);
  1707. break;
  1708. case 'vod/type':
  1709. $replace_to = [$info['type_id'],$info['type_en'],$param['page'],
  1710. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en'],
  1711. ];
  1712. if($config['view']['vod_type'] == 2){
  1713. $path = $config['path']['vod_type'];
  1714. if(substr($path,strlen($path)-1,1)=='/'){
  1715. $path .= 'index';
  1716. }
  1717. $replace_to[] = md5($info['type_id']);
  1718. if($param['page'] !=''){
  1719. $path .= $page_sp . $param['page'];
  1720. }
  1721. }
  1722. else{
  1723. switch($config['rewrite']['type_id'])
  1724. {
  1725. case 1:
  1726. $id = $info['type_en'];
  1727. break;
  1728. case 2:
  1729. $id = mac_alphaID($info['type_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1730. break;
  1731. default:
  1732. $id = $info['type_id'];
  1733. break;
  1734. }
  1735. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  1736. }
  1737. break;
  1738. case 'vod/detail':
  1739. $replace_to = [$info['vod_id'],$info['vod_en'],'',
  1740. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en']
  1741. ];
  1742. if($config['view']['vod_detail'] == 2){
  1743. $path = $config['path' ]['vod_detail'];
  1744. if(substr($path,strlen($path)-1,1)=='/'){
  1745. $path .= 'index';
  1746. }
  1747. $replace_to[] = md5($info['vod_id']);
  1748. }
  1749. else{
  1750. switch($config['rewrite']['vod_id'])
  1751. {
  1752. case 1:
  1753. $id = $info['vod_en'];
  1754. break;
  1755. case 2:
  1756. $id = mac_alphaID($info['vod_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1757. break;
  1758. default:
  1759. $id = $info['vod_id'];
  1760. break;
  1761. }
  1762. $url = url($model,['id'=> $id ]);
  1763. }
  1764. $replace_to = array_merge($replace_to,[date('Y',$info['vod_time']),date('m',$info['vod_time']),date('d',$info['vod_time'])]);
  1765. break;
  1766. case 'vod/play':
  1767. $replace_to = [
  1768. $info['vod_id'],$info['vod_en'],'',
  1769. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en'],
  1770. ];
  1771. if($config['view']['vod_play'] >=2){
  1772. $path = $config['path' ]['vod_play'];
  1773. if(substr($path,strlen($path)-1,1)=='/'){
  1774. $path .= 'index';
  1775. }
  1776. $replace_to[] = md5($info['vod_id']);
  1777. if($config['view']['vod_play'] ==2){
  1778. $path.= '.'. $config['path']['suffix'];
  1779. $path .= '?'.$info['vod_id'] . '-' . $param['sid'] . '-' . $param['nid'] ;
  1780. }
  1781. elseif($config['view']['vod_play'] ==3){
  1782. $path .= $config['path']['page_sp'] . $param['sid'] . $config['path']['page_sp'] . $param['nid'] ;
  1783. }
  1784. elseif($config['view']['vod_play'] ==4){
  1785. $path .= $config['path']['page_sp'] .''. $param['sid'] . $config['path']['page_sp'] . '1';
  1786. $path.= '.'. $config['path']['suffix'];
  1787. $path .= '?'.$info['vod_id'] . '-' . $param['sid'] . '-' . $param['nid'] ;
  1788. }
  1789. }
  1790. else{
  1791. switch($config['rewrite']['vod_id'])
  1792. {
  1793. case 1:
  1794. $id = $info['vod_en'];
  1795. break;
  1796. case 2:
  1797. $id = mac_alphaID($info['vod_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1798. break;
  1799. default:
  1800. $id = $info['vod_id'];
  1801. break;
  1802. }
  1803. $url = url($model,['id'=>$id,'sid'=>$param['sid'],'nid'=>$param['nid']]);
  1804. }
  1805. $replace_to = array_merge($replace_to,[date('Y',$info['vod_time']),date('m',$info['vod_time']),date('d',$info['vod_time']),$param['sid'],$param['nid']]);
  1806. break;
  1807. case 'vod/down':
  1808. $replace_to = [
  1809. $info['vod_id'],$info['vod_en'],'',
  1810. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en']
  1811. ];
  1812. if($config['view']['vod_down'] >= 2){
  1813. $path = $config['path' ]['vod_down'];
  1814. if(substr($path,strlen($path)-1,1)=='/'){
  1815. $path .= 'index';
  1816. }
  1817. $replace_to[] = md5($info['vod_id']);
  1818. if($config['view']['vod_down'] ==2){
  1819. $path.= '.'. $config['path']['suffix'];
  1820. $path .= '?'.$info['vod_id'] . '-' . $param['sid'] . '-' . $param['nid'] ;
  1821. }
  1822. elseif($config['view']['vod_down'] ==3){
  1823. $path .= $config['path']['page_sp'] . $param['sid'] . $config['path']['page_sp'] . $param['nid'] ;
  1824. }
  1825. elseif($config['view']['vod_down'] ==4){
  1826. $path .= $config['path']['page_sp'] .''. $param['sid'] . $config['path']['page_sp'] . '1';
  1827. $path.= '.'. $config['path']['suffix'];
  1828. $path .= '?'.$info['vod_id'] . '-' . $param['sid'] . '-' . $param['nid'] ;
  1829. }
  1830. }
  1831. else{
  1832. switch($config['rewrite']['vod_id'])
  1833. {
  1834. case 1:
  1835. $id = $info['vod_en'];
  1836. break;
  1837. case 2:
  1838. $id = mac_alphaID($info['vod_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1839. break;
  1840. default:
  1841. $id = $info['vod_id'];
  1842. break;
  1843. }
  1844. $url = url($model,['id'=>$id,'sid'=>$param['sid'],'nid'=>$param['nid']]);
  1845. }
  1846. $replace_to = array_merge($replace_to,[date('Y',$info['vod_time']),date('m',$info['vod_time']),date('d',$info['vod_time']),$param['sid'],$param['nid']]);
  1847. break;
  1848. case 'vod/role':
  1849. $replace_to = [$info['vod_id'],$info['vod_en'],'',
  1850. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en']
  1851. ];
  1852. if($config['view']['vod_role'] == 2){
  1853. $path = $config['path' ]['vod_role'];
  1854. if(substr($path,strlen($path)-1,1)=='/'){
  1855. $path .= 'index';
  1856. }
  1857. $replace_to[] = md5($info['vod_id']);
  1858. }
  1859. else{
  1860. switch($config['rewrite']['vod_id'])
  1861. {
  1862. case 1:
  1863. $id = $info['vod_en'];
  1864. break;
  1865. case 2:
  1866. $id = mac_alphaID($info['vod_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1867. break;
  1868. default:
  1869. $id = $info['vod_id'];
  1870. break;
  1871. }
  1872. $url = url($model,['id'=>$id]);
  1873. }
  1874. $replace_to = array_merge($replace_to,[date('Y',$info['vod_time']),date('m',$info['vod_time']),date('d',$info['vod_time'])]);
  1875. break;
  1876. case 'vod/plot':
  1877. $replace_to = [
  1878. $info['vod_id'],$info['vod_en'],$param['page'],
  1879. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en']
  1880. ];
  1881. if($config['view']['vod_plot'] == 2){
  1882. $path = $config['path' ]['vod_plot'];
  1883. if(substr($path,strlen($path)-1,1)=='/'){
  1884. $path .= 'index';
  1885. }
  1886. $replace_to[] = md5($info['vod_id']);
  1887. if($param['page']!=''){
  1888. $path .= $page_sp . $param['page'];
  1889. }
  1890. }
  1891. else{
  1892. switch($config['rewrite']['vod_id'])
  1893. {
  1894. case 1:
  1895. $id = $info['vod_en'];
  1896. break;
  1897. case 2:
  1898. $id = mac_alphaID($info['vod_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1899. break;
  1900. default:
  1901. $id = $info['vod_id'];
  1902. break;
  1903. }
  1904. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  1905. }
  1906. $replace_to = array_merge($replace_to,[date('Y',$info['vod_time']),date('m',$info['vod_time']),date('d',$info['vod_time'])]);
  1907. break;
  1908. case 'art/type':
  1909. $replace_to = [$info['type_id'],$info['type_en'],$param['page'],
  1910. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en'],
  1911. ];
  1912. if($config['view']['art_type'] == 2){
  1913. $path = $config['path']['art_type'];
  1914. if(substr($path,strlen($path)-1,1)=='/'){
  1915. $path .= 'index';
  1916. }
  1917. if(strpos($path,'{md5}')!==false){
  1918. $replace_to[] = md5($info['type_id']);
  1919. }
  1920. if($param['page']!=''){
  1921. $path .= $page_sp . $param['page'];
  1922. }
  1923. }
  1924. else{
  1925. switch($config['rewrite']['type_id'])
  1926. {
  1927. case 1:
  1928. $id = $info['type_en'];
  1929. break;
  1930. case 2:
  1931. $id = mac_alphaID($info['type_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1932. break;
  1933. default:
  1934. $id = $info['type_id'];
  1935. break;
  1936. }
  1937. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  1938. }
  1939. break;
  1940. case 'art/detail':
  1941. $replace_to = [
  1942. $info['art_id'],$info['art_en'],'',
  1943. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en']
  1944. ];
  1945. if($config['view']['art_detail'] == 2){
  1946. $path = $config['path' ]['art_detail'];
  1947. if(substr($path,strlen($path)-1,1)=='/'){
  1948. $path .= 'index';
  1949. }
  1950. $replace_to[] = md5($info['art_id']);
  1951. if($param['page']>1 || $param['page'] =='PAGELINK'){
  1952. $path .= $page_sp . $param['page'];
  1953. }
  1954. }
  1955. else{
  1956. switch($config['rewrite']['art_id'])
  1957. {
  1958. case 1:
  1959. $id = $info['art_en'];
  1960. break;
  1961. case 2:
  1962. $id = mac_alphaID($info['art_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1963. break;
  1964. default:
  1965. $id = $info['art_id'];
  1966. break;
  1967. }
  1968. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  1969. }
  1970. $replace_to = array_merge($replace_to,[date('Y',$info['art_time']),date('m',$info['art_time']),date('d',$info['art_time'])]);
  1971. break;
  1972. case 'topic/index':
  1973. if($config['view']['topic_index'] == 2){
  1974. $path = $config['path' ]['topic_index'];
  1975. if(substr($path,strlen($path)-1,1)=='/'){
  1976. $path .= 'index';
  1977. }
  1978. if($param['page']>1 || $param['page'] =='PAGELINK'){
  1979. $path .= $page_sp . $param['page'];
  1980. }
  1981. }
  1982. else{
  1983. $url = url($model,['page'=>$param['page']]);
  1984. }
  1985. break;
  1986. case 'topic/detail':
  1987. $replace_to = [$info['topic_id'],$info['topic_en'],'','','','',''];
  1988. if($config['view']['topic_detail'] == 2){
  1989. $path = $config['path' ]['topic_detail'];
  1990. if(substr($path,strlen($path)-1,1)=='/'){
  1991. $path .= 'index';
  1992. }
  1993. if(strpos($path,'{md5}')!==false){
  1994. $replace_to[] = md5($info['topic_id']);
  1995. }
  1996. }
  1997. else{
  1998. switch($config['rewrite']['topic_id'])
  1999. {
  2000. case 1:
  2001. $id = $info['topic_en'];
  2002. break;
  2003. case 2:
  2004. $id = mac_alphaID($info['topic_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2005. break;
  2006. default:
  2007. $id = $info['topic_id'];
  2008. break;
  2009. }
  2010. $url = url($model,['id'=>$id]);
  2011. }
  2012. break;
  2013. case 'actor/index':
  2014. if($config['view']['actor_index'] == 2){
  2015. $path = $config['path' ]['actor_index'];
  2016. if(substr($path,strlen($path)-1,1)=='/'){
  2017. $path .= 'index';
  2018. }
  2019. if($param['page']>1 || $param['page'] =='PAGELINK'){
  2020. $path .= $page_sp . $param['page'];
  2021. }
  2022. }
  2023. else{
  2024. $url = url($model,['page'=>$param['page']]);
  2025. }
  2026. break;
  2027. case 'actor/type':
  2028. $replace_to = [$info['type_id'],$info['type_en'],$param['page'],
  2029. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en'],
  2030. ];
  2031. if($config['view']['actor_type'] == 2){
  2032. $path = $config['path']['actor_type'];
  2033. if(substr($path,strlen($path)-1,1)=='/'){
  2034. $path .= 'index';
  2035. }
  2036. if(strpos($path,'{md5}')!==false){
  2037. $replace_to[] = md5($info['type_id']);
  2038. }
  2039. if($param['page']!=''){
  2040. $path .= $page_sp . $param['page'];
  2041. }
  2042. }
  2043. else{
  2044. switch($config['rewrite']['type_id'])
  2045. {
  2046. case 1:
  2047. $id = $info['type_en'];
  2048. break;
  2049. case 2:
  2050. $id = mac_alphaID($info['type_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2051. break;
  2052. default:
  2053. $id = $info['type_id'];
  2054. break;
  2055. }
  2056. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  2057. }
  2058. break;
  2059. case 'actor/detail':
  2060. $replace_to = [$info['actor_id'],$info['actor_en'],'','','','',''];
  2061. if($config['view']['actor_detail'] == 2){
  2062. $path = $config['path' ]['actor_detail'];
  2063. if(substr($path,strlen($path)-1,1)=='/'){
  2064. $path .= 'index';
  2065. }
  2066. if(strpos($path,'{md5}')!==false){
  2067. $replace_to[] = md5($info['actor_id']);
  2068. }
  2069. }
  2070. else{
  2071. switch($config['rewrite']['actor_id'])
  2072. {
  2073. case 1:
  2074. $id = $info['actor_en'];
  2075. break;
  2076. case 2:
  2077. $id = mac_alphaID($info['actor_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2078. break;
  2079. default:
  2080. $id = $info['actor_id'];
  2081. break;
  2082. }
  2083. $url = url($model,['id'=>$id]);
  2084. }
  2085. break;
  2086. case 'role/index':
  2087. if($config['view']['role_index'] == 2){
  2088. $path = $config['path' ]['role_index'];
  2089. if(substr($path,strlen($path)-1,1)=='/'){
  2090. $path .= 'index';
  2091. }
  2092. if($param['page']>1 || $param['page'] =='PAGELINK'){
  2093. $path .= $page_sp . $param['page'];
  2094. }
  2095. }
  2096. else{
  2097. $url = url($model,['page'=>$param['page']]);
  2098. }
  2099. break;
  2100. case 'role/detail':
  2101. $replace_to = [$info['role_id'],$info['actor_en'],'','','','',''];
  2102. if($config['view']['role_detail'] == 2){
  2103. $path = $config['path' ]['role_detail'];
  2104. if(substr($path,strlen($path)-1,1)=='/'){
  2105. $path .= 'index';
  2106. }
  2107. if(strpos($path,'{md5}')!==false){
  2108. $replace_to[] = md5($info['role_id']);
  2109. }
  2110. }
  2111. else{
  2112. switch($config['rewrite']['role_id'])
  2113. {
  2114. case 1:
  2115. $id = $info['role_en'];
  2116. break;
  2117. case 2:
  2118. $id = mac_alphaID($info['role_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2119. break;
  2120. default:
  2121. $id = $info['role_id'];
  2122. break;
  2123. }
  2124. $url = url($model,['id'=>$id]);
  2125. }
  2126. break;
  2127. case 'plot/index':
  2128. if($config['view']['plot_index'] == 2){
  2129. $path = $config['path' ]['plot_index'];
  2130. if(substr($path,strlen($path)-1,1)=='/'){
  2131. $path .= 'index';
  2132. }
  2133. if($param['page']>1 || $param['page'] =='PAGELINK'){
  2134. $path .= $page_sp . $param['page'];
  2135. }
  2136. }
  2137. else{
  2138. $url = url($model,['page'=>$param['page']]);
  2139. }
  2140. break;
  2141. case 'plot/detail':
  2142. $replace_to = [
  2143. $info['vod_id'],$info['vod_en'],'',
  2144. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en']
  2145. ];
  2146. if($config['view']['plot_detail'] == 2){
  2147. $path = $config['path' ]['plot_detail'];
  2148. if(substr($path,strlen($path)-1,1)=='/'){
  2149. $path .= 'index';
  2150. }
  2151. if(strpos($path,'{md5}')!==false){
  2152. $replace_to[] = md5($info['vod_id']);
  2153. }
  2154. if($param['page']>1 || $param['page'] =='PAGELINK'){
  2155. $path .= $page_sp . $param['page'];
  2156. }
  2157. }
  2158. else{
  2159. switch($config['rewrite']['vod_id'])
  2160. {
  2161. case 1:
  2162. $id = $info['vod_en'];
  2163. break;
  2164. case 2:
  2165. $id = mac_alphaID($info['vod_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2166. break;
  2167. default:
  2168. $id = $info['vod_id'];
  2169. break;
  2170. }
  2171. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  2172. }
  2173. $replace_to = array_merge($replace_to,[date('Y',$info['vod_time']),date('m',$info['vod_time']),date('d',$info['vod_time'])]);
  2174. break;
  2175. case 'website/index':
  2176. if($config['view']['website_index'] == 2){
  2177. $path = $config['path' ]['website_index'];
  2178. if(substr($path,strlen($path)-1,1)=='/'){
  2179. $path .= 'index';
  2180. }
  2181. if($param['page']>1 || $param['page'] =='PAGELINK'){
  2182. $path .= $page_sp . $param['page'];
  2183. }
  2184. }
  2185. else{
  2186. $url = url($model,['page'=>$param['page']]);
  2187. }
  2188. break;
  2189. case 'website/type':
  2190. $replace_to = [$info['type_id'],$info['type_en'],$param['page'],
  2191. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en'],
  2192. ];
  2193. if($config['view']['website_type'] == 2){
  2194. $path = $config['path']['website_type'];
  2195. if(substr($path,strlen($path)-1,1)=='/'){
  2196. $path .= 'index';
  2197. }
  2198. if(strpos($path,'{md5}')!==false){
  2199. $replace_to[] = md5($info['type_id']);
  2200. }
  2201. if($param['page']!=''){
  2202. $path .= $page_sp . $param['page'];
  2203. }
  2204. }
  2205. else{
  2206. switch($config['rewrite']['type_id'])
  2207. {
  2208. case 1:
  2209. $id = $info['type_en'];
  2210. break;
  2211. case 2:
  2212. $id = mac_alphaID($info['type_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2213. break;
  2214. default:
  2215. $id = $info['type_id'];
  2216. break;
  2217. }
  2218. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  2219. }
  2220. break;
  2221. case 'website/detail':
  2222. $replace_to = [$info['website_id'],$info['website_en'],'','','','',''];
  2223. if($config['view']['website_detail'] == 2){
  2224. $path = $config['path' ]['website_detail'];
  2225. if(substr($path,strlen($path)-1,1)=='/'){
  2226. $path .= 'index';
  2227. }
  2228. if(strpos($path,'{md5}')!==false){
  2229. $replace_to[] = md5($info['website_id']);
  2230. }
  2231. }
  2232. else{
  2233. switch($config['rewrite']['website_id'])
  2234. {
  2235. case 1:
  2236. $id = $info['website_en'];
  2237. break;
  2238. case 2:
  2239. $id = mac_alphaID($info['website_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2240. break;
  2241. default:
  2242. $id = $info['website_id'];
  2243. break;
  2244. }
  2245. $url = url($model,['id'=>$id]);
  2246. }
  2247. break;
  2248. case 'gbook/index':
  2249. $url = url($model,['page'=>$param['page']]);
  2250. break;
  2251. case 'comment/index':
  2252. $url = url($model,['page'=>$param['page']]);
  2253. break;
  2254. default:
  2255. $url = url($model,$param);
  2256. break;
  2257. }
  2258. if(!empty($path)) {
  2259. $path = str_replace($replace_from, $replace_to, $path);
  2260. $path = str_replace('//', '/', $path);
  2261. $delimiter = false;
  2262. if(substr($path,strlen($path)-6) =='/index'){
  2263. $delimiter = true;
  2264. $path = substr($path,0, strlen($path)-5);
  2265. }
  2266. if($delimiter==false && strpos($path,'.')===false){
  2267. $path.= '.'. $config['path']['suffix'];
  2268. }
  2269. $url = $path;
  2270. if(substr($path,0,1)!='/') {
  2271. $url = MAC_PATH . $path;
  2272. }
  2273. }
  2274. else{
  2275. if(ENTRANCE!='index'){
  2276. $sto= MAC_PATH ;
  2277. if($config['rewrite']['status']==0){
  2278. $sto = MAC_PATH .'index.php/';
  2279. }
  2280. if(!empty(IN_FILE)){
  2281. $url = str_replace(IN_FILE.'/',$sto,$url);
  2282. $url = str_replace(ENTRANCE.'/','',$url);
  2283. }
  2284. }
  2285. elseif($config['rewrite']['status']==0 && strpos($url,'index.php')===false){
  2286. if(MAC_PATH !='/'){
  2287. $url = str_replace(MAC_PATH,'/',$url);
  2288. }
  2289. $url = MAC_PATH. 'index.php' . $url;
  2290. }
  2291. elseif($config['rewrite']['status']==1 && strpos($url,'index.php')!==false){
  2292. $url = str_replace('index.php/','',$url);
  2293. }
  2294. if($config['rewrite']['suffix_hide']==1){
  2295. $url = str_replace('.html','/',$url);
  2296. if(strpos($model,'/show')===false && strpos($model,'/search')===false) {
  2297. $url = str_replace(['-/','_/','-.','_.'],'/',$url);
  2298. }
  2299. }
  2300. else{
  2301. if(strpos($model,'search')===false && strpos($model,'show')===false ) {
  2302. $url = str_replace(['-.', '/.'], '.', $url);
  2303. }
  2304. }
  2305. }
  2306. // 在静态生成模式下,对生成的URL进行后处理,去掉admin/index前缀
  2307. if($is_static_mode && !empty($url)) {
  2308. if(strpos($url, '/index.php/') === 0) {
  2309. $url = preg_replace('/\/index\.php\/[^\/]+\.php\/admin\-/', '/index.php/', $url);
  2310. $url = str_replace('/admin-', '/', $url);
  2311. }
  2312. if(strpos($url, 'admin-') !== false) {
  2313. $url = str_replace('admin-', '', $url);
  2314. }
  2315. if(strpos($url, 'index-') !== false) {
  2316. $url = str_replace('index-', '', $url);
  2317. }
  2318. }
  2319. return $url;
  2320. }
  2321. function mac_url_page($url,$num)
  2322. {
  2323. $url = str_replace(MAC_PAGE_SP.'PAGELINK',($num>1 ? MAC_PAGE_SP.$num : ''),$url);
  2324. $url = str_replace('PAGELINK',$num,$url);
  2325. return $url;
  2326. }
  2327. function mac_url_create($str,$type='actor',$flag='vod',$ac='search',$sp='&nbsp;')
  2328. {
  2329. if(!$str){
  2330. return '未知';
  2331. }
  2332. $res = [];
  2333. // 分割时,中文关键词允许空格分割,英文不用空格(英文名中间是空格分隔的问题)
  2334. $base_finder = array(' / ', '/', '|', ',', ',', ',,');
  2335. $str = str_replace($base_finder, ',', $str);
  2336. $str = trim($str, ',');
  2337. $arr = [];
  2338. foreach (explode(',', $str) as $tag) {
  2339. if (preg_match("/[\x{2E80}-\x{9FFF}]+/u", $tag) && str_contains($tag, ' ')) {
  2340. foreach (explode(' ', $tag) as $tag_exp) {
  2341. $arr[] = $tag_exp;
  2342. }
  2343. } else {
  2344. $arr[] = $tag;
  2345. }
  2346. }
  2347. foreach ($arr as $k => $v) {
  2348. $res[$k] = '<a href="'.mac_url($flag.'/'.$ac,[$type=>$v]).'" target="_blank">'.$v.'</a>'.$sp;
  2349. }
  2350. return implode('',$res);
  2351. }
  2352. function mac_url_search($param=[],$flag='vod')
  2353. {
  2354. return mac_url($flag.'/search',$param);
  2355. }
  2356. function mac_url_type($info,$param=[],$flag='type')
  2357. {
  2358. $tab = 'vod';
  2359. if($info['type_mid'] == 1){
  2360. }
  2361. else if($info['type_mid'] == 2) {
  2362. $tab ='art';
  2363. }
  2364. else if($info['type_mid'] == 8) {
  2365. $tab ='actor';
  2366. }
  2367. else if($info['type_mid'] == 11) {
  2368. $tab ='website';
  2369. }
  2370. if(empty($param['id'])){
  2371. $param['id'] = $info['type_id'];
  2372. }
  2373. return mac_url($tab.'/'.$flag,$param,$info);
  2374. }
  2375. function mac_url_topic_index($param=[])
  2376. {
  2377. return mac_url('topic/index',['page'=>$param['page']]);
  2378. }
  2379. function mac_url_topic_detail($info)
  2380. {
  2381. return mac_url('topic/detail',[],$info);
  2382. }
  2383. function mac_url_role_index($param=[])
  2384. {
  2385. return mac_url('role/index',['page'=>$param['page']]);
  2386. }
  2387. function mac_url_role_detail($info)
  2388. {
  2389. return mac_url('role/detail',[],$info);
  2390. }
  2391. function mac_url_actor_index($param=[])
  2392. {
  2393. return mac_url('actor/index',['page'=>$param['page']]);
  2394. }
  2395. function mac_url_actor_detail($info)
  2396. {
  2397. return mac_url('actor/detail',[],$info);
  2398. }
  2399. function mac_url_actor_search($param)
  2400. {
  2401. return mac_url('actor/search',$param);
  2402. }
  2403. function mac_url_plot_index($param=[])
  2404. {
  2405. return mac_url('plot/index',['page'=>$param['page']]);
  2406. }
  2407. function mac_url_plot_detail($info,$param=[])
  2408. {
  2409. return mac_url('plot/detail',['page'=>$param['page']],$info);
  2410. }
  2411. function mac_url_vod_plot($info,$param=[])
  2412. {
  2413. return mac_url('vod/plot',$param,$info);
  2414. }
  2415. function mac_url_vod_role($info,$param=[])
  2416. {
  2417. return mac_url('vod/role',$param,$info);
  2418. }
  2419. function mac_url_website_index($param=[])
  2420. {
  2421. return mac_url('website/index',['page'=>$param['page']]);
  2422. }
  2423. function mac_url_website_detail($info)
  2424. {
  2425. return mac_url('website/detail',[],$info);
  2426. }
  2427. function mac_url_website_search($param)
  2428. {
  2429. return mac_url('website/search',$param);
  2430. }
  2431. function mac_url_art_index($param=[])
  2432. {
  2433. return mac_url('art/index',['page'=>$param['page']]);
  2434. }
  2435. function mac_url_art_detail($info,$param=[])
  2436. {
  2437. return mac_url('art/detail',['page'=>$param['page']],$info);
  2438. }
  2439. function mac_url_art_search($param)
  2440. {
  2441. return mac_url('art/search',$param);
  2442. }
  2443. function mac_url_vod_index($param=[])
  2444. {
  2445. return mac_url('vod/index',['page'=>$param['page']]);
  2446. }
  2447. function mac_url_vod_detail($info)
  2448. {
  2449. return mac_url('vod/detail',[],$info);
  2450. }
  2451. function mac_url_manga_detail($info)
  2452. {
  2453. return mac_url('manga/detail',[],$info);
  2454. }
  2455. function mac_url_vod_search($param)
  2456. {
  2457. return mac_url('vod/search',$param);
  2458. }
  2459. function mac_url_vod_play($info,$param=[])
  2460. {
  2461. if($param=='first'){
  2462. $sid = intval(key($info['vod_play_list']));
  2463. $nid = intval(key($info['vod_play_list'][$sid]['urls']));
  2464. if($sid==0 || $nid==0){
  2465. return '';
  2466. }
  2467. $param=[];
  2468. $param['sid'] = $sid;
  2469. $param['nid'] = $nid;
  2470. }
  2471. if(intval($param['sid'])<1){
  2472. $param['sid'] =1;
  2473. }
  2474. if(intval($param['nid'])<1){
  2475. $param['nid']=1;
  2476. }
  2477. return mac_url('vod/play',['sid'=>$param['sid'],'nid'=>$param['nid']],$info);
  2478. }
  2479. function mac_url_vod_down($info,$param=[])
  2480. {
  2481. if($param=='first'){
  2482. $sid = intval(key($info['vod_down_list']));
  2483. $nid = intval(key($info['vod_down_list'][$sid]['urls']));
  2484. if($sid==0 || $nid==0){
  2485. return '';
  2486. }
  2487. $param=[];
  2488. $param['sid'] = $sid;
  2489. $param['nid'] = $nid;
  2490. }
  2491. if(intval($param['sid'])<1){
  2492. $param['sid'] =1;
  2493. }
  2494. if(intval($param['nid'])<1){
  2495. $param['nid']=1;
  2496. }
  2497. return mac_url('vod/down',['sid'=>$param['sid'],'nid'=>$param['nid']],$info);
  2498. }
  2499. function mac_label_website_detail($param)
  2500. {
  2501. $where = [];
  2502. if($GLOBALS['config']['rewrite']['website_id']==1){
  2503. $where['website_en'] = ['eq',$param['id']];
  2504. }
  2505. else{
  2506. if($GLOBALS['config']['rewrite']['website_id']==2) {
  2507. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2508. }
  2509. $where['website_id'] = ['eq',$param['id']];
  2510. }
  2511. $where['website_status'] = ['eq',1];
  2512. $res = model('Website')->infoData($where,'*',1);
  2513. $GLOBALS['type_id'] = $res['info']['type_id'];
  2514. $GLOBALS['type_pid'] = $res['info']['type']['type_pid'];
  2515. return $res;
  2516. }
  2517. function mac_label_actor_detail($param)
  2518. {
  2519. $where = [];
  2520. if($GLOBALS['config']['rewrite']['actor_id']==1){
  2521. $where['actor_en'] = ['eq',$param['id']];
  2522. }
  2523. else{
  2524. if($GLOBALS['config']['rewrite']['actor_id']==2) {
  2525. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2526. }
  2527. $where['actor_id'] = ['eq',$param['id']];
  2528. }
  2529. $where['actor_status'] = ['eq',1];
  2530. $res = model('Actor')->infoData($where,'*',1);
  2531. $GLOBALS['type_id'] = $res['info']['type_id'];
  2532. $GLOBALS['type_pid'] = $res['info']['type']['type_pid'];
  2533. return $res;
  2534. }
  2535. function mac_label_role_detail($param)
  2536. {
  2537. $where = [];
  2538. if($GLOBALS['config']['rewrite']['role_id']==1){
  2539. $where['role_en'] = ['eq',$param['id']];
  2540. }
  2541. else{
  2542. if($GLOBALS['config']['rewrite']['role_id']==2) {
  2543. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2544. }
  2545. $where['role_id'] = ['eq',$param['id']];
  2546. }
  2547. $where['role_status'] = ['eq',1];
  2548. $res = model('Role')->infoData($where,'*',1);
  2549. // https://github.com/magicblack/maccms10/issues/960
  2550. $GLOBALS['type_id'] = isset($res['info']['data']['type_id']) ? $res['info']['data']['type_id'] : 0;
  2551. $GLOBALS['type_pid'] = isset($res['info']['data']['type_id_1']) ? $res['info']['data']['type_id_1'] : 0;
  2552. return $res;
  2553. }
  2554. function mac_label_topic_detail($param)
  2555. {
  2556. $where = [];
  2557. if($GLOBALS['config']['rewrite']['topic_id']==1){
  2558. $where['topic_en'] = ['eq',$param['id']];
  2559. }
  2560. else{
  2561. if($GLOBALS['config']['rewrite']['topic_id']==2) {
  2562. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2563. }
  2564. $where['topic_id'] = ['eq',$param['id']];
  2565. }
  2566. $where['topic_status'] = ['eq',1];
  2567. $res = model('Topic')->infoData($where,'*',1);
  2568. return $res;
  2569. }
  2570. function mac_label_art_detail($param)
  2571. {
  2572. $where = [];
  2573. if($GLOBALS['config']['rewrite']['art_id']==1){
  2574. $where['art_en'] = ['eq',$param['id']];
  2575. }
  2576. else{
  2577. if($GLOBALS['config']['rewrite']['art_id']==2) {
  2578. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2579. }
  2580. $where['art_id'] = ['eq',$param['id']];
  2581. }
  2582. $where['art_status'] = ['eq',1];
  2583. $res = model('Art')->infoData($where,'*',1);
  2584. if($res['code'] ==1){
  2585. if($param['page']>$res['info']['art_page_total']){ $param['page'] = $res['info']['art_page_total']; }
  2586. }
  2587. $GLOBALS['type_id'] = $res['info']['type_id'];
  2588. $GLOBALS['type_pid'] = $res['info']['type']['type_pid'];
  2589. return $res;
  2590. }
  2591. function mac_label_vod_detail($param)
  2592. {
  2593. $where = [];
  2594. if($GLOBALS['config']['rewrite']['vod_id']==1){
  2595. $where['vod_en'] = ['eq',$param['id']];
  2596. }
  2597. else{
  2598. if($GLOBALS['config']['rewrite']['vod_id']==2) {
  2599. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2600. }
  2601. $where['vod_id'] = ['eq',$param['id']];
  2602. }
  2603. $where['vod_status'] = ['eq',1];
  2604. $res = model('Vod')->infoData($where,'*',1);
  2605. $GLOBALS['type_id'] = $res['info']['type_id'];
  2606. $GLOBALS['type_pid'] = $res['info']['type']['type_pid'];
  2607. return $res;
  2608. }
  2609. function mac_label_vod_role($param)
  2610. {
  2611. $where = [];
  2612. $where['role_rid'] = $param['rid'];
  2613. $where['role_status'] = ['eq',1];
  2614. $order='role_sort desc,role_id desc';
  2615. $res = model('Role')->listData($where,$order,1,999,0,'*',0,0);
  2616. return $res;
  2617. }
  2618. function mac_label_type($param, $type_id_specified)
  2619. {
  2620. if ($type_id_specified > 0) {
  2621. $type_id = $type_id_specified;
  2622. } else {
  2623. if($GLOBALS['config']['rewrite']['type_id']==1){
  2624. }
  2625. else{
  2626. if($GLOBALS['config']['rewrite']['type_id']==2) {
  2627. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2628. }
  2629. }
  2630. $type_id = $param['id'];
  2631. }
  2632. $type_info = model('Type')->getCacheInfo($type_id);
  2633. $GLOBALS['type_id'] =$type_info['type_id'];
  2634. $GLOBALS['type_pid'] = $type_info['type_pid'];
  2635. $parent = model('Type')->getCacheInfo($type_info['type_pid']);
  2636. $type_info['parent'] = $parent;
  2637. return $type_info;
  2638. }
  2639. function mac_data_count($tid=0,$range='all',$flag='vod')
  2640. {
  2641. if(!in_array($flag,['vod','art','actor','role','topic','website'])) {
  2642. $flag='vod';
  2643. }
  2644. if(!in_array($range,['all','today','min'])){
  2645. $range='all';
  2646. }
  2647. $data = model('Extend')->dataCount();
  2648. $key = 'type_'.$range.'_'.$tid;
  2649. if($tid>0 && in_array($flag,['vod','art']) ){
  2650. }
  2651. else{
  2652. $key = $flag.'_'.$range;
  2653. }
  2654. return intval($data[$key]);
  2655. }
  2656. function mac_get_popedom_filter($group_type,$type_list=[])
  2657. {
  2658. if(empty($type_list)){
  2659. $type_list = model('Type')->getCache('type_list');
  2660. }
  2661. $type_keys = array_keys($type_list);
  2662. $group_type = trim($group_type,',');
  2663. $group_keys = explode(',',$group_type);
  2664. $cha_keys = array_diff($type_keys, $group_keys);
  2665. return implode(',',$cha_keys);
  2666. }
  2667. function reset_html_filename($htmlfile)
  2668. {
  2669. $htmlpath = './';
  2670. if(substr($htmlfile,strlen($htmlfile)-1,1)=='/'){
  2671. $htmlfile .= 'index';
  2672. }
  2673. if(strpos($htmlfile,'.') ===false){
  2674. $htmlfile .= '.'. $GLOBALS['config']['path']['suffix'];
  2675. }
  2676. if(strpos($htmlfile,'?')!==false){
  2677. $htmlfile = substr($htmlfile,0,strpos($htmlfile,'?'));
  2678. }
  2679. $htmlfile = $htmlpath.$htmlfile;
  2680. $htmlfile = str_replace('//','/', $htmlfile);
  2681. if(MAC_PATH !='/'){
  2682. $htmlfile = str_replace('.'.MAC_PATH, './', $htmlfile);
  2683. }
  2684. $htmlfile = str_replace('//','/', $htmlfile);
  2685. return $htmlfile;
  2686. }
  2687. function mac_unicode_encode($str, $encoding = 'UTF-8', $prefix = '&#', $postfix = ';') {
  2688. $str = iconv($encoding, 'UCS-2', $str);
  2689. $arrstr = str_split($str, 2);
  2690. $unistr = '';
  2691. for($i = 0, $len = count($arrstr); $i < $len; $i++) {
  2692. $dec = hexdec(bin2hex($arrstr[$i]));
  2693. $unistr .= $prefix . $dec . $postfix;
  2694. }
  2695. return $unistr;
  2696. }
  2697. function mac_unicode_decode($unistr, $encoding = 'UTF-8', $prefix = '&#', $postfix = ';') {
  2698. $arruni = explode($prefix, $unistr);
  2699. $unistr = '';
  2700. for($i = 1, $len = count($arruni); $i < $len; $i++) {
  2701. if (strlen($postfix) > 0) {
  2702. $arruni[$i] = substr($arruni[$i], 0, strlen($arruni[$i]) - strlen($postfix));
  2703. }
  2704. $temp = intval($arruni[$i]);
  2705. $unistr .= ($temp < 256) ? chr(0) . chr($temp) : chr($temp / 256) . chr($temp % 256);
  2706. }
  2707. return iconv('UCS-2', $encoding, $unistr);
  2708. }
  2709. function mac_escape_param($param)
  2710. {
  2711. if(is_array($param)){
  2712. foreach($param as $k=>$v){
  2713. if(!is_numeric($v) && !empty($v)){
  2714. if($GLOBALS['config']['app']['wall_filter'] ==1){
  2715. $v = mac_unicode_encode($v);
  2716. }
  2717. elseif($GLOBALS['config']['app']['wall_filter'] ==2){
  2718. $v = '';
  2719. }
  2720. $param[$k] = $v;
  2721. }
  2722. }
  2723. }
  2724. else{
  2725. if(!is_numeric($param) && !empty($param)){
  2726. if($GLOBALS['config']['app']['wall_filter'] ==1){
  2727. $param = mac_unicode_encode($param);
  2728. }
  2729. elseif($GLOBALS['config']['app']['wall_filter'] ==2){
  2730. $param = '';
  2731. }
  2732. }
  2733. }
  2734. return $param;
  2735. }
  2736. function mac_search_len_check($param)
  2737. {
  2738. $psm = array('wd','tag','class','letter','name','state','level','area','lang','version','actor','director','starsign','blood');
  2739. foreach($psm as $v){
  2740. if(mb_strlen($param[$v]) > $GLOBALS['config']['app']['search_len']){
  2741. $param[$v] = mac_substring($param[$v],$GLOBALS['config']['app']['search_len']);
  2742. }
  2743. }
  2744. return $param;
  2745. }
  2746. function mac_no_cahche()
  2747. {
  2748. @header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  2749. @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
  2750. @header('Cache-Control: no-cache, must-revalidate');
  2751. @header('Pragma: no-cache');
  2752. }
  2753. function mac_filter_tags($rs)
  2754. {
  2755. $rex = array('{:','<script','<iframe','<frameset','<object','onerror');
  2756. if(is_array($rs)){
  2757. foreach($rs as $k2=>$v2){
  2758. if(!is_numeric($v2)){
  2759. $rs[$k2] = str_ireplace($rex,'*',$rs[$k2]);
  2760. }
  2761. }
  2762. }
  2763. else{
  2764. if(!is_numeric($rs)){
  2765. $rs = str_ireplace($rex,'*',$rs);
  2766. }
  2767. }
  2768. return $rs;
  2769. }
  2770. if (!function_exists('is_really_writable')) {
  2771. /**
  2772. * 判断文件或文件夹是否可写
  2773. * @param string $file 文件或目录
  2774. * @return bool
  2775. */
  2776. function is_really_writable($file)
  2777. {
  2778. if (DIRECTORY_SEPARATOR === '/') {
  2779. return is_writable($file);
  2780. }
  2781. if (is_dir($file)) {
  2782. $file = rtrim($file, '/') . '/' . md5(mt_rand());
  2783. if (($fp = @fopen($file, 'ab')) === false) {
  2784. return false;
  2785. }
  2786. fclose($fp);
  2787. @chmod($file, 0777);
  2788. @unlink($file);
  2789. return true;
  2790. } elseif (!is_file($file) or ($fp = @fopen($file, 'ab')) === false) {
  2791. return false;
  2792. }
  2793. fclose($fp);
  2794. return true;
  2795. }
  2796. }
  2797. if (!function_exists('rmdirs')) {
  2798. /**
  2799. * 删除文件夹
  2800. * @param string $dirname 目录
  2801. * @param bool $withself 是否删除自身
  2802. * @return boolean
  2803. */
  2804. function rmdirs($dirname, $withself = true)
  2805. {
  2806. if (!is_dir($dirname)) {
  2807. return false;
  2808. }
  2809. $files = new RecursiveIteratorIterator(
  2810. new RecursiveDirectoryIterator($dirname, RecursiveDirectoryIterator::SKIP_DOTS),
  2811. RecursiveIteratorIterator::CHILD_FIRST
  2812. );
  2813. foreach ($files as $fileinfo) {
  2814. $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
  2815. $todo($fileinfo->getRealPath());
  2816. }
  2817. if ($withself) {
  2818. @rmdir($dirname);
  2819. }
  2820. return true;
  2821. }
  2822. }
  2823. if (!function_exists('copydirs')) {
  2824. /**
  2825. * 复制文件夹
  2826. * @param string $source 源文件夹
  2827. * @param string $dest 目标文件夹
  2828. */
  2829. function copydirs($source, $dest)
  2830. {
  2831. if (!is_dir($dest)) {
  2832. mkdir($dest, 0755, true);
  2833. }
  2834. foreach (
  2835. $iterator = new RecursiveIteratorIterator(
  2836. new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
  2837. RecursiveIteratorIterator::SELF_FIRST
  2838. ) as $item
  2839. ) {
  2840. if ($item->isDir()) {
  2841. $sontDir = $dest . DS . $iterator->getSubPathName();
  2842. if (!is_dir($sontDir)) {
  2843. mkdir($sontDir, 0755, true);
  2844. }
  2845. } else {
  2846. copy($item, $dest . DS . $iterator->getSubPathName());
  2847. }
  2848. }
  2849. }
  2850. }