Typecho Plugin Authoring Tutorial (v): Core code, Typecho plugin _php tutorial

Source: Internet
Author: User

Typecho Plugin Authoring Tutorial (v): Core code, Typecho plugin


A lot has been said before, now start writing the core code.

Analysis, when publishing the article, we need information is the current article URL, we need to find a way to get him from the $contents, $class.

Currently our plug-in class code is as follows (please note that render was changed to send by me)

Copy the Code code as follows:
Class Baidusubmittest_plugin implements Typecho_plugin_interface
{

public static function activate () {
Mount an interface 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 ' plugin installed successfully, please enter the settings to fill in the access key ';
}

public static function deactivate () {
Do something
Return ' plugin uninstall succeeded ';
}

public static function config (Typecho_widget_helper_form $form) {
$element = new Typecho_widget_helper_form_element_text (' API ', NULL, NULL, _t (' access key '), ' please login to Baidu Webmaster platform to get ');
$form->addinput ($element);
}

public static function Personalconfig (Typecho_widget_helper_form $form) {}

public static function Send ($contents, $class) {
Do something
}
}

Get URL

Getting a permalink needs to be generated by routing rule + Typecho_common::url!

Copy the Code code as follows:
Class Baidusubmittest_plugin implements Typecho_plugin_interface
{

public static function activate () {
Mount an interface 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 ' plugin installed successfully, please enter the settings to fill in the access key ';
}

public static function deactivate () {
Do something
Return ' plugin uninstall succeeded ';
}

public static function config (Typecho_widget_helper_form $form) {
Save Interface Call Address
$element = new Typecho_widget_helper_form_element_text (' API ', NULL, NULL, _t (' Interface call address '), ' please login to Baidu Webmaster platform to get ');
$form->addinput ($element);
}

public static function Personalconfig (Typecho_widget_helper_form $form) {}

/**
* Prepare data
* @param $contents article content
* @param the class that $class the calling interface
* @throws typecho_plugin_exception
*/
public static function Send ($contents, $class) {

If the article properties are hidden or lagged published
if (' publish '! = $contents [' visibility '] | | $contents [' created '] > Time ()) {
Return
}

Get System Configuration
$options = Helper::options ();

Determine if the API is well configured
if (Is_null ($options->plugin (' baidusubmittest ')->api)) {
Return
}

Get article type
$type = $contents [' type '];

Get Routing information
$routeExists = (NULL! = Typecho_router::get ($type));

Creating a permanent connection
$path _info = $routeExists? Typecho_router::url ($type, $contents): ' # ';
$permalink = Typecho_common::url ($path _info, $options->index);
}
}

There are comments in the code, the old Gao is not repeating.

So far we have got the permanent link to the article, the next step is to send data to the Baidu server!

End of this section!

http://www.bkjia.com/PHPjc/1008004.html www.bkjia.com true http://www.bkjia.com/PHPjc/1008004.html techarticle Typecho Plug-in programming tutorial (V): The core code, Typecho plug-in before a lot of verbose, now began to write the core code. Analysis, when we publish the article, the information we need is ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.