Coding with SPIP 3.0
SPIP3.0 Technical Documentation

> > > > affichage_final

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.

  1. 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:

  1. function xspf_affichage_final($page) {
  2. // check to see if the page has any "player" class components
  3. if (strpos($page, 'class="xspf_player"')===FALSE)
  4. return $page;
  5.  
  6. // If so, add the swfobject js
  7. $jsFile = find_in_path('lib/swfobject/swfobject.js');
  8. $head = "<script src='$jsFile' type='text/javascript'></script>";
  9. $pos_head = strpos($page, '</head>');
  10. return substr_replace($page, $head, $pos_head, 0);
  11. }

Download

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:

  1. function target_affichage_final($texte) {
  2. $texte = str_replace('spip_out"', 'spip_out" target="_blank"', $texte);
  3. $texte = str_replace('rel="directory"', 'rel="directory" class="spip_out" target="_blank"', $texte);
  4. $texte = str_replace('spip_glossaire"', 'spip_glossaire" target="_blank"', $texte);
  5. return $texte;
  6. }

Download

  • Author :
  • Published :
  • Updated : 31/05/10
  • Translations : English, français