Difference between revisions of "How to write plugins"

From EPrints Documentation
Jump to: navigation, search
 
m (You will need)
 
(18 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== Write a Plugin! ==
+
[[Category:Plugins]]
 +
[[Category:Contribute]]
 +
 
 +
== 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.)
 
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.)
  
When the system loads, it automatically loads all modules in the perl_lib/EPrints/Plugin/ directory, so for simple plugins you just drop them in that directory and you're done!
+
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 (don't be scared - its not hard and there are plenty of tutorials on the web)
 +
 
 +
* An EPrints installation to play about on. A Virtual box with [[:Category:Installation|EPrints installed]] is ideal.
 +
 
 +
* Information from the [[:Category:API|EPrints API]]
 +
 
 +
* For some types of plugin you might also find some Javascript and CSS knowledge helpful.
 +
 
 +
== 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.
 
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.
Line 9: Line 25:
 
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.
 
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 and will just demand the moon on the stick because you've already given them this nice new feature), but number of researchers able to get their work done: lots. Don't believe me? [[BibTeX Extension Example|look here]]!
+
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? [[BibTeX Extension Example|look here]]!
  
 
* See also [[Extension Packages]] for how to add configuration and resource files to plugins.
 
* See also [[Extension Packages]] for how to add configuration and resource files to plugins.
Line 15: Line 31:
 
=== Types of Plugin ===
 
=== Types of Plugin ===
  
There are a number of different kinds of plugin for EPrints...  
+
There are a number of different kinds of plugin for EPrints. You can find a comprehensive list of [[Perl_lib/EPrints/Plugin/|types of plugins here]]. The most of common of those are...  
  
 
==== Export Plugin ====
 
==== Export Plugin ====
  
These are used to export the data in a variety of formats. They are quite easy to write, once you get started.
+
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:
 +
 
 +
* [[Contribute:_Plugins/ExportPluginsHello| Export Plugin Tutorial 1: "Hello, World!"]]
 +
* [[Contribute:_Plugins/ExportPluginsList| Export Plugin Tutorial 2: List handling]]
 +
* [[Contribute:_Plugins/ExportPluginsHTML| Export Plugin Tutorial 3: HTML]]
 +
* [[Contribute:_Plugins/ExportPluginsExcel| Export Plugin Tutorial 4: Excel]]
 +
* [[Contribute:_Plugins/ExportPluginsZip| Export Plugin Tutorial 5: Zip]]
  
 
==== Import Plugin ====
 
==== Import Plugin ====
Line 25: Line 47:
 
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 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.
+
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:
 +
 
 +
* [[Contribute:_Plugins/ImportPluginsCSV| Import Plugin Tutorial 1: CSV]]
 +
* [[Contribute:_Plugins/ImportPluginsAWS| Import Plugin Tutorial 2: Amazon Web Services]]
  
 
==== Screen Plugin ====
 
==== Screen Plugin ====
Line 37: Line 62:
  
 
Look at the existing Screen Plugins for an idea of how they work. They can be very simple.
 
Look at the existing Screen Plugins for an idea of how they work. They can be very simple.
 +
 +
* [[How to make a Screen for the Admin Section]]
 +
* [[How to make a Screen perform Actions]]
  
 
==== Input Component Plugin ====
 
==== Input Component Plugin ====
Line 42: Line 70:
 
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 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.
  
===== Convert Plugin =====
+
==== Convert Plugin ====
  
 
These are used for two things, currently.
 
These are used for two things, currently.
Line 54: Line 82:
 
* Powerpoint to Thumbnail to allow thumbnail and previews of powerpoint slides
 
* Powerpoint to Thumbnail to allow thumbnail and previews of powerpoint slides
 
* Video to Thumbnail/Preview to make a still preview of a video file.
 
* Video to Thumbnail/Preview to make a still preview of a video file.
 +
 +
== What next ==
 +
Try out some of the examples and see where you get to. If you hit problems you can always talk to EP-Tech. {{EPrintsTech}}.
 +
 +
Go take a look at [[Extension Packages]] for a bit more about how you can make your plugins richer.
 +
 +
Its probably a good a idea to look at [[Tips to write plugins|some tips]]. It will help you write better plugins.
 +
 +
Probably the best place you can go is your own perl_lib/EPrints/Plugin directory and have a look at some of similar cases. Or to [http://files.eprints.org http://files.eprints.org] to take a look at other peoples 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 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.

Latest revision as of 16:12, 2 November 2015


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 (don't be scared - its not hard and there are plenty of tutorials on the web)
  • An EPrints installation to play about on. A Virtual box with EPrints installed is ideal.
  • For some types of plugin you might also find some Javascript and CSS knowledge helpful.

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!

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...

Export Plugin

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:

Import Plugin

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:

Screen Plugin

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.

Convert Plugin

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.

What next

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 here: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech..

Go take a look at Extension Packages for a bit more about how you can make your plugins richer.

Its probably a good a idea to look at some tips. It will help you write better plugins.

Probably the best place you can go is your own perl_lib/EPrints/Plugin directory and have a look at some of similar cases. Or to http://files.eprints.org to take a look at other peoples 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.