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

188 lines
6.9KB

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