//-------------------配置参数结束,以下请勿修改-------------------------
if (isset($_GET['action']))
{
$hm_action=$_GET['action'];
} else
{
die ("操作被禁止>");
}
$post=$_POST;
@$tax_input = $_POST[tax_input];
include "./wp-config.php";
if ( get_magic_quotes_gpc() )
{
$post = array_map('stripslashes_deep', $_POST );
}
if ($post_ping) require_once("./wp-includes/comment.php");
if ( !class_exists("Snoopy") ) require_once ("./wp-includes/class-snoopy.php");
function hm_debug_info($msg)
{
global $logDebugInfo;
if ($logDebugInfo) echo $msg."<br/>\n";
}
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;
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`='publish' WHERE `post_status`='pending' and `post_date`<'$now_date'" );
}
function hm_add_category($post_category)
{
if (!function_exists('wp_insert_category')) @include "./wp-admin/includes/taxonomy.php";
global $wpdb;
$post_category_new=array();
$post_category_list= array_unique(explode(",",$post_category));
foreach ($post_category_list as $category) {
$cat_ID =intval($category);
if ($cat_ID==0) {
$category = $wpdb->escape($category);
$cat_ID = wp_insert_category(array('cat_name' => $category));
$cat_ID = get_category_by_slug($category);
array_push($post_category_new,$cat_ID ->term_id);
} else {
array_push($post_category_new,$cat_ID);
}
}
return $post_category_new;
}
function hm_add_author($post_author)
{
global $wpdb,$post_author_default;
$User_ID =intval($post_author);
if ($User_ID == 0) {
$pattern = '/[^\x00-\x80]/';
if (preg_match($pattern,$post_author)) {
$LoginName = substr(md5($post_author),0,10);
} else {
$LoginName = $post_author;
}
$User_ID = $wpdb->get_col("SELECT ID FROM $wpdb->users WHERE user_login = '$LoginName' ORDER BY ID");
$User_ID = $User_ID[0];
if (empty($User_ID)) {
$website = 'http://'.$_SERVER['HTTP_HOST'];
$userdata = array(
'user_login' => "$LoginName",
'first_name' => $post_author,
'user_nicename' => $post_author,
'display_name' => $post_author,
'nickname' => $post_author,
'user_url' => $website,
'role' => 'contributor',
'user_pass' => NULL);
$User_ID = wp_insert_user( $userdata );
}
$post_author = $User_ID;
} else {
$post_author = $post_author_default;
}
return $post_author;
}
function hm_strip_slashes($str)
{
if (get_magic_quotes_gpc()) {
return stripslashes($str);
} else {
return $str;
}
}
function checkDatetime($str)
{
$format="Y-m-d H:i";
$format1="Y-m-d H:i:s";
$unixTime=strtotime($str);
$checkDate= date($format, $unixTime);
$checkDate1= date($format1, $unixTime);
if ($checkDate==$str or $checkDate1==$str) {
return true;
} else {
return false;
}
}
function hm_do_save_post($post_detail)
{
global $post_author,$post_ping,$post_status,$translate_slug,$autoAddCategory,$post_next,$pViews,$tax_input;
extract($post_detail);
$post_title=trim(hm_strip_slashes($post_title));
$post_name=$post_title;
if ($translate_slug) $post_name=hm_tranlate($post_name);
$post_name=sanitize_title( $post_name);
if ( strlen($post_name) < 2 ) $post_name="";
$post_content=hm_strip_slashes($post_content);
$tags_input=str_replace("|||",",",$tags_input);
if (isset($post_date) && $post_date && checkDatetime($post_date)) {
$tm=strtotime($post_date);
$time_difference = absint(get_option('gmt_offset')) * 3600;
$post_date=date("Y-m-d H:i:s",$tm);
$post_date_gmt = gmdate('Y-m-d H:i:s', $tm-$time_difference);
} else {
$tm=hm_get_post_time($post_next);
$time_difference = absint(get_option('gmt_offset')) * 3600;
$post_date=date("Y-m-d H:i:s",$tm);
$post_date_gmt = gmdate('Y-m-d H:i:s', $tm-$time_difference);
if ($post_status=='next') $post_status='publish';
}
$post_category=hm_add_category($post_category);
$post_data = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_name','tags_input');
$post_data = add_magic_quotes($post_data);
$postID = wp_insert_post($post_data);
if (!empty($fujianid)) {
require_once('./wp-includes/post.php');
set_post_thumbnail($postID,$fujianid);
}
if (!empty($post_meta_list)) {
$post_meta_array= array_unique(explode("|||",$post_meta_list));
foreach ($post_meta_array as $ppm) {
$pp2=explode("$$",$ppm);
if (!empty($pp2[0])&&!empty($pp2[1])) add_post_meta($postID,$pp2[0],$pp2[1],true);
}
}
if (!empty($pViews) && $pViews) add_post_meta($postID,'views',$pViews,true);
if (!empty($tax_input)) {
foreach(array_unique(array_filter($tax_input)) as $key => $value) {
add_post_meta($postID,$key,$value,true);
}
}
if ($post_ping) generic_ping();
}
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('接口密码错误,请修改配置文件或者修改发布参数,保持两者统一。');
}
}
extract($post);
if ($post_title=='[标题]'||$post_title=='') die('标题为空');
if ($post_content=='[内容]'||$post_content=='') die('内容为空');
if ($post_category=='[分类id]'||$post_category=='') die('分类id为空');
if ($tag=='[SY_tag]') {
$tag='';
}
if (!isset($post_date) ||strlen($post_date)<8) $post_date=false;
if (!isset($post_author)) {
$post_author=$post_author_default;
} else {
$post_author=hm_add_author($post_author);
}
if (!isset($post_meta_list)) $post_meta_list="";
/*附件处理*/