@@ -553,16 +553,14 @@ |
||
| 553 | 553 | if (stripos($suite, 'SELECT') !== false) { |
| 554 | 554 | if ($echappe_textes) { |
| 555 | 555 | [$suite_echap, $textes] = query_echappe_textes($suite); |
| 556 | - } |
|
| 557 | - else { |
|
| 556 | + } else { |
|
| 558 | 557 | $suite_echap = $suite; |
| 559 | 558 | } |
| 560 | 559 | if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
| 561 | 560 | $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
| 562 | 561 | if ($echappe_textes) { |
| 563 | 562 | $suite = query_reinjecte_textes($suite_echap, $textes); |
| 564 | - } |
|
| 565 | - else { |
|
| 563 | + } else { |
|
| 566 | 564 | $suite = $suite_echap; |
| 567 | 565 | } |
| 568 | 566 | } |
@@ -58,12 +58,12 @@ discard block |
||
| 58 | 58 | $link = @mysqli_connect($host, $login, $pass); |
| 59 | 59 | } |
| 60 | 60 | } catch (\mysqli_sql_exception $e) { |
| 61 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 61 | + spip_log('mysqli_sql_exception: '.$e->getMessage(), 'mysql.'._LOG_DEBUG); |
|
| 62 | 62 | $link = false; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | if (!$link) { |
| 66 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 66 | + spip_log('Echec mysqli_connect. Erreur : '.mysqli_connect_error(), 'mysql.'._LOG_HS); |
|
| 67 | 67 | |
| 68 | 68 | return false; |
| 69 | 69 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | spip_log( |
| 85 | - "Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? 'operationnelle' : 'impossible'), |
|
| 85 | + "Connexion MySQLi vers $host, base $db, prefixe $prefixe ".($ok ? 'operationnelle' : 'impossible'), |
|
| 86 | 86 | _LOG_DEBUG |
| 87 | 87 | ); |
| 88 | 88 | |
@@ -173,9 +173,9 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 175 | 175 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 176 | - spip_log('changement de charset sql : ' . 'SET NAMES ' . _q($charset), _LOG_DEBUG); |
|
| 176 | + spip_log('changement de charset sql : '.'SET NAMES '._q($charset), _LOG_DEBUG); |
|
| 177 | 177 | |
| 178 | - return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES ' . _q($charset)); |
|
| 178 | + return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES '._q($charset)); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | function spip_mysql_get_charset($charset = [], $serveur = '', $requeter = true) { |
| 191 | 191 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 192 | 192 | $connexion['last'] = $c = 'SHOW CHARACTER SET' |
| 193 | - . (!$charset ? '' : (' LIKE ' . _q($charset['charset']))); |
|
| 193 | + . (!$charset ? '' : (' LIKE '._q($charset['charset']))); |
|
| 194 | 194 | |
| 195 | 195 | return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
| 196 | 196 | } |
@@ -234,21 +234,21 @@ discard block |
||
| 234 | 234 | $debug = ''; |
| 235 | 235 | if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
| 236 | 236 | if (isset($GLOBALS['debug']['aucasou'])) { |
| 237 | - [, $id, , $infos] = $GLOBALS['debug']['aucasou']; |
|
| 238 | - $debug .= "BOUCLE$id @ " . ($infos[0] ?? '') . ' | '; |
|
| 237 | + [, $id,, $infos] = $GLOBALS['debug']['aucasou']; |
|
| 238 | + $debug .= "BOUCLE$id @ ".($infos[0] ?? '').' | '; |
|
| 239 | 239 | } |
| 240 | 240 | if (isset($_SERVER['REQUEST_URI'])) { |
| 241 | 241 | $debug .= $_SERVER['REQUEST_URI']; |
| 242 | 242 | } |
| 243 | 243 | if (!empty($GLOBALS['ip'])) { |
| 244 | - $debug .= ' + ' . $GLOBALS['ip']; |
|
| 244 | + $debug .= ' + '.$GLOBALS['ip']; |
|
| 245 | 245 | } |
| 246 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 246 | + $debug = ' /* '.mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)).' */'; |
|
| 247 | 247 | } |
| 248 | 248 | try { |
| 249 | - $r = mysqli_query($link, $query . $debug); |
|
| 249 | + $r = mysqli_query($link, $query.$debug); |
|
| 250 | 250 | } catch (\mysqli_sql_exception $e) { |
| 251 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 251 | + spip_log('mysqli_sql_exception: '.$e->getMessage(), 'mysql.'._LOG_DEBUG); |
|
| 252 | 252 | $r = false; |
| 253 | 253 | // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
| 254 | 254 | // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
@@ -266,9 +266,9 @@ discard block |
||
| 266 | 266 | $link = $connexion['link']; |
| 267 | 267 | //On retente au cas où |
| 268 | 268 | try { |
| 269 | - $r = mysqli_query($link, $query . $debug); |
|
| 269 | + $r = mysqli_query($link, $query.$debug); |
|
| 270 | 270 | } catch (\mysqli_sql_exception $e) { |
| 271 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 271 | + spip_log('mysqli_sql_exception: '.$e->getMessage(), 'mysql.'._LOG_DEBUG); |
|
| 272 | 272 | $r = false; |
| 273 | 273 | // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
| 274 | 274 | // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | // d'utiliser ceux-ci, copie-colle de phpmyadmin |
| 302 | 302 | $query = preg_replace(',^TABLE\s*`([^`]*)`,i', "TABLE \\1", $query); |
| 303 | 303 | |
| 304 | - return spip_mysql_query('ALTER ' . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 304 | + return spip_mysql_query('ALTER '.$query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * @return bool Toujours true |
| 315 | 315 | */ |
| 316 | 316 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 317 | - spip_mysql_query('OPTIMIZE TABLE ' . $table); |
|
| 317 | + spip_mysql_query('OPTIMIZE TABLE '.$table); |
|
| 318 | 318 | |
| 319 | 319 | return true; |
| 320 | 320 | } |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | $link = $connexion['link']; |
| 338 | 338 | $db = $connexion['db']; |
| 339 | 339 | |
| 340 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 340 | + $query = 'EXPLAIN '._mysql_traite_query($query, $db, $prefixe); |
|
| 341 | 341 | $r = mysqli_query($link, $query); |
| 342 | 342 | |
| 343 | 343 | return spip_mysql_fetch($r, null, $serveur); |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | . calculer_mysql_expression('WHERE', $where) |
| 389 | 389 | . calculer_mysql_expression('GROUP BY', $groupby, ',') |
| 390 | 390 | . calculer_mysql_expression('HAVING', $having) |
| 391 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 391 | + . ($orderby ? ("\nORDER BY ".spip_mysql_order($orderby)) : '') |
|
| 392 | 392 | . ($limit ? "\nLIMIT $limit" : ''); |
| 393 | 393 | |
| 394 | 394 | // renvoyer la requete inerte si demandee |
@@ -478,12 +478,12 @@ discard block |
||
| 478 | 478 | $exp = "\n$expression "; |
| 479 | 479 | |
| 480 | 480 | if (!is_array($v)) { |
| 481 | - return $exp . $v; |
|
| 481 | + return $exp.$v; |
|
| 482 | 482 | } else { |
| 483 | 483 | if (strtoupper($join) === 'AND') { |
| 484 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 484 | + return $exp.join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 485 | 485 | } else { |
| 486 | - return $exp . join($join, $v); |
|
| 486 | + return $exp.join($join, $v); |
|
| 487 | 487 | } |
| 488 | 488 | } |
| 489 | 489 | } |
@@ -501,17 +501,17 @@ discard block |
||
| 501 | 501 | if (substr($k, -1) == '@') { |
| 502 | 502 | // c'est une jointure qui se refere au from precedent |
| 503 | 503 | // pas de virgule |
| 504 | - $res .= ' ' . $v; |
|
| 504 | + $res .= ' '.$v; |
|
| 505 | 505 | } else { |
| 506 | 506 | if (!is_numeric($k)) { |
| 507 | 507 | $p = strpos($v, ' '); |
| 508 | 508 | if ($p) { |
| 509 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 509 | + $v = substr($v, 0, $p)." AS `$k`".substr($v, $p); |
|
| 510 | 510 | } else { |
| 511 | 511 | $v .= " AS `$k`"; |
| 512 | 512 | } |
| 513 | 513 | } |
| 514 | - $res .= ', ' . $v; |
|
| 514 | + $res .= ', '.$v; |
|
| 515 | 515 | } |
| 516 | 516 | } |
| 517 | 517 | |
@@ -541,13 +541,13 @@ discard block |
||
| 541 | 541 | function _mysql_traite_query($query, $db = '', $prefixe = '', $echappe_textes = true) { |
| 542 | 542 | |
| 543 | 543 | if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
| 544 | - $pref = '`' . $db . '`.'; |
|
| 544 | + $pref = '`'.$db.'`.'; |
|
| 545 | 545 | } else { |
| 546 | 546 | $pref = ''; |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | if ($prefixe) { |
| 550 | - $pref .= $prefixe . '_'; |
|
| 550 | + $pref .= $prefixe.'_'; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | $suite_echap = $suite; |
| 567 | 567 | } |
| 568 | 568 | if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
| 569 | - $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 569 | + $suite_echap = $r[1]._mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 570 | 570 | if ($echappe_textes) { |
| 571 | 571 | $suite = query_reinjecte_textes($suite_echap, $textes); |
| 572 | 572 | } |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | } |
| 577 | 577 | } |
| 578 | 578 | } |
| 579 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 579 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1'.$pref, $query).$suite; |
|
| 580 | 580 | |
| 581 | 581 | // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
| 582 | 582 | // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | $ok = false; |
| 617 | 617 | } |
| 618 | 618 | if (!$ok) { |
| 619 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 619 | + spip_log('Echec mysqli_selectdb. Erreur : '.mysqli_error($link), 'mysql.'._LOG_CRITIQUE); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | return $ok; |
@@ -706,10 +706,10 @@ discard block |
||
| 706 | 706 | |
| 707 | 707 | $character_set = ''; |
| 708 | 708 | if (@$GLOBALS['meta']['charset_sql_base']) { |
| 709 | - $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 709 | + $character_set .= ' CHARACTER SET '.$GLOBALS['meta']['charset_sql_base']; |
|
| 710 | 710 | } |
| 711 | 711 | if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
| 712 | - $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 712 | + $character_set .= ' COLLATE '.$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | foreach ($champs as $k => $v) { |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | preg_match(',(char|text),i', $defs[1]) |
| 720 | 720 | and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
| 721 | 721 | ) { |
| 722 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 722 | + $v = $defs[1].$character_set.' '.substr($v, strlen($defs[1])); |
|
| 723 | 723 | } |
| 724 | 724 | } |
| 725 | 725 | |
@@ -731,8 +731,8 @@ discard block |
||
| 731 | 731 | $s = ','; |
| 732 | 732 | } |
| 733 | 733 | $temporary = $temporary ? 'TEMPORARY' : ''; |
| 734 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 735 | - . (defined('_MYSQL_ENGINE') ? ' ENGINE=' . _MYSQL_ENGINE : '') |
|
| 734 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query".($keys ? ",$keys" : '').')' |
|
| 735 | + . (defined('_MYSQL_ENGINE') ? ' ENGINE='._MYSQL_ENGINE : '') |
|
| 736 | 736 | . ($character_set ? " DEFAULT $character_set" : '') |
| 737 | 737 | . "\n"; |
| 738 | 738 | |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | return false; |
| 812 | 812 | } |
| 813 | 813 | |
| 814 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 814 | + $query = "CREATE VIEW $nom AS ".$query_select; |
|
| 815 | 815 | |
| 816 | 816 | return spip_mysql_query($query, $serveur, $requeter); |
| 817 | 817 | } |
@@ -869,7 +869,7 @@ discard block |
||
| 869 | 869 | * Ressource à utiliser avec sql_fetch() |
| 870 | 870 | **/ |
| 871 | 871 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 872 | - return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 872 | + return spip_mysql_query('SHOW TABLES LIKE '._q($match), $serveur, $requeter); |
|
| 873 | 873 | } |
| 874 | 874 | |
| 875 | 875 | /** |
@@ -885,7 +885,7 @@ discard block |
||
| 885 | 885 | * - true si la requête a réussie, false sinon |
| 886 | 886 | */ |
| 887 | 887 | function spip_mysql_repair($table, $serveur = '', $requeter = true) { |
| 888 | - $table_status = spip_mysql_fetch(spip_mysql_query('SHOW TABLE STATUS WHERE Name = ' . _q($table), $serveur, true)); |
|
| 888 | + $table_status = spip_mysql_fetch(spip_mysql_query('SHOW TABLE STATUS WHERE Name = '._q($table), $serveur, true)); |
|
| 889 | 889 | $engine = $table_status['Engine']; |
| 890 | 890 | if ($engine == 'InnoDB') { |
| 891 | 891 | if (spip_mysql_alter("TABLE $table ENGINE = InnoDB", $serveur, $requeter)) { |
@@ -894,7 +894,7 @@ discard block |
||
| 894 | 894 | } elseif ($engine == 'MyISAM') { |
| 895 | 895 | return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
| 896 | 896 | } else { |
| 897 | - spip_log("spip_mysql_repair impossible pour la table $table engine $engine", 'mysql.' . _LOG_DEBUG); |
|
| 897 | + spip_log("spip_mysql_repair impossible pour la table $table engine $engine", 'mysql.'._LOG_DEBUG); |
|
| 898 | 898 | } |
| 899 | 899 | return false; |
| 900 | 900 | } |
@@ -914,7 +914,7 @@ discard block |
||
| 914 | 914 | * - string : requete sql, si $requeter = true |
| 915 | 915 | **/ |
| 916 | 916 | function spip_mysql_table_exists(string $table, $serveur = '', $requeter = true) { |
| 917 | - $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 917 | + $r = spip_mysql_query('SHOW TABLES LIKE '._q($table), $serveur, $requeter); |
|
| 918 | 918 | if (!$requeter) { |
| 919 | 919 | return $r; |
| 920 | 920 | } |
@@ -996,22 +996,22 @@ discard block |
||
| 996 | 996 | } |
| 997 | 997 | if ($val['Default'] === '0' || $val['Default']) { |
| 998 | 998 | if (preg_match('/[A-Z_]/', $val['Default'])) { |
| 999 | - $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 999 | + $nfields[$val['Field']] .= ' DEFAULT '.$val['Default']; |
|
| 1000 | 1000 | } else { |
| 1001 | - $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 1001 | + $nfields[$val['Field']] .= " DEFAULT '".$val['Default']."'"; |
|
| 1002 | 1002 | } |
| 1003 | 1003 | } |
| 1004 | 1004 | if ($val['Extra']) { |
| 1005 | - $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 1005 | + $nfields[$val['Field']] .= ' '.$val['Extra']; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | if ($val['Key'] == 'PRI') { |
| 1008 | 1008 | $nkeys['PRIMARY KEY'] = $val['Field']; |
| 1009 | 1009 | } else { |
| 1010 | 1010 | if ($val['Key'] == 'MUL') { |
| 1011 | - $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 1011 | + $nkeys['KEY '.$val['Field']] = $val['Field']; |
|
| 1012 | 1012 | } else { |
| 1013 | 1013 | if ($val['Key'] == 'UNI') { |
| 1014 | - $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 1014 | + $nkeys['UNIQUE KEY '.$val['Field']] = $val['Field']; |
|
| 1015 | 1015 | } |
| 1016 | 1016 | } |
| 1017 | 1017 | } |
@@ -1087,7 +1087,7 @@ discard block |
||
| 1087 | 1087 | $serveur = '', |
| 1088 | 1088 | $requeter = true |
| 1089 | 1089 | ) { |
| 1090 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1090 | + $c = !$groupby ? '*' : ('DISTINCT '.(is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1091 | 1091 | |
| 1092 | 1092 | $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
| 1093 | 1093 | if (!$requeter) { |
@@ -1127,7 +1127,7 @@ discard block |
||
| 1127 | 1127 | if ($s) { |
| 1128 | 1128 | $trace = debug_backtrace(); |
| 1129 | 1129 | if ($trace[0]['function'] != 'spip_mysql_error') { |
| 1130 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1130 | + spip_log("$s - $query - ".sql_error_backtrace(), 'mysql.'._LOG_ERREUR); |
|
| 1131 | 1131 | } |
| 1132 | 1132 | } |
| 1133 | 1133 | |
@@ -1257,7 +1257,7 @@ discard block |
||
| 1257 | 1257 | try { |
| 1258 | 1258 | $insert = mysqli_query($link, $query); |
| 1259 | 1259 | } catch (\mysqli_sql_exception $e) { |
| 1260 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 1260 | + spip_log('mysqli_sql_exception: '.$e->getMessage(), 'mysql.'._LOG_DEBUG); |
|
| 1261 | 1261 | // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
| 1262 | 1262 | // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
| 1263 | 1263 | } |
@@ -1312,8 +1312,8 @@ discard block |
||
| 1312 | 1312 | |
| 1313 | 1313 | return spip_mysql_insert( |
| 1314 | 1314 | $table, |
| 1315 | - '(' . join(',', array_keys($couples)) . ')', |
|
| 1316 | - '(' . join(',', $couples) . ')', |
|
| 1315 | + '('.join(',', array_keys($couples)).')', |
|
| 1316 | + '('.join(',', $couples).')', |
|
| 1317 | 1317 | $desc, |
| 1318 | 1318 | $serveur, |
| 1319 | 1319 | $requeter |
@@ -1350,7 +1350,7 @@ discard block |
||
| 1350 | 1350 | } |
| 1351 | 1351 | $fields = $desc['field'] ?? []; |
| 1352 | 1352 | |
| 1353 | - $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1353 | + $cles = '('.join(',', array_keys(reset($tab_couples))).')'; |
|
| 1354 | 1354 | $valeurs = []; |
| 1355 | 1355 | $r = false; |
| 1356 | 1356 | |
@@ -1359,7 +1359,7 @@ discard block |
||
| 1359 | 1359 | foreach ($couples as $champ => $val) { |
| 1360 | 1360 | $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
| 1361 | 1361 | } |
| 1362 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1362 | + $valeurs[] = '('.join(',', $couples).')'; |
|
| 1363 | 1363 | if (count($valeurs) >= 100) { |
| 1364 | 1364 | $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
| 1365 | 1365 | $valeurs = []; |
@@ -1396,7 +1396,7 @@ discard block |
||
| 1396 | 1396 | function spip_mysql_update($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1397 | 1397 | $set = []; |
| 1398 | 1398 | foreach ($champs as $champ => $val) { |
| 1399 | - $set[] = $champ . "=$val"; |
|
| 1399 | + $set[] = $champ."=$val"; |
|
| 1400 | 1400 | } |
| 1401 | 1401 | if (!empty($set)) { |
| 1402 | 1402 | return spip_mysql_query( |
@@ -1453,7 +1453,7 @@ discard block |
||
| 1453 | 1453 | } |
| 1454 | 1454 | $set = []; |
| 1455 | 1455 | foreach ($champs as $champ => $val) { |
| 1456 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1456 | + $set[] = $champ.'='.spip_mysql_cite($val, @$fields[$champ]); |
|
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | 1459 | return spip_mysql_query( |
@@ -1522,10 +1522,10 @@ discard block |
||
| 1522 | 1522 | * - false en cas d'erreur. |
| 1523 | 1523 | **/ |
| 1524 | 1524 | function spip_mysql_replace($table, $couples, $desc = [], $serveur = '', $requeter = true) { |
| 1525 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1525 | + return spip_mysql_query("REPLACE $table (".join(',', array_keys($couples)).') VALUES ('.join( |
|
| 1526 | 1526 | ',', |
| 1527 | 1527 | array_map('_q', $couples) |
| 1528 | - ) . ')', $serveur, $requeter); |
|
| 1528 | + ).')', $serveur, $requeter); |
|
| 1529 | 1529 | } |
| 1530 | 1530 | |
| 1531 | 1531 | |
@@ -1554,10 +1554,10 @@ discard block |
||
| 1554 | 1554 | * - false en cas d'erreur. |
| 1555 | 1555 | **/ |
| 1556 | 1556 | function spip_mysql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $requeter = true) { |
| 1557 | - $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1557 | + $cles = '('.join(',', array_keys($tab_couples[0])).')'; |
|
| 1558 | 1558 | $valeurs = []; |
| 1559 | 1559 | foreach ($tab_couples as $couples) { |
| 1560 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1560 | + $valeurs[] = '('.join(',', array_map('_q', $couples)).')'; |
|
| 1561 | 1561 | } |
| 1562 | 1562 | $valeurs = implode(', ', $valeurs); |
| 1563 | 1563 | |
@@ -1577,28 +1577,28 @@ discard block |
||
| 1577 | 1577 | */ |
| 1578 | 1578 | function spip_mysql_multi($objet, $lang) { |
| 1579 | 1579 | $lengthlang = strlen("[$lang]"); |
| 1580 | - $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1581 | - $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1582 | - $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1583 | - $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1584 | - $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1585 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1580 | + $posmulti = 'INSTR('.$objet.", '<multi>')"; |
|
| 1581 | + $posfinmulti = 'INSTR('.$objet.", '</multi>')"; |
|
| 1582 | + $debutchaine = 'LEFT('.$objet.", $posmulti-1)"; |
|
| 1583 | + $finchaine = 'RIGHT('.$objet.', CHAR_LENGTH('.$objet.") -(7+$posfinmulti))"; |
|
| 1584 | + $chainemulti = 'TRIM(SUBSTRING('.$objet.", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1585 | + $poslang = "INSTR($chainemulti,'[".$lang."]')"; |
|
| 1586 | 1586 | $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
| 1587 | - $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1588 | - $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1587 | + $chainelang = 'TRIM(SUBSTRING('.$objet.", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1588 | + $posfinlang = 'INSTR('.$chainelang.", '[')"; |
|
| 1589 | 1589 | $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
| 1590 | 1590 | //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
| 1591 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1592 | - ' TRIM(' . $objet . '), ' . |
|
| 1593 | - ' CONCAT( ' . |
|
| 1594 | - " $debutchaine, " . |
|
| 1595 | - ' IF( ' . |
|
| 1596 | - " $poslang = 0, " . |
|
| 1597 | - " $chainemulti, " . |
|
| 1598 | - " $chainelang" . |
|
| 1599 | - ' ), ' . |
|
| 1600 | - " $finchaine" . |
|
| 1601 | - ' ) ' . |
|
| 1591 | + $retour = "(TRIM(IF($posmulti = 0 , ". |
|
| 1592 | + ' TRIM('.$objet.'), '. |
|
| 1593 | + ' CONCAT( '. |
|
| 1594 | + " $debutchaine, ". |
|
| 1595 | + ' IF( '. |
|
| 1596 | + " $poslang = 0, ". |
|
| 1597 | + " $chainemulti, ". |
|
| 1598 | + " $chainelang". |
|
| 1599 | + ' ), '. |
|
| 1600 | + " $finchaine". |
|
| 1601 | + ' ) '. |
|
| 1602 | 1602 | '))) AS multi'; |
| 1603 | 1603 | |
| 1604 | 1604 | return $retour; |
@@ -1615,7 +1615,7 @@ discard block |
||
| 1615 | 1615 | * Valeur hexadécimale pour MySQL |
| 1616 | 1616 | **/ |
| 1617 | 1617 | function spip_mysql_hex($v) { |
| 1618 | - return '0x' . $v; |
|
| 1618 | + return '0x'.$v; |
|
| 1619 | 1619 | } |
| 1620 | 1620 | |
| 1621 | 1621 | /** |
@@ -1655,7 +1655,7 @@ discard block |
||
| 1655 | 1655 | * Expression SQL |
| 1656 | 1656 | **/ |
| 1657 | 1657 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1658 | - $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1658 | + $use_now = (($champ === 'maj' or strpos($champ, '.maj')) ? true : false); |
|
| 1659 | 1659 | return '(' |
| 1660 | 1660 | . $champ |
| 1661 | 1661 | . (($interval <= 0) ? '>' : '<') |
@@ -1710,7 +1710,7 @@ discard block |
||
| 1710 | 1710 | } elseif ($v === null) { |
| 1711 | 1711 | return "''"; |
| 1712 | 1712 | } |
| 1713 | - return "'" . addslashes($v) . "'"; |
|
| 1713 | + return "'".addslashes($v)."'"; |
|
| 1714 | 1714 | } |
| 1715 | 1715 | |
| 1716 | 1716 | if ($v === null) { |
@@ -1734,7 +1734,7 @@ discard block |
||
| 1734 | 1734 | } |
| 1735 | 1735 | } |
| 1736 | 1736 | |
| 1737 | - return ("'" . addslashes($v) . "'"); |
|
| 1737 | + return ("'".addslashes($v)."'"); |
|
| 1738 | 1738 | } |
| 1739 | 1739 | |
| 1740 | 1740 | /** |
@@ -1768,7 +1768,7 @@ discard block |
||
| 1768 | 1768 | } else { |
| 1769 | 1769 | $GLOBALS['mysql_rappel_nom_base'] = false; |
| 1770 | 1770 | |
| 1771 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1771 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; ". |
|
| 1772 | 1772 | "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
| 1773 | 1773 | } |
| 1774 | 1774 | } |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if (!defined('_MYSQL_NOPLANES')) { |
| 26 | - define('_MYSQL_NOPLANES', true); |
|
| 26 | + define('_MYSQL_NOPLANES', true); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -40,112 +40,112 @@ discard block |
||
| 40 | 40 | * - tableau décrivant la connexion sinon |
| 41 | 41 | */ |
| 42 | 42 | function req_mysql_dist($host, $port, $login, #[\SensitiveParameter] $pass, $db = '', $prefixe = '') { |
| 43 | - if (!extension_loaded(\mysqli::class)) { |
|
| 44 | - return false; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 48 | - try { |
|
| 49 | - if ( |
|
| 50 | - $port and !is_numeric($socket = $port) |
|
| 51 | - and (!$host or $host === 'localhost') |
|
| 52 | - ) { |
|
| 53 | - $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 54 | - } elseif ($port) { |
|
| 55 | - $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 56 | - } else { |
|
| 57 | - $link = @mysqli_connect($host, $login, $pass); |
|
| 58 | - } |
|
| 59 | - } catch (\mysqli_sql_exception $e) { |
|
| 60 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 61 | - $link = false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - if (!$link) { |
|
| 65 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 66 | - |
|
| 67 | - return false; |
|
| 68 | - } |
|
| 69 | - $last = ''; |
|
| 70 | - if (!$db) { |
|
| 71 | - $ok = $link; |
|
| 72 | - $db = 'spip'; |
|
| 73 | - } else { |
|
| 74 | - $ok = mysqli_select_db($link, $db); |
|
| 75 | - if ( |
|
| 76 | - defined('_MYSQL_SET_SQL_MODE') |
|
| 77 | - or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 78 | - ) { |
|
| 79 | - mysqli_query($link, $last = "set sql_mode=''"); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - spip_log( |
|
| 84 | - "Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? 'operationnelle' : 'impossible'), |
|
| 85 | - _LOG_DEBUG |
|
| 86 | - ); |
|
| 87 | - |
|
| 88 | - return !$ok ? false : [ |
|
| 89 | - 'db' => $db, |
|
| 90 | - 'last' => $last, |
|
| 91 | - 'prefixe' => $prefixe ?: $db, |
|
| 92 | - 'link' => $link, |
|
| 93 | - 'total_requetes' => 0, |
|
| 94 | - ]; |
|
| 43 | + if (!extension_loaded(\mysqli::class)) { |
|
| 44 | + return false; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 48 | + try { |
|
| 49 | + if ( |
|
| 50 | + $port and !is_numeric($socket = $port) |
|
| 51 | + and (!$host or $host === 'localhost') |
|
| 52 | + ) { |
|
| 53 | + $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 54 | + } elseif ($port) { |
|
| 55 | + $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 56 | + } else { |
|
| 57 | + $link = @mysqli_connect($host, $login, $pass); |
|
| 58 | + } |
|
| 59 | + } catch (\mysqli_sql_exception $e) { |
|
| 60 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 61 | + $link = false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + if (!$link) { |
|
| 65 | + spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 66 | + |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 69 | + $last = ''; |
|
| 70 | + if (!$db) { |
|
| 71 | + $ok = $link; |
|
| 72 | + $db = 'spip'; |
|
| 73 | + } else { |
|
| 74 | + $ok = mysqli_select_db($link, $db); |
|
| 75 | + if ( |
|
| 76 | + defined('_MYSQL_SET_SQL_MODE') |
|
| 77 | + or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 78 | + ) { |
|
| 79 | + mysqli_query($link, $last = "set sql_mode=''"); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + spip_log( |
|
| 84 | + "Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? 'operationnelle' : 'impossible'), |
|
| 85 | + _LOG_DEBUG |
|
| 86 | + ); |
|
| 87 | + |
|
| 88 | + return !$ok ? false : [ |
|
| 89 | + 'db' => $db, |
|
| 90 | + 'last' => $last, |
|
| 91 | + 'prefixe' => $prefixe ?: $db, |
|
| 92 | + 'link' => $link, |
|
| 93 | + 'total_requetes' => 0, |
|
| 94 | + ]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
| 98 | 98 | $GLOBALS['spip_mysql_functions_1'] = [ |
| 99 | - 'alter' => 'spip_mysql_alter', |
|
| 100 | - 'count' => 'spip_mysql_count', |
|
| 101 | - 'countsel' => 'spip_mysql_countsel', |
|
| 102 | - 'create' => 'spip_mysql_create', |
|
| 103 | - 'create_base' => 'spip_mysql_create_base', |
|
| 104 | - 'create_view' => 'spip_mysql_create_view', |
|
| 105 | - 'date_proche' => 'spip_mysql_date_proche', |
|
| 106 | - 'delete' => 'spip_mysql_delete', |
|
| 107 | - 'drop_table' => 'spip_mysql_drop_table', |
|
| 108 | - 'drop_view' => 'spip_mysql_drop_view', |
|
| 109 | - 'errno' => 'spip_mysql_errno', |
|
| 110 | - 'error' => 'spip_mysql_error', |
|
| 111 | - 'explain' => 'spip_mysql_explain', |
|
| 112 | - 'fetch' => 'spip_mysql_fetch', |
|
| 113 | - 'seek' => 'spip_mysql_seek', |
|
| 114 | - 'free' => 'spip_mysql_free', |
|
| 115 | - 'hex' => 'spip_mysql_hex', |
|
| 116 | - 'in' => 'spip_mysql_in', |
|
| 117 | - 'insert' => 'spip_mysql_insert', |
|
| 118 | - 'insertq' => 'spip_mysql_insertq', |
|
| 119 | - 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 120 | - 'listdbs' => 'spip_mysql_listdbs', |
|
| 121 | - 'multi' => 'spip_mysql_multi', |
|
| 122 | - 'optimize' => 'spip_mysql_optimize', |
|
| 123 | - 'query' => 'spip_mysql_query', |
|
| 124 | - 'quote' => 'spip_mysql_quote', |
|
| 125 | - 'replace' => 'spip_mysql_replace', |
|
| 126 | - 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 127 | - 'repair' => 'spip_mysql_repair', |
|
| 128 | - 'select' => 'spip_mysql_select', |
|
| 129 | - 'selectdb' => 'spip_mysql_selectdb', |
|
| 130 | - 'set_charset' => 'spip_mysql_set_charset', |
|
| 131 | - 'get_charset' => 'spip_mysql_get_charset', |
|
| 132 | - 'showbase' => 'spip_mysql_showbase', |
|
| 133 | - 'showtable' => 'spip_mysql_showtable', |
|
| 134 | - 'table_exists' => 'spip_mysql_table_exists', |
|
| 135 | - 'update' => 'spip_mysql_update', |
|
| 136 | - 'updateq' => 'spip_mysql_updateq', |
|
| 137 | - |
|
| 138 | - // association de chaque nom http d'un charset aux couples MySQL |
|
| 139 | - 'charsets' => [ |
|
| 140 | - 'cp1250' => ['charset' => 'cp1250', 'collation' => 'cp1250_general_ci'], |
|
| 141 | - 'cp1251' => ['charset' => 'cp1251', 'collation' => 'cp1251_general_ci'], |
|
| 142 | - 'cp1256' => ['charset' => 'cp1256', 'collation' => 'cp1256_general_ci'], |
|
| 143 | - 'iso-8859-1' => ['charset' => 'latin1', 'collation' => 'latin1_swedish_ci'], |
|
| 99 | + 'alter' => 'spip_mysql_alter', |
|
| 100 | + 'count' => 'spip_mysql_count', |
|
| 101 | + 'countsel' => 'spip_mysql_countsel', |
|
| 102 | + 'create' => 'spip_mysql_create', |
|
| 103 | + 'create_base' => 'spip_mysql_create_base', |
|
| 104 | + 'create_view' => 'spip_mysql_create_view', |
|
| 105 | + 'date_proche' => 'spip_mysql_date_proche', |
|
| 106 | + 'delete' => 'spip_mysql_delete', |
|
| 107 | + 'drop_table' => 'spip_mysql_drop_table', |
|
| 108 | + 'drop_view' => 'spip_mysql_drop_view', |
|
| 109 | + 'errno' => 'spip_mysql_errno', |
|
| 110 | + 'error' => 'spip_mysql_error', |
|
| 111 | + 'explain' => 'spip_mysql_explain', |
|
| 112 | + 'fetch' => 'spip_mysql_fetch', |
|
| 113 | + 'seek' => 'spip_mysql_seek', |
|
| 114 | + 'free' => 'spip_mysql_free', |
|
| 115 | + 'hex' => 'spip_mysql_hex', |
|
| 116 | + 'in' => 'spip_mysql_in', |
|
| 117 | + 'insert' => 'spip_mysql_insert', |
|
| 118 | + 'insertq' => 'spip_mysql_insertq', |
|
| 119 | + 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 120 | + 'listdbs' => 'spip_mysql_listdbs', |
|
| 121 | + 'multi' => 'spip_mysql_multi', |
|
| 122 | + 'optimize' => 'spip_mysql_optimize', |
|
| 123 | + 'query' => 'spip_mysql_query', |
|
| 124 | + 'quote' => 'spip_mysql_quote', |
|
| 125 | + 'replace' => 'spip_mysql_replace', |
|
| 126 | + 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 127 | + 'repair' => 'spip_mysql_repair', |
|
| 128 | + 'select' => 'spip_mysql_select', |
|
| 129 | + 'selectdb' => 'spip_mysql_selectdb', |
|
| 130 | + 'set_charset' => 'spip_mysql_set_charset', |
|
| 131 | + 'get_charset' => 'spip_mysql_get_charset', |
|
| 132 | + 'showbase' => 'spip_mysql_showbase', |
|
| 133 | + 'showtable' => 'spip_mysql_showtable', |
|
| 134 | + 'table_exists' => 'spip_mysql_table_exists', |
|
| 135 | + 'update' => 'spip_mysql_update', |
|
| 136 | + 'updateq' => 'spip_mysql_updateq', |
|
| 137 | + |
|
| 138 | + // association de chaque nom http d'un charset aux couples MySQL |
|
| 139 | + 'charsets' => [ |
|
| 140 | + 'cp1250' => ['charset' => 'cp1250', 'collation' => 'cp1250_general_ci'], |
|
| 141 | + 'cp1251' => ['charset' => 'cp1251', 'collation' => 'cp1251_general_ci'], |
|
| 142 | + 'cp1256' => ['charset' => 'cp1256', 'collation' => 'cp1256_general_ci'], |
|
| 143 | + 'iso-8859-1' => ['charset' => 'latin1', 'collation' => 'latin1_swedish_ci'], |
|
| 144 | 144 | //'iso-8859-6'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 145 | - 'iso-8859-9' => ['charset' => 'latin5', 'collation' => 'latin5_turkish_ci'], |
|
| 145 | + 'iso-8859-9' => ['charset' => 'latin5', 'collation' => 'latin5_turkish_ci'], |
|
| 146 | 146 | //'iso-8859-15'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 147 | - 'utf-8' => ['charset' => 'utf8', 'collation' => 'utf8_general_ci'] |
|
| 148 | - ] |
|
| 147 | + 'utf-8' => ['charset' => 'utf8', 'collation' => 'utf8_general_ci'] |
|
| 148 | + ] |
|
| 149 | 149 | ]; |
| 150 | 150 | |
| 151 | 151 | |
@@ -156,9 +156,9 @@ discard block |
||
| 156 | 156 | * @return Object Information de connexion pour mysqli |
| 157 | 157 | */ |
| 158 | 158 | function _mysql_link($serveur = '') { |
| 159 | - $link = &$GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 159 | + $link = &$GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 160 | 160 | |
| 161 | - return $link; |
|
| 161 | + return $link; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
@@ -171,10 +171,10 @@ discard block |
||
| 171 | 171 | * @return mysqli_result|bool Jeu de résultats pour fetch() |
| 172 | 172 | */ |
| 173 | 173 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 174 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 175 | - spip_log('changement de charset sql : ' . 'SET NAMES ' . _q($charset), _LOG_DEBUG); |
|
| 174 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 175 | + spip_log('changement de charset sql : ' . 'SET NAMES ' . _q($charset), _LOG_DEBUG); |
|
| 176 | 176 | |
| 177 | - return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES ' . _q($charset)); |
|
| 177 | + return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES ' . _q($charset)); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | * @return array Description du charset (son nom est dans 'charset') |
| 188 | 188 | */ |
| 189 | 189 | function spip_mysql_get_charset($charset = [], $serveur = '', $requeter = true) { |
| 190 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 191 | - $connexion['last'] = $c = 'SHOW CHARACTER SET' |
|
| 192 | - . (!$charset ? '' : (' LIKE ' . _q($charset['charset']))); |
|
| 190 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 191 | + $connexion['last'] = $c = 'SHOW CHARACTER SET' |
|
| 192 | + . (!$charset ? '' : (' LIKE ' . _q($charset['charset']))); |
|
| 193 | 193 | |
| 194 | - return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 194 | + return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -207,80 +207,80 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | function spip_mysql_query($query, $serveur = '', $requeter = true) { |
| 209 | 209 | |
| 210 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 211 | - $prefixe = $connexion['prefixe']; |
|
| 212 | - $link = $connexion['link']; |
|
| 213 | - $db = $connexion['db']; |
|
| 214 | - |
|
| 215 | - $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 216 | - |
|
| 217 | - // renvoyer la requete inerte si demandee |
|
| 218 | - if (!$requeter) { |
|
| 219 | - return $query; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if (isset($_GET['var_profile']) or (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES)) { |
|
| 223 | - include_spip('public/tracer'); |
|
| 224 | - $t = trace_query_start(); |
|
| 225 | - } else { |
|
| 226 | - $t = 0; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $connexion['last'] = $query; |
|
| 230 | - $connexion['total_requetes']++; |
|
| 231 | - |
|
| 232 | - // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 233 | - $debug = ''; |
|
| 234 | - if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 235 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 236 | - [, $id, , $infos] = $GLOBALS['debug']['aucasou']; |
|
| 237 | - $debug .= "BOUCLE$id @ " . ($infos[0] ?? '') . ' | '; |
|
| 238 | - } |
|
| 239 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 240 | - $debug .= $_SERVER['REQUEST_URI']; |
|
| 241 | - } |
|
| 242 | - if (!empty($GLOBALS['ip'])) { |
|
| 243 | - $debug .= ' + ' . $GLOBALS['ip']; |
|
| 244 | - } |
|
| 245 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 246 | - } |
|
| 247 | - try { |
|
| 248 | - $r = mysqli_query($link, $query . $debug); |
|
| 249 | - } catch (\mysqli_sql_exception $e) { |
|
| 250 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 251 | - $r = false; |
|
| 252 | - // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 253 | - // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 257 | - if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 258 | - if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 259 | - //Fermer la connexion defaillante |
|
| 260 | - mysqli_close($connexion['link']); |
|
| 261 | - unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 262 | - //Relancer une connexion vierge |
|
| 263 | - spip_connect($serveur); |
|
| 264 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 265 | - $link = $connexion['link']; |
|
| 266 | - //On retente au cas où |
|
| 267 | - try { |
|
| 268 | - $r = mysqli_query($link, $query . $debug); |
|
| 269 | - } catch (\mysqli_sql_exception $e) { |
|
| 270 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 271 | - $r = false; |
|
| 272 | - // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 273 | - // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // Log de l'erreur eventuelle |
|
| 279 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 280 | - // et du fautif |
|
| 281 | - $e .= spip_mysql_error($query, $serveur); |
|
| 282 | - } |
|
| 283 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 210 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 211 | + $prefixe = $connexion['prefixe']; |
|
| 212 | + $link = $connexion['link']; |
|
| 213 | + $db = $connexion['db']; |
|
| 214 | + |
|
| 215 | + $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 216 | + |
|
| 217 | + // renvoyer la requete inerte si demandee |
|
| 218 | + if (!$requeter) { |
|
| 219 | + return $query; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if (isset($_GET['var_profile']) or (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES)) { |
|
| 223 | + include_spip('public/tracer'); |
|
| 224 | + $t = trace_query_start(); |
|
| 225 | + } else { |
|
| 226 | + $t = 0; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $connexion['last'] = $query; |
|
| 230 | + $connexion['total_requetes']++; |
|
| 231 | + |
|
| 232 | + // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 233 | + $debug = ''; |
|
| 234 | + if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 235 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 236 | + [, $id, , $infos] = $GLOBALS['debug']['aucasou']; |
|
| 237 | + $debug .= "BOUCLE$id @ " . ($infos[0] ?? '') . ' | '; |
|
| 238 | + } |
|
| 239 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 240 | + $debug .= $_SERVER['REQUEST_URI']; |
|
| 241 | + } |
|
| 242 | + if (!empty($GLOBALS['ip'])) { |
|
| 243 | + $debug .= ' + ' . $GLOBALS['ip']; |
|
| 244 | + } |
|
| 245 | + $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 246 | + } |
|
| 247 | + try { |
|
| 248 | + $r = mysqli_query($link, $query . $debug); |
|
| 249 | + } catch (\mysqli_sql_exception $e) { |
|
| 250 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 251 | + $r = false; |
|
| 252 | + // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 253 | + // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 257 | + if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 258 | + if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 259 | + //Fermer la connexion defaillante |
|
| 260 | + mysqli_close($connexion['link']); |
|
| 261 | + unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 262 | + //Relancer une connexion vierge |
|
| 263 | + spip_connect($serveur); |
|
| 264 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 265 | + $link = $connexion['link']; |
|
| 266 | + //On retente au cas où |
|
| 267 | + try { |
|
| 268 | + $r = mysqli_query($link, $query . $debug); |
|
| 269 | + } catch (\mysqli_sql_exception $e) { |
|
| 270 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 271 | + $r = false; |
|
| 272 | + // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 273 | + // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // Log de l'erreur eventuelle |
|
| 279 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 280 | + // et du fautif |
|
| 281 | + $e .= spip_mysql_error($query, $serveur); |
|
| 282 | + } |
|
| 283 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -295,12 +295,12 @@ discard block |
||
| 295 | 295 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 296 | 296 | */ |
| 297 | 297 | function spip_mysql_alter($query, $serveur = '', $requeter = true) { |
| 298 | - // ici on supprime les ` entourant le nom de table pour permettre |
|
| 299 | - // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 300 | - // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 301 | - $query = preg_replace(',^TABLE\s*`([^`]*)`,i', "TABLE \\1", $query); |
|
| 298 | + // ici on supprime les ` entourant le nom de table pour permettre |
|
| 299 | + // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 300 | + // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 301 | + $query = preg_replace(',^TABLE\s*`([^`]*)`,i', "TABLE \\1", $query); |
|
| 302 | 302 | |
| 303 | - return spip_mysql_query('ALTER ' . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 303 | + return spip_mysql_query('ALTER ' . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | |
@@ -313,9 +313,9 @@ discard block |
||
| 313 | 313 | * @return bool Toujours true |
| 314 | 314 | */ |
| 315 | 315 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 316 | - spip_mysql_query('OPTIMIZE TABLE ' . $table); |
|
| 316 | + spip_mysql_query('OPTIMIZE TABLE ' . $table); |
|
| 317 | 317 | |
| 318 | - return true; |
|
| 318 | + return true; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | |
@@ -328,18 +328,18 @@ discard block |
||
| 328 | 328 | * @return array Tableau de l'explication |
| 329 | 329 | */ |
| 330 | 330 | function spip_mysql_explain($query, $serveur = '', $requeter = true) { |
| 331 | - if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 332 | - return []; |
|
| 333 | - } |
|
| 334 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 335 | - $prefixe = $connexion['prefixe']; |
|
| 336 | - $link = $connexion['link']; |
|
| 337 | - $db = $connexion['db']; |
|
| 338 | - |
|
| 339 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 340 | - $r = mysqli_query($link, $query); |
|
| 341 | - |
|
| 342 | - return spip_mysql_fetch($r, null, $serveur); |
|
| 331 | + if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 332 | + return []; |
|
| 333 | + } |
|
| 334 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 335 | + $prefixe = $connexion['prefixe']; |
|
| 336 | + $link = $connexion['link']; |
|
| 337 | + $db = $connexion['db']; |
|
| 338 | + |
|
| 339 | + $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 340 | + $r = mysqli_query($link, $query); |
|
| 341 | + |
|
| 342 | + return spip_mysql_fetch($r, null, $serveur); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | |
@@ -368,35 +368,35 @@ discard block |
||
| 368 | 368 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 369 | 369 | */ |
| 370 | 370 | function spip_mysql_select( |
| 371 | - $select, |
|
| 372 | - $from, |
|
| 373 | - $where = '', |
|
| 374 | - $groupby = '', |
|
| 375 | - $orderby = '', |
|
| 376 | - $limit = '', |
|
| 377 | - $having = '', |
|
| 378 | - $serveur = '', |
|
| 379 | - $requeter = true |
|
| 371 | + $select, |
|
| 372 | + $from, |
|
| 373 | + $where = '', |
|
| 374 | + $groupby = '', |
|
| 375 | + $orderby = '', |
|
| 376 | + $limit = '', |
|
| 377 | + $having = '', |
|
| 378 | + $serveur = '', |
|
| 379 | + $requeter = true |
|
| 380 | 380 | ) { |
| 381 | 381 | |
| 382 | 382 | |
| 383 | - $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 384 | - $query = |
|
| 385 | - calculer_mysql_expression('SELECT', $select, ', ') |
|
| 386 | - . calculer_mysql_expression('FROM', $from, ', ') |
|
| 387 | - . calculer_mysql_expression('WHERE', $where) |
|
| 388 | - . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 389 | - . calculer_mysql_expression('HAVING', $having) |
|
| 390 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 391 | - . ($limit ? "\nLIMIT $limit" : ''); |
|
| 383 | + $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 384 | + $query = |
|
| 385 | + calculer_mysql_expression('SELECT', $select, ', ') |
|
| 386 | + . calculer_mysql_expression('FROM', $from, ', ') |
|
| 387 | + . calculer_mysql_expression('WHERE', $where) |
|
| 388 | + . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 389 | + . calculer_mysql_expression('HAVING', $having) |
|
| 390 | + . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 391 | + . ($limit ? "\nLIMIT $limit" : ''); |
|
| 392 | 392 | |
| 393 | - // renvoyer la requete inerte si demandee |
|
| 394 | - if ($requeter === false) { |
|
| 395 | - return $query; |
|
| 396 | - } |
|
| 397 | - $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 393 | + // renvoyer la requete inerte si demandee |
|
| 394 | + if ($requeter === false) { |
|
| 395 | + return $query; |
|
| 396 | + } |
|
| 397 | + $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 398 | 398 | |
| 399 | - return $r ?: $query; |
|
| 399 | + return $r ?: $query; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | * @return string texte du orderby préparé |
| 414 | 414 | */ |
| 415 | 415 | function spip_mysql_order($orderby) { |
| 416 | - return (is_array($orderby)) ? join(', ', $orderby) : $orderby; |
|
| 416 | + return (is_array($orderby)) ? join(', ', $orderby) : $orderby; |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | |
@@ -436,26 +436,26 @@ discard block |
||
| 436 | 436 | * Contrainte pour clause WHERE |
| 437 | 437 | */ |
| 438 | 438 | function calculer_mysql_where($v) { |
| 439 | - if (!is_array($v)) { |
|
| 440 | - return $v; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - $op = array_shift($v); |
|
| 444 | - if (!($n = count($v))) { |
|
| 445 | - return $op; |
|
| 446 | - } else { |
|
| 447 | - $arg = calculer_mysql_where(array_shift($v)); |
|
| 448 | - if ($n == 1) { |
|
| 449 | - return "$op($arg)"; |
|
| 450 | - } else { |
|
| 451 | - $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 452 | - if ($n == 2) { |
|
| 453 | - return "($arg $op $arg2)"; |
|
| 454 | - } else { |
|
| 455 | - return "($arg $op ($arg2) : $v[0])"; |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - } |
|
| 439 | + if (!is_array($v)) { |
|
| 440 | + return $v; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + $op = array_shift($v); |
|
| 444 | + if (!($n = count($v))) { |
|
| 445 | + return $op; |
|
| 446 | + } else { |
|
| 447 | + $arg = calculer_mysql_where(array_shift($v)); |
|
| 448 | + if ($n == 1) { |
|
| 449 | + return "$op($arg)"; |
|
| 450 | + } else { |
|
| 451 | + $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 452 | + if ($n == 2) { |
|
| 453 | + return "($arg $op $arg2)"; |
|
| 454 | + } else { |
|
| 455 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -470,21 +470,21 @@ discard block |
||
| 470 | 470 | * @return string texte de l'expression, une partie donc, du texte la requête. |
| 471 | 471 | */ |
| 472 | 472 | function calculer_mysql_expression($expression, $v, $join = 'AND') { |
| 473 | - if (empty($v)) { |
|
| 474 | - return ''; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - $exp = "\n$expression "; |
|
| 478 | - |
|
| 479 | - if (!is_array($v)) { |
|
| 480 | - return $exp . $v; |
|
| 481 | - } else { |
|
| 482 | - if (strtoupper($join) === 'AND') { |
|
| 483 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 484 | - } else { |
|
| 485 | - return $exp . join($join, $v); |
|
| 486 | - } |
|
| 487 | - } |
|
| 473 | + if (empty($v)) { |
|
| 474 | + return ''; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + $exp = "\n$expression "; |
|
| 478 | + |
|
| 479 | + if (!is_array($v)) { |
|
| 480 | + return $exp . $v; |
|
| 481 | + } else { |
|
| 482 | + if (strtoupper($join) === 'AND') { |
|
| 483 | + return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 484 | + } else { |
|
| 485 | + return $exp . join($join, $v); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | |
@@ -495,26 +495,26 @@ discard block |
||
| 495 | 495 | * @return string Sélection de colonnes pour une clause SELECT |
| 496 | 496 | */ |
| 497 | 497 | function spip_mysql_select_as($args) { |
| 498 | - $res = ''; |
|
| 499 | - foreach ($args as $k => $v) { |
|
| 500 | - if (substr($k, -1) == '@') { |
|
| 501 | - // c'est une jointure qui se refere au from precedent |
|
| 502 | - // pas de virgule |
|
| 503 | - $res .= ' ' . $v; |
|
| 504 | - } else { |
|
| 505 | - if (!is_numeric($k)) { |
|
| 506 | - $p = strpos($v, ' '); |
|
| 507 | - if ($p) { |
|
| 508 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 509 | - } else { |
|
| 510 | - $v .= " AS `$k`"; |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - $res .= ', ' . $v; |
|
| 514 | - } |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - return substr($res, 2); |
|
| 498 | + $res = ''; |
|
| 499 | + foreach ($args as $k => $v) { |
|
| 500 | + if (substr($k, -1) == '@') { |
|
| 501 | + // c'est une jointure qui se refere au from precedent |
|
| 502 | + // pas de virgule |
|
| 503 | + $res .= ' ' . $v; |
|
| 504 | + } else { |
|
| 505 | + if (!is_numeric($k)) { |
|
| 506 | + $p = strpos($v, ' '); |
|
| 507 | + if ($p) { |
|
| 508 | + $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 509 | + } else { |
|
| 510 | + $v .= " AS `$k`"; |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + $res .= ', ' . $v; |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + return substr($res, 2); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | |
@@ -539,58 +539,58 @@ discard block |
||
| 539 | 539 | */ |
| 540 | 540 | function _mysql_traite_query($query, $db = '', $prefixe = '', $echappe_textes = true) { |
| 541 | 541 | |
| 542 | - if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 543 | - $pref = '`' . $db . '`.'; |
|
| 544 | - } else { |
|
| 545 | - $pref = ''; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - if ($prefixe) { |
|
| 549 | - $pref .= $prefixe . '_'; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 553 | - $suite = ''; |
|
| 554 | - } else { |
|
| 555 | - $suite = strstr($query, (string) $regs[0]); |
|
| 556 | - $query = substr($query, 0, -strlen($suite)); |
|
| 557 | - // propager le prefixe en cas de requete imbriquee |
|
| 558 | - // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 559 | - // modifier une requete qui est en fait juste du texte dans un champ |
|
| 560 | - if (stripos($suite, 'SELECT') !== false) { |
|
| 561 | - if ($echappe_textes) { |
|
| 562 | - [$suite_echap, $textes] = query_echappe_textes($suite); |
|
| 563 | - } |
|
| 564 | - else { |
|
| 565 | - $suite_echap = $suite; |
|
| 566 | - } |
|
| 567 | - if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
|
| 568 | - $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 569 | - if ($echappe_textes) { |
|
| 570 | - $suite = query_reinjecte_textes($suite_echap, $textes); |
|
| 571 | - } |
|
| 572 | - else { |
|
| 573 | - $suite = $suite_echap; |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - } |
|
| 578 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 579 | - |
|
| 580 | - // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 581 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 582 | - if ( |
|
| 583 | - defined('_MYSQL_NOPLANES') |
|
| 584 | - and _MYSQL_NOPLANES |
|
| 585 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 586 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 587 | - ) { |
|
| 588 | - include_spip('inc/charsets'); |
|
| 589 | - $r = utf8_noplanes($r); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 593 | - return $r; |
|
| 542 | + if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 543 | + $pref = '`' . $db . '`.'; |
|
| 544 | + } else { |
|
| 545 | + $pref = ''; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + if ($prefixe) { |
|
| 549 | + $pref .= $prefixe . '_'; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 553 | + $suite = ''; |
|
| 554 | + } else { |
|
| 555 | + $suite = strstr($query, (string) $regs[0]); |
|
| 556 | + $query = substr($query, 0, -strlen($suite)); |
|
| 557 | + // propager le prefixe en cas de requete imbriquee |
|
| 558 | + // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 559 | + // modifier une requete qui est en fait juste du texte dans un champ |
|
| 560 | + if (stripos($suite, 'SELECT') !== false) { |
|
| 561 | + if ($echappe_textes) { |
|
| 562 | + [$suite_echap, $textes] = query_echappe_textes($suite); |
|
| 563 | + } |
|
| 564 | + else { |
|
| 565 | + $suite_echap = $suite; |
|
| 566 | + } |
|
| 567 | + if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
|
| 568 | + $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 569 | + if ($echappe_textes) { |
|
| 570 | + $suite = query_reinjecte_textes($suite_echap, $textes); |
|
| 571 | + } |
|
| 572 | + else { |
|
| 573 | + $suite = $suite_echap; |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + } |
|
| 578 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 579 | + |
|
| 580 | + // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 581 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 582 | + if ( |
|
| 583 | + defined('_MYSQL_NOPLANES') |
|
| 584 | + and _MYSQL_NOPLANES |
|
| 585 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 586 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 587 | + ) { |
|
| 588 | + include_spip('inc/charsets'); |
|
| 589 | + $r = utf8_noplanes($r); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 593 | + return $r; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -608,17 +608,17 @@ discard block |
||
| 608 | 608 | * - False en cas d'erreur. |
| 609 | 609 | **/ |
| 610 | 610 | function spip_mysql_selectdb($db, $serveur = '', $requeter = true) { |
| 611 | - $link = _mysql_link($serveur); |
|
| 612 | - try { |
|
| 613 | - $ok = mysqli_select_db($link, $db); |
|
| 614 | - } catch (\mysqli_sql_exception $e) { |
|
| 615 | - $ok = false; |
|
| 616 | - } |
|
| 617 | - if (!$ok) { |
|
| 618 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - return $ok; |
|
| 611 | + $link = _mysql_link($serveur); |
|
| 612 | + try { |
|
| 613 | + $ok = mysqli_select_db($link, $db); |
|
| 614 | + } catch (\mysqli_sql_exception $e) { |
|
| 615 | + $ok = false; |
|
| 616 | + } |
|
| 617 | + if (!$ok) { |
|
| 618 | + spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + return $ok; |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | |
@@ -639,14 +639,14 @@ discard block |
||
| 639 | 639 | * Liste de noms de bases de données |
| 640 | 640 | **/ |
| 641 | 641 | function spip_mysql_listdbs($serveur = '', $requeter = true) { |
| 642 | - $dbs = []; |
|
| 643 | - if ($res = spip_mysql_query('SHOW DATABASES', $serveur)) { |
|
| 644 | - while ($row = mysqli_fetch_assoc($res)) { |
|
| 645 | - $dbs[] = $row['Database']; |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - return $dbs; |
|
| 642 | + $dbs = []; |
|
| 643 | + if ($res = spip_mysql_query('SHOW DATABASES', $serveur)) { |
|
| 644 | + while ($row = mysqli_fetch_assoc($res)) { |
|
| 645 | + $dbs[] = $row['Database']; |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + return $dbs; |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | |
@@ -669,73 +669,73 @@ discard block |
||
| 669 | 669 | * - true si la requête réussie, false sinon. |
| 670 | 670 | */ |
| 671 | 671 | function spip_mysql_create( |
| 672 | - $nom, |
|
| 673 | - $champs, |
|
| 674 | - $cles, |
|
| 675 | - $autoinc = false, |
|
| 676 | - $temporary = false, |
|
| 677 | - $serveur = '', |
|
| 678 | - $requeter = true |
|
| 672 | + $nom, |
|
| 673 | + $champs, |
|
| 674 | + $cles, |
|
| 675 | + $autoinc = false, |
|
| 676 | + $temporary = false, |
|
| 677 | + $serveur = '', |
|
| 678 | + $requeter = true |
|
| 679 | 679 | ) { |
| 680 | 680 | |
| 681 | - $query = ''; |
|
| 682 | - $keys = ''; |
|
| 683 | - $s = ''; |
|
| 684 | - $p = ''; |
|
| 685 | - |
|
| 686 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 687 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 688 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 689 | - return; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - $res = spip_mysql_query('SELECT version() as v', $serveur); |
|
| 693 | - if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 694 | - spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - foreach ($cles as $k => $v) { |
|
| 698 | - $keys .= "$s\n\t\t$k ($v)"; |
|
| 699 | - if ($k == 'PRIMARY KEY') { |
|
| 700 | - $p = $v; |
|
| 701 | - } |
|
| 702 | - $s = ','; |
|
| 703 | - } |
|
| 704 | - $s = ''; |
|
| 705 | - |
|
| 706 | - $character_set = ''; |
|
| 707 | - if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 708 | - $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 709 | - } |
|
| 710 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 711 | - $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - foreach ($champs as $k => $v) { |
|
| 715 | - $v = _mysql_remplacements_definitions_table($v); |
|
| 716 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 717 | - if ( |
|
| 718 | - preg_match(',(char|text),i', $defs[1]) |
|
| 719 | - and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 720 | - ) { |
|
| 721 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 722 | - } |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - $query .= "$s\n\t\t$k $v" |
|
| 726 | - . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 727 | - ? ' auto_increment' |
|
| 728 | - : '' |
|
| 729 | - ); |
|
| 730 | - $s = ','; |
|
| 731 | - } |
|
| 732 | - $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 733 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 734 | - . (defined('_MYSQL_ENGINE') ? ' ENGINE=' . _MYSQL_ENGINE : '') |
|
| 735 | - . ($character_set ? " DEFAULT $character_set" : '') |
|
| 736 | - . "\n"; |
|
| 737 | - |
|
| 738 | - return spip_mysql_query($q, $serveur); |
|
| 681 | + $query = ''; |
|
| 682 | + $keys = ''; |
|
| 683 | + $s = ''; |
|
| 684 | + $p = ''; |
|
| 685 | + |
|
| 686 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 687 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 688 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 689 | + return; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + $res = spip_mysql_query('SELECT version() as v', $serveur); |
|
| 693 | + if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 694 | + spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + foreach ($cles as $k => $v) { |
|
| 698 | + $keys .= "$s\n\t\t$k ($v)"; |
|
| 699 | + if ($k == 'PRIMARY KEY') { |
|
| 700 | + $p = $v; |
|
| 701 | + } |
|
| 702 | + $s = ','; |
|
| 703 | + } |
|
| 704 | + $s = ''; |
|
| 705 | + |
|
| 706 | + $character_set = ''; |
|
| 707 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 708 | + $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 709 | + } |
|
| 710 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 711 | + $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + foreach ($champs as $k => $v) { |
|
| 715 | + $v = _mysql_remplacements_definitions_table($v); |
|
| 716 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 717 | + if ( |
|
| 718 | + preg_match(',(char|text),i', $defs[1]) |
|
| 719 | + and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 720 | + ) { |
|
| 721 | + $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 722 | + } |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + $query .= "$s\n\t\t$k $v" |
|
| 726 | + . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 727 | + ? ' auto_increment' |
|
| 728 | + : '' |
|
| 729 | + ); |
|
| 730 | + $s = ','; |
|
| 731 | + } |
|
| 732 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 733 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 734 | + . (defined('_MYSQL_ENGINE') ? ' ENGINE=' . _MYSQL_ENGINE : '') |
|
| 735 | + . ($character_set ? " DEFAULT $character_set" : '') |
|
| 736 | + . "\n"; |
|
| 737 | + |
|
| 738 | + return spip_mysql_query($q, $serveur); |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | |
@@ -748,25 +748,25 @@ discard block |
||
| 748 | 748 | * Définition SQL adaptée pour MySQL d'un champ de table |
| 749 | 749 | */ |
| 750 | 750 | function _mysql_remplacements_definitions_table($query) { |
| 751 | - // quelques remplacements |
|
| 752 | - $num = '(\s*\([0-9]*\))?'; |
|
| 753 | - $enum = '(\s*\([^\)]*\))?'; |
|
| 754 | - |
|
| 755 | - $remplace = [ |
|
| 756 | - '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 757 | - '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 758 | - ]; |
|
| 759 | - |
|
| 760 | - if (is_string($query)) { |
|
| 761 | - $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 762 | - } elseif (is_array($query)) { |
|
| 763 | - $keys = array_keys($remplace); |
|
| 764 | - foreach ($query as $k => $q) { |
|
| 765 | - $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 766 | - } |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - return $query; |
|
| 751 | + // quelques remplacements |
|
| 752 | + $num = '(\s*\([0-9]*\))?'; |
|
| 753 | + $enum = '(\s*\([^\)]*\))?'; |
|
| 754 | + |
|
| 755 | + $remplace = [ |
|
| 756 | + '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 757 | + '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 758 | + ]; |
|
| 759 | + |
|
| 760 | + if (is_string($query)) { |
|
| 761 | + $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 762 | + } elseif (is_array($query)) { |
|
| 763 | + $keys = array_keys($remplace); |
|
| 764 | + foreach ($query as $k => $q) { |
|
| 765 | + $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 766 | + } |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + return $query; |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | * @return bool true si la base est créee. |
| 780 | 780 | **/ |
| 781 | 781 | function spip_mysql_create_base($nom, $serveur = '', $requeter = true) { |
| 782 | - return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 782 | + return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | |
@@ -800,19 +800,19 @@ discard block |
||
| 800 | 800 | * - string texte de la requête si $requeter vaut false |
| 801 | 801 | */ |
| 802 | 802 | function spip_mysql_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 803 | - if (!$query_select) { |
|
| 804 | - return false; |
|
| 805 | - } |
|
| 806 | - // vue deja presente |
|
| 807 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 808 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 803 | + if (!$query_select) { |
|
| 804 | + return false; |
|
| 805 | + } |
|
| 806 | + // vue deja presente |
|
| 807 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 808 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 809 | 809 | |
| 810 | - return false; |
|
| 811 | - } |
|
| 810 | + return false; |
|
| 811 | + } |
|
| 812 | 812 | |
| 813 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 813 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 814 | 814 | |
| 815 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 815 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | |
@@ -828,11 +828,11 @@ discard block |
||
| 828 | 828 | * - true si la requête a réussie, false sinon |
| 829 | 829 | */ |
| 830 | 830 | function spip_mysql_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 831 | - if ($exist) { |
|
| 832 | - $exist = ' IF EXISTS'; |
|
| 833 | - } |
|
| 831 | + if ($exist) { |
|
| 832 | + $exist = ' IF EXISTS'; |
|
| 833 | + } |
|
| 834 | 834 | |
| 835 | - return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 835 | + return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 836 | 836 | } |
| 837 | 837 | |
| 838 | 838 | /** |
@@ -847,11 +847,11 @@ discard block |
||
| 847 | 847 | * - true si la requête a réussie, false sinon |
| 848 | 848 | */ |
| 849 | 849 | function spip_mysql_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 850 | - if ($exist) { |
|
| 851 | - $exist = ' IF EXISTS'; |
|
| 852 | - } |
|
| 850 | + if ($exist) { |
|
| 851 | + $exist = ' IF EXISTS'; |
|
| 852 | + } |
|
| 853 | 853 | |
| 854 | - return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 854 | + return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | /** |
@@ -868,7 +868,7 @@ discard block |
||
| 868 | 868 | * Ressource à utiliser avec sql_fetch() |
| 869 | 869 | **/ |
| 870 | 870 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 871 | - return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 871 | + return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 872 | 872 | } |
| 873 | 873 | |
| 874 | 874 | /** |
@@ -884,18 +884,18 @@ discard block |
||
| 884 | 884 | * - true si la requête a réussie, false sinon |
| 885 | 885 | */ |
| 886 | 886 | function spip_mysql_repair($table, $serveur = '', $requeter = true) { |
| 887 | - $table_status = spip_mysql_fetch(spip_mysql_query('SHOW TABLE STATUS WHERE Name = ' . _q($table), $serveur, true)); |
|
| 888 | - $engine = $table_status['Engine']; |
|
| 889 | - if ($engine == 'InnoDB') { |
|
| 890 | - if (spip_mysql_alter("TABLE $table ENGINE = InnoDB", $serveur, $requeter)) { |
|
| 891 | - return [' OK ']; |
|
| 892 | - } |
|
| 893 | - } elseif ($engine == 'MyISAM') { |
|
| 894 | - return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 895 | - } else { |
|
| 896 | - spip_log("spip_mysql_repair impossible pour la table $table engine $engine", 'mysql.' . _LOG_DEBUG); |
|
| 897 | - } |
|
| 898 | - return false; |
|
| 887 | + $table_status = spip_mysql_fetch(spip_mysql_query('SHOW TABLE STATUS WHERE Name = ' . _q($table), $serveur, true)); |
|
| 888 | + $engine = $table_status['Engine']; |
|
| 889 | + if ($engine == 'InnoDB') { |
|
| 890 | + if (spip_mysql_alter("TABLE $table ENGINE = InnoDB", $serveur, $requeter)) { |
|
| 891 | + return [' OK ']; |
|
| 892 | + } |
|
| 893 | + } elseif ($engine == 'MyISAM') { |
|
| 894 | + return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 895 | + } else { |
|
| 896 | + spip_log("spip_mysql_repair impossible pour la table $table engine $engine", 'mysql.' . _LOG_DEBUG); |
|
| 897 | + } |
|
| 898 | + return false; |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | /** |
@@ -913,12 +913,12 @@ discard block |
||
| 913 | 913 | * - string : requete sql, si $requeter = true |
| 914 | 914 | **/ |
| 915 | 915 | function spip_mysql_table_exists(string $table, $serveur = '', $requeter = true) { |
| 916 | - $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 917 | - if (!$requeter) { |
|
| 918 | - return $r; |
|
| 919 | - } |
|
| 920 | - $res = spip_mysql_fetch($r); |
|
| 921 | - return (bool) $res; |
|
| 916 | + $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 917 | + if (!$requeter) { |
|
| 918 | + return $r; |
|
| 919 | + } |
|
| 920 | + $res = spip_mysql_fetch($r); |
|
| 921 | + return (bool) $res; |
|
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | define('_MYSQL_RE_SHOW_TABLE', '/^[^(),]*\(((?:[^()]*\((?:[^()]*\([^()]*\))?[^()]*\)[^()]*)*[^()]*)\)[^()]*$/'); |
@@ -941,86 +941,86 @@ discard block |
||
| 941 | 941 | * - array description de la table sinon |
| 942 | 942 | */ |
| 943 | 943 | function spip_mysql_showtable($nom_table, $serveur = '', $requeter = true) { |
| 944 | - $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 945 | - if (!$s) { |
|
| 946 | - return ''; |
|
| 947 | - } |
|
| 948 | - if (!$requeter) { |
|
| 949 | - return $s; |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - [, $a] = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 953 | - if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 954 | - $desc = $r[1]; |
|
| 955 | - // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 956 | - // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 957 | - if (preg_match('/^(.*?),([^,]*\sKEY[ (].*)$/s', $desc, $r)) { |
|
| 958 | - $namedkeys = $r[2]; |
|
| 959 | - $desc = $r[1]; |
|
| 960 | - } else { |
|
| 961 | - $namedkeys = ''; |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - $fields = []; |
|
| 965 | - foreach (preg_split('/,\s*`/', $desc) as $v) { |
|
| 966 | - preg_match('/^\s*`?([^`]*)`\s*(.*)/', $v, $r); |
|
| 967 | - $fields[strtolower($r[1])] = $r[2]; |
|
| 968 | - } |
|
| 969 | - $keys = []; |
|
| 970 | - |
|
| 971 | - foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 972 | - if (preg_match('/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/', $v, $r)) { |
|
| 973 | - $k = str_replace('`', '', trim($r[1])); |
|
| 974 | - $t = strtolower(str_replace('`', '', $r[2])); |
|
| 975 | - if ($k && !isset($keys[$k])) { |
|
| 976 | - $keys[$k] = $t; |
|
| 977 | - } else { |
|
| 978 | - $keys[] = $t; |
|
| 979 | - } |
|
| 980 | - } |
|
| 981 | - } |
|
| 982 | - spip_mysql_free($s); |
|
| 983 | - |
|
| 984 | - return ['field' => $fields, 'key' => $keys]; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 988 | - if ($res) { |
|
| 989 | - $nfields = []; |
|
| 990 | - $nkeys = []; |
|
| 991 | - while ($val = spip_mysql_fetch($res)) { |
|
| 992 | - $nfields[$val['Field']] = $val['Type']; |
|
| 993 | - if ($val['Null'] == 'NO') { |
|
| 994 | - $nfields[$val['Field']] .= ' NOT NULL'; |
|
| 995 | - } |
|
| 996 | - if ($val['Default'] === '0' || $val['Default']) { |
|
| 997 | - if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 998 | - $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 999 | - } else { |
|
| 1000 | - $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 1001 | - } |
|
| 1002 | - } |
|
| 1003 | - if ($val['Extra']) { |
|
| 1004 | - $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 1005 | - } |
|
| 1006 | - if ($val['Key'] == 'PRI') { |
|
| 1007 | - $nkeys['PRIMARY KEY'] = $val['Field']; |
|
| 1008 | - } else { |
|
| 1009 | - if ($val['Key'] == 'MUL') { |
|
| 1010 | - $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 1011 | - } else { |
|
| 1012 | - if ($val['Key'] == 'UNI') { |
|
| 1013 | - $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 1014 | - } |
|
| 1015 | - } |
|
| 1016 | - } |
|
| 1017 | - } |
|
| 1018 | - spip_mysql_free($res); |
|
| 1019 | - |
|
| 1020 | - return ['field' => $nfields, 'key' => $nkeys]; |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - return ''; |
|
| 944 | + $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 945 | + if (!$s) { |
|
| 946 | + return ''; |
|
| 947 | + } |
|
| 948 | + if (!$requeter) { |
|
| 949 | + return $s; |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + [, $a] = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 953 | + if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 954 | + $desc = $r[1]; |
|
| 955 | + // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 956 | + // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 957 | + if (preg_match('/^(.*?),([^,]*\sKEY[ (].*)$/s', $desc, $r)) { |
|
| 958 | + $namedkeys = $r[2]; |
|
| 959 | + $desc = $r[1]; |
|
| 960 | + } else { |
|
| 961 | + $namedkeys = ''; |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + $fields = []; |
|
| 965 | + foreach (preg_split('/,\s*`/', $desc) as $v) { |
|
| 966 | + preg_match('/^\s*`?([^`]*)`\s*(.*)/', $v, $r); |
|
| 967 | + $fields[strtolower($r[1])] = $r[2]; |
|
| 968 | + } |
|
| 969 | + $keys = []; |
|
| 970 | + |
|
| 971 | + foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 972 | + if (preg_match('/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/', $v, $r)) { |
|
| 973 | + $k = str_replace('`', '', trim($r[1])); |
|
| 974 | + $t = strtolower(str_replace('`', '', $r[2])); |
|
| 975 | + if ($k && !isset($keys[$k])) { |
|
| 976 | + $keys[$k] = $t; |
|
| 977 | + } else { |
|
| 978 | + $keys[] = $t; |
|
| 979 | + } |
|
| 980 | + } |
|
| 981 | + } |
|
| 982 | + spip_mysql_free($s); |
|
| 983 | + |
|
| 984 | + return ['field' => $fields, 'key' => $keys]; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 988 | + if ($res) { |
|
| 989 | + $nfields = []; |
|
| 990 | + $nkeys = []; |
|
| 991 | + while ($val = spip_mysql_fetch($res)) { |
|
| 992 | + $nfields[$val['Field']] = $val['Type']; |
|
| 993 | + if ($val['Null'] == 'NO') { |
|
| 994 | + $nfields[$val['Field']] .= ' NOT NULL'; |
|
| 995 | + } |
|
| 996 | + if ($val['Default'] === '0' || $val['Default']) { |
|
| 997 | + if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 998 | + $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 999 | + } else { |
|
| 1000 | + $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 1001 | + } |
|
| 1002 | + } |
|
| 1003 | + if ($val['Extra']) { |
|
| 1004 | + $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 1005 | + } |
|
| 1006 | + if ($val['Key'] == 'PRI') { |
|
| 1007 | + $nkeys['PRIMARY KEY'] = $val['Field']; |
|
| 1008 | + } else { |
|
| 1009 | + if ($val['Key'] == 'MUL') { |
|
| 1010 | + $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 1011 | + } else { |
|
| 1012 | + if ($val['Key'] == 'UNI') { |
|
| 1013 | + $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 1014 | + } |
|
| 1015 | + } |
|
| 1016 | + } |
|
| 1017 | + } |
|
| 1018 | + spip_mysql_free($res); |
|
| 1019 | + |
|
| 1020 | + return ['field' => $nfields, 'key' => $nkeys]; |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + return ''; |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | |
@@ -1039,13 +1039,13 @@ discard block |
||
| 1039 | 1039 | * - false Erreur |
| 1040 | 1040 | */ |
| 1041 | 1041 | function spip_mysql_fetch($r, $t = '', $serveur = '', $requeter = true) { |
| 1042 | - if (!$t) { |
|
| 1043 | - $t = \MYSQLI_ASSOC; |
|
| 1044 | - } |
|
| 1045 | - if ($r) { |
|
| 1046 | - return mysqli_fetch_array($r, $t); |
|
| 1047 | - } |
|
| 1048 | - return false; |
|
| 1042 | + if (!$t) { |
|
| 1043 | + $t = \MYSQLI_ASSOC; |
|
| 1044 | + } |
|
| 1045 | + if ($r) { |
|
| 1046 | + return mysqli_fetch_array($r, $t); |
|
| 1047 | + } |
|
| 1048 | + return false; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | /** |
@@ -1058,10 +1058,10 @@ discard block |
||
| 1058 | 1058 | * @return bool True si déplacement réussi, false sinon. |
| 1059 | 1059 | **/ |
| 1060 | 1060 | function spip_mysql_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 1061 | - if ($r and mysqli_num_rows($r)) { |
|
| 1062 | - return mysqli_data_seek($r, $row_number); |
|
| 1063 | - } |
|
| 1064 | - return false; |
|
| 1061 | + if ($r and mysqli_num_rows($r)) { |
|
| 1062 | + return mysqli_data_seek($r, $row_number); |
|
| 1063 | + } |
|
| 1064 | + return false; |
|
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | 1067 | |
@@ -1079,26 +1079,26 @@ discard block |
||
| 1079 | 1079 | * - int Nombre de lignes (0 si la requête n'a pas réussie) |
| 1080 | 1080 | **/ |
| 1081 | 1081 | function spip_mysql_countsel( |
| 1082 | - $from = [], |
|
| 1083 | - $where = [], |
|
| 1084 | - $groupby = '', |
|
| 1085 | - $having = [], |
|
| 1086 | - $serveur = '', |
|
| 1087 | - $requeter = true |
|
| 1082 | + $from = [], |
|
| 1083 | + $where = [], |
|
| 1084 | + $groupby = '', |
|
| 1085 | + $having = [], |
|
| 1086 | + $serveur = '', |
|
| 1087 | + $requeter = true |
|
| 1088 | 1088 | ) { |
| 1089 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1090 | - |
|
| 1091 | - $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1092 | - if (!$requeter) { |
|
| 1093 | - return $r; |
|
| 1094 | - } |
|
| 1095 | - if (!$r instanceof mysqli_result) { |
|
| 1096 | - return 0; |
|
| 1097 | - } |
|
| 1098 | - [$c] = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1099 | - mysqli_free_result($r); |
|
| 1100 | - |
|
| 1101 | - return intval($c); |
|
| 1089 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1090 | + |
|
| 1091 | + $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1092 | + if (!$requeter) { |
|
| 1093 | + return $r; |
|
| 1094 | + } |
|
| 1095 | + if (!$r instanceof mysqli_result) { |
|
| 1096 | + return 0; |
|
| 1097 | + } |
|
| 1098 | + [$c] = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1099 | + mysqli_free_result($r); |
|
| 1100 | + |
|
| 1101 | + return intval($c); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | |
@@ -1121,16 +1121,16 @@ discard block |
||
| 1121 | 1121 | * Erreur eventuelle |
| 1122 | 1122 | **/ |
| 1123 | 1123 | function spip_mysql_error($query = '', $serveur = '', $requeter = true) { |
| 1124 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1125 | - $s = mysqli_error($link); |
|
| 1126 | - if ($s) { |
|
| 1127 | - $trace = debug_backtrace(); |
|
| 1128 | - if ($trace[0]['function'] != 'spip_mysql_error') { |
|
| 1129 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1130 | - } |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - return $s; |
|
| 1124 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1125 | + $s = mysqli_error($link); |
|
| 1126 | + if ($s) { |
|
| 1127 | + $trace = debug_backtrace(); |
|
| 1128 | + if ($trace[0]['function'] != 'spip_mysql_error') { |
|
| 1129 | + spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1130 | + } |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + return $s; |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | |
@@ -1145,18 +1145,18 @@ discard block |
||
| 1145 | 1145 | * 0, pas d'erreur. Autre, numéro de l'erreur. |
| 1146 | 1146 | **/ |
| 1147 | 1147 | function spip_mysql_errno($serveur = '', $requeter = true) { |
| 1148 | - $link = $GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 1149 | - $s = mysqli_errno($link); |
|
| 1150 | - // 2006 MySQL server has gone away |
|
| 1151 | - // 2013 Lost connection to MySQL server during query |
|
| 1152 | - if (in_array($s, [2006, 2013])) { |
|
| 1153 | - define('spip_interdire_cache', true); |
|
| 1154 | - } |
|
| 1155 | - if ($s) { |
|
| 1156 | - spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - return $s; |
|
| 1148 | + $link = $GLOBALS['connexions'][$serveur ?: 0]['link']; |
|
| 1149 | + $s = mysqli_errno($link); |
|
| 1150 | + // 2006 MySQL server has gone away |
|
| 1151 | + // 2013 Lost connection to MySQL server during query |
|
| 1152 | + if (in_array($s, [2006, 2013])) { |
|
| 1153 | + define('spip_interdire_cache', true); |
|
| 1154 | + } |
|
| 1155 | + if ($s) { |
|
| 1156 | + spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + return $s; |
|
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | |
@@ -1170,9 +1170,9 @@ discard block |
||
| 1170 | 1170 | * @return int Nombre de lignes |
| 1171 | 1171 | */ |
| 1172 | 1172 | function spip_mysql_count($r, $serveur = '', $requeter = true) { |
| 1173 | - if ($r) { |
|
| 1174 | - return mysqli_num_rows($r); |
|
| 1175 | - } |
|
| 1173 | + if ($r) { |
|
| 1174 | + return mysqli_num_rows($r); |
|
| 1175 | + } |
|
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | |
@@ -1188,11 +1188,11 @@ discard block |
||
| 1188 | 1188 | * @return bool True si réussi |
| 1189 | 1189 | */ |
| 1190 | 1190 | function spip_mysql_free($r, $serveur = '', $requeter = true) { |
| 1191 | - if ($r instanceof mysqli_result) { |
|
| 1192 | - mysqli_free_result($r); |
|
| 1193 | - return true; |
|
| 1194 | - } |
|
| 1195 | - return false; |
|
| 1191 | + if ($r instanceof mysqli_result) { |
|
| 1192 | + mysqli_free_result($r); |
|
| 1193 | + return true; |
|
| 1194 | + } |
|
| 1195 | + return false; |
|
| 1196 | 1196 | } |
| 1197 | 1197 | |
| 1198 | 1198 | |
@@ -1220,59 +1220,59 @@ discard block |
||
| 1220 | 1220 | **/ |
| 1221 | 1221 | function spip_mysql_insert($table, $champs, $valeurs, $desc = [], $serveur = '', $requeter = true) { |
| 1222 | 1222 | |
| 1223 | - $e = null; |
|
| 1224 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1225 | - $link = $connexion['link']; |
|
| 1226 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1227 | - |
|
| 1228 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1229 | - if ( |
|
| 1230 | - defined('_MYSQL_NOPLANES') |
|
| 1231 | - and _MYSQL_NOPLANES |
|
| 1232 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1233 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 1234 | - ) { |
|
| 1235 | - include_spip('inc/charsets'); |
|
| 1236 | - $valeurs = utf8_noplanes($valeurs); |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1240 | - if (!$requeter) { |
|
| 1241 | - return $query; |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - if (isset($_GET['var_profile'])) { |
|
| 1245 | - include_spip('public/tracer'); |
|
| 1246 | - $t = trace_query_start(); |
|
| 1247 | - $e = ''; |
|
| 1248 | - } else { |
|
| 1249 | - $t = 0; |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - $connexion['last'] = $query; |
|
| 1253 | - #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1254 | - $r = false; |
|
| 1255 | - $insert = false; |
|
| 1256 | - try { |
|
| 1257 | - $insert = mysqli_query($link, $query); |
|
| 1258 | - } catch (\mysqli_sql_exception $e) { |
|
| 1259 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 1260 | - // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 1261 | - // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 1262 | - } |
|
| 1263 | - if ($insert) { |
|
| 1264 | - $r = mysqli_insert_id($link); |
|
| 1265 | - } else { |
|
| 1266 | - // Log de l'erreur eventuelle |
|
| 1267 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 1268 | - // et du fautif |
|
| 1269 | - $e .= spip_mysql_error($query, $serveur); |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1274 | - |
|
| 1275 | - // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1223 | + $e = null; |
|
| 1224 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1225 | + $link = $connexion['link']; |
|
| 1226 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1227 | + |
|
| 1228 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1229 | + if ( |
|
| 1230 | + defined('_MYSQL_NOPLANES') |
|
| 1231 | + and _MYSQL_NOPLANES |
|
| 1232 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1233 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 1234 | + ) { |
|
| 1235 | + include_spip('inc/charsets'); |
|
| 1236 | + $valeurs = utf8_noplanes($valeurs); |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1240 | + if (!$requeter) { |
|
| 1241 | + return $query; |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + if (isset($_GET['var_profile'])) { |
|
| 1245 | + include_spip('public/tracer'); |
|
| 1246 | + $t = trace_query_start(); |
|
| 1247 | + $e = ''; |
|
| 1248 | + } else { |
|
| 1249 | + $t = 0; |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + $connexion['last'] = $query; |
|
| 1253 | + #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1254 | + $r = false; |
|
| 1255 | + $insert = false; |
|
| 1256 | + try { |
|
| 1257 | + $insert = mysqli_query($link, $query); |
|
| 1258 | + } catch (\mysqli_sql_exception $e) { |
|
| 1259 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 1260 | + // TODO: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 1261 | + // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 1262 | + } |
|
| 1263 | + if ($insert) { |
|
| 1264 | + $r = mysqli_insert_id($link); |
|
| 1265 | + } else { |
|
| 1266 | + // Log de l'erreur eventuelle |
|
| 1267 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 1268 | + // et du fautif |
|
| 1269 | + $e .= spip_mysql_error($query, $serveur); |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1274 | + |
|
| 1275 | + // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1276 | 1276 | } |
| 1277 | 1277 | |
| 1278 | 1278 | /** |
@@ -1297,26 +1297,26 @@ discard block |
||
| 1297 | 1297 | **/ |
| 1298 | 1298 | function spip_mysql_insertq($table, $couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 1299 | 1299 | |
| 1300 | - if (!$desc) { |
|
| 1301 | - $desc = description_table($table, $serveur); |
|
| 1302 | - } |
|
| 1303 | - if (!$desc) { |
|
| 1304 | - $couples = []; |
|
| 1305 | - } |
|
| 1306 | - $fields = $desc['field'] ?? []; |
|
| 1307 | - |
|
| 1308 | - foreach ($couples as $champ => $val) { |
|
| 1309 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - return spip_mysql_insert( |
|
| 1313 | - $table, |
|
| 1314 | - '(' . join(',', array_keys($couples)) . ')', |
|
| 1315 | - '(' . join(',', $couples) . ')', |
|
| 1316 | - $desc, |
|
| 1317 | - $serveur, |
|
| 1318 | - $requeter |
|
| 1319 | - ); |
|
| 1300 | + if (!$desc) { |
|
| 1301 | + $desc = description_table($table, $serveur); |
|
| 1302 | + } |
|
| 1303 | + if (!$desc) { |
|
| 1304 | + $couples = []; |
|
| 1305 | + } |
|
| 1306 | + $fields = $desc['field'] ?? []; |
|
| 1307 | + |
|
| 1308 | + foreach ($couples as $champ => $val) { |
|
| 1309 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + return spip_mysql_insert( |
|
| 1313 | + $table, |
|
| 1314 | + '(' . join(',', array_keys($couples)) . ')', |
|
| 1315 | + '(' . join(',', $couples) . ')', |
|
| 1316 | + $desc, |
|
| 1317 | + $serveur, |
|
| 1318 | + $requeter |
|
| 1319 | + ); |
|
| 1320 | 1320 | } |
| 1321 | 1321 | |
| 1322 | 1322 | |
@@ -1341,34 +1341,34 @@ discard block |
||
| 1341 | 1341 | **/ |
| 1342 | 1342 | function spip_mysql_insertq_multi($table, $tab_couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 1343 | 1343 | |
| 1344 | - if (!$desc) { |
|
| 1345 | - $desc = description_table($table, $serveur); |
|
| 1346 | - } |
|
| 1347 | - if (!$desc) { |
|
| 1348 | - $tab_couples = []; |
|
| 1349 | - } |
|
| 1350 | - $fields = $desc['field'] ?? []; |
|
| 1351 | - |
|
| 1352 | - $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1353 | - $valeurs = []; |
|
| 1354 | - $r = false; |
|
| 1355 | - |
|
| 1356 | - // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1357 | - foreach ($tab_couples as $couples) { |
|
| 1358 | - foreach ($couples as $champ => $val) { |
|
| 1359 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1360 | - } |
|
| 1361 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1362 | - if (count($valeurs) >= 100) { |
|
| 1363 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1364 | - $valeurs = []; |
|
| 1365 | - } |
|
| 1366 | - } |
|
| 1367 | - if (count($valeurs)) { |
|
| 1368 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1344 | + if (!$desc) { |
|
| 1345 | + $desc = description_table($table, $serveur); |
|
| 1346 | + } |
|
| 1347 | + if (!$desc) { |
|
| 1348 | + $tab_couples = []; |
|
| 1349 | + } |
|
| 1350 | + $fields = $desc['field'] ?? []; |
|
| 1351 | + |
|
| 1352 | + $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1353 | + $valeurs = []; |
|
| 1354 | + $r = false; |
|
| 1355 | + |
|
| 1356 | + // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1357 | + foreach ($tab_couples as $couples) { |
|
| 1358 | + foreach ($couples as $champ => $val) { |
|
| 1359 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1360 | + } |
|
| 1361 | + $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1362 | + if (count($valeurs) >= 100) { |
|
| 1363 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1364 | + $valeurs = []; |
|
| 1365 | + } |
|
| 1366 | + } |
|
| 1367 | + if (count($valeurs)) { |
|
| 1368 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | 1374 | /** |
@@ -1393,20 +1393,20 @@ discard block |
||
| 1393 | 1393 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 1394 | 1394 | */ |
| 1395 | 1395 | function spip_mysql_update($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1396 | - $set = []; |
|
| 1397 | - foreach ($champs as $champ => $val) { |
|
| 1398 | - $set[] = $champ . "=$val"; |
|
| 1399 | - } |
|
| 1400 | - if (!empty($set)) { |
|
| 1401 | - return spip_mysql_query( |
|
| 1402 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1403 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1404 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1405 | - $serveur, |
|
| 1406 | - $requeter |
|
| 1407 | - ); |
|
| 1408 | - } |
|
| 1409 | - return false; |
|
| 1396 | + $set = []; |
|
| 1397 | + foreach ($champs as $champ => $val) { |
|
| 1398 | + $set[] = $champ . "=$val"; |
|
| 1399 | + } |
|
| 1400 | + if (!empty($set)) { |
|
| 1401 | + return spip_mysql_query( |
|
| 1402 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1403 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1404 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1405 | + $serveur, |
|
| 1406 | + $requeter |
|
| 1407 | + ); |
|
| 1408 | + } |
|
| 1409 | + return false; |
|
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | /** |
@@ -1439,29 +1439,29 @@ discard block |
||
| 1439 | 1439 | */ |
| 1440 | 1440 | function spip_mysql_updateq($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1441 | 1441 | |
| 1442 | - if (!$champs) { |
|
| 1443 | - return; |
|
| 1444 | - } |
|
| 1445 | - if (!$desc) { |
|
| 1446 | - $desc = description_table($table, $serveur); |
|
| 1447 | - } |
|
| 1448 | - if (!$desc) { |
|
| 1449 | - $champs = []; |
|
| 1450 | - } else { |
|
| 1451 | - $fields = $desc['field']; |
|
| 1452 | - } |
|
| 1453 | - $set = []; |
|
| 1454 | - foreach ($champs as $champ => $val) { |
|
| 1455 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - return spip_mysql_query( |
|
| 1459 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1460 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1461 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1462 | - $serveur, |
|
| 1463 | - $requeter |
|
| 1464 | - ); |
|
| 1442 | + if (!$champs) { |
|
| 1443 | + return; |
|
| 1444 | + } |
|
| 1445 | + if (!$desc) { |
|
| 1446 | + $desc = description_table($table, $serveur); |
|
| 1447 | + } |
|
| 1448 | + if (!$desc) { |
|
| 1449 | + $champs = []; |
|
| 1450 | + } else { |
|
| 1451 | + $fields = $desc['field']; |
|
| 1452 | + } |
|
| 1453 | + $set = []; |
|
| 1454 | + foreach ($champs as $champ => $val) { |
|
| 1455 | + $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + return spip_mysql_query( |
|
| 1459 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1460 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1461 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1462 | + $serveur, |
|
| 1463 | + $requeter |
|
| 1464 | + ); |
|
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | 1467 | /** |
@@ -1477,22 +1477,22 @@ discard block |
||
| 1477 | 1477 | * - false en cas d'erreur. |
| 1478 | 1478 | **/ |
| 1479 | 1479 | function spip_mysql_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 1480 | - $res = spip_mysql_query( |
|
| 1481 | - calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1482 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1483 | - $serveur, |
|
| 1484 | - $requeter |
|
| 1485 | - ); |
|
| 1486 | - if (!$requeter) { |
|
| 1487 | - return $res; |
|
| 1488 | - } |
|
| 1489 | - if ($res) { |
|
| 1490 | - $link = _mysql_link($serveur); |
|
| 1491 | - |
|
| 1492 | - return mysqli_affected_rows($link); |
|
| 1493 | - } else { |
|
| 1494 | - return false; |
|
| 1495 | - } |
|
| 1480 | + $res = spip_mysql_query( |
|
| 1481 | + calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1482 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1483 | + $serveur, |
|
| 1484 | + $requeter |
|
| 1485 | + ); |
|
| 1486 | + if (!$requeter) { |
|
| 1487 | + return $res; |
|
| 1488 | + } |
|
| 1489 | + if ($res) { |
|
| 1490 | + $link = _mysql_link($serveur); |
|
| 1491 | + |
|
| 1492 | + return mysqli_affected_rows($link); |
|
| 1493 | + } else { |
|
| 1494 | + return false; |
|
| 1495 | + } |
|
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | 1498 | |
@@ -1521,10 +1521,10 @@ discard block |
||
| 1521 | 1521 | * - false en cas d'erreur. |
| 1522 | 1522 | **/ |
| 1523 | 1523 | function spip_mysql_replace($table, $couples, $desc = [], $serveur = '', $requeter = true) { |
| 1524 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1525 | - ',', |
|
| 1526 | - array_map('_q', $couples) |
|
| 1527 | - ) . ')', $serveur, $requeter); |
|
| 1524 | + return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1525 | + ',', |
|
| 1526 | + array_map('_q', $couples) |
|
| 1527 | + ) . ')', $serveur, $requeter); |
|
| 1528 | 1528 | } |
| 1529 | 1529 | |
| 1530 | 1530 | |
@@ -1553,14 +1553,14 @@ discard block |
||
| 1553 | 1553 | * - false en cas d'erreur. |
| 1554 | 1554 | **/ |
| 1555 | 1555 | function spip_mysql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $requeter = true) { |
| 1556 | - $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1557 | - $valeurs = []; |
|
| 1558 | - foreach ($tab_couples as $couples) { |
|
| 1559 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1560 | - } |
|
| 1561 | - $valeurs = implode(', ', $valeurs); |
|
| 1562 | - |
|
| 1563 | - return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1556 | + $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1557 | + $valeurs = []; |
|
| 1558 | + foreach ($tab_couples as $couples) { |
|
| 1559 | + $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1560 | + } |
|
| 1561 | + $valeurs = implode(', ', $valeurs); |
|
| 1562 | + |
|
| 1563 | + return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | 1566 | |
@@ -1575,32 +1575,32 @@ discard block |
||
| 1575 | 1575 | * @return string texte de sélection pour la requête |
| 1576 | 1576 | */ |
| 1577 | 1577 | function spip_mysql_multi($objet, $lang) { |
| 1578 | - $lengthlang = strlen("[$lang]"); |
|
| 1579 | - $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1580 | - $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1581 | - $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1582 | - $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1583 | - $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1584 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1585 | - $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1586 | - $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1587 | - $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1588 | - $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1589 | - //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1590 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1591 | - ' TRIM(' . $objet . '), ' . |
|
| 1592 | - ' CONCAT( ' . |
|
| 1593 | - " $debutchaine, " . |
|
| 1594 | - ' IF( ' . |
|
| 1595 | - " $poslang = 0, " . |
|
| 1596 | - " $chainemulti, " . |
|
| 1597 | - " $chainelang" . |
|
| 1598 | - ' ), ' . |
|
| 1599 | - " $finchaine" . |
|
| 1600 | - ' ) ' . |
|
| 1601 | - '))) AS multi'; |
|
| 1602 | - |
|
| 1603 | - return $retour; |
|
| 1578 | + $lengthlang = strlen("[$lang]"); |
|
| 1579 | + $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1580 | + $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1581 | + $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1582 | + $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1583 | + $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1584 | + $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1585 | + $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1586 | + $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1587 | + $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1588 | + $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1589 | + //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1590 | + $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1591 | + ' TRIM(' . $objet . '), ' . |
|
| 1592 | + ' CONCAT( ' . |
|
| 1593 | + " $debutchaine, " . |
|
| 1594 | + ' IF( ' . |
|
| 1595 | + " $poslang = 0, " . |
|
| 1596 | + " $chainemulti, " . |
|
| 1597 | + " $chainelang" . |
|
| 1598 | + ' ), ' . |
|
| 1599 | + " $finchaine" . |
|
| 1600 | + ' ) ' . |
|
| 1601 | + '))) AS multi'; |
|
| 1602 | + |
|
| 1603 | + return $retour; |
|
| 1604 | 1604 | } |
| 1605 | 1605 | |
| 1606 | 1606 | /** |
@@ -1614,7 +1614,7 @@ discard block |
||
| 1614 | 1614 | * Valeur hexadécimale pour MySQL |
| 1615 | 1615 | **/ |
| 1616 | 1616 | function spip_mysql_hex($v) { |
| 1617 | - return '0x' . $v; |
|
| 1617 | + return '0x' . $v; |
|
| 1618 | 1618 | } |
| 1619 | 1619 | |
| 1620 | 1620 | /** |
@@ -1630,15 +1630,15 @@ discard block |
||
| 1630 | 1630 | * Donnée prête à être utilisée par le gestionnaire SQL |
| 1631 | 1631 | */ |
| 1632 | 1632 | function spip_mysql_quote($v, $type = '') { |
| 1633 | - if (!is_array($v)) { |
|
| 1634 | - return spip_mysql_cite($v, $type); |
|
| 1635 | - } |
|
| 1636 | - |
|
| 1637 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1638 | - foreach ($v as $k => $r) { |
|
| 1639 | - $v[$k] = spip_mysql_quote($r, $type); |
|
| 1640 | - } |
|
| 1641 | - return implode(',', $v); |
|
| 1633 | + if (!is_array($v)) { |
|
| 1634 | + return spip_mysql_cite($v, $type); |
|
| 1635 | + } |
|
| 1636 | + |
|
| 1637 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1638 | + foreach ($v as $k => $r) { |
|
| 1639 | + $v[$k] = spip_mysql_quote($r, $type); |
|
| 1640 | + } |
|
| 1641 | + return implode(',', $v); |
|
| 1642 | 1642 | } |
| 1643 | 1643 | |
| 1644 | 1644 | /** |
@@ -1654,18 +1654,18 @@ discard block |
||
| 1654 | 1654 | * Expression SQL |
| 1655 | 1655 | **/ |
| 1656 | 1656 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1657 | - $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1658 | - return '(' |
|
| 1659 | - . $champ |
|
| 1660 | - . (($interval <= 0) ? '>' : '<') |
|
| 1661 | - . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1662 | - . '(' |
|
| 1663 | - . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1664 | - . ', INTERVAL ' |
|
| 1665 | - . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1666 | - . ' ' |
|
| 1667 | - . $unite |
|
| 1668 | - . '))'; |
|
| 1657 | + $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1658 | + return '(' |
|
| 1659 | + . $champ |
|
| 1660 | + . (($interval <= 0) ? '>' : '<') |
|
| 1661 | + . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1662 | + . '(' |
|
| 1663 | + . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1664 | + . ', INTERVAL ' |
|
| 1665 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1666 | + . ' ' |
|
| 1667 | + . $unite |
|
| 1668 | + . '))'; |
|
| 1669 | 1669 | } |
| 1670 | 1670 | |
| 1671 | 1671 | |
@@ -1689,7 +1689,7 @@ discard block |
||
| 1689 | 1689 | * Expression de requête SQL |
| 1690 | 1690 | **/ |
| 1691 | 1691 | function spip_mysql_in($val, $valeurs, $not = '', $serveur = '', $requeter = true) { |
| 1692 | - return "($val $not IN ($valeurs))"; |
|
| 1692 | + return "($val $not IN ($valeurs))"; |
|
| 1693 | 1693 | } |
| 1694 | 1694 | |
| 1695 | 1695 | |
@@ -1701,39 +1701,39 @@ discard block |
||
| 1701 | 1701 | * @return string|number texte ou nombre échappé |
| 1702 | 1702 | */ |
| 1703 | 1703 | function spip_mysql_cite($v, $type) { |
| 1704 | - if (!$type) { |
|
| 1705 | - if (is_bool($v)) { |
|
| 1706 | - return strval(intval($v)); |
|
| 1707 | - } elseif (is_numeric($v)) { |
|
| 1708 | - return strval($v); |
|
| 1709 | - } elseif ($v === null) { |
|
| 1710 | - return "''"; |
|
| 1711 | - } |
|
| 1712 | - return "'" . addslashes($v) . "'"; |
|
| 1713 | - } |
|
| 1714 | - |
|
| 1715 | - if ($v === null) { |
|
| 1716 | - if (stripos($type, 'NOT NULL') === false) { |
|
| 1717 | - // null php se traduit en NULL SQL |
|
| 1718 | - return 'NULL'; |
|
| 1719 | - } else { |
|
| 1720 | - return "''"; |
|
| 1721 | - } |
|
| 1722 | - } elseif (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1723 | - return $v; |
|
| 1724 | - } elseif (sql_test_int($type)) { |
|
| 1725 | - if ( |
|
| 1726 | - is_numeric($v) |
|
| 1727 | - or ($v and ctype_xdigit(substr($v, 2)) and $v[0] === '0' and $v[1] === 'x') |
|
| 1728 | - ) { |
|
| 1729 | - return $v; |
|
| 1730 | - } else { |
|
| 1731 | - // si pas numerique, forcer le intval |
|
| 1732 | - return intval($v); |
|
| 1733 | - } |
|
| 1734 | - } |
|
| 1735 | - |
|
| 1736 | - return ("'" . addslashes($v) . "'"); |
|
| 1704 | + if (!$type) { |
|
| 1705 | + if (is_bool($v)) { |
|
| 1706 | + return strval(intval($v)); |
|
| 1707 | + } elseif (is_numeric($v)) { |
|
| 1708 | + return strval($v); |
|
| 1709 | + } elseif ($v === null) { |
|
| 1710 | + return "''"; |
|
| 1711 | + } |
|
| 1712 | + return "'" . addslashes($v) . "'"; |
|
| 1713 | + } |
|
| 1714 | + |
|
| 1715 | + if ($v === null) { |
|
| 1716 | + if (stripos($type, 'NOT NULL') === false) { |
|
| 1717 | + // null php se traduit en NULL SQL |
|
| 1718 | + return 'NULL'; |
|
| 1719 | + } else { |
|
| 1720 | + return "''"; |
|
| 1721 | + } |
|
| 1722 | + } elseif (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1723 | + return $v; |
|
| 1724 | + } elseif (sql_test_int($type)) { |
|
| 1725 | + if ( |
|
| 1726 | + is_numeric($v) |
|
| 1727 | + or ($v and ctype_xdigit(substr($v, 2)) and $v[0] === '0' and $v[1] === 'x') |
|
| 1728 | + ) { |
|
| 1729 | + return $v; |
|
| 1730 | + } else { |
|
| 1731 | + // si pas numerique, forcer le intval |
|
| 1732 | + return intval($v); |
|
| 1733 | + } |
|
| 1734 | + } |
|
| 1735 | + |
|
| 1736 | + return ("'" . addslashes($v) . "'"); |
|
| 1737 | 1737 | } |
| 1738 | 1738 | |
| 1739 | 1739 | /** |
@@ -1743,7 +1743,7 @@ discard block |
||
| 1743 | 1743 | * True si on a les fonctions, false sinon |
| 1744 | 1744 | */ |
| 1745 | 1745 | function spip_versions_mysql() { |
| 1746 | - return function_exists('mysqli_query'); |
|
| 1746 | + return function_exists('mysqli_query'); |
|
| 1747 | 1747 | } |
| 1748 | 1748 | |
| 1749 | 1749 | |
@@ -1756,20 +1756,20 @@ discard block |
||
| 1756 | 1756 | * - chaîne : code compilé pour le faire désactiver par SPIP sinon |
| 1757 | 1757 | */ |
| 1758 | 1758 | function test_rappel_nom_base_mysql($server_db) { |
| 1759 | - $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1760 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1761 | - $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1759 | + $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1760 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1761 | + $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1762 | 1762 | |
| 1763 | - if ($ok) { |
|
| 1764 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1763 | + if ($ok) { |
|
| 1764 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1765 | 1765 | |
| 1766 | - return ''; |
|
| 1767 | - } else { |
|
| 1768 | - $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1766 | + return ''; |
|
| 1767 | + } else { |
|
| 1768 | + $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1769 | 1769 | |
| 1770 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1771 | - "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1772 | - } |
|
| 1770 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1771 | + "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1772 | + } |
|
| 1773 | 1773 | } |
| 1774 | 1774 | |
| 1775 | 1775 | /** |
@@ -1783,13 +1783,13 @@ discard block |
||
| 1783 | 1783 | * - chaîne : code compilé pour l'indiquer le résultat du test à SPIP |
| 1784 | 1784 | */ |
| 1785 | 1785 | function test_sql_mode_mysql($server_db) { |
| 1786 | - $res = sql_select('version() as v', '', '', '', '', '', '', $server_db); |
|
| 1787 | - $row = sql_fetch($res, $server_db); |
|
| 1788 | - if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1789 | - defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1786 | + $res = sql_select('version() as v', '', '', '', '', '', '', $server_db); |
|
| 1787 | + $row = sql_fetch($res, $server_db); |
|
| 1788 | + if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1789 | + defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1790 | 1790 | |
| 1791 | - return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1792 | - } |
|
| 1791 | + return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1792 | + } |
|
| 1793 | 1793 | |
| 1794 | - return ''; |
|
| 1794 | + return ''; |
|
| 1795 | 1795 | } |
@@ -63,9 +63,9 @@ |
||
| 63 | 63 | $f = new IndenteurXML(); |
| 64 | 64 | $sax($page, $apply, $f); |
| 65 | 65 | if (!$f->err) { |
| 66 | - return $f->entete . $f->res; |
|
| 66 | + return $f->entete.$f->res; |
|
| 67 | 67 | } |
| 68 | - spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 68 | + spip_log('indentation impossible '.(is_countable($f->err) ? count($f->err) : 0).' erreurs de validation'); |
|
| 69 | 69 | |
| 70 | - return $f->entete . $f->page; |
|
| 70 | + return $f->entete.$f->page; |
|
| 71 | 71 | } |
@@ -10,54 +10,54 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | class IndenteurXML { |
| 17 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 18 | - xml_debutElement($this, $name, $attrs); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - public function finElement($phraseur, $name) { |
|
| 22 | - xml_finElement($this, $name); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public function textElement($phraseur, $data) { |
|
| 26 | - xml_textElement($this, $data); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function piElement($phraseur, $target, $data) { |
|
| 30 | - xml_PiElement($this, $target, $data); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - public function defaultElement($phraseur, $data) { |
|
| 34 | - xml_defaultElement($this, $data); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function phraserTout($phraseur, $data) { |
|
| 38 | - xml_parsestring($this, $data); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public $depth = ''; |
|
| 42 | - public $res = ''; |
|
| 43 | - public $err = []; |
|
| 44 | - public $contenu = []; |
|
| 45 | - public $ouvrant = []; |
|
| 46 | - public $reperes = []; |
|
| 47 | - public $entete = ''; |
|
| 48 | - public $page = ''; |
|
| 49 | - public $dtc = null; |
|
| 50 | - public $sax = null; |
|
| 17 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 18 | + xml_debutElement($this, $name, $attrs); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + public function finElement($phraseur, $name) { |
|
| 22 | + xml_finElement($this, $name); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public function textElement($phraseur, $data) { |
|
| 26 | + xml_textElement($this, $data); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function piElement($phraseur, $target, $data) { |
|
| 30 | + xml_PiElement($this, $target, $data); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + public function defaultElement($phraseur, $data) { |
|
| 34 | + xml_defaultElement($this, $data); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function phraserTout($phraseur, $data) { |
|
| 38 | + xml_parsestring($this, $data); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public $depth = ''; |
|
| 42 | + public $res = ''; |
|
| 43 | + public $err = []; |
|
| 44 | + public $contenu = []; |
|
| 45 | + public $ouvrant = []; |
|
| 46 | + public $reperes = []; |
|
| 47 | + public $entete = ''; |
|
| 48 | + public $page = ''; |
|
| 49 | + public $dtc = null; |
|
| 50 | + public $sax = null; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | function xml_indenter_dist($page, $apply = false) { |
| 54 | - $sax = charger_fonction('sax', 'xml'); |
|
| 55 | - $f = new IndenteurXML(); |
|
| 56 | - $sax($page, $apply, $f); |
|
| 57 | - if (!$f->err) { |
|
| 58 | - return $f->entete . $f->res; |
|
| 59 | - } |
|
| 60 | - spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 61 | - |
|
| 62 | - return $f->entete . $f->page; |
|
| 54 | + $sax = charger_fonction('sax', 'xml'); |
|
| 55 | + $f = new IndenteurXML(); |
|
| 56 | + $sax($page, $apply, $f); |
|
| 57 | + if (!$f->err) { |
|
| 58 | + return $f->entete . $f->res; |
|
| 59 | + } |
|
| 60 | + spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 61 | + |
|
| 62 | + return $f->entete . $f->page; |
|
| 63 | 63 | } |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | " class='picto_err'", |
| 64 | 64 | _T('plugin_info_erreur_xml') |
| 65 | 65 | ) |
| 66 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>'; |
|
| 66 | + . "<div class='erreur'>".join('<br >', $info['erreur']).'</div>'; |
|
| 67 | 67 | $checkable = false; |
| 68 | - } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 68 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])) { |
|
| 69 | 69 | $class_li .= ' error'; |
| 70 | 70 | $erreur = http_img_pack( |
| 71 | 71 | 'plugin-err-32.png', |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | " class='picto_err'", |
| 74 | 74 | _T('plugin_impossible_activer', ['plugin' => $nom]) |
| 75 | 75 | ) |
| 76 | - . "<div class='erreur'>" . implode( |
|
| 76 | + . "<div class='erreur'>".implode( |
|
| 77 | 77 | '<br />', |
| 78 | - $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file] |
|
| 79 | - ) . '</div>'; |
|
| 78 | + $GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file] |
|
| 79 | + ).'</div>'; |
|
| 80 | 80 | } else { |
| 81 | 81 | $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ''; |
| 82 | 82 | if (defined('_DEV_VERSION_SPIP_COMPAT') and !plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'])) { |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | // numerotons les occurrences d'un meme prefix |
| 94 | 94 | $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
| 95 | 95 | |
| 96 | - $class_li .= ($actif ? ' actif' : '') . ($expose ? ' on' : ''); |
|
| 96 | + $class_li .= ($actif ? ' actif' : '').($expose ? ' on' : ''); |
|
| 97 | 97 | |
| 98 | 98 | return "<li id='$prefix$id' class='$class_li'>" |
| 99 | 99 | . ((!$checkable and !$checked) |
| 100 | - ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 100 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins.$plug_file, $checked)) |
|
| 101 | 101 | . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
| 102 | 102 | . $cfg |
| 103 | 103 | . $erreur |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | // si paquet.xml fournit un squelette, le prendre |
| 117 | 117 | if (isset($infos['config']) and $infos['config']) { |
| 118 | 118 | return recuperer_fond( |
| 119 | - "$dir$nom/" . $infos['config'], |
|
| 119 | + "$dir$nom/".$infos['config'], |
|
| 120 | 120 | [ |
| 121 | - 'script' => 'configurer_' . $prefix, |
|
| 121 | + 'script' => 'configurer_'.$prefix, |
|
| 122 | 122 | 'nom' => $nom |
| 123 | 123 | ] |
| 124 | 124 | ); |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | return recuperer_fond( |
| 138 | 138 | 'prive/squelettes/inclure/cfg', |
| 139 | 139 | [ |
| 140 | - 'script' => 'configurer_' . $prefix, |
|
| 140 | + 'script' => 'configurer_'.$prefix, |
|
| 141 | 141 | 'nom' => $nom |
| 142 | 142 | ] |
| 143 | 143 | ); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | . "<input type='checkbox' name='s$name' id='label_$id_input'" |
| 154 | 154 | . ($actif ? " checked='checked'" : '') |
| 155 | 155 | . " class='checkbox' value='O' />" |
| 156 | - . "\n<label for='label_$id_input'>" . _T('activer_plugin') . '</label>' |
|
| 156 | + . "\n<label for='label_$id_input'>"._T('activer_plugin').'</label>' |
|
| 157 | 157 | . '</div>'; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | . "<h3><a href='$url' rel='info'>" |
| 209 | 209 | . $nom |
| 210 | 210 | . '</a></h3>' |
| 211 | - . " <span class='version'>" . $info['version'] . '</span>' |
|
| 211 | + . " <span class='version'>".$info['version'].'</span>' |
|
| 212 | 212 | . " <span class='etat'> - " |
| 213 | 213 | . plugin_etat_en_clair($info['etat']) |
| 214 | 214 | . '</span>' |
| 215 | - . "<div class='short'>" . $slogan . '</div>' |
|
| 215 | + . "<div class='short'>".$slogan.'</div>' |
|
| 216 | 216 | . $i |
| 217 | 217 | . '</div>'; |
| 218 | 218 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | $text2 = _T('info_desinstaller_plugin'); |
| 228 | 228 | $file = basename($plug_file); |
| 229 | 229 | |
| 230 | - return "<div class='actions'>[" . |
|
| 230 | + return "<div class='actions'>[". |
|
| 231 | 231 | "<a href='$action' |
| 232 | 232 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 233 | 233 | . $text |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | $etat = 'developpement'; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - return _T('plugin_etat_' . $etat); |
|
| 252 | + return _T('plugin_etat_'.$etat); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | function plugin_propre($texte, $module = '', $propre = 'propre') { |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | $module = substr($module, strlen(_DIR_RACINE)); |
| 259 | 259 | } |
| 260 | 260 | if (preg_match('|^\w+_[\w_]+$|', $texte)) { |
| 261 | - $texte = _T(($module ? "$module:" : '') . $texte, [], ['force' => false]); |
|
| 261 | + $texte = _T(($module ? "$module:" : '').$texte, [], ['force' => false]); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | return $propre($texte); |
@@ -291,9 +291,9 @@ discard block |
||
| 291 | 291 | isset($info['documentation']) |
| 292 | 292 | and $lien = $info['documentation'] |
| 293 | 293 | ) { |
| 294 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 294 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>"._T('en_savoir_plus').'</a></em></p>'; |
|
| 295 | 295 | } |
| 296 | - $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 296 | + $s .= "<dd class='desc'>".$description."</dd>\n"; |
|
| 297 | 297 | |
| 298 | 298 | if (isset($info['auteur'])) { |
| 299 | 299 | if (is_array($info['auteur'])) { |
@@ -303,19 +303,19 @@ discard block |
||
| 303 | 303 | $a = trim($info['auteur']); |
| 304 | 304 | } |
| 305 | 305 | if ($a) { |
| 306 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre( |
|
| 306 | + $s .= "<dt class='auteurs'>"._T('public:par_auteur')."</dt><dd class='auteurs'>".PtoBR(propre( |
|
| 307 | 307 | $a, |
| 308 | 308 | $dir |
| 309 | - )) . "</dd>\n"; |
|
| 309 | + ))."</dd>\n"; |
|
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | if (isset($info['credit'])) { |
| 314 | 314 | if ($a = formater_credits($info['credit'], ', ')) { |
| 315 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre( |
|
| 315 | + $s .= "<dt class='credits'>"._T('plugin_info_credit')."</dt><dd class='credits'>".PtoBR(propre( |
|
| 316 | 316 | $a, |
| 317 | 317 | $dir |
| 318 | - )) . "</dd>\n"; |
|
| 318 | + ))."</dd>\n"; |
|
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | |
@@ -327,10 +327,10 @@ discard block |
||
| 327 | 327 | $a = trim($info['licence']); |
| 328 | 328 | } |
| 329 | 329 | if ($a) { |
| 330 | - $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre( |
|
| 330 | + $s .= "<dt class='licence'>"._T('intitule_licence')."</dt><dd class='licence'>".PtoBR(propre( |
|
| 331 | 331 | $a, |
| 332 | 332 | $dir |
| 333 | - )) . "</dd>\n"; |
|
| 333 | + ))."</dd>\n"; |
|
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | |
@@ -341,25 +341,24 @@ discard block |
||
| 341 | 341 | // |
| 342 | 342 | $infotech = []; |
| 343 | 343 | |
| 344 | - $version = '<dt>' . _T('version') . '</dt><dd>' . $info['version']; |
|
| 344 | + $version = '<dt>'._T('version').'</dt><dd>'.$info['version']; |
|
| 345 | 345 | // Version VCS |
| 346 | - if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) { |
|
| 347 | - $version .= ' ' . $vcs; |
|
| 346 | + if ($vcs = version_vcs_courante($dir_plugins.$plug_file)) { |
|
| 347 | + $version .= ' '.$vcs; |
|
| 348 | 348 | } |
| 349 | 349 | $version .= '</dd>'; |
| 350 | 350 | $infotech[] = $version; |
| 351 | - $infotech[] = '<dt>' . _T('repertoire_plugins') . '</dt><dd>' . joli_repertoire("$dir_plugins$plug_file") . '</dd>'; |
|
| 351 | + $infotech[] = '<dt>'._T('repertoire_plugins').'</dt><dd>'.joli_repertoire("$dir_plugins$plug_file").'</dd>'; |
|
| 352 | 352 | // source zip le cas echeant |
| 353 | - $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 353 | + $infotech[] = (lire_fichier($dir_plugins.$plug_file.'/install.log', $log) |
|
| 354 | 354 | and preg_match(',^source:(.*)$,m', $log, $r)) |
| 355 | - ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . '</dd>' |
|
| 355 | + ? '<dt>'._T('plugin_source').'</dt><dd>'.trim($r[1]).'</dd>' |
|
| 356 | 356 | : ''; |
| 357 | 357 | |
| 358 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 359 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join( |
|
| 358 | + $infotech[] = !$info['necessite'] ? '' : ('<dt>'._T('plugin_info_necessite').'</dt><dd>'.join( |
|
| 360 | 359 | ' ', |
| 361 | 360 | array_map('array_shift', $info['necessite']) |
| 362 | - ) . '</dd>'); |
|
| 361 | + ).'</dd>'); |
|
| 363 | 362 | |
| 364 | 363 | $s .= "<dl class='tech'>" |
| 365 | 364 | . join('', $infotech) |
@@ -380,8 +379,8 @@ discard block |
||
| 380 | 379 | $texte .= |
| 381 | 380 | (!is_array($_credit)) |
| 382 | 381 | ? PtoBR(propre($_credit)) |
| 383 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 384 | - $_credit['nom'] . |
|
| 382 | + : ($_credit['url'] ? '<a href="'.$_credit['url'].'">' : ''). |
|
| 383 | + $_credit['nom']. |
|
| 385 | 384 | ($_credit['url'] ? '</a>' : ''); |
| 386 | 385 | } |
| 387 | 386 | |
@@ -17,212 +17,212 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('inc/charsets'); |
| 23 | 23 | include_spip('inc/texte'); |
| 24 | 24 | include_spip('inc/plugin'); // pour plugin_est_installe |
| 25 | 25 | |
| 26 | 26 | function plugins_afficher_plugin_dist( |
| 27 | - $url_page, |
|
| 28 | - $plug_file, |
|
| 29 | - $checked, |
|
| 30 | - $actif, |
|
| 31 | - $expose = false, |
|
| 32 | - $class_li = 'item', |
|
| 33 | - $dir_plugins = _DIR_PLUGINS |
|
| 27 | + $url_page, |
|
| 28 | + $plug_file, |
|
| 29 | + $checked, |
|
| 30 | + $actif, |
|
| 31 | + $expose = false, |
|
| 32 | + $class_li = 'item', |
|
| 33 | + $dir_plugins = _DIR_PLUGINS |
|
| 34 | 34 | ) { |
| 35 | 35 | |
| 36 | - static $id_input = 0; |
|
| 37 | - static $versions = []; |
|
| 38 | - |
|
| 39 | - $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 40 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 41 | - $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 42 | - $prefix = $info['prefix']; |
|
| 43 | - $cfg = ''; |
|
| 44 | - $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 45 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 46 | - $erreur = ''; |
|
| 47 | - |
|
| 48 | - if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 49 | - $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 50 | - $erreur = http_img_pack( |
|
| 51 | - 'plugin-dis-32.png', |
|
| 52 | - _T('plugin_info_non_compatible_spip'), |
|
| 53 | - " class='picto_err'", |
|
| 54 | - _T('plugin_info_non_compatible_spip') |
|
| 55 | - ); |
|
| 56 | - $class_li .= ' disabled'; |
|
| 57 | - $checkable = false; |
|
| 58 | - } elseif (isset($info['erreur'])) { |
|
| 59 | - $class_li .= ' error'; |
|
| 60 | - $erreur = http_img_pack( |
|
| 61 | - 'plugin-err-32.png', |
|
| 62 | - _T('plugin_info_erreur_xml'), |
|
| 63 | - " class='picto_err'", |
|
| 64 | - _T('plugin_info_erreur_xml') |
|
| 65 | - ) |
|
| 66 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>'; |
|
| 67 | - $checkable = false; |
|
| 68 | - } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 69 | - $class_li .= ' error'; |
|
| 70 | - $erreur = http_img_pack( |
|
| 71 | - 'plugin-err-32.png', |
|
| 72 | - _T('plugin_impossible_activer', ['plugin' => $nom]), |
|
| 73 | - " class='picto_err'", |
|
| 74 | - _T('plugin_impossible_activer', ['plugin' => $nom]) |
|
| 75 | - ) |
|
| 76 | - . "<div class='erreur'>" . implode( |
|
| 77 | - '<br />', |
|
| 78 | - $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file] |
|
| 79 | - ) . '</div>'; |
|
| 80 | - } else { |
|
| 81 | - $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ''; |
|
| 82 | - if (defined('_DEV_VERSION_SPIP_COMPAT') and !plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'])) { |
|
| 83 | - //$info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 84 | - $erreur = http_img_pack( |
|
| 85 | - 'plugin-dis-32.png', |
|
| 86 | - _T('plugin_info_non_compatible_spip'), |
|
| 87 | - " class='picto_err picto_compat_forcee'", |
|
| 88 | - _L('Version incompatible : compatibilité forcée') |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // numerotons les occurrences d'un meme prefix |
|
| 94 | - $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
|
| 95 | - |
|
| 96 | - $class_li .= ($actif ? ' actif' : '') . ($expose ? ' on' : ''); |
|
| 97 | - |
|
| 98 | - return "<li id='$prefix$id' class='$class_li'>" |
|
| 99 | - . ((!$checkable and !$checked) |
|
| 100 | - ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 101 | - . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 102 | - . $cfg |
|
| 103 | - . $erreur |
|
| 104 | - . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 105 | - ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 106 | - . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 107 | - . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 108 | - . '</div>' |
|
| 109 | - . '</li>'; |
|
| 36 | + static $id_input = 0; |
|
| 37 | + static $versions = []; |
|
| 38 | + |
|
| 39 | + $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 40 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 41 | + $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 42 | + $prefix = $info['prefix']; |
|
| 43 | + $cfg = ''; |
|
| 44 | + $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 45 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 46 | + $erreur = ''; |
|
| 47 | + |
|
| 48 | + if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 49 | + $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 50 | + $erreur = http_img_pack( |
|
| 51 | + 'plugin-dis-32.png', |
|
| 52 | + _T('plugin_info_non_compatible_spip'), |
|
| 53 | + " class='picto_err'", |
|
| 54 | + _T('plugin_info_non_compatible_spip') |
|
| 55 | + ); |
|
| 56 | + $class_li .= ' disabled'; |
|
| 57 | + $checkable = false; |
|
| 58 | + } elseif (isset($info['erreur'])) { |
|
| 59 | + $class_li .= ' error'; |
|
| 60 | + $erreur = http_img_pack( |
|
| 61 | + 'plugin-err-32.png', |
|
| 62 | + _T('plugin_info_erreur_xml'), |
|
| 63 | + " class='picto_err'", |
|
| 64 | + _T('plugin_info_erreur_xml') |
|
| 65 | + ) |
|
| 66 | + . "<div class='erreur'>" . join('<br >', $info['erreur']) . '</div>'; |
|
| 67 | + $checkable = false; |
|
| 68 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 69 | + $class_li .= ' error'; |
|
| 70 | + $erreur = http_img_pack( |
|
| 71 | + 'plugin-err-32.png', |
|
| 72 | + _T('plugin_impossible_activer', ['plugin' => $nom]), |
|
| 73 | + " class='picto_err'", |
|
| 74 | + _T('plugin_impossible_activer', ['plugin' => $nom]) |
|
| 75 | + ) |
|
| 76 | + . "<div class='erreur'>" . implode( |
|
| 77 | + '<br />', |
|
| 78 | + $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file] |
|
| 79 | + ) . '</div>'; |
|
| 80 | + } else { |
|
| 81 | + $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ''; |
|
| 82 | + if (defined('_DEV_VERSION_SPIP_COMPAT') and !plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'])) { |
|
| 83 | + //$info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 84 | + $erreur = http_img_pack( |
|
| 85 | + 'plugin-dis-32.png', |
|
| 86 | + _T('plugin_info_non_compatible_spip'), |
|
| 87 | + " class='picto_err picto_compat_forcee'", |
|
| 88 | + _L('Version incompatible : compatibilité forcée') |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // numerotons les occurrences d'un meme prefix |
|
| 94 | + $versions[$prefix] = $id = isset($versions[$prefix]) ? intval($versions[$prefix]) + 1 : ''; |
|
| 95 | + |
|
| 96 | + $class_li .= ($actif ? ' actif' : '') . ($expose ? ' on' : ''); |
|
| 97 | + |
|
| 98 | + return "<li id='$prefix$id' class='$class_li'>" |
|
| 99 | + . ((!$checkable and !$checked) |
|
| 100 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 101 | + . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 102 | + . $cfg |
|
| 103 | + . $erreur |
|
| 104 | + . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 105 | + ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 106 | + . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 107 | + . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 108 | + . '</div>' |
|
| 109 | + . '</li>'; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | function plugin_bouton_config($nom, $infos, $dir) { |
| 113 | - // la verification se base sur le filesystem |
|
| 114 | - // il faut donc n'utiliser que des minuscules, par convention |
|
| 115 | - $prefix = strtolower($infos['prefix']); |
|
| 116 | - // si paquet.xml fournit un squelette, le prendre |
|
| 117 | - if (isset($infos['config']) and $infos['config']) { |
|
| 118 | - return recuperer_fond( |
|
| 119 | - "$dir$nom/" . $infos['config'], |
|
| 120 | - [ |
|
| 121 | - 'script' => 'configurer_' . $prefix, |
|
| 122 | - 'nom' => $nom |
|
| 123 | - ] |
|
| 124 | - ); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // sinon prendre le squelette std sur le nom std |
|
| 128 | - return recuperer_fond( |
|
| 129 | - 'prive/squelettes/inclure/cfg', |
|
| 130 | - [ |
|
| 131 | - 'script' => 'configurer_' . $prefix, |
|
| 132 | - 'nom' => $nom |
|
| 133 | - ] |
|
| 134 | - ); |
|
| 113 | + // la verification se base sur le filesystem |
|
| 114 | + // il faut donc n'utiliser que des minuscules, par convention |
|
| 115 | + $prefix = strtolower($infos['prefix']); |
|
| 116 | + // si paquet.xml fournit un squelette, le prendre |
|
| 117 | + if (isset($infos['config']) and $infos['config']) { |
|
| 118 | + return recuperer_fond( |
|
| 119 | + "$dir$nom/" . $infos['config'], |
|
| 120 | + [ |
|
| 121 | + 'script' => 'configurer_' . $prefix, |
|
| 122 | + 'nom' => $nom |
|
| 123 | + ] |
|
| 124 | + ); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // sinon prendre le squelette std sur le nom std |
|
| 128 | + return recuperer_fond( |
|
| 129 | + 'prive/squelettes/inclure/cfg', |
|
| 130 | + [ |
|
| 131 | + 'script' => 'configurer_' . $prefix, |
|
| 132 | + 'nom' => $nom |
|
| 133 | + ] |
|
| 134 | + ); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // checkbox pour activer ou desactiver |
| 138 | 138 | // si ce n'est pas une extension |
| 139 | 139 | |
| 140 | 140 | function plugin_checkbox($id_input, $file, $actif) { |
| 141 | - $name = substr(md5($file), 0, 16); |
|
| 142 | - |
|
| 143 | - return "<div class='check'>\n" |
|
| 144 | - . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 145 | - . ($actif ? " checked='checked'" : '') |
|
| 146 | - . " class='checkbox' value='O' />" |
|
| 147 | - . "\n<label for='label_$id_input'>" . _T('activer_plugin') . '</label>' |
|
| 148 | - . '</div>'; |
|
| 141 | + $name = substr(md5($file), 0, 16); |
|
| 142 | + |
|
| 143 | + return "<div class='check'>\n" |
|
| 144 | + . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 145 | + . ($actif ? " checked='checked'" : '') |
|
| 146 | + . " class='checkbox' value='O' />" |
|
| 147 | + . "\n<label for='label_$id_input'>" . _T('activer_plugin') . '</label>' |
|
| 148 | + . '</div>'; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | function plugin_nom($info, $dir_plugins, $plug_file) { |
| 152 | - $prefix = $info['prefix']; |
|
| 153 | - $dir = "$dir_plugins$plug_file"; |
|
| 154 | - // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 155 | - if ($info['dtd'] == 'paquet') { |
|
| 156 | - $nom = plugin_typo("{$prefix}_nom", "$dir/lang/paquet-$prefix"); |
|
| 157 | - if (!$nom) { |
|
| 158 | - $nom = typo($info['nom']); |
|
| 159 | - } |
|
| 160 | - } else { |
|
| 161 | - $nom = typo(attribut_html($info['nom'])); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return trim($nom); |
|
| 152 | + $prefix = $info['prefix']; |
|
| 153 | + $dir = "$dir_plugins$plug_file"; |
|
| 154 | + // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 155 | + if ($info['dtd'] == 'paquet') { |
|
| 156 | + $nom = plugin_typo("{$prefix}_nom", "$dir/lang/paquet-$prefix"); |
|
| 157 | + if (!$nom) { |
|
| 158 | + $nom = typo($info['nom']); |
|
| 159 | + } |
|
| 160 | + } else { |
|
| 161 | + $nom = typo(attribut_html($info['nom'])); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return trim($nom); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // Cartouche Resume |
| 168 | 168 | function plugin_resume($info, $dir_plugins, $plug_file, $url_page) { |
| 169 | - $prefix = $info['prefix']; |
|
| 170 | - $dir = "$dir_plugins$plug_file"; |
|
| 171 | - $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 172 | - // une seule ligne dans le slogan : couper si besoin |
|
| 173 | - if (($p = strpos($slogan, '<br />')) !== false) { |
|
| 174 | - $slogan = substr($slogan, 0, $p); |
|
| 175 | - } |
|
| 176 | - // couper par securite |
|
| 177 | - $slogan = couper($slogan, 80); |
|
| 178 | - |
|
| 179 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 180 | - |
|
| 181 | - $url = parametre_url($url_page, 'plugin', substr($dir, strlen(_DIR_RACINE))); |
|
| 182 | - |
|
| 183 | - $icon_class = 'icon'; |
|
| 184 | - $img = ''; |
|
| 185 | - if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 186 | - $img = http_img_pack("$dir/$i", '', " width='32' height='32'", '', ['variante_svg_si_possible' => true, 'chemin_image' => false]); |
|
| 187 | - if (!extraire_attribut($img, 'src')) { |
|
| 188 | - $img = ''; |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - if (!$img) { |
|
| 192 | - $img = http_img_pack('plugin-xx.svg', '', " width='32' height='32'"); |
|
| 193 | - $icon_class .= ' no-logo'; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - $i = "<div class='$icon_class'><a href='$url' rel='info'>$img</a></div>"; |
|
| 197 | - |
|
| 198 | - return "<div class='resume'>" |
|
| 199 | - . "<h3><a href='$url' rel='info'>" |
|
| 200 | - . $nom |
|
| 201 | - . '</a></h3>' |
|
| 202 | - . " <span class='version'>" . $info['version'] . '</span>' |
|
| 203 | - . " <span class='etat'> - " |
|
| 204 | - . plugin_etat_en_clair($info['etat']) |
|
| 205 | - . '</span>' |
|
| 206 | - . "<div class='short'>" . $slogan . '</div>' |
|
| 207 | - . $i |
|
| 208 | - . '</div>'; |
|
| 169 | + $prefix = $info['prefix']; |
|
| 170 | + $dir = "$dir_plugins$plug_file"; |
|
| 171 | + $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 172 | + // une seule ligne dans le slogan : couper si besoin |
|
| 173 | + if (($p = strpos($slogan, '<br />')) !== false) { |
|
| 174 | + $slogan = substr($slogan, 0, $p); |
|
| 175 | + } |
|
| 176 | + // couper par securite |
|
| 177 | + $slogan = couper($slogan, 80); |
|
| 178 | + |
|
| 179 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 180 | + |
|
| 181 | + $url = parametre_url($url_page, 'plugin', substr($dir, strlen(_DIR_RACINE))); |
|
| 182 | + |
|
| 183 | + $icon_class = 'icon'; |
|
| 184 | + $img = ''; |
|
| 185 | + if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 186 | + $img = http_img_pack("$dir/$i", '', " width='32' height='32'", '', ['variante_svg_si_possible' => true, 'chemin_image' => false]); |
|
| 187 | + if (!extraire_attribut($img, 'src')) { |
|
| 188 | + $img = ''; |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + if (!$img) { |
|
| 192 | + $img = http_img_pack('plugin-xx.svg', '', " width='32' height='32'"); |
|
| 193 | + $icon_class .= ' no-logo'; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + $i = "<div class='$icon_class'><a href='$url' rel='info'>$img</a></div>"; |
|
| 197 | + |
|
| 198 | + return "<div class='resume'>" |
|
| 199 | + . "<h3><a href='$url' rel='info'>" |
|
| 200 | + . $nom |
|
| 201 | + . '</a></h3>' |
|
| 202 | + . " <span class='version'>" . $info['version'] . '</span>' |
|
| 203 | + . " <span class='etat'> - " |
|
| 204 | + . plugin_etat_en_clair($info['etat']) |
|
| 205 | + . '</span>' |
|
| 206 | + . "<div class='short'>" . $slogan . '</div>' |
|
| 207 | + . $i |
|
| 208 | + . '</div>'; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | function plugin_desintalle($plug_file, $nom, $dir_plugins = null) { |
| 212 | - if (!$dir_plugins) { |
|
| 213 | - $dir_plugins = _DIR_PLUGINS; |
|
| 214 | - } |
|
| 212 | + if (!$dir_plugins) { |
|
| 213 | + $dir_plugins = _DIR_PLUGINS; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 217 | - $text = _T('bouton_desinstaller'); |
|
| 218 | - $text2 = _T('info_desinstaller_plugin'); |
|
| 219 | - $file = basename($plug_file); |
|
| 216 | + $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 217 | + $text = _T('bouton_desinstaller'); |
|
| 218 | + $text2 = _T('info_desinstaller_plugin'); |
|
| 219 | + $file = basename($plug_file); |
|
| 220 | 220 | |
| 221 | - return "<div class='actions'>[" . |
|
| 222 | - "<a href='$action' |
|
| 221 | + return "<div class='actions'>[" . |
|
| 222 | + "<a href='$action' |
|
| 223 | 223 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 224 | - . $text |
|
| 225 | - . '</a>]</div>'; |
|
| 224 | + . $text |
|
| 225 | + . '</a>]</div>'; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -236,145 +236,145 @@ discard block |
||
| 236 | 236 | * Traduction de l'état dans la langue en cours |
| 237 | 237 | **/ |
| 238 | 238 | function plugin_etat_en_clair($etat) { |
| 239 | - if (!in_array($etat, ['stable', 'test', 'experimental'])) { |
|
| 240 | - $etat = 'developpement'; |
|
| 241 | - } |
|
| 239 | + if (!in_array($etat, ['stable', 'test', 'experimental'])) { |
|
| 240 | + $etat = 'developpement'; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - return _T('plugin_etat_' . $etat); |
|
| 243 | + return _T('plugin_etat_' . $etat); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | function plugin_propre($texte, $module = '', $propre = 'propre') { |
| 247 | - // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 248 | - if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 249 | - $module = substr($module, strlen(_DIR_RACINE)); |
|
| 250 | - } |
|
| 251 | - if (preg_match('|^\w+_[\w_]+$|', $texte)) { |
|
| 252 | - $texte = _T(($module ? "$module:" : '') . $texte, [], ['force' => false]); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - return $propre($texte); |
|
| 247 | + // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 248 | + if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 249 | + $module = substr($module, strlen(_DIR_RACINE)); |
|
| 250 | + } |
|
| 251 | + if (preg_match('|^\w+_[\w_]+$|', $texte)) { |
|
| 252 | + $texte = _T(($module ? "$module:" : '') . $texte, [], ['force' => false]); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + return $propre($texte); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | function plugin_typo($texte, $module = '') { |
| 259 | - return plugin_propre($texte, $module, 'typo'); |
|
| 259 | + return plugin_propre($texte, $module, 'typo'); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | |
| 263 | 263 | function affiche_bloc_plugin($plug_file, $info, $dir_plugins = null) { |
| 264 | - $log = null; |
|
| 265 | - if (!$dir_plugins) { |
|
| 266 | - $dir_plugins = _DIR_PLUGINS; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $prefix = $info['prefix']; |
|
| 270 | - $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 271 | - |
|
| 272 | - $s = ''; |
|
| 273 | - // TODO: le traiter_multi ici n'est pas beau |
|
| 274 | - // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 275 | - // concerne les anciens plugin.xml donc on devrait plus en avoir besoin |
|
| 276 | - $description = ''; |
|
| 277 | - if (isset($info['description'])) { |
|
| 278 | - $description = plugin_propre($info['description'], $dir); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - if ( |
|
| 282 | - isset($info['documentation']) |
|
| 283 | - and $lien = $info['documentation'] |
|
| 284 | - ) { |
|
| 285 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 286 | - } |
|
| 287 | - $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 288 | - |
|
| 289 | - if (isset($info['auteur'])) { |
|
| 290 | - if (is_array($info['auteur'])) { |
|
| 291 | - $a = formater_credits($info['auteur'], ', '); |
|
| 292 | - } // pour compat mais ne doit plus arriver |
|
| 293 | - else { |
|
| 294 | - $a = trim($info['auteur']); |
|
| 295 | - } |
|
| 296 | - if ($a) { |
|
| 297 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre( |
|
| 298 | - $a, |
|
| 299 | - $dir |
|
| 300 | - )) . "</dd>\n"; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if (isset($info['credit'])) { |
|
| 305 | - if ($a = formater_credits($info['credit'], ', ')) { |
|
| 306 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre( |
|
| 307 | - $a, |
|
| 308 | - $dir |
|
| 309 | - )) . "</dd>\n"; |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - if (isset($info['licence'])) { |
|
| 314 | - if (is_array($info['licence'])) { |
|
| 315 | - $a = formater_credits($info['licence'], ', '); |
|
| 316 | - } // pour compat mais ne doit plus arriver |
|
| 317 | - else { |
|
| 318 | - $a = trim($info['licence']); |
|
| 319 | - } |
|
| 320 | - if ($a) { |
|
| 321 | - $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre( |
|
| 322 | - $a, |
|
| 323 | - $dir |
|
| 324 | - )) . "</dd>\n"; |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - $s = "<dl class='description'>$s</dl>"; |
|
| 329 | - |
|
| 330 | - // |
|
| 331 | - // Ajouter les infos techniques |
|
| 332 | - // |
|
| 333 | - $infotech = []; |
|
| 334 | - |
|
| 335 | - $version = '<dt>' . _T('version') . '</dt><dd>' . $info['version']; |
|
| 336 | - // Version VCS |
|
| 337 | - if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) { |
|
| 338 | - $version .= ' ' . $vcs; |
|
| 339 | - } |
|
| 340 | - $version .= '</dd>'; |
|
| 341 | - $infotech[] = $version; |
|
| 342 | - $infotech[] = '<dt>' . _T('repertoire_plugins') . '</dt><dd>' . joli_repertoire("$dir_plugins$plug_file") . '</dd>'; |
|
| 343 | - // source zip le cas echeant |
|
| 344 | - $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 345 | - and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 346 | - ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . '</dd>' |
|
| 347 | - : ''; |
|
| 348 | - |
|
| 349 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 350 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join( |
|
| 351 | - ' ', |
|
| 352 | - array_map('array_shift', $info['necessite']) |
|
| 353 | - ) . '</dd>'); |
|
| 354 | - |
|
| 355 | - $s .= "<dl class='tech'>" |
|
| 356 | - . join('', $infotech) |
|
| 357 | - . '</dl>'; |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - return $s; |
|
| 264 | + $log = null; |
|
| 265 | + if (!$dir_plugins) { |
|
| 266 | + $dir_plugins = _DIR_PLUGINS; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $prefix = $info['prefix']; |
|
| 270 | + $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 271 | + |
|
| 272 | + $s = ''; |
|
| 273 | + // TODO: le traiter_multi ici n'est pas beau |
|
| 274 | + // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 275 | + // concerne les anciens plugin.xml donc on devrait plus en avoir besoin |
|
| 276 | + $description = ''; |
|
| 277 | + if (isset($info['description'])) { |
|
| 278 | + $description = plugin_propre($info['description'], $dir); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + if ( |
|
| 282 | + isset($info['documentation']) |
|
| 283 | + and $lien = $info['documentation'] |
|
| 284 | + ) { |
|
| 285 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 286 | + } |
|
| 287 | + $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 288 | + |
|
| 289 | + if (isset($info['auteur'])) { |
|
| 290 | + if (is_array($info['auteur'])) { |
|
| 291 | + $a = formater_credits($info['auteur'], ', '); |
|
| 292 | + } // pour compat mais ne doit plus arriver |
|
| 293 | + else { |
|
| 294 | + $a = trim($info['auteur']); |
|
| 295 | + } |
|
| 296 | + if ($a) { |
|
| 297 | + $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre( |
|
| 298 | + $a, |
|
| 299 | + $dir |
|
| 300 | + )) . "</dd>\n"; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if (isset($info['credit'])) { |
|
| 305 | + if ($a = formater_credits($info['credit'], ', ')) { |
|
| 306 | + $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre( |
|
| 307 | + $a, |
|
| 308 | + $dir |
|
| 309 | + )) . "</dd>\n"; |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + if (isset($info['licence'])) { |
|
| 314 | + if (is_array($info['licence'])) { |
|
| 315 | + $a = formater_credits($info['licence'], ', '); |
|
| 316 | + } // pour compat mais ne doit plus arriver |
|
| 317 | + else { |
|
| 318 | + $a = trim($info['licence']); |
|
| 319 | + } |
|
| 320 | + if ($a) { |
|
| 321 | + $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre( |
|
| 322 | + $a, |
|
| 323 | + $dir |
|
| 324 | + )) . "</dd>\n"; |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + $s = "<dl class='description'>$s</dl>"; |
|
| 329 | + |
|
| 330 | + // |
|
| 331 | + // Ajouter les infos techniques |
|
| 332 | + // |
|
| 333 | + $infotech = []; |
|
| 334 | + |
|
| 335 | + $version = '<dt>' . _T('version') . '</dt><dd>' . $info['version']; |
|
| 336 | + // Version VCS |
|
| 337 | + if ($vcs = version_vcs_courante($dir_plugins . $plug_file)) { |
|
| 338 | + $version .= ' ' . $vcs; |
|
| 339 | + } |
|
| 340 | + $version .= '</dd>'; |
|
| 341 | + $infotech[] = $version; |
|
| 342 | + $infotech[] = '<dt>' . _T('repertoire_plugins') . '</dt><dd>' . joli_repertoire("$dir_plugins$plug_file") . '</dd>'; |
|
| 343 | + // source zip le cas echeant |
|
| 344 | + $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 345 | + and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 346 | + ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . '</dd>' |
|
| 347 | + : ''; |
|
| 348 | + |
|
| 349 | + $infotech[] = !$info['necessite'] ? '' : |
|
| 350 | + ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join( |
|
| 351 | + ' ', |
|
| 352 | + array_map('array_shift', $info['necessite']) |
|
| 353 | + ) . '</dd>'); |
|
| 354 | + |
|
| 355 | + $s .= "<dl class='tech'>" |
|
| 356 | + . join('', $infotech) |
|
| 357 | + . '</dl>'; |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + return $s; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | function formater_credits($infos, $sep = ', ') { |
| 364 | - $texte = ''; |
|
| 365 | - |
|
| 366 | - foreach ($infos as $_credit) { |
|
| 367 | - if ($texte) { |
|
| 368 | - $texte .= $sep; |
|
| 369 | - } |
|
| 370 | - // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 371 | - $texte .= |
|
| 372 | - (!is_array($_credit)) |
|
| 373 | - ? PtoBR(propre($_credit)) |
|
| 374 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 375 | - $_credit['nom'] . |
|
| 376 | - ($_credit['url'] ? '</a>' : ''); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - return $texte; |
|
| 364 | + $texte = ''; |
|
| 365 | + |
|
| 366 | + foreach ($infos as $_credit) { |
|
| 367 | + if ($texte) { |
|
| 368 | + $texte .= $sep; |
|
| 369 | + } |
|
| 370 | + // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 371 | + $texte .= |
|
| 372 | + (!is_array($_credit)) |
|
| 373 | + ? PtoBR(propre($_credit)) |
|
| 374 | + : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 375 | + $_credit['nom'] . |
|
| 376 | + ($_credit['url'] ? '</a>' : ''); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + return $texte; |
|
| 380 | 380 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Presentation |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/presentation_mini'); |
@@ -31,141 +31,141 @@ discard block |
||
| 31 | 31 | include_spip('inc/filtres_alertes'); |
| 32 | 32 | |
| 33 | 33 | function debut_cadre($style, $icone = '', $fonction = '', $titre = '', $id = '', $class = '', $padding = true) { |
| 34 | - $fond = null; |
|
| 35 | - $style_mapping = [ |
|
| 36 | - 'r' => 'simple', |
|
| 37 | - 'e' => 'raccourcis', |
|
| 38 | - 'couleur' => 'basic highlight', |
|
| 39 | - 'couleur-foncee' => 'basic highlight', |
|
| 40 | - 'trait-couleur' => 'important', |
|
| 41 | - 'alerte' => 'notice', |
|
| 42 | - 'info' => 'info', |
|
| 43 | - 'sous_rub' => 'simple sous-rub' |
|
| 44 | - ]; |
|
| 45 | - $style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section']; |
|
| 46 | - $c = $style_mapping[$style] ?? 'simple'; |
|
| 47 | - $class = $c . ($class ? " $class" : ''); |
|
| 48 | - if (!$padding) { |
|
| 49 | - $class .= ($class ? ' ' : '') . 'no-padding'; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - //($id?"id='$id' ":"") |
|
| 53 | - if (strlen($icone) > 1) { |
|
| 54 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 55 | - [$fond, $fonction] = $icone_renommer($icone, $fonction); |
|
| 56 | - } |
|
| 57 | - $size = 24; |
|
| 58 | - if (preg_match('/-([0-9]{1,3})[.](gif|png)$/i', $fond, $match)) { |
|
| 59 | - $size = $match[1]; |
|
| 60 | - } |
|
| 61 | - if ($fonction) { |
|
| 62 | - // 2 images pour composer l'icone : le fond (article) en background, |
|
| 63 | - // la fonction (new) en image |
|
| 64 | - $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" . |
|
| 65 | - http_style_background($fond, 'no-repeat center center', $size)); |
|
| 66 | - } else { |
|
| 67 | - $icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'"); |
|
| 68 | - } |
|
| 69 | - $titre = $icone . $titre; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return boite_ouvrir($titre, $class, $style_titre_mapping[$style] ?? '', $id); |
|
| 34 | + $fond = null; |
|
| 35 | + $style_mapping = [ |
|
| 36 | + 'r' => 'simple', |
|
| 37 | + 'e' => 'raccourcis', |
|
| 38 | + 'couleur' => 'basic highlight', |
|
| 39 | + 'couleur-foncee' => 'basic highlight', |
|
| 40 | + 'trait-couleur' => 'important', |
|
| 41 | + 'alerte' => 'notice', |
|
| 42 | + 'info' => 'info', |
|
| 43 | + 'sous_rub' => 'simple sous-rub' |
|
| 44 | + ]; |
|
| 45 | + $style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section']; |
|
| 46 | + $c = $style_mapping[$style] ?? 'simple'; |
|
| 47 | + $class = $c . ($class ? " $class" : ''); |
|
| 48 | + if (!$padding) { |
|
| 49 | + $class .= ($class ? ' ' : '') . 'no-padding'; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + //($id?"id='$id' ":"") |
|
| 53 | + if (strlen($icone) > 1) { |
|
| 54 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 55 | + [$fond, $fonction] = $icone_renommer($icone, $fonction); |
|
| 56 | + } |
|
| 57 | + $size = 24; |
|
| 58 | + if (preg_match('/-([0-9]{1,3})[.](gif|png)$/i', $fond, $match)) { |
|
| 59 | + $size = $match[1]; |
|
| 60 | + } |
|
| 61 | + if ($fonction) { |
|
| 62 | + // 2 images pour composer l'icone : le fond (article) en background, |
|
| 63 | + // la fonction (new) en image |
|
| 64 | + $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" . |
|
| 65 | + http_style_background($fond, 'no-repeat center center', $size)); |
|
| 66 | + } else { |
|
| 67 | + $icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'"); |
|
| 68 | + } |
|
| 69 | + $titre = $icone . $titre; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return boite_ouvrir($titre, $class, $style_titre_mapping[$style] ?? '', $id); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | function fin_cadre() { |
| 76 | - return boite_fermer(); |
|
| 76 | + return boite_fermer(); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
| 80 | 80 | function debut_cadre_relief( |
| 81 | - $icone = '', |
|
| 82 | - $dummy = '', |
|
| 83 | - $fonction = '', |
|
| 84 | - $titre = '', |
|
| 85 | - $id = '', |
|
| 86 | - $class = '' |
|
| 81 | + $icone = '', |
|
| 82 | + $dummy = '', |
|
| 83 | + $fonction = '', |
|
| 84 | + $titre = '', |
|
| 85 | + $id = '', |
|
| 86 | + $class = '' |
|
| 87 | 87 | ) { |
| 88 | - return debut_cadre('r', $icone, $fonction, $titre, $id, $class); |
|
| 88 | + return debut_cadre('r', $icone, $fonction, $titre, $id, $class); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | function fin_cadre_relief() { |
| 92 | - return fin_cadre(); |
|
| 92 | + return fin_cadre(); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | function debut_cadre_enfonce( |
| 96 | - $icone = '', |
|
| 97 | - $dummy = '', |
|
| 98 | - $fonction = '', |
|
| 99 | - $titre = '', |
|
| 100 | - $id = '', |
|
| 101 | - $class = '' |
|
| 96 | + $icone = '', |
|
| 97 | + $dummy = '', |
|
| 98 | + $fonction = '', |
|
| 99 | + $titre = '', |
|
| 100 | + $id = '', |
|
| 101 | + $class = '' |
|
| 102 | 102 | ) { |
| 103 | - return debut_cadre('e', $icone, $fonction, $titre, $id, $class); |
|
| 103 | + return debut_cadre('e', $icone, $fonction, $titre, $id, $class); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | function fin_cadre_enfonce() { |
| 107 | - return fin_cadre(); |
|
| 107 | + return fin_cadre(); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | function debut_cadre_sous_rub( |
| 111 | - $icone = '', |
|
| 112 | - $dummy = '', |
|
| 113 | - $fonction = '', |
|
| 114 | - $titre = '', |
|
| 115 | - $id = '', |
|
| 116 | - $class = '' |
|
| 111 | + $icone = '', |
|
| 112 | + $dummy = '', |
|
| 113 | + $fonction = '', |
|
| 114 | + $titre = '', |
|
| 115 | + $id = '', |
|
| 116 | + $class = '' |
|
| 117 | 117 | ) { |
| 118 | - return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class); |
|
| 118 | + return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | function fin_cadre_sous_rub() { |
| 122 | - return fin_cadre(); |
|
| 122 | + return fin_cadre(); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | function debut_cadre_couleur( |
| 126 | - $icone = '', |
|
| 127 | - $dummy = '', |
|
| 128 | - $fonction = '', |
|
| 129 | - $titre = '', |
|
| 130 | - $id = '', |
|
| 131 | - $class = '' |
|
| 126 | + $icone = '', |
|
| 127 | + $dummy = '', |
|
| 128 | + $fonction = '', |
|
| 129 | + $titre = '', |
|
| 130 | + $id = '', |
|
| 131 | + $class = '' |
|
| 132 | 132 | ) { |
| 133 | - return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class); |
|
| 133 | + return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | function fin_cadre_couleur() { |
| 137 | - return fin_cadre(); |
|
| 137 | + return fin_cadre(); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | function debut_cadre_trait_couleur( |
| 141 | - $icone = '', |
|
| 142 | - $dummy = '', |
|
| 143 | - $fonction = '', |
|
| 144 | - $titre = '', |
|
| 145 | - $id = '', |
|
| 146 | - $class = '' |
|
| 141 | + $icone = '', |
|
| 142 | + $dummy = '', |
|
| 143 | + $fonction = '', |
|
| 144 | + $titre = '', |
|
| 145 | + $id = '', |
|
| 146 | + $class = '' |
|
| 147 | 147 | ) { |
| 148 | - return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class); |
|
| 148 | + return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | function fin_cadre_trait_couleur() { |
| 152 | - return fin_cadre(); |
|
| 152 | + return fin_cadre(); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | function debut_boite_alerte() { |
| 156 | - return debut_cadre('alerte', '', '', '', '', ''); |
|
| 156 | + return debut_cadre('alerte', '', '', '', '', ''); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | function fin_boite_alerte() { |
| 160 | - return fin_cadre(); |
|
| 160 | + return fin_cadre(); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | function debut_boite_info() { |
| 164 | - return debut_cadre('info', '', '', '', '', ''); |
|
| 164 | + return debut_cadre('info', '', '', '', '', ''); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | function fin_boite_info() { |
| 168 | - return fin_cadre(); |
|
| 168 | + return fin_cadre(); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -176,17 +176,17 @@ discard block |
||
| 176 | 176 | * @return string Code PHP. |
| 177 | 177 | **/ |
| 178 | 178 | function gros_titre( |
| 179 | - $titre, |
|
| 180 | - $ze_logo = '' |
|
| 179 | + $titre, |
|
| 180 | + $ze_logo = '' |
|
| 181 | 181 | ) { |
| 182 | - return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n"; |
|
| 182 | + return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n"; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // La boite des raccourcis |
| 186 | 186 | // Se place a droite si l'ecran est en mode panoramique. |
| 187 | 187 | function bloc_des_raccourcis($bloc) { |
| 188 | - return creer_colonne_droite() |
|
| 189 | - . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer(); |
|
| 188 | + return creer_colonne_droite() |
|
| 189 | + . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer(); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | // |
@@ -196,18 +196,18 @@ discard block |
||
| 196 | 196 | // Fonctions onglets |
| 197 | 197 | // @param string $sous_classe prend la valeur second pour definir les onglet de deuxieme niveau |
| 198 | 198 | function debut_onglet($classe = 'barre_onglet') { |
| 199 | - return "<div class = '$classe clearfix'><ul>\n"; |
|
| 199 | + return "<div class = '$classe clearfix'><ul>\n"; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | function fin_onglet() { |
| 203 | - return "</ul></div>\n"; |
|
| 203 | + return "</ul></div>\n"; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | function onglet($texte, $lien, $onglet_ref, $onglet, $icone = '') { |
| 207 | - return '<li>' |
|
| 208 | - . ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '') |
|
| 209 | - . lien_ou_expose($lien, $texte, $onglet == $onglet_ref) |
|
| 210 | - . '</li>'; |
|
| 207 | + return '<li>' |
|
| 208 | + . ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '') |
|
| 209 | + . lien_ou_expose($lien, $texte, $onglet == $onglet_ref) |
|
| 210 | + . '</li>'; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -239,14 +239,14 @@ discard block |
||
| 239 | 239 | * Code HTML du lien |
| 240 | 240 | **/ |
| 241 | 241 | function icone_verticale($texte, $lien, $fond, $fonction = '', $align = '', $javascript = '') { |
| 242 | - // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 243 | - // (il faudrait fusionner avec le cas $javascript) |
|
| 244 | - if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 245 | - [$x, $lien, $atts, $texte] = $r; |
|
| 246 | - $javascript .= $atts; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript); |
|
| 242 | + // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 243 | + // (il faudrait fusionner avec le cas $javascript) |
|
| 244 | + if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 245 | + [$x, $lien, $atts, $texte] = $r; |
|
| 246 | + $javascript .= $atts; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -271,15 +271,15 @@ discard block |
||
| 271 | 271 | * Code HTML du lien |
| 272 | 272 | **/ |
| 273 | 273 | function icone_horizontale($texte, $lien, $fond, $fonction = '', $dummy = '', $javascript = '') { |
| 274 | - $retour = ''; |
|
| 275 | - // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 276 | - // (il faudrait fusionner avec le cas $javascript) |
|
| 277 | - if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 278 | - [$x, $lien, $atts, $texte] = $r; |
|
| 279 | - $javascript .= $atts; |
|
| 280 | - } |
|
| 274 | + $retour = ''; |
|
| 275 | + // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 276 | + // (il faudrait fusionner avec le cas $javascript) |
|
| 277 | + if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 278 | + [$x, $lien, $atts, $texte] = $r; |
|
| 279 | + $javascript .= $atts; |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | - $retour = icone_base($lien, $texte, $fond, $fonction, 'horizontale', $javascript); |
|
| 282 | + $retour = icone_base($lien, $texte, $fond, $fonction, 'horizontale', $javascript); |
|
| 283 | 283 | |
| 284 | - return $retour; |
|
| 284 | + return $retour; |
|
| 285 | 285 | } |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | ]; |
| 45 | 45 | $style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section']; |
| 46 | 46 | $c = $style_mapping[$style] ?? 'simple'; |
| 47 | - $class = $c . ($class ? " $class" : ''); |
|
| 47 | + $class = $c.($class ? " $class" : ''); |
|
| 48 | 48 | if (!$padding) { |
| 49 | - $class .= ($class ? ' ' : '') . 'no-padding'; |
|
| 49 | + $class .= ($class ? ' ' : '').'no-padding'; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | //($id?"id='$id' ":"") |
@@ -61,12 +61,12 @@ discard block |
||
| 61 | 61 | if ($fonction) { |
| 62 | 62 | // 2 images pour composer l'icone : le fond (article) en background, |
| 63 | 63 | // la fonction (new) en image |
| 64 | - $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" . |
|
| 64 | + $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n". |
|
| 65 | 65 | http_style_background($fond, 'no-repeat center center', $size)); |
| 66 | 66 | } else { |
| 67 | 67 | $icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'"); |
| 68 | 68 | } |
| 69 | - $titre = $icone . $titre; |
|
| 69 | + $titre = $icone.$titre; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | return boite_ouvrir($titre, $class, $style_titre_mapping[$style] ?? '', $id); |
@@ -179,14 +179,14 @@ discard block |
||
| 179 | 179 | $titre, |
| 180 | 180 | $ze_logo = '' |
| 181 | 181 | ) { |
| 182 | - return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n"; |
|
| 182 | + return "<h1 class = 'grostitre'>".$ze_logo.' '.typo($titre)."</h1>\n"; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // La boite des raccourcis |
| 186 | 186 | // Se place a droite si l'ecran est en mode panoramique. |
| 187 | 187 | function bloc_des_raccourcis($bloc) { |
| 188 | 188 | return creer_colonne_droite() |
| 189 | - . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer(); |
|
| 189 | + . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis').$bloc.boite_fermer(); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | // |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -26,70 +26,70 @@ discard block |
||
| 26 | 26 | * @return string Code HTML du cadre dépliable |
| 27 | 27 | **/ |
| 28 | 28 | function cadre_depliable($icone, $titre, $deplie, $contenu, $ids = '', $style_cadre = 'r') { |
| 29 | - $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 30 | - |
|
| 31 | - return |
|
| 32 | - debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 33 | - . debut_block_depliable($deplie, $ids) |
|
| 34 | - . "<div class='cadre_padding'>\n" |
|
| 35 | - . $contenu |
|
| 36 | - . "</div>\n" |
|
| 37 | - . fin_block() |
|
| 38 | - . fin_cadre(); |
|
| 29 | + $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 30 | + |
|
| 31 | + return |
|
| 32 | + debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 33 | + . debut_block_depliable($deplie, $ids) |
|
| 34 | + . "<div class='cadre_padding'>\n" |
|
| 35 | + . $contenu |
|
| 36 | + . "</div>\n" |
|
| 37 | + . fin_block() |
|
| 38 | + . fin_cadre(); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | function block_parfois_visible($nom, $invite, $masque, $style = '', $visible = false) { |
| 42 | - return "\n" |
|
| 43 | - . bouton_block_depliable($invite, $visible, $nom) |
|
| 44 | - . debut_block_depliable($visible, $nom) |
|
| 45 | - . $masque |
|
| 46 | - . fin_block(); |
|
| 42 | + return "\n" |
|
| 43 | + . bouton_block_depliable($invite, $visible, $nom) |
|
| 44 | + . debut_block_depliable($visible, $nom) |
|
| 45 | + . $masque |
|
| 46 | + . fin_block(); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | function debut_block_depliable($deplie, $id = '') { |
| 50 | - $class = ' blocdeplie'; |
|
| 51 | - // si on n'accepte pas js, ne pas fermer |
|
| 52 | - if (!$deplie) { |
|
| 53 | - $class = ' blocreplie'; |
|
| 54 | - } |
|
| 50 | + $class = ' blocdeplie'; |
|
| 51 | + // si on n'accepte pas js, ne pas fermer |
|
| 52 | + if (!$deplie) { |
|
| 53 | + $class = ' blocreplie'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 56 | + return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function fin_block() { |
| 60 | - return "<div class='nettoyeur'></div>\n</div>"; |
|
| 60 | + return "<div class='nettoyeur'></div>\n</div>"; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // $texte : texte du bouton |
| 64 | 64 | // $deplie : true (deplie) ou false (plie) ou -1 (inactif) ou 'incertain' pour que le bouton s'auto init au chargement de la page |
| 65 | 65 | // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit) |
| 66 | 66 | function bouton_block_depliable($texte, $deplie, $ids = '') { |
| 67 | - $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 68 | - |
|
| 69 | - $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
|
| 70 | - if (strlen($ids)) { |
|
| 71 | - $cible = explode(',', $ids); |
|
| 72 | - $cible = '#' . implode(',#', $cible); |
|
| 73 | - } else { |
|
| 74 | - $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $b = (strpos($texte, '<h') === false ? 'h3' : 'div'); |
|
| 78 | - |
|
| 79 | - return "<$b " |
|
| 80 | - . ($bouton_id ? "id='$bouton_id' " : '') |
|
| 81 | - . "class='titrem$class'" |
|
| 82 | - . (($deplie === -1) |
|
| 83 | - ? '' |
|
| 84 | - : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 85 | - ) |
|
| 86 | - . '>' |
|
| 87 | - // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 88 | - . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 89 | - . "$texte</$b>" |
|
| 90 | - . http_script(($deplie === 'incertain') |
|
| 91 | - ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 92 | - : ''); |
|
| 67 | + $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 68 | + |
|
| 69 | + $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
|
| 70 | + if (strlen($ids)) { |
|
| 71 | + $cible = explode(',', $ids); |
|
| 72 | + $cible = '#' . implode(',#', $cible); |
|
| 73 | + } else { |
|
| 74 | + $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $b = (strpos($texte, '<h') === false ? 'h3' : 'div'); |
|
| 78 | + |
|
| 79 | + return "<$b " |
|
| 80 | + . ($bouton_id ? "id='$bouton_id' " : '') |
|
| 81 | + . "class='titrem$class'" |
|
| 82 | + . (($deplie === -1) |
|
| 83 | + ? '' |
|
| 84 | + : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 85 | + ) |
|
| 86 | + . '>' |
|
| 87 | + // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 88 | + . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 89 | + . "$texte</$b>" |
|
| 90 | + . http_script(($deplie === 'incertain') |
|
| 91 | + ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 92 | + : ''); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // |
@@ -97,66 +97,66 @@ discard block |
||
| 97 | 97 | // |
| 98 | 98 | function verif_butineur() { |
| 99 | 99 | |
| 100 | - preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 101 | - $GLOBALS['browser_name'] = $match[1]; |
|
| 102 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 103 | - $GLOBALS['browser_description'] = $match[3]; |
|
| 104 | - $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 105 | - $GLOBALS['browser_barre'] = ''; |
|
| 106 | - |
|
| 107 | - if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) { |
|
| 108 | - $GLOBALS['browser_name'] = 'Opera'; |
|
| 109 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 110 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 111 | - } else { |
|
| 112 | - if (preg_match(',opera,i', $GLOBALS['browser_description'])) { |
|
| 113 | - preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match); |
|
| 114 | - $GLOBALS['browser_name'] = 'Opera'; |
|
| 115 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 116 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 117 | - } else { |
|
| 118 | - if (preg_match(',msie,i', $GLOBALS['browser_description'])) { |
|
| 119 | - preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match); |
|
| 120 | - $GLOBALS['browser_name'] = 'MSIE'; |
|
| 121 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 122 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 123 | - } else { |
|
| 124 | - if ( |
|
| 125 | - preg_match(',KHTML,i', $GLOBALS['browser_description']) && |
|
| 126 | - preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match) |
|
| 127 | - ) { |
|
| 128 | - $GLOBALS['browser_name'] = 'Safari'; |
|
| 129 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 130 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 131 | - } else { |
|
| 132 | - if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) { |
|
| 133 | - // Numero de version pour Mozilla "authentique" |
|
| 134 | - if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) { |
|
| 135 | - $GLOBALS['browser_rev'] = doubleval($match[1]); |
|
| 136 | - } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 137 | - else { |
|
| 138 | - if ( |
|
| 139 | - strpos($GLOBALS['browser_description'], 'Gecko') and !strpos( |
|
| 140 | - $GLOBALS['browser_description'], |
|
| 141 | - 'KHTML' |
|
| 142 | - ) |
|
| 143 | - ) { |
|
| 144 | - $GLOBALS['browser_rev'] = 1.4; |
|
| 145 | - } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 146 | - else { |
|
| 147 | - $GLOBALS['browser_rev'] = 1.0; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (!$GLOBALS['browser_name']) { |
|
| 158 | - $GLOBALS['browser_name'] = 'Mozilla'; |
|
| 159 | - } |
|
| 100 | + preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 101 | + $GLOBALS['browser_name'] = $match[1]; |
|
| 102 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 103 | + $GLOBALS['browser_description'] = $match[3]; |
|
| 104 | + $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 105 | + $GLOBALS['browser_barre'] = ''; |
|
| 106 | + |
|
| 107 | + if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) { |
|
| 108 | + $GLOBALS['browser_name'] = 'Opera'; |
|
| 109 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 110 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 111 | + } else { |
|
| 112 | + if (preg_match(',opera,i', $GLOBALS['browser_description'])) { |
|
| 113 | + preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match); |
|
| 114 | + $GLOBALS['browser_name'] = 'Opera'; |
|
| 115 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 116 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 117 | + } else { |
|
| 118 | + if (preg_match(',msie,i', $GLOBALS['browser_description'])) { |
|
| 119 | + preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match); |
|
| 120 | + $GLOBALS['browser_name'] = 'MSIE'; |
|
| 121 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 122 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 123 | + } else { |
|
| 124 | + if ( |
|
| 125 | + preg_match(',KHTML,i', $GLOBALS['browser_description']) && |
|
| 126 | + preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match) |
|
| 127 | + ) { |
|
| 128 | + $GLOBALS['browser_name'] = 'Safari'; |
|
| 129 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 130 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 131 | + } else { |
|
| 132 | + if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) { |
|
| 133 | + // Numero de version pour Mozilla "authentique" |
|
| 134 | + if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) { |
|
| 135 | + $GLOBALS['browser_rev'] = doubleval($match[1]); |
|
| 136 | + } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 137 | + else { |
|
| 138 | + if ( |
|
| 139 | + strpos($GLOBALS['browser_description'], 'Gecko') and !strpos( |
|
| 140 | + $GLOBALS['browser_description'], |
|
| 141 | + 'KHTML' |
|
| 142 | + ) |
|
| 143 | + ) { |
|
| 144 | + $GLOBALS['browser_rev'] = 1.4; |
|
| 145 | + } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 146 | + else { |
|
| 147 | + $GLOBALS['browser_rev'] = 1.0; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (!$GLOBALS['browser_name']) { |
|
| 158 | + $GLOBALS['browser_name'] = 'Mozilla'; |
|
| 159 | + } |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | verif_butineur(); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $class = ' blocreplie'; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 56 | + return '<div '.($id ? "id='$id' " : '')."class='bloc_depliable$class'>"; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | function fin_block() { |
@@ -64,12 +64,12 @@ discard block |
||
| 64 | 64 | // $deplie : true (deplie) ou false (plie) ou -1 (inactif) ou 'incertain' pour que le bouton s'auto init au chargement de la page |
| 65 | 65 | // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit) |
| 66 | 66 | function bouton_block_depliable($texte, $deplie, $ids = '') { |
| 67 | - $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 67 | + $bouton_id = 'b'.substr(md5($texte.microtime()), 0, 8); |
|
| 68 | 68 | |
| 69 | 69 | $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
| 70 | 70 | if (strlen($ids)) { |
| 71 | 71 | $cible = explode(',', $ids); |
| 72 | - $cible = '#' . implode(',#', $cible); |
|
| 72 | + $cible = '#'.implode(',#', $cible); |
|
| 73 | 73 | } else { |
| 74 | 74 | $cible = "#$bouton_id + div.bloc_depliable"; |
| 75 | 75 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * Pile complétée du code compilé |
| 43 | 43 | **/ |
| 44 | 44 | function balise_FORMULAIRE_ADMIN($p) { |
| 45 | - return calculer_balise_dynamique($p, 'FORMULAIRE_ADMIN', []); |
|
| 45 | + return calculer_balise_dynamique($p, 'FORMULAIRE_ADMIN', []); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * - chaîne vide sinon. |
| 60 | 60 | */ |
| 61 | 61 | function balise_FORMULAIRE_ADMIN_stat($args, $context_compil) { |
| 62 | - return $args; |
|
| 62 | + return $args; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | |
@@ -84,66 +84,66 @@ discard block |
||
| 84 | 84 | **/ |
| 85 | 85 | function balise_FORMULAIRE_ADMIN_dyn($float = '', $debug = '') { |
| 86 | 86 | |
| 87 | - static $dejafait = false; |
|
| 87 | + static $dejafait = false; |
|
| 88 | 88 | |
| 89 | - if (empty($_COOKIE['spip_admin'])) { |
|
| 90 | - return ''; |
|
| 91 | - } |
|
| 89 | + if (empty($_COOKIE['spip_admin'])) { |
|
| 90 | + return ''; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - if (!is_array($debug)) { |
|
| 94 | - if ($dejafait) { |
|
| 95 | - return ''; |
|
| 96 | - } |
|
| 97 | - } else { |
|
| 98 | - if ($dejafait) { |
|
| 99 | - if (empty($debug['sourcefile'])) { |
|
| 100 | - return ''; |
|
| 101 | - } |
|
| 102 | - foreach ($debug['sourcefile'] as $k => $v) { |
|
| 103 | - if (strpos($v, 'administration.') !== false) { |
|
| 104 | - if (isset($debug['resultat'][$k . 'tout'])) { |
|
| 105 | - return $debug['resultat'][$k . 'tout']; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 93 | + if (!is_array($debug)) { |
|
| 94 | + if ($dejafait) { |
|
| 95 | + return ''; |
|
| 96 | + } |
|
| 97 | + } else { |
|
| 98 | + if ($dejafait) { |
|
| 99 | + if (empty($debug['sourcefile'])) { |
|
| 100 | + return ''; |
|
| 101 | + } |
|
| 102 | + foreach ($debug['sourcefile'] as $k => $v) { |
|
| 103 | + if (strpos($v, 'administration.') !== false) { |
|
| 104 | + if (isset($debug['resultat'][$k . 'tout'])) { |
|
| 105 | + return $debug['resultat'][$k . 'tout']; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - return ''; |
|
| 111 | - } |
|
| 112 | - } |
|
| 110 | + return ''; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - include_spip('inc/autoriser'); |
|
| 115 | - include_spip('base/abstract_sql'); |
|
| 114 | + include_spip('inc/autoriser'); |
|
| 115 | + include_spip('base/abstract_sql'); |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | - $dejafait = true; |
|
| 118 | + $dejafait = true; |
|
| 119 | 119 | |
| 120 | - // Preparer le #ENV des boutons |
|
| 120 | + // Preparer le #ENV des boutons |
|
| 121 | 121 | |
| 122 | - $env = admin_objet(); |
|
| 122 | + $env = admin_objet(); |
|
| 123 | 123 | |
| 124 | - // Pas de "modifier ce..." ? -> donner "acces a l'espace prive" |
|
| 125 | - if (!$env) { |
|
| 126 | - $env['ecrire'] = _DIR_RESTREINT_ABS; |
|
| 127 | - } |
|
| 124 | + // Pas de "modifier ce..." ? -> donner "acces a l'espace prive" |
|
| 125 | + if (!$env) { |
|
| 126 | + $env['ecrire'] = _DIR_RESTREINT_ABS; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - $env['divclass'] = $float; |
|
| 130 | - $env['lang'] = admin_lang(); |
|
| 131 | - $env['calcul'] = (_request('var_mode') ? 'recalcul' : 'calcul'); |
|
| 132 | - $env['debug'] = ((defined('_VAR_PREVIEW') and _VAR_PREVIEW) ? '' : admin_debug()); |
|
| 133 | - $env['analyser'] = (!$env['debug'] and !$GLOBALS['xhtml']) ? '' : admin_valider(); |
|
| 134 | - $env['inclure'] = ((defined('_VAR_INCLURE') and _VAR_INCLURE) ? 'inclure' : ''); |
|
| 129 | + $env['divclass'] = $float; |
|
| 130 | + $env['lang'] = admin_lang(); |
|
| 131 | + $env['calcul'] = (_request('var_mode') ? 'recalcul' : 'calcul'); |
|
| 132 | + $env['debug'] = ((defined('_VAR_PREVIEW') and _VAR_PREVIEW) ? '' : admin_debug()); |
|
| 133 | + $env['analyser'] = (!$env['debug'] and !$GLOBALS['xhtml']) ? '' : admin_valider(); |
|
| 134 | + $env['inclure'] = ((defined('_VAR_INCLURE') and _VAR_INCLURE) ? 'inclure' : ''); |
|
| 135 | 135 | |
| 136 | - if (empty($GLOBALS['use_cache'])) { |
|
| 137 | - $env['use_cache'] = ' *'; |
|
| 138 | - } |
|
| 136 | + if (empty($GLOBALS['use_cache'])) { |
|
| 137 | + $env['use_cache'] = ' *'; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - if (isset($debug['validation'])) { |
|
| 141 | - $env['xhtml_error'] = $debug['validation']; |
|
| 142 | - } |
|
| 140 | + if (isset($debug['validation'])) { |
|
| 141 | + $env['xhtml_error'] = $debug['validation']; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - $env['_pipelines']['formulaire_admin'] = []; |
|
| 144 | + $env['_pipelines']['formulaire_admin'] = []; |
|
| 145 | 145 | |
| 146 | - return ['formulaires/administration', 0, $env]; |
|
| 146 | + return ['formulaires/administration', 0, $env]; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | |
@@ -161,47 +161,47 @@ discard block |
||
| 161 | 161 | * Tableau de l'environnement calculé |
| 162 | 162 | **/ |
| 163 | 163 | function admin_objet() { |
| 164 | - include_spip('inc/urls'); |
|
| 165 | - $env = []; |
|
| 166 | - |
|
| 167 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 168 | - $objets = urls_liste_objets(false); |
|
| 169 | - $objets = array_diff($objets, ['rubrique']); |
|
| 170 | - $objets = array_reverse($objets); |
|
| 171 | - array_unshift($objets, 'rubrique'); |
|
| 172 | - foreach ($objets as $obj) { |
|
| 173 | - $type = $obj; |
|
| 174 | - if ( |
|
| 175 | - $type == objet_type($type, false) |
|
| 176 | - and $_id_type = id_table_objet($type) |
|
| 177 | - and isset($GLOBALS['contexte'][$_id_type]) |
|
| 178 | - and $id = $GLOBALS['contexte'][$_id_type] |
|
| 179 | - and !is_array($id) |
|
| 180 | - and $id = intval($id) |
|
| 181 | - and $desc = $trouver_table(table_objet_sql($type)) |
|
| 182 | - ) { |
|
| 183 | - $id = sql_getfetsel($_id_type, table_objet_sql($type), "$_id_type=" . intval($id)); |
|
| 184 | - if ($id) { |
|
| 185 | - $env[$_id_type] = $id; |
|
| 186 | - $env['objet'] = $type; |
|
| 187 | - $env['id_objet'] = $id; |
|
| 188 | - $env['voir_' . $obj] = |
|
| 189 | - str_replace('&', '&', generer_objet_url($id, $obj, '', '', false)); |
|
| 190 | - if ( |
|
| 191 | - isset($desc['field']['id_rubrique']) |
|
| 192 | - and $type != 'rubrique' |
|
| 193 | - ) { |
|
| 194 | - unset($env['id_rubrique']); |
|
| 195 | - unset($env['voir_rubrique']); |
|
| 196 | - if (admin_preview($type, $id, $desc)) { |
|
| 197 | - $env['preview'] = parametre_url(self(), 'var_mode', 'preview', '&'); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return $env; |
|
| 164 | + include_spip('inc/urls'); |
|
| 165 | + $env = []; |
|
| 166 | + |
|
| 167 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 168 | + $objets = urls_liste_objets(false); |
|
| 169 | + $objets = array_diff($objets, ['rubrique']); |
|
| 170 | + $objets = array_reverse($objets); |
|
| 171 | + array_unshift($objets, 'rubrique'); |
|
| 172 | + foreach ($objets as $obj) { |
|
| 173 | + $type = $obj; |
|
| 174 | + if ( |
|
| 175 | + $type == objet_type($type, false) |
|
| 176 | + and $_id_type = id_table_objet($type) |
|
| 177 | + and isset($GLOBALS['contexte'][$_id_type]) |
|
| 178 | + and $id = $GLOBALS['contexte'][$_id_type] |
|
| 179 | + and !is_array($id) |
|
| 180 | + and $id = intval($id) |
|
| 181 | + and $desc = $trouver_table(table_objet_sql($type)) |
|
| 182 | + ) { |
|
| 183 | + $id = sql_getfetsel($_id_type, table_objet_sql($type), "$_id_type=" . intval($id)); |
|
| 184 | + if ($id) { |
|
| 185 | + $env[$_id_type] = $id; |
|
| 186 | + $env['objet'] = $type; |
|
| 187 | + $env['id_objet'] = $id; |
|
| 188 | + $env['voir_' . $obj] = |
|
| 189 | + str_replace('&', '&', generer_objet_url($id, $obj, '', '', false)); |
|
| 190 | + if ( |
|
| 191 | + isset($desc['field']['id_rubrique']) |
|
| 192 | + and $type != 'rubrique' |
|
| 193 | + ) { |
|
| 194 | + unset($env['id_rubrique']); |
|
| 195 | + unset($env['voir_rubrique']); |
|
| 196 | + if (admin_preview($type, $id, $desc)) { |
|
| 197 | + $env['preview'] = parametre_url(self(), 'var_mode', 'preview', '&'); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return $env; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | |
@@ -219,30 +219,30 @@ discard block |
||
| 219 | 219 | * - Tableau d'un élément sinon. |
| 220 | 220 | **/ |
| 221 | 221 | function admin_preview($type, $id, $desc = null) { |
| 222 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW) { |
|
| 223 | - return ''; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - if (!$desc) { |
|
| 227 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 228 | - $desc = $trouver_table(table_objet_sql($type)); |
|
| 229 | - } |
|
| 230 | - if (!$desc or !isset($desc['field']['statut'])) { |
|
| 231 | - return ''; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - include_spip('inc/autoriser'); |
|
| 235 | - if (!autoriser('previsualiser')) { |
|
| 236 | - return ''; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - $notpub = sql_in('statut', ['prop', 'prive']); |
|
| 240 | - |
|
| 241 | - if ($type == 'article' and $GLOBALS['meta']['post_dates'] != 'oui') { |
|
| 242 | - $notpub .= " OR (statut='publie' AND date>" . sql_quote(date('Y-m-d H:i:s')) . ')'; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - return sql_fetsel('1', table_objet_sql($type), id_table_objet($type) . '=' . $id . " AND ($notpub)"); |
|
| 222 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW) { |
|
| 223 | + return ''; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + if (!$desc) { |
|
| 227 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 228 | + $desc = $trouver_table(table_objet_sql($type)); |
|
| 229 | + } |
|
| 230 | + if (!$desc or !isset($desc['field']['statut'])) { |
|
| 231 | + return ''; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + include_spip('inc/autoriser'); |
|
| 235 | + if (!autoriser('previsualiser')) { |
|
| 236 | + return ''; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + $notpub = sql_in('statut', ['prop', 'prive']); |
|
| 240 | + |
|
| 241 | + if ($type == 'article' and $GLOBALS['meta']['post_dates'] != 'oui') { |
|
| 242 | + $notpub .= " OR (statut='publie' AND date>" . sql_quote(date('Y-m-d H:i:s')) . ')'; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + return sql_fetsel('1', table_objet_sql($type), id_table_objet($type) . '=' . $id . " AND ($notpub)"); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -253,25 +253,25 @@ discard block |
||
| 253 | 253 | * Code de langue |
| 254 | 254 | **/ |
| 255 | 255 | function admin_lang() { |
| 256 | - $alang = ''; |
|
| 257 | - if (!empty($_COOKIE['spip_admin'])) { |
|
| 258 | - $email_or_login = preg_replace(',^@,', '', $_COOKIE['spip_admin']); |
|
| 259 | - $alang = sql_getfetsel('lang', 'spip_auteurs', 'email=' . sql_quote($email_or_login)); |
|
| 260 | - if (!$alang) { |
|
| 261 | - $alang = sql_getfetsel('lang', 'spip_auteurs', 'login=' . sql_quote($email_or_login)); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - if (!$alang) { |
|
| 265 | - return ''; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - $l = lang_select($alang); |
|
| 269 | - $alang = $GLOBALS['spip_lang']; |
|
| 270 | - if ($l) { |
|
| 271 | - lang_select(); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - return $alang; |
|
| 256 | + $alang = ''; |
|
| 257 | + if (!empty($_COOKIE['spip_admin'])) { |
|
| 258 | + $email_or_login = preg_replace(',^@,', '', $_COOKIE['spip_admin']); |
|
| 259 | + $alang = sql_getfetsel('lang', 'spip_auteurs', 'email=' . sql_quote($email_or_login)); |
|
| 260 | + if (!$alang) { |
|
| 261 | + $alang = sql_getfetsel('lang', 'spip_auteurs', 'login=' . sql_quote($email_or_login)); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + if (!$alang) { |
|
| 265 | + return ''; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + $l = lang_select($alang); |
|
| 269 | + $alang = $GLOBALS['spip_lang']; |
|
| 270 | + if ($l) { |
|
| 271 | + lang_select(); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + return $alang; |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -281,11 +281,11 @@ discard block |
||
| 281 | 281 | **/ |
| 282 | 282 | function admin_valider() { |
| 283 | 283 | |
| 284 | - return ((!isset($GLOBALS['xhtml']) or $GLOBALS['xhtml'] !== 'true') ? |
|
| 285 | - (parametre_url(self(), 'var_mode', 'debug', '&') |
|
| 286 | - . '&var_mode_affiche=validation') : |
|
| 287 | - ('http://validator.w3.org/check?uri=' |
|
| 288 | - . rawurlencode('http://' . $_SERVER['HTTP_HOST'] . nettoyer_uri()))); |
|
| 284 | + return ((!isset($GLOBALS['xhtml']) or $GLOBALS['xhtml'] !== 'true') ? |
|
| 285 | + (parametre_url(self(), 'var_mode', 'debug', '&') |
|
| 286 | + . '&var_mode_affiche=validation') : |
|
| 287 | + ('http://validator.w3.org/check?uri=' |
|
| 288 | + . rawurlencode('http://' . $_SERVER['HTTP_HOST'] . nettoyer_uri()))); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -294,14 +294,14 @@ discard block |
||
| 294 | 294 | * @return string |
| 295 | 295 | **/ |
| 296 | 296 | function admin_debug() { |
| 297 | - return (( |
|
| 298 | - (isset($GLOBALS['forcer_debug']) and $GLOBALS['forcer_debug']) |
|
| 299 | - or (isset($GLOBALS['bouton_admin_debug']) and $GLOBALS['bouton_admin_debug']) |
|
| 300 | - or ( |
|
| 301 | - defined('_VAR_MODE') and _VAR_MODE == 'debug' |
|
| 302 | - and isset($_COOKIE['spip_debug']) and $_COOKIE['spip_debug'] |
|
| 303 | - ) |
|
| 304 | - ) and autoriser('debug') |
|
| 305 | - ) |
|
| 306 | - ? parametre_url(self(), 'var_mode', 'debug', '&') : ''; |
|
| 297 | + return (( |
|
| 298 | + (isset($GLOBALS['forcer_debug']) and $GLOBALS['forcer_debug']) |
|
| 299 | + or (isset($GLOBALS['bouton_admin_debug']) and $GLOBALS['bouton_admin_debug']) |
|
| 300 | + or ( |
|
| 301 | + defined('_VAR_MODE') and _VAR_MODE == 'debug' |
|
| 302 | + and isset($_COOKIE['spip_debug']) and $_COOKIE['spip_debug'] |
|
| 303 | + ) |
|
| 304 | + ) and autoriser('debug') |
|
| 305 | + ) |
|
| 306 | + ? parametre_url(self(), 'var_mode', 'debug', '&') : ''; |
|
| 307 | 307 | } |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | foreach ($debug['sourcefile'] as $k => $v) { |
| 103 | 103 | if (strpos($v, 'administration.') !== false) { |
| 104 | - if (isset($debug['resultat'][$k . 'tout'])) { |
|
| 105 | - return $debug['resultat'][$k . 'tout']; |
|
| 104 | + if (isset($debug['resultat'][$k.'tout'])) { |
|
| 105 | + return $debug['resultat'][$k.'tout']; |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -180,12 +180,12 @@ discard block |
||
| 180 | 180 | and $id = intval($id) |
| 181 | 181 | and $desc = $trouver_table(table_objet_sql($type)) |
| 182 | 182 | ) { |
| 183 | - $id = sql_getfetsel($_id_type, table_objet_sql($type), "$_id_type=" . intval($id)); |
|
| 183 | + $id = sql_getfetsel($_id_type, table_objet_sql($type), "$_id_type=".intval($id)); |
|
| 184 | 184 | if ($id) { |
| 185 | 185 | $env[$_id_type] = $id; |
| 186 | 186 | $env['objet'] = $type; |
| 187 | 187 | $env['id_objet'] = $id; |
| 188 | - $env['voir_' . $obj] = |
|
| 188 | + $env['voir_'.$obj] = |
|
| 189 | 189 | str_replace('&', '&', generer_objet_url($id, $obj, '', '', false)); |
| 190 | 190 | if ( |
| 191 | 191 | isset($desc['field']['id_rubrique']) |
@@ -239,10 +239,10 @@ discard block |
||
| 239 | 239 | $notpub = sql_in('statut', ['prop', 'prive']); |
| 240 | 240 | |
| 241 | 241 | if ($type == 'article' and $GLOBALS['meta']['post_dates'] != 'oui') { |
| 242 | - $notpub .= " OR (statut='publie' AND date>" . sql_quote(date('Y-m-d H:i:s')) . ')'; |
|
| 242 | + $notpub .= " OR (statut='publie' AND date>".sql_quote(date('Y-m-d H:i:s')).')'; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - return sql_fetsel('1', table_objet_sql($type), id_table_objet($type) . '=' . $id . " AND ($notpub)"); |
|
| 245 | + return sql_fetsel('1', table_objet_sql($type), id_table_objet($type).'='.$id." AND ($notpub)"); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | $alang = ''; |
| 257 | 257 | if (!empty($_COOKIE['spip_admin'])) { |
| 258 | 258 | $email_or_login = preg_replace(',^@,', '', $_COOKIE['spip_admin']); |
| 259 | - $alang = sql_getfetsel('lang', 'spip_auteurs', 'email=' . sql_quote($email_or_login)); |
|
| 259 | + $alang = sql_getfetsel('lang', 'spip_auteurs', 'email='.sql_quote($email_or_login)); |
|
| 260 | 260 | if (!$alang) { |
| 261 | - $alang = sql_getfetsel('lang', 'spip_auteurs', 'login=' . sql_quote($email_or_login)); |
|
| 261 | + $alang = sql_getfetsel('lang', 'spip_auteurs', 'login='.sql_quote($email_or_login)); |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | if (!$alang) { |
@@ -283,9 +283,8 @@ discard block |
||
| 283 | 283 | |
| 284 | 284 | return ((!isset($GLOBALS['xhtml']) or $GLOBALS['xhtml'] !== 'true') ? |
| 285 | 285 | (parametre_url(self(), 'var_mode', 'debug', '&') |
| 286 | - . '&var_mode_affiche=validation') : |
|
| 287 | - ('http://validator.w3.org/check?uri=' |
|
| 288 | - . rawurlencode('http://' . $_SERVER['HTTP_HOST'] . nettoyer_uri()))); |
|
| 286 | + . '&var_mode_affiche=validation') : ('http://validator.w3.org/check?uri=' |
|
| 287 | + . rawurlencode('http://'.$_SERVER['HTTP_HOST'].nettoyer_uri()))); |
|
| 289 | 288 | } |
| 290 | 289 | |
| 291 | 290 | /** |
@@ -54,12 +54,12 @@ |
||
| 54 | 54 | $_params = '['; |
| 55 | 55 | $nb_params = is_countable($p->param[0]) ? count($p->param[0]) : 0; // 1ère valeur vide donc 1 en plus |
| 56 | 56 | for ($i = 3; $i < $nb_params; $i++) { |
| 57 | - $_params .= interprete_argument_balise($i, $p) . ','; |
|
| 57 | + $_params .= interprete_argument_balise($i, $p).','; |
|
| 58 | 58 | } |
| 59 | 59 | $_params .= ']'; |
| 60 | 60 | |
| 61 | 61 | $info_sql = strtolower(substr($info, 5)); |
| 62 | - $code = "generer_objet_info($id_objet, $type_objet, '$info_sql', " . ($p->etoile ? _q($p->etoile) : "''") . ", $_params)"; |
|
| 62 | + $code = "generer_objet_info($id_objet, $type_objet, '$info_sql', ".($p->etoile ? _q($p->etoile) : "''").", $_params)"; |
|
| 63 | 63 | $p->code = champ_sql($info, $p, $code); |
| 64 | 64 | $p->interdire_scripts = true; |
| 65 | 65 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -39,29 +39,29 @@ discard block |
||
| 39 | 39 | * Pile complétée par le code à générer |
| 40 | 40 | */ |
| 41 | 41 | function balise_INFO__dist($p) { |
| 42 | - $info = $p->nom_champ; |
|
| 43 | - $type_objet = interprete_argument_balise(1, $p); |
|
| 44 | - $id_objet = interprete_argument_balise(2, $p); |
|
| 45 | - if ($info === 'INFO_' || !$type_objet || !$id_objet) { |
|
| 46 | - $msg = _T('zbug_balise_sans_argument', ['balise' => ' INFO_']); |
|
| 47 | - erreur_squelette($msg, $p); |
|
| 48 | - $p->interdire_scripts = true; |
|
| 42 | + $info = $p->nom_champ; |
|
| 43 | + $type_objet = interprete_argument_balise(1, $p); |
|
| 44 | + $id_objet = interprete_argument_balise(2, $p); |
|
| 45 | + if ($info === 'INFO_' || !$type_objet || !$id_objet) { |
|
| 46 | + $msg = _T('zbug_balise_sans_argument', ['balise' => ' INFO_']); |
|
| 47 | + erreur_squelette($msg, $p); |
|
| 48 | + $p->interdire_scripts = true; |
|
| 49 | 49 | |
| 50 | - return $p; |
|
| 51 | - } else { |
|
| 52 | - // Récupérer tous les params à la suite de objet et id_objet |
|
| 53 | - $_params = '['; |
|
| 54 | - $nb_params = is_countable($p->param[0]) ? count($p->param[0]) : 0; // 1ère valeur vide donc 1 en plus |
|
| 55 | - for ($i = 3; $i < $nb_params; $i++) { |
|
| 56 | - $_params .= interprete_argument_balise($i, $p) . ','; |
|
| 57 | - } |
|
| 58 | - $_params .= ']'; |
|
| 50 | + return $p; |
|
| 51 | + } else { |
|
| 52 | + // Récupérer tous les params à la suite de objet et id_objet |
|
| 53 | + $_params = '['; |
|
| 54 | + $nb_params = is_countable($p->param[0]) ? count($p->param[0]) : 0; // 1ère valeur vide donc 1 en plus |
|
| 55 | + for ($i = 3; $i < $nb_params; $i++) { |
|
| 56 | + $_params .= interprete_argument_balise($i, $p) . ','; |
|
| 57 | + } |
|
| 58 | + $_params .= ']'; |
|
| 59 | 59 | |
| 60 | - $info_sql = strtolower(substr($info, 5)); |
|
| 61 | - $code = "generer_objet_info($id_objet, $type_objet, '$info_sql', " . ($p->etoile ? _q($p->etoile) : "''") . ", $_params)"; |
|
| 62 | - $p->code = champ_sql($info, $p, $code); |
|
| 63 | - $p->interdire_scripts = true; |
|
| 60 | + $info_sql = strtolower(substr($info, 5)); |
|
| 61 | + $code = "generer_objet_info($id_objet, $type_objet, '$info_sql', " . ($p->etoile ? _q($p->etoile) : "''") . ", $_params)"; |
|
| 62 | + $p->code = champ_sql($info, $p, $code); |
|
| 63 | + $p->interdire_scripts = true; |
|
| 64 | 64 | |
| 65 | - return $p; |
|
| 66 | - } |
|
| 65 | + return $p; |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/autoriser'); |
@@ -35,42 +35,42 @@ discard block |
||
| 35 | 35 | **/ |
| 36 | 36 | function action_menu_rubriques_dist() { |
| 37 | 37 | |
| 38 | - // si pas acces a ecrire, pas acces au menu |
|
| 39 | - // on renvoi un 401 qui fait echouer la requete ajax silencieusement |
|
| 40 | - if (!autoriser('ecrire')) { |
|
| 41 | - $retour = |
|
| 42 | - '<ul class="deroulant__sous-menu" data-profondeur="1">' . |
|
| 43 | - '<li class="deroulant__item deroulant__item_plan plan_site" data-profondeur="1">' . |
|
| 44 | - '<a class="deroulant__lien" href="' . generer_url_ecrire('accueil') . '" data-profondeur="1">' . |
|
| 45 | - '<span class="libelle">' . _T('public:lien_connecter') . '</span>' . |
|
| 46 | - '</a>' . |
|
| 47 | - '</li>' . |
|
| 48 | - '</ul>'; |
|
| 49 | - include_spip('inc/actions'); |
|
| 50 | - ajax_retour($retour); |
|
| 51 | - exit; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if ($date = intval(_request('date'))) { |
|
| 55 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $date) . ' GMT'); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - $r = gen_liste_rubriques(); |
|
| 59 | - if ( |
|
| 60 | - !$r |
|
| 61 | - and isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 62 | - and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 63 | - ) { |
|
| 64 | - include_spip('inc/headers'); |
|
| 65 | - header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']); |
|
| 66 | - http_response_code(304); |
|
| 67 | - exit; |
|
| 68 | - } else { |
|
| 69 | - include_spip('inc/actions'); |
|
| 70 | - $ret = menu_rubriques(); |
|
| 71 | - ajax_retour($ret); |
|
| 72 | - exit; |
|
| 73 | - } |
|
| 38 | + // si pas acces a ecrire, pas acces au menu |
|
| 39 | + // on renvoi un 401 qui fait echouer la requete ajax silencieusement |
|
| 40 | + if (!autoriser('ecrire')) { |
|
| 41 | + $retour = |
|
| 42 | + '<ul class="deroulant__sous-menu" data-profondeur="1">' . |
|
| 43 | + '<li class="deroulant__item deroulant__item_plan plan_site" data-profondeur="1">' . |
|
| 44 | + '<a class="deroulant__lien" href="' . generer_url_ecrire('accueil') . '" data-profondeur="1">' . |
|
| 45 | + '<span class="libelle">' . _T('public:lien_connecter') . '</span>' . |
|
| 46 | + '</a>' . |
|
| 47 | + '</li>' . |
|
| 48 | + '</ul>'; |
|
| 49 | + include_spip('inc/actions'); |
|
| 50 | + ajax_retour($retour); |
|
| 51 | + exit; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if ($date = intval(_request('date'))) { |
|
| 55 | + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $date) . ' GMT'); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + $r = gen_liste_rubriques(); |
|
| 59 | + if ( |
|
| 60 | + !$r |
|
| 61 | + and isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 62 | + and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 63 | + ) { |
|
| 64 | + include_spip('inc/headers'); |
|
| 65 | + header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']); |
|
| 66 | + http_response_code(304); |
|
| 67 | + exit; |
|
| 68 | + } else { |
|
| 69 | + include_spip('inc/actions'); |
|
| 70 | + $ret = menu_rubriques(); |
|
| 71 | + ajax_retour($ret); |
|
| 72 | + exit; |
|
| 73 | + } |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -84,44 +84,44 @@ discard block |
||
| 84 | 84 | * Code HTML présentant la liste des rubriques |
| 85 | 85 | **/ |
| 86 | 86 | function menu_rubriques($complet = true) { |
| 87 | - $ret = '<li class="deroulant__item deroulant__item_tout toutsite" data-profondeur="1">' |
|
| 88 | - . '<a class="deroulant__lien" href="' . generer_url_ecrire('plan') . '" data-profondeur="1">' |
|
| 89 | - . '<span class="libelle">' . _T('info_tout_site') . '</span>' |
|
| 90 | - . '</a>' |
|
| 91 | - . '</li>'; |
|
| 92 | - |
|
| 93 | - if (!$complet) { |
|
| 94 | - return "<ul class=\"deroulant__sous-menu\" data-profondeur=\"1\">$ret\n</ul>\n"; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if (!isset($GLOBALS['db_art_cache'])) { |
|
| 98 | - gen_liste_rubriques(); |
|
| 99 | - } |
|
| 100 | - $arr_low = extraire_article(0, $GLOBALS['db_art_cache']); |
|
| 101 | - |
|
| 102 | - $total_lignes = $i = sizeof($arr_low); |
|
| 103 | - |
|
| 104 | - if ($i > 0) { |
|
| 105 | - $nb_col = min(8, ceil($total_lignes / 30)); |
|
| 106 | - if ($nb_col <= 1) { |
|
| 107 | - $nb_col = ceil($total_lignes / 10); |
|
| 108 | - } |
|
| 109 | - foreach ($arr_low as $id_rubrique => $titre_rubrique) { |
|
| 110 | - if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 111 | - $ret .= bandeau_rubrique($id_rubrique, $titre_rubrique, $i); |
|
| 112 | - $i++; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $class_cols = ($nb_col > 1 ? "cols-$nb_col" : ''); |
|
| 117 | - $ret = "<ul class=\"deroulant__sous-menu $class_cols\" data-profondeur=\"1\">" |
|
| 118 | - . $ret |
|
| 119 | - . "\n</ul>\n"; |
|
| 120 | - } else { |
|
| 121 | - $ret = "<ul class=\"deroulant__sous-menu\" data-profondeur=\"1\">$ret\n</ul>\n"; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $ret; |
|
| 87 | + $ret = '<li class="deroulant__item deroulant__item_tout toutsite" data-profondeur="1">' |
|
| 88 | + . '<a class="deroulant__lien" href="' . generer_url_ecrire('plan') . '" data-profondeur="1">' |
|
| 89 | + . '<span class="libelle">' . _T('info_tout_site') . '</span>' |
|
| 90 | + . '</a>' |
|
| 91 | + . '</li>'; |
|
| 92 | + |
|
| 93 | + if (!$complet) { |
|
| 94 | + return "<ul class=\"deroulant__sous-menu\" data-profondeur=\"1\">$ret\n</ul>\n"; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if (!isset($GLOBALS['db_art_cache'])) { |
|
| 98 | + gen_liste_rubriques(); |
|
| 99 | + } |
|
| 100 | + $arr_low = extraire_article(0, $GLOBALS['db_art_cache']); |
|
| 101 | + |
|
| 102 | + $total_lignes = $i = sizeof($arr_low); |
|
| 103 | + |
|
| 104 | + if ($i > 0) { |
|
| 105 | + $nb_col = min(8, ceil($total_lignes / 30)); |
|
| 106 | + if ($nb_col <= 1) { |
|
| 107 | + $nb_col = ceil($total_lignes / 10); |
|
| 108 | + } |
|
| 109 | + foreach ($arr_low as $id_rubrique => $titre_rubrique) { |
|
| 110 | + if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 111 | + $ret .= bandeau_rubrique($id_rubrique, $titre_rubrique, $i); |
|
| 112 | + $i++; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $class_cols = ($nb_col > 1 ? "cols-$nb_col" : ''); |
|
| 117 | + $ret = "<ul class=\"deroulant__sous-menu $class_cols\" data-profondeur=\"1\">" |
|
| 118 | + . $ret |
|
| 119 | + . "\n</ul>\n"; |
|
| 120 | + } else { |
|
| 121 | + $ret = "<ul class=\"deroulant__sous-menu\" data-profondeur=\"1\">$ret\n</ul>\n"; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $ret; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -142,48 +142,48 @@ discard block |
||
| 142 | 142 | * Code HTML présentant la liste des rubriques |
| 143 | 143 | **/ |
| 144 | 144 | function bandeau_rubrique($id_rubrique, $titre_rubrique, $zdecal, $profondeur = 1) { |
| 145 | - static $zmax = 6; |
|
| 146 | - $profondeur_next = $profondeur + 1; |
|
| 147 | - |
|
| 148 | - $nav = '<a class="deroulant__lien" href="' . generer_objet_url($id_rubrique, 'rubrique', '', '', false) . "\" data-profondeur=\"$profondeur\">" |
|
| 149 | - . '<span class="libelle">' . supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique)) . '</span>' |
|
| 150 | - . "</a>\n"; |
|
| 151 | - |
|
| 152 | - // Limiter volontairement le nombre de sous-menus |
|
| 153 | - if (!(--$zmax)) { |
|
| 154 | - $zmax++; |
|
| 155 | - |
|
| 156 | - return "\n<li class=\"deroulant__item\" data-profondeur=\"$profondeur\">$nav</li>"; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - $arr_rub = extraire_article($id_rubrique, $GLOBALS['db_art_cache']); |
|
| 160 | - $i = sizeof($arr_rub); |
|
| 161 | - if (!$i) { |
|
| 162 | - $zmax++; |
|
| 163 | - |
|
| 164 | - return "\n<li class=\"deroulant__item\" data-profondeur=\"$profondeur\">$nav</li>"; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - $nb_col = 1; |
|
| 169 | - if ($nb_rub = count($arr_rub)) { |
|
| 170 | - $nb_col = min(10, max(1, ceil($nb_rub / 10))); |
|
| 171 | - } |
|
| 172 | - $class_cols = ($nb_col > 1 ? "cols-$nb_col" : ''); |
|
| 173 | - $ret = "<li class=\"deroulant__item deroulant__item_parent\" data-profondeur=\"$profondeur\">" |
|
| 174 | - . $nav |
|
| 175 | - . "<ul class=\"deroulant__sous-menu $class_cols\" data-profondeur=\"$profondeur_next\">"; |
|
| 176 | - foreach ($arr_rub as $id_rub => $titre_rub) { |
|
| 177 | - if (autoriser('voir', 'rubrique', $id_rub)) { |
|
| 178 | - $titre = supprimer_numero(typo($titre_rub)); |
|
| 179 | - $ret .= bandeau_rubrique($id_rub, $titre, $zdecal + $i, $profondeur_next); |
|
| 180 | - $i++; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - $ret .= "</ul></li>\n"; |
|
| 184 | - $zmax++; |
|
| 185 | - |
|
| 186 | - return $ret; |
|
| 145 | + static $zmax = 6; |
|
| 146 | + $profondeur_next = $profondeur + 1; |
|
| 147 | + |
|
| 148 | + $nav = '<a class="deroulant__lien" href="' . generer_objet_url($id_rubrique, 'rubrique', '', '', false) . "\" data-profondeur=\"$profondeur\">" |
|
| 149 | + . '<span class="libelle">' . supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique)) . '</span>' |
|
| 150 | + . "</a>\n"; |
|
| 151 | + |
|
| 152 | + // Limiter volontairement le nombre de sous-menus |
|
| 153 | + if (!(--$zmax)) { |
|
| 154 | + $zmax++; |
|
| 155 | + |
|
| 156 | + return "\n<li class=\"deroulant__item\" data-profondeur=\"$profondeur\">$nav</li>"; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + $arr_rub = extraire_article($id_rubrique, $GLOBALS['db_art_cache']); |
|
| 160 | + $i = sizeof($arr_rub); |
|
| 161 | + if (!$i) { |
|
| 162 | + $zmax++; |
|
| 163 | + |
|
| 164 | + return "\n<li class=\"deroulant__item\" data-profondeur=\"$profondeur\">$nav</li>"; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + $nb_col = 1; |
|
| 169 | + if ($nb_rub = count($arr_rub)) { |
|
| 170 | + $nb_col = min(10, max(1, ceil($nb_rub / 10))); |
|
| 171 | + } |
|
| 172 | + $class_cols = ($nb_col > 1 ? "cols-$nb_col" : ''); |
|
| 173 | + $ret = "<li class=\"deroulant__item deroulant__item_parent\" data-profondeur=\"$profondeur\">" |
|
| 174 | + . $nav |
|
| 175 | + . "<ul class=\"deroulant__sous-menu $class_cols\" data-profondeur=\"$profondeur_next\">"; |
|
| 176 | + foreach ($arr_rub as $id_rub => $titre_rub) { |
|
| 177 | + if (autoriser('voir', 'rubrique', $id_rub)) { |
|
| 178 | + $titre = supprimer_numero(typo($titre_rub)); |
|
| 179 | + $ret .= bandeau_rubrique($id_rub, $titre, $zdecal + $i, $profondeur_next); |
|
| 180 | + $i++; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + $ret .= "</ul></li>\n"; |
|
| 184 | + $zmax++; |
|
| 185 | + |
|
| 186 | + return $ret; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * Liste des rubriques enfants de la rubrique (et leur titre) |
| 202 | 202 | **/ |
| 203 | 203 | function extraire_article($id_p, $t) { |
| 204 | - return array_key_exists($id_p, $t) ? $t[$id_p] : []; |
|
| 204 | + return array_key_exists($id_p, $t) ? $t[$id_p] : []; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -217,42 +217,42 @@ discard block |
||
| 217 | 217 | **/ |
| 218 | 218 | function gen_liste_rubriques() { |
| 219 | 219 | |
| 220 | - $cache = null; |
|
| 221 | - include_spip('inc/config'); |
|
| 222 | - // ici, un petit fichier cache ne fait pas de mal |
|
| 223 | - $last = lire_config('date_calcul_rubriques', 0); |
|
| 224 | - if (lire_fichier(_CACHE_RUBRIQUES, $cache)) { |
|
| 225 | - [$date, $GLOBALS['db_art_cache']] = @unserialize($cache); |
|
| 226 | - if ($date == $last) { |
|
| 227 | - return false; |
|
| 228 | - } // c'etait en cache :-) |
|
| 229 | - } |
|
| 230 | - // se restreindre aux rubriques utilisees recemment +secteurs |
|
| 231 | - |
|
| 232 | - $where = sql_in_select( |
|
| 233 | - 'id_rubrique', |
|
| 234 | - 'id_rubrique', |
|
| 235 | - 'spip_rubriques', |
|
| 236 | - '', |
|
| 237 | - '', |
|
| 238 | - 'id_parent=0 DESC, date DESC', |
|
| 239 | - _CACHE_RUBRIQUES_MAX |
|
| 240 | - ); |
|
| 241 | - |
|
| 242 | - // puis refaire la requete pour avoir l'ordre alphabetique |
|
| 243 | - |
|
| 244 | - $res = sql_select('id_rubrique, titre, id_parent', 'spip_rubriques', $where, '', 'id_parent, 0+titre, titre'); |
|
| 245 | - |
|
| 246 | - // il ne faut pas filtrer le autoriser voir ici |
|
| 247 | - // car on met le resultat en cache, commun a tout le monde |
|
| 248 | - $GLOBALS['db_art_cache'] = []; |
|
| 249 | - while ($r = sql_fetch($res)) { |
|
| 250 | - $t = sinon($r['titre'], _T('ecrire:info_sans_titre')); |
|
| 251 | - $GLOBALS['db_art_cache'][$r['id_parent']][$r['id_rubrique']] = supprimer_numero(typo($t)); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - $t = [$last ?: time(), $GLOBALS['db_art_cache']]; |
|
| 255 | - ecrire_fichier(_CACHE_RUBRIQUES, serialize($t)); |
|
| 256 | - |
|
| 257 | - return true; |
|
| 220 | + $cache = null; |
|
| 221 | + include_spip('inc/config'); |
|
| 222 | + // ici, un petit fichier cache ne fait pas de mal |
|
| 223 | + $last = lire_config('date_calcul_rubriques', 0); |
|
| 224 | + if (lire_fichier(_CACHE_RUBRIQUES, $cache)) { |
|
| 225 | + [$date, $GLOBALS['db_art_cache']] = @unserialize($cache); |
|
| 226 | + if ($date == $last) { |
|
| 227 | + return false; |
|
| 228 | + } // c'etait en cache :-) |
|
| 229 | + } |
|
| 230 | + // se restreindre aux rubriques utilisees recemment +secteurs |
|
| 231 | + |
|
| 232 | + $where = sql_in_select( |
|
| 233 | + 'id_rubrique', |
|
| 234 | + 'id_rubrique', |
|
| 235 | + 'spip_rubriques', |
|
| 236 | + '', |
|
| 237 | + '', |
|
| 238 | + 'id_parent=0 DESC, date DESC', |
|
| 239 | + _CACHE_RUBRIQUES_MAX |
|
| 240 | + ); |
|
| 241 | + |
|
| 242 | + // puis refaire la requete pour avoir l'ordre alphabetique |
|
| 243 | + |
|
| 244 | + $res = sql_select('id_rubrique, titre, id_parent', 'spip_rubriques', $where, '', 'id_parent, 0+titre, titre'); |
|
| 245 | + |
|
| 246 | + // il ne faut pas filtrer le autoriser voir ici |
|
| 247 | + // car on met le resultat en cache, commun a tout le monde |
|
| 248 | + $GLOBALS['db_art_cache'] = []; |
|
| 249 | + while ($r = sql_fetch($res)) { |
|
| 250 | + $t = sinon($r['titre'], _T('ecrire:info_sans_titre')); |
|
| 251 | + $GLOBALS['db_art_cache'][$r['id_parent']][$r['id_rubrique']] = supprimer_numero(typo($t)); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + $t = [$last ?: time(), $GLOBALS['db_art_cache']]; |
|
| 255 | + ecrire_fichier(_CACHE_RUBRIQUES, serialize($t)); |
|
| 256 | + |
|
| 257 | + return true; |
|
| 258 | 258 | } |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | // on renvoi un 401 qui fait echouer la requete ajax silencieusement |
| 40 | 40 | if (!autoriser('ecrire')) { |
| 41 | 41 | $retour = |
| 42 | - '<ul class="deroulant__sous-menu" data-profondeur="1">' . |
|
| 43 | - '<li class="deroulant__item deroulant__item_plan plan_site" data-profondeur="1">' . |
|
| 44 | - '<a class="deroulant__lien" href="' . generer_url_ecrire('accueil') . '" data-profondeur="1">' . |
|
| 45 | - '<span class="libelle">' . _T('public:lien_connecter') . '</span>' . |
|
| 46 | - '</a>' . |
|
| 47 | - '</li>' . |
|
| 42 | + '<ul class="deroulant__sous-menu" data-profondeur="1">'. |
|
| 43 | + '<li class="deroulant__item deroulant__item_plan plan_site" data-profondeur="1">'. |
|
| 44 | + '<a class="deroulant__lien" href="'.generer_url_ecrire('accueil').'" data-profondeur="1">'. |
|
| 45 | + '<span class="libelle">'._T('public:lien_connecter').'</span>'. |
|
| 46 | + '</a>'. |
|
| 47 | + '</li>'. |
|
| 48 | 48 | '</ul>'; |
| 49 | 49 | include_spip('inc/actions'); |
| 50 | 50 | ajax_retour($retour); |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | if ($date = intval(_request('date'))) { |
| 55 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $date) . ' GMT'); |
|
| 55 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $date).' GMT'); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | $r = gen_liste_rubriques(); |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
| 63 | 63 | ) { |
| 64 | 64 | include_spip('inc/headers'); |
| 65 | - header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']); |
|
| 65 | + header('Content-Type: text/html; charset='.$GLOBALS['meta']['charset']); |
|
| 66 | 66 | http_response_code(304); |
| 67 | 67 | exit; |
| 68 | 68 | } else { |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | **/ |
| 86 | 86 | function menu_rubriques($complet = true) { |
| 87 | 87 | $ret = '<li class="deroulant__item deroulant__item_tout toutsite" data-profondeur="1">' |
| 88 | - . '<a class="deroulant__lien" href="' . generer_url_ecrire('plan') . '" data-profondeur="1">' |
|
| 89 | - . '<span class="libelle">' . _T('info_tout_site') . '</span>' |
|
| 88 | + . '<a class="deroulant__lien" href="'.generer_url_ecrire('plan').'" data-profondeur="1">' |
|
| 89 | + . '<span class="libelle">'._T('info_tout_site').'</span>' |
|
| 90 | 90 | . '</a>' |
| 91 | 91 | . '</li>'; |
| 92 | 92 | |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | static $zmax = 6; |
| 146 | 146 | $profondeur_next = $profondeur + 1; |
| 147 | 147 | |
| 148 | - $nav = '<a class="deroulant__lien" href="' . generer_objet_url($id_rubrique, 'rubrique', '', '', false) . "\" data-profondeur=\"$profondeur\">" |
|
| 149 | - . '<span class="libelle">' . supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique)) . '</span>' |
|
| 148 | + $nav = '<a class="deroulant__lien" href="'.generer_objet_url($id_rubrique, 'rubrique', '', '', false)."\" data-profondeur=\"$profondeur\">" |
|
| 149 | + . '<span class="libelle">'.supprimer_tags(preg_replace(',[\x00-\x1f]+,', ' ', $titre_rubrique)).'</span>' |
|
| 150 | 150 | . "</a>\n"; |
| 151 | 151 | |
| 152 | 152 | // Limiter volontairement le nombre de sous-menus |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -36,56 +36,56 @@ discard block |
||
| 36 | 36 | * ``` |
| 37 | 37 | **/ |
| 38 | 38 | function action_redirect_dist() { |
| 39 | - $type = _request('type'); |
|
| 40 | - $id = intval(_request('id')); |
|
| 41 | - $page = false; |
|
| 39 | + $type = _request('type'); |
|
| 40 | + $id = intval(_request('id')); |
|
| 41 | + $page = false; |
|
| 42 | 42 | |
| 43 | - // verifier le type ou page transmis |
|
| 44 | - if (!preg_match('/^\w+$/', $type)) { |
|
| 45 | - $page = _request('page'); |
|
| 46 | - if (!preg_match('/^\w+$/', $page)) { |
|
| 47 | - return; |
|
| 48 | - } |
|
| 49 | - } |
|
| 43 | + // verifier le type ou page transmis |
|
| 44 | + if (!preg_match('/^\w+$/', $type)) { |
|
| 45 | + $page = _request('page'); |
|
| 46 | + if (!preg_match('/^\w+$/', $page)) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - if ($var_mode = _request('var_mode')) { |
|
| 52 | - // forcer la mise a jour de l'url de cet objet ! |
|
| 53 | - if (!defined('_VAR_URLS')) { |
|
| 54 | - define('_VAR_URLS', true); |
|
| 55 | - } |
|
| 56 | - } |
|
| 51 | + if ($var_mode = _request('var_mode')) { |
|
| 52 | + // forcer la mise a jour de l'url de cet objet ! |
|
| 53 | + if (!defined('_VAR_URLS')) { |
|
| 54 | + define('_VAR_URLS', true); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - if ($page) { |
|
| 59 | - $url = generer_url_public($page, '', true); |
|
| 60 | - } else { |
|
| 61 | - $url = calculer_url_redirect_entite($type, $id, $var_mode); |
|
| 62 | - } |
|
| 58 | + if ($page) { |
|
| 59 | + $url = generer_url_public($page, '', true); |
|
| 60 | + } else { |
|
| 61 | + $url = calculer_url_redirect_entite($type, $id, $var_mode); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - $status = '302'; |
|
| 65 | - if ($url) { |
|
| 66 | - if ($var_mode) { |
|
| 67 | - $url = parametre_url($url, 'var_mode', $var_mode, '&'); |
|
| 68 | - } |
|
| 64 | + $status = '302'; |
|
| 65 | + if ($url) { |
|
| 66 | + if ($var_mode) { |
|
| 67 | + $url = parametre_url($url, 'var_mode', $var_mode, '&'); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - if ( |
|
| 71 | - $var_mode == 'preview' |
|
| 72 | - and defined('_PREVIEW_TOKEN') |
|
| 73 | - and _PREVIEW_TOKEN |
|
| 74 | - and autoriser('previsualiser') |
|
| 75 | - ) { |
|
| 76 | - include_spip('inc/securiser_action'); |
|
| 77 | - $token = calculer_token_previsu($url); |
|
| 78 | - $url = parametre_url($url, 'var_previewtoken', $token); |
|
| 79 | - } |
|
| 70 | + if ( |
|
| 71 | + $var_mode == 'preview' |
|
| 72 | + and defined('_PREVIEW_TOKEN') |
|
| 73 | + and _PREVIEW_TOKEN |
|
| 74 | + and autoriser('previsualiser') |
|
| 75 | + ) { |
|
| 76 | + include_spip('inc/securiser_action'); |
|
| 77 | + $token = calculer_token_previsu($url); |
|
| 78 | + $url = parametre_url($url, 'var_previewtoken', $token); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - if (_request('status') and _request('status') == '301') { |
|
| 82 | - $status = '301'; |
|
| 83 | - } |
|
| 84 | - } else { |
|
| 85 | - $url = generer_url_public('404', '', true); |
|
| 86 | - } |
|
| 81 | + if (_request('status') and _request('status') == '301') { |
|
| 82 | + $status = '301'; |
|
| 83 | + } |
|
| 84 | + } else { |
|
| 85 | + $url = generer_url_public('404', '', true); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - redirige_par_entete(str_replace('&', '&', $url), '', $status); |
|
| 88 | + redirige_par_entete(str_replace('&', '&', $url), '', $status); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -100,35 +100,35 @@ discard block |
||
| 100 | 100 | * @return string|null |
| 101 | 101 | */ |
| 102 | 102 | function calculer_url_redirect_entite($type, $id, $var_mode) { |
| 103 | - $desc = null; |
|
| 104 | - $publie = null; |
|
| 105 | - $url = null; |
|
| 106 | - // invalider le cache à chaque modif en bdd |
|
| 107 | - $date = 0; |
|
| 108 | - if (isset($GLOBALS['meta']['derniere_modif'])) { |
|
| 109 | - $date = $GLOBALS['meta']['derniere_modif']; |
|
| 110 | - } |
|
| 111 | - $key = "url-$date-$type-$id"; |
|
| 103 | + $desc = null; |
|
| 104 | + $publie = null; |
|
| 105 | + $url = null; |
|
| 106 | + // invalider le cache à chaque modif en bdd |
|
| 107 | + $date = 0; |
|
| 108 | + if (isset($GLOBALS['meta']['derniere_modif'])) { |
|
| 109 | + $date = $GLOBALS['meta']['derniere_modif']; |
|
| 110 | + } |
|
| 111 | + $key = "url-$date-$type-$id"; |
|
| 112 | 112 | |
| 113 | - // Obtenir l’url et si elle est publié du cache memoization |
|
| 114 | - if (function_exists('cache_get') and $desc = cache_get($key)) { |
|
| 115 | - [$url, $publie] = $desc; |
|
| 116 | - } |
|
| 117 | - // Si on ne l’a pas trouvé, ou si var mode, on calcule l’url et son état publie |
|
| 118 | - if (empty($desc) or $var_mode) { |
|
| 119 | - $publie = objet_test_si_publie($type, $id); |
|
| 120 | - $url = generer_objet_url_absolue($id, $type, '', '', true); |
|
| 121 | - if (function_exists('cache_set')) { |
|
| 122 | - cache_set($key, [$url, $publie], 3600); |
|
| 123 | - } |
|
| 124 | - } |
|
| 113 | + // Obtenir l’url et si elle est publié du cache memoization |
|
| 114 | + if (function_exists('cache_get') and $desc = cache_get($key)) { |
|
| 115 | + [$url, $publie] = $desc; |
|
| 116 | + } |
|
| 117 | + // Si on ne l’a pas trouvé, ou si var mode, on calcule l’url et son état publie |
|
| 118 | + if (empty($desc) or $var_mode) { |
|
| 119 | + $publie = objet_test_si_publie($type, $id); |
|
| 120 | + $url = generer_objet_url_absolue($id, $type, '', '', true); |
|
| 121 | + if (function_exists('cache_set')) { |
|
| 122 | + cache_set($key, [$url, $publie], 3600); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - // On valide l’url si elle est publiee ; sinon si preview on teste l’autorisation |
|
| 127 | - if ($publie) { |
|
| 128 | - return $url; |
|
| 129 | - } elseif (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id)) { |
|
| 130 | - return $url; |
|
| 131 | - } |
|
| 126 | + // On valide l’url si elle est publiee ; sinon si preview on teste l’autorisation |
|
| 127 | + if ($publie) { |
|
| 128 | + return $url; |
|
| 129 | + } elseif (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id)) { |
|
| 130 | + return $url; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - return; |
|
| 133 | + return; |
|
| 134 | 134 | } |