Your IP : 216.73.217.68


Current Path : /home/wuectly/www/03cbe/
Upload File :
Current File : /home/wuectly/www/03cbe/PluginTraits.tar

FormTrait.php000060400000006466152455562140007205 0ustar00<?php
/**
 * @package     JCE
 * @subpackage  Fields.MediaJce
 *
 * @copyright   Copyright (C) 2005 - 2023 Open Source Matters, Inc. All rights reserved.
 * @copyright   Copyright (C) 2020 - 2024 Ryan Demmer. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Plugin\Fields\MediaJce\PluginTraits;

defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Uri\Uri;

/**
 * Fields MediaJce FormTrait
 *
 * @since  2.9.73
 */
trait FormTrait
{
    private $mediaLoaded = false;
    
    /**
     * 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;
        }

        if ($field->type !== 'mediajce') {
            return $fieldNode;
        }

        // override "Edit Custom Field Value" permission if set
        $fieldNode->setAttribute('disabled', 'false');

        $fieldParams = clone $this->params;
        $fieldParams->merge($field->fieldparams);

        $field->fieldparams = clone $fieldParams;

        $form->addFieldPath(JPATH_PLUGINS . '/fields/mediajce/fields');

        Factory::getApplication()->triggerEvent('onWfCustomFieldsPrepareDom', array($field, $fieldNode, $form));

        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 ($field->type !== 'mediajce') {
            return;
        }

        // Check if the field value is an old (string) value
        if (is_string($field->value)) {
            $field->value = $this->checkValue($field->value);
        }

        $fieldParams = clone $this->params;
        $fieldParams->merge($field->fieldparams);

        $field->fieldparams = clone $fieldParams;

        // if extendedmedia is disabled, use restricted media support
        if ((int) $fieldParams->get('extendedmedia', 0) == 0 && is_array($field->value)) {
            $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' => '');
    }
}
EventTrait.php000060400000003322152455562140007347 0ustar00<?php
/**
 * @package     JCE
 * @subpackage  Editors.Jce
 *
 * @copyright   Copyright (C) 2005 - 2023 Open Source Matters, Inc. All rights reserved.
 * @copyright   Copyright (c) 2009-2024 Ryan Demmer. All rights reserved
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Plugin\System\Jce\PluginTraits;

use Joomla\CMS\Factory;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Handles the onDisplay event for the JCE editor.
 *
 * @since  2.9.70
 */
trait EventTrait
{
    private function getDummyDispatcher()
    {
        $app = Factory::getApplication();

        if (method_exists($app, 'getDispatcher')) {
            $dispatcher = Factory::getApplication()->getDispatcher();
        } else {
            $dispatcher = JEventDispatcher::getInstance();
        }

        return $dispatcher;
    }

    private function bootCustomPlugin($className, $config = array())
    {
        if (class_exists($className)) {
            $dispatcher = $this->getDummyDispatcher();

            // Instantiate and register the event
            $plugin = new $className($dispatcher, $config);

            if ($plugin instanceof \Joomla\CMS\Extension\PluginInterface) {
                $plugin->registerListeners();
            }
        }
    }

    public function onBeforeWfEditorLoad()
    {
        $path = JPATH_PLUGINS . '/system/jce';

        $items = glob($path . '/templates/*.php');

        foreach ($items as $item) {
            $name = basename($item, '.php');

            $className = 'WfTemplate' . ucfirst($name);

            require_once $item;

            $this->bootCustomPlugin($className);
        }
    }
}
EventsTrait.php000060400000007555152456303460007545 0ustar00<?php
/**
 * @package     JCE
 * @subpackage  Installer.Jce
 *
 * @copyright   Copyright (C) 2005 - 2023 Open Source Matters, Inc. All rights reserved
 * @copyright   Copyright (C) 2023 - 2024 Ryan Demmer. All rights reserved
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Plugin\Installer\Jce\PluginTraits;

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Http\HttpFactory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;

/**
 * JCE Installer Events Trait
 *
 * @since  2.9.73
 */
trait EventsTrait
{
    private function checkIfKeyRequired($query)
    {
        // get the file name from the url without the xml extension
        $file = isset($query['file']) ? $query['file'] : '';

        if (empty($file)) {
            return false;
        }
        
        // jce pro requires a key
        if (strpos($file, 'pkg_jce_pro_') !== false) {
            return true;
        }

        // jce core does not require a key
        if (strpos($file, 'pkg_jce_') !== false) {
            return false;
        }

        // jce plugins require a key
        if (strpos($file, 'plg_jce_') !== false) {
            return true;
        }

        // mediabox does not require a key
        if (strpos($file, 'plg_system_jcemediabox') !== false) {
            return false;
        }

        return false;
    }
    
    /**
     * Handle adding credentials to package download request.
     *
     * @param string $url     url from which package is going to be downloaded
     * @param array  $headers headers to be sent along the download request (key => value format)
     *
     * @return bool true if credentials have been added to request or not our business, false otherwise (credentials not set by user)
     *
     * @since   3.0
     */
    public function onInstallerBeforePackageDownload(&$url, &$headers)
    {
        $app = Factory::getApplication();

        $uri = Uri::getInstance($url);
        $host = $uri->getHost();

        if ($host !== 'www.joomlacontenteditor.net') {
            return true;
        }

        // check if the key has already been set via the dlid field. This will only be available in Joomla 4.x and later
        $key = $uri->getVar('key', '');

        // get the key from the component params or Update Sites (in the case of plugin updates)
        if (empty($key)) {
            $key = $this->getDownloadKey();
        }

        // if no key is set...
        if (empty($key)) {
            $query = $uri->getQuery(true);
            
            // if we are attempting to update JCE Pro or JCE Plugins, display a notice message
            if ($this->checkIfKeyRequired($query) === true) {
                $app->enqueueMessage(Text::_('PLG_INSTALLER_JCE_KEY_WARNING'), 'notice');

                return true;
            }
        }

        // Append the subscription key to the download URL if it exists
        if (!empty($key)) {
            $uri->setVar('key', $key);
        }

        // create the url string
        $url = $uri->toString();

        // check validity of the key and display a message if it is invalid / expired
        try {
            $tmpUri = clone $uri;
            $tmpUri->setVar('task', 'update.validate');

            $tmpUrl = $tmpUri->toString();
            $response = HttpFactory::getHttp()->get($tmpUrl, array());
        } catch (\RuntimeException $exception) {
            $app->enqueueMessage($exception->getMessage(), 'notice');
            return true;
        }

        // invalid key, display a notice message
        if (403 == $response->code || 401 == $response->code) {
            $app->enqueueMessage(Text::_('PLG_INSTALLER_JCE_KEY_INVALID'), 'notice');
        }

        // update limit exceeded
        if (498 === $response->code) {
            $app->enqueueMessage(Text::_('PLG_INSTALLER_JCE_KEY_LIMIT'), 'notice');
        }

        return true;
    }
}DisplayTrait.php000060400000015251152457233430007676 0ustar00<?php
/**
 * @package     JCE
 * @subpackage  Editors.Jce
 *
 * @copyright   Copyright (C) 2005 - 2023 Open Source Matters, Inc. All rights reserved.
 * @copyright   Copyright (c) 2009-2024 Ryan Demmer. All rights reserved
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Plugin\Editors\Jce\PluginTraits;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Editor\Editor;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Plugin\PluginHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Handles the onDisplay event for the JCE editor.
 *
 * @since  3.9.59
 */
trait DisplayTrait
{
    protected static $instances = array();

    protected function getEditorInstance()
    {
        // pass config to WFEditor
        $config = array(
            'profile_id' => $this->params->get('profile_id', 0),
            'plugin' => $this->params->get('plugin', ''),
        );

        $signature = md5(serialize($config));

        if (empty(self::$instances[$signature])) {
            // load base file
            require_once JPATH_ADMINISTRATOR . '/components/com_jce/includes/base.php';

            // create editor
            self::$instances[$signature] = new \WFEditor($config);
        }

        return self::$instances[$signature];
    }

    /**
     * Check that the editor is enabled and has a valid profile
     *
     * @return boolean
     */
    private function isEditorEnabled()
    {
        if (!ComponentHelper::isEnabled('com_jce')) {
            return false;
        }

        $instance = $this->getEditorInstance();

        if ($instance->hasProfile()) {
            return true;
        }

        return false;
    }

    /**
     * Find a fallback editor to load based on the Editor Global Configuration settings.
     * The fallback editor must be enabled.
     * If no editor is available or set, default to "read only" JCE.
     *
     * @return mixed Joomla\CMS\Editor\Editor or boolean false
     */
    private function getFallbackEditor()
    {
        $name = $this->params->get('editor_fallback', '');

        if ($name == '' || $name == 'jce') {
            return false;
        }

        if (!PluginHelper::isEnabled('editors', $name)) {
            return false;
        }

        $ed = Editor::getInstance($name);

        return $ed;
    }

    /**
     * Method to handle the onInit event.
     *  - Initializes the JCE WYSIWYG Editor.

     * @return void
     *
     * @since   1.5
     */
    public function onInit()
    {
        if ($this->isEditorEnabled() === false) {

            $ed = $this->getFallbackEditor();

            if ($ed !== false) {
                $ed->initialise();
                return;
            }
        }

        $language = Factory::getLanguage();
        $document = Factory::getDocument();

        $language->load('com_jce', JPATH_ADMINISTRATOR);

        $editor = $this->getEditorInstance();

        // setup editor without initializing
        $editor->setup(false);

        foreach ($editor->getScripts() as $script => $type) {
            $document->addScript($script, array(), array('type' => $type));
        }

        foreach ($editor->getStyleSheets() as $style) {
            $document->addStylesheet($style);
        }

        $document->addScriptOptions('plg_editor_jce',
            array(
                'editor' => $editor->getScriptOptions(),
            )
        );
    }

    /**
     * JCE WYSIWYG Editor - Display the editor area.
     *
     * @param   string   $name     The name of the editor area.
     * @param   string   $content  The content of the field.
     * @param   string   $width    The width of the editor area.
     * @param   string   $height   The height of the editor area.
     * @param   int      $col      The number of columns for the editor area.
     * @param   int      $row      The number of rows for the editor area.
     * @param   boolean  $buttons  True and the editor buttons will be displayed.
     * @param   string   $id       An optional ID for the textarea. If not supplied the name is used.
     * @param   string   $asset    The object asset
     * @param   object   $author   The author.
     * @param   array    $params   Associative array of editor parameters.
     *
     * @return  string
     */
    public function onDisplay($name, $content, $width = '100%', $height = '500', $col = 20, $row = 4, $buttons = true, $id = null, $asset = null, $author = null, $params = array())
    {
        if ($this->isEditorEnabled() === false) {

            $ed = $this->getFallbackEditor();

            if ($ed !== false) {
                return $ed->display($name, $content, $width, $height, $col, $row, $buttons, $id, $asset, $author, $params);
            }
        }

        if (empty($id)) {
            $id = $name;
        }

        // Only add "px" to width and height if they are not given as a percentage
        if (is_numeric($width)) {
            $width .= 'px';
        }

        // default height value is no longer available in Joomla 6.1
        if (empty($height)) {
            $height = '500';
        }

        if (is_numeric($height)) {
            $height .= 'px';
        }

        if (empty($id)) {
            $id = $name;
        }

        $editor = $this->getEditorInstance();

        // Remove inavlid characters from the ID
        $id = preg_replace('/[^A-Za-z0-9\-_:.]/', '_', $id);

        $buttonsStr = '';

        if ($editor->hasProfile()) {
            if (!$editor->hasPlugin('joomla')) {
                if ((bool) $editor->getParam('editor.xtd_buttons', 1)) {
                    $buttonsStr = $this->displayXtdButtons($id, $buttons, $asset, $author);
                }
            } else {
                $list = $this->getXtdButtonsList($id, $buttons, $asset, $author);

                if (!empty($list)) {
                    $options = array(
                        'joomla_xtd_buttons' => $list,
                    );

                    Factory::getDocument()->addScriptOptions('plg_editor_jce', $options, true);
                }

                $buttonsStr = $this->displayXtdButtons($id, $buttons, $asset, $author, true);
            }
        }

        $displayData = [
            'name' => $name,
            'id' => $id,
            'class' => 'mce_editable wf-editor',
            'cols' => $col,
            'rows' => $row,
            'width' => $width,
            'height' => $height,
            'content' => $content,
            'buttons' => $buttonsStr,
        ];

        // Render Editor markup
        return LayoutHelper::render('editor.jce', $displayData, JPATH_PLUGINS . '/editors/jce/layouts');
    }
}
XTDButtonsTrait.php000060400000010111152457233430010275 0ustar00<?php
/**
 * @package     JCE
 * @subpackage  Editors.Jce
 *
 * @copyright   Copyright (C) 2005 - 2023 Open Source Matters, Inc. All rights reserved.
 * @copyright   Copyright (c) 2009-2024 Ryan Demmer. All rights reserved
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Plugin\Editors\Jce\PluginTraits;

use Joomla\CMS\Factory;
use Joomla\CMS\Editor\Editor;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Uri\Uri;
use Joomla\Event\Event;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

trait XTDButtonsTrait
{
    private function getXtdButtonsList($name, $buttons, $asset, $author)
    {
        $app = Factory::getApplication();
        
        $list = array();

        $excluded = array('readmore', 'pagebreak');

        if (!is_array($buttons)) {
            $buttons = !$buttons ? false : $excluded;
        } else {
            $buttons = array_merge($buttons, $excluded);
        }

        // easiest way to get buttons across versions
        $buttons = Editor::getInstance('jce')->getButtons($name, $buttons);

        if (!empty($buttons)) {
            $list[$name] = array();
            
            foreach ($buttons as $i => $button) {
                if ($button->get('name')) {
                    $id = $name . '_' . $button->name;

                    if (version_compare(JVERSION, '4', 'ge')) {
                        $button->id = $id . '_modal';
                        echo LayoutHelper::render('joomla.editors.buttons.modal', $button);
                    }

                    // create icon class
                    $icon = 'none icon-' . $button->get('icon', $button->get('name'));

                    $options = (array) $button->get('options', array());

                    // set href value
                    if ($button->get('link', '#') == '#') {
                        $link = isset($options['src']) ? $options['src'] : '';
                    } else {
                        $link = Uri::base() . $button->get('link');
                    }

                    // Joomla 5 modal requirements
                    if ($button->get('action', '')) {
                        $options['src']         = $link;
                        $options['textHeader']  = $button->get('text');
                        $options['iconHeader']  = 'icon-' . $icon;
                        $options['popupType']   = $options['popupType'] ?? 'iframe';
                    }

                    $args = array(
                        'name' => $button->get('text'),
                        'id' => $id,
                        'title' => $button->get('text'),
                        'icon' => $icon,
                        'href' => $link,
                        'onclick' => $button->get('onclick', ''),
                        'svg' => $button->get('iconSVG'),
                        'options' => $options,
                        'action' => $button->get('action', '')
                    );

                    $list[$name][] = $args;
                }
            }
        }

        return $list;
    }

    protected function displayXtdButtons($name, $buttons, $asset, $author, $hidden = false)
    {
        // easiest way to get buttons across versions
        $buttons = Editor::getInstance('jce')->getButtons($name, $buttons);

        if (!empty($buttons)) {
            // fix some buttons attributes
            foreach ($buttons as $button) {
                $cls = $button->get('class', '');

                if (empty($cls) || strpos($cls, 'btn') === false) {
                    $cls .= ' btn';
                    $button->set('class', trim($cls));
                }
                
                // set the editor name (Joomla 5) so each modal is unique
                $button->set('editor', $name);

                // hide buttons if required
                if ($hidden) {
                    $button->set('class', 'd-none hidden');
                }
            }

            return LayoutHelper::render('joomla.editors.buttons', $buttons);
        }
    }
}