Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to how to write core code for typecho plug-in

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to write the core code for the typecho plug-in. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

To analyze, when publishing an article, the information we need is the URL of the current article, and we need to find a way to get it from $contents and $class.

At present, our plug-in class code is as follows (please note that render has been changed to send)

The copy code is as follows:

Class BaiduSubmitTest_Plugin implements Typecho_Plugin_Interface

{

Public static function activate () {

/ / Mount the API for publishing articles and pages

Typecho_Plugin::factory ('Widget_Contents_Post_Edit')-> finishPublish = array (' BaiduSubmitTest_Plugin', 'send')

Typecho_Plugin::factory ('Widget_Contents_Page_Edit')-> finishPublish = array (' BaiduSubmitTest_Plugin', 'send')

Return 'plug-in installed successfully, enter the settings and fill in the admission key'

}

Public static function deactivate () {

/ / do something

Return 'plug-in uninstalled successfully'

}

Public static function config (Typecho_Widget_Helper_Form $form) {

$element = new Typecho_Widget_Helper_Form_Element_Text ('api', null, null, _ t (' access key'), 'Please log in to Baidu webmaster platform to get it')

$form- > addInput ($element)

}

Public static function personalConfig (Typecho_Widget_Helper_Form $form) {}

Public static function send ($contents, $class) {

/ / do something

}

}

Get URL

Obtaining permanent links needs to be jointly generated by routing rules and Typecho_Common::url!

The copy code is as follows:

Class BaiduSubmitTest_Plugin implements Typecho_Plugin_Interface

{

Public static function activate () {

/ / Mount the API for publishing articles and pages

Typecho_Plugin::factory ('Widget_Contents_Post_Edit')-> finishPublish = array (' BaiduSubmitTest_Plugin', 'send')

Typecho_Plugin::factory ('Widget_Contents_Page_Edit')-> finishPublish = array (' BaiduSubmitTest_Plugin', 'send')

Return 'plug-in installed successfully, enter the settings and fill in the admission key'

}

Public static function deactivate () {

/ / do something

Return 'plug-in uninstalled successfully'

}

Public static function config (Typecho_Widget_Helper_Form $form) {

/ / Save the API call address

$element = new Typecho_Widget_Helper_Form_Element_Text ('api', null, null, _ t (' API call address'), 'Please log in to Baidu webmaster platform to get it')

$form- > addInput ($element)

}

Public static function personalConfig (Typecho_Widget_Helper_Form $form) {}

/ * *

* prepare data

* @ param $contents article content

* @ param $class class that calls the interface

* @ throws Typecho_Plugin_Exception

, /

Public static function send ($contents, $class) {

/ / if the article attribute is hidden or delayed release

If ('publish'! = $contents [' visibility'] | | $contents ['created'] > time ()) {

Return

}

/ / get system configuration

$options = Helper::options ()

/ / determine whether API is configured or not

If (is_null ($options- > plugin ('BaiduSubmitTest')-> api)) {

Return

}

/ / get the article type

$type = $contents ['type']

/ / get routing information

$routeExists = (NULL! = Typecho_Router::get ($type))

/ / generate a permanent connection

$path_info = $routeExists? Typecho_Router::url ($type, $contents):'#'

$permalink = Typecho_Common::url ($path_info, $options- > index)

}

}

On the typecho plug-in how to write the core code to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report