Completed
Push — master ( b5065b...b2f238 )
by cam
01:06
created
ecrire/notifications/instituerarticle.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -11,53 +11,53 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 // Fonction appelee par divers pipelines
18 18
 function notifications_instituerarticle_dist($quoi, $id_article, $options) {
19 19
 
20
-	// ne devrait jamais se produire
21
-	if ($options['statut'] == $options['statut_ancien']) {
22
-		spip_log('statut inchange', 'notifications');
23
-
24
-		return;
25
-	}
26
-
27
-	include_spip('inc/texte');
28
-
29
-	$modele = '';
30
-	if ($options['statut'] == 'publie') {
31
-		if (
32
-			$GLOBALS['meta']['post_dates'] == 'non'
33
-			and strtotime($options['date']) > time()
34
-		) {
35
-			$modele = 'notifications/article_valide';
36
-		} else {
37
-			$modele = 'notifications/article_publie';
38
-		}
39
-	}
40
-
41
-	if ($options['statut'] == 'prop' and $options['statut_ancien'] != 'publie') {
42
-		$modele = 'notifications/article_propose';
43
-	}
44
-
45
-	if ($modele) {
46
-		$destinataires = [];
47
-		if ($GLOBALS['meta']['suivi_edito'] == 'oui') {
48
-			$destinataires = explode(',', $GLOBALS['meta']['adresse_suivi']);
49
-		}
50
-
51
-
52
-		$destinataires = pipeline(
53
-			'notifications_destinataires',
54
-			[
55
-				'args' => ['quoi' => $quoi, 'id' => $id_article, 'options' => $options],
56
-				'data' => $destinataires
57
-			]
58
-		);
59
-
60
-		$texte = email_notification_article($id_article, $modele);
61
-		notifications_envoyer_mails($destinataires, $texte);
62
-	}
20
+    // ne devrait jamais se produire
21
+    if ($options['statut'] == $options['statut_ancien']) {
22
+        spip_log('statut inchange', 'notifications');
23
+
24
+        return;
25
+    }
26
+
27
+    include_spip('inc/texte');
28
+
29
+    $modele = '';
30
+    if ($options['statut'] == 'publie') {
31
+        if (
32
+            $GLOBALS['meta']['post_dates'] == 'non'
33
+            and strtotime($options['date']) > time()
34
+        ) {
35
+            $modele = 'notifications/article_valide';
36
+        } else {
37
+            $modele = 'notifications/article_publie';
38
+        }
39
+    }
40
+
41
+    if ($options['statut'] == 'prop' and $options['statut_ancien'] != 'publie') {
42
+        $modele = 'notifications/article_propose';
43
+    }
44
+
45
+    if ($modele) {
46
+        $destinataires = [];
47
+        if ($GLOBALS['meta']['suivi_edito'] == 'oui') {
48
+            $destinataires = explode(',', $GLOBALS['meta']['adresse_suivi']);
49
+        }
50
+
51
+
52
+        $destinataires = pipeline(
53
+            'notifications_destinataires',
54
+            [
55
+                'args' => ['quoi' => $quoi, 'id' => $id_article, 'options' => $options],
56
+                'data' => $destinataires
57
+            ]
58
+        );
59
+
60
+        $texte = email_notification_article($id_article, $modele);
61
+        notifications_envoyer_mails($destinataires, $texte);
62
+    }
63 63
 }
Please login to merge, or discard this patch.
ecrire/urls/page.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 define('URLS_PAGE_EXEMPLE', 'spip.php?article12');
@@ -29,67 +29,67 @@  discard block
 block discarded – undo
29 29
 
30 30
 function _generer_url_page($type, $id, $args = '', $ancre = '') {
31 31
 
32
-	if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls', true)) {
33
-		$url = $generer_url_externe($id, $args, $ancre);
34
-		if (null != $url) {
35
-			return $url;
36
-		}
37
-	}
32
+    if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls', true)) {
33
+        $url = $generer_url_externe($id, $args, $ancre);
34
+        if (null != $url) {
35
+            return $url;
36
+        }
37
+    }
38 38
 
39
-	$url = \_debut_urls_page . $type . \_debut_urls_page
40
-		. $id . \_debut_urls_page;
39
+    $url = \_debut_urls_page . $type . \_debut_urls_page
40
+        . $id . \_debut_urls_page;
41 41
 
42
-	if ($args) {
43
-		$args = strpos($url, '?') ? "&$args" : "?$args";
44
-	}
42
+    if ($args) {
43
+        $args = strpos($url, '?') ? "&$args" : "?$args";
44
+    }
45 45
 
46
-	return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : '');
46
+    return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : '');
47 47
 }
48 48
 
49 49
 // retrouve le fond et les parametres d'une URL abregee
50 50
 // le contexte deja existant est fourni dans args sous forme de tableau ou query string
51 51
 function urls_page_dist($i, &$entite, $args = '', $ancre = '') {
52
-	if (is_numeric($i)) {
53
-		return _generer_url_page($entite, $i, $args, $ancre);
54
-	}
55
-
56
-	// traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23
57
-	if ($GLOBALS['profondeur_url'] > 0 and $entite == 'sommaire') {
58
-		return [[], '404'];
59
-	}
60
-
61
-	// voir s'il faut recuperer le id_* implicite et les &debut_xx;
62
-	if (is_array($args)) {
63
-		$contexte = $args;
64
-	} else {
65
-		parse_str($args, $contexte);
66
-	}
67
-	include_spip('inc/urls');
68
-	$r = nettoyer_url_page($i, $contexte);
69
-	if ($r) {
70
-		array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici
71
-		return $r;
72
-	}
73
-
74
-	/*
52
+    if (is_numeric($i)) {
53
+        return _generer_url_page($entite, $i, $args, $ancre);
54
+    }
55
+
56
+    // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23
57
+    if ($GLOBALS['profondeur_url'] > 0 and $entite == 'sommaire') {
58
+        return [[], '404'];
59
+    }
60
+
61
+    // voir s'il faut recuperer le id_* implicite et les &debut_xx;
62
+    if (is_array($args)) {
63
+        $contexte = $args;
64
+    } else {
65
+        parse_str($args, $contexte);
66
+    }
67
+    include_spip('inc/urls');
68
+    $r = nettoyer_url_page($i, $contexte);
69
+    if ($r) {
70
+        array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici
71
+        return $r;
72
+    }
73
+
74
+    /*
75 75
 	 * Le bloc qui suit sert a faciliter les transitions depuis
76 76
 	 * le mode 'urls-propres' vers les modes 'urls-standard' et 'url-html'
77 77
 	 * Il est inutile de le recopier si vous personnalisez vos URLs
78 78
 	 * et votre .htaccess
79 79
 	 */
80
-	// Si on est revenu en mode html, mais c'est une ancienne url_propre
81
-	// on ne redirige pas, on assume le nouveau contexte (si possible)
82
-	$url = $i;
83
-	$url_propre = $url ?? $_SERVER['REDIRECT_url_propre'] ?? $_ENV['url_propre'] ?? '';
84
-
85
-	if ($url_propre) {
86
-		if ($GLOBALS['profondeur_url'] <= 0) {
87
-			$urls_anciennes = charger_fonction('propres', 'urls', true);
88
-		} else {
89
-			$urls_anciennes = charger_fonction('arbo', 'urls', true);
90
-		}
91
-
92
-		return $urls_anciennes ? $urls_anciennes($url_propre, $entite, $contexte) : '';
93
-	}
94
-	/* Fin du bloc compatibilite url-propres */
80
+    // Si on est revenu en mode html, mais c'est une ancienne url_propre
81
+    // on ne redirige pas, on assume le nouveau contexte (si possible)
82
+    $url = $i;
83
+    $url_propre = $url ?? $_SERVER['REDIRECT_url_propre'] ?? $_ENV['url_propre'] ?? '';
84
+
85
+    if ($url_propre) {
86
+        if ($GLOBALS['profondeur_url'] <= 0) {
87
+            $urls_anciennes = charger_fonction('propres', 'urls', true);
88
+        } else {
89
+            $urls_anciennes = charger_fonction('arbo', 'urls', true);
90
+        }
91
+
92
+        return $urls_anciennes ? $urls_anciennes($url_propre, $entite, $contexte) : '';
93
+    }
94
+    /* Fin du bloc compatibilite url-propres */
95 95
 }
Please login to merge, or discard this patch.
ecrire/req/sqlite3.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 
@@ -21,18 +21,18 @@  discard block
 block discarded – undo
21 21
 
22 22
 
23 23
 function req_sqlite3_dist($addr, $port, $login, $pass, $db = '', $prefixe = '') {
24
-	return req_sqlite_dist($addr, $port, $login, $pass, $db, $prefixe, $sqlite_version = 3);
24
+    return req_sqlite_dist($addr, $port, $login, $pass, $db, $prefixe, $sqlite_version = 3);
25 25
 }
26 26
 
27 27
 
28 28
 function spip_sqlite3_constantes() {
29
-	if (!defined('SPIP_SQLITE3_ASSOC')) {
30
-		define('SPIP_SQLITE3_ASSOC', PDO::FETCH_ASSOC);
31
-		define('SPIP_SQLITE3_NUM', PDO::FETCH_NUM);
32
-		define('SPIP_SQLITE3_BOTH', PDO::FETCH_BOTH);
33
-	}
29
+    if (!defined('SPIP_SQLITE3_ASSOC')) {
30
+        define('SPIP_SQLITE3_ASSOC', PDO::FETCH_ASSOC);
31
+        define('SPIP_SQLITE3_NUM', PDO::FETCH_NUM);
32
+        define('SPIP_SQLITE3_BOTH', PDO::FETCH_BOTH);
33
+    }
34 34
 }
35 35
 
36 36
 function spip_versions_sqlite3() {
37
-	return _sqlite_charger_version(3) ? 3 : false;
37
+    return _sqlite_charger_version(3) ? 3 : false;
38 38
 }
Please login to merge, or discard this patch.
ecrire/req/pg.exp.php 2 patches
Indentation   +1179 added lines, -1179 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 
24 24
 define('_DEFAULT_DB', 'spip');
@@ -31,159 +31,159 @@  discard block
 block discarded – undo
31 31
 // si ca ne marche toujours pas, echec.
32 32
 
33 33
 function req_pg_dist($addr, $port, $login, $pass, $db = '', $prefixe = '') {
34
-	static $last_connect = [];
35
-	if (!extension_loaded('pgsql')) {
36
-		return false;
37
-	}
38
-
39
-	// si provient de selectdb
40
-	if (empty($addr) && empty($port) && empty($login) && empty($pass)) {
41
-		foreach (['addr', 'port', 'login', 'pass', 'prefixe'] as $a) {
42
-			${$a} = $last_connect[$a];
43
-		}
44
-	}
45
-	[$host, $p] = array_pad(explode(';', $addr), 2, null);
46
-	if ($p > 0) {
47
-		$port = " port=$p";
48
-	} else {
49
-		$port = '';
50
-	}
51
-	$erreurs = [];
52
-	if ($db) {
53
-		@$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW);
54
-	} elseif (!@$link = pg_connect("host=$host$port user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) {
55
-		$erreurs[] = pg_last_error();
56
-		if (@$link = pg_connect("host=$host$port dbname=$login user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) {
57
-			$db = $login;
58
-		} else {
59
-			$erreurs[] = pg_last_error();
60
-			$db = _DEFAULT_DB;
61
-			$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW);
62
-		}
63
-	}
64
-	if (!$link) {
65
-		$erreurs[] = pg_last_error();
66
-		foreach ($erreurs as $e) {
67
-			spip_log('Echec pg_connect. Erreur : ' . $e, 'pg.' . _LOG_HS);
68
-		}
69
-
70
-		return false;
71
-	}
72
-
73
-	if ($link) {
74
-		$last_connect = [
75
-			'addr' => $addr,
76
-			'port' => $port,
77
-			'login' => $login,
78
-			'pass' => $pass,
79
-			'db' => $db,
80
-			'prefixe' => $prefixe,
81
-		];
82
-	}
83
-
84
-	spip_log(
85
-		"Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'),
86
-		'pg.' . _LOG_DEBUG
87
-	);
88
-
89
-	return !$link ? false : [
90
-		'db' => $db,
91
-		'prefixe' => $prefixe ?: $db,
92
-		'link' => $link,
93
-	];
34
+    static $last_connect = [];
35
+    if (!extension_loaded('pgsql')) {
36
+        return false;
37
+    }
38
+
39
+    // si provient de selectdb
40
+    if (empty($addr) && empty($port) && empty($login) && empty($pass)) {
41
+        foreach (['addr', 'port', 'login', 'pass', 'prefixe'] as $a) {
42
+            ${$a} = $last_connect[$a];
43
+        }
44
+    }
45
+    [$host, $p] = array_pad(explode(';', $addr), 2, null);
46
+    if ($p > 0) {
47
+        $port = " port=$p";
48
+    } else {
49
+        $port = '';
50
+    }
51
+    $erreurs = [];
52
+    if ($db) {
53
+        @$link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW);
54
+    } elseif (!@$link = pg_connect("host=$host$port user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) {
55
+        $erreurs[] = pg_last_error();
56
+        if (@$link = pg_connect("host=$host$port dbname=$login user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW)) {
57
+            $db = $login;
58
+        } else {
59
+            $erreurs[] = pg_last_error();
60
+            $db = _DEFAULT_DB;
61
+            $link = pg_connect("host=$host$port dbname=$db user=$login password='$pass'", PGSQL_CONNECT_FORCE_NEW);
62
+        }
63
+    }
64
+    if (!$link) {
65
+        $erreurs[] = pg_last_error();
66
+        foreach ($erreurs as $e) {
67
+            spip_log('Echec pg_connect. Erreur : ' . $e, 'pg.' . _LOG_HS);
68
+        }
69
+
70
+        return false;
71
+    }
72
+
73
+    if ($link) {
74
+        $last_connect = [
75
+            'addr' => $addr,
76
+            'port' => $port,
77
+            'login' => $login,
78
+            'pass' => $pass,
79
+            'db' => $db,
80
+            'prefixe' => $prefixe,
81
+        ];
82
+    }
83
+
84
+    spip_log(
85
+        "Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'),
86
+        'pg.' . _LOG_DEBUG
87
+    );
88
+
89
+    return !$link ? false : [
90
+        'db' => $db,
91
+        'prefixe' => $prefixe ?: $db,
92
+        'link' => $link,
93
+    ];
94 94
 }
95 95
 
96 96
 $GLOBALS['spip_pg_functions_1'] = [
97
-	'alter' => 'spip_pg_alter',
98
-	'count' => 'spip_pg_count',
99
-	'countsel' => 'spip_pg_countsel',
100
-	'create' => 'spip_pg_create',
101
-	'create_base' => 'spip_pg_create_base',
102
-	'create_view' => 'spip_pg_create_view',
103
-	'date_proche' => 'spip_pg_date_proche',
104
-	'delete' => 'spip_pg_delete',
105
-	'drop_table' => 'spip_pg_drop_table',
106
-	'drop_view' => 'spip_pg_drop_view',
107
-	'errno' => 'spip_pg_errno',
108
-	'error' => 'spip_pg_error',
109
-	'explain' => 'spip_pg_explain',
110
-	'fetch' => 'spip_pg_fetch',
111
-	'seek' => 'spip_pg_seek',
112
-	'free' => 'spip_pg_free',
113
-	'hex' => 'spip_pg_hex',
114
-	'in' => 'spip_pg_in',
115
-	'insert' => 'spip_pg_insert',
116
-	'insertq' => 'spip_pg_insertq',
117
-	'insertq_multi' => 'spip_pg_insertq_multi',
118
-	'listdbs' => 'spip_pg_listdbs',
119
-	'multi' => 'spip_pg_multi',
120
-	'optimize' => 'spip_pg_optimize',
121
-	'query' => 'spip_pg_query',
122
-	'quote' => 'spip_pg_quote',
123
-	'replace' => 'spip_pg_replace',
124
-	'replace_multi' => 'spip_pg_replace_multi',
125
-	'select' => 'spip_pg_select',
126
-	'selectdb' => 'spip_pg_selectdb',
127
-	'set_connect_charset' => 'spip_pg_set_connect_charset',
128
-	'showbase' => 'spip_pg_showbase',
129
-	'showtable' => 'spip_pg_showtable',
130
-	'update' => 'spip_pg_update',
131
-	'updateq' => 'spip_pg_updateq',
97
+    'alter' => 'spip_pg_alter',
98
+    'count' => 'spip_pg_count',
99
+    'countsel' => 'spip_pg_countsel',
100
+    'create' => 'spip_pg_create',
101
+    'create_base' => 'spip_pg_create_base',
102
+    'create_view' => 'spip_pg_create_view',
103
+    'date_proche' => 'spip_pg_date_proche',
104
+    'delete' => 'spip_pg_delete',
105
+    'drop_table' => 'spip_pg_drop_table',
106
+    'drop_view' => 'spip_pg_drop_view',
107
+    'errno' => 'spip_pg_errno',
108
+    'error' => 'spip_pg_error',
109
+    'explain' => 'spip_pg_explain',
110
+    'fetch' => 'spip_pg_fetch',
111
+    'seek' => 'spip_pg_seek',
112
+    'free' => 'spip_pg_free',
113
+    'hex' => 'spip_pg_hex',
114
+    'in' => 'spip_pg_in',
115
+    'insert' => 'spip_pg_insert',
116
+    'insertq' => 'spip_pg_insertq',
117
+    'insertq_multi' => 'spip_pg_insertq_multi',
118
+    'listdbs' => 'spip_pg_listdbs',
119
+    'multi' => 'spip_pg_multi',
120
+    'optimize' => 'spip_pg_optimize',
121
+    'query' => 'spip_pg_query',
122
+    'quote' => 'spip_pg_quote',
123
+    'replace' => 'spip_pg_replace',
124
+    'replace_multi' => 'spip_pg_replace_multi',
125
+    'select' => 'spip_pg_select',
126
+    'selectdb' => 'spip_pg_selectdb',
127
+    'set_connect_charset' => 'spip_pg_set_connect_charset',
128
+    'showbase' => 'spip_pg_showbase',
129
+    'showtable' => 'spip_pg_showtable',
130
+    'update' => 'spip_pg_update',
131
+    'updateq' => 'spip_pg_updateq',
132 132
 ];
133 133
 
134 134
 // Par ou ca passe une fois les traductions faites
135 135
 function spip_pg_trace_query($query, $serveur = '') {
136
-	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
137
-	$prefixe = $connexion['prefixe'];
138
-	$link = $connexion['link'];
139
-	$db = $connexion['db'];
140
-
141
-	if (isset($_GET['var_profile'])) {
142
-		include_spip('public/tracer');
143
-		$t = trace_query_start();
144
-		$e = '';
145
-	} else {
146
-		$t = 0;
147
-	}
148
-
149
-	$connexion['last'] = $query;
150
-	$r = spip_pg_query_simple($link, $query);
151
-
152
-	// Log de l'erreur eventuelle
153
-	if ($e = spip_pg_errno($serveur)) {
154
-		$e .= spip_pg_error($query, $serveur);
155
-	} // et du fautif
156
-	return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r;
136
+    $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
137
+    $prefixe = $connexion['prefixe'];
138
+    $link = $connexion['link'];
139
+    $db = $connexion['db'];
140
+
141
+    if (isset($_GET['var_profile'])) {
142
+        include_spip('public/tracer');
143
+        $t = trace_query_start();
144
+        $e = '';
145
+    } else {
146
+        $t = 0;
147
+    }
148
+
149
+    $connexion['last'] = $query;
150
+    $r = spip_pg_query_simple($link, $query);
151
+
152
+    // Log de l'erreur eventuelle
153
+    if ($e = spip_pg_errno($serveur)) {
154
+        $e .= spip_pg_error($query, $serveur);
155
+    } // et du fautif
156
+    return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r;
157 157
 }
158 158
 
159 159
 // Fonction de requete generale quand on est sur que c'est SQL standard.
160 160
 // Elle change juste le noms des tables ($table_prefix) dans le FROM etc
161 161
 
162 162
 function spip_pg_query($query, $serveur = '', $requeter = true) {
163
-	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
164
-	$prefixe = $connexion['prefixe'];
165
-	$link = $connexion['link'];
166
-	$db = $connexion['db'];
167
-
168
-	if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) {
169
-		$suite = strstr($query, (string) $regs[0]);
170
-		$query = substr($query, 0, -strlen($suite));
171
-	} else {
172
-		$suite = '';
173
-	}
174
-	$query = preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite;
175
-
176
-	// renvoyer la requete inerte si demandee
177
-	if (!$requeter) {
178
-		return $query;
179
-	}
180
-
181
-	return spip_pg_trace_query($query, $serveur);
163
+    $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
164
+    $prefixe = $connexion['prefixe'];
165
+    $link = $connexion['link'];
166
+    $db = $connexion['db'];
167
+
168
+    if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) {
169
+        $suite = strstr($query, (string) $regs[0]);
170
+        $query = substr($query, 0, -strlen($suite));
171
+    } else {
172
+        $suite = '';
173
+    }
174
+    $query = preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite;
175
+
176
+    // renvoyer la requete inerte si demandee
177
+    if (!$requeter) {
178
+        return $query;
179
+    }
180
+
181
+    return spip_pg_trace_query($query, $serveur);
182 182
 }
183 183
 
184 184
 function spip_pg_query_simple($link, $query) {
185
-	#spip_log(var_export($query,true), 'pg.'._LOG_DEBUG);
186
-	return pg_query($link, $query);
185
+    #spip_log(var_export($query,true), 'pg.'._LOG_DEBUG);
186
+    return pg_query($link, $query);
187 187
 }
188 188
 
189 189
 /*
@@ -195,196 +195,196 @@  discard block
 block discarded – undo
195 195
  * de requetes showtable intempestives
196 196
  */
197 197
 function spip_pg_ajouter_champs_timestamp($table, $couples, $desc = '', $serveur = '') {
198
-	static $tables = [];
199
-
200
-	if (!isset($tables[$table])) {
201
-		if (!$desc) {
202
-			$trouver_table = charger_fonction('trouver_table', 'base');
203
-			$desc = $trouver_table($table, $serveur);
204
-			// si pas de description, on ne fait rien, ou on die() ?
205
-			if (!$desc) {
206
-				return $couples;
207
-			}
208
-		}
209
-
210
-		// recherche des champs avec simplement 'TIMESTAMP'
211
-		// cependant, il faudra peut etre etendre
212
-		// avec la gestion de DEFAULT et ON UPDATE
213
-		// mais ceux-ci ne sont pas utilises dans le core
214
-		$tables[$table] = [];
215
-		foreach ($desc['field'] as $k => $v) {
216
-			$v = strtolower(ltrim($v));
217
-			// ne pas ajouter de timestamp now() si un default est specifie
218
-			if (strpos($v, 'timestamp') === 0 and strpos($v, 'default') === false) {
219
-				$tables[$table][] = $k;
220
-			}
221
-		}
222
-	}
223
-
224
-	// ajout des champs type 'timestamp' absents
225
-	foreach ($tables[$table] as $maj) {
226
-		if (!array_key_exists($maj, $couples)) {
227
-			$couples[$maj] = 'NOW()';
228
-		}
229
-	}
230
-
231
-	return $couples;
198
+    static $tables = [];
199
+
200
+    if (!isset($tables[$table])) {
201
+        if (!$desc) {
202
+            $trouver_table = charger_fonction('trouver_table', 'base');
203
+            $desc = $trouver_table($table, $serveur);
204
+            // si pas de description, on ne fait rien, ou on die() ?
205
+            if (!$desc) {
206
+                return $couples;
207
+            }
208
+        }
209
+
210
+        // recherche des champs avec simplement 'TIMESTAMP'
211
+        // cependant, il faudra peut etre etendre
212
+        // avec la gestion de DEFAULT et ON UPDATE
213
+        // mais ceux-ci ne sont pas utilises dans le core
214
+        $tables[$table] = [];
215
+        foreach ($desc['field'] as $k => $v) {
216
+            $v = strtolower(ltrim($v));
217
+            // ne pas ajouter de timestamp now() si un default est specifie
218
+            if (strpos($v, 'timestamp') === 0 and strpos($v, 'default') === false) {
219
+                $tables[$table][] = $k;
220
+            }
221
+        }
222
+    }
223
+
224
+    // ajout des champs type 'timestamp' absents
225
+    foreach ($tables[$table] as $maj) {
226
+        if (!array_key_exists($maj, $couples)) {
227
+            $couples[$maj] = 'NOW()';
228
+        }
229
+    }
230
+
231
+    return $couples;
232 232
 }
233 233
 
234 234
 
235 235
 // Alter en PG ne traite pas les index
236 236
 function spip_pg_alter($query, $serveur = '', $requeter = true) {
237
-	// il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB)
238
-	// tout en cassant en deux alter distincts "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"...
239
-	// ou revoir l'api de sql_alter en creant un
240
-	// sql_alter_table($table,array($actions));
241
-	if (!preg_match('/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is', $query, $regs)) {
242
-		spip_log("$query mal comprise", 'pg.' . _LOG_ERREUR);
243
-
244
-		return false;
245
-	}
246
-	$debut = $regs[1];
247
-	$table = $regs[3];
248
-	$suite = $regs[4];
249
-	$todo = explode(',', $suite);
250
-	// on remet les morceaux dechires ensembles... que c'est laid !
251
-	$todo2 = [];
252
-	$i = 0;
253
-	$ouverte = false;
254
-	while ($do = array_shift($todo)) {
255
-		$todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . ',' . $do : $do;
256
-		$o = (false !== strpos($do, '('));
257
-		$f = (false !== strpos($do, ')'));
258
-		if ($o and !$f) {
259
-			$ouverte = true;
260
-		} elseif ($f) {
261
-			$ouverte = false;
262
-		}
263
-		if (!$ouverte) {
264
-			$i++;
265
-		}
266
-	}
267
-	$todo = $todo2;
268
-	$query = $debut . ' ' . array_shift($todo);
269
-
270
-	if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) {
271
-		spip_log("$query incompris", 'pg.' . _LOG_ERREUR);
272
-	} else {
273
-		if ($r[1]) {
274
-			spip_log("j'ignore IGNORE dans $query", 'pg.' . _LOG_AVERTISSEMENT);
275
-		}
276
-		$f = 'spip_pg_alter_' . strtolower($r[3]);
277
-		if (function_exists($f)) {
278
-			$f($r[2], $r[4], $serveur, $requeter);
279
-		} else {
280
-			spip_log("$query non prevu", 'pg.' . _LOG_ERREUR);
281
-		}
282
-	}
283
-	// Alter a plusieurs args. Faudrait optimiser.
284
-	if ($todo) {
285
-		spip_pg_alter("TABLE $table " . join(',', $todo));
286
-	}
237
+    // il faudrait une regexp pour eviter de spliter ADD PRIMARY KEY (colA, colB)
238
+    // tout en cassant en deux alter distincts "ADD PRIMARY KEY (colA, colB), ADD INDEX (chose)"...
239
+    // ou revoir l'api de sql_alter en creant un
240
+    // sql_alter_table($table,array($actions));
241
+    if (!preg_match('/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is', $query, $regs)) {
242
+        spip_log("$query mal comprise", 'pg.' . _LOG_ERREUR);
243
+
244
+        return false;
245
+    }
246
+    $debut = $regs[1];
247
+    $table = $regs[3];
248
+    $suite = $regs[4];
249
+    $todo = explode(',', $suite);
250
+    // on remet les morceaux dechires ensembles... que c'est laid !
251
+    $todo2 = [];
252
+    $i = 0;
253
+    $ouverte = false;
254
+    while ($do = array_shift($todo)) {
255
+        $todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . ',' . $do : $do;
256
+        $o = (false !== strpos($do, '('));
257
+        $f = (false !== strpos($do, ')'));
258
+        if ($o and !$f) {
259
+            $ouverte = true;
260
+        } elseif ($f) {
261
+            $ouverte = false;
262
+        }
263
+        if (!$ouverte) {
264
+            $i++;
265
+        }
266
+    }
267
+    $todo = $todo2;
268
+    $query = $debut . ' ' . array_shift($todo);
269
+
270
+    if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) {
271
+        spip_log("$query incompris", 'pg.' . _LOG_ERREUR);
272
+    } else {
273
+        if ($r[1]) {
274
+            spip_log("j'ignore IGNORE dans $query", 'pg.' . _LOG_AVERTISSEMENT);
275
+        }
276
+        $f = 'spip_pg_alter_' . strtolower($r[3]);
277
+        if (function_exists($f)) {
278
+            $f($r[2], $r[4], $serveur, $requeter);
279
+        } else {
280
+            spip_log("$query non prevu", 'pg.' . _LOG_ERREUR);
281
+        }
282
+    }
283
+    // Alter a plusieurs args. Faudrait optimiser.
284
+    if ($todo) {
285
+        spip_pg_alter("TABLE $table " . join(',', $todo));
286
+    }
287 287
 }
288 288
 
289 289
 function spip_pg_alter_change($table, $arg, $serveur = '', $requeter = true) {
290
-	if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) {
291
-		spip_log("alter change: $arg  incompris", 'pg.' . _LOG_ERREUR);
292
-	} else {
293
-		[, $old, $new, $type, $default, $null, $def2] = $r;
294
-		$actions = ["ALTER $old TYPE " . mysql2pg_type($type)];
295
-		if ($null) {
296
-			$actions[] = "ALTER $old SET NOT NULL";
297
-		} else {
298
-			$actions[] = "ALTER $old DROP NOT NULL";
299
-		}
300
-
301
-		if ($d = ($default ?: $def2)) {
302
-			$actions[] = "ALTER $old SET $d";
303
-		} else {
304
-			$actions[] = "ALTER $old DROP DEFAULT";
305
-		}
306
-
307
-		spip_pg_query("ALTER TABLE $table " . join(', ', $actions));
308
-
309
-		if ($old != $new) {
310
-			spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur);
311
-		}
312
-	}
290
+    if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) {
291
+        spip_log("alter change: $arg  incompris", 'pg.' . _LOG_ERREUR);
292
+    } else {
293
+        [, $old, $new, $type, $default, $null, $def2] = $r;
294
+        $actions = ["ALTER $old TYPE " . mysql2pg_type($type)];
295
+        if ($null) {
296
+            $actions[] = "ALTER $old SET NOT NULL";
297
+        } else {
298
+            $actions[] = "ALTER $old DROP NOT NULL";
299
+        }
300
+
301
+        if ($d = ($default ?: $def2)) {
302
+            $actions[] = "ALTER $old SET $d";
303
+        } else {
304
+            $actions[] = "ALTER $old DROP DEFAULT";
305
+        }
306
+
307
+        spip_pg_query("ALTER TABLE $table " . join(', ', $actions));
308
+
309
+        if ($old != $new) {
310
+            spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur);
311
+        }
312
+    }
313 313
 }
314 314
 
315 315
 function spip_pg_alter_add($table, $arg, $serveur = '', $requeter = true) {
316
-	$nom_index = null;
317
-	if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) {
318
-		spip_log("alter add $arg  incompris", 'pg.' . _LOG_ERREUR);
319
-
320
-		return null;
321
-	}
322
-	if (!$r[1] or $r[1] == 'COLUMN') {
323
-		preg_match('/`?(\w+)`?(.*)/', $r[2], $m);
324
-		if (preg_match('/^(.*)(BEFORE|AFTER|FIRST)(.*)$/is', $m[2], $n)) {
325
-			$m[2] = $n[1];
326
-		}
327
-
328
-		return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter);
329
-	} elseif ($r[1][0] == 'P') {
330
-		// la primary peut etre sur plusieurs champs
331
-		$r[2] = trim(str_replace('`', '', $r[2]));
332
-		$m = ($r[2][0] == '(') ? substr($r[2], 1, -1) : $r[2];
333
-
334
-		return spip_pg_query(
335
-			"ALTER TABLE $table ADD CONSTRAINT $table" . '_pkey PRIMARY KEY (' . $m . ')',
336
-			$serveur,
337
-			$requeter
338
-		);
339
-	} else {
340
-		preg_match('/([^\s,]*)\s*(.*)?/', $r[2], $m);
341
-		// peut etre "(colonne)" ou "nom_index (colonnes)"
342
-		// bug potentiel si qqn met "(colonne, colonne)"
343
-		//
344
-		// nom_index (colonnes)
345
-		if ($m[2]) {
346
-			$colonnes = substr($m[2], 1, -1);
347
-			$nom_index = $m[1];
348
-		} else {
349
-			// (colonne)
350
-			if ($m[1][0] == '(') {
351
-				$colonnes = substr($m[1], 1, -1);
352
-				if (false !== strpos(',', $colonnes)) {
353
-					spip_log('PG : Erreur, impossible de creer un index sur plusieurs colonnes'
354
-						. " sans qu'il ait de nom ($table, ($colonnes))", 'pg.' . _LOG_ERREUR);
355
-				} else {
356
-					$nom_index = $colonnes;
357
-				}
358
-			} // nom_index
359
-			else {
360
-				$nom_index = $colonnes = $m[1];
361
-			}
362
-		}
363
-
364
-		return spip_pg_create_index($nom_index, $table, $colonnes, $serveur, $requeter);
365
-	}
316
+    $nom_index = null;
317
+    if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) {
318
+        spip_log("alter add $arg  incompris", 'pg.' . _LOG_ERREUR);
319
+
320
+        return null;
321
+    }
322
+    if (!$r[1] or $r[1] == 'COLUMN') {
323
+        preg_match('/`?(\w+)`?(.*)/', $r[2], $m);
324
+        if (preg_match('/^(.*)(BEFORE|AFTER|FIRST)(.*)$/is', $m[2], $n)) {
325
+            $m[2] = $n[1];
326
+        }
327
+
328
+        return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter);
329
+    } elseif ($r[1][0] == 'P') {
330
+        // la primary peut etre sur plusieurs champs
331
+        $r[2] = trim(str_replace('`', '', $r[2]));
332
+        $m = ($r[2][0] == '(') ? substr($r[2], 1, -1) : $r[2];
333
+
334
+        return spip_pg_query(
335
+            "ALTER TABLE $table ADD CONSTRAINT $table" . '_pkey PRIMARY KEY (' . $m . ')',
336
+            $serveur,
337
+            $requeter
338
+        );
339
+    } else {
340
+        preg_match('/([^\s,]*)\s*(.*)?/', $r[2], $m);
341
+        // peut etre "(colonne)" ou "nom_index (colonnes)"
342
+        // bug potentiel si qqn met "(colonne, colonne)"
343
+        //
344
+        // nom_index (colonnes)
345
+        if ($m[2]) {
346
+            $colonnes = substr($m[2], 1, -1);
347
+            $nom_index = $m[1];
348
+        } else {
349
+            // (colonne)
350
+            if ($m[1][0] == '(') {
351
+                $colonnes = substr($m[1], 1, -1);
352
+                if (false !== strpos(',', $colonnes)) {
353
+                    spip_log('PG : Erreur, impossible de creer un index sur plusieurs colonnes'
354
+                        . " sans qu'il ait de nom ($table, ($colonnes))", 'pg.' . _LOG_ERREUR);
355
+                } else {
356
+                    $nom_index = $colonnes;
357
+                }
358
+            } // nom_index
359
+            else {
360
+                $nom_index = $colonnes = $m[1];
361
+            }
362
+        }
363
+
364
+        return spip_pg_create_index($nom_index, $table, $colonnes, $serveur, $requeter);
365
+    }
366 366
 }
367 367
 
368 368
 function spip_pg_alter_drop($table, $arg, $serveur = '', $requeter = true) {
369
-	if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) {
370
-		spip_log("alter drop: $arg  incompris", 'pg.' . _LOG_ERREUR);
371
-	} else {
372
-		if (!$r[1] or $r[1] == 'COLUMN') {
373
-			return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur);
374
-		} elseif ($r[1][0] == 'P') {
375
-			return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur);
376
-		} else {
377
-			return spip_pg_query('DROP INDEX ' . $table . '_' . $r[2], $serveur);
378
-		}
379
-	}
369
+    if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) {
370
+        spip_log("alter drop: $arg  incompris", 'pg.' . _LOG_ERREUR);
371
+    } else {
372
+        if (!$r[1] or $r[1] == 'COLUMN') {
373
+            return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur);
374
+        } elseif ($r[1][0] == 'P') {
375
+            return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur);
376
+        } else {
377
+            return spip_pg_query('DROP INDEX ' . $table . '_' . $r[2], $serveur);
378
+        }
379
+    }
380 380
 }
381 381
 
382 382
 function spip_pg_alter_modify($table, $arg, $serveur = '', $requeter = true) {
383
-	if (!preg_match('/^`?(\w+)`?\s+(.*)$/', $arg, $r)) {
384
-		spip_log("alter modify: $arg  incompris", 'pg.' . _LOG_ERREUR);
385
-	} else {
386
-		return spip_pg_alter_change($table, $r[1] . ' ' . $arg, $serveur = '', $requeter = true);
387
-	}
383
+    if (!preg_match('/^`?(\w+)`?\s+(.*)$/', $arg, $r)) {
384
+        spip_log("alter modify: $arg  incompris", 'pg.' . _LOG_ERREUR);
385
+    } else {
386
+        return spip_pg_alter_change($table, $r[1] . ' ' . $arg, $serveur = '', $requeter = true);
387
+    }
388 388
 }
389 389
 
390 390
 // attention (en pg) :
@@ -392,17 +392,17 @@  discard block
 block discarded – undo
392 392
 // - alter table A rename X to Y = changer le nom de la colonne X en Y
393 393
 // pour l'instant, traiter simplement RENAME TO X
394 394
 function spip_pg_alter_rename($table, $arg, $serveur = '', $requeter = true) {
395
-	$rename = '';
396
-	// si TO, mais pas au debut
397
-	if (!stripos($arg, 'TO ')) {
398
-		$rename = $arg;
399
-	} elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) {
400
-		$rename = $r[2];
401
-	} else {
402
-		spip_log("alter rename: $arg  incompris", 'pg.' . _LOG_ERREUR);
403
-	}
404
-
405
-	return $rename ? spip_pg_query("ALTER TABLE $table RENAME TO $rename") : false;
395
+    $rename = '';
396
+    // si TO, mais pas au debut
397
+    if (!stripos($arg, 'TO ')) {
398
+        $rename = $arg;
399
+    } elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) {
400
+        $rename = $r[2];
401
+    } else {
402
+        spip_log("alter rename: $arg  incompris", 'pg.' . _LOG_ERREUR);
403
+    }
404
+
405
+    return $rename ? spip_pg_query("ALTER TABLE $table RENAME TO $rename") : false;
406 406
 }
407 407
 
408 408
 
@@ -418,59 +418,59 @@  discard block
 block discarded – undo
418 418
  * @return bool ou requete
419 419
  */
420 420
 function spip_pg_create_index($nom, $table, $champs, $serveur = '', $requeter = true) {
421
-	if (!($nom or $table or $champs)) {
422
-		spip_log(
423
-			"Champ manquant pour creer un index pg ($nom, $table, (" . @join(',', $champs) . '))',
424
-			'pg.' . _LOG_ERREUR
425
-		);
426
-
427
-		return false;
428
-	}
429
-
430
-	$nom = str_replace('`', '', $nom);
431
-	$champs = str_replace('`', '', $champs);
432
-
433
-	// PG ne differentie pas noms des index en fonction des tables
434
-	// il faut donc creer des noms uniques d'index pour une base pg
435
-	$nom = $table . '_' . $nom;
436
-	// enlever d'eventuelles parentheses deja presentes sur champs
437
-	if (!is_array($champs)) {
438
-		if ($champs[0] == '(') {
439
-			$champs = substr($champs, 1, -1);
440
-		}
441
-		$champs = [$champs];
442
-	}
443
-	$query = "CREATE INDEX $nom ON $table (" . join(',', $champs) . ')';
444
-	if (!$requeter) {
445
-		return $query;
446
-	}
447
-	$res = spip_pg_query($query, $serveur, $requeter);
448
-
449
-	return $res;
421
+    if (!($nom or $table or $champs)) {
422
+        spip_log(
423
+            "Champ manquant pour creer un index pg ($nom, $table, (" . @join(',', $champs) . '))',
424
+            'pg.' . _LOG_ERREUR
425
+        );
426
+
427
+        return false;
428
+    }
429
+
430
+    $nom = str_replace('`', '', $nom);
431
+    $champs = str_replace('`', '', $champs);
432
+
433
+    // PG ne differentie pas noms des index en fonction des tables
434
+    // il faut donc creer des noms uniques d'index pour une base pg
435
+    $nom = $table . '_' . $nom;
436
+    // enlever d'eventuelles parentheses deja presentes sur champs
437
+    if (!is_array($champs)) {
438
+        if ($champs[0] == '(') {
439
+            $champs = substr($champs, 1, -1);
440
+        }
441
+        $champs = [$champs];
442
+    }
443
+    $query = "CREATE INDEX $nom ON $table (" . join(',', $champs) . ')';
444
+    if (!$requeter) {
445
+        return $query;
446
+    }
447
+    $res = spip_pg_query($query, $serveur, $requeter);
448
+
449
+    return $res;
450 450
 }
451 451
 
452 452
 
453 453
 function spip_pg_explain($query, $serveur = '', $requeter = true) {
454
-	if (strpos(ltrim($query), 'SELECT') !== 0) {
455
-		return [];
456
-	}
457
-	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
458
-	$prefixe = $connexion['prefixe'];
459
-	$link = $connexion['link'];
460
-	if (preg_match('/\s(SET|VALUES|WHERE)\s/i', $query, $regs)) {
461
-		$suite = strstr($query, (string) $regs[0]);
462
-		$query = substr($query, 0, -strlen($suite));
463
-	} else {
464
-		$suite = '';
465
-	}
466
-	$query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite;
467
-
468
-	if (!$requeter) {
469
-		return $query;
470
-	}
471
-	$r = spip_pg_query_simple($link, $query);
472
-
473
-	return spip_pg_fetch($r, null, $serveur);
454
+    if (strpos(ltrim($query), 'SELECT') !== 0) {
455
+        return [];
456
+    }
457
+    $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
458
+    $prefixe = $connexion['prefixe'];
459
+    $link = $connexion['link'];
460
+    if (preg_match('/\s(SET|VALUES|WHERE)\s/i', $query, $regs)) {
461
+        $suite = strstr($query, (string) $regs[0]);
462
+        $query = substr($query, 0, -strlen($suite));
463
+    } else {
464
+        $suite = '';
465
+    }
466
+    $query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite;
467
+
468
+    if (!$requeter) {
469
+        return $query;
470
+    }
471
+    $r = spip_pg_query_simple($link, $query);
472
+
473
+    return spip_pg_fetch($r, null, $serveur);
474 474
 }
475 475
 
476 476
 
@@ -489,92 +489,92 @@  discard block
 block discarded – undo
489 489
  *     - False en cas d'erreur.
490 490
  **/
491 491
 function spip_pg_selectdb($db, $serveur = '', $requeter = true) {
492
-	// se connecter a la base indiquee
493
-	// avec les identifiants connus
494
-	$index = $serveur ? strtolower($serveur) : 0;
495
-
496
-	if ($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')) {
497
-		if (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link) {
498
-			return $db;
499
-		}
500
-	} else {
501
-		return false;
502
-	}
492
+    // se connecter a la base indiquee
493
+    // avec les identifiants connus
494
+    $index = $serveur ? strtolower($serveur) : 0;
495
+
496
+    if ($link = spip_connect_db('', '', '', '', $db, 'pg', '', '')) {
497
+        if (($db == $link['db']) && $GLOBALS['connexions'][$index] = $link) {
498
+            return $db;
499
+        }
500
+    } else {
501
+        return false;
502
+    }
503 503
 }
504 504
 
505 505
 // Qu'une seule base pour le moment
506 506
 
507 507
 function spip_pg_listdbs($serveur) {
508
-	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
509
-	$link = $connexion['link'];
510
-	$dbs = [];
511
-	$res = spip_pg_query_simple($link, 'select * From pg_database');
512
-	while ($row = pg_fetch_array($res, null, PGSQL_NUM)) {
513
-		$dbs[] = reset($row);
514
-	}
515
-
516
-	return $dbs;
508
+    $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
509
+    $link = $connexion['link'];
510
+    $dbs = [];
511
+    $res = spip_pg_query_simple($link, 'select * From pg_database');
512
+    while ($row = pg_fetch_array($res, null, PGSQL_NUM)) {
513
+        $dbs[] = reset($row);
514
+    }
515
+
516
+    return $dbs;
517 517
 }
518 518
 
519 519
 function spip_pg_select(
520
-	$select,
521
-	$from,
522
-	$where = '',
523
-	$groupby = [],
524
-	$orderby = '',
525
-	$limit = '',
526
-	$having = '',
527
-	$serveur = '',
528
-	$requeter = true
520
+    $select,
521
+    $from,
522
+    $where = '',
523
+    $groupby = [],
524
+    $orderby = '',
525
+    $limit = '',
526
+    $having = '',
527
+    $serveur = '',
528
+    $requeter = true
529 529
 ) {
530 530
 
531
-	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
532
-	$prefixe = $connexion['prefixe'];
533
-	$link = $connexion['link'];
534
-	$db = $connexion['db'];
535
-
536
-	$limit = preg_match('/^\s*(([0-9]+),)?\s*([0-9]+)\s*$/', $limit, $limatch);
537
-	if ($limit) {
538
-		$offset = $limatch[2];
539
-		$count = $limatch[3];
540
-	}
541
-
542
-	$select = spip_pg_frommysql($select);
543
-
544
-	// si pas de tri explicitement demande, le GROUP BY ne
545
-	// contient que la clef primaire.
546
-	// lui ajouter alors le champ de tri par defaut
547
-	if (preg_match('/FIELD\(([a-z]+\.[a-z]+),/i', $orderby[0], $groupbyplus)) {
548
-		$groupby[] = $groupbyplus[1];
549
-	}
550
-
551
-	$orderby = spip_pg_orderby($orderby, $select);
552
-
553
-	if ($having) {
554
-		if (is_array($having)) {
555
-			$having = join("\n\tAND ", array_map('calculer_pg_where', $having));
556
-		}
557
-	}
558
-	$from = spip_pg_from($from, $prefixe);
559
-	$query = 'SELECT ' . $select
560
-		. (!$from ? '' : "\nFROM $from")
561
-		. (!$where ? '' : ("\nWHERE " . (!is_array($where) ? calculer_pg_where($where) : (join(
562
-			"\n\tAND ",
563
-			array_map('calculer_pg_where', $where)
564
-		)))))
565
-		. spip_pg_groupby($groupby, $from, $select)
566
-		. (!$having ? '' : "\nHAVING $having")
567
-		. ($orderby ? ("\nORDER BY $orderby") : '')
568
-		. (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset")));
569
-
570
-	// renvoyer la requete inerte si demandee
571
-	if ($requeter === false) {
572
-		return $query;
573
-	}
574
-
575
-	$r = spip_pg_trace_query($query, $serveur);
576
-
577
-	return $r ?: $query;
531
+    $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
532
+    $prefixe = $connexion['prefixe'];
533
+    $link = $connexion['link'];
534
+    $db = $connexion['db'];
535
+
536
+    $limit = preg_match('/^\s*(([0-9]+),)?\s*([0-9]+)\s*$/', $limit, $limatch);
537
+    if ($limit) {
538
+        $offset = $limatch[2];
539
+        $count = $limatch[3];
540
+    }
541
+
542
+    $select = spip_pg_frommysql($select);
543
+
544
+    // si pas de tri explicitement demande, le GROUP BY ne
545
+    // contient que la clef primaire.
546
+    // lui ajouter alors le champ de tri par defaut
547
+    if (preg_match('/FIELD\(([a-z]+\.[a-z]+),/i', $orderby[0], $groupbyplus)) {
548
+        $groupby[] = $groupbyplus[1];
549
+    }
550
+
551
+    $orderby = spip_pg_orderby($orderby, $select);
552
+
553
+    if ($having) {
554
+        if (is_array($having)) {
555
+            $having = join("\n\tAND ", array_map('calculer_pg_where', $having));
556
+        }
557
+    }
558
+    $from = spip_pg_from($from, $prefixe);
559
+    $query = 'SELECT ' . $select
560
+        . (!$from ? '' : "\nFROM $from")
561
+        . (!$where ? '' : ("\nWHERE " . (!is_array($where) ? calculer_pg_where($where) : (join(
562
+            "\n\tAND ",
563
+            array_map('calculer_pg_where', $where)
564
+        )))))
565
+        . spip_pg_groupby($groupby, $from, $select)
566
+        . (!$having ? '' : "\nHAVING $having")
567
+        . ($orderby ? ("\nORDER BY $orderby") : '')
568
+        . (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset")));
569
+
570
+    // renvoyer la requete inerte si demandee
571
+    if ($requeter === false) {
572
+        return $query;
573
+    }
574
+
575
+    $r = spip_pg_trace_query($query, $serveur);
576
+
577
+    return $r ?: $query;
578 578
 ;
579 579
 }
580 580
 
@@ -582,26 +582,26 @@  discard block
 block discarded – undo
582 582
 // car le reste de la requete utilise les alias (AS) systematiquement
583 583
 
584 584
 function spip_pg_from($from, $prefixe) {
585
-	if (is_array($from)) {
586
-		$from = spip_pg_select_as($from);
587
-	}
585
+    if (is_array($from)) {
586
+        $from = spip_pg_select_as($from);
587
+    }
588 588
 
589
-	return !$prefixe ? $from : preg_replace('/(\b)spip_/', '\1' . $prefixe . '_', $from);
589
+    return !$prefixe ? $from : preg_replace('/(\b)spip_/', '\1' . $prefixe . '_', $from);
590 590
 }
591 591
 
592 592
 function spip_pg_orderby($order, $select) {
593
-	$res = [];
594
-	$arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order));
595
-
596
-	foreach ($arg as $v) {
597
-		if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v . '/', $select, $m)) {
598
-			$res[] = $m[1];
599
-		} else {
600
-			$res[] = $v;
601
-		}
602
-	}
603
-
604
-	return spip_pg_frommysql(join(',', $res));
593
+    $res = [];
594
+    $arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order));
595
+
596
+    foreach ($arg as $v) {
597
+        if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v . '/', $select, $m)) {
598
+            $res[] = $m[1];
599
+        } else {
600
+            $res[] = $v;
601
+        }
602
+    }
603
+
604
+    return spip_pg_frommysql(join(',', $res));
605 605
 }
606 606
 
607 607
 // Conversion a l'arrach' des jointures MySQL en jointures PG
@@ -609,56 +609,56 @@  discard block
 block discarded – undo
609 609
 // et pour enlever les repetitions (sans incidence de perf, mais ca fait sale)
610 610
 
611 611
 function spip_pg_groupby($groupby, $from, $select) {
612
-	$join = strpos($from, ',');
613
-	// ismplifier avant de decouper
614
-	if (is_string($select)) { // fct SQL sur colonne et constante apostrophee ==> la colonne
615
-	$select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $select);
616
-	}
617
-
618
-	if ($join or $groupby) {
619
-		$join = is_array($select) ? $select : explode(', ', $select);
620
-	}
621
-	if ($join) {
622
-		// enlever les 0 as points, '', ...
623
-		foreach ($join as $k => $v) {
624
-			$v = str_replace('DISTINCT ', '', $v);
625
-			// fct SQL sur colonne et constante apostrophee ==> la colonne
626
-			$v = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $v);
627
-			$v = preg_replace('/CAST\(\s*([^(),\' ]*\s+)as\s*\w+\)/', '\\1', $v);
628
-			// resultat d'agregat ne sont pas a mettre dans le groupby
629
-			$v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)(\s*AS\s+\w+)\s*,?/i', '', $v);
630
-			// idem sans AS (fetch numerique)
631
-			$v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)\s*,?/i', '', $v);
632
-			// des AS simples : on garde le cote droit du AS
633
-			$v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i', '\\1', $v);
634
-			// ne reste plus que les vrais colonnes, ou des constantes a virer
635
-			if (preg_match(',^[\'"],', $v) or is_numeric($v)) {
636
-				unset($join[$k]);
637
-			} else {
638
-				$join[$k] = trim($v);
639
-			}
640
-		}
641
-		$join = array_diff($join, ['']);
642
-		$join = implode(',', $join);
643
-	}
644
-	if (is_array($groupby)) {
645
-		$groupby = join(',', $groupby);
646
-	}
647
-	if ($join) {
648
-		$groupby = $groupby ? "$groupby, $join" : $join;
649
-	}
650
-	if (!$groupby) {
651
-		return '';
652
-	}
653
-
654
-	$groupby = spip_pg_frommysql($groupby);
655
-	// Ne pas mettre dans le Group-By des valeurs numeriques
656
-	// issue de prepare_recherche
657
-	$groupby = preg_replace('/^\s*\d+\s+AS\s+\w+\s*,?\s*/i', '', $groupby);
658
-	$groupby = preg_replace('/,\s*\d+\s+AS\s+\w+\s*/i', '', $groupby);
659
-	$groupby = preg_replace('/\s+AS\s+\w+\s*/i', '', $groupby);
660
-
661
-	return "\nGROUP BY $groupby";
612
+    $join = strpos($from, ',');
613
+    // ismplifier avant de decouper
614
+    if (is_string($select)) { // fct SQL sur colonne et constante apostrophee ==> la colonne
615
+    $select = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $select);
616
+    }
617
+
618
+    if ($join or $groupby) {
619
+        $join = is_array($select) ? $select : explode(', ', $select);
620
+    }
621
+    if ($join) {
622
+        // enlever les 0 as points, '', ...
623
+        foreach ($join as $k => $v) {
624
+            $v = str_replace('DISTINCT ', '', $v);
625
+            // fct SQL sur colonne et constante apostrophee ==> la colonne
626
+            $v = preg_replace('/\w+\(\s*([^(),\']*),\s*\'[^\']*\'[^)]*\)/', '\\1', $v);
627
+            $v = preg_replace('/CAST\(\s*([^(),\' ]*\s+)as\s*\w+\)/', '\\1', $v);
628
+            // resultat d'agregat ne sont pas a mettre dans le groupby
629
+            $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)(\s*AS\s+\w+)\s*,?/i', '', $v);
630
+            // idem sans AS (fetch numerique)
631
+            $v = preg_replace('/(SUM|COUNT|MAX|MIN|UPPER)\([^)]+\)\s*,?/i', '', $v);
632
+            // des AS simples : on garde le cote droit du AS
633
+            $v = preg_replace('/^.*\sAS\s+(\w+)\s*$/i', '\\1', $v);
634
+            // ne reste plus que les vrais colonnes, ou des constantes a virer
635
+            if (preg_match(',^[\'"],', $v) or is_numeric($v)) {
636
+                unset($join[$k]);
637
+            } else {
638
+                $join[$k] = trim($v);
639
+            }
640
+        }
641
+        $join = array_diff($join, ['']);
642
+        $join = implode(',', $join);
643
+    }
644
+    if (is_array($groupby)) {
645
+        $groupby = join(',', $groupby);
646
+    }
647
+    if ($join) {
648
+        $groupby = $groupby ? "$groupby, $join" : $join;
649
+    }
650
+    if (!$groupby) {
651
+        return '';
652
+    }
653
+
654
+    $groupby = spip_pg_frommysql($groupby);
655
+    // Ne pas mettre dans le Group-By des valeurs numeriques
656
+    // issue de prepare_recherche
657
+    $groupby = preg_replace('/^\s*\d+\s+AS\s+\w+\s*,?\s*/i', '', $groupby);
658
+    $groupby = preg_replace('/,\s*\d+\s+AS\s+\w+\s*/i', '', $groupby);
659
+    $groupby = preg_replace('/\s+AS\s+\w+\s*/i', '', $groupby);
660
+
661
+    return "\nGROUP BY $groupby";
662 662
 }
663 663
 
664 664
 // Conversion des operateurs MySQL en PG
@@ -669,492 +669,492 @@  discard block
 block discarded – undo
669 669
 // A ameliorer.
670 670
 
671 671
 function spip_pg_frommysql($arg) {
672
-	if (is_array($arg)) {
673
-		$arg = join(', ', $arg);
674
-	}
675
-
676
-	$res = spip_pg_fromfield($arg);
677
-
678
-	$res = preg_replace('/\brand[(][)]/i', 'random()', $res);
679
-
680
-	$res = preg_replace(
681
-		'/\b0\.0[+]([a-zA-Z0-9_.]+)\s*/',
682
-		'CAST(substring(\1, \'^ *[0-9.]+\') as float)',
683
-		$res
684
-	);
685
-	$res = preg_replace(
686
-		'/\b0[+]([a-zA-Z0-9_.]+)\s*/',
687
-		'CAST(substring(\1, \'^ *[0-9]+\') as int)',
688
-		$res
689
-	);
690
-	$res = preg_replace(
691
-		'/\bconv[(]([^,]*)[^)]*[)]/i',
692
-		'CAST(substring(\1, \'^ *[0-9]+\') as int)',
693
-		$res
694
-	);
695
-
696
-	$res = preg_replace(
697
-		'/UNIX_TIMESTAMP\s*[(]\s*[)]/',
698
-		' EXTRACT(epoch FROM NOW())',
699
-		$res
700
-	);
701
-
702
-	// la fonction md5(integer) n'est pas connu en pg
703
-	// il faut donc forcer les types en text (cas de md5(id_article))
704
-	$res = preg_replace(
705
-		'/md5\s*[(]([^)]*)[)]/i',
706
-		'MD5(CAST(\1 AS text))',
707
-		$res
708
-	);
709
-
710
-	$res = preg_replace(
711
-		'/UNIX_TIMESTAMP\s*[(]([^)]*)[)]/',
712
-		' EXTRACT(epoch FROM \1)',
713
-		$res
714
-	);
715
-
716
-	$res = preg_replace(
717
-		'/\bDAYOFMONTH\s*[(]([^()]*([(][^()]*[)][^()]*)*[^)]*)[)]/',
718
-		' EXTRACT(day FROM \1)',
719
-		$res
720
-	);
721
-
722
-	$res = preg_replace(
723
-		'/\bMONTH\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/',
724
-		' EXTRACT(month FROM \1)',
725
-		$res
726
-	);
727
-
728
-	$res = preg_replace(
729
-		'/\bYEAR\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/',
730
-		' EXTRACT(year FROM \1)',
731
-		$res
732
-	);
733
-
734
-	$res = preg_replace(
735
-		'/TO_DAYS\s*[(]([^()]*([(][^)]*[)][()]*)*)[)]/',
736
-		' EXTRACT(day FROM \1 - \'0001-01-01\')',
737
-		$res
738
-	);
739
-
740
-	$res = preg_replace('/(EXTRACT[(][^ ]* FROM *)"([^"]*)"/', '\1\'\2\'', $res);
741
-
742
-	$res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m%d\'[)]/', 'to_char(\1, \'YYYYMMDD\')', $res);
743
-
744
-	$res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m\'[)]/', 'to_char(\1, \'YYYYMM\')', $res);
745
-
746
-	$res = preg_replace('/DATE_SUB\s*[(]([^,]*),/', '(\1 -', $res);
747
-	$res = preg_replace('/DATE_ADD\s*[(]([^,]*),/', '(\1 +', $res);
748
-	$res = preg_replace('/INTERVAL\s+(\d+\s+\w+)/', 'INTERVAL \'\1\'', $res);
749
-	$res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\s+\d+:\d+(:\d+)\')/', '\1 timestamp \2', $res);
750
-	$res = preg_replace('/(\'\d+-\d+-\d+\s+\d+:\d+:\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res);
751
-
752
-	$res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\')/', '\1 timestamp \2', $res);
753
-	$res = preg_replace('/(\'\d+-\d+-\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res);
754
-
755
-	$res = preg_replace('/(timestamp .\d+)-00-/', '\1-01-', $res);
756
-	$res = preg_replace('/(timestamp .\d+-\d+)-00/', '\1-01', $res);
672
+    if (is_array($arg)) {
673
+        $arg = join(', ', $arg);
674
+    }
675
+
676
+    $res = spip_pg_fromfield($arg);
677
+
678
+    $res = preg_replace('/\brand[(][)]/i', 'random()', $res);
679
+
680
+    $res = preg_replace(
681
+        '/\b0\.0[+]([a-zA-Z0-9_.]+)\s*/',
682
+        'CAST(substring(\1, \'^ *[0-9.]+\') as float)',
683
+        $res
684
+    );
685
+    $res = preg_replace(
686
+        '/\b0[+]([a-zA-Z0-9_.]+)\s*/',
687
+        'CAST(substring(\1, \'^ *[0-9]+\') as int)',
688
+        $res
689
+    );
690
+    $res = preg_replace(
691
+        '/\bconv[(]([^,]*)[^)]*[)]/i',
692
+        'CAST(substring(\1, \'^ *[0-9]+\') as int)',
693
+        $res
694
+    );
695
+
696
+    $res = preg_replace(
697
+        '/UNIX_TIMESTAMP\s*[(]\s*[)]/',
698
+        ' EXTRACT(epoch FROM NOW())',
699
+        $res
700
+    );
701
+
702
+    // la fonction md5(integer) n'est pas connu en pg
703
+    // il faut donc forcer les types en text (cas de md5(id_article))
704
+    $res = preg_replace(
705
+        '/md5\s*[(]([^)]*)[)]/i',
706
+        'MD5(CAST(\1 AS text))',
707
+        $res
708
+    );
709
+
710
+    $res = preg_replace(
711
+        '/UNIX_TIMESTAMP\s*[(]([^)]*)[)]/',
712
+        ' EXTRACT(epoch FROM \1)',
713
+        $res
714
+    );
715
+
716
+    $res = preg_replace(
717
+        '/\bDAYOFMONTH\s*[(]([^()]*([(][^()]*[)][^()]*)*[^)]*)[)]/',
718
+        ' EXTRACT(day FROM \1)',
719
+        $res
720
+    );
721
+
722
+    $res = preg_replace(
723
+        '/\bMONTH\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/',
724
+        ' EXTRACT(month FROM \1)',
725
+        $res
726
+    );
727
+
728
+    $res = preg_replace(
729
+        '/\bYEAR\s*[(]([^()]*([(][^)]*[)][^()]*)*[^)]*)[)]/',
730
+        ' EXTRACT(year FROM \1)',
731
+        $res
732
+    );
733
+
734
+    $res = preg_replace(
735
+        '/TO_DAYS\s*[(]([^()]*([(][^)]*[)][()]*)*)[)]/',
736
+        ' EXTRACT(day FROM \1 - \'0001-01-01\')',
737
+        $res
738
+    );
739
+
740
+    $res = preg_replace('/(EXTRACT[(][^ ]* FROM *)"([^"]*)"/', '\1\'\2\'', $res);
741
+
742
+    $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m%d\'[)]/', 'to_char(\1, \'YYYYMMDD\')', $res);
743
+
744
+    $res = preg_replace('/DATE_FORMAT\s*[(]([^,]*),\s*\'%Y%m\'[)]/', 'to_char(\1, \'YYYYMM\')', $res);
745
+
746
+    $res = preg_replace('/DATE_SUB\s*[(]([^,]*),/', '(\1 -', $res);
747
+    $res = preg_replace('/DATE_ADD\s*[(]([^,]*),/', '(\1 +', $res);
748
+    $res = preg_replace('/INTERVAL\s+(\d+\s+\w+)/', 'INTERVAL \'\1\'', $res);
749
+    $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\s+\d+:\d+(:\d+)\')/', '\1 timestamp \2', $res);
750
+    $res = preg_replace('/(\'\d+-\d+-\d+\s+\d+:\d+:\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res);
751
+
752
+    $res = preg_replace('/([+<>-]=?)\s*(\'\d+-\d+-\d+\')/', '\1 timestamp \2', $res);
753
+    $res = preg_replace('/(\'\d+-\d+-\d+\')\s*([+<>-]=?)/', 'timestamp \1 \2', $res);
754
+
755
+    $res = preg_replace('/(timestamp .\d+)-00-/', '\1-01-', $res);
756
+    $res = preg_replace('/(timestamp .\d+-\d+)-00/', '\1-01', $res);
757 757
 # correct en theorie mais produit des debordements arithmetiques
758 758
 #	$res = preg_replace("/(EXTRACT[(][^ ]* FROM *)(timestamp *'[^']*' *[+-] *timestamp *'[^']*') *[)]/", '\2', $res);
759
-	$res = preg_replace("/(EXTRACT[(][^ ]* FROM *)('[^']*')/", '\1 timestamp \2', $res);
760
-	$res = preg_replace('/\sLIKE\s+/', ' ILIKE ', $res);
759
+    $res = preg_replace("/(EXTRACT[(][^ ]* FROM *)('[^']*')/", '\1 timestamp \2', $res);
760
+    $res = preg_replace('/\sLIKE\s+/', ' ILIKE ', $res);
761 761
 
762
-	return str_replace('REGEXP', '~', $res);
762
+    return str_replace('REGEXP', '~', $res);
763 763
 }
764 764
 
765 765
 function spip_pg_fromfield($arg) {
766
-	while (preg_match('/^(.*?)FIELD\s*\(([^,]*)((,[^,)]*)*)\)/', $arg, $m)) {
767
-		preg_match_all('/,([^,]*)/', $m[3], $r, PREG_PATTERN_ORDER);
768
-		$res = '';
769
-		$n = 0;
770
-		$index = $m[2];
771
-		foreach ($r[1] as $v) {
772
-			$n++;
773
-			$res .= "\nwhen $index=$v then $n";
774
-		}
775
-		$arg = $m[1] . "case $res else 0 end "
776
-			. substr($arg, strlen($m[0]));
777
-	}
778
-
779
-	return $arg;
766
+    while (preg_match('/^(.*?)FIELD\s*\(([^,]*)((,[^,)]*)*)\)/', $arg, $m)) {
767
+        preg_match_all('/,([^,]*)/', $m[3], $r, PREG_PATTERN_ORDER);
768
+        $res = '';
769
+        $n = 0;
770
+        $index = $m[2];
771
+        foreach ($r[1] as $v) {
772
+            $n++;
773
+            $res .= "\nwhen $index=$v then $n";
774
+        }
775
+        $arg = $m[1] . "case $res else 0 end "
776
+            . substr($arg, strlen($m[0]));
777
+    }
778
+
779
+    return $arg;
780 780
 }
781 781
 
782 782
 function calculer_pg_where($v) {
783
-	if (!is_array($v)) {
784
-		return spip_pg_frommysql($v);
785
-	}
786
-
787
-	$op = str_replace('REGEXP', '~', array_shift($v));
788
-	if (!($n = count($v))) {
789
-		return $op;
790
-	} else {
791
-		$arg = calculer_pg_where(array_shift($v));
792
-		if ($n == 1) {
793
-			return "$op($arg)";
794
-		} else {
795
-			$arg2 = calculer_pg_where(array_shift($v));
796
-			if ($n == 2) {
797
-				return "($arg $op $arg2)";
798
-			} else {
799
-				return "($arg $op ($arg2) : $v[0])";
800
-			}
801
-		}
802
-	}
783
+    if (!is_array($v)) {
784
+        return spip_pg_frommysql($v);
785
+    }
786
+
787
+    $op = str_replace('REGEXP', '~', array_shift($v));
788
+    if (!($n = count($v))) {
789
+        return $op;
790
+    } else {
791
+        $arg = calculer_pg_where(array_shift($v));
792
+        if ($n == 1) {
793
+            return "$op($arg)";
794
+        } else {
795
+            $arg2 = calculer_pg_where(array_shift($v));
796
+            if ($n == 2) {
797
+                return "($arg $op $arg2)";
798
+            } else {
799
+                return "($arg $op ($arg2) : $v[0])";
800
+            }
801
+        }
802
+    }
803 803
 }
804 804
 
805 805
 
806 806
 function calculer_pg_expression($expression, $v, $join = 'AND') {
807
-	if (empty($v)) {
808
-		return '';
809
-	}
807
+    if (empty($v)) {
808
+        return '';
809
+    }
810 810
 
811
-	$exp = "\n$expression ";
811
+    $exp = "\n$expression ";
812 812
 
813
-	if (!is_array($v)) {
814
-		$v = [$v];
815
-	}
813
+    if (!is_array($v)) {
814
+        $v = [$v];
815
+    }
816 816
 
817
-	if (strtoupper($join) === 'AND') {
818
-		return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v));
819
-	} else {
820
-		return $exp . join($join, $v);
821
-	}
817
+    if (strtoupper($join) === 'AND') {
818
+        return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v));
819
+    } else {
820
+        return $exp . join($join, $v);
821
+    }
822 822
 }
823 823
 
824 824
 function spip_pg_select_as($args) {
825
-	$argsas = '';
826
-	foreach ($args as $k => $v) {
827
-		if (substr($k, -1) == '@') {
828
-			// c'est une jointure qui se refere au from precedent
829
-			// pas de virgule
830
-			$argsas .= '  ' . $v;
831
-		} else {
832
-			$as = '';
833
-			//  spip_log("$k : $v", _LOG_DEBUG);
834
-			if (!is_numeric($k)) {
835
-				if (preg_match('/\.(.*)$/', $k, $r)) {
836
-					$v = $k;
837
-				} elseif ($v != $k) {
838
-					$p = strpos($v, ' ');
839
-					if ($p) {
840
-						$v = substr($v, 0, $p) . " AS $k" . substr($v, $p);
841
-					} else {
842
-						$as = " AS $k";
843
-					}
844
-				}
845
-			}
846
-			// spip_log("subs $k : $v avec $as", _LOG_DEBUG);
847
-			// if (strpos($v, 'JOIN') === false)  $argsas .= ', ';
848
-			$argsas .= ', ' . $v . $as;
849
-		}
850
-	}
851
-
852
-	return substr($argsas, 2);
825
+    $argsas = '';
826
+    foreach ($args as $k => $v) {
827
+        if (substr($k, -1) == '@') {
828
+            // c'est une jointure qui se refere au from precedent
829
+            // pas de virgule
830
+            $argsas .= '  ' . $v;
831
+        } else {
832
+            $as = '';
833
+            //  spip_log("$k : $v", _LOG_DEBUG);
834
+            if (!is_numeric($k)) {
835
+                if (preg_match('/\.(.*)$/', $k, $r)) {
836
+                    $v = $k;
837
+                } elseif ($v != $k) {
838
+                    $p = strpos($v, ' ');
839
+                    if ($p) {
840
+                        $v = substr($v, 0, $p) . " AS $k" . substr($v, $p);
841
+                    } else {
842
+                        $as = " AS $k";
843
+                    }
844
+                }
845
+            }
846
+            // spip_log("subs $k : $v avec $as", _LOG_DEBUG);
847
+            // if (strpos($v, 'JOIN') === false)  $argsas .= ', ';
848
+            $argsas .= ', ' . $v . $as;
849
+        }
850
+    }
851
+
852
+    return substr($argsas, 2);
853 853
 }
854 854
 
855 855
 function spip_pg_fetch($res, $t = '', $serveur = '', $requeter = true) {
856 856
 
857
-	if ($res) {
858
-		$res = pg_fetch_array($res, null, PGSQL_ASSOC);
859
-	}
857
+    if ($res) {
858
+        $res = pg_fetch_array($res, null, PGSQL_ASSOC);
859
+    }
860 860
 
861
-	return $res;
861
+    return $res;
862 862
 }
863 863
 
864 864
 function spip_pg_seek($r, $row_number, $serveur = '', $requeter = true) {
865
-	if ($r) {
866
-		return pg_result_seek($r, $row_number);
867
-	}
865
+    if ($r) {
866
+        return pg_result_seek($r, $row_number);
867
+    }
868 868
 }
869 869
 
870 870
 
871 871
 function spip_pg_countsel(
872
-	$from = [],
873
-	$where = [],
874
-	$groupby = [],
875
-	$having = [],
876
-	$serveur = '',
877
-	$requeter = true
872
+    $from = [],
873
+    $where = [],
874
+    $groupby = [],
875
+    $having = [],
876
+    $serveur = '',
877
+    $requeter = true
878 878
 ) {
879
-	$c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby)));
880
-	$r = spip_pg_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter);
881
-	if (!$requeter) {
882
-		return $r;
883
-	}
884
-	if (!is_resource($r)) {
885
-		return 0;
886
-	}
887
-	[$c] = pg_fetch_array($r, null, PGSQL_NUM);
888
-
889
-	return $c;
879
+    $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby)));
880
+    $r = spip_pg_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter);
881
+    if (!$requeter) {
882
+        return $r;
883
+    }
884
+    if (!is_resource($r)) {
885
+        return 0;
886
+    }
887
+    [$c] = pg_fetch_array($r, null, PGSQL_NUM);
888
+
889
+    return $c;
890 890
 }
891 891
 
892 892
 function spip_pg_count($res, $serveur = '', $requeter = true) {
893
-	return !$res ? 0 : pg_numrows($res);
893
+    return !$res ? 0 : pg_numrows($res);
894 894
 }
895 895
 
896 896
 function spip_pg_free($res, $serveur = '', $requeter = true) {
897
-	// rien a faire en postgres
897
+    // rien a faire en postgres
898 898
 }
899 899
 
900 900
 function spip_pg_delete($table, $where = '', $serveur = '', $requeter = true) {
901 901
 
902
-	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
903
-	$table = prefixer_table_spip($table, $connexion['prefixe']);
902
+    $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
903
+    $table = prefixer_table_spip($table, $connexion['prefixe']);
904 904
 
905
-	$query = calculer_pg_expression('DELETE FROM', $table, ',')
906
-		. calculer_pg_expression('WHERE', $where, 'AND');
905
+    $query = calculer_pg_expression('DELETE FROM', $table, ',')
906
+        . calculer_pg_expression('WHERE', $where, 'AND');
907 907
 
908
-	// renvoyer la requete inerte si demandee
909
-	if (!$requeter) {
910
-		return $query;
911
-	}
908
+    // renvoyer la requete inerte si demandee
909
+    if (!$requeter) {
910
+        return $query;
911
+    }
912 912
 
913
-	$res = spip_pg_trace_query($query, $serveur);
914
-	if ($res) {
915
-		return pg_affected_rows($res);
916
-	} else {
917
-		return false;
918
-	}
913
+    $res = spip_pg_trace_query($query, $serveur);
914
+    if ($res) {
915
+        return pg_affected_rows($res);
916
+    } else {
917
+        return false;
918
+    }
919 919
 }
920 920
 
921 921
 function spip_pg_insert($table, $champs, $valeurs, $desc = [], $serveur = '', $requeter = true) {
922
-	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
923
-	$prefixe = $connexion['prefixe'];
924
-	$link = $connexion['link'];
925
-
926
-	if (!$desc) {
927
-		$desc = description_table($table, $serveur);
928
-	}
929
-	$seq = spip_pg_sequence($table, true);
930
-	// si pas de cle primaire dans l'insertion, renvoyer curval
931
-	if (!preg_match(",\b$seq\b,", $champs)) {
932
-		$seq = spip_pg_sequence($table);
933
-		$seq = prefixer_table_spip($seq, $prefixe);
934
-		$seq = "currval('$seq')";
935
-	}
936
-
937
-	$table = prefixer_table_spip($table, $prefixe);
938
-	$ret = !$seq ? '' : (" RETURNING $seq");
939
-	$ins = (strlen($champs) < 3)
940
-		? ' DEFAULT VALUES'
941
-		: "$champs VALUES $valeurs";
942
-	$q = "INSERT INTO $table $ins $ret";
943
-	if (!$requeter) {
944
-		return $q;
945
-	}
946
-	$connexion['last'] = $q;
947
-	$r = spip_pg_query_simple($link, $q);
922
+    $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
923
+    $prefixe = $connexion['prefixe'];
924
+    $link = $connexion['link'];
925
+
926
+    if (!$desc) {
927
+        $desc = description_table($table, $serveur);
928
+    }
929
+    $seq = spip_pg_sequence($table, true);
930
+    // si pas de cle primaire dans l'insertion, renvoyer curval
931
+    if (!preg_match(",\b$seq\b,", $champs)) {
932
+        $seq = spip_pg_sequence($table);
933
+        $seq = prefixer_table_spip($seq, $prefixe);
934
+        $seq = "currval('$seq')";
935
+    }
936
+
937
+    $table = prefixer_table_spip($table, $prefixe);
938
+    $ret = !$seq ? '' : (" RETURNING $seq");
939
+    $ins = (strlen($champs) < 3)
940
+        ? ' DEFAULT VALUES'
941
+        : "$champs VALUES $valeurs";
942
+    $q = "INSERT INTO $table $ins $ret";
943
+    if (!$requeter) {
944
+        return $q;
945
+    }
946
+    $connexion['last'] = $q;
947
+    $r = spip_pg_query_simple($link, $q);
948 948
 #	spip_log($q,'pg.'._LOG_DEBUG);
949
-	if ($r) {
950
-		if (!$ret) {
951
-			return 0;
952
-		}
953
-		if ($r2 = pg_fetch_array($r, null, PGSQL_NUM)) {
954
-			return $r2[0];
955
-		}
956
-	}
957
-
958
-	return false;
949
+    if ($r) {
950
+        if (!$ret) {
951
+            return 0;
952
+        }
953
+        if ($r2 = pg_fetch_array($r, null, PGSQL_NUM)) {
954
+            return $r2[0];
955
+        }
956
+    }
957
+
958
+    return false;
959 959
 }
960 960
 
961 961
 function spip_pg_insertq($table, $couples = [], $desc = [], $serveur = '', $requeter = true) {
962 962
 
963
-	if (!$desc) {
964
-		$desc = description_table($table, $serveur);
965
-	}
966
-	if (!$desc) {
967
-		die("$table insertion sans description");
968
-	}
969
-	$fields = $desc['field'];
970
-
971
-	foreach ($couples as $champ => $val) {
972
-		$couples[$champ] = spip_pg_cite($val, $fields[$champ]);
973
-	}
974
-
975
-	// recherche de champs 'timestamp' pour mise a jour auto de ceux-ci
976
-	$couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur);
977
-
978
-	return spip_pg_insert(
979
-		$table,
980
-		'(' . join(',', array_keys($couples)) . ')',
981
-		'(' . join(',', $couples) . ')',
982
-		$desc,
983
-		$serveur,
984
-		$requeter
985
-	);
963
+    if (!$desc) {
964
+        $desc = description_table($table, $serveur);
965
+    }
966
+    if (!$desc) {
967
+        die("$table insertion sans description");
968
+    }
969
+    $fields = $desc['field'];
970
+
971
+    foreach ($couples as $champ => $val) {
972
+        $couples[$champ] = spip_pg_cite($val, $fields[$champ]);
973
+    }
974
+
975
+    // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci
976
+    $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur);
977
+
978
+    return spip_pg_insert(
979
+        $table,
980
+        '(' . join(',', array_keys($couples)) . ')',
981
+        '(' . join(',', $couples) . ')',
982
+        $desc,
983
+        $serveur,
984
+        $requeter
985
+    );
986 986
 }
987 987
 
988 988
 
989 989
 function spip_pg_insertq_multi($table, $tab_couples = [], $desc = [], $serveur = '', $requeter = true) {
990 990
 
991
-	if (!$desc) {
992
-		$desc = description_table($table, $serveur);
993
-	}
994
-	if (!$desc) {
995
-		die("$table insertion sans description");
996
-	}
997
-	$fields = $desc['field'] ?? [];
998
-
999
-	// recherche de champs 'timestamp' pour mise a jour auto de ceux-ci
1000
-	// une premiere fois pour ajouter maj dans les cles
1001
-	$c = $tab_couples[0] ?? [];
1002
-	$les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur);
1003
-
1004
-	$cles = '(' . join(',', array_keys($les_cles)) . ')';
1005
-	$valeurs = [];
1006
-	foreach ($tab_couples as $couples) {
1007
-		foreach ($couples as $champ => $val) {
1008
-			$couples[$champ] = spip_pg_cite($val, $fields[$champ]);
1009
-		}
1010
-		// recherche de champs 'timestamp' pour mise a jour auto de ceux-ci
1011
-		$couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur);
1012
-
1013
-		$valeurs[] = '(' . join(',', $couples) . ')';
1014
-	}
1015
-	$valeurs = implode(', ', $valeurs);
1016
-
1017
-	return spip_pg_insert($table, $cles, $valeurs, $desc, $serveur, $requeter);
991
+    if (!$desc) {
992
+        $desc = description_table($table, $serveur);
993
+    }
994
+    if (!$desc) {
995
+        die("$table insertion sans description");
996
+    }
997
+    $fields = $desc['field'] ?? [];
998
+
999
+    // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci
1000
+    // une premiere fois pour ajouter maj dans les cles
1001
+    $c = $tab_couples[0] ?? [];
1002
+    $les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur);
1003
+
1004
+    $cles = '(' . join(',', array_keys($les_cles)) . ')';
1005
+    $valeurs = [];
1006
+    foreach ($tab_couples as $couples) {
1007
+        foreach ($couples as $champ => $val) {
1008
+            $couples[$champ] = spip_pg_cite($val, $fields[$champ]);
1009
+        }
1010
+        // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci
1011
+        $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur);
1012
+
1013
+        $valeurs[] = '(' . join(',', $couples) . ')';
1014
+    }
1015
+    $valeurs = implode(', ', $valeurs);
1016
+
1017
+    return spip_pg_insert($table, $cles, $valeurs, $desc, $serveur, $requeter);
1018 1018
 }
1019 1019
 
1020 1020
 
1021 1021
 function spip_pg_update($table, $couples, $where = '', $desc = '', $serveur = '', $requeter = true) {
1022 1022
 
1023
-	if (!$couples) {
1024
-		return;
1025
-	}
1026
-	$connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
1027
-	$table = prefixer_table_spip($table, $connexion['prefixe']);
1023
+    if (!$couples) {
1024
+        return;
1025
+    }
1026
+    $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
1027
+    $table = prefixer_table_spip($table, $connexion['prefixe']);
1028 1028
 
1029
-	// recherche de champs 'timestamp' pour mise a jour auto de ceux-ci
1030
-	$couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur);
1029
+    // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci
1030
+    $couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur);
1031 1031
 
1032
-	$set = [];
1033
-	foreach ($couples as $champ => $val) {
1034
-		$set[] = $champ . '=' . $val;
1035
-	}
1032
+    $set = [];
1033
+    foreach ($couples as $champ => $val) {
1034
+        $set[] = $champ . '=' . $val;
1035
+    }
1036 1036
 
1037
-	$query = calculer_pg_expression('UPDATE', $table, ',')
1038
-		. calculer_pg_expression('SET', $set, ',')
1039
-		. calculer_pg_expression('WHERE', $where, 'AND');
1037
+    $query = calculer_pg_expression('UPDATE', $table, ',')
1038
+        . calculer_pg_expression('SET', $set, ',')
1039
+        . calculer_pg_expression('WHERE', $where, 'AND');
1040 1040
 
1041
-	// renvoyer la requete inerte si demandee
1042
-	if (!$requeter) {
1043
-		return $query;
1044
-	}
1041
+    // renvoyer la requete inerte si demandee
1042
+    if (!$requeter) {
1043
+        return $query;
1044
+    }
1045 1045
 
1046
-	return spip_pg_trace_query($query, $serveur);
1046
+    return spip_pg_trace_query($query, $serveur);
1047 1047
 }
1048 1048
 
1049 1049
 // idem, mais les valeurs sont des constantes a mettre entre apostrophes
1050 1050
 // sauf les expressions de date lorsqu'il s'agit de fonctions SQL (NOW etc)
1051 1051
 function spip_pg_updateq($table, $couples, $where = '', $desc = [], $serveur = '', $requeter = true) {
1052
-	if (!$couples) {
1053
-		return;
1054
-	}
1055
-	if (!$desc) {
1056
-		$desc = description_table($table, $serveur);
1057
-	}
1058
-	$fields = $desc['field'];
1059
-	foreach ($couples as $k => $val) {
1060
-		$couples[$k] = spip_pg_cite($val, $fields[$k]);
1061
-	}
1062
-
1063
-	return spip_pg_update($table, $couples, $where, $desc, $serveur, $requeter);
1052
+    if (!$couples) {
1053
+        return;
1054
+    }
1055
+    if (!$desc) {
1056
+        $desc = description_table($table, $serveur);
1057
+    }
1058
+    $fields = $desc['field'];
1059
+    foreach ($couples as $k => $val) {
1060
+        $couples[$k] = spip_pg_cite($val, $fields[$k]);
1061
+    }
1062
+
1063
+    return spip_pg_update($table, $couples, $where, $desc, $serveur, $requeter);
1064 1064
 }
1065 1065
 
1066 1066
 
1067 1067
 function spip_pg_replace($table, $values, $desc, $serveur = '', $requeter = true) {
1068
-	if (!$values) {
1069
-		spip_log("replace vide $table", 'pg.' . _LOG_AVERTISSEMENT);
1070
-
1071
-		return 0;
1072
-	}
1073
-	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
1074
-	$prefixe = $connexion['prefixe'];
1075
-	$link = $connexion['link'];
1076
-
1077
-	if (!$desc) {
1078
-		$desc = description_table($table, $serveur);
1079
-	}
1080
-	if (!$desc) {
1081
-		die("$table insertion sans description");
1082
-	}
1083
-	$prim = $desc['key']['PRIMARY KEY'];
1084
-	$ids = preg_split('/,\s*/', $prim);
1085
-	$noprims = $prims = [];
1086
-	foreach ($values as $k => $v) {
1087
-		$values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]);
1088
-
1089
-		if (!in_array($k, $ids)) {
1090
-			$noprims[$k] = "$k=$v";
1091
-		} else {
1092
-			$prims[$k] = "$k=$v";
1093
-		}
1094
-	}
1095
-
1096
-	// recherche de champs 'timestamp' pour mise a jour auto de ceux-ci
1097
-	$values = spip_pg_ajouter_champs_timestamp($table, $values, $desc, $serveur);
1098
-
1099
-	$where = join(' AND ', $prims);
1100
-	if (!$where) {
1101
-		return spip_pg_insert(
1102
-			$table,
1103
-			'(' . join(',', array_keys($values)) . ')',
1104
-			'(' . join(',', $values) . ')',
1105
-			$desc,
1106
-			$serveur
1107
-		);
1108
-	}
1109
-	$couples = join(',', $noprims);
1110
-
1111
-	$seq = spip_pg_sequence($table);
1112
-	$table = prefixer_table_spip($table, $prefixe);
1113
-	$seq = prefixer_table_spip($seq, $prefixe);
1114
-
1115
-	$connexion['last'] = $q = "UPDATE $table SET $couples WHERE $where";
1116
-	if ($couples) {
1117
-		$couples = spip_pg_query_simple($link, $q);
1068
+    if (!$values) {
1069
+        spip_log("replace vide $table", 'pg.' . _LOG_AVERTISSEMENT);
1070
+
1071
+        return 0;
1072
+    }
1073
+    $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
1074
+    $prefixe = $connexion['prefixe'];
1075
+    $link = $connexion['link'];
1076
+
1077
+    if (!$desc) {
1078
+        $desc = description_table($table, $serveur);
1079
+    }
1080
+    if (!$desc) {
1081
+        die("$table insertion sans description");
1082
+    }
1083
+    $prim = $desc['key']['PRIMARY KEY'];
1084
+    $ids = preg_split('/,\s*/', $prim);
1085
+    $noprims = $prims = [];
1086
+    foreach ($values as $k => $v) {
1087
+        $values[$k] = $v = spip_pg_cite($v, $desc['field'][$k]);
1088
+
1089
+        if (!in_array($k, $ids)) {
1090
+            $noprims[$k] = "$k=$v";
1091
+        } else {
1092
+            $prims[$k] = "$k=$v";
1093
+        }
1094
+    }
1095
+
1096
+    // recherche de champs 'timestamp' pour mise a jour auto de ceux-ci
1097
+    $values = spip_pg_ajouter_champs_timestamp($table, $values, $desc, $serveur);
1098
+
1099
+    $where = join(' AND ', $prims);
1100
+    if (!$where) {
1101
+        return spip_pg_insert(
1102
+            $table,
1103
+            '(' . join(',', array_keys($values)) . ')',
1104
+            '(' . join(',', $values) . ')',
1105
+            $desc,
1106
+            $serveur
1107
+        );
1108
+    }
1109
+    $couples = join(',', $noprims);
1110
+
1111
+    $seq = spip_pg_sequence($table);
1112
+    $table = prefixer_table_spip($table, $prefixe);
1113
+    $seq = prefixer_table_spip($seq, $prefixe);
1114
+
1115
+    $connexion['last'] = $q = "UPDATE $table SET $couples WHERE $where";
1116
+    if ($couples) {
1117
+        $couples = spip_pg_query_simple($link, $q);
1118 1118
 #	  spip_log($q,'pg.'._LOG_DEBUG);
1119
-		if (!$couples) {
1120
-			return false;
1121
-		}
1122
-		$couples = pg_affected_rows($couples);
1123
-	}
1124
-	if (!$couples) {
1125
-		$ret = !$seq ? '' :
1126
-			(" RETURNING nextval('$seq') < $prim");
1127
-		$connexion['last'] = $q = "INSERT INTO $table (" . join(',', array_keys($values)) . ') VALUES (' . join(
1128
-			',',
1129
-			$values
1130
-		) . ")$ret";
1131
-		$couples = spip_pg_query_simple($link, $q);
1132
-		if (!$couples) {
1133
-			return false;
1134
-		} elseif ($ret) {
1135
-			$r = pg_fetch_array($couples, null, PGSQL_NUM);
1136
-			if ($r[0]) {
1137
-				$connexion['last'] = $q = "SELECT setval('$seq', $prim) from $table";
1138
-				// Le code de SPIP met parfois la sequence a 0 (dans l'import)
1139
-				// MySQL n'en dit rien, on fait pareil pour PG
1140
-				$r = @pg_query($link, $q);
1141
-			}
1142
-		}
1143
-	}
1144
-
1145
-	return $couples;
1119
+        if (!$couples) {
1120
+            return false;
1121
+        }
1122
+        $couples = pg_affected_rows($couples);
1123
+    }
1124
+    if (!$couples) {
1125
+        $ret = !$seq ? '' :
1126
+            (" RETURNING nextval('$seq') < $prim");
1127
+        $connexion['last'] = $q = "INSERT INTO $table (" . join(',', array_keys($values)) . ') VALUES (' . join(
1128
+            ',',
1129
+            $values
1130
+        ) . ")$ret";
1131
+        $couples = spip_pg_query_simple($link, $q);
1132
+        if (!$couples) {
1133
+            return false;
1134
+        } elseif ($ret) {
1135
+            $r = pg_fetch_array($couples, null, PGSQL_NUM);
1136
+            if ($r[0]) {
1137
+                $connexion['last'] = $q = "SELECT setval('$seq', $prim) from $table";
1138
+                // Le code de SPIP met parfois la sequence a 0 (dans l'import)
1139
+                // MySQL n'en dit rien, on fait pareil pour PG
1140
+                $r = @pg_query($link, $q);
1141
+            }
1142
+        }
1143
+    }
1144
+
1145
+    return $couples;
1146 1146
 }
1147 1147
 
1148 1148
 
1149 1149
 function spip_pg_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $requeter = true) {
1150
-	$retour = null;
1151
-	// boucler pour traiter chaque requete independemment
1152
-	foreach ($tab_couples as $couples) {
1153
-		$retour = spip_pg_replace($table, $couples, $desc, $serveur, $requeter);
1154
-	}
1155
-
1156
-	// renvoie le dernier id
1157
-	return $retour;
1150
+    $retour = null;
1151
+    // boucler pour traiter chaque requete independemment
1152
+    foreach ($tab_couples as $couples) {
1153
+        $retour = spip_pg_replace($table, $couples, $desc, $serveur, $requeter);
1154
+    }
1155
+
1156
+    // renvoie le dernier id
1157
+    return $retour;
1158 1158
 }
1159 1159
 
1160 1160
 
@@ -1163,149 +1163,149 @@  discard block
 block discarded – undo
1163 1163
 
1164 1164
 function spip_pg_sequence($table, $raw = false) {
1165 1165
 
1166
-	include_spip('base/serial');
1167
-	if (!isset($GLOBALS['tables_principales'][$table])) {
1168
-		return false;
1169
-	}
1170
-	$desc = $GLOBALS['tables_principales'][$table];
1171
-	$prim = @$desc['key']['PRIMARY KEY'];
1172
-	if (
1173
-		!preg_match('/^\w+$/', $prim)
1174
-		or strpos($desc['field'][$prim], 'int') === false
1175
-	) {
1176
-		return '';
1177
-	} else {
1178
-		return $raw ? $prim : $table . '_' . $prim . '_seq';
1179
-	}
1166
+    include_spip('base/serial');
1167
+    if (!isset($GLOBALS['tables_principales'][$table])) {
1168
+        return false;
1169
+    }
1170
+    $desc = $GLOBALS['tables_principales'][$table];
1171
+    $prim = @$desc['key']['PRIMARY KEY'];
1172
+    if (
1173
+        !preg_match('/^\w+$/', $prim)
1174
+        or strpos($desc['field'][$prim], 'int') === false
1175
+    ) {
1176
+        return '';
1177
+    } else {
1178
+        return $raw ? $prim : $table . '_' . $prim . '_seq';
1179
+    }
1180 1180
 }
1181 1181
 
1182 1182
 // Explicite les conversions de Mysql d'une valeur $v de type $t
1183 1183
 // Dans le cas d'un champ date, pas d'apostrophe, c'est une syntaxe ad hoc
1184 1184
 
1185 1185
 function spip_pg_cite($v, $t) {
1186
-	if (is_null($v)) {
1187
-		return 'NULL';
1188
-	} // null php se traduit en NULL SQL
1189
-
1190
-	if (sql_test_date($t)) {
1191
-		if ($v and (strpos('0123456789', (string) $v[0]) === false)) {
1192
-			return spip_pg_frommysql($v);
1193
-		} else {
1194
-			if (strncmp($v, '0000', 4) == 0) {
1195
-				$v = '0001' . substr($v, 4);
1196
-			}
1197
-			if (strpos($v, '-00-00') === 4) {
1198
-				$v = substr($v, 0, 4) . '-01-01' . substr($v, 10);
1199
-			}
1200
-
1201
-			return "timestamp '$v'";
1202
-		}
1203
-	} elseif (!sql_test_int($t)) {
1204
-		return ("'" . pg_escape_string($v) . "'");
1205
-	} elseif (is_numeric($v) or (strpos($v, 'CAST(') === 0)) {
1206
-		return $v;
1207
-	} elseif ($v[0] == '0' and $v[1] !== 'x' and ctype_xdigit(substr($v, 1))) {
1208
-		return substr($v, 1);
1209
-	} else {
1210
-		spip_log("Warning: '$v'  n'est pas de type $t", 'pg.' . _LOG_AVERTISSEMENT);
1211
-
1212
-		return intval($v);
1213
-	}
1186
+    if (is_null($v)) {
1187
+        return 'NULL';
1188
+    } // null php se traduit en NULL SQL
1189
+
1190
+    if (sql_test_date($t)) {
1191
+        if ($v and (strpos('0123456789', (string) $v[0]) === false)) {
1192
+            return spip_pg_frommysql($v);
1193
+        } else {
1194
+            if (strncmp($v, '0000', 4) == 0) {
1195
+                $v = '0001' . substr($v, 4);
1196
+            }
1197
+            if (strpos($v, '-00-00') === 4) {
1198
+                $v = substr($v, 0, 4) . '-01-01' . substr($v, 10);
1199
+            }
1200
+
1201
+            return "timestamp '$v'";
1202
+        }
1203
+    } elseif (!sql_test_int($t)) {
1204
+        return ("'" . pg_escape_string($v) . "'");
1205
+    } elseif (is_numeric($v) or (strpos($v, 'CAST(') === 0)) {
1206
+        return $v;
1207
+    } elseif ($v[0] == '0' and $v[1] !== 'x' and ctype_xdigit(substr($v, 1))) {
1208
+        return substr($v, 1);
1209
+    } else {
1210
+        spip_log("Warning: '$v'  n'est pas de type $t", 'pg.' . _LOG_AVERTISSEMENT);
1211
+
1212
+        return intval($v);
1213
+    }
1214 1214
 }
1215 1215
 
1216 1216
 function spip_pg_hex($v) {
1217
-	return "CAST(x'" . $v . "' as bigint)";
1217
+    return "CAST(x'" . $v . "' as bigint)";
1218 1218
 }
1219 1219
 
1220 1220
 function spip_pg_quote($v, $type = '') {
1221
-	if (!is_array($v)) {
1222
-		return spip_pg_cite($v, $type);
1223
-	}
1224
-	// si c'est un tableau, le parcourir en propageant le type
1225
-	foreach ($v as $k => $r) {
1226
-		$v[$k] = spip_pg_quote($r, $type);
1227
-	}
1228
-
1229
-	return join(',', $v);
1221
+    if (!is_array($v)) {
1222
+        return spip_pg_cite($v, $type);
1223
+    }
1224
+    // si c'est un tableau, le parcourir en propageant le type
1225
+    foreach ($v as $k => $r) {
1226
+        $v[$k] = spip_pg_quote($r, $type);
1227
+    }
1228
+
1229
+    return join(',', $v);
1230 1230
 }
1231 1231
 
1232 1232
 function spip_pg_date_proche($champ, $interval, $unite) {
1233
-	return '('
1234
-	. $champ
1235
-	. (($interval <= 0) ? '>' : '<')
1236
-	. (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD')
1237
-	. '('
1238
-	. sql_quote(date('Y-m-d H:i:s'))
1239
-	. ', INTERVAL '
1240
-	. (($interval > 0) ? $interval : (0 - $interval))
1241
-	. ' '
1242
-	. $unite
1243
-	. '))';
1233
+    return '('
1234
+    . $champ
1235
+    . (($interval <= 0) ? '>' : '<')
1236
+    . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD')
1237
+    . '('
1238
+    . sql_quote(date('Y-m-d H:i:s'))
1239
+    . ', INTERVAL '
1240
+    . (($interval > 0) ? $interval : (0 - $interval))
1241
+    . ' '
1242
+    . $unite
1243
+    . '))';
1244 1244
 }
1245 1245
 
1246 1246
 function spip_pg_in($val, $valeurs, $not = '', $serveur = '') {
1247 1247
 //
1248 1248
 // IN (...) souvent limite a 255  elements, d'ou cette fonction assistante
1249 1249
 //
1250
-	// s'il n'y a pas de valeur, eviter de produire un IN vide: PG rale.
1251
-	if (!$valeurs) {
1252
-		return $not ? '0=0' : '0=1';
1253
-	}
1254
-	if (strpos($valeurs, "CAST(x'") !== false) {
1255
-		return "($val=" . join("OR $val=", explode(',', $valeurs)) . ')';
1256
-	}
1257
-	$n = $i = 0;
1258
-	$in_sql = '';
1259
-	while ($n = strpos($valeurs, ',', $n + 1)) {
1260
-		if ((++$i) >= 255) {
1261
-			$in_sql .= "($val $not IN (" .
1262
-				substr($valeurs, 0, $n) .
1263
-				"))\n" .
1264
-				($not ? "AND\t" : "OR\t");
1265
-			$valeurs = substr($valeurs, $n + 1);
1266
-			$i = $n = 0;
1267
-		}
1268
-	}
1269
-	$in_sql .= "($val $not IN ($valeurs))";
1270
-
1271
-	return "($in_sql)";
1250
+    // s'il n'y a pas de valeur, eviter de produire un IN vide: PG rale.
1251
+    if (!$valeurs) {
1252
+        return $not ? '0=0' : '0=1';
1253
+    }
1254
+    if (strpos($valeurs, "CAST(x'") !== false) {
1255
+        return "($val=" . join("OR $val=", explode(',', $valeurs)) . ')';
1256
+    }
1257
+    $n = $i = 0;
1258
+    $in_sql = '';
1259
+    while ($n = strpos($valeurs, ',', $n + 1)) {
1260
+        if ((++$i) >= 255) {
1261
+            $in_sql .= "($val $not IN (" .
1262
+                substr($valeurs, 0, $n) .
1263
+                "))\n" .
1264
+                ($not ? "AND\t" : "OR\t");
1265
+            $valeurs = substr($valeurs, $n + 1);
1266
+            $i = $n = 0;
1267
+        }
1268
+    }
1269
+    $in_sql .= "($val $not IN ($valeurs))";
1270
+
1271
+    return "($in_sql)";
1272 1272
 }
1273 1273
 
1274 1274
 function spip_pg_error($query = '', $serveur = '', $requeter = true) {
1275
-	$link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link'];
1276
-	$s = $link ? pg_last_error($link) : pg_last_error();
1277
-	if ($s) {
1278
-		$s = str_replace('ERROR', 'errcode: 1000 ', $s);
1279
-		spip_log("$s - $query", 'pg.' . _LOG_ERREUR);
1280
-	}
1281
-
1282
-	return $s;
1275
+    $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link'];
1276
+    $s = $link ? pg_last_error($link) : pg_last_error();
1277
+    if ($s) {
1278
+        $s = str_replace('ERROR', 'errcode: 1000 ', $s);
1279
+        spip_log("$s - $query", 'pg.' . _LOG_ERREUR);
1280
+    }
1281
+
1282
+    return $s;
1283 1283
 }
1284 1284
 
1285 1285
 function spip_pg_errno($serveur = '') {
1286
-	// il faudrait avoir la derniere ressource retournee et utiliser
1287
-	// http://fr2.php.net/manual/fr/function.pg-result-error.php
1288
-	return 0;
1286
+    // il faudrait avoir la derniere ressource retournee et utiliser
1287
+    // http://fr2.php.net/manual/fr/function.pg-result-error.php
1288
+    return 0;
1289 1289
 }
1290 1290
 
1291 1291
 function spip_pg_drop_table($table, $exist = '', $serveur = '', $requeter = true) {
1292
-	if ($exist) {
1293
-		$exist = ' IF EXISTS';
1294
-	}
1295
-	if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) {
1296
-		return true;
1297
-	} else {
1298
-		return false;
1299
-	}
1292
+    if ($exist) {
1293
+        $exist = ' IF EXISTS';
1294
+    }
1295
+    if (spip_pg_query("DROP TABLE$exist $table", $serveur, $requeter)) {
1296
+        return true;
1297
+    } else {
1298
+        return false;
1299
+    }
1300 1300
 }
1301 1301
 
1302 1302
 // supprime une vue
1303 1303
 function spip_pg_drop_view($view, $exist = '', $serveur = '', $requeter = true) {
1304
-	if ($exist) {
1305
-		$exist = ' IF EXISTS';
1306
-	}
1304
+    if ($exist) {
1305
+        $exist = ' IF EXISTS';
1306
+    }
1307 1307
 
1308
-	return spip_pg_query("DROP VIEW$exist $view", $serveur, $requeter);
1308
+    return spip_pg_query("DROP VIEW$exist $view", $serveur, $requeter);
1309 1309
 }
1310 1310
 
1311 1311
 /**
@@ -1322,40 +1322,40 @@  discard block
 block discarded – undo
1322 1322
  *     Ressource à utiliser avec sql_fetch()
1323 1323
  **/
1324 1324
 function spip_pg_showbase($match, $serveur = '', $requeter = true) {
1325
-	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
1326
-	$link = $connexion['link'];
1327
-	$connexion['last'] = $q = 'SELECT tablename FROM pg_tables WHERE tablename ILIKE ' . _q($match);
1325
+    $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
1326
+    $link = $connexion['link'];
1327
+    $connexion['last'] = $q = 'SELECT tablename FROM pg_tables WHERE tablename ILIKE ' . _q($match);
1328 1328
 
1329
-	return spip_pg_query_simple($link, $q);
1329
+    return spip_pg_query_simple($link, $q);
1330 1330
 }
1331 1331
 
1332 1332
 function spip_pg_showtable($nom_table, $serveur = '', $requeter = true) {
1333
-	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
1334
-	$link = $connexion['link'];
1335
-	$connexion['last'] = $q = 'SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE ' . _q($nom_table);
1336
-
1337
-	$res = spip_pg_query_simple($link, $q);
1338
-	if (!$res) {
1339
-		return false;
1340
-	}
1341
-
1342
-	// etrangement, $res peut ne rien contenir, mais arriver ici...
1343
-	// il faut en tenir compte dans le return
1344
-	$fields = [];
1345
-	while ($field = pg_fetch_array($res, null, PGSQL_NUM)) {
1346
-		$fields[$field[0]] = $field[2] . (!$field[1] ? '' : (' DEFAULT ' . $field[1]));
1347
-	}
1348
-	$connexion['last'] = $q = 'SELECT indexdef FROM pg_indexes WHERE tablename ILIKE ' . _q($nom_table);
1349
-	$res = spip_pg_query_simple($link, $q);
1350
-	$keys = [];
1351
-	while ($index = pg_fetch_array($res, null, PGSQL_NUM)) {
1352
-		if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0], $r)) {
1353
-			$nom = str_replace($nom_table . '_', '', $r[2]);
1354
-			$keys[($r[1] ? 'PRIMARY KEY' : ('KEY ' . $nom))] = $r[3];
1355
-		}
1356
-	}
1357
-
1358
-	return count($fields) ? ['field' => $fields, 'key' => $keys] : false;
1333
+    $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
1334
+    $link = $connexion['link'];
1335
+    $connexion['last'] = $q = 'SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE ' . _q($nom_table);
1336
+
1337
+    $res = spip_pg_query_simple($link, $q);
1338
+    if (!$res) {
1339
+        return false;
1340
+    }
1341
+
1342
+    // etrangement, $res peut ne rien contenir, mais arriver ici...
1343
+    // il faut en tenir compte dans le return
1344
+    $fields = [];
1345
+    while ($field = pg_fetch_array($res, null, PGSQL_NUM)) {
1346
+        $fields[$field[0]] = $field[2] . (!$field[1] ? '' : (' DEFAULT ' . $field[1]));
1347
+    }
1348
+    $connexion['last'] = $q = 'SELECT indexdef FROM pg_indexes WHERE tablename ILIKE ' . _q($nom_table);
1349
+    $res = spip_pg_query_simple($link, $q);
1350
+    $keys = [];
1351
+    while ($index = pg_fetch_array($res, null, PGSQL_NUM)) {
1352
+        if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0], $r)) {
1353
+            $nom = str_replace($nom_table . '_', '', $r[2]);
1354
+            $keys[($r[1] ? 'PRIMARY KEY' : ('KEY ' . $nom))] = $r[3];
1355
+        }
1356
+    }
1357
+
1358
+    return count($fields) ? ['field' => $fields, 'key' => $keys] : false;
1359 1359
 }
1360 1360
 
1361 1361
 // Fonction de creation d'une table SQL nommee $nom
@@ -1366,116 +1366,116 @@  discard block
 block discarded – undo
1366 1366
 // Le nom des index est prefixe par celui de la table pour eviter les conflits
1367 1367
 function spip_pg_create($nom, $champs, $cles, $autoinc = false, $temporary = false, $serveur = '', $requeter = true) {
1368 1368
 
1369
-	$connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
1370
-	$link = $connexion['link'];
1371
-	$nom = prefixer_table_spip($nom, $connexion['prefixe']);
1372
-
1373
-	$query = $prim = $prim_name = $v = $s = $p = '';
1374
-	$keys = [];
1375
-
1376
-	// certains plugins declarent les tables  (permet leur inclusion dans le dump)
1377
-	// sans les renseigner (laisse le compilo recuperer la description)
1378
-	if (!is_array($champs) || !is_array($cles)) {
1379
-		return;
1380
-	}
1381
-
1382
-	foreach ($cles as $k => $v) {
1383
-		if (strpos($k, 'KEY ') === 0) {
1384
-			$n = str_replace('`', '', $k);
1385
-			$v = str_replace('`', '"', $v);
1386
-			$i = $nom . preg_replace('/KEY +/', '_', $n);
1387
-			if ($k != $n) {
1388
-				$i = "\"$i\"";
1389
-			}
1390
-			$keys[] = "CREATE INDEX $i ON $nom ($v);";
1391
-		} elseif (strpos($k, 'UNIQUE ') === 0) {
1392
-			$k = preg_replace('/^UNIQUE +/', '', $k);
1393
-			$prim .= "$s\n\t\tCONSTRAINT " . str_replace('`', '"', $k) . " UNIQUE ($v)";
1394
-		} else {
1395
-			$prim .= "$s\n\t\t" . str_replace('`', '"', $k) . " ($v)";
1396
-		}
1397
-		if ($k == 'PRIMARY KEY') {
1398
-			$prim_name = $v;
1399
-		}
1400
-		$s = ',';
1401
-	}
1402
-	$s = '';
1403
-
1404
-	$character_set = '';
1405
-	if (@$GLOBALS['meta']['charset_sql_base']) {
1406
-		$character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base'];
1407
-	}
1408
-	if (@$GLOBALS['meta']['charset_collation_sql_base']) {
1409
-		$character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base'];
1410
-	}
1411
-
1412
-	foreach ($champs as $k => $v) {
1413
-		$k = str_replace('`', '"', $k);
1414
-		if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) {
1415
-			if (preg_match(',(char|text),i', $defs[1]) and !preg_match(',binary,i', $defs[1])) {
1416
-				$v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1]));
1417
-			}
1418
-		}
1419
-
1420
-		$query .= "$s\n\t\t$k "
1421
-			. (($autoinc && ($prim_name == $k) && preg_match(',\b(big|small|medium|tiny)?int\b,i', $v))
1422
-				? ' bigserial'
1423
-				: mysql2pg_type($v)
1424
-			);
1425
-		$s = ',';
1426
-	}
1427
-	$temporary = $temporary ? 'TEMPORARY' : '';
1428
-
1429
-	// En l'absence de "if not exists" en PG, on neutralise les erreurs
1430
-
1431
-	$q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ')' .
1432
-		($character_set ? " DEFAULT $character_set" : '')
1433
-		. "\n";
1434
-
1435
-	if (!$requeter) {
1436
-		return $q;
1437
-	}
1438
-	$connexion['last'] = $q;
1439
-	$r = @pg_query($link, $q);
1440
-
1441
-	if (!$r) {
1442
-		spip_log("Impossible de creer cette table: $q", 'pg.' . _LOG_ERREUR);
1443
-	} else {
1444
-		foreach ($keys as $index) {
1445
-			pg_query($link, $index);
1446
-		}
1447
-	}
1448
-
1449
-	return $r;
1369
+    $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
1370
+    $link = $connexion['link'];
1371
+    $nom = prefixer_table_spip($nom, $connexion['prefixe']);
1372
+
1373
+    $query = $prim = $prim_name = $v = $s = $p = '';
1374
+    $keys = [];
1375
+
1376
+    // certains plugins declarent les tables  (permet leur inclusion dans le dump)
1377
+    // sans les renseigner (laisse le compilo recuperer la description)
1378
+    if (!is_array($champs) || !is_array($cles)) {
1379
+        return;
1380
+    }
1381
+
1382
+    foreach ($cles as $k => $v) {
1383
+        if (strpos($k, 'KEY ') === 0) {
1384
+            $n = str_replace('`', '', $k);
1385
+            $v = str_replace('`', '"', $v);
1386
+            $i = $nom . preg_replace('/KEY +/', '_', $n);
1387
+            if ($k != $n) {
1388
+                $i = "\"$i\"";
1389
+            }
1390
+            $keys[] = "CREATE INDEX $i ON $nom ($v);";
1391
+        } elseif (strpos($k, 'UNIQUE ') === 0) {
1392
+            $k = preg_replace('/^UNIQUE +/', '', $k);
1393
+            $prim .= "$s\n\t\tCONSTRAINT " . str_replace('`', '"', $k) . " UNIQUE ($v)";
1394
+        } else {
1395
+            $prim .= "$s\n\t\t" . str_replace('`', '"', $k) . " ($v)";
1396
+        }
1397
+        if ($k == 'PRIMARY KEY') {
1398
+            $prim_name = $v;
1399
+        }
1400
+        $s = ',';
1401
+    }
1402
+    $s = '';
1403
+
1404
+    $character_set = '';
1405
+    if (@$GLOBALS['meta']['charset_sql_base']) {
1406
+        $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base'];
1407
+    }
1408
+    if (@$GLOBALS['meta']['charset_collation_sql_base']) {
1409
+        $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base'];
1410
+    }
1411
+
1412
+    foreach ($champs as $k => $v) {
1413
+        $k = str_replace('`', '"', $k);
1414
+        if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) {
1415
+            if (preg_match(',(char|text),i', $defs[1]) and !preg_match(',binary,i', $defs[1])) {
1416
+                $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1]));
1417
+            }
1418
+        }
1419
+
1420
+        $query .= "$s\n\t\t$k "
1421
+            . (($autoinc && ($prim_name == $k) && preg_match(',\b(big|small|medium|tiny)?int\b,i', $v))
1422
+                ? ' bigserial'
1423
+                : mysql2pg_type($v)
1424
+            );
1425
+        $s = ',';
1426
+    }
1427
+    $temporary = $temporary ? 'TEMPORARY' : '';
1428
+
1429
+    // En l'absence de "if not exists" en PG, on neutralise les erreurs
1430
+
1431
+    $q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ')' .
1432
+        ($character_set ? " DEFAULT $character_set" : '')
1433
+        . "\n";
1434
+
1435
+    if (!$requeter) {
1436
+        return $q;
1437
+    }
1438
+    $connexion['last'] = $q;
1439
+    $r = @pg_query($link, $q);
1440
+
1441
+    if (!$r) {
1442
+        spip_log("Impossible de creer cette table: $q", 'pg.' . _LOG_ERREUR);
1443
+    } else {
1444
+        foreach ($keys as $index) {
1445
+            pg_query($link, $index);
1446
+        }
1447
+    }
1448
+
1449
+    return $r;
1450 1450
 }
1451 1451
 
1452 1452
 
1453 1453
 function spip_pg_create_base($nom, $serveur = '', $requeter = true) {
1454
-	return spip_pg_query("CREATE DATABASE $nom", $serveur, $requeter);
1454
+    return spip_pg_query("CREATE DATABASE $nom", $serveur, $requeter);
1455 1455
 }
1456 1456
 
1457 1457
 // Fonction de creation d'une vue SQL nommee $nom
1458 1458
 function spip_pg_create_view($nom, $query_select, $serveur = '', $requeter = true) {
1459
-	if (!$query_select) {
1460
-		return false;
1461
-	}
1462
-	// vue deja presente
1463
-	if (sql_showtable($nom, false, $serveur)) {
1464
-		if ($requeter) {
1465
-			spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.' . _LOG_ERREUR);
1466
-		}
1459
+    if (!$query_select) {
1460
+        return false;
1461
+    }
1462
+    // vue deja presente
1463
+    if (sql_showtable($nom, false, $serveur)) {
1464
+        if ($requeter) {
1465
+            spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.' . _LOG_ERREUR);
1466
+        }
1467 1467
 
1468
-		return false;
1469
-	}
1468
+        return false;
1469
+    }
1470 1470
 
1471
-	$query = "CREATE VIEW $nom AS " . $query_select;
1471
+    $query = "CREATE VIEW $nom AS " . $query_select;
1472 1472
 
1473
-	return spip_pg_query($query, $serveur, $requeter);
1473
+    return spip_pg_query($query, $serveur, $requeter);
1474 1474
 }
1475 1475
 
1476 1476
 
1477 1477
 function spip_pg_set_connect_charset($charset, $serveur = '', $requeter = true) {
1478
-	spip_log('changement de charset sql a ecrire en PG', 'pg.' . _LOG_ERREUR);
1478
+    spip_log('changement de charset sql a ecrire en PG', 'pg.' . _LOG_ERREUR);
1479 1479
 }
1480 1480
 
1481 1481
 
@@ -1488,50 +1488,50 @@  discard block
 block discarded – undo
1488 1488
  * @return bool|string true / false / requete
1489 1489
  **/
1490 1490
 function spip_pg_optimize($table, $serveur = '', $requeter = true) {
1491
-	return spip_pg_query('VACUUM ' . $table, $serveur, $requeter);
1491
+    return spip_pg_query('VACUUM ' . $table, $serveur, $requeter);
1492 1492
 }
1493 1493
 
1494 1494
 // Selectionner la sous-chaine dans $objet
1495 1495
 // correspondant a $lang. Cf balise Multi de Spip
1496 1496
 
1497 1497
 function spip_pg_multi($objet, $lang) {
1498
-	$r = 'regexp_replace('
1499
-		. $objet
1500
-		. ",'<multi>.*[[]"
1501
-		. $lang
1502
-		. "[]]([^[]*).*</multi>', E'\\\\1') AS multi";
1498
+    $r = 'regexp_replace('
1499
+        . $objet
1500
+        . ",'<multi>.*[[]"
1501
+        . $lang
1502
+        . "[]]([^[]*).*</multi>', E'\\\\1') AS multi";
1503 1503
 
1504
-	return $r;
1504
+    return $r;
1505 1505
 }
1506 1506
 
1507 1507
 // Palanquee d'idiosyncrasies MySQL dans les creations de table
1508 1508
 // A completer par les autres, mais essayer de reduire en amont.
1509 1509
 
1510 1510
 function mysql2pg_type($v) {
1511
-	$remplace = [
1512
-		'/auto_increment/i' => '', // non reconnu
1513
-		'/bigint/i' => 'bigint',
1514
-		'/mediumint/i' => 'mediumint',
1515
-		'/smallint/i' => 'smallint',
1516
-		'/tinyint/i' => 'int',
1517
-		'/int\s*[(]\s*\d+\s*[)]/i' => 'int',
1518
-		'/longtext/i' => 'text',
1519
-		'/mediumtext/i' => 'text',
1520
-		'/tinytext/i' => 'text',
1521
-		'/longblob/i' => 'text',
1522
-		'/0000-00-00/' => '0001-01-01',
1523
-		'/datetime/i' => 'timestamp',
1524
-		'/unsigned/i' => '',
1525
-		'/double/i' => 'double precision',
1526
-		'/VARCHAR\((\d+)\)\s+BINARY/i' => 'varchar(\1)',
1527
-		'/ENUM *[(][^)]*[)]/i' => 'varchar(255)',
1528
-		'/(timestamp .* )ON .*$/is' => '\\1',
1529
-	];
1530
-
1531
-	return preg_replace(array_keys($remplace), array_values($remplace), $v);
1511
+    $remplace = [
1512
+        '/auto_increment/i' => '', // non reconnu
1513
+        '/bigint/i' => 'bigint',
1514
+        '/mediumint/i' => 'mediumint',
1515
+        '/smallint/i' => 'smallint',
1516
+        '/tinyint/i' => 'int',
1517
+        '/int\s*[(]\s*\d+\s*[)]/i' => 'int',
1518
+        '/longtext/i' => 'text',
1519
+        '/mediumtext/i' => 'text',
1520
+        '/tinytext/i' => 'text',
1521
+        '/longblob/i' => 'text',
1522
+        '/0000-00-00/' => '0001-01-01',
1523
+        '/datetime/i' => 'timestamp',
1524
+        '/unsigned/i' => '',
1525
+        '/double/i' => 'double precision',
1526
+        '/VARCHAR\((\d+)\)\s+BINARY/i' => 'varchar(\1)',
1527
+        '/ENUM *[(][^)]*[)]/i' => 'varchar(255)',
1528
+        '/(timestamp .* )ON .*$/is' => '\\1',
1529
+    ];
1530
+
1531
+    return preg_replace(array_keys($remplace), array_values($remplace), $v);
1532 1532
 }
1533 1533
 
1534 1534
 // Renvoie false si on n'a pas les fonctions pg (pour l'install)
1535 1535
 function spip_versions_pg() {
1536
-	return function_exists('pg_connect');
1536
+    return function_exists('pg_connect');
1537 1537
 }
Please login to merge, or discard this patch.
Spacing   +83 added lines, -84 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	if (!$link) {
65 65
 		$erreurs[] = pg_last_error();
66 66
 		foreach ($erreurs as $e) {
67
-			spip_log('Echec pg_connect. Erreur : ' . $e, 'pg.' . _LOG_HS);
67
+			spip_log('Echec pg_connect. Erreur : '.$e, 'pg.'._LOG_HS);
68 68
 		}
69 69
 
70 70
 		return false;
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
 	}
83 83
 
84 84
 	spip_log(
85
-		"Connexion vers $host, base $db, prefixe $prefixe " . ($link ? 'operationnelle' : 'impossible'),
86
-		'pg.' . _LOG_DEBUG
85
+		"Connexion vers $host, base $db, prefixe $prefixe ".($link ? 'operationnelle' : 'impossible'),
86
+		'pg.'._LOG_DEBUG
87 87
 	);
88 88
 
89 89
 	return !$link ? false : [
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 	} else {
172 172
 		$suite = '';
173 173
 	}
174
-	$query = preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite;
174
+	$query = preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query).$suite;
175 175
 
176 176
 	// renvoyer la requete inerte si demandee
177 177
 	if (!$requeter) {
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	// ou revoir l'api de sql_alter en creant un
240 240
 	// sql_alter_table($table,array($actions));
241 241
 	if (!preg_match('/\s*((\s*IGNORE)?\s*TABLE\s*([^\s]*))\s*(.*)?/is', $query, $regs)) {
242
-		spip_log("$query mal comprise", 'pg.' . _LOG_ERREUR);
242
+		spip_log("$query mal comprise", 'pg.'._LOG_ERREUR);
243 243
 
244 244
 		return false;
245 245
 	}
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	$i = 0;
253 253
 	$ouverte = false;
254 254
 	while ($do = array_shift($todo)) {
255
-		$todo2[$i] = isset($todo2[$i]) ? $todo2[$i] . ',' . $do : $do;
255
+		$todo2[$i] = isset($todo2[$i]) ? $todo2[$i].','.$do : $do;
256 256
 		$o = (false !== strpos($do, '('));
257 257
 		$f = (false !== strpos($do, ')'));
258 258
 		if ($o and !$f) {
@@ -265,33 +265,33 @@  discard block
 block discarded – undo
265 265
 		}
266 266
 	}
267 267
 	$todo = $todo2;
268
-	$query = $debut . ' ' . array_shift($todo);
268
+	$query = $debut.' '.array_shift($todo);
269 269
 
270 270
 	if (!preg_match('/^\s*(IGNORE\s*)?TABLE\s+(\w+)\s+(ADD|DROP|CHANGE|MODIFY|RENAME)\s*(.*)$/is', $query, $r)) {
271
-		spip_log("$query incompris", 'pg.' . _LOG_ERREUR);
271
+		spip_log("$query incompris", 'pg.'._LOG_ERREUR);
272 272
 	} else {
273 273
 		if ($r[1]) {
274
-			spip_log("j'ignore IGNORE dans $query", 'pg.' . _LOG_AVERTISSEMENT);
274
+			spip_log("j'ignore IGNORE dans $query", 'pg.'._LOG_AVERTISSEMENT);
275 275
 		}
276
-		$f = 'spip_pg_alter_' . strtolower($r[3]);
276
+		$f = 'spip_pg_alter_'.strtolower($r[3]);
277 277
 		if (function_exists($f)) {
278 278
 			$f($r[2], $r[4], $serveur, $requeter);
279 279
 		} else {
280
-			spip_log("$query non prevu", 'pg.' . _LOG_ERREUR);
280
+			spip_log("$query non prevu", 'pg.'._LOG_ERREUR);
281 281
 		}
282 282
 	}
283 283
 	// Alter a plusieurs args. Faudrait optimiser.
284 284
 	if ($todo) {
285
-		spip_pg_alter("TABLE $table " . join(',', $todo));
285
+		spip_pg_alter("TABLE $table ".join(',', $todo));
286 286
 	}
287 287
 }
288 288
 
289 289
 function spip_pg_alter_change($table, $arg, $serveur = '', $requeter = true) {
290 290
 	if (!preg_match('/^`?(\w+)`?\s+`?(\w+)`?\s+(.*?)\s*(DEFAULT .*?)?(NOT\s+NULL)?\s*(DEFAULT .*?)?$/i', $arg, $r)) {
291
-		spip_log("alter change: $arg  incompris", 'pg.' . _LOG_ERREUR);
291
+		spip_log("alter change: $arg  incompris", 'pg.'._LOG_ERREUR);
292 292
 	} else {
293 293
 		[, $old, $new, $type, $default, $null, $def2] = $r;
294
-		$actions = ["ALTER $old TYPE " . mysql2pg_type($type)];
294
+		$actions = ["ALTER $old TYPE ".mysql2pg_type($type)];
295 295
 		if ($null) {
296 296
 			$actions[] = "ALTER $old SET NOT NULL";
297 297
 		} else {
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 			$actions[] = "ALTER $old DROP DEFAULT";
305 305
 		}
306 306
 
307
-		spip_pg_query("ALTER TABLE $table " . join(', ', $actions));
307
+		spip_pg_query("ALTER TABLE $table ".join(', ', $actions));
308 308
 
309 309
 		if ($old != $new) {
310 310
 			spip_pg_query("ALTER TABLE $table RENAME $old TO $new", $serveur);
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 function spip_pg_alter_add($table, $arg, $serveur = '', $requeter = true) {
316 316
 	$nom_index = null;
317 317
 	if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*(.*)$/', $arg, $r)) {
318
-		spip_log("alter add $arg  incompris", 'pg.' . _LOG_ERREUR);
318
+		spip_log("alter add $arg  incompris", 'pg.'._LOG_ERREUR);
319 319
 
320 320
 		return null;
321 321
 	}
@@ -325,14 +325,14 @@  discard block
 block discarded – undo
325 325
 			$m[2] = $n[1];
326 326
 		}
327 327
 
328
-		return spip_pg_query("ALTER TABLE $table ADD " . $m[1] . ' ' . mysql2pg_type($m[2]), $serveur, $requeter);
328
+		return spip_pg_query("ALTER TABLE $table ADD ".$m[1].' '.mysql2pg_type($m[2]), $serveur, $requeter);
329 329
 	} elseif ($r[1][0] == 'P') {
330 330
 		// la primary peut etre sur plusieurs champs
331 331
 		$r[2] = trim(str_replace('`', '', $r[2]));
332 332
 		$m = ($r[2][0] == '(') ? substr($r[2], 1, -1) : $r[2];
333 333
 
334 334
 		return spip_pg_query(
335
-			"ALTER TABLE $table ADD CONSTRAINT $table" . '_pkey PRIMARY KEY (' . $m . ')',
335
+			"ALTER TABLE $table ADD CONSTRAINT $table".'_pkey PRIMARY KEY ('.$m.')',
336 336
 			$serveur,
337 337
 			$requeter
338 338
 		);
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 				$colonnes = substr($m[1], 1, -1);
352 352
 				if (false !== strpos(',', $colonnes)) {
353 353
 					spip_log('PG : Erreur, impossible de creer un index sur plusieurs colonnes'
354
-						. " sans qu'il ait de nom ($table, ($colonnes))", 'pg.' . _LOG_ERREUR);
354
+						. " sans qu'il ait de nom ($table, ($colonnes))", 'pg.'._LOG_ERREUR);
355 355
 				} else {
356 356
 					$nom_index = $colonnes;
357 357
 				}
@@ -367,23 +367,23 @@  discard block
 block discarded – undo
367 367
 
368 368
 function spip_pg_alter_drop($table, $arg, $serveur = '', $requeter = true) {
369 369
 	if (!preg_match('/^(COLUMN|INDEX|KEY|PRIMARY\s+KEY|)\s*`?(\w*)`?/', $arg, $r)) {
370
-		spip_log("alter drop: $arg  incompris", 'pg.' . _LOG_ERREUR);
370
+		spip_log("alter drop: $arg  incompris", 'pg.'._LOG_ERREUR);
371 371
 	} else {
372 372
 		if (!$r[1] or $r[1] == 'COLUMN') {
373
-			return spip_pg_query("ALTER TABLE $table DROP " . $r[2], $serveur);
373
+			return spip_pg_query("ALTER TABLE $table DROP ".$r[2], $serveur);
374 374
 		} elseif ($r[1][0] == 'P') {
375
-			return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table" . '_pkey', $serveur);
375
+			return spip_pg_query("ALTER TABLE $table DROP CONSTRAINT $table".'_pkey', $serveur);
376 376
 		} else {
377
-			return spip_pg_query('DROP INDEX ' . $table . '_' . $r[2], $serveur);
377
+			return spip_pg_query('DROP INDEX '.$table.'_'.$r[2], $serveur);
378 378
 		}
379 379
 	}
380 380
 }
381 381
 
382 382
 function spip_pg_alter_modify($table, $arg, $serveur = '', $requeter = true) {
383 383
 	if (!preg_match('/^`?(\w+)`?\s+(.*)$/', $arg, $r)) {
384
-		spip_log("alter modify: $arg  incompris", 'pg.' . _LOG_ERREUR);
384
+		spip_log("alter modify: $arg  incompris", 'pg.'._LOG_ERREUR);
385 385
 	} else {
386
-		return spip_pg_alter_change($table, $r[1] . ' ' . $arg, $serveur = '', $requeter = true);
386
+		return spip_pg_alter_change($table, $r[1].' '.$arg, $serveur = '', $requeter = true);
387 387
 	}
388 388
 }
389 389
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 	} elseif (preg_match('/^(TO)\s*`?(\w*)`?/', $arg, $r)) {
400 400
 		$rename = $r[2];
401 401
 	} else {
402
-		spip_log("alter rename: $arg  incompris", 'pg.' . _LOG_ERREUR);
402
+		spip_log("alter rename: $arg  incompris", 'pg.'._LOG_ERREUR);
403 403
 	}
404 404
 
405 405
 	return $rename ? spip_pg_query("ALTER TABLE $table RENAME TO $rename") : false;
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
 function spip_pg_create_index($nom, $table, $champs, $serveur = '', $requeter = true) {
421 421
 	if (!($nom or $table or $champs)) {
422 422
 		spip_log(
423
-			"Champ manquant pour creer un index pg ($nom, $table, (" . @join(',', $champs) . '))',
424
-			'pg.' . _LOG_ERREUR
423
+			"Champ manquant pour creer un index pg ($nom, $table, (".@join(',', $champs).'))',
424
+			'pg.'._LOG_ERREUR
425 425
 		);
426 426
 
427 427
 		return false;
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 
433 433
 	// PG ne differentie pas noms des index en fonction des tables
434 434
 	// il faut donc creer des noms uniques d'index pour une base pg
435
-	$nom = $table . '_' . $nom;
435
+	$nom = $table.'_'.$nom;
436 436
 	// enlever d'eventuelles parentheses deja presentes sur champs
437 437
 	if (!is_array($champs)) {
438 438
 		if ($champs[0] == '(') {
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 		}
441 441
 		$champs = [$champs];
442 442
 	}
443
-	$query = "CREATE INDEX $nom ON $table (" . join(',', $champs) . ')';
443
+	$query = "CREATE INDEX $nom ON $table (".join(',', $champs).')';
444 444
 	if (!$requeter) {
445 445
 		return $query;
446 446
 	}
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
 	} else {
464 464
 		$suite = '';
465 465
 	}
466
-	$query = 'EXPLAIN ' . preg_replace('/([,\s])spip_/', '\1' . $prefixe . '_', $query) . $suite;
466
+	$query = 'EXPLAIN '.preg_replace('/([,\s])spip_/', '\1'.$prefixe.'_', $query).$suite;
467 467
 
468 468
 	if (!$requeter) {
469 469
 		return $query;
@@ -556,16 +556,16 @@  discard block
 block discarded – undo
556 556
 		}
557 557
 	}
558 558
 	$from = spip_pg_from($from, $prefixe);
559
-	$query = 'SELECT ' . $select
559
+	$query = 'SELECT '.$select
560 560
 		. (!$from ? '' : "\nFROM $from")
561
-		. (!$where ? '' : ("\nWHERE " . (!is_array($where) ? calculer_pg_where($where) : (join(
561
+		. (!$where ? '' : ("\nWHERE ".(!is_array($where) ? calculer_pg_where($where) : (join(
562 562
 			"\n\tAND ",
563 563
 			array_map('calculer_pg_where', $where)
564 564
 		)))))
565 565
 		. spip_pg_groupby($groupby, $from, $select)
566 566
 		. (!$having ? '' : "\nHAVING $having")
567 567
 		. ($orderby ? ("\nORDER BY $orderby") : '')
568
-		. (!$limit ? '' : (" LIMIT $count" . (!$offset ? '' : " OFFSET $offset")));
568
+		. (!$limit ? '' : (" LIMIT $count".(!$offset ? '' : " OFFSET $offset")));
569 569
 
570 570
 	// renvoyer la requete inerte si demandee
571 571
 	if ($requeter === false) {
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 		$from = spip_pg_select_as($from);
587 587
 	}
588 588
 
589
-	return !$prefixe ? $from : preg_replace('/(\b)spip_/', '\1' . $prefixe . '_', $from);
589
+	return !$prefixe ? $from : preg_replace('/(\b)spip_/', '\1'.$prefixe.'_', $from);
590 590
 }
591 591
 
592 592
 function spip_pg_orderby($order, $select) {
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 	$arg = (is_array($order) ? $order : preg_split('/\s*,\s*/', $order));
595 595
 
596 596
 	foreach ($arg as $v) {
597
-		if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+' . $v . '/', $select, $m)) {
597
+		if (preg_match('/(case\s+.*?else\s+0\s+end)\s*AS\s+'.$v.'/', $select, $m)) {
598 598
 			$res[] = $m[1];
599 599
 		} else {
600 600
 			$res[] = $v;
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
 			$n++;
773 773
 			$res .= "\nwhen $index=$v then $n";
774 774
 		}
775
-		$arg = $m[1] . "case $res else 0 end "
775
+		$arg = $m[1]."case $res else 0 end "
776 776
 			. substr($arg, strlen($m[0]));
777 777
 	}
778 778
 
@@ -815,9 +815,9 @@  discard block
 block discarded – undo
815 815
 	}
816 816
 
817 817
 	if (strtoupper($join) === 'AND') {
818
-		return $exp . join("\n\t$join ", array_map('calculer_pg_where', $v));
818
+		return $exp.join("\n\t$join ", array_map('calculer_pg_where', $v));
819 819
 	} else {
820
-		return $exp . join($join, $v);
820
+		return $exp.join($join, $v);
821 821
 	}
822 822
 }
823 823
 
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
 		if (substr($k, -1) == '@') {
828 828
 			// c'est une jointure qui se refere au from precedent
829 829
 			// pas de virgule
830
-			$argsas .= '  ' . $v;
830
+			$argsas .= '  '.$v;
831 831
 		} else {
832 832
 			$as = '';
833 833
 			//  spip_log("$k : $v", _LOG_DEBUG);
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
 				} elseif ($v != $k) {
838 838
 					$p = strpos($v, ' ');
839 839
 					if ($p) {
840
-						$v = substr($v, 0, $p) . " AS $k" . substr($v, $p);
840
+						$v = substr($v, 0, $p)." AS $k".substr($v, $p);
841 841
 					} else {
842 842
 						$as = " AS $k";
843 843
 					}
@@ -845,7 +845,7 @@  discard block
 block discarded – undo
845 845
 			}
846 846
 			// spip_log("subs $k : $v avec $as", _LOG_DEBUG);
847 847
 			// if (strpos($v, 'JOIN') === false)  $argsas .= ', ';
848
-			$argsas .= ', ' . $v . $as;
848
+			$argsas .= ', '.$v.$as;
849 849
 		}
850 850
 	}
851 851
 
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
 	$serveur = '',
877 877
 	$requeter = true
878 878
 ) {
879
-	$c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby)));
879
+	$c = !$groupby ? '*' : ('DISTINCT '.(is_string($groupby) ? $groupby : join(',', $groupby)));
880 880
 	$r = spip_pg_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter);
881 881
 	if (!$requeter) {
882 882
 		return $r;
@@ -977,8 +977,8 @@  discard block
 block discarded – undo
977 977
 
978 978
 	return spip_pg_insert(
979 979
 		$table,
980
-		'(' . join(',', array_keys($couples)) . ')',
981
-		'(' . join(',', $couples) . ')',
980
+		'('.join(',', array_keys($couples)).')',
981
+		'('.join(',', $couples).')',
982 982
 		$desc,
983 983
 		$serveur,
984 984
 		$requeter
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
 	$c = $tab_couples[0] ?? [];
1002 1002
 	$les_cles = spip_pg_ajouter_champs_timestamp($table, $c, $desc, $serveur);
1003 1003
 
1004
-	$cles = '(' . join(',', array_keys($les_cles)) . ')';
1004
+	$cles = '('.join(',', array_keys($les_cles)).')';
1005 1005
 	$valeurs = [];
1006 1006
 	foreach ($tab_couples as $couples) {
1007 1007
 		foreach ($couples as $champ => $val) {
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
 		// recherche de champs 'timestamp' pour mise a jour auto de ceux-ci
1011 1011
 		$couples = spip_pg_ajouter_champs_timestamp($table, $couples, $desc, $serveur);
1012 1012
 
1013
-		$valeurs[] = '(' . join(',', $couples) . ')';
1013
+		$valeurs[] = '('.join(',', $couples).')';
1014 1014
 	}
1015 1015
 	$valeurs = implode(', ', $valeurs);
1016 1016
 
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
 
1032 1032
 	$set = [];
1033 1033
 	foreach ($couples as $champ => $val) {
1034
-		$set[] = $champ . '=' . $val;
1034
+		$set[] = $champ.'='.$val;
1035 1035
 	}
1036 1036
 
1037 1037
 	$query = calculer_pg_expression('UPDATE', $table, ',')
@@ -1066,7 +1066,7 @@  discard block
 block discarded – undo
1066 1066
 
1067 1067
 function spip_pg_replace($table, $values, $desc, $serveur = '', $requeter = true) {
1068 1068
 	if (!$values) {
1069
-		spip_log("replace vide $table", 'pg.' . _LOG_AVERTISSEMENT);
1069
+		spip_log("replace vide $table", 'pg.'._LOG_AVERTISSEMENT);
1070 1070
 
1071 1071
 		return 0;
1072 1072
 	}
@@ -1100,8 +1100,8 @@  discard block
 block discarded – undo
1100 1100
 	if (!$where) {
1101 1101
 		return spip_pg_insert(
1102 1102
 			$table,
1103
-			'(' . join(',', array_keys($values)) . ')',
1104
-			'(' . join(',', $values) . ')',
1103
+			'('.join(',', array_keys($values)).')',
1104
+			'('.join(',', $values).')',
1105 1105
 			$desc,
1106 1106
 			$serveur
1107 1107
 		);
@@ -1122,12 +1122,11 @@  discard block
 block discarded – undo
1122 1122
 		$couples = pg_affected_rows($couples);
1123 1123
 	}
1124 1124
 	if (!$couples) {
1125
-		$ret = !$seq ? '' :
1126
-			(" RETURNING nextval('$seq') < $prim");
1127
-		$connexion['last'] = $q = "INSERT INTO $table (" . join(',', array_keys($values)) . ') VALUES (' . join(
1125
+		$ret = !$seq ? '' : (" RETURNING nextval('$seq') < $prim");
1126
+		$connexion['last'] = $q = "INSERT INTO $table (".join(',', array_keys($values)).') VALUES ('.join(
1128 1127
 			',',
1129 1128
 			$values
1130
-		) . ")$ret";
1129
+		).")$ret";
1131 1130
 		$couples = spip_pg_query_simple($link, $q);
1132 1131
 		if (!$couples) {
1133 1132
 			return false;
@@ -1175,7 +1174,7 @@  discard block
 block discarded – undo
1175 1174
 	) {
1176 1175
 		return '';
1177 1176
 	} else {
1178
-		return $raw ? $prim : $table . '_' . $prim . '_seq';
1177
+		return $raw ? $prim : $table.'_'.$prim.'_seq';
1179 1178
 	}
1180 1179
 }
1181 1180
 
@@ -1192,29 +1191,29 @@  discard block
 block discarded – undo
1192 1191
 			return spip_pg_frommysql($v);
1193 1192
 		} else {
1194 1193
 			if (strncmp($v, '0000', 4) == 0) {
1195
-				$v = '0001' . substr($v, 4);
1194
+				$v = '0001'.substr($v, 4);
1196 1195
 			}
1197 1196
 			if (strpos($v, '-00-00') === 4) {
1198
-				$v = substr($v, 0, 4) . '-01-01' . substr($v, 10);
1197
+				$v = substr($v, 0, 4).'-01-01'.substr($v, 10);
1199 1198
 			}
1200 1199
 
1201 1200
 			return "timestamp '$v'";
1202 1201
 		}
1203 1202
 	} elseif (!sql_test_int($t)) {
1204
-		return ("'" . pg_escape_string($v) . "'");
1203
+		return ("'".pg_escape_string($v)."'");
1205 1204
 	} elseif (is_numeric($v) or (strpos($v, 'CAST(') === 0)) {
1206 1205
 		return $v;
1207 1206
 	} elseif ($v[0] == '0' and $v[1] !== 'x' and ctype_xdigit(substr($v, 1))) {
1208 1207
 		return substr($v, 1);
1209 1208
 	} else {
1210
-		spip_log("Warning: '$v'  n'est pas de type $t", 'pg.' . _LOG_AVERTISSEMENT);
1209
+		spip_log("Warning: '$v'  n'est pas de type $t", 'pg.'._LOG_AVERTISSEMENT);
1211 1210
 
1212 1211
 		return intval($v);
1213 1212
 	}
1214 1213
 }
1215 1214
 
1216 1215
 function spip_pg_hex($v) {
1217
-	return "CAST(x'" . $v . "' as bigint)";
1216
+	return "CAST(x'".$v."' as bigint)";
1218 1217
 }
1219 1218
 
1220 1219
 function spip_pg_quote($v, $type = '') {
@@ -1252,15 +1251,15 @@  discard block
 block discarded – undo
1252 1251
 		return $not ? '0=0' : '0=1';
1253 1252
 	}
1254 1253
 	if (strpos($valeurs, "CAST(x'") !== false) {
1255
-		return "($val=" . join("OR $val=", explode(',', $valeurs)) . ')';
1254
+		return "($val=".join("OR $val=", explode(',', $valeurs)).')';
1256 1255
 	}
1257 1256
 	$n = $i = 0;
1258 1257
 	$in_sql = '';
1259 1258
 	while ($n = strpos($valeurs, ',', $n + 1)) {
1260 1259
 		if ((++$i) >= 255) {
1261
-			$in_sql .= "($val $not IN (" .
1262
-				substr($valeurs, 0, $n) .
1263
-				"))\n" .
1260
+			$in_sql .= "($val $not IN (".
1261
+				substr($valeurs, 0, $n).
1262
+				"))\n".
1264 1263
 				($not ? "AND\t" : "OR\t");
1265 1264
 			$valeurs = substr($valeurs, $n + 1);
1266 1265
 			$i = $n = 0;
@@ -1276,7 +1275,7 @@  discard block
 block discarded – undo
1276 1275
 	$s = $link ? pg_last_error($link) : pg_last_error();
1277 1276
 	if ($s) {
1278 1277
 		$s = str_replace('ERROR', 'errcode: 1000 ', $s);
1279
-		spip_log("$s - $query", 'pg.' . _LOG_ERREUR);
1278
+		spip_log("$s - $query", 'pg.'._LOG_ERREUR);
1280 1279
 	}
1281 1280
 
1282 1281
 	return $s;
@@ -1324,7 +1323,7 @@  discard block
 block discarded – undo
1324 1323
 function spip_pg_showbase($match, $serveur = '', $requeter = true) {
1325 1324
 	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
1326 1325
 	$link = $connexion['link'];
1327
-	$connexion['last'] = $q = 'SELECT tablename FROM pg_tables WHERE tablename ILIKE ' . _q($match);
1326
+	$connexion['last'] = $q = 'SELECT tablename FROM pg_tables WHERE tablename ILIKE '._q($match);
1328 1327
 
1329 1328
 	return spip_pg_query_simple($link, $q);
1330 1329
 }
@@ -1332,7 +1331,7 @@  discard block
 block discarded – undo
1332 1331
 function spip_pg_showtable($nom_table, $serveur = '', $requeter = true) {
1333 1332
 	$connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0];
1334 1333
 	$link = $connexion['link'];
1335
-	$connexion['last'] = $q = 'SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE ' . _q($nom_table);
1334
+	$connexion['last'] = $q = 'SELECT column_name, column_default, data_type FROM information_schema.columns WHERE table_name ILIKE '._q($nom_table);
1336 1335
 
1337 1336
 	$res = spip_pg_query_simple($link, $q);
1338 1337
 	if (!$res) {
@@ -1343,15 +1342,15 @@  discard block
 block discarded – undo
1343 1342
 	// il faut en tenir compte dans le return
1344 1343
 	$fields = [];
1345 1344
 	while ($field = pg_fetch_array($res, null, PGSQL_NUM)) {
1346
-		$fields[$field[0]] = $field[2] . (!$field[1] ? '' : (' DEFAULT ' . $field[1]));
1345
+		$fields[$field[0]] = $field[2].(!$field[1] ? '' : (' DEFAULT '.$field[1]));
1347 1346
 	}
1348
-	$connexion['last'] = $q = 'SELECT indexdef FROM pg_indexes WHERE tablename ILIKE ' . _q($nom_table);
1347
+	$connexion['last'] = $q = 'SELECT indexdef FROM pg_indexes WHERE tablename ILIKE '._q($nom_table);
1349 1348
 	$res = spip_pg_query_simple($link, $q);
1350 1349
 	$keys = [];
1351 1350
 	while ($index = pg_fetch_array($res, null, PGSQL_NUM)) {
1352 1351
 		if (preg_match('/CREATE\s+(UNIQUE\s+)?INDEX\s([^\s]+).*\((.*)\)$/', $index[0], $r)) {
1353
-			$nom = str_replace($nom_table . '_', '', $r[2]);
1354
-			$keys[($r[1] ? 'PRIMARY KEY' : ('KEY ' . $nom))] = $r[3];
1352
+			$nom = str_replace($nom_table.'_', '', $r[2]);
1353
+			$keys[($r[1] ? 'PRIMARY KEY' : ('KEY '.$nom))] = $r[3];
1355 1354
 		}
1356 1355
 	}
1357 1356
 
@@ -1383,16 +1382,16 @@  discard block
 block discarded – undo
1383 1382
 		if (strpos($k, 'KEY ') === 0) {
1384 1383
 			$n = str_replace('`', '', $k);
1385 1384
 			$v = str_replace('`', '"', $v);
1386
-			$i = $nom . preg_replace('/KEY +/', '_', $n);
1385
+			$i = $nom.preg_replace('/KEY +/', '_', $n);
1387 1386
 			if ($k != $n) {
1388 1387
 				$i = "\"$i\"";
1389 1388
 			}
1390 1389
 			$keys[] = "CREATE INDEX $i ON $nom ($v);";
1391 1390
 		} elseif (strpos($k, 'UNIQUE ') === 0) {
1392 1391
 			$k = preg_replace('/^UNIQUE +/', '', $k);
1393
-			$prim .= "$s\n\t\tCONSTRAINT " . str_replace('`', '"', $k) . " UNIQUE ($v)";
1392
+			$prim .= "$s\n\t\tCONSTRAINT ".str_replace('`', '"', $k)." UNIQUE ($v)";
1394 1393
 		} else {
1395
-			$prim .= "$s\n\t\t" . str_replace('`', '"', $k) . " ($v)";
1394
+			$prim .= "$s\n\t\t".str_replace('`', '"', $k)." ($v)";
1396 1395
 		}
1397 1396
 		if ($k == 'PRIMARY KEY') {
1398 1397
 			$prim_name = $v;
@@ -1403,17 +1402,17 @@  discard block
 block discarded – undo
1403 1402
 
1404 1403
 	$character_set = '';
1405 1404
 	if (@$GLOBALS['meta']['charset_sql_base']) {
1406
-		$character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base'];
1405
+		$character_set .= ' CHARACTER SET '.$GLOBALS['meta']['charset_sql_base'];
1407 1406
 	}
1408 1407
 	if (@$GLOBALS['meta']['charset_collation_sql_base']) {
1409
-		$character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base'];
1408
+		$character_set .= ' COLLATE '.$GLOBALS['meta']['charset_collation_sql_base'];
1410 1409
 	}
1411 1410
 
1412 1411
 	foreach ($champs as $k => $v) {
1413 1412
 		$k = str_replace('`', '"', $k);
1414 1413
 		if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) {
1415 1414
 			if (preg_match(',(char|text),i', $defs[1]) and !preg_match(',binary,i', $defs[1])) {
1416
-				$v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1]));
1415
+				$v = $defs[1].$character_set.' '.substr($v, strlen($defs[1]));
1417 1416
 			}
1418 1417
 		}
1419 1418
 
@@ -1428,7 +1427,7 @@  discard block
 block discarded – undo
1428 1427
 
1429 1428
 	// En l'absence de "if not exists" en PG, on neutralise les erreurs
1430 1429
 
1431
-	$q = "CREATE $temporary TABLE $nom ($query" . ($prim ? ",$prim" : '') . ')' .
1430
+	$q = "CREATE $temporary TABLE $nom ($query".($prim ? ",$prim" : '').')'.
1432 1431
 		($character_set ? " DEFAULT $character_set" : '')
1433 1432
 		. "\n";
1434 1433
 
@@ -1439,7 +1438,7 @@  discard block
 block discarded – undo
1439 1438
 	$r = @pg_query($link, $q);
1440 1439
 
1441 1440
 	if (!$r) {
1442
-		spip_log("Impossible de creer cette table: $q", 'pg.' . _LOG_ERREUR);
1441
+		spip_log("Impossible de creer cette table: $q", 'pg.'._LOG_ERREUR);
1443 1442
 	} else {
1444 1443
 		foreach ($keys as $index) {
1445 1444
 			pg_query($link, $index);
@@ -1462,20 +1461,20 @@  discard block
 block discarded – undo
1462 1461
 	// vue deja presente
1463 1462
 	if (sql_showtable($nom, false, $serveur)) {
1464 1463
 		if ($requeter) {
1465
-			spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.' . _LOG_ERREUR);
1464
+			spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", 'pg.'._LOG_ERREUR);
1466 1465
 		}
1467 1466
 
1468 1467
 		return false;
1469 1468
 	}
1470 1469
 
1471
-	$query = "CREATE VIEW $nom AS " . $query_select;
1470
+	$query = "CREATE VIEW $nom AS ".$query_select;
1472 1471
 
1473 1472
 	return spip_pg_query($query, $serveur, $requeter);
1474 1473
 }
1475 1474
 
1476 1475
 
1477 1476
 function spip_pg_set_connect_charset($charset, $serveur = '', $requeter = true) {
1478
-	spip_log('changement de charset sql a ecrire en PG', 'pg.' . _LOG_ERREUR);
1477
+	spip_log('changement de charset sql a ecrire en PG', 'pg.'._LOG_ERREUR);
1479 1478
 }
1480 1479
 
1481 1480
 
@@ -1488,7 +1487,7 @@  discard block
 block discarded – undo
1488 1487
  * @return bool|string true / false / requete
1489 1488
  **/
1490 1489
 function spip_pg_optimize($table, $serveur = '', $requeter = true) {
1491
-	return spip_pg_query('VACUUM ' . $table, $serveur, $requeter);
1490
+	return spip_pg_query('VACUUM '.$table, $serveur, $requeter);
1492 1491
 }
1493 1492
 
1494 1493
 // Selectionner la sous-chaine dans $objet
Please login to merge, or discard this patch.
ecrire/plugins/afficher_repertoires.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -11,110 +11,110 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 function plugins_afficher_repertoires_dist($url_page, $liste_plugins, $liste_plugins_actifs) {
18
-	$ligne_plug = charger_fonction('afficher_plugin', 'plugins');
19
-	$racine = basename(_DIR_PLUGINS);
20
-	$init_dir = $current_dir = '';
21
-	// liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif
22
-	// des qu'un path est deja note deplie on s'arrete
23
-	$deplie = [$racine => true];
24
-	$fast_liste_plugins_actifs = [];
25
-	foreach ($liste_plugins_actifs as $key => $plug) {
26
-		$chemin_plug = chemin_plug($racine, $plug);
27
-		$fast_liste_plugins_actifs[$chemin_plug] = true;
28
-		$dir = dirname($chemin_plug);
29
-		$maxiter = 100;
30
-		while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) {
31
-			$deplie[$dir] = true;
32
-			$dir = dirname($dir);
33
-		}
34
-	}
18
+    $ligne_plug = charger_fonction('afficher_plugin', 'plugins');
19
+    $racine = basename(_DIR_PLUGINS);
20
+    $init_dir = $current_dir = '';
21
+    // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif
22
+    // des qu'un path est deja note deplie on s'arrete
23
+    $deplie = [$racine => true];
24
+    $fast_liste_plugins_actifs = [];
25
+    foreach ($liste_plugins_actifs as $key => $plug) {
26
+        $chemin_plug = chemin_plug($racine, $plug);
27
+        $fast_liste_plugins_actifs[$chemin_plug] = true;
28
+        $dir = dirname($chemin_plug);
29
+        $maxiter = 100;
30
+        while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) {
31
+            $deplie[$dir] = true;
32
+            $dir = dirname($dir);
33
+        }
34
+    }
35 35
 
36
-	// index repertoires --> plugin
37
-	$dir_index = [];
38
-	foreach ($liste_plugins as $key => $plug) {
39
-		$liste_plugins[$key] = chemin_plug($racine, $plug);
40
-		$dir_index[dirname($liste_plugins[$key])][] = $key;
41
-	}
36
+    // index repertoires --> plugin
37
+    $dir_index = [];
38
+    foreach ($liste_plugins as $key => $plug) {
39
+        $liste_plugins[$key] = chemin_plug($racine, $plug);
40
+        $dir_index[dirname($liste_plugins[$key])][] = $key;
41
+    }
42 42
 
43
-	$visible = @isset($deplie[$current_dir]);
44
-	$maxiter = 1000;
43
+    $visible = @isset($deplie[$current_dir]);
44
+    $maxiter = 1000;
45 45
 
46
-	$res = '';
47
-	while ((is_countable($liste_plugins) ? count($liste_plugins) : 0) && $maxiter--) {
48
-		// le rep suivant
49
-		$dir = dirname(reset($liste_plugins));
50
-		if ($dir != $current_dir) {
51
-			$res .= tree_open_close_dir($current_dir, $dir, $deplie);
52
-		}
46
+    $res = '';
47
+    while ((is_countable($liste_plugins) ? count($liste_plugins) : 0) && $maxiter--) {
48
+        // le rep suivant
49
+        $dir = dirname(reset($liste_plugins));
50
+        if ($dir != $current_dir) {
51
+            $res .= tree_open_close_dir($current_dir, $dir, $deplie);
52
+        }
53 53
 
54
-		// d'abord tous les plugins du rep courant
55
-		if (isset($dir_index[$current_dir])) {
56
-			foreach ($dir_index[$current_dir] as $key) {
57
-				$plug = $liste_plugins[$key];
58
-				$actif = @isset($fast_liste_plugins_actifs[$plug]);
59
-				$id = substr(md5($plug), 0, 16);
60
-				$res .= $ligne_plug(
61
-					$url_page,
62
-					str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug),
63
-					$actif,
64
-					'menu-entree'
65
-				) . "\n";
66
-				unset($liste_plugins[$key]);
67
-			}
68
-		}
69
-	}
70
-	$res .= tree_open_close_dir($current_dir, $init_dir, true);
54
+        // d'abord tous les plugins du rep courant
55
+        if (isset($dir_index[$current_dir])) {
56
+            foreach ($dir_index[$current_dir] as $key) {
57
+                $plug = $liste_plugins[$key];
58
+                $actif = @isset($fast_liste_plugins_actifs[$plug]);
59
+                $id = substr(md5($plug), 0, 16);
60
+                $res .= $ligne_plug(
61
+                    $url_page,
62
+                    str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug),
63
+                    $actif,
64
+                    'menu-entree'
65
+                ) . "\n";
66
+                unset($liste_plugins[$key]);
67
+            }
68
+        }
69
+    }
70
+    $res .= tree_open_close_dir($current_dir, $init_dir, true);
71 71
 
72
-	return "<ul class='menu-liste plugins'>"
73
-	. $res
74
-	. '</ul>';
72
+    return "<ul class='menu-liste plugins'>"
73
+    . $res
74
+    . '</ul>';
75 75
 }
76 76
 
77 77
 
78 78
 // vraiment n'importe quoi la gestion des chemins des plugins
79 79
 // une fonction pour aider...
80 80
 function chemin_plug($racine, $plug) {
81
-	return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug");
81
+    return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug");
82 82
 }
83 83
 
84 84
 function tree_open_close_dir(&$current, $target, $deplie = []) {
85
-	if ($current == $target) {
86
-		return '';
87
-	}
88
-	$tcur = explode('/', $current);
89
-	$ttarg = explode('/', $target);
90
-	$tcom = [];
91
-	$output = '';
92
-	// la partie commune
93
-	while (reset($tcur) == reset($ttarg)) {
94
-		$tcom[] = array_shift($tcur);
95
-		array_shift($ttarg);
96
-	}
97
-	// fermer les repertoires courant jusqu'au point de fork
98
-	while ($close = array_pop($tcur)) {
99
-		$output .= "</ul>\n";
100
-		$output .= fin_block();
101
-		$output .= "</li>\n";
102
-	}
103
-	$chemin = '';
104
-	if (count($tcom)) {
105
-		$chemin .= implode('/', $tcom) . '/';
106
-	}
107
-	// ouvrir les repertoires jusqu'a la cible
108
-	while ($open = array_shift($ttarg)) {
109
-		$visible = @isset($deplie[$chemin . $open]);
110
-		$chemin .= $open . '/';
111
-		$output .= '<li>';
112
-		$output .= bouton_block_depliable($chemin, $visible);
113
-		$output .= debut_block_depliable($visible);
85
+    if ($current == $target) {
86
+        return '';
87
+    }
88
+    $tcur = explode('/', $current);
89
+    $ttarg = explode('/', $target);
90
+    $tcom = [];
91
+    $output = '';
92
+    // la partie commune
93
+    while (reset($tcur) == reset($ttarg)) {
94
+        $tcom[] = array_shift($tcur);
95
+        array_shift($ttarg);
96
+    }
97
+    // fermer les repertoires courant jusqu'au point de fork
98
+    while ($close = array_pop($tcur)) {
99
+        $output .= "</ul>\n";
100
+        $output .= fin_block();
101
+        $output .= "</li>\n";
102
+    }
103
+    $chemin = '';
104
+    if (count($tcom)) {
105
+        $chemin .= implode('/', $tcom) . '/';
106
+    }
107
+    // ouvrir les repertoires jusqu'a la cible
108
+    while ($open = array_shift($ttarg)) {
109
+        $visible = @isset($deplie[$chemin . $open]);
110
+        $chemin .= $open . '/';
111
+        $output .= '<li>';
112
+        $output .= bouton_block_depliable($chemin, $visible);
113
+        $output .= debut_block_depliable($visible);
114 114
 
115
-		$output .= "<ul>\n";
116
-	}
117
-	$current = $target;
115
+        $output .= "<ul>\n";
116
+    }
117
+    $current = $target;
118 118
 
119
-	return $output;
119
+    return $output;
120 120
 }
Please login to merge, or discard this patch.
ecrire/plugins/verifie_conformite.php 1 patch
Indentation   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -11,225 +11,225 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 include_spip('inc/xml');
18 18
 include_spip('inc/plugin');
19 19
 
20 20
 function plugins_verifie_conformite_dist($plug, &$arbre, $dir_plugins = _DIR_PLUGINS) {
21
-	$needs = null;
22
-	$compat_spip = null;
23
-	$uses = null;
24
-	$paths = null;
25
-	$trads = null;
26
-	static $etats = ['dev', 'experimental', 'test', 'stable'];
21
+    $needs = null;
22
+    $compat_spip = null;
23
+    $uses = null;
24
+    $paths = null;
25
+    $trads = null;
26
+    static $etats = ['dev', 'experimental', 'test', 'stable'];
27 27
 
28
-	$matches = [];
29
-	$silence = false;
30
-	$p = null;
31
-	// chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP
32
-	if ($n = spip_xml_match_nodes(',^plugin(\s|$),', $arbre, $matches)) {
33
-		// version de SPIP
34
-		$vspip = $GLOBALS['spip_version_branche'];
35
-		foreach ($matches as $tag => $sous) {
36
-			[$tagname, $atts] = spip_xml_decompose_tag($tag);
37
-			if ($tagname == 'plugin' and is_array($sous)) {
38
-				// On rajoute la condition sur $n :
39
-				// -- en effet si $n==1 on a pas plus a choisir la balise que l'on ait
40
-				//    un attribut spip ou pas. Cela permet de traiter tous les cas mono-balise
41
-				//    de la meme facon.
42
-				if (
43
-					!isset($atts['spip'])
44
-					or $n == 1
45
-					or plugin_version_compatible($atts['spip'], $vspip, 'spip')
46
-				) {
47
-					// on prend la derniere declaration avec ce nom
48
-					$p = end($sous);
49
-					$compat_spip = $atts['spip'] ?? '';
50
-				}
51
-			}
52
-		}
53
-	}
54
-	if (is_null($p)) {
55
-		$arbre = ['erreur' => [_T('erreur_plugin_tag_plugin_absent') . " : $plug"]];
56
-		$silence = true;
57
-	} else {
58
-		$arbre = $p;
59
-	}
60
-	if (!is_array($arbre)) {
61
-		$arbre = [];
62
-	}
63
-	// verification de la conformite du plugin avec quelques
64
-	// precautions elementaires
65
-	if (!isset($arbre['nom'])) {
66
-		if (!$silence) {
67
-			$arbre['erreur'][] = _T('erreur_plugin_nom_manquant');
68
-		}
69
-		$arbre['nom'] = [''];
70
-	}
71
-	if (!isset($arbre['version'])) {
72
-		if (!$silence) {
73
-			$arbre['erreur'][] = _T('erreur_plugin_version_manquant');
74
-		}
75
-		$arbre['version'] = [''];
76
-	}
77
-	if (!isset($arbre['prefix'])) {
78
-		if (!$silence) {
79
-			$arbre['erreur'][] = _T('erreur_plugin_prefix_manquant');
80
-		}
81
-		$arbre['prefix'] = [''];
82
-	} else {
83
-		$prefix = trim(end($arbre['prefix']));
84
-		if (strtoupper($prefix) == 'SPIP' and $plug != './') {
85
-			$arbre['erreur'][] = _T('erreur_plugin_prefix_interdit');
86
-		}
87
-		if (isset($arbre['etat'])) {
88
-			$etat = trim(end($arbre['etat']));
89
-			if (!in_array($etat, $etats)) {
90
-				$arbre['erreur'][] = _T('erreur_plugin_etat_inconnu') . " : '$etat'";
91
-			}
92
-		}
93
-		if (isset($arbre['options'])) {
94
-			foreach ($arbre['options'] as $optfile) {
95
-				$optfile = trim($optfile);
96
-				if (!@is_readable($dir_plugins . "$plug/$optfile")) {
97
-					if (!$silence) {
98
-						$arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile";
99
-					}
100
-				}
101
-			}
102
-		}
103
-		if (isset($arbre['fonctions'])) {
104
-			foreach ($arbre['fonctions'] as $optfile) {
105
-				$optfile = trim($optfile);
106
-				if (!@is_readable($dir_plugins . "$plug/$optfile")) {
107
-					if (!$silence) {
108
-						$arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile";
109
-					}
110
-				}
111
-			}
112
-		}
113
-		$fonctions = [];
114
-		if (isset($arbre['fonctions'])) {
115
-			$fonctions = $arbre['fonctions'];
116
-		}
117
-		$liste_methodes_reservees = [
118
-			'__construct',
119
-			'__destruct',
120
-			'plugin',
121
-			'install',
122
-			'uninstall',
123
-			strtolower($prefix)
124
-		];
28
+    $matches = [];
29
+    $silence = false;
30
+    $p = null;
31
+    // chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP
32
+    if ($n = spip_xml_match_nodes(',^plugin(\s|$),', $arbre, $matches)) {
33
+        // version de SPIP
34
+        $vspip = $GLOBALS['spip_version_branche'];
35
+        foreach ($matches as $tag => $sous) {
36
+            [$tagname, $atts] = spip_xml_decompose_tag($tag);
37
+            if ($tagname == 'plugin' and is_array($sous)) {
38
+                // On rajoute la condition sur $n :
39
+                // -- en effet si $n==1 on a pas plus a choisir la balise que l'on ait
40
+                //    un attribut spip ou pas. Cela permet de traiter tous les cas mono-balise
41
+                //    de la meme facon.
42
+                if (
43
+                    !isset($atts['spip'])
44
+                    or $n == 1
45
+                    or plugin_version_compatible($atts['spip'], $vspip, 'spip')
46
+                ) {
47
+                    // on prend la derniere declaration avec ce nom
48
+                    $p = end($sous);
49
+                    $compat_spip = $atts['spip'] ?? '';
50
+                }
51
+            }
52
+        }
53
+    }
54
+    if (is_null($p)) {
55
+        $arbre = ['erreur' => [_T('erreur_plugin_tag_plugin_absent') . " : $plug"]];
56
+        $silence = true;
57
+    } else {
58
+        $arbre = $p;
59
+    }
60
+    if (!is_array($arbre)) {
61
+        $arbre = [];
62
+    }
63
+    // verification de la conformite du plugin avec quelques
64
+    // precautions elementaires
65
+    if (!isset($arbre['nom'])) {
66
+        if (!$silence) {
67
+            $arbre['erreur'][] = _T('erreur_plugin_nom_manquant');
68
+        }
69
+        $arbre['nom'] = [''];
70
+    }
71
+    if (!isset($arbre['version'])) {
72
+        if (!$silence) {
73
+            $arbre['erreur'][] = _T('erreur_plugin_version_manquant');
74
+        }
75
+        $arbre['version'] = [''];
76
+    }
77
+    if (!isset($arbre['prefix'])) {
78
+        if (!$silence) {
79
+            $arbre['erreur'][] = _T('erreur_plugin_prefix_manquant');
80
+        }
81
+        $arbre['prefix'] = [''];
82
+    } else {
83
+        $prefix = trim(end($arbre['prefix']));
84
+        if (strtoupper($prefix) == 'SPIP' and $plug != './') {
85
+            $arbre['erreur'][] = _T('erreur_plugin_prefix_interdit');
86
+        }
87
+        if (isset($arbre['etat'])) {
88
+            $etat = trim(end($arbre['etat']));
89
+            if (!in_array($etat, $etats)) {
90
+                $arbre['erreur'][] = _T('erreur_plugin_etat_inconnu') . " : '$etat'";
91
+            }
92
+        }
93
+        if (isset($arbre['options'])) {
94
+            foreach ($arbre['options'] as $optfile) {
95
+                $optfile = trim($optfile);
96
+                if (!@is_readable($dir_plugins . "$plug/$optfile")) {
97
+                    if (!$silence) {
98
+                        $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile";
99
+                    }
100
+                }
101
+            }
102
+        }
103
+        if (isset($arbre['fonctions'])) {
104
+            foreach ($arbre['fonctions'] as $optfile) {
105
+                $optfile = trim($optfile);
106
+                if (!@is_readable($dir_plugins . "$plug/$optfile")) {
107
+                    if (!$silence) {
108
+                        $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile";
109
+                    }
110
+                }
111
+            }
112
+        }
113
+        $fonctions = [];
114
+        if (isset($arbre['fonctions'])) {
115
+            $fonctions = $arbre['fonctions'];
116
+        }
117
+        $liste_methodes_reservees = [
118
+            '__construct',
119
+            '__destruct',
120
+            'plugin',
121
+            'install',
122
+            'uninstall',
123
+            strtolower($prefix)
124
+        ];
125 125
 
126
-		$extraire_pipelines = charger_fonction('extraire_pipelines', 'plugins');
127
-		$arbre['pipeline'] = $extraire_pipelines($arbre);
128
-		foreach ($arbre['pipeline'] as $pipe) {
129
-			if (!isset($pipe['nom'])) {
130
-				if (!$silence) {
131
-					$arbre['erreur'][] = _T('erreur_plugin_nom_pipeline_non_defini');
132
-				}
133
-			}
134
-			if (isset($pipe['action'])) {
135
-				$action = $pipe['action'];
136
-			} else {
137
-				$action = $pipe['nom'];
138
-			}
139
-			// verif que la methode a un nom autorise
140
-			if (in_array(strtolower($action), $liste_methodes_reservees)) {
141
-				if (!$silence) {
142
-					$arbre['erreur'][] = _T('erreur_plugin_nom_fonction_interdit') . " : $action";
143
-				}
144
-			}
145
-			if (isset($pipe['inclure'])) {
146
-				$inclure = $dir_plugins . "$plug/" . $pipe['inclure'];
147
-				if (!@is_readable($inclure)) {
148
-					if (!$silence) {
149
-						$arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $inclure";
150
-					}
151
-				}
152
-			}
153
-		}
154
-		$necessite = [];
155
-		$spip_trouve = false;
156
-		if (spip_xml_match_nodes(',^necessite,', $arbre, $needs)) {
157
-			foreach (array_keys($needs) as $tag) {
158
-				[$tag, $att] = spip_xml_decompose_tag($tag);
159
-				if (!isset($att['id'])) {
160
-					if (!$silence) {
161
-						$arbre['erreur'][] = _T(
162
-							'erreur_plugin_attribut_balise_manquant',
163
-							['attribut' => 'id', 'balise' => $att]
164
-						);
165
-					}
166
-				} else {
167
-					$necessite[] = $att;
168
-				}
169
-				if (strtolower($att['id']) == 'spip') {
170
-					$spip_trouve = true;
171
-				}
172
-			}
173
-		}
174
-		if ($compat_spip and !$spip_trouve) {
175
-			$necessite[] = ['id' => 'spip', 'version' => $compat_spip];
176
-		}
177
-		$arbre['necessite'] = $necessite;
178
-		$utilise = [];
179
-		if (spip_xml_match_nodes(',^utilise,', $arbre, $uses)) {
180
-			foreach (array_keys($uses) as $tag) {
181
-				[$tag, $att] = spip_xml_decompose_tag($tag);
182
-				if (!isset($att['id'])) {
183
-					if (!$silence) {
184
-						$arbre['erreur'][] = _T(
185
-							'erreur_plugin_attribut_balise_manquant',
186
-							['attribut' => 'id', 'balise' => $att]
187
-						);
188
-					}
189
-				} else {
190
-					$utilise[] = $att;
191
-				}
192
-			}
193
-		}
194
-		$arbre['utilise'] = $utilise;
195
-		$procure = [];
196
-		if (spip_xml_match_nodes(',^procure,', $arbre, $uses)) {
197
-			foreach (array_keys($uses) as $tag) {
198
-				[$tag, $att] = spip_xml_decompose_tag($tag);
199
-				$procure[] = $att;
200
-			}
201
-		}
202
-		$arbre['procure'] = $procure;
203
-		$path = [];
204
-		if (spip_xml_match_nodes(',^chemin,', $arbre, $paths)) {
205
-			foreach (array_keys($paths) as $tag) {
206
-				[$tag, $att] = spip_xml_decompose_tag($tag);
207
-				$att['path'] = $att['dir']; // ancienne syntaxe
208
-				$path[] = $att;
209
-			}
210
-		} else {
211
-			$path = [['dir' => '']];
212
-		} // initialiser par defaut
213
-		$arbre['path'] = $path;
214
-		// exposer les noisettes
215
-		if (isset($arbre['noisette'])) {
216
-			foreach ($arbre['noisette'] as $k => $nut) {
217
-				$nut = preg_replace(',[.]html$,uims', '', trim($nut));
218
-				$arbre['noisette'][$k] = $nut;
219
-				if (!@is_readable($dir_plugins . "$plug/$nut.html")) {
220
-					if (!$silence) {
221
-						$arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $nut";
222
-					}
223
-				}
224
-			}
225
-		}
226
-		$traduire = [];
227
-		if (spip_xml_match_nodes(',^traduire,', $arbre, $trads)) {
228
-			foreach (array_keys($trads) as $tag) {
229
-				[$tag, $att] = spip_xml_decompose_tag($tag);
230
-				$traduire[] = $att;
231
-			}
232
-		}
233
-		$arbre['traduire'] = $traduire;
234
-	}
126
+        $extraire_pipelines = charger_fonction('extraire_pipelines', 'plugins');
127
+        $arbre['pipeline'] = $extraire_pipelines($arbre);
128
+        foreach ($arbre['pipeline'] as $pipe) {
129
+            if (!isset($pipe['nom'])) {
130
+                if (!$silence) {
131
+                    $arbre['erreur'][] = _T('erreur_plugin_nom_pipeline_non_defini');
132
+                }
133
+            }
134
+            if (isset($pipe['action'])) {
135
+                $action = $pipe['action'];
136
+            } else {
137
+                $action = $pipe['nom'];
138
+            }
139
+            // verif que la methode a un nom autorise
140
+            if (in_array(strtolower($action), $liste_methodes_reservees)) {
141
+                if (!$silence) {
142
+                    $arbre['erreur'][] = _T('erreur_plugin_nom_fonction_interdit') . " : $action";
143
+                }
144
+            }
145
+            if (isset($pipe['inclure'])) {
146
+                $inclure = $dir_plugins . "$plug/" . $pipe['inclure'];
147
+                if (!@is_readable($inclure)) {
148
+                    if (!$silence) {
149
+                        $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $inclure";
150
+                    }
151
+                }
152
+            }
153
+        }
154
+        $necessite = [];
155
+        $spip_trouve = false;
156
+        if (spip_xml_match_nodes(',^necessite,', $arbre, $needs)) {
157
+            foreach (array_keys($needs) as $tag) {
158
+                [$tag, $att] = spip_xml_decompose_tag($tag);
159
+                if (!isset($att['id'])) {
160
+                    if (!$silence) {
161
+                        $arbre['erreur'][] = _T(
162
+                            'erreur_plugin_attribut_balise_manquant',
163
+                            ['attribut' => 'id', 'balise' => $att]
164
+                        );
165
+                    }
166
+                } else {
167
+                    $necessite[] = $att;
168
+                }
169
+                if (strtolower($att['id']) == 'spip') {
170
+                    $spip_trouve = true;
171
+                }
172
+            }
173
+        }
174
+        if ($compat_spip and !$spip_trouve) {
175
+            $necessite[] = ['id' => 'spip', 'version' => $compat_spip];
176
+        }
177
+        $arbre['necessite'] = $necessite;
178
+        $utilise = [];
179
+        if (spip_xml_match_nodes(',^utilise,', $arbre, $uses)) {
180
+            foreach (array_keys($uses) as $tag) {
181
+                [$tag, $att] = spip_xml_decompose_tag($tag);
182
+                if (!isset($att['id'])) {
183
+                    if (!$silence) {
184
+                        $arbre['erreur'][] = _T(
185
+                            'erreur_plugin_attribut_balise_manquant',
186
+                            ['attribut' => 'id', 'balise' => $att]
187
+                        );
188
+                    }
189
+                } else {
190
+                    $utilise[] = $att;
191
+                }
192
+            }
193
+        }
194
+        $arbre['utilise'] = $utilise;
195
+        $procure = [];
196
+        if (spip_xml_match_nodes(',^procure,', $arbre, $uses)) {
197
+            foreach (array_keys($uses) as $tag) {
198
+                [$tag, $att] = spip_xml_decompose_tag($tag);
199
+                $procure[] = $att;
200
+            }
201
+        }
202
+        $arbre['procure'] = $procure;
203
+        $path = [];
204
+        if (spip_xml_match_nodes(',^chemin,', $arbre, $paths)) {
205
+            foreach (array_keys($paths) as $tag) {
206
+                [$tag, $att] = spip_xml_decompose_tag($tag);
207
+                $att['path'] = $att['dir']; // ancienne syntaxe
208
+                $path[] = $att;
209
+            }
210
+        } else {
211
+            $path = [['dir' => '']];
212
+        } // initialiser par defaut
213
+        $arbre['path'] = $path;
214
+        // exposer les noisettes
215
+        if (isset($arbre['noisette'])) {
216
+            foreach ($arbre['noisette'] as $k => $nut) {
217
+                $nut = preg_replace(',[.]html$,uims', '', trim($nut));
218
+                $arbre['noisette'][$k] = $nut;
219
+                if (!@is_readable($dir_plugins . "$plug/$nut.html")) {
220
+                    if (!$silence) {
221
+                        $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $nut";
222
+                    }
223
+                }
224
+            }
225
+        }
226
+        $traduire = [];
227
+        if (spip_xml_match_nodes(',^traduire,', $arbre, $trads)) {
228
+            foreach (array_keys($trads) as $tag) {
229
+                [$tag, $att] = spip_xml_decompose_tag($tag);
230
+                $traduire[] = $att;
231
+            }
232
+        }
233
+        $arbre['traduire'] = $traduire;
234
+    }
235 235
 }
Please login to merge, or discard this patch.
ecrire/plugins/afficher_plugin.php 2 patches
Indentation   +312 added lines, -312 removed lines patch added patch discarded remove patch
@@ -17,221 +17,221 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 include_spip('inc/charsets');
23 23
 include_spip('inc/texte');
24 24
 include_spip('inc/plugin'); // pour plugin_est_installe
25 25
 
26 26
 function plugins_afficher_plugin_dist(
27
-	$url_page,
28
-	$plug_file,
29
-	$checked,
30
-	$actif,
31
-	$expose = false,
32
-	$class_li = 'item',
33
-	$dir_plugins = _DIR_PLUGINS
27
+    $url_page,
28
+    $plug_file,
29
+    $checked,
30
+    $actif,
31
+    $expose = false,
32
+    $class_li = 'item',
33
+    $dir_plugins = _DIR_PLUGINS
34 34
 ) {
35 35
 
36
-	static $id_input = 0;
37
-	static $versions = [];
38
-
39
-	$force_reload = (_request('var_mode') == 'recalcul');
40
-	$get_infos = charger_fonction('get_infos', 'plugins');
41
-	$info = $get_infos($plug_file, $force_reload, $dir_plugins);
42
-	$prefix = $info['prefix'];
43
-	$cfg = '';
44
-	$checkable = ($dir_plugins !== _DIR_PLUGINS_DIST);
45
-	$nom = plugin_nom($info, $dir_plugins, $plug_file);
46
-	$erreur = '';
47
-
48
-	if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
49
-		$info['slogan'] = _T('plugin_info_non_compatible_spip');
50
-		$erreur = http_img_pack(
51
-			'plugin-dis-32.png',
52
-			_T('plugin_info_non_compatible_spip'),
53
-			" class='picto_err'",
54
-			_T('plugin_info_non_compatible_spip')
55
-		);
56
-		$class_li .= ' disabled';
57
-		$checkable = false;
58
-	} elseif (isset($info['erreur'])) {
59
-		$class_li .= ' error';
60
-		$erreur = http_img_pack(
61
-			'plugin-err-32.png',
62
-			_T('plugin_info_erreur_xml'),
63
-			" class='picto_err'",
64
-			_T('plugin_info_erreur_xml')
65
-		)
66
-			. "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>';
67
-		$checkable = false;
68
-	} elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) {
69
-		$class_li .= ' error';
70
-		$erreur = http_img_pack(
71
-			'plugin-err-32.png',
72
-			_T('plugin_impossible_activer', ['plugin' => $nom]),
73
-			" class='picto_err'",
74
-			_T('plugin_impossible_activer', ['plugin' => $nom])
75
-		)
76
-			. "<div class='erreur'>" . implode(
77
-				'<br />',
78
-				$GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]
79
-			) . '</div>';
80
-	} else {
81
-		$cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : '';
82
-		if (defined('_DEV_VERSION_SPIP_COMPAT') and !plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'])) {
83
-			//$info['slogan'] = _T('plugin_info_non_compatible_spip');
84
-			$erreur = http_img_pack(
85
-				'plugin-dis-32.png',
86
-				_T('plugin_info_non_compatible_spip'),
87
-				" class='picto_err picto_compat_forcee'",
88
-				_L('Version incompatible : compatibilité forcée')
89
-			);
90
-		}
91
-	}
92
-
93
-	// numerotons les occurrences d'un meme prefix
94
-	$versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : '';
95
-
96
-	$class_li .= ($actif ? ' actif' : '') . ($expose ? ' on' : '');
97
-
98
-	return "<li id='$prefix$id' class='$class_li'>"
99
-	. ((!$checkable and !$checked)
100
-		? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked))
101
-	. plugin_resume($info, $dir_plugins, $plug_file, $url_page)
102
-	. $cfg
103
-	. $erreur
104
-	. (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file))
105
-		? plugin_desintalle($plug_file, $nom, $dir_plugins) : '')
106
-	. "<div class='details'>" // pour l'ajax de exec/info_plugin
107
-	. (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins))
108
-	. '</div>'
109
-	. '</li>';
36
+    static $id_input = 0;
37
+    static $versions = [];
38
+
39
+    $force_reload = (_request('var_mode') == 'recalcul');
40
+    $get_infos = charger_fonction('get_infos', 'plugins');
41
+    $info = $get_infos($plug_file, $force_reload, $dir_plugins);
42
+    $prefix = $info['prefix'];
43
+    $cfg = '';
44
+    $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST);
45
+    $nom = plugin_nom($info, $dir_plugins, $plug_file);
46
+    $erreur = '';
47
+
48
+    if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) {
49
+        $info['slogan'] = _T('plugin_info_non_compatible_spip');
50
+        $erreur = http_img_pack(
51
+            'plugin-dis-32.png',
52
+            _T('plugin_info_non_compatible_spip'),
53
+            " class='picto_err'",
54
+            _T('plugin_info_non_compatible_spip')
55
+        );
56
+        $class_li .= ' disabled';
57
+        $checkable = false;
58
+    } elseif (isset($info['erreur'])) {
59
+        $class_li .= ' error';
60
+        $erreur = http_img_pack(
61
+            'plugin-err-32.png',
62
+            _T('plugin_info_erreur_xml'),
63
+            " class='picto_err'",
64
+            _T('plugin_info_erreur_xml')
65
+        )
66
+            . "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>';
67
+        $checkable = false;
68
+    } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) {
69
+        $class_li .= ' error';
70
+        $erreur = http_img_pack(
71
+            'plugin-err-32.png',
72
+            _T('plugin_impossible_activer', ['plugin' => $nom]),
73
+            " class='picto_err'",
74
+            _T('plugin_impossible_activer', ['plugin' => $nom])
75
+        )
76
+            . "<div class='erreur'>" . implode(
77
+                '<br />',
78
+                $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]
79
+            ) . '</div>';
80
+    } else {
81
+        $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : '';
82
+        if (defined('_DEV_VERSION_SPIP_COMPAT') and !plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'])) {
83
+            //$info['slogan'] = _T('plugin_info_non_compatible_spip');
84
+            $erreur = http_img_pack(
85
+                'plugin-dis-32.png',
86
+                _T('plugin_info_non_compatible_spip'),
87
+                " class='picto_err picto_compat_forcee'",
88
+                _L('Version incompatible : compatibilité forcée')
89
+            );
90
+        }
91
+    }
92
+
93
+    // numerotons les occurrences d'un meme prefix
94
+    $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : '';
95
+
96
+    $class_li .= ($actif ? ' actif' : '') . ($expose ? ' on' : '');
97
+
98
+    return "<li id='$prefix$id' class='$class_li'>"
99
+    . ((!$checkable and !$checked)
100
+        ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked))
101
+    . plugin_resume($info, $dir_plugins, $plug_file, $url_page)
102
+    . $cfg
103
+    . $erreur
104
+    . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file))
105
+        ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '')
106
+    . "<div class='details'>" // pour l'ajax de exec/info_plugin
107
+    . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins))
108
+    . '</div>'
109
+    . '</li>';
110 110
 }
111 111
 
112 112
 function plugin_bouton_config($nom, $infos, $dir) {
113
-	// la verification se base sur le filesystem
114
-	// il faut donc n'utiliser que des minuscules, par convention
115
-	$prefix = strtolower($infos['prefix']);
116
-	// si paquet.xml fournit un squelette, le prendre
117
-	if (isset($infos['config']) and $infos['config']) {
118
-		return recuperer_fond(
119
-			"$dir$nom/" . $infos['config'],
120
-			[
121
-				'script' => 'configurer_' . $prefix,
122
-				'nom' => $nom
123
-			]
124
-		);
125
-	}
126
-
127
-	// si le plugin CFG est la, l'essayer
128
-	if (defined('_DIR_PLUGIN_CFG')) {
129
-		if (include_spip('inc/cfg')) { // test CFG version >= 1.0.5
130
-		if ($cfg = icone_lien_cfg("$dir$nom", 'cfg')) {
131
-				return "<div class='cfg_link'>$cfg</div>";
132
-		}
133
-		}
134
-	}
135
-
136
-	// sinon prendre le squelette std sur le nom std
137
-	return recuperer_fond(
138
-		'prive/squelettes/inclure/cfg',
139
-		[
140
-			'script' => 'configurer_' . $prefix,
141
-			'nom' => $nom
142
-		]
143
-	);
113
+    // la verification se base sur le filesystem
114
+    // il faut donc n'utiliser que des minuscules, par convention
115
+    $prefix = strtolower($infos['prefix']);
116
+    // si paquet.xml fournit un squelette, le prendre
117
+    if (isset($infos['config']) and $infos['config']) {
118
+        return recuperer_fond(
119
+            "$dir$nom/" . $infos['config'],
120
+            [
121
+                'script' => 'configurer_' . $prefix,
122
+                'nom' => $nom
123
+            ]
124
+        );
125
+    }
126
+
127
+    // si le plugin CFG est la, l'essayer
128
+    if (defined('_DIR_PLUGIN_CFG')) {
129
+        if (include_spip('inc/cfg')) { // test CFG version >= 1.0.5
130
+        if ($cfg = icone_lien_cfg("$dir$nom", 'cfg')) {
131
+                return "<div class='cfg_link'>$cfg</div>";
132
+        }
133
+        }
134
+    }
135
+
136
+    // sinon prendre le squelette std sur le nom std
137
+    return recuperer_fond(
138
+        'prive/squelettes/inclure/cfg',
139
+        [
140
+            'script' => 'configurer_' . $prefix,
141
+            'nom' => $nom
142
+        ]
143
+    );
144 144
 }
145 145
 
146 146
 // checkbox pour activer ou desactiver
147 147
 // si ce n'est pas une extension
148 148
 
149 149
 function plugin_checkbox($id_input, $file, $actif) {
150
-	$name = substr(md5($file), 0, 16);
151
-
152
-	return "<div class='check'>\n"
153
-	. "<input type='checkbox' name='s$name' id='label_$id_input'"
154
-	. ($actif ? " checked='checked'" : '')
155
-	. " class='checkbox'  value='O' />"
156
-	. "\n<label for='label_$id_input'>" . _T('activer_plugin') . '</label>'
157
-	. '</div>';
150
+    $name = substr(md5($file), 0, 16);
151
+
152
+    return "<div class='check'>\n"
153
+    . "<input type='checkbox' name='s$name' id='label_$id_input'"
154
+    . ($actif ? " checked='checked'" : '')
155
+    . " class='checkbox'  value='O' />"
156
+    . "\n<label for='label_$id_input'>" . _T('activer_plugin') . '</label>'
157
+    . '</div>';
158 158
 }
159 159
 
160 160
 function plugin_nom($info, $dir_plugins, $plug_file) {
161
-	$prefix = $info['prefix'];
162
-	$dir = "$dir_plugins$plug_file";
163
-	// Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom"
164
-	if ($info['dtd'] == 'paquet') {
165
-		$nom = plugin_typo("{$prefix}_nom", "$dir/lang/paquet-$prefix");
166
-		if (!$nom) {
167
-			$nom = typo($info['nom']);
168
-		}
169
-	} else {
170
-		$nom = typo(attribut_html($info['nom']));
171
-	}
172
-
173
-	return trim($nom);
161
+    $prefix = $info['prefix'];
162
+    $dir = "$dir_plugins$plug_file";
163
+    // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom"
164
+    if ($info['dtd'] == 'paquet') {
165
+        $nom = plugin_typo("{$prefix}_nom", "$dir/lang/paquet-$prefix");
166
+        if (!$nom) {
167
+            $nom = typo($info['nom']);
168
+        }
169
+    } else {
170
+        $nom = typo(attribut_html($info['nom']));
171
+    }
172
+
173
+    return trim($nom);
174 174
 }
175 175
 
176 176
 // Cartouche Resume
177 177
 function plugin_resume($info, $dir_plugins, $plug_file, $url_page) {
178
-	$prefix = $info['prefix'];
179
-	$dir = "$dir_plugins$plug_file";
180
-	$slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix"));
181
-	// une seule ligne dans le slogan : couper si besoin
182
-	if (($p = strpos($slogan, '<br />')) !== false) {
183
-		$slogan = substr($slogan, 0, $p);
184
-	}
185
-	// couper par securite
186
-	$slogan = couper($slogan, 80);
187
-
188
-	$nom = plugin_nom($info, $dir_plugins, $plug_file);
189
-
190
-	$url = parametre_url($url_page, 'plugin', substr($dir, strlen(_DIR_RACINE)));
191
-
192
-	$icon_class = 'icon';
193
-	$img = '';
194
-	if (isset($info['logo']) and $i = trim($info['logo'])) {
195
-		$img = http_img_pack("$dir/$i", '', " width='32' height='32'", '', ['variante_svg_si_possible' => true, 'chemin_image' => false]);
196
-		if (!extraire_attribut($img, 'src')) {
197
-			$img = '';
198
-		}
199
-	}
200
-	if (!$img) {
201
-		$img = http_img_pack('plugin-xx.svg', '', " width='32' height='32'");
202
-		$icon_class .= ' no-logo';
203
-	}
204
-
205
-	$i = "<div class='$icon_class'><a href='$url' rel='info'>$img</a></div>";
206
-
207
-	return "<div class='resume'>"
208
-	. "<h3><a href='$url' rel='info'>"
209
-	. $nom
210
-	. '</a></h3>'
211
-	. " <span class='version'>" . $info['version'] . '</span>'
212
-	. " <span class='etat'> - "
213
-	. plugin_etat_en_clair($info['etat'])
214
-	. '</span>'
215
-	. "<div class='short'>" . $slogan . '</div>'
216
-	. $i
217
-	. '</div>';
178
+    $prefix = $info['prefix'];
179
+    $dir = "$dir_plugins$plug_file";
180
+    $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix"));
181
+    // une seule ligne dans le slogan : couper si besoin
182
+    if (($p = strpos($slogan, '<br />')) !== false) {
183
+        $slogan = substr($slogan, 0, $p);
184
+    }
185
+    // couper par securite
186
+    $slogan = couper($slogan, 80);
187
+
188
+    $nom = plugin_nom($info, $dir_plugins, $plug_file);
189
+
190
+    $url = parametre_url($url_page, 'plugin', substr($dir, strlen(_DIR_RACINE)));
191
+
192
+    $icon_class = 'icon';
193
+    $img = '';
194
+    if (isset($info['logo']) and $i = trim($info['logo'])) {
195
+        $img = http_img_pack("$dir/$i", '', " width='32' height='32'", '', ['variante_svg_si_possible' => true, 'chemin_image' => false]);
196
+        if (!extraire_attribut($img, 'src')) {
197
+            $img = '';
198
+        }
199
+    }
200
+    if (!$img) {
201
+        $img = http_img_pack('plugin-xx.svg', '', " width='32' height='32'");
202
+        $icon_class .= ' no-logo';
203
+    }
204
+
205
+    $i = "<div class='$icon_class'><a href='$url' rel='info'>$img</a></div>";
206
+
207
+    return "<div class='resume'>"
208
+    . "<h3><a href='$url' rel='info'>"
209
+    . $nom
210
+    . '</a></h3>'
211
+    . " <span class='version'>" . $info['version'] . '</span>'
212
+    . " <span class='etat'> - "
213
+    . plugin_etat_en_clair($info['etat'])
214
+    . '</span>'
215
+    . "<div class='short'>" . $slogan . '</div>'
216
+    . $i
217
+    . '</div>';
218 218
 }
219 219
 
220 220
 function plugin_desintalle($plug_file, $nom, $dir_plugins = null) {
221
-	if (!$dir_plugins) {
222
-		$dir_plugins = _DIR_PLUGINS;
223
-	}
221
+    if (!$dir_plugins) {
222
+        $dir_plugins = _DIR_PLUGINS;
223
+    }
224 224
 
225
-	$action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin');
226
-	$text = _T('bouton_desinstaller');
227
-	$text2 = _T('info_desinstaller_plugin');
228
-	$file = basename($plug_file);
225
+    $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin');
226
+    $text = _T('bouton_desinstaller');
227
+    $text2 = _T('info_desinstaller_plugin');
228
+    $file = basename($plug_file);
229 229
 
230
-	return "<div class='actions'>[" .
231
-	"<a href='$action'
230
+    return "<div class='actions'>[" .
231
+    "<a href='$action'
232 232
 		onclick='return confirm(\"$text $nom ?\\n$text2\")'>"
233
-	. $text
234
-	. '</a>]</div>';
233
+    . $text
234
+    . '</a>]</div>';
235 235
 }
236 236
 
237 237
 /**
@@ -245,145 +245,145 @@  discard block
 block discarded – undo
245 245
  *     Traduction de l'état dans la langue en cours
246 246
  **/
247 247
 function plugin_etat_en_clair($etat) {
248
-	if (!in_array($etat, ['stable', 'test', 'experimental'])) {
249
-		$etat = 'developpement';
250
-	}
248
+    if (!in_array($etat, ['stable', 'test', 'experimental'])) {
249
+        $etat = 'developpement';
250
+    }
251 251
 
252
-	return _T('plugin_etat_' . $etat);
252
+    return _T('plugin_etat_' . $etat);
253 253
 }
254 254
 
255 255
 function plugin_propre($texte, $module = '', $propre = 'propre') {
256
-	// retirer le retour a la racine du module, car le find_in_path se fait depuis la racine
257
-	if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) {
258
-		$module = substr($module, strlen(_DIR_RACINE));
259
-	}
260
-	if (preg_match('|^\w+_[\w_]+$|', $texte)) {
261
-		$texte = _T(($module ? "$module:" : '') . $texte, [], ['force' => false]);
262
-	}
263
-
264
-	return $propre($texte);
256
+    // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine
257
+    if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) {
258
+        $module = substr($module, strlen(_DIR_RACINE));
259
+    }
260
+    if (preg_match('|^\w+_[\w_]+$|', $texte)) {
261
+        $texte = _T(($module ? "$module:" : '') . $texte, [], ['force' => false]);
262
+    }
263
+
264
+    return $propre($texte);
265 265
 }
266 266
 
267 267
 function plugin_typo($texte, $module = '') {
268
-	return plugin_propre($texte, $module, 'typo');
268
+    return plugin_propre($texte, $module, 'typo');
269 269
 }
270 270
 
271 271
 
272 272
 function affiche_bloc_plugin($plug_file, $info, $dir_plugins = null) {
273
-	$log = null;
274
-	if (!$dir_plugins) {
275
-		$dir_plugins = _DIR_PLUGINS;
276
-	}
277
-
278
-	$prefix = $info['prefix'];
279
-	$dir = "$dir_plugins$plug_file/lang/paquet-$prefix";
280
-
281
-	$s = '';
282
-	// TODO: le traiter_multi ici n'est pas beau
283
-	// cf. description du plugin/_stable_/ortho/plugin.xml
284
-	// concerne les anciens plugin.xml donc on devrait plus en avoir besoin
285
-	$description = '';
286
-	if (isset($info['description'])) {
287
-		$description = plugin_propre($info['description'], $dir);
288
-	}
289
-
290
-	if (
291
-		isset($info['documentation'])
292
-		and $lien = $info['documentation']
293
-	) {
294
-		$description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>';
295
-	}
296
-	$s .= "<dd class='desc'>" . $description . "</dd>\n";
297
-
298
-	if (isset($info['auteur'])) {
299
-		if (is_array($info['auteur'])) {
300
-			$a = formater_credits($info['auteur'], ', ');
301
-		} // pour compat mais ne doit plus arriver
302
-		else {
303
-			$a = trim($info['auteur']);
304
-		}
305
-		if ($a) {
306
-			$s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre(
307
-				$a,
308
-				$dir
309
-			)) . "</dd>\n";
310
-		}
311
-	}
312
-
313
-	if (isset($info['credit'])) {
314
-		if ($a = formater_credits($info['credit'], ', ')) {
315
-			$s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre(
316
-				$a,
317
-				$dir
318
-			)) . "</dd>\n";
319
-		}
320
-	}
321
-
322
-	if (isset($info['licence'])) {
323
-		if (is_array($info['licence'])) {
324
-			$a = formater_credits($info['licence'], ', ');
325
-		} // pour compat mais ne doit plus arriver
326
-		else {
327
-			$a = trim($info['licence']);
328
-		}
329
-		if ($a) {
330
-			$s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre(
331
-				$a,
332
-				$dir
333
-			)) . "</dd>\n";
334
-		}
335
-	}
336
-
337
-	$s = "<dl class='description'>$s</dl>";
338
-
339
-	//
340
-	// Ajouter les infos techniques
341
-	//
342
-	$infotech = [];
343
-
344
-	$version = '<dt>' . _T('version') . '</dt><dd>' . $info['version'];
345
-	// Version VCS
346
-	if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) {
347
-		$version .= ' ' . $vcs;
348
-	}
349
-	$version .= '</dd>';
350
-	$infotech[] = $version;
351
-	$infotech[] = '<dt>' . _T('repertoire_plugins') . '</dt><dd>' . joli_repertoire("$dir_plugins$plug_file") . '</dd>';
352
-	// source zip le cas echeant
353
-	$infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log)
354
-		and preg_match(',^source:(.*)$,m', $log, $r))
355
-		? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . '</dd>'
356
-		: '';
357
-
358
-	$infotech[] = !$info['necessite'] ? '' :
359
-		('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(
360
-			' ',
361
-			array_map('array_shift', $info['necessite'])
362
-		) . '</dd>');
363
-
364
-	$s .= "<dl class='tech'>"
365
-		. join('', $infotech)
366
-		. '</dl>';
367
-
368
-
369
-	return $s;
273
+    $log = null;
274
+    if (!$dir_plugins) {
275
+        $dir_plugins = _DIR_PLUGINS;
276
+    }
277
+
278
+    $prefix = $info['prefix'];
279
+    $dir = "$dir_plugins$plug_file/lang/paquet-$prefix";
280
+
281
+    $s = '';
282
+    // TODO: le traiter_multi ici n'est pas beau
283
+    // cf. description du plugin/_stable_/ortho/plugin.xml
284
+    // concerne les anciens plugin.xml donc on devrait plus en avoir besoin
285
+    $description = '';
286
+    if (isset($info['description'])) {
287
+        $description = plugin_propre($info['description'], $dir);
288
+    }
289
+
290
+    if (
291
+        isset($info['documentation'])
292
+        and $lien = $info['documentation']
293
+    ) {
294
+        $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>';
295
+    }
296
+    $s .= "<dd class='desc'>" . $description . "</dd>\n";
297
+
298
+    if (isset($info['auteur'])) {
299
+        if (is_array($info['auteur'])) {
300
+            $a = formater_credits($info['auteur'], ', ');
301
+        } // pour compat mais ne doit plus arriver
302
+        else {
303
+            $a = trim($info['auteur']);
304
+        }
305
+        if ($a) {
306
+            $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre(
307
+                $a,
308
+                $dir
309
+            )) . "</dd>\n";
310
+        }
311
+    }
312
+
313
+    if (isset($info['credit'])) {
314
+        if ($a = formater_credits($info['credit'], ', ')) {
315
+            $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre(
316
+                $a,
317
+                $dir
318
+            )) . "</dd>\n";
319
+        }
320
+    }
321
+
322
+    if (isset($info['licence'])) {
323
+        if (is_array($info['licence'])) {
324
+            $a = formater_credits($info['licence'], ', ');
325
+        } // pour compat mais ne doit plus arriver
326
+        else {
327
+            $a = trim($info['licence']);
328
+        }
329
+        if ($a) {
330
+            $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre(
331
+                $a,
332
+                $dir
333
+            )) . "</dd>\n";
334
+        }
335
+    }
336
+
337
+    $s = "<dl class='description'>$s</dl>";
338
+
339
+    //
340
+    // Ajouter les infos techniques
341
+    //
342
+    $infotech = [];
343
+
344
+    $version = '<dt>' . _T('version') . '</dt><dd>' . $info['version'];
345
+    // Version VCS
346
+    if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) {
347
+        $version .= ' ' . $vcs;
348
+    }
349
+    $version .= '</dd>';
350
+    $infotech[] = $version;
351
+    $infotech[] = '<dt>' . _T('repertoire_plugins') . '</dt><dd>' . joli_repertoire("$dir_plugins$plug_file") . '</dd>';
352
+    // source zip le cas echeant
353
+    $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log)
354
+        and preg_match(',^source:(.*)$,m', $log, $r))
355
+        ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . '</dd>'
356
+        : '';
357
+
358
+    $infotech[] = !$info['necessite'] ? '' :
359
+        ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(
360
+            ' ',
361
+            array_map('array_shift', $info['necessite'])
362
+        ) . '</dd>');
363
+
364
+    $s .= "<dl class='tech'>"
365
+        . join('', $infotech)
366
+        . '</dl>';
367
+
368
+
369
+    return $s;
370 370
 }
371 371
 
372 372
 function formater_credits($infos, $sep = ', ') {
373
-	$texte = '';
374
-
375
-	foreach ($infos as $_credit) {
376
-		if ($texte) {
377
-			$texte .= $sep;
378
-		}
379
-		// Si le credit en cours n'est pas un array c'est donc un copyright
380
-		$texte .=
381
-			(!is_array($_credit))
382
-				? PtoBR(propre($_credit))
383
-				: ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') .
384
-				$_credit['nom'] .
385
-				($_credit['url'] ? '</a>' : '');
386
-	}
387
-
388
-	return $texte;
373
+    $texte = '';
374
+
375
+    foreach ($infos as $_credit) {
376
+        if ($texte) {
377
+            $texte .= $sep;
378
+        }
379
+        // Si le credit en cours n'est pas un array c'est donc un copyright
380
+        $texte .=
381
+            (!is_array($_credit))
382
+                ? PtoBR(propre($_credit))
383
+                : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') .
384
+                $_credit['nom'] .
385
+                ($_credit['url'] ? '</a>' : '');
386
+    }
387
+
388
+    return $texte;
389 389
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -35 removed lines patch added patch discarded remove patch
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 			" class='picto_err'",
64 64
 			_T('plugin_info_erreur_xml')
65 65
 		)
66
-			. "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>';
66
+			. "<div class='erreur'>".join('<br >', $info['erreur']).'</div>';
67 67
 		$checkable = false;
68
-	} elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) {
68
+	} elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])) {
69 69
 		$class_li .= ' error';
70 70
 		$erreur = http_img_pack(
71 71
 			'plugin-err-32.png',
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
 			" class='picto_err'",
74 74
 			_T('plugin_impossible_activer', ['plugin' => $nom])
75 75
 		)
76
-			. "<div class='erreur'>" . implode(
76
+			. "<div class='erreur'>".implode(
77 77
 				'<br />',
78
-				$GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]
79
-			) . '</div>';
78
+				$GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file]
79
+			).'</div>';
80 80
 	} else {
81 81
 		$cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : '';
82 82
 		if (defined('_DEV_VERSION_SPIP_COMPAT') and !plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'])) {
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 	// numerotons les occurrences d'un meme prefix
94 94
 	$versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : '';
95 95
 
96
-	$class_li .= ($actif ? ' actif' : '') . ($expose ? ' on' : '');
96
+	$class_li .= ($actif ? ' actif' : '').($expose ? ' on' : '');
97 97
 
98 98
 	return "<li id='$prefix$id' class='$class_li'>"
99 99
 	. ((!$checkable and !$checked)
100
-		? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked))
100
+		? '' : plugin_checkbox(++$id_input, $dir_plugins.$plug_file, $checked))
101 101
 	. plugin_resume($info, $dir_plugins, $plug_file, $url_page)
102 102
 	. $cfg
103 103
 	. $erreur
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 	// si paquet.xml fournit un squelette, le prendre
117 117
 	if (isset($infos['config']) and $infos['config']) {
118 118
 		return recuperer_fond(
119
-			"$dir$nom/" . $infos['config'],
119
+			"$dir$nom/".$infos['config'],
120 120
 			[
121
-				'script' => 'configurer_' . $prefix,
121
+				'script' => 'configurer_'.$prefix,
122 122
 				'nom' => $nom
123 123
 			]
124 124
 		);
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	return recuperer_fond(
138 138
 		'prive/squelettes/inclure/cfg',
139 139
 		[
140
-			'script' => 'configurer_' . $prefix,
140
+			'script' => 'configurer_'.$prefix,
141 141
 			'nom' => $nom
142 142
 		]
143 143
 	);
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	. "<input type='checkbox' name='s$name' id='label_$id_input'"
154 154
 	. ($actif ? " checked='checked'" : '')
155 155
 	. " class='checkbox'  value='O' />"
156
-	. "\n<label for='label_$id_input'>" . _T('activer_plugin') . '</label>'
156
+	. "\n<label for='label_$id_input'>"._T('activer_plugin').'</label>'
157 157
 	. '</div>';
158 158
 }
159 159
 
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
 	. "<h3><a href='$url' rel='info'>"
209 209
 	. $nom
210 210
 	. '</a></h3>'
211
-	. " <span class='version'>" . $info['version'] . '</span>'
211
+	. " <span class='version'>".$info['version'].'</span>'
212 212
 	. " <span class='etat'> - "
213 213
 	. plugin_etat_en_clair($info['etat'])
214 214
 	. '</span>'
215
-	. "<div class='short'>" . $slogan . '</div>'
215
+	. "<div class='short'>".$slogan.'</div>'
216 216
 	. $i
217 217
 	. '</div>';
218 218
 }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	$text2 = _T('info_desinstaller_plugin');
228 228
 	$file = basename($plug_file);
229 229
 
230
-	return "<div class='actions'>[" .
230
+	return "<div class='actions'>[".
231 231
 	"<a href='$action'
232 232
 		onclick='return confirm(\"$text $nom ?\\n$text2\")'>"
233 233
 	. $text
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 		$etat = 'developpement';
250 250
 	}
251 251
 
252
-	return _T('plugin_etat_' . $etat);
252
+	return _T('plugin_etat_'.$etat);
253 253
 }
254 254
 
255 255
 function plugin_propre($texte, $module = '', $propre = 'propre') {
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 		$module = substr($module, strlen(_DIR_RACINE));
259 259
 	}
260 260
 	if (preg_match('|^\w+_[\w_]+$|', $texte)) {
261
-		$texte = _T(($module ? "$module:" : '') . $texte, [], ['force' => false]);
261
+		$texte = _T(($module ? "$module:" : '').$texte, [], ['force' => false]);
262 262
 	}
263 263
 
264 264
 	return $propre($texte);
@@ -291,9 +291,9 @@  discard block
 block discarded – undo
291 291
 		isset($info['documentation'])
292 292
 		and $lien = $info['documentation']
293 293
 	) {
294
-		$description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>';
294
+		$description .= "<p><em class='site'><a href='$lien' class='spip_out'>"._T('en_savoir_plus').'</a></em></p>';
295 295
 	}
296
-	$s .= "<dd class='desc'>" . $description . "</dd>\n";
296
+	$s .= "<dd class='desc'>".$description."</dd>\n";
297 297
 
298 298
 	if (isset($info['auteur'])) {
299 299
 		if (is_array($info['auteur'])) {
@@ -303,19 +303,19 @@  discard block
 block discarded – undo
303 303
 			$a = trim($info['auteur']);
304 304
 		}
305 305
 		if ($a) {
306
-			$s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre(
306
+			$s .= "<dt class='auteurs'>"._T('public:par_auteur')."</dt><dd class='auteurs'>".PtoBR(propre(
307 307
 				$a,
308 308
 				$dir
309
-			)) . "</dd>\n";
309
+			))."</dd>\n";
310 310
 		}
311 311
 	}
312 312
 
313 313
 	if (isset($info['credit'])) {
314 314
 		if ($a = formater_credits($info['credit'], ', ')) {
315
-			$s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre(
315
+			$s .= "<dt class='credits'>"._T('plugin_info_credit')."</dt><dd class='credits'>".PtoBR(propre(
316 316
 				$a,
317 317
 				$dir
318
-			)) . "</dd>\n";
318
+			))."</dd>\n";
319 319
 		}
320 320
 	}
321 321
 
@@ -327,10 +327,10 @@  discard block
 block discarded – undo
327 327
 			$a = trim($info['licence']);
328 328
 		}
329 329
 		if ($a) {
330
-			$s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre(
330
+			$s .= "<dt class='licence'>"._T('intitule_licence')."</dt><dd class='licence'>".PtoBR(propre(
331 331
 				$a,
332 332
 				$dir
333
-			)) . "</dd>\n";
333
+			))."</dd>\n";
334 334
 		}
335 335
 	}
336 336
 
@@ -341,25 +341,24 @@  discard block
 block discarded – undo
341 341
 	//
342 342
 	$infotech = [];
343 343
 
344
-	$version = '<dt>' . _T('version') . '</dt><dd>' . $info['version'];
344
+	$version = '<dt>'._T('version').'</dt><dd>'.$info['version'];
345 345
 	// Version VCS
346
-	if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) {
347
-		$version .= ' ' . $vcs;
346
+	if ($vcs = version_vcs_courante($dir_plugins.$plug_file)) {
347
+		$version .= ' '.$vcs;
348 348
 	}
349 349
 	$version .= '</dd>';
350 350
 	$infotech[] = $version;
351
-	$infotech[] = '<dt>' . _T('repertoire_plugins') . '</dt><dd>' . joli_repertoire("$dir_plugins$plug_file") . '</dd>';
351
+	$infotech[] = '<dt>'._T('repertoire_plugins').'</dt><dd>'.joli_repertoire("$dir_plugins$plug_file").'</dd>';
352 352
 	// source zip le cas echeant
353
-	$infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log)
353
+	$infotech[] = (lire_fichier($dir_plugins.$plug_file.'/install.log', $log)
354 354
 		and preg_match(',^source:(.*)$,m', $log, $r))
355
-		? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . '</dd>'
355
+		? '<dt>'._T('plugin_source').'</dt><dd>'.trim($r[1]).'</dd>'
356 356
 		: '';
357 357
 
358
-	$infotech[] = !$info['necessite'] ? '' :
359
-		('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(
358
+	$infotech[] = !$info['necessite'] ? '' : ('<dt>'._T('plugin_info_necessite').'</dt><dd>'.join(
360 359
 			' ',
361 360
 			array_map('array_shift', $info['necessite'])
362
-		) . '</dd>');
361
+		).'</dd>');
363 362
 
364 363
 	$s .= "<dl class='tech'>"
365 364
 		. join('', $infotech)
@@ -380,8 +379,8 @@  discard block
 block discarded – undo
380 379
 		$texte .=
381 380
 			(!is_array($_credit))
382 381
 				? PtoBR(propre($_credit))
383
-				: ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') .
384
-				$_credit['nom'] .
382
+				: ($_credit['url'] ? '<a href="'.$_credit['url'].'">' : '').
383
+				$_credit['nom'].
385 384
 				($_credit['url'] ? '</a>' : '');
386 385
 	}
387 386
 
Please login to merge, or discard this patch.
ecrire/plugins/afficher_liste.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 include_spip('inc/charsets');
17 17
 
@@ -27,90 +27,90 @@  discard block
 block discarded – undo
27 27
  * @return string
28 28
  */
29 29
 function plugins_afficher_liste_dist(
30
-	$url_page,
31
-	$liste_plugins,
32
-	$liste_plugins_checked,
33
-	$liste_plugins_actifs,
34
-	$dir_plugins = _DIR_PLUGINS,
35
-	$afficher_un = 'afficher_plugin'
30
+    $url_page,
31
+    $liste_plugins,
32
+    $liste_plugins_checked,
33
+    $liste_plugins_actifs,
34
+    $dir_plugins = _DIR_PLUGINS,
35
+    $afficher_un = 'afficher_plugin'
36 36
 ) {
37
-	$get_infos = charger_fonction('get_infos', 'plugins');
38
-	$ligne_plug = charger_fonction($afficher_un, 'plugins');
37
+    $get_infos = charger_fonction('get_infos', 'plugins');
38
+    $ligne_plug = charger_fonction($afficher_un, 'plugins');
39 39
 
40
-	$all_infos = $get_infos($liste_plugins, false, $dir_plugins);
40
+    $all_infos = $get_infos($liste_plugins, false, $dir_plugins);
41 41
 
42
-	$all_infos = pipeline(
43
-		'filtrer_liste_plugins',
44
-		[
45
-			'args' => [
46
-				'liste_plugins' => $liste_plugins,
47
-				'liste_plugins_checked' => $liste_plugins_checked,
48
-				'liste_plugins_actifs' => $liste_plugins_actifs,
49
-				'dir_plugins' => $dir_plugins
50
-			],
51
-			'data' => $all_infos
52
-		]
53
-	);
42
+    $all_infos = pipeline(
43
+        'filtrer_liste_plugins',
44
+        [
45
+            'args' => [
46
+                'liste_plugins' => $liste_plugins,
47
+                'liste_plugins_checked' => $liste_plugins_checked,
48
+                'liste_plugins_actifs' => $liste_plugins_actifs,
49
+                'dir_plugins' => $dir_plugins
50
+            ],
51
+            'data' => $all_infos
52
+        ]
53
+    );
54 54
 
55
-	$liste_plugins = array_flip($liste_plugins);
56
-	foreach ($liste_plugins as $chemin => $v) {
57
-		// des plugins ont pu etre enleves de la liste par le pipeline. On en tient compte.
58
-		if (isset($all_infos[$chemin])) {
59
-			$liste_plugins[$chemin] = strtoupper(trim(typo(translitteration(unicode2charset(html2unicode($all_infos[$chemin]['nom']))))));
60
-		} else {
61
-			unset($liste_plugins[$chemin]);
62
-		}
63
-	}
64
-	asort($liste_plugins);
65
-	$exposed = urldecode(_request('plugin'));
55
+    $liste_plugins = array_flip($liste_plugins);
56
+    foreach ($liste_plugins as $chemin => $v) {
57
+        // des plugins ont pu etre enleves de la liste par le pipeline. On en tient compte.
58
+        if (isset($all_infos[$chemin])) {
59
+            $liste_plugins[$chemin] = strtoupper(trim(typo(translitteration(unicode2charset(html2unicode($all_infos[$chemin]['nom']))))));
60
+        } else {
61
+            unset($liste_plugins[$chemin]);
62
+        }
63
+    }
64
+    asort($liste_plugins);
65
+    $exposed = urldecode(_request('plugin'));
66 66
 
67
-	$block_par_lettre = false;//count($liste_plugins)>10;
68
-	$fast_liste_plugins_actifs = [];
69
-	$fast_liste_plugins_checked = [];
70
-	if (is_array($liste_plugins_actifs)) {
71
-		$fast_liste_plugins_actifs = array_flip($liste_plugins_actifs);
72
-	}
73
-	if (is_array($liste_plugins_checked)) {
74
-		$fast_liste_plugins_checked = array_flip($liste_plugins_checked);
75
-	}
67
+    $block_par_lettre = false;//count($liste_plugins)>10;
68
+    $fast_liste_plugins_actifs = [];
69
+    $fast_liste_plugins_checked = [];
70
+    if (is_array($liste_plugins_actifs)) {
71
+        $fast_liste_plugins_actifs = array_flip($liste_plugins_actifs);
72
+    }
73
+    if (is_array($liste_plugins_checked)) {
74
+        $fast_liste_plugins_checked = array_flip($liste_plugins_checked);
75
+    }
76 76
 
77
-	$res = '';
78
-	$block = '';
79
-	$initiale = '';
80
-	$block_actif = false;
81
-	foreach ($liste_plugins as $plug => $nom) {
82
-		if (($i = substr($nom, 0, 1)) !== $initiale) {
83
-			$res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block;
84
-			$initiale = $i;
85
-			$block = '';
86
-			$block_actif = false;
87
-		}
88
-		// le rep suivant
89
-		$actif = isset($fast_liste_plugins_actifs[$plug]);
90
-		$checked = isset($fast_liste_plugins_checked[$plug]);
91
-		$block_actif = $block_actif | $actif;
92
-		$expose = ($exposed and ($exposed == $plug or $exposed == $dir_plugins . $plug or $exposed == substr(
93
-			$dir_plugins,
94
-			strlen(_DIR_RACINE)
95
-		) . $plug));
96
-		$block .= $ligne_plug($url_page, $plug, $checked, $actif, $expose, 'item', $dir_plugins) . "\n";
97
-	}
98
-	$res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block;
99
-	$class = basename($dir_plugins);
77
+    $res = '';
78
+    $block = '';
79
+    $initiale = '';
80
+    $block_actif = false;
81
+    foreach ($liste_plugins as $plug => $nom) {
82
+        if (($i = substr($nom, 0, 1)) !== $initiale) {
83
+            $res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block;
84
+            $initiale = $i;
85
+            $block = '';
86
+            $block_actif = false;
87
+        }
88
+        // le rep suivant
89
+        $actif = isset($fast_liste_plugins_actifs[$plug]);
90
+        $checked = isset($fast_liste_plugins_checked[$plug]);
91
+        $block_actif = $block_actif | $actif;
92
+        $expose = ($exposed and ($exposed == $plug or $exposed == $dir_plugins . $plug or $exposed == substr(
93
+            $dir_plugins,
94
+            strlen(_DIR_RACINE)
95
+        ) . $plug));
96
+        $block .= $ligne_plug($url_page, $plug, $checked, $actif, $expose, 'item', $dir_plugins) . "\n";
97
+    }
98
+    $res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block;
99
+    $class = basename($dir_plugins);
100 100
 
101
-	return $res ? "<ul class='liste-items plugins $class'>$res</ul>" : '';
101
+    return $res ? "<ul class='liste-items plugins $class'>$res</ul>" : '';
102 102
 }
103 103
 
104 104
 
105 105
 function affiche_block_initiale($initiale, $block, $block_actif) {
106
-	if (strlen($block)) {
107
-		return "<li class='item'>"
108
-		. bouton_block_depliable($initiale, $block_actif ? true : false)
109
-		. debut_block_depliable($block_actif)
110
-		. "<ul>$block</ul>"
111
-		. fin_block()
112
-		. '</li>';
113
-	}
106
+    if (strlen($block)) {
107
+        return "<li class='item'>"
108
+        . bouton_block_depliable($initiale, $block_actif ? true : false)
109
+        . debut_block_depliable($block_actif)
110
+        . "<ul>$block</ul>"
111
+        . fin_block()
112
+        . '</li>';
113
+    }
114 114
 
115
-	return '';
115
+    return '';
116 116
 }
Please login to merge, or discard this patch.
ecrire/plugins/afficher_nom_plugin.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -11,61 +11,61 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 include_spip('inc/charsets');
17 17
 include_spip('inc/texte');
18 18
 include_spip('plugins/afficher_plugin');
19 19
 
20 20
 function plugins_afficher_nom_plugin_dist(
21
-	$url_page,
22
-	$plug_file,
23
-	$checked,
24
-	$actif,
25
-	$expose = false,
26
-	$class_li = 'item',
27
-	$dir_plugins = _DIR_PLUGINS
21
+    $url_page,
22
+    $plug_file,
23
+    $checked,
24
+    $actif,
25
+    $expose = false,
26
+    $class_li = 'item',
27
+    $dir_plugins = _DIR_PLUGINS
28 28
 ) {
29
-	static $id_input = 0;
30
-	static $versions = [];
29
+    static $id_input = 0;
30
+    static $versions = [];
31 31
 
32
-	$erreur = false;
33
-	$s = '';
32
+    $erreur = false;
33
+    $s = '';
34 34
 
35
-	$get_infos = charger_fonction('get_infos', 'plugins');
36
-	$info = $get_infos($plug_file, false, $dir_plugins);
35
+    $get_infos = charger_fonction('get_infos', 'plugins');
36
+    $info = $get_infos($plug_file, false, $dir_plugins);
37 37
 
38
-	// numerotons les occurences d'un meme prefix
39
-	$versions[$info['prefix']] = isset($versions[$info['prefix']]) ? $versions[$info['prefix']] + 1 : '';
40
-	$id = $info['prefix'] . $versions[$info['prefix']];
38
+    // numerotons les occurences d'un meme prefix
39
+    $versions[$info['prefix']] = isset($versions[$info['prefix']]) ? $versions[$info['prefix']] + 1 : '';
40
+    $id = $info['prefix'] . $versions[$info['prefix']];
41 41
 
42
-	$class = $class_li;
43
-	$class .= $actif ? ' actif' : '';
44
-	$class .= $expose ? ' on' : '';
45
-	$erreur = isset($info['erreur']);
46
-	if ($erreur) {
47
-		$class .= ' error';
48
-	}
49
-	$s .= "<li id='$id' class='$class'>";
42
+    $class = $class_li;
43
+    $class .= $actif ? ' actif' : '';
44
+    $class .= $expose ? ' on' : '';
45
+    $erreur = isset($info['erreur']);
46
+    if ($erreur) {
47
+        $class .= ' error';
48
+    }
49
+    $s .= "<li id='$id' class='$class'>";
50 50
 
51
-	// Cartouche Resume
52
-	$s .= "<div class='resume'>";
51
+    // Cartouche Resume
52
+    $s .= "<div class='resume'>";
53 53
 
54
-	$prefix = $info['prefix'];
55
-	$dir = "$dir_plugins$plug_file/lang/$prefix";
56
-	$desc = plugin_propre($info['description'], $dir);
57
-	$url_stat = parametre_url($url_page, 'plugin', $dir_plugins . $plug_file);
54
+    $prefix = $info['prefix'];
55
+    $dir = "$dir_plugins$plug_file/lang/$prefix";
56
+    $desc = plugin_propre($info['description'], $dir);
57
+    $url_stat = parametre_url($url_page, 'plugin', $dir_plugins . $plug_file);
58 58
 
59
-	$s .= "<strong class='nom'>" . typo($info['nom']) . '</strong>';
60
-	$s .= " <span class='version'>" . $info['version'] . '</span>';
61
-	$s .= " <span class='etat'> - " . plugin_etat_en_clair($info['etat']) . '</span>';
62
-	$s .= '</div>';
59
+    $s .= "<strong class='nom'>" . typo($info['nom']) . '</strong>';
60
+    $s .= " <span class='version'>" . $info['version'] . '</span>';
61
+    $s .= " <span class='etat'> - " . plugin_etat_en_clair($info['etat']) . '</span>';
62
+    $s .= '</div>';
63 63
 
64
-	if ($erreur) {
65
-		$s .= "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>';
66
-	}
64
+    if ($erreur) {
65
+        $s .= "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>';
66
+    }
67 67
 
68
-	$s .= '</li>';
68
+    $s .= '</li>';
69 69
 
70
-	return $s;
70
+    return $s;
71 71
 }
Please login to merge, or discard this patch.