first commit
This commit is contained in:
62
plugins/fields/imagelist/imagelist.xml
Normal file
62
plugins/fields/imagelist/imagelist.xml
Normal file
@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="fields" method="upgrade">
|
||||
<name>plg_fields_imagelist</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2016-03</creationDate>
|
||||
<copyright>(C) 2016 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.7.0</version>
|
||||
<description>PLG_FIELDS_IMAGELIST_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Fields\Imagelist</namespace>
|
||||
<files>
|
||||
<folder>params</folder>
|
||||
<folder plugin="imagelist">services</folder>
|
||||
<folder>src</folder>
|
||||
<folder>tmpl</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_fields_imagelist.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_fields_imagelist.sys.ini</language>
|
||||
</languages>
|
||||
<config>
|
||||
<fields name="params">
|
||||
<fieldset name="basic">
|
||||
<field
|
||||
name="directory"
|
||||
type="folderlist"
|
||||
label="PLG_FIELDS_IMAGELIST_PARAMS_DIRECTORY_LABEL"
|
||||
description="PLG_FIELDS_IMAGELIST_PARAMS_DIRECTORY_DESC"
|
||||
directory="images"
|
||||
hide_none="true"
|
||||
hide_default="true"
|
||||
recursive="true"
|
||||
default="/"
|
||||
validate="options"
|
||||
>
|
||||
<option value="/">/</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="multiple"
|
||||
type="radio"
|
||||
label="PLG_FIELDS_IMAGELIST_PARAMS_MULTIPLE_LABEL"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="0"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="image_class"
|
||||
type="textarea"
|
||||
label="PLG_FIELDS_IMAGELIST_PARAMS_IMAGE_CLASS_LABEL"
|
||||
validate="CssIdentifier"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
40
plugins/fields/imagelist/params/imagelist.xml
Normal file
40
plugins/fields/imagelist/params/imagelist.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
<fields name="fieldparams">
|
||||
<fieldset name="fieldparams">
|
||||
<field
|
||||
name="directory"
|
||||
type="folderlist"
|
||||
label="PLG_FIELDS_IMAGELIST_PARAMS_DIRECTORY_LABEL"
|
||||
description="PLG_FIELDS_IMAGELIST_PARAMS_DIRECTORY_DESC"
|
||||
directory="images"
|
||||
hide_none="true"
|
||||
hide_default="true"
|
||||
recursive="true"
|
||||
validate="options"
|
||||
>
|
||||
<option value="">COM_FIELDS_FIELD_USE_GLOBAL</option>
|
||||
<option value="/">/</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="multiple"
|
||||
type="list"
|
||||
label="PLG_FIELDS_IMAGELIST_PARAMS_MULTIPLE_LABEL"
|
||||
filter="integer"
|
||||
validate="options"
|
||||
>
|
||||
<option value="">COM_FIELDS_FIELD_USE_GLOBAL</option>
|
||||
<option value="1">JYES</option>
|
||||
<option value="0">JNO</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="image_class"
|
||||
type="textarea"
|
||||
label="PLG_FIELDS_IMAGELIST_PARAMS_IMAGE_CLASS_LABEL"
|
||||
validate="CssIdentifier"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</form>
|
||||
46
plugins/fields/imagelist/services/provider.php
Normal file
46
plugins/fields/imagelist/services/provider.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Fields.imagelist
|
||||
*
|
||||
* @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\Event\DispatcherInterface;
|
||||
use Joomla\Plugin\Fields\Imagelist\Extension\Imagelist;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$plugin = new Imagelist(
|
||||
$container->get(DispatcherInterface::class),
|
||||
(array) PluginHelper::getPlugin('fields', 'imagelist')
|
||||
);
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
52
plugins/fields/imagelist/src/Extension/Imagelist.php
Normal file
52
plugins/fields/imagelist/src/Extension/Imagelist.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Fields.imagelist
|
||||
*
|
||||
* @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\Fields\Imagelist\Extension;
|
||||
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin;
|
||||
use Joomla\Event\SubscriberInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Fields Imagelist Plugin
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
final class Imagelist extends FieldsPlugin implements SubscriberInterface
|
||||
{
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
$fieldNode->setAttribute('hide_default', 'true');
|
||||
$fieldNode->setAttribute('directory', '/images/' . $fieldNode->getAttribute('directory'));
|
||||
|
||||
return $fieldNode;
|
||||
}
|
||||
}
|
||||
60
plugins/fields/imagelist/tmpl/imagelist.php
Normal file
60
plugins/fields/imagelist/tmpl/imagelist.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Fields.Imagelist
|
||||
*
|
||||
* @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\Image\Image;
|
||||
|
||||
if ($field->value == '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$class = $fieldParams->get('image_class');
|
||||
|
||||
if ($class) {
|
||||
// space before, so if no class sprintf below works
|
||||
$class = ' class="' . htmlentities($class, ENT_COMPAT, 'UTF-8', true) . '"';
|
||||
}
|
||||
|
||||
$value = (array) $field->value;
|
||||
$buffer = '';
|
||||
|
||||
foreach ($value as $path) {
|
||||
if (!$path || $path == '-1') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$imageFilePath = htmlentities($path, ENT_COMPAT, 'UTF-8', true);
|
||||
|
||||
if ($fieldParams->get('directory', '/') !== '/') {
|
||||
$imageInfo = Image::getImageFileProperties(JPATH_ROOT . '/images/' . $fieldParams->get('directory') . '/' . $imageFilePath);
|
||||
|
||||
$buffer .= sprintf(
|
||||
'<img loading="lazy" width="%s" height="%s" src="images/%s/%s"%s alt="">',
|
||||
$imageInfo->width,
|
||||
$imageInfo->height,
|
||||
$fieldParams->get('directory'),
|
||||
$imageFilePath,
|
||||
$class
|
||||
);
|
||||
} else {
|
||||
$imageInfo = Image::getImageFileProperties(JPATH_ROOT . '/images/' . $imageFilePath);
|
||||
|
||||
$buffer .= sprintf(
|
||||
'<img loading="lazy" width="%s" height="%s" src="images/%s"%s>',
|
||||
$imageInfo->width,
|
||||
$imageInfo->height,
|
||||
$imageFilePath,
|
||||
$class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
echo $buffer;
|
||||
Reference in New Issue
Block a user