node.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <?php
  2. defined('IN_PHPCMS') or exit('No permission resources.');
  3. //模型缓存路径
  4. define('CACHE_MODEL_PATH',PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);
  5. pc_base::load_app_class('admin', 'admin', 0);
  6. pc_base::load_sys_class('form', '', 0);
  7. class node extends admin {
  8. private $db,$siteid;
  9. //HTML标签
  10. private static $html_tag = array("<p([^>]*)>(.*)</p>[|]"=>'<p>', "<a([^>]*)>(.*)</a>[|]"=>'<a>',"<script([^>]*)>(.*)</script>[|]"=>'<script>', "<iframe([^>]*)>(.*)</iframe>[|]"=>'<iframe>', "<table([^>]*)>(.*)</table>[|]"=>'<table>', "<span([^>]*)>(.*)</span>[|]"=>'<span>', "<b([^>]*)>(.*)</b>[|]"=>'<b>', "<img([^>]*)>[|]"=>'<img>', "<object([^>]*)>(.*)</object>[|]"=>'<object>', "<embed([^>]*)>(.*)</embed>[|]"=>'<embed>', "<param([^>]*)>(.*)</param>[|]"=>'<param>', '<div([^>]*)>[|]'=>'<div>', '</div>[|]'=>'</div>', '<!--([^>]*)-->[|]'=>'<!-- -->');
  11. //网址类型
  12. private $url_list_type = array();
  13. function __construct() {
  14. parent::__construct();
  15. $this->db = pc_base::load_model('collection_node_model');
  16. $this->siteid = get_siteid();
  17. $this->url_list_type = array('1'=>L('sequence'), '2'=>L('multiple_pages'), '3'=>L('single_page'), '4'=>'RSS');
  18. }
  19. /**
  20. * node list
  21. */
  22. public function manage() {
  23. $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
  24. $nodelist = $this->db->listinfo(array('siteid'=>$this->get_siteid()), 'nodeid DESC', $page, 15);
  25. $pages = $this->db->pages;
  26. pc_base::load_sys_class('format', '', 0);
  27. include $this->admin_tpl('node_list');
  28. }
  29. /**
  30. * add node
  31. */
  32. public function add() {
  33. header("Cache-control: private");
  34. if(isset($_POST['dosubmit'])) {
  35. $data = isset($_POST['data']) ? $_POST['data'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  36. $customize_config = isset($_POST['customize_config']) ? $_POST['customize_config'] : '';
  37. if (!$data['name'] = trim($data['name'])) {
  38. showmessage(L('nodename').L('empty'), HTTP_REFERER);
  39. }
  40. if ($this->db->get_one(array('name'=>$data['name']))) {
  41. showmessage(L('nodename').L('exists'), HTTP_REFERER);
  42. }
  43. $data['urlpage'] = isset($_POST['urlpage'.$data['sourcetype']]) ? $_POST['urlpage'.$data['sourcetype']] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  44. $data['siteid']= $this->get_siteid();
  45. $data['customize_config'] = array();
  46. if (is_array($customize_config)) foreach ($customize_config['en_name'] as $k => $v) {
  47. if (empty($v) || empty($customize_config['name'][$k])) continue;
  48. $data['customize_config'][] = array('name'=>$customize_config['name'][$k], 'en_name'=>$v, 'rule'=>$customize_config['rule'][$k], 'html_rule'=>$customize_config['html_rule'][$k]);
  49. }
  50. $data['customize_config'] = array2string($data['customize_config']);
  51. if ($this->db->insert($data)) {
  52. showmessage(L('operation_success'), '?m=collection&c=node&a=manage');
  53. } else {
  54. showmessage(L('operation_failure'), HTTP_REFERER);
  55. }
  56. } else {
  57. $show_dialog = $show_validator = true;
  58. include $this->admin_tpl('node_form');
  59. }
  60. }
  61. //修改采集配置
  62. public function edit() {
  63. $nodeid = isset($_GET['nodeid']) ? intval($_GET['nodeid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  64. $data = $this->db->get_one(array('nodeid'=>$nodeid));
  65. if(isset($_POST['dosubmit'])) {
  66. $datas = $data;
  67. unset($data);
  68. $data = isset($_POST['data']) ? $_POST['data'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  69. $customize_config = isset($_POST['customize_config']) ? $_POST['customize_config'] : '';
  70. if (!$data['name'] = trim($data['name'])) {
  71. showmessage(L('nodename').L('empty'), HTTP_REFERER);
  72. }
  73. if ($datas['name'] != $data['name']) {
  74. if ($this->db->get_one(array('name'=>$data['name']))) {
  75. showmessage(L('nodename').L('exists'), HTTP_REFERER);
  76. }
  77. }
  78. $data['urlpage'] = isset($_POST['urlpage'.$data['sourcetype']]) ? $_POST['urlpage'.$data['sourcetype']] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  79. $data['customize_config'] = array();
  80. if (is_array($customize_config)) foreach ($customize_config['en_name'] as $k => $v) {
  81. if (empty($v) || empty($customize_config['name'][$k])) continue;
  82. $data['customize_config'][] = array('name'=>$customize_config['name'][$k], 'en_name'=>$v, 'rule'=>$customize_config['rule'][$k], 'html_rule'=>$customize_config['html_rule'][$k]);
  83. }
  84. $data['customize_config'] = array2string($data['customize_config']);
  85. if ($this->db->update($data, array('nodeid'=>$nodeid))) {
  86. showmessage(L('operation_success'), '?m=collection&c=node&a=manage');
  87. } else {
  88. showmessage(L('operation_failure'), HTTP_REFERER);
  89. }
  90. } else {
  91. $model_cache = getcache('model', 'commons');
  92. $siteid = get_siteid();
  93. foreach($model_cache as $k=>$v) {
  94. $modellist[0] = L('select_model');
  95. if($v['siteid'] == $siteid) {
  96. $modellist[$k] = $v['name'];
  97. }
  98. }
  99. if (isset($data['customize_config'])) {
  100. $data['customize_config'] = string2array($data['customize_config']);
  101. }
  102. $show_dialog = $show_validator = true;
  103. //print_r($nodeinfo);exit;
  104. include $this->admin_tpl('node_form');
  105. }
  106. }
  107. //复制采集
  108. public function copy() {
  109. $nodeid = isset($_GET['nodeid']) ? intval($_GET['nodeid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  110. if ($data = $this->db->get_one(array('nodeid'=>$nodeid))) {
  111. if (isset($_POST['dosubmit'])) {
  112. unset($data['nodeid']);
  113. $name = isset($_POST['name']) && trim($_POST['name']) ? trim($_POST['name']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  114. if ($this->db->get_one(array('name'=>$name), 'nodeid')) {
  115. showmessage(L('nodename').L('exists'), HTTP_REFERER);
  116. }
  117. $data['name'] = $name;
  118. $data = new_addslashes($data);
  119. if ($this->db->insert($data)) {
  120. showmessage(L('operation_success'), '', '', 'test');
  121. } else {
  122. showmessage(L('operation_failure'));
  123. }
  124. } else {
  125. $show_validator = $show_header = true;
  126. include $this->admin_tpl('node_copy');
  127. }
  128. } else {
  129. showmessage(L('notfound'));
  130. }
  131. }
  132. //导入采集点
  133. public function node_import() {
  134. if (isset($_POST['dosubmit'])) {
  135. $filename = $_FILES['file']['tmp_name'];
  136. if (strtolower(substr($_FILES['file']['name'], -3, 3)) != 'txt') {
  137. showmessage(L('only_allowed_to_upload_txt_files'), HTTP_REFERER);
  138. }
  139. $data = json_decode(base64_decode(file_get_contents($filename)), true);
  140. if (pc_base::load_config('system', 'charset') == 'gbk') {
  141. $data = array_iconv($data, 'utf-8', 'gbk');
  142. }
  143. @unlink($filename);
  144. $name = isset($_POST['name']) && trim($_POST['name']) ? trim($_POST['name']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  145. if ($this->db->get_one(array('name'=>$name), 'nodeid')) {
  146. showmessage(L('nodename').L('exists'), HTTP_REFERER);
  147. }
  148. $data['name'] = $name;
  149. $data['siteid'] = $this->get_siteid();
  150. $data = new_addslashes($data);
  151. if ($this->db->insert($data)) {
  152. showmessage(L('operation_success'), '', '', 'test');
  153. } else {
  154. showmessage(L('operation_failure'));
  155. }
  156. } else {
  157. $show_header = $show_validator = true;
  158. include $this->admin_tpl('node_import');
  159. }
  160. }
  161. //导出采集配置
  162. public function export() {
  163. $nodeid = isset($_GET['nodeid']) ? intval($_GET['nodeid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  164. if ($data = $this->db->get_one(array('nodeid'=>$nodeid))) {
  165. unset($data['nodeid'], $data['name'], $data['siteid']);
  166. if (pc_base::load_config('system', 'charset') == 'gbk') {
  167. $data = array_iconv($data);
  168. }
  169. header("Content-type: application/octet-stream");
  170. header("Content-Disposition: attachment; filename=pc_collection_".$nodeid.'.txt');
  171. echo base64_encode(json_encode($data));
  172. } else {
  173. showmessage(L('notfound'));
  174. }
  175. }
  176. //URL配置显示结果
  177. public function public_url() {
  178. $sourcetype = isset($_GET['sourcetype']) && intval($_GET['sourcetype']) ? intval($_GET['sourcetype']) : showmessage(L('illegal_parameters'));
  179. $pagesize_start = isset($_GET['pagesize_start']) && intval($_GET['pagesize_start']) ? intval($_GET['pagesize_start']) : 1;
  180. $pagesize_end = isset($_GET['pagesize_end']) && intval($_GET['pagesize_end']) ? intval($_GET['pagesize_end']) : 10;
  181. $par_num = isset($_GET['par_num']) && intval($_GET['par_num']) ? intval($_GET['par_num']) : 1;
  182. $urlpage = isset($_GET['urlpage']) && trim($_GET['urlpage']) ? trim($_GET['urlpage']) : showmessage(L('illegal_parameters'));
  183. $show_header = true;
  184. include $this->admin_tpl('node_public_url');
  185. }
  186. //删除采集节点
  187. public function del() {
  188. if (isset($_POST['dosubmit'])) {
  189. $nodeid = isset($_POST['nodeid']) ? $_POST['nodeid'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  190. foreach ($nodeid as $k=>$v) {
  191. if(intval($v)) {
  192. $nodeid[$k] = intval($v);
  193. } else {
  194. unset($nodeid[$k]);
  195. }
  196. }
  197. $nodeid = implode('\',\'', $nodeid);
  198. $this->db->delete("nodeid in ('$nodeid')");
  199. $content_db = pc_base::load_model('collection_content_model');
  200. $content_db->delete("nodeid in ('$nodeid')");
  201. showmessage(L('operation_success'), '?m=collection&c=node&a=manage');
  202. } else {
  203. showmessage(L('illegal_parameters'), HTTP_REFERER);
  204. }
  205. }
  206. //测试文章URL采集
  207. public function public_test() {
  208. $nodeid = isset($_GET['nodeid']) ? intval($_GET['nodeid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  209. pc_base::load_app_class('collection', '', 0);
  210. if ($data = $this->db->get_one(array('nodeid'=>$nodeid))) {
  211. $urls = collection::url_list($data, 1);
  212. if (!empty($urls)) foreach ($urls as $v) {
  213. $url = collection::get_url_lists($v, $data);
  214. }
  215. $show_header = $show_dialog = true;
  216. include $this->admin_tpl('public_test');
  217. } else {
  218. showmessage(L('notfound'));
  219. }
  220. }
  221. //测试文章内容采集
  222. public function public_test_content() {
  223. $url = isset($_GET['url']) ? urldecode($_GET['url']) : exit('0');
  224. $nodeid = isset($_GET['nodeid']) ? intval($_GET['nodeid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  225. pc_base::load_app_class('collection', '', 0);
  226. if ($data = $this->db->get_one(array('nodeid'=>$nodeid))) {
  227. $contents = collection::get_content($url, $data);
  228. foreach ($contents as $_key=>$_content) {
  229. if(trim($_content)=='') $contents[$_key] = '◆◆◆◆◆◆◆◆◆◆'.$_key.' empty◆◆◆◆◆◆◆◆◆◆';
  230. }
  231. print_r($contents);
  232. } else {
  233. showmessage(L('notfound'));
  234. }
  235. }
  236. //采集节点名验证
  237. public function public_name() {
  238. $name = isset($_GET['name']) && trim($_GET['name']) ? (pc_base::load_config('system', 'charset') == 'gbk' ? iconv('utf-8', 'gbk', trim($_GET['name'])) : trim($_GET['name'])) : exit('0');
  239. $nodeid = isset($_GET['nodeid']) && intval($_GET['nodeid']) ? intval($_GET['nodeid']) : '';
  240. $data = array();
  241. if ($nodeid) {
  242. $data = $this->db->get_one(array('nodeid'=>$nodeid), 'name');
  243. if (!empty($data) && $data['name'] == $name) {
  244. exit('1');
  245. }
  246. }
  247. if ($this->db->get_one(array('name'=>$name), 'nodeid')) {
  248. exit('0');
  249. } else {
  250. exit('1');
  251. }
  252. }
  253. //采集网址
  254. public function col_url_list() {
  255. $nodeid = isset($_GET['nodeid']) ? intval($_GET['nodeid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  256. if ($data = $this->db->get_one(array('nodeid'=>$nodeid))) {
  257. pc_base::load_app_class('collection', '', 0);
  258. $urls = collection::url_list($data);
  259. $total_page = count($urls);
  260. if ($total_page > 0) {
  261. $page = isset($_GET['page']) ? intval($_GET['page']) : 0;
  262. $url_list = $urls[$page];
  263. $url = collection::get_url_lists($url_list, $data);
  264. $history_db = pc_base::load_model('collection_history_model');
  265. $content_db = pc_base::load_model('collection_content_model');
  266. $total = count($url);
  267. $re = 0;
  268. if (is_array($url) && !empty($url)) foreach ($url as $v) {
  269. if (empty($v['url']) || empty($v['title'])) continue;
  270. $v = new_addslashes($v);
  271. $v['title'] = strip_tags($v['title']);
  272. $md5 = md5($v['url']);
  273. if (!$history_db->get_one(array('md5'=>$md5, 'siteid'=>$this->get_siteid()))) {
  274. $history_db->insert(array('md5'=>$md5, 'siteid'=>$this->get_siteid()));
  275. $content_db->insert(array('nodeid'=>$nodeid, 'status'=>0, 'url'=>$v['url'], 'title'=>$v['title'], 'siteid'=>$this->get_siteid()));
  276. } else {
  277. $re++;
  278. }
  279. }
  280. $show_header = $show_dialog = true;
  281. if ($total_page <= $page) {
  282. $this->db->update(array('lastdate'=>SYS_TIME), array('nodeid'=>$nodeid));
  283. }
  284. include $this->admin_tpl('col_url_list');
  285. } else {
  286. showmessage(L('not_to_collect'));
  287. }
  288. } else {
  289. showmessage(L('notfound'));
  290. }
  291. }
  292. //采集文章
  293. public function col_content() {
  294. $nodeid = isset($_GET['nodeid']) ? intval($_GET['nodeid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  295. if ($data = $this->db->get_one(array('nodeid'=>$nodeid))) {
  296. $content_db = pc_base::load_model('collection_content_model');
  297. //更新附件状态
  298. $attach_status = false;
  299. if(pc_base::load_config('system','attachment_stat')) {
  300. $this->attachment_db = pc_base::load_model('attachment_model');
  301. $attach_status = true;
  302. }
  303. pc_base::load_app_class('collection', '', 0);
  304. $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
  305. $total = isset($_GET['total']) ? intval($_GET['total']) : 0;
  306. if (empty($total)) $total = $content_db->count(array('nodeid'=>$nodeid, 'siteid'=>$this->get_siteid(), 'status'=>0));
  307. $total_page = ceil($total/2);
  308. $list = $content_db->select(array('nodeid'=>$nodeid, 'siteid'=>$this->get_siteid(), 'status'=>0), 'id,url', '2', 'id desc');
  309. $i = 0;
  310. if (!empty($list) && is_array($list)) {
  311. foreach ($list as $v) {
  312. $GLOBALS['downloadfiles'] = array();
  313. $html = collection::get_content($v['url'], $data);
  314. //更新附件状态
  315. if($attach_status) {
  316. $this->attachment_db->api_update($GLOBALS['downloadfiles'],'cj-'.$v['id'],1);
  317. }
  318. $content_db->update(array('status'=>1, 'data'=>array2string($html)), array('id'=>$v['id']));
  319. $i++;
  320. }
  321. } else {
  322. showmessage(L('url_collect_msg'), '?m=collection&c=node&a=manage');
  323. }
  324. if ($total_page > $page) {
  325. showmessage(L('collectioning').($i+($page-1)*2).'/'.$total.'<script type="text/javascript">location.href="?m=collection&c=node&a=col_content&page='.($page+1).'&nodeid='.$nodeid.'&total='.$total.'&pc_hash='.$_SESSION['pc_hash'].'"</script>', '?m=collection&c=node&a=col_content&page='.($page+1).'&nodeid='.$nodeid.'&total='.$total);
  326. } else {
  327. $this->db->update(array('lastdate'=>SYS_TIME), array('nodeid'=>$nodeid));
  328. showmessage(L('collection_success'), '?m=collection&c=node&a=manage');
  329. }
  330. }
  331. }
  332. //文章列表
  333. public function publist() {
  334. $nodeid = isset($_GET['nodeid']) ? intval($_GET['nodeid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  335. $node = $this->db->get_one(array('nodeid'=>$nodeid), 'name');
  336. $content_db = pc_base::load_model('collection_content_model');
  337. $status = isset($_GET['status']) ? intval($_GET['status']) : '';
  338. $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
  339. $sql = array('nodeid'=>$nodeid, 'siteid'=>$this->get_siteid());
  340. if ($status) {
  341. $sql['status'] = $status - 1;
  342. }
  343. $data = $content_db->listinfo($sql, 'id desc', $page);
  344. $pages = $content_db->pages;
  345. $show_header = true;
  346. include $this->admin_tpl('publist');
  347. }
  348. //导入文章
  349. public function import() {
  350. $nodeid = isset($_GET['nodeid']) ? intval($_GET['nodeid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  351. $id = isset($_GET['id']) ? $_GET['id'] : '';
  352. $type = isset($_GET['type']) ? trim($_GET['type']) : '';
  353. if ($type == 'all') {
  354. } else {
  355. $ids = implode(',', $id);
  356. }
  357. $program_db = pc_base::load_model('collection_program_model');
  358. $program_list = $program_db->select(array('nodeid'=>$nodeid, 'siteid'=>$this->get_siteid()), 'id, catid');
  359. $cat = getcache('category_content_'.$this->siteid, 'commons');
  360. include $this->admin_tpl('import_program');
  361. }
  362. //删除文章
  363. public function content_del() {
  364. $id = isset($_GET['id']) ? $_GET['id'] : '';
  365. $history = isset($_GET['history']) ? $_GET['history'] : '';
  366. if (is_array($id)) {
  367. $collection_content_db = pc_base::load_model('collection_content_model');
  368. $history_db = pc_base::load_model('collection_history_model');
  369. $del_array = $id;
  370. $ids = implode('\',\'', $id);
  371. if ($history) {
  372. $data = $collection_content_db->select("id in ('$ids')", 'url');
  373. foreach ($data as $v) {
  374. $list[] = md5($v['url']);
  375. }
  376. $md5 = implode('\',\'', $list);
  377. $history_db->delete("md5 in ('$md5')");
  378. }
  379. $collection_content_db->delete("id in ('$ids')");
  380. //同时删除关联附件
  381. if(!empty($del_array)) {
  382. $attachment = pc_base::load_model('attachment_model');
  383. foreach ($del_array as $id) {
  384. $attachment->api_delete('cj-'.$id);
  385. }
  386. }
  387. showmessage(L('operation_success'), HTTP_REFERER);
  388. }
  389. }
  390. //添加导入方案
  391. public function import_program_add() {
  392. $nodeid = isset($_GET['nodeid']) ? intval($_GET['nodeid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  393. $ids = isset($_GET['ids']) ? $_GET['ids'] : '';
  394. $catid = isset($_GET['catid']) && intval($_GET['catid']) ? intval($_GET['catid']) : showmessage(L('please_select_cat'), HTTP_REFERER);
  395. $type = isset($_GET['type']) ? trim($_GET['type']) : '';
  396. include dirname(__FILE__).DIRECTORY_SEPARATOR.'spider_funs'.DIRECTORY_SEPARATOR.'config.php';
  397. //读取栏目缓存
  398. $catlist = getcache('category_content_'.$this->siteid, 'commons');
  399. $cat = $catlist[$catid];
  400. $cat['setting'] = string2array($cat['setting']);
  401. if ($cat['siteid'] != $this->get_siteid() || $cat['type'] != 0) showmessage(L('illegal_section_parameter'), HTTP_REFERER);
  402. if (isset($_POST['dosubmit'])) {
  403. $config = array();
  404. $model_field = isset($_POST['model_field']) ? $_POST['model_field'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  405. $node_field = isset($_POST['node_field']) ? $_POST['node_field'] : showmessage(L('illegal_parameters'), HTTP_REFERER);
  406. $funcs = isset($_POST['funcs']) ? $_POST['funcs'] : array();
  407. $config['add_introduce'] = isset($_POST['add_introduce']) && intval($_POST['add_introduce']) ? intval($_POST['add_introduce']) : 0;
  408. $config['auto_thumb'] = isset($_POST['auto_thumb']) && intval($_POST['auto_thumb']) ? intval($_POST['auto_thumb']) : 0;
  409. $config['introcude_length'] = isset($_POST['introcude_length']) && intval($_POST['introcude_length']) ? intval($_POST['introcude_length']) : 0;
  410. $config['auto_thumb_no'] = isset($_POST['auto_thumb_no']) && intval($_POST['auto_thumb_no']) ? intval($_POST['auto_thumb_no']) : 0;
  411. $config['content_status'] = isset($_POST['content_status']) && intval($_POST['content_status']) ? intval($_POST['content_status']) : 1;
  412. foreach ($node_field as $k => $v) {
  413. if (empty($v)) continue;
  414. $config['map'][$model_field[$k]] = $v;
  415. }
  416. foreach ($funcs as $k=>$v) {
  417. if (empty($v)) continue;
  418. $config['funcs'][$model_field[$k]] = $v;
  419. }
  420. $data = array('config'=>array2string($config), 'siteid'=>$this->get_siteid(), 'nodeid'=>$nodeid, 'modelid'=>$cat['modelid'], 'catid'=>$catid);
  421. $program_db = pc_base::load_model('collection_program_model');
  422. if ($id = $program_db->insert($data, true)) {
  423. showmessage(L('program_add_operation_success'), '?m=collection&c=node&a=import_content&programid='.$id.'&nodeid='.$nodeid.'&ids='.$ids.'&type='.$type);
  424. } else {
  425. showmessage(L('illegal_parameters'));
  426. }
  427. }
  428. //读取数据模型缓存
  429. $model = getcache('model_field_'.$cat['modelid'], 'model');
  430. if (empty($model)) showmessage(L('model_does_not_exist_please_update_the_cache_model'));
  431. $node_data = $this->db->get_one(array('nodeid'=>$nodeid), "customize_config");
  432. $node_data['customize_config'] = string2array($node_data['customize_config']);
  433. $node_field = array(''=>L('please_choose'),'title'=>L('title'), 'author'=>L('author'), 'comeform'=>L('comeform'), 'time'=>L('time'), 'content'=>L('content'));
  434. if (is_array($node_data['customize_config'])) foreach ($node_data['customize_config'] as $k=>$v) {
  435. if (empty($v['en_name']) || empty($v['name'])) continue;
  436. $node_field[$v['en_name']] = $v['name'];
  437. }
  438. $show_header = true;
  439. include $this->admin_tpl('import_program_add');
  440. }
  441. public function import_program_del() {
  442. $id = isset($_GET['id']) ? intval($_GET['id']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  443. $program_db = pc_base::load_model('collection_program_model');
  444. if ($program_db->delete(array('id'=>$id))) {
  445. showmessage(L('operation_success'), HTTP_REFERER);
  446. } else {
  447. showmessage(L('illegal_parameters'));
  448. }
  449. }
  450. //导入文章到模型
  451. public function import_content() {
  452. $nodeid = isset($_GET['nodeid']) ? intval($_GET['nodeid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  453. $programid = isset($_GET['programid']) ? intval($_GET['programid']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
  454. $ids = isset($_GET['ids']) ? $_GET['ids'] : '';
  455. $type = isset($_GET['type']) ? trim($_GET['type']) : '';
  456. if (!$node = $this->db->get_one(array('nodeid'=>$nodeid), 'coll_order,content_page')) {
  457. showmessage(L('node_not_found'), '?m=collection&c=node&a=manage');
  458. }
  459. $program_db = pc_base::load_model('collection_program_model');
  460. $collection_content_db = pc_base::load_model('collection_content_model');
  461. $content_db = pc_base::load_model('content_model');
  462. //更新附件状态
  463. $attach_status = false;
  464. if(pc_base::load_config('system','attachment_stat')) {
  465. $attachment_db = pc_base::load_model('attachment_model');
  466. $att_index_db = pc_base::load_model('attachment_index_model');
  467. $attach_status = true;
  468. }
  469. $order = $node['coll_order'] == 1 ? 'id desc' : '';
  470. $str = L('operation_success');
  471. $url = '?m=collection&c=node&a=publist&nodeid='.$nodeid.'&status=2&pc_hash='.$_SESSION['pc_hash'];
  472. if ($type == 'all') {
  473. $total = isset($_GET['total']) && intval($_GET['total']) ? intval($_GET['total']) : '';
  474. if (empty($total)) $total = $collection_content_db->count(array('siteid'=>$this->get_siteid(), 'nodeid'=>$nodeid, 'status'=>1));
  475. $total_page = ceil($total/20);
  476. $page = isset($_GET['page']) && intval($_GET['page']) ? intval($_GET['page']) : 1;
  477. $total_page = ceil($total/20);
  478. $data = $collection_content_db->select(array('siteid'=>$this->get_siteid(), 'nodeid'=>$nodeid, 'status'=>1), 'id, data', '20', $order);
  479. } else {
  480. $ids = explode(',', $ids);
  481. $ids = implode('\',\'', $ids);
  482. $data = $collection_content_db->select("siteid='".$this->get_siteid()."' AND id in ('$ids') AND nodeid = '$nodeid' AND status = '1'", 'id, data', '', $order);
  483. $total = count($data);
  484. $str = L('operation_success').$total.L('article_was_imported');
  485. }
  486. $program = $program_db->get_one(array('id'=>$programid));
  487. $program['config'] = string2array($program['config']);
  488. $_POST['add_introduce'] = $program['config']['add_introduce'];
  489. $_POST['introcude_length'] = $program['config']['introcude_length'];
  490. $_POST['auto_thumb'] = $program['config']['auto_thumb'];
  491. $_POST['auto_thumb_no'] = $program['config']['auto_thumb_no'];
  492. $_POST['spider_img'] = 0;
  493. $i = 0;
  494. $content_db->set_model($program['modelid']);
  495. $coll_contentid = array();
  496. //加载所有的处理函数
  497. $funcs_file_list = glob(dirname(__FILE__).DIRECTORY_SEPARATOR.'spider_funs'.DIRECTORY_SEPARATOR.'*.php');
  498. foreach ($funcs_file_list as $v) {
  499. include $v;
  500. }
  501. foreach ($data as $k=>$v) {
  502. $sql = array('catid'=>$program['catid'], 'status'=>$program['config']['content_status']);
  503. $v['data'] = string2array($v['data']);
  504. foreach ($program['config']['map'] as $a=>$b) {
  505. if (isset($program['config']['funcs'][$a]) && function_exists($program['config']['funcs'][$a])) {
  506. $GLOBALS['field'] = $a;
  507. $sql[$a] = $program['config']['funcs'][$a]($v['data'][$b]);
  508. } else {
  509. $sql[$a] = $v['data'][$b];
  510. }
  511. }
  512. if ($node['content_page'] == 1) $sql['paginationtype'] = 2;
  513. $contentid = $content_db->add_content($sql, 1);
  514. if ($contentid) {
  515. $coll_contentid[] = $v['id'];
  516. $i++;
  517. //更新附件状态,将采集关联重置到内容关联
  518. if($attach_status) {
  519. $datas = $att_index_db->select(array('keyid'=>'cj-'.$v['id']),'*',100,'','','aid');
  520. if(!empty($datas)) {
  521. $datas = array_keys($datas);
  522. $datas = implode(',',$datas);
  523. $att_index_db->update(array('keyid'=>'c-'.$program['catid'].'-'.$contentid),array('keyid'=>'cj-'.$v['id']));
  524. $attachment_db->update(array('module'=>'content')," aid IN ($datas)");
  525. }
  526. }
  527. } else {
  528. $collection_content_db->delete(array('id'=>$v['id']));
  529. }
  530. }
  531. $sql_id = implode('\',\'', $coll_contentid);
  532. $collection_content_db->update(array('status'=>2), " id IN ('$sql_id')");
  533. if ($type == 'all' && $total_page > $page) {
  534. $str = L('are_imported_the_import_process').(($page-1)*20+$i).'/'.$total.'<script type="text/javascript">location.href="?m=collection&c=node&a=import_content&nodeid='.$nodeid.'&programid='.$programid.'&type=all&page='.($page+1).'&total='.$total.'&pc_hash='.$_SESSION['pc_hash'].'"</script>';
  535. $url = '';
  536. }
  537. showmessage($str, $url);
  538. }
  539. }
  540. ?>