Collect.php 128 KB

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