- md5
- 9ddcf678e62fa55d334088c09dbb20b3
- sha1
- 3de94f53e5462a81a733a4c215c50e6ae0d95483
- sha256
- 97601d6f30e5da1805fc4a0a92c99d3f6f57de246caaaaf835b2799ab4e3974c
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
<?php
/**
* @package Joomla.Plugin
* @subpackage FileSystem.local
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Filesystem\Local\Extension;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Media\Administrator\Event\MediaProviderEvent;
use Joomla\Component\Media\Administrator\Provider\ProviderInterface;
use Joomla\Event\SubscriberInterface;
use Joomla\Plugin\Filesystem\Local\Adapter\LocalAdapter;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* FileSystem Local plugin.
*
* The plugin to deal with the local filesystem in Media Manager.
*
* @since 4.0.0
*/
final class Local extends CMSPlugin implements SubscriberInterface, ProviderInterface
{
/**
* Affects constructor behavior. If true, language files will be loaded automatically.
*
* @var boolean
* @since 4.0.0
*/
protected $autoloadLanguage = true;
/**
* The root directory path
*
* @var string
* @since 4.3.0
*/
private $rootDirectory;
/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since 5.4.0
*/
public static function getSubscribedEvents(): array
{
return [
'onSetupProviders' => 'onSetupProviders',
];
}
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings
* @param string $rootDirectory The root directory to look for images
*
* @since 4.3.0
*/
public function __construct(array $config, string $rootDirectory)
{
parent::__construct($config);
$this->rootDirectory = $rootDirectory;
}
/**
* Setup Providers for Local Adapter
*
* @param MediaProviderEvent $event Event for ProviderManager
*
* @return void
*
* @since 4.0.0
*/
public function onSetupProviders(MediaProviderEvent $event)
{
$event->getProviderManager()->registerProvider($this);
}
/**
* Returns the ID of the provider
*
* @return string
*
* @since 4.0.0
*/
public function getID()
{
return $this->_name;
}
/**
* Returns the display name of the provider
*
* @return string
*
* @since 4.0.0
*/
public function getDisplayName()
{
return $this->getApplication()->getLanguage()->_('PLG_FILESYSTEM_LOCAL_DEFAULT_NAME');
}
/**
* Returns and array of adapters
*
* @return \Joomla\Component\Media\Administrator\Adapter\AdapterInterface[]
*
* @since 4.0.0
*/
public function getAdapters()
{
$adapters = [];
$directories = $this->params->get('directories', [(object) ['directory' => 'images', 'thumbs' => 0], (object) ['directory' => 'files']]);
// Do a check if default settings are not saved by user, if not initialize them manually
if (\is_string($directories)) {
$directories = json_decode($directories);
}
foreach ($directories as $directoryEntity) {
if (!$directoryEntity->directory) {
continue;
}
$directoryPath = $this->rootDirectory . '/' . $directoryEntity->directory;
$directoryPath = rtrim($directoryPath) . '/';
if (!isset($directoryEntity->thumbs)) {
$directoryEntity->thumbs = 0;
}
$adapter = new LocalAdapter(
$directoryPath,
$directoryEntity->directory,
$directoryEntity->thumbs,
[200, 200]
);
if ($this->getApplication()->getIdentity()) {
$adapter->setCurrentUser($this->getApplication()->getIdentity());
}
$adapters[$adapter->getAdapterName()] = $adapter;
}
return $adapters;
}
}
The same content is in 71 releases, Joomla 5.4.0-beta2 to 6.2.1-rc1. See them all, or every version of this file.