Coding with SPIP 2.1
SPIP 2.1 Technical Documentation

> > > > pre_liens

pre_liens

The "pre_liens" pipeline is used to process typographical shortcuts relating to links of the form[title->url]. It is called by the expanser_liens() (expand_link) function, which is itself called by the propre() function.

  1. $texte = pipeline('pre_liens', $texte);

SPIP itself makes use of this entry point to execute processes that include 3 functions in the definition of the pipeline in the ecrire/inc_version.php file, defined within ecrire/inc/lien.php :

  • traiter_raccourci_liens automatically generates links for a piece of text that looks like a URL,
  • traiter_raccourci_glossaire generates [?title] shortcuts pointing to a glossary.
  • traiter_raccourci_ancre takes care of [<-anchor name] shortcuts that create a named anchor point

Example

The "documentation" plugin (which manages this same documentation), uses this pipeline to automatically add a title attribute on internal link shortcuts of the form [->art30], transforming them into [|art30->art30] (this workaround serves to display the page number relating to the link when exporting the contents of the documentation in PDF format)

  1. function documentation_pre_liens($texte){
  2. // only for the public site
  3. if (test_espace_prive()) return $texte;
  4. $regs = $match = array();
  5. // for each link
  6. if (preg_match_all(_RACCOURCI_LIEN, $texte, $regs, PREG_SET_ORDER)) {
  7. foreach ($regs as $reg) {
  8. // if the shortcut is of the form "art40"
  9. if (preg_match(_RACCOURCI_URL, $reg[4], $match)) {
  10. $title = '|' . $match[1] . $match[2];
  11. // if this title doesn't already exist
  12. if (false === strpos($reg[0], $title)) {
  13. $lien = substr_replace($reg[0], $title, strpos($reg[0], '->'), 0);
  14. $texte = str_replace($reg[0], $lien, $texte);
  15. }
  16. }
  17. }
  18. }
  19. return $texte;
  20. }

Download

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