Plugins - advanced/en

Overview
Starting from LimeSurvey 2.05, LimeSurvey will officially support plugins. Some plugins will be supported by the LimeSurvey team and will go into core. Some will be supported by others outside the LimeSurvey team. To help find them, check out the Available third party plugins and add your own plugin to it!

Plugins allow users to customize the functionality of their installation while still being able to benefit from regular software updates.

This documentation is meant for developers that are extending LimeSurvey for their own use or for their clients; end users will not be helped by this documentation.

Plugins must implement the iPlugin interface. We recommend extending your plugin class from the PluginBase class.

Plugins are developed around an event mechanism.

Plugin settings
By extending you benefit from common functionality required by plugins that we already have implemented for you. One of these function is the implementation of the getPluginSettings function. This function must return an array describing the configuration options for the user.

The example plugin exposes just 1 configurable setting, the message it'll show.

The array contains a name for each setting as a key. The values are arrays containing the required meta data.

Supported types are:


 * logo
 * string
 * html
 * choice
 * relevance
 * info

Besides type a number of other keys are available:


 * label, defines a label
 * default, defines a value to show if no value is specified (only for global settings, not for survey settings)
 * current, defines the current value.
 * readOnly : shown the settings as readonly
 * htmlOptions, the htmlOptions of the input part ( see Yii manual [])
 * pluginOptions, for some settings (html or select) : set the widget option
 * labelOptions : htmlOptions of the label
 * controlOptions : htmlOptions of the wrapper of label and input

You can find a plugin example using all actual settings at exampleSettings

Read and write plugin settings
It's possible to read and write plugin settings directly from your plugin code.

Example:

You can get a default value if the setting happens to be null:

Events
Plugins subscribe to events and can interact with LimeSurvey when the event is fired. For a list of currently available events check Plugin events.

API
Plugins should only extend LimeSurvey via its "public" API. This means that directly using classes found in the source code is a bad practice. Though we can't force you not to, you risk having a broken plugin with every minor update we do.

As much as possible interact with LimeSurvey only via methods described here. Same as for events.

The API object is available via  when extending from PluginBase, otherwise you can get it from the PluginManager instance that is passed to your plugins' constructor.

New functions can be added to the API object upon request.

Localization
It's possible for plugins to add their own locale files. File format used is .mo, same as core translations. The files must be stored in

/locale/ / .mo

where " " is a two letter word like "de" or "fr".

To use the specific locale file, use the plugin function gT:

If the given string can't be found in the plugin specific locale file, the function will look in the core locale files. So it's safe to use strings like "Cancel":

If you are using views together with your plugin, you should use

to do plugin specific translation in your view.

Logging
If you want to log something from your plugin, just write

The default logging level is trace, but you can give another log level as an optional second argument:

The log file can be found in folder

/tmp/runtime/plugin.log

Your plugin name is automatically used as category. A nice way to see only the errors from your plugin is using grep (on Linux):

$ tailf tmp/runtime/plugin.log | grep

Extension updates
Since LimeSurvey version 4.0.0, there's a system in place to deal with plugin and other extension updates. To use this system, your extension config.xml file needs to include updater configuration.

https://somedownloadlink.com/maybegithub

(The source tag above points to the LimeStore REST API, which will be used for all extensions available in our LimeStore.)

If you don't want to supply an updater, you should put the following text in your config XML file:

This way, you tell the system that you purposefully disabled the update system, and didn't just forget to add it.

The new plugin UpdateCheck - installed and activated by default - checks for new updates for all installed extensions when a super admin logs in, asynchronously, max one time every 24 hours. If any new versions are found, a notification is pushed.



If a new security update is found, the notification will open automatically and be styled in "danger" class.



You can manually check for updates by going to the plugin manager view and click on "Check updates". Note that this button is only visible if the UpdateCheck plugin is activated.



Under the hood
This section provides a brief overview over the extension updater implementation.

The extension updater is part of the ExtensionInstaller library. Below is a UML diagram for the classes related to the updater process.



Program flow when Yii starts:

Program flow when running the UpdaterCheck plugin:

The checkAll method in the UpdateCheck plugin provides an example of how to query all extensions for new versions.

Adding new version fetchers
To add a new custom version fetcher, run this during Yii initialization:

Of course, the class  has to subclass.

To use your new version fetcher, configure the  tag in the updater XML to use (instead of e.g. ).

Adding new extension updaters
To add a new custom extension updater, run this during Yii initialization:

Class  has to subclass.

The top  tag in config.xml ('plugin', 'theme', ...) will control which extension updater are used for this extension. The system is not fully customizable yet, since you also need to add a custom ExtensionInstaller, menu items, etc. But in theory, and maybe in the future, it should be possible to add a new type of extension this way.

Special plugins

 * Authentication plugin development
 * Export plugin development

Available plugins

 * Authentication plugins
 * Audit log
 * CintLink
 * Available third party plugins

Tutorial
This step-by-step tutorial shows how to create a plugin that sends a post request on every survey response submission. The tutorial shows you how to create and save global and per-survey settings, how to register events and more.