common.php 86 KB

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