c45ab05473352b8b7d2b12a92f6bd06d62bd5c83
[lhc/web/www.git] / www / plugins / seo-dev / seo_pipelines_ecrire.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_metas_editable($objet) {
17 include_spip('inc/config');
18 if (lire_config('seo/meta_tags/activate', 'off') == 'yes'
19 && lire_config('seo/meta_tags/activate_editing', 'off') == 'yes') {
20 $table_sql = table_objet_sql($objet);
21 if (in_array($table_sql, lire_config('seo/meta_tags/editable_tables', array('spip_articles', 'spip_rubriques')))) {
22 return true;
23 }
24 }
25 return false;
26 }
27 /**
28 * Insertion dans le pipeline afficher_contenu_objet (SPIP)
29 *
30 * Afficher les meta-tags en bas du contenu de l'objet
31 *
32 * @param array $flux
33 * Le contexte du pipeline
34 * @return array $flux
35 * Le contexte du pipeline modifé
36 */
37 function seo_afficher_contenu_objet($flux) {
38 $flux['data'] .= recuperer_fond('prive/objets/seo-metas', array('objet' => $flux['args']['type'], 'id_objet' => $flux['args']['id_objet']));
39 return $flux;
40 }
41
42 /**
43 * Insertion dans le pipeline formulaire_charger
44 *
45 * Charger les valeurs des meta-tags pour la saisie dans l'objet
46 *
47 * @param array $flux
48 * Le contexte du pipeline
49 * @return array $flux
50 * Le contexte du pipeline modifié
51 */
52 function seo_formulaire_charger($flux) {
53 if (strncmp($flux['args']['form'], 'editer_', 7) == 0
54 and $objet = substr($flux['args']['form'], 7)
55 and seo_metas_editable($objet)) {
56 $valeurs = array(
57 'meta_title'=>'',
58 'meta_description'=>'',
59 'meta_keywords'=>'',
60 'meta_copyright'=>'',
61 'meta_author'=>'',
62 'meta_robots'=>'',
63 );
64 if ($id_objet = intval($flux['args']['args'][0])) {
65 $metas = sql_select('*', 'spip_seo', 'id_objet ='.intval($id_objet).' AND objet ='.sql_quote($objet));
66 while ($meta = sql_fetch($metas)) {
67 $valeurs['meta_'.$meta['meta_name']] = $meta['meta_content'];
68 }
69 }
70 $flux['data'] = array_merge($flux['data'], $valeurs);
71 }
72 return $flux;
73 }
74
75 /**
76 * Enregistrer les valeurs des meta-tags apres la saisie dans l'objet
77 * @param array $flux
78 * @return array
79 */
80 function seo_formulaire_traiter($flux) {
81 if (strncmp($flux['args']['form'], 'editer_', 7) == 0
82 and $objet = substr($flux['args']['form'], 7)
83 and _request('seo_metas')
84 and $id_table_objet=id_table_objet($objet)
85 and isset($flux['data'][$id_table_objet])
86 and $id_objet=$flux['data'][$id_table_objet]) {
87 $editer_seo = charger_fonction('editer_seo', 'action');
88 $err = $editer_seo($objet, $id_objet, 'meta_');
89
90 if ($err) {
91 if (!isset($flux['data']['message_erreur'])) {
92 $flux['data']['message_erreur'] = '';
93 }
94 $flux['data']['message_erreur'] .= ' ' ._L('Vous n\'avez pas le droit de modifier les meta-tags : '.$err);
95 if (isset($flux['data']['redirect'])) {
96 unset($flux['data']['redirect']);
97 }
98 }
99 }
100 return $flux;
101 }
102
103
104 /**
105 * Insertion dans le pipeline formulaire_fond (SPIP)
106 *
107 * Ajouter la saisie des meta-tags dans le form de saisie de l'objet
108 *
109 * @param array $flux
110 * Le contexte du pipeline
111 * @return array $flux
112 * Le contexte du pipeline modifié
113 */
114 function seo_formulaire_fond($flux) {
115
116 if (isset($flux['args']['args']['type'])
117 and $objet = $flux['args']['args']['type']
118 and $flux['args']['form']=="editer_$objet"
119 and seo_metas_editable($objet)) {
120 $ins = recuperer_fond('formulaires/inc-editer-seo', $flux['args']['contexte']);
121 if ($p=strpos($flux['data'], $i = '<!--extra-->')
122 or $p=strrpos($flux['data'], $i = '</ul>')) {
123 $p = $p + strlen($i);
124 $flux['data'] = substr_replace($flux['data'], $ins, $p, 0);
125 }
126 }
127 return $flux;
128 }