affichage_final

This pipeline is called at the time that the contents of a page are being sent back to the visitor’s browser. It accepts a text argument (most commonly the HTML page) that it may edit or add to. The modifications are not stored in the cache by SPIP.

echo pipeline('affichage_final', $page['texte']);

This is a pipeline frequently used by plugins that enable a wide range of actions. Nonetheless, since the results of the pipeline are not stored in the cache, and this pipeline is called for every page displayed, it would be wise to limit its usage to functions that are not too resource intensive.

Example

The "XSPF" plugin, which is used to generate multimedia galleries, adds a JavaScript component only to pages that require it, as shown below:

function xspf_affichage_final($page) {
	// check to see if the page has any "player" class components
	if (strpos($page, 'class="xspf_player"')===FALSE)
		return $page;

	// If so, add the swfobject js
	$jsFile = find_in_path('lib/swfobject/swfobject.js');
	$head = "<script src='$jsFile' type='text/javascript'></script>";
	$pos_head = strpos($page, '</head>');
	return substr_replace($page, $head, $pos_head, 0);
}

The "target" plugin opens external links in a new window, (oh, yes, even if that’s not a terribly popular idea these days!), and so it systematically changes "outward" links so that they have an external target attribute:

function target_affichage_final($texte) {		
	$texte = str_replace('spip_out"', 'spip_out" target="_blank"', $texte);
	$texte = str_replace('rel="directory"', 'rel="directory" class="spip_out" target="_blank"', $texte);
	$texte = str_replace('spip_glossaire"', 'spip_glossaire" target="_blank"', $texte);		
	return $texte;
}

Author Mark Baber Published : Updated : 12/03/23

Translations : English, français