common.php 90 KB

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