common.php 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094
  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. // 先将HTML实体中的#临时替换为特殊占位符
  827. $placeholder = '___HTML_ENTITY_HASH___';
  828. $txt = preg_replace('/&#(\d+);/', $placeholder . '$1;', $txt);
  829. $txt = preg_replace('/&#x([0-9a-fA-F]+);/', $placeholder . 'x$1;', $txt);
  830. // 安全地按#分割
  831. $txtarr = explode('#', $txt);
  832. // 还原HTML实体中的#
  833. foreach($txtarr as &$item) {
  834. $item = str_replace($placeholder, '&#', $item);
  835. }
  836. unset($item);
  837. $data=[];
  838. foreach($txtarr as $v){
  839. if (stripos($v, '=') === false) {
  840. continue;
  841. }
  842. list($from, $to) = explode('=', $v, 2);
  843. if ($decode === true && stripos($from, '&') !== false && stripos($from, ';') !== false) {
  844. $from = html_entity_decode($from, ENT_QUOTES, 'UTF-8');
  845. }
  846. if ($decode === true && stripos($to, '&') !== false && stripos($to, ';') !== false) {
  847. $to = html_entity_decode($to, ENT_QUOTES, 'UTF-8');
  848. }
  849. $data['from'][] = $from;
  850. $data['to'][] = $to;
  851. }
  852. return $data;
  853. }
  854. function mac_rep_pse_syn($psearr,$txt)
  855. {
  856. if(empty($txt)){ $txt=""; }
  857. if(is_array($psearr['from']) && is_array($psearr['to'])){
  858. $txt = str_replace($psearr['from'],$psearr['to'],$txt);
  859. }
  860. return $txt;
  861. }
  862. function mac_get_tag($title,$content){
  863. $url = base64_decode('aHR0cDovL2FwaS5kcGxheWVyc3RhdGljLmNvbQ==').'/keyword/index?name='.rawurlencode($title).'&txt='.rawurlencode($title).rawurlencode(mac_substring(strip_tags($content),200));
  864. $data = mac_curl_get($url);
  865. $json = @json_decode($data,true);
  866. if($json){
  867. if($json['code']==1){
  868. return implode(',',$json['data']);
  869. }
  870. }
  871. return false;
  872. }
  873. function mac_get_client_ip()
  874. {
  875. static $final;
  876. if (!is_null($final)) {
  877. return $final;
  878. }
  879. $ips = [];
  880. if (!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) {
  881. $ips[] = $_SERVER['HTTP_CF_CONNECTING_IP'];
  882. }
  883. if (!empty($_SERVER['HTTP_ALI_CDN_REAL_IP'])) {
  884. $ips[] = $_SERVER['HTTP_ALI_CDN_REAL_IP'];
  885. }
  886. if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  887. $ips[] = $_SERVER['HTTP_CLIENT_IP'];
  888. }
  889. if (!empty($_SERVER['HTTP_PROXY_USER'])) {
  890. $ips[] = $_SERVER['HTTP_PROXY_USER'];
  891. }
  892. $real_ip = getenv('HTTP_X_REAL_IP');
  893. if (!empty($real_ip)) {
  894. $ips[] = $real_ip;
  895. }
  896. if (!empty($_SERVER['REMOTE_ADDR'])) {
  897. $ips[] = $_SERVER['REMOTE_ADDR'];
  898. }
  899. // 选第一个最合法的,或最后一个正常的IP
  900. foreach ($ips as $ip) {
  901. $verifyResult = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE);
  902. if (!$verifyResult){
  903. continue;
  904. }
  905. $verifyResult && $final = $ip;
  906. }
  907. empty($final) && $final = '0.0.0.0';
  908. return $final;
  909. }
  910. function mac_get_ip_long($ip_addr = '')
  911. {
  912. $ip_addr = !empty($ip_addr) ? $ip_addr : mac_get_client_ip();
  913. $ip_long = sprintf('%u',ip2long($ip_addr));
  914. // 排除不正确的IP
  915. if ($ip_long < 0 || $ip_long >= 0xFFFFFFFF) {
  916. $ip_long = 0;
  917. }
  918. return $ip_long;
  919. }
  920. function mac_get_uniqid_code($code_prefix='')
  921. {
  922. $code_prefix = strtoupper($code_prefix);
  923. $now_date = date('YmdHis');
  924. $now_time = rand(100000, 999999);
  925. return $code_prefix . $now_date . $now_time;
  926. }
  927. function mac_escape($string, $in_encoding = 'UTF-8',$out_encoding = 'UCS-2') {
  928. $return = '';
  929. if (function_exists('mb_get_info')) {
  930. for($x = 0; $x < mb_strlen ( $string, $in_encoding ); $x ++) {
  931. $str = mb_substr ( $string, $x, 1, $in_encoding );
  932. if (strlen ( $str ) > 1) { // 多字节字符
  933. $return .= '%u' . strtoupper ( bin2hex ( mb_convert_encoding ( $str, $out_encoding, $in_encoding ) ) );
  934. } else {
  935. $return .= '%' . strtoupper ( bin2hex ( $str ) );
  936. }
  937. }
  938. }
  939. return $return;
  940. }
  941. function mac_unescape($str)
  942. {
  943. $ret = '';
  944. $len = strlen($str);
  945. for ($i = 0; $i < $len; $i ++)
  946. {
  947. if ($str[$i] == '%' && $str[$i + 1] == 'u')
  948. {
  949. $val = hexdec(substr($str, $i + 2, 4));
  950. if ($val < 0x7f)
  951. $ret .= chr($val);
  952. else
  953. if ($val < 0x800)
  954. $ret .= chr(0xc0 | ($val >> 6)) .
  955. chr(0x80 | ($val & 0x3f));
  956. else
  957. $ret .= chr(0xe0 | ($val >> 12)) .
  958. chr(0x80 | (($val >> 6) & 0x3f)) .
  959. chr(0x80 | ($val & 0x3f));
  960. $i += 5;
  961. } else
  962. if ($str[$i] == '%')
  963. {
  964. $ret .= urldecode(substr($str, $i, 3));
  965. $i += 2;
  966. } else
  967. $ret .= $str[$i];
  968. }
  969. return $ret;
  970. }
  971. /*特殊字段的值转换*/
  972. function mac_get_mid_code($data)
  973. {
  974. $arr = [
  975. 1 => 'vod',
  976. 2 => 'art',
  977. 3 => 'topic',
  978. 4 => 'comment',
  979. 5 => 'gbook',
  980. 6 => 'user',
  981. 7 => 'label',
  982. 8 => 'actor',
  983. 9 => 'role',
  984. 10 => 'plot',
  985. 11 => 'website',
  986. 12 => 'manga',
  987. ];
  988. return $arr[$data];
  989. }
  990. function mac_get_mid_text($data)
  991. {
  992. $arr = [
  993. 1 => lang('vod'),
  994. 2 => lang('art'),
  995. 3 => lang('topic'),
  996. 4 => lang('comment'),
  997. 5 => lang('gbook'),
  998. 6 => lang('user'),
  999. 7 => lang('label'),
  1000. 8 => lang('actor'),
  1001. 9 => lang('role'),
  1002. 10 => lang('plot'),
  1003. 11 => lang('website'),
  1004. 12 => lang('manga'),
  1005. ];
  1006. return $arr[$data];
  1007. }
  1008. function mac_get_mid($controller)
  1009. {
  1010. $controller=strtolower($controller);
  1011. $arr = [
  1012. 'vod' => 1,
  1013. 'art' => 2,
  1014. 'topic' => 3,
  1015. 'comment' => 4,
  1016. 'gbook' => 5,
  1017. 'user' => 6,
  1018. 'label' => 7,
  1019. 'actor' => 8,
  1020. 'role' => 9,
  1021. 'plot' => 10,
  1022. 'website' => 11,
  1023. 'manga' => 12,
  1024. ];
  1025. return $arr[$controller];
  1026. }
  1027. function mac_get_aid($controller,$action='')
  1028. {
  1029. $controller=strtolower($controller);
  1030. $action=strtolower($action);
  1031. $key = $controller.'/'.$action;
  1032. $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];
  1033. $res = $arr[$controller];
  1034. // https://github.com/magicblack/maccms10/issues/960
  1035. $arr=[
  1036. 'vod/type'=>11,'vod/show'=>12,'vod/search'=>13,'vod/detail'=>14,'vod/play'=>15,'vod/down'=>16,'vod/role'=>17,'vod/plot'=>18,
  1037. 'art/type'=>21,'art/show'=>22,'art/search'=>23,'art/detail'=>24,
  1038. 'manga/type'=>121,'manga/show'=>122,'manga/search'=>123,'manga/detail'=>124,
  1039. 'topic/search'=>33,'topic/detail'=>34,
  1040. 'actor/type'=>81,'actor/show'=>82,'actor/search'=>83,'actor/detail'=>84,
  1041. 'role/show'=>92,'role/search'=>93,'role/detail'=>94,
  1042. 'plot/search'=>103,'plot/detail'=>104,
  1043. 'website/type'=>111,'website/show'=>112,'website/search'=>113,'website/detail'=>114,
  1044. ];
  1045. if(!empty($arr[$key])){
  1046. $res= $arr[$key];
  1047. }
  1048. return $res;
  1049. }
  1050. function mac_get_user_status_text($data)
  1051. {
  1052. $arr = [
  1053. 0 => lang('disable'),
  1054. 1 => lang('enable'),
  1055. ];
  1056. return $arr[$data];
  1057. }
  1058. function mac_get_user_flag_text($data)
  1059. {
  1060. $arr = [
  1061. 0 => lang('counting_points'),
  1062. 1 => lang('counting_times'),
  1063. 2 => lang('counting_ips'),
  1064. ];
  1065. return $arr[$data];
  1066. }
  1067. function mac_get_ulog_type_text($data)
  1068. {
  1069. $arr = [
  1070. 1 => lang('browse'),
  1071. 2 => lang('collect'),
  1072. 3 => lang('want_see'),
  1073. 4 => lang('play'),
  1074. 5 => lang('down'),
  1075. ];
  1076. return $arr[$data];
  1077. }
  1078. function mac_get_plog_type_text($data)
  1079. {
  1080. $arr = [
  1081. 1 => lang('integral_recharge'),
  1082. 2 => lang('registration_promotion'),
  1083. 3 => lang('visit_promotion'),
  1084. 4 => lang('one_level_distribution'),
  1085. 5 => lang('two_level_distribution'),
  1086. 6 => lang('three_level_distribution'),
  1087. 7 => lang('points_upgrade'),
  1088. 8 => lang('integral_consumption'),
  1089. 9 => lang('integral_withdrawal'),
  1090. ];
  1091. return $arr[$data];
  1092. }
  1093. function mac_get_card_sale_status_text($data)
  1094. {
  1095. $arr = [
  1096. 0 => lang('not_sale'),
  1097. 1 => lang('sold'),
  1098. ];
  1099. return $arr[$data];
  1100. }
  1101. function mac_get_card_use_status_text($data)
  1102. {
  1103. $arr = [
  1104. 0 => lang('not_used'),
  1105. 1 => lang('used'),
  1106. ];
  1107. return $arr[$data];
  1108. }
  1109. function mac_get_order_status_text($data)
  1110. {
  1111. $arr = [
  1112. 0 => lang('not_paid'),
  1113. 1 => lang('paid'),
  1114. ];
  1115. return $arr[$data];
  1116. }
  1117. function mac_get_user_portrait($user_id)
  1118. {
  1119. $res = MAC_PATH . 'static_new/images/touxiang.png';
  1120. if(!empty($user_id)){
  1121. $res2 = 'upload/user/'.($user_id % 10 ). '/'.$user_id.'.jpg';
  1122. if(file_exists(ROOT_PATH . $res2)){
  1123. $res = MAC_PATH . $res2;
  1124. }
  1125. }
  1126. return $res;
  1127. }
  1128. function mac_filter_html($str)
  1129. {
  1130. return strip_tags($str);
  1131. }
  1132. function mac_filter_xss($str)
  1133. {
  1134. return trim(htmlspecialchars(strip_tags($str), ENT_QUOTES));
  1135. }
  1136. function mac_restore_htmlfilter($str) {
  1137. if (stripos($str, '&amp;') !== false) {
  1138. return htmlspecialchars_decode($str, ENT_QUOTES);
  1139. }
  1140. return $str;
  1141. }
  1142. function mac_format_text($str, $allow_space = false)
  1143. {
  1144. $finder = array('/', ',', '|', '、', ',,', ',,,');
  1145. if ($allow_space === false) {
  1146. $finder[] = ' ';
  1147. }
  1148. return str_replace($finder, ',', $str);
  1149. }
  1150. function mac_format_count($str)
  1151. {
  1152. $arr = explode(',',$str);
  1153. return count($arr);
  1154. }
  1155. function mac_txt_merge($txt,$str)
  1156. {
  1157. if(empty($str)){
  1158. return $txt;
  1159. }
  1160. if($GLOBALS['config']['collect']['vod']['class_filter'] !='0') {
  1161. if (mb_strlen($str) > 2) {
  1162. $str = str_replace([lang('slice')], [''], $str);
  1163. }
  1164. if (mb_strlen($str) > 2) {
  1165. $str = str_replace([lang('drama')], [''], $str);
  1166. }
  1167. }
  1168. $txt = mac_format_text($txt);
  1169. $str = mac_format_text($str);
  1170. $arr1 = explode(',',$txt);
  1171. $arr2 = explode(',',$str);
  1172. $arr = array_merge($arr1,$arr2);
  1173. return join(',',array_unique( array_filter($arr)));
  1174. }
  1175. function mac_array_check_num($arr)
  1176. {
  1177. if(!is_array($arr)){
  1178. return false;
  1179. }
  1180. $res = true;
  1181. foreach($arr as $a){
  1182. if(!is_numeric($a)){
  1183. $res=false;
  1184. break;
  1185. }
  1186. }
  1187. return $res;
  1188. }
  1189. function mac_like_arr($s)
  1190. {
  1191. $tmp = explode(',',$s);
  1192. $like_arr = [];
  1193. foreach($tmp as $v){
  1194. $like_arr[] = '%'.$v.'%';
  1195. }
  1196. return $like_arr;
  1197. }
  1198. function mac_art_list($art_title,$art_note,$art_content)
  1199. {
  1200. $art_title_list = [];
  1201. $art_note_list = [];
  1202. $art_content_list = [];
  1203. if(!empty($art_title)) {
  1204. $art_title_list = explode('$$$', $art_title);
  1205. }
  1206. if(!empty($art_note)) {
  1207. $art_note_list = explode('$$$', $art_note);
  1208. }
  1209. if(!empty($art_content)) {
  1210. $art_content_list = explode('$$$', $art_content);
  1211. }
  1212. $res_list = [];
  1213. foreach($art_content_list as $k=>$v){
  1214. $res_list[$k+1] = [
  1215. 'page'=> $k+1,
  1216. 'title'=>$art_title_list[$k],
  1217. 'note'=>$art_note_list[$k],
  1218. 'content'=>$v,
  1219. ];
  1220. }
  1221. return $res_list;
  1222. }
  1223. function mac_plot_list($vod_plot_name,$vod_plot_detail)
  1224. {
  1225. $vod_plot_name_list = [];
  1226. $vod_plot_detail_list = [];
  1227. if(!empty($vod_plot_name)) {
  1228. $vod_plot_name_list = explode('$$$', $vod_plot_name);
  1229. }
  1230. if(!empty($vod_plot_detail)) {
  1231. $vod_plot_detail_list = explode('$$$', $vod_plot_detail);
  1232. }
  1233. $res_list = [];
  1234. foreach($vod_plot_name_list as $k=>$v){
  1235. $res_list[$k + 1] = [
  1236. 'name' => $vod_plot_name_list[$k],
  1237. 'detail' => $vod_plot_detail_list[$k],
  1238. ];
  1239. }
  1240. return $res_list;
  1241. }
  1242. function mac_play_list($vod_play_from,$vod_play_url,$vod_play_server,$vod_play_note,$flag='play')
  1243. {
  1244. $vod_play_from_list = [];
  1245. $vod_play_url_list = [];
  1246. $vod_play_server_list = [];
  1247. $vod_play_note_list = [];
  1248. if(!empty($vod_play_from)) {
  1249. $vod_play_from_list = explode('$$$', $vod_play_from);
  1250. }
  1251. if(!empty($vod_play_url)) {
  1252. $vod_play_url_list = explode('$$$', $vod_play_url);
  1253. }
  1254. if(!empty($vod_play_server)) {
  1255. $vod_play_server_list = explode('$$$', $vod_play_server);
  1256. }
  1257. if(!empty($vod_play_note)) {
  1258. $vod_play_note_list = explode('$$$', $vod_play_note);
  1259. }
  1260. if($flag=='play'){
  1261. $player_list = config('vodplayer');
  1262. }
  1263. else{
  1264. $player_list = config('voddowner');
  1265. }
  1266. $server_list = config('vodserver');
  1267. $res_list = [];
  1268. $sort=[];
  1269. foreach($vod_play_from_list as $k=>$v){
  1270. $server = (string)$vod_play_server_list[$k];
  1271. $urls = mac_play_list_one($vod_play_url_list[$k],$v);
  1272. $player_info = $player_list[$v];
  1273. $server_info = $server_list[$server];
  1274. if($player_info['status'] == '1') {
  1275. $sort[] = $player_info['sort'];
  1276. $res_list[$k + 1] = [
  1277. 'sid' => $k + 1,
  1278. 'player_info' => $player_info,
  1279. 'server_info' => $server_info,
  1280. 'from' => $v,
  1281. 'url' => $vod_play_url_list[$k],
  1282. 'server' => $server,
  1283. 'note' => $vod_play_note_list[$k],
  1284. 'url_count' => count($urls),
  1285. 'urls' => $urls,
  1286. ];
  1287. }
  1288. }
  1289. if( (ENTRANCE!='admin' && MAC_PLAYER_SORT=='1') || $GLOBALS['ismake']=='1' ){
  1290. array_multisort($sort, SORT_DESC, SORT_FLAG_CASE , $res_list);
  1291. $tmp=[];
  1292. foreach($res_list as $k=>$v){
  1293. $tmp[$v['sid']] = $v;
  1294. }
  1295. $res_list = $tmp;
  1296. }
  1297. return $res_list;
  1298. }
  1299. function new_stripslashes($string) {
  1300. if(!is_array($string)) return stripslashes($string);
  1301. foreach($string as $key => $val) $string[$key] = new_stripslashes($val);
  1302. return $string;
  1303. }
  1304. function mac_screenshot_list($screenshot)
  1305. {
  1306. $url_list = array();
  1307. $array_url = explode('#',$screenshot);
  1308. foreach($array_url as $key=>$val){
  1309. if(empty($val)) continue;
  1310. list($title, $url) = explode('$', $val);
  1311. if ( empty($url) ) {
  1312. $url_list[$key+1]['name'] = ($key+1);
  1313. $url_list[$key+1]['url'] = $title;
  1314. }else{
  1315. $url_list[$key+1]['name'] = $title;
  1316. $url_list[$key+1]['url'] = $url;
  1317. }
  1318. }
  1319. return $url_list;
  1320. }
  1321. function mac_play_list_one($url_one, $from_one, $server_one=''){
  1322. $url_list = array();
  1323. $array_url = explode('#',$url_one);
  1324. foreach($array_url as $key=>$val){
  1325. if(empty($val)) continue;
  1326. list($title, $url, $from) = explode('$', $val);
  1327. if ( empty($url) ) {
  1328. $url_list[$key+1]['name'] = lang('the').($key+1).lang('episode');
  1329. $url_list[$key+1]['url'] = $server_one.$title;
  1330. }else{
  1331. $url_list[$key+1]['name'] = $title;
  1332. $url_list[$key+1]['url'] = $server_one.$url;
  1333. }
  1334. if(empty($from)){
  1335. $from = $from_one;
  1336. }
  1337. $url_list[$key+1]['from'] = (string)$from;
  1338. $url_list[$key+1]['nid'] = $key+1;
  1339. }
  1340. return $url_list;
  1341. }
  1342. function mac_manga_list($manga_play_from,$manga_play_url,$manga_play_server,$manga_play_note)
  1343. {
  1344. $manga_play_from_list = [];
  1345. $manga_play_url_list = [];
  1346. $manga_play_server_list = [];
  1347. $manga_play_note_list = [];
  1348. if(!empty($manga_play_from)) {
  1349. $manga_play_from_list = explode('$$$', $manga_play_from);
  1350. }
  1351. if(!empty($manga_play_url)) {
  1352. $manga_play_url_list = explode('$$$', $manga_play_url);
  1353. }
  1354. if(!empty($manga_play_server)) {
  1355. $manga_play_server_list = explode('$$$', $manga_play_server);
  1356. }
  1357. if(!empty($manga_play_note)) {
  1358. $manga_play_note_list = explode('$$$', $manga_play_note);
  1359. }
  1360. $res_list = [];
  1361. foreach($manga_play_from_list as $k=>$v){
  1362. $server = (string)$manga_play_server_list[$k];
  1363. $urls = mac_play_list_one($manga_play_url_list[$k],$v);
  1364. $res_list[$k + 1] = [
  1365. 'sid' => $k + 1,
  1366. 'from' => $v,
  1367. 'url' => $manga_play_url_list[$k],
  1368. 'server' => $server,
  1369. 'note' => $manga_play_note_list[$k],
  1370. 'url_count' => count($urls),
  1371. 'urls' => $urls,
  1372. ];
  1373. }
  1374. return $res_list;
  1375. }
  1376. function mac_filter_words($p)
  1377. {
  1378. $config = config('maccms.app');
  1379. $arr = explode(",",$config['filter_words']);
  1380. if(is_array($p)){
  1381. foreach($p as $k=>$v){
  1382. $p[$k] = str_replace($arr,"***",$v);
  1383. }
  1384. }
  1385. else{
  1386. $p = str_replace($arr,"***",$p);
  1387. }
  1388. return $p;
  1389. }
  1390. function mac_long2ip($ip){
  1391. $ip = long2ip($ip);
  1392. $reg2 = '~(\d+)\.(\d+)\.(\d+)\.(\d+)~';
  1393. return preg_replace($reg2, "$1.$2.*.*", $ip);
  1394. }
  1395. function mac_default($s,$def='')
  1396. {
  1397. if(empty($s)){
  1398. return $def;
  1399. }
  1400. return $s;
  1401. }
  1402. function mac_num_fill($num)
  1403. {
  1404. if($num<10){
  1405. $num = '0' . $num;
  1406. }
  1407. return $num;
  1408. }
  1409. function mac_multisort($arr,$col_sort,$sort_order,$col_status='',$status_val='')
  1410. {
  1411. $sort=[];
  1412. foreach($arr as $k=>$v){
  1413. if($col_status!='' && $v[$col_status] != $status_val){
  1414. unset($arr[$k]);
  1415. } else {
  1416. $sort[] = isset($v[$col_sort]) ? $v[$col_sort] : 0;
  1417. }
  1418. }
  1419. array_multisort($sort, $sort_order, SORT_FLAG_CASE, $arr);
  1420. return $arr;
  1421. }
  1422. function mac_get_body($text,$start,$end)
  1423. {
  1424. if(empty($text)){ return false; }
  1425. if(empty($start)){ return false; }
  1426. if(empty($end)){ return false; }
  1427. $start=stripslashes($start);
  1428. $end=stripslashes($end);
  1429. if(strpos($text,$start)!=""){
  1430. $str = substr($text,strpos($text,$start)+strlen($start));
  1431. $str = substr($str,0,strpos($str,$end));
  1432. }
  1433. else{
  1434. $str='';
  1435. }
  1436. return $str;
  1437. }
  1438. function mac_find_array($text,$start,$end)
  1439. {
  1440. $start=stripslashes($start);
  1441. $end=stripslashes($end);
  1442. if(empty($text)){ return false; }
  1443. if(empty($start)){ return false; }
  1444. if(empty($end)){ return false; }
  1445. $start = str_replace(["(",")","'","?"],["\(","\)","\'","\?"],$start);
  1446. $end = str_replace(["(",")","'","?"],["\(","\)","\'","\?"],$end);
  1447. $labelRule = $start."(.*?)".$end;
  1448. $labelRule = mac_buildregx($labelRule,"is");
  1449. preg_match_all($labelRule,$text,$tmparr);
  1450. $tmparrlen=count($tmparr[1]);
  1451. $rc=false;
  1452. $str='';
  1453. $arr=[];
  1454. for($i=0;$i<$tmparrlen;$i++) {
  1455. if($rc){ $str .= "{array}"; }
  1456. $str .= $tmparr[1][$i];
  1457. $rc=true;
  1458. }
  1459. if(empty($str)) { return false ;}
  1460. $str=str_replace($start,"",$str);
  1461. $str=str_replace($end,"",$str);
  1462. //$str=str_replace("\"\"","",$str);
  1463. //$str=str_replace("'","",$str);
  1464. //$str=str_replace(" ","",$str);
  1465. if(empty($str)) { return false ;}
  1466. return $str;
  1467. }
  1468. /*前台页面*/
  1469. function mac_param_url(){
  1470. $input = input() ;
  1471. $param = [];
  1472. $tmp = $_REQUEST;
  1473. $input = array_merge($input,$tmp);
  1474. //$param['id'] = intval($input['id']);
  1475. $param['page'] = intval($input['page']) <1 ? 1 : intval($input['page']);
  1476. $param['ajax'] = intval($input['ajax']);
  1477. $param['tid'] = intval($input['tid']);
  1478. $param['mid'] = intval($input['mid']);
  1479. $param['rid'] = intval($input['rid']);
  1480. $param['pid'] = intval($input['pid']);
  1481. $param['sid'] = intval($input['sid']);
  1482. $param['nid'] = intval($input['nid']);
  1483. $param['uid'] = intval($input['uid']);
  1484. $param['level'] = intval($input['level']);
  1485. $param['score'] = intval($input['score']);
  1486. $param['limit'] = intval($input['limit']);
  1487. $param['id'] = htmlspecialchars(urldecode(trim($input['id'])));
  1488. $param['ids'] = htmlspecialchars(urldecode(trim($input['ids'])));
  1489. $param['wd'] = htmlspecialchars(urldecode(trim($input['wd'])));
  1490. $param['en'] = htmlspecialchars(urldecode(trim($input['en'])));
  1491. $param['state'] = htmlspecialchars(urldecode(trim($input['state'])));
  1492. $param['area'] = htmlspecialchars(urldecode(trim($input['area'])));
  1493. $param['year'] = htmlspecialchars(urldecode(trim($input['year'])));
  1494. $param['lang'] = htmlspecialchars(urldecode(trim($input['lang'])));
  1495. $param['letter'] = htmlspecialchars(trim($input['letter']));
  1496. $param['actor'] = htmlspecialchars(urldecode(trim($input['actor'])));
  1497. $param['director'] = htmlspecialchars(urldecode(trim($input['director'])));
  1498. $param['tag'] = htmlspecialchars(urldecode(trim($input['tag'])));
  1499. $param['class'] = htmlspecialchars(urldecode(trim($input['class'])));
  1500. $param['order'] = htmlspecialchars(urldecode(trim($input['order'])));
  1501. $param['by'] = htmlspecialchars(urldecode(trim($input['by'])));
  1502. $param['file'] = htmlspecialchars(urldecode(trim($input['file'])));
  1503. $param['name'] = htmlspecialchars(urldecode(trim($input['name'])));
  1504. $param['url'] = htmlspecialchars(urldecode(trim($input['url'])));
  1505. $param['type'] = htmlspecialchars(urldecode(trim($input['type'])));
  1506. $param['sex'] = htmlspecialchars(urldecode(trim($input['sex'])));
  1507. $param['version'] = htmlspecialchars(urldecode(trim($input['version'])));
  1508. $param['blood'] = htmlspecialchars(urldecode(trim($input['blood'])));
  1509. $param['starsign'] = htmlspecialchars(urldecode(trim($input['starsign'])));
  1510. $param['domain'] = htmlspecialchars(urldecode(trim($input['domain'])));
  1511. return $param;
  1512. }
  1513. function mac_get_page($page)
  1514. {
  1515. if(empty($page)) {
  1516. $param = mac_param_url();
  1517. $page = $param['page'];
  1518. }
  1519. return $page;
  1520. }
  1521. function mac_tpl_fetch($model,$tpl,$def='')
  1522. {
  1523. return $model . '/' . ( empty($tpl) ? $def : str_replace('.html','',$tpl) );
  1524. }
  1525. function mac_get_order($order,$param)
  1526. {
  1527. if(!empty($param['order'])) {
  1528. $order = $param['order'];
  1529. }
  1530. if(!in_array($order, ['asc', 'desc'])) {
  1531. $order = 'desc';
  1532. }
  1533. return $order;
  1534. }
  1535. function mac_url_img($url)
  1536. {
  1537. if(substr($url,0,4) == 'mac:'){
  1538. $protocol = $GLOBALS['config']['upload']['protocol'];
  1539. if(empty($protocol)){
  1540. $protocol = 'http';
  1541. }
  1542. $url = str_replace('mac:', $protocol.':',$url);
  1543. }
  1544. elseif(substr($url,0,4) != 'http' && substr($url,0,2) != '//' && substr($url,0,1) != '/'){
  1545. if($GLOBALS['config']['upload']['mode']=='remote'){
  1546. $url = $GLOBALS['config']['upload']['remoteurl'] . $url;
  1547. }
  1548. else{
  1549. $url = MAC_PATH . $url;
  1550. }
  1551. }
  1552. elseif(!empty($GLOBALS['config']['upload']['img_key']) && preg_match('/'.$GLOBALS['config']['upload']['img_key'].'/',$url)){
  1553. $url = $GLOBALS['config']['upload']['img_api'] . '' . $url;
  1554. }
  1555. $url = mac_filter_xss($url);
  1556. $url = str_replace('&quot;&gt;', '', $url);
  1557. $url = str_replace('&amp;', '&', $url);
  1558. return $url;
  1559. }
  1560. function mac_url_content_img($content)
  1561. {
  1562. $protocol = $GLOBALS['config']['upload']['protocol'];
  1563. if(empty($protocol)){
  1564. $protocol = 'http';
  1565. }
  1566. $content = str_replace('mac:',$protocol.':',$content);
  1567. if(!empty($GLOBALS['config']['upload']['img_key'])){
  1568. $rule = mac_buildregx("<img[^>]*src\s*=\s*['" . chr(34) . "]?([\w/\-\:.]*)['" . chr(34) . "]?[^>]*>", "is");
  1569. preg_match_all($rule, $content, $matches);
  1570. if(is_array($matches[1])){
  1571. foreach ($matches[1] as $f => $matchfieldstr) {
  1572. $img_src = trim(preg_replace("/[ \r\n\t\f]{1,}/", " ", $matchfieldstr));
  1573. if(preg_match('/'.$GLOBALS['config']['upload']['img_key'].'/',$img_src)){
  1574. $content = str_replace($img_src,$GLOBALS['config']['upload']['img_api'] . '' . $img_src,$content);
  1575. }
  1576. }
  1577. }
  1578. }
  1579. return $content;
  1580. }
  1581. function mac_alphaID($in, $to_num=false, $pad_up=false, $passKey='')
  1582. {
  1583. $key = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  1584. if (!empty($passKey)) {
  1585. for ($n = 0; $n<strlen($key); $n++) {
  1586. $i[] = substr($key,$n ,1);
  1587. }
  1588. $len = strlen($key);
  1589. $passhash = hash('sha256',$passKey);
  1590. $passhash = (strlen($passhash) < $len)
  1591. ? hash('sha512',$passKey)
  1592. : $passhash;
  1593. for ($n=0; $n < $len; $n++) {
  1594. $p[] = substr($passhash, $n ,1);
  1595. }
  1596. array_multisort($p, SORT_DESC, $i);
  1597. $key = implode($i);
  1598. }
  1599. $base = strlen($key);
  1600. if ($to_num) {
  1601. $out = 0;
  1602. $len = strlen($in);
  1603. for ($t = 0; $t < $len; $t++) {
  1604. $char = substr($in, $t, 1);
  1605. $pos = strpos($key, $char);
  1606. if ($pos === false) {
  1607. $pos = 0;
  1608. }
  1609. $out = $out * $base + $pos;
  1610. }
  1611. if (is_numeric($pad_up)) {
  1612. if ($pad_up > 1) {
  1613. $out -= pow($base, $pad_up - 1);
  1614. }
  1615. }
  1616. } else {
  1617. if (is_numeric($pad_up)) {
  1618. if ($pad_up > 1) {
  1619. $in += pow($base, $pad_up - 1);
  1620. }
  1621. }
  1622. $out = "";
  1623. // 修复部分:改用逐位计算代替浮点运算
  1624. while ($in > 0) {
  1625. $remainder = $in % $base;
  1626. $out = substr($key, $remainder, 1) . $out;
  1627. $in = ($in - $remainder) / $base;
  1628. }
  1629. }
  1630. return $out;
  1631. }
  1632. function mac_url($model,$param=[],$info=[])
  1633. {
  1634. foreach($param as $k=>$v){
  1635. if(empty($v)){
  1636. unset($param[$k]);
  1637. }
  1638. }
  1639. if(!isset($param['page'])) $param['page']=1;
  1640. if($param['page'] == 1){
  1641. $param['page']='';
  1642. }
  1643. ksort($param);
  1644. $config = $GLOBALS['config'];
  1645. $is_static_mode = isset($GLOBALS['ismake']) && $GLOBALS['ismake'] == '1';
  1646. // 静态生成模式标记(用于后续URL处理)
  1647. $replace_from = ['{id}','{en}','{page}','{type_id}','{type_en}','{type_pid}','{type_pen}','{md5}','{year}','{month}','{day}','{sid}','{nid}'];
  1648. $replace_to = [];
  1649. $page_sp = $config['path']['page_sp'];
  1650. $path = '';
  1651. switch ($model)
  1652. {
  1653. case 'index/index':
  1654. if($config['view']['index'] == 2){
  1655. $path = 'index';
  1656. if(substr($path,strlen($path)-1,1)=='/'){
  1657. $path .= 'index';
  1658. }
  1659. }
  1660. else{
  1661. $url = url($model,$param);
  1662. if($url=='/PAGELINK.html'){
  1663. $url = '/index-PAGELINK.html';
  1664. }
  1665. }
  1666. break;
  1667. case 'map/index':
  1668. if($config['view']['map'] == 2){
  1669. $path = 'map';
  1670. if(substr($path,strlen($path)-1,1)=='/'){
  1671. $path .= 'index';
  1672. }
  1673. }
  1674. else{
  1675. $url = url($model,$param);
  1676. }
  1677. break;
  1678. case strpos($model,'rss/')!==false:
  1679. if($config['view']['rss'] == 2){
  1680. $path = $model;
  1681. if($param['page'] !=''){
  1682. $path .= $page_sp . $param['page'];
  1683. }
  1684. $path .= '.xml';
  1685. }
  1686. else{
  1687. $url = url($model,$param,'xml');
  1688. }
  1689. break;
  1690. case strpos($model,'label/')!==false:
  1691. if($config['view']['label'] == 2){
  1692. $path = $model;
  1693. }
  1694. else{
  1695. $url = url($model,$param);
  1696. }
  1697. break;
  1698. case 'vod/show':
  1699. case 'art/show':
  1700. case 'actor/show':
  1701. case 'website/show':
  1702. switch($config['rewrite']['type_id'])
  1703. {
  1704. case 1:
  1705. $id = $info['type_en'];
  1706. break;
  1707. case 2:
  1708. $id = mac_alphaID($info['type_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1709. break;
  1710. default:
  1711. $id = $info['type_id'];
  1712. break;
  1713. }
  1714. if(!empty($id)){
  1715. $param['id'] = $id;
  1716. }
  1717. $url = url($model,$param);
  1718. break;
  1719. case 'vod/type':
  1720. $replace_to = [$info['type_id'],$info['type_en'],$param['page'],
  1721. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en'],
  1722. ];
  1723. if($config['view']['vod_type'] == 2){
  1724. $path = $config['path']['vod_type'];
  1725. if(substr($path,strlen($path)-1,1)=='/'){
  1726. $path .= 'index';
  1727. }
  1728. $replace_to[] = md5($info['type_id']);
  1729. if($param['page'] !=''){
  1730. $path .= $page_sp . $param['page'];
  1731. }
  1732. }
  1733. else{
  1734. switch($config['rewrite']['type_id'])
  1735. {
  1736. case 1:
  1737. $id = $info['type_en'];
  1738. break;
  1739. case 2:
  1740. $id = mac_alphaID($info['type_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1741. break;
  1742. default:
  1743. $id = $info['type_id'];
  1744. break;
  1745. }
  1746. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  1747. }
  1748. break;
  1749. case 'vod/detail':
  1750. $replace_to = [$info['vod_id'],$info['vod_en'],'',
  1751. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en']
  1752. ];
  1753. if($config['view']['vod_detail'] == 2){
  1754. $path = $config['path' ]['vod_detail'];
  1755. if(substr($path,strlen($path)-1,1)=='/'){
  1756. $path .= 'index';
  1757. }
  1758. $replace_to[] = md5($info['vod_id']);
  1759. }
  1760. else{
  1761. switch($config['rewrite']['vod_id'])
  1762. {
  1763. case 1:
  1764. $id = $info['vod_en'];
  1765. break;
  1766. case 2:
  1767. $id = mac_alphaID($info['vod_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1768. break;
  1769. default:
  1770. $id = $info['vod_id'];
  1771. break;
  1772. }
  1773. $url = url($model,['id'=> $id ]);
  1774. }
  1775. $replace_to = array_merge($replace_to,[date('Y',$info['vod_time']),date('m',$info['vod_time']),date('d',$info['vod_time'])]);
  1776. break;
  1777. case 'vod/play':
  1778. $replace_to = [
  1779. $info['vod_id'],$info['vod_en'],'',
  1780. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en'],
  1781. ];
  1782. if($config['view']['vod_play'] >=2){
  1783. $path = $config['path' ]['vod_play'];
  1784. if(substr($path,strlen($path)-1,1)=='/'){
  1785. $path .= 'index';
  1786. }
  1787. $replace_to[] = md5($info['vod_id']);
  1788. if($config['view']['vod_play'] ==2){
  1789. $path.= '.'. $config['path']['suffix'];
  1790. $path .= '?'.$info['vod_id'] . '-' . $param['sid'] . '-' . $param['nid'] ;
  1791. }
  1792. elseif($config['view']['vod_play'] ==3){
  1793. $path .= $config['path']['page_sp'] . $param['sid'] . $config['path']['page_sp'] . $param['nid'] ;
  1794. }
  1795. elseif($config['view']['vod_play'] ==4){
  1796. $path .= $config['path']['page_sp'] .''. $param['sid'] . $config['path']['page_sp'] . '1';
  1797. $path.= '.'. $config['path']['suffix'];
  1798. $path .= '?'.$info['vod_id'] . '-' . $param['sid'] . '-' . $param['nid'] ;
  1799. }
  1800. }
  1801. else{
  1802. switch($config['rewrite']['vod_id'])
  1803. {
  1804. case 1:
  1805. $id = $info['vod_en'];
  1806. break;
  1807. case 2:
  1808. $id = mac_alphaID($info['vod_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1809. break;
  1810. default:
  1811. $id = $info['vod_id'];
  1812. break;
  1813. }
  1814. $url = url($model,['id'=>$id,'sid'=>$param['sid'],'nid'=>$param['nid']]);
  1815. }
  1816. $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']]);
  1817. break;
  1818. case 'vod/down':
  1819. $replace_to = [
  1820. $info['vod_id'],$info['vod_en'],'',
  1821. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en']
  1822. ];
  1823. if($config['view']['vod_down'] >= 2){
  1824. $path = $config['path' ]['vod_down'];
  1825. if(substr($path,strlen($path)-1,1)=='/'){
  1826. $path .= 'index';
  1827. }
  1828. $replace_to[] = md5($info['vod_id']);
  1829. if($config['view']['vod_down'] ==2){
  1830. $path.= '.'. $config['path']['suffix'];
  1831. $path .= '?'.$info['vod_id'] . '-' . $param['sid'] . '-' . $param['nid'] ;
  1832. }
  1833. elseif($config['view']['vod_down'] ==3){
  1834. $path .= $config['path']['page_sp'] . $param['sid'] . $config['path']['page_sp'] . $param['nid'] ;
  1835. }
  1836. elseif($config['view']['vod_down'] ==4){
  1837. $path .= $config['path']['page_sp'] .''. $param['sid'] . $config['path']['page_sp'] . '1';
  1838. $path.= '.'. $config['path']['suffix'];
  1839. $path .= '?'.$info['vod_id'] . '-' . $param['sid'] . '-' . $param['nid'] ;
  1840. }
  1841. }
  1842. else{
  1843. switch($config['rewrite']['vod_id'])
  1844. {
  1845. case 1:
  1846. $id = $info['vod_en'];
  1847. break;
  1848. case 2:
  1849. $id = mac_alphaID($info['vod_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1850. break;
  1851. default:
  1852. $id = $info['vod_id'];
  1853. break;
  1854. }
  1855. $url = url($model,['id'=>$id,'sid'=>$param['sid'],'nid'=>$param['nid']]);
  1856. }
  1857. $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']]);
  1858. break;
  1859. case 'vod/role':
  1860. $replace_to = [$info['vod_id'],$info['vod_en'],'',
  1861. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en']
  1862. ];
  1863. if($config['view']['vod_role'] == 2){
  1864. $path = $config['path' ]['vod_role'];
  1865. if(substr($path,strlen($path)-1,1)=='/'){
  1866. $path .= 'index';
  1867. }
  1868. $replace_to[] = md5($info['vod_id']);
  1869. }
  1870. else{
  1871. switch($config['rewrite']['vod_id'])
  1872. {
  1873. case 1:
  1874. $id = $info['vod_en'];
  1875. break;
  1876. case 2:
  1877. $id = mac_alphaID($info['vod_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1878. break;
  1879. default:
  1880. $id = $info['vod_id'];
  1881. break;
  1882. }
  1883. $url = url($model,['id'=>$id]);
  1884. }
  1885. $replace_to = array_merge($replace_to,[date('Y',$info['vod_time']),date('m',$info['vod_time']),date('d',$info['vod_time'])]);
  1886. break;
  1887. case 'vod/plot':
  1888. $replace_to = [
  1889. $info['vod_id'],$info['vod_en'],$param['page'],
  1890. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en']
  1891. ];
  1892. if($config['view']['vod_plot'] == 2){
  1893. $path = $config['path' ]['vod_plot'];
  1894. if(substr($path,strlen($path)-1,1)=='/'){
  1895. $path .= 'index';
  1896. }
  1897. $replace_to[] = md5($info['vod_id']);
  1898. if($param['page']!=''){
  1899. $path .= $page_sp . $param['page'];
  1900. }
  1901. }
  1902. else{
  1903. switch($config['rewrite']['vod_id'])
  1904. {
  1905. case 1:
  1906. $id = $info['vod_en'];
  1907. break;
  1908. case 2:
  1909. $id = mac_alphaID($info['vod_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1910. break;
  1911. default:
  1912. $id = $info['vod_id'];
  1913. break;
  1914. }
  1915. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  1916. }
  1917. $replace_to = array_merge($replace_to,[date('Y',$info['vod_time']),date('m',$info['vod_time']),date('d',$info['vod_time'])]);
  1918. break;
  1919. case 'art/type':
  1920. $replace_to = [$info['type_id'],$info['type_en'],$param['page'],
  1921. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en'],
  1922. ];
  1923. if($config['view']['art_type'] == 2){
  1924. $path = $config['path']['art_type'];
  1925. if(substr($path,strlen($path)-1,1)=='/'){
  1926. $path .= 'index';
  1927. }
  1928. if(strpos($path,'{md5}')!==false){
  1929. $replace_to[] = md5($info['type_id']);
  1930. }
  1931. if($param['page']!=''){
  1932. $path .= $page_sp . $param['page'];
  1933. }
  1934. }
  1935. else{
  1936. switch($config['rewrite']['type_id'])
  1937. {
  1938. case 1:
  1939. $id = $info['type_en'];
  1940. break;
  1941. case 2:
  1942. $id = mac_alphaID($info['type_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1943. break;
  1944. default:
  1945. $id = $info['type_id'];
  1946. break;
  1947. }
  1948. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  1949. }
  1950. break;
  1951. case 'art/detail':
  1952. $replace_to = [
  1953. $info['art_id'],$info['art_en'],'',
  1954. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en']
  1955. ];
  1956. if($config['view']['art_detail'] == 2){
  1957. $path = $config['path' ]['art_detail'];
  1958. if(substr($path,strlen($path)-1,1)=='/'){
  1959. $path .= 'index';
  1960. }
  1961. $replace_to[] = md5($info['art_id']);
  1962. if($param['page']>1 || $param['page'] =='PAGELINK'){
  1963. $path .= $page_sp . $param['page'];
  1964. }
  1965. }
  1966. else{
  1967. switch($config['rewrite']['art_id'])
  1968. {
  1969. case 1:
  1970. $id = $info['art_en'];
  1971. break;
  1972. case 2:
  1973. $id = mac_alphaID($info['art_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  1974. break;
  1975. default:
  1976. $id = $info['art_id'];
  1977. break;
  1978. }
  1979. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  1980. }
  1981. $replace_to = array_merge($replace_to,[date('Y',$info['art_time']),date('m',$info['art_time']),date('d',$info['art_time'])]);
  1982. break;
  1983. case 'topic/index':
  1984. if($config['view']['topic_index'] == 2){
  1985. $path = $config['path' ]['topic_index'];
  1986. if(substr($path,strlen($path)-1,1)=='/'){
  1987. $path .= 'index';
  1988. }
  1989. if($param['page']>1 || $param['page'] =='PAGELINK'){
  1990. $path .= $page_sp . $param['page'];
  1991. }
  1992. }
  1993. else{
  1994. $url = url($model,['page'=>$param['page']]);
  1995. }
  1996. break;
  1997. case 'topic/detail':
  1998. $replace_to = [$info['topic_id'],$info['topic_en'],'','','','',''];
  1999. if($config['view']['topic_detail'] == 2){
  2000. $path = $config['path' ]['topic_detail'];
  2001. if(substr($path,strlen($path)-1,1)=='/'){
  2002. $path .= 'index';
  2003. }
  2004. if(strpos($path,'{md5}')!==false){
  2005. $replace_to[] = md5($info['topic_id']);
  2006. }
  2007. }
  2008. else{
  2009. switch($config['rewrite']['topic_id'])
  2010. {
  2011. case 1:
  2012. $id = $info['topic_en'];
  2013. break;
  2014. case 2:
  2015. $id = mac_alphaID($info['topic_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2016. break;
  2017. default:
  2018. $id = $info['topic_id'];
  2019. break;
  2020. }
  2021. $url = url($model,['id'=>$id]);
  2022. }
  2023. break;
  2024. case 'actor/index':
  2025. if($config['view']['actor_index'] == 2){
  2026. $path = $config['path' ]['actor_index'];
  2027. if(substr($path,strlen($path)-1,1)=='/'){
  2028. $path .= 'index';
  2029. }
  2030. if($param['page']>1 || $param['page'] =='PAGELINK'){
  2031. $path .= $page_sp . $param['page'];
  2032. }
  2033. }
  2034. else{
  2035. $url = url($model,['page'=>$param['page']]);
  2036. }
  2037. break;
  2038. case 'actor/type':
  2039. $replace_to = [$info['type_id'],$info['type_en'],$param['page'],
  2040. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en'],
  2041. ];
  2042. if($config['view']['actor_type'] == 2){
  2043. $path = $config['path']['actor_type'];
  2044. if(substr($path,strlen($path)-1,1)=='/'){
  2045. $path .= 'index';
  2046. }
  2047. if(strpos($path,'{md5}')!==false){
  2048. $replace_to[] = md5($info['type_id']);
  2049. }
  2050. if($param['page']!=''){
  2051. $path .= $page_sp . $param['page'];
  2052. }
  2053. }
  2054. else{
  2055. switch($config['rewrite']['type_id'])
  2056. {
  2057. case 1:
  2058. $id = $info['type_en'];
  2059. break;
  2060. case 2:
  2061. $id = mac_alphaID($info['type_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2062. break;
  2063. default:
  2064. $id = $info['type_id'];
  2065. break;
  2066. }
  2067. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  2068. }
  2069. break;
  2070. case 'actor/detail':
  2071. $replace_to = [$info['actor_id'],$info['actor_en'],'','','','',''];
  2072. if($config['view']['actor_detail'] == 2){
  2073. $path = $config['path' ]['actor_detail'];
  2074. if(substr($path,strlen($path)-1,1)=='/'){
  2075. $path .= 'index';
  2076. }
  2077. if(strpos($path,'{md5}')!==false){
  2078. $replace_to[] = md5($info['actor_id']);
  2079. }
  2080. }
  2081. else{
  2082. switch($config['rewrite']['actor_id'])
  2083. {
  2084. case 1:
  2085. $id = $info['actor_en'];
  2086. break;
  2087. case 2:
  2088. $id = mac_alphaID($info['actor_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2089. break;
  2090. default:
  2091. $id = $info['actor_id'];
  2092. break;
  2093. }
  2094. $url = url($model,['id'=>$id]);
  2095. }
  2096. break;
  2097. case 'role/index':
  2098. if($config['view']['role_index'] == 2){
  2099. $path = $config['path' ]['role_index'];
  2100. if(substr($path,strlen($path)-1,1)=='/'){
  2101. $path .= 'index';
  2102. }
  2103. if($param['page']>1 || $param['page'] =='PAGELINK'){
  2104. $path .= $page_sp . $param['page'];
  2105. }
  2106. }
  2107. else{
  2108. $url = url($model,['page'=>$param['page']]);
  2109. }
  2110. break;
  2111. case 'role/detail':
  2112. $replace_to = [$info['role_id'],$info['actor_en'],'','','','',''];
  2113. if($config['view']['role_detail'] == 2){
  2114. $path = $config['path' ]['role_detail'];
  2115. if(substr($path,strlen($path)-1,1)=='/'){
  2116. $path .= 'index';
  2117. }
  2118. if(strpos($path,'{md5}')!==false){
  2119. $replace_to[] = md5($info['role_id']);
  2120. }
  2121. }
  2122. else{
  2123. switch($config['rewrite']['role_id'])
  2124. {
  2125. case 1:
  2126. $id = $info['role_en'];
  2127. break;
  2128. case 2:
  2129. $id = mac_alphaID($info['role_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2130. break;
  2131. default:
  2132. $id = $info['role_id'];
  2133. break;
  2134. }
  2135. $url = url($model,['id'=>$id]);
  2136. }
  2137. break;
  2138. case 'plot/index':
  2139. if($config['view']['plot_index'] == 2){
  2140. $path = $config['path' ]['plot_index'];
  2141. if(substr($path,strlen($path)-1,1)=='/'){
  2142. $path .= 'index';
  2143. }
  2144. if($param['page']>1 || $param['page'] =='PAGELINK'){
  2145. $path .= $page_sp . $param['page'];
  2146. }
  2147. }
  2148. else{
  2149. $url = url($model,['page'=>$param['page']]);
  2150. }
  2151. break;
  2152. case 'plot/detail':
  2153. $replace_to = [
  2154. $info['vod_id'],$info['vod_en'],'',
  2155. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en']
  2156. ];
  2157. if($config['view']['plot_detail'] == 2){
  2158. $path = $config['path' ]['plot_detail'];
  2159. if(substr($path,strlen($path)-1,1)=='/'){
  2160. $path .= 'index';
  2161. }
  2162. if(strpos($path,'{md5}')!==false){
  2163. $replace_to[] = md5($info['vod_id']);
  2164. }
  2165. if($param['page']>1 || $param['page'] =='PAGELINK'){
  2166. $path .= $page_sp . $param['page'];
  2167. }
  2168. }
  2169. else{
  2170. switch($config['rewrite']['vod_id'])
  2171. {
  2172. case 1:
  2173. $id = $info['vod_en'];
  2174. break;
  2175. case 2:
  2176. $id = mac_alphaID($info['vod_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2177. break;
  2178. default:
  2179. $id = $info['vod_id'];
  2180. break;
  2181. }
  2182. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  2183. }
  2184. $replace_to = array_merge($replace_to,[date('Y',$info['vod_time']),date('m',$info['vod_time']),date('d',$info['vod_time'])]);
  2185. break;
  2186. case 'website/index':
  2187. if($config['view']['website_index'] == 2){
  2188. $path = $config['path' ]['website_index'];
  2189. if(substr($path,strlen($path)-1,1)=='/'){
  2190. $path .= 'index';
  2191. }
  2192. if($param['page']>1 || $param['page'] =='PAGELINK'){
  2193. $path .= $page_sp . $param['page'];
  2194. }
  2195. }
  2196. else{
  2197. $url = url($model,['page'=>$param['page']]);
  2198. }
  2199. break;
  2200. case 'website/type':
  2201. $replace_to = [$info['type_id'],$info['type_en'],$param['page'],
  2202. $info['type_id'],$info['type']['type_en'],$info['type_1']['type_id'],$info['type_1']['type_en'],
  2203. ];
  2204. if($config['view']['website_type'] == 2){
  2205. $path = $config['path']['website_type'];
  2206. if(substr($path,strlen($path)-1,1)=='/'){
  2207. $path .= 'index';
  2208. }
  2209. if(strpos($path,'{md5}')!==false){
  2210. $replace_to[] = md5($info['type_id']);
  2211. }
  2212. if($param['page']!=''){
  2213. $path .= $page_sp . $param['page'];
  2214. }
  2215. }
  2216. else{
  2217. switch($config['rewrite']['type_id'])
  2218. {
  2219. case 1:
  2220. $id = $info['type_en'];
  2221. break;
  2222. case 2:
  2223. $id = mac_alphaID($info['type_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2224. break;
  2225. default:
  2226. $id = $info['type_id'];
  2227. break;
  2228. }
  2229. $url = url($model,['id'=>$id,'page'=>$param['page']]);
  2230. }
  2231. break;
  2232. case 'website/detail':
  2233. $replace_to = [$info['website_id'],$info['website_en'],'','','','',''];
  2234. if($config['view']['website_detail'] == 2){
  2235. $path = $config['path' ]['website_detail'];
  2236. if(substr($path,strlen($path)-1,1)=='/'){
  2237. $path .= 'index';
  2238. }
  2239. if(strpos($path,'{md5}')!==false){
  2240. $replace_to[] = md5($info['website_id']);
  2241. }
  2242. }
  2243. else{
  2244. switch($config['rewrite']['website_id'])
  2245. {
  2246. case 1:
  2247. $id = $info['website_en'];
  2248. break;
  2249. case 2:
  2250. $id = mac_alphaID($info['website_id'],false,$config['rewrite']['encode_len'],$config['rewrite']['encode_key']);
  2251. break;
  2252. default:
  2253. $id = $info['website_id'];
  2254. break;
  2255. }
  2256. $url = url($model,['id'=>$id]);
  2257. }
  2258. break;
  2259. case 'gbook/index':
  2260. $url = url($model,['page'=>$param['page']]);
  2261. break;
  2262. case 'comment/index':
  2263. $url = url($model,['page'=>$param['page']]);
  2264. break;
  2265. default:
  2266. $url = url($model,$param);
  2267. break;
  2268. }
  2269. if(!empty($path)) {
  2270. $path = str_replace($replace_from, $replace_to, $path);
  2271. $path = str_replace('//', '/', $path);
  2272. $delimiter = false;
  2273. if(substr($path,strlen($path)-6) =='/index'){
  2274. $delimiter = true;
  2275. $path = substr($path,0, strlen($path)-5);
  2276. }
  2277. if($delimiter==false && strpos($path,'.')===false){
  2278. $path.= '.'. $config['path']['suffix'];
  2279. }
  2280. $url = $path;
  2281. if(substr($path,0,1)!='/') {
  2282. $url = MAC_PATH . $path;
  2283. }
  2284. }
  2285. else{
  2286. if(ENTRANCE!='index'){
  2287. $sto= MAC_PATH ;
  2288. if($config['rewrite']['status']==0){
  2289. $sto = MAC_PATH .'index.php/';
  2290. }
  2291. if(!empty(IN_FILE)){
  2292. $url = str_replace(IN_FILE.'/',$sto,$url);
  2293. $url = str_replace(ENTRANCE.'/','',$url);
  2294. }
  2295. }
  2296. elseif($config['rewrite']['status']==0 && strpos($url,'index.php')===false){
  2297. if(MAC_PATH !='/'){
  2298. $url = str_replace(MAC_PATH,'/',$url);
  2299. }
  2300. $url = MAC_PATH. 'index.php' . $url;
  2301. }
  2302. elseif($config['rewrite']['status']==1 && strpos($url,'index.php')!==false){
  2303. $url = str_replace('index.php/','',$url);
  2304. }
  2305. if($config['rewrite']['suffix_hide']==1){
  2306. $url = str_replace('.html','/',$url);
  2307. if(strpos($model,'/show')===false && strpos($model,'/search')===false) {
  2308. $url = str_replace(['-/','_/','-.','_.'],'/',$url);
  2309. }
  2310. }
  2311. else{
  2312. if(strpos($model,'search')===false && strpos($model,'show')===false ) {
  2313. $url = str_replace(['-.', '/.'], '.', $url);
  2314. }
  2315. }
  2316. }
  2317. // 在静态生成模式下,对生成的URL进行后处理,去掉admin/index前缀
  2318. if($is_static_mode && !empty($url)) {
  2319. if(strpos($url, '/index.php/') === 0) {
  2320. $url = preg_replace('/\/index\.php\/[^\/]+\.php\/admin\-/', '/index.php/', $url);
  2321. $url = str_replace('/admin-', '/', $url);
  2322. }
  2323. if(strpos($url, 'admin-') !== false) {
  2324. $url = str_replace('admin-', '', $url);
  2325. }
  2326. if(strpos($url, 'index-') !== false) {
  2327. $url = str_replace('index-', '', $url);
  2328. }
  2329. }
  2330. return $url;
  2331. }
  2332. function mac_url_page($url,$num)
  2333. {
  2334. $url = str_replace(MAC_PAGE_SP.'PAGELINK',($num>1 ? MAC_PAGE_SP.$num : ''),$url);
  2335. $url = str_replace('PAGELINK',$num,$url);
  2336. return $url;
  2337. }
  2338. function mac_url_create($str,$type='actor',$flag='vod',$ac='search',$sp='&nbsp;')
  2339. {
  2340. if(!$str){
  2341. return '未知';
  2342. }
  2343. $res = [];
  2344. // 分割时,中文关键词允许空格分割,英文不用空格(英文名中间是空格分隔的问题)
  2345. $base_finder = array(' / ', '/', '|', ',', ',', ',,');
  2346. $str = str_replace($base_finder, ',', $str);
  2347. $str = trim($str, ',');
  2348. $arr = [];
  2349. foreach (explode(',', $str) as $tag) {
  2350. if (preg_match("/[\x{2E80}-\x{9FFF}]+/u", $tag) && str_contains($tag, ' ')) {
  2351. foreach (explode(' ', $tag) as $tag_exp) {
  2352. $arr[] = $tag_exp;
  2353. }
  2354. } else {
  2355. $arr[] = $tag;
  2356. }
  2357. }
  2358. foreach ($arr as $k => $v) {
  2359. $res[$k] = '<a href="'.mac_url($flag.'/'.$ac,[$type=>$v]).'" target="_blank">'.$v.'</a>'.$sp;
  2360. }
  2361. return implode('',$res);
  2362. }
  2363. function mac_url_search($param=[],$flag='vod')
  2364. {
  2365. return mac_url($flag.'/search',$param);
  2366. }
  2367. function mac_url_type($info,$param=[],$flag='type')
  2368. {
  2369. $tab = 'vod';
  2370. if($info['type_mid'] == 1){
  2371. }
  2372. else if($info['type_mid'] == 2) {
  2373. $tab ='art';
  2374. }
  2375. else if($info['type_mid'] == 8) {
  2376. $tab ='actor';
  2377. }
  2378. else if($info['type_mid'] == 11) {
  2379. $tab ='website';
  2380. }
  2381. if(empty($param['id'])){
  2382. $param['id'] = $info['type_id'];
  2383. }
  2384. return mac_url($tab.'/'.$flag,$param,$info);
  2385. }
  2386. function mac_url_topic_index($param=[])
  2387. {
  2388. return mac_url('topic/index',['page'=>$param['page']]);
  2389. }
  2390. function mac_url_topic_detail($info)
  2391. {
  2392. return mac_url('topic/detail',[],$info);
  2393. }
  2394. function mac_url_role_index($param=[])
  2395. {
  2396. return mac_url('role/index',['page'=>$param['page']]);
  2397. }
  2398. function mac_url_role_detail($info)
  2399. {
  2400. return mac_url('role/detail',[],$info);
  2401. }
  2402. function mac_url_actor_index($param=[])
  2403. {
  2404. return mac_url('actor/index',['page'=>$param['page']]);
  2405. }
  2406. function mac_url_actor_detail($info)
  2407. {
  2408. return mac_url('actor/detail',[],$info);
  2409. }
  2410. function mac_url_actor_search($param)
  2411. {
  2412. return mac_url('actor/search',$param);
  2413. }
  2414. function mac_url_plot_index($param=[])
  2415. {
  2416. return mac_url('plot/index',['page'=>$param['page']]);
  2417. }
  2418. function mac_url_plot_detail($info,$param=[])
  2419. {
  2420. return mac_url('plot/detail',['page'=>$param['page']],$info);
  2421. }
  2422. function mac_url_vod_plot($info,$param=[])
  2423. {
  2424. return mac_url('vod/plot',$param,$info);
  2425. }
  2426. function mac_url_vod_role($info,$param=[])
  2427. {
  2428. return mac_url('vod/role',$param,$info);
  2429. }
  2430. function mac_url_website_index($param=[])
  2431. {
  2432. return mac_url('website/index',['page'=>$param['page']]);
  2433. }
  2434. function mac_url_website_detail($info)
  2435. {
  2436. return mac_url('website/detail',[],$info);
  2437. }
  2438. function mac_url_website_search($param)
  2439. {
  2440. return mac_url('website/search',$param);
  2441. }
  2442. function mac_url_art_index($param=[])
  2443. {
  2444. return mac_url('art/index',['page'=>$param['page']]);
  2445. }
  2446. function mac_url_art_detail($info,$param=[])
  2447. {
  2448. return mac_url('art/detail',['page'=>$param['page']],$info);
  2449. }
  2450. function mac_url_art_search($param)
  2451. {
  2452. return mac_url('art/search',$param);
  2453. }
  2454. function mac_url_vod_index($param=[])
  2455. {
  2456. return mac_url('vod/index',['page'=>$param['page']]);
  2457. }
  2458. function mac_url_vod_detail($info)
  2459. {
  2460. return mac_url('vod/detail',[],$info);
  2461. }
  2462. function mac_url_manga_detail($info)
  2463. {
  2464. return mac_url('manga/detail',[],$info);
  2465. }
  2466. function mac_url_vod_search($param)
  2467. {
  2468. return mac_url('vod/search',$param);
  2469. }
  2470. function mac_url_vod_play($info,$param=[])
  2471. {
  2472. if($param=='first'){
  2473. $sid = intval(key($info['vod_play_list']));
  2474. $nid = intval(key($info['vod_play_list'][$sid]['urls']));
  2475. if($sid==0 || $nid==0){
  2476. return '';
  2477. }
  2478. $param=[];
  2479. $param['sid'] = $sid;
  2480. $param['nid'] = $nid;
  2481. }
  2482. if(intval($param['sid'])<1){
  2483. $param['sid'] =1;
  2484. }
  2485. if(intval($param['nid'])<1){
  2486. $param['nid']=1;
  2487. }
  2488. return mac_url('vod/play',['sid'=>$param['sid'],'nid'=>$param['nid']],$info);
  2489. }
  2490. function mac_url_vod_down($info,$param=[])
  2491. {
  2492. if($param=='first'){
  2493. $sid = intval(key($info['vod_down_list']));
  2494. $nid = intval(key($info['vod_down_list'][$sid]['urls']));
  2495. if($sid==0 || $nid==0){
  2496. return '';
  2497. }
  2498. $param=[];
  2499. $param['sid'] = $sid;
  2500. $param['nid'] = $nid;
  2501. }
  2502. if(intval($param['sid'])<1){
  2503. $param['sid'] =1;
  2504. }
  2505. if(intval($param['nid'])<1){
  2506. $param['nid']=1;
  2507. }
  2508. return mac_url('vod/down',['sid'=>$param['sid'],'nid'=>$param['nid']],$info);
  2509. }
  2510. function mac_label_website_detail($param)
  2511. {
  2512. $where = [];
  2513. if($GLOBALS['config']['rewrite']['website_id']==1){
  2514. $where['website_en'] = ['eq',$param['id']];
  2515. }
  2516. else{
  2517. if($GLOBALS['config']['rewrite']['website_id']==2) {
  2518. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2519. }
  2520. $where['website_id'] = ['eq',$param['id']];
  2521. }
  2522. $where['website_status'] = ['eq',1];
  2523. $res = model('Website')->infoData($where,'*',1);
  2524. $GLOBALS['type_id'] = $res['info']['type_id'];
  2525. $GLOBALS['type_pid'] = $res['info']['type']['type_pid'];
  2526. return $res;
  2527. }
  2528. function mac_label_actor_detail($param)
  2529. {
  2530. $where = [];
  2531. if($GLOBALS['config']['rewrite']['actor_id']==1){
  2532. $where['actor_en'] = ['eq',$param['id']];
  2533. }
  2534. else{
  2535. if($GLOBALS['config']['rewrite']['actor_id']==2) {
  2536. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2537. }
  2538. $where['actor_id'] = ['eq',$param['id']];
  2539. }
  2540. $where['actor_status'] = ['eq',1];
  2541. $res = model('Actor')->infoData($where,'*',1);
  2542. $GLOBALS['type_id'] = $res['info']['type_id'];
  2543. $GLOBALS['type_pid'] = $res['info']['type']['type_pid'];
  2544. return $res;
  2545. }
  2546. function mac_label_role_detail($param)
  2547. {
  2548. $where = [];
  2549. if($GLOBALS['config']['rewrite']['role_id']==1){
  2550. $where['role_en'] = ['eq',$param['id']];
  2551. }
  2552. else{
  2553. if($GLOBALS['config']['rewrite']['role_id']==2) {
  2554. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2555. }
  2556. $where['role_id'] = ['eq',$param['id']];
  2557. }
  2558. $where['role_status'] = ['eq',1];
  2559. $res = model('Role')->infoData($where,'*',1);
  2560. // https://github.com/magicblack/maccms10/issues/960
  2561. $GLOBALS['type_id'] = isset($res['info']['data']['type_id']) ? $res['info']['data']['type_id'] : 0;
  2562. $GLOBALS['type_pid'] = isset($res['info']['data']['type_id_1']) ? $res['info']['data']['type_id_1'] : 0;
  2563. return $res;
  2564. }
  2565. function mac_label_topic_detail($param)
  2566. {
  2567. $where = [];
  2568. if($GLOBALS['config']['rewrite']['topic_id']==1){
  2569. $where['topic_en'] = ['eq',$param['id']];
  2570. }
  2571. else{
  2572. if($GLOBALS['config']['rewrite']['topic_id']==2) {
  2573. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2574. }
  2575. $where['topic_id'] = ['eq',$param['id']];
  2576. }
  2577. $where['topic_status'] = ['eq',1];
  2578. $res = model('Topic')->infoData($where,'*',1);
  2579. return $res;
  2580. }
  2581. function mac_label_art_detail($param)
  2582. {
  2583. $where = [];
  2584. if($GLOBALS['config']['rewrite']['art_id']==1){
  2585. $where['art_en'] = ['eq',$param['id']];
  2586. }
  2587. else{
  2588. if($GLOBALS['config']['rewrite']['art_id']==2) {
  2589. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2590. }
  2591. $where['art_id'] = ['eq',$param['id']];
  2592. }
  2593. $where['art_status'] = ['eq',1];
  2594. $res = model('Art')->infoData($where,'*',1);
  2595. if($res['code'] ==1){
  2596. if($param['page']>$res['info']['art_page_total']){ $param['page'] = $res['info']['art_page_total']; }
  2597. }
  2598. $GLOBALS['type_id'] = $res['info']['type_id'];
  2599. $GLOBALS['type_pid'] = $res['info']['type']['type_pid'];
  2600. return $res;
  2601. }
  2602. function mac_label_vod_detail($param)
  2603. {
  2604. $where = [];
  2605. if($GLOBALS['config']['rewrite']['vod_id']==1){
  2606. $where['vod_en'] = ['eq',$param['id']];
  2607. }
  2608. else{
  2609. if($GLOBALS['config']['rewrite']['vod_id']==2) {
  2610. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2611. }
  2612. $where['vod_id'] = ['eq',$param['id']];
  2613. }
  2614. $where['vod_status'] = ['eq',1];
  2615. $res = model('Vod')->infoData($where,'*',1);
  2616. $GLOBALS['type_id'] = $res['info']['type_id'];
  2617. $GLOBALS['type_pid'] = $res['info']['type']['type_pid'];
  2618. return $res;
  2619. }
  2620. function mac_label_vod_role($param)
  2621. {
  2622. $where = [];
  2623. $where['role_rid'] = $param['rid'];
  2624. $where['role_status'] = ['eq',1];
  2625. $order='role_sort desc,role_id desc';
  2626. $res = model('Role')->listData($where,$order,1,999,0,'*',0,0);
  2627. return $res;
  2628. }
  2629. function mac_label_type($param, $type_id_specified)
  2630. {
  2631. if ($type_id_specified > 0) {
  2632. $type_id = $type_id_specified;
  2633. } else {
  2634. if($GLOBALS['config']['rewrite']['type_id']==1){
  2635. }
  2636. else{
  2637. if($GLOBALS['config']['rewrite']['type_id']==2) {
  2638. $param['id'] = mac_alphaID($param['id'], true, $GLOBALS['config']['rewrite']['encode_len'],$GLOBALS['config']['rewrite']['encode_key'] );
  2639. }
  2640. }
  2641. $type_id = $param['id'];
  2642. }
  2643. $type_info = model('Type')->getCacheInfo($type_id);
  2644. $GLOBALS['type_id'] =$type_info['type_id'];
  2645. $GLOBALS['type_pid'] = $type_info['type_pid'];
  2646. $parent = model('Type')->getCacheInfo($type_info['type_pid']);
  2647. $type_info['parent'] = $parent;
  2648. return $type_info;
  2649. }
  2650. function mac_data_count($tid=0,$range='all',$flag='vod')
  2651. {
  2652. if(!in_array($flag,['vod','art','actor','role','topic','website'])) {
  2653. $flag='vod';
  2654. }
  2655. if(!in_array($range,['all','today','min'])){
  2656. $range='all';
  2657. }
  2658. $data = model('Extend')->dataCount();
  2659. $key = 'type_'.$range.'_'.$tid;
  2660. if($tid>0 && in_array($flag,['vod','art']) ){
  2661. }
  2662. else{
  2663. $key = $flag.'_'.$range;
  2664. }
  2665. return intval($data[$key]);
  2666. }
  2667. function mac_get_popedom_filter($group_type_list, $type_list = [])
  2668. {
  2669. if (empty($type_list)) {
  2670. $type_list = model('Type')->getCache('type_list');
  2671. }
  2672. $type_keys = array_keys($type_list);
  2673. $group_type_list = array_map('trim', explode(',', trim($group_type_list, ',')));
  2674. $group_keys = [];
  2675. foreach ($group_type_list as $group_type) {
  2676. $group_keys = array_merge($group_keys, explode(',', $group_type));
  2677. }
  2678. $group_keys = get_array_unique_id_list($group_keys);
  2679. $cha_keys = array_diff($type_keys, $group_keys);
  2680. return implode(',', $cha_keys);
  2681. }
  2682. function reset_html_filename($htmlfile)
  2683. {
  2684. $htmlpath = './';
  2685. if(substr($htmlfile,strlen($htmlfile)-1,1)=='/'){
  2686. $htmlfile .= 'index';
  2687. }
  2688. if(strpos($htmlfile,'.') ===false){
  2689. $htmlfile .= '.'. $GLOBALS['config']['path']['suffix'];
  2690. }
  2691. if(strpos($htmlfile,'?')!==false){
  2692. $htmlfile = substr($htmlfile,0,strpos($htmlfile,'?'));
  2693. }
  2694. $htmlfile = $htmlpath.$htmlfile;
  2695. $htmlfile = str_replace('//','/', $htmlfile);
  2696. if(MAC_PATH !='/'){
  2697. $htmlfile = str_replace('.'.MAC_PATH, './', $htmlfile);
  2698. }
  2699. $htmlfile = str_replace('//','/', $htmlfile);
  2700. return $htmlfile;
  2701. }
  2702. function mac_unicode_encode($str, $encoding = 'UTF-8', $prefix = '&#', $postfix = ';') {
  2703. $str = iconv($encoding, 'UCS-2', $str);
  2704. $arrstr = str_split($str, 2);
  2705. $unistr = '';
  2706. for($i = 0, $len = count($arrstr); $i < $len; $i++) {
  2707. $dec = hexdec(bin2hex($arrstr[$i]));
  2708. $unistr .= $prefix . $dec . $postfix;
  2709. }
  2710. return $unistr;
  2711. }
  2712. function mac_unicode_decode($unistr, $encoding = 'UTF-8', $prefix = '&#', $postfix = ';') {
  2713. $arruni = explode($prefix, $unistr);
  2714. $unistr = '';
  2715. for($i = 1, $len = count($arruni); $i < $len; $i++) {
  2716. if (strlen($postfix) > 0) {
  2717. $arruni[$i] = substr($arruni[$i], 0, strlen($arruni[$i]) - strlen($postfix));
  2718. }
  2719. $temp = intval($arruni[$i]);
  2720. $unistr .= ($temp < 256) ? chr(0) . chr($temp) : chr($temp / 256) . chr($temp % 256);
  2721. }
  2722. return iconv('UCS-2', $encoding, $unistr);
  2723. }
  2724. function mac_escape_param($param)
  2725. {
  2726. if(is_array($param)){
  2727. foreach($param as $k=>$v){
  2728. if(!is_numeric($v) && !empty($v)){
  2729. if($GLOBALS['config']['app']['wall_filter'] ==1){
  2730. $v = mac_unicode_encode($v);
  2731. }
  2732. elseif($GLOBALS['config']['app']['wall_filter'] ==2){
  2733. $v = '';
  2734. }
  2735. $param[$k] = $v;
  2736. }
  2737. }
  2738. }
  2739. else{
  2740. if(!is_numeric($param) && !empty($param)){
  2741. if($GLOBALS['config']['app']['wall_filter'] ==1){
  2742. $param = mac_unicode_encode($param);
  2743. }
  2744. elseif($GLOBALS['config']['app']['wall_filter'] ==2){
  2745. $param = '';
  2746. }
  2747. }
  2748. }
  2749. return $param;
  2750. }
  2751. function mac_search_len_check($param)
  2752. {
  2753. $psm = array('wd','tag','class','letter','name','state','level','area','lang','version','actor','director','starsign','blood');
  2754. foreach($psm as $v){
  2755. if(mb_strlen($param[$v]) > $GLOBALS['config']['app']['search_len']){
  2756. $param[$v] = mac_substring($param[$v],$GLOBALS['config']['app']['search_len']);
  2757. }
  2758. }
  2759. return $param;
  2760. }
  2761. function mac_no_cahche()
  2762. {
  2763. @header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  2764. @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
  2765. @header('Cache-Control: no-cache, must-revalidate');
  2766. @header('Pragma: no-cache');
  2767. }
  2768. function mac_filter_tags($rs)
  2769. {
  2770. $rex = array('{:','<script','<iframe','<frameset','<object','onerror');
  2771. if(is_array($rs)){
  2772. foreach($rs as $k2=>$v2){
  2773. if(!is_numeric($v2)){
  2774. $rs[$k2] = str_ireplace($rex,'*',$rs[$k2]);
  2775. }
  2776. }
  2777. }
  2778. else{
  2779. if(!is_numeric($rs)){
  2780. $rs = str_ireplace($rex,'*',$rs);
  2781. }
  2782. }
  2783. return $rs;
  2784. }
  2785. if (!function_exists('is_really_writable')) {
  2786. /**
  2787. * 判断文件或文件夹是否可写
  2788. * @param string $file 文件或目录
  2789. * @return bool
  2790. */
  2791. function is_really_writable($file)
  2792. {
  2793. if (DIRECTORY_SEPARATOR === '/') {
  2794. return is_writable($file);
  2795. }
  2796. if (is_dir($file)) {
  2797. $file = rtrim($file, '/') . '/' . md5(mt_rand());
  2798. if (($fp = @fopen($file, 'ab')) === false) {
  2799. return false;
  2800. }
  2801. fclose($fp);
  2802. @chmod($file, 0777);
  2803. @unlink($file);
  2804. return true;
  2805. } elseif (!is_file($file) or ($fp = @fopen($file, 'ab')) === false) {
  2806. return false;
  2807. }
  2808. fclose($fp);
  2809. return true;
  2810. }
  2811. }
  2812. if (!function_exists('rmdirs')) {
  2813. /**
  2814. * 删除文件夹
  2815. * @param string $dirname 目录
  2816. * @param bool $withself 是否删除自身
  2817. * @return boolean
  2818. */
  2819. function rmdirs($dirname, $withself = true)
  2820. {
  2821. if (!is_dir($dirname)) {
  2822. return false;
  2823. }
  2824. $files = new RecursiveIteratorIterator(
  2825. new RecursiveDirectoryIterator($dirname, RecursiveDirectoryIterator::SKIP_DOTS),
  2826. RecursiveIteratorIterator::CHILD_FIRST
  2827. );
  2828. foreach ($files as $fileinfo) {
  2829. $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
  2830. $todo($fileinfo->getRealPath());
  2831. }
  2832. if ($withself) {
  2833. @rmdir($dirname);
  2834. }
  2835. return true;
  2836. }
  2837. }
  2838. if (!function_exists('copydirs')) {
  2839. /**
  2840. * 复制文件夹
  2841. * @param string $source 源文件夹
  2842. * @param string $dest 目标文件夹
  2843. */
  2844. function copydirs($source, $dest)
  2845. {
  2846. if (!is_dir($dest)) {
  2847. mkdir($dest, 0755, true);
  2848. }
  2849. foreach (
  2850. $iterator = new RecursiveIteratorIterator(
  2851. new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
  2852. RecursiveIteratorIterator::SELF_FIRST
  2853. ) as $item
  2854. ) {
  2855. if ($item->isDir()) {
  2856. $sontDir = $dest . DS . $iterator->getSubPathName();
  2857. if (!is_dir($sontDir)) {
  2858. mkdir($sontDir, 0755, true);
  2859. }
  2860. } else {
  2861. copy($item, $dest . DS . $iterator->getSubPathName());
  2862. }
  2863. }
  2864. }
  2865. }