The plugin-system of Lychee allows you to execute scripts, when a certain action fires. Plugins are hooks, which are injected directly into Lychee. They only affect the back-end and can't modify the front-end.
### Use Cases
* Automatically watermark photos on upload
* Automatically set albums public
* Write metadata changes back to the original photo
* …
### How to create a plugin
1. Create a folder in `plugins/`
2. Create an `index.php` within the new folder and with the following content:
```php
<?php
###
# @name ExamplePlugin
# @author Tobias Reich
# @copyright 2014 by Tobias Reich
###
if(!defined('LYCHEE'))exit('Error: Direct access is not allowed!');
classExamplePluginimplementsSplObserver{
private$database=null;
private$settings=null;
publicfunction__construct($database,$settings){
# These params are passed to your plugin from Lychee
# Save them to access the database and settings of Lychee
$this->database=$database;
$this->settings=$settings;
# Add more code here if wanted
# __construct() will be called every time Lychee gets called
# Make sure this part is performant
returntrue;
}
publicfunctionupdate(\SplSubject$subject){
# Check if the called hook is the hook you are waiting for
Select the table `lychee_settings` and edit the value of `plugins` to the path of your plugin. The path must be relative from the `plugins/`-folder: `ExamplePlugin/index.php`.
Divide multiple plugins with commas: `Plugin01/index.php,Plugin02/index.php`.
### Available hooks
##### About :before and :after
Hooks named `:before` will be executed prior to the original function.
Hooks named `:after` will be executed after the original function.
`Album::add:before` will be called when the user creates a new album in Lychee. The album doesn't exist at this moment.
`Album::add:after` will be called after the album has been created.
##### Album
These hooks are called from `php/modules/Album.php`.
| Name | Description |
|:-----------|:------------|:------------|
| Album::add:before | User adds album |
| Album::add:after | |
| Album::get:before | User opens album |
| Album::get:after | |
| Album::getAll:before | User opens album overview |
| Album::getAll:after | |
| Album::getArchive:before | User downloads album |
| Album::getArchive:after | |
| Album::setTitle:before | User renames album |
| Album::setTitle:after | |
| Album::setDescription:before | User sets description |
| Album::setDescription:after | |
| Album::getPublic:before | User makes album public or private |
| Album::getPublic:after | |
| Album::setPassword:before | User sets password |
| Album::setPassword:after | |
| Album::checkPassword:before | Lychee checks if password is correct |
| Album::checkPassword:after | |
| Album::delete:before | User deletes album |
| Album::delete:after | |
##### Photo
These hooks are called from `php/modules/Photo.php`.
@@ -41,7 +41,7 @@ Lychee supports [Twitter Cards](https://dev.twitter.com/docs/cards) and [Open Gr
### Plugins and Extensions
The plugin-system of Lychee allows you to execute scripts, when a certain action fires. Plugins are hooks, which are injected directly into Lychee. [Plugin documentation »](docs/)
The plugin-system of Lychee allows you to execute scripts, when a certain action fires. Plugins are hooks, which are injected directly into Lychee. [Plugin documentation »](docs/Plugins.md)
It's also possible to build extensions upon Lychee. The way to do so isn't documented and can change every time. We recommend to use the plugin-system, when possible.