Completed
Push — master ( 7c506a...1b45a2 )
by cam
01:11
created
ecrire/urls/page.php 2 patches
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');
@@ -30,68 +30,68 @@  discard block
 block discarded – undo
30 30
 // https://code.spip.net/@_generer_url_page
31 31
 function _generer_url_page($type, $id, $args = '', $ancre = '') {
32 32
 
33
-	if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls', true)) {
34
-		$url = $generer_url_externe($id, $args, $ancre);
35
-		if (null != $url) {
36
-			return $url;
37
-		}
38
-	}
33
+    if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls', true)) {
34
+        $url = $generer_url_externe($id, $args, $ancre);
35
+        if (null != $url) {
36
+            return $url;
37
+        }
38
+    }
39 39
 
40
-	$url = \_debut_urls_page . $type . \_debut_urls_page
41
-		. $id . \_debut_urls_page;
40
+    $url = \_debut_urls_page . $type . \_debut_urls_page
41
+        . $id . \_debut_urls_page;
42 42
 
43
-	if ($args) {
44
-		$args = strpos($url, '?') ? "&$args" : "?$args";
45
-	}
43
+    if ($args) {
44
+        $args = strpos($url, '?') ? "&$args" : "?$args";
45
+    }
46 46
 
47
-	return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : '');
47
+    return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : '');
48 48
 }
49 49
 
50 50
 // retrouve le fond et les parametres d'une URL abregee
51 51
 // le contexte deja existant est fourni dans args sous forme de tableau ou query string
52 52
 // https://code.spip.net/@urls_page_dist
53 53
 function urls_page_dist($i, &$entite, $args = '', $ancre = '') {
54
-	if (is_numeric($i)) {
55
-		return _generer_url_page($entite, $i, $args, $ancre);
56
-	}
57
-
58
-	// traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23
59
-	if ($GLOBALS['profondeur_url'] > 0 and $entite == 'sommaire') {
60
-		return [[], '404'];
61
-	}
62
-
63
-	// voir s'il faut recuperer le id_* implicite et les &debut_xx;
64
-	if (is_array($args)) {
65
-		$contexte = $args;
66
-	} else {
67
-		parse_str($args, $contexte);
68
-	}
69
-	include_spip('inc/urls');
70
-	$r = nettoyer_url_page($i, $contexte);
71
-	if ($r) {
72
-		array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici
73
-		return $r;
74
-	}
75
-
76
-	/*
54
+    if (is_numeric($i)) {
55
+        return _generer_url_page($entite, $i, $args, $ancre);
56
+    }
57
+
58
+    // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23
59
+    if ($GLOBALS['profondeur_url'] > 0 and $entite == 'sommaire') {
60
+        return [[], '404'];
61
+    }
62
+
63
+    // voir s'il faut recuperer le id_* implicite et les &debut_xx;
64
+    if (is_array($args)) {
65
+        $contexte = $args;
66
+    } else {
67
+        parse_str($args, $contexte);
68
+    }
69
+    include_spip('inc/urls');
70
+    $r = nettoyer_url_page($i, $contexte);
71
+    if ($r) {
72
+        array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici
73
+        return $r;
74
+    }
75
+
76
+    /*
77 77
 	 * Le bloc qui suit sert a faciliter les transitions depuis
78 78
 	 * le mode 'urls-propres' vers les modes 'urls-standard' et 'url-html'
79 79
 	 * Il est inutile de le recopier si vous personnalisez vos URLs
80 80
 	 * et votre .htaccess
81 81
 	 */
82
-	// Si on est revenu en mode html, mais c'est une ancienne url_propre
83
-	// on ne redirige pas, on assume le nouveau contexte (si possible)
84
-	$url = $i;
85
-	$url_propre = $url ?? $_SERVER['REDIRECT_url_propre'] ?? $_ENV['url_propre'] ?? '';
86
-
87
-	if ($url_propre) {
88
-		if ($GLOBALS['profondeur_url'] <= 0) {
89
-			$urls_anciennes = charger_fonction('propres', 'urls', true);
90
-		} else {
91
-			$urls_anciennes = charger_fonction('arbo', 'urls', true);
92
-		}
93
-
94
-		return $urls_anciennes ? $urls_anciennes($url_propre, $entite, $contexte) : '';
95
-	}
96
-	/* Fin du bloc compatibilite url-propres */
82
+    // Si on est revenu en mode html, mais c'est une ancienne url_propre
83
+    // on ne redirige pas, on assume le nouveau contexte (si possible)
84
+    $url = $i;
85
+    $url_propre = $url ?? $_SERVER['REDIRECT_url_propre'] ?? $_ENV['url_propre'] ?? '';
86
+
87
+    if ($url_propre) {
88
+        if ($GLOBALS['profondeur_url'] <= 0) {
89
+            $urls_anciennes = charger_fonction('propres', 'urls', true);
90
+        } else {
91
+            $urls_anciennes = charger_fonction('arbo', 'urls', true);
92
+        }
93
+
94
+        return $urls_anciennes ? $urls_anciennes($url_propre, $entite, $contexte) : '';
95
+    }
96
+    /* Fin du bloc compatibilite url-propres */
97 97
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 # attention toutefois seuls '' et '=' figurent dans les modes de compatibilite
24 24
 define('_separateur_urls_page', '');
25 25
 # on peut indiquer '' si on a installe le .htaccess
26
-define('_debut_urls_page', get_spip_script('./') . '?');
26
+define('_debut_urls_page', get_spip_script('./').'?');
27 27
 #######
28 28
 
29 29
 
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
 		}
38 38
 	}
39 39
 
40
-	$url = \_debut_urls_page . $type . \_debut_urls_page
41
-		. $id . \_debut_urls_page;
40
+	$url = \_debut_urls_page.$type.\_debut_urls_page
41
+		. $id.\_debut_urls_page;
42 42
 
43 43
 	if ($args) {
44 44
 		$args = strpos($url, '?') ? "&$args" : "?$args";
45 45
 	}
46 46
 
47
-	return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : '');
47
+	return _DIR_RACINE.$url.$args.($ancre ? "#$ancre" : '');
48 48
 }
49 49
 
50 50
 // retrouve le fond et les parametres d'une URL abregee
Please login to merge, or discard this patch.
ecrire/inc/prepare_recherche.php 1 patch
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 include_spip('inc/rechercher');
24 24
 if (!defined('_DELAI_CACHE_resultats')) {
25
-	define('_DELAI_CACHE_resultats', 600);
25
+    define('_DELAI_CACHE_resultats', 600);
26 26
 }
27 27
 
28 28
 /**
@@ -49,129 +49,129 @@  discard block
 block discarded – undo
49 49
  * @return array
50 50
  */
51 51
 function inc_prepare_recherche_dist(
52
-	$recherche,
53
-	$table = 'articles',
54
-	$cond = false,
55
-	$serveur = '',
56
-	$modificateurs = [],
57
-	$primary = ''
52
+    $recherche,
53
+    $table = 'articles',
54
+    $cond = false,
55
+    $serveur = '',
56
+    $modificateurs = [],
57
+    $primary = ''
58 58
 ) {
59
-	$where = null;
60
-	$rows = null;
61
-	static $cache = [];
62
-	$delai_fraicheur = min(
63
-		\_DELAI_CACHE_resultats,
64
-		time() - ($GLOBALS['meta']['derniere_modif'] ?? 0)
65
-	);
66
-
67
-	// si recherche n'est pas dans le contexte, on va prendre en globals
68
-	// ca permet de faire des inclure simple.
69
-	if (!isset($recherche) and isset($GLOBALS['recherche'])) {
70
-		$recherche = $GLOBALS['recherche'];
71
-	}
72
-
73
-	// traiter le cas {recherche?}
74
-	if ($cond and !strlen($recherche)) {
75
-		return [
76
-			'0 as points' /* as points */, /* where */
77
-			''
78
-		];
79
-	}
80
-
81
-
82
-	$rechercher = false;
83
-
84
-	$where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND');
85
-	if (!isset($cache[$serveur][$table][$recherche])) {
86
-		$hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
87
-		$hash = substr(md5($recherche . $table), 0, 16);
88
-		$where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
89
-		$row = sql_fetsel(
90
-			'recherche',
91
-			'spip_resultats AS resultats',
92
-			$where . " AND $where_resultat_recent",
93
-			'',
94
-			'',
95
-			'0,1'
96
-		);
97
-		if (
98
-			!$row
99
-			or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
100
-		) {
101
-			$rechercher = true;
102
-		}
103
-	}
104
-
105
-	// si on n'a pas encore traite les donnees dans une boucle precedente
106
-	if ($rechercher) {
107
-		//$tables = liste_des_champs();
108
-		$x = objet_type($table);
109
-		$points = recherche_en_base(
110
-			$recherche,
111
-			$x,
112
-			[
113
-				'score' => true,
114
-				'toutvoir' => true,
115
-				'jointures' => true
116
-			],
117
-			$serveur
118
-		);
119
-		// pas de résultat, pas de point
120
-		$points = $points[$x] ?? [];
121
-
122
-		// permettre aux plugins de modifier le resultat
123
-		$points = pipeline('prepare_recherche', [
124
-			'args' => [
125
-				'type' => $x,
126
-				'recherche' => $recherche,
127
-				'serveur' => $serveur,
128
-				'modificateurs' => $modificateurs
129
-			],
130
-			'data' => $points
131
-		]);
132
-
133
-		// supprimer les anciens resultats de cette recherche
134
-		// et les resultats trop vieux avec une marge
135
-		// pas de AS resultats dans un delete (mysql)
136
-		$whered = str_replace(
137
-			['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'],
138
-			['recherche', 'table_objet', 'serveur'],
139
-			$where
140
-		);
141
-
142
-		sql_delete(
143
-			'spip_resultats',
144
-			"NOT($where_resultat_recent) OR ($whered)"
145
-		);
146
-
147
-		// inserer les resultats dans la table de cache des resultats
148
-		if (is_countable($points) ? count($points) : 0) {
149
-			$tab_couples = [];
150
-			foreach ($points as $id => $p) {
151
-				$tab_couples[] = [
152
-					'recherche' => $hash,
153
-					'id' => $id,
154
-					'points' => $p['score'],
155
-					'table_objet' => $table,
156
-					'serveur' => $hash_serv,
157
-				];
158
-			}
159
-			sql_insertq_multi('spip_resultats', $tab_couples, []);
160
-		}
161
-	}
162
-
163
-	if (!isset($cache[$serveur][$table][$recherche])) {
164
-		if (!$serveur) {
165
-			$cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where];
166
-		} else {
167
-			if (sql_countsel('spip_resultats as resultats', $where)) {
168
-				$rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
169
-			}
170
-			$cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
171
-		}
172
-	}
173
-
174
-	return $cache[$serveur][$table][$recherche];
59
+    $where = null;
60
+    $rows = null;
61
+    static $cache = [];
62
+    $delai_fraicheur = min(
63
+        \_DELAI_CACHE_resultats,
64
+        time() - ($GLOBALS['meta']['derniere_modif'] ?? 0)
65
+    );
66
+
67
+    // si recherche n'est pas dans le contexte, on va prendre en globals
68
+    // ca permet de faire des inclure simple.
69
+    if (!isset($recherche) and isset($GLOBALS['recherche'])) {
70
+        $recherche = $GLOBALS['recherche'];
71
+    }
72
+
73
+    // traiter le cas {recherche?}
74
+    if ($cond and !strlen($recherche)) {
75
+        return [
76
+            '0 as points' /* as points */, /* where */
77
+            ''
78
+        ];
79
+    }
80
+
81
+
82
+    $rechercher = false;
83
+
84
+    $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND');
85
+    if (!isset($cache[$serveur][$table][$recherche])) {
86
+        $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
87
+        $hash = substr(md5($recherche . $table), 0, 16);
88
+        $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
89
+        $row = sql_fetsel(
90
+            'recherche',
91
+            'spip_resultats AS resultats',
92
+            $where . " AND $where_resultat_recent",
93
+            '',
94
+            '',
95
+            '0,1'
96
+        );
97
+        if (
98
+            !$row
99
+            or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
100
+        ) {
101
+            $rechercher = true;
102
+        }
103
+    }
104
+
105
+    // si on n'a pas encore traite les donnees dans une boucle precedente
106
+    if ($rechercher) {
107
+        //$tables = liste_des_champs();
108
+        $x = objet_type($table);
109
+        $points = recherche_en_base(
110
+            $recherche,
111
+            $x,
112
+            [
113
+                'score' => true,
114
+                'toutvoir' => true,
115
+                'jointures' => true
116
+            ],
117
+            $serveur
118
+        );
119
+        // pas de résultat, pas de point
120
+        $points = $points[$x] ?? [];
121
+
122
+        // permettre aux plugins de modifier le resultat
123
+        $points = pipeline('prepare_recherche', [
124
+            'args' => [
125
+                'type' => $x,
126
+                'recherche' => $recherche,
127
+                'serveur' => $serveur,
128
+                'modificateurs' => $modificateurs
129
+            ],
130
+            'data' => $points
131
+        ]);
132
+
133
+        // supprimer les anciens resultats de cette recherche
134
+        // et les resultats trop vieux avec une marge
135
+        // pas de AS resultats dans un delete (mysql)
136
+        $whered = str_replace(
137
+            ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'],
138
+            ['recherche', 'table_objet', 'serveur'],
139
+            $where
140
+        );
141
+
142
+        sql_delete(
143
+            'spip_resultats',
144
+            "NOT($where_resultat_recent) OR ($whered)"
145
+        );
146
+
147
+        // inserer les resultats dans la table de cache des resultats
148
+        if (is_countable($points) ? count($points) : 0) {
149
+            $tab_couples = [];
150
+            foreach ($points as $id => $p) {
151
+                $tab_couples[] = [
152
+                    'recherche' => $hash,
153
+                    'id' => $id,
154
+                    'points' => $p['score'],
155
+                    'table_objet' => $table,
156
+                    'serveur' => $hash_serv,
157
+                ];
158
+            }
159
+            sql_insertq_multi('spip_resultats', $tab_couples, []);
160
+        }
161
+    }
162
+
163
+    if (!isset($cache[$serveur][$table][$recherche])) {
164
+        if (!$serveur) {
165
+            $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where];
166
+        } else {
167
+            if (sql_countsel('spip_resultats as resultats', $where)) {
168
+                $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
169
+            }
170
+            $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
171
+        }
172
+    }
173
+
174
+    return $cache[$serveur][$table][$recherche];
175 175
 }
176 176
 
177 177
 
@@ -187,22 +187,22 @@  discard block
 block discarded – undo
187 187
  * @return array
188 188
  */
189 189
 function generer_select_where_explicites($table, $primary, $rows, $serveur) {
190
-	# calculer le {id_article IN()} et le {... as points}
191
-	if (!count($rows)) {
192
-		return ["''", '0=1'];
193
-	} else {
194
-		$listes_ids = [];
195
-		$select = '0';
196
-		foreach ($rows as $r) {
197
-			$listes_ids[$r['points']][] = $r['id'];
198
-		}
199
-
200
-		foreach ($listes_ids as $p => $ids) {
201
-			$select .= "+$p*(" .
202
-				sql_in("$table.$primary", $ids, '', $serveur)
203
-				. ') ';
204
-		}
205
-
206
-		return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)];
207
-	}
190
+    # calculer le {id_article IN()} et le {... as points}
191
+    if (!count($rows)) {
192
+        return ["''", '0=1'];
193
+    } else {
194
+        $listes_ids = [];
195
+        $select = '0';
196
+        foreach ($rows as $r) {
197
+            $listes_ids[$r['points']][] = $r['id'];
198
+        }
199
+
200
+        foreach ($listes_ids as $p => $ids) {
201
+            $select .= "+$p*(" .
202
+                sql_in("$table.$primary", $ids, '', $serveur)
203
+                . ') ';
204
+        }
205
+
206
+        return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)];
207
+    }
208 208
 }
Please login to merge, or discard this patch.