A free, self-hostable news aggregator…
Allow to change the view layout (#2467)
Marien Fressinaud49e1a2c57975
diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.phpindex 9c5ee2616..0215128f4 100755--- a/app/Controllers/entryController.php+++ b/app/Controllers/entryController.php@@ -17,7 +17,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController {// If ajax request, we do not print layout$this->ajax = Minz_Request::param('ajax');if ($this->ajax) {- $this->view->_useLayout(false);+ $this->view->_layout(false);Minz_Request::_param('ajax');}}diff --git a/app/Controllers/extensionController.php b/app/Controllers/extensionController.phpindex 806e5a696..9a523e0ad 100644--- a/app/Controllers/extensionController.php+++ b/app/Controllers/extensionController.php@@ -80,7 +80,7 @@ class FreshRSS_extension_Controller extends Minz_ActionController {*/public function configureAction() {if (Minz_Request::param('ajax')) {- $this->view->_useLayout(false);+ $this->view->_layout(false);} else {$this->indexAction();$this->view->change_view('extension', 'index');diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.phpindex 862bb10fb..c2c0cce37 100755--- a/app/Controllers/feedController.php+++ b/app/Controllers/feedController.php@@ -530,7 +530,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {);Minz_Session::_param('notification', $notif);// No layout in ajax request.- $this->view->_useLayout(false);+ $this->view->_layout(false);} else {// Redirect to the main page with correct notification.if ($updated_feeds === 1) {diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.phpindex 1d7176929..51fec75eb 100644--- a/app/Controllers/importExportController.php+++ b/app/Controllers/importExportController.php@@ -773,7 +773,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {if (!Minz_Request::isPost()) {Minz_Request::forward(array('c' => 'importExport', 'a' => 'index'), true);}- $this->view->_useLayout(false);+ $this->view->_layout(false);$nb_files = 0;try {diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.phpindex f536113dd..4023492d2 100755--- a/app/Controllers/indexController.php+++ b/app/Controllers/indexController.php@@ -155,7 +155,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {// No layout for RSS output.$this->view->url = PUBLIC_TO_INDEX_PATH . '/' . (empty($_SERVER['QUERY_STRING']) ? '' : '?' . $_SERVER['QUERY_STRING']);$this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title();- $this->view->_useLayout(false);+ $this->view->_layout(false);header('Content-Type: application/rss+xml; charset=utf-8');}diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.phpindex d56da9cbb..c84e5483b 100755--- a/app/Controllers/javascriptController.php+++ b/app/Controllers/javascriptController.php@@ -2,7 +2,7 @@class FreshRSS_javascript_Controller extends Minz_ActionController {public function firstAction() {- $this->view->_useLayout(false);+ $this->view->_layout(false);}public function actualizeAction() {diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.phpindex 79da39751..f6d5e9457 100644--- a/app/Controllers/subscriptionController.php+++ b/app/Controllers/subscriptionController.php@@ -74,7 +74,7 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {*/public function feedAction() {if (Minz_Request::param('ajax')) {- $this->view->_useLayout(false);+ $this->view->_layout(false);}$feedDAO = FreshRSS_Factory::createFeedDao();@@ -152,7 +152,7 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {}public function categoryAction() {- $this->view->_useLayout(false);+ $this->view->_layout(false);$categoryDAO = FreshRSS_Factory::createCategoryDao();diff --git a/app/Controllers/tagController.php b/app/Controllers/tagController.phpindex 106e0afa8..ba9efe2fc 100644--- a/app/Controllers/tagController.php+++ b/app/Controllers/tagController.php@@ -16,7 +16,7 @@ class FreshRSS_tag_Controller extends Minz_ActionController {// If ajax request, we do not print layout$this->ajax = Minz_Request::param('ajax');if ($this->ajax) {- $this->view->_useLayout(false);+ $this->view->_layout(false);Minz_Request::_param('ajax');}}@@ -70,7 +70,7 @@ class FreshRSS_tag_Controller extends Minz_ActionController {}public function getTagsForEntryAction() {- $this->view->_useLayout(false);+ $this->view->_layout(false);header('Content-Type: application/json; charset=UTF-8');header('Cache-Control: private, no-cache, no-store, must-revalidate');$id_entry = Minz_Request::param('id_entry', 0);diff --git a/lib/Minz/View.php b/lib/Minz/View.phpindex d6bf6ea2c..6f044c98e 100644--- a/lib/Minz/View.php+++ b/lib/Minz/View.php@@ -9,11 +9,11 @@*/class Minz_View {const VIEWS_PATH_NAME = '/views';- const LAYOUT_PATH_NAME = '/layout';- const LAYOUT_FILENAME = '/layout.phtml';+ const LAYOUT_PATH_NAME = '/layout/';+ const LAYOUT_DEFAULT = 'layout';private $view_filename = '';- private $use_layout = true;+ private $layout_filename = '';private static $base_pathnames = array(APP_PATH);private static $title = '';@@ -30,6 +30,7 @@ class Minz_View {$this->change_view(Minz_Request::controllerName(),Minz_Request::actionName());+ $this->_layout(self::LAYOUT_DEFAULT);$conf = Minz_Configuration::get('system');self::$title = $conf->title;}@@ -58,7 +59,7 @@ class Minz_View {* Construit la vue*/public function build () {- if ($this->use_layout) {+ if ($this->layout_filename !== '') {$this->buildLayout ();} else {$this->render ();@@ -92,7 +93,9 @@ class Minz_View {*/public function buildLayout () {header('Content-Type: text/html; charset=UTF-8');- $this->includeFile(self::LAYOUT_PATH_NAME . self::LAYOUT_FILENAME);+ if (!$this->includeFile($this->layout_filename)) {+ Minz_Log::notice('File not found: `' . $this->layout_filename . '`');+ }}/**@@ -137,11 +140,29 @@ class Minz_View {}/**- * Permet de choisir si on souhaite utiliser le layout- * @param $use true si on souhaite utiliser le layout, false sinon+ * Choose the current view layout.+ * @param $layout the layout name to use, false to use no layouts.+ */+ public function _layout($layout) {+ if ($layout) {+ $this->layout_filename = self::LAYOUT_PATH_NAME . $layout . '.phtml';+ } else {+ $this->layout_filename = '';+ }+ }++ /**+ * [deprecated] Choose if we want to use the layout or not.+ * Please use the `_layout` function instead.+ * @param $use true if we want to use the layout, false else*/public function _useLayout ($use) {- $this->use_layout = $use;+ Minz_Log::warning('Minz_View::_useLayout is deprecated, it will be removed in a future version. Please use Minz_View::_layout instead.');+ if ($use) {+ $this->_layout(self::LAYOUT_DEFAULT);+ } else {+ $this->_layout(false);+ }}/**