joomlajoomla2.5joomla-extensionsjoomla3.2

Joomla! - Load editor-xtd plugin layout from specified file in button's iframe handler


I'm working on a Joomla! 2.5/3.x editor-xtd button and I have a problem loading a layout from file on button click.

I have tried this method:

$link = 'plugins/editors-xtd/myplugin/myplugin.layout.php?name='.$name;

$button = new JObject;
$button->modal = true;
$button->class = 'btn';
$button->link  = $link;
$button->text  = 'Insert something';
$button->name  = 'myplugin';
$button->options = "{handler: 'iframe', size: {x: 500, y: 300}}";

... but the full generated link in admin looks like http://my.local.host/mywebsite/administrator/plugins/editor-xtd/link-etc.. and it doesn't work. I also have tried including JURI::base in my $link, but the administrator path is still loaded.

I'm new in plugin dev with Joomla! and I have search a lot but no solution found.

** I also tried a link like this index.php?folder=plugins.editors-xtd.myplugin&file=myplugin.layout.php&name=$name but still nothing. Is there a workout for this or I'll have to create&use a javascript function to run on button click?


Solution

  • Solution

    Modify link variable like this (if application is admin):

    $link = '../plugins/editors-xtd/myplugin/myplugin.layout.php?name='.$name;
    

    ... and delete button options (this means that file contents will be loaded via ajax inside modal)

    Further more, in myplugin.layout.php we can add a little security check and we can import Joomla! framework library and defines so that we can make use of Joomla! framework in our file (things like language load for eg.) This is my actual header of file:

    <?php
    
    // No direct access
    define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); 
    if( ! IS_AJAX) die;
    
    // Include J!Framework for later use
    define( '_JEXEC', 1 );
    define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../..'));
    define( 'DS', DIRECTORY_SEPARATOR );
    require_once ( JPATH_BASE.DS.'includes'.DS.'defines.php');
    require_once ( JPATH_BASE.DS.'includes'.DS.'framework.php');
    
    //more magic goes here...