common.php 93 KB

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