Home >Backend Development >PHP Tutorial >Typecho plug-in writing tutorial (2): Write a new plug-in, typecho plug-in_PHP tutorial

Typecho plug-in writing tutorial (2): Write a new plug-in, typecho plug-in_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:52:301053browse

Typecho plug-in writing tutorial (2): Write a new plug-in, typecho plug-in

In the first section, we learned about the basic structure of a plug-in. Next, we need an example to practice and consolidate.

What a coincidence, Lao Gao is currently revising the Baidu sitemap submission plug-in for typecho. Let’s revise it with Lao Gao!

Preparation

Have you ever used the WP version of Baidu structured plug-in? Lao Gao studied that plug-in, observed its API, and then wrote the typecho version.

Why the revision?

Baidu webmaster recently launched a new interface, which is easier to use and the workload is not heavy, so just change it!

What functions does the new plug-in need to implement?

1. Real-time push of articles
2. Push historical data
3.Sitemap

Where is the interface calling address (API)?

Baidu webmaster backend, PHP interface example:
Copy code The code is as follows:
$urls = array(
'http://www.example.com/1.html',
'http://www.example.com/2.html',
);
$api = 'http://data.zz.baidu.com/urls?site=www.phpgao.com&token=your access key';
$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);
echo $result;

Get started

Let Lao Gao pirate the code of the HELLO_WORLD plug-in in the previous section, delete all comments, and add his own information.
Copy code The code is as follows:
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* Baidu structured plug-in tutorial version
*
* @package BaiduSubmitTest
* @author 老高
* @version 0.4
* @link http://www.phpgao.com/typecho_plugin_baidusubmit.html
​*/
class BaiduSubmitTest_Plugin implements Typecho_Plugin_Interface
{

public static function activate(){}

public static function deactivate(){}

public static function config(Typecho_Widget_Helper_Form $form){}

public static function personalConfig(Typecho_Widget_Helper_Form $form){}

public static function render(){}
}

Lao Gao named the above code a naked plug-in, which means a plug-in that can’t do anything. Lao Gao will prepare a naked plug-in every time he writes a plug-in.

We put it in usr/plugins/BaiduSubmitTest/Plugin.php

Go to the backend plug-in immediately, as shown in the picture

Why plug and play?

Because we have no way to implement the plug-in, it cannot be enabled.

In the next section we will make our plug-in fuller!

End of this section.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1008010.htmlTechArticleTypecho plug-in writing tutorial (2): Writing a new plug-in, typecho plug-in In the first section, we learned about a plug-in The basic composition, below we need an example to practice and consolidate. What a coincidence...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn