推荐一个很不错的插件:Typecho百度SEO插件

主要作用于发布文章的时候,会实时推送,而且在用户前端浏览的时候,也会进行百度推送,个人觉得更适合普通推送合适一点

本插件目前有两个功能:

1、发布文章时通过API主动将文章推送给百度

2、用户在前台浏览文章时,会在每个页面底部加载自动提交代码,将当前浏览的页面提交给百度

下载地址:https://www.cwlog.net/archives/337.html

实现思路:

将功能的具体实现注册到对应的调用点。

启用插件后提示用户,要求设置提交接口。

发布文章后获取文章的链接与提交接口,提交数据,若提交失败给出提示。

前台访问触发后,将自动提交的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提交-接口调用地址
(格式如下: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(''); $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(''); } /** * 用户浏览文章时自动推送 * * @access public * @return void */ public static function auto_push() { echo PHP_EOL.''.PHP_EOL; } }

本站也有另外一款百度推送的插件

Typecho百度SEO插件(浏览页面自动提交给百度)
Typecho百度推送插件,普通or快速收录2种推送方式

就是一款针对百度站长(原熊掌号收录)推送,当发布文章的时候,可以同时推送给百度,实现快速收录的插件 目前,百度站长区分有普通和快速收录的接口,其中快速收录是根据网站....

区别:区分了快速推送和普通推送的功能,会获取数据保存到数据库方便查询

本次文章推荐的插件,部分功能已经整合到了spimes里面,自媒体比较更适合普通推送嘛……

TAGS:自媒体 PHP 插件 百度推送
!如链接失效请在下方留言。本站所有资源均来源于网络,版权属于原作者!仅供学习参考,本站不对您的使用负任何责任。如果有侵权之处请第一时间联系我们删除,敬请谅解!