写了个百度链接主动提交工具,要的拿走吧,不谢
下载地址:BaiduLinkSubmit.v1.0.0.zip
1<?php
2/**
3 * 百度站长工具 链接提交
4 * 发布、更新文章后,自动提交百度链接更新
5 * 详情请查看 http://dwz.cn/265Rcs
6 *
7 * @package BaiduLinkSubmit
8 * @author mrasong
9 * @version 1.0.0
10 * @link http://mrasong.com/a/baidu-link-submit-for-typecho
11 */
12class BaiduLinkSubmit implements Typecho_Plugin_Interface {
13 /* 激活插件方法 */
14 public static function activate(){
15 Typecho_Plugin::factory('Widget_Contents_Post_Edit')->finishPublish = array(__CLASS__, 'render');
16 Typecho_Plugin::factory('Widget_Contents_Page_Edit')->finishPublish = array(__CLASS__, 'render');
17 return _t('请设置 <b>站点域名</b> 和 <b>密钥</b>');
18 }
19
20 /* 禁用插件方法 */
21 public static function deactivate(){}
22
23 /* 插件配置方法 */
24 public static function config(Typecho_Widget_Helper_Form $form){
25 preg_match("/^(http(s)?:\/\/)?([^\/]+)/i", Helper::options()->siteUrl, $matches);
26 $domain = $matches[2] ? $matches[2] : '';
27 $site = new Typecho_Widget_Helper_Form_Element_Text('site', NULL, $domain, _t('站点域名'), _t('站长工具中添加的域名'));
28 $form->addInput($site->addRule('required', _t('请填写站点域名')));
29
30 $token = new Typecho_Widget_Helper_Form_Element_Text('token', NULL, '', _t('准入密钥'), _t('更新密钥后,请同步修改此处密钥,否则身份校验不通过将导致数据发送失败。'));
31 $form->addInput($token->addRule('required', _t('请填写准入密钥')));
32 }
33
34 /* 个人用户的配置方法 */
35 public static function personalConfig(Typecho_Widget_Helper_Form $form){}
36
37 /* 插件实现方法 */
38 public static function render($contents, $widget){
39 $options = Helper::options();
40 $site = $options->plugin(__CLASS__)->site;
41 $token = $options->plugin(__CLASS__)->token;
42
43 $urls = array( $widget->permalink );
44 $api = sprintf('http://data.zz.baidu.com/urls?site=%s&token=%s', $site, $token);
45
46 $client = Typecho_Http_Client::get();
47 if ($client) {
48 $client->setData( implode(PHP_EOL, $urls ) )
49 ->setHeader('Content-Type', 'text/plain')
50 ->setTimeout(30)
51 ->send($api);
52
53 $status = $client->getResponseStatus();
54 $rs = $client->getResponseBody();
55 return true;
56 }
57 return false;
58 }
59}