I – Silex Plugins
Plugins extends basics Silex functionnalities. All Silex Plugins are installed in the “plugins/” folder, each one having it’s own folder. For exemple, in Silex base distribution, the “wysiwyg” plugin can be found, allowing publications editing. The “snapshot” plugin can also be found, handling publication thumbs pictures creation. Those captures are then used by the manager to display the publication preview. You can find more plugins on the Silex exchange platform : www.silexlabs.org/plugins/ or in the manager using the exchange platform plugin. If you downloaded the plugin from the exxhnage platforme, just unzip the downloaded .zip in the plugins/ folder to install it, with the manager’s plugin, the installation is automatic. > see also the tutorial HelloSilex, creating a silex plugin
II – Creating a Silex Plugin
a/ the index.php file
Silex server accesses each plugin by reading the index.php file located at the plugin’s folder root. ex: for the “snapshot” plugin, this file is located in the “plugins/snapshot/index.php” folder When you navigate to a silex publication, the Silex server will scan all plugins/ folders looking for all index.php files. The index.php file must be a class with the same name than the plugins folder and extending the “plugin_base” class located in “cgi/includes” folder of the server. To do so, the first line of the index.php file must include : require_once ROOTPATH.’cgi/includes/plugin_base.php’; where ROOTPATH is the root of the Silex server. You then need to override methods from the base plugin class to set the behaviour of your plugin.
b/ Silex hooks
Silex server’s index.php file calls different hooks at start-up indicating the initialisation progress. Silex’ s hook that most plugins need to use is “index-body-end” which is called when Silex server ‘s index.php (and not the plugin’s one) has finished server initialisation. Then the plugin can be loaded, knowing that all Silex Core references will be existing. Look the “initHooks” method in the “toolTip” index.php for an exemple of how to add a PHP hook. Here is the list of all the hooks called at start-up:
- index-head – called just after the “<head>” tag.
- index-noembed -
- index-body-end – called last in silex server’s index.php
Another useful hook is the “admin-body-end” PHP hook called when the user logs in, this hook must be used for tool plugins (see below) insted of “index-body-end” as some plugin must only be activated for an admin user and not a simple visitor. You can find an exemple of an “admin-end-hook in the index.php of the snapshot plugin. You can find the complete list of hooks here (TO DO).
c/ The Tools Plugins
Tools Plugins are a sub-category of Silex Plugins. A Tool Plugin is a plugin only used in admin mode, and typically loaded after the “admin-body-end” hook has been called on the Silex PHP Hook Manager. It’s up to the developper to create a regular or tool plugin, based on usage. For instance, google analytics plugin, storing states on a publication usage when activated, only needs to work for end-user. On the other hand, the snapshot plugin, capturing a preview of a publication only makes sense when the user is a logged admin.
d/ Silex Plugins Parameters
III – Silex Plugins and Silex Core
IV – Silex Plugins and ViewMenu
V – Silex Plugins and Manager
When your plugin is set and installed in the plugins/ folder, go to the manager to activate it at server or publication level and to edit it’s parameters.
a/ activating a plugin at server level
When a plugin is actived at server level it is activated for all the server’s publications. ex: the “wysiwyg” and “snapshot” plugins are by default activated on all publications. To activate a plugin, you can either use the manager or do it by direct file editing.
Via the manager:
Go to the settings > plugins page and click “activate a plugin” if you want to add one or select a plugin in the list and click “Deactivate a plugin”.
Via file editing:
In silex server, go to the “conf” folder and open the plugins_server.php file. Add or remove plugins in the string list, separating them with a “@” character.
b/ activating a plugin at publication level
A plugin activated at publication level is only activated for this publication. Like server level plugin activation, you can do it either via the manager or via direct file editing.
Via the manager:
Go to manager, select the target publication in the list, then click on “plugins”. The activated plugins are listed. You can then deactivate one by selected it and clicking on the “deactivate a plugin” button or activate one by clicking the activate a plugin button and selecting it in the appearing list.
Via file editing:
In your silex server, go to contents, select the folder of the target publication then open the conf.txt file in this folder. Look for the “PLUGINS_LIST” parameter and fill it with the names of the plugins to activate separated by “@” symbols.
c/ Editing the Plugin’s parameters
When a plugin is activated, you can set the paramters described in it’s index.php file (see III – d/) by using the manager. By selecting the activated plugin in the manager (at server or publication level), you will see a list appearing displaying all plugin’s parameters. ex: by selecting “wysiwyg” plugin, “Wysiwyg style url” parameter appear, allowing you to edit the style swf file url. Then click on the parameter to edit its value.