本文简单介绍一个帝国cms7.0实现微博群发的插件,该插件可支持28个微博平台支持定时发布。具体步骤如下:
一、使用说明:
1、该函数由微博通wordpress插件修改而来。可以实现群发微博功能,前提条件是你在各大微博都有注册。可以实现定时发布。
定时发的时候"发布微博"选空。
2、升级以后批量更新不会群发微博,修改文章的时候选1为发布微博,0为不发布,定时发布的时候选空。
3、插件如果是在UTF-8的编码下使用需要改代码,如果单纯复制使用只适合GBK版本。
二、操作方法:
1、首先在帝国CMS后台新建一个字段,注:初始值是3个值:0为不发布;1为发布;空未审核。
字段名:"weibo"
字段标识:"发布微博"
初始值:
0:default
1
(空也就是回车)
2、将以下函数放入userfun.php中 。
复制代码
代码如下:
//---------------------------微博发布函数
function send_to_wbto($id) {
global $empire,$dbtbpre,$public_r,$navinfor ;
$rr = $empire->fetch1("select * from {$dbtbpre}ecms_news_data_1,{$dbtbpre}ecms_news where {$dbtbpre}ecms_news_data_1.id = '".$id."' and {$dbtbpre}ecms_news_data_1.id = {$dbtbpre}ecms_news.id limit 1");
$title = $rr[title] ;
$content =esub(strip_tags($rr[smalltext]),200);
$url = $rr[titleurl] ;
$title1 = $title.'//'.$content.$rr[titleurl];
preg_match_all('/]+src=['"](http[^'"]+)['"].*>/isU',$rr[newstext], $image);//匹配图像格式
$p_sum = count($image[1]);
if ($p_sum > 0) {
$p = $image[1][0];
}
if (!$p) {
$p = $rr[titlepic];
}
$username = 'xxxxx';
$password = 'xxxxx';
$image_url = $p;
$title1 = iconv('GB2312', 'UTF-8',$title1); //将字符串的编码从GB2312转到UTF-8,如果是UTF-8段代码可以注释掉
$fields = array();
$fields['source'] = 'wordpress';
$fields['content'] = urlencode($title1); //
$ch = curl_init();
if ($image_url) {
$fields['imgurl'] =$image_url;
curl_setopt($ch, CURLOPT_URL, "http://wbto.cn/api/upload.json");
} else {
curl_setopt($ch, CURLOPT_URL, "http://wbto.cn/api/update.json");
}
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($ch);
curl_close($ch);
}
?>
function send_to_wbto($id) {
global $empire,$dbtbpre,$public_r,$navinfor ;
$rr = $empire->fetch1("select * from {$dbtbpre}ecms_news_data_1,{$dbtbpre}ecms_news where {$dbtbpre}ecms_news_data_1.id = '".$id."' and {$dbtbpre}ecms_news_data_1.id = {$dbtbpre}ecms_news.id limit 1");
$title = $rr[title] ;
$content =esub(strip_tags($rr[smalltext]),200);
$url = $rr[titleurl] ;
$title1 = $title.'//'.$content.$rr[titleurl];
preg_match_all('/]+src=['"](http[^'"]+)['"].*>/isU',$rr[newstext], $image);//匹配图像格式
$p_sum = count($image[1]);
if ($p_sum > 0) {
$p = $image[1][0];
}
if (!$p) {
$p = $rr[titlepic];
}
$username = 'xxxxx';
$password = 'xxxxx';
$image_url = $p;
$title1 = iconv('GB2312', 'UTF-8',$title1); //将字符串的编码从GB2312转到UTF-8,如果是UTF-8段代码可以注释掉
$fields = array();
$fields['source'] = 'wordpress';
$fields['content'] = urlencode($title1); //
$ch = curl_init();
if ($image_url) {
$fields['imgurl'] =$image_url;
curl_setopt($ch, CURLOPT_URL, "http://wbto.cn/api/upload.json");
} else {
curl_setopt($ch, CURLOPT_URL, "http://wbto.cn/api/update.json");
}
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($ch);
curl_close($ch);
}
?>
3、建一个公共变量"weibo_se"
复制代码
代码如下:
$rrr2 = $empire->fetch1(" select * from {$dbtbpre}ecms_news where id='".$navinfor['id']."' limit 1 ");
$sql = $empire->query1(" UPDATE {$dbtbpre}ecms_news set weibo='0' where id='".$navinfor['id']."' ");
if(function_exists('send_to_wbto') ) {
if($rrr2['weibo']=='1'||$rrr2['weibo']=='' ){
send_to_wbto($navinfor['id']) ;
}
}
?>
$sql = $empire->query1(" UPDATE {$dbtbpre}ecms_news set weibo='0' where id='".$navinfor['id']."' ");
if(function_exists('send_to_wbto') ) {
if($rrr2['weibo']=='1'||$rrr2['weibo']=='' ){
send_to_wbto($navinfor['id']) ;
}
}
?>
4、[!--temp.weibo_se--]放入内容模板中即可。