Your IP : 216.73.217.68


Current Path : /home/w/u/e/wuectly/www/03cbe/
Upload File :
Current File : /home/w/u/e/wuectly/www/03cbe/PluginTraits.zip

PK�!]z_�mmEventsTrait.phpnu&1i�<?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;
    }
}PK�"]]3K�DisplayTrait.phpnu&1i�<?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');
    }
}
PK�"]\u�{IIXTDButtonsTrait.phpnu&1i�<?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);
        }
    }
}PK�!]z_�mmEventsTrait.phpnu&1i�PK�"]]3K��DisplayTrait.phpnu&1i�PK�"]\u�{II�*XTDButtonsTrait.phpnu&1i�PK�!;