@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | */ |
| 334 | 334 | function _sqlite_func_preg_replace($quoi, $cherche, $remplace) { |
| 335 | 335 | #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
| 336 | - return preg_replace('%' . $cherche . '%', $remplace, $quoi); |
|
| 336 | + return preg_replace('%'.$cherche.'%', $remplace, $quoi); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | $u = $GLOBALS['meta']['pcre_u'] ?? 'u'; |
| 396 | 396 | |
| 397 | 397 | #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
| 398 | - return preg_match('%' . $cherche . '%imsS' . $u, $quoi); |
|
| 398 | + return preg_match('%'.$cherche.'%imsS'.$u, $quoi); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | $count = 0; |
| 445 | 445 | str_replace($mysql_to_strftime_not_ok, '', $conv, $count); |
| 446 | 446 | if ($count > 0) { |
| 447 | - spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR); |
|
| 447 | + spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.'._LOG_ERREUR); |
|
| 448 | 448 | } |
| 449 | 449 | $to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv); |
| 450 | 450 | } |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | */ |
| 464 | 464 | function _sqlite_func_to_days($d) { |
| 465 | 465 | static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
| 466 | - $result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 466 | + $result = $offset + (int) ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 467 | 467 | |
| 468 | 468 | #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
| 469 | 469 | return $result; |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -44,90 +44,90 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | function _sqlite_init_functions(&$sqlite) { |
| 46 | 46 | |
| 47 | - if (!$sqlite) { |
|
| 48 | - return false; |
|
| 49 | - } |
|
| 47 | + if (!$sqlite) { |
|
| 48 | + return false; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - $fonctions = [ |
|
| 53 | - // A |
|
| 54 | - 'ACOS' => ['acos', 1], |
|
| 55 | - 'ASIN' => ['asin', 1], |
|
| 56 | - 'ATAN' => ['atan', 1], // mysql accepte 2 params comme atan2… hum ? |
|
| 57 | - 'ATAN2' => ['atan2', 2], |
|
| 52 | + $fonctions = [ |
|
| 53 | + // A |
|
| 54 | + 'ACOS' => ['acos', 1], |
|
| 55 | + 'ASIN' => ['asin', 1], |
|
| 56 | + 'ATAN' => ['atan', 1], // mysql accepte 2 params comme atan2… hum ? |
|
| 57 | + 'ATAN2' => ['atan2', 2], |
|
| 58 | 58 | |
| 59 | - // C |
|
| 60 | - 'CEIL' => ['_sqlite_func_ceil', 1], |
|
| 61 | - 'CONCAT' => ['_sqlite_func_concat', -1], |
|
| 62 | - 'COS' => ['cos', 1], |
|
| 59 | + // C |
|
| 60 | + 'CEIL' => ['_sqlite_func_ceil', 1], |
|
| 61 | + 'CONCAT' => ['_sqlite_func_concat', -1], |
|
| 62 | + 'COS' => ['cos', 1], |
|
| 63 | 63 | |
| 64 | - // D |
|
| 65 | - 'DATE_FORMAT' => ['_sqlite_func_date_format', 2], // équivalent a strftime avec args inversés |
|
| 66 | - 'DAYOFMONTH' => ['_sqlite_func_dayofmonth', 1], |
|
| 67 | - 'DEGREES' => ['rad2deg', 1], |
|
| 64 | + // D |
|
| 65 | + 'DATE_FORMAT' => ['_sqlite_func_date_format', 2], // équivalent a strftime avec args inversés |
|
| 66 | + 'DAYOFMONTH' => ['_sqlite_func_dayofmonth', 1], |
|
| 67 | + 'DEGREES' => ['rad2deg', 1], |
|
| 68 | 68 | |
| 69 | - // E |
|
| 70 | - 'EXTRAIRE_MULTI' => ['_sqlite_func_extraire_multi', 2], // specifique a SPIP/sql_multi() |
|
| 71 | - 'EXP' => ['exp', 1], |
|
| 69 | + // E |
|
| 70 | + 'EXTRAIRE_MULTI' => ['_sqlite_func_extraire_multi', 2], // specifique a SPIP/sql_multi() |
|
| 71 | + 'EXP' => ['exp', 1], |
|
| 72 | 72 | |
| 73 | - // F |
|
| 74 | - 'FIND_IN_SET' => ['_sqlite_func_find_in_set', 2], |
|
| 75 | - 'FLOOR' => ['_sqlite_func_floor', 1], |
|
| 73 | + // F |
|
| 74 | + 'FIND_IN_SET' => ['_sqlite_func_find_in_set', 2], |
|
| 75 | + 'FLOOR' => ['_sqlite_func_floor', 1], |
|
| 76 | 76 | |
| 77 | - // G |
|
| 78 | - 'GREATEST' => ['_sqlite_func_greatest', -1], |
|
| 77 | + // G |
|
| 78 | + 'GREATEST' => ['_sqlite_func_greatest', -1], |
|
| 79 | 79 | |
| 80 | - // I |
|
| 81 | - 'IF' => ['_sqlite_func_if', 3], |
|
| 82 | - 'INSERT' => ['_sqlite_func_insert', 4], |
|
| 83 | - 'INSTR' => ['_sqlite_func_instr', 2], |
|
| 80 | + // I |
|
| 81 | + 'IF' => ['_sqlite_func_if', 3], |
|
| 82 | + 'INSERT' => ['_sqlite_func_insert', 4], |
|
| 83 | + 'INSTR' => ['_sqlite_func_instr', 2], |
|
| 84 | 84 | |
| 85 | - // L |
|
| 86 | - 'LEAST' => ['_sqlite_func_least', -1], |
|
| 87 | - '_LEFT' => ['_sqlite_func_left', 2], |
|
| 85 | + // L |
|
| 86 | + 'LEAST' => ['_sqlite_func_least', -1], |
|
| 87 | + '_LEFT' => ['_sqlite_func_left', 2], |
|
| 88 | 88 | |
| 89 | - // N |
|
| 90 | - 'NOW' => ['_sqlite_func_now', 0], |
|
| 89 | + // N |
|
| 90 | + 'NOW' => ['_sqlite_func_now', 0], |
|
| 91 | 91 | |
| 92 | - // M |
|
| 93 | - 'MD5' => ['md5', 1], |
|
| 94 | - 'MONTH' => ['_sqlite_func_month', 1], |
|
| 92 | + // M |
|
| 93 | + 'MD5' => ['md5', 1], |
|
| 94 | + 'MONTH' => ['_sqlite_func_month', 1], |
|
| 95 | 95 | |
| 96 | - // P |
|
| 97 | - 'PREG_REPLACE' => ['_sqlite_func_preg_replace', 3], |
|
| 96 | + // P |
|
| 97 | + 'PREG_REPLACE' => ['_sqlite_func_preg_replace', 3], |
|
| 98 | 98 | |
| 99 | - // R |
|
| 100 | - 'RADIANS' => ['deg2rad', 1], |
|
| 101 | - 'RAND' => ['_sqlite_func_rand', 0], // sinon random() v2.4 |
|
| 102 | - 'REGEXP' => ['_sqlite_func_regexp_match', 2], // critere REGEXP supporte a partir de v3.3.2 |
|
| 103 | - 'RIGHT' => ['_sqlite_func_right', 2], |
|
| 99 | + // R |
|
| 100 | + 'RADIANS' => ['deg2rad', 1], |
|
| 101 | + 'RAND' => ['_sqlite_func_rand', 0], // sinon random() v2.4 |
|
| 102 | + 'REGEXP' => ['_sqlite_func_regexp_match', 2], // critere REGEXP supporte a partir de v3.3.2 |
|
| 103 | + 'RIGHT' => ['_sqlite_func_right', 2], |
|
| 104 | 104 | |
| 105 | - // S |
|
| 106 | - 'SETTYPE' => ['settype', 2], // CAST present en v3.2.3 |
|
| 107 | - 'SIN' => ['sin', 1], |
|
| 108 | - 'SQRT' => ['sqrt', 1], |
|
| 109 | - 'SUBSTRING' => ['_sqlite_func_substring' /*, 3*/], // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0 |
|
| 105 | + // S |
|
| 106 | + 'SETTYPE' => ['settype', 2], // CAST present en v3.2.3 |
|
| 107 | + 'SIN' => ['sin', 1], |
|
| 108 | + 'SQRT' => ['sqrt', 1], |
|
| 109 | + 'SUBSTRING' => ['_sqlite_func_substring' /*, 3*/], // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0 |
|
| 110 | 110 | |
| 111 | - // T |
|
| 112 | - 'TAN' => ['tan', 1], |
|
| 113 | - 'TIMESTAMPDIFF' => ['_sqlite_timestampdiff' /*, 3*/], |
|
| 114 | - 'TO_DAYS' => ['_sqlite_func_to_days', 1], |
|
| 111 | + // T |
|
| 112 | + 'TAN' => ['tan', 1], |
|
| 113 | + 'TIMESTAMPDIFF' => ['_sqlite_timestampdiff' /*, 3*/], |
|
| 114 | + 'TO_DAYS' => ['_sqlite_func_to_days', 1], |
|
| 115 | 115 | |
| 116 | - // U |
|
| 117 | - 'UNIX_TIMESTAMP' => ['_sqlite_func_unix_timestamp', 1], |
|
| 116 | + // U |
|
| 117 | + 'UNIX_TIMESTAMP' => ['_sqlite_func_unix_timestamp', 1], |
|
| 118 | 118 | |
| 119 | - // V |
|
| 120 | - 'VIDE' => ['_sqlite_func_vide', 0], // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide() |
|
| 119 | + // V |
|
| 120 | + 'VIDE' => ['_sqlite_func_vide', 0], // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide() |
|
| 121 | 121 | |
| 122 | - // Y |
|
| 123 | - 'YEAR' => ['_sqlite_func_year', 1] |
|
| 124 | - ]; |
|
| 122 | + // Y |
|
| 123 | + 'YEAR' => ['_sqlite_func_year', 1] |
|
| 124 | + ]; |
|
| 125 | 125 | |
| 126 | - foreach ($fonctions as $f => $r) { |
|
| 127 | - _sqlite_add_function($sqlite, $f, $r); |
|
| 128 | - } |
|
| 126 | + foreach ($fonctions as $f => $r) { |
|
| 127 | + _sqlite_add_function($sqlite, $f, $r); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - #spip_log('functions sqlite chargees ','sqlite.'._LOG_DEBUG); |
|
| 130 | + #spip_log('functions sqlite chargees ','sqlite.'._LOG_DEBUG); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | **/ |
| 150 | 150 | function _sqlite_add_function(&$sqlite, &$f, &$r) { |
| 151 | - isset($r[1]) |
|
| 152 | - ? $sqlite->sqliteCreateFunction($f, $r[0], $r[1]) |
|
| 153 | - : $sqlite->sqliteCreateFunction($f, $r[0]); |
|
| 151 | + isset($r[1]) |
|
| 152 | + ? $sqlite->sqliteCreateFunction($f, $r[0], $r[1]) |
|
| 153 | + : $sqlite->sqliteCreateFunction($f, $r[0]); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * @return int |
| 161 | 161 | */ |
| 162 | 162 | function _sqlite_func_ceil($a) { |
| 163 | - return ceil($a); |
|
| 163 | + return ceil($a); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @return string |
| 171 | 171 | */ |
| 172 | 172 | function _sqlite_func_concat(...$args) { |
| 173 | - return implode('', $args); |
|
| 173 | + return implode('', $args); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @return string |
| 184 | 184 | */ |
| 185 | 185 | function _sqlite_func_dayofmonth($d) { |
| 186 | - return _sqlite_func_date('d', $d); |
|
| 186 | + return _sqlite_func_date('d', $d); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | |
@@ -195,15 +195,15 @@ discard block |
||
| 195 | 195 | * @return int |
| 196 | 196 | */ |
| 197 | 197 | function _sqlite_func_find_in_set($num, $set) { |
| 198 | - $rank = 0; |
|
| 199 | - foreach (explode(',', $set) as $v) { |
|
| 200 | - if ($v == $num) { |
|
| 201 | - return (++$rank); |
|
| 202 | - } |
|
| 203 | - $rank++; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return 0; |
|
| 198 | + $rank = 0; |
|
| 199 | + foreach (explode(',', $set) as $v) { |
|
| 200 | + if ($v == $num) { |
|
| 201 | + return (++$rank); |
|
| 202 | + } |
|
| 203 | + $rank++; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return 0; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * @return int |
| 214 | 214 | */ |
| 215 | 215 | function _sqlite_func_floor($a) { |
| 216 | - return floor($a); |
|
| 216 | + return floor($a); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * @return mixed |
| 227 | 227 | */ |
| 228 | 228 | function _sqlite_func_if($bool, $oui, $non) { |
| 229 | - return ($bool) ? $oui : $non; |
|
| 229 | + return ($bool) ? $oui : $non; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
@@ -243,10 +243,10 @@ discard block |
||
| 243 | 243 | * @return string |
| 244 | 244 | */ |
| 245 | 245 | function _sqlite_func_insert($s, $index, $longueur, $chaine) { |
| 246 | - return |
|
| 247 | - substr($s, 0, $index) |
|
| 248 | - . $chaine |
|
| 249 | - . substr(substr($s, $index), $longueur); |
|
| 246 | + return |
|
| 247 | + substr($s, 0, $index) |
|
| 248 | + . $chaine |
|
| 249 | + . substr(substr($s, $index), $longueur); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return int |
| 259 | 259 | */ |
| 260 | 260 | function _sqlite_func_instr($s, $search) { |
| 261 | - return strpos($s, $search); |
|
| 261 | + return strpos($s, $search); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | * @return int |
| 270 | 270 | */ |
| 271 | 271 | function _sqlite_func_least(...$args) { |
| 272 | - return min($args); |
|
| 272 | + return min($args); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | * @return int |
| 281 | 281 | */ |
| 282 | 282 | function _sqlite_func_greatest(...$args) { |
| 283 | - return max($args); |
|
| 283 | + return max($args); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | * @return string |
| 293 | 293 | */ |
| 294 | 294 | function _sqlite_func_left($s, $lenght) { |
| 295 | - return substr($s, $lenght); |
|
| 295 | + return substr($s, $lenght); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -302,13 +302,13 @@ discard block |
||
| 302 | 302 | * @return string |
| 303 | 303 | */ |
| 304 | 304 | function _sqlite_func_now($force_refresh = false) { |
| 305 | - static $now = null; |
|
| 306 | - if (is_null($now) || $force_refresh) { |
|
| 307 | - $now = date('Y-m-d H:i:s'); |
|
| 308 | - } |
|
| 305 | + static $now = null; |
|
| 306 | + if (is_null($now) || $force_refresh) { |
|
| 307 | + $now = date('Y-m-d H:i:s'); |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - #spip_log("Passage avec NOW : $now | ".time(),'sqlite.'._LOG_DEBUG); |
|
| 311 | - return $now; |
|
| 310 | + #spip_log("Passage avec NOW : $now | ".time(),'sqlite.'._LOG_DEBUG); |
|
| 311 | + return $now; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @return string |
| 322 | 322 | */ |
| 323 | 323 | function _sqlite_func_month($d) { |
| 324 | - return _sqlite_func_date('m', $d); |
|
| 324 | + return _sqlite_func_date('m', $d); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | * @return string |
| 335 | 335 | */ |
| 336 | 336 | function _sqlite_func_preg_replace($quoi, $cherche, $remplace) { |
| 337 | - #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 338 | - return preg_replace('%' . $cherche . '%', $remplace, $quoi); |
|
| 337 | + #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 338 | + return preg_replace('%' . $cherche . '%', $remplace, $quoi); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -348,11 +348,11 @@ discard block |
||
| 348 | 348 | * @return string, l'extrait trouve. |
| 349 | 349 | **/ |
| 350 | 350 | function _sqlite_func_extraire_multi($quoi, $lang) { |
| 351 | - if (str_contains($quoi, '<')) { |
|
| 352 | - $collecteurMultis = new Multis(); |
|
| 353 | - $quoi = $collecteurMultis->traiter($quoi, ['lang' => $lang, 'appliquer_typo' => false]); |
|
| 354 | - } |
|
| 355 | - return $quoi; |
|
| 351 | + if (str_contains($quoi, '<')) { |
|
| 352 | + $collecteurMultis = new Multis(); |
|
| 353 | + $quoi = $collecteurMultis->traiter($quoi, ['lang' => $lang, 'appliquer_typo' => false]); |
|
| 354 | + } |
|
| 355 | + return $quoi; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * @return float |
| 363 | 363 | */ |
| 364 | 364 | function _sqlite_func_rand() { |
| 365 | - return random_int(0, mt_getrandmax()); |
|
| 365 | + return random_int(0, mt_getrandmax()); |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | * @return string |
| 375 | 375 | */ |
| 376 | 376 | function _sqlite_func_right($s, $length) { |
| 377 | - return substr($s, 0 - $length); |
|
| 377 | + return substr($s, 0 - $length); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | |
@@ -386,16 +386,16 @@ discard block |
||
| 386 | 386 | * @return bool |
| 387 | 387 | */ |
| 388 | 388 | function _sqlite_func_regexp_match($cherche, $quoi) { |
| 389 | - // optimiser un cas tres courant avec les requetes en base |
|
| 390 | - if (!$quoi && !strlen($quoi)) { |
|
| 391 | - return false; |
|
| 392 | - } |
|
| 393 | - // il faut enlever un niveau d'echappement pour être homogène à mysql |
|
| 394 | - $cherche = str_replace('\\\\', '\\', $cherche); |
|
| 395 | - $u = $GLOBALS['meta']['pcre_u'] ?? 'u'; |
|
| 396 | - |
|
| 397 | - #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 398 | - return preg_match('%' . $cherche . '%imsS' . $u, $quoi); |
|
| 389 | + // optimiser un cas tres courant avec les requetes en base |
|
| 390 | + if (!$quoi && !strlen($quoi)) { |
|
| 391 | + return false; |
|
| 392 | + } |
|
| 393 | + // il faut enlever un niveau d'echappement pour être homogène à mysql |
|
| 394 | + $cherche = str_replace('\\\\', '\\', $cherche); |
|
| 395 | + $u = $GLOBALS['meta']['pcre_u'] ?? 'u'; |
|
| 396 | + |
|
| 397 | + #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 398 | + return preg_match('%' . $cherche . '%imsS' . $u, $quoi); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | |
@@ -410,8 +410,8 @@ discard block |
||
| 410 | 410 | * @return string |
| 411 | 411 | */ |
| 412 | 412 | function _sqlite_func_date_format($date, $conv) { |
| 413 | - $conv = _sqlite_func_strftime_format_converter($conv); |
|
| 414 | - return strftime($conv, is_int($date) ? $date : strtotime($date)); |
|
| 413 | + $conv = _sqlite_func_strftime_format_converter($conv); |
|
| 414 | + return strftime($conv, is_int($date) ? $date : strtotime($date)); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | /** |
@@ -427,28 +427,28 @@ discard block |
||
| 427 | 427 | * @return void |
| 428 | 428 | */ |
| 429 | 429 | function _sqlite_func_strftime_format_converter(string $conv): string { |
| 430 | - // ok : %a %b %d %e %H %I %l %j %k %m %p %r %S %T %w %y %Y |
|
| 431 | - // on ne sait pas en gérer certains... |
|
| 432 | - static $mysql_to_strftime_not_ok = ['%c', '%D', '%f', '%U', '%V', '%W', '%X']; |
|
| 433 | - static $mysql_to_strftime = [ |
|
| 434 | - '%h' => '%I', |
|
| 435 | - '%i' => '%M', |
|
| 436 | - '%M' => '%B', |
|
| 437 | - '%s' => '%S', |
|
| 438 | - '%u' => '%U', |
|
| 439 | - '%v' => '%V', |
|
| 440 | - '%x' => '%G', |
|
| 441 | - ]; |
|
| 442 | - static $to_strftime = []; |
|
| 443 | - if (!isset($to_strftime[$conv])) { |
|
| 444 | - $count = 0; |
|
| 445 | - str_replace($mysql_to_strftime_not_ok, '', $conv, $count); |
|
| 446 | - if ($count > 0) { |
|
| 447 | - spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR); |
|
| 448 | - } |
|
| 449 | - $to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv); |
|
| 450 | - } |
|
| 451 | - return $to_strftime[$conv]; |
|
| 430 | + // ok : %a %b %d %e %H %I %l %j %k %m %p %r %S %T %w %y %Y |
|
| 431 | + // on ne sait pas en gérer certains... |
|
| 432 | + static $mysql_to_strftime_not_ok = ['%c', '%D', '%f', '%U', '%V', '%W', '%X']; |
|
| 433 | + static $mysql_to_strftime = [ |
|
| 434 | + '%h' => '%I', |
|
| 435 | + '%i' => '%M', |
|
| 436 | + '%M' => '%B', |
|
| 437 | + '%s' => '%S', |
|
| 438 | + '%u' => '%U', |
|
| 439 | + '%v' => '%V', |
|
| 440 | + '%x' => '%G', |
|
| 441 | + ]; |
|
| 442 | + static $to_strftime = []; |
|
| 443 | + if (!isset($to_strftime[$conv])) { |
|
| 444 | + $count = 0; |
|
| 445 | + str_replace($mysql_to_strftime_not_ok, '', $conv, $count); |
|
| 446 | + if ($count > 0) { |
|
| 447 | + spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR); |
|
| 448 | + } |
|
| 449 | + $to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv); |
|
| 450 | + } |
|
| 451 | + return $to_strftime[$conv]; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | /** |
@@ -462,11 +462,11 @@ discard block |
||
| 462 | 462 | * @return int |
| 463 | 463 | */ |
| 464 | 464 | function _sqlite_func_to_days($d) { |
| 465 | - static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
|
| 466 | - $result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 465 | + static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
|
| 466 | + $result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 467 | 467 | |
| 468 | - #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
|
| 469 | - return $result; |
|
| 468 | + #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
|
| 469 | + return $result; |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -478,13 +478,13 @@ discard block |
||
| 478 | 478 | * @return string |
| 479 | 479 | */ |
| 480 | 480 | function _sqlite_func_substring($string, $start, $len = null) { |
| 481 | - // SQL compte a partir de 1, php a partir de 0 |
|
| 482 | - $start = ($start > 0) ? $start - 1 : $start; |
|
| 483 | - if (is_null($len)) { |
|
| 484 | - return substr($string, $start); |
|
| 485 | - } else { |
|
| 486 | - return substr($string, $start, $len); |
|
| 487 | - } |
|
| 481 | + // SQL compte a partir de 1, php a partir de 0 |
|
| 482 | + $start = ($start > 0) ? $start - 1 : $start; |
|
| 483 | + if (is_null($len)) { |
|
| 484 | + return substr($string, $start); |
|
| 485 | + } else { |
|
| 486 | + return substr($string, $start, $len); |
|
| 487 | + } |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | /** |
@@ -500,22 +500,22 @@ discard block |
||
| 500 | 500 | * @return int |
| 501 | 501 | */ |
| 502 | 502 | function _sqlite_timestampdiff($unit, $date1, $date2) { |
| 503 | - $d1 = date_create($date1); |
|
| 504 | - $d2 = date_create($date2); |
|
| 505 | - $diff = date_diff($d1, $d2); |
|
| 506 | - $inv = $diff->invert ? -1 : 1; |
|
| 507 | - return match ($unit) { |
|
| 508 | - 'YEAR' => $inv * $diff->y, |
|
| 509 | - 'QUARTER' => $inv * (4 * $diff->y + (int) floor($diff->m / 3)), |
|
| 510 | - 'MONTH' => $inv * (12 * $diff->y + $diff->m), |
|
| 511 | - 'WEEK' => $inv * (int) floor($diff->days / 7), |
|
| 512 | - 'DAY' => $inv * $diff->days, |
|
| 513 | - 'HOUR' => $inv * (24 * $diff->days + $diff->h), |
|
| 514 | - 'MINUTE' => $inv * ((24 * $diff->days + $diff->h) * 60 + $diff->i), |
|
| 515 | - 'SECOND' => $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s), |
|
| 516 | - 'MICROSECOND' => $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s) * 1_000_000, |
|
| 517 | - default => 0, |
|
| 518 | - }; |
|
| 503 | + $d1 = date_create($date1); |
|
| 504 | + $d2 = date_create($date2); |
|
| 505 | + $diff = date_diff($d1, $d2); |
|
| 506 | + $inv = $diff->invert ? -1 : 1; |
|
| 507 | + return match ($unit) { |
|
| 508 | + 'YEAR' => $inv * $diff->y, |
|
| 509 | + 'QUARTER' => $inv * (4 * $diff->y + (int) floor($diff->m / 3)), |
|
| 510 | + 'MONTH' => $inv * (12 * $diff->y + $diff->m), |
|
| 511 | + 'WEEK' => $inv * (int) floor($diff->days / 7), |
|
| 512 | + 'DAY' => $inv * $diff->days, |
|
| 513 | + 'HOUR' => $inv * (24 * $diff->days + $diff->h), |
|
| 514 | + 'MINUTE' => $inv * ((24 * $diff->days + $diff->h) * 60 + $diff->i), |
|
| 515 | + 'SECOND' => $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s), |
|
| 516 | + 'MICROSECOND' => $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s) * 1_000_000, |
|
| 517 | + default => 0, |
|
| 518 | + }; |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | /** |
@@ -525,24 +525,24 @@ discard block |
||
| 525 | 525 | * @return int |
| 526 | 526 | */ |
| 527 | 527 | function _sqlite_func_unix_timestamp($d) { |
| 528 | - static $mem = []; |
|
| 529 | - static $n = 0; |
|
| 530 | - if (isset($mem[$d])) { |
|
| 531 | - return $mem[$d]; |
|
| 532 | - } |
|
| 533 | - if ($n++ > 100) { |
|
| 534 | - $mem = []; |
|
| 535 | - $n = 0; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - //2005-12-02 20:53:53 |
|
| 539 | - #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG); |
|
| 540 | - if (!$d) { |
|
| 541 | - return $mem[$d] = time(); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // une pile plus grosse n'accelere pas le calcul |
|
| 545 | - return $mem[$d] = strtotime($d); |
|
| 528 | + static $mem = []; |
|
| 529 | + static $n = 0; |
|
| 530 | + if (isset($mem[$d])) { |
|
| 531 | + return $mem[$d]; |
|
| 532 | + } |
|
| 533 | + if ($n++ > 100) { |
|
| 534 | + $mem = []; |
|
| 535 | + $n = 0; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + //2005-12-02 20:53:53 |
|
| 539 | + #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG); |
|
| 540 | + if (!$d) { |
|
| 541 | + return $mem[$d] = time(); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // une pile plus grosse n'accelere pas le calcul |
|
| 545 | + return $mem[$d] = strtotime($d); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | * @return string |
| 556 | 556 | */ |
| 557 | 557 | function _sqlite_func_year($d) { |
| 558 | - return _sqlite_func_date('Y', $d); |
|
| 558 | + return _sqlite_func_date('Y', $d); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | /** |
@@ -568,20 +568,20 @@ discard block |
||
| 568 | 568 | * @return string |
| 569 | 569 | */ |
| 570 | 570 | function _sqlite_func_date($quoi, $d) { |
| 571 | - static $mem = []; |
|
| 572 | - static $n = 0; |
|
| 573 | - if (isset($mem[$d])) { |
|
| 574 | - return $mem[$d][$quoi]; |
|
| 575 | - } |
|
| 576 | - if ($n++ > 100) { |
|
| 577 | - $mem = []; |
|
| 578 | - $n = 0; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - $dec = date('Y-m-d', _sqlite_func_unix_timestamp($d)); |
|
| 582 | - $mem[$d] = ['Y' => substr($dec, 0, 4), 'm' => substr($dec, 5, 2), 'd' => substr($dec, 8, 2)]; |
|
| 583 | - |
|
| 584 | - return $mem[$d][$quoi]; |
|
| 571 | + static $mem = []; |
|
| 572 | + static $n = 0; |
|
| 573 | + if (isset($mem[$d])) { |
|
| 574 | + return $mem[$d][$quoi]; |
|
| 575 | + } |
|
| 576 | + if ($n++ > 100) { |
|
| 577 | + $mem = []; |
|
| 578 | + $n = 0; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + $dec = date('Y-m-d', _sqlite_func_unix_timestamp($d)); |
|
| 582 | + $mem[$d] = ['Y' => substr($dec, 0, 4), 'm' => substr($dec, 5, 2), 'd' => substr($dec, 8, 2)]; |
|
| 583 | + |
|
| 584 | + return $mem[$d][$quoi]; |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | /** |
@@ -590,5 +590,5 @@ discard block |
||
| 590 | 590 | * @return void |
| 591 | 591 | */ |
| 592 | 592 | function _sqlite_func_vide() { |
| 593 | - return; |
|
| 593 | + return; |
|
| 594 | 594 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $type = reset($objets); |
| 160 | 160 | $type = objet_type($type); |
| 161 | 161 | $id = (int) $ref; |
| 162 | - $ref = $type . $ref; |
|
| 162 | + $ref = $type.$ref; |
|
| 163 | 163 | } |
| 164 | 164 | else { |
| 165 | 165 | // Si la référence ne correspond à rien, c'est fini |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | return json_export(false); |
| 168 | 168 | } |
| 169 | 169 | // Sinon on récupère les infos utiles |
| 170 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 170 | + [$type,, $id,,,,] = array_pad($match, 7, null); |
|
| 171 | 171 | |
| 172 | 172 | // On regarde si le type trouvé fait partie des objets sélectionnables |
| 173 | 173 | if (!in_array(table_objet($type), $objets)) { |
@@ -213,8 +213,8 @@ discard block |
||
| 213 | 213 | $types = (is_array($types) ? array_filter($types) : []); |
| 214 | 214 | |
| 215 | 215 | // recuperer tous les freres et soeurs de la rubrique visee |
| 216 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 216 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique); |
|
| 217 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent='.(int) $id_parent); |
|
| 218 | 218 | $fratrie = array_column($fratrie, 'id_rubrique'); |
| 219 | 219 | $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
| 220 | 220 | $has = array_column($has, 'id_parent'); |
@@ -160,8 +160,7 @@ |
||
| 160 | 160 | $type = objet_type($type); |
| 161 | 161 | $id = (int) $ref; |
| 162 | 162 | $ref = $type . $ref; |
| 163 | - } |
|
| 164 | - else { |
|
| 163 | + } else { |
|
| 165 | 164 | // Si la référence ne correspond à rien, c'est fini |
| 166 | 165 | if (!($match = typer_raccourci($ref))) { |
| 167 | 166 | return json_export(false); |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | **/ |
| 8 | 8 | |
| 9 | 9 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 10 | - return; |
|
| 10 | + return; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -28,49 +28,49 @@ discard block |
||
| 28 | 28 | * - afficher : tableau des objets à afficher (mais pas forcément sélectionnables) |
| 29 | 29 | */ |
| 30 | 30 | function selecteur_lister_objets($includelist = [], $excludelist = []) { |
| 31 | - static $liste_selecteurs, $liste_parents; |
|
| 32 | - |
|
| 33 | - if (!$liste_selecteurs) { |
|
| 34 | - $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | - } |
|
| 36 | - $objets_selectionner = []; |
|
| 37 | - foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | - $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | - if (!empty($includelist)) { |
|
| 43 | - $includelist = array_map('table_objet', $includelist); |
|
| 44 | - $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | - } |
|
| 46 | - // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | - $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | - // On enlève toujours la racine |
|
| 49 | - $excludelist[] = 'racine'; |
|
| 50 | - $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | - |
|
| 52 | - // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | - $objets_afficher = $objets_selectionner; |
|
| 54 | - |
|
| 55 | - // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | - // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | - if (!$liste_parents) { |
|
| 58 | - $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | - } |
|
| 60 | - foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | - preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures); |
|
| 62 | - $parent = $captures[1]; |
|
| 63 | - $type = $captures[2]; |
|
| 64 | - // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | - if (in_array($type, $objets_afficher)) { |
|
| 66 | - $objets_afficher[] = $parent; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return [ |
|
| 71 | - 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | - 'afficher' => array_unique($objets_afficher), |
|
| 73 | - ]; |
|
| 31 | + static $liste_selecteurs, $liste_parents; |
|
| 32 | + |
|
| 33 | + if (!$liste_selecteurs) { |
|
| 34 | + $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | + } |
|
| 36 | + $objets_selectionner = []; |
|
| 37 | + foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | + $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | + if (!empty($includelist)) { |
|
| 43 | + $includelist = array_map('table_objet', $includelist); |
|
| 44 | + $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | + } |
|
| 46 | + // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | + $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | + // On enlève toujours la racine |
|
| 49 | + $excludelist[] = 'racine'; |
|
| 50 | + $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | + |
|
| 52 | + // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | + $objets_afficher = $objets_selectionner; |
|
| 54 | + |
|
| 55 | + // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | + // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | + if (!$liste_parents) { |
|
| 58 | + $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | + } |
|
| 60 | + foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | + preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures); |
|
| 62 | + $parent = $captures[1]; |
|
| 63 | + $type = $captures[2]; |
|
| 64 | + // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | + if (in_array($type, $objets_afficher)) { |
|
| 66 | + $objets_afficher[] = $parent; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return [ |
|
| 71 | + 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | + 'afficher' => array_unique($objets_afficher), |
|
| 73 | + ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -97,31 +97,31 @@ discard block |
||
| 97 | 97 | * liste des couples (objets => id_objet) ou liste des identifiants d'un type d'objet. |
| 98 | 98 | **/ |
| 99 | 99 | function picker_selected($selected, $type = '') { |
| 100 | - $select = []; |
|
| 101 | - $type = preg_replace(',\W,', '', $type); |
|
| 102 | - |
|
| 103 | - if ($selected && !is_array($selected)) { |
|
| 104 | - $selected = explode(',', $selected); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if (is_array($selected)) { |
|
| 108 | - foreach ($selected as $value) { |
|
| 109 | - // Si c'est le bon format déjà |
|
| 110 | - if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) { |
|
| 111 | - $objet = $captures[1]; |
|
| 112 | - $id_objet = (int) $captures[2]; |
|
| 113 | - |
|
| 114 | - // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | - if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | - $select[] = $id_objet; |
|
| 117 | - } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | - $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $select; |
|
| 100 | + $select = []; |
|
| 101 | + $type = preg_replace(',\W,', '', $type); |
|
| 102 | + |
|
| 103 | + if ($selected && !is_array($selected)) { |
|
| 104 | + $selected = explode(',', $selected); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if (is_array($selected)) { |
|
| 108 | + foreach ($selected as $value) { |
|
| 109 | + // Si c'est le bon format déjà |
|
| 110 | + if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) { |
|
| 111 | + $objet = $captures[1]; |
|
| 112 | + $id_objet = (int) $captures[2]; |
|
| 113 | + |
|
| 114 | + // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | + if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | + $select[] = $id_objet; |
|
| 117 | + } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | + $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $select; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -138,53 +138,53 @@ discard block |
||
| 138 | 138 | * Booléen indiquant si les articles sont sélectionnables |
| 139 | 139 | */ |
| 140 | 140 | function picker_identifie_id_rapide($ref, $rubriques_ou_objets = false, $articles = false) { |
| 141 | - include_spip('inc/json'); |
|
| 142 | - include_spip('inc/lien'); |
|
| 143 | - |
|
| 144 | - // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | - $objets = []; |
|
| 146 | - if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | - $objets = $rubriques_ou_objets; |
|
| 148 | - } else { |
|
| 149 | - if ($rubriques_ou_objets) { |
|
| 150 | - $objets[] = 'rubriques'; |
|
| 151 | - } |
|
| 152 | - if ($articles) { |
|
| 153 | - $objets[] = 'articles'; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | - if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | - $type = reset($objets); |
|
| 160 | - $type = objet_type($type); |
|
| 161 | - $id = (int) $ref; |
|
| 162 | - $ref = $type . $ref; |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - // Si la référence ne correspond à rien, c'est fini |
|
| 166 | - if (!($match = typer_raccourci($ref))) { |
|
| 167 | - return json_export(false); |
|
| 168 | - } |
|
| 169 | - // Sinon on récupère les infos utiles |
|
| 170 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | - |
|
| 172 | - // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | - if (!in_array(table_objet($type), $objets)) { |
|
| 174 | - return json_export(false); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | - include_spip('inc/filtres'); |
|
| 180 | - if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | - return json_export(false); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // On simplifie le texte |
|
| 185 | - $titre = attribut_html($titre); |
|
| 186 | - |
|
| 187 | - return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 141 | + include_spip('inc/json'); |
|
| 142 | + include_spip('inc/lien'); |
|
| 143 | + |
|
| 144 | + // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | + $objets = []; |
|
| 146 | + if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | + $objets = $rubriques_ou_objets; |
|
| 148 | + } else { |
|
| 149 | + if ($rubriques_ou_objets) { |
|
| 150 | + $objets[] = 'rubriques'; |
|
| 151 | + } |
|
| 152 | + if ($articles) { |
|
| 153 | + $objets[] = 'articles'; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | + if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | + $type = reset($objets); |
|
| 160 | + $type = objet_type($type); |
|
| 161 | + $id = (int) $ref; |
|
| 162 | + $ref = $type . $ref; |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + // Si la référence ne correspond à rien, c'est fini |
|
| 166 | + if (!($match = typer_raccourci($ref))) { |
|
| 167 | + return json_export(false); |
|
| 168 | + } |
|
| 169 | + // Sinon on récupère les infos utiles |
|
| 170 | + [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | + |
|
| 172 | + // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | + if (!in_array(table_objet($type), $objets)) { |
|
| 174 | + return json_export(false); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | + include_spip('inc/filtres'); |
|
| 180 | + if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | + return json_export(false); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // On simplifie le texte |
|
| 185 | + $titre = attribut_html($titre); |
|
| 186 | + |
|
| 187 | + return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -207,34 +207,34 @@ discard block |
||
| 207 | 207 | * Comme le filtre `oui` : espace (` `) si rubrique à afficher, chaîne vide sinon. |
| 208 | 208 | */ |
| 209 | 209 | function test_enfants_rubrique($id_rubrique, $types = []) { |
| 210 | - static $has_child = []; |
|
| 211 | - |
|
| 212 | - if (!isset($has_child[$id_rubrique])) { |
|
| 213 | - $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | - |
|
| 215 | - // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | - $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | - $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | - $has = array_column($has, 'id_parent'); |
|
| 221 | - $fratrie = array_diff($fratrie, $has); |
|
| 222 | - |
|
| 223 | - while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | - $type = array_shift($types); |
|
| 225 | - $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | - $h = array_column($h, 'id_rubrique'); |
|
| 227 | - $has = [...$has, ...$h]; |
|
| 228 | - $fratrie = array_diff($fratrie, $h); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - if ($has !== []) { |
|
| 232 | - $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | - } |
|
| 234 | - if ($fratrie !== []) { |
|
| 235 | - $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 210 | + static $has_child = []; |
|
| 211 | + |
|
| 212 | + if (!isset($has_child[$id_rubrique])) { |
|
| 213 | + $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | + |
|
| 215 | + // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | + $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | + $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | + $has = array_column($has, 'id_parent'); |
|
| 221 | + $fratrie = array_diff($fratrie, $has); |
|
| 222 | + |
|
| 223 | + while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | + $type = array_shift($types); |
|
| 225 | + $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | + $h = array_column($h, 'id_rubrique'); |
|
| 227 | + $has = [...$has, ...$h]; |
|
| 228 | + $fratrie = array_diff($fratrie, $h); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + if ($has !== []) { |
|
| 232 | + $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | + } |
|
| 234 | + if ($fratrie !== []) { |
|
| 235 | + $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 240 | 240 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -74,28 +74,28 @@ discard block |
||
| 74 | 74 | * @return |
| 75 | 75 | **/ |
| 76 | 76 | function inc_genie_dist($taches = []) { |
| 77 | - include_spip('inc/queue'); |
|
| 78 | - |
|
| 79 | - if (_request('exec') == 'job_queue') { |
|
| 80 | - return false; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $force_jobs = []; |
|
| 84 | - // l'ancienne facon de lancer une tache cron immediatement |
|
| 85 | - // etait de la passer en parametre a ing_genie_dist |
|
| 86 | - // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 87 | - foreach ($taches as $function => $period) { |
|
| 88 | - $force_jobs[] = queue_add_job( |
|
| 89 | - $function, |
|
| 90 | - _T('tache_cron_asap', ['function' => $function]), |
|
| 91 | - [time() - abs($period)], |
|
| 92 | - 'genie/' |
|
| 93 | - ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // et on passe la main a la gestion de la queue ! |
|
| 97 | - // en forcant eventuellement les jobs ajoute a l'instant |
|
| 98 | - return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 77 | + include_spip('inc/queue'); |
|
| 78 | + |
|
| 79 | + if (_request('exec') == 'job_queue') { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $force_jobs = []; |
|
| 84 | + // l'ancienne facon de lancer une tache cron immediatement |
|
| 85 | + // etait de la passer en parametre a ing_genie_dist |
|
| 86 | + // on reroute en ajoutant simplement le job a la queue, ASAP |
|
| 87 | + foreach ($taches as $function => $period) { |
|
| 88 | + $force_jobs[] = queue_add_job( |
|
| 89 | + $function, |
|
| 90 | + _T('tache_cron_asap', ['function' => $function]), |
|
| 91 | + [time() - abs($period)], |
|
| 92 | + 'genie/' |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // et on passe la main a la gestion de la queue ! |
|
| 97 | + // en forcant eventuellement les jobs ajoute a l'instant |
|
| 98 | + return queue_schedule(count($force_jobs) ? $force_jobs : null); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // |
@@ -108,34 +108,34 @@ discard block |
||
| 108 | 108 | // |
| 109 | 109 | function taches_generales($taches_generales = []) { |
| 110 | 110 | |
| 111 | - // verifier que toutes les taches cron sont planifiees |
|
| 112 | - // c'est une tache cron ! |
|
| 113 | - $taches_generales['queue_watch'] = 3600 * 24; |
|
| 111 | + // verifier que toutes les taches cron sont planifiees |
|
| 112 | + // c'est une tache cron ! |
|
| 113 | + $taches_generales['queue_watch'] = 3600 * 24; |
|
| 114 | 114 | |
| 115 | - // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 116 | - // est fait au coup par coup a present |
|
| 117 | - // $taches_generales['rubriques'] = 3600; |
|
| 115 | + // MAJ des rubriques publiques (cas de la publication post-datee) |
|
| 116 | + // est fait au coup par coup a present |
|
| 117 | + // $taches_generales['rubriques'] = 3600; |
|
| 118 | 118 | |
| 119 | - // Optimisation de la base |
|
| 120 | - $taches_generales['optimiser'] = 3600 * 48; |
|
| 119 | + // Optimisation de la base |
|
| 120 | + $taches_generales['optimiser'] = 3600 * 48; |
|
| 121 | 121 | |
| 122 | - // nouveautes |
|
| 123 | - if ( |
|
| 124 | - isset($GLOBALS['meta']['adresse_neuf']) |
|
| 125 | - && $GLOBALS['meta']['adresse_neuf'] |
|
| 126 | - && $GLOBALS['meta']['jours_neuf'] |
|
| 127 | - && $GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 128 | - ) { |
|
| 129 | - $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 130 | - } |
|
| 122 | + // nouveautes |
|
| 123 | + if ( |
|
| 124 | + isset($GLOBALS['meta']['adresse_neuf']) |
|
| 125 | + && $GLOBALS['meta']['adresse_neuf'] |
|
| 126 | + && $GLOBALS['meta']['jours_neuf'] |
|
| 127 | + && $GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 128 | + ) { |
|
| 129 | + $taches_generales['mail'] = 3600 * 24 * $GLOBALS['meta']['jours_neuf']; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - // maintenance (ajax, verifications diverses) |
|
| 133 | - $taches_generales['maintenance'] = 3600 * 2; |
|
| 132 | + // maintenance (ajax, verifications diverses) |
|
| 133 | + $taches_generales['maintenance'] = 3600 * 2; |
|
| 134 | 134 | |
| 135 | - // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 136 | - $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 135 | + // verifier si une mise a jour de spip est disponible (2 fois par semaine suffit largement) |
|
| 136 | + $taches_generales['mise_a_jour'] = 3 * 24 * 3600; |
|
| 137 | 137 | |
| 138 | - return pipeline('taches_generales_cron', $taches_generales); |
|
| 138 | + return pipeline('taches_generales_cron', $taches_generales); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,22 +151,22 @@ discard block |
||
| 151 | 151 | * @return int |
| 152 | 152 | */ |
| 153 | 153 | function genie_queue_watch_dist() { |
| 154 | - static $deja_la = false; |
|
| 155 | - if ($deja_la) { |
|
| 156 | - return; |
|
| 157 | - } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 158 | - $deja_la = true; |
|
| 159 | - $taches = taches_generales(); |
|
| 160 | - $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 161 | - $programmees = array_column($programmees, 'fonction'); |
|
| 162 | - foreach ($taches as $tache => $periode) { |
|
| 163 | - if (!in_array($tache, $programmees)) { |
|
| 164 | - queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - $deja_la = false; |
|
| 168 | - |
|
| 169 | - return 1; |
|
| 154 | + static $deja_la = false; |
|
| 155 | + if ($deja_la) { |
|
| 156 | + return; |
|
| 157 | + } // re-entrance si l'insertion des jobs echoue (pas de table spip_jobs a l'upgrade par exemple) |
|
| 158 | + $deja_la = true; |
|
| 159 | + $taches = taches_generales(); |
|
| 160 | + $programmees = sql_allfetsel('fonction', 'spip_jobs', sql_in('fonction', array_keys($taches))); |
|
| 161 | + $programmees = array_column($programmees, 'fonction'); |
|
| 162 | + foreach ($taches as $tache => $periode) { |
|
| 163 | + if (!in_array($tache, $programmees)) { |
|
| 164 | + queue_genie_replan_job($tache, $periode, time() - round(random_int(1, $periode)), 0); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + $deja_la = false; |
|
| 168 | + |
|
| 169 | + return 1; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -187,32 +187,32 @@ discard block |
||
| 187 | 187 | * @return void |
| 188 | 188 | */ |
| 189 | 189 | function queue_genie_replan_job($function, $period, $last = 0, $time = null, $priority = 0) { |
| 190 | - static $done = []; |
|
| 191 | - if (isset($done[$function])) { |
|
| 192 | - return; |
|
| 193 | - } |
|
| 194 | - $done[$function] = true; |
|
| 195 | - if (is_null($time)) { |
|
| 196 | - $time = time(); |
|
| 197 | - if ($last) { |
|
| 198 | - $time = max($last + $period, $time); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - if (!$last) { |
|
| 202 | - $last = $time - $period; |
|
| 203 | - } |
|
| 204 | - spip_log("replan_job $function $period $last $time $priority", 'queue'); |
|
| 205 | - include_spip('inc/queue'); |
|
| 206 | - // on replanifie un job cron |
|
| 207 | - // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 208 | - // independament de l'argument |
|
| 209 | - queue_add_job( |
|
| 210 | - $function, |
|
| 211 | - _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 212 | - [$last], |
|
| 213 | - 'genie/', |
|
| 214 | - 'function_only', |
|
| 215 | - $time, |
|
| 216 | - $priority |
|
| 217 | - ); |
|
| 190 | + static $done = []; |
|
| 191 | + if (isset($done[$function])) { |
|
| 192 | + return; |
|
| 193 | + } |
|
| 194 | + $done[$function] = true; |
|
| 195 | + if (is_null($time)) { |
|
| 196 | + $time = time(); |
|
| 197 | + if ($last) { |
|
| 198 | + $time = max($last + $period, $time); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + if (!$last) { |
|
| 202 | + $last = $time - $period; |
|
| 203 | + } |
|
| 204 | + spip_log("replan_job $function $period $last $time $priority", 'queue'); |
|
| 205 | + include_spip('inc/queue'); |
|
| 206 | + // on replanifie un job cron |
|
| 207 | + // uniquement si il n'y en a pas deja un avec le meme nom |
|
| 208 | + // independament de l'argument |
|
| 209 | + queue_add_job( |
|
| 210 | + $function, |
|
| 211 | + _T('tache_cron_secondes', ['function' => $function, 'nb' => $period]), |
|
| 212 | + [$last], |
|
| 213 | + 'genie/', |
|
| 214 | + 'function_only', |
|
| 215 | + $time, |
|
| 216 | + $priority |
|
| 217 | + ); |
|
| 218 | 218 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | 29 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 30 | - return; |
|
| 30 | + return; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -47,55 +47,55 @@ discard block |
||
| 47 | 47 | * array : description des roles applicables dans 3 index : colonne, titres, roles |
| 48 | 48 | **/ |
| 49 | 49 | function roles_presents($objet, $objet_destination = '') { |
| 50 | - $desc = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 51 | - |
|
| 52 | - // pas de liste de roles, on sort |
|
| 53 | - if (!isset($desc['roles_titres']) || !($titres = $desc['roles_titres'])) { |
|
| 54 | - return false; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - // on vérifie que la table de liaison existe |
|
| 58 | - include_spip('action/editer_liens'); |
|
| 59 | - if (!$lien = objet_associable($objet)) { |
|
| 60 | - return false; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // on cherche ensuite si la colonne existe bien dans la table de liaison (par défaut 'role') |
|
| 64 | - $colonne = $desc['roles_colonne'] ?? 'role'; |
|
| 65 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 66 | - [, $table_lien] = $lien; |
|
| 67 | - $desc_lien = $trouver_table($table_lien); |
|
| 68 | - if (!isset($desc_lien['field'][$colonne])) { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // sur quoi peuvent s'appliquer nos rôles |
|
| 73 | - if (!$application = $desc['roles_objets']) { |
|
| 74 | - return false; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // destination presente, on restreint si possible |
|
| 78 | - if ($objet_destination) { |
|
| 79 | - $objet_destination = table_objet($objet_destination); |
|
| 80 | - |
|
| 81 | - // pour l'objet |
|
| 82 | - if (isset($application[$objet_destination])) { |
|
| 83 | - $application = $application[$objet_destination]; |
|
| 84 | - // sinon pour tous les objets |
|
| 85 | - } elseif (isset($application['*'])) { |
|
| 86 | - $application = $application['*']; |
|
| 87 | - } // sinon tant pis |
|
| 88 | - else { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // tout est ok |
|
| 94 | - return [ |
|
| 95 | - 'titres' => $titres, |
|
| 96 | - 'roles' => $application, |
|
| 97 | - 'colonne' => $colonne |
|
| 98 | - ]; |
|
| 50 | + $desc = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 51 | + |
|
| 52 | + // pas de liste de roles, on sort |
|
| 53 | + if (!isset($desc['roles_titres']) || !($titres = $desc['roles_titres'])) { |
|
| 54 | + return false; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + // on vérifie que la table de liaison existe |
|
| 58 | + include_spip('action/editer_liens'); |
|
| 59 | + if (!$lien = objet_associable($objet)) { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // on cherche ensuite si la colonne existe bien dans la table de liaison (par défaut 'role') |
|
| 64 | + $colonne = $desc['roles_colonne'] ?? 'role'; |
|
| 65 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 66 | + [, $table_lien] = $lien; |
|
| 67 | + $desc_lien = $trouver_table($table_lien); |
|
| 68 | + if (!isset($desc_lien['field'][$colonne])) { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // sur quoi peuvent s'appliquer nos rôles |
|
| 73 | + if (!$application = $desc['roles_objets']) { |
|
| 74 | + return false; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // destination presente, on restreint si possible |
|
| 78 | + if ($objet_destination) { |
|
| 79 | + $objet_destination = table_objet($objet_destination); |
|
| 80 | + |
|
| 81 | + // pour l'objet |
|
| 82 | + if (isset($application[$objet_destination])) { |
|
| 83 | + $application = $application[$objet_destination]; |
|
| 84 | + // sinon pour tous les objets |
|
| 85 | + } elseif (isset($application['*'])) { |
|
| 86 | + $application = $application['*']; |
|
| 87 | + } // sinon tant pis |
|
| 88 | + else { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // tout est ok |
|
| 94 | + return [ |
|
| 95 | + 'titres' => $titres, |
|
| 96 | + 'roles' => $application, |
|
| 97 | + 'colonne' => $colonne |
|
| 98 | + ]; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | * Nom de la colonne, sinon vide |
| 110 | 110 | **/ |
| 111 | 111 | function roles_colonne($objet, $objet_destination) { |
| 112 | - if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 113 | - return $roles['colonne']; |
|
| 114 | - } |
|
| 112 | + if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 113 | + return $roles['colonne']; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - return ''; |
|
| 116 | + return ''; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | |
@@ -135,21 +135,21 @@ discard block |
||
| 135 | 135 | * Liste ('', '', array()) sinon. |
| 136 | 136 | **/ |
| 137 | 137 | function roles_trouver_dans_qualif($objet, $objet_destination, $qualif = []) { |
| 138 | - // si des rôles sont possibles, on les utilise |
|
| 139 | - $role = $colonne_role = ''; # role défini |
|
| 140 | - // condition du where par defaut |
|
| 141 | - $cond = []; |
|
| 142 | - if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 143 | - $colonne_role = $roles['colonne']; |
|
| 144 | - // qu'il n'est pas défini |
|
| 145 | - if (!isset($qualif[$colonne_role]) || !($role = $qualif[$colonne_role])) { |
|
| 146 | - $role = $roles['roles']['defaut']; |
|
| 147 | - } |
|
| 148 | - // where |
|
| 149 | - $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return [$role, $colonne_role, $cond]; |
|
| 138 | + // si des rôles sont possibles, on les utilise |
|
| 139 | + $role = $colonne_role = ''; # role défini |
|
| 140 | + // condition du where par defaut |
|
| 141 | + $cond = []; |
|
| 142 | + if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 143 | + $colonne_role = $roles['colonne']; |
|
| 144 | + // qu'il n'est pas défini |
|
| 145 | + if (!isset($qualif[$colonne_role]) || !($role = $qualif[$colonne_role])) { |
|
| 146 | + $role = $roles['roles']['defaut']; |
|
| 147 | + } |
|
| 148 | + // where |
|
| 149 | + $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return [$role, $colonne_role, $cond]; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -171,18 +171,18 @@ discard block |
||
| 171 | 171 | * Liste (Tableau de conditions where complété du role, Colonne du role, role utilisé) |
| 172 | 172 | **/ |
| 173 | 173 | function roles_creer_condition_role($objet_source, $objet, $cond, $tous_si_absent = false) { |
| 174 | - // role par défaut, colonne |
|
| 175 | - [$role_defaut, $colonne_role] = roles_trouver_dans_qualif($objet_source, $objet); |
|
| 176 | - |
|
| 177 | - // chercher d'eventuels rôles transmis |
|
| 178 | - $role = ($cond['role'] ?? ($tous_si_absent ? '*' : $role_defaut)); |
|
| 179 | - unset($cond['role']); // cette condition est particuliere... |
|
| 180 | - // on ajoute la condition du role aux autres conditions. |
|
| 181 | - if ($colonne_role && $role != '*') { |
|
| 182 | - $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - return [$cond, $colonne_role, $role]; |
|
| 174 | + // role par défaut, colonne |
|
| 175 | + [$role_defaut, $colonne_role] = roles_trouver_dans_qualif($objet_source, $objet); |
|
| 176 | + |
|
| 177 | + // chercher d'eventuels rôles transmis |
|
| 178 | + $role = ($cond['role'] ?? ($tous_si_absent ? '*' : $role_defaut)); |
|
| 179 | + unset($cond['role']); // cette condition est particuliere... |
|
| 180 | + // on ajoute la condition du role aux autres conditions. |
|
| 181 | + if ($colonne_role && $role != '*') { |
|
| 182 | + $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + return [$cond, $colonne_role, $role]; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -204,28 +204,28 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | function roles_complets($objet_source, $objet, $id_objet, $objet_lien) { |
| 206 | 206 | |
| 207 | - $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 208 | - // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 209 | - if ($presents === false) { |
|
| 210 | - return lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - // types de roles possibles |
|
| 214 | - $roles_possibles = $presents['roles']['roles']['choix']; |
|
| 215 | - // couples id / roles |
|
| 216 | - $ids = $presents['ids']; |
|
| 217 | - |
|
| 218 | - // pour chaque groupe, on fait le diff entre tous les roles possibles |
|
| 219 | - // et les roles attribués à l'élément : s'il en reste, c'est que l'élément |
|
| 220 | - // n'est pas complet |
|
| 221 | - $complets = []; |
|
| 222 | - foreach ($ids as $id => $roles_presents) { |
|
| 223 | - if (!array_diff($roles_possibles, $roles_presents)) { |
|
| 224 | - $complets[] = $id; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return $complets; |
|
| 207 | + $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 208 | + // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 209 | + if ($presents === false) { |
|
| 210 | + return lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + // types de roles possibles |
|
| 214 | + $roles_possibles = $presents['roles']['roles']['choix']; |
|
| 215 | + // couples id / roles |
|
| 216 | + $ids = $presents['ids']; |
|
| 217 | + |
|
| 218 | + // pour chaque groupe, on fait le diff entre tous les roles possibles |
|
| 219 | + // et les roles attribués à l'élément : s'il en reste, c'est que l'élément |
|
| 220 | + // n'est pas complet |
|
| 221 | + $complets = []; |
|
| 222 | + foreach ($ids as $id => $roles_presents) { |
|
| 223 | + if (!array_diff($roles_possibles, $roles_presents)) { |
|
| 224 | + $complets[] = $id; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return $complets; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | |
@@ -242,17 +242,17 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | function roles_presents_sur_id($id_objet_source, $objet_source, $objet, $id_objet, $objet_lien) { |
| 244 | 244 | |
| 245 | - $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 246 | - // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 247 | - if ($presents === false) { |
|
| 248 | - return []; |
|
| 249 | - } |
|
| 245 | + $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 246 | + // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 247 | + if ($presents === false) { |
|
| 248 | + return []; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - if (!isset($presents['ids'][$id_objet_source])) { |
|
| 252 | - return []; |
|
| 253 | - } |
|
| 251 | + if (!isset($presents['ids'][$id_objet_source])) { |
|
| 252 | + return []; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - return $presents['ids'][$id_objet_source]; |
|
| 255 | + return $presents['ids'][$id_objet_source]; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | |
@@ -280,47 +280,47 @@ discard block |
||
| 280 | 280 | * - False si pas de role déclarés |
| 281 | 281 | */ |
| 282 | 282 | function roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien) { |
| 283 | - static $done = []; |
|
| 284 | - |
|
| 285 | - // stocker le résultat |
|
| 286 | - $hash = "$objet_source-$objet-$id_objet-$objet_lien"; |
|
| 287 | - if (isset($done[$hash])) { |
|
| 288 | - return $done[$hash]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - // pas de roles sur ces objets, on sort |
|
| 292 | - $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 293 | - if (!$roles) { |
|
| 294 | - return $done[$hash] = false; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // inspiré de lister_objets_lies() |
|
| 298 | - if ($objet_lien == $objet) { |
|
| 299 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 300 | - } else { |
|
| 301 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // types de roles possibles |
|
| 305 | - $roles_possibles = $roles['roles']['choix']; |
|
| 306 | - // colonne du role |
|
| 307 | - $colonne = $roles['colonne']; |
|
| 308 | - |
|
| 309 | - // on recupere par id, et role existant |
|
| 310 | - $ids = []; |
|
| 311 | - while ($row = array_shift($res)) { |
|
| 312 | - $id = $row[$objet_source]; |
|
| 313 | - if (!isset($ids[$id])) { |
|
| 314 | - $ids[$id] = []; |
|
| 315 | - } |
|
| 316 | - // tableau des roles présents |
|
| 317 | - $ids[$id][] = $row[$colonne]; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - return $done[$hash] = [ |
|
| 321 | - 'roles' => $roles, |
|
| 322 | - 'ids' => $ids |
|
| 323 | - ]; |
|
| 283 | + static $done = []; |
|
| 284 | + |
|
| 285 | + // stocker le résultat |
|
| 286 | + $hash = "$objet_source-$objet-$id_objet-$objet_lien"; |
|
| 287 | + if (isset($done[$hash])) { |
|
| 288 | + return $done[$hash]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + // pas de roles sur ces objets, on sort |
|
| 292 | + $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 293 | + if (!$roles) { |
|
| 294 | + return $done[$hash] = false; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // inspiré de lister_objets_lies() |
|
| 298 | + if ($objet_lien == $objet) { |
|
| 299 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 300 | + } else { |
|
| 301 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // types de roles possibles |
|
| 305 | + $roles_possibles = $roles['roles']['choix']; |
|
| 306 | + // colonne du role |
|
| 307 | + $colonne = $roles['colonne']; |
|
| 308 | + |
|
| 309 | + // on recupere par id, et role existant |
|
| 310 | + $ids = []; |
|
| 311 | + while ($row = array_shift($res)) { |
|
| 312 | + $id = $row[$objet_source]; |
|
| 313 | + if (!isset($ids[$id])) { |
|
| 314 | + $ids[$id] = []; |
|
| 315 | + } |
|
| 316 | + // tableau des roles présents |
|
| 317 | + $ids[$id][] = $row[$colonne]; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + return $done[$hash] = [ |
|
| 321 | + 'roles' => $roles, |
|
| 322 | + 'ids' => $ids |
|
| 323 | + ]; |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | |
@@ -338,33 +338,33 @@ discard block |
||
| 338 | 338 | * - false si pas de role déclarés |
| 339 | 339 | */ |
| 340 | 340 | function roles_connus_en_base($objet_source, $objet, $objet_lien) { |
| 341 | - static $done = []; |
|
| 342 | - |
|
| 343 | - // stocker le résultat |
|
| 344 | - $hash = "$objet_source-$objet-$objet_lien"; |
|
| 345 | - if (isset($done[$hash])) { |
|
| 346 | - return $done[$hash]; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if (!$lien = objet_associable($objet_lien)) { |
|
| 350 | - return $done[$hash] = false; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - // pas de roles sur ces objets, on sort |
|
| 354 | - $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 355 | - if (!$roles) { |
|
| 356 | - return $done[$hash] = false; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - [$primary, $l] = $lien; |
|
| 360 | - $colone_role = $roles['colonne']; |
|
| 361 | - |
|
| 362 | - $all = sql_allfetsel( |
|
| 363 | - "DISTINCT $colone_role", |
|
| 364 | - $l, |
|
| 365 | - 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 366 | - ); |
|
| 367 | - $done[$hash] = array_map('reset', $all); |
|
| 368 | - |
|
| 369 | - return $done[$hash]; |
|
| 341 | + static $done = []; |
|
| 342 | + |
|
| 343 | + // stocker le résultat |
|
| 344 | + $hash = "$objet_source-$objet-$objet_lien"; |
|
| 345 | + if (isset($done[$hash])) { |
|
| 346 | + return $done[$hash]; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if (!$lien = objet_associable($objet_lien)) { |
|
| 350 | + return $done[$hash] = false; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + // pas de roles sur ces objets, on sort |
|
| 354 | + $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 355 | + if (!$roles) { |
|
| 356 | + return $done[$hash] = false; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + [$primary, $l] = $lien; |
|
| 360 | + $colone_role = $roles['colonne']; |
|
| 361 | + |
|
| 362 | + $all = sql_allfetsel( |
|
| 363 | + "DISTINCT $colone_role", |
|
| 364 | + $l, |
|
| 365 | + 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 366 | + ); |
|
| 367 | + $done[$hash] = array_map('reset', $all); |
|
| 368 | + |
|
| 369 | + return $done[$hash]; |
|
| 370 | 370 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $role = $roles['roles']['defaut']; |
| 147 | 147 | } |
| 148 | 148 | // where |
| 149 | - $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 149 | + $cond = ["$colonne_role=".sql_quote($role)]; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | return [$role, $colonne_role, $cond]; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | unset($cond['role']); // cette condition est particuliere... |
| 180 | 180 | // on ajoute la condition du role aux autres conditions. |
| 181 | 181 | if ($colonne_role && $role != '*') { |
| 182 | - $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 182 | + $cond[] = "$colonne_role=".sql_quote($role); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | return [$cond, $colonne_role, $role]; |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | $all = sql_allfetsel( |
| 363 | 363 | "DISTINCT $colone_role", |
| 364 | 364 | $l, |
| 365 | - 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 365 | + 'objet='.sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 366 | 366 | ); |
| 367 | 367 | $done[$hash] = array_map('reset', $all); |
| 368 | 368 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | static $t1 = ['&', '<', '>']; |
| 120 | 120 | static $t2 = ['&', '<', '>']; |
| 121 | 121 | |
| 122 | - return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>'; |
|
| 122 | + return '<pre>'.str_replace($t1, $t2, (string) $t).'</pre>'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | foreach ($lignes as &$l) { |
| 140 | 140 | $l = implode('|', $l); |
| 141 | 141 | } |
| 142 | - $corps = implode("\n", $lignes) . "\n"; |
|
| 143 | - $corps = $caption . |
|
| 144 | - "\n|{{" . |
|
| 145 | - implode('}}|{{', $entete) . |
|
| 146 | - '}}|' . |
|
| 147 | - "\n|" . |
|
| 142 | + $corps = implode("\n", $lignes)."\n"; |
|
| 143 | + $corps = $caption. |
|
| 144 | + "\n|{{". |
|
| 145 | + implode('}}|{{', $entete). |
|
| 146 | + '}}|'. |
|
| 147 | + "\n|". |
|
| 148 | 148 | str_replace("\n", "|\n|", $corps); |
| 149 | 149 | include_spip('inc/texte'); |
| 150 | 150 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
| 189 | 189 | $t = safehtml(preg_replace(',<script.*?</script>,is', '', $t)); |
| 190 | 190 | |
| 191 | - return ($style ? "\n<style>" . $style . '</style>' : '') . $t; |
|
| 191 | + return ($style ? "\n<style>".$style.'</style>' : '').$t; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | **/ |
| 22 | 22 | |
| 23 | 23 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | include_spip('inc/filtres'); |
| 27 | 27 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return string Rien. |
| 39 | 39 | **/ |
| 40 | 40 | function filtre_image_dist($t) { |
| 41 | - return ''; |
|
| 41 | + return ''; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @return string Rien. |
| 52 | 52 | **/ |
| 53 | 53 | function filtre_audio_dist($t) { |
| 54 | - return ''; |
|
| 54 | + return ''; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @return string Rien. |
| 65 | 65 | **/ |
| 66 | 66 | function filtre_video_dist($t) { |
| 67 | - return ''; |
|
| 67 | + return ''; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * @return string Rien. |
| 78 | 78 | **/ |
| 79 | 79 | function filtre_application_dist($t) { |
| 80 | - return ''; |
|
| 80 | + return ''; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @return string Rien. |
| 91 | 91 | **/ |
| 92 | 92 | function filtre_message_dist($t) { |
| 93 | - return ''; |
|
| 93 | + return ''; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | * @return string Rien. |
| 104 | 104 | **/ |
| 105 | 105 | function filtre_multipart_dist($t) { |
| 106 | - return ''; |
|
| 106 | + return ''; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -116,10 +116,10 @@ discard block |
||
| 116 | 116 | * @return string Contenu échappé. |
| 117 | 117 | **/ |
| 118 | 118 | function filtre_text_dist($t) { |
| 119 | - static $t1 = ['&', '<', '>']; |
|
| 120 | - static $t2 = ['&', '<', '>']; |
|
| 119 | + static $t1 = ['&', '<', '>']; |
|
| 120 | + static $t2 = ['&', '<', '>']; |
|
| 121 | 121 | |
| 122 | - return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>'; |
|
| 122 | + return '<pre>' . str_replace($t1, $t2, (string) $t) . '</pre>'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -134,21 +134,21 @@ discard block |
||
| 134 | 134 | * Tableau (formaté en SPIP) |
| 135 | 135 | **/ |
| 136 | 136 | function filtre_text_csv_dist($t) { |
| 137 | - include_spip('inc/csv'); |
|
| 138 | - [$entete, $lignes, $caption] = analyse_csv($t); |
|
| 139 | - foreach ($lignes as &$l) { |
|
| 140 | - $l = implode('|', $l); |
|
| 141 | - } |
|
| 142 | - $corps = implode("\n", $lignes) . "\n"; |
|
| 143 | - $corps = $caption . |
|
| 144 | - "\n|{{" . |
|
| 145 | - implode('}}|{{', $entete) . |
|
| 146 | - '}}|' . |
|
| 147 | - "\n|" . |
|
| 148 | - str_replace("\n", "|\n|", $corps); |
|
| 149 | - include_spip('inc/texte'); |
|
| 150 | - |
|
| 151 | - return propre($corps); |
|
| 137 | + include_spip('inc/csv'); |
|
| 138 | + [$entete, $lignes, $caption] = analyse_csv($t); |
|
| 139 | + foreach ($lignes as &$l) { |
|
| 140 | + $l = implode('|', $l); |
|
| 141 | + } |
|
| 142 | + $corps = implode("\n", $lignes) . "\n"; |
|
| 143 | + $corps = $caption . |
|
| 144 | + "\n|{{" . |
|
| 145 | + implode('}}|{{', $entete) . |
|
| 146 | + '}}|' . |
|
| 147 | + "\n|" . |
|
| 148 | + str_replace("\n", "|\n|", $corps); |
|
| 149 | + include_spip('inc/texte'); |
|
| 150 | + |
|
| 151 | + return propre($corps); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -162,33 +162,33 @@ discard block |
||
| 162 | 162 | * @return string Code html sécurisé ou texte échappé |
| 163 | 163 | **/ |
| 164 | 164 | function filtre_text_html_dist($t) { |
| 165 | - if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) { |
|
| 166 | - return appliquer_filtre($t, 'text/plain'); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - [, $h, $t] = $r; |
|
| 170 | - |
|
| 171 | - $style = ''; |
|
| 172 | - // recuperer les styles internes |
|
| 173 | - if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 174 | - $style = implode("\n", $r[1]); |
|
| 175 | - } |
|
| 176 | - // ... et externes |
|
| 177 | - |
|
| 178 | - include_spip('inc/distant'); |
|
| 179 | - if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 180 | - foreach ($r[0] as $l) { |
|
| 181 | - preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m); |
|
| 182 | - $page = recuperer_url($m[1]); |
|
| 183 | - $page = $page['page'] ?? ''; |
|
| 184 | - $style .= "\n/* $l */\n" |
|
| 185 | - . str_replace('<', '', (string) $page); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 189 | - $t = safehtml(preg_replace(',<script.*?</script>,is', '', $t)); |
|
| 190 | - |
|
| 191 | - return ($style ? "\n<style>" . $style . '</style>' : '') . $t; |
|
| 165 | + if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) { |
|
| 166 | + return appliquer_filtre($t, 'text/plain'); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + [, $h, $t] = $r; |
|
| 170 | + |
|
| 171 | + $style = ''; |
|
| 172 | + // recuperer les styles internes |
|
| 173 | + if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 174 | + $style = implode("\n", $r[1]); |
|
| 175 | + } |
|
| 176 | + // ... et externes |
|
| 177 | + |
|
| 178 | + include_spip('inc/distant'); |
|
| 179 | + if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 180 | + foreach ($r[0] as $l) { |
|
| 181 | + preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m); |
|
| 182 | + $page = recuperer_url($m[1]); |
|
| 183 | + $page = $page['page'] ?? ''; |
|
| 184 | + $style .= "\n/* $l */\n" |
|
| 185 | + . str_replace('<', '', (string) $page); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 189 | + $t = safehtml(preg_replace(',<script.*?</script>,is', '', $t)); |
|
| 190 | + |
|
| 191 | + return ($style ? "\n<style>" . $style . '</style>' : '') . $t; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @return string Code HTML des balises `<param>` |
| 202 | 202 | **/ |
| 203 | 203 | function filtre_audio_x_pn_realaudio($id) { |
| 204 | - return " |
|
| 204 | + return " |
|
| 205 | 205 | <param name='controls' value='PositionSlider' /> |
| 206 | 206 | <param name='controls' value='ImageWindow' /> |
| 207 | 207 | <param name='controls' value='PlayButton' /> |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_spip('inc/charsets'); |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * @return array |
| 42 | 42 | */ |
| 43 | 43 | function importer_csv_importcharset($texte, $definir_charset_source = false) { |
| 44 | - // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 45 | - static $charset_source = 'iso-8859-1'; |
|
| 46 | - if ($definir_charset_source) { |
|
| 47 | - $charset_source = $definir_charset_source === true ? 'iso-8859-1' : $definir_charset_source; |
|
| 48 | - } |
|
| 49 | - // mais open-office sait faire mieux, donc mefiance ! |
|
| 50 | - $charset = is_utf8($texte) ? 'utf-8' : $charset_source; |
|
| 51 | - return importer_charset($texte, $charset); |
|
| 44 | + // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 45 | + static $charset_source = 'iso-8859-1'; |
|
| 46 | + if ($definir_charset_source) { |
|
| 47 | + $charset_source = $definir_charset_source === true ? 'iso-8859-1' : $definir_charset_source; |
|
| 48 | + } |
|
| 49 | + // mais open-office sait faire mieux, donc mefiance ! |
|
| 50 | + $charset = is_utf8($texte) ? 'utf-8' : $charset_source; |
|
| 51 | + return importer_charset($texte, $charset); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | 61 | function importer_csv_nettoie_key($key) { |
| 62 | - return translitteration($key); |
|
| 62 | + return translitteration($key); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -78,70 +78,70 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | function inc_importer_csv_dist($file, $options = []) { |
| 80 | 80 | |
| 81 | - // support ancienne syntaxe |
|
| 82 | - // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 83 | - if (!is_array($options)) { |
|
| 84 | - $args = func_get_args(); |
|
| 85 | - $options = []; |
|
| 86 | - foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 87 | - if (!empty($args[$k])) { |
|
| 88 | - $options[$option] = $args[$k]; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 81 | + // support ancienne syntaxe |
|
| 82 | + // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 83 | + if (!is_array($options)) { |
|
| 84 | + $args = func_get_args(); |
|
| 85 | + $options = []; |
|
| 86 | + foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 87 | + if (!empty($args[$k])) { |
|
| 88 | + $options[$option] = $args[$k]; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $default_options = [ |
|
| 94 | - 'head' => false, |
|
| 95 | - 'delim' => ',', |
|
| 96 | - 'enclos' => '"', |
|
| 97 | - 'len' => 10000, |
|
| 98 | - 'charset_source' => '', |
|
| 99 | - ]; |
|
| 100 | - $options = array_merge($default_options, $options); |
|
| 93 | + $default_options = [ |
|
| 94 | + 'head' => false, |
|
| 95 | + 'delim' => ',', |
|
| 96 | + 'enclos' => '"', |
|
| 97 | + 'len' => 10000, |
|
| 98 | + 'charset_source' => '', |
|
| 99 | + ]; |
|
| 100 | + $options = array_merge($default_options, $options); |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - $return = []; |
|
| 104 | - if (@file_exists($file) && ($handle = fopen($file, 'r'))) { |
|
| 105 | - if ($options['charset_source']) { |
|
| 106 | - importer_csv_importcharset('', $options['charset_source']); |
|
| 107 | - } |
|
| 108 | - if ($options['head']) { |
|
| 109 | - $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 110 | - if ($header) { |
|
| 111 | - $header = array_map('importer_csv_importcharset', $header); |
|
| 112 | - $header = array_map('importer_csv_nettoie_key', $header); |
|
| 113 | - $header_type = []; |
|
| 114 | - foreach ($header as $heading) { |
|
| 115 | - $header_type[$heading] = isset($header_type[$heading]) ? 'array' : 'scalar'; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 103 | + $return = []; |
|
| 104 | + if (@file_exists($file) && ($handle = fopen($file, 'r'))) { |
|
| 105 | + if ($options['charset_source']) { |
|
| 106 | + importer_csv_importcharset('', $options['charset_source']); |
|
| 107 | + } |
|
| 108 | + if ($options['head']) { |
|
| 109 | + $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 110 | + if ($header) { |
|
| 111 | + $header = array_map('importer_csv_importcharset', $header); |
|
| 112 | + $header = array_map('importer_csv_nettoie_key', $header); |
|
| 113 | + $header_type = []; |
|
| 114 | + foreach ($header as $heading) { |
|
| 115 | + $header_type[$heading] = isset($header_type[$heading]) ? 'array' : 'scalar'; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 121 | - $data = array_map('importer_csv_importcharset', $data); |
|
| 122 | - if ($options['head'] && isset($header)) { |
|
| 123 | - $row = []; |
|
| 124 | - foreach ($header as $key => $heading) { |
|
| 125 | - if ($header_type[$heading] == 'array') { |
|
| 126 | - if (!isset($row[$heading])) { |
|
| 127 | - $row[$heading] = []; |
|
| 128 | - } |
|
| 129 | - if (isset($data[$key]) && strlen($data[$key])) { |
|
| 130 | - $row[$heading][] = $data[$key]; |
|
| 131 | - } |
|
| 132 | - } else { |
|
| 133 | - $row[$heading] = $data[$key] ?? ''; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $return[] = $row; |
|
| 137 | - } else { |
|
| 138 | - $return[] = $data; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - if ($options['charset_source']) { |
|
| 142 | - importer_csv_importcharset('', true); |
|
| 143 | - } |
|
| 144 | - } |
|
| 120 | + while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 121 | + $data = array_map('importer_csv_importcharset', $data); |
|
| 122 | + if ($options['head'] && isset($header)) { |
|
| 123 | + $row = []; |
|
| 124 | + foreach ($header as $key => $heading) { |
|
| 125 | + if ($header_type[$heading] == 'array') { |
|
| 126 | + if (!isset($row[$heading])) { |
|
| 127 | + $row[$heading] = []; |
|
| 128 | + } |
|
| 129 | + if (isset($data[$key]) && strlen($data[$key])) { |
|
| 130 | + $row[$heading][] = $data[$key]; |
|
| 131 | + } |
|
| 132 | + } else { |
|
| 133 | + $row[$heading] = $data[$key] ?? ''; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $return[] = $row; |
|
| 137 | + } else { |
|
| 138 | + $return[] = $data; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + if ($options['charset_source']) { |
|
| 142 | + importer_csv_importcharset('', true); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - return $return ?: false; |
|
| 146 | + return $return ?: false; |
|
| 147 | 147 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $_id_table = reset($_id_table); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 69 | + $requete['SELECT'][] = 't.'.$_id_table; |
|
| 70 | 70 | $a = []; |
| 71 | 71 | // Recherche fulltext |
| 72 | 72 | foreach ($champs as $champ => $poids) { |
@@ -77,13 +77,13 @@ discard block |
||
| 77 | 77 | $champ = "t.$champ"; |
| 78 | 78 | } |
| 79 | 79 | $requete['SELECT'][] = $champ; |
| 80 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 80 | + $a[] = $champ.' '.$methode.' '.$q; |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | if ($a) { |
| 84 | 84 | $requete['WHERE'][] = implode(' OR ', $a); |
| 85 | 85 | } |
| 86 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 86 | + $requete['FROM'][] = table_objet_sql($table).' AS t'; |
|
| 87 | 87 | |
| 88 | 88 | $results = []; |
| 89 | 89 | |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | ); |
| 245 | 245 | } // cas table de liaison generique spip_xxx_yyy |
| 246 | 246 | elseif ( |
| 247 | - ($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)) |
|
| 248 | - || ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)) |
|
| 247 | + ($t = $trouver_table($table_arrivee.'_'.$table_depart, $serveur)) |
|
| 248 | + || ($t = $trouver_table($table_depart.'_'.$table_arrivee, $serveur)) |
|
| 249 | 249 | ) { |
| 250 | 250 | $s = sql_select( |
| 251 | 251 | "$cle_depart,$cle_arrivee", |
@@ -284,12 +284,12 @@ discard block |
||
| 284 | 284 | } |
| 285 | 285 | if (isset($joint['champs']) && $joint['champs']) { |
| 286 | 286 | foreach ($joint['champs'] as $c => $val) { |
| 287 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 287 | + $results[$id]['champs'][$table_liee.'.'.$c] = $val; |
|
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | if (isset($joint['matches']) && $joint['matches']) { |
| 291 | 291 | foreach ($joint['matches'] as $c => $val) { |
| 292 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 292 | + $results[$id]['matches'][$table_liee.'.'.$c] = $val; |
|
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | } |
@@ -10,291 +10,291 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | // methodes sql |
| 18 | 18 | function inc_recherche_to_array_dist($recherche, $options = []) { |
| 19 | 19 | |
| 20 | - // options par defaut |
|
| 21 | - $options = array_merge( |
|
| 22 | - [ |
|
| 23 | - 'score' => true, |
|
| 24 | - 'champs' => false, |
|
| 25 | - 'toutvoir' => false, |
|
| 26 | - 'matches' => false, |
|
| 27 | - 'jointures' => false |
|
| 28 | - ], |
|
| 29 | - $options |
|
| 30 | - ); |
|
| 20 | + // options par defaut |
|
| 21 | + $options = array_merge( |
|
| 22 | + [ |
|
| 23 | + 'score' => true, |
|
| 24 | + 'champs' => false, |
|
| 25 | + 'toutvoir' => false, |
|
| 26 | + 'matches' => false, |
|
| 27 | + 'jointures' => false |
|
| 28 | + ], |
|
| 29 | + $options |
|
| 30 | + ); |
|
| 31 | 31 | |
| 32 | - include_spip('inc/rechercher'); |
|
| 33 | - include_spip('inc/autoriser'); |
|
| 32 | + include_spip('inc/rechercher'); |
|
| 33 | + include_spip('inc/autoriser'); |
|
| 34 | 34 | |
| 35 | - $requete = [ |
|
| 36 | - 'SELECT' => [], |
|
| 37 | - 'FROM' => [], |
|
| 38 | - 'WHERE' => [], |
|
| 39 | - 'GROUPBY' => [], |
|
| 40 | - 'ORDERBY' => [], |
|
| 41 | - 'LIMIT' => '', |
|
| 42 | - 'HAVING' => [] |
|
| 43 | - ]; |
|
| 35 | + $requete = [ |
|
| 36 | + 'SELECT' => [], |
|
| 37 | + 'FROM' => [], |
|
| 38 | + 'WHERE' => [], |
|
| 39 | + 'GROUPBY' => [], |
|
| 40 | + 'ORDERBY' => [], |
|
| 41 | + 'LIMIT' => '', |
|
| 42 | + 'HAVING' => [] |
|
| 43 | + ]; |
|
| 44 | 44 | |
| 45 | - $table = sinon($options['table'], 'article'); |
|
| 46 | - if ($options['champs']) { |
|
| 47 | - $champs = $options['champs']; |
|
| 48 | - } else { |
|
| 49 | - $l = liste_des_champs(); |
|
| 50 | - $champs = $l['article']; |
|
| 51 | - } |
|
| 52 | - $serveur = $options['serveur']; |
|
| 45 | + $table = sinon($options['table'], 'article'); |
|
| 46 | + if ($options['champs']) { |
|
| 47 | + $champs = $options['champs']; |
|
| 48 | + } else { |
|
| 49 | + $l = liste_des_champs(); |
|
| 50 | + $champs = $l['article']; |
|
| 51 | + } |
|
| 52 | + $serveur = $options['serveur']; |
|
| 53 | 53 | |
| 54 | - [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 54 | + [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 55 | 55 | |
| 56 | - $jointures = $options['jointures'] |
|
| 57 | - ? liste_des_jointures() |
|
| 58 | - : []; |
|
| 56 | + $jointures = $options['jointures'] |
|
| 57 | + ? liste_des_jointures() |
|
| 58 | + : []; |
|
| 59 | 59 | |
| 60 | - $_id_table = id_table_objet($table); |
|
| 60 | + $_id_table = id_table_objet($table); |
|
| 61 | 61 | |
| 62 | - // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 63 | - // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 64 | - if (str_contains((string) $_id_table, ',')) { |
|
| 65 | - $_id_table = explode(',', (string) $_id_table); |
|
| 66 | - $_id_table = reset($_id_table); |
|
| 67 | - } |
|
| 62 | + // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 63 | + // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 64 | + if (str_contains((string) $_id_table, ',')) { |
|
| 65 | + $_id_table = explode(',', (string) $_id_table); |
|
| 66 | + $_id_table = reset($_id_table); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 70 | - $a = []; |
|
| 71 | - // Recherche fulltext |
|
| 72 | - foreach ($champs as $champ => $poids) { |
|
| 73 | - if (is_array($champ)) { |
|
| 74 | - spip_log('requetes imbriquees interdites'); |
|
| 75 | - } else { |
|
| 76 | - if (!str_contains((string) $champ, '.')) { |
|
| 77 | - $champ = "t.$champ"; |
|
| 78 | - } |
|
| 79 | - $requete['SELECT'][] = $champ; |
|
| 80 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - if ($a) { |
|
| 84 | - $requete['WHERE'][] = implode(' OR ', $a); |
|
| 85 | - } |
|
| 86 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 69 | + $requete['SELECT'][] = 't.' . $_id_table; |
|
| 70 | + $a = []; |
|
| 71 | + // Recherche fulltext |
|
| 72 | + foreach ($champs as $champ => $poids) { |
|
| 73 | + if (is_array($champ)) { |
|
| 74 | + spip_log('requetes imbriquees interdites'); |
|
| 75 | + } else { |
|
| 76 | + if (!str_contains((string) $champ, '.')) { |
|
| 77 | + $champ = "t.$champ"; |
|
| 78 | + } |
|
| 79 | + $requete['SELECT'][] = $champ; |
|
| 80 | + $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + if ($a) { |
|
| 84 | + $requete['WHERE'][] = implode(' OR ', $a); |
|
| 85 | + } |
|
| 86 | + $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 87 | 87 | |
| 88 | - $results = []; |
|
| 88 | + $results = []; |
|
| 89 | 89 | |
| 90 | - $s = sql_select( |
|
| 91 | - $requete['SELECT'], |
|
| 92 | - $requete['FROM'], |
|
| 93 | - $requete['WHERE'], |
|
| 94 | - implode(' ', $requete['GROUPBY']), |
|
| 95 | - $requete['ORDERBY'], |
|
| 96 | - $requete['LIMIT'], |
|
| 97 | - $requete['HAVING'], |
|
| 98 | - $serveur |
|
| 99 | - ); |
|
| 90 | + $s = sql_select( |
|
| 91 | + $requete['SELECT'], |
|
| 92 | + $requete['FROM'], |
|
| 93 | + $requete['WHERE'], |
|
| 94 | + implode(' ', $requete['GROUPBY']), |
|
| 95 | + $requete['ORDERBY'], |
|
| 96 | + $requete['LIMIT'], |
|
| 97 | + $requete['HAVING'], |
|
| 98 | + $serveur |
|
| 99 | + ); |
|
| 100 | 100 | |
| 101 | - while ( |
|
| 102 | - ($t = sql_fetch($s, $serveur)) |
|
| 103 | - && (!isset($t['score']) || $t['score'] > 0) |
|
| 104 | - ) { |
|
| 105 | - $id = (int) $t[$_id_table]; |
|
| 101 | + while ( |
|
| 102 | + ($t = sql_fetch($s, $serveur)) |
|
| 103 | + && (!isset($t['score']) || $t['score'] > 0) |
|
| 104 | + ) { |
|
| 105 | + $id = (int) $t[$_id_table]; |
|
| 106 | 106 | |
| 107 | - if ($options['toutvoir'] || autoriser('voir', $table, $id)) { |
|
| 108 | - // indiquer les champs concernes |
|
| 109 | - $champs_vus = []; |
|
| 110 | - $score = 0; |
|
| 111 | - $matches = []; |
|
| 107 | + if ($options['toutvoir'] || autoriser('voir', $table, $id)) { |
|
| 108 | + // indiquer les champs concernes |
|
| 109 | + $champs_vus = []; |
|
| 110 | + $score = 0; |
|
| 111 | + $matches = []; |
|
| 112 | 112 | |
| 113 | - $vu = false; |
|
| 114 | - foreach ($champs as $champ => $poids) { |
|
| 115 | - $champ = explode('.', (string) $champ); |
|
| 116 | - $champ = end($champ); |
|
| 117 | - // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 118 | - $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 119 | - if ( |
|
| 120 | - $n = |
|
| 121 | - ($options['score'] || $options['matches']) |
|
| 122 | - ? preg_match_all($preg, (string) $value, $regs, PREG_SET_ORDER) |
|
| 123 | - : preg_match($preg, (string) $value) |
|
| 124 | - ) { |
|
| 125 | - $vu = true; |
|
| 113 | + $vu = false; |
|
| 114 | + foreach ($champs as $champ => $poids) { |
|
| 115 | + $champ = explode('.', (string) $champ); |
|
| 116 | + $champ = end($champ); |
|
| 117 | + // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 118 | + $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 119 | + if ( |
|
| 120 | + $n = |
|
| 121 | + ($options['score'] || $options['matches']) |
|
| 122 | + ? preg_match_all($preg, (string) $value, $regs, PREG_SET_ORDER) |
|
| 123 | + : preg_match($preg, (string) $value) |
|
| 124 | + ) { |
|
| 125 | + $vu = true; |
|
| 126 | 126 | |
| 127 | - if ($options['champs']) { |
|
| 128 | - $champs_vus[$champ] = $t[$champ]; |
|
| 129 | - } |
|
| 130 | - if ($options['score']) { |
|
| 131 | - // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 132 | - $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 133 | - } |
|
| 127 | + if ($options['champs']) { |
|
| 128 | + $champs_vus[$champ] = $t[$champ]; |
|
| 129 | + } |
|
| 130 | + if ($options['score']) { |
|
| 131 | + // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 132 | + $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - if ($options['matches']) { |
|
| 136 | - $matches[$champ] = $regs; |
|
| 137 | - } |
|
| 135 | + if ($options['matches']) { |
|
| 136 | + $matches[$champ] = $regs; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if (!$options['champs'] && !$options['score'] && !$options['matches']) { |
|
| 140 | - break; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 139 | + if (!$options['champs'] && !$options['score'] && !$options['matches']) { |
|
| 140 | + break; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - if ($vu) { |
|
| 146 | - if (!isset($results)) { |
|
| 147 | - $results = []; |
|
| 148 | - } |
|
| 149 | - $results[$id] = []; |
|
| 150 | - if ($champs_vus) { |
|
| 151 | - $results[$id]['champs'] = $champs_vus; |
|
| 152 | - } |
|
| 153 | - if ($score) { |
|
| 154 | - $results[$id]['score'] = $score; |
|
| 155 | - } |
|
| 156 | - if ($matches) { |
|
| 157 | - $results[$id]['matches'] = $matches; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 145 | + if ($vu) { |
|
| 146 | + if (!isset($results)) { |
|
| 147 | + $results = []; |
|
| 148 | + } |
|
| 149 | + $results[$id] = []; |
|
| 150 | + if ($champs_vus) { |
|
| 151 | + $results[$id]['champs'] = $champs_vus; |
|
| 152 | + } |
|
| 153 | + if ($score) { |
|
| 154 | + $results[$id]['score'] = $score; |
|
| 155 | + } |
|
| 156 | + if ($matches) { |
|
| 157 | + $results[$id]['matches'] = $matches; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | |
| 164 | - // Gerer les donnees associees |
|
| 165 | - // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 166 | - // on ne sait passer que par table de laison en 1 coup |
|
| 167 | - if ( |
|
| 168 | - isset($jointures[$table]) |
|
| 169 | - && ($joints = recherche_en_base( |
|
| 170 | - $recherche, |
|
| 171 | - $jointures[$table], |
|
| 172 | - array_merge($options, ['jointures' => false]) |
|
| 173 | - )) |
|
| 174 | - ) { |
|
| 175 | - include_spip('action/editer_liens'); |
|
| 176 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 177 | - $cle_depart = id_table_objet($table); |
|
| 178 | - $table_depart = table_objet($table, $serveur); |
|
| 179 | - $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 180 | - $depart_associable = objet_associable($table); |
|
| 181 | - foreach ($joints as $table_liee => $ids_trouves) { |
|
| 182 | - // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 183 | - if ( |
|
| 184 | - !( |
|
| 185 | - ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true)) |
|
| 186 | - || ($rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true)) |
|
| 187 | - || ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true)) |
|
| 188 | - ) |
|
| 189 | - ) { |
|
| 190 | - $cle_arrivee = id_table_objet($table_liee); |
|
| 191 | - $table_arrivee = table_objet($table_liee, $serveur); |
|
| 192 | - $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 193 | - // cas simple : $cle_depart dans la table_liee |
|
| 194 | - if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 195 | - $s = sql_select( |
|
| 196 | - "$cle_depart, $cle_arrivee", |
|
| 197 | - $desc_arrivee['table_sql'], |
|
| 198 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 199 | - '', |
|
| 200 | - '', |
|
| 201 | - '', |
|
| 202 | - '', |
|
| 203 | - $serveur |
|
| 204 | - ); |
|
| 205 | - } // cas simple : $cle_arrivee dans la table |
|
| 206 | - elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 207 | - $s = sql_select( |
|
| 208 | - "$cle_depart, $cle_arrivee", |
|
| 209 | - $desc_depart['table_sql'], |
|
| 210 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 211 | - '', |
|
| 212 | - '', |
|
| 213 | - '', |
|
| 214 | - '', |
|
| 215 | - $serveur |
|
| 216 | - ); |
|
| 217 | - } |
|
| 218 | - // sinon cherchons une table de liaison |
|
| 219 | - // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 220 | - elseif ($l = objet_associable($table_liee)) { |
|
| 221 | - [$primary, $table_liens] = $l; |
|
| 222 | - $s = sql_select( |
|
| 223 | - "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 224 | - $table_liens, |
|
| 225 | - ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 226 | - '', |
|
| 227 | - '', |
|
| 228 | - '', |
|
| 229 | - '', |
|
| 230 | - $serveur |
|
| 231 | - ); |
|
| 232 | - } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 233 | - elseif ($l = $depart_associable) { |
|
| 234 | - [$primary, $table_liens] = $l; |
|
| 235 | - $s = sql_select( |
|
| 236 | - "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 237 | - $table_liens, |
|
| 238 | - ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 239 | - '', |
|
| 240 | - '', |
|
| 241 | - '', |
|
| 242 | - '', |
|
| 243 | - $serveur |
|
| 244 | - ); |
|
| 245 | - } // cas table de liaison generique spip_xxx_yyy |
|
| 246 | - elseif ( |
|
| 247 | - ($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)) |
|
| 248 | - || ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)) |
|
| 249 | - ) { |
|
| 250 | - $s = sql_select( |
|
| 251 | - "$cle_depart,$cle_arrivee", |
|
| 252 | - $t['table_sql'], |
|
| 253 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 254 | - '', |
|
| 255 | - '', |
|
| 256 | - '', |
|
| 257 | - '', |
|
| 258 | - $serveur |
|
| 259 | - ); |
|
| 260 | - } |
|
| 261 | - } else { |
|
| 262 | - [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 263 | - $table, |
|
| 264 | - $table_liee, |
|
| 265 | - array_keys($ids_trouves), |
|
| 266 | - $serveur |
|
| 267 | - ); |
|
| 268 | - } |
|
| 164 | + // Gerer les donnees associees |
|
| 165 | + // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 166 | + // on ne sait passer que par table de laison en 1 coup |
|
| 167 | + if ( |
|
| 168 | + isset($jointures[$table]) |
|
| 169 | + && ($joints = recherche_en_base( |
|
| 170 | + $recherche, |
|
| 171 | + $jointures[$table], |
|
| 172 | + array_merge($options, ['jointures' => false]) |
|
| 173 | + )) |
|
| 174 | + ) { |
|
| 175 | + include_spip('action/editer_liens'); |
|
| 176 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 177 | + $cle_depart = id_table_objet($table); |
|
| 178 | + $table_depart = table_objet($table, $serveur); |
|
| 179 | + $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 180 | + $depart_associable = objet_associable($table); |
|
| 181 | + foreach ($joints as $table_liee => $ids_trouves) { |
|
| 182 | + // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 183 | + if ( |
|
| 184 | + !( |
|
| 185 | + ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true)) |
|
| 186 | + || ($rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true)) |
|
| 187 | + || ($rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true)) |
|
| 188 | + ) |
|
| 189 | + ) { |
|
| 190 | + $cle_arrivee = id_table_objet($table_liee); |
|
| 191 | + $table_arrivee = table_objet($table_liee, $serveur); |
|
| 192 | + $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 193 | + // cas simple : $cle_depart dans la table_liee |
|
| 194 | + if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 195 | + $s = sql_select( |
|
| 196 | + "$cle_depart, $cle_arrivee", |
|
| 197 | + $desc_arrivee['table_sql'], |
|
| 198 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 199 | + '', |
|
| 200 | + '', |
|
| 201 | + '', |
|
| 202 | + '', |
|
| 203 | + $serveur |
|
| 204 | + ); |
|
| 205 | + } // cas simple : $cle_arrivee dans la table |
|
| 206 | + elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 207 | + $s = sql_select( |
|
| 208 | + "$cle_depart, $cle_arrivee", |
|
| 209 | + $desc_depart['table_sql'], |
|
| 210 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 211 | + '', |
|
| 212 | + '', |
|
| 213 | + '', |
|
| 214 | + '', |
|
| 215 | + $serveur |
|
| 216 | + ); |
|
| 217 | + } |
|
| 218 | + // sinon cherchons une table de liaison |
|
| 219 | + // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 220 | + elseif ($l = objet_associable($table_liee)) { |
|
| 221 | + [$primary, $table_liens] = $l; |
|
| 222 | + $s = sql_select( |
|
| 223 | + "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 224 | + $table_liens, |
|
| 225 | + ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 226 | + '', |
|
| 227 | + '', |
|
| 228 | + '', |
|
| 229 | + '', |
|
| 230 | + $serveur |
|
| 231 | + ); |
|
| 232 | + } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 233 | + elseif ($l = $depart_associable) { |
|
| 234 | + [$primary, $table_liens] = $l; |
|
| 235 | + $s = sql_select( |
|
| 236 | + "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 237 | + $table_liens, |
|
| 238 | + ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 239 | + '', |
|
| 240 | + '', |
|
| 241 | + '', |
|
| 242 | + '', |
|
| 243 | + $serveur |
|
| 244 | + ); |
|
| 245 | + } // cas table de liaison generique spip_xxx_yyy |
|
| 246 | + elseif ( |
|
| 247 | + ($t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur)) |
|
| 248 | + || ($t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur)) |
|
| 249 | + ) { |
|
| 250 | + $s = sql_select( |
|
| 251 | + "$cle_depart,$cle_arrivee", |
|
| 252 | + $t['table_sql'], |
|
| 253 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 254 | + '', |
|
| 255 | + '', |
|
| 256 | + '', |
|
| 257 | + '', |
|
| 258 | + $serveur |
|
| 259 | + ); |
|
| 260 | + } |
|
| 261 | + } else { |
|
| 262 | + [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 263 | + $table, |
|
| 264 | + $table_liee, |
|
| 265 | + array_keys($ids_trouves), |
|
| 266 | + $serveur |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 271 | - $id = $t[$cle_depart]; |
|
| 272 | - $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 273 | - if (!isset($results)) { |
|
| 274 | - $results = []; |
|
| 275 | - } |
|
| 276 | - if (!isset($results[$id])) { |
|
| 277 | - $results[$id] = []; |
|
| 278 | - } |
|
| 279 | - if (isset($joint['score']) && $joint['score']) { |
|
| 280 | - if (!isset($results[$id]['score'])) { |
|
| 281 | - $results[$id]['score'] = 0; |
|
| 282 | - } |
|
| 283 | - $results[$id]['score'] += $joint['score']; |
|
| 284 | - } |
|
| 285 | - if (isset($joint['champs']) && $joint['champs']) { |
|
| 286 | - foreach ($joint['champs'] as $c => $val) { |
|
| 287 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - if (isset($joint['matches']) && $joint['matches']) { |
|
| 291 | - foreach ($joint['matches'] as $c => $val) { |
|
| 292 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - } |
|
| 270 | + while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 271 | + $id = $t[$cle_depart]; |
|
| 272 | + $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 273 | + if (!isset($results)) { |
|
| 274 | + $results = []; |
|
| 275 | + } |
|
| 276 | + if (!isset($results[$id])) { |
|
| 277 | + $results[$id] = []; |
|
| 278 | + } |
|
| 279 | + if (isset($joint['score']) && $joint['score']) { |
|
| 280 | + if (!isset($results[$id]['score'])) { |
|
| 281 | + $results[$id]['score'] = 0; |
|
| 282 | + } |
|
| 283 | + $results[$id]['score'] += $joint['score']; |
|
| 284 | + } |
|
| 285 | + if (isset($joint['champs']) && $joint['champs']) { |
|
| 286 | + foreach ($joint['champs'] as $c => $val) { |
|
| 287 | + $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + if (isset($joint['matches']) && $joint['matches']) { |
|
| 291 | + foreach ($joint['matches'] as $c => $val) { |
|
| 292 | + $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - return $results; |
|
| 299 | + return $results; |
|
| 300 | 300 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | include_spip('inc/autoriser'); |
@@ -29,74 +29,74 @@ discard block |
||
| 29 | 29 | * Un tableau des sous rubriques |
| 30 | 30 | */ |
| 31 | 31 | function enfant_rub($collection, $debut = 0, $limite = 500) { |
| 32 | - $voir_logo = (isset($GLOBALS['meta']['image_process']) && $GLOBALS['meta']['image_process'] != 'non'); |
|
| 33 | - $logo = ''; |
|
| 34 | - |
|
| 35 | - if ($voir_logo) { |
|
| 36 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 37 | - include_spip('inc/filtres_images_mini'); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - $res = []; |
|
| 41 | - |
|
| 42 | - $result = sql_select( |
|
| 43 | - 'id_rubrique, id_parent, titre, descriptif, lang', |
|
| 44 | - 'spip_rubriques', |
|
| 45 | - 'id_parent=' . (int) $collection, |
|
| 46 | - '', |
|
| 47 | - '0+titre,titre', |
|
| 48 | - $debut == -1 ? '' : "$debut,$limite" |
|
| 49 | - ); |
|
| 50 | - while ($row = sql_fetch($result)) { |
|
| 51 | - $id_rubrique = $row['id_rubrique']; |
|
| 52 | - $id_parent = $row['id_parent']; |
|
| 53 | - // pour etre sur de passer par tous les traitements |
|
| 54 | - $titre = generer_objet_info($id_rubrique, 'rubrique', 'titre'); |
|
| 55 | - if ('' !== ($rang = recuperer_numero($row['titre']))) { |
|
| 56 | - $rang = "<span class='rang'>$rang.</span> "; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 60 | - $les_sous_enfants = sous_enfant_rub($id_rubrique); |
|
| 61 | - |
|
| 62 | - changer_typo($row['lang']); |
|
| 63 | - $lang_dir = lang_dir($row['lang']); |
|
| 64 | - $descriptif = propre($row['descriptif']); |
|
| 65 | - |
|
| 66 | - if ($voir_logo && ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on'))) { |
|
| 67 | - [$fid, $dir, $nom, $format] = $logo; |
|
| 68 | - $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70); |
|
| 69 | - if ($logo) { |
|
| 70 | - $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">'); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - $lib_bouton = (acces_restreint_rubrique($id_rubrique) |
|
| 75 | - ? http_img_pack('auteur-0minirezo-16.png', '', " width='16' height='16'", _T('image_administrer_rubrique')) |
|
| 76 | - : '') . |
|
| 77 | - " <a class='titremlien' dir='$lang_dir'" . |
|
| 78 | - ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 79 | - " href='" . |
|
| 80 | - generer_objet_url($id_rubrique, 'rubrique') . |
|
| 81 | - "'><span class='titre'>" . |
|
| 82 | - $rang . $titre |
|
| 83 | - . '</span>' |
|
| 84 | - . (is_string($logo) ? $logo : '') |
|
| 85 | - . '</a>'; |
|
| 86 | - |
|
| 87 | - $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique") |
|
| 88 | - . ($descriptif ? "\n<div class='descriptif'>$descriptif</div>" : '') |
|
| 89 | - ; |
|
| 90 | - |
|
| 91 | - $res[] = |
|
| 92 | - debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 93 | - $les_sous_enfants . |
|
| 94 | - fin_cadre_sous_rub(); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite |
|
| 99 | - return $res; |
|
| 32 | + $voir_logo = (isset($GLOBALS['meta']['image_process']) && $GLOBALS['meta']['image_process'] != 'non'); |
|
| 33 | + $logo = ''; |
|
| 34 | + |
|
| 35 | + if ($voir_logo) { |
|
| 36 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 37 | + include_spip('inc/filtres_images_mini'); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + $res = []; |
|
| 41 | + |
|
| 42 | + $result = sql_select( |
|
| 43 | + 'id_rubrique, id_parent, titre, descriptif, lang', |
|
| 44 | + 'spip_rubriques', |
|
| 45 | + 'id_parent=' . (int) $collection, |
|
| 46 | + '', |
|
| 47 | + '0+titre,titre', |
|
| 48 | + $debut == -1 ? '' : "$debut,$limite" |
|
| 49 | + ); |
|
| 50 | + while ($row = sql_fetch($result)) { |
|
| 51 | + $id_rubrique = $row['id_rubrique']; |
|
| 52 | + $id_parent = $row['id_parent']; |
|
| 53 | + // pour etre sur de passer par tous les traitements |
|
| 54 | + $titre = generer_objet_info($id_rubrique, 'rubrique', 'titre'); |
|
| 55 | + if ('' !== ($rang = recuperer_numero($row['titre']))) { |
|
| 56 | + $rang = "<span class='rang'>$rang.</span> "; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 60 | + $les_sous_enfants = sous_enfant_rub($id_rubrique); |
|
| 61 | + |
|
| 62 | + changer_typo($row['lang']); |
|
| 63 | + $lang_dir = lang_dir($row['lang']); |
|
| 64 | + $descriptif = propre($row['descriptif']); |
|
| 65 | + |
|
| 66 | + if ($voir_logo && ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on'))) { |
|
| 67 | + [$fid, $dir, $nom, $format] = $logo; |
|
| 68 | + $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70); |
|
| 69 | + if ($logo) { |
|
| 70 | + $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">'); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + $lib_bouton = (acces_restreint_rubrique($id_rubrique) |
|
| 75 | + ? http_img_pack('auteur-0minirezo-16.png', '', " width='16' height='16'", _T('image_administrer_rubrique')) |
|
| 76 | + : '') . |
|
| 77 | + " <a class='titremlien' dir='$lang_dir'" . |
|
| 78 | + ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 79 | + " href='" . |
|
| 80 | + generer_objet_url($id_rubrique, 'rubrique') . |
|
| 81 | + "'><span class='titre'>" . |
|
| 82 | + $rang . $titre |
|
| 83 | + . '</span>' |
|
| 84 | + . (is_string($logo) ? $logo : '') |
|
| 85 | + . '</a>'; |
|
| 86 | + |
|
| 87 | + $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique") |
|
| 88 | + . ($descriptif ? "\n<div class='descriptif'>$descriptif</div>" : '') |
|
| 89 | + ; |
|
| 90 | + |
|
| 91 | + $res[] = |
|
| 92 | + debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 93 | + $les_sous_enfants . |
|
| 94 | + fin_cadre_sous_rub(); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite |
|
| 99 | + return $res; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -109,71 +109,71 @@ discard block |
||
| 109 | 109 | * Le contenu du bloc dépliable |
| 110 | 110 | */ |
| 111 | 111 | function sous_enfant_rub($collection2) { |
| 112 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $collection2); |
|
| 113 | - |
|
| 114 | - $retour = ''; |
|
| 115 | - $pagination = ''; |
|
| 116 | - $debut = 0; |
|
| 117 | - $limite = 500; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * On ne va afficher que 500 résultats max |
|
| 121 | - * Si > 500 on affiche une pagination |
|
| 122 | - */ |
|
| 123 | - if ($nb > $limite) { |
|
| 124 | - $debut = _request('debut_rubrique' . $collection2) ?: $debut; |
|
| 125 | - $pagination = chercher_filtre('pagination'); |
|
| 126 | - $pagination = '<nav class="pagination">' . $pagination( |
|
| 127 | - $nb, |
|
| 128 | - '_rubrique' . $collection2, |
|
| 129 | - $debut, |
|
| 130 | - $limite, |
|
| 131 | - true, |
|
| 132 | - 'prive' |
|
| 133 | - ) . '</nav>'; |
|
| 134 | - $limite = $debut + $limite; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $result = sql_select( |
|
| 138 | - 'id_rubrique, id_parent, titre, lang', |
|
| 139 | - 'spip_rubriques', |
|
| 140 | - 'id_parent=' . (int) $collection2, |
|
| 141 | - '', |
|
| 142 | - '0+titre,titre', |
|
| 143 | - $debut == -1 ? '' : "$debut,$limite" |
|
| 144 | - ); |
|
| 145 | - |
|
| 146 | - while ($row = sql_fetch($result)) { |
|
| 147 | - $id_rubrique2 = $row['id_rubrique']; |
|
| 148 | - $titre2 = generer_objet_info( |
|
| 149 | - $id_rubrique2, |
|
| 150 | - 'rubrique', |
|
| 151 | - 'titre' |
|
| 152 | - ); // pour etre sur de passer par tous les traitements |
|
| 153 | - if ('' !== ($rang2 = recuperer_numero($row['titre']))) { |
|
| 154 | - $rang2 = "<span class='rang'>$rang2.</span> "; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - changer_typo($row['lang']); |
|
| 158 | - $lang_dir = lang_dir($row['lang']); |
|
| 159 | - if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
|
| 160 | - $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url( |
|
| 161 | - $id_rubrique2, |
|
| 162 | - 'rubrique' |
|
| 163 | - ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - $retour = $pagination . $retour . $pagination; |
|
| 168 | - |
|
| 169 | - if (!$retour) { |
|
| 170 | - return ''; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return debut_block_depliable($debut > 0, "enfants$collection2") |
|
| 174 | - . "\n<ul class='liste-items sous-sous-rub'>\n" |
|
| 175 | - . $retour |
|
| 176 | - . "</ul>\n" . fin_block() . "\n\n"; |
|
| 112 | + $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $collection2); |
|
| 113 | + |
|
| 114 | + $retour = ''; |
|
| 115 | + $pagination = ''; |
|
| 116 | + $debut = 0; |
|
| 117 | + $limite = 500; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * On ne va afficher que 500 résultats max |
|
| 121 | + * Si > 500 on affiche une pagination |
|
| 122 | + */ |
|
| 123 | + if ($nb > $limite) { |
|
| 124 | + $debut = _request('debut_rubrique' . $collection2) ?: $debut; |
|
| 125 | + $pagination = chercher_filtre('pagination'); |
|
| 126 | + $pagination = '<nav class="pagination">' . $pagination( |
|
| 127 | + $nb, |
|
| 128 | + '_rubrique' . $collection2, |
|
| 129 | + $debut, |
|
| 130 | + $limite, |
|
| 131 | + true, |
|
| 132 | + 'prive' |
|
| 133 | + ) . '</nav>'; |
|
| 134 | + $limite = $debut + $limite; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $result = sql_select( |
|
| 138 | + 'id_rubrique, id_parent, titre, lang', |
|
| 139 | + 'spip_rubriques', |
|
| 140 | + 'id_parent=' . (int) $collection2, |
|
| 141 | + '', |
|
| 142 | + '0+titre,titre', |
|
| 143 | + $debut == -1 ? '' : "$debut,$limite" |
|
| 144 | + ); |
|
| 145 | + |
|
| 146 | + while ($row = sql_fetch($result)) { |
|
| 147 | + $id_rubrique2 = $row['id_rubrique']; |
|
| 148 | + $titre2 = generer_objet_info( |
|
| 149 | + $id_rubrique2, |
|
| 150 | + 'rubrique', |
|
| 151 | + 'titre' |
|
| 152 | + ); // pour etre sur de passer par tous les traitements |
|
| 153 | + if ('' !== ($rang2 = recuperer_numero($row['titre']))) { |
|
| 154 | + $rang2 = "<span class='rang'>$rang2.</span> "; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + changer_typo($row['lang']); |
|
| 158 | + $lang_dir = lang_dir($row['lang']); |
|
| 159 | + if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
|
| 160 | + $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url( |
|
| 161 | + $id_rubrique2, |
|
| 162 | + 'rubrique' |
|
| 163 | + ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + $retour = $pagination . $retour . $pagination; |
|
| 168 | + |
|
| 169 | + if (!$retour) { |
|
| 170 | + return ''; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return debut_block_depliable($debut > 0, "enfants$collection2") |
|
| 174 | + . "\n<ul class='liste-items sous-sous-rub'>\n" |
|
| 175 | + . $retour |
|
| 176 | + . "</ul>\n" . fin_block() . "\n\n"; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -188,41 +188,41 @@ discard block |
||
| 188 | 188 | * Le contenu textuel affiché, la liste des sous rubriques |
| 189 | 189 | */ |
| 190 | 190 | function afficher_enfant_rub($id_rubrique = 0) { |
| 191 | - $pagination = ''; |
|
| 192 | - $debut = 0; |
|
| 193 | - $limite = 500; |
|
| 194 | - |
|
| 195 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $id_rubrique); |
|
| 196 | - |
|
| 197 | - if ($nb > $limite) { |
|
| 198 | - $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut; |
|
| 199 | - $pagination = chercher_filtre('pagination'); |
|
| 200 | - $pagination = '<br class="nettoyeur"><nav class="pagination">' . |
|
| 201 | - $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 202 | - '</nav>'; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $les_enfants = enfant_rub($id_rubrique, $debut, $limite); |
|
| 206 | - |
|
| 207 | - if (!$n = count($les_enfants)) { |
|
| 208 | - return ''; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if ($n == 1) { |
|
| 212 | - $les_enfants = reset($les_enfants); |
|
| 213 | - $les_enfants2 = ''; |
|
| 214 | - } else { |
|
| 215 | - $n = ceil($n / 2); |
|
| 216 | - $les_enfants2 = implode('', array_slice($les_enfants, $n)); |
|
| 217 | - $les_enfants = implode('', array_slice($les_enfants, 0, $n)); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return $pagination |
|
| 221 | - . "<div class='gauche'>" |
|
| 222 | - . $les_enfants |
|
| 223 | - . '</div>' |
|
| 224 | - . "<div class='droite'>" |
|
| 225 | - . $les_enfants2 |
|
| 226 | - . '</div>' |
|
| 227 | - . $pagination; |
|
| 191 | + $pagination = ''; |
|
| 192 | + $debut = 0; |
|
| 193 | + $limite = 500; |
|
| 194 | + |
|
| 195 | + $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $id_rubrique); |
|
| 196 | + |
|
| 197 | + if ($nb > $limite) { |
|
| 198 | + $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut; |
|
| 199 | + $pagination = chercher_filtre('pagination'); |
|
| 200 | + $pagination = '<br class="nettoyeur"><nav class="pagination">' . |
|
| 201 | + $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 202 | + '</nav>'; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $les_enfants = enfant_rub($id_rubrique, $debut, $limite); |
|
| 206 | + |
|
| 207 | + if (!$n = count($les_enfants)) { |
|
| 208 | + return ''; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if ($n == 1) { |
|
| 212 | + $les_enfants = reset($les_enfants); |
|
| 213 | + $les_enfants2 = ''; |
|
| 214 | + } else { |
|
| 215 | + $n = ceil($n / 2); |
|
| 216 | + $les_enfants2 = implode('', array_slice($les_enfants, $n)); |
|
| 217 | + $les_enfants = implode('', array_slice($les_enfants, 0, $n)); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return $pagination |
|
| 221 | + . "<div class='gauche'>" |
|
| 222 | + . $les_enfants |
|
| 223 | + . '</div>' |
|
| 224 | + . "<div class='droite'>" |
|
| 225 | + . $les_enfants2 |
|
| 226 | + . '</div>' |
|
| 227 | + . $pagination; |
|
| 228 | 228 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | $result = sql_select( |
| 43 | 43 | 'id_rubrique, id_parent, titre, descriptif, lang', |
| 44 | 44 | 'spip_rubriques', |
| 45 | - 'id_parent=' . (int) $collection, |
|
| 45 | + 'id_parent='.(int) $collection, |
|
| 46 | 46 | '', |
| 47 | 47 | '0+titre,titre', |
| 48 | 48 | $debut == -1 ? '' : "$debut,$limite" |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | $lib_bouton = (acces_restreint_rubrique($id_rubrique) |
| 75 | 75 | ? http_img_pack('auteur-0minirezo-16.png', '', " width='16' height='16'", _T('image_administrer_rubrique')) |
| 76 | - : '') . |
|
| 77 | - " <a class='titremlien' dir='$lang_dir'" . |
|
| 78 | - ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 79 | - " href='" . |
|
| 80 | - generer_objet_url($id_rubrique, 'rubrique') . |
|
| 81 | - "'><span class='titre'>" . |
|
| 82 | - $rang . $titre |
|
| 76 | + : ''). |
|
| 77 | + " <a class='titremlien' dir='$lang_dir'". |
|
| 78 | + ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='".$row['lang']."'" : ''). |
|
| 79 | + " href='". |
|
| 80 | + generer_objet_url($id_rubrique, 'rubrique'). |
|
| 81 | + "'><span class='titre'>". |
|
| 82 | + $rang.$titre |
|
| 83 | 83 | . '</span>' |
| 84 | 84 | . (is_string($logo) ? $logo : '') |
| 85 | 85 | . '</a>'; |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | ; |
| 90 | 90 | |
| 91 | 91 | $res[] = |
| 92 | - debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 93 | - $les_sous_enfants . |
|
| 92 | + debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre). |
|
| 93 | + $les_sous_enfants. |
|
| 94 | 94 | fin_cadre_sous_rub(); |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * Le contenu du bloc dépliable |
| 110 | 110 | */ |
| 111 | 111 | function sous_enfant_rub($collection2) { |
| 112 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $collection2); |
|
| 112 | + $nb = sql_countsel('spip_rubriques', 'id_parent='.(int) $collection2); |
|
| 113 | 113 | |
| 114 | 114 | $retour = ''; |
| 115 | 115 | $pagination = ''; |
@@ -121,23 +121,23 @@ discard block |
||
| 121 | 121 | * Si > 500 on affiche une pagination |
| 122 | 122 | */ |
| 123 | 123 | if ($nb > $limite) { |
| 124 | - $debut = _request('debut_rubrique' . $collection2) ?: $debut; |
|
| 124 | + $debut = _request('debut_rubrique'.$collection2) ?: $debut; |
|
| 125 | 125 | $pagination = chercher_filtre('pagination'); |
| 126 | - $pagination = '<nav class="pagination">' . $pagination( |
|
| 126 | + $pagination = '<nav class="pagination">'.$pagination( |
|
| 127 | 127 | $nb, |
| 128 | - '_rubrique' . $collection2, |
|
| 128 | + '_rubrique'.$collection2, |
|
| 129 | 129 | $debut, |
| 130 | 130 | $limite, |
| 131 | 131 | true, |
| 132 | 132 | 'prive' |
| 133 | - ) . '</nav>'; |
|
| 133 | + ).'</nav>'; |
|
| 134 | 134 | $limite = $debut + $limite; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | $result = sql_select( |
| 138 | 138 | 'id_rubrique, id_parent, titre, lang', |
| 139 | 139 | 'spip_rubriques', |
| 140 | - 'id_parent=' . (int) $collection2, |
|
| 140 | + 'id_parent='.(int) $collection2, |
|
| 141 | 141 | '', |
| 142 | 142 | '0+titre,titre', |
| 143 | 143 | $debut == -1 ? '' : "$debut,$limite" |
@@ -157,14 +157,14 @@ discard block |
||
| 157 | 157 | changer_typo($row['lang']); |
| 158 | 158 | $lang_dir = lang_dir($row['lang']); |
| 159 | 159 | if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
| 160 | - $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_objet_url( |
|
| 160 | + $retour .= "\n<li class='item' dir='$lang_dir'><a href='".generer_objet_url( |
|
| 161 | 161 | $id_rubrique2, |
| 162 | 162 | 'rubrique' |
| 163 | - ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 163 | + )."'>".$rang2.$titre2."</a></li>\n"; |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - $retour = $pagination . $retour . $pagination; |
|
| 167 | + $retour = $pagination.$retour.$pagination; |
|
| 168 | 168 | |
| 169 | 169 | if (!$retour) { |
| 170 | 170 | return ''; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | return debut_block_depliable($debut > 0, "enfants$collection2") |
| 174 | 174 | . "\n<ul class='liste-items sous-sous-rub'>\n" |
| 175 | 175 | . $retour |
| 176 | - . "</ul>\n" . fin_block() . "\n\n"; |
|
| 176 | + . "</ul>\n".fin_block()."\n\n"; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -192,13 +192,13 @@ discard block |
||
| 192 | 192 | $debut = 0; |
| 193 | 193 | $limite = 500; |
| 194 | 194 | |
| 195 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . (int) $id_rubrique); |
|
| 195 | + $nb = sql_countsel('spip_rubriques', 'id_parent='.(int) $id_rubrique); |
|
| 196 | 196 | |
| 197 | 197 | if ($nb > $limite) { |
| 198 | - $debut = _request('debut_rubrique' . $id_rubrique) ?: $debut; |
|
| 198 | + $debut = _request('debut_rubrique'.$id_rubrique) ?: $debut; |
|
| 199 | 199 | $pagination = chercher_filtre('pagination'); |
| 200 | - $pagination = '<br class="nettoyeur"><nav class="pagination">' . |
|
| 201 | - $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 200 | + $pagination = '<br class="nettoyeur"><nav class="pagination">'. |
|
| 201 | + $pagination($nb, '_rubrique'.$id_rubrique, $debut, $limite, true, 'prive'). |
|
| 202 | 202 | '</nav>'; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -10,10 +10,10 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | if (!defined('_AUTO_SELECTION_RUBRIQUE')) { |
| 16 | - define('_AUTO_SELECTION_RUBRIQUE', false); |
|
| 16 | + define('_AUTO_SELECTION_RUBRIQUE', false); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | |
@@ -27,39 +27,39 @@ discard block |
||
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | 29 | function inc_preselectionner_parent_nouvel_objet_dist($objet, $row) { |
| 30 | - if (!_AUTO_SELECTION_RUBRIQUE) { |
|
| 31 | - return ''; |
|
| 32 | - } |
|
| 30 | + if (!_AUTO_SELECTION_RUBRIQUE) { |
|
| 31 | + return ''; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - if (!isset($row['id_rubrique'])) { |
|
| 35 | - return ''; |
|
| 36 | - } |
|
| 34 | + if (!isset($row['id_rubrique'])) { |
|
| 35 | + return ''; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $id_rubrique = ''; |
|
| 39 | - if ($GLOBALS['connect_id_rubrique']) { |
|
| 40 | - // si admin restreint : sa rubrique |
|
| 41 | - $id_rubrique = $GLOBALS['connect_id_rubrique'][0]; |
|
| 42 | - } elseif ( |
|
| 43 | - is_int(_AUTO_SELECTION_RUBRIQUE) |
|
| 44 | - && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE) |
|
| 45 | - ) { |
|
| 46 | - $id_rubrique = _AUTO_SELECTION_RUBRIQUE; |
|
| 47 | - } else { |
|
| 48 | - // sinon la derniere rubrique cree |
|
| 49 | - $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', '0,1'); |
|
| 50 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 51 | - } |
|
| 52 | - // si le choix ne convient pas, on cherche dans un secteur |
|
| 53 | - if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) { |
|
| 54 | - $id_rubrique = ''; |
|
| 55 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 56 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 57 | - while (!$id_rubrique && ($row_rub = sql_fetch($res))) { |
|
| 58 | - if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 59 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 38 | + $id_rubrique = ''; |
|
| 39 | + if ($GLOBALS['connect_id_rubrique']) { |
|
| 40 | + // si admin restreint : sa rubrique |
|
| 41 | + $id_rubrique = $GLOBALS['connect_id_rubrique'][0]; |
|
| 42 | + } elseif ( |
|
| 43 | + is_int(_AUTO_SELECTION_RUBRIQUE) |
|
| 44 | + && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE) |
|
| 45 | + ) { |
|
| 46 | + $id_rubrique = _AUTO_SELECTION_RUBRIQUE; |
|
| 47 | + } else { |
|
| 48 | + // sinon la derniere rubrique cree |
|
| 49 | + $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', '0,1'); |
|
| 50 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 51 | + } |
|
| 52 | + // si le choix ne convient pas, on cherche dans un secteur |
|
| 53 | + if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) { |
|
| 54 | + $id_rubrique = ''; |
|
| 55 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 56 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 57 | + while (!$id_rubrique && ($row_rub = sql_fetch($res))) { |
|
| 58 | + if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 59 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return $id_rubrique; |
|
| 64 | + return $id_rubrique; |
|
| 65 | 65 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $id_rubrique = $GLOBALS['connect_id_rubrique'][0]; |
| 42 | 42 | } elseif ( |
| 43 | 43 | is_int(_AUTO_SELECTION_RUBRIQUE) |
| 44 | - && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE) |
|
| 44 | + && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique='.(int) _AUTO_SELECTION_RUBRIQUE) |
|
| 45 | 45 | ) { |
| 46 | 46 | $id_rubrique = _AUTO_SELECTION_RUBRIQUE; |
| 47 | 47 | } else { |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | $id_rubrique = $row_rub['id_rubrique']; |
| 51 | 51 | } |
| 52 | 52 | // si le choix ne convient pas, on cherche dans un secteur |
| 53 | - if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) { |
|
| 53 | + if (!autoriser('creer'.$objet.'dans', 'rubrique', $id_rubrique)) { |
|
| 54 | 54 | $id_rubrique = ''; |
| 55 | 55 | // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
| 56 | 56 | $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
| 57 | 57 | while (!$id_rubrique && ($row_rub = sql_fetch($res))) { |
| 58 | - if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 58 | + if (autoriser('creer'.$objet.'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 59 | 59 | $id_rubrique = $row_rub['id_rubrique']; |
| 60 | 60 | } |
| 61 | 61 | } |