[PLUGINS] ~maj globale
[lhc/web/www.git] / www / plugins / seo-dev / seo_pipelines.php
1 <?php
2 /**
3 * BouncingOrange SPIP SEO plugin
4 *
5 * @category SEO
6 * @package SPIP\SEO\Pipelines
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')) {
13 return;
14 }
15
16 function seo_autoriser() {
17 }
18
19 function autoriser_seo_bouton_dist($faire, $type, $id, $qui, $opt) {
20 // seul les administrateurs globaux ont acces au bouton de configuration
21 return autoriser('configurer', '_seo');
22 }
23
24 /**
25 * Insertion dans le squelette head/truc de Z si dispo
26 * Remplace/ajoute des metas et title a celles du squelette
27 *
28 * @param string $flux
29 * Le contenu de la page
30 * @return string
31 * Le contenu de la page modifiée
32 */
33 function seo_recuperer_fond($flux) {
34 if (strncmp($flux['args']['fond'], 'head/', 5)==0
35 and strpos($flux['data']['texte'], '<!--seo_insere-->') === false
36 and strpos($flux['data']['texte'], '<title') !== false
37 and include_spip('inc/config')
38 and lire_config('seo/insert_head/activate', 'no') == 'yes'
39 ) {
40 $flux['data']['texte'] = recuperer_fond('inclure/seo-head', array('head' => $flux['data']['texte'], 'contexte' => $flux['args']['contexte']));
41 }
42 return $flux;
43 }
44
45 /**
46 * Insertion dans le pipeline affichage_final (SPIP)
47 * Remplace/ajoute des metas et title a celles du <head>
48 *
49 * @param string $flux
50 * Le contenu de la page
51 * @return string
52 * Le contenu de la page modifiée
53 */
54 function seo_affichage_final($flux) {
55
56 #$t = spip_timer();
57 /**
58 * On n'agit que si on a un head
59 * sinon c'est tout et n'importe quoi
60 */
61 if ($GLOBALS['html']
62 and stripos($flux, '<head>') !== false
63 and strpos($flux, '<!--seo_insere-->') === false
64 and include_spip('inc/config')
65 and lire_config('seo/insert_head/activate', 'no') == 'yes'
66 and ($ps = stripos($flux, '<head>')) !== false
67 and ($pe = stripos($flux, '</head>')) !== false
68 and $pe > $ps
69 and $head = substr($flux, $ps+6, $pe-$ps-6)
70 ) {
71 $head_new = recuperer_fond('inclure/seo-head', array('head' => $head, 'contexte' => $GLOBALS['contexte']));
72 $flux = str_replace($head, $head_new, $flux);
73 }
74 #var_dump(spip_timer());
75 return $flux;
76 }