From febabccdd5e6db573ab80bd5c1758d136b91cd78 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 5 Oct 2014 12:14:22 +0200 Subject: Primitive extension system https://github.com/marienfressinaud/FreshRSS/issues/252 I have been using this extension system for a little while, in particular to include custom CSS and/or JavaScript (inclusion of PHP code is not done yet). There is very little code and it does not impact performances. I hurry to post it before https://github.com/marienfressinaud/FreshRSS/issues/655 --- app/FreshRSS.php | 21 +++++++++++++++++++++ extensions/.gitignore | 1 + extensions/Read-me.txt | 15 +++++++++++++++ p/ext.php | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 extensions/.gitignore create mode 100644 extensions/Read-me.txt create mode 100644 p/ext.php diff --git a/app/FreshRSS.php b/app/FreshRSS.php index cdf8962cb..58aac4059 100644 --- a/app/FreshRSS.php +++ b/app/FreshRSS.php @@ -17,6 +17,7 @@ class FreshRSS extends Minz_FrontController { Minz_View::_param('loginOk', $loginOk); $this->loadStylesAndScripts($loginOk); //TODO: Do not load that when not needed, e.g. some Ajax requests $this->loadNotifications(); + $this->loadExtensions(); } private static function getCredentialsFromLongTermCookie() { @@ -179,4 +180,24 @@ class FreshRSS extends Minz_FrontController { Minz_Session::_param ('notification'); } } + + private function loadExtensions() { + $extensionPath = FRESHRSS_PATH . '/extensions/'; + //TODO: Add a preference to load only user-selected extensions + foreach (scandir($extensionPath) as $key => $extension) { + if (ctype_alpha($extension)) { + $mtime = @filemtime($extensionPath . $extension . '/style.css'); + if ($mtime !== false) { + Minz_View::appendStyle(Minz_Url::display('/ext.php?c&e=' . $extension . '&' . $mtime)); + } + $mtime = @filemtime($extensionPath . $extension . '/script.js'); + if ($mtime !== false) { + Minz_View::appendScript(Minz_Url::display('/ext.php?j&e=' . $extension . '&' . $mtime)); + } + if (file_exists($extensionPath . $extension . '/module.php')) { + //TODO: include + } + } + } + } } diff --git a/extensions/.gitignore b/extensions/.gitignore new file mode 100644 index 000000000..d93e5e396 --- /dev/null +++ b/extensions/.gitignore @@ -0,0 +1 @@ +/[xX] diff --git a/extensions/Read-me.txt b/extensions/Read-me.txt new file mode 100644 index 000000000..e7b66d5bc --- /dev/null +++ b/extensions/Read-me.txt @@ -0,0 +1,15 @@ +== FreshRSS extensions == + +You may place in this directory some custom extensions for FreshRSS. + +The structure must be: + +./FreshRSS/extensions/ + ./NameOfExtensionAlphanumeric/ + ./style.css + ./script.js + ./module.php + +Each file is optional. + +The name of non-official extensions should start by an 'x'. diff --git a/p/ext.php b/p/ext.php new file mode 100644 index 000000000..cff194343 --- /dev/null +++ b/p/ext.php @@ -0,0 +1,35 @@ +