Skip to content

Commit

Permalink
Show the new media manager for browsers that do support ECMAScript 5 (#…
Browse files Browse the repository at this point in the history
…68)

* Code style

* Move legacy component to subfolder

* Adjust the component paths for the legacy app

* Code style

* Fix ie check

* Make the condition more readable

* Code style

* Fix ECMAscript version

* Create the new media manager base controller

* Code style

* Implement pr feedback

* Remove line indent
  • Loading branch information
dneukirchen authored and laoneo committed Dec 24, 2016
1 parent 7bb10c1 commit 7cf6fa1
Show file tree
Hide file tree
Showing 37 changed files with 135 additions and 93 deletions.
80 changes: 7 additions & 73 deletions administrator/components/com_media/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,89 +9,23 @@

defined('_JEXEC') or die;

/**
* Media Manager Component Controller
*
* @since 1.5
*/
class MediaController extends JControllerLegacy
{
/**
* Method to display a view.
* Typical view method for MVC based architecture
*
* This function is provide as a default implementation, in most cases
* you will need to override it in your own controllers.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $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 JControllerLegacy A JControllerLegacy object to support chaining.
*
* @since 1.5
* @since __DEPLOY_VERSION__
*/
public function display($cachable = false, $urlparams = false)
{
JPluginHelper::importPlugin('content');

$vType = JFactory::getDocument()->getType();
$vName = $this->input->get('view', 'media');

switch ($vName)
{
case 'images':
$vLayout = $this->input->get('layout', 'default', 'string');
$mName = 'manager';

break;

case 'imagesList':
$mName = 'list';
$vLayout = $this->input->get('layout', 'default', 'string');

break;

case 'mediaList':
$app = JFactory::getApplication();
$mName = 'list';
$vLayout = $app->getUserStateFromRequest('media.list.layout', 'layout', 'thumbs', 'word');

break;

case 'media':
default:
$vName = 'media';
$vLayout = $this->input->get('layout', 'default', 'string');
$mName = 'manager';

break;
}

// Get/Create the view
$view = $this->getView($vName, $vType, '', array('base_path' => JPATH_COMPONENT_ADMINISTRATOR));

// Get/Create the model
if ($model = $this->getModel($mName))
{
// Push the model into the view (as default)
$view->setModel($model, true);
}

// Set the layout
$view->setLayout($vLayout);

// Display the view
$view->display();

return $this;
}

/**
* Validate FTP credentials
*
* @return void
*
* @since 1.5
*/
public function ftpValidate()
{
// Set FTP credentials, if given
JClientHelper::setCredentialsFromRequest('ftp');
echo 'Welcome to the new media manager';
}
}
97 changes: 97 additions & 0 deletions administrator/components/com_media/legacy/controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_media
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

/**
* Media Manager Component Controller
*
* @since 1.5
*/
class MediaController extends JControllerLegacy
{
/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $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.
*
* @since 1.5
*/
public function display($cachable = false, $urlparams = false)
{
JPluginHelper::importPlugin('content');

$vType = JFactory::getDocument()->getType();
$vName = $this->input->get('view', 'media');

switch ($vName)
{
case 'images':
$vLayout = $this->input->get('layout', 'default', 'string');
$mName = 'manager';

break;

case 'imagesList':
$mName = 'list';
$vLayout = $this->input->get('layout', 'default', 'string');

break;

case 'mediaList':
$app = JFactory::getApplication();
$mName = 'list';
$vLayout = $app->getUserStateFromRequest('media.list.layout', 'layout', 'thumbs', 'word');

break;

case 'media':
default:
$vName = 'media';
$vLayout = $this->input->get('layout', 'default', 'string');
$mName = 'manager';

break;
}

// Get/Create the view
$view = $this->getView($vName, $vType, '', array('base_path' => JPATH_COMPONENT_ADMINISTRATOR . '/legacy'));

// Get/Create the model
if ($model = $this->getModel($mName))
{
// Push the model into the view (as default)
$view->setModel($model, true);
}

// Set the layout
$view->setLayout($vLayout);

// Display the view
$view->display();

return $this;
}

/**
* Validate FTP credentials
*
* @return void
*
* @since 1.5
*/
public function ftpValidate()
{
// Set FTP credentials, if given
JClientHelper::setCredentialsFromRequest('ftp');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function addToolbar()
if ($user->authorise('core.create', 'com_media'))
{
// Instantiate a new JLayoutFile instance and render the layout
$layout = new JLayoutFile('toolbar.uploadmedia');
$layout = new JLayoutFile('toolbar.uploadmedia', JPATH_COMPONENT_ADMINISTRATOR . '/legacy/layouts');

$bar->appendButton('Custom', $layout->render(array()), 'upload');
JToolbarHelper::divider();
Expand All @@ -88,7 +88,7 @@ protected function addToolbar()
if ($user->authorise('core.create', 'com_media'))
{
// Instantiate a new JLayoutFile instance and render the layout
$layout = new JLayoutFile('toolbar.newfolder');
$layout = new JLayoutFile('toolbar.newfolder', JPATH_COMPONENT_ADMINISTRATOR . '/legacy/layouts');

$bar->appendButton('Custom', $layout->render(array()), 'upload');
JToolbarHelper::divider();
Expand All @@ -98,7 +98,7 @@ protected function addToolbar()
if ($user->authorise('core.delete', 'com_media'))
{
// Instantiate a new JLayoutFile instance and render the layout
$layout = new JLayoutFile('toolbar.deletemedia');
$layout = new JLayoutFile('toolbar.deletemedia', JPATH_COMPONENT_ADMINISTRATOR . '/legacy/layouts');

$bar->appendButton('Custom', $layout->render(array()), 'upload');
JToolbarHelper::divider();
Expand Down
42 changes: 27 additions & 15 deletions administrator/components/com_media/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

use Joomla\Application\Web\WebClient;

defined('_JEXEC') or die;

$input = JFactory::getApplication()->input;
Expand All @@ -15,32 +17,42 @@
$author = $input->get('author');

// Access check.
if (!$user->authorise('core.manage', 'com_media') && (!$asset or (!$user->authorise('core.edit', $asset)
if (!$user->authorise('core.manage', 'com_media') && (!$asset || (!$user->authorise('core.edit', $asset)
&& !$user->authorise('core.create', $asset)
&& count($user->getAuthorisedCategories($asset, 'core.create')) == 0)
&& !($user->id == $author && $user->authorise('core.edit.own', $asset))))
{
throw new JAccessExceptionNotallowed(JText::_('JERROR_ALERTNOAUTHOR'), 403);
}

$params = JComponentHelper::getParams('com_media');
$client = JFactory::getApplication()->client;
$basePath = JPATH_COMPONENT_ADMINISTRATOR;

// Load the helper class
JLoader::register('MediaHelper', JPATH_ADMINISTRATOR . '/components/com_media/helpers/media.php');
// Show the old media manager for browsers that do not support ECMAScript 5
if ($client->browser == WebClient::IE && $client->version <= 8)
{
// Load the helper class
JLoader::register('MediaHelper', JPATH_ADMINISTRATOR . '/components/com_media/legacy/helpers/media.php');

// Set the path definitions
$popup_upload = $input->get('pop_up', null);
$path = 'file_path';
$view = $input->get('view');
// Get the component parameters
$params = JComponentHelper::getParams('com_media');

if (substr(strtolower($view), 0, 6) == 'images' || $popup_upload == 1)
{
$path = 'image_path';
}
// Set the path definitions
$popup_upload = $input->get('pop_up', null);
$path = 'file_path';
$view = $input->get('view');

define('COM_MEDIA_BASE', JPATH_ROOT . '/' . $params->get($path, 'images'));
define('COM_MEDIA_BASEURL', JUri::root() . $params->get($path, 'images'));
if (substr(strtolower($view), 0, 6) == 'images' || $popup_upload == 1)
{
$path = 'image_path';
}

define('COM_MEDIA_BASE', JPATH_ROOT . '/' . $params->get($path, 'images'));
define('COM_MEDIA_BASEURL', JUri::root() . $params->get($path, 'images'));

$basePath .= '/legacy';
}

$controller = JControllerLegacy::getInstance('Media', array('base_path' => JPATH_COMPONENT_ADMINISTRATOR));
$controller = JControllerLegacy::getInstance('Media', array('base_path' => $basePath));
$controller->execute($input->get('task'));
$controller->redirect();
3 changes: 1 addition & 2 deletions administrator/components/com_media/media.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
<filename>controller.php</filename>
<filename>media.php</filename>
<folder>controllers</folder>
<folder>helpers</folder>
<folder>layouts</folder>
<folder>legacy</folder>
<folder>models</folder>
<folder>views</folder>
</files>
Expand Down

0 comments on commit 7cf6fa1

Please sign in to comment.