Added Plugins

This commit is contained in:
Tobias Reich 2014-04-02 19:30:58 +02:00
parent 3bb5511f81
commit 186efaf86f
4 changed files with 98 additions and 1 deletions

View File

@ -18,6 +18,9 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
define('LYCHEE', true); define('LYCHEE', true);
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
// Load autoload
require('autoload.php');
// Load modules // Load modules
require('modules/album.php'); require('modules/album.php');
require('modules/db.php'); require('modules/db.php');
@ -45,6 +48,10 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
$database = dbConnect(); $database = dbConnect();
$settings = getSettings(); $settings = getSettings();
// Init plugins
$plugins = explode(';', $settings['plugins']);
$plugins = new Plugins($plugins);
// Escape // Escape
foreach(array_keys($_POST) as $key) $_POST[$key] = mysqli_real_escape_string($database, urldecode($_POST[$key])); 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])); foreach(array_keys($_GET) as $key) $_GET[$key] = mysqli_real_escape_string($database, urldecode($_GET[$key]));

13
php/autoload.php Normal file
View 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
View 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;
}
}
?>

View File

@ -14,7 +14,7 @@ function getSettings() {
$result = $database->query('SELECT * FROM lychee_settings;'); $result = $database->query('SELECT * FROM lychee_settings;');
while($row = $result->fetch_object()) { while ($row = $result->fetch_object()) {
$return[$row->key] = $row->value; $return[$row->key] = $row->value;
} }