common.php 91 KB

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