Added Plugins
This commit is contained in:
parent
3bb5511f81
commit
186efaf86f
@ -18,6 +18,9 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
|
||||
define('LYCHEE', true);
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
// Load autoload
|
||||
require('autoload.php');
|
||||
|
||||
// Load modules
|
||||
require('modules/album.php');
|
||||
require('modules/db.php');
|
||||
@ -45,6 +48,10 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
|
||||
$database = dbConnect();
|
||||
$settings = getSettings();
|
||||
|
||||
// Init plugins
|
||||
$plugins = explode(';', $settings['plugins']);
|
||||
$plugins = new Plugins($plugins);
|
||||
|
||||
// Escape
|
||||
foreach(array_keys($_POST) as $key) $_POST[$key] = mysqli_real_escape_string($database, urldecode($_POST[$key]));
|
||||
foreach(array_keys($_GET) as $key) $_GET[$key] = mysqli_real_escape_string($database, urldecode($_GET[$key]));
|
||||
|
13
php/autoload.php
Normal file
13
php/autoload.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @name Autoload
|
||||
* @author Tobias Reich
|
||||
* @copyright 2014 by Tobias Reich
|
||||
*/
|
||||
|
||||
function __autoload($class_name) {
|
||||
require './modules/' . $class_name . '.php';
|
||||
}
|
||||
|
||||
?>
|
77
php/modules/Plugins.php
Normal file
77
php/modules/Plugins.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @name Plugins Module
|
||||
* @author Tobias Reich
|
||||
* @copyright 2014 by Tobias Reich
|
||||
*/
|
||||
|
||||
class Plugins implements \SplSubject {
|
||||
|
||||
private $files = array();
|
||||
private $observers = array();
|
||||
|
||||
public $action = null;
|
||||
public $args = null;
|
||||
|
||||
public function __construct($files) {
|
||||
|
||||
if (!isset($files)) return false;
|
||||
|
||||
$plugins = $this;
|
||||
$this->files = $files;
|
||||
|
||||
foreach ($this->files as $file) {
|
||||
if ($file==='') continue;
|
||||
include('../plugins/' . $file);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function attach(\SplObserver $observer) {
|
||||
|
||||
if (!isset($observer)) return false;
|
||||
|
||||
$this->observers[] = $observer;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function detach(\SplObserver $observer) {
|
||||
|
||||
if (!isset($observer)) return false;
|
||||
|
||||
$key = array_search($observer, $this->observers, true);
|
||||
if ($key) unset($this->observers[$key]);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function notify() {
|
||||
|
||||
foreach ($this->observers as $value) $value->update($this);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function activate($action, $args) {
|
||||
|
||||
if (!isset($action, $args)) return false;
|
||||
|
||||
$this->action = $action;
|
||||
$this->args = $args;
|
||||
|
||||
$this->notify();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -14,7 +14,7 @@ function getSettings() {
|
||||
|
||||
$result = $database->query('SELECT * FROM lychee_settings;');
|
||||
|
||||
while($row = $result->fetch_object()) {
|
||||
while ($row = $result->fetch_object()) {
|
||||
$return[$row->key] = $row->value;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user