From 0c243d75c8cd4ed0f8a7207a24c82cba39b43eb2 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Sat, 3 Mar 2018 06:01:21 +0200 Subject: [PATCH] Added temp workaround for gh-238 to insure component behave correctly with cache enabled on website --- README.md | 2 +- admin/README.txt | 2 +- .../joomla_3/JControllerLegacySITE.php | 45 +++++++++++++++++-- site/controller.php | 45 +++++++++++++++++-- 4 files changed, 84 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index fe4a09d38..87766018e 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ Component Builder is mapped as a component in itself on my local development env + *Version*: 2.6.17 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **183530** ++ *Line count*: **183567** + *Field count*: **1645** + *File count*: **1169** + *Folder count*: **189** diff --git a/admin/README.txt b/admin/README.txt index fe4a09d38..87766018e 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -130,7 +130,7 @@ Component Builder is mapped as a component in itself on my local development env + *Version*: 2.6.17 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **183530** ++ *Line count*: **183567** + *Field count*: **1645** + *File count*: **1169** + *Folder count*: **189** diff --git a/admin/compiler/joomla_3/JControllerLegacySITE.php b/admin/compiler/joomla_3/JControllerLegacySITE.php index effb2a5a9..7d9a3f208 100644 --- a/admin/compiler/joomla_3/JControllerLegacySITE.php +++ b/admin/compiler/joomla_3/JControllerLegacySITE.php @@ -38,18 +38,30 @@ jimport('joomla.application.component.controller'); class ###Component###Controller extends JControllerLegacy { /** - * display task + * Method to display a view. + * + * @param boolean $cachable If true, the view output will be cached. + * @param boolean $urlparams An array of safe URL parameters and their variable types, for valid values see {@link JFilterInput::clean()}. + * + * @return JController This object to support chaining. * - * @return void */ function display($cachable = false, $urlparams = false) { // set default view if not set $view = $this->input->getCmd('view', '###SITE_DEFAULT_VIEW###'); + $this->input->set('view', $view); $isEdit = $this->checkEditView($view); $layout = $this->input->get('layout', null, 'WORD'); $id = $this->input->getInt('id'); - $cachable = true; + // $cachable = true; (TODO) working on a fix [gh-238](https://github.com/vdm-io/Joomla-Component-Builder/issues/238) + + // insure that the view is not cashable if edit view or if user is logged in + $user = JFactory::getUser(); + if ($user->get('id') || $isEdit) + { + $cachable = false; + } // Check for edit form. if($isEdit) @@ -81,8 +93,33 @@ class ###Component###Controller extends JControllerLegacy return false; } } + + // we may need to make this more dynamic in the future. (TODO) + $safeurlparams = array( + 'catid' => 'INT', + 'id' => 'INT', + 'cid' => 'ARRAY', + 'year' => 'INT', + 'month' => 'INT', + 'limit' => 'UINT', + 'limitstart' => 'UINT', + 'showall' => 'INT', + 'return' => 'BASE64', + 'filter' => 'STRING', + 'filter_order' => 'CMD', + 'filter_order_Dir' => 'CMD', + 'filter-search' => 'STRING', + 'print' => 'BOOLEAN', + 'lang' => 'CMD', + 'Itemid' => 'INT'); - return parent::display($cachable, $urlparams); + // should these not merge? + if (###Component###Helper::checkArray($urlparams)) + { + $safeurlparams = ###Component###Helper::mergeArrays(array($urlparams, $safeurlparams)); + } + + return parent::display($cachable, $safeurlparams); } protected function checkEditView($view) diff --git a/site/controller.php b/site/controller.php index 40bb93a7e..2712beec1 100644 --- a/site/controller.php +++ b/site/controller.php @@ -35,18 +35,30 @@ jimport('joomla.application.component.controller'); class ComponentbuilderController extends JControllerLegacy { /** - * display task + * Method to display a view. + * + * @param boolean $cachable If true, the view output will be cached. + * @param boolean $urlparams An array of safe URL parameters and their variable types, for valid values see {@link JFilterInput::clean()}. + * + * @return JController This object to support chaining. * - * @return void */ function display($cachable = false, $urlparams = false) { // set default view if not set $view = $this->input->getCmd('view', ''); + $this->input->set('view', $view); $isEdit = $this->checkEditView($view); $layout = $this->input->get('layout', null, 'WORD'); $id = $this->input->getInt('id'); - $cachable = true; + // $cachable = true; (TODO) working on a fix [gh-238](https://github.com/vdm-io/Joomla-Component-Builder/issues/238) + + // insure that the view is not cashable if edit view or if user is logged in + $user = JFactory::getUser(); + if ($user->get('id') || $isEdit) + { + $cachable = false; + } // Check for edit form. if($isEdit) @@ -78,8 +90,33 @@ class ComponentbuilderController extends JControllerLegacy return false; } } + + // we may need to make this more dynamic in the future. (TODO) + $safeurlparams = array( + 'catid' => 'INT', + 'id' => 'INT', + 'cid' => 'ARRAY', + 'year' => 'INT', + 'month' => 'INT', + 'limit' => 'UINT', + 'limitstart' => 'UINT', + 'showall' => 'INT', + 'return' => 'BASE64', + 'filter' => 'STRING', + 'filter_order' => 'CMD', + 'filter_order_Dir' => 'CMD', + 'filter-search' => 'STRING', + 'print' => 'BOOLEAN', + 'lang' => 'CMD', + 'Itemid' => 'INT'); - return parent::display($cachable, $urlparams); + // should these not merge? + if (ComponentbuilderHelper::checkArray($urlparams)) + { + $safeurlparams = ComponentbuilderHelper::mergeArrays(array($urlparams, $safeurlparams)); + } + + return parent::display($cachable, $safeurlparams); } protected function checkEditView($view)