Code:
static function triggerContentPlugins(&$field, &$item, $method, $view=FLEXI_ITEMVIEW)
{
$debug = false;
static $_plgs_loaded = array();
static $_fields_plgs = array();
static $_initialize = false;
static $_view, $_option, $limitstart;
static $dispatcher, $fcdispatcher;
//$flexiparams = JComponentHelper::getParams('com_flexicontent');
//$print_logging_info = $flexiparams->get('print_logging_info');
// Log content plugin and other performance information
//if ($print_logging_info) global $fc_run_times;
if (!$_initialize) {
// some request and other variables
$_view = JRequest::getVar('view');
$_option = JRequest::getVar('option');
$limitstart = JRequest::getVar('limitstart', 0, '', 'int');
$_initialize = true;
// ***********************************************************************
// We use a custom Dispatcher to allow selective Content Plugin triggering
// ***********************************************************************
require_once (JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'helpers'.DS.'dispatcher.php');
$dispatcher = JDispatcher::getInstance();
$fcdispatcher = FCDispatcher::getInstance_FC($debug);
}
// CASE: FLEXIcontent item view:
// Set triggering 'context' to 'com_content.article', (and also set the 'view' request variable)
if ($view == FLEXI_ITEMVIEW) {
JRequest::setVar('view', 'article');
$context = 'com_content.article';
}
// ALL OTHER CASES: (FLEXIcontent category, FLEXIcontent module, etc),
// Set triggering 'context' to 'com_content.category', (and also set the 'view' request variable)
else {
JRequest::setVar('view', 'category');
$context = 'com_content.category';
}
if ($debug) echo "<br><br>Executing plugins for <b>".$field->name."</b>:<br>";
if ( !@$_fields_plgs[$field->name] )
{
// Make sure the necessary plugin are already loaded, but do not try to load them again since this will harm performance
if (!$field->parameters->get('plugins'))
{
$_plgs = null;
if (!@$_plgs_loaded['__ALL__']) {
JPluginHelper::importPlugin('content', $plugin = null, $autocreate = true, $dispatcher);
$_plgs_loaded['__ALL__'] = 1;
}
}
else
{
$_plgs = $field->parameters->get('plugins');
$_plgs = $_plgs ? $_plgs : array();
$_plgs = is_array($_plgs) ? $_plgs : explode('|', $_plgs); // compatibility because old versions did not JSON encode the parameters
if (!@$_plgs_loaded['__ALL__']) foreach ($_plgs as $_plg) if (!@$_plgs_loaded[$_plg]) {
JPluginHelper::importPlugin('content', $_plg, $autocreate = true, $dispatcher);
$_plgs_loaded[$_plg] = 1;
}
}
$_fields_plgs[$field->name] = $_plgs;
}
$plg_arr = $_fields_plgs[$field->name];
// Suppress some plugins from triggering for compatibility reasons, e.g.
// (a) jcomments, jom_comment_bot plugins, because we will get comments HTML manually inside the template files
$suppress_arr = array('jcomments', 'jom_comment_bot');
FLEXIUtilities::suppressPlugins($suppress_arr, 'suppress' );
// Initialize field for plugin triggering
$method_text = isset($field->{$method}) ? $field->{$method} : '';
$field->text = $method_text;
$field->introtext = $method_text; // needed by some plugins that do not use or clear ->text property
$field->created_by = $item->created_by;
$field->title = $item->title;
$field->slug = isset($item->slug) ? $item->slug : $item->id;
$field->sectionid = !FLEXI_J16GE ? $item->sectionid : false;
$field->catid = $item->catid;
$field->catslug = @$item->categoryslug;
$field->fieldid = $field->id;
$field->id = $item->id;
$field->state = $item->state;
$field->type_id = $item->type_id;
// Set the 'option' to 'com_content' but set a flag 'isflexicontent' to indicate triggering from inside FLEXIcontent ... code
JRequest::setVar('option', 'com_content');
JRequest::setVar("isflexicontent", "yes");
// Trigger content plugins on field's HTML display, as if they were a "joomla article"
if (FLEXI_J16GE) $results = $fcdispatcher->trigger('onContentPrepare', array ($context, &$field, &$item->parameters, $limitstart), $plg_arr);
else $results = $fcdispatcher->trigger('onPrepareContent', array (&$field, &$item->parameters, $limitstart), false, $plg_arr);
// Restore 'view' and 'option' request variables
JRequest::setVar('view', $_view);
JRequest::setVar('option', $_option);
$field->id = $field->fieldid;
$field->{$method} = $field->text;
// Restore suppressed plugins
FLEXIUtilities::suppressPlugins( $suppress_arr,'restore' );
}