maryar 发表于 2008-6-30 20:02:57

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

各位前辈,我想采集内容和评论(回帖),发布的时候按照wordpress的样式,发布内容和评论,不知道要怎么实现?各位前辈请多多指点,谢谢了!

vus520 发表于 2008-6-30 20:40:47

写一个接口入库,或者直接使用SQL入库模块。

maryar 发表于 2008-7-1 10:11:41

写接口对我来说有点难,直接SQL入库可以考虑一下!多谢楼上,如过搞不定就请你帮忙了!

maryar 发表于 2008-7-1 23:12:06

忙了半天,还没搞出来,有点复杂。
我还在继续测试,希望有懂得朋友多多指点,谢谢了!

http://gpssys.cn

Jarvis 发表于 2009-2-16 15:01:46

我是这样做的,采集文章的时候,列出文章标题吧,采评论的时候,也列出文章标题,然后,用php做一个(发布站 站内)模拟搜索的语句,查出发布站内,哪一个URL是评论对应的文章,然后,取这个URL用,然后的事情,就很好办了.
只是思路share-soft.org就是这么干的.

Jarvis 发表于 2009-2-16 15:03:01

好像还没评论,要尽量把文章都发上去,然后才能站内search.
search到文章页,取出地址,才能发评论.

kiss2008 发表于 2009-2-16 22:24:50

本帖最后由 kiss2008 于 2009-2-16 22:27 编辑

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

define('WP_ADMIN', TRUE);

if ( defined('ABSPATH') )
require_once( ABSPATH . 'wp-config.php');
else
    require_once('../wp-config.php');

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



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



//ET增加------
$etuser = wp_signon();
if (is_wp_error($etuser))
{
echo('login error');
exit;
}
$_POST['user_ID']=$etuser->ID;


//------------

/*
auth_redirect();


nocache_headers();

update_category_cache();

$posts_per_page = get_option('posts_per_page');
$what_to_show = get_option('what_to_show');
$date_format = get_option('date_format');
$time_format = get_option('time_format');

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

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

wp_enqueue_script( 'common' );
wp_enqueue_script( 'jquery-color' );

$editing = false;

if (isset($_GET['page'])) {
$plugin_page = stripslashes($_GET['page']);
$plugin_page = plugin_basename($plugin_page);
}

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

do_action('admin_init');

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

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

do_action($page_hook);
} else {
if ( validate_file($plugin_page) ) {
wp_die(__('Invalid plugin page'));
}

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

do_action('load-' . $plugin_page);

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

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

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

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

$importer = $_GET['import'];

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

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

// Allow plugins to define importers as well
if (! is_callable($wp_importers[$importer]))
{
if (! file_exists(ABSPATH . "wp-admin/import/$importer.php"))
{
wp_die(__('Cannot load importer.'));
}
include(ABSPATH . "wp-admin/import/$importer.php");
}

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

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

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

define('WP_IMPORTING', true);

call_user_func($wp_importers[$importer]);

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

exit();
} else {
do_action("load-$pagenow");
}
*/
//替换admin.php结束

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

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

if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write
$_POST['post_ID'] = $draft_ids[$temp_id];
unset($_POST['temp_ID']);
update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
return edit_post();
}
}

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

if (!empty ( $_POST['post_author_override'] ) ) {
$_POST['post_author'] = (int) $_POST['post_author_override'];
} else {
if (!empty ( $_POST['post_author'] ) ) {
$_POST['post_author'] = (int) $_POST['post_author'];
} else {
$_POST['post_author'] = (int) $_POST['user_ID'];
}

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

}
}
*/

// What to do based on which button they pressed
$_POST['post_status'] = 'publish';
/* if ( isset($_POST['saveasdraft']) && '' != $_POST['saveasdraft'] )
$_POST['post_status'] = 'draft';
if ( isset($_POST['saveasprivate']) && '' != $_POST['saveasprivate'] )
$_POST['post_status'] = 'private';
if ( isset($_POST['publish']) && ( '' != $_POST['publish'] ) && ( $_POST['post_status'] != 'private' ) )
$_POST['post_status'] = 'publish';
if ( isset($_POST['advanced']) && '' != $_POST['advanced'] )
$_POST['post_status'] = 'draft';

if ( 'page' == $_POST['post_type'] ) {
if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) )
$_POST['post_status'] = 'pending';
} else {
if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) )
$_POST['post_status'] = 'pending';
}
*/
if (!isset( $_POST['comment_status'] ))
$_POST['comment_status'] = 'closed';

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

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

if (!empty ( $_POST['edit_date'] ) ) {
$aa = $_POST['aa'];
$mm = $_POST['mm'];
$jj = $_POST['jj'];
$hh = $_POST['hh'];
$mn = $_POST['mn'];
$ss = $_POST['ss'];
$jj = ($jj > 31 ) ? 31 : $jj;
$hh = ($hh > 23 ) ? $hh -24 : $hh;
$mn = ($mn > 59 ) ? $mn -60 : $mn;
$ss = ($ss > 59 ) ? $ss -60 : $ss;
$_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
$_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );
}

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

if ( empty($post_ID) )
return 0;

add_meta( $post_ID );

// Reunite any orphaned attachments with their parent
if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
$draft_ids = array();
if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
_relocate_children( $draft_temp_id, $post_ID );
if ( $temp_id && $temp_id != $draft_temp_id )
_relocate_children( $temp_id, $post_ID );

// Update autosave collision detection
if ( $temp_id ) {
$draft_ids[$temp_id] = $post_ID;
update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
}

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

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

return $post_ID;
}


function ETwrite_post() {
$result = ETwp_write_post();
if( is_wp_error( $result ) )
wp_die( $result->get_error_message() );
else
return $result;
}

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

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

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

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

$commentdata = wp_filter_comment($commentdata);

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

$commentdata['comment_approved'] =1;

$comment_ID = wp_insert_comment($commentdata);

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

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

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

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

return $comment_ID;
}

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

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


//$_POST['temp_ID'] = -1 * time();
//$_POST['_wpnonce']=wp_create_nonce('add-post');
$_POST['action']='post';
$_POST['post_type']='post';
$_POST['publish']='publish';
$_POST['advanced_view']=1;
$_POST['post_pingback']=1;
$ETreplay=$_POST['ETreplay'];
$ruser=$_POST['ruser'];
if($ETreplay==1) //ET增加
{ $ETcontents=spliti("<!--content-->", $_POST['content']);
for($i=count($ETcontents)-1;$i >=0; $i--) {
if(trim($ETcontents[$i])==''){
unset($ETcontents[$i]);
}

}
$ETcontents=array_values($ETcontents);
if (count($ETcontents)>0){
$_POST['content']=$ETcontents;
}

}


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



//check_admin_referer('add-post');

$post_ID = ETwrite_post() ;
if (is_numeric($post_ID)){
echo(1);}
else{
echo(0);
exit;}



//回复部分
if($ETreplay!=1){
exit;
}
$comment_post_ID = $post_ID;

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



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

$comment_author=$ETrusers[$user_j];
$comment_content =$ETcontents[$i];

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


$comment_type = '';


if ( '' == $comment_content ) continue;

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

$comment_id = ET_new_comment( $commentdata );



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


}
exit();
?>


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

几点这个文件的说明:
ET做的这个接口是免费的;
支持WP2.5,WP2.51-2.71有待进一步测试是否支持;
不支持TAGS;
评论的IP及时间不能随机或自定义。
文件放到http://您的网址/wp-admin/ETchk.php

6sky 发表于 2009-2-16 23:20:42

就改改ET就好了!
页: [1]
查看完整版本: WordPress采集了内容和评论(回帖),能否同时这样发布?