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!');
class ExamplePlugin implements SplObserver {
private $database = null;
private $settings = null;
public function __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
return true;
}
public function update(\SplSubject $subject) {
# Check if the called hook is the hook you are waiting for
# A list of all hooks is available online
if ($subject->action!=='Photo::add:before') return false;
# Do something when Photo::add:before gets called
# $this->database => The database of Lychee
# $this->settings => The settings of Lychee
# $subject->args => Params passed to the original function
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`.