国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
6.9KB

  1. <?php
  2. /**
  3. * 采集规则添加
  4. *
  5. * @version $Id: co_add.php 1 14:31 2010年7月12日Z tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__) . "/config.php");
  12. CheckPurview('co_AddNote');
  13. if (empty($step)) $step = "";
  14. if (empty($exrule)) $exrule = "";
  15. //选择操作频道类型,载入表单
  16. /*----------------------
  17. function Init(){ }
  18. ----------------------*/
  19. if (empty($step)) {
  20. require_once(DEDEADMIN . "/templets/co_add_step0.htm");
  21. exit();
  22. } else if ($step == 1) {
  23. require_once(DEDEADMIN . "/templets/co_add_step1.htm");
  24. exit();
  25. }
  26. //保存索引规则
  27. /*----------------------
  28. function Save_List(){ }
  29. ----------------------*/ else if ($step == 2) {
  30. //对完整规则进行测试
  31. if ($dopost == 'test') {
  32. include(DEDEINC . "/dedecollection.class.php");
  33. $usemore = (!isset($usemore) ? 0 : 1);
  34. $listconfig = "{dede:noteinfo notename=\\\"$notename\\\" channelid=\\\"$channelid\\\" macthtype=\\\"$macthtype\\\"
  35. refurl=\\\"$refurl\\\" sourcelang=\\\"$sourcelang\\\" cosort=\\\"$cosort\\\" isref=\\\"$isref\\\" exptime=\\\"$exptime\\\" usemore=\\\"$usemore\\\" /}
  36. {dede:listrule sourcetype=\\\"$sourcetype\\\" rssurl=\\\"$rssurl\\\" regxurl=\\\"$regxurl\\\"
  37. startid=\\\"$startid\\\" endid=\\\"$endid\\\" addv=\\\"$addv\\\" urlrule=\\\"$urlrule\\\"
  38. musthas=\\\"$musthas\\\" nothas=\\\"$nothas\\\" listpic=\\\"$listpic\\\" usemore=\\\"$usemore\\\"}
  39. {dede:addurls}$addurls{/dede:addurls}
  40. {dede:batchrule}$batchrule{/dede:batchrule}
  41. {dede:regxrule}$regxrule{/dede:regxrule}
  42. {dede:areastart}$areastart{/dede:areastart}
  43. {dede:areaend}$areaend{/dede:areaend}
  44. {/dede:listrule}\r\n";
  45. $tmplistconfig = stripslashes($listconfig);
  46. $notename = stripslashes($notename);
  47. if ($sourcetype == 'rss' && $refurl = '') {
  48. $refurl = $rssurl;
  49. }
  50. $refurl = stripslashes($refurl);
  51. $errmsg = '';
  52. $freq = empty($freq) ? "" : $freq;
  53. $extypeid = empty($freq) ? "" : $extypeid;
  54. //测试规则
  55. if ($sourcetype == 'rss') {
  56. $links = GetRssLinks(stripslashes($rssurl));
  57. $demopage = $rssurl;
  58. } else {
  59. $links = array();
  60. $lists = GetUrlFromListRule($regxurl, stripslashes($addurls), $startid, $endid, $addv, $usemore, stripslashes($batchrule));
  61. if (isset($lists[0][0])) {
  62. $demopage = $lists[0][0];
  63. $dc = new DedeCollection();
  64. $dc->LoadListConfig($tmplistconfig);
  65. $listurl = '';
  66. $links = $dc->Testlists($listurl);
  67. $errmsg = $dc->errString;
  68. } else {
  69. $demopage = '没有匹配到适合的列表页!';
  70. }
  71. }
  72. require_once(DEDEADMIN . "/templets/co_add_step1_test.htm");
  73. exit();
  74. }
  75. //从预览并提示进入下一步
  76. else {
  77. $row = $dsql->GetOne("SELECT nid,channelid FROM `#@__co_note` WHERE isok=0 AND notename LIKE '$notename' ");
  78. if (!is_array($row)) {
  79. $uptime = time();
  80. $listconfig = urldecode($listconfig);
  81. $inquery = " INSERT INTO `#@__co_note`(`channelid`,`notename`,`sourcelang`,`uptime`,`cotime`,`pnum`,`isok`,`usemore`,`listconfig`,`itemconfig`)
  82. VALUES ('$channelid','$notename','$sourcelang','$uptime','0','0','0','$usemore','$listconfig',''); ";
  83. $rs = $dsql->ExecuteNoneQuery($inquery);
  84. if (!$rs) {
  85. ShowMsg("保存信息时出现错误!" . $dsql->GetError(), "-1");
  86. exit();
  87. }
  88. $nid = $dsql->GetLastID();
  89. } else {
  90. $channelid = $row['channelid'];
  91. $uptime = time();
  92. if (empty($freq)) $freq = 1;
  93. if (empty($extypeid)) $extypeid = 0;
  94. if (empty($islisten)) $islisten = 0;
  95. $usemore = (!isset($usemore) ? 0 : 1);
  96. $query = " UPDATE `#@__co_note` SET
  97. `channelid`='$channelid',
  98. `notename`='$notename',
  99. `sourcelang`='$sourcelang',
  100. `uptime`='$uptime',
  101. `isok`='1',
  102. `usemore`='$usemore',
  103. `listconfig`='$listconfig' WHERE nid='$nid'; ";
  104. $dsql->ExecuteNoneQuery($query);
  105. $nid = $row['nid'];
  106. }
  107. if (!isset($previewurl)) $previewurl = '';
  108. require_once(DEDEINC . '/dedetag.class.php');
  109. require_once(DEDEADMIN . "/templets/co_add_step2.htm");
  110. exit();
  111. }
  112. }
  113. //保存文章规则
  114. /*----------------------
  115. function Save_Art(){ }
  116. ----------------------*/ else if ($step == 5) {
  117. /*
  118. [previewurl] => ''
  119. */
  120. $itemconfig = "{dede:sppage sptype=\\'$sptype\\' sptype=\\'$sptype\\' srul=\\'$srul\\' erul=\\'$erul\\'}$sppage{/dede:sppage}\r\n";
  121. $itemconfig .= "{dede:previewurl}$previewurl{/dede:previewurl}\r\n";
  122. $itemconfig .= "{dede:keywordtrim}$keywordtrim{/dede:keywordtrim}\r\n";
  123. $itemconfig .= "{dede:descriptiontrim}$descriptiontrim{/dede:descriptiontrim}\r\n";
  124. $fs = explode(',', 'value,match,isunit,isdown,trim,function');
  125. foreach ($fields as $field) {
  126. foreach ($fs as $f) {
  127. $GLOBALS[$f . '_' . $field] = (!isset($GLOBALS[$f . '_' . $field]) ? '' : $GLOBALS[$f . '_' . $field]);
  128. }
  129. $matchstr = $GLOBALS["match_" . $field];
  130. $trimstr = $GLOBALS["trim_" . $field];
  131. $trimstr = trim(str_replace('&nbsp;', '#n#', $trimstr));
  132. $matchstr = trim(str_replace('&nbsp;', '#n#', $matchstr));
  133. if ($trimstr != '' && !preg_match("#{dede:trim#i", $trimstr)) {
  134. $trimstr = " {dede:trim}$trimstr{/dede:trim}\r\n";
  135. }
  136. $itemconfig .= "{dede:item field=\\'" . $field . "\\' value=\\'" . $GLOBALS["value_" . $field] . "\\' isunit=\\'" . $GLOBALS["isunit_" . $field] . "\\' isdown=\\'" . $GLOBALS["isdown_" . $field] . "\\'}
  137. {dede:match}" . $matchstr . "{/dede:match}
  138. $trimstr
  139. {dede:function}" . $GLOBALS["function_" . $field] . "{/dede:function}
  140. {/dede:item}\r\n";
  141. }
  142. $dsql->ExecuteNoneQuery("UPDATE `#@__co_note` SET itemconfig='$itemconfig' WHERE nid='$nid' ");
  143. //echo $dsql->GetError();
  144. require_once(DEDEINC . '/dedecollection.class.php');
  145. require_once(DEDEADMIN . "/templets/co_add_step2_test.htm");
  146. exit();
  147. } else if ($step == 6) {
  148. $dsql->ExecuteNoneQuery("UPDATE `#@__co_note` SET isok='1' WHERE nid='$nid' ");
  149. ShowMsg("成功设置一个规则!", "co_main.php");
  150. exit();
  151. } else if ($step == 7) {
  152. $dsql->ExecuteNoneQuery("UPDATE `#@__co_note` SET isok='1' WHERE nid='$nid' ");
  153. ShowMsg("成功设置一个规则,现在转向采集页面!", "co_gather_start.php?nid=$nid");
  154. exit();
  155. }