Wordpress 2.6-2.7 采集发布解决方案
这个我们是写了一个接口来实现,代码公开,可以自己随意修改。使用请看模块说明。<?php
include "wp-config.php"; //这里是引用原来的数据库文件.
include "mysql.class.php"; //这里是引用数据库类.
$DB = new Mysql(DB_HOST, DB_USER, DB_PASSWORD,DB_NAME);//初始化数据库类
if(isset($_GET['action'])&&$_GET['action'] == "list")
{
$sql="SELECT tt.term_id,tt.term_taxonomy_id,t.name,tt.term_id,t.term_id,tt.taxonomy from ".$table_prefix."terms t,".$table_prefix."term_taxonomy tt where t.term_id=tt.term_id AND tt.taxonomy='category' ";
$query=$DB->query($sql);
while ($config=$DB->fetch_array($query))
{
echo '<<<'.$config['term_id'].'--'.$config['name'].'>>>';
}
}
elseif(isset($_GET['action'])&&$_GET['action'] == "save")
{
$post=$_POST;
extract($post);
($post_title=='[标签:标题]'||$post_title=='')?die('标题为空'):'';
($post_content=='[标签:内容]'||$post_content=='')?die('内容为空'):'';
($post_category=='[分类id]'||$post_category=='')?die('分类id为空'):'';
if($tag=='[标签:SY_tag]'){$tag='';}
$post_date=date("Y-m-d H:i:s");
$tm=time();
$sql="INSERT INTO `".$table_prefix."posts` ( `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_category`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES (1, '$post_date', '$post_date', '$post_content', '$post_title', '$post_category', '$post_excerpt', 'publish', 'open', 'open', '', '$post_name', '', '', '$post_date', '$post_date', '$post_content_filtered', 0, '$guid', '$menu_order', 'post', '$post_mime_type', '$comment_count')";
$query=$DB->query($sql);
$postid=$DB->insert_id($sql);
$sqledit="INSERT INTO `".$table_prefix."postmeta` (post_id ,meta_key ,meta_value ) VALUES ($postid,'_edit_lock','$tm'),($postid,'_edit_last',1)";
$query2=$DB->query($sqledit);
/*自定义字段处理方法
if(!$image=='[标签:缩略]')
{
$sqledit2="INSERT INTO `".$table_prefix."postmeta` (post_id ,meta_key ,meta_value ) VALUES ($postid,'image','$image')";
$qim=$DB->query($sqledit2);
}
*/
$sqlcid="INSERT INTO `".$table_prefix."term_relationships` (object_id ,term_taxonomy_id ) VALUES ($postid,'$cid')";
$cidquery=$DB->query($sqlcid);
if(!$tag=='')
{
$tags= array_unique(explode(",",$tag));
foreach($tags as $var)
{
$ssql="SELECT * from ".$table_prefix."terms where name='$var' ";
$squery=$DB->fetch_one_array($ssql);
if($squery)
{
$tagidss=$DB->fetch_one_array($ssql);
$tagids=$tagidss['term_id'];
$gettagid="SELECT term_taxonomy_id,term_id from ".$table_prefix."term_taxonomy where term_id='$tagids' ";
$gettag=$DB->fetch_one_array($gettagid);
$tagid=$gettag['term_taxonomy_id'];
$sqltag="INSERT INTO `".$table_prefix."term_relationships` (object_id ,term_taxonomy_id ) VALUES ($postid,'$tagid')";
$tagquery=$DB->query($sqltag);
}else{
$uc=urlencode($var);
$addtag="INSERT INTO `".$table_prefix."terms` (name,slug) VALUES ('$var','$uc')";
$addquery=$DB->query($addtag);
$addtagid=$DB->insert_id($addtag);
$addterm="INSERT INTO `".$table_prefix."term_taxonomy` (term_id,taxonomy) VALUES ('$addtagid','post_tag')";
//echo $addtag.$addterm;
$termquery=$DB->query($addterm);
$tagids=$DB->insert_id($addterm);
$sqltag="INSERT INTO `".$table_prefix."term_relationships` (object_id ,term_taxonomy_id ) VALUES ($postid,'$tagids')";
$tagquery=$DB->query($sqltag);
}
}
}
echo '发布成功';
}else{
echo 'rq204告诉你,你没有选择任何的操作。请返回';
}
?>
我先到了支持先再说
3k 嘿嘿,不错哦,推荐大家使用WP,虽然刚被GG K了一站,OH MY GOD 刷不出来分类,是哪里的问题? Thanks a lot. 本帖最后由 kiss2008 于 2008-12-20 19:03 编辑
刷不出来分类,是哪里的问题?
月七月八 发表于 2008-12-20 11:53 http://bbs.locoy.com/images/common/back.gif
找到文件夹locoy里的spl.php文件,修改里面的第二行代码,include "wp-config.php";替换成include "../wp-config.php";即可。(这时可以删除locoy文件夹里的wp-config.php文件了)
感谢rq204的开源精神,赞一个!
顺便问个问题,这个模块是模拟入库还是在线post?如果不是在线post,那能在发布的同时,可以ping吗?(不能ping,大大影响搜索引擎的收录)敬请管理员回答一下。
再次感谢! 不要同时ping,最好能够隔段时间ping 支持先再说 6# kiss2008
这个是将数据post给程序,程序入库。具体ping的话你可以添加上相关代码。 9# rq204
我不懂数据库的代码。rq204,你能帮个忙加个在入库时自动ping的功能代码吗?这个功能实现后,就相当于模拟在线发布了。
先谢了。