国内流行的内容管理系统(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.

189 lines
7.0KB

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