Collect.php 112 KB

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