Просмотр исходного кода

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
Alexandre Alapetite 11 лет назад
Родитель
Сommit
febabccdd5
4 измененных файлов с 72 добавлено и 0 удалено
  1. 21 0
      app/FreshRSS.php
  2. 1 0
      extensions/.gitignore
  3. 15 0
      extensions/Read-me.txt
  4. 35 0
      p/ext.php

+ 21 - 0
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
+				} 
+			}
+		}
+	}
 }

+ 1 - 0
extensions/.gitignore

@@ -0,0 +1 @@
+/[xX]

+ 15 - 0
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'.

+ 35 - 0
p/ext.php

@@ -0,0 +1,35 @@
+<?php
+if (!isset($_GET['e'])) {
+	header('HTTP/1.1 400 Bad Request');
+	die();
+}
+$extension = substr($_GET['e'], 0, 64);
+if (!ctype_alpha($extension)) {
+	header('HTTP/1.1 400 Bad Request');
+	die();
+}
+
+require('../constants.php');
+$filename = FRESHRSS_PATH . '/extensions/' . $extension . '/';
+
+if (isset($_GET['j'])) {
+	header('Content-Type: application/javascript; charset=UTF-8');
+	header('Content-Disposition: inline; filename="script.js"');
+	$filename .= 'script.js';
+} elseif (isset($_GET['c'])) {
+	header('Content-Type: text/css; charset=UTF-8');
+	header('Content-Disposition: inline; filename="style.css"');
+	$filename .= 'style.css';
+}
+
+$mtime = @filemtime($filename);
+if ($mtime == false) {
+	header('HTTP/1.1 404 Not Found');
+	die();
+}
+
+require(LIB_PATH . '/http-conditional.php');
+
+if (!httpConditional($mtime, 604800, 2)) {
+	readfile($filename);
+}