ソースを参照

First draft for listing and manipulate extensions

See https://github.com/FreshRSS/FreshRSS/issues/252
Marien Fressinaud 11 年 前
コミット
9fc60317ee

+ 43 - 0
app/Controllers/extensionController.php

@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * The controller to manage extensions.
+ */
+class FreshRSS_extension_Controller extends Minz_ActionController {
+	/**
+	 * This action is called before every other action in that class. It is
+	 * the common boiler plate for every action. It is triggered by the
+	 * underlying framework.
+	 */
+	public function firstAction() {
+		if (!FreshRSS_Auth::hasAccess()) {
+			Minz_Error::error(403);
+		}
+	}
+
+	/**
+	 * This action lists all the extensions available to the current user.
+	 */
+	public function indexAction() {
+		Minz_View::prependTitle(_t('admin.extensions.title') . ' · ');
+		$this->view->extension_list = Minz_ExtensionManager::list_extensions();
+	}
+
+	public function configureAction() {
+		if (Minz_Request::param('ajax')) {
+			$this->view->_useLayout(false);
+		}
+	}
+
+	public function enableAction() {
+		
+	}
+
+	public function disableAction() {
+		
+	}
+
+	public function removeAction() {
+		
+	}
+}

+ 4 - 0
app/layout/aside_configure.phtml

@@ -22,6 +22,10 @@
 	                          Minz_Request::actionName() === 'profile'? ' active' : ''; ?>">
 		<a href="<?php echo _url('user', 'profile'); ?>"><?php echo _t('gen.menu.user_profile'); ?></a>
 	</li>
+	<li class="item<?php echo Minz_Request::controllerName() === 'extension' &&
+	                          Minz_Request::actionName() === 'index'? ' active' : ''; ?>">
+		<a href="<?php echo _url('extension', 'index'); ?>"><?php echo _t('gen.menu.extensions'); ?></a>
+	</li>
 	<?php if (FreshRSS_Auth::hasAccess('admin')) { ?>
 	<li class="nav-header"><?php echo _t('gen.menu.admin'); ?></li>
 	<li class="item<?php echo Minz_Request::controllerName() === 'user' &&

+ 1 - 0
app/layout/header.phtml

@@ -63,6 +63,7 @@ if (Minz_Configuration::canLogIn()) {
 				<li class="item"><a href="<?php echo _url('configure', 'shortcut'); ?>"><?php echo _t('shortcuts'); ?></a></li>
 				<li class="item"><a href="<?php echo _url('configure', 'queries'); ?>"><?php echo _t('queries'); ?></a></li>
 				<li class="item"><a href="<?php echo _url('user', 'profile'); ?>"><?php echo _t('gen.menu.user_profile'); ?></a></li>
+				<li class="item"><a href="<?php echo _url('extension', 'index'); ?>"><?php echo _t('gen.menu.extensions'); ?></a></li>
 				<?php if (FreshRSS_Auth::hasAccess('admin')) { ?>
 				<li class="separator"></li>
 				<li class="dropdown-header"><?php echo _t('gen.menu.admin'); ?></li>

+ 35 - 0
app/views/extension/index.phtml

@@ -0,0 +1,35 @@
+<?php $this->partial('aside_configure'); ?>
+
+<div class="post">
+	<a href="<?php echo _url('index', 'index'); ?>"><?php echo _t('gen.back_to_rss_feeds'); ?></a>
+
+	<h1><?php echo _t('admin.extensions.title'); ?></h1>
+
+	<?php if (!empty($this->extension_list)) { ?>
+	<form id="form-extension" method="post" style="display: none"></form>
+	<?php foreach ($this->extension_list as $ext) { ?>
+	<ul class="horizontal-list">
+		<li class="item">
+			<?php $name_encoded = urlencode($ext->getName()); ?>
+			<div class="stick">
+				<a class="btn open-slider" href="<?php echo _url('extension', 'configure', 'e', $name_encoded); ?>"><?php echo _i('configure'); ?> <?php echo _t('admin.extensions.manage'); ?></a>
+				<?php if ($ext->is_enabled()) { ?>
+				<button class="btn" form="form-extension" formaction="<?php echo _url('extension', 'disable', 'e', $name_encoded); ?>"><?php echo _t('admin.extensions.disable'); ?></button>
+				<?php } else { ?>
+				<button class="btn" form="form-extension" formaction="<?php echo _url('extension', 'enable', 'e', $name_encoded); ?>"><?php echo _t('admin.extensions.enable'); ?></button>
+				<?php } ?>
+				<?php if (FreshRSS_Auth::hasAccess('admin')) { ?>
+				<button class="btn btn-attention confirm" form="form-extension" formaction="<?php echo _url('extension', 'remove', 'e', $name_encoded); ?>"><?php echo _t('admin.extensions.remove'); ?></button>
+				<?php } ?>
+			</div>
+		</li>
+		<li class="item"><?php echo $ext->getName(); ?></li>
+	</ul>
+	<?php } ?>
+	<?php } else { ?>
+	<p class="alert alert-warn"><?php echo _t('admin.extensions.empty_list'); ?></p>
+	<?php } ?>
+</div>
+
+<a href="#" id="close-slider"></a>
+<div id="slider"></div>

+ 20 - 0
lib/Minz/Extension.php

@@ -17,6 +17,8 @@ class Minz_Extension {
 		'user',
 	);
 
+	private $is_enabled;
+
 	/**
 	 * The constructor to assign specific information to the extension.
 	 *
@@ -41,6 +43,8 @@ class Minz_Extension {
 		$this->description = isset($meta_info['description']) ? $meta_info['description'] : '';
 		$this->version = isset($meta_info['version']) ? $meta_info['version'] : '0.1';
 		$this->setType(isset($meta_info['type']) ? $meta_info['type'] : 'user');
+
+		$this->is_enabled = false;
 	}
 
 	/**
@@ -66,6 +70,22 @@ class Minz_Extension {
 	 */
 	public function init() {}
 
+	/**
+	 * Set the current extension to enable.
+	 */
+	public function enable() {
+		$this->is_enabled = true;
+	}
+
+	/**
+	 * Return if the extension is currently enabled.
+	 *
+	 * @return true if extension is enabled, false else.
+	 */
+	public function is_enabled() {
+		return $this->is_enabled;
+	}
+
 	/**
 	 * Getters and setters.
 	 */

+ 17 - 0
lib/Minz/ExtensionManager.php

@@ -144,6 +144,7 @@ class Minz_ExtensionManager {
 		if (isset(self::$ext_list[$ext_name])) {
 			$ext = self::$ext_list[$ext_name];
 			self::$ext_list_enabled[$ext_name] = $ext;
+			$ext->enable();
 			$ext->init();
 		}
 	}
@@ -158,4 +159,20 @@ class Minz_ExtensionManager {
 			self::enable($ext_name);
 		}
 	}
+
+
+
+	/**
+	 * Returns a list of extensions.
+	 *
+	 * @param $only_enabled if true returns only the enabled extensions (false by default).
+	 * @return an array of extensions.
+	 */
+	public static function list_extensions($only_enabled = false) {
+		if ($only_enabled) {
+			return self::$ext_list_enabled;
+		} else {
+			return self::$ext_list;
+		}
+	}
 }