From 3985a55beaece34946b9aac455db90cfff08c22e Mon Sep 17 00:00:00 2001 From: Bill Tomczak Date: Wed, 11 Sep 2019 16:16:37 -0700 Subject: [PATCH] Shorten view class hierarchy / centralize autoloaded classes --- src/admin/include.php | 6 +++ .../Free/Joomla/Controller/Admin/Emails.php | 5 --- .../library/Free/Joomla/View/Admin/Emails.php | 6 +-- src/admin/library/Free/Joomla/View/Legacy.php | 38 ------------------- .../library/Free/Joomla/View/Site/Base.php | 5 +-- .../library/Free/Joomla/View/Site/Item.php | 5 --- src/admin/library/MailingLists/Manager.php | 2 - src/admin/models/file.php | 3 -- .../OSDownloadsFiles/tmpl/default.php | 3 -- src/osdownloads.xml | 1 + src/site/models/fields/modal/document.php | 25 ++++-------- src/site/router.php | 2 - src/site/views/download/view.html.php | 4 +- 13 files changed, 20 insertions(+), 85 deletions(-) delete mode 100644 src/admin/library/Free/Joomla/View/Legacy.php diff --git a/src/admin/include.php b/src/admin/include.php index 61de6f63..1dca703e 100644 --- a/src/admin/include.php +++ b/src/admin/include.php @@ -55,6 +55,12 @@ require_once OSDOWNLOADS_ADMIN . '/vendor/autoload.php'; JLoader::register('ContentHelperRoute', JPATH_SITE . '/components/com_content/helpers/route.php'); + if (version_compare(JVERSION, '3.9.0', 'lt')) { + JLoader::register('JFile', JPATH_LIBRARIES . '/joomla/filesystem/file.php'); + JLoader::register('JFolder', JPATH_LIBRARIES . '/joomla/filesystem/folder.php'); + JLoader::register('JPagination', JPATH_LIBRARIES . '/joomla/html/pagination.php'); + JLoader::register('JLog', JPATH_LIBRARIES . '/joomla/log/log.php'); + } switch (JFactory::getApplication()->getName()) { case 'site': diff --git a/src/admin/library/Free/Joomla/Controller/Admin/Emails.php b/src/admin/library/Free/Joomla/Controller/Admin/Emails.php index 4f8265dc..9f40ffce 100644 --- a/src/admin/library/Free/Joomla/Controller/Admin/Emails.php +++ b/src/admin/library/Free/Joomla/Controller/Admin/Emails.php @@ -24,17 +24,12 @@ namespace Alledia\OSDownloads\Free\Joomla\Controller\Admin; use Alledia\Framework\Factory; -use Alledia\Framework\Joomla\Controller\Base as BaseController; -use Alledia\OSDownloads\Free\Joomla\Component\Site as FreeComponentSite; use Alledia\OSDownloads\Free\Factory as OSDFactory; use JControllerLegacy; use JText; defined('_JEXEC') or die(); -jimport('joomla.application.component.controller'); - - class Emails extends JControllerLegacy { public function delete() diff --git a/src/admin/library/Free/Joomla/View/Admin/Emails.php b/src/admin/library/Free/Joomla/View/Admin/Emails.php index c7e87dbf..ca9865f0 100644 --- a/src/admin/library/Free/Joomla/View/Admin/Emails.php +++ b/src/admin/library/Free/Joomla/View/Admin/Emails.php @@ -24,17 +24,16 @@ namespace Alledia\OSDownloads\Free\Joomla\View\Admin; use Alledia\Framework\Joomla\Extension\Licensed; -use Alledia\OSDownloads\Free\Joomla\View\Legacy as LegacyView; use Alledia\Framework\Factory; use JHtmlSidebar; use JPagination; use JToolBarHelper; use JText; +use JViewLegacy; defined('_JEXEC') or die(); - -class Emails extends LegacyView +class Emails extends JViewLegacy { /** * @var string @@ -135,7 +134,6 @@ public function display($tpl = null) $db->setQuery($query)->execute(); $total = $db->getNumRows(); - jimport('joomla.html.pagination'); $this->pagination = new JPagination($total, $limitstart, $limit); $db->setQuery($query, $this->pagination->limitstart, $this->pagination->limit); $this->items = (array)$db->loadObjectList(); diff --git a/src/admin/library/Free/Joomla/View/Legacy.php b/src/admin/library/Free/Joomla/View/Legacy.php deleted file mode 100644 index e2c96113..00000000 --- a/src/admin/library/Free/Joomla/View/Legacy.php +++ /dev/null @@ -1,38 +0,0 @@ -. - */ - -namespace Alledia\OSDownloads\Free\Joomla\View; - -defined('_JEXEC') or die(); - -if (!class_exists('JViewLegacy')) { - jimport('legacy.view.legacy'); -} - -use JViewLegacy; - - -class Legacy extends JViewLegacy -{ - -} diff --git a/src/admin/library/Free/Joomla/View/Site/Base.php b/src/admin/library/Free/Joomla/View/Site/Base.php index eee58918..2de0b210 100644 --- a/src/admin/library/Free/Joomla/View/Site/Base.php +++ b/src/admin/library/Free/Joomla/View/Site/Base.php @@ -23,13 +23,12 @@ namespace Alledia\OSDownloads\Free\Joomla\View\Site; -use Alledia\OSDownloads\Free\Joomla\View\Legacy; use Exception; +use JViewLegacy; defined('_JEXEC') or die(); - -class Base extends Legacy +class Base extends JViewLegacy { /** * @param string $tpl diff --git a/src/admin/library/Free/Joomla/View/Site/Item.php b/src/admin/library/Free/Joomla/View/Site/Item.php index 44241039..80cdf9b2 100644 --- a/src/admin/library/Free/Joomla/View/Site/Item.php +++ b/src/admin/library/Free/Joomla/View/Site/Item.php @@ -35,11 +35,6 @@ use JText; use OSDownloadsModelItem; -if (!class_exists('JViewLegacy')) { - jimport('legacy.view.legacy'); -} - - class Item extends Base { /** diff --git a/src/admin/library/MailingLists/Manager.php b/src/admin/library/MailingLists/Manager.php index 450bdb32..5476818c 100644 --- a/src/admin/library/MailingLists/Manager.php +++ b/src/admin/library/MailingLists/Manager.php @@ -134,8 +134,6 @@ public function loadForms(JForm $form) */ protected function getPluginFiles($type) { - jimport('joomla.filesystem.folder'); - $baseFolder = '/MailingList'; $regex = sprintf('\.%s$', $type); $extension = $this->getExtension(); diff --git a/src/admin/models/file.php b/src/admin/models/file.php index 5d6a2cd7..6ce7b943 100644 --- a/src/admin/models/file.php +++ b/src/admin/models/file.php @@ -249,10 +249,7 @@ protected function uploadFile(&$data) throw new Exception($errorMessage); } - jimport('joomla.filesystem.file'); if ($fileName = JFile::makeSafe($upload->get('name'))) { - jimport('joomla.filesystem.folder'); - if (!is_dir($this->uploadDir)) { if (is_file($this->uploadDir)) { throw new Exception(JText::_('COM_OSDOWNLOADS_UPLOAD_ERR_FILESYSTEM')); diff --git a/src/extensions/OSDownloadsFiles/tmpl/default.php b/src/extensions/OSDownloadsFiles/tmpl/default.php index 1dcd456e..938a0bc5 100644 --- a/src/extensions/OSDownloadsFiles/tmpl/default.php +++ b/src/extensions/OSDownloadsFiles/tmpl/default.php @@ -23,13 +23,10 @@ defined('_JEXEC') or die(); -use Alledia\Framework\Helper as AllediaHelper; use Alledia\OSDownloads\Free\Factory; use Alledia\OSDownloads\Free\Joomla\Component\Site as FreeComponentSite; use Joomla\Utilities\ArrayHelper; -jimport('joomla.application.component.helper'); - $app = JFactory::getApplication(); $doc = JFactory::getDocument(); $lang = JFactory::getLanguage(); diff --git a/src/osdownloads.xml b/src/osdownloads.xml index 6f37ba9d..30986484 100644 --- a/src/osdownloads.xml +++ b/src/osdownloads.xml @@ -139,6 +139,7 @@ administrator/components/com_osdownloads/models/abstract + administrator/com_osdownloads/library/Free/Joomla/View/Legacy.php administrator/components/com_osdownloads/models/items.php administrator/components/com_osdownloads/tables/abstract.php administrator/components/com_osdownloads/tables/abstractdocument.php diff --git a/src/site/models/fields/modal/document.php b/src/site/models/fields/modal/document.php index 109089cf..d30cb0a4 100644 --- a/src/site/models/fields/modal/document.php +++ b/src/site/models/fields/modal/document.php @@ -23,9 +23,6 @@ defined('JPATH_BASE') or die(); -jimport('joomla.html.html'); -jimport('joomla.form.formfield'); -jimport('joomla.form.helper'); JFormHelper::loadFieldClass('list'); class JFormFieldModal_Document extends JFormFieldList @@ -39,33 +36,27 @@ protected function getOptions() $db = JFactory::getDBO(); - $query = $db->getQuery(true); - $query->select("*"); - $query->from("#__osdownloads_documents"); - $query->where("published = 1"); + $query = $db->getQuery(true) + ->select('*') + ->from('#__osdownloads_documents') + ->where('published = 1'); + $db->setQuery($query); $rows = $db->loadObjectList(); foreach ($rows as $item) { - - // Create a new option object based on the