This commit is contained in:
AlexBa16
2026-06-08 15:29:52 +02:00
commit 27903eed4a
9931 changed files with 1535659 additions and 0 deletions
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="media-action" method="upgrade">
<name>plg_media-action_crop</name>
<author>Joomla! Project</author>
<creationDate>2017-01</creationDate>
<copyright>(C) 2017 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>4.0.0</version>
<description>PLG_MEDIA-ACTION_CROP_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\MediaAction\Crop</namespace>
<files>
<folder>form</folder>
<folder plugin="crop">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_media-action_crop.ini</language>
<language tag="en-GB">language/en-GB/plg_media-action_crop.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field
name="aspect_ratios"
type="subform"
label="PLG_MEDIA-ACTION_CROP_ASPECT_RATIOS_LABEL"
description="PLG_MEDIA-ACTION_CROP_ASPECT_RATIOS_DESC"
multiple="true"
layout="joomla.form.field.subform.repeatable-table"
default='{"aspect_ratios0":{"label":"1:1","value":"1","group":""},"aspect_ratios1":{"label":"5:4","value":"5/4","group":"landscape"},"aspect_ratios2":{"label":"4:3","value":"4/3","group":"landscape"},"aspect_ratios3":{"label":"3:2","value":"3/2","group":"landscape"},"aspect_ratios4":{"label":"16:9","value":"16/9","group":"landscape"},"aspect_ratios5":{"label":"4:5","value":"4/5","group":"portrait"},"aspect_ratios6":{"label":"3:4","value":"3/4","group":"portrait"},"aspect_ratios7":{"label":"2:3","value":"2/3","group":"portrait"},"aspect_ratios8":{"label":"9:16","value":"9/16","group":"portrait"}}'
>
<form>
<field
name="label"
type="text"
label="PLG_MEDIA-ACTION_CROP_RATIO_LABEL_LABEL"
description="PLG_MEDIA-ACTION_CROP_RATIO_LABEL_DESC"
required="true"
filter="string"
/>
<field
name="value"
type="text"
label="PLG_MEDIA-ACTION_CROP_RATIO_VALUE_LABEL"
description="PLG_MEDIA-ACTION_CROP_RATIO_VALUE_DESC"
required="true"
pattern="([1-9]\d*/[1-9]\d*|[1-9]\d*)"
filter="string"
hint="9/16"
class="input-small"
size="10"
maxlength="10"
/>
<field
name="group"
type="list"
label="PLG_MEDIA-ACTION_CROP_RATIO_GROUP_LABEL"
description="PLG_MEDIA-ACTION_CROP_RATIO_GROUP_DESC"
default=""
>
<option value="">PLG_MEDIA-ACTION_CROP_RATIO_GROUP_NONE</option>
<option value="landscape">PLG_MEDIA-ACTION_CROP_PARAM_LANDSCAPE</option>
<option value="portrait">PLG_MEDIA-ACTION_CROP_PARAM_PORTRAIT</option>
</field>
</form>
</field>
</fieldset>
</fields>
</config>
</extension>
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset name="crop" label="PLG_MEDIA-ACTION_CROP_LABEL">
<field
name="crop_quality"
type="number"
label="PLG_MEDIA-ACTION_CROP_QUALITY"
addonBefore="PLG_MEDIA-ACTION_CROP_QUALITY"
min="1"
max="100"
step="1"
default="80"
filter="integer"
/>
<field
type="spacer"
hr="true"
/>
<field
name="crop_x"
type="text"
label="PLG_MEDIA-ACTION_CROP_PARAM_X"
hiddenLabel="true"
addonBefore="PLG_MEDIA-ACTION_CROP_PARAM_X"
addonAfter="px"
pattern="\d*\.?\d*"
/>
<field
name="crop_y"
type="text"
label="PLG_MEDIA-ACTION_CROP_PARAM_Y"
hiddenLabel="true"
addonBefore="PLG_MEDIA-ACTION_CROP_PARAM_Y"
addonAfter="px"
pattern="\d*\.?\d*"
/>
<field
name="crop_width"
type="text"
label="PLG_MEDIA-ACTION_CROP_PARAM_WIDTH"
hiddenLabel="true"
addonBefore="PLG_MEDIA-ACTION_CROP_PARAM_WIDTH"
addonAfter="px"
pattern="\d*\.?\d*"
/>
<field
name="crop_height"
type="text"
label="PLG_MEDIA-ACTION_CROP_PARAM_HEIGHT"
hiddenLabel="true"
addonBefore="PLG_MEDIA-ACTION_CROP_PARAM_HEIGHT"
addonAfter="px"
pattern="\d*\.?\d*"
/>
<field
name="aspectRatio"
type="groupedlist"
label="PLG_MEDIA-ACTION_CROP_PARAM_ASPECT"
hiddenLabel="true"
class="crop-aspect-ratio-options"
default="10/9"
>
<option class="crop-aspect-ratio-option" value="10/9">PLG_MEDIA-ACTION_CROP_PARAM_DEFAULT_RATIO</option>
<option class="crop-aspect-ratio-option" value="">PLG_MEDIA-ACTION_CROP_PARAM_NO_RATIO</option>
<option class="crop-aspect-ratio-option" value="1">1:1</option>
<group label="PLG_MEDIA-ACTION_CROP_PARAM_LANDSCAPE">
<option class="crop-aspect-ratio-option" value="5/4">5:4</option>
<option class="crop-aspect-ratio-option" value="4/3">4:3</option>
<option class="crop-aspect-ratio-option" value="3/2">3:2</option>
<option class="crop-aspect-ratio-option" value="16/9">16:9</option>
</group>
<group label="PLG_MEDIA-ACTION_CROP_PARAM_PORTRAIT">
<option class="crop-aspect-ratio-option" value="4/5">4:5</option>
<option class="crop-aspect-ratio-option" value="3/4">3:4</option>
<option class="crop-aspect-ratio-option" value="2/3">2:3</option>
<option class="crop-aspect-ratio-option" value="9/16">9:16</option>
</group>
</field>
</fieldset>
</form>
@@ -0,0 +1,44 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Media-Action.crop
*
* @copyright (C) 2023 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\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Plugin\MediaAction\Crop\Extension\Crop;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.4.0
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
$container->lazy(Crop::class, function (Container $container) {
$plugin = new Crop(
(array) PluginHelper::getPlugin('media-action', 'crop')
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
})
);
}
};
@@ -0,0 +1,217 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Media-Action.crop
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\MediaAction\Crop\Extension;
use Joomla\CMS\Application\CMSWebApplicationInterface;
use Joomla\CMS\Form\Form;
use Joomla\Component\Media\Administrator\Plugin\MediaActionPlugin;
use Joomla\Event\SubscriberInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Media Manager Crop Action
*
* @since 4.0.0
*/
final class Crop extends MediaActionPlugin implements SubscriberInterface
{
/**
* The form event. Load additional parameters when available into the field form.
* Override to dynamically inject aspect ratios from plugin settings.
*
* @param Form $form The form
* @param \stdClass $data The data (required by the event interface, not used in this implementation)
*
* @return void
*
* @since 6.1.0
* @note The $data parameter is required by the Joomla event interface but is not used in this method.
*/
public function onContentPrepareForm(Form $form, $data): void
{
// 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);
// Get the aspect ratios from plugin parameters
$aspectRatios = $this->params->get('aspect_ratios');
// Convert to array if needed (handles stdClass from Registry)
if (\is_object($aspectRatios)) {
$aspectRatios = (array) $aspectRatios;
}
// If we have custom aspect ratios, modify the form field
if (!empty($aspectRatios) && \is_array($aspectRatios)) {
$this->injectAspectRatios($form, $aspectRatios);
}
}
}
/**
* Inject custom aspect ratios into the crop form
*
* @param Form $form The form object
* @param array $aspectRatios The aspect ratios from plugin settings
*
* @return void
*
* @since 6.1.0
*/
private function injectAspectRatios(Form $form, array $aspectRatios): void
{
// Get the aspectRatio field (try without group first, then with 'crop' group)
$field = $form->getField('aspectRatio');
if (!$field) {
$field = $form->getField('aspectRatio', 'crop');
}
if (!$field) {
return;
}
// Build new XML for the field with custom options
$xml = new \SimpleXMLElement('<field/>');
$xml->addAttribute('name', 'aspectRatio');
$xml->addAttribute('type', 'groupedlist');
$xml->addAttribute('label', 'PLG_MEDIA-ACTION_CROP_PARAM_ASPECT');
$xml->addAttribute('hiddenLabel', 'true');
$xml->addAttribute('class', 'crop-aspect-ratio-options');
$xml->addAttribute('default', '10/9');
// Add default options
$option = $xml->addChild('option', 'PLG_MEDIA-ACTION_CROP_PARAM_DEFAULT_RATIO');
$option->addAttribute('class', 'crop-aspect-ratio-option');
$option->addAttribute('value', '10/9');
$option = $xml->addChild('option', 'PLG_MEDIA-ACTION_CROP_PARAM_NO_RATIO');
$option->addAttribute('class', 'crop-aspect-ratio-option');
$option->addAttribute('value', '');
// Group ratios by landscape/portrait
$grouped = [
'' => [],
'landscape' => [],
'portrait' => [],
];
foreach ($aspectRatios as $ratio) {
// Convert individual ratio to array if it's an object
$ratio = (array) $ratio;
$label = $ratio['label'] ?? '';
$value = $ratio['value'] ?? '';
$group = strtolower(trim($ratio['group'] ?? ''));
if (empty($label) || $value === '' || $value === null) {
continue;
}
if (!isset($grouped[$group])) {
$grouped[$group] = [];
}
$grouped[$group][] = [
'label' => $label,
'value' => $value,
'group' => $group,
];
}
// Add ungrouped ratios
foreach ($grouped[''] as $ratio) {
$option = $xml->addChild('option', htmlspecialchars($ratio['label'], ENT_XML1, 'UTF-8'));
$option->addAttribute('class', 'crop-aspect-ratio-option');
$option->addAttribute('value', htmlspecialchars($ratio['value'], ENT_XML1, 'UTF-8'));
}
// Add landscape group
if (!empty($grouped['landscape'])) {
$group = $xml->addChild('group');
$group->addAttribute('label', 'PLG_MEDIA-ACTION_CROP_PARAM_LANDSCAPE');
foreach ($grouped['landscape'] as $ratio) {
$option = $group->addChild('option', htmlspecialchars($ratio['label'], ENT_XML1, 'UTF-8'));
$option->addAttribute('class', 'crop-aspect-ratio-option');
$option->addAttribute('value', htmlspecialchars($ratio['value'], ENT_XML1, 'UTF-8'));
}
}
// Add portrait group
if (!empty($grouped['portrait'])) {
$group = $xml->addChild('group');
$group->addAttribute('label', 'PLG_MEDIA-ACTION_CROP_PARAM_PORTRAIT');
foreach ($grouped['portrait'] as $ratio) {
$option = $group->addChild('option', htmlspecialchars($ratio['label'], ENT_XML1, 'UTF-8'));
$option->addAttribute('class', 'crop-aspect-ratio-option');
$option->addAttribute('value', htmlspecialchars($ratio['value'], ENT_XML1, 'UTF-8'));
}
}
// Replace the field in the form
// Try setting in default group first, then 'crop' group
if (!$form->setField($xml, null, true)) {
$form->setField($xml, 'crop', true);
}
}
/**
* Load the javascript files of the plugin.
*
* @return void
*
* @since 4.0.0
*/
protected function loadJs(): void
{
parent::loadJs();
if (!$this->getApplication() instanceof CMSWebApplicationInterface) {
return;
}
$this->getApplication()->getDocument()->getWebAssetManager()->useScript('cropper-module');
}
/**
* Load the CSS files of the plugin.
*
* @return void
*
* @since 4.0.0
*/
protected function loadCss(): void
{
parent::loadCss();
if (!$this->getApplication() instanceof CMSWebApplicationInterface) {
return;
}
$this->getApplication()->getDocument()->getWebAssetManager()->useStyle('cropperjs');
}
}
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset name="resize" label="PLG_MEDIA-ACTION_RESIZE_LABEL">
<field
name="resize_quality"
type="number"
label="PLG_MEDIA-ACTION_RESIZE_QUALITY"
addonBefore="PLG_MEDIA-ACTION_RESIZE_QUALITY"
min="1"
max="100"
step="1"
default="80"
filter="integer"
/>
<field
type="spacer"
hr="true"
/>
<field
name="resize_width"
type="text"
label="PLG_MEDIA-ACTION_RESIZE_PARAM_WIDTH"
hiddenLabel="true"
addonBefore="PLG_MEDIA-ACTION_RESIZE_PARAM_WIDTH"
addonAfter="px"
pattern="\d*\.?\d*"
/>
<field
name="resize_height"
type="text"
label="PLG_MEDIA-ACTION_RESIZE_PARAM_HEIGHT"
hiddenLabel="true"
addonBefore="PLG_MEDIA-ACTION_RESIZE_PARAM_HEIGHT"
addonAfter="px"
pattern="\d*\.?\d*"
/>
</fieldset>
</form>
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="media-action" method="upgrade">
<name>plg_media-action_resize</name>
<author>Joomla! Project</author>
<creationDate>2017-01</creationDate>
<copyright>(C) 2017 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>4.0.0</version>
<description>PLG_MEDIA-ACTION_RESIZE_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\MediaAction\Resize</namespace>
<files>
<folder>form</folder>
<folder plugin="resize">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_media-action_resize.ini</language>
<language tag="en-GB">language/en-GB/plg_media-action_resize.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset
name="batch"
label="PLG_MEDIA-ACTION_RESIZE_BATCH_LABEL"
description="PLG_MEDIA-ACTION_RESIZE_BATCH_DESC"
>
<field
name="batch_width"
type="text"
label="PLG_MEDIA-ACTION_RESIZE_BATCH_MAX_WIDTH_LABEL"
addonAfter="px"
filter="integer"
/>
<field
name="batch_height"
type="text"
label="PLG_MEDIA-ACTION_RESIZE_BATCH_MAX_HEIGHT_LABEL"
addonAfter="px"
filter="integer"
/>
</fieldset>
</fields>
</config>
</extension>
@@ -0,0 +1,44 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Media-Action.resize
*
* @copyright (C) 2023 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\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Plugin\MediaAction\Resize\Extension\Resize;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.4.0
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
$container->lazy(Resize::class, function (Container $container) {
$plugin = new Resize(
(array) PluginHelper::getPlugin('media-action', 'resize')
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
})
);
}
};
@@ -0,0 +1,112 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Media-Action.resize
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\MediaAction\Resize\Extension;
use Joomla\CMS\Event\Model\BeforeSaveEvent;
use Joomla\CMS\Image\Image;
use Joomla\Component\Media\Administrator\Plugin\MediaActionPlugin;
use Joomla\Event\SubscriberInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Media Manager Resize Action
*
* @since 4.0.0
*/
final class Resize extends MediaActionPlugin implements SubscriberInterface
{
/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since 5.2.0
*/
public static function getSubscribedEvents(): array
{
return array_merge(parent::getSubscribedEvents(), [
'onContentBeforeSave' => 'onContentBeforeSave',
]);
}
/**
* The save event.
*
* @param BeforeSaveEvent $event The event instance
*
* @return void
*
* @since 4.0.0
*/
public function onContentBeforeSave(BeforeSaveEvent $event): void
{
$context = $event->getContext();
$item = $event->getItem();
if ($context != 'com_media.file') {
return;
}
if (!$this->params->get('batch_width') && !$this->params->get('batch_height')) {
return;
}
if (!\in_array(strtolower($item->extension), ['jpg', 'jpeg', 'png', 'gif', 'webp', 'avif'])) {
return;
}
if (strtolower($item->extension) === 'avif' && !\function_exists('imageavif')) {
return;
}
$imgObject = new Image(imagecreatefromstring($item->data));
$maxWidth = (int) $this->params->get('batch_width', 0);
$maxHeight = (int) $this->params->get('batch_height', 0);
if (
!(($maxWidth && $imgObject->getWidth() > $maxWidth)
|| ($maxHeight && $imgObject->getHeight() > $maxHeight))
) {
return;
}
$imgObject->resize(
$maxWidth,
$maxHeight,
false,
Image::SCALE_INSIDE
);
switch (strtolower($item->extension)) {
case 'gif':
$type = IMAGETYPE_GIF;
break;
case 'png':
$type = IMAGETYPE_PNG;
break;
case 'avif':
$type = IMAGETYPE_AVIF;
break;
case 'webp':
$type = IMAGETYPE_WEBP;
break;
default:
$type = IMAGETYPE_JPEG;
}
ob_start();
$imgObject->toFile(null, $type);
$item->data = ob_get_clean();
}
}
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset name="rotate" label="PLG_MEDIA-ACTION_ROTATE_LABEL">
<field
name="rotate_quality"
type="number"
label="PLG_MEDIA-ACTION_ROTATE_QUALITY"
addonBefore="PLG_MEDIA-ACTION_ROTATE_QUALITY"
min="1"
max="100"
step="1"
default="80"
filter="integer"
/>
<field
type="spacer"
hr="true"
/>
<field
name="rotate_a"
type="number"
label="PLG_MEDIA-ACTION_ROTATE_PARAM_ANGLE"
min="0"
max="360"
step="1"
default="0"
filter="integer"
/>
<field
name="rotate_distinct"
type="radio"
label="PLG_MEDIA-ACTION_ROTATE_PARAM_BUTTONS"
class="btn-group"
default=""
>
<option value="0">0</option>
<option value="90">90</option>
<option value="180">180</option>
<option value="270">270</option>
</field>
</fieldset>
</form>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="media-action" method="upgrade">
<name>plg_media-action_rotate</name>
<author>Joomla! Project</author>
<creationDate>2017-01</creationDate>
<copyright>(C) 2017 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>4.0.0</version>
<description>PLG_MEDIA-ACTION_ROTATE_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\MediaAction\Rotate</namespace>
<files>
<folder>form</folder>
<folder plugin="rotate">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_media-action_rotate.ini</language>
<language tag="en-GB">language/en-GB/plg_media-action_rotate.sys.ini</language>
</languages>
</extension>
@@ -0,0 +1,44 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Media-Action.rotate
*
* @copyright (C) 2023 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\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Plugin\MediaAction\Rotate\Extension\Rotate;
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.4.0
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
$container->lazy(Rotate::class, function (Container $container) {
$plugin = new Rotate(
(array) PluginHelper::getPlugin('media-action', 'rotate')
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
})
);
}
};
@@ -0,0 +1,27 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Media-Action.rotate
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\MediaAction\Rotate\Extension;
use Joomla\Component\Media\Administrator\Plugin\MediaActionPlugin;
use Joomla\Event\SubscriberInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Media Manager Rotate Action
*
* @since 4.0.0
*/
final class Rotate extends MediaActionPlugin implements SubscriberInterface
{
}