first commit
This commit is contained in:
11
administrator/components/com_media/access.xml
Normal file
11
administrator/components/com_media/access.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<access component="com_media">
|
||||
<section name="component">
|
||||
<action name="core.admin" title="JACTION_ADMIN" />
|
||||
<action name="core.options" title="JACTION_OPTIONS" />
|
||||
<action name="core.manage" title="JACTION_MANAGE" />
|
||||
<action name="core.create" title="JACTION_CREATE" />
|
||||
<action name="core.delete" title="JACTION_DELETE" />
|
||||
<action name="core.edit" title="JACTION_EDIT" />
|
||||
</section>
|
||||
</access>
|
||||
139
administrator/components/com_media/config.xml
Normal file
139
administrator/components/com_media/config.xml
Normal file
@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<config>
|
||||
<help key="Media:_Options"/>
|
||||
<inlinehelp button="show"/>
|
||||
<fieldset
|
||||
name="component"
|
||||
label="COM_MEDIA_FIELDSET_OPTIONS_LABEL">
|
||||
|
||||
<help key="Media:_Options"/>
|
||||
|
||||
<field
|
||||
name="upload_maxsize"
|
||||
type="number"
|
||||
label="COM_MEDIA_FIELD_MAXIMUM_SIZE_LABEL"
|
||||
description="COM_MEDIA_FIELD_MAXIMUM_SIZE_DESC"
|
||||
validate="number"
|
||||
min="0"
|
||||
default="10"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="file_path"
|
||||
type="text"
|
||||
label="COM_MEDIA_FIELD_PATH_FILE_FOLDER_LABEL"
|
||||
description="COM_MEDIA_FIELD_PATH_FILE_FOLDER_DESC"
|
||||
default="images"
|
||||
validate="folderPathExists"
|
||||
exclude="administrator|api|cache|cli|components|includes|language|layouts|libraries|media|modules|plugins|templates|tmp"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="image_path"
|
||||
type="text"
|
||||
label="COM_MEDIA_FIELD_PATH_IMAGE_FOLDER_LABEL"
|
||||
description="COM_MEDIA_FIELD_PATH_IMAGE_FOLDER_DESC"
|
||||
default="images"
|
||||
validate="folderPathExists"
|
||||
exclude="administrator|api|cache|cli|components|includes|language|layouts|libraries|modules|plugins|templates|tmp"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="restrict_uploads"
|
||||
type="radio"
|
||||
label="COM_MEDIA_FIELD_RESTRICT_UPLOADS_LABEL"
|
||||
description="COM_MEDIA_FIELD_RESTRICT_UPLOADS_DESC"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="1"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="restrict_uploads_extensions"
|
||||
type="textarea"
|
||||
label="COM_MEDIA_FIELD_RESTRICT_UPLOADS_EXTENSIONS_LABEL"
|
||||
description="COM_MEDIA_FIELD_RESTRICT_UPLOADS_EXTENSIONS_DESC"
|
||||
default="bmp,gif,jpg,jpeg,png,webp,avif,ico,mp3,mp4,odg,odp,ods,odt,pdf,png,ppt,txt,xcf,xls,csv"
|
||||
showon="restrict_uploads:1"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="check_mime"
|
||||
type="radio"
|
||||
label="COM_MEDIA_FIELD_CHECK_MIME_LABEL"
|
||||
description="COM_MEDIA_FIELD_CHECK_MIME_DESC"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="1"
|
||||
showon="restrict_uploads:1"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="image_extensions"
|
||||
type="textarea"
|
||||
label="COM_MEDIA_FIELD_LEGAL_IMAGE_EXTENSIONS_LABEL"
|
||||
description="COM_MEDIA_FIELD_LEGAL_IMAGE_EXTENSIONS_DESC"
|
||||
default="bmp,gif,jpg,jpeg,png,webp,avif"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="audio_extensions"
|
||||
type="textarea"
|
||||
label="COM_MEDIA_FIELD_LEGAL_AUDIO_EXTENSIONS_LABEL"
|
||||
description="COM_MEDIA_FIELD_LEGAL_AUDIO_EXTENSIONS_DESC"
|
||||
default="mp3,m4a,mp4a,ogg"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="video_extensions"
|
||||
type="textarea"
|
||||
label="COM_MEDIA_FIELD_LEGAL_VIDEO_EXTENSIONS_LABEL"
|
||||
description="COM_MEDIA_FIELD_LEGAL_VIDEO_EXTENSIONS_DESC"
|
||||
default="mp4,mp4v,mpeg,mov,webm"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="doc_extensions"
|
||||
type="textarea"
|
||||
label="COM_MEDIA_FIELD_LEGAL_DOCUMENT_EXTENSIONS_LABEL"
|
||||
description="COM_MEDIA_FIELD_LEGAL_DOCUMENT_EXTENSIONS_DESC"
|
||||
default="doc,odg,odp,ods,odt,pdf,ppt,txt,xcf,xls,csv"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="ignore_extensions"
|
||||
type="textarea"
|
||||
label="COM_MEDIA_FIELD_IGNORED_EXTENSIONS_LABEL"
|
||||
description="COM_MEDIA_FIELD_IGNORED_EXTENSIONS_DESC"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="upload_mime"
|
||||
type="textarea"
|
||||
label="COM_MEDIA_FIELD_LEGAL_MIME_TYPES_LABEL"
|
||||
description="COM_MEDIA_FIELD_LEGAL_MIME_TYPES_DESC"
|
||||
default="image/jpeg,image/gif,image/png,image/bmp,image/webp,image/avif,audio/ogg,audio/mpeg,audio/mp4,video/mp4,video/mpeg,video/quicktime,video/webm,application/msword,application/excel,application/pdf,application/powerpoint,text/plain,application/x-zip"
|
||||
showon="restrict_uploads:1"
|
||||
/>
|
||||
</fieldset>
|
||||
|
||||
<fieldset
|
||||
name="permissions"
|
||||
label="JCONFIG_PERMISSIONS_LABEL"
|
||||
>
|
||||
|
||||
<field
|
||||
name="rules"
|
||||
type="rules"
|
||||
label="JCONFIG_PERMISSIONS_LABEL"
|
||||
filter="rules"
|
||||
validate="rules"
|
||||
component="com_media"
|
||||
section="component"
|
||||
/>
|
||||
</fieldset>
|
||||
</config>
|
||||
3
administrator/components/com_media/forms/file.xml
Normal file
3
administrator/components/com_media/forms/file.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
</form>
|
||||
53
administrator/components/com_media/helpers/media.php
Normal file
53
administrator/components/com_media/helpers/media.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*
|
||||
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
*/
|
||||
|
||||
use Joomla\CMS\Object\CMSObject;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Media helper class.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
abstract class MediaHelper
|
||||
{
|
||||
/**
|
||||
* Generates the URL to the object in the action logs component
|
||||
*
|
||||
* @param string $contentType The content type
|
||||
* @param integer $id The integer id
|
||||
* @param CMSObject $mediaObject The media object being uploaded
|
||||
*
|
||||
* @return string The link for the action log
|
||||
*
|
||||
* @since 3.9.27
|
||||
*/
|
||||
public static function getContentTypeLink($contentType, $id, CMSObject $mediaObject)
|
||||
{
|
||||
if ($contentType === 'com_media.file') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$link = 'index.php?option=com_media';
|
||||
$adapter = $mediaObject->get('adapter');
|
||||
$uploadedPath = $mediaObject->get('path');
|
||||
|
||||
if (!empty($adapter) && !empty($uploadedPath)) {
|
||||
$link .= '&path=' . $adapter . ':' . $uploadedPath;
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
Factory::getDocument()->getWebAssetManager()
|
||||
->useScript('webcomponent.toolbar-button');
|
||||
|
||||
$title = Text::_('COM_MEDIA_CREATE_NEW_FOLDER');
|
||||
?>
|
||||
<joomla-toolbar-button>
|
||||
<button class="btn btn-info" onclick="MediaManager.Event.fire('onClickCreateFolder');">
|
||||
<span class="icon-folder icon-fw" aria-hidden="true"></span>
|
||||
<?php echo $title; ?>
|
||||
</button>
|
||||
</joomla-toolbar-button>
|
||||
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
Factory::getDocument()->getWebAssetManager()
|
||||
->useScript('webcomponent.toolbar-button');
|
||||
|
||||
$title = Text::_('JTOOLBAR_DELETE');
|
||||
?>
|
||||
<joomla-toolbar-button>
|
||||
<button id="mediaDelete" class="btn btn-danger" onclick="MediaManager.Event.fire('onClickDelete');">
|
||||
<span class="icon-times" aria-hidden="true"></span>
|
||||
<?php echo $title; ?>
|
||||
</button>
|
||||
</joomla-toolbar-button>
|
||||
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
Factory::getDocument()->getWebAssetManager()
|
||||
->useScript('webcomponent.toolbar-button');
|
||||
|
||||
$title = Text::_('JTOOLBAR_UPLOAD');
|
||||
?>
|
||||
<joomla-toolbar-button>
|
||||
<button class="btn btn-success" onclick="MediaManager.Event.fire('onClickUpload');">
|
||||
<span class="icon-upload" aria-hidden="true"></span>
|
||||
<?php echo $title; ?>
|
||||
</button>
|
||||
</joomla-toolbar-button>
|
||||
37
administrator/components/com_media/media.xml
Normal file
37
administrator/components/com_media/media.xml
Normal file
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="component" method="upgrade">
|
||||
<name>com_media</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2006-04</creationDate>
|
||||
<copyright>(C) 2006 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>3.0.0</version>
|
||||
<description>COM_MEDIA_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Component\Media</namespace>
|
||||
<files folder="site">
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
<languages folder="site">
|
||||
<language tag="en-GB">language/en-GB/com_media.ini</language>
|
||||
</languages>
|
||||
<administration>
|
||||
<files folder="admin">
|
||||
<filename>access.xml</filename>
|
||||
<filename>config.xml</filename>
|
||||
<filename>media.xml</filename>
|
||||
<folder>forms</folder>
|
||||
<folder>layouts</folder>
|
||||
<folder>resources</folder>
|
||||
<folder>services</folder>
|
||||
<folder>src</folder>
|
||||
<folder>tmpl</folder>
|
||||
</files>
|
||||
<languages folder="admin">
|
||||
<language tag="en-GB">language/en-GB/com_media.ini</language>
|
||||
<language tag="en-GB">language/en-GB/com_media.sys.ini</language>
|
||||
</languages>
|
||||
</administration>
|
||||
</extension>
|
||||
|
||||
53
administrator/components/com_media/services/provider.php
Normal file
53
administrator/components/com_media/services/provider.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Dispatcher\ComponentDispatcherFactoryInterface;
|
||||
use Joomla\CMS\Extension\ComponentInterface;
|
||||
use Joomla\CMS\Extension\MVCComponent;
|
||||
use Joomla\CMS\Extension\Service\Provider\ComponentDispatcherFactory;
|
||||
use Joomla\CMS\Extension\Service\Provider\MVCFactory;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
|
||||
/**
|
||||
* The media service provider.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->registerServiceProvider(new MVCFactory('\\Joomla\\Component\\Media'));
|
||||
$container->registerServiceProvider(new ComponentDispatcherFactory('\\Joomla\\Component\\Media'));
|
||||
|
||||
$container->set(
|
||||
ComponentInterface::class,
|
||||
function (Container $container) {
|
||||
$component = new MVCComponent($container->get(ComponentDispatcherFactoryInterface::class));
|
||||
|
||||
$component->setMVCFactory($container->get(MVCFactoryInterface::class));
|
||||
|
||||
return $component;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Media\Administrator\Adapter;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Media file adapter interface.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
interface AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Returns the requested file or folder. The returned object
|
||||
* has the following properties available:
|
||||
* - type: The type can be file or dir
|
||||
* - name: The name of the file
|
||||
* - path: The relative path to the root
|
||||
* - extension: The file extension
|
||||
* - size: The size of the file
|
||||
* - create_date: The date created
|
||||
* - modified_date: The date modified
|
||||
* - mime_type: The mime type
|
||||
* - width: The width, when available
|
||||
* - height: The height, when available
|
||||
*
|
||||
* If the path doesn't exist a FileNotFoundException is thrown.
|
||||
*
|
||||
* @param string $path The path to the file or folder
|
||||
*
|
||||
* @return \stdClass
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getFile(string $path = '/'): \stdClass;
|
||||
|
||||
/**
|
||||
* Returns the folders and files for the given path. The returned objects
|
||||
* have the following properties available:
|
||||
* - type: The type can be file or dir
|
||||
* - name: The name of the file
|
||||
* - path: The relative path to the root
|
||||
* - extension: The file extension
|
||||
* - size: The size of the file
|
||||
* - create_date: The date created
|
||||
* - modified_date: The date modified
|
||||
* - mime_type: The mime type
|
||||
* - width: The width, when available
|
||||
* - height: The height, when available
|
||||
*
|
||||
* If the path doesn't exist a FileNotFoundException is thrown.
|
||||
*
|
||||
* @param string $path The folder
|
||||
*
|
||||
* @return \stdClass[]
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getFiles(string $path = '/'): array;
|
||||
|
||||
/**
|
||||
* Returns a resource for the given path.
|
||||
*
|
||||
* @param string $path The path
|
||||
*
|
||||
* @return resource
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getResource(string $path);
|
||||
|
||||
/**
|
||||
* Creates a folder with the given name in the given path.
|
||||
*
|
||||
* It returns the new folder name. This allows the implementation
|
||||
* classes to normalise the file name.
|
||||
*
|
||||
* @param string $name The name
|
||||
* @param string $path The folder
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createFolder(string $name, string $path): string;
|
||||
|
||||
/**
|
||||
* Creates a file with the given name in the given path with the data.
|
||||
*
|
||||
* It returns the new file name. This allows the implementation
|
||||
* classes to normalise the file name.
|
||||
*
|
||||
* @param string $name The name
|
||||
* @param string $path The folder
|
||||
* @param string $data The data
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createFile(string $name, string $path, $data): string;
|
||||
|
||||
/**
|
||||
* Updates the file with the given name in the given path with the data.
|
||||
*
|
||||
* @param string $name The name
|
||||
* @param string $path The folder
|
||||
* @param string $data The data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateFile(string $name, string $path, $data);
|
||||
|
||||
/**
|
||||
* Deletes the folder or file of the given path.
|
||||
*
|
||||
* @param string $path The path to the file or folder
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(string $path);
|
||||
|
||||
/**
|
||||
* Moves a file or folder from source to destination.
|
||||
*
|
||||
* It returns the new destination path. This allows the implementation
|
||||
* classes to normalise the file name.
|
||||
*
|
||||
* @param string $sourcePath The source path
|
||||
* @param string $destinationPath The destination path
|
||||
* @param bool $force Force to overwrite
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function move(string $sourcePath, string $destinationPath, bool $force = false): string;
|
||||
|
||||
/**
|
||||
* Copies a file or folder from source to destination.
|
||||
*
|
||||
* It returns the new destination path. This allows the implementation
|
||||
* classes to normalise the file name.
|
||||
*
|
||||
* @param string $sourcePath The source path
|
||||
* @param string $destinationPath The destination path
|
||||
* @param bool $force Force to overwrite
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function copy(string $sourcePath, string $destinationPath, bool $force = false): string;
|
||||
|
||||
/**
|
||||
* Returns a public url for the given path. This function can be used by the cloud
|
||||
* adapter to publish the media file and create a permanent publicly accessible
|
||||
* url.
|
||||
*
|
||||
* @param string $path The path to file
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Joomla\Component\Media\Administrator\Exception\FileNotFoundException
|
||||
*/
|
||||
public function getUrl(string $path): string;
|
||||
|
||||
/**
|
||||
* Returns the name of the adapter.
|
||||
* It will be shown in the Media Manager
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getAdapterName(): string;
|
||||
|
||||
/**
|
||||
* Search for a pattern in a given path
|
||||
*
|
||||
* @param string $path The base path for the search
|
||||
* @param string $needle The path to file
|
||||
* @param bool $recursive Do a recursive search
|
||||
*
|
||||
* @return \stdClass[]
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function search(string $path, string $needle, bool $recursive = false): array;
|
||||
}
|
||||
@ -0,0 +1,401 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Helper\MediaHelper;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\MVC\Model\BaseModel;
|
||||
use Joomla\CMS\Response\JsonResponse;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Session\Session;
|
||||
use Joomla\Component\Media\Administrator\Exception\FileExistsException;
|
||||
use Joomla\Component\Media\Administrator\Exception\FileNotFoundException;
|
||||
use Joomla\Component\Media\Administrator\Exception\InvalidPathException;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Api Media Controller
|
||||
*
|
||||
* This is NO public api controller, it is internal for the com_media component only!
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class ApiController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Execute a task by triggering a method in the derived class.
|
||||
*
|
||||
* @param string $task The task to perform. If no matching task is found, the '__default' task is executed, if defined.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function execute($task)
|
||||
{
|
||||
$method = $this->input->getMethod();
|
||||
|
||||
$this->task = $task;
|
||||
|
||||
try {
|
||||
// Check token for requests which do modify files (all except get requests)
|
||||
if ($method !== 'GET' && !Session::checkToken('json')) {
|
||||
throw new \InvalidArgumentException(Text::_('JINVALID_TOKEN_NOTICE'), 403);
|
||||
}
|
||||
|
||||
$doTask = strtolower($method) . ucfirst($task);
|
||||
|
||||
// Record the actual task being fired
|
||||
$this->doTask = $doTask;
|
||||
|
||||
if (!\in_array($this->doTask, $this->taskMap)) {
|
||||
throw new \Exception(Text::sprintf('JLIB_APPLICATION_ERROR_TASK_NOT_FOUND', $task), 405);
|
||||
}
|
||||
|
||||
$data = $this->$doTask();
|
||||
|
||||
// Return the data
|
||||
$this->sendResponse($data);
|
||||
} catch (FileNotFoundException $e) {
|
||||
$this->sendResponse($e, 404);
|
||||
} catch (FileExistsException $e) {
|
||||
$this->sendResponse($e, 409);
|
||||
} catch (InvalidPathException $e) {
|
||||
$this->sendResponse($e, 400);
|
||||
} catch (\Exception $e) {
|
||||
$errorCode = 500;
|
||||
|
||||
if ($e->getCode() > 0) {
|
||||
$errorCode = $e->getCode();
|
||||
}
|
||||
|
||||
$this->sendResponse($e, $errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Files Get Method
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* - GET a list of folders below the root:
|
||||
* index.php?option=com_media&task=api.files
|
||||
* /api/files
|
||||
* - GET a list of files and subfolders of a given folder:
|
||||
* index.php?option=com_media&task=api.files&format=json&path=/sampledata/cassiopeia
|
||||
* /api/files/sampledata/cassiopeia
|
||||
* - GET a list of files and subfolders of a given folder for a given search term:
|
||||
* use recursive=1 to search recursively in the working directory
|
||||
* index.php?option=com_media&task=api.files&format=json&path=/sampledata/cassiopeia&search=nasa5
|
||||
* /api/files/sampledata/cassiopeia?search=nasa5
|
||||
* To look up in same working directory set flag recursive=0
|
||||
* index.php?option=com_media&task=api.files&format=json&path=/sampledata/cassiopeia&search=nasa5&recursive=0
|
||||
* /api/files/sampledata/cassiopeia?search=nasa5&recursive=0
|
||||
* - GET file information for a specific file:
|
||||
* index.php?option=com_media&task=api.files&format=json&path=/sampledata/cassiopeia/test.jpg
|
||||
* /api/files/sampledata/cassiopeia/test.jpg
|
||||
* - GET a temporary URL to a given file
|
||||
* index.php?option=com_media&task=api.files&format=json&path=/sampledata/cassiopeia/test.jpg&url=1&temp=1
|
||||
* /api/files/sampledata/cassiopeia/test.jpg&url=1&temp=1
|
||||
* - GET a temporary URL to a given file
|
||||
* index.php?option=com_media&task=api.files&format=json&path=/sampledata/cassiopeia/test.jpg&url=1
|
||||
* /api/files/sampledata/cassiopeia/test.jpg&url=1
|
||||
*
|
||||
* @return array The data to send with the response
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getFiles()
|
||||
{
|
||||
// Grab options
|
||||
$options = [];
|
||||
$options['url'] = $this->input->getBool('url', false);
|
||||
$options['search'] = $this->input->getString('search', '');
|
||||
$options['recursive'] = $this->input->getBool('recursive', true);
|
||||
$options['content'] = $this->input->getBool('content', false);
|
||||
|
||||
return $this->getModel()->getFiles($this->getAdapter(), $this->getPath(), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Files delete Method
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* - DELETE an existing folder in a specific folder:
|
||||
* index.php?option=com_media&task=api.files&format=json&path=/sampledata/cassiopeia/test
|
||||
* /api/files/sampledata/cassiopeia/test
|
||||
* - DELETE an existing file in a specific folder:
|
||||
* index.php?option=com_media&task=api.files&path=/sampledata/cassiopeia/test.jpg
|
||||
* /api/files/sampledata/cassiopeia/test.jpg
|
||||
*
|
||||
* @return null
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deleteFiles()
|
||||
{
|
||||
if (!$this->app->getIdentity()->authorise('core.delete', 'com_media')) {
|
||||
throw new \Exception(Text::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), 403);
|
||||
}
|
||||
|
||||
$this->getModel()->delete($this->getAdapter(), $this->getPath());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Files Post Method
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* - POST a new file or folder into a specific folder, the file or folder information is returned:
|
||||
* index.php?option=com_media&task=api.files&format=json&path=/sampledata/cassiopeia
|
||||
* /api/files/sampledata/cassiopeia
|
||||
*
|
||||
* New file body:
|
||||
* {
|
||||
* "name": "test.jpg",
|
||||
* "content":"base64 encoded image"
|
||||
* }
|
||||
* New folder body:
|
||||
* {
|
||||
* "name": "test",
|
||||
* }
|
||||
*
|
||||
* @return array The data to send with the response
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function postFiles()
|
||||
{
|
||||
if (!$this->app->getIdentity()->authorise('core.create', 'com_media')) {
|
||||
throw new \Exception(Text::_('JLIB_APPLICATION_ERROR_CREATE_RECORD_NOT_PERMITTED'), 403);
|
||||
}
|
||||
|
||||
$adapter = $this->getAdapter();
|
||||
$path = $this->getPath();
|
||||
$content = $this->input->json;
|
||||
$name = $content->getString('name');
|
||||
$mediaContent = base64_decode($content->get('content', '', 'raw'));
|
||||
$override = $content->get('override', false);
|
||||
|
||||
if ($mediaContent) {
|
||||
$this->checkContent();
|
||||
|
||||
// A file needs to be created
|
||||
$name = $this->getModel()->createFile($adapter, $name, $path, $mediaContent, $override);
|
||||
} else {
|
||||
// A folder needs to be created
|
||||
$name = $this->getModel()->createFolder($adapter, $name, $path, $override);
|
||||
}
|
||||
|
||||
$options = [];
|
||||
$options['url'] = $this->input->getBool('url', false);
|
||||
|
||||
return $this->getModel()->getFile($adapter, $path . '/' . $name, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Files Put method
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* - PUT a media file, the file or folder information is returned:
|
||||
* index.php?option=com_media&task=api.files&format=json&path=/sampledata/cassiopeia/test.jpg
|
||||
* /api/files/sampledata/cassiopeia/test.jpg
|
||||
*
|
||||
* Update file body:
|
||||
* {
|
||||
* "content":"base64 encoded image"
|
||||
* }
|
||||
*
|
||||
* - PUT move a file, folder to another one
|
||||
* path : will be taken as the source
|
||||
* index.php?option=com_media&task=api.files&format=json&path=/sampledata/cassiopeia/test.jpg
|
||||
* /api/files/sampledata/cassiopeia/test.jpg
|
||||
*
|
||||
* JSON body:
|
||||
* {
|
||||
* "newPath" : "/path/to/destination",
|
||||
* "move" : "1"
|
||||
* }
|
||||
*
|
||||
* - PUT copy a file, folder to another one
|
||||
* path : will be taken as the source
|
||||
* index.php?option=com_media&task=api.files&format=json&path=/sampledata/cassiopeia/test.jpg
|
||||
* /api/files/sampledata/cassiopeia/test.jpg
|
||||
*
|
||||
* JSON body:
|
||||
* {
|
||||
* "newPath" : "/path/to/destination",
|
||||
* "move" : "0"
|
||||
* }
|
||||
*
|
||||
* @return array The data to send with the response
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function putFiles()
|
||||
{
|
||||
if (!$this->app->getIdentity()->authorise('core.edit', 'com_media')) {
|
||||
throw new \Exception(Text::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'), 403);
|
||||
}
|
||||
|
||||
$adapter = $this->getAdapter();
|
||||
$path = $this->getPath();
|
||||
|
||||
$content = $this->input->json;
|
||||
$name = basename($path);
|
||||
$mediaContent = base64_decode($content->get('content', '', 'raw'));
|
||||
$newPath = $content->getString('newPath', null);
|
||||
$move = $content->get('move', true);
|
||||
|
||||
if ($mediaContent != null) {
|
||||
$this->checkContent();
|
||||
|
||||
$this->getModel()->updateFile($adapter, $name, str_replace($name, '', $path), $mediaContent);
|
||||
}
|
||||
|
||||
if ($newPath != null && $newPath !== $adapter . ':' . $path) {
|
||||
list($destinationAdapter, $destinationPath) = explode(':', $newPath, 2);
|
||||
|
||||
if ($move) {
|
||||
$destinationPath = $this->getModel()->move($adapter, $path, $destinationPath, false);
|
||||
} else {
|
||||
$destinationPath = $this->getModel()->copy($adapter, $path, $destinationPath, false);
|
||||
}
|
||||
|
||||
$path = $destinationPath;
|
||||
}
|
||||
|
||||
return $this->getModel()->getFile($adapter, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the given data as JSON response in the following format:
|
||||
*
|
||||
* {"success":true,"message":"ok","messages":null,"data":[{"type":"dir","name":"banners","path":"//"}]}
|
||||
*
|
||||
* @param mixed $data The data to send
|
||||
* @param integer $responseCode The response code
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function sendResponse($data = null, int $responseCode = 200)
|
||||
{
|
||||
// Set the correct content type
|
||||
$this->app->setHeader('Content-Type', 'application/json');
|
||||
|
||||
// Set the status code for the response
|
||||
http_response_code($responseCode);
|
||||
|
||||
// Send the data
|
||||
echo new JsonResponse($data);
|
||||
|
||||
$this->app->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a model object, loading it if required.
|
||||
*
|
||||
* @param string $name The model name. Optional.
|
||||
* @param string $prefix The class prefix. Optional.
|
||||
* @param array $config Configuration array for model. Optional.
|
||||
*
|
||||
* @return BaseModel|boolean Model object on success; otherwise false on failure.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getModel($name = 'Api', $prefix = 'Administrator', $config = [])
|
||||
{
|
||||
return parent::getModel($name, $prefix, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs various checks if it is allowed to save the content.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function checkContent()
|
||||
{
|
||||
$helper = new MediaHelper();
|
||||
$contentLength = $this->input->server->getInt('CONTENT_LENGTH');
|
||||
$params = ComponentHelper::getParams('com_media');
|
||||
$paramsUploadMaxsize = $params->get('upload_maxsize', 0) * 1024 * 1024;
|
||||
$uploadMaxFilesize = $helper->toBytes(ini_get('upload_max_filesize'));
|
||||
$postMaxSize = $helper->toBytes(ini_get('post_max_size'));
|
||||
$memoryLimit = $helper->toBytes(ini_get('memory_limit'));
|
||||
|
||||
if (
|
||||
($paramsUploadMaxsize > 0 && $contentLength > $paramsUploadMaxsize)
|
||||
|| ($uploadMaxFilesize > 0 && $contentLength > $uploadMaxFilesize)
|
||||
|| ($postMaxSize > 0 && $contentLength > $postMaxSize)
|
||||
|| ($memoryLimit > -1 && $contentLength > $memoryLimit)
|
||||
) {
|
||||
$link = 'index.php?option=com_config&view=component&component=com_media';
|
||||
$output = HTMLHelper::_('link', Route::_($link), Text::_('JOPTIONS'));
|
||||
throw new \Exception(Text::sprintf('COM_MEDIA_ERROR_WARNFILETOOLARGE', $output), 403);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Adapter.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function getAdapter()
|
||||
{
|
||||
$parts = explode(':', $this->input->getString('path', ''), 2);
|
||||
|
||||
if (\count($parts) < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $parts[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Path.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function getPath()
|
||||
{
|
||||
$parts = explode(':', $this->input->getString('path', ''), 2);
|
||||
|
||||
if (\count($parts) < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $parts[1];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Media\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Media Manager Component Controller
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class DisplayController extends BaseController
|
||||
{
|
||||
/**
|
||||
* The default view.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $default_view = 'media';
|
||||
|
||||
/**
|
||||
* Method to get a reference to the current view and load it if necessary.
|
||||
*
|
||||
* @param string $name The view name. Optional, defaults to the controller name.
|
||||
* @param string $type The view type. Optional.
|
||||
* @param string $prefix The class prefix. Optional.
|
||||
* @param array $config Configuration array for view. Optional.
|
||||
*
|
||||
* @return \Joomla\CMS\MVC\View\ViewInterface Reference to the view or an error.
|
||||
*
|
||||
* @since 3.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getView($name = '', $type = '', $prefix = '', $config = [])
|
||||
{
|
||||
// Force to load the admin view
|
||||
return parent::getView($name, $type, 'Administrator', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a model object, loading it if required.
|
||||
*
|
||||
* @param string $name The model name. Optional.
|
||||
* @param string $prefix The class prefix. Optional.
|
||||
* @param array $config Configuration array for model. Optional.
|
||||
*
|
||||
* @return \Joomla\CMS\MVC\Model\BaseDatabaseModel|boolean Model object on success; otherwise false on failure.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public function getModel($name = '', $prefix = '', $config = [])
|
||||
{
|
||||
// Force to load the admin model
|
||||
return parent::getModel($name, 'Administrator', $config);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Controller;
|
||||
|
||||
use Joomla\CMS\MVC\Controller\BaseController;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\Component\Media\Administrator\Event\OAuthCallbackEvent;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Plugin Controller for OAuth2.0 callbacks
|
||||
*
|
||||
* This controller handles OAuth2 Callbacks
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class PluginController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Handles an OAuth Callback request for a specified plugin.
|
||||
*
|
||||
* URLs containing [sitename]/administrator/index.php?option=com_media&task=plugin.oauthcallback
|
||||
* &plugin=[plugin_name]
|
||||
*
|
||||
* will be handled by this endpoint.
|
||||
* It will select the plugin specified by plugin_name and pass all the data received from the provider
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function oauthcallback()
|
||||
{
|
||||
try {
|
||||
// Load plugin names
|
||||
$pluginName = $this->input->getString('plugin', null);
|
||||
$plugins = PluginHelper::getPlugin('filesystem');
|
||||
|
||||
// If plugin name was not found in parameters redirect back to control panel
|
||||
if (!$pluginName || !$this->containsPlugin($plugins, $pluginName)) {
|
||||
throw new \Exception('Plugin not found!');
|
||||
}
|
||||
|
||||
// Check if the plugin is disabled, if so redirect to control panel
|
||||
if (!PluginHelper::isEnabled('filesystem', $pluginName)) {
|
||||
throw new \Exception('Plugin ' . $pluginName . ' is disabled.');
|
||||
}
|
||||
|
||||
// Only import our required plugin, not entire group
|
||||
PluginHelper::importPlugin('filesystem', $pluginName);
|
||||
|
||||
// Event parameters
|
||||
$eventParameters = ['context' => $pluginName, 'input' => $this->input];
|
||||
$event = new OAuthCallbackEvent('onFileSystemOAuthCallback', $eventParameters);
|
||||
|
||||
// Get results from event
|
||||
$eventResults = (array) $this->app->triggerEvent('onFileSystemOAuthCallback', $event);
|
||||
|
||||
// If event was not triggered in the selected Plugin, raise a warning and fallback to Control Panel
|
||||
if (!$eventResults) {
|
||||
throw new \Exception(
|
||||
'Plugin ' . $pluginName . ' should have implemented onFileSystemOAuthCallback method'
|
||||
);
|
||||
}
|
||||
|
||||
$action = $eventResults['action'] ?? null;
|
||||
|
||||
// If there are any messages display them
|
||||
if (isset($eventResults['message'])) {
|
||||
$message = $eventResults['message'];
|
||||
$messageType = ($eventResults['message_type'] ?? '');
|
||||
|
||||
$this->app->enqueueMessage($message, $messageType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute actions defined by the plugin
|
||||
* Supported actions
|
||||
* - close : Closes the current window, use this only for windows opened by javascript
|
||||
* - redirect : Redirect to a URI defined in 'redirect_uri' parameter, if not fallback to control panel
|
||||
* - media-manager : Redirect to Media Manager
|
||||
* - control-panel : Redirect to Control Panel
|
||||
*/
|
||||
switch ($action) {
|
||||
/**
|
||||
* Close a window opened by developer
|
||||
* Use this for close New Windows opened for OAuth Process
|
||||
*/
|
||||
case 'close':
|
||||
$this->setRedirect(Route::_('index.php?option=com_media&view=plugin&action=close', false));
|
||||
break;
|
||||
|
||||
// Redirect browser to any page specified by the user
|
||||
case 'redirect':
|
||||
if (!isset($eventResults['redirect_uri'])) {
|
||||
throw new \Exception("Redirect URI must be set in the plugin");
|
||||
}
|
||||
|
||||
$this->setRedirect($eventResults['redirect_uri']);
|
||||
break;
|
||||
|
||||
// Redirect browser to Control Panel
|
||||
case 'control-panel':
|
||||
$this->setRedirect(Route::_('index.php', false));
|
||||
break;
|
||||
|
||||
// Redirect browser to Media Manager
|
||||
case 'media-manager':
|
||||
default:
|
||||
$this->setRedirect(Route::_('index.php?option=com_media&view=media', false));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Display any error
|
||||
$this->app->enqueueMessage($e->getMessage(), 'error');
|
||||
$this->setRedirect(Route::_('index.php', false));
|
||||
}
|
||||
|
||||
// Redirect
|
||||
$this->redirect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a plugin exists in given plugin array.
|
||||
*
|
||||
* @param array $plugins Array of plugin names
|
||||
* @param string $pluginName Plugin name to look up
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function containsPlugin($plugins, $pluginName)
|
||||
{
|
||||
foreach ($plugins as $plugin) {
|
||||
if ($plugin->name == $pluginName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Dispatcher;
|
||||
|
||||
use Joomla\CMS\Access\Exception\NotAllowed;
|
||||
use Joomla\CMS\Dispatcher\ComponentDispatcher;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* ComponentDispatcher class for com_media
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class Dispatcher extends ComponentDispatcher
|
||||
{
|
||||
/**
|
||||
* Method to check component access permission
|
||||
*
|
||||
* @since 4.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function checkAccess()
|
||||
{
|
||||
$user = $this->app->getIdentity();
|
||||
$asset = $this->input->get('asset');
|
||||
$author = $this->input->get('author');
|
||||
|
||||
// Access check
|
||||
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 NotAllowed($this->app->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Media\Administrator\Event;
|
||||
|
||||
use Joomla\CMS\Event\AbstractImmutableEvent;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Event to validate media items.
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
abstract class AbstractMediaItemValidationEvent extends AbstractImmutableEvent
|
||||
{
|
||||
/**
|
||||
* Validate $item to have all attributes with a valid type.
|
||||
*
|
||||
* Properties validated:
|
||||
* - type: The type can be file or dir
|
||||
* - name: The name of the item
|
||||
* - path: The relative path to the root
|
||||
* - extension: The file extension
|
||||
* - size: The size of the file
|
||||
* - create_date: The date created
|
||||
* - modified_date: The date modified
|
||||
* - mime_type: The mime type
|
||||
* - width: The width, when available
|
||||
* - height: The height, when available
|
||||
*
|
||||
* Properties generated:
|
||||
* - created_date_formatted: DATE_FORMAT_LC5 formatted string based on create_date
|
||||
* - modified_date_formatted: DATE_FORMAT_LC5 formatted string based on modified_date
|
||||
*
|
||||
* @param \stdClass $item The item to set
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.1.0
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
protected function validate(\stdClass $item): void
|
||||
{
|
||||
// Only "dir" or "file" is allowed
|
||||
if (!isset($item->type) || ($item->type !== 'dir' && $item->type !== 'file')) {
|
||||
throw new \BadMethodCallException("Property 'type' of argument 'item' of event {$this->name} has a wrong item. Valid: 'dir' or 'file'");
|
||||
}
|
||||
|
||||
// Non empty string
|
||||
if (!isset($item->name) || !\is_string($item->name) || trim($item->name) === '') {
|
||||
throw new \BadMethodCallException("Property 'name' of argument 'item' of event {$this->name} has a wrong item. Valid: non empty string");
|
||||
}
|
||||
|
||||
// Non empty string
|
||||
if (!isset($item->path) || !\is_string($item->path) || trim($item->path) === '') {
|
||||
throw new \BadMethodCallException("Property 'path' of argument 'item' of event {$this->name} has a wrong item. Valid: non empty string");
|
||||
}
|
||||
|
||||
// A string
|
||||
if ($item->type === 'file' && (!isset($item->extension) || !\is_string($item->extension))) {
|
||||
throw new \BadMethodCallException("Property 'extension' of argument 'item' of event {$this->name} has a wrong item. Valid: string");
|
||||
}
|
||||
|
||||
// An empty string or an integer
|
||||
if (
|
||||
!isset($item->size) ||
|
||||
(!\is_integer($item->size) && !\is_string($item->size)) ||
|
||||
(\is_string($item->size) && $item->size !== '')
|
||||
) {
|
||||
throw new \BadMethodCallException("Property 'size' of argument 'item' of event {$this->name} has a wrong item. Valid: empty string or integer");
|
||||
}
|
||||
|
||||
// A string
|
||||
if (!isset($item->mime_type) || !\is_string($item->mime_type)) {
|
||||
throw new \BadMethodCallException("Property 'mime_type' of argument 'item' of event {$this->name} has a wrong item. Valid: string");
|
||||
}
|
||||
|
||||
// An integer
|
||||
if (!isset($item->width) || !\is_integer($item->width)) {
|
||||
throw new \BadMethodCallException("Property 'width' of argument 'item' of event {$this->name} has a wrong item. Valid: integer");
|
||||
}
|
||||
|
||||
// An integer
|
||||
if (!isset($item->height) || !\is_integer($item->height)) {
|
||||
throw new \BadMethodCallException("Property 'height' of argument 'item' of event {$this->name} has a wrong item. Valid: integer");
|
||||
}
|
||||
|
||||
// A string
|
||||
if (!isset($item->create_date) || !\is_string($item->create_date)) {
|
||||
throw new \BadMethodCallException("Property 'create_date' of argument 'item' of event {$this->name} has a wrong item. Valid: string");
|
||||
}
|
||||
|
||||
// A string
|
||||
if (!isset($item->create_date_formatted) || !\is_string($item->create_date_formatted)) {
|
||||
throw new \BadMethodCallException("Property 'create_date_formatted' of argument 'item' of event {$this->name} has a wrong item. Valid: string");
|
||||
}
|
||||
|
||||
// A string
|
||||
if (!isset($item->modified_date) || !\is_string($item->modified_date)) {
|
||||
throw new \BadMethodCallException("Property 'modified_date' of argument 'item' of event {$this->name} has a wrong item. Valid: string");
|
||||
}
|
||||
|
||||
// A string
|
||||
if (!isset($item->modified_date_formatted) || !\is_string($item->modified_date_formatted)) {
|
||||
throw new \BadMethodCallException("Property 'modified_date_formatted' of argument 'item' of event {$this->name} has a wrong item. Valid: string");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Media\Administrator\Event;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Event object for fetch media item.
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
final class FetchMediaItemEvent extends AbstractMediaItemValidationEvent
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The event name.
|
||||
* @param array $arguments The event arguments.
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
public function __construct($name, array $arguments = [])
|
||||
{
|
||||
parent::__construct($name, $arguments);
|
||||
|
||||
// Check for required arguments
|
||||
if (!\array_key_exists('item', $arguments) || !\is_object($arguments['item'])) {
|
||||
throw new \BadMethodCallException("Argument 'item' of event $name is not of the expected type");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate $item to have all attributes with a valid type
|
||||
*
|
||||
* Validation based on \Joomla\Component\Media\Administrator\Adapter\AdapterInterface::getFile()
|
||||
*
|
||||
* Properties validated:
|
||||
* - type: The type can be file or dir
|
||||
* - name: The name of the item
|
||||
* - path: The relative path to the root
|
||||
* - extension: The file extension
|
||||
* - size: The size of the file
|
||||
* - create_date: The date created
|
||||
* - modified_date: The date modified
|
||||
* - mime_type: The mime type
|
||||
* - width: The width, when available
|
||||
* - height: The height, when available
|
||||
*
|
||||
* Generation based on \Joomla\Plugin\Filesystem\Local\Adapter\LocalAdapter::getPathInformation()
|
||||
*
|
||||
* Properties generated:
|
||||
* - created_date_formatted: DATE_FORMAT_LC5 formatted string based on create_date
|
||||
* - modified_date_formatted: DATE_FORMAT_LC5 formatted string based on modified_date
|
||||
*
|
||||
* @param \stdClass $item The item to set
|
||||
*
|
||||
* @return \stdClass
|
||||
*
|
||||
* @since 4.1.0
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
protected function setItem(\stdClass $item): \stdClass
|
||||
{
|
||||
// Make immutable object
|
||||
$item = clone $item;
|
||||
|
||||
$this->validate($item);
|
||||
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Media\Administrator\Event;
|
||||
|
||||
use Joomla\CMS\Event\AbstractImmutableEvent;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Event object to set an url.
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
final class FetchMediaItemUrlEvent extends AbstractImmutableEvent
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The event name.
|
||||
* @param array $arguments The event arguments.
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
public function __construct($name, array $arguments = [])
|
||||
{
|
||||
// Check for required arguments
|
||||
if (!\array_key_exists('adapter', $arguments) || !\is_string($arguments['adapter'])) {
|
||||
throw new \BadMethodCallException("Argument 'adapter' of event $name is not of the expected type");
|
||||
}
|
||||
|
||||
$this->arguments[$arguments['adapter']] = $arguments['adapter'];
|
||||
unset($arguments['adapter']);
|
||||
|
||||
// Check for required arguments
|
||||
if (!\array_key_exists('path', $arguments) || !\is_string($arguments['path'])) {
|
||||
throw new \BadMethodCallException("Argument 'path' of event $name is not of the expected type");
|
||||
}
|
||||
|
||||
$this->arguments[$arguments['path']] = $arguments['path'];
|
||||
unset($arguments['path']);
|
||||
|
||||
// Check for required arguments
|
||||
if (!\array_key_exists('url', $arguments) || !\is_string($arguments['url'])) {
|
||||
throw new \BadMethodCallException("Argument 'url' of event $name is not of the expected type");
|
||||
}
|
||||
|
||||
parent::__construct($name, $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate $value to be a string
|
||||
*
|
||||
* @param string $value The value to set
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
protected function setUrl(string $value): string
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forbid setting $path
|
||||
*
|
||||
* @param string $value The value to set
|
||||
*
|
||||
* @since 4.1.0
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
protected function setPath(string $value): string
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot set the argument "path" of the immutable event ' . $this->name . '.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Forbid setting $path
|
||||
*
|
||||
* @param string $value The value to set
|
||||
*
|
||||
* @since 4.1.0
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
protected function setAdapter(string $value): string
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot set the argument "adapter" of the immutable event ' . $this->name . '.');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Media\Administrator\Event;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Event object for fetch media items.
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
final class FetchMediaItemsEvent extends AbstractMediaItemValidationEvent
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The event name.
|
||||
* @param array $arguments The event arguments.
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
public function __construct($name, array $arguments = [])
|
||||
{
|
||||
parent::__construct($name, $arguments);
|
||||
|
||||
// Check for required arguments
|
||||
if (!\array_key_exists('items', $arguments) || !\is_array($arguments['items'])) {
|
||||
throw new \BadMethodCallException("Argument 'items' of event $name is not of the expected type");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate $item to be an array
|
||||
*
|
||||
* @param array $items The value to set
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
protected function setItems(array $items): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($items as $item) {
|
||||
$clone = clone $item;
|
||||
|
||||
$this->validate($clone);
|
||||
|
||||
$result[] = $clone;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the items.
|
||||
*
|
||||
* @param array $items The value to set
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
protected function getItems(array $items): array
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($items as $item) {
|
||||
$result[] = clone $item;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Event;
|
||||
|
||||
use Joomla\CMS\Event\AbstractEvent;
|
||||
use Joomla\Component\Media\Administrator\Provider\ProviderManager;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Event object to retrieve Media Adapters.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class MediaProviderEvent extends AbstractEvent
|
||||
{
|
||||
/**
|
||||
* The ProviderManager for event
|
||||
*
|
||||
* @var ProviderManager
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $providerManager = null;
|
||||
|
||||
/**
|
||||
* Return the ProviderManager
|
||||
*
|
||||
* @return ProviderManager
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getProviderManager(): ProviderManager
|
||||
{
|
||||
return $this->providerManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ProviderManager
|
||||
*
|
||||
* @param ProviderManager $providerManager The Provider Manager to be set
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function setProviderManager(ProviderManager $providerManager)
|
||||
{
|
||||
$this->providerManager = $providerManager;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Event;
|
||||
|
||||
use Joomla\CMS\Event\AbstractEvent;
|
||||
use Joomla\Input\Input;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Event object to retrieve OAuthCallbacks.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class OAuthCallbackEvent extends AbstractEvent
|
||||
{
|
||||
/**
|
||||
* The event context.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $context = null;
|
||||
|
||||
/**
|
||||
* The event input.
|
||||
*
|
||||
* @var Input
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $input = null;
|
||||
|
||||
/**
|
||||
* Get the event context.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getContext()
|
||||
{
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the event context.
|
||||
*
|
||||
* @param string $context Event context
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function setContext($context)
|
||||
{
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the event input.
|
||||
*
|
||||
* @return Input
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getInput()
|
||||
{
|
||||
return $this->input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the event input.
|
||||
*
|
||||
* @param Input $input Event input
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function setInput($input)
|
||||
{
|
||||
$this->input = $input;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Exception;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Media file exists exception.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class FileExistsException extends \Exception
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Exception;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Media file not found exception.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class FileNotFoundException extends \Exception
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Exception;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Media invalid path exception.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class InvalidPathException extends \Exception
|
||||
{
|
||||
}
|
||||
543
administrator/components/com_media/src/Model/ApiModel.php
Normal file
543
administrator/components/com_media/src/Model/ApiModel.php
Normal file
@ -0,0 +1,543 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Model;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Filesystem\File;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Object\CMSObject;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Component\Media\Administrator\Event\FetchMediaItemEvent;
|
||||
use Joomla\Component\Media\Administrator\Event\FetchMediaItemsEvent;
|
||||
use Joomla\Component\Media\Administrator\Event\FetchMediaItemUrlEvent;
|
||||
use Joomla\Component\Media\Administrator\Exception\FileExistsException;
|
||||
use Joomla\Component\Media\Administrator\Exception\FileNotFoundException;
|
||||
use Joomla\Component\Media\Administrator\Exception\InvalidPathException;
|
||||
use Joomla\Component\Media\Administrator\Provider\ProviderManagerHelperTrait;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Api Model
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class ApiModel extends BaseDatabaseModel
|
||||
{
|
||||
use ProviderManagerHelperTrait;
|
||||
|
||||
/**
|
||||
* The available extensions.
|
||||
*
|
||||
* @var string[]
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $allowedExtensions = null;
|
||||
|
||||
/**
|
||||
* Returns the requested file or folder information. More information
|
||||
* can be found in AdapterInterface::getFile().
|
||||
*
|
||||
* @param string $adapter The adapter
|
||||
* @param string $path The path to the file or folder
|
||||
* @param array $options The options
|
||||
*
|
||||
* @return \stdClass
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
* @see AdapterInterface::getFile()
|
||||
*/
|
||||
public function getFile($adapter, $path = '/', $options = [])
|
||||
{
|
||||
// Add adapter prefix to the file returned
|
||||
$file = $this->getAdapter($adapter)->getFile($path);
|
||||
|
||||
// Check if it is a media file
|
||||
if ($file->type == 'file' && !$this->isMediaFile($file->path)) {
|
||||
throw new InvalidPathException();
|
||||
}
|
||||
|
||||
if (isset($options['url']) && $options['url'] && $file->type == 'file') {
|
||||
$file->url = $this->getUrl($adapter, $file->path);
|
||||
}
|
||||
|
||||
if (isset($options['content']) && $options['content'] && $file->type == 'file') {
|
||||
$resource = $this->getAdapter($adapter)->getResource($file->path);
|
||||
|
||||
if ($resource) {
|
||||
$file->content = base64_encode(stream_get_contents($resource));
|
||||
}
|
||||
}
|
||||
|
||||
$file->path = $adapter . ":" . $file->path;
|
||||
$file->adapter = $adapter;
|
||||
|
||||
$event = new FetchMediaItemEvent('onFetchMediaItem', ['item' => $file]);
|
||||
Factory::getApplication()->getDispatcher()->dispatch($event->getName(), $event);
|
||||
|
||||
return $event->getArgument('item');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the folders and files for the given path. More information
|
||||
* can be found in AdapterInterface::getFiles().
|
||||
*
|
||||
* @param string $adapter The adapter
|
||||
* @param string $path The folder
|
||||
* @param array $options The options
|
||||
*
|
||||
* @return \stdClass[]
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
* @see AdapterInterface::getFile()
|
||||
*/
|
||||
public function getFiles($adapter, $path = '/', $options = [])
|
||||
{
|
||||
// Check whether user searching
|
||||
if ($options['search'] != null) {
|
||||
// Do search
|
||||
$files = $this->search($adapter, $options['search'], $path, $options['recursive']);
|
||||
} else {
|
||||
// Grab files for the path
|
||||
$files = $this->getAdapter($adapter)->getFiles($path);
|
||||
}
|
||||
|
||||
// Add adapter prefix to all the files to be returned
|
||||
foreach ($files as $key => $file) {
|
||||
// Check if the file is valid
|
||||
if ($file->type == 'file' && !$this->isMediaFile($file->path)) {
|
||||
// Remove the file from the data
|
||||
unset($files[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if we need more information
|
||||
if (isset($options['url']) && $options['url'] && $file->type == 'file') {
|
||||
$file->url = $this->getUrl($adapter, $file->path);
|
||||
}
|
||||
|
||||
if (isset($options['content']) && $options['content'] && $file->type == 'file') {
|
||||
$resource = $this->getAdapter($adapter)->getResource($file->path);
|
||||
|
||||
if ($resource) {
|
||||
$file->content = base64_encode(stream_get_contents($resource));
|
||||
}
|
||||
}
|
||||
|
||||
$file->path = $adapter . ":" . $file->path;
|
||||
$file->adapter = $adapter;
|
||||
}
|
||||
|
||||
// Make proper indexes
|
||||
$files = array_values($files);
|
||||
|
||||
$event = new FetchMediaItemsEvent('onFetchMediaItems', ['items' => $files]);
|
||||
Factory::getApplication()->getDispatcher()->dispatch($event->getName(), $event);
|
||||
|
||||
return $event->getArgument('items');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a folder with the given name in the given path. More information
|
||||
* can be found in AdapterInterface::createFolder().
|
||||
*
|
||||
* @param string $adapter The adapter
|
||||
* @param string $name The name
|
||||
* @param string $path The folder
|
||||
* @param boolean $override Should the folder being overridden when it exists
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
* @see AdapterInterface::createFolder()
|
||||
*/
|
||||
public function createFolder($adapter, $name, $path, $override)
|
||||
{
|
||||
try {
|
||||
$file = $this->getFile($adapter, $path . '/' . $name);
|
||||
} catch (FileNotFoundException $e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
// Check if the file exists
|
||||
if (isset($file) && !$override) {
|
||||
throw new FileExistsException();
|
||||
}
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$object = new CMSObject();
|
||||
$object->adapter = $adapter;
|
||||
$object->name = $name;
|
||||
$object->path = $path;
|
||||
|
||||
PluginHelper::importPlugin('content');
|
||||
|
||||
$result = $app->triggerEvent('onContentBeforeSave', ['com_media.folder', $object, true, $object]);
|
||||
|
||||
if (\in_array(false, $result, true)) {
|
||||
throw new \Exception($object->getError());
|
||||
}
|
||||
|
||||
$object->name = $this->getAdapter($object->adapter)->createFolder($object->name, $object->path);
|
||||
|
||||
$app->triggerEvent('onContentAfterSave', ['com_media.folder', $object, true, $object]);
|
||||
|
||||
return $object->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file with the given name in the given path with the data. More information
|
||||
* can be found in AdapterInterface::createFile().
|
||||
*
|
||||
* @param string $adapter The adapter
|
||||
* @param string $name The name
|
||||
* @param string $path The folder
|
||||
* @param string $data The data
|
||||
* @param boolean $override Should the file being overridden when it exists
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
* @see AdapterInterface::createFile()
|
||||
*/
|
||||
public function createFile($adapter, $name, $path, $data, $override)
|
||||
{
|
||||
try {
|
||||
$file = $this->getFile($adapter, $path . '/' . $name);
|
||||
} catch (FileNotFoundException $e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
// Check if the file exists
|
||||
if (isset($file) && !$override) {
|
||||
throw new FileExistsException();
|
||||
}
|
||||
|
||||
// Check if it is a media file
|
||||
if (!$this->isMediaFile($path . '/' . $name)) {
|
||||
throw new InvalidPathException(Text::_('JLIB_MEDIA_ERROR_WARNFILETYPE'));
|
||||
}
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$object = new CMSObject();
|
||||
$object->adapter = $adapter;
|
||||
$object->name = $name;
|
||||
$object->path = $path;
|
||||
$object->data = $data;
|
||||
$object->extension = strtolower(File::getExt($name));
|
||||
|
||||
PluginHelper::importPlugin('content');
|
||||
|
||||
// Also include the filesystem plugins, perhaps they support batch processing too
|
||||
PluginHelper::importPlugin('media-action');
|
||||
|
||||
$result = $app->triggerEvent('onContentBeforeSave', ['com_media.file', $object, true, $object]);
|
||||
|
||||
if (\in_array(false, $result, true)) {
|
||||
throw new \Exception($object->getError());
|
||||
}
|
||||
|
||||
$object->name = $this->getAdapter($object->adapter)->createFile($object->name, $object->path, $object->data);
|
||||
|
||||
$app->triggerEvent('onContentAfterSave', ['com_media.file', $object, true, $object]);
|
||||
|
||||
return $object->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the file with the given name in the given path with the data. More information
|
||||
* can be found in AdapterInterface::updateFile().
|
||||
*
|
||||
* @param string $adapter The adapter
|
||||
* @param string $name The name
|
||||
* @param string $path The folder
|
||||
* @param string $data The data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
* @see AdapterInterface::updateFile()
|
||||
*/
|
||||
public function updateFile($adapter, $name, $path, $data)
|
||||
{
|
||||
// Check if it is a media file
|
||||
if (!$this->isMediaFile($path . '/' . $name)) {
|
||||
throw new InvalidPathException();
|
||||
}
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$object = new CMSObject();
|
||||
$object->adapter = $adapter;
|
||||
$object->name = $name;
|
||||
$object->path = $path;
|
||||
$object->data = $data;
|
||||
$object->extension = strtolower(File::getExt($name));
|
||||
|
||||
PluginHelper::importPlugin('content');
|
||||
|
||||
// Also include the filesystem plugins, perhaps they support batch processing too
|
||||
PluginHelper::importPlugin('media-action');
|
||||
|
||||
$result = $app->triggerEvent('onContentBeforeSave', ['com_media.file', $object, false, $object]);
|
||||
|
||||
if (\in_array(false, $result, true)) {
|
||||
throw new \Exception($object->getError());
|
||||
}
|
||||
|
||||
$this->getAdapter($object->adapter)->updateFile($object->name, $object->path, $object->data);
|
||||
|
||||
$app->triggerEvent('onContentAfterSave', ['com_media.file', $object, false, $object]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the folder or file of the given path. More information
|
||||
* can be found in AdapterInterface::delete().
|
||||
*
|
||||
* @param string $adapter The adapter
|
||||
* @param string $path The path to the file or folder
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
* @see AdapterInterface::delete()
|
||||
*/
|
||||
public function delete($adapter, $path)
|
||||
{
|
||||
$file = $this->getFile($adapter, $path);
|
||||
|
||||
// Check if it is a media file
|
||||
if ($file->type == 'file' && !$this->isMediaFile($file->path)) {
|
||||
throw new InvalidPathException();
|
||||
}
|
||||
|
||||
$type = $file->type === 'file' ? 'file' : 'folder';
|
||||
$app = Factory::getApplication();
|
||||
$object = new CMSObject();
|
||||
$object->adapter = $adapter;
|
||||
$object->path = $path;
|
||||
|
||||
PluginHelper::importPlugin('content');
|
||||
|
||||
// Also include the filesystem plugins, perhaps they support batch processing too
|
||||
PluginHelper::importPlugin('media-action');
|
||||
|
||||
$result = $app->triggerEvent('onContentBeforeDelete', ['com_media.' . $type, $object]);
|
||||
|
||||
if (\in_array(false, $result, true)) {
|
||||
throw new \Exception($object->getError());
|
||||
}
|
||||
|
||||
$this->getAdapter($object->adapter)->delete($object->path);
|
||||
|
||||
$app->triggerEvent('onContentAfterDelete', ['com_media.' . $type, $object]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies file or folder from source path to destination path
|
||||
* If forced, existing files/folders would be overwritten
|
||||
*
|
||||
* @param string $adapter The adapter
|
||||
* @param string $sourcePath Source path of the file or folder (relative)
|
||||
* @param string $destinationPath Destination path(relative)
|
||||
* @param bool $force Force to overwrite
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function copy($adapter, $sourcePath, $destinationPath, $force = false)
|
||||
{
|
||||
return $this->getAdapter($adapter)->copy($sourcePath, $destinationPath, $force);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves file or folder from source path to destination path
|
||||
* If forced, existing files/folders would be overwritten
|
||||
*
|
||||
* @param string $adapter The adapter
|
||||
* @param string $sourcePath Source path of the file or folder (relative)
|
||||
* @param string $destinationPath Destination path(relative)
|
||||
* @param bool $force Force to overwrite
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function move($adapter, $sourcePath, $destinationPath, $force = false)
|
||||
{
|
||||
return $this->getAdapter($adapter)->move($sourcePath, $destinationPath, $force);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a url for serve media files from adapter.
|
||||
* Url must provide a valid image type to be displayed on Joomla! site.
|
||||
*
|
||||
* @param string $adapter The adapter
|
||||
* @param string $path The relative path for the file
|
||||
*
|
||||
* @return string Permalink to the relative file
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public function getUrl($adapter, $path)
|
||||
{
|
||||
// Check if it is a media file
|
||||
if (!$this->isMediaFile($path)) {
|
||||
throw new InvalidPathException();
|
||||
}
|
||||
|
||||
$url = $this->getAdapter($adapter)->getUrl($path);
|
||||
|
||||
$event = new FetchMediaItemUrlEvent('onFetchMediaFileUrl', ['adapter' => $adapter, 'path' => $path, 'url' => $url]);
|
||||
Factory::getApplication()->getDispatcher()->dispatch($event->getName(), $event);
|
||||
|
||||
return $event->getArgument('url');
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for a pattern in a given path
|
||||
*
|
||||
* @param string $adapter The adapter to work on
|
||||
* @param string $needle The search therm
|
||||
* @param string $path The base path for the search
|
||||
* @param bool $recursive Do a recursive search
|
||||
*
|
||||
* @return \stdClass[]
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function search($adapter, $needle, $path = '/', $recursive = true)
|
||||
{
|
||||
return $this->getAdapter($adapter)->search($path, $needle, $recursive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given path is an allowed media file.
|
||||
*
|
||||
* @param string $path The path to file
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function isMediaFile($path)
|
||||
{
|
||||
// Check if there is an extension available
|
||||
if (!strrpos($path, '.')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialize the allowed extensions
|
||||
if ($this->allowedExtensions === null) {
|
||||
// Get options from the input or fallback to images only
|
||||
$mediaTypes = explode(',', Factory::getApplication()->getInput()->getString('mediatypes', '0'));
|
||||
$types = [];
|
||||
$extensions = [];
|
||||
|
||||
// Default to showing all supported formats
|
||||
if (\count($mediaTypes) === 0) {
|
||||
$mediaTypes = ['0', '1', '2', '3'];
|
||||
}
|
||||
|
||||
array_map(
|
||||
function ($mediaType) use (&$types) {
|
||||
switch ($mediaType) {
|
||||
case '0':
|
||||
$types[] = 'images';
|
||||
break;
|
||||
case '1':
|
||||
$types[] = 'audios';
|
||||
break;
|
||||
case '2':
|
||||
$types[] = 'videos';
|
||||
break;
|
||||
case '3':
|
||||
$types[] = 'documents';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
$mediaTypes
|
||||
);
|
||||
|
||||
$images = array_map(
|
||||
'trim',
|
||||
explode(
|
||||
',',
|
||||
ComponentHelper::getParams('com_media')->get(
|
||||
'image_extensions',
|
||||
'bmp,gif,jpg,jpeg,png,webp'
|
||||
)
|
||||
)
|
||||
);
|
||||
$audios = array_map(
|
||||
'trim',
|
||||
explode(
|
||||
',',
|
||||
ComponentHelper::getParams('com_media')->get(
|
||||
'audio_extensions',
|
||||
'mp3,m4a,mp4a,ogg'
|
||||
)
|
||||
)
|
||||
);
|
||||
$videos = array_map(
|
||||
'trim',
|
||||
explode(
|
||||
',',
|
||||
ComponentHelper::getParams('com_media')->get(
|
||||
'video_extensions',
|
||||
'mp4,mp4v,mpeg,mov,webm'
|
||||
)
|
||||
)
|
||||
);
|
||||
$documents = array_map(
|
||||
'trim',
|
||||
explode(
|
||||
',',
|
||||
ComponentHelper::getParams('com_media')->get(
|
||||
'doc_extensions',
|
||||
'doc,odg,odp,ods,odt,pdf,ppt,txt,xcf,xls,csv'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($types as $type) {
|
||||
if (\in_array($type, ['images', 'audios', 'videos', 'documents'])) {
|
||||
$extensions = array_merge($extensions, ${$type});
|
||||
}
|
||||
}
|
||||
|
||||
// Make them an array
|
||||
$this->allowedExtensions = $extensions;
|
||||
}
|
||||
|
||||
// Extract the extension
|
||||
$extension = strtolower(substr($path, strrpos($path, '.') + 1));
|
||||
|
||||
// Check if the extension exists in the allowed extensions
|
||||
return \in_array($extension, $this->allowedExtensions);
|
||||
}
|
||||
}
|
||||
73
administrator/components/com_media/src/Model/FileModel.php
Normal file
73
administrator/components/com_media/src/Model/FileModel.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Model;
|
||||
|
||||
use Joomla\CMS\Form\FormHelper;
|
||||
use Joomla\CMS\MVC\Model\FormModel;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* File Model
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class FileModel extends FormModel
|
||||
{
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return \Joomla\CMS\Form\Form|boolean A Form object on success, false on failure
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getForm($data = [], $loadData = true)
|
||||
{
|
||||
PluginHelper::importPlugin('media-action');
|
||||
|
||||
// Load backend forms in frontend.
|
||||
FormHelper::addFormPath(JPATH_ADMINISTRATOR . '/components/com_media/forms');
|
||||
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_media.file', 'file', ['control' => 'jform', 'load_data' => $loadData]);
|
||||
|
||||
if (empty($form)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the file information for the given path. Path must be
|
||||
* in the format: adapter:path/to/file.extension
|
||||
*
|
||||
* @param string $path The path to get the information from.
|
||||
*
|
||||
* @return \stdClass An object with file information
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @see ApiModel::getFile()
|
||||
*/
|
||||
public function getFileInformation($path)
|
||||
{
|
||||
list($adapter, $path) = explode(':', $path, 2);
|
||||
|
||||
return $this->bootComponent('com_media')->getMVCFactory()->createModel('Api', 'Administrator')
|
||||
->getFile($adapter, $path, ['url' => true, 'content' => true]);
|
||||
}
|
||||
}
|
||||
55
administrator/components/com_media/src/Model/MediaModel.php
Normal file
55
administrator/components/com_media/src/Model/MediaModel.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Model;
|
||||
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\Component\Media\Administrator\Provider\ProviderManagerHelperTrait;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Media View Model
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class MediaModel extends BaseDatabaseModel
|
||||
{
|
||||
use ProviderManagerHelperTrait;
|
||||
|
||||
/**
|
||||
* Obtain list of supported providers
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getProviders()
|
||||
{
|
||||
$results = [];
|
||||
|
||||
foreach ($this->getProviderManager()->getProviders() as $provider) {
|
||||
$result = new \stdClass();
|
||||
$result->name = $provider->getID();
|
||||
$result->displayName = $provider->getDisplayName();
|
||||
$result->adapterNames = [];
|
||||
|
||||
foreach ($provider->getAdapters() as $adapter) {
|
||||
$result->adapterNames[] = $adapter->getAdapterName();
|
||||
}
|
||||
|
||||
$results[] = $result;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Plugin;
|
||||
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Media Manager Base Plugin for the media actions
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class MediaActionPlugin extends CMSPlugin
|
||||
{
|
||||
/**
|
||||
* Load the language file on instantiation.
|
||||
*
|
||||
* @var boolean
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* The form event. Load additional parameters when available into the field form.
|
||||
* Only when the type of the form is of interest.
|
||||
*
|
||||
* @param Form $form The form
|
||||
* @param \stdClass $data The data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function onContentPrepareForm(Form $form, $data)
|
||||
{
|
||||
// Check if it is the right form
|
||||
if ($form->getName() != 'com_media.file') {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->loadCss();
|
||||
$this->loadJs();
|
||||
|
||||
// The file with the params for the edit view
|
||||
$paramsFile = JPATH_PLUGINS . '/media-action/' . $this->_name . '/form/' . $this->_name . '.xml';
|
||||
|
||||
// When the file exists, load it into the form
|
||||
if (file_exists($paramsFile)) {
|
||||
$form->loadFile($paramsFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the javascript files of the plugin.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function loadJs()
|
||||
{
|
||||
HTMLHelper::_(
|
||||
'script',
|
||||
'plg_media-action_' . $this->_name . '/' . $this->_name . '.js',
|
||||
['version' => 'auto', 'relative' => true],
|
||||
['type' => 'module']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the CSS files of the plugin.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function loadCss()
|
||||
{
|
||||
HTMLHelper::_(
|
||||
'stylesheet',
|
||||
'plg_media-action_' . $this->_name . '/' . $this->_name . '.css',
|
||||
['version' => 'auto', 'relative' => true]
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Provider;
|
||||
|
||||
use Joomla\Component\Media\Administrator\Adapter\AdapterInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Media provider interface.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
interface ProviderInterface
|
||||
{
|
||||
/**
|
||||
* Returns the ID of the provider
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getID();
|
||||
|
||||
/**
|
||||
* Returns the display name
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getDisplayName();
|
||||
|
||||
/**
|
||||
* Returns a list of adapters
|
||||
*
|
||||
* @return AdapterInterface[]
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getAdapters();
|
||||
}
|
||||
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\Provider;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\Component\Media\Administrator\Adapter\AdapterInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Media Adapter Manager
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class ProviderManager
|
||||
{
|
||||
/**
|
||||
* The array of providers
|
||||
*
|
||||
* @var ProviderInterface[]
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $providers = [];
|
||||
|
||||
/**
|
||||
* Returns an associative array of adapters with provider name as the key
|
||||
*
|
||||
* @return ProviderInterface[]
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getProviders()
|
||||
{
|
||||
return $this->providers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a provider into the ProviderManager
|
||||
*
|
||||
* @param ProviderInterface $provider The provider to be registered
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function registerProvider(ProviderInterface $provider)
|
||||
{
|
||||
$this->providers[$provider->getID()] = $provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a provider from the ProviderManager.
|
||||
* When no provider, or null is passed in, then all providers are cleared.
|
||||
*
|
||||
* @param ProviderInterface|null $provider The provider to be unregistered
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.6
|
||||
*/
|
||||
public function unregisterProvider(ProviderInterface $provider = null): void
|
||||
{
|
||||
if ($provider === null) {
|
||||
$this->providers = [];
|
||||
return;
|
||||
}
|
||||
|
||||
if (!\array_key_exists($provider->getID(), $this->providers)) {
|
||||
return;
|
||||
}
|
||||
|
||||
unset($this->providers[$provider->getID()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the provider for a particular ID
|
||||
*
|
||||
* @param string $id The ID for the provider
|
||||
*
|
||||
* @return ProviderInterface
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getProvider($id)
|
||||
{
|
||||
if (!isset($this->providers[$id])) {
|
||||
throw new \Exception(Text::_('COM_MEDIA_ERROR_MEDIA_PROVIDER_NOT_FOUND'));
|
||||
}
|
||||
|
||||
return $this->providers[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an adapter for an account
|
||||
*
|
||||
* @param string $name The name of an adapter
|
||||
*
|
||||
* @return AdapterInterface
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getAdapter($name)
|
||||
{
|
||||
list($provider, $account) = array_pad(explode('-', $name, 2), 2, null);
|
||||
|
||||
if ($account == null) {
|
||||
throw new \Exception(Text::_('COM_MEDIA_ERROR_ACCOUNT_NOT_SET'));
|
||||
}
|
||||
|
||||
$adapters = $this->getProvider($provider)->getAdapters();
|
||||
|
||||
if (!isset($adapters[$account])) {
|
||||
throw new \Exception(Text::_('COM_MEDIA_ERROR_ACCOUNT_NOT_FOUND'));
|
||||
}
|
||||
|
||||
return $adapters[$account];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.API
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Media\Administrator\Provider;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Component\Media\Administrator\Adapter\AdapterInterface;
|
||||
use Joomla\Component\Media\Administrator\Event\MediaProviderEvent;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Trait for classes that need adapters.
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
trait ProviderManagerHelperTrait
|
||||
{
|
||||
/**
|
||||
* Holds the available media file adapters.
|
||||
*
|
||||
* @var ProviderManager
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
private $providerManager = null;
|
||||
|
||||
/**
|
||||
* The default adapter name.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
private $defaultAdapterName = null;
|
||||
|
||||
/**
|
||||
* Return a provider manager.
|
||||
*
|
||||
* @return ProviderManager
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
public function getProviderManager(): ProviderManager
|
||||
{
|
||||
if (!$this->providerManager) {
|
||||
// Fire the event to get the results
|
||||
$eventParameters = ['context' => 'AdapterManager', 'providerManager' => new ProviderManager()];
|
||||
$event = new MediaProviderEvent('onSetupProviders', $eventParameters);
|
||||
PluginHelper::importPlugin('filesystem');
|
||||
Factory::getApplication()->triggerEvent('onSetupProviders', $event);
|
||||
$this->providerManager = $event->getProviderManager();
|
||||
}
|
||||
|
||||
return $this->providerManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a provider for the given id.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return ProviderInterface
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 4.1.0
|
||||
*/
|
||||
public function getProvider(string $id): ProviderInterface
|
||||
{
|
||||
return $this->getProviderManager()->getProvider($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an adapter for the given name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return AdapterInterface
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 4.1.0
|
||||
*/
|
||||
public function getAdapter(string $name): AdapterInterface
|
||||
{
|
||||
return $this->getProviderManager()->getAdapter($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with the adapter name as key and the path of the file.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Exception
|
||||
* @since 4.1.0
|
||||
*/
|
||||
protected function resolveAdapterAndPath(string $path): array
|
||||
{
|
||||
$result = [];
|
||||
$parts = explode(':', $path, 2);
|
||||
|
||||
// If we have 2 parts, we have both an adapter name and a file path
|
||||
if (\count($parts) === 2) {
|
||||
$result['adapter'] = $parts[0];
|
||||
$result['path'] = $parts[1];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!$this->getDefaultAdapterName()) {
|
||||
throw new \InvalidArgumentException(Text::_('COM_MEDIA_ERROR_NO_ADAPTER_FOUND'));
|
||||
}
|
||||
|
||||
// If we have less than 2 parts, we return a default adapter name
|
||||
$result['adapter'] = $this->getDefaultAdapterName();
|
||||
|
||||
// If we have 1 part, we return it as the path. Otherwise we return a default path
|
||||
$result['path'] = \count($parts) ? $parts[0] : '/';
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default adapter name.
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 4.1.0
|
||||
*/
|
||||
protected function getDefaultAdapterName(): ?string
|
||||
{
|
||||
if ($this->defaultAdapterName) {
|
||||
return $this->defaultAdapterName;
|
||||
}
|
||||
|
||||
$defaultAdapter = $this->getAdapter('local-' . ComponentHelper::getParams('com_media')->get('file_path', 'images'));
|
||||
|
||||
if (
|
||||
!$defaultAdapter
|
||||
&& $this->getProviderManager()->getProvider('local')
|
||||
&& $this->getProviderManager()->getProvider('local')->getAdapters()
|
||||
) {
|
||||
$defaultAdapter = $this->getProviderManager()->getProvider('local')->getAdapters()[0];
|
||||
}
|
||||
|
||||
if (!$defaultAdapter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->defaultAdapterName = 'local-' . $defaultAdapter->getAdapterName();
|
||||
|
||||
return $this->defaultAdapterName;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @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\Component\Media\Administrator\View\File;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\CMS\Toolbar\Toolbar;
|
||||
use Joomla\CMS\Toolbar\ToolbarHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* View to edit a file.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$input = Factory::getApplication()->getInput();
|
||||
|
||||
$this->form = $this->get('Form');
|
||||
|
||||
// The component params
|
||||
$this->params = ComponentHelper::getParams('com_media');
|
||||
|
||||
// The requested file
|
||||
$this->file = $this->getModel()->getFileInformation($input->getString('path', null));
|
||||
|
||||
if (empty($this->file->content)) {
|
||||
// @todo error handling controller redirect files
|
||||
throw new \Exception(Text::_('COM_MEDIA_ERROR_NO_CONTENT_AVAILABLE'));
|
||||
}
|
||||
|
||||
$this->addToolbar();
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the toolbar buttons
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function addToolbar()
|
||||
{
|
||||
ToolbarHelper::title(Text::_('COM_MEDIA_EDIT'), 'images mediamanager');
|
||||
|
||||
$toolbar = Toolbar::getInstance();
|
||||
$toolbar->apply('apply');
|
||||
$toolbar->save('save');
|
||||
$toolbar->standardButton('reset', 'COM_MEDIA_RESET', 'reset')
|
||||
->icon('icon-refresh')
|
||||
->listCheck(false);
|
||||
|
||||
$toolbar->cancel('cancel');
|
||||
}
|
||||
}
|
||||
133
administrator/components/com_media/src/View/Media/HtmlView.php
Normal file
133
administrator/components/com_media/src/View/Media/HtmlView.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Media\Administrator\View\Media;
|
||||
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Layout\FileLayout;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Toolbar\Toolbar;
|
||||
use Joomla\CMS\Toolbar\ToolbarHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Media List View
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
/**
|
||||
* Holds a list of providers
|
||||
*
|
||||
* @var array|string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $providers = null;
|
||||
|
||||
/**
|
||||
* The current path of the media manager
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $currentPath;
|
||||
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param string $tpl The name of the template file to parse;
|
||||
* automatically searches through the template paths.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
// Prepare the toolbar
|
||||
$this->prepareToolbar();
|
||||
|
||||
// Get enabled adapters
|
||||
$this->providers = $this->get('Providers');
|
||||
|
||||
// Check that there are providers
|
||||
if (!\count($this->providers)) {
|
||||
$link = Route::_('index.php?option=com_plugins&view=plugins&filter[folder]=filesystem');
|
||||
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_MEDIA_ERROR_NO_PROVIDERS', $link), CMSApplication::MSG_WARNING);
|
||||
}
|
||||
|
||||
$this->currentPath = Factory::getApplication()->getInput()->getString('path');
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the toolbar.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function prepareToolbar()
|
||||
{
|
||||
$tmpl = Factory::getApplication()->getInput()->getCmd('tmpl');
|
||||
$toolbar = Toolbar::getInstance();
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
// Set the title
|
||||
ToolbarHelper::title(Text::_('COM_MEDIA'), 'images mediamanager');
|
||||
|
||||
// Add the upload and create folder buttons
|
||||
if ($user->authorise('core.create', 'com_media')) {
|
||||
// Add the upload button
|
||||
$layout = new FileLayout('toolbar.upload', JPATH_COMPONENT_ADMINISTRATOR . '/layouts');
|
||||
|
||||
$toolbar->customButton('upload')
|
||||
->html($layout->render([]));
|
||||
$toolbar->divider();
|
||||
|
||||
// Add the create folder button
|
||||
$layout = new FileLayout('toolbar.create-folder', JPATH_COMPONENT_ADMINISTRATOR . '/layouts');
|
||||
|
||||
$toolbar->customButton('new')
|
||||
->html($layout->render([]));
|
||||
$toolbar->divider();
|
||||
}
|
||||
|
||||
// Add a delete button
|
||||
if ($user->authorise('core.delete', 'com_media')) {
|
||||
// Instantiate a new FileLayout instance and render the layout
|
||||
$layout = new FileLayout('toolbar.delete', JPATH_COMPONENT_ADMINISTRATOR . '/layouts');
|
||||
|
||||
$toolbar->customButton('delete')
|
||||
->html($layout->render([]));
|
||||
$toolbar->divider();
|
||||
}
|
||||
|
||||
// Add the preferences button
|
||||
if (($user->authorise('core.admin', 'com_media') || $user->authorise('core.options', 'com_media')) && $tmpl !== 'component') {
|
||||
$toolbar->preferences('com_media');
|
||||
$toolbar->divider();
|
||||
}
|
||||
|
||||
if ($tmpl !== 'component') {
|
||||
$toolbar->help('Media');
|
||||
}
|
||||
}
|
||||
}
|
||||
73
administrator/components/com_media/tmpl/file/default.php
Normal file
73
administrator/components/com_media/tmpl/file/default.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Layout\LayoutHelper;
|
||||
use Joomla\CMS\Session\Session;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = $this->document->getWebAssetManager();
|
||||
$wa->useScript('keepalive')
|
||||
->useScript('form.validate')
|
||||
->useStyle('com_media.mediamanager');
|
||||
|
||||
$script = $wa->getAsset('script', 'com_media.edit-images')->getUri(true);
|
||||
|
||||
$params = ComponentHelper::getParams('com_media');
|
||||
$input = Factory::getApplication()->getInput();
|
||||
|
||||
/** @var \Joomla\CMS\Form\Form $form */
|
||||
$form = $this->form;
|
||||
|
||||
$tmpl = $input->getCmd('tmpl');
|
||||
|
||||
$input->set('hidemainmenu', true);
|
||||
|
||||
$mediaTypes = $input->getString('mediatypes', '0');
|
||||
|
||||
// Populate the media config
|
||||
$config = [
|
||||
'apiBaseUrl' => Uri::base() . 'index.php?option=com_media&format=json' . '&mediatypes=' . $mediaTypes,
|
||||
'csrfToken' => Session::getFormToken(),
|
||||
'uploadPath' => $this->file->path,
|
||||
'editViewUrl' => Uri::base() . 'index.php?option=com_media&view=file' . ($tmpl ? '&tmpl=' . $tmpl : '') . '&mediatypes=' . $mediaTypes,
|
||||
'imagesExtensions' => array_map('trim', explode(',', $params->get('image_extensions', 'bmp,gif,jpg,jpeg,png,webp'))),
|
||||
'audioExtensions' => array_map('trim', explode(',', $params->get('audio_extensions', 'mp3,m4a,mp4a,ogg'))),
|
||||
'videoExtensions' => array_map('trim', explode(',', $params->get('video_extensions', 'mp4,mp4v,mpeg,mov,webm'))),
|
||||
'documentExtensions' => array_map('trim', explode(',', $params->get('doc_extensions', 'doc,odg,odp,ods,odt,pdf,ppt,txt,xcf,xls,csv'))),
|
||||
'maxUploadSizeMb' => $params->get('upload_maxsize', 10),
|
||||
'contents' => $this->file->content,
|
||||
];
|
||||
|
||||
$this->document->addScriptOptions('com_media', $config);
|
||||
|
||||
$this->useCoreUI = true;
|
||||
?>
|
||||
<?php if ($tmpl === 'component') : ?>
|
||||
<div class="subhead noshadow mb-3">
|
||||
<?php echo $this->document->getToolbar('toolbar')->render(); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form action="#" method="post" name="adminForm" id="media-form" class="form-validate main-card media-form mt-3">
|
||||
<?php $fieldSets = $form->getFieldsets(); ?>
|
||||
<?php if ($fieldSets) : ?>
|
||||
<?php echo HTMLHelper::_('uitab.startTabSet', 'myTab', ['active' => 'attrib-' . reset($fieldSets)->name, 'breakpoint' => 768]); ?>
|
||||
<?php echo LayoutHelper::render('joomla.edit.params', $this); ?>
|
||||
<?php echo '<div id="media-manager-edit-container" class="media-manager-edit"></div>'; ?>
|
||||
<?php echo HTMLHelper::_('uitab.endTabSet'); ?>
|
||||
<?php endif; ?>
|
||||
<input type="hidden" name="mediatypes" value="<?php echo $this->escape($mediaTypes); ?>">
|
||||
</form>
|
||||
<script type="module" src="<?php echo $script . '?' . $this->document->getMediaVersion(); ?>"></script>
|
||||
63
administrator/components/com_media/tmpl/media/default.php
Normal file
63
administrator/components/com_media/tmpl/media/default.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Session\Session;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$params = ComponentHelper::getParams('com_media');
|
||||
$input = $app->getInput();
|
||||
$user = $app->getIdentity();
|
||||
|
||||
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = $this->document->getWebAssetManager();
|
||||
$wa->useScript('keepalive')
|
||||
->useStyle('com_media.mediamanager')
|
||||
->useScript('com_media.mediamanager');
|
||||
|
||||
// Populate the language
|
||||
$this->loadTemplate('texts');
|
||||
|
||||
$tmpl = $input->getCmd('tmpl');
|
||||
|
||||
$mediaTypes = '&mediatypes=' . $input->getString('mediatypes', '0,1,2,3');
|
||||
|
||||
// Populate the media config
|
||||
$config = [
|
||||
'apiBaseUrl' => Uri::base() . 'index.php?option=com_media&format=json' . $mediaTypes,
|
||||
'csrfToken' => Session::getFormToken(),
|
||||
'filePath' => $params->get('file_path', 'images'),
|
||||
'fileBaseUrl' => Uri::root() . $params->get('file_path', 'images'),
|
||||
'fileBaseRelativeUrl' => $params->get('file_path', 'images'),
|
||||
'editViewUrl' => Uri::base() . 'index.php?option=com_media&view=file' . ($tmpl ? '&tmpl=' . $tmpl : '') . $mediaTypes,
|
||||
'imagesExtensions' => array_map('trim', explode(',', $params->get('image_extensions', 'bmp,gif,jpg,jpeg,png,webp'))),
|
||||
'audioExtensions' => array_map('trim', explode(',', $params->get('audio_extensions', 'mp3,m4a,mp4a,ogg'))),
|
||||
'videoExtensions' => array_map('trim', explode(',', $params->get('video_extensions', 'mp4,mp4v,mpeg,mov,webm'))),
|
||||
'documentExtensions' => array_map('trim', explode(',', $params->get('doc_extensions', 'doc,odg,odp,ods,odt,pdf,ppt,txt,xcf,xls,csv'))),
|
||||
'maxUploadSizeMb' => $params->get('upload_maxsize', 10),
|
||||
'providers' => (array) $this->providers,
|
||||
'currentPath' => $this->currentPath,
|
||||
'isModal' => $tmpl === 'component',
|
||||
'canCreate' => $user->authorise('core.create', 'com_media'),
|
||||
'canEdit' => $user->authorise('core.edit', 'com_media'),
|
||||
'canDelete' => $user->authorise('core.delete', 'com_media'),
|
||||
];
|
||||
$this->document->addScriptOptions('com_media', $config);
|
||||
?>
|
||||
<?php if ($tmpl === 'component') : ?>
|
||||
<div class="subhead noshadow mb-3">
|
||||
<?php echo $this->document->getToolbar('toolbar')->render(); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div id="com-media"></div>
|
||||
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata>
|
||||
<layout title="COM_MEDIA_MEDIA_VIEW_DEFAULT_TITLE">
|
||||
<message>
|
||||
<![CDATA[COM_MEDIA_MEDIA_VIEW_DEFAULT_DESC]]>
|
||||
</message>
|
||||
</layout>
|
||||
</metadata>
|
||||
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_media
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
$translationStrings = [
|
||||
'COM_MEDIA_ACTIONS_TOOLBAR_LABEL',
|
||||
'COM_MEDIA_ACTION_DELETE',
|
||||
'COM_MEDIA_ACTION_DOWNLOAD',
|
||||
'COM_MEDIA_ACTION_EDIT',
|
||||
'COM_MEDIA_ACTION_PREVIEW',
|
||||
'COM_MEDIA_ACTION_RENAME',
|
||||
'COM_MEDIA_ACTION_SHARE',
|
||||
'COM_MEDIA_BREADCRUMB_LABEL',
|
||||
'COM_MEDIA_BROWSER_TABLE_CAPTION',
|
||||
'COM_MEDIA_CHANGE_ORDERING',
|
||||
'COM_MEDIA_CONFIRM_DELETE_MODAL',
|
||||
'COM_MEDIA_CONFIRM_DELETE_MODAL_HEADING',
|
||||
'COM_MEDIA_CREATE_NEW_FOLDER',
|
||||
'COM_MEDIA_CREATE_NEW_FOLDER_ERROR',
|
||||
'COM_MEDIA_CREATE_NEW_FOLDER_SUCCESS',
|
||||
'COM_MEDIA_DECREASE_GRID',
|
||||
'COM_MEDIA_DELETE_ERROR',
|
||||
'COM_MEDIA_DELETE_SUCCESS',
|
||||
'COM_MEDIA_DROP_FILE',
|
||||
'COM_MEDIA_ERROR',
|
||||
'COM_MEDIA_ERROR_NOT_AUTHENTICATED',
|
||||
'COM_MEDIA_ERROR_NOT_AUTHORIZED',
|
||||
'COM_MEDIA_ERROR_NOT_FOUND',
|
||||
'COM_MEDIA_ERROR_WARNFILETOOLARGE',
|
||||
'COM_MEDIA_FILE',
|
||||
'COM_MEDIA_FILE_EXISTS_AND_OVERRIDE',
|
||||
'COM_MEDIA_FOLDER',
|
||||
'COM_MEDIA_FOLDER_NAME',
|
||||
'COM_MEDIA_INCREASE_GRID',
|
||||
'COM_MEDIA_MANAGE_ITEM',
|
||||
'COM_MEDIA_MEDIA_DATE_CREATED',
|
||||
'COM_MEDIA_MEDIA_DATE_MODIFIED',
|
||||
'COM_MEDIA_MEDIA_DIMENSION',
|
||||
'COM_MEDIA_MEDIA_EXTENSION',
|
||||
'COM_MEDIA_MEDIA_MIME_TYPE',
|
||||
'COM_MEDIA_MEDIA_NAME',
|
||||
'COM_MEDIA_MEDIA_SIZE',
|
||||
'COM_MEDIA_MEDIA_TYPE',
|
||||
'COM_MEDIA_NAME',
|
||||
'COM_MEDIA_ORDER_ASC',
|
||||
'COM_MEDIA_ORDER_BY',
|
||||
'COM_MEDIA_ORDER_DESC',
|
||||
'COM_MEDIA_ORDER_DIRECTION',
|
||||
'COM_MEDIA_PLEASE_SELECT_ITEM',
|
||||
'COM_MEDIA_RENAME',
|
||||
'COM_MEDIA_RENAME_ERROR',
|
||||
'COM_MEDIA_RENAME_SUCCESS',
|
||||
'COM_MEDIA_SEARCH',
|
||||
'COM_MEDIA_SELECT_ALL',
|
||||
'COM_MEDIA_SERVER_ERROR',
|
||||
'COM_MEDIA_SHARE',
|
||||
'COM_MEDIA_SHARE_COPY',
|
||||
'COM_MEDIA_SHARE_COPY_FAILED_ERROR',
|
||||
'COM_MEDIA_SHARE_DESC',
|
||||
'COM_MEDIA_TOGGLE_INFO',
|
||||
'COM_MEDIA_TOGGLE_LIST_VIEW',
|
||||
'COM_MEDIA_TOGGLE_SELECT_ITEM',
|
||||
'COM_MEDIA_TOOLBAR_LABEL',
|
||||
'COM_MEDIA_UPLOAD_SUCCESS',
|
||||
'ERROR',
|
||||
'JACTION_CREATE',
|
||||
'JAPPLY',
|
||||
'JCANCEL',
|
||||
'JGLOBAL_CONFIRM_DELETE',
|
||||
'JGLOBAL_NO_MATCHING_RESULTS',
|
||||
'JLIB_FORM_FIELD_REQUIRED_VALUE',
|
||||
'MESSAGE',
|
||||
];
|
||||
|
||||
foreach ($translationStrings as $string) {
|
||||
Text::script($string);
|
||||
}
|
||||
Reference in New Issue
Block a user