Plugin development guide #1: Getting started Plugin development guide #1: Getting started

Default files, folders and code structure

Introduction
So you want to write your own plugins? This is the first in a series of articles to help you use the Cotonti plugins system. Each article in the series will discuss a specific subject concerning plugin development.

  1. Default files, folders and code structure
  2. Using and understanding hooks
  3. Setting config values and using them
  4. Using the XTemplate system, defining tags and using rows
  5. Plugin localisation

Getting started
The first step in the process of developing a plugin is setting up the directory structure and creating some default files. Your plugin directory structure should look like this:



If the plugin you will be writing is not going to use template files and/or language strings, you are free to omit the respective folders.

Your plugin name, when used as a filename or code, should:
  • be unique
  • be all lowercase
  • consist of only letters, numbers and dashes (-)

All files inside your plugin folder (root) have a predefined code structure:

<?PHP

/* ====================
[BEGIN_SED_EXTPLUGIN]
Code=pluginname
Part=main
File=pluginname
Hooks=standalone
Tags=
Order=10
[END_SED_EXTPLUGIN]
==================== */

/**
 * Plugin description
 *
 * @package Plugin name
 * @version 1.0
 * @author You
 * @copyright Your company
 * @license BSD
 */

defined('SED_CODE') or die("Wrong URL.");

// Your plugin code

?>

The first thing you will notice is the presence of some setup values. These values are used by Cotonti to setup and configure your plugin when it is installed through the adminpanel.

Code: the plugin name
Part: the second part of the filename (example: ‘index’ for pluginname.index.php). default: main
File: the filename without extension (example: pluginname.index)
Hooks: Cotonti hook code, or ‘standalone’ for standalone pages
Tags: list of tags using this format: file.tpl:{TAG_ONE},{TAG_TWO}
Order: integer, default 10, order by which plugins are executed by a hook

The following javadoc comment block is optional, but recommended. You are free to modify this to your liking.

Finally, there is one line of code which is required for all your php files, as a security feature. It will prevent your file from being included (and executed) in non-Cotonti php files.

-Edited by: ZEFEX
Your pluginname.setup.php file will need the following:
<?
/* ====================
[BEGIN_SED_EXTPLUGIN]
Code=blank
Name=Blank
Description=Some description
Version=the version
Date=2010-april-15
Author=Your name!
Copyright=All rights reserved (c) 2009-2010
Notes=BSD License.
SQL=
Auth_guests=R
Lock_guests=W12345A
Auth_members=RW
Lock_members=12345
[END_SED_EXTPLUGIN]
  
[BEGIN_SED_EXTPLUGIN_CONFIG]
something=01:radio::1:Enable Something
[END_SED_EXTPLUGIN_CONFIG]
  
==================== */
   
/**
 * Plugin description
 *
 * @package Plugin name
 * @version 1.0
 * @author You
 * @copyright Your company
 * @license BSD
 */
   
defined('SED_CODE') or die("Wrong URL.");
   
// Your plugin code
   
?>


Коментарі відсутні
Додавання комментарів доступно лише зареєстрованим користувачам