火车采集器软件交流官方论坛

 找回密码
 加入会员
搜索
火车采集器V9版免费下载火车浏览器 - 可视采集,万能群发,全自动脚本工具
查看: 6494|回复: 7

WordPress采集了内容和评论(回帖),能否同时这样发布?

[复制链接]
发表于 2008-6-30 20:02:57 | 显示全部楼层 |阅读模式
各位前辈,我想采集内容和评论(回帖),发布的时候按照wordpress的样式,发布内容和评论,不知道要怎么实现?各位前辈请多多指点,谢谢了!
发表于 2008-6-30 20:40:47 | 显示全部楼层
写一个接口入库,或者直接使用SQL入库模块。
 楼主| 发表于 2008-7-1 10:11:41 | 显示全部楼层
写接口对我来说有点难,直接SQL入库可以考虑一下!多谢楼上,如过搞不定就请你帮忙了!
 楼主| 发表于 2008-7-1 23:12:06 | 显示全部楼层
忙了半天,还没搞出来,有点复杂。
我还在继续测试,希望有懂得朋友多多指点,谢谢了!

http://gpssys.cn
发表于 2009-2-16 15:01:46 | 显示全部楼层
我是这样做的,采集文章的时候,列出文章标题吧,采评论的时候,也列出文章标题,然后,用php做一个(发布站 站内)模拟搜索的语句,查出发布站内,哪一个URL是评论对应的文章,然后,取这个URL用,然后的事情,就很好办了.
只是思路share-soft.org就是这么干的.
发表于 2009-2-16 15:03:01 | 显示全部楼层
好像还没评论,要尽量把文章都发上去,然后才能站内search.
search到文章页,取出地址,才能发评论.
发表于 2009-2-16 22:24:50 | 显示全部楼层
本帖最后由 kiss2008 于 2009-2-16 22:27 编辑

这是ET关于WP2.5的文章及评论一并发布的接口。
  1. <?php
  2. //require_once('admin.php');
  3. //以下为替换admin.php代码

  4. define('WP_ADMIN', TRUE);

  5. if ( defined('ABSPATH') )
  6. require_once( ABSPATH . 'wp-config.php');
  7. else
  8.     require_once('../wp-config.php');

  9. if ( get_option('db_version') != $wp_db_version ) {
  10. //wp_redirect(get_option('siteurl') . '/wp-admin/upgrade.php?_wp_http_referer=' . urlencode(stripslashes($_SERVER['REQUEST_URI'])));
  11. echo('db_version error');
  12. exit;
  13. }



  14. require_once(ABSPATH . 'wp-admin/includes/admin.php');



  15. //ET增加------
  16. $etuser = wp_signon();
  17. if (is_wp_error($etuser))
  18. {
  19. echo('login error');
  20. exit;
  21. }
  22. $_POST['user_ID']=$etuser->ID;


  23. //------------

  24. /*
  25. auth_redirect();


  26. nocache_headers();

  27. update_category_cache();

  28. $posts_per_page = get_option('posts_per_page');
  29. $what_to_show = get_option('what_to_show');
  30. $date_format = get_option('date_format');
  31. $time_format = get_option('time_format');

  32. wp_reset_vars(array('profile', 'redirect', 'redirect_url', 'a', 'popuptitle', 'popupurl', 'text', 'trackback', 'pingback'));

  33. wp_admin_css_color('classic', __('Classic'), get_option( 'siteurl' ) . "/wp-admin/css/colors-classic.css", array('#07273E', '#14568A', '#D54E21', '#2683AE'));
  34. wp_admin_css_color('fresh', __('Fresh'), get_option( 'siteurl' ) . "/wp-admin/css/colors-fresh.css", array('#464646', '#CEE1EF', '#D54E21', '#2683AE'));

  35. wp_enqueue_script( 'common' );
  36. wp_enqueue_script( 'jquery-color' );

  37. $editing = false;

  38. if (isset($_GET['page'])) {
  39. $plugin_page = stripslashes($_GET['page']);
  40. $plugin_page = plugin_basename($plugin_page);
  41. }

  42. require(ABSPATH . 'wp-admin/menu.php');

  43. do_action('admin_init');

  44. // Handle plugin admin pages.
  45. if (isset($plugin_page)) {
  46. $page_hook = get_plugin_page_hook($plugin_page, $pagenow);

  47. if ( $page_hook ) {
  48. do_action('load-' . $page_hook);
  49. if (! isset($_GET['noheader']))
  50. require_once(ABSPATH . 'wp-admin/admin-header.php');

  51. do_action($page_hook);
  52. } else {
  53. if ( validate_file($plugin_page) ) {
  54. wp_die(__('Invalid plugin page'));
  55. }

  56. if (! ( file_exists(ABSPATH . PLUGINDIR . "/$plugin_page") && is_file( ABSPATH . PLUGINDIR . "/$plugin_page") ) )
  57. wp_die(sprintf(__('Cannot load %s.'), htmlentities($plugin_page)));

  58. do_action('load-' . $plugin_page);

  59. if (! isset($_GET['noheader']))
  60. require_once(ABSPATH . 'wp-admin/admin-header.php');

  61. include(ABSPATH . PLUGINDIR . "/$plugin_page");
  62. }

  63. include(ABSPATH . 'wp-admin/admin-footer.php');

  64. exit();
  65. } else if (isset($_GET['import'])) {

  66. $importer = $_GET['import'];

  67. if ( ! current_user_can('import') )
  68. wp_die(__('You are not allowed to import.'));

  69. if ( validate_file($importer) ) {
  70. wp_die(__('Invalid importer.'));
  71. }

  72. // Allow plugins to define importers as well
  73. if (! is_callable($wp_importers[$importer][2]))
  74. {
  75. if (! file_exists(ABSPATH . "wp-admin/import/$importer.php"))
  76. {
  77. wp_die(__('Cannot load importer.'));
  78. }
  79. include(ABSPATH . "wp-admin/import/$importer.php");
  80. }

  81. $parent_file = 'edit.php';
  82. $submenu_file = 'import.php';
  83. $title = __('Import');

  84. if (! isset($_GET['noheader']))
  85. require_once(ABSPATH . 'wp-admin/admin-header.php');

  86. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

  87. define('WP_IMPORTING', true);

  88. call_user_func($wp_importers[$importer][2]);

  89. include(ABSPATH . 'wp-admin/admin-footer.php');

  90. exit();
  91. } else {
  92. do_action("load-$pagenow");
  93. }
  94. */
  95. //替换admin.php结束

  96. //ET增加函数
  97. function ETwp_write_post() {
  98. global $user_ID;
  99. /*
  100. if ( 'page' == $_POST['post_type'] ) {
  101. if ( !current_user_can( 'edit_pages' ) )
  102. return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this blog.' ) );
  103. } else {
  104. if ( !current_user_can( 'edit_posts' ) )
  105. return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) );
  106. }
  107. */

  108. // Check for autosave collisions
  109. $temp_id = false;
  110. if ( isset($_POST['temp_ID']) ) {
  111. $temp_id = (int) $_POST['temp_ID'];
  112. if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
  113. $draft_ids = array();
  114. foreach ( $draft_ids as $temp => $real )
  115. if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then )
  116. unset($draft_ids[$temp]);

  117. if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write
  118. $_POST['post_ID'] = $draft_ids[$temp_id];
  119. unset($_POST['temp_ID']);
  120. update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
  121. return edit_post();
  122. }
  123. }

  124. // Rename.
  125. $_POST['post_content'] = $_POST['content'];
  126. $_POST['post_excerpt'] = $_POST['excerpt'];
  127. $_POST['post_parent'] = isset($_POST['parent_id'])? $_POST['parent_id'] : '';
  128. $_POST['to_ping'] = $_POST['trackback_url'];

  129. if (!empty ( $_POST['post_author_override'] ) ) {
  130. $_POST['post_author'] = (int) $_POST['post_author_override'];
  131. } else {
  132. if (!empty ( $_POST['post_author'] ) ) {
  133. $_POST['post_author'] = (int) $_POST['post_author'];
  134. } else {
  135. $_POST['post_author'] = (int) $_POST['user_ID'];
  136. }

  137. }
  138. /*
  139. if ( $_POST['post_author'] != $_POST['user_ID'] ) {
  140. if ( 'page' == $_POST['post_type'] ) {
  141. if ( !current_user_can( 'edit_others_pages' ) )
  142. return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) );
  143. } else {
  144. if ( !current_user_can( 'edit_others_posts' ) )
  145. return new WP_Error( 'edit_others_posts', __( 'You are not allowed to post as this user.' ) );

  146. }
  147. }
  148. */

  149. // What to do based on which button they pressed
  150. $_POST['post_status'] = 'publish';
  151. /* if ( isset($_POST['saveasdraft']) && '' != $_POST['saveasdraft'] )
  152. $_POST['post_status'] = 'draft';
  153. if ( isset($_POST['saveasprivate']) && '' != $_POST['saveasprivate'] )
  154. $_POST['post_status'] = 'private';
  155. if ( isset($_POST['publish']) && ( '' != $_POST['publish'] ) && ( $_POST['post_status'] != 'private' ) )
  156. $_POST['post_status'] = 'publish';
  157. if ( isset($_POST['advanced']) && '' != $_POST['advanced'] )
  158. $_POST['post_status'] = 'draft';

  159. if ( 'page' == $_POST['post_type'] ) {
  160. if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) )
  161. $_POST['post_status'] = 'pending';
  162. } else {
  163. if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) )
  164. $_POST['post_status'] = 'pending';
  165. }
  166. */
  167. if (!isset( $_POST['comment_status'] ))
  168. $_POST['comment_status'] = 'closed';

  169. if (!isset( $_POST['ping_status'] ))
  170. $_POST['ping_status'] = 'closed';

  171. foreach ( array ('aa', 'mm', 'jj', 'hh', 'mm') as $timeunit ) {
  172. if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
  173. $_POST['edit_date'] = '1';
  174. break;
  175. }
  176. }

  177. if (!empty ( $_POST['edit_date'] ) ) {
  178. $aa = $_POST['aa'];
  179. $mm = $_POST['mm'];
  180. $jj = $_POST['jj'];
  181. $hh = $_POST['hh'];
  182. $mn = $_POST['mn'];
  183. $ss = $_POST['ss'];
  184. $jj = ($jj > 31 ) ? 31 : $jj;
  185. $hh = ($hh > 23 ) ? $hh -24 : $hh;
  186. $mn = ($mn > 59 ) ? $mn -60 : $mn;
  187. $ss = ($ss > 59 ) ? $ss -60 : $ss;
  188. $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
  189. $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );
  190. }

  191. // Create the post.
  192. $post_ID = wp_insert_post( $_POST );
  193. if ( is_wp_error( $post_ID ) )
  194. return $post_ID;

  195. if ( empty($post_ID) )
  196. return 0;

  197. add_meta( $post_ID );

  198. // Reunite any orphaned attachments with their parent
  199. if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
  200. $draft_ids = array();
  201. if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
  202. _relocate_children( $draft_temp_id, $post_ID );
  203. if ( $temp_id && $temp_id != $draft_temp_id )
  204. _relocate_children( $temp_id, $post_ID );

  205. // Update autosave collision detection
  206. if ( $temp_id ) {
  207. $draft_ids[$temp_id] = $post_ID;
  208. update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
  209. }

  210. // Now that we have an ID we can fix any attachment anchor hrefs
  211. _fix_attachment_links( $post_ID );

  212. wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );

  213. return $post_ID;
  214. }


  215. function ETwrite_post() {
  216. $result = ETwp_write_post();
  217. if( is_wp_error( $result ) )
  218. wp_die( $result->get_error_message() );
  219. else
  220. return $result;
  221. }

  222. function ET_new_comment( $commentdata ) {
  223. $commentdata = apply_filters('preprocess_comment', $commentdata);

  224. $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
  225. $commentdata['user_ID']         = (int) $commentdata['user_ID'];

  226. $commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '',$_SERVER['REMOTE_ADDR'] );
  227. $commentdata['comment_agent']     = $_SERVER['HTTP_USER_AGENT'];

  228. $commentdata['comment_date']     = current_time('mysql');
  229. $commentdata['comment_date_gmt'] = current_time('mysql', 1);

  230. $commentdata = wp_filter_comment($commentdata);

  231. //$commentdata['comment_approved'] = wp_allow_comment($commentdata);

  232. $commentdata['comment_approved'] =1;

  233. $comment_ID = wp_insert_comment($commentdata);

  234. do_action('comment_post', $comment_ID, $commentdata['comment_approved']);

  235. if ( 'spam' !== $commentdata['comment_approved'] ) { // If it's spam save it silently for later crunching
  236. if ( '0' == $commentdata['comment_approved'] )
  237. wp_notify_moderator($comment_ID);

  238. $post = &get_post($commentdata['comment_post_ID']); // Don't notify if it's your own comment

  239. if ( get_option('comments_notify') && $commentdata['comment_approved'] && $post->post_author != $commentdata['user_ID'] )
  240. wp_notify_postauthor($comment_ID, $commentdata['comment_type']);
  241. }

  242. return $comment_ID;
  243. }

  244. //ET增加函数结束
  245. //以下修改POST.php

  246. //$parent_file = 'edit.php';
  247. //$submenu_file = 'edit.php';


  248. //$_POST['temp_ID'] = -1 * time();
  249. //$_POST['_wpnonce']=wp_create_nonce('add-post');
  250. $_POST['action']='post';
  251. $_POST['post_type']='post';
  252. $_POST['publish']='publish';
  253. $_POST['advanced_view']=1;
  254. $_POST['post_pingback']=1;
  255. $ETreplay=$_POST['ETreplay'];
  256. $ruser=$_POST['ruser'];
  257. if($ETreplay==1) //ET增加
  258. { $ETcontents=spliti("<!--content-->", $_POST['content']);
  259. for($i=count($ETcontents)-1;$i >=0; $i--) {
  260. if(trim($ETcontents[$i])==''){
  261. unset($ETcontents[$i]);
  262. }

  263. }
  264. $ETcontents=array_values($ETcontents);
  265. if (count($ETcontents)>0){
  266. $_POST['content']=$ETcontents[0];
  267. }

  268. }


  269. wp_reset_vars(array('action', 'safe_mode', 'withcomments', 'posts', 'content', 'edited_post_title', 'comment_error', 'profile', 'trackback_url', 'excerpt', 'showcomments', 'commentstart', 'commentend', 'commentorder'));



  270. //check_admin_referer('add-post');

  271. $post_ID = ETwrite_post() ;
  272. if (is_numeric($post_ID)){
  273. echo(1);}
  274. else{
  275. echo(0);
  276. exit;}



  277. //回复部分
  278. if($ETreplay!=1){
  279. exit;
  280. }
  281. $comment_post_ID = $post_ID;

  282. $ETrusers=explode(",",$ruser);



  283. for($i=1;$i <= count($ETcontents)-1; $i++) {
  284. $user_j=rand(0,count($ETrusers)-1);

  285. $comment_author=$ETrusers[$user_j];
  286. $comment_content =$ETcontents[$i];

  287. //$comment_author       = trim(strip_tags($_POST['author']));
  288. //$comment_author_email = trim($_POST['email']);
  289. //$comment_author_url   = trim($_POST['url']);
  290. //$comment_content      = trim($_POST['comment']);


  291. $comment_type = '';


  292. if ( '' == $comment_content ) continue;

  293. $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');

  294. $comment_id = ET_new_comment( $commentdata );



  295. if($comment_id ){echo(chr(10).'第'.$i.'项回复发布成功');}


  296. }
  297. exit();
  298. ?>

复制代码

希望火车官方尽快把WP的文章及评论接口放出来,造福广大Wordpress爱好者.

几点这个文件的说明:
ET做的这个接口是免费的;
支持WP2.5,WP2.51-2.71有待进一步测试是否支持;
不支持TAGS;
评论的IP及时间不能随机或自定义。
文件放到http://您的网址/wp-admin/ETchk.php
发表于 2009-2-16 23:20:42 | 显示全部楼层
就改改ET就好了!
您需要登录后才可以回帖 登录 | 加入会员

本版积分规则

QQ|手机版|Archiver|火车采集器官方站 ( 皖ICP备06000549 )

GMT+8, 2024-11-22 19:28

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表