Differences

This shows you the differences between the selected revision and the current version of the page.

punbb13:extension_development 2010/04/09 06:33 punbb13:extension_development 2020/02/06 11:04 current
Line 1: Line 1:
====== PunBB 1.3 extension development ====== ====== PunBB 1.3 extension development ======
 +
 +A PunBB extension is a folder containing some files. The folder is named after the extension ID and is placed in the ''extensions'' directory within PunBB.
 +
 +The main file of an extension is the manifest file, manifest.xml. It is to be directly in the extension folder.
===== The manifest ===== ===== The manifest =====
-All extensions come with a manifest file, manifest.xml. The manifest file is basically the entry point to an extension. It is a regular XML file that contains information about the extension, such as author name, short description of what it does, and what version of PunBB it requires. It also has information about hooks, and how PunBB should use them.+The manifest file is a regular XML file that contains information about the extension, such as author name, short description of what it does, and what version of PunBB it requires. It also has information about hooks, and how PunBB should use them.
<code xml> <code xml>
Line 133: Line 137:
</hooks></code> </hooks></code>
 +
 +===== Other extension issues =====
 +
 +==== Using $ext_info ====
 +
 +Every extension is provided with the $ext_info array, which contains information about the extension.
 +
 +^  Variable  ^  Description  ^  Example  ^
 +| ''$ext_info['id']''  | The ID of current extension  | example_extension    |
 +| ''$ext_info['path']''  | The relative path to the current extension (without trailing slash). Use it to include files  | ./extensions/example_extension    |
 +| ''$ext_info['url']''  | The URL to the folder of the current extension (absolute, without trailing slash). Use it when embedding stylesheets or images  | http://example.net/forums/extensions/example_extension    |
 +
 +==== Including files ====
 +
 +    * You must not use includes in the uninstall process, since the code within the uninstall hook is copied to the database upon installation (and thus must be able to be run by itself). All of the code for these must be contained within the manifest.xml file.
 +    * When using includes in hooks it's recommended in general to include functions and libraries.
 +
 +==== Including CSS/JavaScript ====
 +
 +    * To include CSS/JavaScript use the ''$forum_loader'' class' "''add_css''" and "''add_js''" methods.
 +    * For more information on the forum_loader class, see [[punbb13:extension_development:forum_loader]].
 +
 +==== Language files ====
 +
 +If the extension contains any strings that could be translated these should be put in a language file. The structure for language files is ''extensions/ext_id/lang/Language.php'', for example ''extensions/example_extension/lang/English.php''. The language file would then contain
 +
 +<code php><?php
 +
 +$lang_example_extension = array(
 +  'Example 1'  =>  'An example language string',
 +);</code>
 +
 +To include the language file the following code would be used
 +
 +<code php>if (file_exists($ext_info['path'].'/lang/'.$forum_user['language'].'.php'))
 +  require $ext_info['path'].'/lang/'.$forum_user['language'].'.php';
 +else
 +  require $ext_info['path'].'/lang/English.php';</code>
 +
 +==== Databases ====
 +
 +It is important your extension work in all 3 database systems supported by PunBB. To do this, you should use the helper functions provided in the [[punbb13:database helpers|database abstraction layer]] as much as possible.
 +
 +==== Version numbers ====
 +
 +Extension versions should be numbered in the same format as PunBB, that is for example 1.2.3 where 1 is the major version, 2 is the minor version and 3 is the release. Extensions in beta stages should be numbered 0.x.x, each time new functionality is added the minor version should be increased, and after a full/major rewrite the major number should be increased. Small bugfixes should increase the release number.
 +
 +==== Extensions must be able to be disabled ====
 +
 +Extensions in PunBB can be disabled from the administration panel or via a [[punbb13:constants#forum_disable_hooks|constant in config.php]]. This action does not uninstall the extension but simply turns off its hooks. It is important you think about this situation when coding your extension. As a result, in general you can not perform destructive actions on the core database (eg: remove the Guest user, delete a core configuration value, shrink a column to an unusable size, drop a table or column, etc).
 +
 +It is also important to make sure that any files in your extension that are accessed directly return some form of error message if they are accessed when the extension is disabled.
 +
 +==== Extensible extensions ====
 +
 +When writing extensions it is important you think about the task your extension will perform, where possible try to do one task and do it well. When writing more complex extensions it is best to break them down into multiple extensions and use dependencies to combine them. For example a donation extension could be separate from a cash extension but depend on it. Then users who do not want the donate function can choose not to install that part.
 +
 +Even extensions themselves can be extended. Use hooks in your extension to give other developers the chance to enhance your extension. Hooks of extensions can be used exactly like normal hooks. To guarantee that the extension you extended is available, add dependencies to your manifest.
===== PunBB team extension development life cycle ===== ===== PunBB team extension development life cycle =====
  - Create the wiki article for the extension and write the general idea and the specification there.   - Create the wiki article for the extension and write the general idea and the specification there.
-    * The page url must be ''%%http://punbb.informer.com/wiki/punbb13:<extension_id>%%'', e.g. http://punbb.informer.com/wiki/punbb13:pun_pm. +    * The page url must be ''%%https://punbb.informer.com/wiki/punbb13:extensions:<extension_id>%%'', e.g. https://punbb.informer.com/wiki/punbb13:extensions:pun_pm. 
-    * You may also start the discussion in [[http://punbb.informer.com/forums/forum/65/13-extensions-talk/|Forums]] to ask users to add their feature requests to the specification. +    * You may also start the discussion in [[https://punbb.informer.com/forums/forum/65/13-extensions-talk/|Forums]] to ask users to add their feature requests to the specification. 
-  - Add the ticket to the [[http://punbb.informer.com/trac/|Trac]] (or just start a text file, if you have no [[http://en.wikipedia.org/wiki/Trac|Trac]]). List the main tasks to complete the extension.+  - Add the ticket to the [[https://punbb.informer.com/trac/|Trac]] (or just start a text file, if you have no [[http://en.wikipedia.org/wiki/Trac|Trac]]). List the main tasks to complete the extension.
  - //To be invented: // Create the automatic test (e.g. using [[pun_admin_simpletest]]) for all the features in your task-list.   - //To be invented: // Create the automatic test (e.g. using [[pun_admin_simpletest]]) for all the features in your task-list.
  - Code them all! Follow your task-list and strike out done.   - Code them all! Follow your task-list and strike out done.
-    * Commit your changes to the [[http://punbb.informer.com/svn/|SVN]] separately: one feature or one bug fix is one commit. Do not commit multiple changes simultaneously.+    * Commit your changes to the [[https://punbb.informer.com/svn/|SVN]] separately: one feature or one bug fix is one commit. Do not commit multiple changes simultaneously.
    * BTW: Use [[http://en.wikipedia.org/wiki/Subversion_(software)|SVN]] or other [[http://en.wikipedia.org/wiki/Version_control_system|VCS]]. (I personally prefer [[http://en.wikipedia.org/wiki/Bazaar_(software)|Bazaar]].)     * BTW: Use [[http://en.wikipedia.org/wiki/Subversion_(software)|SVN]] or other [[http://en.wikipedia.org/wiki/Version_control_system|VCS]]. (I personally prefer [[http://en.wikipedia.org/wiki/Bazaar_(software)|Bazaar]].)
  - Add the documentation to the wiki article.   - Add the documentation to the wiki article.
    * Extension usage.     * Extension usage.
    * Extension customization and integration.     * Extension customization and integration.
-  - Publish extension in the [[http://punbb.informer.com/extensions/|extension repository]] //(as soon as it passed all the automatic tests)//. +  - Publish extension in the [[https://punbb.informer.com/extensions/|extension repository]] //(as soon as it passed all the automatic tests)//. 
-    * Third-party developers may propose their extensions to be reviewed and published in the [[http://punbb.informer.com/extensions/|repository]]. +    * Third-party developers may propose their extensions to be reviewed and published in the [[https://punbb.informer.com/extensions/|repository]]. 
-  - Release the extension in [[http://punbb.informer.com/forums/forum/65/13-extensions-talk/|Forums]].+  - Release the extension in [[https://punbb.informer.com/forums/forum/65/13-extensions-talk/|Forums]]. 
 + 
 +===== See also ===== 
 +  * [[punbb13:extensions|PunBB 1.3 Extensions]] 
 + 
 +//This description is mainly based on the [[http://fluxbb.org/wiki/v1.3:developing_extensions|FluxBB documentation]]. We would like to express our thanks to the FluxBB development team.//

Personal Tools