first commit

This commit is contained in:
2025-06-17 11:53:18 +02:00
commit 9f0f7ba12b
8804 changed files with 1369176 additions and 0 deletions

View File

@ -0,0 +1,168 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="editors" method="upgrade">
<name>plg_editors_codemirror</name>
<version>6.0.0</version>
<creationDate>28 March 2011</creationDate>
<author>Marijn Haverbeke</author>
<authorEmail>marijnh@gmail.com</authorEmail>
<authorUrl>https://codemirror.net/</authorUrl>
<copyright>Copyright (C) 2014 - 2021 by Marijn Haverbeke &lt;marijnh@gmail.com&gt; and others</copyright>
<license>MIT license: https://codemirror.net/LICENSE</license>
<description>PLG_CODEMIRROR_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Editors\CodeMirror</namespace>
<files>
<folder>layouts</folder>
<folder plugin="codemirror">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_editors_codemirror.ini</language>
<language tag="en-GB">language/en-GB/plg_editors_codemirror.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field
name="lineNumbers"
type="radio"
layout="joomla.form.field.radio.switcher"
label="PLG_CODEMIRROR_FIELD_LINENUMBERS_LABEL"
default="1"
filter="integer"
>
<option value="0">JOFF</option>
<option value="1">JON</option>
</field>
<field
name="codeFolding"
type="radio"
label="PLG_CODEMIRROR_FIELD_CODEFOLDING_LABEL"
layout="joomla.form.field.radio.switcher"
default="1"
filter="integer"
>
<option value="0">JOFF</option>
<option value="1">JON</option>
</field>
<field
name="lineWrapping"
type="radio"
label="PLG_CODEMIRROR_FIELD_LINEWRAPPING_LABEL"
layout="joomla.form.field.radio.switcher"
default="1"
filter="integer"
>
<option value="0">JOFF</option>
<option value="1">JON</option>
</field>
<field
name="activeLine"
type="radio"
label="PLG_CODEMIRROR_FIELD_ACTIVELINE_LABEL"
layout="joomla.form.field.radio.switcher"
default="1"
filter="integer"
>
<option value="0">JOFF</option>
<option value="1">JON</option>
</field>
<field
name="selectionMatches"
type="radio"
layout="joomla.form.field.radio.switcher"
label="PLG_CODEMIRROR_FIELD_SELECTIONMATCHES_LABEL"
default="1"
filter="integer"
>
<option value="0">JOFF</option>
<option value="1">JON</option>
</field>
<field
name="autoCloseBrackets"
type="radio"
layout="joomla.form.field.radio.switcher"
label="PLG_CODEMIRROR_FIELD_AUTOCLOSEBRACKET_LABEL"
default="1"
filter="integer"
>
<option value="0">JOFF</option>
<option value="1">JON</option>
</field>
<field
name="keyMap"
type="list"
label="PLG_CODEMIRROR_FIELD_KEYMAP_LABEL"
description="PLG_CODEMIRROR_FIELD_KEYMAP_DESC"
default=""
validate="options"
>
<option value="">JDEFAULT</option>
<option value="emacs">PLG_CODEMIRROR_FIELD_KEYMAP_EMACS</option>
</field>
<field
name="fullScreen"
type="list"
label="PLG_CODEMIRROR_FIELD_FULLSCREEN_LABEL"
default="F10"
validate="options"
>
<option value="F1">F1</option>
<option value="F2">F2</option>
<option value="F3">F3</option>
<option value="F4">F4</option>
<option value="F5">F5</option>
<option value="F6">F6</option>
<option value="F7">F7</option>
<option value="F8">F8</option>
<option value="F9">F9</option>
<option value="F10">F10</option>
<option value="F11">F11</option>
<option value="F12">F12</option>
</field>
<field
name="fullScreenMod"
type="checkboxes"
label="PLG_CODEMIRROR_FIELD_FULLSCREEN_MOD_LABEL"
>
<option value="Shift">PLG_CODEMIRROR_FIELD_VALUE_FULLSCREEN_MOD_SHIFT</option>
<option value="Cmd">PLG_CODEMIRROR_FIELD_VALUE_FULLSCREEN_MOD_CMD</option>
<option value="Ctrl">PLG_CODEMIRROR_FIELD_VALUE_FULLSCREEN_MOD_CTRL</option>
<option value="Alt">PLG_CODEMIRROR_FIELD_VALUE_FULLSCREEN_MOD_ALT</option>
</field>
</fieldset>
<fieldset name="advanced">
<field
name="customExtensions"
type="subform"
label="PLG_CODEMIRROR_FIELD_CUSTOM_EXTENSIONS_LABEL"
multiple="true"
>
<form>
<field
name="module"
type="text"
label="PLG_CODEMIRROR_FIELD_CUSTOM_EXTENSIONS_MODULE_LABEL"
description="PLG_CODEMIRROR_FIELD_CUSTOM_EXTENSIONS_MODULE_DESCR"
/>
<field
name="methods"
type="text"
label="PLG_CODEMIRROR_FIELD_CUSTOM_EXTENSIONS_METHOD_LABEL"
description="PLG_CODEMIRROR_FIELD_CUSTOM_EXTENSIONS_METHOD_DESCR"
/>
</form>
</field>
</fieldset>
</fields>
</config>
</extension>

View File

@ -0,0 +1,66 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Editors.codemirror
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\Registry\Registry;
extract($displayData);
/**
* Layout variables
*
* @var array $options JS options for editor
* @var Registry $params Plugin parameters
* @var string $id The id of the input
* @var string $name The name of the input
* @var integer $cols Textarea cols attribute
* @var integer $rows Textarea rows attribute
* @var string $content The value
* @var string $buttons Editor XTD buttons
*/
$option = ' options="' . $this->escape(json_encode($options)) . '"';
$style = '';
if ($options->width) {
$style .= 'width:' . $options->width . ';';
}
if ($options->height) {
$style .= 'height:' . $options->height . ';';
}
// Fullscreen combo
$fsCombo = '';
if (empty($options->readOnly)) {
$fskeys = $params->get('fullScreenMod', []);
$fskeys[] = $params->get('fullScreen', 'F10');
$fullScreenCombo = implode('-', $fskeys);
$fsCombo = ' fs-combo=' . $this->escape($fullScreenCombo);
}
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->getRegistry()->addExtensionRegistryFile('plg_editors_codemirror');
$wa->useStyle('plg_editors_codemirror')
->useScript('webcomponent.editor-codemirror');
?>
<joomla-editor-codemirror <?php echo $fsCombo . $option; ?>>
<?php echo '<textarea name="' . $name . '" id="' . $id . '" cols="' . $cols . '" rows="' . $rows . '" style="' . $style . '">' . $content . '</textarea>'; ?>
<?php if ($fsCombo) : ?>
<p class="small float-end">
<?php echo Text::sprintf('PLG_CODEMIRROR_TOGGLE_FULL_SCREEN', $fullScreenCombo); ?>
</p>
<?php endif; ?>
<?php echo $buttons ?? ''; ?>
</joomla-editor-codemirror>

View File

@ -0,0 +1,46 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Editors.codemirror
*
* @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\Editors\CodeMirror\Extension\Codemirror;
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 Codemirror(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('editors', 'codemirror')
);
$plugin->setApplication(Factory::getApplication());
return $plugin;
}
);
}
};

View File

@ -0,0 +1,57 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Editors.codemirror
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Editors\CodeMirror\Extension;
use Joomla\CMS\Event\Editor\EditorSetupEvent;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\SubscriberInterface;
use Joomla\Plugin\Editors\CodeMirror\Provider\CodeMirrorProvider;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* CodeMirror Editor Plugin.
*
* @since 1.6
*/
final class Codemirror extends CMSPlugin implements SubscriberInterface
{
/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since 5.0.0
*/
public static function getSubscribedEvents(): array
{
return ['onEditorSetup' => 'onEditorSetup'];
}
/**
* Register Editor instance
*
* @param EditorSetupEvent $event
*
* @return void
*
* @since 5.0.0
*/
public function onEditorSetup(EditorSetupEvent $event)
{
$this->loadLanguage();
$event->getEditorsRegistry()
->add(new CodeMirrorProvider($this->params, $this->getApplication(), $this->getDispatcher()));
}
}

View File

@ -0,0 +1,165 @@
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Editors\CodeMirror\Provider;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Editor\AbstractEditorProvider;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Uri\Uri;
use Joomla\Event\DispatcherInterface;
use Joomla\Registry\Registry;
/**
* Editor provider class
*
* @since 5.0.0
*/
final class CodeMirrorProvider extends AbstractEditorProvider
{
/**
* A Registry object holding the parameters for the plugin
*
* @var Registry
* @since 5.0.0
*/
protected $params;
/**
* The application object
*
* @var CMSApplicationInterface
*
* @since 5.0.0
*/
protected $application;
/**
* Class constructor
*
* @param Registry $params
* @param CMSApplicationInterface $application
* @param DispatcherInterface $dispatcher
*
* @since 5.0.0
*/
public function __construct(Registry $params, CMSApplicationInterface $application, DispatcherInterface $dispatcher)
{
$this->params = $params;
$this->application = $application;
$this->setDispatcher($dispatcher);
}
/**
* Return Editor name, CMD string.
*
* @return string
* @since 5.0.0
*/
public function getName(): string
{
return 'codemirror';
}
/**
* Gets the editor HTML markup
*
* @param string $name Input name.
* @param string $content The content of the field.
* @param array $attributes Associative array of editor attributes.
* @param array $params Associative array of editor parameters.
*
* @return string The HTML markup of the editor
*
* @since 5.0.0
*/
public function display(string $name, string $content = '', array $attributes = [], array $params = []): string
{
$col = $attributes['col'] ?? '';
$row = $attributes['row'] ?? '';
$width = $attributes['width'] ?? '';
$height = $attributes['height'] ?? '';
$id = $attributes['id'] ?? '';
$buttons = $params['buttons'] ?? true;
$asset = $params['asset'] ?? 0;
$author = $params['author'] ?? 0;
// Must pass the field id to the buttons in this editor.
$buttonsStr = $this->displayButtons($buttons, ['asset' => $asset, 'author' => $author, 'editorId' => $id]);
// Options for the CodeMirror constructor.
$options = new \stdClass();
// Is field readonly?
if (!empty($params['readonly'])) {
$options->readOnly = true;
}
// Only add "px" to width and height if they are not given as a percentage.
$options->width = is_numeric($width) ? $width . 'px' : $width;
$options->height = is_numeric($height) ? $height . 'px' : $height;
$options->lineNumbers = (bool) $this->params->get('lineNumbers', 1);
$options->foldGutter = (bool) $this->params->get('codeFolding', 1);
$options->lineWrapping = (bool) $this->params->get('lineWrapping', 1);
$options->activeLine = (bool) $this->params->get('activeLine', 1);
$options->highlightSelection = (bool) $this->params->get('selectionMatches', 1);
// Load the syntax mode.
$modeAlias = [
'scss' => 'css',
'sass' => 'css',
'less' => 'css',
];
$options->mode = !empty($params['syntax']) ? $params['syntax'] : $this->params->get('syntax', 'html');
$options->mode = $modeAlias[$options->mode] ?? $options->mode;
// Special options for non-tagged modes.
if (!\in_array($options->mode, ['xml', 'html'])) {
// Autogenerate closing brackets.
$options->autoCloseBrackets = (bool) $this->params->get('autoCloseBrackets', 1);
}
// KeyMap settings.
$options->keyMap = $this->params->get('keyMap', '');
// Check for custom extensions
$customExtensions = $this->params->get('customExtensions', []);
$options->customExtensions = [];
if ($customExtensions) {
foreach ($customExtensions as $item) {
$methods = array_filter(array_map('trim', explode(',', $item->methods ?? '')));
if (empty($item->module) || !$methods) {
continue;
}
// Prepend root path if we have a file
$module = str_ends_with($item->module, '.js') ? Uri::root(true) . '/' . $item->module : $item->module;
$options->customExtensions[] = [$module, $methods];
}
}
$displayData = [
'options' => $options,
'params' => $this->params,
'name' => $name,
'id' => $id,
'cols' => $col,
'rows' => $row,
'content' => $content,
'buttons' => $buttonsStr,
];
return LayoutHelper::render('editors.codemirror.codemirror', $displayData, JPATH_PLUGINS . '/editors/codemirror/layouts');
}
}