30Blog

ZBlog development tutorial: Z-BlogPHP plug-in development guide

1. Description

Plug ins use various interfaces provided by the system to implement some advanced customization functions, making Z-LogPHP more robust and interesting (Very Good, Very Strong.).

2. Contents and naming requirements

Plug ins are placed in the zb_users/plugin directory of the system. Plug ins must have their own directory name and not the same name as other plug-ins.

The plug-in directory name is the ID name of the plug-in, which is also recognized by the system.

The plug-in must be set with a correct plugin.xml file, which the system relies on to manage plug-ins.

It is very important that the "<id>" node in the plugin.xml file be set to the ID name of the plug-in (that is, the directory name of the plug-in).

Because the Linux system is sensitive to the case of file names, for compatibility, all file names must use lowercase English characters and other half width characters

3. Plugin.xml format specification

3.1 Sample Documents

plugin.xml

 <? xml version="1.0" encoding="utf-8"?> <plugin version="php"> <id>Totoro</id> <name>Totoro</name> <url> http://www.zsxsoft.com/ </url> <note>Review and reference management audit system enhanced version based on Z-Blog of TotoroII</ note> <description></description> <path>main.php</path> <include>include.php</include> <level>1</level> <author>   <name>zsx</name>   <email> zsx@zsxsoft.com </email>   <url> http://www.zsxsoft.com </url> </author> <source>   <name></name>   <email></email>   <url></url> </source> <adapted>130707</adapted> <version>1.0</version> <pubdate>2013-07-07</pubdate> <modified>2013-09-02</modified> <price>0</price> <advanced>   <dependency></dependency>   <rewritefunctions></rewritefunctions>   <conflict></conflict> </advanced> <sidebars>   <sidebar1></sidebar1>   <sidebar2></sidebar2>   <sidebar3></sidebar3>   <sidebar4></sidebar4>   <sidebar5></sidebar5> </sidebars> </plugin>

3.2 Node description

Plugin, which means that this document stores plug-in information, and version="php" which means that this plug-in is a Z-Blog PHP version plug-in, not an ASP version plug-in

ID, plug-in ID, English and numbers, which is the directory name where the plug-in is stored. Note: Do not duplicate the name of other plug-ins

Name, plug-in name, both in Chinese and English

Url, website of plug-in publishing page

Note, plug-in introduction

Description, detailed description of plug-in

Path, the file path of the plugin management page. Plugins without management pages can be left blank

Include, interface hook page. The default is include.php. Plug ins that do not need interface calls can be left blank

Level, the lowest permission level of plug-in management, expressed in numbers, 1 is administrator, 2 is advanced user, 3 is intermediate user, 4 is ordinary user, and 5 is tourist

Author, plug-in author

Name, author name

URL, the author's web address

Email, the author's email

Source, source author information, sub node reference author

Adapted, the minimum required blog version number for plug-ins

Version, the version number of the plug-in

Pubdate, plug-in release date

Modified, the last update date

Price, the price of the paid plug-in, which can be purchased directly in the application center. 0 means free.

Advanced, advanced plug-in options

Dependency is a list of dependent plug-ins. If the plug-in needs to be used together with other plug-ins, you should fill in an accurate list of dependent plug-in IDs separated by "|", such as "demo1 | demo2 | demo3".

Rewritefunctions, system function rewrite list. If the plug-in wants to rewrite system functions, it should fill in an accurate list of original function names here, separated by "|".

Conflict is the list of conflicting plug-ins. If the plug-in conflicts with other plug-ins, fill in the accurate list of conflicting plug-in IDs here, separated by "|".

Sidebars, theme plug-in built-in sidebar attribute

Sidebar1, sidebar 1. If the plug-in needs to determine the sidebar configuration, it should fill in the accurate module ID list here, separated by the "|" symbol, such as "searchpanel | comments | archives | link".

Sidebar2, sidebar 2, configuration method is the same as above

Sidebar3, sidebar 3, configuration method is the same as above

Sidebar4, sidebar 4, configuration method is the same as above

Sidebar5, sidebar 5, configuration method is the same as above

4. Interface classification and calling

Plug in hook mode

 Add_Filter_Plugin ('API name ','Execution code (function)');

5. Plug in registration

The plug-in of Z-BlogPHP system uses active insertion to notify the system. Therefore, the RegisterPlugin function must be called in the include.php file to allow the plug-in to enter the plug-in system of the system.

 //Register plug-in RegisterPlugin ("Plug in ID", "ActivePlugin_ Plug in ID");

To attach the system interface, you must also attach the interface in the "ActivePlugin_ Plug in ID Name" function, for example:

 //Specific interface hooking Function ActivePlugin_ Plugin ID (){ Add_Filter_Plugin ('API name ','Execution code (function)'); }

6. Activation and disabling of plug-in execution functions

The system sets that each plug-in can provide two special functions to perform one-time tasks during activation and disabling.

If your plug-in has this requirement, please use these two functions in include.php, and the system will automatically execute the corresponding functions when you enable and disable the plug-in.

 Function InstallPlugin_ Plugin ID () {} Function UninstallPlugin_ Plugin ID () {}

7. Judge plug-in status

Determine whether a plug-in is activated. The plug-in function configuration can be changed according to the plug-in activation status.

 If (! $zbp ->CheckPlugin ('Plug in ID ')) {$zbp ->ShowError (48); die();//The plug-in is not enabled and you can exit this page directly (usually used to configure the page)}

Note that the global declaration should be made before using the variable $zbp in the function, that is, use the code: global $zbp;

8. Save plug-in data to the database

If the plug-in needs to add configuration data or other extended data to the database, Z-BlogPHP provides three storage methods:

8.1 Option mechanism for using Z-BlogPHP

The Z-BlogPHP option mechanism is mainly used to save simple plug-in option data. The value of the option can be a string, an array, or a PHP object (PHP objects should be able to be serialized or converted to strings, and should be able to be deserialized when reading).

1. Set and save configuration options

 $zbp ->Config ('Plug in ID ') ->Option parameter=option value; $zbp ->SaveConfig ('Plug in ID ');

2. Read configuration options

 $s=$zbp ->Config ('Plug in ID ') ->Option parameter;

3. Determine whether the configuration option has been created

 $zbp ->HasConfig ('plug in ID ');  //return bool

4. Judge whether a key value of the configuration option exists

 $zbp ->Config ('Plug in ID ') ->HasKey ('Option parameter');  //return bool

5. Delete Configuration

The configuration deletion is usually performed when the plug-in is uninstalled. It is recommended to set whether to delete as required. Generally, we recommend to keep the configuration for next re enabling.

 $zbp ->DelConfig ('Plug in ID ');

8.2 Using the Extended Metadata Mechanism

It is also the custom domain mechanism of Z-BlogPHP, which is mainly used to save some extended data, such as article scores, the number of people who agree or disagree, and so on. The operation of user-defined fields is very simple. We just need to define options and option values (note that the definition of options should be unique and not duplicate with other plug-in definitions, and the value requirements are the same as the above option mechanism). When the original data is saved, its user-defined field operation data will be saved at the same time. Take the article ($article is an example of an article) as an example:

1. Set and save custom field options

 $article ->Metas ->option parameter=option value; $article->Save();

Note: It is not necessary to call the Save method immediately after setting. Metas data will be saved automatically when the article is saved.

2. Read Custom Field Options

 $s=$article ->Metas ->option parameter;

3. Delete Custom Field

The configuration deletion is usually performed when the plug-in is uninstalled

 $article ->Metas ->Del ('option parameter ');

8.3 Custom Data Table

That is, create a new customized database table. This method is suitable for saving independent data that has nothing to do with the original data, such as articles, pages or attachments, or can also be used in cases where the original data is related but the amount of data itself is large and needs to be stored independently. For more information about the usage of custom database, please refer to the custom database table

9. Plugins attached to the theme

A theme can contain a plug-in whose ID name is equal to the theme ID.

The plug-in files in the theme must be placed directly in the theme directory.

The plug-ins in the theme do not have plugin.xml, and their information is recorded in the theme's configuration file theme.xml file node.

Plug ins in the theme have the highest priority and cannot be adjusted. As long as this theme is enabled, the plug-in will be automatically activated until other themes are switched.


QQ pre-sales consultation