Forums / Cotonti / Core Labs / set metas from standalone plugin

dervan
#8745 2009-02-24 20:18
known problem:
impossible to set metas from standalone plugin

the cause of problem:
header is included and parsed before launching of standalone plugin

possible solution:
header may be included (with pointers technique) after launching of standalone plugin

this solution works without problems in Seditio 121
link (in russian)


code from current system/core/plug/plug.inc.php in trac:
	/* ============= */

	require_once $cfg['system_dir'] . '/header.php';

	$t = new XTemplate($path_skin);

	$extp = array();

	if (is_array($sed_plugins))
	{
		foreach($sed_plugins as $i => $k)
		{
			if ($k['pl_hook']=='standalone' && $k['pl_code']==$e)
			{ $extp[$i] = $k; }
		}
	}

	if (count($extp)==0)
	{
		header("Location: " . SED_ABSOLUTE_URL . sed_url('message', "msg=907", '', true));
		exit;
	}

	if (is_array($extp))
	{ foreach($extp as $k => $pl) { include_once($cfg['plugins_dir'].'/'.$pl['pl_code'].'/'.$pl['pl_file'].'.php'); } }

	if ($autoassigntags)
	{
		$plugin_title = (empty($plugin_title)) ? $L['plu_title'] : $plugin_title;

		if($cfg['homebreadcrumb'])
		{
			$bhome = '<a href="'.$cfg['mainurl'].'">'.sed_cc($cfg['maintitle']).'</a> '.$cfg['separator'].' ';
		}
		else
		{
			$bhome = '';
		}

		$t-> assign(array(
			"PLUGIN_TITLE" => $bhome . '<a href="'.sed_url('plug', "e=$e").'">'.$plugin_title."</a>",
			"PLUGIN_SUBTITLE" => $plugin_subtitle,
			"PLUGIN_BODY" => $plugin_body
		));
	}

	$t->parse("MAIN");
	$t->out("MAIN");

	require_once $cfg['system_dir'] . '/footer.php';


modified code with this solution:
	/* ============= */

	$t_plug = new XTemplate($path_skin);
	$t =& $t_plug;

	$extp = array();

	if (is_array($sed_plugins))
	{
		foreach($sed_plugins as $i => $k)
		{
			if ($k['pl_hook']=='standalone' && $k['pl_code']==$e)
			{ $extp[$i] = $k; }
		}
	}

	if (count($extp)==0)
	{
		header("Location: " . SED_ABSOLUTE_URL . sed_url('message', "msg=907", '', true));
		exit;
	}

	if (is_array($extp))
	{ foreach($extp as $k => $pl) { include_once($cfg['plugins_dir'].'/'.$pl['pl_code'].'/'.$pl['pl_file'].'.php'); } }

	unset($t);
	require_once $cfg['system_dir'] . '/header.php';
	unset($t);
	$t =& $t_plug;

	if ($autoassigntags)
	{
		$plugin_title = (empty($plugin_title)) ? $L['plu_title'] : $plugin_title;

		if($cfg['homebreadcrumb'])
		{
			$bhome = '<a href="'.$cfg['mainurl'].'">'.sed_cc($cfg['maintitle']).'</a> '.$cfg['separator'].' ';
		}
		else
		{
			$bhome = '';
		}

		$t-> assign(array(
			"PLUGIN_TITLE" => $bhome . '<a href="'.sed_url('plug', "e=$e").'">'.$plugin_title."</a>",
			"PLUGIN_SUBTITLE" => $plugin_subtitle,
			"PLUGIN_BODY" => $plugin_body
		));
	}

	$t->parse("MAIN");
	$t->out("MAIN");
	unset($t, $t_plug);

	require_once $cfg['system_dir'] . '/footer.php';