소스 검색

Add behaviour to configure action (extensions)

- Put extension configure view in dir_ext/configure.phtml
- Handle POST action in Extension->handleConfigureAction() method

See https://github.com/FreshRSS/FreshRSS/issues/252
Marien Fressinaud 11 년 전
부모
커밋
c6dfec3ad3
3개의 변경된 파일51개의 추가작업 그리고 3개의 파일을 삭제
  1. 16 0
      app/Controllers/extensionController.php
  2. 14 3
      app/views/extension/configure.phtml
  3. 21 0
      lib/Minz/Extension.php

+ 16 - 0
app/Controllers/extensionController.php

@@ -27,6 +27,22 @@ class FreshRSS_extension_Controller extends Minz_ActionController {
 		if (Minz_Request::param('ajax')) {
 		if (Minz_Request::param('ajax')) {
 			$this->view->_useLayout(false);
 			$this->view->_useLayout(false);
 		}
 		}
+
+		$ext_name = urldecode(Minz_Request::param('e'));
+		$ext = Minz_ExtensionManager::find_extension($ext_name);
+
+		if (is_null($ext)) {
+			Minz_Error::error(404);
+		}
+		if ($ext->getType() === 'system' && !FreshRSS_Auth::hasAccess('admin')) {
+			Minz_Error::error(403);
+		}
+
+		$this->view->extension = $ext;
+
+		if (Minz_Request::isPost()) {
+			$this->view->extension->handleConfigureAction();
+		}
 	}
 	}
 
 
 	/**
 	/**

+ 14 - 3
app/views/extension/configure.phtml

@@ -7,6 +7,17 @@ if (!Minz_Request::param('ajax')) {
 ?>
 ?>
 
 
 <div class="post">
 <div class="post">
-	<h1>Extension name</h1>
-	Not implemented yet!
-</div>
+	<h1><?php echo $this->extension->getName(); ?> (<?php echo $this->extension->getVersion(); ?>) — <?php echo $this->extension->getType(); ?></h1>
+
+	<p class="alert alert-warn"><?php echo $this->extension->getDescription(); ?> — <?php echo _t('gen.by'), ' ', $this->extension->getAuthor(); ?></p>
+
+	<h2><?php echo _t('gen.actions.manage'); ?></h2>
+	<?php
+		$configure_view = $this->extension->getConfigureView();
+		if ($configure_view !== false) {
+			echo $configure_view;
+		} else {
+	?>
+	<p class="alert alert-warn"><?php echo _t('admin.extensions.no_configure_view'); ?></p>
+	<?php } ?>
+</div>

+ 21 - 0
lib/Minz/Extension.php

@@ -86,6 +86,27 @@ class Minz_Extension {
 		return $this->is_enabled;
 		return $this->is_enabled;
 	}
 	}
 
 
+	/**
+	 * Return the content of the configure view for the current extension.
+	 *
+	 * @return the html content from ext_dir/configure.phtml, false if it does
+	 *         not exist.
+	 */
+	public function getConfigureView() {
+		$filename = $this->path . '/configure.phtml';
+		if (!file_exists($filename)) {
+			return false;
+		}
+		return @file_get_contents($filename);
+	}
+
+	/**
+	 * Handle the configure POST action.
+	 *
+	 * It must be redefined by child classes.
+	 */
+	public function handleConfigureAction() {}
+
 	/**
 	/**
 	 * Getters and setters.
 	 * Getters and setters.
 	 */
 	 */