====== Plugin files organization ====== ===== General organization of a plugin ===== **ROOT** : * [[public-page#le-fichier-_define.php|_define.php]] : file that describes the plugin (name, author, version number, ...). * [[auto-install#le-fichier-_install.php|_install.php]] : called when users visit the dashboard via the administration panel. * [[public-page#le-fichier-_prepend.php|_prepend.php]] : is read after creating objects, but before display, in both public pages and administration pages. * [[admin#structure-minimale|_admin.php]] : is only read in administration panel. * [[public-page#le-fichier-_public.php|_public.php]] : is only read on public pages. * [[widgets#creation-du-widget-et-administration|_widgets.php]] : used by _admin.php and _public.php when widget is available outside of the sidebar via the [[/2.0/resources/themes/tags/widget|]] tag. * _xmlrpc.php : xmlrpc interface of the plugin. * [[services#service-creation|_services.php]] : contains all //Ajax// services used by the plugin. * [[admin#structure-minimale|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 [[http://php.net/manual/fr/language.oop5.autoload.php|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: * [[admin#structure-minimale|_admin.php]] * [[admin#structure-minimale|index.php]] * [[auto-install#le-fichier-_install.php|_install.php]] * [[services#service-creation|_services.php]] * files containing classes used in the back-end We add this code : if (!defined('DC_CONTEXT_ADMIN')) {return;} For other files: * [[public-page#le-fichier-_define.php|_define.php]] * [[public-page#le-fichier-_prepend.php|_prepend.php]] * [[public-page#le-fichier-_public.php|_public.php]] * _xmlrpc.php * other class files We add: if (!defined('DC_RC_PATH')) {return;}