[PLUGINS] +set de base
[lhc/web/www.git] / www / plugins / seo-v1 / pipelines / seo_affichage_final.php
1 <?php
2 /**
3 * BouncingOrange SPIP SEO plugin
4 *
5 * @category SEO
6 * @package SPIP_SEO
7 * @author Pierre ROUSSET (p.rousset@gmail.com)
8 * @copyright Copyright (c) 2009 BouncingOrange (http://www.bouncingorange.com)
9 * @license http://opensource.org/licenses/gpl-2.0.php General Public License (GPL 2.0)
10 */
11
12 if (!defined("_ECRIRE_INC_VERSION")) return;
13
14 /**
15 * Insertion dans le pipeline affichage_final (SPIP)
16 * Remplacement des métas et title dans le <head>
17 * Remplace les métas et title du squelette et celles insérées via insert_head également
18 *
19 * @param string $flux
20 * Le contenu de la page
21 * @return string
22 * Le contenu de la page modifié
23 */
24 function seo_affichage_final($flux){
25 preg_match('/<head>(.*)<\/head>/mis', $flux, $head);
26 $head = isset($head[1]) ? $head[1] : false;
27
28 /**
29 * On n'agit que si on a un head
30 * sinon c'est tout et n'importe quoi
31 */
32 if ($head){
33 /**
34 * Pour lire_config
35 */
36 include_spip('inc/config');
37
38 $forcer_squelette = lire_config('seo/forcer_squelette', 'no');
39 if ($forcer_squelette!='yes')
40 return $flux;
41
42 include_spip('seo_fonctions');
43
44 $meta_tags = calculer_meta_tags();
45
46 foreach ($meta_tags as $key => $value){
47 $meta = generer_meta_tags(array($key => $value));
48 $flux_meta = '';
49 /**
50 * Si le tag est <title>
51 */
52 if ($key=='title')
53 $flux_meta = preg_replace("/(<\s*$key.*?>.*?<\/\s*$key.*?>)/mi", $meta, $flux, 1);
54 /**
55 * Le tag est une <meta>
56 */
57 else
58 $flux_meta = preg_replace("/(<\s*meta\s*name=\"$key\"\s*content=\".*?\".*?>)/mi", $meta, $flux, 1);
59
60 /**
61 * Si $flux == $flux_meta
62 * C'est que _SEO_FORCER_SQUELETTE est placé
63 * On ajoute les metas juste avant </head>
64 */
65 if ($flux==$flux_meta)
66 $flux_meta = str_replace('</head>', "\n" . $meta . "</head>", $flux);
67
68 $flux = $flux_meta;
69 }
70 }
71 return $flux;
72 }
73