2014-04-02 17:30:58 +00:00
|
|
|
<?php
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
###
|
2014-10-21 11:45:11 +00:00
|
|
|
# @name Plugins Module
|
2015-02-01 21:08:37 +00:00
|
|
|
# @copyright 2015 by Tobias Reich
|
2014-04-02 20:14:20 +00:00
|
|
|
###
|
2014-04-02 17:30:58 +00:00
|
|
|
|
2014-04-16 08:13:30 +00:00
|
|
|
if (!defined('LYCHEE')) exit('Error: Direct access is not allowed!');
|
|
|
|
|
2016-01-19 10:45:41 +00:00
|
|
|
final class Plugins implements \SplSubject {
|
2014-04-02 17:30:58 +00:00
|
|
|
|
|
|
|
private $files = array();
|
|
|
|
private $observers = array();
|
|
|
|
|
|
|
|
public $action = null;
|
|
|
|
public $args = null;
|
|
|
|
|
2016-01-19 15:08:50 +00:00
|
|
|
public function __construct(array $files, $database, array $settings) {
|
2014-04-02 17:30:58 +00:00
|
|
|
|
|
|
|
if (!isset($files)) return false;
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Init vars
|
2016-01-19 15:08:43 +00:00
|
|
|
$this->files = $files;
|
2014-04-02 17:30:58 +00:00
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Load plugins
|
2014-04-02 17:30:58 +00:00
|
|
|
foreach ($this->files as $file) {
|
2014-05-17 14:51:56 +00:00
|
|
|
|
2014-04-02 17:30:58 +00:00
|
|
|
if ($file==='') continue;
|
2014-05-17 14:51:56 +00:00
|
|
|
|
|
|
|
$file = LYCHEE_PLUGINS . $file;
|
|
|
|
|
|
|
|
if (file_exists($file)===false) {
|
|
|
|
Log::warning($database, __METHOD__, __LINE__, 'Could not include plugin. File does not exist (' . $file . ').');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
include($file);
|
|
|
|
|
2014-04-02 17:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attach(\SplObserver $observer) {
|
|
|
|
|
|
|
|
if (!isset($observer)) return false;
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Add observer
|
2014-04-02 17:30:58 +00:00
|
|
|
$this->observers[] = $observer;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function detach(\SplObserver $observer) {
|
|
|
|
|
|
|
|
if (!isset($observer)) return false;
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Remove observer
|
2014-04-02 17:30:58 +00:00
|
|
|
$key = array_search($observer, $this->observers, true);
|
|
|
|
if ($key) unset($this->observers[$key]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function notify() {
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Notify each observer
|
2014-04-02 17:30:58 +00:00
|
|
|
foreach ($this->observers as $value) $value->update($this);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function activate($action, $args) {
|
|
|
|
|
|
|
|
if (!isset($action, $args)) return false;
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Save vars
|
2014-04-02 17:30:58 +00:00
|
|
|
$this->action = $action;
|
|
|
|
$this->args = $args;
|
|
|
|
|
2014-04-02 20:14:20 +00:00
|
|
|
# Notify observers
|
2014-04-02 17:30:58 +00:00
|
|
|
$this->notify();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-07 21:44:42 +00:00
|
|
|
?>
|