[PLUGINS] ~maj globale
[lhc/web/www.git] / www / plugins / seo-dev / action / editer_seo.php
1 <?php
2
3 if (!defined('_ECRIRE_INC_VERSION')) {
4 return;
5 }
6
7 /**
8 * @param $objet
9 * @param $id_objet
10 * @param string $prefixe
11 * @return string
12 */
13 function action_editer_seo_dist($objet, $id_objet, $prefixe = '') {
14 include_spip('inc/autoriser');
15 $err = '';
16
17 // si id_article n'est pas un nombre, c'est une creation
18 // mais on verifie qu'on a toutes les donnees qu'il faut.
19 if ($objet
20 and $id_objet
21 and autoriser('modifier', $objet, $id_objet)) {
22 $meta_tags = array('title', 'description', 'author', 'keywords', 'copyright', 'robots');
23
24 $existing = array();
25 $rows = sql_allfetsel('*', 'spip_seo', 'id_objet=' . intval($id_objet) . ' AND objet=' . sql_quote($objet));
26 foreach ($rows as $row) {
27 $existing[$row['meta_name']] = $row['meta_content'];
28 }
29
30 $dels = array();
31 $inss = array();
32 foreach ($meta_tags as $tag) {
33 $value = _request($prefixe.$tag);
34 if (is_null($value) or !strlen($value)) {
35 if (isset($existing[$tag])) {
36 $dels[] = $tag;
37 }
38 } else {
39 if (!isset($existing[$tag])) {
40 $inss[] = array('objet'=>$objet,'id_objet'=>$id_objet,'meta_name'=>$tag,'meta_content'=>$value);
41 } elseif ($value!==$existing[$tag]) {
42 sql_updateq('spip_seo', array('meta_content' => $value), 'id_objet=' . intval($id_objet) . ' AND objet=' . sql_quote($objet).' AND meta_name='.sql_quote($tag));
43 }
44 }
45 if (($value = _request($tag)) && (strlen($value)>0)) {
46 sql_insertq('spip_seo', array('id_objet' => $id_objet, 'objet' => $objet, 'meta_name' => $tag, 'meta_content' => $value));
47 }
48 }
49 if (count($dels)) {
50 sql_delete('spip_seo', 'id_objet=' . intval($id_objet) . ' AND objet=' . sql_quote($objet). ' AND '.sql_in('meta_name', $dels));
51 }
52 if (count($inss)) {
53 sql_insertq_multi('spip_seo', $inss);
54 }
55
56 return '';
57 }
58
59 return 'Erreur : acces interdit';
60 }