<?php
$post_author_default = 1;
$post_status = 'draft'; //发布状态:publish立即发布; pending 审核; draft 草稿箱
$time_interval = 1; //作者id
$post_next = 'now';
$post_ping = false;
$translate_slug = false;
$secretWord = '123123';//接口密码,可自行修改,保持与火车采集器发布模块的全局变量一致!
$checkTitle = true;
$postformat = false;
//接口作者:https://xianyupai.taobao.com/
if(isset($_GET['action'])){
$hm_action=$_GET['action'];
}else{
die("操作被禁止>");
}
include_once "./wp-config.php";
if($post_ping) require_once("./wp-includes/comment.php");
extract($_POST);
if($hm_action== "list"){
hm_print_catogary_list();
}elseif($hm_action== "update"){
hm_publish_pending_post();
}elseif($hm_action == "save"){
//检查通讯密码
if (isset($secretWord)&&($secretWord!=false)) {
if (!isset($_GET['secret']) || $_GET['secret'] != $secretWord) {
die('接口密码错误,请修改配置文件或者修改发布参数,保持两者统一。');
}
}
//判断标题是否为空
if ($post_title=='[标题]'||$post_title=='') {die('标题为空');}
//检查标题是否重复
if($checkTitle){
$post_title = trim(hm_strip_slashes($post_title));
$sql = "SELECT `ID` FROM $wpdb->posts WHERE `post_title` = '$post_title'";
$t_row = $wpdb->query($sql);
echo $t_row;
if($t_row) {die('标题重复,发布成功');};
}
//判断标题是否为空
if ($post_content=='[内容]'||$post_content=='') {die('内容为空');}
//检查自定义文章类型
if (empty($post_type) || strpos($post_type, '[') || strpos($post_type, ']')) {$post_type='post';}
//检查自定义分类目录
if (empty($post_taxonomy) || strpos($post_taxonomy, '[') || strpos($post_taxonomy, ']')) {$post_taxonomy='category';}
//检查分类描述是否未设置
if (empty($category_description) || strpos($category_description, '[') || strpos($category_description, ']')) {$category_description='';}
//检查自定义字段
if(array_key_exists('post_meta', $post)){$post_meta = $post['post_meta'];}
//检查自定义分类信息
if(array_key_exists('post_cate_meta', $post)){$post_cate_meta = $post['post_cate_meta'];}
//检查发布时间
if (!isset($post_date) ||strlen($post_date)<8) $post_date=false;
//检查作者
if (empty($post_author)) {
$post_author=$post_author_default;
} else {
$post_author=hm_add_author($post_author);
}
$post_content = fileHandle('fujian',$post_content);
fileHandle('thumb');
hm_do_save_post(array('post_title'=>$post_title,
'post_content'=>$post_content,
'post_category'=>$post_category,
'post_excerpt'=>$post_excerpt,
'post_type'=>$post_type,
'post_taxonomy'=>$post_taxonomy,
'tags_input'=>$tag,
'post_date'=>$post_date,
'post_author'=>$post_author,
'fujianid'=>$fujianid));
echo '发布成功';
}else{
echo '非法操作['.$hm_action.']';
}
//附件处理
//$filename 附件名称
//$content 标签内容,为空返回首张图片ID
function fileHandle($filesnames, $content = null)
{
global $thumbid;
if (!empty($_FILES[$filesnames.'0']['name'])) {
require_once('./wp-load.php');
require_once('./wp-admin/includes/file.php');
require_once('./wp-admin/includes/image.php');
$i = 0;
while (isset($_FILES[$filesnames.$i])) {
$fujian[$i] = $_FILES[$filesnames.$i];
$filename = $fujian[$i]['name'];
$fileExt=array_pop(explode(".", $filename));
//附件保存格式【时间】
$upFileTime=date("YmdHis");
//更改上传文件的文件名为时间+随机数+后缀
$fujian[$i]['name'] = $upFileTime."-".uniqid().".".$fileExt;
$uploaded_file = wp_handle_upload($fujian[$i], array('test_form' => false));
$content = str_replace("\'".$filename."\'", "\"".$uploaded_file[url]."\"", $content);
$content = str_replace($filename, $uploaded_file[url], $content);
if (isset($uploaded_file['error'])) {
echo "文件上传失败";
wp_die($uploaded_file['error']);
}
$file = $uploaded_file['file'];
$new_file = iconv('GBK', 'UTF-8', $file);
$url = iconv('GBK', 'UTF-8', $uploaded_file['url']);
$type = $uploaded_file['type'];
$attachment = array(
'guid' => $url,
'post_mime_type' => $type,
'post_title' => $filename,
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment($attachment, $new_file);
if (strpos($fujian[$i]['type'], 'image') !== false) {
if(empty($thumbid) || $filesnames == 'thumb') $thumbid = $attach_id;
$attach_data = wp_generate_attachment_metadata($attach_id, $file);
$attach_data['file'] = iconv('GBK', 'UTF-8', $attach_data['file']);
foreach ($attach_data['sizes'] as $key => $sizes) {
$sizes['file'] = iconv('GBK', 'UTF-8', $sizes['file']);
$attach_data['sizes'][$key]['file'] = $sizes['file'];
}
wp_update_attachment_metadata($attach_id, $attach_data);
}
$i++;
}
}
return $content;
}
function hm_tranlate($text)
{
global $translate_slug;
$pattern = '/[^\x00-\x80]/';
if (preg_match($pattern,$text)) {
$htmlret = substr(md5($text),0,$translate_slug);
} else {
$htmlret = $text;
}
return $htmlret;
}
function hm_print_catogary_list()
{
$cats = get_categories("hierarchical=0&hide_empty=0");
foreach ((array) $cats as $cat) {
echo '<<<'.$cat->cat_ID.'--'.$cat->cat_name.'>>>';
}
}
function hm_get_post_time($post_next="normal")
{
global $time_interval;
global $wpdb;
$time_difference = absint(get_option('gmt_offset')) * 3600;
$tm_now = time()+$time_difference;
if ($post_next=='now') {
$tm=time()+$time_difference;
} else { //if ($post_next=='next')
$tm = time()+$time_difference;
$posts = $wpdb->get_results( "SELECT post_date FROM $wpdb->posts ORDER BY post_date DESC limit 0,1" );
foreach ( $posts as $post ) {
$tm=strtotime($post->post_date);
}
}
return $tm+$time_interval;
}
function hm_publish_pending_post()
{
global $wpdb;
$tm_now = time()+absint(get_option('gmt_offset')) * 3600;
$now_date=date("Y-m-d H:i:s",$tm_now);
$wpdb->get_results( "UPDATE $wpdb->posts set `post_status`='draft' WHERE `post_status`='draft' and `post_date`<'$now_date'" );
}
function hm_add_category($post_category, $post_taxonomy = 'category')
{
if (!function_exists('wp_insert_category')) {include_once "./wp-admin/includes/taxonomy.php";}
global $wpdb,$post_cate_meta,$post_parent_cate,$category_description;
$post_category_new=array();
$post_category_list= array_unique(explode(",", $post_category));
foreach ($post_category_list as $category) {
$cat_ID =$category;
if (!isInteger($cat_ID) || $cat_ID < 1) {
$category = $wpdb->escape($category);
$term = get_term_by('name',$category,$post_taxonomy,'ARRAY_A');
$cat_ID = $term['term_id'];
if($cat_ID == 0){
//检查父分类是否存在和创建父分类->start
if(!empty($post_pare
WordPressc,发布到后台草稿箱
需积分: 9 132 浏览量
2022-07-21
13:14:50
上传
评论
收藏 16KB ZIP 举报
lzw小白
- 粉丝: 1
- 资源: 6
最新资源
- 成都市地图含高新区(高新南区,高新西区),天府新区,东部新区虚拟行政区划
- XILINXFPGA源码XilinxEDK设计试验
- XILINXFPGA源码XilinxEDKMicroBlaze内置USB固件程序
- 基于 django 的视频点播后台管理系统源代码+数据库
- 基于Java的网上医院预约挂号系统的设计与实现(部署视频)-kaic.mp4
- 新建项目opengrok
- XILINXFPGA源码XilinxDDR3最新VHDL代码(通过调试)
- XILINXFPGA源码XilinxDDR2存储器接口调试代码
- 班级事务管理系统设计与实现(部署视频)-kaic.mp4
- excel带下拉框展示(动态展示)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0