How to write plugins
What is a Plugin?
The plugin system for EPrints 3 has been developed to make it easy and share the most common extensions to the code without having to hack the core system (and causing yourself problems with upgrades etc.)
Plugins are a way to make functionality easy to maintain and transfer. If you make any customizations to your repository other than metadata and appearence changes then you will probably want to write a plugin.
You will need
- A basic understanding of perl (dont be scared - its not hard and theres plenty of tutorials on the web)
- An EPrints installation to play about on. A Virtual box with EPrints installed is ideal.
- Information from the EPrints API
Write a Plugin!
When the system loads, it automatically loads all modules in the archives/ARCHIVE_ID/cfg/plugins/EPrints/Plugin/ directory, so for simple plugins you just drop them in that directory and you're done!
When a plugin is loaded it has a registration method which is called which tells the core EPrints system what this plugin does. EPrints then makes it available as appropriate.
Clever plugins can detect features they need and adapt to use the tools available, or disable themselves if they are missing required tools (rather than crash the system). Some specialised plugins are disabled in their default state and must be enabled in the repository configuration.
Another cool thing is that plugins are Perl Objects, which means you can subclass them. Here's an real-world example: We have a research group which uses BibTeX but over the years standardised within the group on an extra field. This is not a valid bibtex field, but are essential to their working because they have ancient and essential scripts which depend on it. To handle this we can subclass the default BibTeX Export plugin and override a single method (the data mapping one). We then just call the original parent plugins mapping method to do all the heavy lifting, then just add our non-standard extra field. Total code required: less than one screen. Number of happy researchers: none (they are never satisfied), but number of researchers able to get their work done: lots. Don't believe me? look here!
- See also Extension Packages for how to add configuration and resource files to plugins.
Types of Plugin
There are a number of different kinds of plugin for EPrints. You can find a comprehensive list of types of plugins here. The most of common of those are...
These are used to export the data in a variety of formats. A number of tutorials have been created to help you create your own export plugins:
- Export Plugin Tutorial 1: "Hello, World!"
- Export Plugin Tutorial 2: List handling
- Export Plugin Tutorial 3: HTML
- Export Plugin Tutorial 4: Excel
- Export Plugin Tutorial 5: Zip
These are used to import data into a repository. They can take datafiles directly, or they can take an ID of a record that can be retrieved in a known way, or a URL of a file, or... whatever.
These are a bit trickier to write than export plugins as parsing data is harder than just "print"ing it, but they are still reasonably straight forward. To get you started a small selection of tutorials has been written:
These handle (almost) all the user interface screens. Pages like "Review" and "Profile" are just built-in plugins. You can add your own very easily.
Examples you could create...
- Birds Eye View - a view of various statistics on the database, all in one page.
- Spellchecking Tab - an additional tab in the item control page which checks the spelling on certain fields.
- Bulk Delete tool - a tool which takes a list of eprintid's and deletes them all in a fell swoop.
Look at the existing Screen Plugins for an idea of how they work. They can be very simple.
Input Component Plugin
These handle how the workflow components are rendered. Built in components include the default (one field) component, the multiple fields component, the upload component, the subject component (which does pretty things to a field of type "subject") and the XHTML component. You can add your own or sub-class existing ones.
These are used for two things, currently.
- Converting the full text of documents into utf-8 text for search indexing
- Converting images and pdfs into thumbnails and previews
Some examples you could create:
- RTF to utf-8 to allow rich text documents to be indexed.
- Powerpoint to Thumbnail to allow thumbnail and previews of powerpoint slides
- Video to Thumbnail/Preview to make a still preview of a video file.
Try out some of the examples and see where you get to. If you hit problems you can always talk to EP-Tech. For free support and discussion about EPrints you can sign up to the EP-Tech..
Its probably a good a idea to look at some tips. It will help you write better plugins.
If you've written a plugin and you're happy with it the EPrints Team encourages you to share it with the EPrints community at http://files.eprints.org. If nothing else its a good place to store your code for future use. You might even get some valuable feed back.