esedic
2/3/2016 - 6:23 PM

Using JCE system plugin with 3rd party extensions (Seblod example) - part2

Using JCE system plugin with 3rd party extensions (Seblod example) - part2

<?php
// no direct access
defined('JPATH_BASE') or die;

/**
 * Source: https://www.joomlacontenteditor.net/support/forum/using-jce-system-plugin-with-other-extensions
 * I've been looking for an image selector/ manager that can be used within jSeblod for a while,  * luckily your JCE version 2.5.5 
 * came along providing the system plugin. I know this is turned off for extensions due to some conflicts.I would love to see this 
 * being able to be turned on for request pairs, ie. option/ task values. For my use in jSeblod I have created this little plugin.
 */
class plgSystemJceimagemanagerinseblod extends JPlugin
{
    function onAfterRender()
    {
        $app = JFactory::getApplication();
        $jinput = $app->input;

        if ($app->getName() == 'site') {
            return true;
        }

        if ($jinput->get('option') == 'com_cck') {

            $buffer = JResponse::getBody();

            $token = JUtility::getToken();
            $regex = '#(<a[^>]*class="modal btn"[^>]*href="/)(index.php?option=com_media[^"]*fieldid=(\w+))"#ism';
            $replacement = '\\1index.php?option=com_jce&view=editor&layout=plugin&plugin=browser&standalone=1&wf' . $token
                . '=1&filter=images&fieldid=\\3&folder=" rel="{handler: \'iframe\', size: {x: 800, y: 500}}"';
            $buffer = preg_replace( $regex, $replacement, $buffer );

            JResponse::setBody( $buffer );
        }

        return true;
    }
}