Collect.php 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573
  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 vod_xml_replace($url)
  111. {
  112. $array_url = array();
  113. $arr_ji = explode('#',str_replace('||','//',$url));
  114. foreach($arr_ji as $key=>$value){
  115. $urlji = explode('$',$value);
  116. if( count($urlji) > 1 ){
  117. $array_url[$key] = $urlji[0].'$'.trim($urlji[1]);
  118. }else{
  119. $array_url[$key] = trim($urlji[0]);
  120. }
  121. }
  122. return implode('#',$array_url);
  123. }
  124. public function vod_xml($param,$html='')
  125. {
  126. $url_param = [];
  127. $url_param['ac'] = $param['ac'];
  128. $url_param['t'] = $param['t'];
  129. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  130. $url_param['h'] = $param['h'];
  131. $url_param['ids'] = $param['ids'];
  132. $url_param['wd'] = $param['wd'];
  133. if(empty($param['h']) && !empty($param['rday'])){
  134. $url_param['h'] = $param['rday'];
  135. }
  136. if($param['ac']!='list'){
  137. $url_param['ac'] = 'videolist';
  138. }
  139. $url = $param['cjurl'];
  140. if(strpos($url,'?')===false){
  141. $url .='?';
  142. }
  143. else{
  144. $url .='&';
  145. }
  146. $url .= http_build_query($url_param). base64_decode($param['param']);
  147. $result = $this->checkCjUrl($url);
  148. if ($result['code'] > 1) {
  149. return $result;
  150. }
  151. $html = mac_curl_get($url);
  152. if(empty($html)){
  153. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  154. }
  155. $html = mac_filter_tags($html);
  156. $xml = @simplexml_load_string($html);
  157. if(empty($xml)){
  158. $labelRule = '<pic>'."(.*?)".'</pic>';
  159. $labelRule = mac_buildregx($labelRule,"is");
  160. preg_match_all($labelRule,$html,$tmparr);
  161. $ec=false;
  162. foreach($tmparr[1] as $tt){
  163. if(strpos($tt,'[CDATA')===false){
  164. $ec=true;
  165. $ne = '<pic>'.'<![CDATA['.$tt .']]>'.'</pic>';
  166. $html = str_replace('<pic>'.$tt.'</pic>',$ne,$html);
  167. }
  168. }
  169. if($ec) {
  170. $xml = @simplexml_load_string($html);
  171. }
  172. if(empty($xml)) {
  173. return ['code' => 1002, 'msg'=>lang('model/collect/xml_err')];
  174. }
  175. }
  176. $array_page = [];
  177. $array_page['page'] = (string)$xml->list->attributes()->page;
  178. $array_page['pagecount'] = (string)$xml->list->attributes()->pagecount;
  179. $array_page['pagesize'] = (string)$xml->list->attributes()->pagesize;
  180. $array_page['recordcount'] = (string)$xml->list->attributes()->recordcount;
  181. $array_page['url'] = $url;
  182. $type_list = model('Type')->getCache('type_list');
  183. $bind_list = config('bind');
  184. $key = 0;
  185. $array_data = [];
  186. foreach($xml->list->video as $video){
  187. $bind_key = $param['cjflag'] .'_'.(string)$video->tid;
  188. if($bind_list[$bind_key] >0){
  189. $array_data[$key]['type_id'] = $bind_list[$bind_key];
  190. }
  191. else{
  192. $array_data[$key]['type_id'] = 0;
  193. }
  194. $array_data[$key]['vod_id'] = (string)$video->id;
  195. //$array_data[$key]['type_id'] = (string)$video->tid;
  196. $array_data[$key]['vod_name'] = (string)$video->name;
  197. $array_data[$key]['vod_sub'] = (string)$video->subname;
  198. $array_data[$key]['vod_remarks'] = (string)$video->note;
  199. $array_data[$key]['type_name'] = (string)$video->type;
  200. $array_data[$key]['vod_pic'] = (string)$video->pic;
  201. $array_data[$key]['vod_lang'] = (string)$video->lang;
  202. $array_data[$key]['vod_area'] = (string)$video->area;
  203. $array_data[$key]['vod_year'] = (string)$video->year;
  204. $array_data[$key]['vod_serial'] = (string)$video->state;
  205. $array_data[$key]['vod_actor'] = (string)$video->actor;
  206. $array_data[$key]['vod_director'] = (string)$video->director;
  207. $array_data[$key]['vod_content'] = (string)$video->des;
  208. $array_data[$key]['vod_status'] = 1;
  209. $array_data[$key]['vod_type'] = $array_data[$key]['list_name'];
  210. $array_data[$key]['vod_time'] = (string)$video->last;
  211. $array_data[$key]['vod_total'] = 0;
  212. $array_data[$key]['vod_isend'] = 1;
  213. if($array_data[$key]['vod_serial']){
  214. $array_data[$key]['vod_isend'] = 0;
  215. }
  216. //格式化地址与播放器
  217. $array_from = [];
  218. $array_url = [];
  219. $array_server=[];
  220. $array_note=[];
  221. //videolist|list播放列表不同
  222. if(isset($video->dl->dd) && $count=count($video->dl->dd)){
  223. for($i=0; $i<$count; $i++){
  224. $array_from[$i] = (string)$video->dl->dd[$i]['flag'];
  225. $urls = explode('#', $this->vod_xml_replace((string)$video->dl->dd[$i]));
  226. $sorted_urls = $this->sortPlayUrls($urls);
  227. $array_url[$i] = implode('#', $sorted_urls);
  228. $array_server[$i] = 'no';
  229. $array_note[$i] = '';
  230. }
  231. }else{
  232. $array_from[]=(string)$video->dt;
  233. $array_url[] ='';
  234. $array_server[]='';
  235. $array_note[]='';
  236. }
  237. if(strpos(base64_decode($param['param']),'ct=1')!==false){
  238. $array_data[$key]['vod_down_from'] = implode('$$$', $array_from);
  239. $array_data[$key]['vod_down_url'] = implode('$$$', $array_url);
  240. $array_data[$key]['vod_down_server'] = implode('$$$', $array_server);
  241. $array_data[$key]['vod_down_note'] = implode('$$$', $array_note);
  242. }
  243. else{
  244. $array_data[$key]['vod_play_from'] = implode('$$$', $array_from);
  245. $array_data[$key]['vod_play_url'] = implode('$$$', $array_url);
  246. $array_data[$key]['vod_play_server'] = implode('$$$', $array_server);
  247. $array_data[$key]['vod_play_note'] = implode('$$$', $array_note);
  248. }
  249. $key++;
  250. }
  251. $array_type = [];
  252. $key=0;
  253. //分类列表
  254. if($param['ac'] == 'list'){
  255. foreach($xml->class->ty as $ty){
  256. $array_type[$key]['type_id'] = (string)$ty->attributes()->id;
  257. $array_type[$key]['type_name'] = (string)$ty;
  258. $key++;
  259. }
  260. }
  261. $res = ['code'=>1, 'msg'=>'xml', 'page'=>$array_page, 'type'=>$array_type, 'data'=>$array_data ];
  262. return $res;
  263. }
  264. public function vod_json($param)
  265. {
  266. $url_param = [];
  267. $url_param['ac'] = $param['ac'];
  268. $url_param['t'] = $param['t'];
  269. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  270. $url_param['h'] = $param['h'];
  271. $url_param['ids'] = $param['ids'];
  272. $url_param['wd'] = $param['wd'];
  273. if($param['ac']!='list'){
  274. $url_param['ac'] = 'videolist';
  275. }
  276. $url = $param['cjurl'];
  277. if(strpos($url,'?')===false){
  278. $url .='?';
  279. }
  280. else{
  281. $url .='&';
  282. }
  283. $url .= http_build_query($url_param). base64_decode($param['param']);
  284. $result = $this->checkCjUrl($url);
  285. if ($result['code'] > 1) {
  286. return $result;
  287. }
  288. $html = mac_curl_get($url);
  289. if(empty($html)){
  290. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  291. }
  292. $html = mac_filter_tags($html);
  293. $json = json_decode($html,true);
  294. if(!$json){
  295. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ', url: ' . $url . ', response: ' . mb_substr($html, 0, 15)];
  296. }
  297. $array_page = [];
  298. $array_page['page'] = $json['page'];
  299. $array_page['pagecount'] = $json['pagecount'];
  300. $array_page['pagesize'] = $json['limit'];
  301. $array_page['recordcount'] = $json['total'];
  302. $array_page['url'] = $url;
  303. $type_list = model('Type')->getCache('type_list');
  304. $bind_list = config('bind');
  305. $key = 0;
  306. $array_data = [];
  307. foreach($json['list'] as $key=>$v){
  308. $array_data[$key] = $v;
  309. $bind_key = $param['cjflag'] .'_'.$v['type_id'];
  310. if($bind_list[$bind_key] >0){
  311. $array_data[$key]['type_id'] = $bind_list[$bind_key];
  312. }
  313. else{
  314. $array_data[$key]['type_id'] = 0;
  315. }
  316. if(!empty($v['dl'])) {
  317. //格式化地址与播放器
  318. $array_from = [];
  319. $array_url = [];
  320. $array_server = [];
  321. $array_note = [];
  322. //videolist|list播放列表不同
  323. foreach ($v['dl'] as $k2 => $v2) {
  324. $array_from[] = $k2;
  325. $urls = explode('#', $v2);
  326. $sorted_urls = $this->sortPlayUrls($urls);
  327. $array_url[] = implode('#', $sorted_urls);
  328. $array_server[] = 'no';
  329. $array_note[] = '';
  330. }
  331. $array_data[$key]['vod_play_from'] = implode('$$$', $array_from);
  332. $array_data[$key]['vod_play_url'] = implode('$$$', $array_url);
  333. $array_data[$key]['vod_play_server'] = implode('$$$', $array_server);
  334. $array_data[$key]['vod_play_note'] = implode('$$$', $array_note);
  335. }
  336. }
  337. $array_type = [];
  338. $key=0;
  339. //分类列表
  340. if($param['ac'] == 'list'){
  341. foreach($json['class'] as $k=>$v){
  342. $array_type[$key]['type_id'] = $v['type_id'];
  343. $array_type[$key]['type_name'] = $v['type_name'];
  344. $key++;
  345. }
  346. }
  347. $res = ['code'=>1, 'msg'=>'json', 'page'=>$array_page, 'type'=>$array_type, 'data'=>$array_data ];
  348. return $res;
  349. }
  350. private function sortPlayUrls($urls) {
  351. $sorted = [];
  352. foreach ($urls as $url) {
  353. if (preg_match('/(?:第|EP|E)?(\d+)(?:集|话|回)?/', $url, $matches)) {
  354. $episode = (int)$matches[1];
  355. $sorted[$episode] = $url;
  356. } else {
  357. $sorted[] = $url;
  358. }
  359. }
  360. ksort($sorted);
  361. return array_values($sorted);
  362. }
  363. /**
  364. * 同步图片
  365. *
  366. * @param $pic_status int 是否同步。为1时,同步图片
  367. * @param $pic_url
  368. * @param string $flag
  369. * @return array
  370. */
  371. private function syncImages($pic_status, $pic_url, $flag = 'vod')
  372. {
  373. $img_url_downloaded = $pic_url;
  374. if ($pic_status == 1) {
  375. $config = (array)config('maccms.upload');
  376. $img_url_downloaded = model('Image')->down_load($pic_url, $config, $flag);
  377. if ($img_url_downloaded == $pic_url) {
  378. // 下载失败,显示老图信息
  379. $des = '<a href="' . $pic_url . '" target="_blank">' . $pic_url . '</a><font color=red>'.lang('download_err').'!</font>';
  380. } else {
  381. // 下载成功,显示新图信息
  382. if (str_starts_with($img_url_downloaded, 'upload/')) {
  383. $link = MAC_PATH . $img_url_downloaded;
  384. } else {
  385. $link = str_replace('mac:', $config['protocol'] . ':', $img_url_downloaded);
  386. }
  387. $des = '<a href="' . $link . '" target="_blank">' . $link . '</a><font color=green>'.lang('download_ok').'!</font>';
  388. }
  389. }
  390. return ['pic' => $img_url_downloaded, 'msg' => $des];
  391. }
  392. public function vod_data($param,$data,$show=1)
  393. {
  394. if($show==1) {
  395. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1', [$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  396. }
  397. $config = config('maccms.collect');
  398. $config = $config['vod'];
  399. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  400. $filter_year = !empty($param['filter_year']) ? $param['filter_year'] : '';
  401. $filter_year_list = $filter_year ? get_array_unique_id_list(explode(',', $filter_year)) : [];
  402. $players = config('vodplayer');
  403. $downers = config('voddowner');
  404. $vod_search = model('VodSearch');
  405. $vod_search_enabled = $vod_search->isCollectEnabled();
  406. $vs_max_id_count = $vod_search->maxIdCount;
  407. $type_list = model('Type')->getCache('type_list');
  408. $filter_arr = explode(',',$config['filter']);
  409. $filter_arr = array_filter($filter_arr);
  410. $pse_rnd = explode('#',$config['words']);
  411. $pse_rnd = array_filter($pse_rnd);
  412. $pse_name = mac_txt_explain($config['namewords'], true);
  413. $pse_syn = mac_txt_explain($config['thesaurus'], true);
  414. $pse_player = mac_txt_explain($config['playerwords'], true);
  415. $pse_area = mac_txt_explain($config['areawords'], true);
  416. $pse_lang = mac_txt_explain($config['langwords'], true);
  417. foreach($data['data'] as $k=>$v){
  418. $color='red';
  419. $des='';
  420. $msg='';
  421. $tmp='';
  422. if ($v['type_id'] ==0) {
  423. $des = lang('model/collect/type_err');
  424. } elseif (empty($v['vod_name'])) {
  425. $des = lang('model/collect/name_err');
  426. } elseif (mac_array_filter($filter_arr,$v['vod_name']) !==false) {
  427. $des = lang('model/collect/name_in_filter_err');
  428. } elseif ($filter_year_list && !in_array(intval($v['vod_year']), $filter_year_list)) {
  429. // 采集时,过滤年份
  430. // https://github.com/magicblack/maccms10/issues/1057
  431. $color = 'orange';
  432. $des = 'year [' . intval($v['vod_year']) . '] not in: ' . join(',', $filter_year_list);
  433. } else {
  434. unset($v['vod_id']);
  435. foreach($v as $k2=>$v2){
  436. if(strpos($k2,'_content')===false && $k2!=='vod_plot_detail') {
  437. $v[$k2] = strip_tags($v2);
  438. }
  439. }
  440. $v['type_id_1'] = intval($type_list[$v['type_id']]['type_pid']);
  441. $v['vod_en'] = Pinyin::get($v['vod_name']);
  442. $v['vod_letter'] = strtoupper(substr($v['vod_en'],0,1));
  443. // 使用资源站的添加时间,更新时间保持当前
  444. // https://github.com/magicblack/maccms10/issues/780
  445. if (empty($v['vod_time_add']) || strlen($v['vod_time_add']) != 10) {
  446. $v['vod_time_add'] = time();
  447. }
  448. // 支持外部自定义修改时间
  449. // https://github.com/magicblack/maccms10/issues/862
  450. $v['vod_time'] = time();
  451. if (!empty($v['vod_time_update']) && strlen($v['vod_time_update']) == 10) {
  452. $v['vod_time'] = (int)$v['vod_time_update'];
  453. }
  454. $v['vod_status'] = intval($config['status']);
  455. $v['vod_lock'] = intval($v['vod_lock']);
  456. if(!empty($v['vod_status'])) {
  457. $v['vod_status'] = intval($v['vod_status']);
  458. }
  459. $v['vod_year'] = intval($v['vod_year']);
  460. $v['vod_level'] = intval($v['vod_level']);
  461. $v['vod_hits'] = intval($v['vod_hits']);
  462. $v['vod_hits_day'] = intval($v['vod_hits_day']);
  463. $v['vod_hits_week'] = intval($v['vod_hits_week']);
  464. $v['vod_hits_month'] = intval($v['vod_hits_month']);
  465. $v['vod_stint_play'] = intval($v['vod_stint_play']);
  466. $v['vod_stint_down'] = intval($v['vod_stint_down']);
  467. $v['vod_total'] = intval($v['vod_total']);
  468. $v['vod_serial'] = intval($v['vod_serial']);
  469. $v['vod_isend'] = intval($v['vod_isend']);
  470. $v['vod_up'] = intval($v['vod_up']);
  471. $v['vod_down'] = intval($v['vod_down']);
  472. $v['vod_score'] = floatval($v['vod_score']);
  473. $v['vod_score_all'] = intval($v['vod_score_all']);
  474. $v['vod_score_num'] = intval($v['vod_score_num']);
  475. $v['vod_class'] = mac_txt_merge($v['vod_class'],$v['type_name']);
  476. $v['vod_actor'] = mac_format_text($v['vod_actor'], true);
  477. $v['vod_director'] = mac_format_text($v['vod_director'], true);
  478. $v['vod_class'] = mac_format_text($v['vod_class'], true);
  479. $v['vod_tag'] = mac_format_text($v['vod_tag'], true);
  480. $v['vod_plot_name'] = (string)$v['vod_plot_name'];
  481. $v['vod_plot_detail'] = (string)$v['vod_plot_detail'];
  482. if(!empty($v['vod_plot_name'])){
  483. $v['vod_plot'] = 1;
  484. $v['vod_plot_name'] = trim($v['vod_plot_name'],'$$$');
  485. }
  486. if(!empty($v['vod_plot_detail'])){
  487. $v['vod_plot_detail'] = trim($v['vod_plot_detail'],'$$$');
  488. }
  489. if(empty($v['vod_isend']) && !empty($v['vod_serial'])){
  490. $v['vod_isend'] = 0;
  491. }
  492. if($config['hits_start']>0 && $config['hits_end']>0) {
  493. $v['vod_hits'] = rand($config['hits_start'], $config['hits_end']);
  494. $v['vod_hits_day'] = rand($config['hits_start'], $config['hits_end']);
  495. $v['vod_hits_week'] = rand($config['hits_start'], $config['hits_end']);
  496. $v['vod_hits_month'] = rand($config['hits_start'], $config['hits_end']);
  497. }
  498. if($config['updown_start']>0 && $config['updown_end']){
  499. $v['vod_up'] = rand($config['updown_start'], $config['updown_end']);
  500. $v['vod_down'] = rand($config['updown_start'], $config['updown_end']);
  501. }
  502. if($config['score']==1) {
  503. $v['vod_score_num'] = rand(1, 1000);
  504. $v['vod_score_all'] = $v['vod_score_num'] * rand(1, 10);
  505. $v['vod_score'] = round($v['vod_score_all'] / $v['vod_score_num'], 1);
  506. }
  507. if ($config['psename'] == 1) {
  508. $v['vod_name'] = mac_rep_pse_syn($pse_name, $v['vod_name']);
  509. }
  510. if ($config['psernd'] == 1) {
  511. $v['vod_content'] = mac_rep_pse_rnd($pse_rnd, $v['vod_content']);
  512. }
  513. if ($config['psesyn'] == 1) {
  514. $v['vod_content'] = mac_rep_pse_syn($pse_syn, $v['vod_content']);
  515. }
  516. if ($config['pseplayer'] == 1) {
  517. $v['vod_play_from'] = mac_rep_pse_syn($pse_player, $v['vod_play_from']);
  518. }
  519. if ($config['psearea'] == 1) {
  520. $v['vod_area'] = mac_rep_pse_syn($pse_area, $v['vod_area']);
  521. }
  522. if ($config['pselang'] == 1) {
  523. $v['vod_lang'] = mac_rep_pse_syn($pse_lang, $v['vod_lang']);
  524. }
  525. if(empty($v['vod_blurb'])){
  526. $v['vod_blurb'] = mac_substring( strip_tags($v['vod_content']) ,100);
  527. }
  528. $where = [];
  529. if (strpos($config['inrule'], 'a')!==false) {
  530. $where['vod_name'] = mac_filter_xss($v['vod_name']);
  531. }
  532. $blend=false;
  533. if (strpos($config['inrule'], 'b')!==false) {
  534. $where['type_id'] = $v['type_id'];
  535. }
  536. if (strpos($config['inrule'], 'c')!==false) {
  537. $where['vod_year'] = $v['vod_year'];
  538. }
  539. if (strpos($config['inrule'], 'd')!==false) {
  540. $where['vod_area'] = $v['vod_area'];
  541. }
  542. if (strpos($config['inrule'], 'e')!==false) {
  543. $where['vod_lang'] = $v['vod_lang'];
  544. }
  545. $search_actor_id_list = [];
  546. if (strpos($config['inrule'], 'f')!==false) {
  547. $where['vod_actor'] = ['like', mac_like_arr(mac_filter_xss($v['vod_actor'])), 'OR'];
  548. if ($vod_search_enabled) {
  549. $search_actor_id_list = $vod_search->getResultIdList(mac_filter_xss($v['vod_actor']), 'vod_actor', true);
  550. $search_actor_id_list = empty($search_actor_id_list) ? [0] : $search_actor_id_list;
  551. }
  552. }
  553. if (strpos($config['inrule'], 'g')!==false) {
  554. $where['vod_director'] = mac_filter_xss($v['vod_director']);
  555. }
  556. if (strpos($config['inrule'], 'h')!==false) {
  557. $where['vod_douban_id'] = intval($v['vod_douban_id']);
  558. }
  559. if ($config['tag'] == 1) {
  560. $v['vod_tag'] = mac_filter_xss(mac_get_tag($v['vod_name'], $v['vod_content']));
  561. }
  562. if(!empty($where['vod_actor']) && !empty($where['vod_director'])){
  563. $blend = true;
  564. $GLOBALS['blend'] = [
  565. 'vod_actor' => $where['vod_actor'],
  566. 'vod_director' => $where['vod_director'],
  567. ];
  568. // 结果太大时,筛选更耗时。仅在结果数量较小时,才加入
  569. $GLOBALS['blend']['vod_id'] = null;
  570. if ($vod_search_enabled && count($search_actor_id_list) <= $vs_max_id_count) {
  571. $GLOBALS['blend']['vod_id'] = ['IN', $search_actor_id_list];
  572. }
  573. unset($where['vod_actor'],$where['vod_director']);
  574. }
  575. if(empty($v['vod_play_url'])){
  576. $v['vod_play_url'] = '';
  577. }
  578. if(empty($v['vod_down_url'])){
  579. $v['vod_down_url'] = '';
  580. }
  581. //验证地址
  582. $cj_play_from_arr = explode('$$$',$v['vod_play_from'] );
  583. $cj_play_url_arr = explode('$$$',$v['vod_play_url']);
  584. $cj_play_server_arr = explode('$$$',$v['vod_play_server']);
  585. $cj_play_note_arr = explode('$$$',$v['vod_play_note']);
  586. $cj_down_from_arr = explode('$$$',$v['vod_down_from'] );
  587. $cj_down_url_arr = explode('$$$',$v['vod_down_url']);
  588. $cj_down_server_arr = explode('$$$',$v['vod_down_server']);
  589. $cj_down_note_arr = explode('$$$',$v['vod_down_note']);
  590. $collect_filter=[];
  591. foreach($cj_play_from_arr as $kk=>$vv){
  592. if(empty($vv)){
  593. unset($cj_play_from_arr[$kk]);
  594. unset($cj_play_url_arr[$kk]);
  595. unset($cj_play_server_arr[$kk]);
  596. unset($cj_play_note_arr[$kk]);
  597. continue;
  598. }
  599. if(empty($players[$vv])){
  600. unset($cj_play_from_arr[$kk]);
  601. unset($cj_play_url_arr[$kk]);
  602. unset($cj_play_server_arr[$kk]);
  603. unset($cj_play_note_arr[$kk]);
  604. continue;
  605. }
  606. $cj_play_url_arr[$kk] = rtrim($cj_play_url_arr[$kk],'#');
  607. $cj_play_server_arr[$kk] = $cj_play_server_arr[$kk];
  608. $cj_play_note_arr[$kk] = $cj_play_note_arr[$kk];
  609. if($param['filter'] > 0){
  610. if(strpos(','.$param['filter_from'].',',$vv)!==false) {
  611. $collect_filter['play'][$param['filter']]['cj_play_from_arr'][$kk] = $vv;
  612. $collect_filter['play'][$param['filter']]['cj_play_url_arr'][$kk] = $cj_play_url_arr[$kk];
  613. $collect_filter['play'][$param['filter']]['cj_play_server_arr'][$kk] = $cj_play_server_arr[$kk];
  614. $collect_filter['play'][$param['filter']]['cj_play_note_arr'][$kk] = $cj_play_note_arr[$kk];
  615. }
  616. }
  617. }
  618. foreach($cj_down_from_arr as $kk=>$vv){
  619. if(empty($vv)){
  620. unset($cj_down_from_arr[$kk]);
  621. unset($cj_down_url_arr[$kk]);
  622. unset($cj_down_server_arr[$kk]);
  623. unset($cj_down_note_arr[$kk]);
  624. continue;
  625. }
  626. if(empty($downers[$vv])){
  627. unset($cj_down_from_arr[$kk]);
  628. unset($cj_down_url_arr[$kk]);
  629. unset($cj_down_server_arr[$kk]);
  630. unset($cj_down_note_arr[$kk]);
  631. continue;
  632. }
  633. $cj_down_url_arr[$kk] = rtrim($cj_down_url_arr[$kk]);
  634. $cj_down_server_arr[$kk] = $cj_down_server_arr[$kk];
  635. $cj_down_note_arr[$kk] = $cj_down_note_arr[$kk];
  636. if($param['filter'] > 0){
  637. if(strpos(','.$param['filter_from'].',',$vv)!==false) {
  638. $collect_filter['down'][$param['filter']]['cj_down_from_arr'][$kk] = $vv;
  639. $collect_filter['down'][$param['filter']]['cj_down_url_arr'][$kk] = $cj_down_url_arr[$kk];
  640. $collect_filter['down'][$param['filter']]['cj_down_server_arr'][$kk] = $cj_down_server_arr[$kk];
  641. $collect_filter['down'][$param['filter']]['cj_down_note_arr'][$kk] = $cj_down_note_arr[$kk];
  642. }
  643. }
  644. }
  645. $v['vod_play_from'] = (string)join('$$$', (array)$cj_play_from_arr);
  646. $v['vod_play_url'] = (string)join('$$$', (array)$cj_play_url_arr);
  647. $v['vod_play_server'] = (string)join('$$$', (array)$cj_play_server_arr);
  648. $v['vod_play_note'] = (string)join('$$$', (array)$cj_play_note_arr);
  649. $v['vod_down_from'] = (string)join('$$$', (array)$cj_down_from_arr);
  650. $v['vod_down_url'] = (string)join('$$$', (array)$cj_down_url_arr);
  651. $v['vod_down_server'] = (string)join('$$$', (array)$cj_down_server_arr);
  652. $v['vod_down_note'] = (string)join('$$$', (array)$cj_down_note_arr);
  653. if($blend===false){
  654. $info = model('Vod')->where($where)->find();
  655. }
  656. else{
  657. $info = model('Vod')->where($where)
  658. ->where(function($query) {
  659. $query->where('vod_director',$GLOBALS['blend']['vod_director']);
  660. if (!empty($GLOBALS['blend']['vod_id'])) {
  661. $query->whereOr('vod_id', $GLOBALS['blend']['vod_id']);
  662. } else {
  663. $query->whereOr('vod_actor', $GLOBALS['blend']['vod_actor']);
  664. }
  665. })
  666. ->find();
  667. }
  668. if (!$info) {
  669. // 新增
  670. if ($param['opt'] == 2) {
  671. $des= lang('model/collect/not_check_add');
  672. } else {
  673. if ($param['filter'] == 1 || $param['filter'] == 2) {
  674. $v['vod_play_from'] = (string)join('$$$', (array)$collect_filter['play'][$param['filter']]['cj_play_from_arr']);
  675. $v['vod_play_url'] = (string)join('$$$', (array)$collect_filter['play'][$param['filter']]['cj_play_url_arr']);
  676. $v['vod_play_server'] = (string)join('$$$', (array)$collect_filter['play'][$param['filter']]['cj_play_server_arr']);
  677. $v['vod_play_note'] = (string)join('$$$', (array)$collect_filter['play'][$param['filter']]['cj_play_note_arr']);
  678. $v['vod_down_from'] = (string)join('$$$', (array)$collect_filter['down'][$param['filter']]['cj_down_from_arr']);
  679. $v['vod_down_url'] = (string)join('$$$', (array)$collect_filter['down'][$param['filter']]['cj_down_url_arr']);
  680. $v['vod_down_server'] = (string)join('$$$', (array)$collect_filter['down'][$param['filter']]['cj_down_server_arr']);
  681. $v['vod_down_note'] = (string)join('$$$', (array)$collect_filter['down'][$param['filter']]['cj_down_note_arr']);
  682. }
  683. $tmp = $this->syncImages($config_sync_pic, $v['vod_pic'], 'vod');
  684. $v['vod_pic'] = (string)$tmp['pic'];
  685. $msg = $tmp['msg'];
  686. $v = VodValidate::formatDataBeforeDb($v);
  687. $vod_id = model('Vod')->insert($v, false, true);
  688. if ($vod_id > 0) {
  689. $vod_search_enabled && $vod_search->checkAndUpdateTopResults(['vod_id' => $vod_id] + $v, true);
  690. $color = 'green';
  691. $des = lang('model/collect/add_ok');
  692. } else {
  693. $color = 'red';
  694. $des = 'vod insert failed';
  695. }
  696. }
  697. } else {
  698. // 更新
  699. if(empty($config['uprule'])){
  700. $des = lang('model/collect/uprule_empty');
  701. }
  702. elseif ($info['vod_lock'] == 1) {
  703. $des = lang('model/collect/data_lock');
  704. }
  705. elseif($param['opt'] == 1){
  706. $des = lang('model/collect/not_check_update');
  707. }
  708. else {
  709. unset($v['vod_time_add']);
  710. $update = [];
  711. $ec=false;
  712. if($param['filter'] ==1 || $param['filter']==3){
  713. $cj_play_from_arr = $collect_filter['play'][$param['filter']]['cj_play_from_arr'];
  714. $cj_play_url_arr = $collect_filter['play'][$param['filter']]['cj_play_url_arr'];
  715. $cj_play_server_arr = $collect_filter['play'][$param['filter']]['cj_play_server_arr'];
  716. $cj_play_note_arr = $collect_filter['play'][$param['filter']]['cj_play_note_arr'];
  717. $cj_down_from_arr = $collect_filter['down'][$param['filter']]['cj_down_from_arr'];
  718. $cj_down_url_arr = $collect_filter['down'][$param['filter']]['cj_down_url_arr'];
  719. $cj_down_server_arr = $collect_filter['down'][$param['filter']]['cj_down_server_arr'];
  720. $cj_down_note_arr = $collect_filter['down'][$param['filter']]['cj_down_note_arr'];
  721. }
  722. if (strpos(',' . $config['uprule'], 'a')!==false && !empty($v['vod_play_from'])) {
  723. $old_play_from = $info['vod_play_from'];
  724. $old_play_url = $info['vod_play_url'];
  725. $old_play_server = $info['vod_play_server'];
  726. $old_play_note = $info['vod_play_note'];
  727. foreach ($cj_play_from_arr as $k2 => $v2) {
  728. $cj_play_from = $v2;
  729. $cj_play_url = $cj_play_url_arr[$k2];
  730. $cj_play_server = $cj_play_server_arr[$k2];
  731. $cj_play_note = $cj_play_note_arr[$k2];
  732. if ($cj_play_url == $info['vod_play_url']) {
  733. $des .= lang('model/collect/playurl_same');
  734. } elseif (empty($cj_play_from)) {
  735. $des .= lang('model/collect/playfrom_empty');
  736. } elseif (strpos('$$$'.$info['vod_play_from'].'$$$', '$$$'.$cj_play_from.'$$$') === false) {
  737. // 新类型播放组,加入
  738. $color = 'green';
  739. $des .= lang('model/collect/playgroup_add_ok',[$cj_play_from]);
  740. if(!empty($old_play_from)){
  741. $old_play_url .="$$$";
  742. $old_play_from .= "$$$" ;
  743. $old_play_server .= "$$$" ;
  744. $old_play_note .= "$$$" ;
  745. }
  746. $old_play_url .= "" . $cj_play_url;
  747. $old_play_from .= "" . $cj_play_from;
  748. $old_play_server .= "" . $cj_play_server;
  749. $old_play_note .= "" . $cj_play_note;
  750. $ec=true;
  751. } elseif (!empty($cj_play_url)) {
  752. // 同类型播放组
  753. $arr1 = explode("$$$", $old_play_url);
  754. $arr2 = explode("$$$", $old_play_from);
  755. $play_key = array_search($cj_play_from, $arr2);
  756. if ($arr1[$play_key] == $cj_play_url) {
  757. $des .= lang('model/collect/playgroup_same',[$cj_play_from]);;
  758. } else {
  759. $color = 'green';
  760. $des .= lang('model/collect/playgroup_update_ok',[$cj_play_from]);
  761. // 根据「地址二更规则」配置,替换或合并
  762. if ($config['urlrole'] == 1) {
  763. $tmp1 = explode('#',$arr1[$play_key]);
  764. $tmp2 = explode('#',$cj_play_url);
  765. $tmp1 = array_merge($tmp1,$tmp2);
  766. $tmp1 = array_unique($tmp1);
  767. $cj_play_url = join('#', (array)$tmp1);
  768. unset($tmp1,$tmp2);
  769. }
  770. $arr1[$play_key] = $cj_play_url;
  771. $ec=true;
  772. }
  773. $old_play_url = join('$$$', (array)$arr1);
  774. }
  775. }
  776. if($ec) {
  777. $update['vod_play_from'] = $old_play_from;
  778. $update['vod_play_url'] = $old_play_url;
  779. $update['vod_play_server'] = $old_play_server;
  780. $update['vod_play_note'] = $old_play_note;
  781. }
  782. }
  783. $ec=false;
  784. if (strpos(',' . $config['uprule'], 'b')!==false && !empty($v['vod_down_from'])) {
  785. $old_down_from = $info['vod_down_from'];
  786. $old_down_url = $info['vod_down_url'];
  787. $old_down_server = $info['vod_down_server'];
  788. $old_down_note = $info['vod_down_note'];
  789. foreach ($cj_down_from_arr as $k2 => $v2) {
  790. $cj_down_from = $v2;
  791. $cj_down_url = $cj_down_url_arr[$k2];
  792. $cj_down_server = $cj_down_server_arr[$k2];
  793. $cj_down_note = $cj_down_note_arr[$k2];
  794. if ($cj_down_url == $info['vod_down_url']) {
  795. $des .= lang('model/collect/downurl_same');
  796. } elseif (empty($cj_down_from)) {
  797. $des .= lang('model/collect/downfrom_empty');
  798. } elseif (strpos('$$$'.$info['vod_down_from'].'$$$', '$$$'.$cj_down_from.'$$$')===false) {
  799. $color = 'green';
  800. $des .= lang('model/collect/downgroup_add_ok',[$cj_down_from]);
  801. if(!empty($old_down_from)){
  802. $old_down_url .="$$$";
  803. $old_down_from .= "$$$" ;
  804. $old_down_server .= "$$$" ;
  805. $old_down_note .= "$$$" ;
  806. }
  807. $old_down_url .= "" .$cj_down_url;
  808. $old_down_from .= "" .$cj_down_from;
  809. $old_down_server .= "" .$cj_down_server;
  810. $old_down_note .= "" .$cj_down_note;
  811. $ec=true;
  812. } elseif (!empty($cj_down_url)) {
  813. $arr1 = explode("$$$", $old_down_url);
  814. $arr2 = explode("$$$", $old_down_from);
  815. $down_key = array_search($cj_down_from, $arr2);
  816. if ($arr1[$down_key] == $cj_down_url) {
  817. $des .= lang('model/collect/downgroup_same',[$cj_down_from]);
  818. } else {
  819. $color = 'green';
  820. $des .= lang('model/collect/downgroup_update_ok',[$cj_down_from]);
  821. // 根据「地址二更规则」配置,替换或合并
  822. // “采集参数配置--地址二更规则”配置需要对下载地址生效
  823. // https://github.com/magicblack/maccms10/issues/893
  824. if ($config['urlrole'] == 1) {
  825. $tmp1 = explode('#',$arr1[$down_key]);
  826. $tmp2 = explode('#',$cj_down_url);
  827. $tmp1 = array_merge($tmp1,$tmp2);
  828. $tmp1 = array_unique($tmp1);
  829. $cj_down_url = join('#', (array)$tmp1);
  830. unset($tmp1,$tmp2);
  831. }
  832. $arr1[$down_key] = $cj_down_url;
  833. $ec=true;
  834. }
  835. $old_down_url = join('$$$', (array)$arr1);
  836. }
  837. }
  838. if($ec) {
  839. $update['vod_down_from'] = $old_down_from;
  840. $update['vod_down_url'] = $old_down_url;
  841. $update['vod_down_server'] = $old_down_server;
  842. $update['vod_down_note'] = $old_down_note;
  843. }
  844. }
  845. if (strpos(',' . $config['uprule'], 'c')!==false && !empty($v['vod_serial']) && $v['vod_serial']!=$info['vod_serial']) {
  846. $update['vod_serial'] = $v['vod_serial'];
  847. // 连载数如果均为整数,则取较大值
  848. // https://github.com/magicblack/maccms10/issues/878
  849. if (floor($v['vod_serial']) == $v['vod_serial'] && floor($info['vod_serial']) == $info['vod_serial']) {
  850. $update['vod_serial'] = max($v['vod_serial'], $info['vod_serial']);
  851. }
  852. }
  853. if (strpos(',' . $config['uprule'], 'd')!==false && !empty($v['vod_remarks']) && $v['vod_remarks']!=$info['vod_remarks']) {
  854. $update['vod_remarks'] = $v['vod_remarks'];
  855. }
  856. if (strpos(',' . $config['uprule'], 'e')!==false && !empty($v['vod_director']) && $v['vod_director']!=$info['vod_director']) {
  857. $update['vod_director'] = $v['vod_director'];
  858. }
  859. if (strpos(',' . $config['uprule'], 'f')!==false && !empty($v['vod_actor']) && $v['vod_actor']!=$info['vod_actor']) {
  860. $update['vod_actor'] = $v['vod_actor'];
  861. }
  862. if (strpos(',' . $config['uprule'], 'g')!==false && !empty($v['vod_year']) && $v['vod_year']!=$info['vod_year']) {
  863. $update['vod_year'] = $v['vod_year'];
  864. }
  865. if (strpos(',' . $config['uprule'], 'h')!==false && !empty($v['vod_area']) && $v['vod_area']!=$info['vod_area']) {
  866. $update['vod_area'] = $v['vod_area'];
  867. }
  868. if (strpos(',' . $config['uprule'], 'i')!==false && !empty($v['vod_lang']) && $v['vod_lang']!=$info['vod_lang']) {
  869. $update['vod_lang'] = $v['vod_lang'];
  870. }
  871. if (strpos(',' . $config['uprule'], 'j')!==false && (substr($info["vod_pic"], 0, 4) == "http" || empty($info['vod_pic']) ) && $v['vod_pic']!=$info['vod_pic'] ) {
  872. $tmp = $this->syncImages($config_sync_pic, $v['vod_pic'],'vod');
  873. $update['vod_pic'] = (string)$tmp['pic'];
  874. $msg =$tmp['msg'];
  875. }
  876. if (strpos(',' . $config['uprule'], 'k')!==false && !empty($v['vod_content']) && $v['vod_content']!=$info['vod_content']) {
  877. $update['vod_content'] = $v['vod_content'];
  878. }
  879. if (strpos(',' . $config['uprule'], 'l')!==false && !empty($v['vod_tag']) && $v['vod_tag']!=$info['vod_tag']) {
  880. $update['vod_tag'] = $v['vod_tag'];
  881. }
  882. if (strpos(',' . $config['uprule'], 'm')!==false && !empty($v['vod_sub']) && $v['vod_sub']!=$info['vod_sub']) {
  883. $update['vod_sub'] = $v['vod_sub'];
  884. }
  885. if (strpos(',' . $config['uprule'], 'n')!==false && !empty($v['vod_class']) && $v['vod_class']!=$info['vod_class']) {
  886. $update['vod_class'] = mac_txt_merge($info['vod_class'], $v['vod_class']);
  887. }
  888. if (strpos(',' . $config['uprule'], 'o')!==false && !empty($v['vod_writer']) && $v['vod_writer']!=$info['vod_writer']) {
  889. $update['vod_writer'] = $v['vod_writer'];
  890. }
  891. if (strpos(',' . $config['uprule'], 'p')!==false && !empty($v['vod_version']) && $v['vod_version']!=$info['vod_version']) {
  892. $update['vod_version'] = $v['vod_version'];
  893. }
  894. if (strpos(',' . $config['uprule'], 'q')!==false && !empty($v['vod_state']) && $v['vod_state']!=$info['vod_state']) {
  895. $update['vod_state'] = $v['vod_state'];
  896. }
  897. if (strpos(',' . $config['uprule'], 'r')!==false && !empty($v['vod_blurb']) && $v['vod_blurb']!=$info['vod_blurb']) {
  898. $update['vod_blurb'] = $v['vod_blurb'];
  899. }
  900. if (strpos(',' . $config['uprule'], 's')!==false && !empty($v['vod_tv']) && $v['vod_tv']!=$info['vod_tv']) {
  901. $update['vod_tv'] = $v['vod_tv'];
  902. }
  903. if (strpos(',' . $config['uprule'], 't')!==false && !empty($v['vod_weekday']) && $v['vod_weekday']!=$info['vod_weekday']) {
  904. $update['vod_weekday'] = $v['vod_weekday'];
  905. }
  906. if (strpos(',' . $config['uprule'], 'u')!==false && !empty($v['vod_total']) && $v['vod_total']!=$info['vod_total']) {
  907. $update['vod_total'] = $v['vod_total'];
  908. }
  909. if (strpos(',' . $config['uprule'], 'v')!==false && (isset($v['vod_isend']) && $v['vod_isend'] !== '') && $v['vod_isend']!=$info['vod_isend']) {
  910. $update['vod_isend'] = $v['vod_isend'];
  911. }
  912. if (strpos(',' . $config['uprule'], 'w')!==false && !empty($v['vod_plot_name']) && $v['vod_plot_name']!=$info['vod_plot_name']) {
  913. $update['vod_plot'] = 1;
  914. $update['vod_plot_name'] = $v['vod_plot_name'];
  915. $update['vod_plot_detail'] = $v['vod_plot_detail'];
  916. }
  917. if(count($update)>0){
  918. $update['vod_time'] = time();
  919. $where = [];
  920. $where['vod_id'] = $info['vod_id'];
  921. $update = VodValidate::formatDataBeforeDb($update);
  922. $res = model('Vod')->where($where)->update($update);
  923. $color = 'green';
  924. if ($res === false) {
  925. }
  926. }
  927. else{
  928. $des = lang('model/collect/not_need_update');
  929. }
  930. }
  931. }
  932. if(Cache::has('vod_repeat_table_created_time')){
  933. Cache::rm('vod_repeat_table_created_time');
  934. }
  935. }
  936. if($show==1) {
  937. mac_echo( ($k + 1) .'、'. $v['vod_name'] . " <font color='{$color}'>" .$des .'</font>'. $msg.'' );
  938. }
  939. else{
  940. return ['code'=>($color=='red' ? 1001 : 1),'msg'=>$des ];
  941. }
  942. }
  943. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_vod';
  944. if(ENTRANCE=='api'){
  945. Cache::rm($key);
  946. if ($data['page']['page'] < $data['page']['pagecount']) {
  947. $param['page'] = intval($data['page']['page']) + 1;
  948. $res = $this->vod($param);
  949. if($res['code']>1){
  950. return $this->error($res['msg']);
  951. }
  952. $this->vod_data($param,$res );
  953. }
  954. mac_echo(lang('model/collect/is_over'));
  955. die;
  956. }
  957. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  958. $GLOBALS['config']['app']['collect_timespan'] = 3;
  959. }
  960. if($show==1) {
  961. if ($param['ac'] == 'cjsel') {
  962. Cache::rm($key);
  963. mac_echo(lang('model/collect/is_over'));
  964. unset($param['ids']);
  965. $param['ac'] = 'list';
  966. $url = url('api') . '?' . http_build_query($param);
  967. $ref = $_SERVER["HTTP_REFERER"];
  968. if(!empty($ref)){
  969. $url = $ref;
  970. }
  971. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  972. } else {
  973. if ($data['page']['page'] >= $data['page']['pagecount']) {
  974. Cache::rm($key);
  975. mac_echo(lang('model/collect/is_over'));
  976. unset($param['page'],$param['ids']);
  977. $param['ac'] = 'list';
  978. $url = url('api') . '?' . http_build_query($param);
  979. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  980. } else {
  981. $param['page'] = intval($data['page']['page']) + 1;
  982. $url = url('api') . '?' . http_build_query($param);
  983. mac_jump($url, $GLOBALS['config']['app']['collect_timespan'] );
  984. }
  985. }
  986. }
  987. }
  988. public function art_json($param)
  989. {
  990. $url_param = [];
  991. $url_param['ac'] = $param['ac'];
  992. $url_param['t'] = $param['t'];
  993. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  994. $url_param['h'] = $param['h'];
  995. $url_param['ids'] = $param['ids'];
  996. $url_param['wd'] = $param['wd'];
  997. if($param['ac']!='list'){
  998. $url_param['ac'] = 'detail';
  999. }
  1000. $url = $param['cjurl'];
  1001. if(strpos($url,'?')===false){
  1002. $url .='?';
  1003. }
  1004. else{
  1005. $url .='&';
  1006. }
  1007. $url .= http_build_query($url_param). base64_decode($param['param']);
  1008. $result = $this->checkCjUrl($url);
  1009. if ($result['code'] > 1) {
  1010. return $result;
  1011. }
  1012. $html = mac_curl_get($url);
  1013. if(empty($html)){
  1014. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  1015. }
  1016. $html = mac_filter_tags($html);
  1017. $json = json_decode($html,true);
  1018. if(!$json){
  1019. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ': ' . mb_substr($html, 0, 15)];
  1020. }
  1021. $array_page = [];
  1022. $array_page['page'] = $json['page'];
  1023. $array_page['pagecount'] = $json['pagecount'];
  1024. $array_page['pagesize'] = $json['limit'];
  1025. $array_page['recordcount'] = $json['total'];
  1026. $array_page['url'] = $url;
  1027. $type_list = model('Type')->getCache('type_list');
  1028. $bind_list = config('bind');
  1029. $key = 0;
  1030. $array_data = [];
  1031. foreach($json['list'] as $key=>$v){
  1032. $array_data[$key] = $v;
  1033. $bind_key = $param['cjflag'] .'_'.$v['type_id'];
  1034. if($bind_list[$bind_key] >0){
  1035. $array_data[$key]['type_id'] = $bind_list[$bind_key];
  1036. }
  1037. else{
  1038. $array_data[$key]['type_id'] = 0;
  1039. }
  1040. }
  1041. $array_type = [];
  1042. $key=0;
  1043. //分类列表
  1044. if($param['ac'] == 'list'){
  1045. foreach($json['class'] as $k=>$v){
  1046. $array_type[$key]['type_id'] = $v['type_id'];
  1047. $array_type[$key]['type_name'] = $v['type_name'];
  1048. $key++;
  1049. }
  1050. }
  1051. $res = ['code'=>1, 'msg'=>'ok', 'page'=>$array_page, 'type'=>$array_type, 'data'=>$array_data ];
  1052. return $res;
  1053. }
  1054. public function art_data($param,$data,$show=1)
  1055. {
  1056. if($show==1) {
  1057. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1',[$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  1058. }
  1059. $config = config('maccms.collect');
  1060. $config = $config['art'];
  1061. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  1062. $type_list = model('Type')->getCache('type_list');
  1063. $filter_arr = explode(',',$config['filter']); $filter_arr = array_filter($filter_arr);
  1064. $pse_rnd = explode('#',$config['words']); $pse_rnd = array_filter($pse_rnd);
  1065. $pse_syn = mac_txt_explain($config['thesaurus'], true);
  1066. foreach($data['data'] as $k=>$v){
  1067. $color='red';
  1068. $des='';
  1069. $msg='';
  1070. $tmp='';
  1071. if($v['type_id'] ==0){
  1072. $des = lang('model/collect/type_err');
  1073. }
  1074. elseif(empty($v['art_name'])) {
  1075. $des = lang('model/collect/name_err');
  1076. }
  1077. elseif( mac_array_filter($filter_arr,$v['art_name']) !==false) {
  1078. $des = lang('model/collect/name_in_filter_err');
  1079. }
  1080. else {
  1081. unset($v['art_id']);
  1082. foreach($v as $k2=>$v2){
  1083. if(strpos($k2,'_content')===false) {
  1084. $v[$k2] = strip_tags($v2);
  1085. }
  1086. }
  1087. $v['art_name'] = trim($v['art_name']);
  1088. $v['type_id_1'] = intval($type_list[$v['type_id']]['type_pid']);
  1089. $v['art_en'] = Pinyin::get($v['art_name']);
  1090. $v['art_letter'] = strtoupper(substr($v['art_en'],0,1));
  1091. $v['art_time_add'] = time();
  1092. $v['art_time'] = time();
  1093. $v['art_status'] = intval($config['status']);
  1094. $v['art_lock'] = intval($v['art_lock']);
  1095. if(!empty($v['art_status'])) {
  1096. $v['art_status'] = intval($v['art_status']);
  1097. }
  1098. $v['art_level'] = intval($v['art_level']);
  1099. $v['art_hits'] = intval($v['art_hits']);
  1100. $v['art_hits_day'] = intval($v['art_hits_day']);
  1101. $v['art_hits_week'] = intval($v['art_hits_week']);
  1102. $v['art_hits_month'] = intval($v['art_hits_month']);
  1103. $v['art_stint'] = intval($v['art_stint']);
  1104. $v['art_up'] = intval($v['art_up']);
  1105. $v['art_down'] = intval($v['art_down']);
  1106. $v['art_score'] = floatval($v['art_score']);
  1107. $v['art_score_all'] = intval($v['art_score_all']);
  1108. $v['art_score_num'] = intval($v['art_score_num']);
  1109. if($config['hits_start']>0 && $config['hits_end']>0) {
  1110. $v['art_hits'] = rand($config['hits_start'], $config['hits_end']);
  1111. $v['art_hits_day'] = rand($config['hits_start'], $config['hits_end']);
  1112. $v['art_hits_week'] = rand($config['hits_start'], $config['hits_end']);
  1113. $v['art_hits_month'] = rand($config['hits_start'], $config['hits_end']);
  1114. }
  1115. if($config['updown_start']>0 && $config['updown_end']){
  1116. $v['art_up'] = rand($config['updown_start'], $config['updown_end']);
  1117. $v['art_down'] = rand($config['updown_start'], $config['updown_end']);
  1118. }
  1119. if($config['score']==1) {
  1120. $v['art_score_num'] = rand(1, 1000);
  1121. $v['art_score_all'] = $v['art_score_num'] * rand(1, 10);
  1122. $v['art_score'] = round($v['art_score_all'] / $v['art_score_num'], 1);
  1123. }
  1124. if ($config['psernd'] == 1) {
  1125. $v['art_content'] = mac_rep_pse_rnd($pse_rnd, $v['art_content']);
  1126. }
  1127. if ($config['psesyn'] == 1) {
  1128. $v['art_content'] = mac_rep_pse_syn($pse_syn, $v['art_content']);
  1129. }
  1130. if(empty($v['art_blurb'])){
  1131. $v['art_blurb'] = mac_substring( strip_tags( str_replace('$$$','',$v['art_content']) ) ,100);
  1132. }
  1133. $where = [];
  1134. $where['art_name'] = $v['art_name'];
  1135. if (strpos($config['inrule'], 'b')!==false) {
  1136. $where['type_id'] = $v['type_id'];
  1137. }
  1138. //验证地址
  1139. $cj_title_arr = explode('$$$',$v['art_title'] );
  1140. $cj_note_arr = explode('$$$',$v['art_note']);
  1141. $cj_content_arr = explode('$$$',$v['art_content']);
  1142. $tmp_title_arr=[];
  1143. $tmp_note_arr=[];
  1144. $tmp_content_arr=[];
  1145. foreach($cj_content_arr as $kk=>$vv){
  1146. $tmp_content_arr[] = $vv;
  1147. $tmp_title_arr[] = $cj_title_arr[$kk];
  1148. $tmp_note_arr[] = $cj_note_arr[$kk];
  1149. }
  1150. $v['art_title'] = join('$$$', (array)$tmp_title_arr);
  1151. $v['art_note'] = join('$$$', (array)$tmp_note_arr);
  1152. $v['art_content'] = join('$$$', (array)$tmp_content_arr);
  1153. $info = model('Art')->where($where)->find();
  1154. if (!$info) {
  1155. $tmp = $this->syncImages($config_sync_pic, $v['art_pic'],'art');
  1156. $v['art_pic'] = (string)$tmp['pic'];
  1157. $msg = $tmp['msg'];
  1158. $res = model('Art')->insert($v);
  1159. if($res===false){
  1160. }
  1161. $color ='green';
  1162. $des= lang('model/collect/add_ok');
  1163. }
  1164. else {
  1165. if(empty($config['uprule'])){
  1166. $des = lang('model/collect/uprule_empty');
  1167. }
  1168. elseif($info['art_lock'] == 1) {
  1169. $des = lang('model/collect/data_lock');
  1170. }
  1171. else {
  1172. unset($v['art_time_add']);
  1173. $old_art_title = $info['art_title'];
  1174. $old_art_note = $info['art_note'];
  1175. $old_art_content = $info['art_content'];
  1176. $cj_art_title = $v['art_title'];
  1177. $cj_art_note = $v['art_note'];
  1178. $cj_art_content = $v['art_content'];
  1179. $rc=true;
  1180. if($rc){
  1181. $update=[];
  1182. if(strpos(','.$config['uprule'],'a')!==false && !empty($v['art_content']) && $v['art_content']!=$info['art_content']){
  1183. $update['art_content'] = $v['art_content'];
  1184. }
  1185. if(strpos(','.$config['uprule'],'b')!==false && !empty($v['art_author']) && $v['art_author']!=$info['art_author']){
  1186. $update['art_author'] = $v['art_author'];
  1187. }
  1188. if(strpos(','.$config['uprule'],'c')!==false && !empty($v['art_from']) && $v['art_from']!=$info['art_from']){
  1189. $update['art_from'] = $v['art_from'];
  1190. }
  1191. if(strpos(','.$config['uprule'],'d')!==false && (substr($info["art_pic"], 0, 4) == "http" || empty($info['art_pic'])) && $v['art_pic']!=$info['art_pic'] ){
  1192. $tmp = $this->syncImages($config_sync_pic, $v['art_pic'],'art');
  1193. $update['art_pic'] = (string)$tmp['pic'];
  1194. $msg =$tmp['msg'];
  1195. }
  1196. if(strpos(','.$config['uprule'],'e')!==false && !empty($v['art_tag']) && $v['art_tag']!=$info['art_tag']){
  1197. $update['art_tag'] = $v['art_tag'];
  1198. }
  1199. if(strpos(','.$config['uprule'],'f')!==false && !empty($v['art_blurb']) && $v['art_blurb']!=$info['art_blurb']){
  1200. $update['art_blurb'] = $v['art_blurb'];
  1201. }
  1202. if(count($update)>0){
  1203. $update['art_time'] = time();
  1204. $where = [];
  1205. $where['art_id'] = $info['art_id'];
  1206. $res = model('Art')->where($where)->update($update);
  1207. $color = 'green';
  1208. if($res===false){
  1209. }
  1210. }
  1211. else{
  1212. $des = lang('model/collect/not_need_update');
  1213. }
  1214. }
  1215. }
  1216. }
  1217. }
  1218. if($show==1) {
  1219. mac_echo( ($k + 1) . $v['art_name'] . "<font color=$color>" .$des .'</font>'. $msg . '');
  1220. }
  1221. else{
  1222. return ['code'=>($color=='red' ? 1001 : 1),'msg'=> $v['art_name'] .' '.$des ];
  1223. }
  1224. }
  1225. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_art';
  1226. if(ENTRANCE=='api'){
  1227. Cache::rm($key);
  1228. if ($data['page']['page'] < $data['page']['pagecount']) {
  1229. $param['page'] = intval($data['page']['page']) + 1;
  1230. $res = $this->art($param);
  1231. if($res['code']>1){
  1232. return $this->error($res['msg']);
  1233. }
  1234. $this->art_data($param,$res );
  1235. }
  1236. mac_echo(lang('model/collect/is_over'));
  1237. die;
  1238. }
  1239. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  1240. $GLOBALS['config']['app']['collect_timespan'] = 3;
  1241. }
  1242. if($show==1) {
  1243. if ($param['ac'] == 'cjsel') {
  1244. Cache::rm($key);
  1245. mac_echo(lang('model/collect/is_over'));
  1246. unset($param['ids']);
  1247. $param['ac'] = 'list';
  1248. $url = url('api') . '?' . http_build_query($param);
  1249. $ref = $_SERVER["HTTP_REFERER"];
  1250. if(!empty($ref)){
  1251. $url = $ref;
  1252. }
  1253. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1254. } else {
  1255. if ($data['page']['page'] >= $data['page']['pagecount']) {
  1256. Cache::rm($key);
  1257. mac_echo(lang('model/collect/is_over'));
  1258. unset($param['page']);
  1259. $param['ac'] = 'list';
  1260. $url = url('api') . '?' . http_build_query($param);
  1261. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1262. } else {
  1263. $param['page'] = intval($data['page']['page']) + 1;
  1264. $url = url('api') . '?' . http_build_query($param);
  1265. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1266. }
  1267. }
  1268. }
  1269. }
  1270. public function actor_json($param)
  1271. {
  1272. $url_param = [];
  1273. $url_param['ac'] = $param['ac'];
  1274. $url_param['t'] = $param['t'];
  1275. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  1276. $url_param['h'] = $param['h'];
  1277. $url_param['ids'] = $param['ids'];
  1278. $url_param['wd'] = $param['wd'];
  1279. if($param['ac']!='list'){
  1280. $url_param['ac'] = 'detail';
  1281. }
  1282. $url = $param['cjurl'];
  1283. if(strpos($url,'?')===false){
  1284. $url .='?';
  1285. }
  1286. else{
  1287. $url .='&';
  1288. }
  1289. $url .= http_build_query($url_param).base64_decode($param['param']);
  1290. $result = $this->checkCjUrl($url);
  1291. if ($result['code'] > 1) {
  1292. return $result;
  1293. }
  1294. $html = mac_curl_get($url);
  1295. if(empty($html)){
  1296. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  1297. }
  1298. $html = mac_filter_tags($html);
  1299. $json = json_decode($html,true);
  1300. if(!$json){
  1301. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ': ' . mb_substr($html, 0, 15)];
  1302. }
  1303. $array_page = [];
  1304. $array_page['page'] = $json['page'];
  1305. $array_page['pagecount'] = $json['pagecount'];
  1306. $array_page['pagesize'] = $json['limit'];
  1307. $array_page['recordcount'] = $json['total'];
  1308. $array_page['url'] = $url;
  1309. $type_list = model('Type')->getCache('type_list');
  1310. $bind_list = config('bind');
  1311. $key = 0;
  1312. $array_data = [];
  1313. foreach($json['list'] as $key=>$v){
  1314. $array_data[$key] = $v;
  1315. $bind_key = $param['cjflag'] .'_'.$v['type_id'];
  1316. if($bind_list[$bind_key] >0){
  1317. $array_data[$key]['type_id'] = $bind_list[$bind_key];
  1318. }
  1319. else{
  1320. $array_data[$key]['type_id'] = 0;
  1321. }
  1322. }
  1323. $array_type = [];
  1324. $key=0;
  1325. //分类列表
  1326. if($param['ac'] == 'list'){
  1327. foreach($json['class'] as $k=>$v){
  1328. $array_type[$key]['type_id'] = $v['type_id'];
  1329. $array_type[$key]['type_name'] = $v['type_name'];
  1330. $key++;
  1331. }
  1332. }
  1333. $res = ['code'=>1, 'msg'=>'ok', 'page'=>$array_page, 'type'=>$array_type, 'data'=>$array_data ];
  1334. return $res;
  1335. }
  1336. public function actor_data($param,$data,$show=1)
  1337. {
  1338. if($show==1) {
  1339. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1',[$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  1340. }
  1341. $config = config('maccms.collect');
  1342. $config = $config['actor'];
  1343. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  1344. $type_list = model('Type')->getCache('type_list');
  1345. $filter_arr = explode(',',$config['filter']); $filter_arr = array_filter($filter_arr);
  1346. $pse_rnd = explode('#',$config['words']); $pse_rnd = array_filter($pse_rnd);
  1347. $pse_syn = mac_txt_explain($config['thesaurus'], true);
  1348. foreach($data['data'] as $k=>$v){
  1349. $color='red';
  1350. $des='';
  1351. $msg='';
  1352. $tmp='';
  1353. if($v['type_id'] ==0){
  1354. $des = lang('model/collect/type_err');
  1355. }
  1356. elseif(empty($v['actor_name']) || empty($v['actor_sex'])) {
  1357. $des = lang('odel/collect/actor_data_require');
  1358. }
  1359. elseif( mac_array_filter($filter_arr,$v['actor_name'])!==false) {
  1360. $des = lang('model/collect/name_in_filter_err');
  1361. }
  1362. else {
  1363. unset($v['actor_id']);
  1364. foreach($v as $k2=>$v2){
  1365. if(strpos($k2,'_content')===false) {
  1366. $v[$k2] = strip_tags($v2);
  1367. }
  1368. }
  1369. $v['actor_name'] = trim($v['actor_name']);
  1370. $v['type_id_1'] = intval($type_list[$v['type_id']]['type_pid']);
  1371. $v['actor_en'] = Pinyin::get($v['actor_name']);
  1372. $v['actor_letter'] = strtoupper(substr($v['actor_en'],0,1));
  1373. $v['actor_time_add'] = time();
  1374. $v['actor_time'] = time();
  1375. $v['actor_status'] = intval($config['status']);
  1376. $v['actor_lock'] = intval($v['actor_lock']);
  1377. if(!empty($v['actor_status'])) {
  1378. $v['actor_status'] = intval($v['actor_status']);
  1379. }
  1380. $v['actor_level'] = intval($v['actor_level']);
  1381. $v['actor_hits'] = intval($v['actor_hits']);
  1382. $v['actor_hits_day'] = intval($v['actor_hits_day']);
  1383. $v['actor_hits_week'] = intval($v['actor_hits_week']);
  1384. $v['actor_hits_month'] = intval($v['actor_hits_month']);
  1385. $v['actor_up'] = intval($v['actor_up']);
  1386. $v['actor_down'] = intval($v['actor_down']);
  1387. $v['actor_score'] = floatval($v['actor_score']);
  1388. $v['actor_score_all'] = intval($v['actor_score_all']);
  1389. $v['actor_score_num'] = intval($v['actor_score_num']);
  1390. if($config['hits_start']>0 && $config['hits_end']>0) {
  1391. $v['actor_hits'] = rand($config['hits_start'], $config['hits_end']);
  1392. $v['actor_hits_day'] = rand($config['hits_start'], $config['hits_end']);
  1393. $v['actor_hits_week'] = rand($config['hits_start'], $config['hits_end']);
  1394. $v['actor_hits_month'] = rand($config['hits_start'], $config['hits_end']);
  1395. }
  1396. if($config['updown_start']>0 && $config['updown_end']){
  1397. $v['actor_up'] = rand($config['updown_start'], $config['updown_end']);
  1398. $v['actor_down'] = rand($config['updown_start'], $config['updown_end']);
  1399. }
  1400. if($config['score']==1) {
  1401. $v['actor_score_num'] = rand(1, 1000);
  1402. $v['actor_score_all'] = $v['actor_score_num'] * rand(1, 10);
  1403. $v['actor_score'] = round($v['actor_score_all'] / $v['actor_score_num'], 1);
  1404. }
  1405. if ($config['psernd'] == 1) {
  1406. $v['actor_content'] = mac_rep_pse_rnd($pse_rnd, $v['actor_content']);
  1407. }
  1408. if ($config['psesyn'] == 1) {
  1409. $v['actor_content'] = mac_rep_pse_syn($pse_syn, $v['actor_content']);
  1410. }
  1411. if(empty($v['actor_blurb'])){
  1412. $v['actor_blurb'] = mac_substring( strip_tags($v['actor_content']) ,100);
  1413. }
  1414. $where = [];
  1415. $where['actor_name'] = $v['actor_name'];
  1416. if (strpos($config['inrule'], 'b')!==false) {
  1417. $where['actor_sex'] = $v['actor_sex'];
  1418. }
  1419. if (strpos($config['inrule'], 'c')!==false) {
  1420. $where['type_id'] = $v['type_id'];
  1421. }
  1422. $info = model('Actor')->where($where)->find();
  1423. if (!$info) {
  1424. $tmp = $this->syncImages($config_sync_pic, $v['actor_pic'],'actor');
  1425. $v['actor_pic'] = $tmp['pic'];
  1426. $msg = $tmp['msg'];
  1427. $res = model('Actor')->insert($v);
  1428. if($res===false){
  1429. }
  1430. $color ='green';
  1431. $des= lang('model/collect/add_ok');
  1432. } else {
  1433. if(empty($config['uprule'])){
  1434. $des = lang('model/collect/uprule_empty');
  1435. }
  1436. elseif ($info['actor_lock'] == 1) {
  1437. $des = lang('model/collect/data_lock');
  1438. }
  1439. else {
  1440. unset($v['actor_time_add']);
  1441. $rc=true;
  1442. if($rc){
  1443. $update=[];
  1444. if(strpos(','.$config['uprule'],'a')!==false && !empty($v['actor_content']) && $v['actor_content']!=$info['actor_content']){
  1445. $update['actor_content'] = $v['actor_content'];
  1446. }
  1447. if(strpos(','.$config['uprule'],'b')!==false && !empty($v['actor_blurb']) && $v['actor_blurb']!=$info['actor_blurb']){
  1448. $update['actor_blurb'] = $v['actor_blurb'];
  1449. }
  1450. if(strpos(','.$config['uprule'],'c')!==false && !empty($v['actor_remarks']) && $v['actor_remarks']!=$info['actor_remarks']){
  1451. $update['actor_remarks'] = $v['actor_remarks'];
  1452. }
  1453. if(strpos(','.$config['uprule'],'d')!==false && !empty($v['actor_works']) && $v['actor_works']!=$info['actor_works']){
  1454. $update['actor_works'] = $v['actor_works'];
  1455. }
  1456. if(strpos(','.$config['uprule'],'e')!==false && (substr($info["actor_pic"], 0, 4) == "http" ||empty($info['actor_pic']) ) && $v['actor_pic']!=$info['actor_pic'] ){
  1457. $tmp = $this->syncImages($config_sync_pic, $v['actor_pic'],'actor');
  1458. $update['actor_pic'] =$tmp['pic'];
  1459. $msg =$tmp['msg'];
  1460. }
  1461. if(count($update)>0){
  1462. $update['actor_time'] = time();
  1463. $where = [];
  1464. $where['actor_id'] = $info['actor_id'];
  1465. $res = model('Actor')->where($where)->update($update);
  1466. $color = 'green';
  1467. if($res===false){
  1468. }
  1469. }
  1470. else{
  1471. $des = lang('model/collect/not_need_update');
  1472. }
  1473. }
  1474. }
  1475. }
  1476. }
  1477. if($show==1) {
  1478. mac_echo( ($k + 1) . $v['actor_name'] . "<font color=$color>" .$des .'</font>'. $msg . '');
  1479. }
  1480. else{
  1481. return ['code'=>($color=='red' ? 1001 : 1),'msg'=> $v['actor_name'] .' '.$des ];
  1482. }
  1483. }
  1484. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_actor';
  1485. if(ENTRANCE=='api'){
  1486. Cache::rm($key);
  1487. if ($data['page']['page'] < $data['page']['pagecount']) {
  1488. $param['page'] = intval($data['page']['page']) + 1;
  1489. $res = $this->actor($param);
  1490. if($res['code']>1){
  1491. return $this->error($res['msg']);
  1492. }
  1493. $this->actor_data($param,$res );
  1494. }
  1495. mac_echo(lang('model/collect/is_over'));
  1496. die;
  1497. }
  1498. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  1499. $GLOBALS['config']['app']['collect_timespan'] = 3;
  1500. }
  1501. if($show==1) {
  1502. if ($param['ac'] == 'cjsel') {
  1503. Cache::rm($key);
  1504. mac_echo(lang('model/collect/is_over'));
  1505. unset($param['ids']);
  1506. $param['ac'] = 'list';
  1507. $url = url('api') . '?' . http_build_query($param);
  1508. $ref = $_SERVER["HTTP_REFERER"];
  1509. if(!empty($ref)){
  1510. $url = $ref;
  1511. }
  1512. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1513. } else {
  1514. if ($data['page']['page'] >= $data['page']['pagecount']) {
  1515. Cache::rm($key);
  1516. mac_echo(lang('model/collect/is_over'));
  1517. unset($param['page']);
  1518. $param['ac'] = 'list';
  1519. $url = url('api') . '?' . http_build_query($param);
  1520. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1521. } else {
  1522. $param['page'] = intval($data['page']['page']) + 1;
  1523. $url = url('api') . '?' . http_build_query($param);
  1524. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1525. }
  1526. }
  1527. }
  1528. }
  1529. public function role_json($param)
  1530. {
  1531. $url_param = [];
  1532. $url_param['ac'] = $param['ac'];
  1533. $url_param['t'] = $param['t'];
  1534. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  1535. $url_param['h'] = $param['h'];
  1536. $url_param['ids'] = $param['ids'];
  1537. $url_param['wd'] = $param['wd'];
  1538. if($param['ac']!='list'){
  1539. $url_param['ac'] = 'detail';
  1540. }
  1541. $url = $param['cjurl'];
  1542. if(strpos($url,'?')===false){
  1543. $url .='?';
  1544. }
  1545. else{
  1546. $url .='&';
  1547. }
  1548. $url .= http_build_query($url_param).base64_decode($param['param']);
  1549. $result = $this->checkCjUrl($url);
  1550. if ($result['code'] > 1) {
  1551. return $result;
  1552. }
  1553. $html = mac_curl_get($url);
  1554. if(empty($html)){
  1555. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  1556. }
  1557. $html = mac_filter_tags($html);
  1558. $json = json_decode($html,true);
  1559. if(!$json){
  1560. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ': ' . mb_substr($html, 0, 15)];
  1561. }
  1562. $array_page = [];
  1563. $array_page['page'] = $json['page'];
  1564. $array_page['pagecount'] = $json['pagecount'];
  1565. $array_page['pagesize'] = $json['limit'];
  1566. $array_page['recordcount'] = $json['total'];
  1567. $array_page['url'] = $url;
  1568. $key = 0;
  1569. $array_data = [];
  1570. foreach($json['list'] as $key=>$v){
  1571. $array_data[$key] = $v;
  1572. }
  1573. $res = ['code'=>1, 'msg'=>'ok', 'page'=>$array_page, 'data'=>$array_data ];
  1574. return $res;
  1575. }
  1576. public function role_data($param,$data,$show=1)
  1577. {
  1578. if($show==1) {
  1579. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1',[$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  1580. }
  1581. $config = config('maccms.collect');
  1582. $config = $config['role'];
  1583. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  1584. $filter_arr = explode(',',$config['filter']); $filter_arr = array_filter($filter_arr);
  1585. $pse_rnd = explode('#',$config['words']); $pse_rnd = array_filter($pse_rnd);
  1586. $pse_syn = mac_txt_explain($config['thesaurus'], true);
  1587. foreach($data['data'] as $k=>$v){
  1588. $color='red';
  1589. $des='';
  1590. $msg='';
  1591. $tmp='';
  1592. if(empty($v['role_name']) || empty($v['role_actor']) || empty($v['vod_name']) ) {
  1593. $des = lang('model/collect/role_data_require');
  1594. }
  1595. elseif( mac_array_filter($filter_arr,$v['role_name']) !==false) {
  1596. $des = lang('model/collect/name_in_filter_err');
  1597. }
  1598. else {
  1599. unset($v['role_id']);
  1600. foreach($v as $k2=>$v2){
  1601. if(strpos($k2,'_content')===false) {
  1602. $v[$k2] = strip_tags($v2);
  1603. }
  1604. }
  1605. $v['role_en'] = Pinyin::get($v['role_name']);
  1606. $v['role_letter'] = strtoupper(substr($v['role_en'],0,1));
  1607. $v['role_time_add'] = time();
  1608. $v['role_time'] = time();
  1609. $v['role_status'] = intval($config['status']);
  1610. $v['role_lock'] = intval($v['role_lock']);
  1611. if(!empty($v['role_status'])) {
  1612. $v['role_status'] = intval($v['role_status']);
  1613. }
  1614. $v['role_level'] = intval($v['role_level']);
  1615. $v['role_hits'] = intval($v['role_hits']);
  1616. $v['role_hits_day'] = intval($v['role_hits_day']);
  1617. $v['role_hits_week'] = intval($v['role_hits_week']);
  1618. $v['role_hits_month'] = intval($v['role_hits_month']);
  1619. $v['role_up'] = intval($v['role_up']);
  1620. $v['role_down'] = intval($v['role_down']);
  1621. $v['role_score'] = floatval($v['role_score']);
  1622. $v['role_score_all'] = intval($v['role_score_all']);
  1623. $v['role_score_num'] = intval($v['role_score_num']);
  1624. if($config['hits_start']>0 && $config['hits_end']>0) {
  1625. $v['role_hits'] = rand($config['hits_start'], $config['hits_end']);
  1626. $v['role_hits_day'] = rand($config['hits_start'], $config['hits_end']);
  1627. $v['role_hits_week'] = rand($config['hits_start'], $config['hits_end']);
  1628. $v['role_hits_month'] = rand($config['hits_start'], $config['hits_end']);
  1629. }
  1630. if($config['updown_start']>0 && $config['updown_end']){
  1631. $v['role_up'] = rand($config['updown_start'], $config['updown_end']);
  1632. $v['role_down'] = rand($config['updown_start'], $config['updown_end']);
  1633. }
  1634. if($config['score']==1) {
  1635. $v['role_score_num'] = rand(1, 1000);
  1636. $v['role_score_all'] = $v['role_score_num'] * rand(1, 10);
  1637. $v['role_score'] = round($v['role_score_all'] / $v['role_score_num'], 1);
  1638. }
  1639. if ($config['psernd'] == 1) {
  1640. $v['role_content'] = mac_rep_pse_rnd($pse_rnd, $v['role_content']);
  1641. }
  1642. if ($config['psesyn'] == 1) {
  1643. $v['role_content'] = mac_rep_pse_syn($pse_syn, $v['role_content']);
  1644. }
  1645. $where = [];
  1646. $where['role_name'] = $v['role_name'];
  1647. $where['role_actor'] = $v['role_actor'];
  1648. $where2 = [];
  1649. $blend = false;
  1650. if(!empty($v['douban_id'])){
  1651. $where2['vod_douban_id'] = ['eq',$v['douban_id']];
  1652. unset($v['douban_id']);
  1653. }
  1654. else{
  1655. $where2['vod_name'] = ['eq',$v['vod_name']];
  1656. }
  1657. if (strpos($config['inrule'], 'c')!==false) {
  1658. $where2['vod_actor'] = ['like', mac_like_arr($v['role_actor']), 'OR'];
  1659. }
  1660. if (strpos($config['inrule'], 'd')!==false) {
  1661. $where2['vod_director'] = ['like', mac_like_arr($v['role_actor']), 'OR'];
  1662. }
  1663. if(!empty($where2['vod_actor']) && !empty($where2['vod_director'])){
  1664. $blend = true;
  1665. $GLOBALS['blend'] = [
  1666. 'vod_actor' => $where2['vod_actor'],
  1667. 'vod_director' => $where2['vod_director']
  1668. ];
  1669. unset($where2['vod_actor'],$where2['vod_director']);
  1670. }
  1671. if($blend===false){
  1672. $vod_info = model('Vod')->where($where2)->find();
  1673. }
  1674. else{
  1675. $vod_info = model('Vod')->where($where2)
  1676. ->where(function($query){
  1677. $query->where('vod_director',$GLOBALS['blend']['vod_director'])
  1678. ->whereOr('vod_actor',$GLOBALS['blend']['vod_actor']);
  1679. })
  1680. ->find();
  1681. }
  1682. if (!$vod_info) {
  1683. $des = lang('model/collect/not_found_rel_vod');
  1684. }
  1685. else {
  1686. $v['role_rid'] = $vod_info['vod_id'];
  1687. $where['role_rid'] = $vod_info['vod_id'];
  1688. $info = model('Role')->where($where)->find();
  1689. if (!$info) {
  1690. $tmp = $this->syncImages($config_sync_pic, $v['role_pic'], 'role');
  1691. $v['role_pic'] = $tmp['pic'];
  1692. $msg = $tmp['msg'];
  1693. $res = model('Role')->insert($v);
  1694. if ($res === false) {
  1695. }
  1696. $color = 'green';
  1697. $des = lang('model/collect/add_ok');
  1698. } else {
  1699. if(empty($config['uprule'])){
  1700. $des = lang('model/collect/uprule_empty');
  1701. }
  1702. elseif ($info['role_lock'] == 1) {
  1703. $des = lang('model/collect/data_lock');
  1704. }
  1705. else {
  1706. unset($v['role_time_add']);
  1707. $rc = true;
  1708. if ($rc) {
  1709. $update = [];
  1710. if (strpos(',' . $config['uprule'], 'a') !== false && !empty($v['role_content']) && $v['role_content'] != $info['role_content']) {
  1711. $update['role_content'] = $v['role_content'];
  1712. }
  1713. if (strpos(',' . $config['uprule'], 'b') !== false && !empty($v['role_remarks']) && $v['role_remarks'] != $info['role_remarks']) {
  1714. $update['role_remarks'] = $v['role_remarks'];
  1715. }
  1716. if (strpos(',' . $config['uprule'], 'c') !== false && (substr($info["role_pic"], 0, 4) == "http" || empty($info['role_pic'])) && $v['role_pic'] != $info['role_pic']) {
  1717. $tmp = $this->syncImages($config_sync_pic, $v['role_pic'], 'role');
  1718. $update['role_pic'] = $tmp['pic'];
  1719. $msg = $tmp['msg'];
  1720. }
  1721. if(count($update)>0){
  1722. $update['role_time'] = time();
  1723. $where = [];
  1724. $where['role_id'] = $info['role_id'];
  1725. $res = model('Role')->where($where)->update($update);
  1726. $color = 'green';
  1727. if ($res === false) {
  1728. }
  1729. }
  1730. else{
  1731. $des = lang('model/collect/not_need_update');
  1732. }
  1733. }
  1734. }
  1735. }
  1736. }
  1737. }
  1738. if($show==1) {
  1739. mac_echo( ($k + 1) . $v['role_name'] . "<font color=$color>" .$des .'</font>'. $msg . '');
  1740. }
  1741. else{
  1742. return ['code'=>($color=='red' ? 1001 : 1),'msg'=> $v['role_name'] .' '.$des ];
  1743. }
  1744. }
  1745. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_role';
  1746. if(ENTRANCE=='api'){
  1747. Cache::rm($key);
  1748. if ($data['page']['page'] < $data['page']['pagecount']) {
  1749. $param['page'] = intval($data['page']['page']) + 1;
  1750. $res = $this->role($param);
  1751. if($res['code']>1){
  1752. return $this->error($res['msg']);
  1753. }
  1754. $this->role_data($param,$res );
  1755. }
  1756. mac_echo(lang('model/collect/is_over'));
  1757. die;
  1758. }
  1759. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  1760. $GLOBALS['config']['app']['collect_timespan'] = 3;
  1761. }
  1762. if($show==1) {
  1763. if ($param['ac'] == 'cjsel') {
  1764. Cache::rm($key);
  1765. mac_echo(lang('model/collect/is_over'));
  1766. unset($param['ids']);
  1767. $param['ac'] = 'list';
  1768. $url = url('api') . '?' . http_build_query($param);
  1769. $ref = $_SERVER["HTTP_REFERER"];
  1770. if(!empty($ref)){
  1771. $url = $ref;
  1772. }
  1773. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1774. } else {
  1775. if ($data['page']['page'] >= $data['page']['pagecount']) {
  1776. Cache::rm($key);
  1777. mac_echo(lang('model/collect/is_over'));
  1778. unset($param['page']);
  1779. $param['ac'] = 'list';
  1780. $url = url('api') . '?' . http_build_query($param);
  1781. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1782. } else {
  1783. $param['page'] = intval($data['page']['page']) + 1;
  1784. $url = url('api') . '?' . http_build_query($param);
  1785. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  1786. }
  1787. }
  1788. }
  1789. }
  1790. public function website_json($param)
  1791. {
  1792. $url_param = [];
  1793. $url_param['ac'] = $param['ac'];
  1794. $url_param['t'] = $param['t'];
  1795. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  1796. $url_param['h'] = $param['h'];
  1797. $url_param['ids'] = $param['ids'];
  1798. $url_param['wd'] = $param['wd'];
  1799. if($param['ac']!='list'){
  1800. $url_param['ac'] = 'detail';
  1801. }
  1802. $url = $param['cjurl'];
  1803. if(strpos($url,'?')===false){
  1804. $url .='?';
  1805. }
  1806. else{
  1807. $url .='&';
  1808. }
  1809. $url .= http_build_query($url_param).base64_decode($param['param']);
  1810. $result = $this->checkCjUrl($url);
  1811. if ($result['code'] > 1) {
  1812. return $result;
  1813. }
  1814. $html = mac_curl_get($url);
  1815. if(empty($html)){
  1816. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  1817. }
  1818. $html = mac_filter_tags($html);
  1819. $json = json_decode($html,true);
  1820. if(!$json){
  1821. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ': ' . mb_substr($html, 0, 15)];
  1822. }
  1823. $array_page = [];
  1824. $array_page['page'] = $json['page'];
  1825. $array_page['pagecount'] = $json['pagecount'];
  1826. $array_page['pagesize'] = $json['limit'];
  1827. $array_page['recordcount'] = $json['total'];
  1828. $array_page['url'] = $url;
  1829. $type_list = model('Type')->getCache('type_list');
  1830. $bind_list = config('bind');
  1831. $key = 0;
  1832. $array_data = [];
  1833. foreach($json['list'] as $key=>$v){
  1834. $array_data[$key] = $v;
  1835. $bind_key = $param['cjflag'] .'_'.$v['type_id'];
  1836. if($bind_list[$bind_key] >0){
  1837. $array_data[$key]['type_id'] = $bind_list[$bind_key];
  1838. }
  1839. else{
  1840. $array_data[$key]['type_id'] = 0;
  1841. }
  1842. }
  1843. $array_type = [];
  1844. $key=0;
  1845. //分类列表
  1846. if($param['ac'] == 'list'){
  1847. foreach($json['class'] as $k=>$v){
  1848. $array_type[$key]['type_id'] = $v['type_id'];
  1849. $array_type[$key]['type_name'] = $v['type_name'];
  1850. $key++;
  1851. }
  1852. }
  1853. $res = ['code'=>1, 'msg'=>'ok', 'page'=>$array_page, 'type'=>$array_type, 'data'=>$array_data ];
  1854. return $res;
  1855. }
  1856. public function website_data($param,$data,$show=1)
  1857. {
  1858. if($show==1) {
  1859. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1',[$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  1860. }
  1861. $config = config('maccms.collect');
  1862. $config = $config['website'];
  1863. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  1864. $type_list = model('Type')->getCache('type_list');
  1865. $filter_arr = explode(',',$config['filter']); $filter_arr = array_filter($filter_arr);
  1866. $pse_rnd = explode('#',$config['words']); $pse_rnd = array_filter($pse_rnd);
  1867. $pse_syn = mac_txt_explain($config['thesaurus'], true);
  1868. foreach($data['data'] as $k=>$v){
  1869. $color='red';
  1870. $des='';
  1871. $msg='';
  1872. $tmp='';
  1873. if($v['type_id'] ==0){
  1874. $des = lang('model/collect/type_err');
  1875. }
  1876. elseif(empty($v['website_name'])) {
  1877. $des = lang('model/collect/name_err');
  1878. }
  1879. elseif( mac_array_filter($filter_arr,$v['website_name'])!==false) {
  1880. $des = lang('model/collect/name_in_filter_err');
  1881. }
  1882. else {
  1883. unset($v['website_id']);
  1884. foreach($v as $k2=>$v2){
  1885. if(strpos($k2,'_content')===false) {
  1886. $v[$k2] = strip_tags($v2);
  1887. }
  1888. }
  1889. $v['website_name'] = trim($v['website_name']);
  1890. $v['type_id_1'] = intval($type_list[$v['type_id']]['type_pid']);
  1891. $v['website_en'] = Pinyin::get($v['website_name']);
  1892. $v['website_letter'] = strtoupper(substr($v['website_en'],0,1));
  1893. $v['website_time_add'] = time();
  1894. $v['website_time'] = time();
  1895. $v['website_status'] = intval($config['status']);
  1896. $v['website_lock'] = intval($v['website_lock']);
  1897. if(!empty($v['website_status'])) {
  1898. $v['website_status'] = intval($v['website_status']);
  1899. }
  1900. $v['website_level'] = intval($v['website_level']);
  1901. $v['website_hits'] = intval($v['website_hits']);
  1902. $v['website_hits_day'] = intval($v['website_hits_day']);
  1903. $v['website_hits_week'] = intval($v['website_hits_week']);
  1904. $v['website_hits_month'] = intval($v['website_hits_month']);
  1905. $v['website_up'] = intval($v['website_up']);
  1906. $v['website_down'] = intval($v['website_down']);
  1907. $v['website_score'] = floatval($v['website_score']);
  1908. $v['website_score_all'] = intval($v['website_score_all']);
  1909. $v['website_score_num'] = intval($v['website_score_num']);
  1910. if($config['hits_start']>0 && $config['hits_end']>0) {
  1911. $v['website_hits'] = rand($config['hits_start'], $config['hits_end']);
  1912. $v['website_hits_day'] = rand($config['hits_start'], $config['hits_end']);
  1913. $v['website_hits_week'] = rand($config['hits_start'], $config['hits_end']);
  1914. $v['website_hits_month'] = rand($config['hits_start'], $config['hits_end']);
  1915. }
  1916. if($config['updown_start']>0 && $config['updown_end']){
  1917. $v['website_up'] = rand($config['updown_start'], $config['updown_end']);
  1918. $v['website_down'] = rand($config['updown_start'], $config['updown_end']);
  1919. }
  1920. if($config['score']==1) {
  1921. $v['website_score_num'] = rand(1, 1000);
  1922. $v['website_score_all'] = $v['website_score_num'] * rand(1, 10);
  1923. $v['website_score'] = round($v['website_score_all'] / $v['website_score_num'], 1);
  1924. }
  1925. if ($config['psernd'] == 1) {
  1926. $v['website_content'] = mac_rep_pse_rnd($pse_rnd, $v['website_content']);
  1927. }
  1928. if ($config['psesyn'] == 1) {
  1929. $v['website_content'] = mac_rep_pse_syn($pse_syn, $v['website_content']);
  1930. }
  1931. if(empty($v['website_blurb'])){
  1932. $v['website_blurb'] = mac_substring( strip_tags($v['website_content']) ,100);
  1933. }
  1934. $where = [];
  1935. $where['website_name'] = $v['website_name'];
  1936. if (strpos($config['inrule'], 'b')!==false) {
  1937. $where['type_id'] = $v['type_id'];
  1938. }
  1939. // 采集网址入库重复规则建议增加跳转url
  1940. // https://github.com/magicblack/maccms10/issues/1071
  1941. if (strpos($config['inrule'], 'c')!==false) {
  1942. $where['website_jumpurl'] = $v['website_jumpurl'];
  1943. }
  1944. $info = model('Website')->where($where)->find();
  1945. if (!$info) {
  1946. $tmp = $this->syncImages($config_sync_pic, $v['website_pic'],'website');
  1947. $v['website_pic'] = $tmp['pic'];
  1948. $msg = $tmp['msg'];
  1949. $res = model('Website')->insert($v);
  1950. if($res===false){
  1951. }
  1952. $color ='green';
  1953. $des= lang('model/collect/add_ok');
  1954. } else {
  1955. if(empty($config['uprule'])){
  1956. $des = lang('model/collect/uprule_empty');
  1957. }
  1958. elseif ($info['website_lock'] == 1) {
  1959. $des = lang('model/collect/data_lock');
  1960. }
  1961. else {
  1962. unset($v['website_time_add']);
  1963. $rc=true;
  1964. if($rc){
  1965. $update=[];
  1966. if(strpos(','.$config['uprule'],'a')!==false && !empty($v['website_content']) && $v['website_content']!=$info['website_content']){
  1967. $update['website_content'] = $v['website_content'];
  1968. }
  1969. if(strpos(','.$config['uprule'],'b')!==false && !empty($v['website_blurb']) && $v['website_blurb']!=$info['website_blurb']){
  1970. $update['website_blurb'] = $v['website_blurb'];
  1971. }
  1972. if(strpos(','.$config['uprule'],'c')!==false && !empty($v['website_remarks']) && $v['website_remarks']!=$info['website_remarks']){
  1973. $update['website_remarks'] = $v['website_remarks'];
  1974. }
  1975. if(strpos(','.$config['uprule'],'d')!==false && !empty($v['website_jumpurl']) && $v['website_jumpurl']!=$info['website_jumpurl']){
  1976. $update['website_jumpurl'] = $v['website_jumpurl'];
  1977. }
  1978. if(strpos(','.$config['uprule'],'e')!==false && (substr($info["website_pic"], 0, 4) == "http" ||empty($info['website_pic']) ) && $v['website_pic']!=$info['website_pic'] ){
  1979. $tmp = $this->syncImages($config_sync_pic, $v['website_pic'],'website');
  1980. $update['website_pic'] =$tmp['pic'];
  1981. $msg =$tmp['msg'];
  1982. }
  1983. if(count($update)>0){
  1984. $update['website_time'] = time();
  1985. $where = [];
  1986. $where['website_id'] = $info['website_id'];
  1987. $res = model('Website')->where($where)->update($update);
  1988. $color = 'green';
  1989. if($res===false){
  1990. }
  1991. }
  1992. else{
  1993. $des = lang('model/collect/not_need_update');
  1994. }
  1995. }
  1996. }
  1997. }
  1998. }
  1999. if($show==1) {
  2000. mac_echo( ($k + 1) . $v['website_name'] . "<font color=$color>" .$des .'</font>'. $msg . '');
  2001. }
  2002. else{
  2003. return ['code'=>($color=='red' ? 1001 : 1),'msg'=> $v['website_name'] .' '.$des ];
  2004. }
  2005. }
  2006. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_website';
  2007. if(ENTRANCE=='api'){
  2008. Cache::rm($key);
  2009. if ($data['page']['page'] < $data['page']['pagecount']) {
  2010. $param['page'] = intval($data['page']['page']) + 1;
  2011. $res = $this->actor($param);
  2012. if($res['code']>1){
  2013. return $this->error($res['msg']);
  2014. }
  2015. $this->website_data($param,$res );
  2016. }
  2017. mac_echo(lang('model/collect/is_over'));
  2018. die;
  2019. }
  2020. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  2021. $GLOBALS['config']['app']['collect_timespan'] = 3;
  2022. }
  2023. if($show==1) {
  2024. if ($param['ac'] == 'cjsel') {
  2025. Cache::rm($key);
  2026. mac_echo(lang('model/collect/is_over'));
  2027. unset($param['ids']);
  2028. $param['ac'] = 'list';
  2029. $url = url('api') . '?' . http_build_query($param);
  2030. $ref = $_SERVER["HTTP_REFERER"];
  2031. if(!empty($ref)){
  2032. $url = $ref;
  2033. }
  2034. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2035. } else {
  2036. if ($data['page']['page'] >= $data['page']['pagecount']) {
  2037. Cache::rm($key);
  2038. mac_echo(lang('model/collect/is_over'));
  2039. unset($param['page']);
  2040. $param['ac'] = 'list';
  2041. $url = url('api') . '?' . http_build_query($param);
  2042. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2043. } else {
  2044. $param['page'] = intval($data['page']['page']) + 1;
  2045. $url = url('api') . '?' . http_build_query($param);
  2046. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2047. }
  2048. }
  2049. }
  2050. }
  2051. public function comment_json($param)
  2052. {
  2053. $url_param = [];
  2054. $url_param['ac'] = $param['ac'];
  2055. $url_param['t'] = $param['t'];
  2056. $url_param['pg'] = is_numeric($param['page']) ? $param['page'] : '';
  2057. $url_param['h'] = $param['h'];
  2058. $url_param['ids'] = $param['ids'];
  2059. $url_param['wd'] = $param['wd'];
  2060. if($param['ac']!='list'){
  2061. $url_param['ac'] = 'detail';
  2062. }
  2063. $url = $param['cjurl'];
  2064. if(strpos($url,'?')===false){
  2065. $url .='?';
  2066. }
  2067. else{
  2068. $url .='&';
  2069. }
  2070. $url .= http_build_query($url_param).base64_decode($param['param']);
  2071. $result = $this->checkCjUrl($url);
  2072. if ($result['code'] > 1) {
  2073. return $result;
  2074. }
  2075. $html = mac_curl_get($url);
  2076. if(empty($html)){
  2077. return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
  2078. }
  2079. $html = mac_filter_tags($html);
  2080. $json = json_decode($html,true);
  2081. if(!$json){
  2082. return ['code'=>1002, 'msg'=>lang('model/collect/json_err') . ': ' . mb_substr($html, 0, 15)];
  2083. }
  2084. $array_page = [];
  2085. $array_page['page'] = $json['page'];
  2086. $array_page['pagecount'] = $json['pagecount'];
  2087. $array_page['pagesize'] = $json['limit'];
  2088. $array_page['recordcount'] = $json['total'];
  2089. $array_page['url'] = $url;
  2090. $key = 0;
  2091. $array_data = [];
  2092. foreach($json['list'] as $key=>$v){
  2093. $array_data[$key] = $v;
  2094. }
  2095. $res = ['code'=>1, 'msg'=>'ok', 'page'=>$array_page, 'data'=>$array_data ];
  2096. return $res;
  2097. }
  2098. public function comment_data($param,$data,$show=1)
  2099. {
  2100. if($show==1) {
  2101. mac_echo('[' . __FUNCTION__ . '] ' . lang('model/collect/data_tip1',[$data['page']['page'],$data['page']['pagecount'],$data['page']['url']]));
  2102. }
  2103. $config = config('maccms.collect');
  2104. $config = $config['comment'];
  2105. $config_sync_pic = $param['sync_pic_opt'] > 0 ? $param['sync_pic_opt'] : $config['pic'];
  2106. $filter_arr = explode(',',$config['filter']); $filter_arr = array_filter($filter_arr);
  2107. $pse_rnd = explode('#',$config['words']); $pse_rnd = array_filter($pse_rnd);
  2108. $pse_syn = mac_txt_explain($config['thesaurus'], true);
  2109. foreach($data['data'] as $k=>$v){
  2110. $color='red';
  2111. $des='';
  2112. $msg='';
  2113. $tmp='';
  2114. if(empty($v['comment_name']) || empty($v['comment_content']) || empty($v['rel_name']) ) {
  2115. $des = lang('model/collect/comment_data_require');
  2116. }
  2117. elseif( mac_array_filter($filter_arr,$v['comment_content']) !==false) {
  2118. $des = lang('model/collect/name_in_filter_err');
  2119. }
  2120. else {
  2121. unset($v['comment_id']);
  2122. foreach($v as $k2=>$v2){
  2123. if(strpos($k2,'_content')===false) {
  2124. $v[$k2] = strip_tags($v2);
  2125. }
  2126. }
  2127. $v['comment_time'] = time();
  2128. $v['comment_status'] = intval($config['status']);
  2129. $v['comment_up'] = intval($v['comment_up']);
  2130. $v['comment_down'] = intval($v['comment_down']);
  2131. $v['comment_mid'] = intval($v['comment_mid']);
  2132. if(!empty($v['comment_ip']) && !is_numeric($v['comment_ip'])){
  2133. $v['comment_ip'] = mac_get_ip_long($v['comment_ip']);
  2134. }
  2135. if($config['updown_start']>0 && $config['updown_end']){
  2136. $v['comment_up'] = rand($config['updown_start'], $config['updown_end']);
  2137. $v['comment_down'] = rand($config['updown_start'], $config['updown_end']);
  2138. }
  2139. if ($config['psernd'] == 1) {
  2140. $v['comment_content'] = mac_rep_pse_rnd($pse_rnd, $v['comment_content']);
  2141. }
  2142. if ($config['psesyn'] == 1) {
  2143. $v['comment_content'] = mac_rep_pse_syn($pse_syn, $v['comment_content']);
  2144. }
  2145. $where = [];
  2146. $where2 = [];
  2147. $blend = false;
  2148. if (strpos($config['inrule'], 'b')!==false) {
  2149. $where['comment_content'] = ['eq', $v['comment_content']];
  2150. }
  2151. if (strpos($config['inrule'], 'c')!==false) {
  2152. $where['comment_name'] = ['eq', $v['comment_name']];
  2153. }
  2154. if(empty($v['rel_id'])){
  2155. if($v['comment_mid']==1){
  2156. if(!empty($v['douban_id'])){
  2157. $where2['vod_douban_id'] = ['eq',$v['douban_id']];
  2158. unset($v['douban_id']);
  2159. }
  2160. else{
  2161. $where2['vod_name'] = ['eq',$v['rel_name']];
  2162. }
  2163. $rel_info = model('Vod')->where($where2)->find();
  2164. }
  2165. elseif($v['comment_mid']==2){
  2166. $where2['art_name'] = ['eq',$v['rel_name']];
  2167. $rel_info = model('Art')->where($where2)->find();
  2168. }
  2169. elseif($v['comment_mid']==3){
  2170. $where2['topic_name'] = ['eq',$v['rel_name']];
  2171. $rel_info = model('Topic')->where($where2)->find();
  2172. }
  2173. elseif($v['comment_mid']==8){
  2174. $where2['actor_name'] = ['eq',$v['rel_name']];
  2175. $rel_info = model('Actor')->where($where2)->find();
  2176. }
  2177. elseif($v['comment_mid']==9){
  2178. $where2['role_name'] = ['eq',$v['rel_name']];
  2179. $rel_info = model('Role')->where($where2)->find();
  2180. }
  2181. elseif($v['comment_mid']==11){
  2182. $where2['website_name'] = ['eq',$v['rel_name']];
  2183. $rel_info = model('Website')->where($where2)->find();
  2184. }
  2185. $rel_id = $rel_info[mac_get_mid_code($v['comment_mid']).'_id'];
  2186. }
  2187. else{
  2188. $rel_id = $v['rel_id'];
  2189. }
  2190. if(empty($rel_id)){
  2191. $des = lang('model/collect/not_found_rel_data');
  2192. }
  2193. else {
  2194. $v['comment_rid'] = $rel_id;
  2195. $info=false;
  2196. if(!empty($where)) {
  2197. $where['comment_rid'] = $rel_id;
  2198. $info = model('Comment')->where($where)->find();
  2199. }
  2200. if (!$info) {
  2201. $msg = isset($tmp['msg']) ? $tmp['msg'] : '';
  2202. $res = model('Comment')->insert($v);
  2203. if ($res === false) {
  2204. }
  2205. $color = 'green';
  2206. $des = lang('model/collect/add_ok');
  2207. } else {
  2208. if(empty($config['uprule'])){
  2209. $des = lang('model/collect/uprule_empty');
  2210. }
  2211. else {
  2212. $rc = true;
  2213. if ($rc) {
  2214. $update = [];
  2215. if (strpos(',' . $config['uprule'], 'a') !== false && !empty($v['comment_time']) && $v['comment_time'] != $info['comment_time']) {
  2216. $update['comment_time'] = $v['comment_time'];
  2217. }
  2218. if(count($update)>0){
  2219. $update['comment_time'] = time();
  2220. $where = [];
  2221. $where['comment_id'] = $info['comment_id'];
  2222. $res = model('Comment')->where($where)->update($update);
  2223. $color = 'green';
  2224. if ($res === false) {
  2225. }
  2226. }
  2227. else{
  2228. $des = lang('model/collect/not_need_update');
  2229. }
  2230. }
  2231. }
  2232. }
  2233. }
  2234. }
  2235. if($show==1) {
  2236. mac_echo( ($k + 1) . $v['comment_content'] . "<font color=$color>" .$des .'</font>'. $msg . '');
  2237. }
  2238. else{
  2239. return ['code'=>($color=='red' ? 1001 : 1),'msg'=> $v['comment_content'] .' '.$des ];
  2240. }
  2241. }
  2242. $key = $GLOBALS['config']['app']['cache_flag']. '_'.'collect_break_comment';
  2243. if(ENTRANCE=='api'){
  2244. Cache::rm($key);
  2245. if ($data['page']['page'] < $data['page']['pagecount']) {
  2246. $param['page'] = intval($data['page']['page']) + 1;
  2247. $res = $this->role($param);
  2248. if($res['code']>1){
  2249. return $this->error($res['msg']);
  2250. }
  2251. $this->actor_data($param,$res );
  2252. }
  2253. mac_echo(lang('model/collect/is_over'));
  2254. die;
  2255. }
  2256. if(empty($GLOBALS['config']['app']['collect_timespan'])){
  2257. $GLOBALS['config']['app']['collect_timespan'] = 3;
  2258. }
  2259. if($show==1) {
  2260. if ($param['ac'] == 'cjsel') {
  2261. Cache::rm($key);
  2262. mac_echo(lang('model/collect/is_over'));
  2263. unset($param['ids']);
  2264. $param['ac'] = 'list';
  2265. $url = url('api') . '?' . http_build_query($param);
  2266. $ref = $_SERVER["HTTP_REFERER"];
  2267. if(!empty($ref)){
  2268. $url = $ref;
  2269. }
  2270. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2271. } else {
  2272. if ($data['page']['page'] >= $data['page']['pagecount']) {
  2273. Cache::rm($key);
  2274. mac_echo(lang('model/collect/is_over'));
  2275. unset($param['page']);
  2276. $param['ac'] = 'list';
  2277. $url = url('api') . '?' . http_build_query($param);
  2278. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2279. } else {
  2280. $param['page'] = intval($data['page']['page']) + 1;
  2281. $url = url('api') . '?' . http_build_query($param);
  2282. mac_jump($url, $GLOBALS['config']['app']['collect_timespan']);
  2283. }
  2284. }
  2285. }
  2286. }
  2287. /**
  2288. * 检查url合法性
  2289. * https://github.com/magicblack/maccms10/issues/763
  2290. */
  2291. private function checkCjUrl($url)
  2292. {
  2293. $result = parse_url($url);
  2294. if (empty($result['host']) || in_array($result['host'], ['127.0.0.1', 'localhost'])) {
  2295. return ['code' => 1001, 'msg' => lang('model/collect/cjurl_err') . ': ' . $url];
  2296. }
  2297. return ['code' => 1];
  2298. }
  2299. }