Contents |
The basic plugin framework can be created using the graphical plugin creator located at: http://www.companytools.nl/kfm-plugin-creator Note that is a helper tool.
It is really easy to create your own KFM plugin. Here is an example of how to do it. By convention I will call the plugin name plugin_name.
A plugin will have a folder in the plugins directory of KFM. The main file of each plugin is the plugin.php file. As addition there can be a plugin.js file which will add javascript to KFM. Also a plugin.css stylesheet file can be added for the styling. So the basic structure looks like:
plugin.php (required for KFM 1.4 and greater) plugin.js plugin.css
The plugin.php file lets KFM know that it exists (KFM 1.4 and greater). So the basic syntax of this file will be:
<?php
$p=new kfmPlugin("plugin_name");
$kfm->addPlugin($p);
?>
This is it. The rest can be done in the javascript file plugin.js.
The javascript plugin syntax looks like: an example syntax could be:
function kfm_plugin_plugin_name{
this.name="plugin_name";
this.title="I do this!";
this.mode="2"; // Important!!!
this.writable=2;
this.category="edit";
this.extensions=['jpg','png','gif'];
this.doFunction=function(files){
alert('There are '+files.length+' files passed to the plugin');
}
this.nocontextmenu=false;
}
kfm_addHook(new kfm_plugin_plugin_name());
A description of the properties:
The name property is the name of the plugin. It must be unique for each plugin.
The title property contains the title as displayed in KFM. So language support should be added here. For example:
this.title=kfm.lang.ResizeImage
The mode property is really important. It determines what kind of plugin it is. Here are the possible values:
This property determines if a file or folder is writable. If the mode property is 0,1,2 or 4 it is required. The possible values are 0,1 and 2.
The category determines in what category the plugin belongs. The current possible values are:
main, view, edit, returning, selection, kfm
The extensions property defines for which kind of files this plugin is ment. This property will only be relevant if the mode property is 0, 1 or 2. Examples are:
this.extensions=['jpg','png','giv']; // Image files this.extensions="all"; // All files
The doFunction is the function that is executed when the plugin is called. When the plugin acts on files, it will get an array which contains the id's of the files. You can get the file object by typing:
var F=File_getInstance(files[0]);
Note that this is a call for a one file plugin. The argument is still an array!
This is an optional property. You can set this to false if you want to create a plugin and don't want it to show in the context menu. An example can be a plugin that is only meant for a double click action.
You can add a stylesheet with your plugin. Do this by creating a plugin.css file in your plugin folder. Then it will be automatically added to KFM. Styling of the plugin is for the moment limited to the context menu. A context menu entry for your plugin will get the class kfm_plugin_plugin_name_contexticon. So for example a stylesheet can look like:
kfm_plugin_cropper_contexticon{
background-image:url('cropper/img/crop.gif');
background-repeat:no-repeat;
}
Adding settings to the KFM system is quite easy but requires some extra knowledge. A good example illustrating many of the plugin features is the lytebox plugin:
<?php
$p=new kfmPlugin('lytebox');
$p->addSetting('lytebox_slideshow_delay',array('type'=>'integer', 'unit'=>'s', 'properties'=>array('size'=>3)),4);
$p->addSetting('lytebox_theme',
array(
'type'=>'choice_list',
'options'=>array('Grey' => 'grey', 'Red'=>'red', 'Green'=>'green', 'Blue'=>'blue','Gold'=>'gold')
),
'grey'); // default
$p->addJavascript('lytebox.js');
$p->addJavascript('var lytebox_theme="{$setting.lytebox_theme}";lytebox_slideshow_delay="{$setting.lytebox_slideshow_delay}";');
$kfm->addPlugin($p);
?>
Various setting types can be used listed below:
Text is just a text field
array('type'=>'text')
array( 'type'=>'text', 'properties'=>array('size'=>10,'maxsize'=>25))
array('type'=>'bool')
Text box evaluated as integer in KFM
array('type'=>'integer', 'properties'=>array('size'=>3,'maxsize'=>3))
array('type'=>'array')
List of checkboxes
array('type'=>'select_list', 'options'=>array('logs','file_details','file_upload','search','directory_properties','widgets'))
Selectbox selector
array('type'=>'choice_list','options'=>array('File url'=>'url','Secure'=>'secure'))
You might want to have two (or more) instances of one plugin which has a similar task. For example resizing images.