Collect.php 134 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. use think\Cache;
  5. use app\common\util\Pinyin;
  6. use think\Request;
  7. use app\common\validate\Vod as VodValidate;
  8. class Collect extends Base {
  9. // 设置数据表(不含前缀)
  10. protected $name = 'collect';
  11. // 定义时间戳字段名
  12. protected $createTime = '';
  13. protected $updateTime = '';
  14. // 自动完成
  15. protected $auto = [];
  16. protected $insert = [];
  17. protected $update = [];
  18. public function listData($where,$order,$page=1,$limit=20,$start=0)
  19. {
  20. $page = $page > 0 ? (int)$page : 1;
  21. $limit = $limit ? (int)$limit : 20;
  22. $start = $start ? (int)$start : 0;
  23. $total = $this->where($where)->count();
  24. $list = Db::name('Collect')->where($where)->order($order)->page($page)->limit($limit)->select();
  25. return ['code'=>1,'msg'=>lang('data_list'),'page'=>$page,'pagecount'=>ceil($total/$limit),'limit'=>$limit,'total'=>$total,'list'=>$list];
  26. }
  27. public function infoData($where,$field='*')
  28. {
  29. if(empty($where) || !is_array($where)){
  30. return ['code'=>1001,'msg'=>lang('param_err')];
  31. }
  32. $info = $this->field($field)->where($where)->find();
  33. if(empty($info)){
  34. return ['code'=>1002,'msg'=>lang('obtain_err')];
  35. }
  36. $info = $info->toArray();
  37. return ['code'=>1,'msg'=>lang('obtain_ok'),'info'=>$info];
  38. }
  39. public function saveData($data)
  40. {
  41. $validate = \think\Loader::validate('Collect');
  42. if(!empty($data['collect_id'])){
  43. if(!$validate->scene('edit')->check($data)){
  44. return ['code'=>1001,'msg'=>lang('param_err').':'.$validate->getError() ];
  45. }
  46. $where=[];
  47. $where['collect_id'] = ['eq',$data['collect_id']];
  48. $res = $this->where($where)->update($data);
  49. }
  50. else{
  51. if(!$validate->scene('edit')->check($data)){
  52. return ['code'=>1002,'msg'=>lang('param_err').':'.$validate->getError() ];
  53. }
  54. $res = $this->insert($data);
  55. }
  56. if(false === $res){
  57. return ['code'=>1003,'msg'=>''.$this->getError() ];
  58. }
  59. return ['code'=>1,'msg'=>lang('save_ok')];
  60. }
  61. public function delData($where)
  62. {
  63. $res = $this->where($where)->delete();
  64. if($res===false){
  65. return ['code'=>1001,'msg'=>lang('del_err').':'.$this->getError() ];
  66. }
  67. return ['code'=>1,'msg'=>lang('del_ok')];
  68. }
  69. public function check_flag($param)
  70. {
  71. if($param['cjflag'] != md5($param['cjurl'])){
  72. return ['code'=>9001, 'msg'=>lang('model/collect/flag_err')];
  73. }
  74. return ['code'=>1,'msg'=>'ok'];
  75. }
  76. public function vod($param)
  77. {
  78. if($param['type'] == '1'){
  79. return $this->vod_xml($param);
  80. }
  81. elseif($param['type'] == '2'){
  82. return $this->vod_json($param);
  83. }
  84. else{
  85. $data = $this->vod_json($param);
  86. if($data['code'] == 1){
  87. return $data;
  88. }
  89. else{
  90. return $this->vod_xml($param);
  91. }
  92. }
  93. }
  94. public function art($param)
  95. {
  96. return $this->art_json($param);
  97. }
  98. public function actor($param)
  99. {
  100. return $this->actor_json($param);
  101. }
  102. public function role($param)
  103. {
  104. return $this->role_json($param);
  105. }
  106. public function website($param)
  107. {
  108. return $this->website_json($param);
  109. }
  110. public function manga($param)
  111. {
  112. if($param['type'] == '1'){
  113. return $this->manga_xml($param);
  114. }
  115. elseif($param['type'] == '2'){
  116. return $this->manga_json($param);
  117. }
  118. else{
  119. $data = $this->manga_json($param);
  120. if($data['code'] == 1){
  121. return $data;
  122. }
  123. else{
  124. return $this->manga_xml($param);
  125. }
  126. }
  127. }
  128. public function vod_xml_replace($url)
  129. {
  130. $array_url = array();
  131. $arr_ji = explode('#',str_replace('||','//',$url));
  132. foreach($arr_ji as $key=>$value){
  133. $urlji = explode('$',$value);
  134. if( count($urlji) > 1 ){
  135. $array_url[$key] = $urlji[0].'$'.trim($urlji[1]);
  136. }else{
  137. $array_url[$key] = trim($urlji[0]);
  138. }
  139. }
  140. return implode('#',$array_url);
  141. }
  142. public function vod_xml($param,$html='')
  143. {
  144. $url_param = [];
  145. $url_param['ac'] = $param['ac'];
  146. $url_param['t'] = $param['t'];
  147. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  148. $url_param['h'] = $param['h'];
  149. $url_param['ids'] = $param['ids'];
  150. $url_param['wd'] = $param['wd'];
  151. if(empty($param['h']) && !empty($param['rday'])){
  152. $url_param['h'] = $param['rday'];
  153. }
  154. if($param['ac']!='list'){
  155. $url_param['ac'] = 'videolist';
  156. }
  157. $url = $param['cjurl'];
  158. if(strpos($url,'?')===false){
  159. $url .='?';
  160. }
  161. else{
  162. $url .='&';
  163. }
  164. $url .= http_build_query($url_param). base64_decode($param['param']);
  165. $result = $this->checkCjUrl($url);
  166. if ($result['code'] > 1) {
  167. return $result;
  168. }
  169. $html = mac_curl_get($url);
  170. if(empty($html)){
  171. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  172. }
  173. $html = mac_filter_tags($html);
  174. $xml = @simplexml_load_string($html);
  175. if(empty($xml)){
  176. $labelRule = '<pic>'."(.*?)".'</pic>';
  177. $labelRule = mac_buildregx($labelRule,"is");
  178. preg_match_all($labelRule,$html,$tmparr);
  179. $ec=false;
  180. foreach($tmparr[1] as $tt){
  181. if(strpos($tt,'[CDATA')===false){
  182. $ec=true;
  183. $ne = '<pic>'.'<![CDATA['.$tt .']]>'.'</pic>';
  184. $html = str_replace('<pic>'.$tt.'</pic>',$ne,$html);
  185. }
  186. }
  187. if($ec) {
  188. $xml = @simplexml_load_string($html);
  189. }
  190. if(empty($xml)) {
  191. return ['code' => 1002, 'msg'=>lang('model/collect/xml_err')];
  192. }
  193. }
  194. $array_page = [];
  195. $array_page['page'] = (string)$xml->list->attributes()->page;
  196. $array_page['pagecount'] = (string)$xml->list->attributes()->pagecount;
  197. $array_page['pagesize'] = (string)$xml->list->attributes()->pagesize;
  198. $array_page['recordcount'] = (string)$xml->list->attributes()->recordcount;
  199. $array_page['url'] = $url;
  200. $type_list = model('Type')->getCache('type_list');
  201. $bind_list = config('bind');
  202. $key = 0;
  203. $array_data = [];
  204. foreach($xml->list->video as $video){
  205. $bind_key = $param['cjflag'] .'_'.(string)$video->tid;
  206. if($bind_list[$bind_key] >0){
  207. $array_data[$key]['type_id'] = $bind_list[$bind_key];
  208. }
  209. else{
  210. $array_data[$key]['type_id'] = 0;
  211. }
  212. $array_data[$key]['vod_id'] = (string)$video->id;
  213. //$array_data[$key]['type_id'] = (string)$video->tid;
  214. $array_data[$key]['vod_name'] = (string)$video->name;
  215. $array_data[$key]['vod_sub'] = (string)$video->subname;
  216. $array_data[$key]['vod_remarks'] = (string)$video->note;
  217. $array_data[$key]['type_name'] = (string)$video->type;
  218. $array_data[$key]['vod_pic'] = (string)$video->pic;
  219. $array_data[$key]['vod_lang'] = (string)$video->lang;
  220. $array_data[$key]['vod_area'] = (string)$video->area;
  221. $array_data[$key]['vod_year'] = (string)$video->year;
  222. $array_data[$key]['vod_serial'] = (string)$video->state;
  223. $array_data[$key]['vod_actor'] = (string)$video->actor;
  224. $array_data[$key]['vod_director'] = (string)$video->director;
  225. $array_data[$key]['vod_content'] = (string)$video->des;
  226. $array_data[$key]['vod_status'] = 1;
  227. $array_data[$key]['vod_type'] = $array_data[$key]['list_name'];
  228. $array_data[$key]['vod_time'] = (string)$video->last;
  229. $array_data[$key]['vod_total'] = 0;
  230. $array_data[$key]['vod_isend'] = 1;
  231. if($array_data[$key]['vod_serial']){
  232. $array_data[$key]['vod_isend'] = 0;
  233. }
  234. //格式化地址与播放器
  235. $array_from = [];
  236. $array_url = [];
  237. $array_server=[];
  238. $array_note=[];
  239. //videolist|list播放列表不同
  240. if(isset($video->dl->dd) && $count=count($video->dl->dd)){
  241. for($i=0; $i<$count; $i++){
  242. $array_from[$i] = (string)$video->dl->dd[$i]['flag'];
  243. $urls = explode('#', $this->vod_xml_replace((string)$video->dl->dd[$i]));
  244. $sorted_urls = $this->sortPlayUrls($urls);
  245. $array_url[$i] = implode('#', $sorted_urls);
  246. $array_server[$i] = 'no';
  247. $array_note[$i] = '';
  248. }
  249. }else{
  250. $array_from[]=(string)$video->dt;
  251. $array_url[] ='';
  252. $array_server[]='';
  253. $array_note[]='';
  254. }
  255. if(strpos(base64_decode($param['param']),'ct=1')!==false){
  256. $array_data[$key]['vod_down_from'] = implode('$$$', $array_from);
  257. $array_data[$key]['vod_down_url'] = implode('$$$', $array_url);
  258. $array_data[$key]['vod_down_server'] = implode('$$$', $array_server);
  259. $array_data[$key]['vod_down_note'] = implode('$$$', $array_note);
  260. }
  261. else{
  262. $array_data[$key]['vod_play_from'] = implode('$$$', $array_from);
  263. $array_data[$key]['vod_play_url'] = implode('$$$', $array_url);
  264. $array_data[$key]['vod_play_server'] = implode('$$$', $array_server);
  265. $array_data[$key]['vod_play_note'] = implode('$$$', $array_note);
  266. }
  267. $key++;
  268. }
  269. $array_type = [];
  270. $key=0;
  271. //分类列表
  272. if($param['ac'] == 'list'){
  273. foreach($xml->class->ty as $ty){
  274. $array_type[$key]['type_id'] = (string)$ty->attributes()->id;
  275. $array_type[$key]['type_name'] = (string)$ty;
  276. $key++;
  277. }
  278. }
  279. $res = ['code'=>1, 'msg'=>'xml', 'page'=>$array_page, 'type'=>$array_type, 'data'=>$array_data ];
  280. return $res;
  281. }
  282. public function vod_json($param)
  283. {
  284. $url_param = [];
  285. $url_param['ac'] = $param['ac'];
  286. $url_param['t'] = $param['t'];
  287. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  288. $url_param['h'] = $param['h'];
  289. $url_param['ids'] = $param['ids'];
  290. $url_param['wd'] = $param['wd'];
  291. if($param['ac']!='list'){
  292. $url_param['ac'] = 'videolist';
  293. }
  294. $url = $param['cjurl'];
  295. if(strpos($url,'?')===false){
  296. $url .='?';
  297. }
  298. else{
  299. $url .='&';
  300. }
  301. $url .= http_build_query($url_param). base64_decode($param['param']);
  302. $result = $this->checkCjUrl($url);
  303. if ($result['code'] > 1) {
  304. return $result;
  305. }
  306. $html = mac_curl_get($url);
  307. if(empty($html)){
  308. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  309. }
  310. $html = mac_filter_tags($html);
  311. $json = json_decode($html,true);
  312. if(!$json){
  313. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ', url: ' . $url . ', response: ' . mb_substr($html, 0, 15)];
  314. }
  315. $array_page = [];
  316. $array_page['page'] = $json['page'];
  317. $array_page['pagecount'] = $json['pagecount'];
  318. $array_page['pagesize'] = $json['limit'];
  319. $array_page['recordcount'] = $json['total'];
  320. $array_page['url'] = $url;
  321. $type_list = model('Type')->getCache('type_list');
  322. $bind_list = config('bind');
  323. $key = 0;
  324. $array_data = [];
  325. foreach($json['list'] as $key=>$v){
  326. $array_data[$key] = $v;
  327. $bind_key = $param['cjflag'] .'_'.$v['type_id'];
  328. if($bind_list[$bind_key] >0){
  329. $array_data[$key]['type_id'] = $bind_list[$bind_key];
  330. }
  331. else{
  332. $array_data[$key]['type_id'] = 0;
  333. }
  334. if(!empty($v['dl'])) {
  335. //格式化地址与播放器
  336. $array_from = [];
  337. $array_url = [];
  338. $array_server = [];
  339. $array_note = [];
  340. //videolist|list播放列表不同
  341. foreach ($v['dl'] as $k2 => $v2) {
  342. $array_from[] = $k2;
  343. $urls = explode('#', $v2);
  344. $sorted_urls = $this->sortPlayUrls($urls);
  345. $array_url[] = implode('#', $sorted_urls);
  346. $array_server[] = 'no';
  347. $array_note[] = '';
  348. }
  349. $array_data[$key]['vod_play_from'] = implode('$$$', $array_from);
  350. $array_data[$key]['vod_play_url'] = implode('$$$', $array_url);
  351. $array_data[$key]['vod_play_server'] = implode('$$$', $array_server);
  352. $array_data[$key]['vod_play_note'] = implode('$$$', $array_note);
  353. }
  354. }
  355. $array_type = [];
  356. $key=0;
  357. //分类列表
  358. if($param['ac'] == 'list'){
  359. foreach($json['class'] as $k=>$v){
  360. $array_type[$key]['type_id'] = $v['type_id'];
  361. $array_type[$key]['type_name'] = $v['type_name'];
  362. $key++;
  363. }
  364. }
  365. $res = ['code'=>1, 'msg'=>'json', 'page'=>$array_page, 'type'=>$array_type, 'data'=>$array_data ];
  366. return $res;
  367. }
  368. private function sortPlayUrls($urls) {
  369. $sorted = [];
  370. $datePartMap = []; // 用于存储同一日期的上下期
  371. foreach ($urls as $url) {
  372. // 匹配纯数字集数:第1集、EP1、E1等
  373. if (preg_match('/(?:第|EP|E)?(\d+)(?:集|话|回)?/', $url, $matches)) {
  374. $episode = (int)$matches[1];
  375. $sorted[$episode] = $url;
  376. }
  377. // 匹配日期+上下期格式:20250120上、20250120下、20250120中
  378. elseif (preg_match('/(\d{8})([上中下])/', $url, $matches)) {
  379. $datePart = $matches[1]; // 20250120
  380. $part = $matches[2]; // 上/中/下
  381. // 优先级:下 > 中 > 上
  382. if (!isset($datePartMap[$datePart])) {
  383. $datePartMap[$datePart] = ['part' => $part, 'url' => $url];
  384. } else {
  385. $priority = ['上' => 1, '中' => 2, '下' => 3];
  386. if ($priority[$part] > $priority[$datePartMap[$datePart]['part']]) {
  387. $datePartMap[$datePart] = ['part' => $part, 'url' => $url];
  388. }
  389. }
  390. }
  391. else {
  392. $sorted[] = $url;
  393. }
  394. }
  395. // 将过滤后的日期上下期加入排序结果
  396. foreach ($datePartMap as $item) {
  397. $sorted[] = $item['url'];
  398. }
  399. ksort($sorted);
  400. return array_values($sorted);
  401. }
  402. /**
  403. * 统计播放组集数
  404. */
  405. private function getPlayGroupEpisodeCount($v, $play_group_episode_count = [])
  406. {
  407. // 如果播放地址更新没有统计集数,则在这里统计
  408. if (empty($play_group_episode_count) && !empty($v['vod_play_from'])) {
  409. $tmp_play_from_arr = explode('$$$', $v['vod_play_from']);
  410. $tmp_play_url_arr = explode('$$$', $v['vod_play_url']);
  411. foreach ($tmp_play_from_arr as $tmp_k => $tmp_play_from) {
  412. if (!empty($tmp_play_from) && isset($tmp_play_url_arr[$tmp_k])) {
  413. $tmp_episode_count = empty($tmp_play_url_arr[$tmp_k]) ? 0 : count(explode('#', $tmp_play_url_arr[$tmp_k]));
  414. $play_group_episode_count[$tmp_play_from] = $tmp_episode_count;
  415. }
  416. }
  417. }
  418. return $play_group_episode_count;
  419. }
  420. /**
  421. * 找出集数最多的播放组
  422. */
  423. private function findMaxEpisodePlayGroup($play_group_episode_count)
  424. {
  425. if (empty($play_group_episode_count)) {
  426. return '';
  427. }
  428. // 找出集数最多的播放组
  429. $max_episode_count = 0;
  430. $max_episode_play_from = '';
  431. foreach ($play_group_episode_count as $play_from => $episode_count) {
  432. if ($episode_count > $max_episode_count) {
  433. $max_episode_count = $episode_count;
  434. $max_episode_play_from = $play_from;
  435. }
  436. }
  437. return $max_episode_play_from;
  438. }
  439. /**
  440. * 根据播放组获取备注
  441. */
  442. private function getRemarksByPlayGroup($v, $update, $max_episode_play_from)
  443. {
  444. if (empty($max_episode_play_from)) {
  445. return null;
  446. }
  447. // 使用更新后的 vod_play_note,如果已经在前面更新过
  448. $current_play_note = isset($update['vod_play_note']) ? $update['vod_play_note'] : $v['vod_play_note'];
  449. $play_from_arr = explode('$$$', $v['vod_play_from']);
  450. $play_note_arr = explode('$$$', $current_play_note);
  451. $max_play_key = array_search($max_episode_play_from, $play_from_arr);
  452. if ($max_play_key !== false && isset($play_note_arr[$max_play_key]) && !empty($play_note_arr[$max_play_key])) {
  453. return $play_note_arr[$max_play_key];
  454. }
  455. // 如果找不到对应的备注,但有API传递的备注,则使用API备注
  456. if (!empty($v['vod_remarks'])) {
  457. return $v['vod_remarks'];
  458. }
  459. return null;
  460. }
  461. /**
  462. * 处理视频备注更新逻辑
  463. * 根据集数最多的播放组来更新备注
  464. */
  465. private function handleVodRemarksUpdate($v, $info, $update, $play_group_episode_count)
  466. {
  467. // 优先使用 API 明确传递的备注(如果不为空且与当前不同)
  468. $should_use_api_remarks = !empty($v['vod_remarks']) && $v['vod_remarks'] != $info['vod_remarks'];
  469. // 如果 API 明确传递了不同的备注,直接使用
  470. if ($should_use_api_remarks) {
  471. return $v['vod_remarks'];
  472. }
  473. // 根据播放组来更新备注
  474. $play_group_episode_count = $this->getPlayGroupEpisodeCount($v, $play_group_episode_count);
  475. if (!empty($play_group_episode_count)) {
  476. // 找出集数最多的播放组
  477. $max_episode_play_from = $this->findMaxEpisodePlayGroup($play_group_episode_count);
  478. // 获取对应播放组的备注
  479. $remarks = $this->getRemarksByPlayGroup($v, $update, $max_episode_play_from);
  480. if ($remarks !== null) {
  481. return $remarks;
  482. }
  483. }
  484. // 如果以上都没有找到合适的备注,但有API传递的备注且与当前不同,则使用API备注
  485. if (!empty($v['vod_remarks']) && $v['vod_remarks'] != $info['vod_remarks']) {
  486. return $v['vod_remarks'];
  487. }
  488. return null;
  489. }
  490. /**
  491. * 同步图片
  492. *
  493. * @param $pic_status int 是否同步。为1时,同步图片
  494. * @param $pic_url
  495. * @param string $flag
  496. * @return array
  497. */
  498. private function syncImages($pic_status, $pic_url, $flag = 'vod')
  499. {
  500. $img_url_downloaded = $pic_url;
  501. if ($pic_status == 1) {
  502. // 清理失败标记,获取真实URL
  503. $clean_url = str_replace('#err', '', $pic_url);
  504. $config = (array)config('maccms.upload');
  505. $img_url_downloaded = model('Image')->down_load($clean_url, $config, $flag);
  506. if ($img_url_downloaded == $clean_url || strpos($img_url_downloaded, '#err') !== false) {
  507. // 下载失败,显示老图信息
  508. $des = '<a href="' . $clean_url . '" target="_blank">' . $clean_url . '</a><font color=red>'.lang('download_err').'!</font>';
  509. } else {
  510. // 下载成功,显示新图信息
  511. if (str_starts_with($img_url_downloaded, 'upload/')) {
  512. $link = MAC_PATH . $img_url_downloaded;
  513. } else {
  514. $link = str_replace('mac:', $config['protocol'] . ':', $img_url_downloaded);
  515. }
  516. $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=green>'.lang('download_ok').'!</font>';
  517. }
  518. }
  519. return ['pic' => $img_url_downloaded, 'msg' => $des];
  520. }
  521. public function vod_data($param,$data,$show=1)
  522. {
  523. if($show==1) {
  524. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1', [$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  525. }
  526. $config = config('maccms.collect');
  527. $config = $config['vod'];
  528. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  529. $filter_year = !empty($param['filter_year']) ? $param['filter_year'] : '';
  530. $filter_year_list = $filter_year ? get_array_unique_id_list(explode(',', $filter_year)) : [];
  531. $players = config('vodplayer');
  532. $downers = config('voddowner');
  533. $vod_search = model('VodSearch');
  534. $vod_search_enabled = $vod_search->isCollectEnabled();
  535. $vs_max_id_count = $vod_search->maxIdCount;
  536. $type_list = model('Type')->getCache('type_list');
  537. $filter_arr = explode(',',$config['filter']);
  538. $filter_arr = array_filter($filter_arr);
  539. $pse_rnd = explode('#',$config['words']);
  540. $pse_rnd = array_filter($pse_rnd);
  541. $pse_name = mac_txt_explain($config['namewords'], true);
  542. $pse_syn = mac_txt_explain($config['thesaurus'], true);
  543. $pse_player = mac_txt_explain($config['playerwords'], true);
  544. $pse_area = mac_txt_explain($config['areawords'], true);
  545. $pse_lang = mac_txt_explain($config['langwords'], true);
  546. foreach($data['data'] as $k=>$v){
  547. $color='red';
  548. $des='';
  549. $msg='';
  550. $tmp='';
  551. if ($v['type_id'] ==0) {
  552. $des = lang('model/collect/type_err');
  553. } elseif (empty($v['vod_name'])) {
  554. $des = lang('model/collect/name_err');
  555. } elseif (mac_array_filter($filter_arr,$v['vod_name']) !==false) {
  556. $des = lang('model/collect/name_in_filter_err');
  557. } elseif ($filter_year_list && !in_array(intval($v['vod_year']), $filter_year_list)) {
  558. // 采集时,过滤年份
  559. // https://github.com/magicblack/maccms10/issues/1057
  560. $color = 'orange';
  561. $des = 'year [' . intval($v['vod_year']) . '] not in: ' . join(',', $filter_year_list);
  562. } else {
  563. unset($v['vod_id']);
  564. foreach($v as $k2=>$v2){
  565. if(strpos($k2,'_content')===false && $k2!=='vod_plot_detail') {
  566. $v[$k2] = mac_strip_tags($v2);
  567. }
  568. }
  569. $v['type_id_1'] = intval($type_list[$v['type_id']]['type_pid']);
  570. if(empty($v['vod_en'])){
  571. $v['vod_en'] = Pinyin::get($v['vod_name']);
  572. }
  573. if(empty($v['vod_letter'])){
  574. $v['vod_letter'] = strtoupper(substr($v['vod_en'],0,1));
  575. }
  576. // 使用资源站的添加时间,更新时间保持当前
  577. // https://github.com/magicblack/maccms10/issues/780
  578. if (empty($v['vod_time_add']) || strlen($v['vod_time_add']) != 10) {
  579. $v['vod_time_add'] = time();
  580. }
  581. // 支持外部自定义修改时间
  582. // https://github.com/magicblack/maccms10/issues/862
  583. $v['vod_time'] = time();
  584. if (!empty($v['vod_time_update']) && strlen($v['vod_time_update']) == 10) {
  585. $v['vod_time'] = (int)$v['vod_time_update'];
  586. }
  587. $v['vod_status'] = intval($config['status']);
  588. $v['vod_lock'] = intval($v['vod_lock']);
  589. if(!empty($v['vod_status'])) {
  590. $v['vod_status'] = intval($v['vod_status']);
  591. }
  592. $v['vod_year'] = intval($v['vod_year']);
  593. $v['vod_level'] = intval($v['vod_level']);
  594. $v['vod_hits'] = intval($v['vod_hits']);
  595. $v['vod_hits_day'] = intval($v['vod_hits_day']);
  596. $v['vod_hits_week'] = intval($v['vod_hits_week']);
  597. $v['vod_hits_month'] = intval($v['vod_hits_month']);
  598. $v['vod_stint_play'] = intval($v['vod_stint_play']);
  599. $v['vod_stint_down'] = intval($v['vod_stint_down']);
  600. $v['vod_total'] = intval($v['vod_total']);
  601. $v['vod_serial'] = intval($v['vod_serial']);
  602. $v['vod_isend'] = intval($v['vod_isend']);
  603. $v['vod_up'] = intval($v['vod_up']);
  604. $v['vod_down'] = intval($v['vod_down']);
  605. $v['vod_score'] = floatval($v['vod_score']);
  606. $v['vod_score_all'] = intval($v['vod_score_all']);
  607. $v['vod_score_num'] = intval($v['vod_score_num']);
  608. $v['vod_class'] = mac_txt_merge($v['vod_class'],$v['type_name']);
  609. $v['vod_actor'] = mac_format_text($v['vod_actor'], true);
  610. $v['vod_director'] = mac_format_text($v['vod_director'], true);
  611. $v['vod_class'] = mac_format_text($v['vod_class'], true);
  612. $v['vod_tag'] = mac_format_text($v['vod_tag'], true);
  613. $v['vod_plot_name'] = (string)$v['vod_plot_name'];
  614. $v['vod_plot_detail'] = (string)$v['vod_plot_detail'];
  615. if(!empty($v['vod_plot_name'])){
  616. $v['vod_plot'] = 1;
  617. $v['vod_plot_name'] = trim($v['vod_plot_name'],'$$$');
  618. }
  619. if(!empty($v['vod_plot_detail'])){
  620. $v['vod_plot_detail'] = trim($v['vod_plot_detail'],'$$$');
  621. }
  622. if(empty($v['vod_isend']) && !empty($v['vod_serial'])){
  623. $v['vod_isend'] = 0;
  624. }
  625. if($config['hits_start']>0 && $config['hits_end']>0) {
  626. $v['vod_hits'] = rand($config['hits_start'], $config['hits_end']);
  627. $v['vod_hits_day'] = rand($config['hits_start'], $config['hits_end']);
  628. $v['vod_hits_week'] = rand($config['hits_start'], $config['hits_end']);
  629. $v['vod_hits_month'] = rand($config['hits_start'], $config['hits_end']);
  630. }
  631. if($config['updown_start']>0 && $config['updown_end']){
  632. $v['vod_up'] = rand($config['updown_start'], $config['updown_end']);
  633. $v['vod_down'] = rand($config['updown_start'], $config['updown_end']);
  634. }
  635. if($config['score']==1) {
  636. $v['vod_score_num'] = rand(1, 1000);
  637. $v['vod_score_all'] = $v['vod_score_num'] * rand(1, 10);
  638. $v['vod_score'] = round($v['vod_score_all'] / $v['vod_score_num'], 1);
  639. }
  640. if ($config['psename'] == 1) {
  641. $v['vod_name'] = mac_rep_pse_syn($pse_name, $v['vod_name']);
  642. }
  643. if ($config['psernd'] == 1) {
  644. $v['vod_content'] = mac_rep_pse_rnd($pse_rnd, $v['vod_content']);
  645. }
  646. if ($config['psesyn'] == 1) {
  647. $v['vod_content'] = mac_rep_pse_syn($pse_syn, $v['vod_content']);
  648. }
  649. if ($config['pseplayer'] == 1) {
  650. $v['vod_play_from'] = mac_rep_pse_syn($pse_player, $v['vod_play_from']);
  651. }
  652. if ($config['psearea'] == 1) {
  653. $v['vod_area'] = mac_rep_pse_syn($pse_area, $v['vod_area']);
  654. }
  655. if ($config['pselang'] == 1) {
  656. $v['vod_lang'] = mac_rep_pse_syn($pse_lang, $v['vod_lang']);
  657. }
  658. if(empty($v['vod_blurb'])){
  659. $v['vod_blurb'] = mac_substring( strip_tags($v['vod_content']) ,100);
  660. }
  661. $where = [];
  662. if (strpos($config['inrule'], 'a')!==false) {
  663. $where['vod_name'] = mac_filter_xss($v['vod_name']);
  664. }
  665. $blend=false;
  666. if (strpos($config['inrule'], 'b')!==false) {
  667. $where['type_id'] = $v['type_id'];
  668. }
  669. if (strpos($config['inrule'], 'c')!==false) {
  670. $where['vod_year'] = $v['vod_year'];
  671. }
  672. if (strpos($config['inrule'], 'd')!==false) {
  673. $where['vod_area'] = $v['vod_area'];
  674. }
  675. if (strpos($config['inrule'], 'e')!==false) {
  676. $where['vod_lang'] = $v['vod_lang'];
  677. }
  678. $search_actor_id_list = [];
  679. if (strpos($config['inrule'], 'f')!==false) {
  680. $where['vod_actor'] = ['like', mac_like_arr(mac_filter_xss($v['vod_actor'])), 'OR'];
  681. if ($vod_search_enabled) {
  682. $search_actor_id_list = $vod_search->getResultIdList(mac_filter_xss($v['vod_actor']), 'vod_actor', true);
  683. $search_actor_id_list = empty($search_actor_id_list) ? [0] : $search_actor_id_list;
  684. }
  685. }
  686. if (strpos($config['inrule'], 'g')!==false) {
  687. $where['vod_director'] = mac_filter_xss($v['vod_director']);
  688. }
  689. if (strpos($config['inrule'], 'h')!==false) {
  690. $where['vod_douban_id'] = intval($v['vod_douban_id']);
  691. }
  692. if(!empty($where['vod_actor']) && !empty($where['vod_director'])){
  693. $blend = true;
  694. $GLOBALS['blend'] = [
  695. 'vod_actor' => $where['vod_actor'],
  696. 'vod_director' => $where['vod_director'],
  697. ];
  698. // 结果太大时,筛选更耗时。仅在结果数量较小时,才加入
  699. $GLOBALS['blend']['vod_id'] = null;
  700. if ($vod_search_enabled && count($search_actor_id_list) <= $vs_max_id_count) {
  701. $GLOBALS['blend']['vod_id'] = ['IN', $search_actor_id_list];
  702. }
  703. unset($where['vod_actor'],$where['vod_director']);
  704. }
  705. if(empty($v['vod_play_url'])){
  706. $v['vod_play_url'] = '';
  707. }
  708. if(empty($v['vod_down_url'])){
  709. $v['vod_down_url'] = '';
  710. }
  711. //验证地址
  712. $cj_play_from_arr = explode('$$$',$v['vod_play_from'] );
  713. $cj_play_url_arr = explode('$$$',$v['vod_play_url']);
  714. $cj_play_server_arr = explode('$$$',$v['vod_play_server']);
  715. $cj_play_note_arr = explode('$$$',$v['vod_play_note']);
  716. $cj_down_from_arr = explode('$$$',$v['vod_down_from'] );
  717. $cj_down_url_arr = explode('$$$',$v['vod_down_url']);
  718. $cj_down_server_arr = explode('$$$',$v['vod_down_server']);
  719. $cj_down_note_arr = explode('$$$',$v['vod_down_note']);
  720. $collect_filter=[];
  721. foreach($cj_play_from_arr as $kk=>$vv){
  722. if(empty($vv)){
  723. unset($cj_play_from_arr[$kk]);
  724. unset($cj_play_url_arr[$kk]);
  725. unset($cj_play_server_arr[$kk]);
  726. unset($cj_play_note_arr[$kk]);
  727. continue;
  728. }
  729. if(empty($players[$vv])){
  730. unset($cj_play_from_arr[$kk]);
  731. unset($cj_play_url_arr[$kk]);
  732. unset($cj_play_server_arr[$kk]);
  733. unset($cj_play_note_arr[$kk]);
  734. continue;
  735. }
  736. $cj_play_url_arr[$kk] = rtrim($cj_play_url_arr[$kk],'#');
  737. $cj_play_server_arr[$kk] = $cj_play_server_arr[$kk];
  738. $cj_play_note_arr[$kk] = $cj_play_note_arr[$kk];
  739. if($param['filter'] > 0){
  740. if(strpos(','.$param['filter_from'].',',$vv)!==false) {
  741. $collect_filter['play'][$param['filter']]['cj_play_from_arr'][$kk] = $vv;
  742. $collect_filter['play'][$param['filter']]['cj_play_url_arr'][$kk] = $cj_play_url_arr[$kk];
  743. $collect_filter['play'][$param['filter']]['cj_play_server_arr'][$kk] = $cj_play_server_arr[$kk];
  744. $collect_filter['play'][$param['filter']]['cj_play_note_arr'][$kk] = $cj_play_note_arr[$kk];
  745. }
  746. }
  747. }
  748. foreach($cj_down_from_arr as $kk=>$vv){
  749. if(empty($vv)){
  750. unset($cj_down_from_arr[$kk]);
  751. unset($cj_down_url_arr[$kk]);
  752. unset($cj_down_server_arr[$kk]);
  753. unset($cj_down_note_arr[$kk]);
  754. continue;
  755. }
  756. if(empty($downers[$vv])){
  757. unset($cj_down_from_arr[$kk]);
  758. unset($cj_down_url_arr[$kk]);
  759. unset($cj_down_server_arr[$kk]);
  760. unset($cj_down_note_arr[$kk]);
  761. continue;
  762. }
  763. $cj_down_url_arr[$kk] = rtrim($cj_down_url_arr[$kk]);
  764. $cj_down_server_arr[$kk] = $cj_down_server_arr[$kk];
  765. $cj_down_note_arr[$kk] = $cj_down_note_arr[$kk];
  766. if($param['filter'] > 0){
  767. if(strpos(','.$param['filter_from'].',',$vv)!==false) {
  768. $collect_filter['down'][$param['filter']]['cj_down_from_arr'][$kk] = $vv;
  769. $collect_filter['down'][$param['filter']]['cj_down_url_arr'][$kk] = $cj_down_url_arr[$kk];
  770. $collect_filter['down'][$param['filter']]['cj_down_server_arr'][$kk] = $cj_down_server_arr[$kk];
  771. $collect_filter['down'][$param['filter']]['cj_down_note_arr'][$kk] = $cj_down_note_arr[$kk];
  772. }
  773. }
  774. }
  775. $v['vod_play_from'] = (string)join('$$$', (array)$cj_play_from_arr);
  776. $v['vod_play_url'] = (string)join('$$$', (array)$cj_play_url_arr);
  777. $v['vod_play_server'] = (string)join('$$$', (array)$cj_play_server_arr);
  778. $v['vod_play_note'] = (string)join('$$$', (array)$cj_play_note_arr);
  779. $v['vod_down_from'] = (string)join('$$$', (array)$cj_down_from_arr);
  780. $v['vod_down_url'] = (string)join('$$$', (array)$cj_down_url_arr);
  781. $v['vod_down_server'] = (string)join('$$$', (array)$cj_down_server_arr);
  782. $v['vod_down_note'] = (string)join('$$$', (array)$cj_down_note_arr);
  783. if($blend===false){
  784. $info = model('Vod')->where($where)->find();
  785. }
  786. else{
  787. $info = model('Vod')->where($where)
  788. ->where(function($query) {
  789. $query->where('vod_director',$GLOBALS['blend']['vod_director']);
  790. if (!empty($GLOBALS['blend']['vod_id'])) {
  791. $query->whereOr('vod_id', $GLOBALS['blend']['vod_id']);
  792. } else {
  793. $query->whereOr('vod_actor', $GLOBALS['blend']['vod_actor']);
  794. }
  795. })
  796. ->find();
  797. }
  798. // 优化自动生成TAG https://github.com/magicblack/maccms10/issues/1178
  799. if ($config['tag'] == 1 && empty($v['vod_tag']) && empty($info['vod_tag'])) {
  800. $v['vod_tag'] = mac_filter_xss(mac_get_tag($v['vod_name'], $v['vod_content']));
  801. }
  802. if (!$info) {
  803. // 新增
  804. if ($param['opt'] == 2) {
  805. $des= lang('model/collect/not_check_add');
  806. } else {
  807. if ($param['filter'] == 1 || $param['filter'] == 2) {
  808. $v['vod_play_from'] = (string)join('$$$', (array)$collect_filter['play'][$param['filter']]['cj_play_from_arr']);
  809. $v['vod_play_url'] = (string)join('$$$', (array)$collect_filter['play'][$param['filter']]['cj_play_url_arr']);
  810. $v['vod_play_server'] = (string)join('$$$', (array)$collect_filter['play'][$param['filter']]['cj_play_server_arr']);
  811. $v['vod_play_note'] = (string)join('$$$', (array)$collect_filter['play'][$param['filter']]['cj_play_note_arr']);
  812. $v['vod_down_from'] = (string)join('$$$', (array)$collect_filter['down'][$param['filter']]['cj_down_from_arr']);
  813. $v['vod_down_url'] = (string)join('$$$', (array)$collect_filter['down'][$param['filter']]['cj_down_url_arr']);
  814. $v['vod_down_server'] = (string)join('$$$', (array)$collect_filter['down'][$param['filter']]['cj_down_server_arr']);
  815. $v['vod_down_note'] = (string)join('$$$', (array)$collect_filter['down'][$param['filter']]['cj_down_note_arr']);
  816. }
  817. $tmp = $this->syncImages($config_sync_pic, $v['vod_pic'], 'vod');
  818. $v['vod_pic'] = (string)$tmp['pic'];
  819. $msg = $tmp['msg'];
  820. $v = VodValidate::formatDataBeforeDb($v);
  821. $vod_id = model('Vod')->insert($v, false, true);
  822. if ($vod_id > 0) {
  823. $vod_search_enabled && $vod_search->checkAndUpdateTopResults(['vod_id' => $vod_id] + $v, true);
  824. $color = 'green';
  825. $des = lang('model/collect/add_ok');
  826. } else {
  827. $color = 'red';
  828. $des = 'vod insert failed';
  829. }
  830. }
  831. } else {
  832. // 更新
  833. if(empty($config['uprule'])){
  834. $des = lang('model/collect/uprule_empty');
  835. }
  836. elseif ($info['vod_lock'] == 1) {
  837. $des = lang('model/collect/data_lock');
  838. }
  839. elseif($param['opt'] == 1){
  840. $des = lang('model/collect/not_check_update');
  841. }
  842. else {
  843. unset($v['vod_time_add']);
  844. $update = [];
  845. $ec=false;
  846. // 记录每个播放组的集数,用于后续选择集数最多的播放组
  847. $play_group_episode_count = [];
  848. if($param['filter'] ==1 || $param['filter']==3){
  849. $cj_play_from_arr = $collect_filter['play'][$param['filter']]['cj_play_from_arr'];
  850. $cj_play_url_arr = $collect_filter['play'][$param['filter']]['cj_play_url_arr'];
  851. $cj_play_server_arr = $collect_filter['play'][$param['filter']]['cj_play_server_arr'];
  852. $cj_play_note_arr = $collect_filter['play'][$param['filter']]['cj_play_note_arr'];
  853. $cj_down_from_arr = $collect_filter['down'][$param['filter']]['cj_down_from_arr'];
  854. $cj_down_url_arr = $collect_filter['down'][$param['filter']]['cj_down_url_arr'];
  855. $cj_down_server_arr = $collect_filter['down'][$param['filter']]['cj_down_server_arr'];
  856. $cj_down_note_arr = $collect_filter['down'][$param['filter']]['cj_down_note_arr'];
  857. }
  858. if (strpos(',' . $config['uprule'], 'a')!==false && !empty($v['vod_play_from'])) {
  859. $old_play_from = $info['vod_play_from'];
  860. $old_play_url = $info['vod_play_url'];
  861. $old_play_server = $info['vod_play_server'];
  862. $old_play_note = $info['vod_play_note'];
  863. foreach ($cj_play_from_arr as $k2 => $v2) {
  864. $cj_play_from = $v2;
  865. $cj_play_url = $cj_play_url_arr[$k2];
  866. $cj_play_server = $cj_play_server_arr[$k2];
  867. $cj_play_note = $cj_play_note_arr[$k2];
  868. // 统计该播放组的集数
  869. $episode_count = empty($cj_play_url) ? 0 : count(explode('#', $cj_play_url));
  870. $play_group_episode_count[$cj_play_from] = $episode_count;
  871. if ($cj_play_url == $info['vod_play_url']) {
  872. $des .= lang('model/collect/playurl_same');
  873. } elseif (empty($cj_play_from)) {
  874. $des .= lang('model/collect/playfrom_empty');
  875. } elseif (strpos('$$$'.$info['vod_play_from'].'$$$', '$$$'.$cj_play_from.'$$$') === false) {
  876. // 新类型播放组,加入
  877. $color = 'green';
  878. $des .= lang('model/collect/playgroup_add_ok',[$cj_play_from]);
  879. if(!empty($old_play_from)){
  880. $old_play_url .="$$$";
  881. $old_play_from .= "$$$" ;
  882. $old_play_server .= "$$$" ;
  883. $old_play_note .= "$$$" ;
  884. }
  885. $old_play_url .= "" . $cj_play_url;
  886. $old_play_from .= "" . $cj_play_from;
  887. $old_play_server .= "" . $cj_play_server;
  888. $old_play_note .= "" . $cj_play_note;
  889. $ec=true;
  890. } elseif (!empty($cj_play_url)) {
  891. // 同类型播放组
  892. $arr1 = explode("$$$", $old_play_url);
  893. $arr2 = explode("$$$", $old_play_from);
  894. $arr_note = explode("$$$", $old_play_note);
  895. $play_key = array_search($cj_play_from, $arr2);
  896. if ($arr1[$play_key] == $cj_play_url) {
  897. $des .= lang('model/collect/playgroup_same',[$cj_play_from]);;
  898. } else {
  899. $color = 'green';
  900. $des .= lang('model/collect/playgroup_update_ok',[$cj_play_from]);
  901. // 根据「地址二更规则」配置,替换或合并
  902. if ($config['urlrole'] == 1) {
  903. $tmp1 = explode('#',$arr1[$play_key]);
  904. $tmp2 = explode('#',$cj_play_url);
  905. $tmp1 = array_merge($tmp1,$tmp2);
  906. $tmp1 = array_unique($tmp1);
  907. $cj_play_url = join('#', (array)$tmp1);
  908. unset($tmp1,$tmp2);
  909. }
  910. $arr1[$play_key] = $cj_play_url;
  911. $arr_note[$play_key] = $cj_play_note;
  912. $ec=true;
  913. }
  914. $old_play_url = join('$$$', (array)$arr1);
  915. $old_play_note = join('$$$', (array)$arr_note);
  916. }
  917. }
  918. if($ec) {
  919. $update['vod_play_from'] = $old_play_from;
  920. $update['vod_play_url'] = $old_play_url;
  921. $update['vod_play_server'] = $old_play_server;
  922. $update['vod_play_note'] = $old_play_note;
  923. }
  924. }
  925. $ec=false;
  926. if (strpos(',' . $config['uprule'], 'b')!==false && !empty($v['vod_down_from'])) {
  927. $old_down_from = $info['vod_down_from'];
  928. $old_down_url = $info['vod_down_url'];
  929. $old_down_server = $info['vod_down_server'];
  930. $old_down_note = $info['vod_down_note'];
  931. foreach ($cj_down_from_arr as $k2 => $v2) {
  932. $cj_down_from = $v2;
  933. $cj_down_url = $cj_down_url_arr[$k2];
  934. $cj_down_server = $cj_down_server_arr[$k2];
  935. $cj_down_note = $cj_down_note_arr[$k2];
  936. if ($cj_down_url == $info['vod_down_url']) {
  937. $des .= lang('model/collect/downurl_same');
  938. } elseif (empty($cj_down_from)) {
  939. $des .= lang('model/collect/downfrom_empty');
  940. } elseif (strpos('$$$'.$info['vod_down_from'].'$$$', '$$$'.$cj_down_from.'$$$')===false) {
  941. $color = 'green';
  942. $des .= lang('model/collect/downgroup_add_ok',[$cj_down_from]);
  943. if(!empty($old_down_from)){
  944. $old_down_url .="$$$";
  945. $old_down_from .= "$$$" ;
  946. $old_down_server .= "$$$" ;
  947. $old_down_note .= "$$$" ;
  948. }
  949. $old_down_url .= "" .$cj_down_url;
  950. $old_down_from .= "" .$cj_down_from;
  951. $old_down_server .= "" .$cj_down_server;
  952. $old_down_note .= "" .$cj_down_note;
  953. $ec=true;
  954. } elseif (!empty($cj_down_url)) {
  955. $arr1 = explode("$$$", $old_down_url);
  956. $arr2 = explode("$$$", $old_down_from);
  957. $down_key = array_search($cj_down_from, $arr2);
  958. if ($arr1[$down_key] == $cj_down_url) {
  959. $des .= lang('model/collect/downgroup_same',[$cj_down_from]);
  960. } else {
  961. $color = 'green';
  962. $des .= lang('model/collect/downgroup_update_ok',[$cj_down_from]);
  963. // 根据「地址二更规则」配置,替换或合并
  964. // “采集参数配置--地址二更规则”配置需要对下载地址生效
  965. // https://github.com/magicblack/maccms10/issues/893
  966. if ($config['urlrole'] == 1) {
  967. $tmp1 = explode('#',$arr1[$down_key]);
  968. $tmp2 = explode('#',$cj_down_url);
  969. $tmp1 = array_merge($tmp1,$tmp2);
  970. $tmp1 = array_unique($tmp1);
  971. $cj_down_url = join('#', (array)$tmp1);
  972. unset($tmp1,$tmp2);
  973. }
  974. $arr1[$down_key] = $cj_down_url;
  975. $ec=true;
  976. }
  977. $old_down_url = join('$$$', (array)$arr1);
  978. }
  979. }
  980. if($ec) {
  981. $update['vod_down_from'] = $old_down_from;
  982. $update['vod_down_url'] = $old_down_url;
  983. $update['vod_down_server'] = $old_down_server;
  984. $update['vod_down_note'] = $old_down_note;
  985. }
  986. }
  987. if (strpos(',' . $config['uprule'], 'c')!==false && !empty($v['vod_serial']) && $v['vod_serial']!=$info['vod_serial']) {
  988. $update['vod_serial'] = $v['vod_serial'];
  989. // 连载数如果均为整数,则取较大值
  990. // https://github.com/magicblack/maccms10/issues/878
  991. if (floor($v['vod_serial']) == $v['vod_serial'] && floor($info['vod_serial']) == $info['vod_serial']) {
  992. $update['vod_serial'] = max($v['vod_serial'], $info['vod_serial']);
  993. }
  994. }
  995. if (strpos(',' . $config['uprule'], 'd')!==false) {
  996. $new_remarks = $this->handleVodRemarksUpdate($v, $info, $update, $play_group_episode_count);
  997. if ($new_remarks !== null) {
  998. $update['vod_remarks'] = $new_remarks;
  999. }
  1000. }
  1001. if (strpos(',' . $config['uprule'], 'e')!==false && !empty($v['vod_director']) && $v['vod_director']!=$info['vod_director']) {
  1002. $update['vod_director'] = $v['vod_director'];
  1003. }
  1004. if (strpos(',' . $config['uprule'], 'f')!==false && !empty($v['vod_actor']) && $v['vod_actor']!=$info['vod_actor']) {
  1005. $update['vod_actor'] = $v['vod_actor'];
  1006. }
  1007. if (strpos(',' . $config['uprule'], 'g')!==false && !empty($v['vod_year']) && $v['vod_year']!=$info['vod_year']) {
  1008. $update['vod_year'] = $v['vod_year'];
  1009. }
  1010. if (strpos(',' . $config['uprule'], 'h')!==false && !empty($v['vod_area']) && $v['vod_area']!=$info['vod_area']) {
  1011. $update['vod_area'] = $v['vod_area'];
  1012. }
  1013. if (strpos(',' . $config['uprule'], 'i')!==false && !empty($v['vod_lang']) && $v['vod_lang']!=$info['vod_lang']) {
  1014. $update['vod_lang'] = $v['vod_lang'];
  1015. }
  1016. if (strpos(',' . $config['uprule'], 'j')!==false && (substr($info["vod_pic"], 0, 4) == "http" || empty($info['vod_pic']) ) && ($v['vod_pic']!=$info['vod_pic'] || strpos($info['vod_pic'], '#err') !== false) ) {
  1017. $tmp = $this->syncImages($config_sync_pic, $v['vod_pic'],'vod');
  1018. $update['vod_pic'] = (string)$tmp['pic'];
  1019. $msg =$tmp['msg'];
  1020. }
  1021. if (strpos(',' . $config['uprule'], 'k')!==false && !empty($v['vod_content']) && $v['vod_content']!=$info['vod_content']) {
  1022. $update['vod_content'] = $v['vod_content'];
  1023. }
  1024. if (strpos(',' . $config['uprule'], 'l')!==false && !empty($v['vod_tag']) && $v['vod_tag']!=$info['vod_tag']) {
  1025. $update['vod_tag'] = $v['vod_tag'];
  1026. }
  1027. if (strpos(',' . $config['uprule'], 'm')!==false && !empty($v['vod_sub']) && $v['vod_sub']!=$info['vod_sub']) {
  1028. $update['vod_sub'] = $v['vod_sub'];
  1029. }
  1030. if (strpos(',' . $config['uprule'], 'n')!==false && !empty($v['vod_class']) && $v['vod_class']!=$info['vod_class']) {
  1031. $update['vod_class'] = mac_txt_merge($info['vod_class'], $v['vod_class']);
  1032. }
  1033. if (strpos(',' . $config['uprule'], 'o')!==false && !empty($v['vod_writer']) && $v['vod_writer']!=$info['vod_writer']) {
  1034. $update['vod_writer'] = $v['vod_writer'];
  1035. }
  1036. if (strpos(',' . $config['uprule'], 'p')!==false && !empty($v['vod_version']) && $v['vod_version']!=$info['vod_version']) {
  1037. $update['vod_version'] = $v['vod_version'];
  1038. }
  1039. if (strpos(',' . $config['uprule'], 'q')!==false && !empty($v['vod_state']) && $v['vod_state']!=$info['vod_state']) {
  1040. $update['vod_state'] = $v['vod_state'];
  1041. }
  1042. if (strpos(',' . $config['uprule'], 'r')!==false && !empty($v['vod_blurb']) && $v['vod_blurb']!=$info['vod_blurb']) {
  1043. $update['vod_blurb'] = $v['vod_blurb'];
  1044. }
  1045. if (strpos(',' . $config['uprule'], 's')!==false && !empty($v['vod_tv']) && $v['vod_tv']!=$info['vod_tv']) {
  1046. $update['vod_tv'] = $v['vod_tv'];
  1047. }
  1048. if (strpos(',' . $config['uprule'], 't')!==false && !empty($v['vod_weekday']) && $v['vod_weekday']!=$info['vod_weekday']) {
  1049. $update['vod_weekday'] = $v['vod_weekday'];
  1050. }
  1051. if (strpos(',' . $config['uprule'], 'u')!==false && !empty($v['vod_total']) && $v['vod_total']!=$info['vod_total']) {
  1052. $update['vod_total'] = $v['vod_total'];
  1053. }
  1054. if (strpos(',' . $config['uprule'], 'v')!==false && (isset($v['vod_isend']) && $v['vod_isend'] !== '') && $v['vod_isend']!=$info['vod_isend']) {
  1055. $update['vod_isend'] = $v['vod_isend'];
  1056. }
  1057. if (strpos(',' . $config['uprule'], 'w')!==false && !empty($v['vod_plot_name']) && $v['vod_plot_name']!=$info['vod_plot_name']) {
  1058. $update['vod_plot'] = 1;
  1059. $update['vod_plot_name'] = $v['vod_plot_name'];
  1060. $update['vod_plot_detail'] = $v['vod_plot_detail'];
  1061. }
  1062. if(count($update)>0){
  1063. $update['vod_time'] = time();
  1064. $where = [];
  1065. $where['vod_id'] = $info['vod_id'];
  1066. $update = VodValidate::formatDataBeforeDb($update);
  1067. $res = model('Vod')->where($where)->update($update);
  1068. $color = 'green';
  1069. if ($res === false) {
  1070. }
  1071. }
  1072. else{
  1073. $des = lang('model/collect/not_need_update');
  1074. }
  1075. }
  1076. }
  1077. if(Cache::has('vod_repeat_table_created_time')){
  1078. Cache::rm('vod_repeat_table_created_time');
  1079. }
  1080. }
  1081. if($show==1) {
  1082. mac_echo( ($k + 1) .'、'. $v['vod_name'] . " <font color='{$color}'>" .$des .'</font>'. $msg.'' );
  1083. }
  1084. else{
  1085. return ['code'=>($color=='red' ? 1001 : 1),'msg'=>$des ];
  1086. }
  1087. }
  1088. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_vod';
  1089. if(ENTRANCE=='api'){
  1090. Cache::rm($key);
  1091. if ($data['page']['page'] < $data['page']['pagecount']) {
  1092. $param['page'] = intval($data['page']['page']) + 1;
  1093. $res = $this->vod($param);
  1094. if($res['code']>1){
  1095. return $this->error($res['msg']);
  1096. }
  1097. $this->vod_data($param,$res );
  1098. }
  1099. mac_echo(lang('model/collect/is_over'));
  1100. die;
  1101. }
  1102. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  1103. $GLOBALS['config']['app']['collect_timespan'] = 3;
  1104. }
  1105. if($show==1) {
  1106. if ($param['ac'] == 'cjsel') {
  1107. Cache::rm($key);
  1108. mac_echo(lang('model/collect/is_over'));
  1109. unset($param['ids']);
  1110. $param['ac'] = 'list';
  1111. $url = url('api') . '?' . http_build_query($param);
  1112. $ref = $_SERVER["HTTP_REFERER"];
  1113. if(!empty($ref)){
  1114. $url = $ref;
  1115. }
  1116. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1117. } else {
  1118. if ($data['page']['page'] >= $data['page']['pagecount']) {
  1119. Cache::rm($key);
  1120. mac_echo(lang('model/collect/is_over'));
  1121. unset($param['page'],$param['ids']);
  1122. $param['ac'] = 'list';
  1123. $url = url('api') . '?' . http_build_query($param);
  1124. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1125. } else {
  1126. $param['page'] = intval($data['page']['page']) + 1;
  1127. $url = url('api') . '?' . http_build_query($param);
  1128. mac_jump($url, $GLOBALS['config']['app']['collect_timespan'] );
  1129. }
  1130. }
  1131. }
  1132. }
  1133. public function art_json($param)
  1134. {
  1135. $url_param = [];
  1136. $url_param['ac'] = $param['ac'];
  1137. $url_param['t'] = $param['t'];
  1138. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  1139. $url_param['h'] = $param['h'];
  1140. $url_param['ids'] = $param['ids'];
  1141. $url_param['wd'] = $param['wd'];
  1142. if($param['ac']!='list'){
  1143. $url_param['ac'] = 'detail';
  1144. }
  1145. $url = $param['cjurl'];
  1146. if(strpos($url,'?')===false){
  1147. $url .='?';
  1148. }
  1149. else{
  1150. $url .='&';
  1151. }
  1152. $url .= http_build_query($url_param). base64_decode($param['param']);
  1153. $result = $this->checkCjUrl($url);
  1154. if ($result['code'] > 1) {
  1155. return $result;
  1156. }
  1157. $html = mac_curl_get($url);
  1158. if(empty($html)){
  1159. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  1160. }
  1161. $html = mac_filter_tags($html);
  1162. $json = json_decode($html,true);
  1163. if(!$json){
  1164. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ': ' . mb_substr($html, 0, 15)];
  1165. }
  1166. $array_page = [];
  1167. $array_page['page'] = $json['page'];
  1168. $array_page['pagecount'] = $json['pagecount'];
  1169. $array_page['pagesize'] = $json['limit'];
  1170. $array_page['recordcount'] = $json['total'];
  1171. $array_page['url'] = $url;
  1172. $type_list = model('Type')->getCache('type_list');
  1173. $bind_list = config('bind');
  1174. $key = 0;
  1175. $array_data = [];
  1176. foreach($json['list'] as $key=>$v){
  1177. $array_data[$key] = $v;
  1178. $bind_key = $param['cjflag'] .'_'.$v['type_id'];
  1179. if($bind_list[$bind_key] >0){
  1180. $array_data[$key]['type_id'] = $bind_list[$bind_key];
  1181. }
  1182. else{
  1183. $array_data[$key]['type_id'] = 0;
  1184. }
  1185. }
  1186. $array_type = [];
  1187. $key=0;
  1188. //分类列表
  1189. if($param['ac'] == 'list'){
  1190. foreach($json['class'] as $k=>$v){
  1191. $array_type[$key]['type_id'] = $v['type_id'];
  1192. $array_type[$key]['type_name'] = $v['type_name'];
  1193. $key++;
  1194. }
  1195. }
  1196. $res = ['code'=>1, 'msg'=>'ok', 'page'=>$array_page, 'type'=>$array_type, 'data'=>$array_data ];
  1197. return $res;
  1198. }
  1199. public function manga_json($param)
  1200. {
  1201. $url_param = [];
  1202. $url_param['ac'] = $param['ac'];
  1203. $url_param['t'] = $param['t'];
  1204. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  1205. $url_param['h'] = $param['h'];
  1206. $url_param['ids'] = $param['ids'];
  1207. $url_param['wd'] = $param['wd'];
  1208. if($param['ac']!='list'){
  1209. $url_param['ac'] = 'detail';
  1210. }
  1211. $url = $param['cjurl'];
  1212. if(strpos($url,'?')===false){
  1213. $url .='?';
  1214. }
  1215. else{
  1216. $url .='&';
  1217. }
  1218. $url .= http_build_query($url_param). base64_decode($param['param']);
  1219. $result = $this->checkCjUrl($url);
  1220. if ($result['code'] > 1) {
  1221. return $result;
  1222. }
  1223. $html = mac_curl_get($url);
  1224. if(empty($html)){
  1225. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  1226. }
  1227. $html = mac_filter_tags($html);
  1228. $json = json_decode($html,true);
  1229. if(!$json){
  1230. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ': ' . mb_substr($html, 0, 15)];
  1231. }
  1232. $array_page = [];
  1233. $array_page['page'] = $json['page'];
  1234. $array_page['pagecount'] = $json['pagecount'];
  1235. $array_page['pagesize'] = $json['limit'];
  1236. $array_page['recordcount'] = $json['total'];
  1237. $array_page['url'] = $url;
  1238. $type_list = model('Type')->getCache('type_list');
  1239. $bind_list = config('bind');
  1240. $key = 0;
  1241. $array_data = [];
  1242. foreach($json['list'] as $key=>$v){
  1243. $array_data[$key] = $v;
  1244. $bind_key = $param['cjflag'] .'_'.$v['type_id'];
  1245. if($bind_list[$bind_key] >0){
  1246. $array_data[$key]['type_id'] = $bind_list[$bind_key];
  1247. }
  1248. else{
  1249. $array_data[$key]['type_id'] = 0;
  1250. }
  1251. }
  1252. $array_type = [];
  1253. $key=0;
  1254. //分类列表
  1255. if($param['ac'] == 'list'){
  1256. foreach($json['class'] as $k=>$v){
  1257. $array_type[$key]['type_id'] = $v['type_id'];
  1258. $array_type[$key]['type_name'] = $v['type_name'];
  1259. $key++;
  1260. }
  1261. }
  1262. $res = ['code'=>1, 'msg'=>'ok', 'page'=>$array_page, 'type'=>$array_type, 'data'=>$array_data ];
  1263. return $res;
  1264. }
  1265. public function art_data($param,$data,$show=1)
  1266. {
  1267. if($show==1) {
  1268. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1',[$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  1269. }
  1270. $config = config('maccms.collect');
  1271. $config = $config['art'];
  1272. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  1273. $type_list = model('Type')->getCache('type_list');
  1274. $filter_arr = explode(',',$config['filter']); $filter_arr = array_filter($filter_arr);
  1275. $pse_rnd = explode('#',$config['words']); $pse_rnd = array_filter($pse_rnd);
  1276. $pse_syn = mac_txt_explain($config['thesaurus'], true);
  1277. foreach($data['data'] as $k=>$v){
  1278. $color='red';
  1279. $des='';
  1280. $msg='';
  1281. $tmp='';
  1282. if($v['type_id'] ==0){
  1283. $des = lang('model/collect/type_err');
  1284. }
  1285. elseif(empty($v['art_name'])) {
  1286. $des = lang('model/collect/name_err');
  1287. }
  1288. elseif( mac_array_filter($filter_arr,$v['art_name']) !==false) {
  1289. $des = lang('model/collect/name_in_filter_err');
  1290. }
  1291. else {
  1292. unset($v['art_id']);
  1293. foreach($v as $k2=>$v2){
  1294. if(strpos($k2,'_content')===false) {
  1295. $v[$k2] = mac_strip_tags($v2);
  1296. }
  1297. }
  1298. $v['art_name'] = trim($v['art_name']);
  1299. $v['type_id_1'] = intval($type_list[$v['type_id']]['type_pid']);
  1300. $v['art_en'] = Pinyin::get($v['art_name']);
  1301. $v['art_letter'] = strtoupper(substr($v['art_en'],0,1));
  1302. $v['art_time_add'] = time();
  1303. $v['art_time'] = time();
  1304. $v['art_status'] = intval($config['status']);
  1305. $v['art_lock'] = intval($v['art_lock']);
  1306. if(!empty($v['art_status'])) {
  1307. $v['art_status'] = intval($v['art_status']);
  1308. }
  1309. $v['art_level'] = intval($v['art_level']);
  1310. $v['art_hits'] = intval($v['art_hits']);
  1311. $v['art_hits_day'] = intval($v['art_hits_day']);
  1312. $v['art_hits_week'] = intval($v['art_hits_week']);
  1313. $v['art_hits_month'] = intval($v['art_hits_month']);
  1314. $v['art_stint'] = intval($v['art_stint']);
  1315. $v['art_up'] = intval($v['art_up']);
  1316. $v['art_down'] = intval($v['art_down']);
  1317. $v['art_score'] = floatval($v['art_score']);
  1318. $v['art_score_all'] = intval($v['art_score_all']);
  1319. $v['art_score_num'] = intval($v['art_score_num']);
  1320. if($config['hits_start']>0 && $config['hits_end']>0) {
  1321. $v['art_hits'] = rand($config['hits_start'], $config['hits_end']);
  1322. $v['art_hits_day'] = rand($config['hits_start'], $config['hits_end']);
  1323. $v['art_hits_week'] = rand($config['hits_start'], $config['hits_end']);
  1324. $v['art_hits_month'] = rand($config['hits_start'], $config['hits_end']);
  1325. }
  1326. if($config['updown_start']>0 && $config['updown_end']){
  1327. $v['art_up'] = rand($config['updown_start'], $config['updown_end']);
  1328. $v['art_down'] = rand($config['updown_start'], $config['updown_end']);
  1329. }
  1330. if($config['score']==1) {
  1331. $v['art_score_num'] = rand(1, 1000);
  1332. $v['art_score_all'] = $v['art_score_num'] * rand(1, 10);
  1333. $v['art_score'] = round($v['art_score_all'] / $v['art_score_num'], 1);
  1334. }
  1335. if ($config['psernd'] == 1) {
  1336. $v['art_content'] = mac_rep_pse_rnd($pse_rnd, $v['art_content']);
  1337. }
  1338. if ($config['psesyn'] == 1) {
  1339. $v['art_content'] = mac_rep_pse_syn($pse_syn, $v['art_content']);
  1340. }
  1341. if(empty($v['art_blurb'])){
  1342. $v['art_blurb'] = mac_substring( strip_tags( str_replace('$$$','',$v['art_content']) ) ,100);
  1343. }
  1344. if ($config['tag'] == 1) {
  1345. $v['art_tag'] = mac_filter_xss(mac_get_tag($v['art_name'], $v['art_content']));
  1346. }
  1347. $where = [];
  1348. $where['art_name'] = $v['art_name'];
  1349. if (strpos($config['inrule'], 'b')!==false) {
  1350. $where['type_id'] = $v['type_id'];
  1351. }
  1352. //验证地址
  1353. $cj_title_arr = explode('$$$',$v['art_title'] );
  1354. $cj_note_arr = explode('$$$',$v['art_note']);
  1355. $cj_content_arr = explode('$$$',$v['art_content']);
  1356. $tmp_title_arr=[];
  1357. $tmp_note_arr=[];
  1358. $tmp_content_arr=[];
  1359. foreach($cj_content_arr as $kk=>$vv){
  1360. $tmp_content_arr[] = $vv;
  1361. $tmp_title_arr[] = $cj_title_arr[$kk];
  1362. $tmp_note_arr[] = $cj_note_arr[$kk];
  1363. }
  1364. $v['art_title'] = join('$$$', (array)$tmp_title_arr);
  1365. $v['art_note'] = join('$$$', (array)$tmp_note_arr);
  1366. $v['art_content'] = join('$$$', (array)$tmp_content_arr);
  1367. $info = model('Art')->where($where)->find();
  1368. if (!$info) {
  1369. $tmp = $this->syncImages($config_sync_pic, $v['art_pic'],'art');
  1370. $v['art_pic'] = (string)$tmp['pic'];
  1371. $msg = $tmp['msg'];
  1372. $res = model('Art')->insert($v);
  1373. if($res===false){
  1374. }
  1375. $color ='green';
  1376. $des= lang('model/collect/add_ok');
  1377. }
  1378. else {
  1379. if(empty($config['uprule'])){
  1380. $des = lang('model/collect/uprule_empty');
  1381. }
  1382. elseif($info['art_lock'] == 1) {
  1383. $des = lang('model/collect/data_lock');
  1384. }
  1385. else {
  1386. unset($v['art_time_add']);
  1387. $old_art_title = $info['art_title'];
  1388. $old_art_note = $info['art_note'];
  1389. $old_art_content = $info['art_content'];
  1390. $cj_art_title = $v['art_title'];
  1391. $cj_art_note = $v['art_note'];
  1392. $cj_art_content = $v['art_content'];
  1393. $rc=true;
  1394. if($rc){
  1395. $update=[];
  1396. if(strpos(','.$config['uprule'],'a')!==false && !empty($v['art_content']) && $v['art_content']!=$info['art_content']){
  1397. $update['art_content'] = $v['art_content'];
  1398. }
  1399. if(strpos(','.$config['uprule'],'b')!==false && !empty($v['art_author']) && $v['art_author']!=$info['art_author']){
  1400. $update['art_author'] = $v['art_author'];
  1401. }
  1402. if(strpos(','.$config['uprule'],'c')!==false && !empty($v['art_from']) && $v['art_from']!=$info['art_from']){
  1403. $update['art_from'] = $v['art_from'];
  1404. }
  1405. if(strpos(','.$config['uprule'],'d')!==false && (substr($info["art_pic"], 0, 4) == "http" || empty($info['art_pic'])) && ($v['art_pic']!=$info['art_pic'] || strpos($info['art_pic'], '#err') !== false) ){
  1406. $tmp = $this->syncImages($config_sync_pic, $v['art_pic'],'art');
  1407. $update['art_pic'] = (string)$tmp['pic'];
  1408. $msg =$tmp['msg'];
  1409. }
  1410. if(strpos(','.$config['uprule'],'e')!==false && !empty($v['art_tag']) && $v['art_tag']!=$info['art_tag']){
  1411. $update['art_tag'] = $v['art_tag'];
  1412. }
  1413. if(strpos(','.$config['uprule'],'f')!==false && !empty($v['art_blurb']) && $v['art_blurb']!=$info['art_blurb']){
  1414. $update['art_blurb'] = $v['art_blurb'];
  1415. }
  1416. if(count($update)>0){
  1417. $update['art_time'] = time();
  1418. $where = [];
  1419. $where['art_id'] = $info['art_id'];
  1420. $res = model('Art')->where($where)->update($update);
  1421. $color = 'green';
  1422. if($res===false){
  1423. }
  1424. }
  1425. else{
  1426. $des = lang('model/collect/not_need_update');
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. if($show==1) {
  1433. mac_echo( ($k + 1) . $v['art_name'] . "<font color=$color>" .$des .'</font>'. $msg . '');
  1434. }
  1435. else{
  1436. return ['code'=>($color=='red' ? 1001 : 1),'msg'=> $v['art_name'] .' '.$des ];
  1437. }
  1438. }
  1439. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_art';
  1440. if(ENTRANCE=='api'){
  1441. Cache::rm($key);
  1442. if ($data['page']['page'] < $data['page']['pagecount']) {
  1443. $param['page'] = intval($data['page']['page']) + 1;
  1444. $res = $this->art($param);
  1445. if($res['code']>1){
  1446. return $this->error($res['msg']);
  1447. }
  1448. $this->art_data($param,$res );
  1449. }
  1450. mac_echo(lang('model/collect/is_over'));
  1451. die;
  1452. }
  1453. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  1454. $GLOBALS['config']['app']['collect_timespan'] = 3;
  1455. }
  1456. if($show==1) {
  1457. if ($param['ac'] == 'cjsel') {
  1458. Cache::rm($key);
  1459. mac_echo(lang('model/collect/is_over'));
  1460. unset($param['ids']);
  1461. $param['ac'] = 'list';
  1462. $url = url('api') . '?' . http_build_query($param);
  1463. $ref = $_SERVER["HTTP_REFERER"];
  1464. if(!empty($ref)){
  1465. $url = $ref;
  1466. }
  1467. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1468. } else {
  1469. if ($data['page']['page'] >= $data['page']['pagecount']) {
  1470. Cache::rm($key);
  1471. mac_echo(lang('model/collect/is_over'));
  1472. unset($param['page']);
  1473. $param['ac'] = 'list';
  1474. $url = url('api') . '?' . http_build_query($param);
  1475. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1476. } else {
  1477. $param['page'] = intval($data['page']['page']) + 1;
  1478. $url = url('api') . '?' . http_build_query($param);
  1479. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1480. }
  1481. }
  1482. }
  1483. }
  1484. public function actor_json($param)
  1485. {
  1486. $url_param = [];
  1487. $url_param['ac'] = $param['ac'];
  1488. $url_param['t'] = $param['t'];
  1489. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  1490. $url_param['h'] = $param['h'];
  1491. $url_param['ids'] = $param['ids'];
  1492. $url_param['wd'] = $param['wd'];
  1493. if($param['ac']!='list'){
  1494. $url_param['ac'] = 'detail';
  1495. }
  1496. $url = $param['cjurl'];
  1497. if(strpos($url,'?')===false){
  1498. $url .='?';
  1499. }
  1500. else{
  1501. $url .='&';
  1502. }
  1503. $url .= http_build_query($url_param).base64_decode($param['param']);
  1504. $result = $this->checkCjUrl($url);
  1505. if ($result['code'] > 1) {
  1506. return $result;
  1507. }
  1508. $html = mac_curl_get($url);
  1509. if(empty($html)){
  1510. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  1511. }
  1512. $html = mac_filter_tags($html);
  1513. $json = json_decode($html,true);
  1514. if(!$json){
  1515. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ': ' . mb_substr($html, 0, 15)];
  1516. }
  1517. $array_page = [];
  1518. $array_page['page'] = $json['page'];
  1519. $array_page['pagecount'] = $json['pagecount'];
  1520. $array_page['pagesize'] = $json['limit'];
  1521. $array_page['recordcount'] = $json['total'];
  1522. $array_page['url'] = $url;
  1523. $type_list = model('Type')->getCache('type_list');
  1524. $bind_list = config('bind');
  1525. $key = 0;
  1526. $array_data = [];
  1527. foreach($json['list'] as $key=>$v){
  1528. $array_data[$key] = $v;
  1529. $bind_key = $param['cjflag'] .'_'.$v['type_id'];
  1530. if($bind_list[$bind_key] >0){
  1531. $array_data[$key]['type_id'] = $bind_list[$bind_key];
  1532. }
  1533. else{
  1534. $array_data[$key]['type_id'] = 0;
  1535. }
  1536. }
  1537. $array_type = [];
  1538. $key=0;
  1539. //分类列表
  1540. if($param['ac'] == 'list'){
  1541. foreach($json['class'] as $k=>$v){
  1542. $array_type[$key]['type_id'] = $v['type_id'];
  1543. $array_type[$key]['type_name'] = $v['type_name'];
  1544. $key++;
  1545. }
  1546. }
  1547. $res = ['code'=>1, 'msg'=>'ok', 'page'=>$array_page, 'type'=>$array_type, 'data'=>$array_data ];
  1548. return $res;
  1549. }
  1550. public function actor_data($param,$data,$show=1)
  1551. {
  1552. if($show==1) {
  1553. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1',[$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  1554. }
  1555. $config = config('maccms.collect');
  1556. $config = $config['actor'];
  1557. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  1558. $type_list = model('Type')->getCache('type_list');
  1559. $filter_arr = explode(',',$config['filter']); $filter_arr = array_filter($filter_arr);
  1560. $pse_rnd = explode('#',$config['words']); $pse_rnd = array_filter($pse_rnd);
  1561. $pse_syn = mac_txt_explain($config['thesaurus'], true);
  1562. foreach($data['data'] as $k=>$v){
  1563. $color='red';
  1564. $des='';
  1565. $msg='';
  1566. $tmp='';
  1567. if($v['type_id'] ==0){
  1568. $des = lang('model/collect/type_err');
  1569. }
  1570. elseif(empty($v['actor_name']) || empty($v['actor_sex'])) {
  1571. $des = lang('odel/collect/actor_data_require');
  1572. }
  1573. elseif( mac_array_filter($filter_arr,$v['actor_name'])!==false) {
  1574. $des = lang('model/collect/name_in_filter_err');
  1575. }
  1576. else {
  1577. unset($v['actor_id']);
  1578. foreach($v as $k2=>$v2){
  1579. if(strpos($k2,'_content')===false) {
  1580. $v[$k2] = mac_strip_tags($v2);
  1581. }
  1582. }
  1583. $v['actor_name'] = trim($v['actor_name']);
  1584. $v['type_id_1'] = intval($type_list[$v['type_id']]['type_pid']);
  1585. $v['actor_en'] = Pinyin::get($v['actor_name']);
  1586. $v['actor_letter'] = strtoupper(substr($v['actor_en'],0,1));
  1587. $v['actor_time_add'] = time();
  1588. $v['actor_time'] = time();
  1589. $v['actor_status'] = intval($config['status']);
  1590. $v['actor_lock'] = intval($v['actor_lock']);
  1591. if(!empty($v['actor_status'])) {
  1592. $v['actor_status'] = intval($v['actor_status']);
  1593. }
  1594. $v['actor_level'] = intval($v['actor_level']);
  1595. $v['actor_hits'] = intval($v['actor_hits']);
  1596. $v['actor_hits_day'] = intval($v['actor_hits_day']);
  1597. $v['actor_hits_week'] = intval($v['actor_hits_week']);
  1598. $v['actor_hits_month'] = intval($v['actor_hits_month']);
  1599. $v['actor_up'] = intval($v['actor_up']);
  1600. $v['actor_down'] = intval($v['actor_down']);
  1601. $v['actor_score'] = floatval($v['actor_score']);
  1602. $v['actor_score_all'] = intval($v['actor_score_all']);
  1603. $v['actor_score_num'] = intval($v['actor_score_num']);
  1604. if($config['hits_start']>0 && $config['hits_end']>0) {
  1605. $v['actor_hits'] = rand($config['hits_start'], $config['hits_end']);
  1606. $v['actor_hits_day'] = rand($config['hits_start'], $config['hits_end']);
  1607. $v['actor_hits_week'] = rand($config['hits_start'], $config['hits_end']);
  1608. $v['actor_hits_month'] = rand($config['hits_start'], $config['hits_end']);
  1609. }
  1610. if($config['updown_start']>0 && $config['updown_end']){
  1611. $v['actor_up'] = rand($config['updown_start'], $config['updown_end']);
  1612. $v['actor_down'] = rand($config['updown_start'], $config['updown_end']);
  1613. }
  1614. if($config['score']==1) {
  1615. $v['actor_score_num'] = rand(1, 1000);
  1616. $v['actor_score_all'] = $v['actor_score_num'] * rand(1, 10);
  1617. $v['actor_score'] = round($v['actor_score_all'] / $v['actor_score_num'], 1);
  1618. }
  1619. if ($config['psernd'] == 1) {
  1620. $v['actor_content'] = mac_rep_pse_rnd($pse_rnd, $v['actor_content']);
  1621. }
  1622. if ($config['psesyn'] == 1) {
  1623. $v['actor_content'] = mac_rep_pse_syn($pse_syn, $v['actor_content']);
  1624. }
  1625. if(empty($v['actor_blurb'])){
  1626. $v['actor_blurb'] = mac_substring( strip_tags($v['actor_content']) ,100);
  1627. }
  1628. $where = [];
  1629. $where['actor_name'] = $v['actor_name'];
  1630. if (strpos($config['inrule'], 'b')!==false) {
  1631. $where['actor_sex'] = $v['actor_sex'];
  1632. }
  1633. if (strpos($config['inrule'], 'c')!==false) {
  1634. $where['type_id'] = $v['type_id'];
  1635. }
  1636. $info = model('Actor')->where($where)->find();
  1637. if (!$info) {
  1638. $tmp = $this->syncImages($config_sync_pic, $v['actor_pic'],'actor');
  1639. $v['actor_pic'] = $tmp['pic'];
  1640. $msg = $tmp['msg'];
  1641. $res = model('Actor')->insert($v);
  1642. if($res===false){
  1643. }
  1644. $color ='green';
  1645. $des= lang('model/collect/add_ok');
  1646. } else {
  1647. if(empty($config['uprule'])){
  1648. $des = lang('model/collect/uprule_empty');
  1649. }
  1650. elseif ($info['actor_lock'] == 1) {
  1651. $des = lang('model/collect/data_lock');
  1652. }
  1653. else {
  1654. unset($v['actor_time_add']);
  1655. $rc=true;
  1656. if($rc){
  1657. $update=[];
  1658. if(strpos(','.$config['uprule'],'a')!==false && !empty($v['actor_content']) && $v['actor_content']!=$info['actor_content']){
  1659. $update['actor_content'] = $v['actor_content'];
  1660. }
  1661. if(strpos(','.$config['uprule'],'b')!==false && !empty($v['actor_blurb']) && $v['actor_blurb']!=$info['actor_blurb']){
  1662. $update['actor_blurb'] = $v['actor_blurb'];
  1663. }
  1664. if(strpos(','.$config['uprule'],'c')!==false && !empty($v['actor_remarks']) && $v['actor_remarks']!=$info['actor_remarks']){
  1665. $update['actor_remarks'] = $v['actor_remarks'];
  1666. }
  1667. if(strpos(','.$config['uprule'],'d')!==false && !empty($v['actor_works']) && $v['actor_works']!=$info['actor_works']){
  1668. $update['actor_works'] = $v['actor_works'];
  1669. }
  1670. if(strpos(','.$config['uprule'],'e')!==false && (substr($info["actor_pic"], 0, 4) == "http" ||empty($info['actor_pic']) ) && ($v['actor_pic']!=$info['actor_pic'] || strpos($info['actor_pic'], '#err') !== false) ){
  1671. $tmp = $this->syncImages($config_sync_pic, $v['actor_pic'],'actor');
  1672. $update['actor_pic'] =$tmp['pic'];
  1673. $msg =$tmp['msg'];
  1674. }
  1675. if(count($update)>0){
  1676. $update['actor_time'] = time();
  1677. $where = [];
  1678. $where['actor_id'] = $info['actor_id'];
  1679. $res = model('Actor')->where($where)->update($update);
  1680. $color = 'green';
  1681. if($res===false){
  1682. }
  1683. }
  1684. else{
  1685. $des = lang('model/collect/not_need_update');
  1686. }
  1687. }
  1688. }
  1689. }
  1690. }
  1691. if($show==1) {
  1692. mac_echo( ($k + 1) . $v['actor_name'] . "<font color=$color>" .$des .'</font>'. $msg . '');
  1693. }
  1694. else{
  1695. return ['code'=>($color=='red' ? 1001 : 1),'msg'=> $v['actor_name'] .' '.$des ];
  1696. }
  1697. }
  1698. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_actor';
  1699. if(ENTRANCE=='api'){
  1700. Cache::rm($key);
  1701. if ($data['page']['page'] < $data['page']['pagecount']) {
  1702. $param['page'] = intval($data['page']['page']) + 1;
  1703. $res = $this->actor($param);
  1704. if($res['code']>1){
  1705. return $this->error($res['msg']);
  1706. }
  1707. $this->actor_data($param,$res );
  1708. }
  1709. mac_echo(lang('model/collect/is_over'));
  1710. die;
  1711. }
  1712. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  1713. $GLOBALS['config']['app']['collect_timespan'] = 3;
  1714. }
  1715. if($show==1) {
  1716. if ($param['ac'] == 'cjsel') {
  1717. Cache::rm($key);
  1718. mac_echo(lang('model/collect/is_over'));
  1719. unset($param['ids']);
  1720. $param['ac'] = 'list';
  1721. $url = url('api') . '?' . http_build_query($param);
  1722. $ref = $_SERVER["HTTP_REFERER"];
  1723. if(!empty($ref)){
  1724. $url = $ref;
  1725. }
  1726. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1727. } else {
  1728. if ($data['page']['page'] >= $data['page']['pagecount']) {
  1729. Cache::rm($key);
  1730. mac_echo(lang('model/collect/is_over'));
  1731. unset($param['page']);
  1732. $param['ac'] = 'list';
  1733. $url = url('api') . '?' . http_build_query($param);
  1734. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1735. } else {
  1736. $param['page'] = intval($data['page']['page']) + 1;
  1737. $url = url('api') . '?' . http_build_query($param);
  1738. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1739. }
  1740. }
  1741. }
  1742. }
  1743. public function role_json($param)
  1744. {
  1745. $url_param = [];
  1746. $url_param['ac'] = $param['ac'];
  1747. $url_param['t'] = $param['t'];
  1748. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  1749. $url_param['h'] = $param['h'];
  1750. $url_param['ids'] = $param['ids'];
  1751. $url_param['wd'] = $param['wd'];
  1752. if($param['ac']!='list'){
  1753. $url_param['ac'] = 'detail';
  1754. }
  1755. $url = $param['cjurl'];
  1756. if(strpos($url,'?')===false){
  1757. $url .='?';
  1758. }
  1759. else{
  1760. $url .='&';
  1761. }
  1762. $url .= http_build_query($url_param).base64_decode($param['param']);
  1763. $result = $this->checkCjUrl($url);
  1764. if ($result['code'] > 1) {
  1765. return $result;
  1766. }
  1767. $html = mac_curl_get($url);
  1768. if(empty($html)){
  1769. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  1770. }
  1771. $html = mac_filter_tags($html);
  1772. $json = json_decode($html,true);
  1773. if(!$json){
  1774. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ': ' . mb_substr($html, 0, 15)];
  1775. }
  1776. $array_page = [];
  1777. $array_page['page'] = $json['page'];
  1778. $array_page['pagecount'] = $json['pagecount'];
  1779. $array_page['pagesize'] = $json['limit'];
  1780. $array_page['recordcount'] = $json['total'];
  1781. $array_page['url'] = $url;
  1782. $key = 0;
  1783. $array_data = [];
  1784. foreach($json['list'] as $key=>$v){
  1785. $array_data[$key] = $v;
  1786. }
  1787. $res = ['code'=>1, 'msg'=>'ok', 'page'=>$array_page, 'data'=>$array_data ];
  1788. return $res;
  1789. }
  1790. public function role_data($param,$data,$show=1)
  1791. {
  1792. if($show==1) {
  1793. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1',[$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  1794. }
  1795. $config = config('maccms.collect');
  1796. $config = $config['role'];
  1797. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  1798. $filter_arr = explode(',',$config['filter']); $filter_arr = array_filter($filter_arr);
  1799. $pse_rnd = explode('#',$config['words']); $pse_rnd = array_filter($pse_rnd);
  1800. $pse_syn = mac_txt_explain($config['thesaurus'], true);
  1801. foreach($data['data'] as $k=>$v){
  1802. $color='red';
  1803. $des='';
  1804. $msg='';
  1805. $tmp='';
  1806. if(empty($v['role_name']) || empty($v['role_actor']) || empty($v['vod_name']) ) {
  1807. $des = lang('model/collect/role_data_require');
  1808. }
  1809. elseif( mac_array_filter($filter_arr,$v['role_name']) !==false) {
  1810. $des = lang('model/collect/name_in_filter_err');
  1811. }
  1812. else {
  1813. unset($v['role_id']);
  1814. foreach($v as $k2=>$v2){
  1815. if(strpos($k2,'_content')===false) {
  1816. $v[$k2] = mac_strip_tags($v2);
  1817. }
  1818. }
  1819. $v['role_en'] = Pinyin::get($v['role_name']);
  1820. $v['role_letter'] = strtoupper(substr($v['role_en'],0,1));
  1821. $v['role_time_add'] = time();
  1822. $v['role_time'] = time();
  1823. $v['role_status'] = intval($config['status']);
  1824. $v['role_lock'] = intval($v['role_lock']);
  1825. if(!empty($v['role_status'])) {
  1826. $v['role_status'] = intval($v['role_status']);
  1827. }
  1828. $v['role_level'] = intval($v['role_level']);
  1829. $v['role_hits'] = intval($v['role_hits']);
  1830. $v['role_hits_day'] = intval($v['role_hits_day']);
  1831. $v['role_hits_week'] = intval($v['role_hits_week']);
  1832. $v['role_hits_month'] = intval($v['role_hits_month']);
  1833. $v['role_up'] = intval($v['role_up']);
  1834. $v['role_down'] = intval($v['role_down']);
  1835. $v['role_score'] = floatval($v['role_score']);
  1836. $v['role_score_all'] = intval($v['role_score_all']);
  1837. $v['role_score_num'] = intval($v['role_score_num']);
  1838. if($config['hits_start']>0 && $config['hits_end']>0) {
  1839. $v['role_hits'] = rand($config['hits_start'], $config['hits_end']);
  1840. $v['role_hits_day'] = rand($config['hits_start'], $config['hits_end']);
  1841. $v['role_hits_week'] = rand($config['hits_start'], $config['hits_end']);
  1842. $v['role_hits_month'] = rand($config['hits_start'], $config['hits_end']);
  1843. }
  1844. if($config['updown_start']>0 && $config['updown_end']){
  1845. $v['role_up'] = rand($config['updown_start'], $config['updown_end']);
  1846. $v['role_down'] = rand($config['updown_start'], $config['updown_end']);
  1847. }
  1848. if($config['score']==1) {
  1849. $v['role_score_num'] = rand(1, 1000);
  1850. $v['role_score_all'] = $v['role_score_num'] * rand(1, 10);
  1851. $v['role_score'] = round($v['role_score_all'] / $v['role_score_num'], 1);
  1852. }
  1853. if ($config['psernd'] == 1) {
  1854. $v['role_content'] = mac_rep_pse_rnd($pse_rnd, $v['role_content']);
  1855. }
  1856. if ($config['psesyn'] == 1) {
  1857. $v['role_content'] = mac_rep_pse_syn($pse_syn, $v['role_content']);
  1858. }
  1859. $where = [];
  1860. $where['role_name'] = $v['role_name'];
  1861. $where['role_actor'] = $v['role_actor'];
  1862. $where2 = [];
  1863. $blend = false;
  1864. if(!empty($v['douban_id'])){
  1865. $where2['vod_douban_id'] = ['eq',$v['douban_id']];
  1866. unset($v['douban_id']);
  1867. }
  1868. else{
  1869. $where2['vod_name'] = ['eq',$v['vod_name']];
  1870. }
  1871. if (strpos($config['inrule'], 'c')!==false) {
  1872. $where2['vod_actor'] = ['like', mac_like_arr($v['role_actor']), 'OR'];
  1873. }
  1874. if (strpos($config['inrule'], 'd')!==false) {
  1875. $where2['vod_director'] = ['like', mac_like_arr($v['role_actor']), 'OR'];
  1876. }
  1877. if(!empty($where2['vod_actor']) && !empty($where2['vod_director'])){
  1878. $blend = true;
  1879. $GLOBALS['blend'] = [
  1880. 'vod_actor' => $where2['vod_actor'],
  1881. 'vod_director' => $where2['vod_director']
  1882. ];
  1883. unset($where2['vod_actor'],$where2['vod_director']);
  1884. }
  1885. if($blend===false){
  1886. $vod_info = model('Vod')->where($where2)->find();
  1887. }
  1888. else{
  1889. $vod_info = model('Vod')->where($where2)
  1890. ->where(function($query){
  1891. $query->where('vod_director',$GLOBALS['blend']['vod_director'])
  1892. ->whereOr('vod_actor',$GLOBALS['blend']['vod_actor']);
  1893. })
  1894. ->find();
  1895. }
  1896. if (!$vod_info) {
  1897. $des = lang('model/collect/not_found_rel_vod');
  1898. }
  1899. else {
  1900. $v['role_rid'] = $vod_info['vod_id'];
  1901. $where['role_rid'] = $vod_info['vod_id'];
  1902. $info = model('Role')->where($where)->find();
  1903. if (!$info) {
  1904. $tmp = $this->syncImages($config_sync_pic, $v['role_pic'], 'role');
  1905. $v['role_pic'] = $tmp['pic'];
  1906. $msg = $tmp['msg'];
  1907. $res = model('Role')->insert($v);
  1908. if ($res === false) {
  1909. }
  1910. $color = 'green';
  1911. $des = lang('model/collect/add_ok');
  1912. } else {
  1913. if(empty($config['uprule'])){
  1914. $des = lang('model/collect/uprule_empty');
  1915. }
  1916. elseif ($info['role_lock'] == 1) {
  1917. $des = lang('model/collect/data_lock');
  1918. }
  1919. else {
  1920. unset($v['role_time_add']);
  1921. $rc = true;
  1922. if ($rc) {
  1923. $update = [];
  1924. if (strpos(',' . $config['uprule'], 'a') !== false && !empty($v['role_content']) && $v['role_content'] != $info['role_content']) {
  1925. $update['role_content'] = $v['role_content'];
  1926. }
  1927. if (strpos(',' . $config['uprule'], 'b') !== false && !empty($v['role_remarks']) && $v['role_remarks'] != $info['role_remarks']) {
  1928. $update['role_remarks'] = $v['role_remarks'];
  1929. }
  1930. if (strpos(',' . $config['uprule'], 'c') !== false && (substr($info["role_pic"], 0, 4) == "http" || empty($info['role_pic'])) && ($v['role_pic'] != $info['role_pic'] || strpos($info['role_pic'], '#err') !== false)) {
  1931. $tmp = $this->syncImages($config_sync_pic, $v['role_pic'], 'role');
  1932. $update['role_pic'] = $tmp['pic'];
  1933. $msg = $tmp['msg'];
  1934. }
  1935. if(count($update)>0){
  1936. $update['role_time'] = time();
  1937. $where = [];
  1938. $where['role_id'] = $info['role_id'];
  1939. $res = model('Role')->where($where)->update($update);
  1940. $color = 'green';
  1941. if ($res === false) {
  1942. }
  1943. }
  1944. else{
  1945. $des = lang('model/collect/not_need_update');
  1946. }
  1947. }
  1948. }
  1949. }
  1950. }
  1951. }
  1952. if($show==1) {
  1953. mac_echo( ($k + 1) . $v['role_name'] . "<font color=$color>" .$des .'</font>'. $msg . '');
  1954. }
  1955. else{
  1956. return ['code'=>($color=='red' ? 1001 : 1),'msg'=> $v['role_name'] .' '.$des ];
  1957. }
  1958. }
  1959. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_role';
  1960. if(ENTRANCE=='api'){
  1961. Cache::rm($key);
  1962. if ($data['page']['page'] < $data['page']['pagecount']) {
  1963. $param['page'] = intval($data['page']['page']) + 1;
  1964. $res = $this->role($param);
  1965. if($res['code']>1){
  1966. return $this->error($res['msg']);
  1967. }
  1968. $this->role_data($param,$res );
  1969. }
  1970. mac_echo(lang('model/collect/is_over'));
  1971. die;
  1972. }
  1973. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  1974. $GLOBALS['config']['app']['collect_timespan'] = 3;
  1975. }
  1976. if($show==1) {
  1977. if ($param['ac'] == 'cjsel') {
  1978. Cache::rm($key);
  1979. mac_echo(lang('model/collect/is_over'));
  1980. unset($param['ids']);
  1981. $param['ac'] = 'list';
  1982. $url = url('api') . '?' . http_build_query($param);
  1983. $ref = $_SERVER["HTTP_REFERER"];
  1984. if(!empty($ref)){
  1985. $url = $ref;
  1986. }
  1987. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1988. } else {
  1989. if ($data['page']['page'] >= $data['page']['pagecount']) {
  1990. Cache::rm($key);
  1991. mac_echo(lang('model/collect/is_over'));
  1992. unset($param['page']);
  1993. $param['ac'] = 'list';
  1994. $url = url('api') . '?' . http_build_query($param);
  1995. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1996. } else {
  1997. $param['page'] = intval($data['page']['page']) + 1;
  1998. $url = url('api') . '?' . http_build_query($param);
  1999. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2000. }
  2001. }
  2002. }
  2003. }
  2004. public function website_json($param)
  2005. {
  2006. $url_param = [];
  2007. $url_param['ac'] = $param['ac'];
  2008. $url_param['t'] = $param['t'];
  2009. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  2010. $url_param['h'] = $param['h'];
  2011. $url_param['ids'] = $param['ids'];
  2012. $url_param['wd'] = $param['wd'];
  2013. if($param['ac']!='list'){
  2014. $url_param['ac'] = 'detail';
  2015. }
  2016. $url = $param['cjurl'];
  2017. if(strpos($url,'?')===false){
  2018. $url .='?';
  2019. }
  2020. else{
  2021. $url .='&';
  2022. }
  2023. $url .= http_build_query($url_param).base64_decode($param['param']);
  2024. $result = $this->checkCjUrl($url);
  2025. if ($result['code'] > 1) {
  2026. return $result;
  2027. }
  2028. $html = mac_curl_get($url);
  2029. if(empty($html)){
  2030. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  2031. }
  2032. $html = mac_filter_tags($html);
  2033. $json = json_decode($html,true);
  2034. if(!$json){
  2035. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ': ' . mb_substr($html, 0, 15)];
  2036. }
  2037. $array_page = [];
  2038. $array_page['page'] = $json['page'];
  2039. $array_page['pagecount'] = $json['pagecount'];
  2040. $array_page['pagesize'] = $json['limit'];
  2041. $array_page['recordcount'] = $json['total'];
  2042. $array_page['url'] = $url;
  2043. $type_list = model('Type')->getCache('type_list');
  2044. $bind_list = config('bind');
  2045. $key = 0;
  2046. $array_data = [];
  2047. foreach($json['list'] as $key=>$v){
  2048. $array_data[$key] = $v;
  2049. $bind_key = $param['cjflag'] .'_'.$v['type_id'];
  2050. if($bind_list[$bind_key] >0){
  2051. $array_data[$key]['type_id'] = $bind_list[$bind_key];
  2052. }
  2053. else{
  2054. $array_data[$key]['type_id'] = 0;
  2055. }
  2056. }
  2057. $array_type = [];
  2058. $key=0;
  2059. //分类列表
  2060. if($param['ac'] == 'list'){
  2061. foreach($json['class'] as $k=>$v){
  2062. $array_type[$key]['type_id'] = $v['type_id'];
  2063. $array_type[$key]['type_name'] = $v['type_name'];
  2064. $key++;
  2065. }
  2066. }
  2067. $res = ['code'=>1, 'msg'=>'ok', 'page'=>$array_page, 'type'=>$array_type, 'data'=>$array_data ];
  2068. return $res;
  2069. }
  2070. public function website_data($param,$data,$show=1)
  2071. {
  2072. if($show==1) {
  2073. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1',[$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  2074. }
  2075. $config = config('maccms.collect');
  2076. $config = $config['website'];
  2077. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  2078. $type_list = model('Type')->getCache('type_list');
  2079. $filter_arr = explode(',',$config['filter']); $filter_arr = array_filter($filter_arr);
  2080. $pse_rnd = explode('#',$config['words']); $pse_rnd = array_filter($pse_rnd);
  2081. $pse_syn = mac_txt_explain($config['thesaurus'], true);
  2082. foreach($data['data'] as $k=>$v){
  2083. $color='red';
  2084. $des='';
  2085. $msg='';
  2086. $tmp='';
  2087. if($v['type_id'] ==0){
  2088. $des = lang('model/collect/type_err');
  2089. }
  2090. elseif(empty($v['website_name'])) {
  2091. $des = lang('model/collect/name_err');
  2092. }
  2093. elseif( mac_array_filter($filter_arr,$v['website_name'])!==false) {
  2094. $des = lang('model/collect/name_in_filter_err');
  2095. }
  2096. else {
  2097. unset($v['website_id']);
  2098. foreach($v as $k2=>$v2){
  2099. if(strpos($k2,'_content')===false) {
  2100. $v[$k2] = mac_strip_tags($v2);
  2101. }
  2102. }
  2103. $v['website_name'] = trim($v['website_name']);
  2104. $v['type_id_1'] = intval($type_list[$v['type_id']]['type_pid']);
  2105. $v['website_en'] = Pinyin::get($v['website_name']);
  2106. $v['website_letter'] = strtoupper(substr($v['website_en'],0,1));
  2107. $v['website_time_add'] = time();
  2108. $v['website_time'] = time();
  2109. $v['website_status'] = intval($config['status']);
  2110. $v['website_lock'] = intval($v['website_lock']);
  2111. if(!empty($v['website_status'])) {
  2112. $v['website_status'] = intval($v['website_status']);
  2113. }
  2114. $v['website_level'] = intval($v['website_level']);
  2115. $v['website_hits'] = intval($v['website_hits']);
  2116. $v['website_hits_day'] = intval($v['website_hits_day']);
  2117. $v['website_hits_week'] = intval($v['website_hits_week']);
  2118. $v['website_hits_month'] = intval($v['website_hits_month']);
  2119. $v['website_up'] = intval($v['website_up']);
  2120. $v['website_down'] = intval($v['website_down']);
  2121. $v['website_score'] = floatval($v['website_score']);
  2122. $v['website_score_all'] = intval($v['website_score_all']);
  2123. $v['website_score_num'] = intval($v['website_score_num']);
  2124. if($config['hits_start']>0 && $config['hits_end']>0) {
  2125. $v['website_hits'] = rand($config['hits_start'], $config['hits_end']);
  2126. $v['website_hits_day'] = rand($config['hits_start'], $config['hits_end']);
  2127. $v['website_hits_week'] = rand($config['hits_start'], $config['hits_end']);
  2128. $v['website_hits_month'] = rand($config['hits_start'], $config['hits_end']);
  2129. }
  2130. if($config['updown_start']>0 && $config['updown_end']){
  2131. $v['website_up'] = rand($config['updown_start'], $config['updown_end']);
  2132. $v['website_down'] = rand($config['updown_start'], $config['updown_end']);
  2133. }
  2134. if($config['score']==1) {
  2135. $v['website_score_num'] = rand(1, 1000);
  2136. $v['website_score_all'] = $v['website_score_num'] * rand(1, 10);
  2137. $v['website_score'] = round($v['website_score_all'] / $v['website_score_num'], 1);
  2138. }
  2139. if ($config['psernd'] == 1) {
  2140. $v['website_content'] = mac_rep_pse_rnd($pse_rnd, $v['website_content']);
  2141. }
  2142. if ($config['psesyn'] == 1) {
  2143. $v['website_content'] = mac_rep_pse_syn($pse_syn, $v['website_content']);
  2144. }
  2145. if(empty($v['website_blurb'])){
  2146. $v['website_blurb'] = mac_substring( strip_tags($v['website_content']) ,100);
  2147. }
  2148. $where = [];
  2149. $where['website_name'] = $v['website_name'];
  2150. if (strpos($config['inrule'], 'b')!==false) {
  2151. $where['type_id'] = $v['type_id'];
  2152. }
  2153. // 采集网址入库重复规则建议增加跳转url
  2154. // https://github.com/magicblack/maccms10/issues/1071
  2155. if (strpos($config['inrule'], 'c')!==false) {
  2156. $where['website_jumpurl'] = $v['website_jumpurl'];
  2157. }
  2158. $info = model('Website')->where($where)->find();
  2159. if (!$info) {
  2160. $tmp = $this->syncImages($config_sync_pic, $v['website_pic'],'website');
  2161. $v['website_pic'] = $tmp['pic'];
  2162. $msg = $tmp['msg'];
  2163. $res = model('Website')->insert($v);
  2164. if($res===false){
  2165. }
  2166. $color ='green';
  2167. $des= lang('model/collect/add_ok');
  2168. } else {
  2169. if(empty($config['uprule'])){
  2170. $des = lang('model/collect/uprule_empty');
  2171. }
  2172. elseif ($info['website_lock'] == 1) {
  2173. $des = lang('model/collect/data_lock');
  2174. }
  2175. else {
  2176. unset($v['website_time_add']);
  2177. $rc=true;
  2178. if($rc){
  2179. $update=[];
  2180. if(strpos(','.$config['uprule'],'a')!==false && !empty($v['website_content']) && $v['website_content']!=$info['website_content']){
  2181. $update['website_content'] = $v['website_content'];
  2182. }
  2183. if(strpos(','.$config['uprule'],'b')!==false && !empty($v['website_blurb']) && $v['website_blurb']!=$info['website_blurb']){
  2184. $update['website_blurb'] = $v['website_blurb'];
  2185. }
  2186. if(strpos(','.$config['uprule'],'c')!==false && !empty($v['website_remarks']) && $v['website_remarks']!=$info['website_remarks']){
  2187. $update['website_remarks'] = $v['website_remarks'];
  2188. }
  2189. if(strpos(','.$config['uprule'],'d')!==false && !empty($v['website_jumpurl']) && $v['website_jumpurl']!=$info['website_jumpurl']){
  2190. $update['website_jumpurl'] = $v['website_jumpurl'];
  2191. }
  2192. if(strpos(','.$config['uprule'],'e')!==false && (substr($info["website_pic"], 0, 4) == "http" ||empty($info['website_pic']) ) && ($v['website_pic']!=$info['website_pic'] || strpos($info['website_pic'], '#err') !== false) ){
  2193. $tmp = $this->syncImages($config_sync_pic, $v['website_pic'],'website');
  2194. $update['website_pic'] =$tmp['pic'];
  2195. $msg =$tmp['msg'];
  2196. }
  2197. if(count($update)>0){
  2198. $update['website_time'] = time();
  2199. $where = [];
  2200. $where['website_id'] = $info['website_id'];
  2201. $res = model('Website')->where($where)->update($update);
  2202. $color = 'green';
  2203. if($res===false){
  2204. }
  2205. }
  2206. else{
  2207. $des = lang('model/collect/not_need_update');
  2208. }
  2209. }
  2210. }
  2211. }
  2212. }
  2213. if($show==1) {
  2214. mac_echo( ($k + 1) . $v['website_name'] . "<font color=$color>" .$des .'</font>'. $msg . '');
  2215. }
  2216. else{
  2217. return ['code'=>($color=='red' ? 1001 : 1),'msg'=> $v['website_name'] .' '.$des ];
  2218. }
  2219. }
  2220. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_website';
  2221. if(ENTRANCE=='api'){
  2222. Cache::rm($key);
  2223. if ($data['page']['page'] < $data['page']['pagecount']) {
  2224. $param['page'] = intval($data['page']['page']) + 1;
  2225. $res = $this->actor($param);
  2226. if($res['code']>1){
  2227. return $this->error($res['msg']);
  2228. }
  2229. $this->website_data($param,$res );
  2230. }
  2231. mac_echo(lang('model/collect/is_over'));
  2232. die;
  2233. }
  2234. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  2235. $GLOBALS['config']['app']['collect_timespan'] = 3;
  2236. }
  2237. if($show==1) {
  2238. if ($param['ac'] == 'cjsel') {
  2239. Cache::rm($key);
  2240. mac_echo(lang('model/collect/is_over'));
  2241. unset($param['ids']);
  2242. $param['ac'] = 'list';
  2243. $url = url('api') . '?' . http_build_query($param);
  2244. $ref = $_SERVER["HTTP_REFERER"];
  2245. if(!empty($ref)){
  2246. $url = $ref;
  2247. }
  2248. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2249. } else {
  2250. if ($data['page']['page'] >= $data['page']['pagecount']) {
  2251. Cache::rm($key);
  2252. mac_echo(lang('model/collect/is_over'));
  2253. unset($param['page']);
  2254. $param['ac'] = 'list';
  2255. $url = url('api') . '?' . http_build_query($param);
  2256. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2257. } else {
  2258. $param['page'] = intval($data['page']['page']) + 1;
  2259. $url = url('api') . '?' . http_build_query($param);
  2260. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2261. }
  2262. }
  2263. }
  2264. }
  2265. public function comment_json($param)
  2266. {
  2267. $url_param = [];
  2268. $url_param['ac'] = $param['ac'];
  2269. $url_param['t'] = $param['t'];
  2270. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  2271. $url_param['h'] = $param['h'];
  2272. $url_param['ids'] = $param['ids'];
  2273. $url_param['wd'] = $param['wd'];
  2274. if($param['ac']!='list'){
  2275. $url_param['ac'] = 'detail';
  2276. }
  2277. $url = $param['cjurl'];
  2278. if(strpos($url,'?')===false){
  2279. $url .='?';
  2280. }
  2281. else{
  2282. $url .='&';
  2283. }
  2284. $url .= http_build_query($url_param).base64_decode($param['param']);
  2285. $result = $this->checkCjUrl($url);
  2286. if ($result['code'] > 1) {
  2287. return $result;
  2288. }
  2289. $html = mac_curl_get($url);
  2290. if(empty($html)){
  2291. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  2292. }
  2293. $html = mac_filter_tags($html);
  2294. $json = json_decode($html,true);
  2295. if(!$json){
  2296. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ': ' . mb_substr($html, 0, 15)];
  2297. }
  2298. $array_page = [];
  2299. $array_page['page'] = $json['page'];
  2300. $array_page['pagecount'] = $json['pagecount'];
  2301. $array_page['pagesize'] = $json['limit'];
  2302. $array_page['recordcount'] = $json['total'];
  2303. $array_page['url'] = $url;
  2304. $key = 0;
  2305. $array_data = [];
  2306. foreach($json['list'] as $key=>$v){
  2307. $array_data[$key] = $v;
  2308. }
  2309. $res = ['code'=>1, 'msg'=>'ok', 'page'=>$array_page, 'data'=>$array_data ];
  2310. return $res;
  2311. }
  2312. public function comment_data($param,$data,$show=1)
  2313. {
  2314. if($show==1) {
  2315. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1',[$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  2316. }
  2317. $config = config('maccms.collect');
  2318. $config = $config['comment'];
  2319. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  2320. $filter_arr = explode(',',$config['filter']); $filter_arr = array_filter($filter_arr);
  2321. $pse_rnd = explode('#',$config['words']); $pse_rnd = array_filter($pse_rnd);
  2322. $pse_syn = mac_txt_explain($config['thesaurus'], true);
  2323. foreach($data['data'] as $k=>$v){
  2324. $color='red';
  2325. $des='';
  2326. $msg='';
  2327. $tmp='';
  2328. if(empty($v['comment_name']) || empty($v['comment_content']) || empty($v['rel_name']) ) {
  2329. $des = lang('model/collect/comment_data_require');
  2330. }
  2331. elseif( mac_array_filter($filter_arr,$v['comment_content']) !==false) {
  2332. $des = lang('model/collect/name_in_filter_err');
  2333. }
  2334. else {
  2335. unset($v['comment_id']);
  2336. foreach($v as $k2=>$v2){
  2337. if(strpos($k2,'_content')===false) {
  2338. $v[$k2] = mac_strip_tags($v2);
  2339. }
  2340. }
  2341. $v['comment_time'] = time();
  2342. $v['comment_status'] = intval($config['status']);
  2343. $v['comment_up'] = intval($v['comment_up']);
  2344. $v['comment_down'] = intval($v['comment_down']);
  2345. $v['comment_mid'] = intval($v['comment_mid']);
  2346. if(!empty($v['comment_ip']) && !is_numeric($v['comment_ip'])){
  2347. $v['comment_ip'] = mac_get_ip_long($v['comment_ip']);
  2348. }
  2349. if($config['updown_start']>0 && $config['updown_end']){
  2350. $v['comment_up'] = rand($config['updown_start'], $config['updown_end']);
  2351. $v['comment_down'] = rand($config['updown_start'], $config['updown_end']);
  2352. }
  2353. if ($config['psernd'] == 1) {
  2354. $v['comment_content'] = mac_rep_pse_rnd($pse_rnd, $v['comment_content']);
  2355. }
  2356. if ($config['psesyn'] == 1) {
  2357. $v['comment_content'] = mac_rep_pse_syn($pse_syn, $v['comment_content']);
  2358. }
  2359. $where = [];
  2360. $where2 = [];
  2361. $blend = false;
  2362. if (strpos($config['inrule'], 'b')!==false) {
  2363. $where['comment_content'] = ['eq', $v['comment_content']];
  2364. }
  2365. if (strpos($config['inrule'], 'c')!==false) {
  2366. $where['comment_name'] = ['eq', $v['comment_name']];
  2367. }
  2368. if(empty($v['rel_id'])){
  2369. if($v['comment_mid']==1){
  2370. if(!empty($v['douban_id'])){
  2371. $where2['vod_douban_id'] = ['eq',$v['douban_id']];
  2372. unset($v['douban_id']);
  2373. }
  2374. else{
  2375. $where2['vod_name'] = ['eq',$v['rel_name']];
  2376. }
  2377. $rel_info = model('Vod')->where($where2)->find();
  2378. }
  2379. elseif($v['comment_mid']==2){
  2380. $where2['art_name'] = ['eq',$v['rel_name']];
  2381. $rel_info = model('Art')->where($where2)->find();
  2382. }
  2383. elseif($v['comment_mid']==3){
  2384. $where2['topic_name'] = ['eq',$v['rel_name']];
  2385. $rel_info = model('Topic')->where($where2)->find();
  2386. }
  2387. elseif($v['comment_mid']==8){
  2388. $where2['actor_name'] = ['eq',$v['rel_name']];
  2389. $rel_info = model('Actor')->where($where2)->find();
  2390. }
  2391. elseif($v['comment_mid']==9){
  2392. $where2['role_name'] = ['eq',$v['rel_name']];
  2393. $rel_info = model('Role')->where($where2)->find();
  2394. }
  2395. elseif($v['comment_mid']==11){
  2396. $where2['website_name'] = ['eq',$v['rel_name']];
  2397. $rel_info = model('Website')->where($where2)->find();
  2398. }
  2399. $rel_id = $rel_info[mac_get_mid_code($v['comment_mid']).'_id'];
  2400. }
  2401. else{
  2402. $rel_id = $v['rel_id'];
  2403. }
  2404. if(empty($rel_id)){
  2405. $des = lang('model/collect/not_found_rel_data');
  2406. }
  2407. else {
  2408. $v['comment_rid'] = $rel_id;
  2409. $info=false;
  2410. if(!empty($where)) {
  2411. $where['comment_rid'] = $rel_id;
  2412. $info = model('Comment')->where($where)->find();
  2413. }
  2414. if (!$info) {
  2415. $msg = isset($tmp['msg']) ? $tmp['msg'] : '';
  2416. $res = model('Comment')->insert($v);
  2417. if ($res === false) {
  2418. }
  2419. $color = 'green';
  2420. $des = lang('model/collect/add_ok');
  2421. } else {
  2422. if(empty($config['uprule'])){
  2423. $des = lang('model/collect/uprule_empty');
  2424. }
  2425. else {
  2426. $rc = true;
  2427. if ($rc) {
  2428. $update = [];
  2429. if (strpos(',' . $config['uprule'], 'a') !== false && !empty($v['comment_time']) && $v['comment_time'] != $info['comment_time']) {
  2430. $update['comment_time'] = $v['comment_time'];
  2431. }
  2432. if(count($update)>0){
  2433. $update['comment_time'] = time();
  2434. $where = [];
  2435. $where['comment_id'] = $info['comment_id'];
  2436. $res = model('Comment')->where($where)->update($update);
  2437. $color = 'green';
  2438. if ($res === false) {
  2439. }
  2440. }
  2441. else{
  2442. $des = lang('model/collect/not_need_update');
  2443. }
  2444. }
  2445. }
  2446. }
  2447. }
  2448. }
  2449. if($show==1) {
  2450. mac_echo( ($k + 1) . $v['comment_content'] . "<font color=$color>" .$des .'</font>'. $msg . '');
  2451. }
  2452. else{
  2453. return ['code'=>($color=='red' ? 1001 : 1),'msg'=> $v['comment_content'] .' '.$des ];
  2454. }
  2455. }
  2456. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_comment';
  2457. if(ENTRANCE=='api'){
  2458. Cache::rm($key);
  2459. if ($data['page']['page'] < $data['page']['pagecount']) {
  2460. $param['page'] = intval($data['page']['page']) + 1;
  2461. $res = $this->role($param);
  2462. if($res['code']>1){
  2463. return $this->error($res['msg']);
  2464. }
  2465. $this->actor_data($param,$res );
  2466. }
  2467. mac_echo(lang('model/collect/is_over'));
  2468. die;
  2469. }
  2470. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  2471. $GLOBALS['config']['app']['collect_timespan'] = 3;
  2472. }
  2473. if($show==1) {
  2474. if ($param['ac'] == 'cjsel') {
  2475. Cache::rm($key);
  2476. mac_echo(lang('model/collect/is_over'));
  2477. unset($param['ids']);
  2478. $param['ac'] = 'list';
  2479. $url = url('api') . '?' . http_build_query($param);
  2480. $ref = $_SERVER["HTTP_REFERER"];
  2481. if(!empty($ref)){
  2482. $url = $ref;
  2483. }
  2484. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2485. } else {
  2486. if ($data['page']['page'] >= $data['page']['pagecount']) {
  2487. Cache::rm($key);
  2488. mac_echo(lang('model/collect/is_over'));
  2489. unset($param['page']);
  2490. $param['ac'] = 'list';
  2491. $url = url('api') . '?' . http_build_query($param);
  2492. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2493. } else {
  2494. $param['page'] = intval($data['page']['page']) + 1;
  2495. $url = url('api') . '?' . http_build_query($param);
  2496. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2497. }
  2498. }
  2499. }
  2500. }
  2501. /**
  2502. * 检查url合法性
  2503. * https://github.com/magicblack/maccms10/issues/763
  2504. */
  2505. private function checkCjUrl($url)
  2506. {
  2507. $result = parse_url($url);
  2508. if (empty($result['host']) || in_array($result['host'], ['127.0.0.1', 'localhost'])) {
  2509. return ['code' => 1001, 'msg' => lang('model/collect/cjurl_err') . ': ' . $url];
  2510. }
  2511. return ['code' => 1];
  2512. }
  2513. public function manga_xml($param,$html='')
  2514. {
  2515. $url_param = [];
  2516. $url_param['ac'] = $param['ac'];
  2517. $url_param['t'] = $param['t'];
  2518. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  2519. $url_param['h'] = $param['h'];
  2520. $url_param['ids'] = $param['ids'];
  2521. $url_param['wd'] = $param['wd'];
  2522. if(empty($param['h']) && !empty($param['rday'])){
  2523. $url_param['h'] = $param['rday'];
  2524. }
  2525. if($param['ac']!='list'){
  2526. $url_param['ac'] = 'mangalist';
  2527. }
  2528. $url = $param['cjurl'];
  2529. if(strpos($url,'?')===false){
  2530. $url .='?';
  2531. }
  2532. else{
  2533. $url .='&';
  2534. }
  2535. $url .= http_build_query($url_param). base64_decode($param['param']);
  2536. $result = $this->checkCjUrl($url);
  2537. if ($result['code'] > 1) {
  2538. return $result;
  2539. }
  2540. $html = mac_curl_get($url);
  2541. if(empty($html)){
  2542. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  2543. }
  2544. $html = mac_filter_tags($html);
  2545. $xml = @simplexml_load_string($html);
  2546. if(empty($xml)){
  2547. $labelRule = '<pic>'."(.*?)".'</pic>';
  2548. $labelRule = mac_buildregx($labelRule,"is");
  2549. preg_match_all($labelRule,$html,$tmparr);
  2550. $ec=false;
  2551. foreach($tmparr[1] as $tt){
  2552. if(strpos($tt,'[CDATA')===false){
  2553. $ec=true;
  2554. $ne = '<pic>'.'<![CDATA['.$tt .']]>'.'</pic>';
  2555. $html = str_replace('<pic>'.$tt.'</pic>',$ne,$html);
  2556. }
  2557. }
  2558. if($ec) {
  2559. $xml = @simplexml_load_string($html);
  2560. }
  2561. if(empty($xml)) {
  2562. return ['code' => 1002, 'msg'=>lang('model/collect/xml_err')];
  2563. }
  2564. }
  2565. $array_page = [];
  2566. $array_page['page'] = (string)$xml->list->attributes()->page;
  2567. $array_page['pagecount'] = (string)$xml->list->attributes()->pagecount;
  2568. $array_page['pagesize'] = (string)$xml->list->attributes()->pagesize;
  2569. $array_page['recordcount'] = (string)$xml->list->attributes()->recordcount;
  2570. $array_page['url'] = $url;
  2571. $type_list = model('Type')->getCache('type_list');
  2572. $bind_list = config('bind');
  2573. $key = 0;
  2574. $array_data = [];
  2575. foreach($xml->list->manga as $manga){
  2576. $bind_key = $param['cjflag'] .'_'.(string)$manga->tid;
  2577. if($bind_list[$bind_key] >0){
  2578. $array_data[$key]['type_id'] = $bind_list[$bind_key];
  2579. }
  2580. else{
  2581. $array_data[$key]['type_id'] = 0;
  2582. }
  2583. $array_data[$key]['manga_id'] = (string)$manga->id;
  2584. $array_data[$key]['manga_name'] = (string)$manga->name;
  2585. $array_data[$key]['manga_sub'] = (string)$manga->sub;
  2586. $array_data[$key]['manga_remarks'] = (string)$manga->remarks;
  2587. $array_data[$key]['type_name'] = (string)$manga->type;
  2588. $array_data[$key]['manga_pic'] = (string)$manga->pic;
  2589. $array_data[$key]['manga_lang'] = (string)$manga->lang;
  2590. $array_data[$key]['manga_area'] = (string)$manga->area;
  2591. $array_data[$key]['manga_year'] = (string)$manga->year;
  2592. $array_data[$key]['manga_serial'] = (string)$manga->serial;
  2593. $array_data[$key]['manga_author'] = (string)$manga->author;
  2594. $array_data[$key]['manga_artist'] = (string)$manga->artist;
  2595. $array_data[$key]['manga_content'] = (string)$manga->content;
  2596. $array_data[$key]['manga_status'] = 1;
  2597. $array_data[$key]['manga_time'] = (string)$manga->last;
  2598. $array_data[$key]['manga_total'] = 0;
  2599. $array_data[$key]['manga_isend'] = 1;
  2600. if($array_data[$key]['manga_serial']){
  2601. $array_data[$key]['manga_isend'] = 0;
  2602. }
  2603. // 格式化章節
  2604. $array_from = [];
  2605. $array_url = [];
  2606. $array_server=[];
  2607. $array_note=[];
  2608. if(isset($manga->dl->dd) && count($manga->dl->dd)){
  2609. for($i=0; $i<count($manga->dl->dd); $i++){
  2610. $array_from[$i] = (string)$manga->dl->dd[$i]['flag'];
  2611. $urls = explode('#', $this->vod_xml_replace((string)$manga->dl->dd[$i]));
  2612. $sorted_urls = $this->sortPlayUrls($urls);
  2613. $array_url[$i] = implode('#', $sorted_urls);
  2614. $array_server[$i] = 'no';
  2615. $array_note[$i] = '';
  2616. }
  2617. }else{
  2618. $array_from[]=(string)$manga->dt;
  2619. $array_url[] ='';
  2620. $array_server[]='';
  2621. $array_note[]='';
  2622. }
  2623. $array_data[$key]['manga_play_from'] = implode('$$$', $array_from);
  2624. $array_data[$key]['manga_play_url'] = implode('$$$', $array_url);
  2625. $array_data[$key]['manga_play_server'] = implode('$$$', $array_server);
  2626. $array_data[$key]['manga_play_note'] = implode('$$$', $array_note);
  2627. $key++;
  2628. }
  2629. $array_type = [];
  2630. $key=0;
  2631. //分类列表
  2632. if($param['ac'] == 'list'){
  2633. foreach($xml->class->ty as $ty){
  2634. $array_type[$key]['type_id'] = (string)$ty->attributes()->id;
  2635. $array_type[$key]['type_name'] = (string)$ty;
  2636. $key++;
  2637. }
  2638. }
  2639. $res = ['code'=>1, 'msg'=>'xml', 'page'=>$array_page, 'type'=>$array_type, 'data'=>$array_data ];
  2640. return $res;
  2641. }
  2642. public function manga_data($param,$data,$show=1)
  2643. {
  2644. if($show==1) {
  2645. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1', [$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  2646. }
  2647. $config = config('maccms.collect');
  2648. $config = $config['manga'];
  2649. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  2650. $type_list = model('Type')->getCache('type_list');
  2651. $filter_arr = explode(',',$config['filter']);
  2652. $filter_arr = array_filter($filter_arr);
  2653. foreach($data['data'] as $k=>$v){
  2654. $color='red';
  2655. $des='';
  2656. $msg='';
  2657. $tmp='';
  2658. if ($v['type_id'] ==0) {
  2659. $des = lang('model/collect/type_err');
  2660. } elseif (empty($v['manga_name'])) {
  2661. $des = lang('model/collect/name_err');
  2662. } elseif (mac_array_filter($filter_arr,$v['manga_name']) !==false) {
  2663. $des = lang('model/collect/name_in_filter_err');
  2664. } else {
  2665. unset($v['manga_id']);
  2666. foreach($v as $k2=>$v2){
  2667. if(strpos($k2,'_content')===false) {
  2668. $v[$k2] = mac_strip_tags($v2);
  2669. }
  2670. }
  2671. $v['type_id_1'] = intval($type_list[$v['type_id']]['type_pid']);
  2672. $v['manga_en'] = Pinyin::get($v['manga_name']);
  2673. $v['manga_letter'] = strtoupper(substr($v['manga_en'],0,1));
  2674. $v['manga_time_add'] = time();
  2675. $v['manga_time'] = time();
  2676. $v['manga_status'] = intval($config['status']);
  2677. $where = [];
  2678. $where['manga_name'] = $v['manga_name'];
  2679. if (strpos($config['inrule'], 'b')!==false) {
  2680. $where['type_id'] = $v['type_id'];
  2681. }
  2682. $info = model('Manga')->where($where)->find();
  2683. if (!$info) {
  2684. $tmp = $this->syncImages($config_sync_pic, $v['manga_pic'],'manga');
  2685. $v['manga_pic'] = (string)$tmp['pic'];
  2686. $msg = $tmp['msg'];
  2687. $v['manga_chapter_from'] = $v['manga_play_from'];
  2688. $v['manga_chapter_url'] = $v['manga_play_url'];
  2689. $res = model('Manga')->insert($v);
  2690. if($res===false){
  2691. }
  2692. $color ='green';
  2693. $des= lang('model/collect/add_ok');
  2694. }
  2695. else{
  2696. if(empty($config['uprule'])){
  2697. $des = lang('model/collect/uprule_empty');
  2698. }
  2699. elseif ($info['manga_lock'] == 1) {
  2700. $des = lang('model/collect/data_lock');
  2701. }
  2702. else {
  2703. $update = [];
  2704. $ec=false;
  2705. if (strpos(',' . $config['uprule'], 'a')!==false && !empty($v['manga_play_from'])) {
  2706. $old_play_from = $info['manga_chapter_from'];
  2707. $old_play_url = $info['manga_chapter_url'];
  2708. $cj_play_from_arr = explode('$$$',$v['manga_play_from'] );
  2709. $cj_play_url_arr = explode('$$$',$v['manga_play_url']);
  2710. foreach ($cj_play_from_arr as $k2 => $v2) {
  2711. $cj_play_from = $v2;
  2712. $cj_play_url = $cj_play_url_arr[$k2];
  2713. if (strpos('$$$'.$info['manga_chapter_from'].'$$$', '$$$'.$cj_play_from.'$$$') === false) {
  2714. if(!empty($old_play_from)){
  2715. $old_play_url .="$$$";
  2716. $old_play_from .= "$$$" ;
  2717. }
  2718. $old_play_url .= "" . $cj_play_url;
  2719. $old_play_from .= "" . $cj_play_from;
  2720. $ec=true;
  2721. }
  2722. }
  2723. if($ec) {
  2724. $update['manga_chapter_from'] = $old_play_from;
  2725. $update['manga_chapter_url'] = $old_play_url;
  2726. }
  2727. }
  2728. if(count($update)>0){
  2729. $update['manga_time'] = time();
  2730. $where = [];
  2731. $where['manga_id'] = $info['manga_id'];
  2732. $res = model('Manga')->where($where)->update($update);
  2733. $color = 'green';
  2734. }
  2735. else{
  2736. $des = lang('model/collect/not_need_update');
  2737. }
  2738. }
  2739. }
  2740. }
  2741. if($show==1) {
  2742. mac_echo( ($k + 1) .'、'. $v['manga_name'] . " <font color='{$color}'>" .$des .'</font>'. $msg.'' );
  2743. }
  2744. else{
  2745. return ['code'=>($color=='red' ? 1001 : 1),'msg'=>$des ];
  2746. }
  2747. }
  2748. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_manga';
  2749. if(ENTRANCE=='api'){
  2750. Cache::rm($key);
  2751. if ($data['page']['page'] < $data['page']['pagecount']) {
  2752. $param['page'] = intval($data['page']['page']) + 1;
  2753. $res = $this->manga($param);
  2754. if($res['code']>1){
  2755. return $this->error($res['msg']);
  2756. }
  2757. $this->manga_data($param,$res );
  2758. }
  2759. mac_echo(lang('model/collect/is_over'));
  2760. die;
  2761. }
  2762. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  2763. $GLOBALS['config']['app']['collect_timespan'] = 3;
  2764. }
  2765. if($show==1) {
  2766. if ($param['ac'] == 'cjsel') {
  2767. Cache::rm($key);
  2768. mac_echo(lang('model/collect/is_over'));
  2769. unset($param['ids']);
  2770. $param['ac'] = 'list';
  2771. $url = url('api') . '?' . http_build_query($param);
  2772. $ref = $_SERVER["HTTP_REFERER"];
  2773. if(!empty($ref)){
  2774. $url = $ref;
  2775. }
  2776. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2777. } else {
  2778. if ($data['page']['page'] >= $data['page']['pagecount']) {
  2779. Cache::rm($key);
  2780. mac_echo(lang('model/collect/is_over'));
  2781. unset($param['page'],$param['ids']);
  2782. $param['ac'] = 'list';
  2783. $url = url('api') . '?' . http_build_query($param);
  2784. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2785. } else {
  2786. $param['page'] = intval($data['page']['page']) + 1;
  2787. $url = url('api') . '?' . http_build_query($param);
  2788. mac_jump($url, $GLOBALS['config']['app']['collect_timespan'] );
  2789. }
  2790. }
  2791. }
  2792. }
  2793. }