Collect.php 109 KB

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