diff --git a/php/api.php b/php/api.php index cfdfa08..f409791 100755 --- a/php/api.php +++ b/php/api.php @@ -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])); diff --git a/php/autoload.php b/php/autoload.php new file mode 100644 index 0000000..cbf3211 --- /dev/null +++ b/php/autoload.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/php/modules/Plugins.php b/php/modules/Plugins.php new file mode 100644 index 0000000..b59e812 --- /dev/null +++ b/php/modules/Plugins.php @@ -0,0 +1,77 @@ +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; + + } + +} + +?> \ No newline at end of file diff --git a/php/modules/settings.php b/php/modules/settings.php index 94da29c..2a7b4e0 100755 --- a/php/modules/settings.php +++ b/php/modules/settings.php @@ -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; }