<?php
/**
* 百度站长工具 链接提交
* 发布、更新文章后,自动提交百度链接更新
* 详情请查看 http://dwz.cn/265Rcs
*
* @package BaiduLinkSubmit
* @author 朱纯树
* @version 1.0.0
* @link https://sirblog.cn
*/
class BaiduLinkSubmit implements Typecho_Plugin_Interface {
/* 激活插件方法 */
public static function activate(){
Typecho_Plugin::factory('Widget_Contents_Post_Edit')->finishPublish = array(__CLASS__, 'render');
Typecho_Plugin::factory('Widget_Contents_Page_Edit')->finishPublish = array(__CLASS__, 'render');
return _t('请设置 <b>站点域名</b> 和 <b>密钥</b>');
}
/* 禁用插件方法 */
public static function deactivate(){}
/* 插件配置方法 */
public static function config(Typecho_Widget_Helper_Form $form){
preg_match("/^(http(s)?:\/\/)?([^\/]+)/i", Helper::options()->siteUrl, $matches);
$domain = $matches[2] ? $matches[2] : '';
$site = new Typecho_Widget_Helper_Form_Element_Text('site', NULL, $domain, _t('站点域名'), _t('站长工具中添加的域名'));
$form->addInput($site->addRule('required', _t('请填写站点域名')));
$token = new Typecho_Widget_Helper_Form_Element_Text('token', NULL, '', _t('准入密钥'), _t('更新密钥后,请同步修改此处密钥,否则身份校验不通过将导致数据发送失败。'));
$form->addInput($token->addRule('required', _t('请填写准入密钥')));
}
/* 个人用户的配置方法 */
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
/* 插件实现方法 */
public static function render($contents, $widget){
$options = Helper::options();
$site = $options->plugin(__CLASS__)->site;
$token = $options->plugin(__CLASS__)->token;
$urls = array( $widget->permalink );
$api = sprintf('http://data.zz.baidu.com/urls?site=%s&token=%s', $site, $token);
$client = Typecho_Http_Client::get();
if ($client) {
$client->setData( implode(PHP_EOL, $urls ) )
->setHeader('Content-Type', 'text/plain')
->setTimeout(30)
->send($api);
$status = $client->getResponseStatus();
$rs = $client->getResponseBody();
return true;
}
return false;
}
}
下载地址:
此处内容需要评论回复后(审核通过)方可阅读。
插件上传解压到插件文件夹plugins,填入域名和token密匙即可
如果你需要神马自动推送插件,请阅读下面的文章
插件设计代码:<?php /** * <strong style="color:red;...
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有