Plugin files organization

General organization of a plugin

ROOT :

  • _define.php : file that describes the plugin (name, author, version number, …).
  • _install.php : called when users visit the dashboard via the administration panel.
  • _prepend.php : is read after creating objects, but before display, in both public pages and administration pages.
  • _admin.php : is only read in administration panel.
  • _public.php : is only read on public pages.
  • _widgets.php : used by _admin.php and _public.php when widget is available outside of the sidebar via the <tpl:Widget> tag.
  • _xmlrpc.php : xmlrpc interface of the plugin.
  • _services.php : contains all Ajax services used by the plugin.
  • index.php : contains the plugin's administration page.
  • style.css : contains CSS rules for the plugin if needed.
  • icon.png : the plugin's icon.
  • inc : directory containing all necessary files for the plugin.
  • locales : directory containing all translation subdirectory.
    • fr : directory containing *.po files for French translation.
    • en : directory containing *.po files for English translation (optional since plugins are already in English).
  • js : directory containing javascript files used by the plugin.
  • default-templates : directory containing all *.html file for new templates.

Organizing files in the inc/ directory

When you create a class, make sure its name is well chosen. For example, a plugin whose name is « foo » uses its own class. The file name should then be:

  • class.foo.php

If your class extends a Dotclear class, it should be called as a librairy. For example, if you need to create lists in the plugin's administration panel, the classe name will be « fooList » et le nom du fichier sera alors :

  • lib.foo.list.php

To load thoses classes, you can use PHP classes autoload, and put this code in the _prepend.php file :

$__autoload['foo'] = dirname(__FILE__).'/inc/class.foo.php';

You can also include files:

require_once(dirname(__FILE__).'/inc/class.foo.php');

Protecting files

In order to avoid PHP files to be executed outside of Dotclear, we can add a piece of code at the beginning of the files.

For files that are read only in the back-end:

We add this code :

if (!defined('DC_CONTEXT_ADMIN')) {return;}

For other files:

We add:

if (!defined('DC_RC_PATH')) {return;}

Wiki powered by Dokuwiki.