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

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

[原创]wordpress 快速入库的程序

[复制链接]
发表于 2008-5-4 15:22:44 | 显示全部楼层 |阅读模式
相信大家知道这个是用来做什么用的
  1. /**
  2. * **************wordpress 2.5.0快速入库的程序*******************
  3. *
  4. * **********************主要功能*******************************
  5. * 1.批量添加分类
  6. * 2.批量添加标签
  7. * 3.批量处理分类标签urlslug
  8. *
  9. * ********************后期功能预览*****************************
  10. * 1.url 对搜索引擎友好话处理
  11. * 2.文章内容 对搜索引擎友好话处理
  12. * 3.增加自定义标签处理
  13. *
  14. * ***********************关于*********************************
  15. * 作者                zeusion           www.zeusion.com
  16. * 转载请注明出处      http://www.zeusion.com
  17. * http://www.zeusion.com/43/wordpr ... e-database-program/
  18. * ***********************版本*********************************
  19. * 2008.4.20  0.1   zeusion
  20. *
  21. */
复制代码


文章来源:
http://www.zeusion.com/43/wordpr ... e-database-program/

[ 本帖最后由 zeusion 于 2008-5-4 15:24 编辑 ]

评分

1

查看全部评分

发表于 2008-5-4 18:42:56 | 显示全部楼层
菜鸟应该不会使用
发表于 2008-5-4 19:03:08 | 显示全部楼层
不错的一个东西,收藏了。
发表于 2008-5-4 22:45:44 | 显示全部楼层
看不懂啊。。哈哈
 楼主| 发表于 2008-5-5 08:55:18 | 显示全部楼层
可以批量的 帮你导入采集来得数据

直接操作数据库的程序


发来这里,给大家提供些方便啊
发表于 2008-5-7 21:24:30 | 显示全部楼层

回复 5楼 的帖子

能指点下不?
发表于 2008-7-11 08:57:50 | 显示全部楼层
可以批量的 帮你导入采集来得数据

直接操作数据库的程序


发来这里,给大家提供些方便啊
发表于 2008-7-11 09:30:36 | 显示全部楼层
域名已过期?
发表于 2008-7-12 20:27:04 | 显示全部楼层
[原创]wordpress 快速入库的程序

字体: 小 中 大 | 打印 发表于: 2008-5-05 10:34    作者: zeusion    来源: 爱我玉田网
* 作者 zeusion www.zeusion.com
* 转载请注明出处 http://www.zeusion.com

CODE:
<?php
/**
* **************wordpress 2.5.0快速入库的程序*******************
*
* **********************主要功能*******************************
* 1.批量添加分类
* 2.批量添加标签
* 3.批量处理分类标签urlslug
*
* ********************后期功能预览*****************************
* 1.url 对搜索引擎友好话处理
* 2.文章内容 对搜索引擎友好话处理
* 3.增加自定义标签处理
*
* ***********************关于*********************************
* 作者 zeusion www.zeusion.com
* 转载请注明出处 http://www.zeusion.com
*
* ***********************版本*********************************
* 2008.4.20 0.1 zeusion
*
*/

include_once('common.inc.php');
class Wordpress {
var $siteurl = 'http://127.0.0.1'; //设置网站的域名
private $_db;
function __construct() {
global $db;
$this->_db = $db;
}
// 批量转换slug
private function name_slug(){

$sql = "SELECT * FROM `wp_terms`";
$rs = $this->_db->query($sql);
while ($rw = $this->_db->fetch_array($rs)) {
$name = urlencode($rw['name']);
$sql2 = "update `wp_terms` set `slug` = '".$name."' where `term_id` = ".$rw['term_id'];
$rs2 = $this->_db->query($sql2);
}
}
/**
* 批量添加分类
*
* @param array $name
* @return array $re
*/
function add_cat($name){

$re =array();
if (is_array($name)) {
$i = 0;
foreach ($name as $v) {
if (!$this->is_here($v)) {
$sql = "INSERT INTO `wp_terms` (`term_id`, `name`, `slug`, `term_group`) VALUES (NULL, '{$v}', '".urlencode($v)."', 0);";
$rs = $this->_db->query($sql);
$num = $this->_db->insert_id();
$re[$i] = $num;
$sql1 = "INSERT INTO `wp_term_taxonomy` (`term_taxonomy_id`, `term_id`, `taxonomy`, `description`, `parent`, `count`) VALUES
(NULL, {$num}, 'category', '', 0, 0)";
$rs = $this->_db->query($sql1);
$i++;
}
}
return $re;
}else {
if (!$this->is_here($name)) {
$sql = "INSERT INTO `wp_terms` (`term_id`, `name`, `slug`, `term_group`) VALUES (NULL, '{$name}', '".urlencode($name)."', 0);";
$rs = $this->_db->query($sql);
$num = $this->_db->insert_id();
$sql1 = "INSERT INTO `wp_term_taxonomy` (`term_taxonomy_id`, `term_id`, `taxonomy`, `description`, `parent`, `count`) VALUES
(NULL, {$num}, 'category', '', 0, 0)";
$rs = $this->_db->query($sql1);
return $num;
}
}
return $num;
}
/**
* 批量添加标签
*
* @param array $name
* @return array $re
*/
function add_tags($name){

$re =array();
if (is_array($name)) {
$i = 0;
foreach ($name as $v) {
if (!$this->is_here($v,'post_tag')) {
$sql = "INSERT INTO `wp_terms` (`term_id`, `name`, `slug`, `term_group`) VALUES (NULL, '{$v}', '".urlencode($v)."', 0);";
$rs = $this->_db->query($sql);
$num = $this->_db->insert_id();
$re[$i] = $num;
$sql1 = "INSERT INTO `wp_term_taxonomy` (`term_taxonomy_id`, `term_id`, `taxonomy`, `description`, `parent`, `count`) VALUES
(NULL, {$num}, 'post_tag', '', 0, 0)";
$rs = $this->_db->query($sql1);
$i++;
}
}
return $re;
}else {

if (!$this->is_here($name,'post_tag')) {
$sql = "INSERT INTO `wp_terms` (`term_id`, `name`, `slug`, `term_group`) VALUES (NULL, '{$name}', '".urlencode($name)."', 0);";
$rs = $this->_db->query($sql);
$num = $this->_db->insert_id();
$sql1 = "INSERT INTO `wp_term_taxonomy` (`term_taxonomy_id`, `term_id`, `taxonomy`, `description`, `parent`, `count`) VALUES
(NULL, {$num}, 'post_tag', '', 0, 0)";
$rs = $this->_db->query($sql1);
return $num;
}
}
}
/**
* 验证一个标签 分类是否存在
*
* @param string $name
* @param string $type
* @return bool
*/
function is_here($name,$type = 'category'){

$sql ="SELECT s.`term_id` FROM `wp_terms` s, `wp_term_taxonomy` y
WHERE s.`name` = '{$name}'
AND y.`taxonomy` = '{$type}'
AND s.`term_id` = y.`term_id`";
$rs = $this->_db->query($sql);
if ($num = $this->_db->affected_rows()) {
return true;
}else {
return false;
}
}
/**
* 添加一个新文章
*
* 示例
* $rw['title'] = 'title';
* $rw['content'] = 'content';
* $rw['tags'] = array('黑色','美丽');
* $rw['category'] = array('黑色1','美丽2');
*
* @param unknown_type $row
*/
function add_post($row){

$time = date("Y-m-d H:i:s",time());
$sql = "INSERT INTO `wp_posts`
(`ID`, `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
(NULL, 1, '{$time}', '{$time}',
'{$row['content']}', '{$row['title']}', 0, '', 'publish', 'open', 'open', '',
'".urlencode($row['title'])."', '', '', '{$time}', '{$time}',
'', 0, '{$siteurl}/wp/?p=3', 0, 'post', '', 0)";
$rs = $this->_db->query($sql);
if ($rs) {
$id = $this->_db->insert_id();
$sql_u = "UPDATE `wp_posts` SET `guid` = '".$siteurl."/wp/?p=".$id."' WHERE `wp_posts`.`ID` ={$id} LIMIT 1 ;";
$this->_db->query($sql_u);
//建立分类关联
$cate = $this->add_cat($row['category']);
if (!empty($cate)) {
$sql = "INSERT INTO `wp_term_relationships` (`object_id`, `term_taxonomy_id`) VALUES ";
if (is_array($cate)) {
foreach ($cate as $v) {
$sql .="({$id}, $v),";
}
}else {
$sql .= "({$id}, $cate),";
}
}

//建立标签关联
$tags = $this->add_tags($row['tags']);
if (!empty($tags)) {
if (is_array($tags)) {
foreach ($tags as $s) {
$sql .="({$id}, $s),";
}
}else {
$sql .= "({$id}, $tags),";
}
$sql = substr($sql,0,-1).";";
$rs = $this->_db->query($sql);
}
return true;
}

}
}
$wp = new Wordpress();
$rw['title'] = 'title';
$rw['content'] = 'content';
$rw['tags'] = array('黑色','美丽');
$rw['category'] = array('黑色1','美丽2');
$wp->add_post($rw);
//$wp->name_slug();
发表于 2008-7-12 20:27:44 | 显示全部楼层
域名过期~
您需要登录后才可以回帖 登录 | 加入会员

本版积分规则

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

GMT+8, 2026-3-31 01:25

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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