Skip to content

Commit

Permalink
Shorten view class hierarchy / centralize autoloaded classes
Browse files Browse the repository at this point in the history
  • Loading branch information
billtomczak committed Sep 11, 2019
1 parent 60d501a commit 3985a55
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 85 deletions.
6 changes: 6 additions & 0 deletions src/admin/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
5 changes: 0 additions & 5 deletions src/admin/library/Free/Joomla/Controller/Admin/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 2 additions & 4 deletions src/admin/library/Free/Joomla/View/Admin/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
38 changes: 0 additions & 38 deletions src/admin/library/Free/Joomla/View/Legacy.php

This file was deleted.

5 changes: 2 additions & 3 deletions src/admin/library/Free/Joomla/View/Site/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/admin/library/Free/Joomla/View/Site/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@
use JText;
use OSDownloadsModelItem;

if (!class_exists('JViewLegacy')) {
jimport('legacy.view.legacy');
}


class Item extends Base
{
/**
Expand Down
2 changes: 0 additions & 2 deletions src/admin/library/MailingLists/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions src/admin/models/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
3 changes: 0 additions & 3 deletions src/extensions/OSDownloadsFiles/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/osdownloads.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
<obsolete>
<folder>administrator/components/com_osdownloads/models/abstract</folder>

<file>administrator/com_osdownloads/library/Free/Joomla/View/Legacy.php</file>
<file>administrator/components/com_osdownloads/models/items.php</file>
<file>administrator/components/com_osdownloads/tables/abstract.php</file>
<file>administrator/components/com_osdownloads/tables/abstractdocument.php</file>
Expand Down
25 changes: 8 additions & 17 deletions src/site/models/fields/modal/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <option /> element.
$tmp = JHtml::_(
$options[] = JHtml::_(
'select.option',
(string) $item->id,
(string)$item->id,
JText::alt(
trim((string) $item->name),
trim((string)$item->name),
preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)
),
'value',
'text'
);

// Add the option object to the result set.
$options[] = $tmp;
}

reset($options);

return $options;
}
}
2 changes: 0 additions & 2 deletions src/site/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

defined('_JEXEC') or die();

jimport('joomla.log.log');

if (!defined('OSDOWNLOADS_LOADED')) {
require_once JPATH_ADMINISTRATOR . '/components/com_osdownloads/include.php';
}
Expand Down
4 changes: 1 addition & 3 deletions src/site/views/download/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@

defined('_JEXEC') or die();

use Alledia\Framework\Factory;
use Alledia\OSDownloads\Free\Joomla\Component\Site as FreeComponentSite;
use Alledia\OSDownloads\Free\File;
use Alledia\OSDownloads\Free\Helper\Helper;
use Alledia\OSDownloads\Free\Joomla\View\Legacy as LegacyView;


class OSDownloadsViewDownload extends LegacyView
class OSDownloadsViewDownload extends JViewLegacy
{
/**
* @var string
Expand Down

0 comments on commit 3985a55

Please sign in to comment.