Collect.php 133 KB

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