first commit

This commit is contained in:
2026-02-08 21:16:11 +01:00
commit e17b7026fd
8881 changed files with 1160453 additions and 0 deletions

View File

@@ -0,0 +1,163 @@
<?php
/**
* @package JCE - System Plugin
* @subpackage Fields
*
* @copyright (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
* @copyright (C) 2022 Ryan Demmer. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
// phpcs:disable PSR1.Files.SideEffects
\defined('JPATH_PLATFORM') or die;
// phpcs:enable PSR1.Files.SideEffects
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\Registry\Registry;
/**
* Extended the JCE Media Field with additional options
*
* @since 2.9.31
*/
class ExtendedMediaField extends FormField
{
/**
* The form field type.
*
* @var string
* @since 2.9.31
*/
protected $type = 'ExtendedMedia';
/**
* Layout to render the form
* @var string
*/
protected $layout = 'joomla.form.field.subform.default';
/**
* Method to attach a Form object to the field.
*
* @param \SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value.
*
* @return boolean True on success.
*
* @since 2.9.31
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
// convert array value to object
$value = is_array($value) ? (object) $value : $value;
// decode value if it is a string
if (is_string($value)) {
json_decode($value);
// Check if value is a valid JSON string.
if ($value !== '' && json_last_error() !== JSON_ERROR_NONE) {
// check for valid file which indicates value string
if (is_file(JPATH_ROOT . '/' . $value)) {
$value = '{"media_src":"' . $value . '","media_text":""}';
} else {
$value = '';
}
}
} elseif (
!is_object($value)
|| !property_exists($value, 'media_src')
|| !property_exists($value, 'media_text')
) {
return false;
}
if (!parent::setup($element, $value, $group)) {
return false;
}
return true;
}
/**
* Method to get the field input markup.
*
* @return string The field input markup.
*
* @since 2.7
*/
protected function getInput()
{
$xml = file_get_contents(__DIR__ . '/media.xml');
$formname = 'subform.' . str_replace(array('jform[', '[', ']'), array('', '.', ''), $this->name);
$subForm = Form::getInstance($formname, $xml, array('control' => $this->name));
if (is_string($this->value)) {
$this->value = json_decode($this->value);
}
// add data
$subForm->bind($this->value);
$exclude = array('name', 'type', 'label', 'description');
foreach ($this->element->attributes() as $key => $value) {
if (in_array($key, $exclude)) {
continue;
}
$subForm->setFieldAttribute('media_src', $key, (string) $value);
}
$data = $this->getLayoutData();
$data['forms'] = array($subForm);
// Prepare renderer
$renderer = $this->getRenderer($this->layout);
// Render
$html = $renderer->render($data);
return $html;
}
/**
* Method to post-process a field value.
*
* @param mixed $value The optional value to use as the default for the field.
* @param string $group The optional dot-separated form group path on which to find the field.
* @param Registry $input An optional Registry object with the entire data set to filter
* against the entire form.
*
* @return mixed The processed value.
*
* @since 2.9.31
*/
public function postProcess($value, $group = null, Registry $input = null)
{
$media = array('img', 'video', 'audio', 'iframe', 'a');
$value->media_supported = array_filter($media, function ($tag) {
$html = '<' . $tag . '></' . $tag . '>';
if ($tag == 'img') {
$html = '<' . $tag . '/>';
}
$html = ComponentHelper::filterText($html);
return !empty($html);
});
return $value;
}
}

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset name="extendedmedia" label="">
<field name="media_src" type="mediajce" label="PLG_FIELDS_MEDIAJCE_MEDIA_FILE_LABEL" />
<field name="media_text" type="text" label="PLG_FIELDS_MEDIAJCE_MEDIA_TEXT_LABEL" />
<field name="media_width" type="text" label="PLG_FIELDS_MEDIAJCE_MEDIA_WIDTH_LABEL" size="20" />
<field name="media_height" type="text" label="PLG_FIELDS_MEDIAJCE_MEDIA_HEIGHT_LABEL" />
<field name="media_type" type="list" label="PLG_FIELDS_MEDIAJCE_MEDIA_TYPE_LABEL">
<option value="embed">Embed</option>
<option value="link">Link</option>
</field>
<field name="media_caption" type="text" label="PLG_FIELDS_MEDIAJCE_MEDIA_CAPTION_LABEL" showon="media_type:embed" />
<field name="media_target" type="list" default="" label="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_LABEL" description="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_DESC" showon="media_type:link">
<option value=""></option>
<option value="_blank">PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_BLANK</option>
<option value="_self">PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_SELF</option>
<option value="_parent">PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_PARENT</option>
<option value="_top">PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_TOP</option>
<option value="download">PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_DOWNLOAD</option>
</field>
</fieldset>
</form>

View File

@@ -0,0 +1,248 @@
<?php
/**
* @package JCE - System Plugin
* @subpackage Fields
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @copyright (C) 2017 - 2022 Ryan Demmer. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Form\Field\MediaField;
use Joomla\CMS\Helper\MediaHelper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\Registry\Registry;
/**
* Provides a modal media selector field for the JCE File Browser
*
* @since 2.6.17
*/
class JFormFieldMediaJce extends MediaField
{
/**
* The form field type.
*
* @var string
*/
protected $type = 'MediaJce';
/**
* Layout to render
*
* @var string
* @since 3.5
*/
protected $layout = 'joomla.form.field.media';
/**
* Method to attach a JForm object to the field.
*
* @param SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
*
* @return boolean True on success.
*
* @see JFormField::setup()
*/
public function setup(SimpleXMLElement $element, $value, $group = null)
{
// decode value if it is a string
if (is_string($value)) {
$json = json_decode($value, true);
if ($json) {
$value = isset($json['media_src']) ? $json['media_src'] : $value;
}
} elseif (is_array($value)) {
$value = isset($value['media_src']) ? $value['media_src'] : '';
}
$result = parent::setup($element, $value, $group);
if ($result === true) {
$this->mediatype = isset($this->element['mediatype']) ? (string) $this->element['mediatype'] : 'images';
if (isset($this->types)) {
$this->value = MediaHelper::getCleanMediaFieldValue($this->value);
}
}
return $result;
}
/**
* Get the data that is going to be passed to the layout
*
* @return array
*/
public function getLayoutData()
{
// component must be installed and enabled
if (!ComponentHelper::isEnabled('com_jce')) {
return parent::getLayoutData();
}
require_once JPATH_ADMINISTRATOR . '/components/com_jce/helpers/browser.php';
$config = array(
'element' => $this->id,
'mediatype' => strtolower($this->mediatype),
'converted' => (int) $this->element['converted'] ? true : false
);
$options = WFBrowserHelper::getMediaFieldOptions($config);
$this->link = $options['url'];
// Get the basic field data
$data = parent::getLayoutData();
// not a valid file browser link
if (!$this->link) {
return $data;
}
$extraData = array(
'link' => $this->link,
'class' => $this->element['class'] . ' input-medium wf-media-input wf-media-input-active'
);
if ($options['upload'] == 1) {
$extraData['class'] .= ' wf-media-input-upload';
}
// Joomla 4
if (isset($this->types)) {
$mediaData = array(
'imagesAllowedExt' => '',
'audiosAllowedExt' => '',
'videosAllowedExt' => '',
'documentsAllowedExt' => ''
);
$allowable = array('jpg,jpeg,png,gif', 'mp3,m4a,mp4a,ogg', 'mp4,mp4v,mpeg,mov,webm', 'doc,docx,odg,odp,ods,odt,pdf,ppt,pptx,txt,xcf,xls,xlsx,csv', 'zip,tar,gz');
if (!empty($options['accept'])) {
$accept = explode(',', $options['accept']);
array_walk($allowable, function (&$item) use ($accept) {
$items = explode(',', $item);
$values = array_intersect($items, $accept);
$item = empty($values) ? '' : implode(',', $values);
});
}
$mediaMap = array('images', 'audio', 'video', 'documents', 'media', 'files');
// find mediatype value if passed in values is an extension list, eg: pdf,docx
if (!in_array($this->mediatype, $mediaMap)) {
$accept = explode(',', $this->mediatype);
$mediatypes = array();
array_walk($allowable, function (&$item, $key) use ($accept, $mediaMap, &$mediatypes) {
$items = explode(',', $item);
$values = array_intersect($items, $accept);
if (!empty($values)) {
$mediatypes[] = $mediaMap[$key];
$item = implode(',', $values);
}
});
if (count($mediatypes) == 2 && $mediatypes[0] == 'audio' && $mediatypes[1] == 'video') {
$this->mediatype = 'media';
} else if (count($mediatypes) > 1) {
$this->mediatype = 'files';
}
}
$mediaType = [0, 1, 2, 3];
switch ($this->mediatype) {
case 'images':
$mediaType = [0];
$mediaData['imagesAllowedExt'] = $allowable[0];
break;
case 'audio':
$mediaType = [1];
$mediaData['audiosAllowedExt'] = $allowable[1];
break;
case 'video':
$mediaType = [2];
$mediaData['videosAllowedExt'] = $allowable[2];
break;
case 'media':
$mediaType = [1, 2];
$mediaData['audiosAllowedExt'] = $allowable[1];
$mediaData['videosAllowedExt'] = $allowable[2];
break;
case 'documents':
$mediaType = [3];
$mediaData['documentsAllowedExt'] = $allowable[3];
break;
case 'files':
$mediaType = [0, 1, 2, 3];
$mediaData = array(
'imagesAllowedExt' => $allowable[0],
'audiosAllowedExt' => $allowable[1],
'videosAllowedExt' => $allowable[2],
'documentsAllowedExt' => $allowable[3]
);
break;
}
$mediaData['mediaTypes'] = implode(',', $mediaType);
$extraData = array_merge($extraData, $mediaData);
}
return array_merge($data, $extraData);
}
/**
* Method to post-process a field value.
* Remove Joomla 4.2 Media Field parameters
*
* @param mixed $value The optional value to use as the default for the field.
* @param string $group The optional dot-separated form group path on which to find the field.
* @param Registry $input An optional Registry object with the entire data set to filter
* against the entire form.
*
* @return mixed The processed value.
*
* @since 2.9.31
*/
public function postProcess($value, $group = null, Registry $input = null)
{
$value = MediaHelper::getCleanMediaFieldValue($value);
return $value;
}
/**
* Allow to override renderer include paths in child fields
*
* @return array
*
* @since 3.5
*/
protected function getLayoutPaths()
{
if (isset($this->types)) {
return array(JPATH_SITE . '/layouts', JPATH_PLUGINS . '/fields/mediajce/layouts');
}
return parent::getLayoutPaths();
}
}

View File

@@ -0,0 +1,147 @@
<?php
/**
* @package JCE.System
* @subpackage Layout
*
* @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
* @copyright Copyright (C) 2022 Ryan Demmer All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\MediaHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
extract($displayData);
/**
* Layout variables
* -----------------
* @var string $asset The asset text
* @var string $authorField The label text
* @var integer $authorId The author id
* @var string $class The class text
* @var boolean $disabled True if field is disabled
* @var string $folder The folder text
* @var string $id The label text
* @var string $link The link text
* @var string $name The name text
* @var string $preview The preview image relative path
* @var integer $previewHeight The image preview height
* @var integer $previewWidth The image preview width
* @var string $onchange The onchange text
* @var boolean $readonly True if field is readonly
* @var integer $size The size text
* @var string $value The value text
* @var string $src The path and filename of the image
* @var array $mediaTypes The supported media types for the Media Manager
* @var array $imagesExt The supported extensions for images
* @var array $audiosExt The supported extensions for audios
* @var array $videosExt The supported extensions for videos
* @var array $documentsExt The supported extensions for documents
* @var string $dataAttribute Miscellaneous data attributes preprocessed for HTML output
* @var array $dataAttributes Miscellaneous data attribute for eg, data-*
*/
$attr = '';
// Initialize some field attributes.
$attr .= !empty($class) ? ' class="form-control field-media-input ' . $class . '"' : ' class="form-control field-media-input"';
$attr .= !empty($size) ? ' size="' . $size . '"' : '';
$attr .= $dataAttribute;
// Initialize JavaScript field attributes.
$attr .= !empty($onchange) ? ' onchange="' . $onchange . '"' : '';
switch ($preview) {
case 'false':
$showPreview = false;
break;
case 'true':
default:
$showPreview = true;
break;
}
// clean up image src
if (MediaHelper::isImage($value)) {
$value = MediaHelper::getCleanMediaFieldValue($value);
}
// Pre fill the contents of the popover
if ($showPreview) {
$cleanValue = MediaHelper::getCleanMediaFieldValue($value);
if ($cleanValue && file_exists(JPATH_ROOT . '/' . $cleanValue)) {
$src = Uri::root() . $value;
} else {
$src = '';
}
$width = $previewWidth;
$height = $previewHeight;
$style = '';
$style .= ($width > 0) ? 'max-width:' . $width . 'px;' : '';
$style .= ($height > 0) ? 'max-height:' . $height . 'px;' : '';
$imgattr = array(
'id' => $id . '_preview',
'class' => 'media-preview',
'style' => $style,
);
$img = HTMLHelper::_('image', $src, Text::_('JLIB_FORM_MEDIA_PREVIEW_ALT'), $imgattr);
$previewImg = '<div id="' . $id . '_preview_img">' . $img . '<span class="field-media-preview-icon"></span></div>';
$showPreview = 'static';
}
// The url for the modal
$url = $readonly ? '' : $link;
// Correctly route the url to ensure it's correctly using sef modes and subfolders
$url = Route::_($url);
$doc = Factory::getDocument();
$wam = $doc->getWebAssetManager();
$modalHTML = HTMLHelper::_(
'bootstrap.renderModal',
'imageModal_' . $id,
[
'url' => $url,
'title' => '&nbsp;',
'closeButton' => true,
'height' => '100%',
'width' => '100%',
'modalWidth' => '80',
'bodyHeight' => '60',
'footer' => '',
]
);
// only load media field stylesheet
$wam->useStyle('webcomponent.field-media');
?>
<div class="field-media-wrapper wf-media-wrapper-custom" data-url="<?php echo $url; ?>">
<?php echo $modalHTML; ?>
<?php if ($showPreview) : ?>
<div class="field-media-preview">
<?php echo ' ' . $previewImg; ?>
</div>
<?php endif; ?>
<div class="input-group">
<input type="text" name="<?php echo $name; ?>" id="<?php echo $id; ?>" value="<?php echo htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); ?>" <?php echo $attr; ?>>
<?php if ($disabled != true) : ?>
<button type="button" class="btn btn-success button-select"><?php echo Text::_('JLIB_FORM_BUTTON_SELECT'); ?></button>
<button type="button" class="btn btn-danger button-clear"><span class="icon-times" aria-hidden="true"></span><span class="visually-hidden"><?php echo Text::_('JLIB_FORM_BUTTON_CLEAR'); ?></span></button>
<?php endif; ?>
</div>
</div>

View File

@@ -0,0 +1,111 @@
<?php
/**
* @package JCE.Plugin
* @subpackage Fields.Media_Jce
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @copyright Copyright (C) 2020 Ryan Demmer. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Form\Form;
// use legacy import to support J3.9
JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR);
Form::addFieldPath(__DIR__ . '/fields');
/**
* Fields MediaJce Plugin
*
* @since 2.6.27
*/
class PlgFieldsMediaJce extends FieldsPlugin
{
/**
* Transforms the field into a DOM XML element and appends it as a child on the given parent.
*
* @param stdClass $field The field.
* @param DOMElement $parent The field node parent.
* @param Form $form The form.
*
* @return DOMElement
*
* @since 3.7.0
*/
public function onCustomFieldsPrepareDom($field, DOMElement $parent, Form $form)
{
$fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form);
if (!$fieldNode)
{
return $fieldNode;
}
$fieldParams = clone $this->params;
$fieldParams->merge($field->fieldparams);
// reset from parent
$fieldNode->setAttribute('type', 'mediajce');
if ((int) $fieldParams->get('extendedmedia', 0) == 1) {
$fieldNode->setAttribute('type', 'extendedmedia');
}
return $fieldNode;
}
/**
* Before prepares the field value.
*
* @param string $context The context.
* @param \stdclass $item The item.
* @param \stdclass $field The field.
*
* @return void
*
* @since 3.7.0
*/
public function onCustomFieldsBeforePrepareField($context, $item, $field)
{
// Check if the field should be processed by us
if (!$this->isTypeSupported($field->type))
{
return;
}
// Check if the field value is an old (string) value
$field->value = $this->checkValue($field->value);
$fieldParams = clone $this->params;
$fieldParams->merge($field->fieldparams);
// if extendedmedia is disabled, use restricted media support
if ((int) $fieldParams->get('extendedmedia', 0) == 0) {
$field->value['media_supported'] = array('img', 'a');
}
}
/**
* Before prepares the field value.
*
* @param string $value The value to check.
*
* @return array The checked value
*
* @since 4.0.0
*/
private function checkValue($value)
{
json_decode($value);
if (json_last_error() === JSON_ERROR_NONE)
{
return (array) json_decode($value, true);
}
return array('media_src' => $value, 'media_text' => '');
}
}

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8" ?>
<extension type="plugin" version="3.8" group="fields" method="upgrade">
<name>plg_fields_mediajce</name>
<version>2.9.32</version>
<creationDate>01-11-2022</creationDate>
<author>Ryan Demmer</author>
<authorEmail>info@joomlacontenteditor.net</authorEmail>
<authorUrl>https://www.joomlacontenteditor.net</authorUrl>
<copyright>Copyright (C) 2006 - 2022 Ryan Demmer. All rights reserved</copyright>
<license>GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html</license>
<description>PLG_FIELDS_MEDIAJCE_XML_DESCRIPTION</description>
<files folder="plugins/fields/mediajce">
<filename plugin="mediajce">mediajce.php</filename>
<folder>fields</folder>
<folder>layouts</folder>
<folder>params</folder>
<folder>tmpl</folder>
</files>
<languages folder="administrator/language/en-GB">
<language tag="en-GB">en-GB.plg_fields_mediajce.ini</language>
<language tag="en-GB">en-GB.plg_fields_mediajce.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<!--field
name="extendedmedia"
type="list"
label="PLG_FIELDS_MEDIAJCE_PARAMS_EXTENDEDMEDIA_LABEL"
description="PLG_FIELDS_MEDIAJCE_PARAMS_EXTENDEDMEDIA_DESC"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field-->
<field
name="mediatype"
type="combo"
label="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIATYPE_LABEL"
description="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIATYPE_DESC"
layout="joomla.form.field.list-fancy-select"
>
<option value="images">images</option>
<option value="media">media</option>
<option value="documents">documents</option>
<option value="files">files</option>
</field>
<field
name="media_class"
type="text"
label="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_CLASS_LABEL"
description="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_CLASS_DESC"
/>
<field
name="media_description"
type="text"
label="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_DESCRIPTION_LABEL"
description="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_DESCRIPTION_DESC"
/>
</fieldset>
</fields>
</config>
</extension>

View File

@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="fieldparams">
<fieldset name="fieldparams">
<!--field
name="extendedmedia"
type="list"
label="PLG_FIELDS_MEDIAJCE_PARAMS_EXTENDEDMEDIA_LABEL"
description="PLG_FIELDS_MEDIAJCE_PARAMS_EXTENDEDMEDIA_DESC"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field-->
<field
name="mediatype"
type="combo"
label="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIATYPE_LABEL"
description="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIATYPE_DESC"
>
<option value="images">images</option>
<option value="media">media</option>
<option value="documents">documents</option>
<option value="files">files</option>
</field>
<field
name="media_class"
type="text"
label="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_CLASS_LABEL"
description="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_CLASS_DESC"
/>
<field
name="media_description"
type="text"
label="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_DESCRIPTION_LABEL"
description="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_DESCRIPTION_DESC"
/>
<field
name="media_target"
type="list"
default=""
label="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_LABEL"
description="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_DESC"
showon="mediatype!:images"
>
<option value=""></option>
<option value="_blank">PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_BLANK</option>
<option value="_self">PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_SELF</option>
<option value="_parent">PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_PARENT</option>
<option value="_top">PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_TOP</option>
<option value="download">PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_TARGET_DOWNLOAD</option>
</field>
<!--field
name="media_caption_class"
type="text"
label="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_CAPTION_CLASS_LABEL"
description="PLG_FIELDS_MEDIAJCE_PARAMS_MEDIA_CAPTION_CLASS_DESC"
showon="extendedmedia:1"
/-->
</fieldset>
</fields>
</form>

View File

@@ -0,0 +1,189 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Fields.MediaJce
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @copyright Copyright (C) 2020 Ryan Demmer. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Filesystem\Path;
use Joomla\Utilities\ArrayHelper;
use Joomla\CMS\Helper\MediaHelper;
if (empty($field->value) || empty($field->value['media_src']))
{
return;
}
$data = array_merge(array(
'media_src' => '',
'media_text' => '',
'media_type' => (string) $fieldParams->get('mediatype', 'embed'),
'media_target' => (string) $fieldParams->get('media_target', ''),
'media_class' => (string) $fieldParams->get('media_class', ''),
'media_caption' => '',
'media_supported' => array('img', 'video', 'audio', 'iframe', 'a')
), $field->value);
// convert to object
$data = (object) $data;
// convert legacy value
if (isset($data->src)) {
$data->media_src = $data->src;
}
// clean Joomla 4 media stuff
if ($pos = strpos($data->media_src, '#')) {
$data->media_src = substr($data->media_src, 0, $pos);
}
$allowable = array(
'img' => 'jpg,jpeg,png,gif',
'audio' => 'mp3,m4a,mp4a,ogg',
'video' => 'mp4,mp4v,mpeg,mov,webm',
'iframe' => 'doc,docx,odg,odp,ods,odt,pdf,ppt,pptx,txt,xcf,xls,xlsx,csv'
);
// get file extension to determine tag
$extension = File::getExt($data->media_src);
// lowercase
$extension = strtolower($extension);
// get tag from extension
array_walk($allowable, function ($values, $key) use ($extension, &$tag) {
if (in_array($extension, explode(',', $values))) {
$tag = $key;
}
});
// reset media_type as link
if (false == in_array($tag, $data->media_supported)) {
$data->media_type = 'link';
}
// reset tag type
if ($data->media_type == 'link') {
$tag = 'a';
}
$attribs = array();
if ($data->media_class) {
$data->media_class = preg_replace('/[^A-Z0-9_- ]/i', '', $data->media_class);
$attribs['class'] = trim($data->media_class);
}
$text = '';
if ($data->media_text) {
$text = htmlentities($data->media_text, ENT_COMPAT, 'UTF-8', true);
}
switch ($tag) {
case 'a':
default:
$element = '<a href="%s"%s>%s</a>';
break;
case 'img':
$element = '<img src="%s"%s alt="%s" />';
$attribs['width'] = isset($data->media_width) ? $data->media_width : '';
$attribs['height'] = isset($data->media_height) ? $data->media_height : '';
$attribs['loading'] = 'lazy';
break;
case 'audio':
$element = '<audio src="%s"%s></audio>';
$attribs['controls'] = 'controls';
if ($text) {
$attribs['title'] = $text;
}
break;
case 'video':
$element = '<video src="%s"%s></video>';
$attribs['controls'] = 'controls';
$attribs['width'] = isset($data->media_width) ? $data->media_width : '';
$attribs['height'] = isset($data->media_height) ? $data->media_height : '';
if ($text) {
$attribs['title'] = $text;
}
break;
case 'iframe':
$element = '<iframe src="%s"%s></iframe>';
$attribs['frameborder'] = 0;
$attribs['width'] = isset($data->media_width) ? $data->media_width : '100%';
$attribs['height'] = isset($data->media_height) ? $data->media_height : '100%';
$attribs['loading'] = 'lazy';
if ($text) {
$attribs['title'] = $text;
}
break;
}
if ($data->media_type == 'embed' && $data->media_caption) {
$fig_attribs = '';
$caption_class = (string) $fieldParams->get('media_caption_class', '');
if ($caption_class) {
$caption_class = preg_replace('/[^A-Z0-9_- ]/i', '', $caption_class);
$fig_attribs = ' class="' . $caption_class . '"';
}
$element = '<figure' . $fig_attribs . '>' . $element . '<figcaption>' . htmlentities($data->media_caption, ENT_COMPAT, 'UTF-8', true) . '</figcaption></figure>';
}
$buffer = '';
// remove some common characters
$path = preg_replace('#[\+\\\?\#%&<>"\'=\[\]\{\},;@\^\(\)£€$]#', '', $data->media_src);
// trim
$path = trim($path);
// check for valid path after clean
if ($path) {
// clean path
$path = Path::clean($path);
// create full path
$fullpath = JPATH_SITE . '/' . trim($path, '/');
// check path is valid
if (is_file($fullpath)) {
// set text as basename if not an image
if (!$text && $data->media_type == "link") {
$text = basename($path);
if ($data->media_target) {
if ($data->media_target == 'download') {
$attribs['download'] = $path;
} else {
$attribs['target'] = $data->media_target;
}
}
}
$buffer .= sprintf(
$element,
htmlentities($path, ENT_COMPAT, 'UTF-8', true),
ArrayHelper::toString($attribs),
$text
);
}
}
echo $buffer;