Typecho百度SEO插件(浏览页面自动提交给百度)

推荐一个很不错的插件:Typecho百度SEO插件
主要作用于发布文章的时候,会实时推送,而且在用户前端浏览的时候,也会进行百度推送,个人觉得更适合普通推送合适一点
本插件目前有两个功能:
1、发布文章时通过API主动将文章推送给百度
2、用户在前台浏览文章时,会在每个页面底部加载自动提交代码,将当前浏览的页面提交给百度
下载地址:
https://github.com/bluejay21st/Typecho-BaiduSeo
https://github.com/bluejay21st/Typecho-Sitemap
实现思路:
将功能的具体实现注册到对应的调用点。
启用插件后提示用户,要求设置提交接口。
发布文章后获取文章的链接与提交接口,提交数据,若提交失败给出提示。
前台访问触发后,将自动提交的JS代码输出到前台模板。
- 代码如下
-
- * @package BaiduSeo
- * @author 寒冬日志
- * @version 1.0.0
- * @link https://www.cwlog.net/
- */
- class BaiduSeo_Plugin implements Typecho_Plugin_Interface
- {
- /**
- * 激活插件方法,如果激活失败,直接抛出异常
- *
- * @access public
- * @return void
- * @throws Typecho_Plugin_Exception
- */
- public static function activate()
- {
- Typecho_Plugin::factory('Widget_Contents_Post_Edit')->finishPublish = array('BaiduSeo_Plugin', 'publish_push');
- Typecho_Plugin::factory('Widget_Archive')->footer = array('BaiduSeo_Plugin', 'auto_push');
- return _t('请设置接口调用地址');
- }
-
- /**
- * 禁用插件方法,如果禁用失败,直接抛出异常
- *
- * @static
- * @access public
- * @return void
- * @throws Typecho_Plugin_Exception
- */
- public static function deactivate()
- {}
-
- /**
- * 获取插件配置面板
- *
- * @access public
- * @param Typecho_Widget_Helper_Form $form 配置面板
- * @return void
- */
- public static function config(Typecho_Widget_Helper_Form $form)
- {
- $api = new Typecho_Widget_Helper_Form_Element_Text('api', NULL, 'NULL', _t('接口调用地址'), _t('站长工具-普通收录-资源提交-API提交-接口调用地址<br>(格式如下:http://data.zz.baidu.com/urls?site=https://www.cwlog.net&token=xxxxxxxxxxx)'));
- $form->addInput($api->addRule('required', _t('请填写接口调用地址')));
- }
-
- /**
- * 个人用户的配置面板
- *
- * @access public
- * @param Typecho_Widget_Helper_Form $form
- * @return void
- */
- public static function personalConfig(Typecho_Widget_Helper_Form $form)
- {}
-
- /**
- * 发布文章时使用接口推送
- *
- * @access public
- * @return void
- */
- public static function publish_push($content, $edit)
- {
- $api = Typecho_Widget::widget('Widget_Options')->plugin('BaiduSeo')->api;
- if($api === 'NULL' || strpos($api, 'data.zz.baidu.com') !== 7) exit('<script>alert("请为BaiduSeo插件配置正确的接口调用地址");location.href="'.$siteUrl.'/admin/manage-posts.php";</script>');
-
- $db = Typecho_Db::get();
- $siteUrl = Typecho_Widget::widget('Widget_Options')->index;
-
- $content['cid'] = $edit->cid;
- $content['slug'] = $edit->slug;
-
- //获取分类缩略名
- $content['category'] = urlencode(current(Typecho_Common::arrayFlatten($db->fetchAll($db->select()->from('table.metas')
- ->join('table.relationships', 'table.relationships.mid = table.metas.mid')
- ->where('table.relationships.cid = ?', $content['cid'])
- ->where('table.metas.type = ?', 'category')
- ->order('table.metas.order', Typecho_Db::SORT_ASC)), 'slug')));
-
- //获取并格式化文章创建时间
- $content['created'] = $edit->created;
- $created = new Typecho_Date($content['created']);
- $content['year'] = $created->year; $content['month'] = $created->month; $content['day'] = $created->day;
-
- //生成URL
- $url = Typecho_Common::url(Typecho_Router::url($content['type'], $content), $siteUrl);
-
- //发送请求
- $urls = array(0=>$url);
- $ch = curl_init();
- $options = array(
- CURLOPT_URL => $api,
- CURLOPT_POST => true,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POSTFIELDS => implode("\n", $urls),
- CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
- );
- curl_setopt_array($ch, $options);
- $result = curl_exec($ch);
-
- $res = json_decode($result, true);
- if(isset($res['error'])) exit('<script>alert("链接提交百度接口失败!错误代码:'.$res['error'].',错误信息:'.$res['message'].'。");location.href="'.$siteUrl.'/admin/manage-posts.php";</script>');
- }
-
- /**
- * 用户浏览文章时自动推送
- *
- * @access public
- * @return void
- */
- public static function auto_push()
- {
- echo PHP_EOL.'<script>
- (function(){
- var bp = document.createElement("script");
- var curProtocol = window.location.protocol.split(":")[0];
- if (curProtocol === "https"){
- bp.src = "https://zz.bdstatic.com/linksubmit/push.js";
- }else{
- bp.src = "http://push.zhanzhang.baidu.com/push.js";
- }
- var s = document.getElementsByTagName("script")[0];
- s.parentNode.insertBefore(bp, s);
- })();
- </script>'.PHP_EOL;
- }
- }
本站也有另外一款百度推送的插件

Typecho百度推送插件,普通or快速收录2种推送方式
就是一款针对百度站长(原熊掌号收录)推送,当发布文章的时候,可以同时推送给百度,实现快速收录的插件 目前,百度站长区分有普通和快速收录的接口,其中快速收录是根据网站....
区别:区分了快速推送和普通推送的功能,会获取数据保存到数据库方便查询
本次文章推荐的插件,部分功能已经整合到了spimes里面,自媒体比较更适合普通推送嘛……
文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/881
2 条评论
8k
发表评论
已有 2 条评论
热门文章
自媒体博客Spimes主题44w 阅读
Spimes主题专为博客、自媒体、资讯类的网站设计....
Splity博客双栏主题14w 阅读
仿制主题,Typecho博客主题,昼夜双版设计,可....
vCard主题个人简历主题13w 阅读
一款个人简历主题,可以简单搭建一下,具体也比较简单....
Spzac个人资讯下载类主题12w 阅读
用于作品展示、资源下载,行业垂直性网站、个人博客,....
热评文章
自媒体博客Spimes主题424 评论
Splity博客双栏主题191 评论
Spzac个人资讯下载类主题89 评论
Splinx博客图片主题35 评论
Spzhi知识付费社区主题34 评论
三栏清新博客S_blog主题31 评论
vCard主题个人简历主题29 评论
Pure轻简主题29 评论
我是作者,很意外我的插件会被转载,非常感谢。因为平时比较忙,改了博客的域名但是并没有及时做重定向以及更新插件,十分抱歉。
大家如果需要可以去Github下载我的插件:
https://github.com/bluejay21st/Typecho-BaiduSeo
https://github.com/bluejay21st/Typecho-Sitemap
没有下载链接呀