请高手多指教指教哦wordpress 快速入库的程序
时间:2008-05-01
来源:互联网
请高手多指教指教哦
来源:http://www.zeusion.com
来源:http://www.zeusion.com
复制PHP内容到剪贴板
<?php
/**
* **************wordpress 2.5.0快速入库的程序*******************
*
* **********************主要功能*******************************
* 1.批量添加分类
* 2.批量添加标签
* 3.批量处理分类标签urlslug
*
* ********************后期功能预览*****************************
* 1.url 对搜索引擎友好话处理
* 2.文章内容 对搜索引擎友好话处理
* 3.增加自定义标签处理
*
* ***********************关于*********************************
* 作者 zeusion [url=http://www.zeusion.com]www.zeusion.com[/url]
* 转载请注明出处 [url=http://www.zeusion.com]http://www.zeusion.com[/url]
*
* ***********************版本*********************************
* 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();
[ 本帖最后由 zeusion 于 2008-5-1 09:31 编辑 ] PHP代码:
<?php
/**
* **************wordpress 2.5.0快速入库的程序*******************
*
* **********************主要功能*******************************
* 1.批量添加分类
* 2.批量添加标签
* 3.批量处理分类标签urlslug
*
* ********************后期功能预览*****************************
* 1.url 对搜索引擎友好话处理
* 2.文章内容 对搜索引擎友好话处理
* 3.增加自定义标签处理
*
* ***********************关于*********************************
* 作者 zeusion [url=http://www.zeusion.com]www.zeusion.com[/url]
* 转载请注明出处 [url=http://www.zeusion.com]http://www.zeusion.com[/url]
*
* ***********************版本*********************************
* 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();
作者: zeusion 发布时间: 2008-05-01

作者: 125231896 发布时间: 2008-05-01
大家给点意见啊
作者: zeusion 发布时间: 2008-05-05
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28