Collect.php 111 KB

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