Topic-icon Output system plugin in external file for Mootools Ajax call

Active Subscriptions:

None
I am building an audio component and for social media buttons I'm trying to get it to work with the JFBconnect system plugin.

What I'm trying to accomplish is that when a user clicks on a "Share" button an Ajax call will call an external file containing the JFBconnect plugin tags. The output (Like buttons) have to be shown in a div.

I got the Ajax call right (at least it calls the file and pushes the output to the div)...
window.addEvent('domready', function(){
  $('ajax-replace').addEvent('click', function(event) {
    //prevent the page from changing
    event.stop();
    //make the ajax call, replace text
    var req = new Request.HTML({
      method: 'get',
      url: 'components/com_cooltracks/assets/lib/social.php?format=raw',
      data: { 'do' : '1' },
      onRequest: function() { alert('Request made. Please wait...'); },
      update: $('message-here'),
      onComplete: function(response) { alert('Request completed successfully.'); $('message-here').setStyle('background','#fffea1');
      }
    }).send();
});


This is the php code in the external file
//init Joomla Framework
define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../..' ));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe = JFactory::getApplication('site');


JPluginHelper::importPlugin('system');
$dispatcher = &JDispatcher::getInstance();
$dispatcher->trigger('onBeforeDisplayContent');
After the php code there is the system tag "{JFBCLike href=http://www.sourcecoast.com layout=standard show_faces=true show_send_button=true width=300 action=like font=verdana colorscheme=light}"

This will output the system tag "{JFBCLike href=http://www.sourcecoast.com…}" and not the actual plugin output.

I've been searching for days to get this to work and with the little info I can find my code should work. I'm hoping someone could shine a light on why it doesn't.
The topic has been locked.
Support Specialist
I'm not sure where the tag is being inserted from the code you mentioned, but I don't think that's important to answer your question. Basically, the {JFBCLike...} tags can be inserted in multiple different ways. The JFBCSystem plugin will then replace them with the proper code in the onAfterRender function. So, I think you may just need to add the following at the bottom of the code you mentioned:
$dispatcher->trigger('onAfterRender');

Hope that helps, but if not, let us know. You may need to help us understand how/where the body response is being sent back to the AJAX call and where the {JFBCLike} tag is being included.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
Thank you very mush for your quick reaction.

There already was a $dispatcher->trigger('onBeforeDisplayContent');
line in my code. I replaced "onBeforeDisplayContent" to "onAfterRender" but that didn't help.

I'll try to be a bit more detailed.

The ajax call script is in my components view tmpl folder, in a sub template file (default_items.php) that get's included by the default.php.

For now I'm just trying to get it to work with one link (triggering the ajax script). The output should be rendered inside a div. The Ajax call java script, link and result container div are all in the same view tmpl file.

If I can get this to work I'm able to finish of the rest. Giving every item in a list it's own social media buttons, called with Ajax only when needed.

I could not post the complete code of the (external) file (social.php) that holds the plugin tag because of the start php and stop php tags. You forum doesn't like them ;-) Below you can find the complete code. I replaced the php tags (smaller then/question mark/"php" and the closing one) tags with "start php" and "end php".

social.php:
start php

//init Joomla Framework
define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../..' ));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe = JFactory::getApplication('site');


JPluginHelper::importPlugin('system');
$dispatcher = &JDispatcher::getInstance();
$dispatcher->trigger('onAfterRender'); 

end php 
 
{JFBCLike href=http://www.sourcecoast.com layout=standard show_faces=true show_send_button=true width=300 action=like font=verdana colorscheme=light}

As you can see the last line of php code is the $dispatcher->trigger line. I already replaced "onBeforeDisplayContent" to "onAfterRender" but, as mentioned, only the {JFBCLike...} tag shows inside result div.
The topic has been locked.