@@ -11,109 +11,109 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function inc_log_dist($message, $logname = null, $logdir = null, $logsuf = null) { |
| 18 | - static $test_repertoire = []; |
|
| 19 | - static $compteur = []; |
|
| 20 | - static $debugverb = ''; // pour ne pas le recalculer au reappel |
|
| 21 | - |
|
| 22 | - if (is_null($logname) or !is_string($logname)) { |
|
| 23 | - $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; |
|
| 24 | - } |
|
| 25 | - if (!isset($compteur[$logname])) { |
|
| 26 | - $compteur[$logname] = 0; |
|
| 27 | - } |
|
| 28 | - if ( |
|
| 29 | - $logname != 'maj' |
|
| 30 | - and defined('_MAX_LOG') |
|
| 31 | - and ( |
|
| 32 | - $compteur[$logname]++ > _MAX_LOG |
|
| 33 | - or !$GLOBALS['nombre_de_logs'] |
|
| 34 | - or !$GLOBALS['taille_des_logs'] |
|
| 35 | - ) |
|
| 36 | - ) { |
|
| 37 | - return; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
|
| 41 | - $logfile = |
|
| 42 | - ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 43 | - . $logname |
|
| 44 | - . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
|
| 45 | - |
|
| 46 | - if (!isset($test_repertoire[$d = dirname($logfile)])) { |
|
| 47 | - $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire |
|
| 48 | - $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire( |
|
| 49 | - $d, |
|
| 50 | - '', |
|
| 51 | - false, |
|
| 52 | - true |
|
| 53 | - ) : false)); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Si le repertoire défini n'existe pas, poser dans tmp/ |
|
| 57 | - if (!$test_repertoire[$d]) { |
|
| 58 | - $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $rotate = 0; |
|
| 62 | - $pid = '(pid ' . @getmypid() . ')'; |
|
| 63 | - |
|
| 64 | - // accepter spip_log( Array ) |
|
| 65 | - if (!is_string($message)) { |
|
| 66 | - $message = var_export($message, true); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) { |
|
| 70 | - $debug = debug_backtrace(); |
|
| 71 | - $l = $debug[1]['line']; |
|
| 72 | - $fi = $debug[1]['file']; |
|
| 73 | - if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) { |
|
| 74 | - $fi = substr($fi, strlen(_ROOT_RACINE)); |
|
| 75 | - } |
|
| 76 | - $fu = $debug[2]['function'] ?? ''; |
|
| 77 | - $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 81 | - //distinguer les logs prives et publics dans les grep |
|
| 82 | - . $debugverb |
|
| 83 | - . (test_espace_prive() ? ':Pri:' : ':Pub:') |
|
| 84 | - . preg_replace("/\n*$/", "\n", $message); |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - if ( |
|
| 88 | - @is_readable($logfile) |
|
| 89 | - and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024) |
|
| 90 | - ) { |
|
| 91 | - $rotate = $GLOBALS['nombre_de_logs']; |
|
| 92 | - $m .= "[-- rotate --]\n"; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $f = @fopen($logfile, 'ab'); |
|
| 96 | - if ($f) { |
|
| 97 | - fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '<', $m)); |
|
| 98 | - fclose($f); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if ( |
|
| 102 | - $rotate-- > 0 |
|
| 103 | - and function_exists('spip_unlink') |
|
| 104 | - ) { |
|
| 105 | - spip_unlink($logfile . '.' . $rotate); |
|
| 106 | - while ($rotate--) { |
|
| 107 | - @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Dupliquer les erreurs specifiques dans le log general |
|
| 112 | - if ( |
|
| 113 | - defined('_FILE_LOG') |
|
| 114 | - and ($logname !== _FILE_LOG) |
|
| 115 | - ) { |
|
| 116 | - inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message); |
|
| 117 | - } |
|
| 118 | - $debugverb = ''; |
|
| 18 | + static $test_repertoire = []; |
|
| 19 | + static $compteur = []; |
|
| 20 | + static $debugverb = ''; // pour ne pas le recalculer au reappel |
|
| 21 | + |
|
| 22 | + if (is_null($logname) or !is_string($logname)) { |
|
| 23 | + $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; |
|
| 24 | + } |
|
| 25 | + if (!isset($compteur[$logname])) { |
|
| 26 | + $compteur[$logname] = 0; |
|
| 27 | + } |
|
| 28 | + if ( |
|
| 29 | + $logname != 'maj' |
|
| 30 | + and defined('_MAX_LOG') |
|
| 31 | + and ( |
|
| 32 | + $compteur[$logname]++ > _MAX_LOG |
|
| 33 | + or !$GLOBALS['nombre_de_logs'] |
|
| 34 | + or !$GLOBALS['taille_des_logs'] |
|
| 35 | + ) |
|
| 36 | + ) { |
|
| 37 | + return; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
|
| 41 | + $logfile = |
|
| 42 | + ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 43 | + . $logname |
|
| 44 | + . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
|
| 45 | + |
|
| 46 | + if (!isset($test_repertoire[$d = dirname($logfile)])) { |
|
| 47 | + $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire |
|
| 48 | + $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire( |
|
| 49 | + $d, |
|
| 50 | + '', |
|
| 51 | + false, |
|
| 52 | + true |
|
| 53 | + ) : false)); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Si le repertoire défini n'existe pas, poser dans tmp/ |
|
| 57 | + if (!$test_repertoire[$d]) { |
|
| 58 | + $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $rotate = 0; |
|
| 62 | + $pid = '(pid ' . @getmypid() . ')'; |
|
| 63 | + |
|
| 64 | + // accepter spip_log( Array ) |
|
| 65 | + if (!is_string($message)) { |
|
| 66 | + $message = var_export($message, true); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) { |
|
| 70 | + $debug = debug_backtrace(); |
|
| 71 | + $l = $debug[1]['line']; |
|
| 72 | + $fi = $debug[1]['file']; |
|
| 73 | + if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) { |
|
| 74 | + $fi = substr($fi, strlen(_ROOT_RACINE)); |
|
| 75 | + } |
|
| 76 | + $fu = $debug[2]['function'] ?? ''; |
|
| 77 | + $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 81 | + //distinguer les logs prives et publics dans les grep |
|
| 82 | + . $debugverb |
|
| 83 | + . (test_espace_prive() ? ':Pri:' : ':Pub:') |
|
| 84 | + . preg_replace("/\n*$/", "\n", $message); |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + if ( |
|
| 88 | + @is_readable($logfile) |
|
| 89 | + and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024) |
|
| 90 | + ) { |
|
| 91 | + $rotate = $GLOBALS['nombre_de_logs']; |
|
| 92 | + $m .= "[-- rotate --]\n"; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $f = @fopen($logfile, 'ab'); |
|
| 96 | + if ($f) { |
|
| 97 | + fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '<', $m)); |
|
| 98 | + fclose($f); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if ( |
|
| 102 | + $rotate-- > 0 |
|
| 103 | + and function_exists('spip_unlink') |
|
| 104 | + ) { |
|
| 105 | + spip_unlink($logfile . '.' . $rotate); |
|
| 106 | + while ($rotate--) { |
|
| 107 | + @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // Dupliquer les erreurs specifiques dans le log general |
|
| 112 | + if ( |
|
| 113 | + defined('_FILE_LOG') |
|
| 114 | + and ($logname !== _FILE_LOG) |
|
| 115 | + ) { |
|
| 116 | + inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message); |
|
| 117 | + } |
|
| 118 | + $debugverb = ''; |
|
| 119 | 119 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
| 41 | 41 | $logfile = |
| 42 | - ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 42 | + ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 43 | 43 | . $logname |
| 44 | 44 | . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
| 45 | 45 | |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | // Si le repertoire défini n'existe pas, poser dans tmp/ |
| 57 | 57 | if (!$test_repertoire[$d]) { |
| 58 | - $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 58 | + $logfile = _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES.$logname.'.log'; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $rotate = 0; |
| 62 | - $pid = '(pid ' . @getmypid() . ')'; |
|
| 62 | + $pid = '(pid '.@getmypid().')'; |
|
| 63 | 63 | |
| 64 | 64 | // accepter spip_log( Array ) |
| 65 | 65 | if (!is_string($message)) { |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | $fi = substr($fi, strlen(_ROOT_RACINE)); |
| 75 | 75 | } |
| 76 | 76 | $fu = $debug[2]['function'] ?? ''; |
| 77 | - $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 77 | + $debugverb = "$fi:L$l:$fu".'():'; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 80 | + $m = date('Y-m-d H:i:s').' '.($GLOBALS['ip'] ?? '').' '.$pid.' ' |
|
| 81 | 81 | //distinguer les logs prives et publics dans les grep |
| 82 | 82 | . $debugverb |
| 83 | 83 | . (test_espace_prive() ? ':Pri:' : ':Pub:') |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | $rotate-- > 0 |
| 103 | 103 | and function_exists('spip_unlink') |
| 104 | 104 | ) { |
| 105 | - spip_unlink($logfile . '.' . $rotate); |
|
| 105 | + spip_unlink($logfile.'.'.$rotate); |
|
| 106 | 106 | while ($rotate--) { |
| 107 | - @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 107 | + @rename($logfile.($rotate ? '.'.$rotate : ''), $logfile.'.'.($rotate + 1)); |
|
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
@@ -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 | include_spip('inc/headers'); |
@@ -19,199 +19,199 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | function install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db) { |
| 21 | 21 | |
| 22 | - // Prefix des tables : |
|
| 23 | - // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 24 | - // a partir de ce qui est envoye a l'installation |
|
| 25 | - if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 26 | - $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 27 | - ? $GLOBALS['table_prefix'] |
|
| 28 | - : preparer_prefixe_tables(_request('tprefix')); |
|
| 29 | - // S'il est vide on remet spip |
|
| 30 | - if (!$table_prefix) { |
|
| 31 | - $table_prefix = 'spip'; |
|
| 32 | - } |
|
| 33 | - } else { |
|
| 34 | - $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 38 | - [, $adresse_db, $port] = $r; |
|
| 39 | - } else { |
|
| 40 | - $port = ''; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - $GLOBALS['connexions'][$server_db] |
|
| 44 | - = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
|
| 45 | - |
|
| 46 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 47 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 48 | - |
|
| 49 | - $fquery = sql_serveur('query', $server_db); |
|
| 50 | - if ($choix_db == 'new_spip') { |
|
| 51 | - $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 52 | - if (preg_match($re, $sel_db)) { |
|
| 53 | - $ok = sql_create_base($sel_db, $server_db); |
|
| 54 | - if (!$ok) { |
|
| 55 | - $re = "Impossible de creer la base $re"; |
|
| 56 | - spip_log($re); |
|
| 57 | - return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 58 | - } |
|
| 59 | - } else { |
|
| 60 | - $re = "Le nom de la base doit correspondre a $re"; |
|
| 61 | - spip_log($re); |
|
| 62 | - |
|
| 63 | - return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 68 | - // un sql_mode |
|
| 69 | - install_mode_appel($server_db, false); |
|
| 70 | - $GLOBALS['connexions'][$server_db] |
|
| 71 | - = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
|
| 72 | - |
|
| 73 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 74 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 75 | - |
|
| 76 | - // Completer le tableau decrivant la connexion |
|
| 77 | - |
|
| 78 | - $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 79 | - $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 80 | - |
|
| 81 | - $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 82 | - if ($old) { |
|
| 83 | - $old = sql_fetch($old, $server_db); |
|
| 84 | - } |
|
| 85 | - if (!$old) { |
|
| 86 | - // Si possible, demander au serveur d'envoyer les textes |
|
| 87 | - // dans le codage std de SPIP, |
|
| 88 | - $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 89 | - |
|
| 90 | - if ($charset) { |
|
| 91 | - sql_set_charset($charset['charset'], $server_db); |
|
| 92 | - $GLOBALS['meta']['charset_sql_base'] = |
|
| 93 | - $charset['charset']; |
|
| 94 | - $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 95 | - $charset['collation']; |
|
| 96 | - $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 97 | - $charset['charset']; |
|
| 98 | - $charsetbase = $charset['charset']; |
|
| 99 | - } else { |
|
| 100 | - spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 101 | - $charsetbase = 'standard'; |
|
| 102 | - } |
|
| 103 | - spip_log("Creation des tables. Codage $charsetbase"); |
|
| 104 | - creer_base($server_db); // AT LAST |
|
| 105 | - // memoriser avec quel charset on l'a creee |
|
| 106 | - |
|
| 107 | - if ($charset) { |
|
| 108 | - $t = [ |
|
| 109 | - 'nom' => 'charset_sql_base', |
|
| 110 | - 'valeur' => $charset['charset'], |
|
| 111 | - 'impt' => 'non' |
|
| 112 | - ]; |
|
| 113 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 114 | - $t['nom'] = 'charset_collation_sql_base'; |
|
| 115 | - $t['valeur'] = $charset['collation']; |
|
| 116 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 117 | - $t['nom'] = 'charset_sql_connexion'; |
|
| 118 | - $t['valeur'] = $charset['charset']; |
|
| 119 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 120 | - } |
|
| 121 | - $t = [ |
|
| 122 | - 'nom' => 'version_installee', |
|
| 123 | - 'valeur' => $GLOBALS['spip_version_base'], |
|
| 124 | - 'impt' => 'non' |
|
| 125 | - ]; |
|
| 126 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 127 | - $t['nom'] = 'nouvelle_install'; |
|
| 128 | - $t['valeur'] = 1; |
|
| 129 | - @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 130 | - // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 131 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 132 | - @sql_insertq( |
|
| 133 | - 'spip_meta', |
|
| 134 | - ['nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']], |
|
| 135 | - [], |
|
| 136 | - $server_db |
|
| 137 | - ); |
|
| 138 | - } |
|
| 139 | - } else { |
|
| 140 | - // pour recreer les tables disparues au besoin |
|
| 141 | - spip_log('Table des Meta deja la. Verification des autres.'); |
|
| 142 | - creer_base($server_db); |
|
| 143 | - $fupdateq = sql_serveur('updateq', $server_db); |
|
| 144 | - |
|
| 145 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 146 | - |
|
| 147 | - if ($r) { |
|
| 148 | - $r = sql_fetch($r, $server_db); |
|
| 149 | - } |
|
| 150 | - $version_installee = !$r ? 0 : (double)$r['valeur']; |
|
| 151 | - if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 152 | - $fupdateq( |
|
| 153 | - 'spip_meta', |
|
| 154 | - ['valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'], |
|
| 155 | - "nom='version_installee'", |
|
| 156 | - '', |
|
| 157 | - $server_db |
|
| 158 | - ); |
|
| 159 | - spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 160 | - } |
|
| 161 | - // eliminer la derniere operation d'admin mal terminee |
|
| 162 | - // notamment la mise a jour |
|
| 163 | - @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // recuperer le charset de la connexion dans les meta |
|
| 167 | - $charset = ''; |
|
| 168 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
|
| 169 | - if ($r) { |
|
| 170 | - $r = sql_fetch($r, $server_db); |
|
| 171 | - } |
|
| 172 | - if ($r) { |
|
| 173 | - $charset = $r['valeur']; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $ligne_rappel = install_mode_appel($server_db); |
|
| 177 | - |
|
| 178 | - $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db); |
|
| 179 | - if (!$result_ok) { |
|
| 180 | - return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - if ($chmod_db) { |
|
| 184 | - install_fichier_connexion( |
|
| 185 | - _FILE_CHMOD_TMP, |
|
| 186 | - "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 187 | - ); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // si ce fichier existe a cette etape c'est qu'il provient |
|
| 191 | - // d'une installation qui ne l'a pas cree correctement. |
|
| 192 | - // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 193 | - |
|
| 194 | - if (_FILE_CONNECT and file_exists(_FILE_CONNECT)) { |
|
| 195 | - spip_unlink(_FILE_CONNECT); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - install_fichier_connexion( |
|
| 199 | - _FILE_CONNECT_TMP, |
|
| 200 | - $ligne_rappel |
|
| 201 | - . install_connexion( |
|
| 202 | - $adresse_db, |
|
| 203 | - $port, |
|
| 204 | - $login_db, |
|
| 205 | - $pass_db, |
|
| 206 | - $sel_db, |
|
| 207 | - $server_db, |
|
| 208 | - $table_prefix, |
|
| 209 | - '', |
|
| 210 | - $charset |
|
| 211 | - ) |
|
| 212 | - ); |
|
| 213 | - |
|
| 214 | - return ''; |
|
| 22 | + // Prefix des tables : |
|
| 23 | + // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 24 | + // a partir de ce qui est envoye a l'installation |
|
| 25 | + if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 26 | + $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 27 | + ? $GLOBALS['table_prefix'] |
|
| 28 | + : preparer_prefixe_tables(_request('tprefix')); |
|
| 29 | + // S'il est vide on remet spip |
|
| 30 | + if (!$table_prefix) { |
|
| 31 | + $table_prefix = 'spip'; |
|
| 32 | + } |
|
| 33 | + } else { |
|
| 34 | + $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 38 | + [, $adresse_db, $port] = $r; |
|
| 39 | + } else { |
|
| 40 | + $port = ''; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + $GLOBALS['connexions'][$server_db] |
|
| 44 | + = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
|
| 45 | + |
|
| 46 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 47 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 48 | + |
|
| 49 | + $fquery = sql_serveur('query', $server_db); |
|
| 50 | + if ($choix_db == 'new_spip') { |
|
| 51 | + $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 52 | + if (preg_match($re, $sel_db)) { |
|
| 53 | + $ok = sql_create_base($sel_db, $server_db); |
|
| 54 | + if (!$ok) { |
|
| 55 | + $re = "Impossible de creer la base $re"; |
|
| 56 | + spip_log($re); |
|
| 57 | + return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 58 | + } |
|
| 59 | + } else { |
|
| 60 | + $re = "Le nom de la base doit correspondre a $re"; |
|
| 61 | + spip_log($re); |
|
| 62 | + |
|
| 63 | + return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 68 | + // un sql_mode |
|
| 69 | + install_mode_appel($server_db, false); |
|
| 70 | + $GLOBALS['connexions'][$server_db] |
|
| 71 | + = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
|
| 72 | + |
|
| 73 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 74 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 75 | + |
|
| 76 | + // Completer le tableau decrivant la connexion |
|
| 77 | + |
|
| 78 | + $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 79 | + $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 80 | + |
|
| 81 | + $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 82 | + if ($old) { |
|
| 83 | + $old = sql_fetch($old, $server_db); |
|
| 84 | + } |
|
| 85 | + if (!$old) { |
|
| 86 | + // Si possible, demander au serveur d'envoyer les textes |
|
| 87 | + // dans le codage std de SPIP, |
|
| 88 | + $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 89 | + |
|
| 90 | + if ($charset) { |
|
| 91 | + sql_set_charset($charset['charset'], $server_db); |
|
| 92 | + $GLOBALS['meta']['charset_sql_base'] = |
|
| 93 | + $charset['charset']; |
|
| 94 | + $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 95 | + $charset['collation']; |
|
| 96 | + $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 97 | + $charset['charset']; |
|
| 98 | + $charsetbase = $charset['charset']; |
|
| 99 | + } else { |
|
| 100 | + spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 101 | + $charsetbase = 'standard'; |
|
| 102 | + } |
|
| 103 | + spip_log("Creation des tables. Codage $charsetbase"); |
|
| 104 | + creer_base($server_db); // AT LAST |
|
| 105 | + // memoriser avec quel charset on l'a creee |
|
| 106 | + |
|
| 107 | + if ($charset) { |
|
| 108 | + $t = [ |
|
| 109 | + 'nom' => 'charset_sql_base', |
|
| 110 | + 'valeur' => $charset['charset'], |
|
| 111 | + 'impt' => 'non' |
|
| 112 | + ]; |
|
| 113 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 114 | + $t['nom'] = 'charset_collation_sql_base'; |
|
| 115 | + $t['valeur'] = $charset['collation']; |
|
| 116 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 117 | + $t['nom'] = 'charset_sql_connexion'; |
|
| 118 | + $t['valeur'] = $charset['charset']; |
|
| 119 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 120 | + } |
|
| 121 | + $t = [ |
|
| 122 | + 'nom' => 'version_installee', |
|
| 123 | + 'valeur' => $GLOBALS['spip_version_base'], |
|
| 124 | + 'impt' => 'non' |
|
| 125 | + ]; |
|
| 126 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 127 | + $t['nom'] = 'nouvelle_install'; |
|
| 128 | + $t['valeur'] = 1; |
|
| 129 | + @sql_insertq('spip_meta', $t, [], $server_db); |
|
| 130 | + // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 131 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 132 | + @sql_insertq( |
|
| 133 | + 'spip_meta', |
|
| 134 | + ['nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']], |
|
| 135 | + [], |
|
| 136 | + $server_db |
|
| 137 | + ); |
|
| 138 | + } |
|
| 139 | + } else { |
|
| 140 | + // pour recreer les tables disparues au besoin |
|
| 141 | + spip_log('Table des Meta deja la. Verification des autres.'); |
|
| 142 | + creer_base($server_db); |
|
| 143 | + $fupdateq = sql_serveur('updateq', $server_db); |
|
| 144 | + |
|
| 145 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 146 | + |
|
| 147 | + if ($r) { |
|
| 148 | + $r = sql_fetch($r, $server_db); |
|
| 149 | + } |
|
| 150 | + $version_installee = !$r ? 0 : (double)$r['valeur']; |
|
| 151 | + if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 152 | + $fupdateq( |
|
| 153 | + 'spip_meta', |
|
| 154 | + ['valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'], |
|
| 155 | + "nom='version_installee'", |
|
| 156 | + '', |
|
| 157 | + $server_db |
|
| 158 | + ); |
|
| 159 | + spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 160 | + } |
|
| 161 | + // eliminer la derniere operation d'admin mal terminee |
|
| 162 | + // notamment la mise a jour |
|
| 163 | + @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // recuperer le charset de la connexion dans les meta |
|
| 167 | + $charset = ''; |
|
| 168 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
|
| 169 | + if ($r) { |
|
| 170 | + $r = sql_fetch($r, $server_db); |
|
| 171 | + } |
|
| 172 | + if ($r) { |
|
| 173 | + $charset = $r['valeur']; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $ligne_rappel = install_mode_appel($server_db); |
|
| 177 | + |
|
| 178 | + $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db); |
|
| 179 | + if (!$result_ok) { |
|
| 180 | + return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + if ($chmod_db) { |
|
| 184 | + install_fichier_connexion( |
|
| 185 | + _FILE_CHMOD_TMP, |
|
| 186 | + "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 187 | + ); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // si ce fichier existe a cette etape c'est qu'il provient |
|
| 191 | + // d'une installation qui ne l'a pas cree correctement. |
|
| 192 | + // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 193 | + |
|
| 194 | + if (_FILE_CONNECT and file_exists(_FILE_CONNECT)) { |
|
| 195 | + spip_unlink(_FILE_CONNECT); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + install_fichier_connexion( |
|
| 199 | + _FILE_CONNECT_TMP, |
|
| 200 | + $ligne_rappel |
|
| 201 | + . install_connexion( |
|
| 202 | + $adresse_db, |
|
| 203 | + $port, |
|
| 204 | + $login_db, |
|
| 205 | + $pass_db, |
|
| 206 | + $sel_db, |
|
| 207 | + $server_db, |
|
| 208 | + $table_prefix, |
|
| 209 | + '', |
|
| 210 | + $charset |
|
| 211 | + ) |
|
| 212 | + ); |
|
| 213 | + |
|
| 214 | + return ''; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -226,166 +226,166 @@ discard block |
||
| 226 | 226 | * @return string Le préfixe corrigé |
| 227 | 227 | */ |
| 228 | 228 | function preparer_prefixe_tables($prefixe) { |
| 229 | - return trim(preg_replace(',^[0-9]+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe)))); |
|
| 229 | + return trim(preg_replace(',^[0-9]+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe)))); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | function install_propose_ldap() { |
| 233 | - return generer_form_ecrire('install', ( |
|
| 234 | - fieldset( |
|
| 235 | - _T('info_authentification_externe'), |
|
| 236 | - [ |
|
| 237 | - 'etape' => [ |
|
| 238 | - 'label' => _T('texte_annuaire_ldap_1'), |
|
| 239 | - 'valeur' => 'ldap1', |
|
| 240 | - 'hidden' => true |
|
| 241 | - ] |
|
| 242 | - ], |
|
| 243 | - bouton_suivant(_T('bouton_acces_ldap')) |
|
| 244 | - ))); |
|
| 233 | + return generer_form_ecrire('install', ( |
|
| 234 | + fieldset( |
|
| 235 | + _T('info_authentification_externe'), |
|
| 236 | + [ |
|
| 237 | + 'etape' => [ |
|
| 238 | + 'label' => _T('texte_annuaire_ldap_1'), |
|
| 239 | + 'valeur' => 'ldap1', |
|
| 240 | + 'hidden' => true |
|
| 241 | + ] |
|
| 242 | + ], |
|
| 243 | + bouton_suivant(_T('bouton_acces_ldap')) |
|
| 244 | + ))); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
| 248 | 248 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) { |
| 249 | - return info_progression_etape(3, 'etape_', 'install/') . |
|
| 250 | - info_etape( |
|
| 251 | - _T('info_informations_personnelles'), |
|
| 252 | - '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 253 | - aider('install5', true) . |
|
| 254 | - '<p>' . |
|
| 255 | - ($auteur_obligatoire ? |
|
| 256 | - '' |
|
| 257 | - : |
|
| 258 | - _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 259 | - ) |
|
| 260 | - ) |
|
| 261 | - . generer_form_ecrire('install', ( |
|
| 262 | - "\n<input type='hidden' name='etape' value='3b' />" |
|
| 263 | - . $hidden |
|
| 264 | - . fieldset( |
|
| 265 | - _T('info_identification_publique'), |
|
| 266 | - [ |
|
| 267 | - 'nom' => [ |
|
| 268 | - 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 269 | - 'valeur' => $nom, |
|
| 270 | - 'required' => $auteur_obligatoire, |
|
| 271 | - ], |
|
| 272 | - 'email' => [ |
|
| 273 | - 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 274 | - 'valeur' => $email, |
|
| 275 | - ] |
|
| 276 | - ] |
|
| 277 | - ) |
|
| 278 | - |
|
| 279 | - . fieldset( |
|
| 280 | - _T('entree_identifiants_connexion'), |
|
| 281 | - [ |
|
| 282 | - 'login' => [ |
|
| 283 | - 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 284 | - 'info_login_trop_court_car_pluriel', |
|
| 285 | - ['nb' => _LOGIN_TROP_COURT] |
|
| 286 | - ) . "\n", |
|
| 287 | - 'valeur' => $login, |
|
| 288 | - 'required' => $auteur_obligatoire, |
|
| 289 | - ], |
|
| 290 | - 'pass' => [ |
|
| 291 | - 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 292 | - 'info_passe_trop_court_car_pluriel', |
|
| 293 | - ['nb' => _PASS_LONGUEUR_MINI] |
|
| 294 | - ) . "\n", |
|
| 295 | - 'valeur' => $pass, |
|
| 296 | - 'required' => $auteur_obligatoire, |
|
| 297 | - ], |
|
| 298 | - 'pass_verif' => [ |
|
| 299 | - 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 300 | - 'valeur' => $pass, |
|
| 301 | - 'required' => $auteur_obligatoire, |
|
| 302 | - ] |
|
| 303 | - ] |
|
| 304 | - ) |
|
| 305 | - . bouton_suivant())); |
|
| 249 | + return info_progression_etape(3, 'etape_', 'install/') . |
|
| 250 | + info_etape( |
|
| 251 | + _T('info_informations_personnelles'), |
|
| 252 | + '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 253 | + aider('install5', true) . |
|
| 254 | + '<p>' . |
|
| 255 | + ($auteur_obligatoire ? |
|
| 256 | + '' |
|
| 257 | + : |
|
| 258 | + _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 259 | + ) |
|
| 260 | + ) |
|
| 261 | + . generer_form_ecrire('install', ( |
|
| 262 | + "\n<input type='hidden' name='etape' value='3b' />" |
|
| 263 | + . $hidden |
|
| 264 | + . fieldset( |
|
| 265 | + _T('info_identification_publique'), |
|
| 266 | + [ |
|
| 267 | + 'nom' => [ |
|
| 268 | + 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 269 | + 'valeur' => $nom, |
|
| 270 | + 'required' => $auteur_obligatoire, |
|
| 271 | + ], |
|
| 272 | + 'email' => [ |
|
| 273 | + 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 274 | + 'valeur' => $email, |
|
| 275 | + ] |
|
| 276 | + ] |
|
| 277 | + ) |
|
| 278 | + |
|
| 279 | + . fieldset( |
|
| 280 | + _T('entree_identifiants_connexion'), |
|
| 281 | + [ |
|
| 282 | + 'login' => [ |
|
| 283 | + 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 284 | + 'info_login_trop_court_car_pluriel', |
|
| 285 | + ['nb' => _LOGIN_TROP_COURT] |
|
| 286 | + ) . "\n", |
|
| 287 | + 'valeur' => $login, |
|
| 288 | + 'required' => $auteur_obligatoire, |
|
| 289 | + ], |
|
| 290 | + 'pass' => [ |
|
| 291 | + 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 292 | + 'info_passe_trop_court_car_pluriel', |
|
| 293 | + ['nb' => _PASS_LONGUEUR_MINI] |
|
| 294 | + ) . "\n", |
|
| 295 | + 'valeur' => $pass, |
|
| 296 | + 'required' => $auteur_obligatoire, |
|
| 297 | + ], |
|
| 298 | + 'pass_verif' => [ |
|
| 299 | + 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 300 | + 'valeur' => $pass, |
|
| 301 | + 'required' => $auteur_obligatoire, |
|
| 302 | + ] |
|
| 303 | + ] |
|
| 304 | + ) |
|
| 305 | + . bouton_suivant())); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | function install_etape_3_dist() { |
| 309 | - $ldap_present = _request('ldap_present'); |
|
| 310 | - |
|
| 311 | - if (!$ldap_present) { |
|
| 312 | - $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 313 | - ? _INSTALL_HOST_DB |
|
| 314 | - : _request('adresse_db'); |
|
| 315 | - |
|
| 316 | - $login_db = defined('_INSTALL_USER_DB') |
|
| 317 | - ? _INSTALL_USER_DB |
|
| 318 | - : _request('login_db'); |
|
| 319 | - |
|
| 320 | - $pass_db = defined('_INSTALL_PASS_DB') |
|
| 321 | - ? _INSTALL_PASS_DB |
|
| 322 | - : _request('pass_db'); |
|
| 323 | - |
|
| 324 | - $server_db = defined('_INSTALL_SERVER_DB') |
|
| 325 | - ? _INSTALL_SERVER_DB |
|
| 326 | - : _request('server_db'); |
|
| 327 | - |
|
| 328 | - $chmod_db = defined('_SPIP_CHMOD') |
|
| 329 | - ? _SPIP_CHMOD |
|
| 330 | - : _request('chmod'); |
|
| 331 | - |
|
| 332 | - $choix_db = defined('_INSTALL_NAME_DB') |
|
| 333 | - ? _INSTALL_NAME_DB |
|
| 334 | - : _request('choix_db'); |
|
| 335 | - |
|
| 336 | - $sel_db = ($choix_db == 'new_spip') |
|
| 337 | - ? _request('table_new') : $choix_db; |
|
| 338 | - |
|
| 339 | - $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 340 | - |
|
| 341 | - if ($res) { |
|
| 342 | - $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 343 | - . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 344 | - . $res |
|
| 345 | - . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 346 | - . '</div>'; |
|
| 347 | - } |
|
| 348 | - } else { |
|
| 349 | - $res = ''; |
|
| 350 | - [$adresse_db, $login_db, $pass_db, $sel_db, $server_db] = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 351 | - $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - if (!$res) { |
|
| 355 | - if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 356 | - include(_FILE_CONNECT_TMP); |
|
| 357 | - } else { |
|
| 358 | - redirige_url_ecrire('install'); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 362 | - include(_FILE_CHMOD_TMP); |
|
| 363 | - } else { |
|
| 364 | - redirige_url_ecrire('install'); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 368 | - . (defined('_INSTALL_NAME_DB') ? '' |
|
| 369 | - : "\n<input type='hidden' name='sel_db' value=\"" . spip_htmlspecialchars($sel_db) . '" />'); |
|
| 370 | - |
|
| 371 | - $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 372 | - |
|
| 373 | - $res = "<div class='success'><b>" |
|
| 374 | - . _T('info_base_installee') |
|
| 375 | - . '</b></div>' |
|
| 376 | - . install_premier_auteur( |
|
| 377 | - _request('email'), |
|
| 378 | - _request('login'), |
|
| 379 | - _request('nom'), |
|
| 380 | - _request('pass'), |
|
| 381 | - $hidden, |
|
| 382 | - $auteur_obligatoire |
|
| 383 | - ) |
|
| 384 | - . (($ldap_present or !function_exists('ldap_connect')) |
|
| 385 | - ? '' : install_propose_ldap()); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - echo install_debut_html(); |
|
| 389 | - echo $res; |
|
| 390 | - echo install_fin_html(); |
|
| 309 | + $ldap_present = _request('ldap_present'); |
|
| 310 | + |
|
| 311 | + if (!$ldap_present) { |
|
| 312 | + $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 313 | + ? _INSTALL_HOST_DB |
|
| 314 | + : _request('adresse_db'); |
|
| 315 | + |
|
| 316 | + $login_db = defined('_INSTALL_USER_DB') |
|
| 317 | + ? _INSTALL_USER_DB |
|
| 318 | + : _request('login_db'); |
|
| 319 | + |
|
| 320 | + $pass_db = defined('_INSTALL_PASS_DB') |
|
| 321 | + ? _INSTALL_PASS_DB |
|
| 322 | + : _request('pass_db'); |
|
| 323 | + |
|
| 324 | + $server_db = defined('_INSTALL_SERVER_DB') |
|
| 325 | + ? _INSTALL_SERVER_DB |
|
| 326 | + : _request('server_db'); |
|
| 327 | + |
|
| 328 | + $chmod_db = defined('_SPIP_CHMOD') |
|
| 329 | + ? _SPIP_CHMOD |
|
| 330 | + : _request('chmod'); |
|
| 331 | + |
|
| 332 | + $choix_db = defined('_INSTALL_NAME_DB') |
|
| 333 | + ? _INSTALL_NAME_DB |
|
| 334 | + : _request('choix_db'); |
|
| 335 | + |
|
| 336 | + $sel_db = ($choix_db == 'new_spip') |
|
| 337 | + ? _request('table_new') : $choix_db; |
|
| 338 | + |
|
| 339 | + $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 340 | + |
|
| 341 | + if ($res) { |
|
| 342 | + $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 343 | + . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 344 | + . $res |
|
| 345 | + . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 346 | + . '</div>'; |
|
| 347 | + } |
|
| 348 | + } else { |
|
| 349 | + $res = ''; |
|
| 350 | + [$adresse_db, $login_db, $pass_db, $sel_db, $server_db] = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 351 | + $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + if (!$res) { |
|
| 355 | + if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 356 | + include(_FILE_CONNECT_TMP); |
|
| 357 | + } else { |
|
| 358 | + redirige_url_ecrire('install'); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 362 | + include(_FILE_CHMOD_TMP); |
|
| 363 | + } else { |
|
| 364 | + redirige_url_ecrire('install'); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 368 | + . (defined('_INSTALL_NAME_DB') ? '' |
|
| 369 | + : "\n<input type='hidden' name='sel_db' value=\"" . spip_htmlspecialchars($sel_db) . '" />'); |
|
| 370 | + |
|
| 371 | + $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 372 | + |
|
| 373 | + $res = "<div class='success'><b>" |
|
| 374 | + . _T('info_base_installee') |
|
| 375 | + . '</b></div>' |
|
| 376 | + . install_premier_auteur( |
|
| 377 | + _request('email'), |
|
| 378 | + _request('login'), |
|
| 379 | + _request('nom'), |
|
| 380 | + _request('pass'), |
|
| 381 | + $hidden, |
|
| 382 | + $auteur_obligatoire |
|
| 383 | + ) |
|
| 384 | + . (($ldap_present or !function_exists('ldap_connect')) |
|
| 385 | + ? '' : install_propose_ldap()); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + echo install_debut_html(); |
|
| 389 | + echo $res; |
|
| 390 | + echo install_fin_html(); |
|
| 391 | 391 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
| 45 | 45 | |
| 46 | 46 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 47 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 47 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 48 | 48 | |
| 49 | 49 | $fquery = sql_serveur('query', $server_db); |
| 50 | 50 | if ($choix_db == 'new_spip') { |
@@ -54,13 +54,13 @@ discard block |
||
| 54 | 54 | if (!$ok) { |
| 55 | 55 | $re = "Impossible de creer la base $re"; |
| 56 | 56 | spip_log($re); |
| 57 | - return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 57 | + return '<p>'._T('avis_connexion_erreur_creer_base')."</p><!--\n$re\n-->"; |
|
| 58 | 58 | } |
| 59 | 59 | } else { |
| 60 | 60 | $re = "Le nom de la base doit correspondre a $re"; |
| 61 | 61 | spip_log($re); |
| 62 | 62 | |
| 63 | - return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 63 | + return '<p>'._T('avis_connexion_erreur_nom_base')."</p><!--\n$re\n-->"; |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
@@ -71,14 +71,14 @@ discard block |
||
| 71 | 71 | = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
| 72 | 72 | |
| 73 | 73 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 74 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 74 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 75 | 75 | |
| 76 | 76 | // Completer le tableau decrivant la connexion |
| 77 | 77 | |
| 78 | 78 | $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
| 79 | 79 | $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
| 80 | 80 | |
| 81 | - $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 81 | + $old = sql_showbase($table_prefix.'_meta', $server_db); |
|
| 82 | 82 | if ($old) { |
| 83 | 83 | $old = sql_fetch($old, $server_db); |
| 84 | 84 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $charset['charset']; |
| 98 | 98 | $charsetbase = $charset['charset']; |
| 99 | 99 | } else { |
| 100 | - spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 100 | + spip_log(_DEFAULT_CHARSET.' inconnu du serveur SQL'); |
|
| 101 | 101 | $charsetbase = 'standard'; |
| 102 | 102 | } |
| 103 | 103 | spip_log("Creation des tables. Codage $charsetbase"); |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | if ($r) { |
| 148 | 148 | $r = sql_fetch($r, $server_db); |
| 149 | 149 | } |
| 150 | - $version_installee = !$r ? 0 : (double)$r['valeur']; |
|
| 150 | + $version_installee = !$r ? 0 : (double) $r['valeur']; |
|
| 151 | 151 | if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
| 152 | 152 | $fupdateq( |
| 153 | 153 | 'spip_meta', |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | '', |
| 157 | 157 | $server_db |
| 158 | 158 | ); |
| 159 | - spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 159 | + spip_log('nouvelle version installee: '.$GLOBALS['spip_version_base']); |
|
| 160 | 160 | } |
| 161 | 161 | // eliminer la derniere operation d'admin mal terminee |
| 162 | 162 | // notamment la mise a jour |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | if ($chmod_db) { |
| 184 | 184 | install_fichier_connexion( |
| 185 | 185 | _FILE_CHMOD_TMP, |
| 186 | - "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 186 | + "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', ".sprintf('0%3o', $chmod_db).");\n" |
|
| 187 | 187 | ); |
| 188 | 188 | } |
| 189 | 189 | |
@@ -246,16 +246,16 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | |
| 248 | 248 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) { |
| 249 | - return info_progression_etape(3, 'etape_', 'install/') . |
|
| 249 | + return info_progression_etape(3, 'etape_', 'install/'). |
|
| 250 | 250 | info_etape( |
| 251 | 251 | _T('info_informations_personnelles'), |
| 252 | - '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 253 | - aider('install5', true) . |
|
| 254 | - '<p>' . |
|
| 252 | + '<b>'._T('texte_informations_personnelles_1').'</b>'. |
|
| 253 | + aider('install5', true). |
|
| 254 | + '<p>'. |
|
| 255 | 255 | ($auteur_obligatoire ? |
| 256 | 256 | '' |
| 257 | 257 | : |
| 258 | - _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 258 | + _T('texte_informations_personnelles_2').' '._T('info_laisser_champs_vides') |
|
| 259 | 259 | ) |
| 260 | 260 | ) |
| 261 | 261 | . generer_form_ecrire('install', ( |
@@ -265,12 +265,12 @@ discard block |
||
| 265 | 265 | _T('info_identification_publique'), |
| 266 | 266 | [ |
| 267 | 267 | 'nom' => [ |
| 268 | - 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 268 | + 'label' => '<b>'._T('entree_signature')."</b><br />\n"._T('entree_nom_pseudo_1')."\n", |
|
| 269 | 269 | 'valeur' => $nom, |
| 270 | 270 | 'required' => $auteur_obligatoire, |
| 271 | 271 | ], |
| 272 | 272 | 'email' => [ |
| 273 | - 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 273 | + 'label' => '<b>'._T('entree_adresse_email')."</b>\n", |
|
| 274 | 274 | 'valeur' => $email, |
| 275 | 275 | ] |
| 276 | 276 | ] |
@@ -280,23 +280,23 @@ discard block |
||
| 280 | 280 | _T('entree_identifiants_connexion'), |
| 281 | 281 | [ |
| 282 | 282 | 'login' => [ |
| 283 | - 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 283 | + 'label' => '<b>'._T('entree_login')."</b><br />\n"._T( |
|
| 284 | 284 | 'info_login_trop_court_car_pluriel', |
| 285 | 285 | ['nb' => _LOGIN_TROP_COURT] |
| 286 | - ) . "\n", |
|
| 286 | + )."\n", |
|
| 287 | 287 | 'valeur' => $login, |
| 288 | 288 | 'required' => $auteur_obligatoire, |
| 289 | 289 | ], |
| 290 | 290 | 'pass' => [ |
| 291 | - 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 291 | + 'label' => '<b>'._T('entree_mot_passe')."</b><br />\n"._T( |
|
| 292 | 292 | 'info_passe_trop_court_car_pluriel', |
| 293 | 293 | ['nb' => _PASS_LONGUEUR_MINI] |
| 294 | - ) . "\n", |
|
| 294 | + )."\n", |
|
| 295 | 295 | 'valeur' => $pass, |
| 296 | 296 | 'required' => $auteur_obligatoire, |
| 297 | 297 | ], |
| 298 | 298 | 'pass_verif' => [ |
| 299 | - 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 299 | + 'label' => '<b>'._T('info_confirmer_passe')."</b><br />\n", |
|
| 300 | 300 | 'valeur' => $pass, |
| 301 | 301 | 'required' => $auteur_obligatoire, |
| 302 | 302 | ] |
@@ -340,9 +340,9 @@ discard block |
||
| 340 | 340 | |
| 341 | 341 | if ($res) { |
| 342 | 342 | $res = info_progression_etape(2, 'etape_', 'install/', true) |
| 343 | - . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 343 | + . "<div class='error'><h3>"._T('avis_operation_echec').'</h3>' |
|
| 344 | 344 | . $res |
| 345 | - . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 345 | + . '<p>'._T('texte_operation_echec').'</p>' |
|
| 346 | 346 | . '</div>'; |
| 347 | 347 | } |
| 348 | 348 | } else { |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
| 368 | 368 | . (defined('_INSTALL_NAME_DB') ? '' |
| 369 | - : "\n<input type='hidden' name='sel_db' value=\"" . spip_htmlspecialchars($sel_db) . '" />'); |
|
| 369 | + : "\n<input type='hidden' name='sel_db' value=\"".spip_htmlspecialchars($sel_db).'" />'); |
|
| 370 | 370 | |
| 371 | 371 | $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
| 372 | 372 | |
@@ -45,10 +45,10 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | if ($query) { |
| 48 | - $url .= '?' . $query; |
|
| 48 | + $url .= '?'.$query; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - return '/' . preg_replace(',^/,S', '', $url); |
|
| 51 | + return '/'.preg_replace(',^/,S', '', $url); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
| 79 | 79 | $r = array_pad($r, 3, ''); |
| 80 | 80 | |
| 81 | - return $r[1] . resolve_path($r[2]); |
|
| 81 | + return $r[1].resolve_path($r[2]); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | # L'url site spip est un lien absolu aussi |
@@ -99,13 +99,13 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | switch (substr($lien, 0, 1)) { |
| 101 | 101 | case '/': |
| 102 | - return $debut . resolve_path($lien); |
|
| 102 | + return $debut.resolve_path($lien); |
|
| 103 | 103 | case '#': |
| 104 | - return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 104 | + return $debut.resolve_path($dir.$mot.$get.$lien); |
|
| 105 | 105 | case '': |
| 106 | - return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 106 | + return $debut.resolve_path($dir.$mot.$get.$hash); |
|
| 107 | 107 | default: |
| 108 | - return $debut . resolve_path($dir . $lien); |
|
| 108 | + return $debut.resolve_path($dir.$lien); |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | return ''; |
| 134 | 134 | } |
| 135 | 135 | if (!$base) { |
| 136 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 136 | + $base = url_de_base().(_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | return suivre_lien($base, $url); |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * @param array $protocoles_autorises |
| 157 | 157 | * @return bool |
| 158 | 158 | */ |
| 159 | -function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
|
| 159 | +function protocole_verifier($url_absolue, $protocoles_autorises = ['http', 'https']) { |
|
| 160 | 160 | |
| 161 | 161 | if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
| 162 | 162 | $protocole = $m[1]; |
@@ -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 | |
@@ -35,20 +35,20 @@ discard block |
||
| 35 | 35 | * @return string URL nettoyée |
| 36 | 36 | **/ |
| 37 | 37 | function resolve_path($url) { |
| 38 | - [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | - while ( |
|
| 40 | - preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | - or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | - or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | - ) { |
|
| 44 | - $url = str_replace($regs[0], '/', $url); |
|
| 45 | - } |
|
| 38 | + [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | + while ( |
|
| 40 | + preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | + or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | + or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | + ) { |
|
| 44 | + $url = str_replace($regs[0], '/', $url); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - if ($query) { |
|
| 48 | - $url .= '?' . $query; |
|
| 49 | - } |
|
| 47 | + if ($query) { |
|
| 48 | + $url .= '?' . $query; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - return '/' . preg_replace(',^/,S', '', $url); |
|
| 51 | + return '/' . preg_replace(',^/,S', '', $url); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -69,44 +69,44 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function suivre_lien($url, $lien) { |
| 71 | 71 | |
| 72 | - $mot = null; |
|
| 73 | - $get = null; |
|
| 74 | - $hash = null; |
|
| 75 | - if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 76 | - return $lien; |
|
| 77 | - } |
|
| 78 | - if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 79 | - $r = array_pad($r, 3, ''); |
|
| 72 | + $mot = null; |
|
| 73 | + $get = null; |
|
| 74 | + $hash = null; |
|
| 75 | + if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 76 | + return $lien; |
|
| 77 | + } |
|
| 78 | + if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 79 | + $r = array_pad($r, 3, ''); |
|
| 80 | 80 | |
| 81 | - return $r[1] . resolve_path($r[2]); |
|
| 82 | - } |
|
| 81 | + return $r[1] . resolve_path($r[2]); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - # L'url site spip est un lien absolu aussi |
|
| 85 | - if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 86 | - return $lien; |
|
| 87 | - } |
|
| 84 | + # L'url site spip est un lien absolu aussi |
|
| 85 | + if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 86 | + return $lien; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - # lien relatif, il faut verifier l'url de base |
|
| 90 | - # commencer par virer la chaine de get de l'url de base |
|
| 91 | - $dir = '/'; |
|
| 92 | - $debut = ''; |
|
| 93 | - if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 94 | - $debut = $regs[1]; |
|
| 95 | - $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 96 | - $mot = $regs[3]; |
|
| 97 | - $get = $regs[4] ?? ''; |
|
| 98 | - $hash = $regs[5] ?? ''; |
|
| 99 | - } |
|
| 100 | - switch (substr($lien, 0, 1)) { |
|
| 101 | - case '/': |
|
| 102 | - return $debut . resolve_path($lien); |
|
| 103 | - case '#': |
|
| 104 | - return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 105 | - case '': |
|
| 106 | - return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 107 | - default: |
|
| 108 | - return $debut . resolve_path($dir . $lien); |
|
| 109 | - } |
|
| 89 | + # lien relatif, il faut verifier l'url de base |
|
| 90 | + # commencer par virer la chaine de get de l'url de base |
|
| 91 | + $dir = '/'; |
|
| 92 | + $debut = ''; |
|
| 93 | + if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 94 | + $debut = $regs[1]; |
|
| 95 | + $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 96 | + $mot = $regs[3]; |
|
| 97 | + $get = $regs[4] ?? ''; |
|
| 98 | + $hash = $regs[5] ?? ''; |
|
| 99 | + } |
|
| 100 | + switch (substr($lien, 0, 1)) { |
|
| 101 | + case '/': |
|
| 102 | + return $debut . resolve_path($lien); |
|
| 103 | + case '#': |
|
| 104 | + return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 105 | + case '': |
|
| 106 | + return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 107 | + default: |
|
| 108 | + return $debut . resolve_path($dir . $lien); |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -129,15 +129,15 @@ discard block |
||
| 129 | 129 | * @return string Texte ou URL (en absolus) |
| 130 | 130 | **/ |
| 131 | 131 | function url_absolue($url, $base = '') { |
| 132 | - $url = trim((string) $url); |
|
| 133 | - if (strlen($url = trim($url)) == 0) { |
|
| 134 | - return ''; |
|
| 135 | - } |
|
| 136 | - if (!$base) { |
|
| 137 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 138 | - } |
|
| 132 | + $url = trim((string) $url); |
|
| 133 | + if (strlen($url = trim($url)) == 0) { |
|
| 134 | + return ''; |
|
| 135 | + } |
|
| 136 | + if (!$base) { |
|
| 137 | + $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - return suivre_lien($base, $url); |
|
| 140 | + return suivre_lien($base, $url); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * @return string |
| 149 | 149 | */ |
| 150 | 150 | function protocole_implicite($url_absolue) { |
| 151 | - return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 151 | + return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -159,16 +159,16 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
| 161 | 161 | |
| 162 | - if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 163 | - $protocole = $m[1]; |
|
| 164 | - if ( |
|
| 165 | - in_array($protocole, $protocoles_autorises) |
|
| 166 | - or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 167 | - ) { |
|
| 168 | - return true; |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - return false; |
|
| 162 | + if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 163 | + $protocole = $m[1]; |
|
| 164 | + if ( |
|
| 165 | + in_array($protocole, $protocoles_autorises) |
|
| 166 | + or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 167 | + ) { |
|
| 168 | + return true; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + return false; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -185,27 +185,27 @@ discard block |
||
| 185 | 185 | * @return string Texte avec des URLs absolues |
| 186 | 186 | **/ |
| 187 | 187 | function liens_absolus($texte, $base = '') { |
| 188 | - if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 189 | - if (!function_exists('extraire_attribut')) { |
|
| 190 | - include_spip('inc/filtres'); |
|
| 191 | - } |
|
| 192 | - foreach ($liens as $lien) { |
|
| 193 | - foreach (['href', 'src'] as $attr) { |
|
| 194 | - $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 195 | - if (strlen($href) > 0) { |
|
| 196 | - if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 197 | - $abs = url_absolue($href, $base); |
|
| 198 | - if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 199 | - $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | - $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 188 | + if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 189 | + if (!function_exists('extraire_attribut')) { |
|
| 190 | + include_spip('inc/filtres'); |
|
| 191 | + } |
|
| 192 | + foreach ($liens as $lien) { |
|
| 193 | + foreach (['href', 'src'] as $attr) { |
|
| 194 | + $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 195 | + if (strlen($href) > 0) { |
|
| 196 | + if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 197 | + $abs = url_absolue($href, $base); |
|
| 198 | + if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 199 | + $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | + $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - return $texte; |
|
| 208 | + return $texte; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | * @return string Texte ou URL (en absolus) |
| 222 | 222 | **/ |
| 223 | 223 | function abs_url($texte, $base = '') { |
| 224 | - if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 225 | - return url_absolue($texte, $base); |
|
| 226 | - } else { |
|
| 227 | - return liens_absolus($texte, $base); |
|
| 228 | - } |
|
| 224 | + if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 225 | + return url_absolue($texte, $base); |
|
| 226 | + } else { |
|
| 227 | + return liens_absolus($texte, $base); |
|
| 228 | + } |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | 240 | function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 241 | - if (is_null($flags)) { |
|
| 242 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 243 | - } |
|
| 241 | + if (is_null($flags)) { |
|
| 242 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 245 | + return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | 257 | function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 258 | - if (is_null($flags)) { |
|
| 259 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 260 | - } |
|
| 258 | + if (is_null($flags)) { |
|
| 259 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 262 | + return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 263 | 263 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $select = true |
| 125 | 125 | ) { |
| 126 | 126 | if (!is_string($defaut)) { |
| 127 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 127 | + $defaut = '($Pile[0][\''.strtolower($nom_champ).'\'] ?? null)'; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | $idb_origine = $idb; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | // renseigner la boucle source de ce champ pour les traitements |
| 159 | 159 | $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
| 160 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 160 | + $champ = '$Pile[$SP'.($i ? "-$i" : '').'][\''.$c.'\']'; |
|
| 161 | 161 | if (!$joker) { |
| 162 | 162 | return index_compose($conditionnel, $champ); |
| 163 | 163 | } |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | function index_compose($conditionnel, $defaut) { |
| 199 | 199 | while ($c = array_pop($conditionnel)) { |
| 200 | 200 | // si on passe defaut = '', ne pas générer d'erreur de compilation. |
| 201 | - $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 201 | + $defaut = "($c:(".($defaut ?: "''").'))'; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | return $defaut; |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | if (!$r) { |
| 246 | 246 | $joker = false; // indiquer a l'appelant |
| 247 | 247 | # continuer pour chercher l'erreur suivante |
| 248 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 248 | + return ["'#".$r.':'.$nom_champ."'", '']; |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | $desc = $boucles[$idb]->show; |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
| 288 | 288 | [, $_table, $_nom_champ] = $r; |
| 289 | 289 | if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
| 290 | - $_alias = $cle . '_' . $_nom_champ; |
|
| 290 | + $_alias = $cle.'_'.$_nom_champ; |
|
| 291 | 291 | return index_exception( |
| 292 | 292 | $boucles[$idb], |
| 293 | 293 | $desc, |
@@ -367,8 +367,8 @@ discard block |
||
| 367 | 367 | $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
| 368 | 368 | } |
| 369 | 369 | if ($t == null) { |
| 370 | - [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 371 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 370 | + [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 371 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 372 | 372 | $j = $trouver_table($e, $boucle->sql_serveur); |
| 373 | 373 | if (!$j) { |
| 374 | 374 | return ['', '']; |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | $l = (preg_split('/\s*,\s*/', $k)); |
| 381 | 381 | $k = $desc['key']['PRIMARY KEY']; |
| 382 | 382 | if (!in_array($k, $l)) { |
| 383 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 383 | + spip_log("jointure impossible $e ".join(',', $l)); |
|
| 384 | 384 | |
| 385 | 385 | return ['', '']; |
| 386 | 386 | } |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | // demander a SQL de gerer le synonyme |
| 397 | 397 | // ca permet que excep soit dynamique (Cedric, 2/3/06) |
| 398 | 398 | if ($excep != $nom_champ) { |
| 399 | - $excep .= ' AS ' . $nom_champ; |
|
| 399 | + $excep .= ' AS '.$nom_champ; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | return ["$t.$excep", $nom_champ]; |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | join(',', $collecte), |
| 631 | 631 | ($collecte ? $param : substr($param, 1)), # virer la virgule |
| 632 | 632 | memoriser_contexte_compil($p), |
| 633 | - (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 633 | + (!$supp ? '' : (', '.join(',', $supp))) |
|
| 634 | 634 | ); |
| 635 | 635 | |
| 636 | 636 | $p->interdire_scripts = false; |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | $nom = $p->id_boucle; |
| 733 | 733 | |
| 734 | 734 | if ($nom and trouver_nom_serveur_distant($p)) { |
| 735 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 735 | + spip_log($nom.':'.$p->nom_champ.' '._T('zbug_distant_interdit')); |
|
| 736 | 736 | |
| 737 | 737 | return false; |
| 738 | 738 | } |
@@ -817,7 +817,7 @@ discard block |
||
| 817 | 817 | (strpos($ps, 'typo') !== false) |
| 818 | 818 | ) |
| 819 | 819 | ) { |
| 820 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 820 | + $ps = 'traiter_doublons_documents($doublons, '.$ps.')'; |
|
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | // La protection des champs par |safehtml est assuree par les extensions |
@@ -935,7 +935,7 @@ discard block |
||
| 935 | 935 | function compose_filtres_args($p, $args, $sep) { |
| 936 | 936 | $arglist = ''; |
| 937 | 937 | foreach ($args as $arg) { |
| 938 | - $arglist .= $sep . |
|
| 938 | + $arglist .= $sep. |
|
| 939 | 939 | calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
| 940 | 940 | } |
| 941 | 941 | |
@@ -985,7 +985,7 @@ discard block |
||
| 985 | 985 | while ($b != '') { |
| 986 | 986 | foreach ($p->boucles[$b]->criteres as $critere) { |
| 987 | 987 | if ($critere->op == $motif) { |
| 988 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 988 | + $p->code = '$Pile[$SP'.(($n == 0) ? '' : "-$n"). |
|
| 989 | 989 | "]['$champ']"; |
| 990 | 990 | $b = ''; |
| 991 | 991 | break 2; |
@@ -1013,6 +1013,6 @@ discard block |
||
| 1013 | 1013 | */ |
| 1014 | 1014 | function zbug_presenter_champ($p, $champ = '') { |
| 1015 | 1015 | $balise = $champ ?: $p->nom_champ; |
| 1016 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1016 | + $explicite = $p->nom_boucle ? $p->nom_boucle.':' : ''; |
|
| 1017 | 1017 | return "#{$explicite}{$balise}"; |
| 1018 | 1018 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Compilateur\References |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * - '' si une référence explicite incorrecte est envoyée |
| 42 | 42 | */ |
| 43 | 43 | function index_boucle($p) { |
| 44 | - if (strlen($p->nom_boucle)) { |
|
| 45 | - // retourne l’index explicite demandé s’il existe |
|
| 46 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | - return $p->nom_boucle; |
|
| 48 | - } |
|
| 49 | - return ''; |
|
| 50 | - } |
|
| 51 | - return $p->id_boucle; |
|
| 44 | + if (strlen($p->nom_boucle)) { |
|
| 45 | + // retourne l’index explicite demandé s’il existe |
|
| 46 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | + return $p->nom_boucle; |
|
| 48 | + } |
|
| 49 | + return ''; |
|
| 50 | + } |
|
| 51 | + return $p->id_boucle; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | * - '' si une référence explicite incorrecte est envoyée |
| 72 | 72 | */ |
| 73 | 73 | function index_boucle_mere($p) { |
| 74 | - if (strlen($p->nom_boucle)) { |
|
| 75 | - // retourne l’index explicite demandé s’il existe |
|
| 76 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | - return $p->nom_boucle; |
|
| 78 | - } |
|
| 79 | - return ''; |
|
| 80 | - } |
|
| 81 | - if (!empty($p->descr['id_mere'])) { |
|
| 82 | - return $p->descr['id_mere']; |
|
| 83 | - } |
|
| 84 | - return ''; |
|
| 74 | + if (strlen($p->nom_boucle)) { |
|
| 75 | + // retourne l’index explicite demandé s’il existe |
|
| 76 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | + return $p->nom_boucle; |
|
| 78 | + } |
|
| 79 | + return ''; |
|
| 80 | + } |
|
| 81 | + if (!empty($p->descr['id_mere'])) { |
|
| 82 | + return $p->descr['id_mere']; |
|
| 83 | + } |
|
| 84 | + return ''; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -115,74 +115,74 @@ discard block |
||
| 115 | 115 | * Code PHP pour obtenir le champ SQL |
| 116 | 116 | */ |
| 117 | 117 | function index_pile( |
| 118 | - $idb, |
|
| 119 | - $nom_champ, |
|
| 120 | - &$boucles, |
|
| 121 | - $explicite = '', |
|
| 122 | - $defaut = null, |
|
| 123 | - $remonte_pile = true, |
|
| 124 | - $select = true |
|
| 118 | + $idb, |
|
| 119 | + $nom_champ, |
|
| 120 | + &$boucles, |
|
| 121 | + $explicite = '', |
|
| 122 | + $defaut = null, |
|
| 123 | + $remonte_pile = true, |
|
| 124 | + $select = true |
|
| 125 | 125 | ) { |
| 126 | - if (!is_string($defaut)) { |
|
| 127 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $idb_origine = $idb; |
|
| 131 | - $nom_champ_origine = $nom_champ; |
|
| 132 | - |
|
| 133 | - $i = 0; |
|
| 134 | - if (strlen($explicite)) { |
|
| 135 | - // Recherche d'un champ dans un etage superieur |
|
| 136 | - while (($idb !== $explicite) && ($idb !== '')) { |
|
| 137 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 138 | - $i++; |
|
| 139 | - $idb = $boucles[$idb]->id_parent; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 144 | - $nom_champ = strtolower($nom_champ); |
|
| 145 | - $conditionnel = []; |
|
| 146 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 147 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 148 | - while (isset($boucles[$idb])) { |
|
| 149 | - $joker = true; |
|
| 150 | - // modifie $joker si tous les champs sont autorisés. |
|
| 151 | - // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 152 | - // $c = le nom du champ demandé |
|
| 153 | - [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 154 | - if ($t) { |
|
| 155 | - if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 156 | - $boucles[$idb]->select[] = $t; |
|
| 157 | - } |
|
| 158 | - // renseigner la boucle source de ce champ pour les traitements |
|
| 159 | - $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 160 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 161 | - if (!$joker) { |
|
| 162 | - return index_compose($conditionnel, $champ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // tant que l'on trouve des tables avec joker, on continue |
|
| 166 | - // avec la boucle parente et on conditionne à l'exécution |
|
| 167 | - // la présence du champ. Si le champ existe à l'exécution |
|
| 168 | - // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 169 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ($remonte_pile) { |
|
| 173 | - # spip_log("On remonte vers $i"); |
|
| 174 | - // Sinon on remonte d'un cran |
|
| 175 | - $idb = $boucles[$idb]->id_parent; |
|
| 176 | - $i++; |
|
| 177 | - } else { |
|
| 178 | - $idb = null; |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - # spip_log("Pas vu $nom_champ"); |
|
| 183 | - // esperons qu'il y sera |
|
| 184 | - // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 185 | - return index_compose($conditionnel, $defaut); |
|
| 126 | + if (!is_string($defaut)) { |
|
| 127 | + $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $idb_origine = $idb; |
|
| 131 | + $nom_champ_origine = $nom_champ; |
|
| 132 | + |
|
| 133 | + $i = 0; |
|
| 134 | + if (strlen($explicite)) { |
|
| 135 | + // Recherche d'un champ dans un etage superieur |
|
| 136 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 137 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 138 | + $i++; |
|
| 139 | + $idb = $boucles[$idb]->id_parent; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 144 | + $nom_champ = strtolower($nom_champ); |
|
| 145 | + $conditionnel = []; |
|
| 146 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 147 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 148 | + while (isset($boucles[$idb])) { |
|
| 149 | + $joker = true; |
|
| 150 | + // modifie $joker si tous les champs sont autorisés. |
|
| 151 | + // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 152 | + // $c = le nom du champ demandé |
|
| 153 | + [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 154 | + if ($t) { |
|
| 155 | + if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 156 | + $boucles[$idb]->select[] = $t; |
|
| 157 | + } |
|
| 158 | + // renseigner la boucle source de ce champ pour les traitements |
|
| 159 | + $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 160 | + $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 161 | + if (!$joker) { |
|
| 162 | + return index_compose($conditionnel, $champ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // tant que l'on trouve des tables avec joker, on continue |
|
| 166 | + // avec la boucle parente et on conditionne à l'exécution |
|
| 167 | + // la présence du champ. Si le champ existe à l'exécution |
|
| 168 | + // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 169 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ($remonte_pile) { |
|
| 173 | + # spip_log("On remonte vers $i"); |
|
| 174 | + // Sinon on remonte d'un cran |
|
| 175 | + $idb = $boucles[$idb]->id_parent; |
|
| 176 | + $i++; |
|
| 177 | + } else { |
|
| 178 | + $idb = null; |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + # spip_log("Pas vu $nom_champ"); |
|
| 183 | + // esperons qu'il y sera |
|
| 184 | + // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 185 | + return index_compose($conditionnel, $defaut); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | * @return string Code PHP complet de recherche d'un champ |
| 197 | 197 | */ |
| 198 | 198 | function index_compose($conditionnel, $defaut) { |
| 199 | - while ($c = array_pop($conditionnel)) { |
|
| 200 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 201 | - $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 202 | - } |
|
| 199 | + while ($c = array_pop($conditionnel)) { |
|
| 200 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 201 | + $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - return $defaut; |
|
| 204 | + return $defaut; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -237,97 +237,97 @@ discard block |
||
| 237 | 237 | **/ |
| 238 | 238 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 239 | 239 | |
| 240 | - $r = $boucles[$idb]->type_requete; |
|
| 241 | - // boucle recursive, c'est foutu... |
|
| 242 | - if ($r == TYPE_RECURSIF) { |
|
| 243 | - return []; |
|
| 244 | - } |
|
| 245 | - if (!$r) { |
|
| 246 | - $joker = false; // indiquer a l'appelant |
|
| 247 | - # continuer pour chercher l'erreur suivante |
|
| 248 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $desc = $boucles[$idb]->show; |
|
| 252 | - // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | - $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 254 | - if ($excep) { |
|
| 255 | - $excep = $excep[$nom_champ] ?? ''; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - // il y a un alias connu pour ce champ |
|
| 259 | - if ($excep) { |
|
| 260 | - $joker = false; // indiquer a l'appelant |
|
| 261 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // le champ existe dans la table, on le prend. |
|
| 265 | - if (isset($desc['field'][$nom_champ])) { |
|
| 266 | - $t = $boucles[$idb]->id_table ?? ''; |
|
| 267 | - $joker = false; // indiquer a l'appelant |
|
| 268 | - // note: dans certains cas ('valeur' d’une boucle DATA, sans id_table), retourne ['.valeur', 'valeur'] … |
|
| 269 | - return ["$t.$nom_champ", $nom_champ]; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - // Tous les champs sont-ils acceptés ? |
|
| 273 | - // Si oui, on retourne le champ, et on lève le flag joker |
|
| 274 | - // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 275 | - // et testent la présence du champ à l'exécution et non à la compilation |
|
| 276 | - // car ils ne connaissent pas ici leurs contenus. |
|
| 277 | - if ( |
|
| 278 | - /*$joker AND */ |
|
| 279 | - isset($desc['field']['*']) |
|
| 280 | - ) { |
|
| 281 | - $joker = true; // indiquer a l'appelant |
|
| 282 | - return [$nom_champ, $nom_champ]; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $joker = false; // indiquer a l'appelant |
|
| 286 | - |
|
| 287 | - // la table de jointure est explicitement indiquée (rubrique.titre) |
|
| 288 | - if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
|
| 289 | - [, $_table, $_nom_champ] = $r; |
|
| 290 | - if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
|
| 291 | - $_alias = $cle . '_' . $_nom_champ; |
|
| 292 | - return index_exception( |
|
| 293 | - $boucles[$idb], |
|
| 294 | - $desc, |
|
| 295 | - $_alias, |
|
| 296 | - [$_table, $_nom_champ] |
|
| 297 | - ); |
|
| 298 | - } |
|
| 299 | - return ['', '']; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - // pas d'alias, pas de champ, pas de joker... |
|
| 303 | - // tenter via une jointure... |
|
| 304 | - |
|
| 305 | - // regarder si le champ est deja dans une jointure existante |
|
| 306 | - // sinon, si il y a des joitures explicites, la construire |
|
| 307 | - if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 308 | - if ($boucles[$idb]->jointures_explicites) { |
|
| 309 | - // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 310 | - // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 311 | - // mais est-ce ce qu'on veut ? |
|
| 312 | - $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 313 | - if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 314 | - $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - if ($t) { |
|
| 320 | - // si on a trouvé une jointure possible, on fait comme |
|
| 321 | - // si c'était une exception pour le champ demandé |
|
| 322 | - return index_exception( |
|
| 323 | - $boucles[$idb], |
|
| 324 | - $desc, |
|
| 325 | - $nom_champ, |
|
| 326 | - [$t[1]['id_table'], reset($t[2])] |
|
| 327 | - ); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - return ['', '']; |
|
| 240 | + $r = $boucles[$idb]->type_requete; |
|
| 241 | + // boucle recursive, c'est foutu... |
|
| 242 | + if ($r == TYPE_RECURSIF) { |
|
| 243 | + return []; |
|
| 244 | + } |
|
| 245 | + if (!$r) { |
|
| 246 | + $joker = false; // indiquer a l'appelant |
|
| 247 | + # continuer pour chercher l'erreur suivante |
|
| 248 | + return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $desc = $boucles[$idb]->show; |
|
| 252 | + // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | + $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 254 | + if ($excep) { |
|
| 255 | + $excep = $excep[$nom_champ] ?? ''; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + // il y a un alias connu pour ce champ |
|
| 259 | + if ($excep) { |
|
| 260 | + $joker = false; // indiquer a l'appelant |
|
| 261 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // le champ existe dans la table, on le prend. |
|
| 265 | + if (isset($desc['field'][$nom_champ])) { |
|
| 266 | + $t = $boucles[$idb]->id_table ?? ''; |
|
| 267 | + $joker = false; // indiquer a l'appelant |
|
| 268 | + // note: dans certains cas ('valeur' d’une boucle DATA, sans id_table), retourne ['.valeur', 'valeur'] … |
|
| 269 | + return ["$t.$nom_champ", $nom_champ]; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + // Tous les champs sont-ils acceptés ? |
|
| 273 | + // Si oui, on retourne le champ, et on lève le flag joker |
|
| 274 | + // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 275 | + // et testent la présence du champ à l'exécution et non à la compilation |
|
| 276 | + // car ils ne connaissent pas ici leurs contenus. |
|
| 277 | + if ( |
|
| 278 | + /*$joker AND */ |
|
| 279 | + isset($desc['field']['*']) |
|
| 280 | + ) { |
|
| 281 | + $joker = true; // indiquer a l'appelant |
|
| 282 | + return [$nom_champ, $nom_champ]; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $joker = false; // indiquer a l'appelant |
|
| 286 | + |
|
| 287 | + // la table de jointure est explicitement indiquée (rubrique.titre) |
|
| 288 | + if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
|
| 289 | + [, $_table, $_nom_champ] = $r; |
|
| 290 | + if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
|
| 291 | + $_alias = $cle . '_' . $_nom_champ; |
|
| 292 | + return index_exception( |
|
| 293 | + $boucles[$idb], |
|
| 294 | + $desc, |
|
| 295 | + $_alias, |
|
| 296 | + [$_table, $_nom_champ] |
|
| 297 | + ); |
|
| 298 | + } |
|
| 299 | + return ['', '']; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + // pas d'alias, pas de champ, pas de joker... |
|
| 303 | + // tenter via une jointure... |
|
| 304 | + |
|
| 305 | + // regarder si le champ est deja dans une jointure existante |
|
| 306 | + // sinon, si il y a des joitures explicites, la construire |
|
| 307 | + if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 308 | + if ($boucles[$idb]->jointures_explicites) { |
|
| 309 | + // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 310 | + // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 311 | + // mais est-ce ce qu'on veut ? |
|
| 312 | + $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 313 | + if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 314 | + $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + if ($t) { |
|
| 320 | + // si on a trouvé une jointure possible, on fait comme |
|
| 321 | + // si c'était une exception pour le champ demandé |
|
| 322 | + return index_exception( |
|
| 323 | + $boucles[$idb], |
|
| 324 | + $desc, |
|
| 325 | + $nom_champ, |
|
| 326 | + [$t[1]['id_table'], reset($t[2])] |
|
| 327 | + ); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + return ['', '']; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | |
@@ -355,52 +355,52 @@ discard block |
||
| 355 | 355 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 356 | 356 | **/ |
| 357 | 357 | function index_exception(&$boucle, $desc, $nom_champ, $excep) { |
| 358 | - static $trouver_table; |
|
| 359 | - if (!$trouver_table) { |
|
| 360 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - if (is_array($excep)) { |
|
| 364 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 365 | - $t = null; |
|
| 366 | - if (count($excep) == 3) { |
|
| 367 | - $index_exception_derogatoire = array_pop($excep); |
|
| 368 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 369 | - } |
|
| 370 | - if ($t == null) { |
|
| 371 | - [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 372 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 373 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 374 | - if (!$j) { |
|
| 375 | - return ['', '']; |
|
| 376 | - } |
|
| 377 | - $e = $j['table']; |
|
| 378 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 379 | - $k = $j['key']['PRIMARY KEY']; |
|
| 380 | - if (strpos($k, ',')) { |
|
| 381 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 382 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 383 | - if (!in_array($k, $l)) { |
|
| 384 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 385 | - |
|
| 386 | - return ['', '']; |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - $k = [$boucle->id_table, [$e], $k]; |
|
| 390 | - fabrique_jointures($boucle, [$k]); |
|
| 391 | - $t = array_search($e, $boucle->from); |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - } else { |
|
| 395 | - $t = $boucle->id_table; |
|
| 396 | - } |
|
| 397 | - // demander a SQL de gerer le synonyme |
|
| 398 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 399 | - if ($excep != $nom_champ) { |
|
| 400 | - $excep .= ' AS ' . $nom_champ; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - return ["$t.$excep", $nom_champ]; |
|
| 358 | + static $trouver_table; |
|
| 359 | + if (!$trouver_table) { |
|
| 360 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + if (is_array($excep)) { |
|
| 364 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 365 | + $t = null; |
|
| 366 | + if (count($excep) == 3) { |
|
| 367 | + $index_exception_derogatoire = array_pop($excep); |
|
| 368 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 369 | + } |
|
| 370 | + if ($t == null) { |
|
| 371 | + [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 372 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 373 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 374 | + if (!$j) { |
|
| 375 | + return ['', '']; |
|
| 376 | + } |
|
| 377 | + $e = $j['table']; |
|
| 378 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 379 | + $k = $j['key']['PRIMARY KEY']; |
|
| 380 | + if (strpos($k, ',')) { |
|
| 381 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 382 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 383 | + if (!in_array($k, $l)) { |
|
| 384 | + spip_log("jointure impossible $e " . join(',', $l)); |
|
| 385 | + |
|
| 386 | + return ['', '']; |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + $k = [$boucle->id_table, [$e], $k]; |
|
| 390 | + fabrique_jointures($boucle, [$k]); |
|
| 391 | + $t = array_search($e, $boucle->from); |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + } else { |
|
| 395 | + $t = $boucle->id_table; |
|
| 396 | + } |
|
| 397 | + // demander a SQL de gerer le synonyme |
|
| 398 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 399 | + if ($excep != $nom_champ) { |
|
| 400 | + $excep .= ' AS ' . $nom_champ; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + return ["$t.$excep", $nom_champ]; |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | /** |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | * Code PHP pour retrouver le champ |
| 426 | 426 | */ |
| 427 | 427 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 428 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 428 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | |
@@ -445,9 +445,9 @@ discard block |
||
| 445 | 445 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 446 | 446 | **/ |
| 447 | 447 | function calculer_champ($p) { |
| 448 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 448 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 449 | 449 | |
| 450 | - return applique_filtres($p); |
|
| 450 | + return applique_filtres($p); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | |
@@ -484,26 +484,26 @@ discard block |
||
| 484 | 484 | **/ |
| 485 | 485 | function calculer_balise(string $nom, \Champ $p): \Champ { |
| 486 | 486 | |
| 487 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 488 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 489 | - $p->balise_calculee = true; |
|
| 490 | - $res = $f($p); |
|
| 491 | - if ($res !== null and is_object($res)) { |
|
| 492 | - return $res; |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - // Certaines des balises comportant un _ sont generiques |
|
| 497 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 498 | - $res = $balise_generique['fonction_generique']($p); |
|
| 499 | - if ($res !== null and is_object($res)) { |
|
| 500 | - return $res; |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 505 | - |
|
| 506 | - return $f($nom, $p); |
|
| 487 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 488 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 489 | + $p->balise_calculee = true; |
|
| 490 | + $res = $f($p); |
|
| 491 | + if ($res !== null and is_object($res)) { |
|
| 492 | + return $res; |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + // Certaines des balises comportant un _ sont generiques |
|
| 497 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 498 | + $res = $balise_generique['fonction_generique']($p); |
|
| 499 | + if ($res !== null and is_object($res)) { |
|
| 500 | + return $res; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 505 | + |
|
| 506 | + return $f($nom, $p); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | |
@@ -531,37 +531,37 @@ discard block |
||
| 531 | 531 | **/ |
| 532 | 532 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 533 | 533 | |
| 534 | - // ca pourrait etre un champ SQL homonyme, |
|
| 535 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 536 | - |
|
| 537 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 538 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 539 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 540 | - $code = addslashes($p->fonctions[0][1]); |
|
| 541 | - $p->code .= " . '$code'"; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 545 | - if (strpos($nom, 'ID_') === 0) { |
|
| 546 | - $p->interdire_scripts = false; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 550 | - // SI le champ SQL n'est pas trouve |
|
| 551 | - // ET si la balise a une forme de couleur |
|
| 552 | - // ET s'il n'y a ni filtre ni etoile |
|
| 553 | - // ALORS retourner la couleur. |
|
| 554 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 555 | - if ( |
|
| 556 | - preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 557 | - and !$p->etoile |
|
| 558 | - and !$p->fonctions |
|
| 559 | - ) { |
|
| 560 | - $p->code = "'#$nom'"; |
|
| 561 | - $p->interdire_scripts = false; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - return $p; |
|
| 534 | + // ca pourrait etre un champ SQL homonyme, |
|
| 535 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 536 | + |
|
| 537 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 538 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 539 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 540 | + $code = addslashes($p->fonctions[0][1]); |
|
| 541 | + $p->code .= " . '$code'"; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 545 | + if (strpos($nom, 'ID_') === 0) { |
|
| 546 | + $p->interdire_scripts = false; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 550 | + // SI le champ SQL n'est pas trouve |
|
| 551 | + // ET si la balise a une forme de couleur |
|
| 552 | + // ET s'il n'y a ni filtre ni etoile |
|
| 553 | + // ALORS retourner la couleur. |
|
| 554 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 555 | + if ( |
|
| 556 | + preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 557 | + and !$p->etoile |
|
| 558 | + and !$p->fonctions |
|
| 559 | + ) { |
|
| 560 | + $p->code = "'#$nom'"; |
|
| 561 | + $p->interdire_scripts = false; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + return $p; |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | |
@@ -609,53 +609,53 @@ discard block |
||
| 609 | 609 | **/ |
| 610 | 610 | function calculer_balise_dynamique($p, $nom, $l, $supp = []) { |
| 611 | 611 | |
| 612 | - if (!balise_distante_interdite($p)) { |
|
| 613 | - $p->code = "''"; |
|
| 614 | - |
|
| 615 | - return $p; |
|
| 616 | - } |
|
| 617 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 618 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 619 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 620 | - $p->fonctions = []; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - if ($p->param and ($c = $p->param[0])) { |
|
| 624 | - // liste d'arguments commence toujours par la chaine vide |
|
| 625 | - array_shift($c); |
|
| 626 | - // construire la liste d'arguments comme pour un filtre |
|
| 627 | - $param = compose_filtres_args($p, $c, ','); |
|
| 628 | - } else { |
|
| 629 | - $param = ''; |
|
| 630 | - } |
|
| 631 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 632 | - |
|
| 633 | - $dans_un_modele = false; |
|
| 634 | - if (!empty($p->descr['sourcefile']) |
|
| 635 | - and $f = $p->descr['sourcefile'] |
|
| 636 | - and basename(dirname($f)) === 'modeles' |
|
| 637 | - ) { |
|
| 638 | - $dans_un_modele = true; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - // un modele est toujours inséré en texte dans son contenant |
|
| 642 | - // donc si on est dans le public avec un cache on va perdre le dynamisme |
|
| 643 | - // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
|
| 644 | - // on passe donc par une fonction proxy qui si besoin va collecter les arguments |
|
| 645 | - // et injecter le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
|
| 646 | - // (dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave)) |
|
| 647 | - $p->code = sprintf( |
|
| 648 | - $dans_un_modele ? CODE_EXECUTER_BALISE_MODELE : CODE_EXECUTER_BALISE, |
|
| 649 | - $nom, |
|
| 650 | - join(',', $collecte), |
|
| 651 | - ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 652 | - memoriser_contexte_compil($p), |
|
| 653 | - (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 654 | - ); |
|
| 655 | - |
|
| 656 | - $p->interdire_scripts = false; |
|
| 657 | - |
|
| 658 | - return $p; |
|
| 612 | + if (!balise_distante_interdite($p)) { |
|
| 613 | + $p->code = "''"; |
|
| 614 | + |
|
| 615 | + return $p; |
|
| 616 | + } |
|
| 617 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 618 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 619 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 620 | + $p->fonctions = []; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + if ($p->param and ($c = $p->param[0])) { |
|
| 624 | + // liste d'arguments commence toujours par la chaine vide |
|
| 625 | + array_shift($c); |
|
| 626 | + // construire la liste d'arguments comme pour un filtre |
|
| 627 | + $param = compose_filtres_args($p, $c, ','); |
|
| 628 | + } else { |
|
| 629 | + $param = ''; |
|
| 630 | + } |
|
| 631 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 632 | + |
|
| 633 | + $dans_un_modele = false; |
|
| 634 | + if (!empty($p->descr['sourcefile']) |
|
| 635 | + and $f = $p->descr['sourcefile'] |
|
| 636 | + and basename(dirname($f)) === 'modeles' |
|
| 637 | + ) { |
|
| 638 | + $dans_un_modele = true; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + // un modele est toujours inséré en texte dans son contenant |
|
| 642 | + // donc si on est dans le public avec un cache on va perdre le dynamisme |
|
| 643 | + // et on risque de mettre en cache les valeurs pre-remplies du formulaire |
|
| 644 | + // on passe donc par une fonction proxy qui si besoin va collecter les arguments |
|
| 645 | + // et injecter le PHP qui va appeler la fonction pour generer le formulaire au lieu de directement la fonction |
|
| 646 | + // (dans l'espace prive on a pas de cache, donc pas de soucis (et un leak serait moins grave)) |
|
| 647 | + $p->code = sprintf( |
|
| 648 | + $dans_un_modele ? CODE_EXECUTER_BALISE_MODELE : CODE_EXECUTER_BALISE, |
|
| 649 | + $nom, |
|
| 650 | + join(',', $collecte), |
|
| 651 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 652 | + memoriser_contexte_compil($p), |
|
| 653 | + (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 654 | + ); |
|
| 655 | + |
|
| 656 | + $p->interdire_scripts = false; |
|
| 657 | + |
|
| 658 | + return $p; |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | |
@@ -685,17 +685,17 @@ discard block |
||
| 685 | 685 | * Liste des codes PHP d'éxecution des balises collectées |
| 686 | 686 | **/ |
| 687 | 687 | function collecter_balise_dynamique(array $l, \Champ &$p, string $nom): array { |
| 688 | - $args = []; |
|
| 689 | - foreach ($l as $c) { |
|
| 690 | - if ($c === null) { |
|
| 691 | - $args[] = 'null'; |
|
| 692 | - } else { |
|
| 693 | - $x = calculer_balise($c, $p); |
|
| 694 | - $args[] = $x->code; |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - return $args; |
|
| 688 | + $args = []; |
|
| 689 | + foreach ($l as $c) { |
|
| 690 | + if ($c === null) { |
|
| 691 | + $args[] = 'null'; |
|
| 692 | + } else { |
|
| 693 | + $x = calculer_balise($c, $p); |
|
| 694 | + $args[] = $x->code; |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + return $args; |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | |
@@ -710,22 +710,22 @@ discard block |
||
| 710 | 710 | * Nom de la connexion |
| 711 | 711 | **/ |
| 712 | 712 | function trouver_nom_serveur_distant($p) { |
| 713 | - $nom = $p->id_boucle; |
|
| 714 | - if ( |
|
| 715 | - $nom |
|
| 716 | - and isset($p->boucles[$nom]) |
|
| 717 | - ) { |
|
| 718 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 719 | - if ( |
|
| 720 | - strlen($s) |
|
| 721 | - and strlen($serveur = strtolower($s)) |
|
| 722 | - and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 723 | - ) { |
|
| 724 | - return $serveur; |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - return ''; |
|
| 713 | + $nom = $p->id_boucle; |
|
| 714 | + if ( |
|
| 715 | + $nom |
|
| 716 | + and isset($p->boucles[$nom]) |
|
| 717 | + ) { |
|
| 718 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 719 | + if ( |
|
| 720 | + strlen($s) |
|
| 721 | + and strlen($serveur = strtolower($s)) |
|
| 722 | + and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 723 | + ) { |
|
| 724 | + return $serveur; |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + return ''; |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | |
@@ -749,15 +749,15 @@ discard block |
||
| 749 | 749 | * - false : La balise est interdite car le serveur est distant |
| 750 | 750 | **/ |
| 751 | 751 | function balise_distante_interdite($p) { |
| 752 | - $nom = $p->id_boucle; |
|
| 752 | + $nom = $p->id_boucle; |
|
| 753 | 753 | |
| 754 | - if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 755 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 754 | + if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 755 | + spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 756 | 756 | |
| 757 | - return false; |
|
| 758 | - } |
|
| 757 | + return false; |
|
| 758 | + } |
|
| 759 | 759 | |
| 760 | - return true; |
|
| 760 | + return true; |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | |
@@ -767,84 +767,84 @@ discard block |
||
| 767 | 767 | // |
| 768 | 768 | function champs_traitements($p) { |
| 769 | 769 | |
| 770 | - if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 771 | - $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 772 | - } else { |
|
| 773 | - // quand on utilise un traitement catch-all * |
|
| 774 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 775 | - // leur propre securite |
|
| 776 | - if (!$p->balise_calculee) { |
|
| 777 | - $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 778 | - } else { |
|
| 779 | - $ps = false; |
|
| 780 | - } |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - if (is_array($ps)) { |
|
| 784 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 785 | - $idb = index_boucle($p); |
|
| 786 | - // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 787 | - if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 788 | - $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 792 | - $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 793 | - $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 794 | - |
|
| 795 | - // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 796 | - if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 797 | - $type_alias = $type_requete; |
|
| 798 | - $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 799 | - } else { |
|
| 800 | - $type_alias = false; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 804 | - if ($table_sql and isset($ps[$table_sql])) { |
|
| 805 | - $ps = $ps[$table_sql]; |
|
| 806 | - } // ou pour une boucle en particulier "DATA","articles" |
|
| 807 | - elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 808 | - $ps = $ps[$type_requete]; |
|
| 809 | - } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 810 | - elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 811 | - $ps = $ps[$type_alias]; |
|
| 812 | - } // ou pour indifféremment quelle que soit la boucle |
|
| 813 | - elseif (isset($ps[0])) { |
|
| 814 | - $ps = $ps[0]; |
|
| 815 | - } else { |
|
| 816 | - $ps = false; |
|
| 817 | - } |
|
| 818 | - } |
|
| 819 | - |
|
| 820 | - if (!$ps) { |
|
| 821 | - return $p->code; |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 825 | - // ou si in INCLURE contient {doublons} |
|
| 826 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 827 | - // dans les filtres propre() ou typo() |
|
| 828 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 829 | - |
|
| 830 | - if ( |
|
| 831 | - isset($p->descr['documents']) |
|
| 832 | - and |
|
| 833 | - $p->descr['documents'] |
|
| 834 | - and ( |
|
| 835 | - (strpos($ps, 'propre') !== false) |
|
| 836 | - or |
|
| 837 | - (strpos($ps, 'typo') !== false) |
|
| 838 | - ) |
|
| 839 | - ) { |
|
| 840 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 844 | - // dans la declaration des traitements des champs sensibles |
|
| 845 | - |
|
| 846 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 847 | - return str_replace('%s', $p->code, $ps); |
|
| 770 | + if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 771 | + $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 772 | + } else { |
|
| 773 | + // quand on utilise un traitement catch-all * |
|
| 774 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 775 | + // leur propre securite |
|
| 776 | + if (!$p->balise_calculee) { |
|
| 777 | + $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 778 | + } else { |
|
| 779 | + $ps = false; |
|
| 780 | + } |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + if (is_array($ps)) { |
|
| 784 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 785 | + $idb = index_boucle($p); |
|
| 786 | + // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 787 | + if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 788 | + $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 792 | + $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 793 | + $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 794 | + |
|
| 795 | + // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 796 | + if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 797 | + $type_alias = $type_requete; |
|
| 798 | + $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 799 | + } else { |
|
| 800 | + $type_alias = false; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 804 | + if ($table_sql and isset($ps[$table_sql])) { |
|
| 805 | + $ps = $ps[$table_sql]; |
|
| 806 | + } // ou pour une boucle en particulier "DATA","articles" |
|
| 807 | + elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 808 | + $ps = $ps[$type_requete]; |
|
| 809 | + } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 810 | + elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 811 | + $ps = $ps[$type_alias]; |
|
| 812 | + } // ou pour indifféremment quelle que soit la boucle |
|
| 813 | + elseif (isset($ps[0])) { |
|
| 814 | + $ps = $ps[0]; |
|
| 815 | + } else { |
|
| 816 | + $ps = false; |
|
| 817 | + } |
|
| 818 | + } |
|
| 819 | + |
|
| 820 | + if (!$ps) { |
|
| 821 | + return $p->code; |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 825 | + // ou si in INCLURE contient {doublons} |
|
| 826 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 827 | + // dans les filtres propre() ou typo() |
|
| 828 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 829 | + |
|
| 830 | + if ( |
|
| 831 | + isset($p->descr['documents']) |
|
| 832 | + and |
|
| 833 | + $p->descr['documents'] |
|
| 834 | + and ( |
|
| 835 | + (strpos($ps, 'propre') !== false) |
|
| 836 | + or |
|
| 837 | + (strpos($ps, 'typo') !== false) |
|
| 838 | + ) |
|
| 839 | + ) { |
|
| 840 | + $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 844 | + // dans la declaration des traitements des champs sensibles |
|
| 845 | + |
|
| 846 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 847 | + return str_replace('%s', $p->code, $ps); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | |
@@ -856,110 +856,110 @@ discard block |
||
| 856 | 856 | // |
| 857 | 857 | function applique_filtres($p) { |
| 858 | 858 | |
| 859 | - // Traitements standards (cf. supra) |
|
| 860 | - if ($p->etoile == '') { |
|
| 861 | - $code = champs_traitements($p); |
|
| 862 | - } else { |
|
| 863 | - $code = $p->code; |
|
| 864 | - } |
|
| 859 | + // Traitements standards (cf. supra) |
|
| 860 | + if ($p->etoile == '') { |
|
| 861 | + $code = champs_traitements($p); |
|
| 862 | + } else { |
|
| 863 | + $code = $p->code; |
|
| 864 | + } |
|
| 865 | 865 | |
| 866 | - // Appliquer les filtres perso |
|
| 867 | - if ($p->param) { |
|
| 868 | - $code = compose_filtres($p, $code); |
|
| 869 | - } |
|
| 866 | + // Appliquer les filtres perso |
|
| 867 | + if ($p->param) { |
|
| 868 | + $code = compose_filtres($p, $code); |
|
| 869 | + } |
|
| 870 | 870 | |
| 871 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 872 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 873 | - if (isset($p->descr['session'])) { |
|
| 874 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 875 | - } |
|
| 871 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 872 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 873 | + if (isset($p->descr['session'])) { |
|
| 874 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 875 | + } |
|
| 876 | 876 | |
| 877 | - $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 877 | + $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 878 | 878 | |
| 879 | - return $code; |
|
| 879 | + return $code; |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 883 | 883 | function compose_filtres(&$p, $code) { |
| 884 | 884 | |
| 885 | - $image_miette = false; |
|
| 886 | - foreach ($p->param as $filtre) { |
|
| 887 | - $fonc = array_shift($filtre); |
|
| 888 | - if (!$fonc) { |
|
| 889 | - continue; |
|
| 890 | - } // normalement qu'au premier tour. |
|
| 891 | - $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 892 | - if ($image_miette and !$is_filtre_image) { |
|
| 893 | - // il faut graver maintenant car apres le filtre en cours |
|
| 894 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 895 | - $code = "filtrer('image_graver', $code)"; |
|
| 896 | - $image_miette = false; |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - // recuperer les arguments du filtre, |
|
| 900 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 901 | - $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 902 | - if ($fonc !== '?') { |
|
| 903 | - $sep = ','; |
|
| 904 | - } else { |
|
| 905 | - $sep = ':'; |
|
| 906 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 907 | - if ($countfiltre != 2) { |
|
| 908 | - $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 909 | - $countfiltre = 2; |
|
| 910 | - } |
|
| 911 | - } |
|
| 912 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 913 | - $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 914 | - if ($logique) { |
|
| 915 | - $code = $logique; |
|
| 916 | - } else { |
|
| 917 | - $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 918 | - if ($is_filtre_image) { |
|
| 919 | - $image_miette = true; |
|
| 920 | - } |
|
| 921 | - } |
|
| 922 | - } |
|
| 923 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 924 | - if ($image_miette) { |
|
| 925 | - $code = "filtrer('image_graver',$code)"; |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - return $code; |
|
| 885 | + $image_miette = false; |
|
| 886 | + foreach ($p->param as $filtre) { |
|
| 887 | + $fonc = array_shift($filtre); |
|
| 888 | + if (!$fonc) { |
|
| 889 | + continue; |
|
| 890 | + } // normalement qu'au premier tour. |
|
| 891 | + $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 892 | + if ($image_miette and !$is_filtre_image) { |
|
| 893 | + // il faut graver maintenant car apres le filtre en cours |
|
| 894 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 895 | + $code = "filtrer('image_graver', $code)"; |
|
| 896 | + $image_miette = false; |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + // recuperer les arguments du filtre, |
|
| 900 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 901 | + $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 902 | + if ($fonc !== '?') { |
|
| 903 | + $sep = ','; |
|
| 904 | + } else { |
|
| 905 | + $sep = ':'; |
|
| 906 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 907 | + if ($countfiltre != 2) { |
|
| 908 | + $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 909 | + $countfiltre = 2; |
|
| 910 | + } |
|
| 911 | + } |
|
| 912 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 913 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 914 | + if ($logique) { |
|
| 915 | + $code = $logique; |
|
| 916 | + } else { |
|
| 917 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 918 | + if ($is_filtre_image) { |
|
| 919 | + $image_miette = true; |
|
| 920 | + } |
|
| 921 | + } |
|
| 922 | + } |
|
| 923 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 924 | + if ($image_miette) { |
|
| 925 | + $code = "filtrer('image_graver',$code)"; |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + return $code; |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 932 | 932 | // et comparateurs |
| 933 | 933 | function filtre_logique($fonc, $code, $arg) { |
| 934 | 934 | |
| 935 | - switch (true) { |
|
| 936 | - case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 937 | - return "($code $fonc $arg)"; |
|
| 938 | - case ($fonc == 'and') or ($fonc == 'et'): |
|
| 939 | - return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 940 | - case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 941 | - return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 942 | - case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 943 | - return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 944 | - case ($fonc == 'sinon'): |
|
| 945 | - return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 946 | - case ($fonc == 'not') or ($fonc == 'non'): |
|
| 947 | - return "(($code) ?'' :' ')"; |
|
| 948 | - case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 949 | - return "(($code) ?' ' :'')"; |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - return ''; |
|
| 935 | + switch (true) { |
|
| 936 | + case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 937 | + return "($code $fonc $arg)"; |
|
| 938 | + case ($fonc == 'and') or ($fonc == 'et'): |
|
| 939 | + return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 940 | + case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 941 | + return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 942 | + case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 943 | + return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 944 | + case ($fonc == 'sinon'): |
|
| 945 | + return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 946 | + case ($fonc == 'not') or ($fonc == 'non'): |
|
| 947 | + return "(($code) ?'' :' ')"; |
|
| 948 | + case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 949 | + return "(($code) ?' ' :'')"; |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + return ''; |
|
| 953 | 953 | } |
| 954 | 954 | |
| 955 | 955 | function compose_filtres_args($p, $args, $sep) { |
| 956 | - $arglist = ''; |
|
| 957 | - foreach ($args as $arg) { |
|
| 958 | - $arglist .= $sep . |
|
| 959 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 960 | - } |
|
| 956 | + $arglist = ''; |
|
| 957 | + foreach ($args as $arg) { |
|
| 958 | + $arglist .= $sep . |
|
| 959 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 960 | + } |
|
| 961 | 961 | |
| 962 | - return $arglist; |
|
| 962 | + return $arglist; |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | |
@@ -977,15 +977,15 @@ discard block |
||
| 977 | 977 | **/ |
| 978 | 978 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 979 | 979 | |
| 980 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 981 | - if ($boucles[$idb]->externe) { |
|
| 982 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 983 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 984 | - // on ignore le defaut fourni dans ce cas |
|
| 985 | - $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 986 | - } |
|
| 980 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 981 | + if ($boucles[$idb]->externe) { |
|
| 982 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 983 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 984 | + // on ignore le defaut fourni dans ce cas |
|
| 985 | + $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 986 | + } |
|
| 987 | 987 | |
| 988 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 988 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | // |
@@ -999,30 +999,30 @@ discard block |
||
| 999 | 999 | // |
| 1000 | 1000 | |
| 1001 | 1001 | function rindex_pile($p, $champ, $motif) { |
| 1002 | - $n = 0; |
|
| 1003 | - $b = $p->id_boucle; |
|
| 1004 | - $p->code = ''; |
|
| 1005 | - while ($b != '') { |
|
| 1006 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 1007 | - if ($critere->op == $motif) { |
|
| 1008 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 1009 | - "]['$champ']"; |
|
| 1010 | - $b = ''; |
|
| 1011 | - break 2; |
|
| 1012 | - } |
|
| 1013 | - } |
|
| 1014 | - $n++; |
|
| 1015 | - $b = $p->boucles[$b]->id_parent; |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 1019 | - if (!$p->code) { |
|
| 1020 | - $p->code = "''"; |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - $p->interdire_scripts = false; |
|
| 1024 | - |
|
| 1025 | - return $p; |
|
| 1002 | + $n = 0; |
|
| 1003 | + $b = $p->id_boucle; |
|
| 1004 | + $p->code = ''; |
|
| 1005 | + while ($b != '') { |
|
| 1006 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 1007 | + if ($critere->op == $motif) { |
|
| 1008 | + $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 1009 | + "]['$champ']"; |
|
| 1010 | + $b = ''; |
|
| 1011 | + break 2; |
|
| 1012 | + } |
|
| 1013 | + } |
|
| 1014 | + $n++; |
|
| 1015 | + $b = $p->boucles[$b]->id_parent; |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 1019 | + if (!$p->code) { |
|
| 1020 | + $p->code = "''"; |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + $p->interdire_scripts = false; |
|
| 1024 | + |
|
| 1025 | + return $p; |
|
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | 1028 | /** |
@@ -1032,7 +1032,7 @@ discard block |
||
| 1032 | 1032 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 1033 | 1033 | */ |
| 1034 | 1034 | function zbug_presenter_champ($p, $champ = '') { |
| 1035 | - $balise = $champ ?: $p->nom_champ; |
|
| 1036 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1037 | - return "#{$explicite}{$balise}"; |
|
| 1035 | + $balise = $champ ?: $p->nom_champ; |
|
| 1036 | + $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1037 | + return "#{$explicite}{$balise}"; |
|
| 1038 | 1038 | } |
@@ -19,78 +19,78 @@ |
||
| 19 | 19 | * @link https://www.php.net/manual/fr/book.sodium.php |
| 20 | 20 | */ |
| 21 | 21 | class Chiffrement { |
| 22 | - /** Chiffre un message en utilisant une clé ou un mot de passe */ |
|
| 23 | - public static function chiffrer( |
|
| 24 | - string $message, |
|
| 25 | - #[\SensitiveParameter] |
|
| 26 | - string $key |
|
| 27 | - ): ?string { |
|
| 28 | - // create a random salt for key derivation |
|
| 29 | - $salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES); |
|
| 30 | - $key = self::deriveKeyFromPassword($key, $salt); |
|
| 31 | - $nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 32 | - $padded_message = sodium_pad($message, 16); |
|
| 33 | - $encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key); |
|
| 34 | - $encoded = base64_encode($salt . $nonce . $encrypted); |
|
| 35 | - sodium_memzero($key); |
|
| 36 | - sodium_memzero($nonce); |
|
| 37 | - sodium_memzero($salt); |
|
| 38 | - #spip_log("chiffrer($message)=$encoded", 'chiffrer' . _LOG_DEBUG); |
|
| 39 | - return $encoded; |
|
| 40 | - } |
|
| 22 | + /** Chiffre un message en utilisant une clé ou un mot de passe */ |
|
| 23 | + public static function chiffrer( |
|
| 24 | + string $message, |
|
| 25 | + #[\SensitiveParameter] |
|
| 26 | + string $key |
|
| 27 | + ): ?string { |
|
| 28 | + // create a random salt for key derivation |
|
| 29 | + $salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES); |
|
| 30 | + $key = self::deriveKeyFromPassword($key, $salt); |
|
| 31 | + $nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 32 | + $padded_message = sodium_pad($message, 16); |
|
| 33 | + $encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key); |
|
| 34 | + $encoded = base64_encode($salt . $nonce . $encrypted); |
|
| 35 | + sodium_memzero($key); |
|
| 36 | + sodium_memzero($nonce); |
|
| 37 | + sodium_memzero($salt); |
|
| 38 | + #spip_log("chiffrer($message)=$encoded", 'chiffrer' . _LOG_DEBUG); |
|
| 39 | + return $encoded; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** Déchiffre un message en utilisant une clé ou un mot de passe */ |
|
| 43 | - public static function dechiffrer( |
|
| 44 | - string $encoded, |
|
| 45 | - #[\SensitiveParameter] |
|
| 46 | - string $key |
|
| 47 | - ): ?string { |
|
| 48 | - $decoded = base64_decode($encoded); |
|
| 49 | - $salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES); |
|
| 50 | - $nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 51 | - $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 52 | - $key = self::deriveKeyFromPassword($key, $salt); |
|
| 53 | - $padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key); |
|
| 54 | - sodium_memzero($key); |
|
| 55 | - sodium_memzero($nonce); |
|
| 56 | - sodium_memzero($salt); |
|
| 57 | - if ($padded_message === false) { |
|
| 58 | - spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG); |
|
| 59 | - return null; |
|
| 60 | - } |
|
| 61 | - $message = sodium_unpad($padded_message, 16); |
|
| 62 | - #spip_log("dechiffrer($encoded)=$message", 'chiffrer' . _LOG_DEBUG); |
|
| 63 | - return $message; |
|
| 64 | - } |
|
| 42 | + /** Déchiffre un message en utilisant une clé ou un mot de passe */ |
|
| 43 | + public static function dechiffrer( |
|
| 44 | + string $encoded, |
|
| 45 | + #[\SensitiveParameter] |
|
| 46 | + string $key |
|
| 47 | + ): ?string { |
|
| 48 | + $decoded = base64_decode($encoded); |
|
| 49 | + $salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES); |
|
| 50 | + $nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 51 | + $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 52 | + $key = self::deriveKeyFromPassword($key, $salt); |
|
| 53 | + $padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key); |
|
| 54 | + sodium_memzero($key); |
|
| 55 | + sodium_memzero($nonce); |
|
| 56 | + sodium_memzero($salt); |
|
| 57 | + if ($padded_message === false) { |
|
| 58 | + spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG); |
|
| 59 | + return null; |
|
| 60 | + } |
|
| 61 | + $message = sodium_unpad($padded_message, 16); |
|
| 62 | + #spip_log("dechiffrer($encoded)=$message", 'chiffrer' . _LOG_DEBUG); |
|
| 63 | + return $message; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** Génère une clé de la taille attendue pour le chiffrement */ |
|
| 67 | - public static function keygen(): string { |
|
| 68 | - return sodium_crypto_secretbox_keygen(); |
|
| 69 | - } |
|
| 66 | + /** Génère une clé de la taille attendue pour le chiffrement */ |
|
| 67 | + public static function keygen(): string { |
|
| 68 | + return sodium_crypto_secretbox_keygen(); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Retourne une clé de la taille attendue pour le chiffrement |
|
| 73 | - * |
|
| 74 | - * Notamment si on utilise un mot de passe comme clé, il faut le hacher |
|
| 75 | - * pour servir de clé à la taille correspondante. |
|
| 76 | - */ |
|
| 77 | - private static function deriveKeyFromPassword( |
|
| 78 | - #[\SensitiveParameter] |
|
| 79 | - string $password, |
|
| 80 | - string $salt |
|
| 81 | - ): string { |
|
| 82 | - if (strlen($password) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 83 | - return $password; |
|
| 84 | - } |
|
| 85 | - $key = sodium_crypto_pwhash( |
|
| 86 | - \SODIUM_CRYPTO_SECRETBOX_KEYBYTES, |
|
| 87 | - $password, |
|
| 88 | - $salt, |
|
| 89 | - \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, |
|
| 90 | - \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE |
|
| 91 | - ); |
|
| 92 | - sodium_memzero($password); |
|
| 71 | + /** |
|
| 72 | + * Retourne une clé de la taille attendue pour le chiffrement |
|
| 73 | + * |
|
| 74 | + * Notamment si on utilise un mot de passe comme clé, il faut le hacher |
|
| 75 | + * pour servir de clé à la taille correspondante. |
|
| 76 | + */ |
|
| 77 | + private static function deriveKeyFromPassword( |
|
| 78 | + #[\SensitiveParameter] |
|
| 79 | + string $password, |
|
| 80 | + string $salt |
|
| 81 | + ): string { |
|
| 82 | + if (strlen($password) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 83 | + return $password; |
|
| 84 | + } |
|
| 85 | + $key = sodium_crypto_pwhash( |
|
| 86 | + \SODIUM_CRYPTO_SECRETBOX_KEYBYTES, |
|
| 87 | + $password, |
|
| 88 | + $salt, |
|
| 89 | + \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, |
|
| 90 | + \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE |
|
| 91 | + ); |
|
| 92 | + sodium_memzero($password); |
|
| 93 | 93 | |
| 94 | - return $key; |
|
| 95 | - } |
|
| 94 | + return $key; |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
| 32 | 32 | $padded_message = sodium_pad($message, 16); |
| 33 | 33 | $encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key); |
| 34 | - $encoded = base64_encode($salt . $nonce . $encrypted); |
|
| 34 | + $encoded = base64_encode($salt.$nonce.$encrypted); |
|
| 35 | 35 | sodium_memzero($key); |
| 36 | 36 | sodium_memzero($nonce); |
| 37 | 37 | sodium_memzero($salt); |
@@ -48,14 +48,14 @@ discard block |
||
| 48 | 48 | $decoded = base64_decode($encoded); |
| 49 | 49 | $salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES); |
| 50 | 50 | $nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
| 51 | - $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 51 | + $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES +\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 52 | 52 | $key = self::deriveKeyFromPassword($key, $salt); |
| 53 | 53 | $padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key); |
| 54 | 54 | sodium_memzero($key); |
| 55 | 55 | sodium_memzero($nonce); |
| 56 | 56 | sodium_memzero($salt); |
| 57 | 57 | if ($padded_message === false) { |
| 58 | - spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG); |
|
| 58 | + spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer'._LOG_DEBUG); |
|
| 59 | 59 | return null; |
| 60 | 60 | } |
| 61 | 61 | $message = sodium_unpad($padded_message, 16); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @package SPIP\Core\Drapeaux\Edition |
| 31 | 31 | **/ |
| 32 | 32 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 33 | - return; |
|
| 33 | + return; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | |
@@ -45,46 +45,46 @@ discard block |
||
| 45 | 45 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 46 | 46 | **/ |
| 47 | 47 | function lire_tableau_edition() { |
| 48 | - $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 49 | - if (!$edition) { |
|
| 50 | - return []; |
|
| 51 | - } |
|
| 52 | - $changed = false; |
|
| 48 | + $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 49 | + if (!$edition) { |
|
| 50 | + return []; |
|
| 51 | + } |
|
| 52 | + $changed = false; |
|
| 53 | 53 | |
| 54 | - $bon_pour_le_service = time() - 3600; |
|
| 55 | - // parcourir le tableau et virer les vieux |
|
| 56 | - foreach ($edition as $objet => $data) { |
|
| 57 | - if (!is_array($data)) { |
|
| 58 | - unset($edition[$objet]); |
|
| 59 | - } // vieille version |
|
| 60 | - else { |
|
| 61 | - foreach ($data as $id => $tab) { |
|
| 62 | - if (!is_array($tab)) { |
|
| 63 | - unset($edition[$objet][$tab]); |
|
| 64 | - } // vieille version |
|
| 65 | - else { |
|
| 66 | - foreach ($tab as $n => $duo) { |
|
| 67 | - if (current($duo) < $bon_pour_le_service) { |
|
| 68 | - unset($edition[$objet][$id][$n]); |
|
| 69 | - $changed = true; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - if (!$edition[$objet][$id]) { |
|
| 74 | - unset($edition[$objet][$id]); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - if (!$edition[$objet]) { |
|
| 79 | - unset($edition[$objet]); |
|
| 80 | - } |
|
| 81 | - } |
|
| 54 | + $bon_pour_le_service = time() - 3600; |
|
| 55 | + // parcourir le tableau et virer les vieux |
|
| 56 | + foreach ($edition as $objet => $data) { |
|
| 57 | + if (!is_array($data)) { |
|
| 58 | + unset($edition[$objet]); |
|
| 59 | + } // vieille version |
|
| 60 | + else { |
|
| 61 | + foreach ($data as $id => $tab) { |
|
| 62 | + if (!is_array($tab)) { |
|
| 63 | + unset($edition[$objet][$tab]); |
|
| 64 | + } // vieille version |
|
| 65 | + else { |
|
| 66 | + foreach ($tab as $n => $duo) { |
|
| 67 | + if (current($duo) < $bon_pour_le_service) { |
|
| 68 | + unset($edition[$objet][$id][$n]); |
|
| 69 | + $changed = true; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + if (!$edition[$objet][$id]) { |
|
| 74 | + unset($edition[$objet][$id]); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + if (!$edition[$objet]) { |
|
| 79 | + unset($edition[$objet]); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - if ($changed) { |
|
| 84 | - ecrire_tableau_edition($edition); |
|
| 85 | - } |
|
| 83 | + if ($changed) { |
|
| 84 | + ecrire_tableau_edition($edition); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - return $edition; |
|
| 87 | + return $edition; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 98 | 98 | **/ |
| 99 | 99 | function ecrire_tableau_edition($edition) { |
| 100 | - ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 100 | + ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -117,22 +117,22 @@ discard block |
||
| 117 | 117 | * Type d'objet édité |
| 118 | 118 | */ |
| 119 | 119 | function signale_edition($id, $auteur, $type = 'article') { |
| 120 | - include_spip('base/objets'); |
|
| 121 | - include_spip('inc/filtres'); |
|
| 122 | - if (objet_info($type, 'editable') !== 'oui') { |
|
| 123 | - return; |
|
| 124 | - } |
|
| 120 | + include_spip('base/objets'); |
|
| 121 | + include_spip('inc/filtres'); |
|
| 122 | + if (objet_info($type, 'editable') !== 'oui') { |
|
| 123 | + return; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - $edition = lire_tableau_edition(); |
|
| 126 | + $edition = lire_tableau_edition(); |
|
| 127 | 127 | |
| 128 | - $nom = $auteur['nom'] ?? $GLOBALS['ip']; |
|
| 129 | - $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip']; |
|
| 128 | + $nom = $auteur['nom'] ?? $GLOBALS['ip']; |
|
| 129 | + $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip']; |
|
| 130 | 130 | |
| 131 | - if (!isset($edition[$type][$id]) or !is_array($edition[$type][$id])) { |
|
| 132 | - $edition[$type][$id] = []; |
|
| 133 | - } |
|
| 134 | - $edition[$type][$id][$id_a][$nom] = time(); |
|
| 135 | - ecrire_tableau_edition($edition); |
|
| 131 | + if (!isset($edition[$type][$id]) or !is_array($edition[$type][$id])) { |
|
| 132 | + $edition[$type][$id] = []; |
|
| 133 | + } |
|
| 134 | + $edition[$type][$id][$id_a][$nom] = time(); |
|
| 135 | + ecrire_tableau_edition($edition); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | function qui_edite($id, $type = 'article') { |
| 151 | 151 | |
| 152 | - $edition = lire_tableau_edition(); |
|
| 152 | + $edition = lire_tableau_edition(); |
|
| 153 | 153 | |
| 154 | - return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 154 | + return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -165,23 +165,23 @@ discard block |
||
| 165 | 165 | * Liste de tableaux `['nom_auteur_modif' => x|y|z, 'date_diff' => n]` |
| 166 | 166 | */ |
| 167 | 167 | function mention_qui_edite($id, $type = 'article'): array { |
| 168 | - $modif = qui_edite($id, $type); |
|
| 169 | - unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 168 | + $modif = qui_edite($id, $type); |
|
| 169 | + unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 170 | 170 | |
| 171 | - if ($modif) { |
|
| 172 | - $quand = 0; |
|
| 173 | - foreach ($modif as $duo) { |
|
| 174 | - $auteurs[] = typo(key($duo)); |
|
| 175 | - $quand = max($quand, current($duo)); |
|
| 176 | - } |
|
| 171 | + if ($modif) { |
|
| 172 | + $quand = 0; |
|
| 173 | + foreach ($modif as $duo) { |
|
| 174 | + $auteurs[] = typo(key($duo)); |
|
| 175 | + $quand = max($quand, current($duo)); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - // format lie a la chaine de langue 'avis_article_modifie' |
|
| 179 | - return [ |
|
| 180 | - 'nom_auteur_modif' => join(' | ', $auteurs), |
|
| 181 | - 'date_diff' => ceil((time() - $quand) / 60) |
|
| 182 | - ]; |
|
| 183 | - } |
|
| 184 | - return []; |
|
| 178 | + // format lie a la chaine de langue 'avis_article_modifie' |
|
| 179 | + return [ |
|
| 180 | + 'nom_auteur_modif' => join(' | ', $auteurs), |
|
| 181 | + 'date_diff' => ceil((time() - $quand) / 60) |
|
| 182 | + ]; |
|
| 183 | + } |
|
| 184 | + return []; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -195,25 +195,25 @@ discard block |
||
| 195 | 195 | * Liste de tableaux `['objet' => x, 'id_objet' => n]` |
| 196 | 196 | */ |
| 197 | 197 | function liste_drapeau_edition($id_auteur) { |
| 198 | - $edition = lire_tableau_edition(); |
|
| 199 | - $objets_ouverts = []; |
|
| 198 | + $edition = lire_tableau_edition(); |
|
| 199 | + $objets_ouverts = []; |
|
| 200 | 200 | |
| 201 | - foreach ($edition as $objet => $data) { |
|
| 202 | - foreach ($data as $id => $auteurs) { |
|
| 203 | - if ( |
|
| 204 | - isset($auteurs[$id_auteur]) |
|
| 205 | - and is_array($auteurs[$id_auteur]) // precaution |
|
| 206 | - and (array_pop($auteurs[$id_auteur]) > time() - 3600) |
|
| 207 | - ) { |
|
| 208 | - $objets_ouverts[] = [ |
|
| 209 | - 'objet' => $objet, |
|
| 210 | - 'id_objet' => $id, |
|
| 211 | - ]; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - } |
|
| 201 | + foreach ($edition as $objet => $data) { |
|
| 202 | + foreach ($data as $id => $auteurs) { |
|
| 203 | + if ( |
|
| 204 | + isset($auteurs[$id_auteur]) |
|
| 205 | + and is_array($auteurs[$id_auteur]) // precaution |
|
| 206 | + and (array_pop($auteurs[$id_auteur]) > time() - 3600) |
|
| 207 | + ) { |
|
| 208 | + $objets_ouverts[] = [ |
|
| 209 | + 'objet' => $objet, |
|
| 210 | + 'id_objet' => $id, |
|
| 211 | + ]; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - return $objets_ouverts; |
|
| 216 | + return $objets_ouverts; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -226,15 +226,15 @@ discard block |
||
| 226 | 226 | * @return void |
| 227 | 227 | */ |
| 228 | 228 | function debloquer_tous($id_auteur) { |
| 229 | - $edition = lire_tableau_edition(); |
|
| 230 | - foreach ($edition as $objet => $data) { |
|
| 231 | - foreach ($data as $id => $auteurs) { |
|
| 232 | - if (isset($auteurs[$id_auteur])) { |
|
| 233 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 234 | - ecrire_tableau_edition($edition); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 229 | + $edition = lire_tableau_edition(); |
|
| 230 | + foreach ($edition as $objet => $data) { |
|
| 231 | + foreach ($data as $id => $auteurs) { |
|
| 232 | + if (isset($auteurs[$id_auteur])) { |
|
| 233 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 234 | + ecrire_tableau_edition($edition); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -252,19 +252,19 @@ discard block |
||
| 252 | 252 | * @return void |
| 253 | 253 | */ |
| 254 | 254 | function debloquer_edition($id_auteur, $id_objet, $type = 'article') { |
| 255 | - $edition = lire_tableau_edition(); |
|
| 255 | + $edition = lire_tableau_edition(); |
|
| 256 | 256 | |
| 257 | - foreach ($edition as $objet => $data) { |
|
| 258 | - if ($objet == $type) { |
|
| 259 | - foreach ($data as $id => $auteurs) { |
|
| 260 | - if ( |
|
| 261 | - $id == $id_objet |
|
| 262 | - and isset($auteurs[$id_auteur]) |
|
| 263 | - ) { |
|
| 264 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 265 | - ecrire_tableau_edition($edition); |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 257 | + foreach ($edition as $objet => $data) { |
|
| 258 | + if ($objet == $type) { |
|
| 259 | + foreach ($data as $id => $auteurs) { |
|
| 260 | + if ( |
|
| 261 | + $id == $id_objet |
|
| 262 | + and isset($auteurs[$id_auteur]) |
|
| 263 | + ) { |
|
| 264 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 265 | + ecrire_tableau_edition($edition); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | } |
@@ -648,8 +648,7 @@ discard block |
||
| 648 | 648 | if (!$srcSize) { |
| 649 | 649 | $poids_img[$src] = filesize($src); |
| 650 | 650 | } |
| 651 | - } |
|
| 652 | - elseif (strpos($src, '<svg') !== false) { |
|
| 651 | + } elseif (strpos($src, '<svg') !== false) { |
|
| 653 | 652 | include_spip('inc/svg'); |
| 654 | 653 | if ($attrs = svg_lire_attributs($src)) { |
| 655 | 654 | [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
@@ -3507,8 +3506,7 @@ discard block |
||
| 3507 | 3506 | ) { |
| 3508 | 3507 | if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
| 3509 | 3508 | $img_file = $variante_svg_size; |
| 3510 | - } |
|
| 3511 | - else { |
|
| 3509 | + } else { |
|
| 3512 | 3510 | $img_file = $variante_svg_generique; |
| 3513 | 3511 | } |
| 3514 | 3512 | } |
@@ -3540,8 +3538,7 @@ discard block |
||
| 3540 | 3538 | } |
| 3541 | 3539 | if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
| 3542 | 3540 | $img_file = chemin_image($img); |
| 3543 | - } |
|
| 3544 | - else { |
|
| 3541 | + } else { |
|
| 3545 | 3542 | if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
| 3546 | 3543 | $img_file = http_img_variante_svg_si_possible($img_file); |
| 3547 | 3544 | } |
@@ -3571,11 +3568,9 @@ discard block |
||
| 3571 | 3568 | } |
| 3572 | 3569 | if ($alt === false) { |
| 3573 | 3570 | $alt = ''; |
| 3574 | - } |
|
| 3575 | - elseif ($alt or $alt === '') { |
|
| 3571 | + } elseif ($alt or $alt === '') { |
|
| 3576 | 3572 | $alt = " alt='" . attribut_html($alt) . "'"; |
| 3577 | - } |
|
| 3578 | - else { |
|
| 3573 | + } else { |
|
| 3579 | 3574 | $alt = " alt='" . attribut_html($title) . "'"; |
| 3580 | 3575 | } |
| 3581 | 3576 | return "<img src='" . attribut_html($img_file) . "'$alt" |
@@ -3702,13 +3697,11 @@ discard block |
||
| 3702 | 3697 | if (!is_null($class)) { |
| 3703 | 3698 | if (strlen($class)) { |
| 3704 | 3699 | $img = inserer_attribut($img, 'class', $class); |
| 3705 | - } |
|
| 3706 | - else { |
|
| 3700 | + } else { |
|
| 3707 | 3701 | $img = vider_attribut($img, 'class'); |
| 3708 | 3702 | } |
| 3709 | 3703 | } |
| 3710 | - } |
|
| 3711 | - else { |
|
| 3704 | + } else { |
|
| 3712 | 3705 | $img = http_img_pack( |
| 3713 | 3706 | $img, |
| 3714 | 3707 | $alt, |
@@ -3806,8 +3799,7 @@ discard block |
||
| 3806 | 3799 | if (!is_null($class)) { |
| 3807 | 3800 | if (strlen($class)) { |
| 3808 | 3801 | $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
| 3809 | - } |
|
| 3810 | - else { |
|
| 3802 | + } else { |
|
| 3811 | 3803 | $balise_svg = vider_attribut($balise_svg, 'class'); |
| 3812 | 3804 | } |
| 3813 | 3805 | } |
@@ -3819,8 +3811,7 @@ discard block |
||
| 3819 | 3811 | $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
| 3820 | 3812 | $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
| 3821 | 3813 | $balise_svg .= $title; |
| 3822 | - } |
|
| 3823 | - else { |
|
| 3814 | + } else { |
|
| 3824 | 3815 | $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
| 3825 | 3816 | } |
| 3826 | 3817 | |
@@ -5231,8 +5222,7 @@ discard block |
||
| 5231 | 5222 | // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
| 5232 | 5223 | if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
| 5233 | 5224 | $hash = md5($contexte_implicite['host'] . '::' . $cache); |
| 5234 | - } |
|
| 5235 | - else { |
|
| 5225 | + } else { |
|
| 5236 | 5226 | unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
| 5237 | 5227 | ksort($contexte); |
| 5238 | 5228 | $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @return string Fonction PHP correspondante du filtre |
| 43 | 43 | */ |
| 44 | 44 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 45 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | - return chercher_filtre($fonc, $default); |
|
| 45 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | + return chercher_filtre($fonc, $default); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return string Texte |
| 54 | 54 | **/ |
| 55 | 55 | function filtre_identite_dist($texte) { |
| 56 | - return $texte; |
|
| 56 | + return $texte; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -77,33 +77,33 @@ discard block |
||
| 77 | 77 | * Fonction PHP correspondante du filtre demandé |
| 78 | 78 | */ |
| 79 | 79 | function chercher_filtre($fonc, $default = null) { |
| 80 | - if (!$fonc) { |
|
| 81 | - return $default; |
|
| 82 | - } |
|
| 83 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | - // Foo::Bar |
|
| 85 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | - $f = chercher_filtre($nom); |
|
| 89 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | - if (!$f and $nom !== $fonc) { |
|
| 92 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $f; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - include_fichiers_fonctions(); |
|
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | - if (is_callable($f)) { |
|
| 102 | - return $f; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $default; |
|
| 80 | + if (!$fonc) { |
|
| 81 | + return $default; |
|
| 82 | + } |
|
| 83 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | + // Foo::Bar |
|
| 85 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | + $f = chercher_filtre($nom); |
|
| 89 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | + if (!$f and $nom !== $fonc) { |
|
| 92 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $f; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + include_fichiers_fonctions(); |
|
| 99 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | + if (is_callable($f)) { |
|
| 102 | + return $f; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $default; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -147,8 +147,8 @@ discard block |
||
| 147 | 147 | * Chaîne vide sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function appliquer_filtre($arg, $filtre) { |
| 150 | - $args = func_get_args(); |
|
| 151 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 150 | + $args = func_get_args(); |
|
| 151 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * Texte d'origine sinon |
| 174 | 174 | **/ |
| 175 | 175 | function appliquer_si_filtre($arg, $filtre) { |
| 176 | - $args = func_get_args(); |
|
| 177 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 176 | + $args = func_get_args(); |
|
| 177 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -190,12 +190,12 @@ discard block |
||
| 190 | 190 | * Version de SPIP |
| 191 | 191 | **/ |
| 192 | 192 | function spip_version() { |
| 193 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 194 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 195 | - $version .= " $vcs_version"; |
|
| 196 | - } |
|
| 193 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 194 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 195 | + $version .= " $vcs_version"; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - return $version; |
|
| 198 | + return $version; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -207,11 +207,11 @@ discard block |
||
| 207 | 207 | * @return string |
| 208 | 208 | */ |
| 209 | 209 | function header_silencieux($version): string { |
| 210 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 211 | - $version = ''; |
|
| 212 | - } |
|
| 210 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 211 | + $version = ''; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - return (string) $version; |
|
| 214 | + return (string) $version; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -224,19 +224,19 @@ discard block |
||
| 224 | 224 | * - string|null si $raw = false |
| 225 | 225 | */ |
| 226 | 226 | function version_vcs_courante($dir, $raw = false) { |
| 227 | - $desc = decrire_version_git($dir); |
|
| 228 | - if ($desc === null) { |
|
| 229 | - $desc = decrire_version_svn($dir); |
|
| 230 | - } |
|
| 231 | - if ($desc === null or $raw) { |
|
| 232 | - return $desc; |
|
| 233 | - } |
|
| 234 | - // affichage "GIT [master: abcdef]" |
|
| 235 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 236 | - if ($desc['branch']) { |
|
| 237 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 238 | - } |
|
| 239 | - return "{$desc['vcs']} [$commit]"; |
|
| 227 | + $desc = decrire_version_git($dir); |
|
| 228 | + if ($desc === null) { |
|
| 229 | + $desc = decrire_version_svn($dir); |
|
| 230 | + } |
|
| 231 | + if ($desc === null or $raw) { |
|
| 232 | + return $desc; |
|
| 233 | + } |
|
| 234 | + // affichage "GIT [master: abcdef]" |
|
| 235 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 236 | + if ($desc['branch']) { |
|
| 237 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 238 | + } |
|
| 239 | + return "{$desc['vcs']} [$commit]"; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -248,24 +248,24 @@ discard block |
||
| 248 | 248 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 249 | 249 | **/ |
| 250 | 250 | function decrire_version_git($dir) { |
| 251 | - if (!$dir) { |
|
| 252 | - $dir = '.'; |
|
| 253 | - } |
|
| 251 | + if (!$dir) { |
|
| 252 | + $dir = '.'; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - // version installee par GIT |
|
| 256 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 257 | - $currentHead = trim(substr($c, 4)); |
|
| 258 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 259 | - return [ |
|
| 260 | - 'vcs' => 'GIT', |
|
| 261 | - 'branch' => basename($currentHead), |
|
| 262 | - 'commit' => trim($hash), |
|
| 263 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 264 | - ]; |
|
| 265 | - } |
|
| 266 | - } |
|
| 255 | + // version installee par GIT |
|
| 256 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 257 | + $currentHead = trim(substr($c, 4)); |
|
| 258 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 259 | + return [ |
|
| 260 | + 'vcs' => 'GIT', |
|
| 261 | + 'branch' => basename($currentHead), |
|
| 262 | + 'commit' => trim($hash), |
|
| 263 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 264 | + ]; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - return null; |
|
| 268 | + return null; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | |
@@ -278,25 +278,25 @@ discard block |
||
| 278 | 278 | * array ['commit' => yy, 'date' => xx, 'author' => xx] sinon. |
| 279 | 279 | **/ |
| 280 | 280 | function decrire_version_svn($dir) { |
| 281 | - if (!$dir) { |
|
| 282 | - $dir = '.'; |
|
| 283 | - } |
|
| 284 | - // version installee par SVN |
|
| 285 | - if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 286 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 287 | - $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 288 | - if ($result) { |
|
| 289 | - $row = $result->fetchArray(); |
|
| 290 | - if ($row['changed_revision'] != '') { |
|
| 291 | - return [ |
|
| 292 | - 'vcs' => 'SVN', |
|
| 293 | - 'branch' => '', |
|
| 294 | - 'commit' => $row['changed_revision'], |
|
| 295 | - ]; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - return null; |
|
| 281 | + if (!$dir) { |
|
| 282 | + $dir = '.'; |
|
| 283 | + } |
|
| 284 | + // version installee par SVN |
|
| 285 | + if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 286 | + $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 287 | + $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 288 | + if ($result) { |
|
| 289 | + $row = $result->fetchArray(); |
|
| 290 | + if ($row['changed_revision'] != '') { |
|
| 291 | + return [ |
|
| 292 | + 'vcs' => 'SVN', |
|
| 293 | + 'branch' => '', |
|
| 294 | + 'commit' => $row['changed_revision'], |
|
| 295 | + ]; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + return null; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -343,18 +343,18 @@ discard block |
||
| 343 | 343 | * Code HTML retourné par le filtre |
| 344 | 344 | **/ |
| 345 | 345 | function filtrer($filtre) { |
| 346 | - $tous = func_get_args(); |
|
| 347 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 348 | - return image_filtrer($tous); |
|
| 349 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 350 | - array_shift($tous); |
|
| 351 | - return $f(...$tous); |
|
| 352 | - } else { |
|
| 353 | - // le filtre n'existe pas, on provoque une erreur |
|
| 354 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 355 | - erreur_squelette($msg); |
|
| 356 | - return ''; |
|
| 357 | - } |
|
| 346 | + $tous = func_get_args(); |
|
| 347 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 348 | + return image_filtrer($tous); |
|
| 349 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 350 | + array_shift($tous); |
|
| 351 | + return $f(...$tous); |
|
| 352 | + } else { |
|
| 353 | + // le filtre n'existe pas, on provoque une erreur |
|
| 354 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 355 | + erreur_squelette($msg); |
|
| 356 | + return ''; |
|
| 357 | + } |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -371,11 +371,11 @@ discard block |
||
| 371 | 371 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 372 | 372 | */ |
| 373 | 373 | function trouver_filtre_matrice($filtre) { |
| 374 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 375 | - find_in_path($f, '', true); |
|
| 376 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 377 | - } |
|
| 378 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 374 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 375 | + find_in_path($f, '', true); |
|
| 376 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 377 | + } |
|
| 378 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | |
@@ -403,8 +403,8 @@ discard block |
||
| 403 | 403 | * @return mixed |
| 404 | 404 | */ |
| 405 | 405 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 406 | - $Pile['vars'][$key] = $val; |
|
| 407 | - return $continue ? $val : ''; |
|
| 406 | + $Pile['vars'][$key] = $val; |
|
| 407 | + return $continue ? $val : ''; |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -430,8 +430,8 @@ discard block |
||
| 430 | 430 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 431 | 431 | */ |
| 432 | 432 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 433 | - $Pile[0][$key] = $val; |
|
| 434 | - return $continue ? $val : ''; |
|
| 433 | + $Pile[0][$key] = $val; |
|
| 434 | + return $continue ? $val : ''; |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -440,8 +440,8 @@ discard block |
||
| 440 | 440 | * @return string |
| 441 | 441 | */ |
| 442 | 442 | function filtre_sanitize_env(&$Pile, $keys) { |
| 443 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 444 | - return ''; |
|
| 443 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 444 | + return ''; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | |
@@ -464,18 +464,18 @@ discard block |
||
| 464 | 464 | * @return mixed Retourne la valeur (sans la modifier). |
| 465 | 465 | */ |
| 466 | 466 | function filtre_debug($val, $key = null) { |
| 467 | - $debug = ( |
|
| 468 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 469 | - ) . var_export($val, true); |
|
| 467 | + $debug = ( |
|
| 468 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 469 | + ) . var_export($val, true); |
|
| 470 | 470 | |
| 471 | - include_spip('inc/autoriser'); |
|
| 472 | - if (autoriser('webmestre')) { |
|
| 473 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 474 | - } |
|
| 471 | + include_spip('inc/autoriser'); |
|
| 472 | + if (autoriser('webmestre')) { |
|
| 473 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 474 | + } |
|
| 475 | 475 | |
| 476 | - spip_log($debug, 'debug'); |
|
| 476 | + spip_log($debug, 'debug'); |
|
| 477 | 477 | |
| 478 | - return $val; |
|
| 478 | + return $val; |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | |
@@ -505,84 +505,84 @@ discard block |
||
| 505 | 505 | * Texte qui a reçu les filtres |
| 506 | 506 | **/ |
| 507 | 507 | function image_filtrer($args) { |
| 508 | - $filtre = array_shift($args); # enlever $filtre |
|
| 509 | - $texte = array_shift($args); |
|
| 510 | - if ($texte === null || !strlen($texte)) { |
|
| 511 | - return ''; |
|
| 512 | - } |
|
| 513 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 514 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 515 | - // Cas du nom de fichier local |
|
| 516 | - $is_file = trim($texte); |
|
| 517 | - if ( |
|
| 518 | - strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 519 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 520 | - or strpos($is_file, '/') === 0 |
|
| 521 | - ) { |
|
| 522 | - $is_file = false; |
|
| 523 | - } |
|
| 524 | - if ($is_file) { |
|
| 525 | - $is_local_file = function ($path) { |
|
| 526 | - if (strpos($path, '?') !== false) { |
|
| 527 | - $path = supprimer_timestamp($path); |
|
| 528 | - // remove ?24px added by find_in_theme on .svg files |
|
| 529 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 530 | - } |
|
| 531 | - return file_exists($path); |
|
| 532 | - }; |
|
| 533 | - if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 534 | - $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 535 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 536 | - return $res; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 541 | - if ( |
|
| 542 | - preg_match_all( |
|
| 543 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 544 | - $texte, |
|
| 545 | - $tags, |
|
| 546 | - PREG_SET_ORDER |
|
| 547 | - ) |
|
| 548 | - ) { |
|
| 549 | - foreach ($tags as $tag) { |
|
| 550 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 551 | - if ( |
|
| 552 | - !$class or |
|
| 553 | - (strpos($class, 'filtre_inactif') === false |
|
| 554 | - // compat historique a virer en 3.2 |
|
| 555 | - and strpos($class, 'no_image_filtrer') === false) |
|
| 556 | - ) { |
|
| 557 | - if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 558 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 559 | - if ($tag[1]) { |
|
| 560 | - $w = extraire_attribut($reduit, 'width'); |
|
| 561 | - if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 562 | - $w = $regs[1]; |
|
| 563 | - } |
|
| 564 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 565 | - $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 566 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 567 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - // traiter aussi un eventuel mouseover |
|
| 571 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 572 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 573 | - $srcover = $match[1]; |
|
| 574 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 575 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 576 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 585 | - return $texte; |
|
| 508 | + $filtre = array_shift($args); # enlever $filtre |
|
| 509 | + $texte = array_shift($args); |
|
| 510 | + if ($texte === null || !strlen($texte)) { |
|
| 511 | + return ''; |
|
| 512 | + } |
|
| 513 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 514 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 515 | + // Cas du nom de fichier local |
|
| 516 | + $is_file = trim($texte); |
|
| 517 | + if ( |
|
| 518 | + strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 519 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 520 | + or strpos($is_file, '/') === 0 |
|
| 521 | + ) { |
|
| 522 | + $is_file = false; |
|
| 523 | + } |
|
| 524 | + if ($is_file) { |
|
| 525 | + $is_local_file = function ($path) { |
|
| 526 | + if (strpos($path, '?') !== false) { |
|
| 527 | + $path = supprimer_timestamp($path); |
|
| 528 | + // remove ?24px added by find_in_theme on .svg files |
|
| 529 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 530 | + } |
|
| 531 | + return file_exists($path); |
|
| 532 | + }; |
|
| 533 | + if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 534 | + $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 535 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 536 | + return $res; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 541 | + if ( |
|
| 542 | + preg_match_all( |
|
| 543 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 544 | + $texte, |
|
| 545 | + $tags, |
|
| 546 | + PREG_SET_ORDER |
|
| 547 | + ) |
|
| 548 | + ) { |
|
| 549 | + foreach ($tags as $tag) { |
|
| 550 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 551 | + if ( |
|
| 552 | + !$class or |
|
| 553 | + (strpos($class, 'filtre_inactif') === false |
|
| 554 | + // compat historique a virer en 3.2 |
|
| 555 | + and strpos($class, 'no_image_filtrer') === false) |
|
| 556 | + ) { |
|
| 557 | + if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 558 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 559 | + if ($tag[1]) { |
|
| 560 | + $w = extraire_attribut($reduit, 'width'); |
|
| 561 | + if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 562 | + $w = $regs[1]; |
|
| 563 | + } |
|
| 564 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 565 | + $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 566 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 567 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + // traiter aussi un eventuel mouseover |
|
| 571 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 572 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 573 | + $srcover = $match[1]; |
|
| 574 | + $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 575 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 576 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 585 | + return $texte; |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | /** |
@@ -599,91 +599,91 @@ discard block |
||
| 599 | 599 | **/ |
| 600 | 600 | function infos_image($img, $force_refresh = false) { |
| 601 | 601 | |
| 602 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 603 | - $srcWidth = 0; |
|
| 604 | - $srcHeight = 0; |
|
| 605 | - $srcSize = null; |
|
| 606 | - |
|
| 607 | - $src = extraire_attribut($img, 'src'); |
|
| 608 | - |
|
| 609 | - if (!$src) { |
|
| 610 | - $src = $img; |
|
| 611 | - } else { |
|
| 612 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 613 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 617 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 618 | - if (tester_url_absolue($src)) { |
|
| 619 | - include_spip('inc/distant'); |
|
| 620 | - $fichier = copie_locale($src); |
|
| 621 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 622 | - } |
|
| 623 | - if (($p = strpos($src, '?')) !== false) { |
|
| 624 | - $src = substr($src, 0, $p); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - $imagesize = false; |
|
| 628 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 629 | - $srcWidth = $largeur_img[$src]; |
|
| 630 | - } |
|
| 631 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 632 | - $srcHeight = $hauteur_img[$src]; |
|
| 633 | - } |
|
| 634 | - if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 635 | - $srcSize = $poids_img[$src]; |
|
| 636 | - } |
|
| 637 | - if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 638 | - if ( |
|
| 639 | - file_exists($src) |
|
| 640 | - and $imagesize = spip_getimagesize($src) |
|
| 641 | - ) { |
|
| 642 | - if (!$srcWidth) { |
|
| 643 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 644 | - } |
|
| 645 | - if (!$srcHeight) { |
|
| 646 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 647 | - } |
|
| 648 | - if (!$srcSize) { |
|
| 649 | - $poids_img[$src] = filesize($src); |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - elseif (strpos($src, '<svg') !== false) { |
|
| 653 | - include_spip('inc/svg'); |
|
| 654 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 655 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 656 | - if (!$srcWidth) { |
|
| 657 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 658 | - } |
|
| 659 | - if (!$srcHeight) { |
|
| 660 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 661 | - } |
|
| 662 | - if (!$srcSize) { |
|
| 663 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 664 | - } |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 668 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 669 | - elseif ( |
|
| 670 | - @file_exists($f = "$src.src") |
|
| 671 | - and lire_fichier($f, $valeurs) |
|
| 672 | - and $valeurs = unserialize($valeurs) |
|
| 673 | - ) { |
|
| 674 | - if (!$srcWidth) { |
|
| 675 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 676 | - } |
|
| 677 | - if (!$srcHeight) { |
|
| 678 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 679 | - } |
|
| 680 | - if (!$srcSize) { |
|
| 681 | - $poids_img[$src] = $srcSize = 0; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 602 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 603 | + $srcWidth = 0; |
|
| 604 | + $srcHeight = 0; |
|
| 605 | + $srcSize = null; |
|
| 606 | + |
|
| 607 | + $src = extraire_attribut($img, 'src'); |
|
| 608 | + |
|
| 609 | + if (!$src) { |
|
| 610 | + $src = $img; |
|
| 611 | + } else { |
|
| 612 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 613 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 617 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 618 | + if (tester_url_absolue($src)) { |
|
| 619 | + include_spip('inc/distant'); |
|
| 620 | + $fichier = copie_locale($src); |
|
| 621 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 622 | + } |
|
| 623 | + if (($p = strpos($src, '?')) !== false) { |
|
| 624 | + $src = substr($src, 0, $p); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + $imagesize = false; |
|
| 628 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 629 | + $srcWidth = $largeur_img[$src]; |
|
| 630 | + } |
|
| 631 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 632 | + $srcHeight = $hauteur_img[$src]; |
|
| 633 | + } |
|
| 634 | + if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 635 | + $srcSize = $poids_img[$src]; |
|
| 636 | + } |
|
| 637 | + if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 638 | + if ( |
|
| 639 | + file_exists($src) |
|
| 640 | + and $imagesize = spip_getimagesize($src) |
|
| 641 | + ) { |
|
| 642 | + if (!$srcWidth) { |
|
| 643 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 644 | + } |
|
| 645 | + if (!$srcHeight) { |
|
| 646 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 647 | + } |
|
| 648 | + if (!$srcSize) { |
|
| 649 | + $poids_img[$src] = filesize($src); |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + elseif (strpos($src, '<svg') !== false) { |
|
| 653 | + include_spip('inc/svg'); |
|
| 654 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 655 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 656 | + if (!$srcWidth) { |
|
| 657 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 658 | + } |
|
| 659 | + if (!$srcHeight) { |
|
| 660 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 661 | + } |
|
| 662 | + if (!$srcSize) { |
|
| 663 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 664 | + } |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 668 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 669 | + elseif ( |
|
| 670 | + @file_exists($f = "$src.src") |
|
| 671 | + and lire_fichier($f, $valeurs) |
|
| 672 | + and $valeurs = unserialize($valeurs) |
|
| 673 | + ) { |
|
| 674 | + if (!$srcWidth) { |
|
| 675 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 676 | + } |
|
| 677 | + if (!$srcHeight) { |
|
| 678 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 679 | + } |
|
| 680 | + if (!$srcSize) { |
|
| 681 | + $poids_img[$src] = $srcSize = 0; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | /** |
@@ -699,13 +699,13 @@ discard block |
||
| 699 | 699 | * poids |
| 700 | 700 | **/ |
| 701 | 701 | function poids_image($img, $force_refresh = false) { |
| 702 | - $infos = infos_image($img, $force_refresh); |
|
| 703 | - return $infos['poids']; |
|
| 702 | + $infos = infos_image($img, $force_refresh); |
|
| 703 | + return $infos['poids']; |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | function taille_image($img, $force_refresh = false) { |
| 707 | - $infos = infos_image($img, $force_refresh); |
|
| 708 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 707 | + $infos = infos_image($img, $force_refresh); |
|
| 708 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -722,12 +722,12 @@ discard block |
||
| 722 | 722 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 723 | 723 | **/ |
| 724 | 724 | function largeur($img) { |
| 725 | - if (!$img) { |
|
| 726 | - return; |
|
| 727 | - } |
|
| 728 | - [$h, $l] = taille_image($img); |
|
| 725 | + if (!$img) { |
|
| 726 | + return; |
|
| 727 | + } |
|
| 728 | + [$h, $l] = taille_image($img); |
|
| 729 | 729 | |
| 730 | - return $l; |
|
| 730 | + return $l; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -744,12 +744,12 @@ discard block |
||
| 744 | 744 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 745 | 745 | **/ |
| 746 | 746 | function hauteur($img) { |
| 747 | - if (!$img) { |
|
| 748 | - return; |
|
| 749 | - } |
|
| 750 | - [$h, $l] = taille_image($img); |
|
| 747 | + if (!$img) { |
|
| 748 | + return; |
|
| 749 | + } |
|
| 750 | + [$h, $l] = taille_image($img); |
|
| 751 | 751 | |
| 752 | - return $h; |
|
| 752 | + return $h; |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | |
@@ -769,11 +769,11 @@ discard block |
||
| 769 | 769 | * @return string |
| 770 | 770 | **/ |
| 771 | 771 | function corriger_entites_html($texte) { |
| 772 | - if (strpos($texte, '&') === false) { |
|
| 773 | - return $texte; |
|
| 774 | - } |
|
| 772 | + if (strpos($texte, '&') === false) { |
|
| 773 | + return $texte; |
|
| 774 | + } |
|
| 775 | 775 | |
| 776 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 776 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | /** |
@@ -788,11 +788,11 @@ discard block |
||
| 788 | 788 | * @return string |
| 789 | 789 | **/ |
| 790 | 790 | function corriger_toutes_entites_html($texte) { |
| 791 | - if (strpos($texte, '&') === false) { |
|
| 792 | - return $texte; |
|
| 793 | - } |
|
| 791 | + if (strpos($texte, '&') === false) { |
|
| 792 | + return $texte; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 795 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | * @return string |
| 803 | 803 | **/ |
| 804 | 804 | function proteger_amp($texte) { |
| 805 | - return str_replace('&', '&', $texte); |
|
| 805 | + return str_replace('&', '&', $texte); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | |
@@ -833,21 +833,21 @@ discard block |
||
| 833 | 833 | * @return mixed|string |
| 834 | 834 | */ |
| 835 | 835 | function entites_html($texte, $tout = false, $quote = true) { |
| 836 | - if ( |
|
| 837 | - !is_string($texte) or !$texte |
|
| 838 | - or strpbrk($texte, "&\"'<>") == false |
|
| 839 | - ) { |
|
| 840 | - return $texte; |
|
| 841 | - } |
|
| 842 | - include_spip('inc/texte'); |
|
| 843 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 844 | - $flags |= ENT_HTML401; |
|
| 845 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 846 | - if ($tout) { |
|
| 847 | - return corriger_toutes_entites_html($texte); |
|
| 848 | - } else { |
|
| 849 | - return corriger_entites_html($texte); |
|
| 850 | - } |
|
| 836 | + if ( |
|
| 837 | + !is_string($texte) or !$texte |
|
| 838 | + or strpbrk($texte, "&\"'<>") == false |
|
| 839 | + ) { |
|
| 840 | + return $texte; |
|
| 841 | + } |
|
| 842 | + include_spip('inc/texte'); |
|
| 843 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 844 | + $flags |= ENT_HTML401; |
|
| 845 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 846 | + if ($tout) { |
|
| 847 | + return corriger_toutes_entites_html($texte); |
|
| 848 | + } else { |
|
| 849 | + return corriger_entites_html($texte); |
|
| 850 | + } |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | /** |
@@ -866,38 +866,38 @@ discard block |
||
| 866 | 866 | * Texte converti |
| 867 | 867 | **/ |
| 868 | 868 | function filtrer_entites(?string $texte): string { |
| 869 | - $texte ??= ''; |
|
| 870 | - if (strpos($texte, '&') === false) { |
|
| 871 | - return $texte; |
|
| 872 | - } |
|
| 873 | - // filtrer |
|
| 874 | - $texte = html2unicode($texte); |
|
| 875 | - // remettre le tout dans le charset cible |
|
| 876 | - $texte = unicode2charset($texte); |
|
| 877 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 878 | - // (on le faisait deja avec un ") |
|
| 879 | - if (strpos($texte, '&#') !== false) { |
|
| 880 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 881 | - } |
|
| 869 | + $texte ??= ''; |
|
| 870 | + if (strpos($texte, '&') === false) { |
|
| 871 | + return $texte; |
|
| 872 | + } |
|
| 873 | + // filtrer |
|
| 874 | + $texte = html2unicode($texte); |
|
| 875 | + // remettre le tout dans le charset cible |
|
| 876 | + $texte = unicode2charset($texte); |
|
| 877 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 878 | + // (on le faisait deja avec un ") |
|
| 879 | + if (strpos($texte, '&#') !== false) { |
|
| 880 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 881 | + } |
|
| 882 | 882 | |
| 883 | - return $texte; |
|
| 883 | + return $texte; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | |
| 887 | 887 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 888 | - /** |
|
| 889 | - * Version sécurisée de filtrer_entites |
|
| 890 | - * |
|
| 891 | - * @uses interdire_scripts() |
|
| 892 | - * @uses filtrer_entites() |
|
| 893 | - * |
|
| 894 | - * @param string $t |
|
| 895 | - * @return string |
|
| 896 | - */ |
|
| 897 | - function filtre_filtrer_entites_dist($t) { |
|
| 898 | - include_spip('inc/texte'); |
|
| 899 | - return interdire_scripts(filtrer_entites($t)); |
|
| 900 | - } |
|
| 888 | + /** |
|
| 889 | + * Version sécurisée de filtrer_entites |
|
| 890 | + * |
|
| 891 | + * @uses interdire_scripts() |
|
| 892 | + * @uses filtrer_entites() |
|
| 893 | + * |
|
| 894 | + * @param string $t |
|
| 895 | + * @return string |
|
| 896 | + */ |
|
| 897 | + function filtre_filtrer_entites_dist($t) { |
|
| 898 | + include_spip('inc/texte'); |
|
| 899 | + return interdire_scripts(filtrer_entites($t)); |
|
| 900 | + } |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | |
@@ -912,18 +912,18 @@ discard block |
||
| 912 | 912 | * @return string|array |
| 913 | 913 | **/ |
| 914 | 914 | function supprimer_caracteres_illegaux($texte) { |
| 915 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 916 | - static $to = null; |
|
| 915 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 916 | + static $to = null; |
|
| 917 | 917 | |
| 918 | - if (is_array($texte)) { |
|
| 919 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 920 | - } |
|
| 918 | + if (is_array($texte)) { |
|
| 919 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 920 | + } |
|
| 921 | 921 | |
| 922 | - if (!$to) { |
|
| 923 | - $to = str_repeat('-', strlen($from)); |
|
| 924 | - } |
|
| 922 | + if (!$to) { |
|
| 923 | + $to = str_repeat('-', strlen($from)); |
|
| 924 | + } |
|
| 925 | 925 | |
| 926 | - return strtr($texte, $from, $to); |
|
| 926 | + return strtr($texte, $from, $to); |
|
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | /** |
@@ -935,10 +935,10 @@ discard block |
||
| 935 | 935 | * @return string|array |
| 936 | 936 | **/ |
| 937 | 937 | function corriger_caracteres($texte) { |
| 938 | - $texte = corriger_caracteres_windows($texte); |
|
| 939 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 938 | + $texte = corriger_caracteres_windows($texte); |
|
| 939 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 940 | 940 | |
| 941 | - return $texte; |
|
| 941 | + return $texte; |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | /** |
@@ -955,44 +955,44 @@ discard block |
||
| 955 | 955 | * Texte encodé pour XML |
| 956 | 956 | */ |
| 957 | 957 | function texte_backend(string $texte): string { |
| 958 | - if ($texte === '') { |
|
| 959 | - return ''; |
|
| 960 | - } |
|
| 958 | + if ($texte === '') { |
|
| 959 | + return ''; |
|
| 960 | + } |
|
| 961 | 961 | |
| 962 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 962 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 963 | 963 | |
| 964 | - // si on a des liens ou des images, les passer en absolu |
|
| 965 | - $texte = liens_absolus($texte); |
|
| 964 | + // si on a des liens ou des images, les passer en absolu |
|
| 965 | + $texte = liens_absolus($texte); |
|
| 966 | 966 | |
| 967 | - // echapper les tags > < |
|
| 968 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 967 | + // echapper les tags > < |
|
| 968 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 969 | 969 | |
| 970 | - // importer les é |
|
| 971 | - $texte = filtrer_entites($texte); |
|
| 970 | + // importer les é |
|
| 971 | + $texte = filtrer_entites($texte); |
|
| 972 | 972 | |
| 973 | - // " -> " et tout ce genre de choses |
|
| 974 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 975 | - $texte = str_replace(' ', ' ', $texte); |
|
| 976 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 977 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 978 | - $texte = entites_html($texte, false, false); |
|
| 979 | - // mais bien echapper les double quotes ! |
|
| 980 | - $texte = str_replace('"', '"', $texte); |
|
| 973 | + // " -> " et tout ce genre de choses |
|
| 974 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 975 | + $texte = str_replace(' ', ' ', $texte); |
|
| 976 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 977 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 978 | + $texte = entites_html($texte, false, false); |
|
| 979 | + // mais bien echapper les double quotes ! |
|
| 980 | + $texte = str_replace('"', '"', $texte); |
|
| 981 | 981 | |
| 982 | - // verifier le charset |
|
| 983 | - $texte = charset2unicode($texte); |
|
| 982 | + // verifier le charset |
|
| 983 | + $texte = charset2unicode($texte); |
|
| 984 | 984 | |
| 985 | - // Caracteres problematiques en iso-latin 1 |
|
| 986 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 987 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 988 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 989 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 990 | - } |
|
| 985 | + // Caracteres problematiques en iso-latin 1 |
|
| 986 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 987 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 988 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 989 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 990 | + } |
|
| 991 | 991 | |
| 992 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 993 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 994 | - // ==> on les remplace par l'entite HTML |
|
| 995 | - return str_replace($apostrophe, "'", $texte); |
|
| 992 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 993 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 994 | + // ==> on les remplace par l'entite HTML |
|
| 995 | + return str_replace($apostrophe, "'", $texte); |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | /** |
@@ -1009,7 +1009,7 @@ discard block |
||
| 1009 | 1009 | * Texte encodé et quote pour XML |
| 1010 | 1010 | */ |
| 1011 | 1011 | function texte_backendq(string $texte): string { |
| 1012 | - return addslashes(texte_backend($texte)); |
|
| 1012 | + return addslashes(texte_backend($texte)); |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | |
@@ -1031,14 +1031,14 @@ discard block |
||
| 1031 | 1031 | * Texte sans son numéro éventuel |
| 1032 | 1032 | **/ |
| 1033 | 1033 | function supprimer_numero(?string $texte): string { |
| 1034 | - if ($texte === null) { |
|
| 1035 | - return ''; |
|
| 1036 | - } |
|
| 1037 | - return preg_replace( |
|
| 1038 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1039 | - '', |
|
| 1040 | - $texte |
|
| 1041 | - ); |
|
| 1034 | + if ($texte === null) { |
|
| 1035 | + return ''; |
|
| 1036 | + } |
|
| 1037 | + return preg_replace( |
|
| 1038 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1039 | + '', |
|
| 1040 | + $texte |
|
| 1041 | + ); |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | /** |
@@ -1061,18 +1061,18 @@ discard block |
||
| 1061 | 1061 | * Numéro de titre, sinon chaîne vide |
| 1062 | 1062 | **/ |
| 1063 | 1063 | function recuperer_numero(?string $texte): string { |
| 1064 | - if ( |
|
| 1065 | - $texte and |
|
| 1066 | - preg_match( |
|
| 1067 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1068 | - $texte, |
|
| 1069 | - $regs |
|
| 1070 | - ) |
|
| 1071 | - ) { |
|
| 1072 | - return strval($regs[1]); |
|
| 1073 | - } else { |
|
| 1074 | - return ''; |
|
| 1075 | - } |
|
| 1064 | + if ( |
|
| 1065 | + $texte and |
|
| 1066 | + preg_match( |
|
| 1067 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1068 | + $texte, |
|
| 1069 | + $regs |
|
| 1070 | + ) |
|
| 1071 | + ) { |
|
| 1072 | + return strval($regs[1]); |
|
| 1073 | + } else { |
|
| 1074 | + return ''; |
|
| 1075 | + } |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | /** |
@@ -1099,16 +1099,16 @@ discard block |
||
| 1099 | 1099 | * Texte ou tableau de textes converti |
| 1100 | 1100 | **/ |
| 1101 | 1101 | function supprimer_tags($texte, $rempl = '') { |
| 1102 | - if ($texte === null) { |
|
| 1103 | - return ''; |
|
| 1104 | - } |
|
| 1105 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1106 | - // ne pas oublier un < final non ferme car coupe |
|
| 1107 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1108 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1109 | - $texte = str_replace('<', '<', $texte); |
|
| 1102 | + if ($texte === null) { |
|
| 1103 | + return ''; |
|
| 1104 | + } |
|
| 1105 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1106 | + // ne pas oublier un < final non ferme car coupe |
|
| 1107 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1108 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1109 | + $texte = str_replace('<', '<', $texte); |
|
| 1110 | 1110 | |
| 1111 | - return $texte; |
|
| 1111 | + return $texte; |
|
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | /** |
@@ -1131,9 +1131,9 @@ discard block |
||
| 1131 | 1131 | * Texte converti |
| 1132 | 1132 | **/ |
| 1133 | 1133 | function echapper_tags($texte, $rempl = '') { |
| 1134 | - $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1134 | + $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1135 | 1135 | |
| 1136 | - return $texte; |
|
| 1136 | + return $texte; |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | /** |
@@ -1154,18 +1154,18 @@ discard block |
||
| 1154 | 1154 | * Texte converti |
| 1155 | 1155 | **/ |
| 1156 | 1156 | function textebrut($texte) { |
| 1157 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1158 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1159 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1160 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1161 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1162 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1163 | - $texte = supprimer_tags($texte); |
|
| 1164 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1165 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1166 | - $texte = str_replace('’', "'", $texte); |
|
| 1157 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1158 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1159 | + $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1160 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1161 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1162 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1163 | + $texte = supprimer_tags($texte); |
|
| 1164 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1165 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1166 | + $texte = str_replace('’', "'", $texte); |
|
| 1167 | 1167 | |
| 1168 | - return $texte; |
|
| 1168 | + return $texte; |
|
| 1169 | 1169 | } |
| 1170 | 1170 | |
| 1171 | 1171 | |
@@ -1181,23 +1181,23 @@ discard block |
||
| 1181 | 1181 | * Texte avec liens ouvrants |
| 1182 | 1182 | **/ |
| 1183 | 1183 | function liens_ouvrants($texte) { |
| 1184 | - if ( |
|
| 1185 | - preg_match_all( |
|
| 1186 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1187 | - $texte, |
|
| 1188 | - $liens, |
|
| 1189 | - PREG_PATTERN_ORDER |
|
| 1190 | - ) |
|
| 1191 | - ) { |
|
| 1192 | - foreach ($liens[0] as $a) { |
|
| 1193 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1194 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1195 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1196 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1197 | - } |
|
| 1198 | - } |
|
| 1199 | - |
|
| 1200 | - return $texte; |
|
| 1184 | + if ( |
|
| 1185 | + preg_match_all( |
|
| 1186 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1187 | + $texte, |
|
| 1188 | + $liens, |
|
| 1189 | + PREG_PATTERN_ORDER |
|
| 1190 | + ) |
|
| 1191 | + ) { |
|
| 1192 | + foreach ($liens[0] as $a) { |
|
| 1193 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1194 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1195 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1196 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1197 | + } |
|
| 1198 | + } |
|
| 1199 | + |
|
| 1200 | + return $texte; |
|
| 1201 | 1201 | } |
| 1202 | 1202 | |
| 1203 | 1203 | /** |
@@ -1207,22 +1207,22 @@ discard block |
||
| 1207 | 1207 | * @return string |
| 1208 | 1208 | */ |
| 1209 | 1209 | function liens_nofollow($texte) { |
| 1210 | - if (stripos($texte, '<a') === false) { |
|
| 1211 | - return $texte; |
|
| 1212 | - } |
|
| 1210 | + if (stripos($texte, '<a') === false) { |
|
| 1211 | + return $texte; |
|
| 1212 | + } |
|
| 1213 | 1213 | |
| 1214 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1215 | - foreach ($regs[0] as $a) { |
|
| 1216 | - $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1217 | - if (strpos($rel, 'nofollow') === false) { |
|
| 1218 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1219 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1220 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1221 | - } |
|
| 1222 | - } |
|
| 1223 | - } |
|
| 1214 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1215 | + foreach ($regs[0] as $a) { |
|
| 1216 | + $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1217 | + if (strpos($rel, 'nofollow') === false) { |
|
| 1218 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1219 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1220 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1221 | + } |
|
| 1222 | + } |
|
| 1223 | + } |
|
| 1224 | 1224 | |
| 1225 | - return $texte; |
|
| 1225 | + return $texte; |
|
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | /** |
@@ -1241,12 +1241,12 @@ discard block |
||
| 1241 | 1241 | * Texte sans paraghaphes |
| 1242 | 1242 | **/ |
| 1243 | 1243 | function PtoBR($texte) { |
| 1244 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1245 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1246 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1247 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1244 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1245 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1246 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1247 | + $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1248 | 1248 | |
| 1249 | - return $texte; |
|
| 1249 | + return $texte; |
|
| 1250 | 1250 | } |
| 1251 | 1251 | |
| 1252 | 1252 | |
@@ -1271,14 +1271,14 @@ discard block |
||
| 1271 | 1271 | * @return string Texte encadré du style CSS |
| 1272 | 1272 | */ |
| 1273 | 1273 | function lignes_longues($texte) { |
| 1274 | - if (!strlen(trim($texte))) { |
|
| 1275 | - return $texte; |
|
| 1276 | - } |
|
| 1277 | - include_spip('inc/texte'); |
|
| 1278 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1279 | - 'div' : 'span'; |
|
| 1274 | + if (!strlen(trim($texte))) { |
|
| 1275 | + return $texte; |
|
| 1276 | + } |
|
| 1277 | + include_spip('inc/texte'); |
|
| 1278 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1279 | + 'div' : 'span'; |
|
| 1280 | 1280 | |
| 1281 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1281 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | 1284 | /** |
@@ -1297,30 +1297,30 @@ discard block |
||
| 1297 | 1297 | * @return string Texte en majuscule |
| 1298 | 1298 | */ |
| 1299 | 1299 | function majuscules($texte) { |
| 1300 | - if (!strlen($texte)) { |
|
| 1301 | - return ''; |
|
| 1302 | - } |
|
| 1300 | + if (!strlen($texte)) { |
|
| 1301 | + return ''; |
|
| 1302 | + } |
|
| 1303 | 1303 | |
| 1304 | - // Cas du turc |
|
| 1305 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1306 | - # remplacer hors des tags et des entites |
|
| 1307 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1308 | - foreach ($regs as $n => $match) { |
|
| 1309 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1310 | - } |
|
| 1311 | - } |
|
| 1304 | + // Cas du turc |
|
| 1305 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1306 | + # remplacer hors des tags et des entites |
|
| 1307 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1308 | + foreach ($regs as $n => $match) { |
|
| 1309 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1310 | + } |
|
| 1311 | + } |
|
| 1312 | 1312 | |
| 1313 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1313 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1314 | 1314 | |
| 1315 | - if ($regs) { |
|
| 1316 | - foreach ($regs as $n => $match) { |
|
| 1317 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1318 | - } |
|
| 1319 | - } |
|
| 1320 | - } |
|
| 1315 | + if ($regs) { |
|
| 1316 | + foreach ($regs as $n => $match) { |
|
| 1317 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1318 | + } |
|
| 1319 | + } |
|
| 1320 | + } |
|
| 1321 | 1321 | |
| 1322 | - // Cas general |
|
| 1323 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1322 | + // Cas general |
|
| 1323 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | /** |
@@ -1338,29 +1338,29 @@ discard block |
||
| 1338 | 1338 | * @return string |
| 1339 | 1339 | **/ |
| 1340 | 1340 | function taille_en_octets($taille) { |
| 1341 | - if (!defined('_KILOBYTE')) { |
|
| 1342 | - /** |
|
| 1343 | - * Définit le nombre d'octets dans un Kilobyte |
|
| 1344 | - * |
|
| 1345 | - * @var int |
|
| 1346 | - **/ |
|
| 1347 | - define('_KILOBYTE', 1024); |
|
| 1348 | - } |
|
| 1341 | + if (!defined('_KILOBYTE')) { |
|
| 1342 | + /** |
|
| 1343 | + * Définit le nombre d'octets dans un Kilobyte |
|
| 1344 | + * |
|
| 1345 | + * @var int |
|
| 1346 | + **/ |
|
| 1347 | + define('_KILOBYTE', 1024); |
|
| 1348 | + } |
|
| 1349 | 1349 | |
| 1350 | - if ($taille < 1) { |
|
| 1351 | - return ''; |
|
| 1352 | - } |
|
| 1353 | - if ($taille < _KILOBYTE) { |
|
| 1354 | - $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1355 | - } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1356 | - $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1357 | - } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1358 | - $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1359 | - } else { |
|
| 1360 | - $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1361 | - } |
|
| 1350 | + if ($taille < 1) { |
|
| 1351 | + return ''; |
|
| 1352 | + } |
|
| 1353 | + if ($taille < _KILOBYTE) { |
|
| 1354 | + $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1355 | + } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1356 | + $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1357 | + } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1358 | + $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1359 | + } else { |
|
| 1360 | + $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1361 | + } |
|
| 1362 | 1362 | |
| 1363 | - return $taille; |
|
| 1363 | + return $taille; |
|
| 1364 | 1364 | } |
| 1365 | 1365 | |
| 1366 | 1366 | |
@@ -1382,21 +1382,21 @@ discard block |
||
| 1382 | 1382 | * Texte prêt pour être utilisé en attribut HTML |
| 1383 | 1383 | **/ |
| 1384 | 1384 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1385 | - if ($texte === null) { |
|
| 1386 | - return ''; |
|
| 1387 | - } |
|
| 1388 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1389 | - if ($textebrut) { |
|
| 1390 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1391 | - } |
|
| 1392 | - $texte = texte_backend($texte); |
|
| 1393 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1385 | + if ($texte === null) { |
|
| 1386 | + return ''; |
|
| 1387 | + } |
|
| 1388 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1389 | + if ($textebrut) { |
|
| 1390 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1391 | + } |
|
| 1392 | + $texte = texte_backend($texte); |
|
| 1393 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1394 | 1394 | |
| 1395 | - return preg_replace( |
|
| 1396 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1397 | - ['&', '&'], |
|
| 1398 | - $texte |
|
| 1399 | - ); |
|
| 1395 | + return preg_replace( |
|
| 1396 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1397 | + ['&', '&'], |
|
| 1398 | + $texte |
|
| 1399 | + ); |
|
| 1400 | 1400 | } |
| 1401 | 1401 | |
| 1402 | 1402 | |
@@ -1416,15 +1416,15 @@ discard block |
||
| 1416 | 1416 | * URL ou chaîne vide |
| 1417 | 1417 | **/ |
| 1418 | 1418 | function vider_url(?string $url, $entites = true): string { |
| 1419 | - if ($url === null) { |
|
| 1420 | - return ''; |
|
| 1421 | - } |
|
| 1422 | - # un message pour abs_url |
|
| 1423 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1424 | - $url = trim($url); |
|
| 1425 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1419 | + if ($url === null) { |
|
| 1420 | + return ''; |
|
| 1421 | + } |
|
| 1422 | + # un message pour abs_url |
|
| 1423 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1424 | + $url = trim($url); |
|
| 1425 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1426 | 1426 | |
| 1427 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1427 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1428 | 1428 | } |
| 1429 | 1429 | |
| 1430 | 1430 | |
@@ -1439,10 +1439,10 @@ discard block |
||
| 1439 | 1439 | * @return string Adresse email maquillée |
| 1440 | 1440 | **/ |
| 1441 | 1441 | function antispam($texte) { |
| 1442 | - include_spip('inc/acces'); |
|
| 1443 | - $masque = creer_pass_aleatoire(3); |
|
| 1442 | + include_spip('inc/acces'); |
|
| 1443 | + $masque = creer_pass_aleatoire(3); |
|
| 1444 | 1444 | |
| 1445 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1445 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | 1448 | /** |
@@ -1474,8 +1474,8 @@ discard block |
||
| 1474 | 1474 | * True si on a le droit d'accès, false sinon. |
| 1475 | 1475 | **/ |
| 1476 | 1476 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1477 | - include_spip('inc/acces'); |
|
| 1478 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1477 | + include_spip('inc/acces'); |
|
| 1478 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1479 | 1479 | } |
| 1480 | 1480 | |
| 1481 | 1481 | /** |
@@ -1500,13 +1500,13 @@ discard block |
||
| 1500 | 1500 | * Retourne $texte, sinon $sinon. |
| 1501 | 1501 | **/ |
| 1502 | 1502 | function sinon($texte, $sinon = '') { |
| 1503 | - if ($texte) { |
|
| 1504 | - return $texte; |
|
| 1505 | - } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1506 | - return $texte; |
|
| 1507 | - } else { |
|
| 1508 | - return $sinon; |
|
| 1509 | - } |
|
| 1503 | + if ($texte) { |
|
| 1504 | + return $texte; |
|
| 1505 | + } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1506 | + return $texte; |
|
| 1507 | + } else { |
|
| 1508 | + return $sinon; |
|
| 1509 | + } |
|
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | 1512 | /** |
@@ -1530,7 +1530,7 @@ discard block |
||
| 1530 | 1530 | * @return mixed |
| 1531 | 1531 | **/ |
| 1532 | 1532 | function choixsivide($a, $vide, $pasvide) { |
| 1533 | - return $a ? $pasvide : $vide; |
|
| 1533 | + return $a ? $pasvide : $vide; |
|
| 1534 | 1534 | } |
| 1535 | 1535 | |
| 1536 | 1536 | /** |
@@ -1554,7 +1554,7 @@ discard block |
||
| 1554 | 1554 | * @return mixed |
| 1555 | 1555 | **/ |
| 1556 | 1556 | function choixsiegal($a1, $a2, $v, $f) { |
| 1557 | - return ($a1 == $a2) ? $v : $f; |
|
| 1557 | + return ($a1 == $a2) ? $v : $f; |
|
| 1558 | 1558 | } |
| 1559 | 1559 | |
| 1560 | 1560 | // |
@@ -1573,13 +1573,13 @@ discard block |
||
| 1573 | 1573 | * @return string |
| 1574 | 1574 | **/ |
| 1575 | 1575 | function filtrer_ical($texte) { |
| 1576 | - #include_spip('inc/charsets'); |
|
| 1577 | - $texte = html2unicode($texte); |
|
| 1578 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1579 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1580 | - $texte = preg_replace('/,/', '\,', $texte); |
|
| 1576 | + #include_spip('inc/charsets'); |
|
| 1577 | + $texte = html2unicode($texte); |
|
| 1578 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1579 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1580 | + $texte = preg_replace('/,/', '\,', $texte); |
|
| 1581 | 1581 | |
| 1582 | - return $texte; |
|
| 1582 | + return $texte; |
|
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | 1585 | |
@@ -1604,58 +1604,58 @@ discard block |
||
| 1604 | 1604 | * @return string |
| 1605 | 1605 | **/ |
| 1606 | 1606 | function post_autobr($texte, $delim = "\n_ ") { |
| 1607 | - if (!function_exists('echappe_html')) { |
|
| 1608 | - include_spip('inc/texte_mini'); |
|
| 1609 | - } |
|
| 1610 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1611 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1612 | - |
|
| 1613 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1614 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1615 | - } else { |
|
| 1616 | - $fin = ''; |
|
| 1617 | - } |
|
| 1618 | - |
|
| 1619 | - $texte = echappe_html($texte, '', true); |
|
| 1620 | - |
|
| 1621 | - // echapper les modeles |
|
| 1622 | - $collecteurModeles = null; |
|
| 1623 | - if (strpos($texte, '<') !== false) { |
|
| 1624 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1625 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 1626 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1627 | - $texte = $collecteurModeles->echapper($texte); |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - $debut = ''; |
|
| 1631 | - $suite = $texte; |
|
| 1632 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1633 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1634 | - $suite = substr($suite, $t); |
|
| 1635 | - $car = substr($suite, 0, 1); |
|
| 1636 | - if ( |
|
| 1637 | - ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1638 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1639 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1640 | - ) { |
|
| 1641 | - $debut .= $delim; |
|
| 1642 | - } else { |
|
| 1643 | - $debut .= "\n"; |
|
| 1644 | - } |
|
| 1645 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1646 | - $debut .= $regs[0]; |
|
| 1647 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1648 | - } |
|
| 1649 | - } |
|
| 1650 | - $texte = $debut . $suite; |
|
| 1651 | - |
|
| 1652 | - if ($collecteurModeles) { |
|
| 1653 | - $texte = $collecteurModeles->retablir($texte); |
|
| 1654 | - } |
|
| 1655 | - |
|
| 1656 | - $texte = echappe_retour($texte); |
|
| 1657 | - |
|
| 1658 | - return $texte . $fin; |
|
| 1607 | + if (!function_exists('echappe_html')) { |
|
| 1608 | + include_spip('inc/texte_mini'); |
|
| 1609 | + } |
|
| 1610 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1611 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1612 | + |
|
| 1613 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1614 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1615 | + } else { |
|
| 1616 | + $fin = ''; |
|
| 1617 | + } |
|
| 1618 | + |
|
| 1619 | + $texte = echappe_html($texte, '', true); |
|
| 1620 | + |
|
| 1621 | + // echapper les modeles |
|
| 1622 | + $collecteurModeles = null; |
|
| 1623 | + if (strpos($texte, '<') !== false) { |
|
| 1624 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1625 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 1626 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1627 | + $texte = $collecteurModeles->echapper($texte); |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + $debut = ''; |
|
| 1631 | + $suite = $texte; |
|
| 1632 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1633 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1634 | + $suite = substr($suite, $t); |
|
| 1635 | + $car = substr($suite, 0, 1); |
|
| 1636 | + if ( |
|
| 1637 | + ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1638 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1639 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1640 | + ) { |
|
| 1641 | + $debut .= $delim; |
|
| 1642 | + } else { |
|
| 1643 | + $debut .= "\n"; |
|
| 1644 | + } |
|
| 1645 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1646 | + $debut .= $regs[0]; |
|
| 1647 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1648 | + } |
|
| 1649 | + } |
|
| 1650 | + $texte = $debut . $suite; |
|
| 1651 | + |
|
| 1652 | + if ($collecteurModeles) { |
|
| 1653 | + $texte = $collecteurModeles->retablir($texte); |
|
| 1654 | + } |
|
| 1655 | + |
|
| 1656 | + $texte = echappe_retour($texte); |
|
| 1657 | + |
|
| 1658 | + return $texte . $fin; |
|
| 1659 | 1659 | } |
| 1660 | 1660 | |
| 1661 | 1661 | |
@@ -1690,30 +1690,30 @@ discard block |
||
| 1690 | 1690 | **/ |
| 1691 | 1691 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1692 | 1692 | |
| 1693 | - if ( |
|
| 1694 | - $letexte |
|
| 1695 | - and strpos($letexte, '<:') !== false |
|
| 1696 | - ) { |
|
| 1697 | - if (!$lang) { |
|
| 1698 | - $lang = $GLOBALS['spip_lang']; |
|
| 1699 | - } |
|
| 1700 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1701 | - if (is_bool($options)) { |
|
| 1702 | - $options = ['echappe_span' => $options]; |
|
| 1703 | - } |
|
| 1704 | - if (!isset($options['echappe_span'])) { |
|
| 1705 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1706 | - } |
|
| 1707 | - $options['lang'] = $lang; |
|
| 1693 | + if ( |
|
| 1694 | + $letexte |
|
| 1695 | + and strpos($letexte, '<:') !== false |
|
| 1696 | + ) { |
|
| 1697 | + if (!$lang) { |
|
| 1698 | + $lang = $GLOBALS['spip_lang']; |
|
| 1699 | + } |
|
| 1700 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1701 | + if (is_bool($options)) { |
|
| 1702 | + $options = ['echappe_span' => $options]; |
|
| 1703 | + } |
|
| 1704 | + if (!isset($options['echappe_span'])) { |
|
| 1705 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1706 | + } |
|
| 1707 | + $options['lang'] = $lang; |
|
| 1708 | 1708 | |
| 1709 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1710 | - include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 1711 | - $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1709 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1710 | + include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 1711 | + $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1712 | 1712 | |
| 1713 | - $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1713 | + $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1714 | 1714 | |
| 1715 | - } |
|
| 1716 | - return $letexte; |
|
| 1715 | + } |
|
| 1716 | + return $letexte; |
|
| 1717 | 1717 | } |
| 1718 | 1718 | |
| 1719 | 1719 | /** |
@@ -1751,34 +1751,34 @@ discard block |
||
| 1751 | 1751 | **/ |
| 1752 | 1752 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1753 | 1753 | |
| 1754 | - if ( |
|
| 1755 | - $letexte |
|
| 1756 | - and stripos($letexte, '<multi') !== false |
|
| 1757 | - ) { |
|
| 1758 | - if (!$lang) { |
|
| 1759 | - $lang = $GLOBALS['spip_lang']; |
|
| 1760 | - } |
|
| 1754 | + if ( |
|
| 1755 | + $letexte |
|
| 1756 | + and stripos($letexte, '<multi') !== false |
|
| 1757 | + ) { |
|
| 1758 | + if (!$lang) { |
|
| 1759 | + $lang = $GLOBALS['spip_lang']; |
|
| 1760 | + } |
|
| 1761 | 1761 | |
| 1762 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1763 | - if (is_bool($options)) { |
|
| 1764 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1765 | - } |
|
| 1766 | - if (!isset($options['echappe_span'])) { |
|
| 1767 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1768 | - } |
|
| 1769 | - if (!isset($options['lang_defaut'])) { |
|
| 1770 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1771 | - } |
|
| 1772 | - $options['lang'] = $lang; |
|
| 1762 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1763 | + if (is_bool($options)) { |
|
| 1764 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1765 | + } |
|
| 1766 | + if (!isset($options['echappe_span'])) { |
|
| 1767 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1768 | + } |
|
| 1769 | + if (!isset($options['lang_defaut'])) { |
|
| 1770 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1771 | + } |
|
| 1772 | + $options['lang'] = $lang; |
|
| 1773 | 1773 | |
| 1774 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1775 | - include_spip("src/Texte/Collecteur/Multis"); |
|
| 1776 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1774 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1775 | + include_spip("src/Texte/Collecteur/Multis"); |
|
| 1776 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1777 | 1777 | |
| 1778 | - $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1779 | - } |
|
| 1778 | + $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1779 | + } |
|
| 1780 | 1780 | |
| 1781 | - return $letexte; |
|
| 1781 | + return $letexte; |
|
| 1782 | 1782 | } |
| 1783 | 1783 | |
| 1784 | 1784 | /** |
@@ -1788,7 +1788,7 @@ discard block |
||
| 1788 | 1788 | * @return string L'initiale en majuscule |
| 1789 | 1789 | */ |
| 1790 | 1790 | function filtre_initiale($nom) { |
| 1791 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1791 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1792 | 1792 | } |
| 1793 | 1793 | |
| 1794 | 1794 | |
@@ -1833,33 +1833,33 @@ discard block |
||
| 1833 | 1833 | * - null (interne) : si on empile |
| 1834 | 1834 | **/ |
| 1835 | 1835 | function unique($donnee, $famille = '', $cpt = false) { |
| 1836 | - static $mem = []; |
|
| 1837 | - // permettre de vider la pile et de la restaurer |
|
| 1838 | - // pour le calcul de introduction... |
|
| 1839 | - if ($famille == '_spip_raz_') { |
|
| 1840 | - $tmp = $mem; |
|
| 1841 | - $mem = []; |
|
| 1842 | - |
|
| 1843 | - return $tmp; |
|
| 1844 | - } elseif ($famille == '_spip_set_') { |
|
| 1845 | - $mem = $donnee; |
|
| 1846 | - |
|
| 1847 | - return; |
|
| 1848 | - } |
|
| 1849 | - // eviter une notice |
|
| 1850 | - if (!isset($mem[$famille])) { |
|
| 1851 | - $mem[$famille] = []; |
|
| 1852 | - } |
|
| 1853 | - if ($cpt) { |
|
| 1854 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1855 | - } |
|
| 1856 | - // eviter une notice |
|
| 1857 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1858 | - $mem[$famille][$donnee] = 0; |
|
| 1859 | - } |
|
| 1860 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1861 | - return $donnee; |
|
| 1862 | - } |
|
| 1836 | + static $mem = []; |
|
| 1837 | + // permettre de vider la pile et de la restaurer |
|
| 1838 | + // pour le calcul de introduction... |
|
| 1839 | + if ($famille == '_spip_raz_') { |
|
| 1840 | + $tmp = $mem; |
|
| 1841 | + $mem = []; |
|
| 1842 | + |
|
| 1843 | + return $tmp; |
|
| 1844 | + } elseif ($famille == '_spip_set_') { |
|
| 1845 | + $mem = $donnee; |
|
| 1846 | + |
|
| 1847 | + return; |
|
| 1848 | + } |
|
| 1849 | + // eviter une notice |
|
| 1850 | + if (!isset($mem[$famille])) { |
|
| 1851 | + $mem[$famille] = []; |
|
| 1852 | + } |
|
| 1853 | + if ($cpt) { |
|
| 1854 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1855 | + } |
|
| 1856 | + // eviter une notice |
|
| 1857 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1858 | + $mem[$famille][$donnee] = 0; |
|
| 1859 | + } |
|
| 1860 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1861 | + return $donnee; |
|
| 1862 | + } |
|
| 1863 | 1863 | } |
| 1864 | 1864 | |
| 1865 | 1865 | |
@@ -1889,20 +1889,20 @@ discard block |
||
| 1889 | 1889 | * Une des valeurs en fonction du compteur. |
| 1890 | 1890 | **/ |
| 1891 | 1891 | function alterner($i, ...$args) { |
| 1892 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1893 | - $num = count($args); |
|
| 1892 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1893 | + $num = count($args); |
|
| 1894 | 1894 | |
| 1895 | - if ($num === 1 && is_array($args[0])) { |
|
| 1896 | - // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1897 | - $args = array_values($args[0]); |
|
| 1898 | - $num = count($args); |
|
| 1899 | - } |
|
| 1895 | + if ($num === 1 && is_array($args[0])) { |
|
| 1896 | + // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1897 | + $args = array_values($args[0]); |
|
| 1898 | + $num = count($args); |
|
| 1899 | + } |
|
| 1900 | 1900 | |
| 1901 | - // un index compris entre 0 et num exclus |
|
| 1902 | - $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 1903 | - $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1904 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1905 | - return $args[$i]; |
|
| 1901 | + // un index compris entre 0 et num exclus |
|
| 1902 | + $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 1903 | + $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1904 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1905 | + return $args[$i]; |
|
| 1906 | 1906 | } |
| 1907 | 1907 | |
| 1908 | 1908 | |
@@ -1928,52 +1928,52 @@ discard block |
||
| 1928 | 1928 | * - null lorsque l’attribut n’existe pas. |
| 1929 | 1929 | **/ |
| 1930 | 1930 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1931 | - if (is_array($balise)) { |
|
| 1932 | - array_walk( |
|
| 1933 | - $balise, |
|
| 1934 | - function (&$a, $key, $t) { |
|
| 1935 | - $a = extraire_attribut($a, $t); |
|
| 1936 | - }, |
|
| 1937 | - $attribut |
|
| 1938 | - ); |
|
| 1939 | - |
|
| 1940 | - return $balise; |
|
| 1941 | - } |
|
| 1942 | - if ( |
|
| 1943 | - $balise |
|
| 1944 | - && stripos($balise, $attribut) !== false |
|
| 1945 | - && preg_match( |
|
| 1946 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1947 | - . $attribut |
|
| 1948 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1949 | - $balise, |
|
| 1950 | - $r |
|
| 1951 | - ) |
|
| 1952 | - ) { |
|
| 1953 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1954 | - $r[4] = substr($r[3], 1, -1); |
|
| 1955 | - $r[3] = $r[3][0]; |
|
| 1956 | - } elseif ($r[3] !== '') { |
|
| 1957 | - $r[4] = $r[3]; |
|
| 1958 | - $r[3] = ''; |
|
| 1959 | - } else { |
|
| 1960 | - $r[4] = trim($r[2]); |
|
| 1961 | - } |
|
| 1962 | - $att = $r[4]; |
|
| 1963 | - if (strpos($att, '&#') !== false) { |
|
| 1964 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1965 | - } |
|
| 1966 | - $att = filtrer_entites($att); |
|
| 1967 | - } else { |
|
| 1968 | - $att = null; |
|
| 1969 | - $r = []; |
|
| 1970 | - } |
|
| 1971 | - |
|
| 1972 | - if ($complet) { |
|
| 1973 | - return [$att, $r]; |
|
| 1974 | - } else { |
|
| 1975 | - return $att; |
|
| 1976 | - } |
|
| 1931 | + if (is_array($balise)) { |
|
| 1932 | + array_walk( |
|
| 1933 | + $balise, |
|
| 1934 | + function (&$a, $key, $t) { |
|
| 1935 | + $a = extraire_attribut($a, $t); |
|
| 1936 | + }, |
|
| 1937 | + $attribut |
|
| 1938 | + ); |
|
| 1939 | + |
|
| 1940 | + return $balise; |
|
| 1941 | + } |
|
| 1942 | + if ( |
|
| 1943 | + $balise |
|
| 1944 | + && stripos($balise, $attribut) !== false |
|
| 1945 | + && preg_match( |
|
| 1946 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1947 | + . $attribut |
|
| 1948 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1949 | + $balise, |
|
| 1950 | + $r |
|
| 1951 | + ) |
|
| 1952 | + ) { |
|
| 1953 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1954 | + $r[4] = substr($r[3], 1, -1); |
|
| 1955 | + $r[3] = $r[3][0]; |
|
| 1956 | + } elseif ($r[3] !== '') { |
|
| 1957 | + $r[4] = $r[3]; |
|
| 1958 | + $r[3] = ''; |
|
| 1959 | + } else { |
|
| 1960 | + $r[4] = trim($r[2]); |
|
| 1961 | + } |
|
| 1962 | + $att = $r[4]; |
|
| 1963 | + if (strpos($att, '&#') !== false) { |
|
| 1964 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1965 | + } |
|
| 1966 | + $att = filtrer_entites($att); |
|
| 1967 | + } else { |
|
| 1968 | + $att = null; |
|
| 1969 | + $r = []; |
|
| 1970 | + } |
|
| 1971 | + |
|
| 1972 | + if ($complet) { |
|
| 1973 | + return [$att, $r]; |
|
| 1974 | + } else { |
|
| 1975 | + return $att; |
|
| 1976 | + } |
|
| 1977 | 1977 | } |
| 1978 | 1978 | |
| 1979 | 1979 | /** |
@@ -2006,41 +2006,41 @@ discard block |
||
| 2006 | 2006 | **/ |
| 2007 | 2007 | function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string { |
| 2008 | 2008 | |
| 2009 | - if ($balise === null or $balise === '') { |
|
| 2010 | - return ''; |
|
| 2011 | - } |
|
| 2009 | + if ($balise === null or $balise === '') { |
|
| 2010 | + return ''; |
|
| 2011 | + } |
|
| 2012 | 2012 | |
| 2013 | - // preparer l'attribut |
|
| 2014 | - // supprimer les etc mais pas les balises html |
|
| 2015 | - // qui ont un sens dans un attribut value d'un input |
|
| 2016 | - if ($proteger) { |
|
| 2017 | - $val = attribut_html($val, false); |
|
| 2018 | - } |
|
| 2013 | + // preparer l'attribut |
|
| 2014 | + // supprimer les etc mais pas les balises html |
|
| 2015 | + // qui ont un sens dans un attribut value d'un input |
|
| 2016 | + if ($proteger) { |
|
| 2017 | + $val = attribut_html($val, false); |
|
| 2018 | + } |
|
| 2019 | 2019 | |
| 2020 | - // echapper les ' pour eviter tout bug |
|
| 2021 | - $val = str_replace("'", ''', $val); |
|
| 2022 | - if ($vider and strlen($val) === 0) { |
|
| 2023 | - $insert = ''; |
|
| 2024 | - } else { |
|
| 2025 | - $insert = " $attribut='$val'"; |
|
| 2026 | - } |
|
| 2020 | + // echapper les ' pour eviter tout bug |
|
| 2021 | + $val = str_replace("'", ''', $val); |
|
| 2022 | + if ($vider and strlen($val) === 0) { |
|
| 2023 | + $insert = ''; |
|
| 2024 | + } else { |
|
| 2025 | + $insert = " $attribut='$val'"; |
|
| 2026 | + } |
|
| 2027 | 2027 | |
| 2028 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2028 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2029 | 2029 | |
| 2030 | - if ($old !== null) { |
|
| 2031 | - // Remplacer l'ancien attribut du meme nom |
|
| 2032 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2033 | - } else { |
|
| 2034 | - // preferer une balise " />" (comme <img />) |
|
| 2035 | - if (preg_match(',/>,', $balise)) { |
|
| 2036 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2037 | - } // sinon une balise <a ...> ... </a> |
|
| 2038 | - else { |
|
| 2039 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2040 | - } |
|
| 2041 | - } |
|
| 2030 | + if ($old !== null) { |
|
| 2031 | + // Remplacer l'ancien attribut du meme nom |
|
| 2032 | + $balise = $r[1] . $insert . $r[5]; |
|
| 2033 | + } else { |
|
| 2034 | + // preferer une balise " />" (comme <img />) |
|
| 2035 | + if (preg_match(',/>,', $balise)) { |
|
| 2036 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2037 | + } // sinon une balise <a ...> ... </a> |
|
| 2038 | + else { |
|
| 2039 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2040 | + } |
|
| 2041 | + } |
|
| 2042 | 2042 | |
| 2043 | - return $balise; |
|
| 2043 | + return $balise; |
|
| 2044 | 2044 | } |
| 2045 | 2045 | |
| 2046 | 2046 | /** |
@@ -2058,7 +2058,7 @@ discard block |
||
| 2058 | 2058 | * @return string Code HTML sans l'attribut |
| 2059 | 2059 | **/ |
| 2060 | 2060 | function vider_attribut(?string $balise, string $attribut): string { |
| 2061 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2061 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2062 | 2062 | } |
| 2063 | 2063 | |
| 2064 | 2064 | /** |
@@ -2070,53 +2070,53 @@ discard block |
||
| 2070 | 2070 | * @return string |
| 2071 | 2071 | */ |
| 2072 | 2072 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2073 | - if (is_string($class)) { |
|
| 2074 | - $class = explode(' ', trim($class)); |
|
| 2075 | - } |
|
| 2076 | - $class = array_filter($class); |
|
| 2077 | - $class = array_unique($class); |
|
| 2078 | - if (!$class) { |
|
| 2079 | - return $balise; |
|
| 2080 | - } |
|
| 2081 | - |
|
| 2082 | - // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2083 | - if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2084 | - return $balise; |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2088 | - $class_new = $class_courante; |
|
| 2089 | - foreach ($class as $c) { |
|
| 2090 | - $is_class_presente = false; |
|
| 2091 | - if ( |
|
| 2092 | - $class_courante |
|
| 2093 | - and strpos($class_courante, (string) $c) !== false |
|
| 2094 | - and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2095 | - ) { |
|
| 2096 | - $is_class_presente = true; |
|
| 2097 | - } |
|
| 2098 | - if ( |
|
| 2099 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2100 | - and !$is_class_presente |
|
| 2101 | - ) { |
|
| 2102 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2103 | - } elseif ( |
|
| 2104 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2105 | - and $is_class_presente |
|
| 2106 | - ) { |
|
| 2107 | - $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2108 | - } |
|
| 2109 | - } |
|
| 2110 | - |
|
| 2111 | - if ($class_new !== $class_courante) { |
|
| 2112 | - if (strlen($class_new)) { |
|
| 2113 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2114 | - } elseif ($class_courante) { |
|
| 2115 | - $balise = vider_attribut($balise, 'class'); |
|
| 2116 | - } |
|
| 2117 | - } |
|
| 2118 | - |
|
| 2119 | - return $balise; |
|
| 2073 | + if (is_string($class)) { |
|
| 2074 | + $class = explode(' ', trim($class)); |
|
| 2075 | + } |
|
| 2076 | + $class = array_filter($class); |
|
| 2077 | + $class = array_unique($class); |
|
| 2078 | + if (!$class) { |
|
| 2079 | + return $balise; |
|
| 2080 | + } |
|
| 2081 | + |
|
| 2082 | + // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2083 | + if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2084 | + return $balise; |
|
| 2085 | + } |
|
| 2086 | + |
|
| 2087 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2088 | + $class_new = $class_courante; |
|
| 2089 | + foreach ($class as $c) { |
|
| 2090 | + $is_class_presente = false; |
|
| 2091 | + if ( |
|
| 2092 | + $class_courante |
|
| 2093 | + and strpos($class_courante, (string) $c) !== false |
|
| 2094 | + and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2095 | + ) { |
|
| 2096 | + $is_class_presente = true; |
|
| 2097 | + } |
|
| 2098 | + if ( |
|
| 2099 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2100 | + and !$is_class_presente |
|
| 2101 | + ) { |
|
| 2102 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2103 | + } elseif ( |
|
| 2104 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2105 | + and $is_class_presente |
|
| 2106 | + ) { |
|
| 2107 | + $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2108 | + } |
|
| 2109 | + } |
|
| 2110 | + |
|
| 2111 | + if ($class_new !== $class_courante) { |
|
| 2112 | + if (strlen($class_new)) { |
|
| 2113 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2114 | + } elseif ($class_courante) { |
|
| 2115 | + $balise = vider_attribut($balise, 'class'); |
|
| 2116 | + } |
|
| 2117 | + } |
|
| 2118 | + |
|
| 2119 | + return $balise; |
|
| 2120 | 2120 | } |
| 2121 | 2121 | |
| 2122 | 2122 | /** |
@@ -2126,7 +2126,7 @@ discard block |
||
| 2126 | 2126 | * @return string |
| 2127 | 2127 | */ |
| 2128 | 2128 | function ajouter_class($balise, $class) { |
| 2129 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2129 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2130 | 2130 | } |
| 2131 | 2131 | |
| 2132 | 2132 | /** |
@@ -2136,7 +2136,7 @@ discard block |
||
| 2136 | 2136 | * @return string |
| 2137 | 2137 | */ |
| 2138 | 2138 | function supprimer_class($balise, $class) { |
| 2139 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2139 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2140 | 2140 | } |
| 2141 | 2141 | |
| 2142 | 2142 | /** |
@@ -2147,7 +2147,7 @@ discard block |
||
| 2147 | 2147 | * @return string |
| 2148 | 2148 | */ |
| 2149 | 2149 | function commuter_class($balise, $class) { |
| 2150 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2150 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2151 | 2151 | } |
| 2152 | 2152 | |
| 2153 | 2153 | /** |
@@ -2158,19 +2158,19 @@ discard block |
||
| 2158 | 2158 | * @return string |
| 2159 | 2159 | */ |
| 2160 | 2160 | function tester_config($id, $mode = '') { |
| 2161 | - include_spip('action/inscrire_auteur'); |
|
| 2161 | + include_spip('action/inscrire_auteur'); |
|
| 2162 | 2162 | |
| 2163 | - return tester_statut_inscription($mode, $id); |
|
| 2163 | + return tester_statut_inscription($mode, $id); |
|
| 2164 | 2164 | } |
| 2165 | 2165 | |
| 2166 | 2166 | // |
| 2167 | 2167 | // Quelques fonctions de calcul arithmetique |
| 2168 | 2168 | // |
| 2169 | 2169 | function floatstr($a) { |
| 2170 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2170 | + return str_replace(',', '.', (string)floatval($a)); |
|
| 2171 | 2171 | } |
| 2172 | 2172 | function strize($f, $a, $b) { |
| 2173 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2173 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2174 | 2174 | } |
| 2175 | 2175 | |
| 2176 | 2176 | /** |
@@ -2189,7 +2189,7 @@ discard block |
||
| 2189 | 2189 | * @return int $a+$b |
| 2190 | 2190 | **/ |
| 2191 | 2191 | function plus($a, $b) { |
| 2192 | - return $a + $b; |
|
| 2192 | + return $a + $b; |
|
| 2193 | 2193 | } |
| 2194 | 2194 | function strplus($a, $b) { |
| 2195 | 2195 | return strize('plus', $a, $b); |
@@ -2210,7 +2210,7 @@ discard block |
||
| 2210 | 2210 | * @return int $a-$b |
| 2211 | 2211 | **/ |
| 2212 | 2212 | function moins($a, $b) { |
| 2213 | - return $a - $b; |
|
| 2213 | + return $a - $b; |
|
| 2214 | 2214 | } |
| 2215 | 2215 | function strmoins($a, $b) { |
| 2216 | 2216 | return strize('moins', $a, $b); |
@@ -2233,7 +2233,7 @@ discard block |
||
| 2233 | 2233 | * @return int $a*$b |
| 2234 | 2234 | **/ |
| 2235 | 2235 | function mult($a, $b) { |
| 2236 | - return $a * $b; |
|
| 2236 | + return $a * $b; |
|
| 2237 | 2237 | } |
| 2238 | 2238 | function strmult($a, $b) { |
| 2239 | 2239 | return strize('mult', $a, $b); |
@@ -2256,7 +2256,7 @@ discard block |
||
| 2256 | 2256 | * @return int $a/$b (ou 0 si $b est nul) |
| 2257 | 2257 | **/ |
| 2258 | 2258 | function div($a, $b) { |
| 2259 | - return $b ? $a / $b : 0; |
|
| 2259 | + return $b ? $a / $b : 0; |
|
| 2260 | 2260 | } |
| 2261 | 2261 | function strdiv($a, $b) { |
| 2262 | 2262 | return strize('div', $a, $b); |
@@ -2280,7 +2280,7 @@ discard block |
||
| 2280 | 2280 | * @return int ($nb % $mod) + $add |
| 2281 | 2281 | **/ |
| 2282 | 2282 | function modulo($nb, $mod, $add = 0) { |
| 2283 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2283 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2284 | 2284 | } |
| 2285 | 2285 | |
| 2286 | 2286 | |
@@ -2295,26 +2295,26 @@ discard block |
||
| 2295 | 2295 | * - true sinon |
| 2296 | 2296 | **/ |
| 2297 | 2297 | function nom_acceptable($nom) { |
| 2298 | - $remp2 = []; |
|
| 2299 | - $remp1 = []; |
|
| 2300 | - if (!is_string($nom)) { |
|
| 2301 | - return false; |
|
| 2302 | - } |
|
| 2303 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2304 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2305 | - } |
|
| 2306 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2307 | - foreach ($tags_acceptes as $tag) { |
|
| 2308 | - if (strlen($tag)) { |
|
| 2309 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2310 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2311 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2312 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2313 | - } |
|
| 2314 | - } |
|
| 2315 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2316 | - |
|
| 2317 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2298 | + $remp2 = []; |
|
| 2299 | + $remp1 = []; |
|
| 2300 | + if (!is_string($nom)) { |
|
| 2301 | + return false; |
|
| 2302 | + } |
|
| 2303 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2304 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2305 | + } |
|
| 2306 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2307 | + foreach ($tags_acceptes as $tag) { |
|
| 2308 | + if (strlen($tag)) { |
|
| 2309 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2310 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2311 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2312 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2313 | + } |
|
| 2314 | + } |
|
| 2315 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2316 | + |
|
| 2317 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2318 | 2318 | } |
| 2319 | 2319 | |
| 2320 | 2320 | |
@@ -2330,14 +2330,14 @@ discard block |
||
| 2330 | 2330 | * - renvoie un tableau si l'entree est un tableau |
| 2331 | 2331 | **/ |
| 2332 | 2332 | function email_valide($adresses) { |
| 2333 | - if (is_array($adresses)) { |
|
| 2334 | - $adresses = array_map('email_valide', $adresses); |
|
| 2335 | - $adresses = array_filter($adresses); |
|
| 2336 | - return $adresses; |
|
| 2337 | - } |
|
| 2333 | + if (is_array($adresses)) { |
|
| 2334 | + $adresses = array_map('email_valide', $adresses); |
|
| 2335 | + $adresses = array_filter($adresses); |
|
| 2336 | + return $adresses; |
|
| 2337 | + } |
|
| 2338 | 2338 | |
| 2339 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2340 | - return $email_valide($adresses); |
|
| 2339 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2340 | + return $email_valide($adresses); |
|
| 2341 | 2341 | } |
| 2342 | 2342 | |
| 2343 | 2343 | /** |
@@ -2351,29 +2351,29 @@ discard block |
||
| 2351 | 2351 | * @return string Texte |
| 2352 | 2352 | **/ |
| 2353 | 2353 | function afficher_enclosures($tags) { |
| 2354 | - $s = []; |
|
| 2355 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2356 | - if ( |
|
| 2357 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2358 | - and $t = extraire_attribut($tag, 'href') |
|
| 2359 | - ) { |
|
| 2360 | - $s[] = preg_replace( |
|
| 2361 | - ',>[^<]+</a>,S', |
|
| 2362 | - '>' |
|
| 2363 | - . http_img_pack( |
|
| 2364 | - 'attachment-16.png', |
|
| 2365 | - $t, |
|
| 2366 | - '', |
|
| 2367 | - $t, |
|
| 2368 | - ['utiliser_suffixe_size' => true] |
|
| 2369 | - ) |
|
| 2370 | - . '</a>', |
|
| 2371 | - $tag |
|
| 2372 | - ); |
|
| 2373 | - } |
|
| 2374 | - } |
|
| 2375 | - |
|
| 2376 | - return join(' ', $s); |
|
| 2354 | + $s = []; |
|
| 2355 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2356 | + if ( |
|
| 2357 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2358 | + and $t = extraire_attribut($tag, 'href') |
|
| 2359 | + ) { |
|
| 2360 | + $s[] = preg_replace( |
|
| 2361 | + ',>[^<]+</a>,S', |
|
| 2362 | + '>' |
|
| 2363 | + . http_img_pack( |
|
| 2364 | + 'attachment-16.png', |
|
| 2365 | + $t, |
|
| 2366 | + '', |
|
| 2367 | + $t, |
|
| 2368 | + ['utiliser_suffixe_size' => true] |
|
| 2369 | + ) |
|
| 2370 | + . '</a>', |
|
| 2371 | + $tag |
|
| 2372 | + ); |
|
| 2373 | + } |
|
| 2374 | + } |
|
| 2375 | + |
|
| 2376 | + return join(' ', $s); |
|
| 2377 | 2377 | } |
| 2378 | 2378 | |
| 2379 | 2379 | /** |
@@ -2388,15 +2388,15 @@ discard block |
||
| 2388 | 2388 | * @return string Liens trouvés |
| 2389 | 2389 | **/ |
| 2390 | 2390 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2391 | - $s = []; |
|
| 2392 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2393 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2394 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2395 | - $s[] = $tag; |
|
| 2396 | - } |
|
| 2397 | - } |
|
| 2391 | + $s = []; |
|
| 2392 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2393 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2394 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2395 | + $s[] = $tag; |
|
| 2396 | + } |
|
| 2397 | + } |
|
| 2398 | 2398 | |
| 2399 | - return join(', ', $s); |
|
| 2399 | + return join(', ', $s); |
|
| 2400 | 2400 | } |
| 2401 | 2401 | |
| 2402 | 2402 | |
@@ -2418,21 +2418,21 @@ discard block |
||
| 2418 | 2418 | * @return string Tag HTML `<a>` avec microformat. |
| 2419 | 2419 | **/ |
| 2420 | 2420 | function enclosure2microformat($e) { |
| 2421 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2422 | - $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2423 | - } |
|
| 2424 | - $type = extraire_attribut($e, 'type'); |
|
| 2425 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2426 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2427 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2428 | - } |
|
| 2429 | - $fichier = basename($url); |
|
| 2421 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2422 | + $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2423 | + } |
|
| 2424 | + $type = extraire_attribut($e, 'type'); |
|
| 2425 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2426 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2427 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2428 | + } |
|
| 2429 | + $fichier = basename($url); |
|
| 2430 | 2430 | |
| 2431 | - return '<a rel="enclosure"' |
|
| 2432 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2433 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2434 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2435 | - . '>' . $fichier . '</a>'; |
|
| 2431 | + return '<a rel="enclosure"' |
|
| 2432 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2433 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2434 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2435 | + . '>' . $fichier . '</a>'; |
|
| 2436 | 2436 | } |
| 2437 | 2437 | |
| 2438 | 2438 | /** |
@@ -2450,24 +2450,24 @@ discard block |
||
| 2450 | 2450 | * @return string Tags RSS `<enclosure>`. |
| 2451 | 2451 | **/ |
| 2452 | 2452 | function microformat2enclosure($tags) { |
| 2453 | - $enclosures = []; |
|
| 2454 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2455 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2456 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2457 | - $type = extraire_attribut($e, 'type'); |
|
| 2458 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2459 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2460 | - } # vieux data |
|
| 2461 | - $fichier = basename($url); |
|
| 2462 | - $enclosures[] = '<enclosure' |
|
| 2463 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2464 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2465 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2466 | - . ' />'; |
|
| 2467 | - } |
|
| 2468 | - } |
|
| 2453 | + $enclosures = []; |
|
| 2454 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2455 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2456 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2457 | + $type = extraire_attribut($e, 'type'); |
|
| 2458 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2459 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2460 | + } # vieux data |
|
| 2461 | + $fichier = basename($url); |
|
| 2462 | + $enclosures[] = '<enclosure' |
|
| 2463 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2464 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2465 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2466 | + . ' />'; |
|
| 2467 | + } |
|
| 2468 | + } |
|
| 2469 | 2469 | |
| 2470 | - return join("\n", $enclosures); |
|
| 2470 | + return join("\n", $enclosures); |
|
| 2471 | 2471 | } |
| 2472 | 2472 | |
| 2473 | 2473 | |
@@ -2483,16 +2483,16 @@ discard block |
||
| 2483 | 2483 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2484 | 2484 | **/ |
| 2485 | 2485 | function tags2dcsubject($tags) { |
| 2486 | - $subjects = ''; |
|
| 2487 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2488 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2489 | - $subjects .= '<dc:subject>' |
|
| 2490 | - . texte_backend(textebrut($e)) |
|
| 2491 | - . '</dc:subject>' . "\n"; |
|
| 2492 | - } |
|
| 2493 | - } |
|
| 2486 | + $subjects = ''; |
|
| 2487 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2488 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2489 | + $subjects .= '<dc:subject>' |
|
| 2490 | + . texte_backend(textebrut($e)) |
|
| 2491 | + . '</dc:subject>' . "\n"; |
|
| 2492 | + } |
|
| 2493 | + } |
|
| 2494 | 2494 | |
| 2495 | - return $subjects; |
|
| 2495 | + return $subjects; |
|
| 2496 | 2496 | } |
| 2497 | 2497 | |
| 2498 | 2498 | /** |
@@ -2521,27 +2521,27 @@ discard block |
||
| 2521 | 2521 | * - Tableau de résultats, si tableau en entrée. |
| 2522 | 2522 | **/ |
| 2523 | 2523 | function extraire_balise($texte, $tag = 'a') { |
| 2524 | - if (is_array($texte)) { |
|
| 2525 | - array_walk( |
|
| 2526 | - $texte, |
|
| 2527 | - function (&$a, $key, $t) { |
|
| 2528 | - $a = extraire_balise($a, $t); |
|
| 2529 | - }, |
|
| 2530 | - $tag |
|
| 2531 | - ); |
|
| 2532 | - |
|
| 2533 | - return $texte; |
|
| 2534 | - } |
|
| 2535 | - |
|
| 2536 | - if ( |
|
| 2537 | - preg_match( |
|
| 2538 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2539 | - $texte, |
|
| 2540 | - $regs |
|
| 2541 | - ) |
|
| 2542 | - ) { |
|
| 2543 | - return $regs[0]; |
|
| 2544 | - } |
|
| 2524 | + if (is_array($texte)) { |
|
| 2525 | + array_walk( |
|
| 2526 | + $texte, |
|
| 2527 | + function (&$a, $key, $t) { |
|
| 2528 | + $a = extraire_balise($a, $t); |
|
| 2529 | + }, |
|
| 2530 | + $tag |
|
| 2531 | + ); |
|
| 2532 | + |
|
| 2533 | + return $texte; |
|
| 2534 | + } |
|
| 2535 | + |
|
| 2536 | + if ( |
|
| 2537 | + preg_match( |
|
| 2538 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2539 | + $texte, |
|
| 2540 | + $regs |
|
| 2541 | + ) |
|
| 2542 | + ) { |
|
| 2543 | + return $regs[0]; |
|
| 2544 | + } |
|
| 2545 | 2545 | } |
| 2546 | 2546 | |
| 2547 | 2547 | /** |
@@ -2569,30 +2569,30 @@ discard block |
||
| 2569 | 2569 | * - Tableau de résultats, si tableau en entrée. |
| 2570 | 2570 | **/ |
| 2571 | 2571 | function extraire_balises($texte, $tag = 'a') { |
| 2572 | - if (is_array($texte)) { |
|
| 2573 | - array_walk( |
|
| 2574 | - $texte, |
|
| 2575 | - function (&$a, $key, $t) { |
|
| 2576 | - $a = extraire_balises($a, $t); |
|
| 2577 | - }, |
|
| 2578 | - $tag |
|
| 2579 | - ); |
|
| 2580 | - |
|
| 2581 | - return $texte; |
|
| 2582 | - } |
|
| 2583 | - |
|
| 2584 | - if ( |
|
| 2585 | - preg_match_all( |
|
| 2586 | - ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2587 | - $texte, |
|
| 2588 | - $regs, |
|
| 2589 | - PREG_PATTERN_ORDER |
|
| 2590 | - ) |
|
| 2591 | - ) { |
|
| 2592 | - return $regs[0]; |
|
| 2593 | - } else { |
|
| 2594 | - return []; |
|
| 2595 | - } |
|
| 2572 | + if (is_array($texte)) { |
|
| 2573 | + array_walk( |
|
| 2574 | + $texte, |
|
| 2575 | + function (&$a, $key, $t) { |
|
| 2576 | + $a = extraire_balises($a, $t); |
|
| 2577 | + }, |
|
| 2578 | + $tag |
|
| 2579 | + ); |
|
| 2580 | + |
|
| 2581 | + return $texte; |
|
| 2582 | + } |
|
| 2583 | + |
|
| 2584 | + if ( |
|
| 2585 | + preg_match_all( |
|
| 2586 | + ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2587 | + $texte, |
|
| 2588 | + $regs, |
|
| 2589 | + PREG_PATTERN_ORDER |
|
| 2590 | + ) |
|
| 2591 | + ) { |
|
| 2592 | + return $regs[0]; |
|
| 2593 | + } else { |
|
| 2594 | + return []; |
|
| 2595 | + } |
|
| 2596 | 2596 | } |
| 2597 | 2597 | |
| 2598 | 2598 | /** |
@@ -2621,11 +2621,11 @@ discard block |
||
| 2621 | 2621 | * - `$def` si on n'a pas transmis de tableau |
| 2622 | 2622 | **/ |
| 2623 | 2623 | function in_any($val, $vals, $def = '') { |
| 2624 | - if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2625 | - $vals = $v; |
|
| 2626 | - } |
|
| 2624 | + if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2625 | + $vals = $v; |
|
| 2626 | + } |
|
| 2627 | 2627 | |
| 2628 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2628 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2629 | 2629 | } |
| 2630 | 2630 | |
| 2631 | 2631 | |
@@ -2646,12 +2646,12 @@ discard block |
||
| 2646 | 2646 | * Résultat du calcul |
| 2647 | 2647 | **/ |
| 2648 | 2648 | function valeur_numerique($expr) { |
| 2649 | - $a = 0; |
|
| 2650 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2651 | - eval("\$a = $expr;"); |
|
| 2652 | - } |
|
| 2649 | + $a = 0; |
|
| 2650 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2651 | + eval("\$a = $expr;"); |
|
| 2652 | + } |
|
| 2653 | 2653 | |
| 2654 | - return intval($a); |
|
| 2654 | + return intval($a); |
|
| 2655 | 2655 | } |
| 2656 | 2656 | |
| 2657 | 2657 | /** |
@@ -2670,7 +2670,7 @@ discard block |
||
| 2670 | 2670 | * Retourne `$a*$b/$c` |
| 2671 | 2671 | **/ |
| 2672 | 2672 | function regledetrois($a, $b, $c) { |
| 2673 | - return round($a * $b / $c); |
|
| 2673 | + return round($a * $b / $c); |
|
| 2674 | 2674 | } |
| 2675 | 2675 | |
| 2676 | 2676 | |
@@ -2693,79 +2693,79 @@ discard block |
||
| 2693 | 2693 | * @return string Suite de champs input hidden |
| 2694 | 2694 | **/ |
| 2695 | 2695 | function form_hidden(?string $action = ''): string { |
| 2696 | - $action ??= ''; |
|
| 2697 | - |
|
| 2698 | - $contexte = []; |
|
| 2699 | - include_spip('inc/urls'); |
|
| 2700 | - if ( |
|
| 2701 | - $p = urls_decoder_url($action, '') |
|
| 2702 | - and reset($p) |
|
| 2703 | - ) { |
|
| 2704 | - $fond = array_shift($p); |
|
| 2705 | - if ($fond != '404') { |
|
| 2706 | - $contexte = array_shift($p); |
|
| 2707 | - $contexte['page'] = $fond; |
|
| 2708 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2709 | - } |
|
| 2710 | - } |
|
| 2711 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2712 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2713 | - unset($contexte['type']); |
|
| 2714 | - } |
|
| 2715 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2716 | - unset($contexte['type-page']); |
|
| 2717 | - } |
|
| 2718 | - |
|
| 2719 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2720 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2721 | - $values = []; |
|
| 2722 | - |
|
| 2723 | - // d'abord avec celles de l'url |
|
| 2724 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2725 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2726 | - $c = explode('=', $c, 2); |
|
| 2727 | - $var = array_shift($c); |
|
| 2728 | - $val = array_shift($c) ?? ''; |
|
| 2729 | - if ($var) { |
|
| 2730 | - $val = rawurldecode($val); |
|
| 2731 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2732 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2733 | - $values[] = [$var, $val]; |
|
| 2734 | - } else { |
|
| 2735 | - if (!isset($values[$var])) { |
|
| 2736 | - $values[$var] = [$var, $val]; |
|
| 2737 | - } |
|
| 2738 | - } |
|
| 2739 | - } |
|
| 2740 | - } |
|
| 2741 | - } |
|
| 2742 | - |
|
| 2743 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2744 | - foreach ($contexte as $var => $val) { |
|
| 2745 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2746 | - $values[] = [$var, $val]; |
|
| 2747 | - } else { |
|
| 2748 | - if (!isset($values[$var])) { |
|
| 2749 | - $values[$var] = [$var, $val]; |
|
| 2750 | - } |
|
| 2751 | - } |
|
| 2752 | - } |
|
| 2753 | - |
|
| 2754 | - // puis on rassemble le tout |
|
| 2755 | - $hidden = []; |
|
| 2756 | - foreach ($values as $value) { |
|
| 2757 | - [$var, $val] = $value; |
|
| 2758 | - $hidden[] = '<input name="' |
|
| 2759 | - . entites_html($var) |
|
| 2760 | - . '"' |
|
| 2761 | - . (is_null($val) |
|
| 2762 | - ? '' |
|
| 2763 | - : ' value="' . entites_html($val) . '"' |
|
| 2764 | - ) |
|
| 2765 | - . ' type="hidden"' . "\n/>"; |
|
| 2766 | - } |
|
| 2767 | - |
|
| 2768 | - return join('', $hidden); |
|
| 2696 | + $action ??= ''; |
|
| 2697 | + |
|
| 2698 | + $contexte = []; |
|
| 2699 | + include_spip('inc/urls'); |
|
| 2700 | + if ( |
|
| 2701 | + $p = urls_decoder_url($action, '') |
|
| 2702 | + and reset($p) |
|
| 2703 | + ) { |
|
| 2704 | + $fond = array_shift($p); |
|
| 2705 | + if ($fond != '404') { |
|
| 2706 | + $contexte = array_shift($p); |
|
| 2707 | + $contexte['page'] = $fond; |
|
| 2708 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2709 | + } |
|
| 2710 | + } |
|
| 2711 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2712 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2713 | + unset($contexte['type']); |
|
| 2714 | + } |
|
| 2715 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2716 | + unset($contexte['type-page']); |
|
| 2717 | + } |
|
| 2718 | + |
|
| 2719 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2720 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2721 | + $values = []; |
|
| 2722 | + |
|
| 2723 | + // d'abord avec celles de l'url |
|
| 2724 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2725 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2726 | + $c = explode('=', $c, 2); |
|
| 2727 | + $var = array_shift($c); |
|
| 2728 | + $val = array_shift($c) ?? ''; |
|
| 2729 | + if ($var) { |
|
| 2730 | + $val = rawurldecode($val); |
|
| 2731 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2732 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2733 | + $values[] = [$var, $val]; |
|
| 2734 | + } else { |
|
| 2735 | + if (!isset($values[$var])) { |
|
| 2736 | + $values[$var] = [$var, $val]; |
|
| 2737 | + } |
|
| 2738 | + } |
|
| 2739 | + } |
|
| 2740 | + } |
|
| 2741 | + } |
|
| 2742 | + |
|
| 2743 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2744 | + foreach ($contexte as $var => $val) { |
|
| 2745 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2746 | + $values[] = [$var, $val]; |
|
| 2747 | + } else { |
|
| 2748 | + if (!isset($values[$var])) { |
|
| 2749 | + $values[$var] = [$var, $val]; |
|
| 2750 | + } |
|
| 2751 | + } |
|
| 2752 | + } |
|
| 2753 | + |
|
| 2754 | + // puis on rassemble le tout |
|
| 2755 | + $hidden = []; |
|
| 2756 | + foreach ($values as $value) { |
|
| 2757 | + [$var, $val] = $value; |
|
| 2758 | + $hidden[] = '<input name="' |
|
| 2759 | + . entites_html($var) |
|
| 2760 | + . '"' |
|
| 2761 | + . (is_null($val) |
|
| 2762 | + ? '' |
|
| 2763 | + : ' value="' . entites_html($val) . '"' |
|
| 2764 | + ) |
|
| 2765 | + . ' type="hidden"' . "\n/>"; |
|
| 2766 | + } |
|
| 2767 | + |
|
| 2768 | + return join('', $hidden); |
|
| 2769 | 2769 | } |
| 2770 | 2770 | |
| 2771 | 2771 | |
@@ -2787,7 +2787,7 @@ discard block |
||
| 2787 | 2787 | * - la première valeur du tableau sinon. |
| 2788 | 2788 | **/ |
| 2789 | 2789 | function filtre_reset($array) { |
| 2790 | - return !is_array($array) ? null : reset($array); |
|
| 2790 | + return !is_array($array) ? null : reset($array); |
|
| 2791 | 2791 | } |
| 2792 | 2792 | |
| 2793 | 2793 | /** |
@@ -2808,7 +2808,7 @@ discard block |
||
| 2808 | 2808 | * - la dernière valeur du tableau sinon. |
| 2809 | 2809 | **/ |
| 2810 | 2810 | function filtre_end($array) { |
| 2811 | - return !is_array($array) ? null : end($array); |
|
| 2811 | + return !is_array($array) ? null : end($array); |
|
| 2812 | 2812 | } |
| 2813 | 2813 | |
| 2814 | 2814 | /** |
@@ -2828,11 +2828,11 @@ discard block |
||
| 2828 | 2828 | * |
| 2829 | 2829 | **/ |
| 2830 | 2830 | function filtre_push($array, $val) { |
| 2831 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2832 | - return ''; |
|
| 2833 | - } |
|
| 2831 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2832 | + return ''; |
|
| 2833 | + } |
|
| 2834 | 2834 | |
| 2835 | - return $array; |
|
| 2835 | + return $array; |
|
| 2836 | 2836 | } |
| 2837 | 2837 | |
| 2838 | 2838 | /** |
@@ -2851,7 +2851,7 @@ discard block |
||
| 2851 | 2851 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2852 | 2852 | **/ |
| 2853 | 2853 | function filtre_find($array, $val) { |
| 2854 | - return (is_array($array) and in_array($val, $array)); |
|
| 2854 | + return (is_array($array) and in_array($val, $array)); |
|
| 2855 | 2855 | } |
| 2856 | 2856 | |
| 2857 | 2857 | |
@@ -2868,13 +2868,13 @@ discard block |
||
| 2868 | 2868 | * Contenu avec urls en absolus |
| 2869 | 2869 | **/ |
| 2870 | 2870 | function urls_absolues_css($contenu, $source) { |
| 2871 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2871 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2872 | 2872 | |
| 2873 | - return preg_replace_callback( |
|
| 2874 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2875 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2876 | - $contenu |
|
| 2877 | - ); |
|
| 2873 | + return preg_replace_callback( |
|
| 2874 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2875 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2876 | + $contenu |
|
| 2877 | + ); |
|
| 2878 | 2878 | } |
| 2879 | 2879 | |
| 2880 | 2880 | |
@@ -2903,119 +2903,119 @@ discard block |
||
| 2903 | 2903 | * Chemin du fichier CSS inversé |
| 2904 | 2904 | **/ |
| 2905 | 2905 | function direction_css($css, $voulue = '') { |
| 2906 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2907 | - return $css; |
|
| 2908 | - } |
|
| 2909 | - include_spip('inc/lang'); |
|
| 2910 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2911 | - if ($voulue = strtolower($voulue)) { |
|
| 2912 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2913 | - $voulue = lang_dir($voulue); |
|
| 2914 | - } |
|
| 2915 | - } else { |
|
| 2916 | - $voulue = lang_dir(); |
|
| 2917 | - } |
|
| 2918 | - |
|
| 2919 | - $r = count($r) > 1; |
|
| 2920 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2921 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2922 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2923 | - |
|
| 2924 | - if ($voulue == $dir) { |
|
| 2925 | - return $css; |
|
| 2926 | - } |
|
| 2927 | - |
|
| 2928 | - if ( |
|
| 2929 | - // url absolue |
|
| 2930 | - preg_match(',^https?:,i', $css) |
|
| 2931 | - // ou qui contient un ? |
|
| 2932 | - or (($p = strpos($css, '?')) !== false) |
|
| 2933 | - ) { |
|
| 2934 | - $distant = true; |
|
| 2935 | - $cssf = parse_url($css); |
|
| 2936 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2937 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2938 | - } else { |
|
| 2939 | - $distant = false; |
|
| 2940 | - $cssf = $css; |
|
| 2941 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2942 | - //propose (rien a faire dans ce cas) |
|
| 2943 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2944 | - if (@file_exists($f)) { |
|
| 2945 | - return $f; |
|
| 2946 | - } |
|
| 2947 | - } |
|
| 2948 | - |
|
| 2949 | - // 2. |
|
| 2950 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2951 | - $f = $dir_var |
|
| 2952 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2953 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2954 | - |
|
| 2955 | - // la css peut etre distante (url absolue !) |
|
| 2956 | - if ($distant) { |
|
| 2957 | - include_spip('inc/distant'); |
|
| 2958 | - $res = recuperer_url($css); |
|
| 2959 | - if (!$res or !$contenu = $res['page']) { |
|
| 2960 | - return $css; |
|
| 2961 | - } |
|
| 2962 | - } else { |
|
| 2963 | - if ( |
|
| 2964 | - (@filemtime($f) > @filemtime($css)) |
|
| 2965 | - and (_VAR_MODE != 'recalcul') |
|
| 2966 | - ) { |
|
| 2967 | - return $f; |
|
| 2968 | - } |
|
| 2969 | - if (!lire_fichier($css, $contenu)) { |
|
| 2970 | - return $css; |
|
| 2971 | - } |
|
| 2972 | - } |
|
| 2973 | - |
|
| 2974 | - |
|
| 2975 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2976 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 2977 | - $parser = new csstidy(); |
|
| 2978 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 2979 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 2980 | - $parser->parse($contenu); |
|
| 2981 | - |
|
| 2982 | - $contenu = $parser->print->plain(); |
|
| 2983 | - |
|
| 2984 | - |
|
| 2985 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 2986 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2987 | - $src = []; |
|
| 2988 | - $src_direction_css = []; |
|
| 2989 | - $src_faux_abs = []; |
|
| 2990 | - $d = dirname($css); |
|
| 2991 | - foreach ($regs[1] as $k => $import_css) { |
|
| 2992 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2993 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2994 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2995 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2996 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2997 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2998 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2999 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3000 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3001 | - } |
|
| 3002 | - $src[] = $regs[0][$k]; |
|
| 3003 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3004 | - } |
|
| 3005 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3006 | - |
|
| 3007 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3008 | - |
|
| 3009 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 3010 | - if (count($src_faux_abs)) { |
|
| 3011 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3012 | - } |
|
| 3013 | - |
|
| 3014 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3015 | - return $css; |
|
| 3016 | - } |
|
| 3017 | - |
|
| 3018 | - return $f; |
|
| 2906 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2907 | + return $css; |
|
| 2908 | + } |
|
| 2909 | + include_spip('inc/lang'); |
|
| 2910 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2911 | + if ($voulue = strtolower($voulue)) { |
|
| 2912 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2913 | + $voulue = lang_dir($voulue); |
|
| 2914 | + } |
|
| 2915 | + } else { |
|
| 2916 | + $voulue = lang_dir(); |
|
| 2917 | + } |
|
| 2918 | + |
|
| 2919 | + $r = count($r) > 1; |
|
| 2920 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2921 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2922 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2923 | + |
|
| 2924 | + if ($voulue == $dir) { |
|
| 2925 | + return $css; |
|
| 2926 | + } |
|
| 2927 | + |
|
| 2928 | + if ( |
|
| 2929 | + // url absolue |
|
| 2930 | + preg_match(',^https?:,i', $css) |
|
| 2931 | + // ou qui contient un ? |
|
| 2932 | + or (($p = strpos($css, '?')) !== false) |
|
| 2933 | + ) { |
|
| 2934 | + $distant = true; |
|
| 2935 | + $cssf = parse_url($css); |
|
| 2936 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2937 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2938 | + } else { |
|
| 2939 | + $distant = false; |
|
| 2940 | + $cssf = $css; |
|
| 2941 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2942 | + //propose (rien a faire dans ce cas) |
|
| 2943 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2944 | + if (@file_exists($f)) { |
|
| 2945 | + return $f; |
|
| 2946 | + } |
|
| 2947 | + } |
|
| 2948 | + |
|
| 2949 | + // 2. |
|
| 2950 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2951 | + $f = $dir_var |
|
| 2952 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2953 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2954 | + |
|
| 2955 | + // la css peut etre distante (url absolue !) |
|
| 2956 | + if ($distant) { |
|
| 2957 | + include_spip('inc/distant'); |
|
| 2958 | + $res = recuperer_url($css); |
|
| 2959 | + if (!$res or !$contenu = $res['page']) { |
|
| 2960 | + return $css; |
|
| 2961 | + } |
|
| 2962 | + } else { |
|
| 2963 | + if ( |
|
| 2964 | + (@filemtime($f) > @filemtime($css)) |
|
| 2965 | + and (_VAR_MODE != 'recalcul') |
|
| 2966 | + ) { |
|
| 2967 | + return $f; |
|
| 2968 | + } |
|
| 2969 | + if (!lire_fichier($css, $contenu)) { |
|
| 2970 | + return $css; |
|
| 2971 | + } |
|
| 2972 | + } |
|
| 2973 | + |
|
| 2974 | + |
|
| 2975 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2976 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 2977 | + $parser = new csstidy(); |
|
| 2978 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 2979 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 2980 | + $parser->parse($contenu); |
|
| 2981 | + |
|
| 2982 | + $contenu = $parser->print->plain(); |
|
| 2983 | + |
|
| 2984 | + |
|
| 2985 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 2986 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2987 | + $src = []; |
|
| 2988 | + $src_direction_css = []; |
|
| 2989 | + $src_faux_abs = []; |
|
| 2990 | + $d = dirname($css); |
|
| 2991 | + foreach ($regs[1] as $k => $import_css) { |
|
| 2992 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2993 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2994 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2995 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2996 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2997 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2998 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2999 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3000 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3001 | + } |
|
| 3002 | + $src[] = $regs[0][$k]; |
|
| 3003 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3004 | + } |
|
| 3005 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3006 | + |
|
| 3007 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3008 | + |
|
| 3009 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 3010 | + if (count($src_faux_abs)) { |
|
| 3011 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3012 | + } |
|
| 3013 | + |
|
| 3014 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3015 | + return $css; |
|
| 3016 | + } |
|
| 3017 | + |
|
| 3018 | + return $f; |
|
| 3019 | 3019 | } |
| 3020 | 3020 | |
| 3021 | 3021 | |
@@ -3038,46 +3038,46 @@ discard block |
||
| 3038 | 3038 | * - Chemin ou URL du fichier CSS source sinon. |
| 3039 | 3039 | **/ |
| 3040 | 3040 | function url_absolue_css($css) { |
| 3041 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3042 | - return $css; |
|
| 3043 | - } |
|
| 3041 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3042 | + return $css; |
|
| 3043 | + } |
|
| 3044 | 3044 | |
| 3045 | - $url_absolue_css = url_absolue($css); |
|
| 3045 | + $url_absolue_css = url_absolue($css); |
|
| 3046 | 3046 | |
| 3047 | - $f = basename($css, '.css'); |
|
| 3048 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3049 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3050 | - . '.css'; |
|
| 3047 | + $f = basename($css, '.css'); |
|
| 3048 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3049 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3050 | + . '.css'; |
|
| 3051 | 3051 | |
| 3052 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3053 | - return $f; |
|
| 3054 | - } |
|
| 3052 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3053 | + return $f; |
|
| 3054 | + } |
|
| 3055 | 3055 | |
| 3056 | - if ($url_absolue_css == $css) { |
|
| 3057 | - if ( |
|
| 3058 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3059 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3060 | - ) { |
|
| 3061 | - include_spip('inc/distant'); |
|
| 3062 | - $contenu = recuperer_url($css); |
|
| 3063 | - $contenu = $contenu['page'] ?? ''; |
|
| 3064 | - if (!$contenu) { |
|
| 3065 | - return $css; |
|
| 3066 | - } |
|
| 3067 | - } |
|
| 3068 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3069 | - return $css; |
|
| 3070 | - } |
|
| 3056 | + if ($url_absolue_css == $css) { |
|
| 3057 | + if ( |
|
| 3058 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3059 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3060 | + ) { |
|
| 3061 | + include_spip('inc/distant'); |
|
| 3062 | + $contenu = recuperer_url($css); |
|
| 3063 | + $contenu = $contenu['page'] ?? ''; |
|
| 3064 | + if (!$contenu) { |
|
| 3065 | + return $css; |
|
| 3066 | + } |
|
| 3067 | + } |
|
| 3068 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3069 | + return $css; |
|
| 3070 | + } |
|
| 3071 | 3071 | |
| 3072 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3073 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3072 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3073 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3074 | 3074 | |
| 3075 | - // ecrire la css |
|
| 3076 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3077 | - return $css; |
|
| 3078 | - } |
|
| 3075 | + // ecrire la css |
|
| 3076 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3077 | + return $css; |
|
| 3078 | + } |
|
| 3079 | 3079 | |
| 3080 | - return $f; |
|
| 3080 | + return $f; |
|
| 3081 | 3081 | } |
| 3082 | 3082 | |
| 3083 | 3083 | |
@@ -3111,24 +3111,24 @@ discard block |
||
| 3111 | 3111 | * Valeur trouvée ou valeur par défaut. |
| 3112 | 3112 | **/ |
| 3113 | 3113 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3114 | - foreach (explode('/', $cle) as $k) { |
|
| 3115 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3114 | + foreach (explode('/', $cle) as $k) { |
|
| 3115 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3116 | 3116 | |
| 3117 | - if (is_object($table)) { |
|
| 3118 | - $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3119 | - } elseif (is_array($table)) { |
|
| 3120 | - if ($conserver_null) { |
|
| 3121 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3122 | - } else { |
|
| 3123 | - $table = ($table[$k] ?? $defaut); |
|
| 3124 | - } |
|
| 3125 | - } else { |
|
| 3126 | - $table = $defaut; |
|
| 3127 | - break; |
|
| 3128 | - } |
|
| 3129 | - } |
|
| 3117 | + if (is_object($table)) { |
|
| 3118 | + $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3119 | + } elseif (is_array($table)) { |
|
| 3120 | + if ($conserver_null) { |
|
| 3121 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3122 | + } else { |
|
| 3123 | + $table = ($table[$k] ?? $defaut); |
|
| 3124 | + } |
|
| 3125 | + } else { |
|
| 3126 | + $table = $defaut; |
|
| 3127 | + break; |
|
| 3128 | + } |
|
| 3129 | + } |
|
| 3130 | 3130 | |
| 3131 | - return $table; |
|
| 3131 | + return $table; |
|
| 3132 | 3132 | } |
| 3133 | 3133 | |
| 3134 | 3134 | /** |
@@ -3161,22 +3161,22 @@ discard block |
||
| 3161 | 3161 | * - string : expression trouvée. |
| 3162 | 3162 | **/ |
| 3163 | 3163 | function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) { |
| 3164 | - if (intval($modif) and $capte == 0) { |
|
| 3165 | - $capte = $modif; |
|
| 3166 | - $modif = 'UuimsS'; |
|
| 3167 | - } |
|
| 3168 | - $expression = str_replace('\/', '/', $expression); |
|
| 3169 | - $expression = str_replace('/', '\/', $expression); |
|
| 3164 | + if (intval($modif) and $capte == 0) { |
|
| 3165 | + $capte = $modif; |
|
| 3166 | + $modif = 'UuimsS'; |
|
| 3167 | + } |
|
| 3168 | + $expression = str_replace('\/', '/', $expression); |
|
| 3169 | + $expression = str_replace('/', '\/', $expression); |
|
| 3170 | 3170 | |
| 3171 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3172 | - if (isset($r[$capte])) { |
|
| 3173 | - return $r[$capte]; |
|
| 3174 | - } else { |
|
| 3175 | - return true; |
|
| 3176 | - } |
|
| 3177 | - } |
|
| 3171 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3172 | + if (isset($r[$capte])) { |
|
| 3173 | + return $r[$capte]; |
|
| 3174 | + } else { |
|
| 3175 | + return true; |
|
| 3176 | + } |
|
| 3177 | + } |
|
| 3178 | 3178 | |
| 3179 | - return false; |
|
| 3179 | + return false; |
|
| 3180 | 3180 | } |
| 3181 | 3181 | |
| 3182 | 3182 | |
@@ -3203,10 +3203,10 @@ discard block |
||
| 3203 | 3203 | * Texte |
| 3204 | 3204 | **/ |
| 3205 | 3205 | function replace($texte, $expression, $replace = '', $modif = 'UimsS') { |
| 3206 | - $expression = str_replace('\/', '/', $expression); |
|
| 3207 | - $expression = str_replace('/', '\/', $expression); |
|
| 3206 | + $expression = str_replace('\/', '/', $expression); |
|
| 3207 | + $expression = str_replace('/', '\/', $expression); |
|
| 3208 | 3208 | |
| 3209 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3209 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3210 | 3210 | } |
| 3211 | 3211 | |
| 3212 | 3212 | |
@@ -3224,25 +3224,25 @@ discard block |
||
| 3224 | 3224 | **/ |
| 3225 | 3225 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3226 | 3226 | |
| 3227 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3228 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3227 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3228 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3229 | 3229 | |
| 3230 | - if ( |
|
| 3231 | - strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3232 | - and preg_match_all( |
|
| 3233 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3234 | - $t, |
|
| 3235 | - $matches, |
|
| 3236 | - PREG_PATTERN_ORDER |
|
| 3237 | - ) |
|
| 3238 | - ) { |
|
| 3239 | - if (!isset($doublons['documents'])) { |
|
| 3240 | - $doublons['documents'] = ''; |
|
| 3241 | - } |
|
| 3242 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3243 | - } |
|
| 3230 | + if ( |
|
| 3231 | + strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3232 | + and preg_match_all( |
|
| 3233 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3234 | + $t, |
|
| 3235 | + $matches, |
|
| 3236 | + PREG_PATTERN_ORDER |
|
| 3237 | + ) |
|
| 3238 | + ) { |
|
| 3239 | + if (!isset($doublons['documents'])) { |
|
| 3240 | + $doublons['documents'] = ''; |
|
| 3241 | + } |
|
| 3242 | + $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3243 | + } |
|
| 3244 | 3244 | |
| 3245 | - return $letexte; |
|
| 3245 | + return $letexte; |
|
| 3246 | 3246 | } |
| 3247 | 3247 | |
| 3248 | 3248 | /** |
@@ -3256,7 +3256,7 @@ discard block |
||
| 3256 | 3256 | * @return string Chaîne vide |
| 3257 | 3257 | **/ |
| 3258 | 3258 | function vide($texte) { |
| 3259 | - return ''; |
|
| 3259 | + return ''; |
|
| 3260 | 3260 | } |
| 3261 | 3261 | |
| 3262 | 3262 | // |
@@ -3285,23 +3285,23 @@ discard block |
||
| 3285 | 3285 | * Code HTML résultant |
| 3286 | 3286 | **/ |
| 3287 | 3287 | function env_to_params($env, $ignore_params = []) { |
| 3288 | - $ignore_params = array_merge( |
|
| 3289 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3290 | - $ignore_params |
|
| 3291 | - ); |
|
| 3292 | - if (!is_array($env)) { |
|
| 3293 | - $env = unserialize($env); |
|
| 3294 | - } |
|
| 3295 | - $texte = ''; |
|
| 3296 | - if ($env) { |
|
| 3297 | - foreach ($env as $i => $j) { |
|
| 3298 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3299 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3300 | - } |
|
| 3301 | - } |
|
| 3302 | - } |
|
| 3303 | - |
|
| 3304 | - return $texte; |
|
| 3288 | + $ignore_params = array_merge( |
|
| 3289 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3290 | + $ignore_params |
|
| 3291 | + ); |
|
| 3292 | + if (!is_array($env)) { |
|
| 3293 | + $env = unserialize($env); |
|
| 3294 | + } |
|
| 3295 | + $texte = ''; |
|
| 3296 | + if ($env) { |
|
| 3297 | + foreach ($env as $i => $j) { |
|
| 3298 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3299 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3300 | + } |
|
| 3301 | + } |
|
| 3302 | + } |
|
| 3303 | + |
|
| 3304 | + return $texte; |
|
| 3305 | 3305 | } |
| 3306 | 3306 | |
| 3307 | 3307 | /** |
@@ -3324,23 +3324,23 @@ discard block |
||
| 3324 | 3324 | * Code HTML résultant |
| 3325 | 3325 | **/ |
| 3326 | 3326 | function env_to_attributs($env, $ignore_params = []) { |
| 3327 | - $ignore_params = array_merge( |
|
| 3328 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3329 | - $ignore_params |
|
| 3330 | - ); |
|
| 3331 | - if (!is_array($env)) { |
|
| 3332 | - $env = unserialize($env); |
|
| 3333 | - } |
|
| 3334 | - $texte = ''; |
|
| 3335 | - if ($env) { |
|
| 3336 | - foreach ($env as $i => $j) { |
|
| 3337 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3338 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3339 | - } |
|
| 3340 | - } |
|
| 3341 | - } |
|
| 3327 | + $ignore_params = array_merge( |
|
| 3328 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3329 | + $ignore_params |
|
| 3330 | + ); |
|
| 3331 | + if (!is_array($env)) { |
|
| 3332 | + $env = unserialize($env); |
|
| 3333 | + } |
|
| 3334 | + $texte = ''; |
|
| 3335 | + if ($env) { |
|
| 3336 | + foreach ($env as $i => $j) { |
|
| 3337 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3338 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3339 | + } |
|
| 3340 | + } |
|
| 3341 | + } |
|
| 3342 | 3342 | |
| 3343 | - return $texte; |
|
| 3343 | + return $texte; |
|
| 3344 | 3344 | } |
| 3345 | 3345 | |
| 3346 | 3346 | |
@@ -3358,7 +3358,7 @@ discard block |
||
| 3358 | 3358 | * @return string Chaînes concaténés |
| 3359 | 3359 | **/ |
| 3360 | 3360 | function concat(...$args): string { |
| 3361 | - return join('', $args); |
|
| 3361 | + return join('', $args); |
|
| 3362 | 3362 | } |
| 3363 | 3363 | |
| 3364 | 3364 | |
@@ -3378,23 +3378,23 @@ discard block |
||
| 3378 | 3378 | * Contenu du ou des fichiers, concaténé |
| 3379 | 3379 | **/ |
| 3380 | 3380 | function charge_scripts($files, $script = true) { |
| 3381 | - $flux = ''; |
|
| 3382 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3383 | - if (!is_string($file)) { |
|
| 3384 | - continue; |
|
| 3385 | - } |
|
| 3386 | - if ($script) { |
|
| 3387 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3388 | - } |
|
| 3389 | - if ($file) { |
|
| 3390 | - $path = find_in_path($file); |
|
| 3391 | - if ($path) { |
|
| 3392 | - $flux .= spip_file_get_contents($path); |
|
| 3393 | - } |
|
| 3394 | - } |
|
| 3395 | - } |
|
| 3396 | - |
|
| 3397 | - return $flux; |
|
| 3381 | + $flux = ''; |
|
| 3382 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3383 | + if (!is_string($file)) { |
|
| 3384 | + continue; |
|
| 3385 | + } |
|
| 3386 | + if ($script) { |
|
| 3387 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3388 | + } |
|
| 3389 | + if ($file) { |
|
| 3390 | + $path = find_in_path($file); |
|
| 3391 | + if ($path) { |
|
| 3392 | + $flux .= spip_file_get_contents($path); |
|
| 3393 | + } |
|
| 3394 | + } |
|
| 3395 | + } |
|
| 3396 | + |
|
| 3397 | + return $flux; |
|
| 3398 | 3398 | } |
| 3399 | 3399 | |
| 3400 | 3400 | /** |
@@ -3405,22 +3405,22 @@ discard block |
||
| 3405 | 3405 | * @return string |
| 3406 | 3406 | */ |
| 3407 | 3407 | function http_img_variante_svg_si_possible($img_file) { |
| 3408 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3409 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3410 | - if ( |
|
| 3411 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3412 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3413 | - and file_exists($variante_svg_generique) |
|
| 3414 | - ) { |
|
| 3415 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3416 | - $img_file = $variante_svg_size; |
|
| 3417 | - } |
|
| 3418 | - else { |
|
| 3419 | - $img_file = $variante_svg_generique; |
|
| 3420 | - } |
|
| 3421 | - } |
|
| 3408 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3409 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3410 | + if ( |
|
| 3411 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3412 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3413 | + and file_exists($variante_svg_generique) |
|
| 3414 | + ) { |
|
| 3415 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3416 | + $img_file = $variante_svg_size; |
|
| 3417 | + } |
|
| 3418 | + else { |
|
| 3419 | + $img_file = $variante_svg_generique; |
|
| 3420 | + } |
|
| 3421 | + } |
|
| 3422 | 3422 | |
| 3423 | - return $img_file; |
|
| 3423 | + return $img_file; |
|
| 3424 | 3424 | } |
| 3425 | 3425 | |
| 3426 | 3426 | /** |
@@ -3441,54 +3441,54 @@ discard block |
||
| 3441 | 3441 | */ |
| 3442 | 3442 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3443 | 3443 | |
| 3444 | - $img_file = $img; |
|
| 3445 | - if ($p = strpos($img_file, '?')) { |
|
| 3446 | - $img_file = substr($img_file, 0, $p); |
|
| 3447 | - } |
|
| 3448 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3449 | - $img_file = chemin_image($img); |
|
| 3450 | - } |
|
| 3451 | - else { |
|
| 3452 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3453 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3454 | - } |
|
| 3455 | - } |
|
| 3456 | - if (stripos($atts, 'width') === false) { |
|
| 3457 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3458 | - if ( |
|
| 3459 | - (!isset($options['utiliser_suffixe_size']) |
|
| 3460 | - or $options['utiliser_suffixe_size'] == true |
|
| 3461 | - or strpos($img_file, '-xx.svg') !== false) |
|
| 3462 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3463 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3464 | - ) { |
|
| 3465 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3466 | - } else { |
|
| 3467 | - $taille = taille_image($img_file); |
|
| 3468 | - [$hauteur, $largeur] = $taille; |
|
| 3469 | - if (!$hauteur or !$largeur) { |
|
| 3470 | - return ''; |
|
| 3471 | - } |
|
| 3472 | - } |
|
| 3473 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3474 | - } |
|
| 3475 | - |
|
| 3476 | - if (file_exists($img_file)) { |
|
| 3477 | - $img_file = timestamp($img_file); |
|
| 3478 | - } |
|
| 3479 | - if ($alt === false) { |
|
| 3480 | - $alt = ''; |
|
| 3481 | - } |
|
| 3482 | - elseif ($alt or $alt === '') { |
|
| 3483 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3484 | - } |
|
| 3485 | - else { |
|
| 3486 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3487 | - } |
|
| 3488 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3489 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3490 | - . ' ' . ltrim($atts) |
|
| 3491 | - . ' />'; |
|
| 3444 | + $img_file = $img; |
|
| 3445 | + if ($p = strpos($img_file, '?')) { |
|
| 3446 | + $img_file = substr($img_file, 0, $p); |
|
| 3447 | + } |
|
| 3448 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3449 | + $img_file = chemin_image($img); |
|
| 3450 | + } |
|
| 3451 | + else { |
|
| 3452 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3453 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3454 | + } |
|
| 3455 | + } |
|
| 3456 | + if (stripos($atts, 'width') === false) { |
|
| 3457 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3458 | + if ( |
|
| 3459 | + (!isset($options['utiliser_suffixe_size']) |
|
| 3460 | + or $options['utiliser_suffixe_size'] == true |
|
| 3461 | + or strpos($img_file, '-xx.svg') !== false) |
|
| 3462 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3463 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3464 | + ) { |
|
| 3465 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3466 | + } else { |
|
| 3467 | + $taille = taille_image($img_file); |
|
| 3468 | + [$hauteur, $largeur] = $taille; |
|
| 3469 | + if (!$hauteur or !$largeur) { |
|
| 3470 | + return ''; |
|
| 3471 | + } |
|
| 3472 | + } |
|
| 3473 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3474 | + } |
|
| 3475 | + |
|
| 3476 | + if (file_exists($img_file)) { |
|
| 3477 | + $img_file = timestamp($img_file); |
|
| 3478 | + } |
|
| 3479 | + if ($alt === false) { |
|
| 3480 | + $alt = ''; |
|
| 3481 | + } |
|
| 3482 | + elseif ($alt or $alt === '') { |
|
| 3483 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3484 | + } |
|
| 3485 | + else { |
|
| 3486 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3487 | + } |
|
| 3488 | + return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3489 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3490 | + . ' ' . ltrim($atts) |
|
| 3491 | + . ' />'; |
|
| 3492 | 3492 | } |
| 3493 | 3493 | |
| 3494 | 3494 | /** |
@@ -3500,70 +3500,70 @@ discard block |
||
| 3500 | 3500 | * @return string |
| 3501 | 3501 | */ |
| 3502 | 3502 | function http_style_background($img, $att = '', $size = null) { |
| 3503 | - if ($size and is_numeric($size)) { |
|
| 3504 | - $size = trim($size) . 'px'; |
|
| 3505 | - } |
|
| 3506 | - return " style='background" . |
|
| 3507 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3508 | - . ($size ? "background-size:{$size};" : '') |
|
| 3509 | - . "'"; |
|
| 3503 | + if ($size and is_numeric($size)) { |
|
| 3504 | + $size = trim($size) . 'px'; |
|
| 3505 | + } |
|
| 3506 | + return " style='background" . |
|
| 3507 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3508 | + . ($size ? "background-size:{$size};" : '') |
|
| 3509 | + . "'"; |
|
| 3510 | 3510 | } |
| 3511 | 3511 | |
| 3512 | 3512 | |
| 3513 | 3513 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3514 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3515 | - while (is_null(end($args)) and count($args)) { |
|
| 3516 | - array_pop($args); |
|
| 3517 | - } |
|
| 3518 | - if (!count($args)) { |
|
| 3519 | - return [null, null, null]; |
|
| 3520 | - } |
|
| 3521 | - if (count($args) < 3) { |
|
| 3522 | - $maybe_size = array_pop($args); |
|
| 3523 | - // @2x |
|
| 3524 | - // @1.5x |
|
| 3525 | - // 512 |
|
| 3526 | - // 512x* |
|
| 3527 | - // 512x300 |
|
| 3528 | - if ( |
|
| 3529 | - !strlen($maybe_size) |
|
| 3530 | - or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3531 | - ) { |
|
| 3532 | - $args[] = $maybe_size; |
|
| 3533 | - $maybe_size = null; |
|
| 3534 | - } |
|
| 3535 | - while (count($args) < 2) { |
|
| 3536 | - $args[] = null; // default alt or class |
|
| 3537 | - } |
|
| 3538 | - $args[] = $maybe_size; |
|
| 3539 | - } |
|
| 3540 | - return $args; |
|
| 3514 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3515 | + while (is_null(end($args)) and count($args)) { |
|
| 3516 | + array_pop($args); |
|
| 3517 | + } |
|
| 3518 | + if (!count($args)) { |
|
| 3519 | + return [null, null, null]; |
|
| 3520 | + } |
|
| 3521 | + if (count($args) < 3) { |
|
| 3522 | + $maybe_size = array_pop($args); |
|
| 3523 | + // @2x |
|
| 3524 | + // @1.5x |
|
| 3525 | + // 512 |
|
| 3526 | + // 512x* |
|
| 3527 | + // 512x300 |
|
| 3528 | + if ( |
|
| 3529 | + !strlen($maybe_size) |
|
| 3530 | + or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3531 | + ) { |
|
| 3532 | + $args[] = $maybe_size; |
|
| 3533 | + $maybe_size = null; |
|
| 3534 | + } |
|
| 3535 | + while (count($args) < 2) { |
|
| 3536 | + $args[] = null; // default alt or class |
|
| 3537 | + } |
|
| 3538 | + $args[] = $maybe_size; |
|
| 3539 | + } |
|
| 3540 | + return $args; |
|
| 3541 | 3541 | } |
| 3542 | 3542 | |
| 3543 | 3543 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3544 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3545 | - if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3546 | - $coef = floatval(substr($size, 1, -1)); |
|
| 3547 | - [$h, $w] = taille_image($img); |
|
| 3548 | - $height = intval(round($h / $coef)); |
|
| 3549 | - $width = intval(round($w / $coef)); |
|
| 3550 | - } |
|
| 3551 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3552 | - else { |
|
| 3553 | - $size = explode('x', $size, 2); |
|
| 3554 | - $size = array_map('trim', $size); |
|
| 3555 | - $height = $width = intval(array_shift($size)); |
|
| 3556 | - |
|
| 3557 | - if (count($size) and reset($size)) { |
|
| 3558 | - $height = array_shift($size); |
|
| 3559 | - if ($height === '*') { |
|
| 3560 | - [$h, $w] = taille_image($img); |
|
| 3561 | - $height = intval(round($h * $width / $w)); |
|
| 3562 | - } |
|
| 3563 | - } |
|
| 3564 | - } |
|
| 3565 | - |
|
| 3566 | - return [$width, $height]; |
|
| 3544 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3545 | + if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3546 | + $coef = floatval(substr($size, 1, -1)); |
|
| 3547 | + [$h, $w] = taille_image($img); |
|
| 3548 | + $height = intval(round($h / $coef)); |
|
| 3549 | + $width = intval(round($w / $coef)); |
|
| 3550 | + } |
|
| 3551 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3552 | + else { |
|
| 3553 | + $size = explode('x', $size, 2); |
|
| 3554 | + $size = array_map('trim', $size); |
|
| 3555 | + $height = $width = intval(array_shift($size)); |
|
| 3556 | + |
|
| 3557 | + if (count($size) and reset($size)) { |
|
| 3558 | + $height = array_shift($size); |
|
| 3559 | + if ($height === '*') { |
|
| 3560 | + [$h, $w] = taille_image($img); |
|
| 3561 | + $height = intval(round($h * $width / $w)); |
|
| 3562 | + } |
|
| 3563 | + } |
|
| 3564 | + } |
|
| 3565 | + |
|
| 3566 | + return [$width, $height]; |
|
| 3567 | 3567 | } |
| 3568 | 3568 | |
| 3569 | 3569 | /** |
@@ -3599,43 +3599,43 @@ discard block |
||
| 3599 | 3599 | */ |
| 3600 | 3600 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3601 | 3601 | |
| 3602 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3603 | - |
|
| 3604 | - $img = trim((string) $img); |
|
| 3605 | - if (strpos($img, '<img') === 0) { |
|
| 3606 | - if (!is_null($alt)) { |
|
| 3607 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3608 | - } |
|
| 3609 | - if (!is_null($class)) { |
|
| 3610 | - if (strlen($class)) { |
|
| 3611 | - $img = inserer_attribut($img, 'class', $class); |
|
| 3612 | - } |
|
| 3613 | - else { |
|
| 3614 | - $img = vider_attribut($img, 'class'); |
|
| 3615 | - } |
|
| 3616 | - } |
|
| 3617 | - } |
|
| 3618 | - else { |
|
| 3619 | - $img = http_img_pack( |
|
| 3620 | - $img, |
|
| 3621 | - $alt, |
|
| 3622 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3623 | - '', |
|
| 3624 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3625 | - ); |
|
| 3626 | - if (is_null($alt)) { |
|
| 3627 | - $img = vider_attribut($img, 'alt'); |
|
| 3628 | - } |
|
| 3629 | - } |
|
| 3630 | - |
|
| 3631 | - if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3632 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3633 | - |
|
| 3634 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3635 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3636 | - } |
|
| 3637 | - |
|
| 3638 | - return $img; |
|
| 3602 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3603 | + |
|
| 3604 | + $img = trim((string) $img); |
|
| 3605 | + if (strpos($img, '<img') === 0) { |
|
| 3606 | + if (!is_null($alt)) { |
|
| 3607 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3608 | + } |
|
| 3609 | + if (!is_null($class)) { |
|
| 3610 | + if (strlen($class)) { |
|
| 3611 | + $img = inserer_attribut($img, 'class', $class); |
|
| 3612 | + } |
|
| 3613 | + else { |
|
| 3614 | + $img = vider_attribut($img, 'class'); |
|
| 3615 | + } |
|
| 3616 | + } |
|
| 3617 | + } |
|
| 3618 | + else { |
|
| 3619 | + $img = http_img_pack( |
|
| 3620 | + $img, |
|
| 3621 | + $alt, |
|
| 3622 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3623 | + '', |
|
| 3624 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3625 | + ); |
|
| 3626 | + if (is_null($alt)) { |
|
| 3627 | + $img = vider_attribut($img, 'alt'); |
|
| 3628 | + } |
|
| 3629 | + } |
|
| 3630 | + |
|
| 3631 | + if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3632 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3633 | + |
|
| 3634 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3635 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3636 | + } |
|
| 3637 | + |
|
| 3638 | + return $img; |
|
| 3639 | 3639 | } |
| 3640 | 3640 | |
| 3641 | 3641 | |
@@ -3669,80 +3669,80 @@ discard block |
||
| 3669 | 3669 | */ |
| 3670 | 3670 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3671 | 3671 | |
| 3672 | - $svg = null; |
|
| 3673 | - $img = trim($img); |
|
| 3674 | - $img_file = $img; |
|
| 3675 | - if (strpos($img, '<svg') === false) { |
|
| 3676 | - if ($p = strpos($img_file, '?')) { |
|
| 3677 | - $img_file = substr($img_file, 0, $p); |
|
| 3678 | - } |
|
| 3679 | - |
|
| 3680 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3681 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3682 | - if (tester_url_absolue($img_file)) { |
|
| 3683 | - include_spip('inc/distant'); |
|
| 3684 | - $fichier = copie_locale($img_file); |
|
| 3685 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3686 | - } |
|
| 3687 | - |
|
| 3688 | - if ( |
|
| 3689 | - !$img_file |
|
| 3690 | - or !file_exists($img_file) |
|
| 3691 | - or !$svg = file_get_contents($img_file) |
|
| 3692 | - ) { |
|
| 3693 | - return ''; |
|
| 3694 | - } |
|
| 3695 | - } |
|
| 3696 | - |
|
| 3697 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3698 | - return ''; |
|
| 3699 | - } |
|
| 3700 | - |
|
| 3701 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3702 | - |
|
| 3703 | - $balise_svg = $match[0]; |
|
| 3704 | - $balise_svg_source = $balise_svg; |
|
| 3705 | - |
|
| 3706 | - // entete XML à supprimer |
|
| 3707 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3708 | - |
|
| 3709 | - // IE est toujours mon ami |
|
| 3710 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3711 | - |
|
| 3712 | - // regler la classe |
|
| 3713 | - if (!is_null($class)) { |
|
| 3714 | - if (strlen($class)) { |
|
| 3715 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3716 | - } |
|
| 3717 | - else { |
|
| 3718 | - $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3719 | - } |
|
| 3720 | - } |
|
| 3721 | - |
|
| 3722 | - // regler le alt |
|
| 3723 | - if ($alt) { |
|
| 3724 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3725 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3726 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3727 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3728 | - $balise_svg .= $title; |
|
| 3729 | - } |
|
| 3730 | - else { |
|
| 3731 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3732 | - } |
|
| 3733 | - |
|
| 3734 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3735 | - |
|
| 3736 | - if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3737 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3738 | - |
|
| 3739 | - if (!function_exists('svg_redimensionner')) { |
|
| 3740 | - include_spip('inc/svg'); |
|
| 3741 | - } |
|
| 3742 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3743 | - } |
|
| 3744 | - |
|
| 3745 | - return $svg; |
|
| 3672 | + $svg = null; |
|
| 3673 | + $img = trim($img); |
|
| 3674 | + $img_file = $img; |
|
| 3675 | + if (strpos($img, '<svg') === false) { |
|
| 3676 | + if ($p = strpos($img_file, '?')) { |
|
| 3677 | + $img_file = substr($img_file, 0, $p); |
|
| 3678 | + } |
|
| 3679 | + |
|
| 3680 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3681 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3682 | + if (tester_url_absolue($img_file)) { |
|
| 3683 | + include_spip('inc/distant'); |
|
| 3684 | + $fichier = copie_locale($img_file); |
|
| 3685 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3686 | + } |
|
| 3687 | + |
|
| 3688 | + if ( |
|
| 3689 | + !$img_file |
|
| 3690 | + or !file_exists($img_file) |
|
| 3691 | + or !$svg = file_get_contents($img_file) |
|
| 3692 | + ) { |
|
| 3693 | + return ''; |
|
| 3694 | + } |
|
| 3695 | + } |
|
| 3696 | + |
|
| 3697 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3698 | + return ''; |
|
| 3699 | + } |
|
| 3700 | + |
|
| 3701 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3702 | + |
|
| 3703 | + $balise_svg = $match[0]; |
|
| 3704 | + $balise_svg_source = $balise_svg; |
|
| 3705 | + |
|
| 3706 | + // entete XML à supprimer |
|
| 3707 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3708 | + |
|
| 3709 | + // IE est toujours mon ami |
|
| 3710 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3711 | + |
|
| 3712 | + // regler la classe |
|
| 3713 | + if (!is_null($class)) { |
|
| 3714 | + if (strlen($class)) { |
|
| 3715 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3716 | + } |
|
| 3717 | + else { |
|
| 3718 | + $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3719 | + } |
|
| 3720 | + } |
|
| 3721 | + |
|
| 3722 | + // regler le alt |
|
| 3723 | + if ($alt) { |
|
| 3724 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3725 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3726 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3727 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3728 | + $balise_svg .= $title; |
|
| 3729 | + } |
|
| 3730 | + else { |
|
| 3731 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3732 | + } |
|
| 3733 | + |
|
| 3734 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3735 | + |
|
| 3736 | + if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3737 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3738 | + |
|
| 3739 | + if (!function_exists('svg_redimensionner')) { |
|
| 3740 | + include_spip('inc/svg'); |
|
| 3741 | + } |
|
| 3742 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3743 | + } |
|
| 3744 | + |
|
| 3745 | + return $svg; |
|
| 3746 | 3746 | } |
| 3747 | 3747 | |
| 3748 | 3748 | |
@@ -3768,18 +3768,18 @@ discard block |
||
| 3768 | 3768 | * Code HTML résultant |
| 3769 | 3769 | **/ |
| 3770 | 3770 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3771 | - $texte = ''; |
|
| 3772 | - if (is_array($tableau)) { |
|
| 3773 | - foreach ($tableau as $k => $v) { |
|
| 3774 | - $res = recuperer_fond( |
|
| 3775 | - 'modeles/' . $modele, |
|
| 3776 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3777 | - ); |
|
| 3778 | - $texte .= $res; |
|
| 3779 | - } |
|
| 3780 | - } |
|
| 3771 | + $texte = ''; |
|
| 3772 | + if (is_array($tableau)) { |
|
| 3773 | + foreach ($tableau as $k => $v) { |
|
| 3774 | + $res = recuperer_fond( |
|
| 3775 | + 'modeles/' . $modele, |
|
| 3776 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3777 | + ); |
|
| 3778 | + $texte .= $res; |
|
| 3779 | + } |
|
| 3780 | + } |
|
| 3781 | 3781 | |
| 3782 | - return $texte; |
|
| 3782 | + return $texte; |
|
| 3783 | 3783 | } |
| 3784 | 3784 | |
| 3785 | 3785 | |
@@ -3804,37 +3804,37 @@ discard block |
||
| 3804 | 3804 | * - tout : retourne toutes les informations du plugin actif |
| 3805 | 3805 | **/ |
| 3806 | 3806 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3807 | - include_spip('inc/plugin'); |
|
| 3808 | - $plugin = strtoupper($plugin); |
|
| 3809 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3810 | - |
|
| 3811 | - if (!$plugin) { |
|
| 3812 | - return serialize(array_keys($plugins_actifs)); |
|
| 3813 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3814 | - return ''; |
|
| 3815 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3816 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3817 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3818 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3819 | - } else { |
|
| 3820 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3821 | - // On prend en compte les extensions |
|
| 3822 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3823 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3824 | - } else { |
|
| 3825 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3826 | - } |
|
| 3827 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3828 | - return ''; |
|
| 3829 | - } |
|
| 3830 | - if ($type_info == 'tout') { |
|
| 3831 | - return $infos; |
|
| 3832 | - } elseif ($type_info == 'est_actif') { |
|
| 3833 | - return $infos ? 1 : 0; |
|
| 3834 | - } else { |
|
| 3835 | - return strval($infos[$type_info]); |
|
| 3836 | - } |
|
| 3837 | - } |
|
| 3807 | + include_spip('inc/plugin'); |
|
| 3808 | + $plugin = strtoupper($plugin); |
|
| 3809 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3810 | + |
|
| 3811 | + if (!$plugin) { |
|
| 3812 | + return serialize(array_keys($plugins_actifs)); |
|
| 3813 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3814 | + return ''; |
|
| 3815 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3816 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3817 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3818 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3819 | + } else { |
|
| 3820 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3821 | + // On prend en compte les extensions |
|
| 3822 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3823 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3824 | + } else { |
|
| 3825 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3826 | + } |
|
| 3827 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3828 | + return ''; |
|
| 3829 | + } |
|
| 3830 | + if ($type_info == 'tout') { |
|
| 3831 | + return $infos; |
|
| 3832 | + } elseif ($type_info == 'est_actif') { |
|
| 3833 | + return $infos ? 1 : 0; |
|
| 3834 | + } else { |
|
| 3835 | + return strval($infos[$type_info]); |
|
| 3836 | + } |
|
| 3837 | + } |
|
| 3838 | 3838 | } |
| 3839 | 3839 | |
| 3840 | 3840 | |
@@ -3861,9 +3861,9 @@ discard block |
||
| 3861 | 3861 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3862 | 3862 | */ |
| 3863 | 3863 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3864 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3864 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3865 | 3865 | |
| 3866 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3866 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3867 | 3867 | } |
| 3868 | 3868 | |
| 3869 | 3869 | |
@@ -3893,19 +3893,19 @@ discard block |
||
| 3893 | 3893 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3894 | 3894 | */ |
| 3895 | 3895 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3896 | - static $puce_statut = null; |
|
| 3897 | - if (!$puce_statut) { |
|
| 3898 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3899 | - } |
|
| 3896 | + static $puce_statut = null; |
|
| 3897 | + if (!$puce_statut) { |
|
| 3898 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3899 | + } |
|
| 3900 | 3900 | |
| 3901 | - return $puce_statut( |
|
| 3902 | - $id_objet, |
|
| 3903 | - $statut, |
|
| 3904 | - $id_parent, |
|
| 3905 | - $objet, |
|
| 3906 | - false, |
|
| 3907 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3908 | - ); |
|
| 3901 | + return $puce_statut( |
|
| 3902 | + $id_objet, |
|
| 3903 | + $statut, |
|
| 3904 | + $id_parent, |
|
| 3905 | + $objet, |
|
| 3906 | + false, |
|
| 3907 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3908 | + ); |
|
| 3909 | 3909 | } |
| 3910 | 3910 | |
| 3911 | 3911 | |
@@ -3932,98 +3932,98 @@ discard block |
||
| 3932 | 3932 | * hash du contexte |
| 3933 | 3933 | */ |
| 3934 | 3934 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3935 | - $env = null; |
|
| 3936 | - if ( |
|
| 3937 | - is_string($c) |
|
| 3938 | - and @unserialize($c) !== false |
|
| 3939 | - ) { |
|
| 3940 | - $c = unserialize($c); |
|
| 3941 | - } |
|
| 3942 | - |
|
| 3943 | - // supprimer les parametres debut_x |
|
| 3944 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3945 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3946 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3947 | - if (is_array($c)) { |
|
| 3948 | - foreach ($c as $k => $v) { |
|
| 3949 | - if (strpos($k, 'debut_') === 0) { |
|
| 3950 | - unset($c[$k]); |
|
| 3951 | - } |
|
| 3952 | - } |
|
| 3953 | - } |
|
| 3954 | - |
|
| 3955 | - if (!function_exists('calculer_cle_action')) { |
|
| 3956 | - include_spip('inc/securiser_action'); |
|
| 3957 | - } |
|
| 3958 | - |
|
| 3959 | - $c = serialize($c); |
|
| 3960 | - $cle = calculer_cle_action($form . $c); |
|
| 3961 | - $c = "$cle:$c"; |
|
| 3962 | - |
|
| 3963 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3964 | - // par defaut, sauf si cette configuration a été forcée |
|
| 3965 | - // OU que la longueur de l’argument géneré est plus long |
|
| 3966 | - // que ce qui est toléré. |
|
| 3967 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3968 | - if (!$cache_contextes_ajax) { |
|
| 3969 | - $env = $c; |
|
| 3970 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3971 | - $env = gzdeflate($env); |
|
| 3972 | - } |
|
| 3973 | - $env = _xor($env); |
|
| 3974 | - $env = base64_encode($env); |
|
| 3975 | - $len = strlen($env); |
|
| 3976 | - // Si l’url est trop longue pour le navigateur |
|
| 3977 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3978 | - if ($len > $max_len) { |
|
| 3979 | - $cache_contextes_ajax = true; |
|
| 3980 | - spip_log( |
|
| 3981 | - 'Contextes AJAX forces en fichiers !' |
|
| 3982 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3983 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3984 | - _LOG_AVERTISSEMENT |
|
| 3985 | - ); |
|
| 3986 | - } |
|
| 3987 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3988 | - elseif ( |
|
| 3989 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3990 | - and $max_len < $len |
|
| 3991 | - ) { |
|
| 3992 | - $cache_contextes_ajax = true; |
|
| 3993 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 3994 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3995 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3996 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3997 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3998 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3999 | - } |
|
| 4000 | - } |
|
| 4001 | - |
|
| 4002 | - if ($cache_contextes_ajax) { |
|
| 4003 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4004 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4005 | - $md5 = md5($c); |
|
| 4006 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 4007 | - $env = $md5; |
|
| 4008 | - } |
|
| 4009 | - |
|
| 4010 | - if ($emboite === null) { |
|
| 4011 | - return $env; |
|
| 4012 | - } |
|
| 4013 | - if (!trim($emboite)) { |
|
| 4014 | - return ''; |
|
| 4015 | - } |
|
| 4016 | - // toujours encoder l'url source dans le bloc ajax |
|
| 4017 | - $r = self(); |
|
| 4018 | - $r = ' data-origin="' . $r . '"'; |
|
| 4019 | - $class = 'ajaxbloc'; |
|
| 4020 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 4021 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 4022 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4023 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4024 | - } |
|
| 4025 | - |
|
| 4026 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3935 | + $env = null; |
|
| 3936 | + if ( |
|
| 3937 | + is_string($c) |
|
| 3938 | + and @unserialize($c) !== false |
|
| 3939 | + ) { |
|
| 3940 | + $c = unserialize($c); |
|
| 3941 | + } |
|
| 3942 | + |
|
| 3943 | + // supprimer les parametres debut_x |
|
| 3944 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3945 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3946 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3947 | + if (is_array($c)) { |
|
| 3948 | + foreach ($c as $k => $v) { |
|
| 3949 | + if (strpos($k, 'debut_') === 0) { |
|
| 3950 | + unset($c[$k]); |
|
| 3951 | + } |
|
| 3952 | + } |
|
| 3953 | + } |
|
| 3954 | + |
|
| 3955 | + if (!function_exists('calculer_cle_action')) { |
|
| 3956 | + include_spip('inc/securiser_action'); |
|
| 3957 | + } |
|
| 3958 | + |
|
| 3959 | + $c = serialize($c); |
|
| 3960 | + $cle = calculer_cle_action($form . $c); |
|
| 3961 | + $c = "$cle:$c"; |
|
| 3962 | + |
|
| 3963 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3964 | + // par defaut, sauf si cette configuration a été forcée |
|
| 3965 | + // OU que la longueur de l’argument géneré est plus long |
|
| 3966 | + // que ce qui est toléré. |
|
| 3967 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3968 | + if (!$cache_contextes_ajax) { |
|
| 3969 | + $env = $c; |
|
| 3970 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3971 | + $env = gzdeflate($env); |
|
| 3972 | + } |
|
| 3973 | + $env = _xor($env); |
|
| 3974 | + $env = base64_encode($env); |
|
| 3975 | + $len = strlen($env); |
|
| 3976 | + // Si l’url est trop longue pour le navigateur |
|
| 3977 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3978 | + if ($len > $max_len) { |
|
| 3979 | + $cache_contextes_ajax = true; |
|
| 3980 | + spip_log( |
|
| 3981 | + 'Contextes AJAX forces en fichiers !' |
|
| 3982 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3983 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3984 | + _LOG_AVERTISSEMENT |
|
| 3985 | + ); |
|
| 3986 | + } |
|
| 3987 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3988 | + elseif ( |
|
| 3989 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3990 | + and $max_len < $len |
|
| 3991 | + ) { |
|
| 3992 | + $cache_contextes_ajax = true; |
|
| 3993 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 3994 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3995 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3996 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3997 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3998 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3999 | + } |
|
| 4000 | + } |
|
| 4001 | + |
|
| 4002 | + if ($cache_contextes_ajax) { |
|
| 4003 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4004 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4005 | + $md5 = md5($c); |
|
| 4006 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 4007 | + $env = $md5; |
|
| 4008 | + } |
|
| 4009 | + |
|
| 4010 | + if ($emboite === null) { |
|
| 4011 | + return $env; |
|
| 4012 | + } |
|
| 4013 | + if (!trim($emboite)) { |
|
| 4014 | + return ''; |
|
| 4015 | + } |
|
| 4016 | + // toujours encoder l'url source dans le bloc ajax |
|
| 4017 | + $r = self(); |
|
| 4018 | + $r = ' data-origin="' . $r . '"'; |
|
| 4019 | + $class = 'ajaxbloc'; |
|
| 4020 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 4021 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 4022 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4023 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4024 | + } |
|
| 4025 | + |
|
| 4026 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4027 | 4027 | } |
| 4028 | 4028 | |
| 4029 | 4029 | /** |
@@ -4043,37 +4043,37 @@ discard block |
||
| 4043 | 4043 | * - false : erreur de décodage |
| 4044 | 4044 | */ |
| 4045 | 4045 | function decoder_contexte_ajax($c, $form = '') { |
| 4046 | - if (!function_exists('calculer_cle_action')) { |
|
| 4047 | - include_spip('inc/securiser_action'); |
|
| 4048 | - } |
|
| 4049 | - if ( |
|
| 4050 | - ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4051 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4052 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 4053 | - ) { |
|
| 4054 | - $c = $contexte; |
|
| 4055 | - } else { |
|
| 4056 | - $c = @base64_decode($c); |
|
| 4057 | - $c = _xor($c); |
|
| 4058 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4059 | - $c = @gzinflate($c); |
|
| 4060 | - } |
|
| 4061 | - } |
|
| 4062 | - |
|
| 4063 | - // extraire la signature en debut de contexte |
|
| 4064 | - // et la verifier avant de deserializer |
|
| 4065 | - // format : signature:donneesserializees |
|
| 4066 | - if ($p = strpos($c, ':')) { |
|
| 4067 | - $cle = substr($c, 0, $p); |
|
| 4068 | - $c = substr($c, $p + 1); |
|
| 4069 | - |
|
| 4070 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4071 | - $env = @unserialize($c); |
|
| 4072 | - return $env; |
|
| 4073 | - } |
|
| 4074 | - } |
|
| 4075 | - |
|
| 4076 | - return false; |
|
| 4046 | + if (!function_exists('calculer_cle_action')) { |
|
| 4047 | + include_spip('inc/securiser_action'); |
|
| 4048 | + } |
|
| 4049 | + if ( |
|
| 4050 | + ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4051 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4052 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 4053 | + ) { |
|
| 4054 | + $c = $contexte; |
|
| 4055 | + } else { |
|
| 4056 | + $c = @base64_decode($c); |
|
| 4057 | + $c = _xor($c); |
|
| 4058 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4059 | + $c = @gzinflate($c); |
|
| 4060 | + } |
|
| 4061 | + } |
|
| 4062 | + |
|
| 4063 | + // extraire la signature en debut de contexte |
|
| 4064 | + // et la verifier avant de deserializer |
|
| 4065 | + // format : signature:donneesserializees |
|
| 4066 | + if ($p = strpos($c, ':')) { |
|
| 4067 | + $cle = substr($c, 0, $p); |
|
| 4068 | + $c = substr($c, $p + 1); |
|
| 4069 | + |
|
| 4070 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4071 | + $env = @unserialize($c); |
|
| 4072 | + return $env; |
|
| 4073 | + } |
|
| 4074 | + } |
|
| 4075 | + |
|
| 4076 | + return false; |
|
| 4077 | 4077 | } |
| 4078 | 4078 | |
| 4079 | 4079 | |
@@ -4091,20 +4091,20 @@ discard block |
||
| 4091 | 4091 | * Message décrypté ou encrypté |
| 4092 | 4092 | **/ |
| 4093 | 4093 | function _xor($message, $key = null) { |
| 4094 | - if (is_null($key)) { |
|
| 4095 | - if (!function_exists('calculer_cle_action')) { |
|
| 4096 | - include_spip('inc/securiser_action'); |
|
| 4097 | - } |
|
| 4098 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4099 | - } |
|
| 4094 | + if (is_null($key)) { |
|
| 4095 | + if (!function_exists('calculer_cle_action')) { |
|
| 4096 | + include_spip('inc/securiser_action'); |
|
| 4097 | + } |
|
| 4098 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4099 | + } |
|
| 4100 | 4100 | |
| 4101 | - $keylen = strlen($key); |
|
| 4102 | - $messagelen = strlen($message); |
|
| 4103 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4104 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4105 | - } |
|
| 4101 | + $keylen = strlen($key); |
|
| 4102 | + $messagelen = strlen($message); |
|
| 4103 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4104 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4105 | + } |
|
| 4106 | 4106 | |
| 4107 | - return $message; |
|
| 4107 | + return $message; |
|
| 4108 | 4108 | } |
| 4109 | 4109 | |
| 4110 | 4110 | /** |
@@ -4118,7 +4118,7 @@ discard block |
||
| 4118 | 4118 | * @return string |
| 4119 | 4119 | */ |
| 4120 | 4120 | function url_reponse_forum($texte) { |
| 4121 | - return $texte; |
|
| 4121 | + return $texte; |
|
| 4122 | 4122 | } |
| 4123 | 4123 | |
| 4124 | 4124 | /** |
@@ -4132,7 +4132,7 @@ discard block |
||
| 4132 | 4132 | * @return string |
| 4133 | 4133 | */ |
| 4134 | 4134 | function url_rss_forum($texte) { |
| 4135 | - return $texte; |
|
| 4135 | + return $texte; |
|
| 4136 | 4136 | } |
| 4137 | 4137 | |
| 4138 | 4138 | |
@@ -4171,37 +4171,37 @@ discard block |
||
| 4171 | 4171 | * Code HTML |
| 4172 | 4172 | */ |
| 4173 | 4173 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4174 | - if ($on) { |
|
| 4175 | - $bal = 'strong'; |
|
| 4176 | - $class = ''; |
|
| 4177 | - $att = ''; |
|
| 4178 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4179 | - // a.active span.selected.active etc.... |
|
| 4180 | - if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4181 | - $on = explode('.', $on); |
|
| 4182 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4183 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4184 | - $bal = array_shift($on); |
|
| 4185 | - $class = implode(' ', $on); |
|
| 4186 | - if ($bal == 'a') { |
|
| 4187 | - $att = 'href="#" '; |
|
| 4188 | - } |
|
| 4189 | - } |
|
| 4190 | - } |
|
| 4191 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4192 | - } else { |
|
| 4193 | - $bal = 'a'; |
|
| 4194 | - $att = "href='$url'" |
|
| 4195 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4196 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4197 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4198 | - . $evt; |
|
| 4199 | - } |
|
| 4200 | - if ($libelle === null) { |
|
| 4201 | - $libelle = $url; |
|
| 4202 | - } |
|
| 4203 | - |
|
| 4204 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4174 | + if ($on) { |
|
| 4175 | + $bal = 'strong'; |
|
| 4176 | + $class = ''; |
|
| 4177 | + $att = ''; |
|
| 4178 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4179 | + // a.active span.selected.active etc.... |
|
| 4180 | + if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4181 | + $on = explode('.', $on); |
|
| 4182 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4183 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4184 | + $bal = array_shift($on); |
|
| 4185 | + $class = implode(' ', $on); |
|
| 4186 | + if ($bal == 'a') { |
|
| 4187 | + $att = 'href="#" '; |
|
| 4188 | + } |
|
| 4189 | + } |
|
| 4190 | + } |
|
| 4191 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4192 | + } else { |
|
| 4193 | + $bal = 'a'; |
|
| 4194 | + $att = "href='$url'" |
|
| 4195 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4196 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4197 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4198 | + . $evt; |
|
| 4199 | + } |
|
| 4200 | + if ($libelle === null) { |
|
| 4201 | + $libelle = $url; |
|
| 4202 | + } |
|
| 4203 | + |
|
| 4204 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4205 | 4205 | } |
| 4206 | 4206 | |
| 4207 | 4207 | |
@@ -4218,39 +4218,39 @@ discard block |
||
| 4218 | 4218 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4219 | 4219 | */ |
| 4220 | 4220 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4221 | - static $local_singulier_ou_pluriel = []; |
|
| 4222 | - |
|
| 4223 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4224 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 4225 | - return ''; |
|
| 4226 | - } |
|
| 4227 | - if (!is_array($vars)) { |
|
| 4228 | - return ''; |
|
| 4229 | - } |
|
| 4230 | - |
|
| 4231 | - $langue = $GLOBALS['spip_lang']; |
|
| 4232 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4233 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4234 | - if ( |
|
| 4235 | - $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true) |
|
| 4236 | - or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4237 | - ) { |
|
| 4238 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4239 | - } |
|
| 4240 | - } |
|
| 4241 | - |
|
| 4242 | - // si on a une surcharge on l'utilise |
|
| 4243 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4244 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4245 | - } |
|
| 4246 | - |
|
| 4247 | - // sinon traitement par defaut |
|
| 4248 | - $vars[$var] = $nb; |
|
| 4249 | - if ($nb >= 2) { |
|
| 4250 | - return _T($chaine_plusieurs, $vars); |
|
| 4251 | - } else { |
|
| 4252 | - return _T($chaine_un, $vars); |
|
| 4253 | - } |
|
| 4221 | + static $local_singulier_ou_pluriel = []; |
|
| 4222 | + |
|
| 4223 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4224 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 4225 | + return ''; |
|
| 4226 | + } |
|
| 4227 | + if (!is_array($vars)) { |
|
| 4228 | + return ''; |
|
| 4229 | + } |
|
| 4230 | + |
|
| 4231 | + $langue = $GLOBALS['spip_lang']; |
|
| 4232 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4233 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4234 | + if ( |
|
| 4235 | + $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true) |
|
| 4236 | + or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4237 | + ) { |
|
| 4238 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4239 | + } |
|
| 4240 | + } |
|
| 4241 | + |
|
| 4242 | + // si on a une surcharge on l'utilise |
|
| 4243 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4244 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4245 | + } |
|
| 4246 | + |
|
| 4247 | + // sinon traitement par defaut |
|
| 4248 | + $vars[$var] = $nb; |
|
| 4249 | + if ($nb >= 2) { |
|
| 4250 | + return _T($chaine_plusieurs, $vars); |
|
| 4251 | + } else { |
|
| 4252 | + return _T($chaine_un, $vars); |
|
| 4253 | + } |
|
| 4254 | 4254 | } |
| 4255 | 4255 | |
| 4256 | 4256 | |
@@ -4278,73 +4278,73 @@ discard block |
||
| 4278 | 4278 | */ |
| 4279 | 4279 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4280 | 4280 | |
| 4281 | - $class_lien = $class_bouton = $class; |
|
| 4282 | - |
|
| 4283 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4284 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4285 | - $class_lien .= ' danger'; |
|
| 4286 | - $class_bouton .= ' btn_danger'; |
|
| 4287 | - } elseif ($fonction == 'rien.gif') { |
|
| 4288 | - $fonction = ''; |
|
| 4289 | - } elseif ($fonction == 'delsafe') { |
|
| 4290 | - $fonction = 'del'; |
|
| 4291 | - } |
|
| 4292 | - |
|
| 4293 | - $fond_origine = $fond; |
|
| 4294 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4295 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4296 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4297 | - } |
|
| 4298 | - |
|
| 4299 | - // Ajouter le type d'objet dans la classe |
|
| 4300 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4301 | - $class_lien .= " $objet_type"; |
|
| 4302 | - $class_bouton .= " $objet_type"; |
|
| 4303 | - |
|
| 4304 | - // Texte |
|
| 4305 | - $alt = attribut_html($texte); |
|
| 4306 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4307 | - |
|
| 4308 | - // Liens : préparer les classes ajax |
|
| 4309 | - $ajax = ''; |
|
| 4310 | - if ($type === 'lien') { |
|
| 4311 | - if (strpos($class_lien, 'ajax') !== false) { |
|
| 4312 | - $ajax = 'ajax'; |
|
| 4313 | - if (strpos($class_lien, 'preload') !== false) { |
|
| 4314 | - $ajax .= ' preload'; |
|
| 4315 | - } |
|
| 4316 | - if (strpos($class_lien, 'nocache') !== false) { |
|
| 4317 | - $ajax .= ' nocache'; |
|
| 4318 | - } |
|
| 4319 | - $ajax = " class='$ajax'"; |
|
| 4320 | - } |
|
| 4321 | - } |
|
| 4322 | - |
|
| 4323 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4324 | - $size = 24; |
|
| 4325 | - if ( |
|
| 4326 | - preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4327 | - or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4328 | - ) { |
|
| 4329 | - $size = $match[1]; |
|
| 4330 | - } |
|
| 4331 | - $class_lien .= " s$size"; |
|
| 4332 | - $class_bouton .= " s$size"; |
|
| 4333 | - |
|
| 4334 | - // Icône |
|
| 4335 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4336 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4337 | - |
|
| 4338 | - // Markup final |
|
| 4339 | - if ($type == 'lien') { |
|
| 4340 | - return "<span class='icone $class_lien'>" |
|
| 4341 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4342 | - . $icone |
|
| 4343 | - . "<b>$texte</b>" |
|
| 4344 | - . "</a></span>\n"; |
|
| 4345 | - } else { |
|
| 4346 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4347 | - } |
|
| 4281 | + $class_lien = $class_bouton = $class; |
|
| 4282 | + |
|
| 4283 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4284 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4285 | + $class_lien .= ' danger'; |
|
| 4286 | + $class_bouton .= ' btn_danger'; |
|
| 4287 | + } elseif ($fonction == 'rien.gif') { |
|
| 4288 | + $fonction = ''; |
|
| 4289 | + } elseif ($fonction == 'delsafe') { |
|
| 4290 | + $fonction = 'del'; |
|
| 4291 | + } |
|
| 4292 | + |
|
| 4293 | + $fond_origine = $fond; |
|
| 4294 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4295 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4296 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4297 | + } |
|
| 4298 | + |
|
| 4299 | + // Ajouter le type d'objet dans la classe |
|
| 4300 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4301 | + $class_lien .= " $objet_type"; |
|
| 4302 | + $class_bouton .= " $objet_type"; |
|
| 4303 | + |
|
| 4304 | + // Texte |
|
| 4305 | + $alt = attribut_html($texte); |
|
| 4306 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4307 | + |
|
| 4308 | + // Liens : préparer les classes ajax |
|
| 4309 | + $ajax = ''; |
|
| 4310 | + if ($type === 'lien') { |
|
| 4311 | + if (strpos($class_lien, 'ajax') !== false) { |
|
| 4312 | + $ajax = 'ajax'; |
|
| 4313 | + if (strpos($class_lien, 'preload') !== false) { |
|
| 4314 | + $ajax .= ' preload'; |
|
| 4315 | + } |
|
| 4316 | + if (strpos($class_lien, 'nocache') !== false) { |
|
| 4317 | + $ajax .= ' nocache'; |
|
| 4318 | + } |
|
| 4319 | + $ajax = " class='$ajax'"; |
|
| 4320 | + } |
|
| 4321 | + } |
|
| 4322 | + |
|
| 4323 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4324 | + $size = 24; |
|
| 4325 | + if ( |
|
| 4326 | + preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4327 | + or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4328 | + ) { |
|
| 4329 | + $size = $match[1]; |
|
| 4330 | + } |
|
| 4331 | + $class_lien .= " s$size"; |
|
| 4332 | + $class_bouton .= " s$size"; |
|
| 4333 | + |
|
| 4334 | + // Icône |
|
| 4335 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4336 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4337 | + |
|
| 4338 | + // Markup final |
|
| 4339 | + if ($type == 'lien') { |
|
| 4340 | + return "<span class='icone $class_lien'>" |
|
| 4341 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4342 | + . $icone |
|
| 4343 | + . "<b>$texte</b>" |
|
| 4344 | + . "</a></span>\n"; |
|
| 4345 | + } else { |
|
| 4346 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4347 | + } |
|
| 4348 | 4348 | } |
| 4349 | 4349 | |
| 4350 | 4350 | /** |
@@ -4368,7 +4368,7 @@ discard block |
||
| 4368 | 4368 | * Code HTML du lien |
| 4369 | 4369 | **/ |
| 4370 | 4370 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4371 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4371 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4372 | 4372 | } |
| 4373 | 4373 | |
| 4374 | 4374 | /** |
@@ -4403,7 +4403,7 @@ discard block |
||
| 4403 | 4403 | * Code HTML du lien |
| 4404 | 4404 | **/ |
| 4405 | 4405 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4406 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4406 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4407 | 4407 | } |
| 4408 | 4408 | |
| 4409 | 4409 | /** |
@@ -4448,7 +4448,7 @@ discard block |
||
| 4448 | 4448 | * Code HTML du lien |
| 4449 | 4449 | **/ |
| 4450 | 4450 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4451 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4451 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4452 | 4452 | } |
| 4453 | 4453 | |
| 4454 | 4454 | /** |
@@ -4479,7 +4479,7 @@ discard block |
||
| 4479 | 4479 | * Code HTML du lien |
| 4480 | 4480 | **/ |
| 4481 | 4481 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4482 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4482 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4483 | 4483 | } |
| 4484 | 4484 | |
| 4485 | 4485 | /** |
@@ -4510,7 +4510,7 @@ discard block |
||
| 4510 | 4510 | * Code HTML du lien |
| 4511 | 4511 | */ |
| 4512 | 4512 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4513 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4513 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4514 | 4514 | } |
| 4515 | 4515 | |
| 4516 | 4516 | |
@@ -4532,7 +4532,7 @@ discard block |
||
| 4532 | 4532 | * @return array Liste des éléments |
| 4533 | 4533 | */ |
| 4534 | 4534 | function filtre_explode_dist($a, $b) { |
| 4535 | - return explode($b, (string) $a); |
|
| 4535 | + return explode($b, (string) $a); |
|
| 4536 | 4536 | } |
| 4537 | 4537 | |
| 4538 | 4538 | /** |
@@ -4553,7 +4553,7 @@ discard block |
||
| 4553 | 4553 | * @return string Texte |
| 4554 | 4554 | */ |
| 4555 | 4555 | function filtre_implode_dist($a, $b) { |
| 4556 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4556 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4557 | 4557 | } |
| 4558 | 4558 | |
| 4559 | 4559 | /** |
@@ -4562,22 +4562,22 @@ discard block |
||
| 4562 | 4562 | * @return string Code CSS |
| 4563 | 4563 | */ |
| 4564 | 4564 | function bando_images_background() { |
| 4565 | - include_spip('inc/bandeau'); |
|
| 4566 | - // recuperer tous les boutons et leurs images |
|
| 4567 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4565 | + include_spip('inc/bandeau'); |
|
| 4566 | + // recuperer tous les boutons et leurs images |
|
| 4567 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4568 | 4568 | |
| 4569 | - $res = ''; |
|
| 4570 | - foreach ($boutons as $page => $detail) { |
|
| 4571 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4572 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4573 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4574 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4575 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4576 | - } |
|
| 4577 | - } |
|
| 4578 | - } |
|
| 4569 | + $res = ''; |
|
| 4570 | + foreach ($boutons as $page => $detail) { |
|
| 4571 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4572 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4573 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4574 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4575 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4576 | + } |
|
| 4577 | + } |
|
| 4578 | + } |
|
| 4579 | 4579 | |
| 4580 | - return $res; |
|
| 4580 | + return $res; |
|
| 4581 | 4581 | } |
| 4582 | 4582 | |
| 4583 | 4583 | /** |
@@ -4602,27 +4602,27 @@ discard block |
||
| 4602 | 4602 | */ |
| 4603 | 4603 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4604 | 4604 | |
| 4605 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4606 | - $class_form = ''; |
|
| 4607 | - if (strpos($class, 'ajax') !== false) { |
|
| 4608 | - $class_form = 'ajax'; |
|
| 4609 | - $class = str_replace('ajax', '', $class); |
|
| 4610 | - } |
|
| 4611 | - $class_btn = 'submit ' . trim($class); |
|
| 4605 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4606 | + $class_form = ''; |
|
| 4607 | + if (strpos($class, 'ajax') !== false) { |
|
| 4608 | + $class_form = 'ajax'; |
|
| 4609 | + $class = str_replace('ajax', '', $class); |
|
| 4610 | + } |
|
| 4611 | + $class_btn = 'submit ' . trim($class); |
|
| 4612 | 4612 | |
| 4613 | - if ($confirm) { |
|
| 4614 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4615 | - if ($callback) { |
|
| 4616 | - $callback = "$confirm?($callback):false"; |
|
| 4617 | - } else { |
|
| 4618 | - $callback = $confirm; |
|
| 4619 | - } |
|
| 4620 | - } |
|
| 4621 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4622 | - $title = $title ? " title='$title'" : ''; |
|
| 4613 | + if ($confirm) { |
|
| 4614 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4615 | + if ($callback) { |
|
| 4616 | + $callback = "$confirm?($callback):false"; |
|
| 4617 | + } else { |
|
| 4618 | + $callback = $confirm; |
|
| 4619 | + } |
|
| 4620 | + } |
|
| 4621 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4622 | + $title = $title ? " title='$title'" : ''; |
|
| 4623 | 4623 | |
| 4624 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4625 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4624 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4625 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4626 | 4626 | } |
| 4627 | 4627 | |
| 4628 | 4628 | /** |
@@ -4645,101 +4645,101 @@ discard block |
||
| 4645 | 4645 | * @return string |
| 4646 | 4646 | */ |
| 4647 | 4647 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4648 | - static $trouver_table = null; |
|
| 4649 | - static $objets; |
|
| 4650 | - |
|
| 4651 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4652 | - $id_objet = intval($id_objet); |
|
| 4653 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4654 | - return ''; |
|
| 4655 | - } |
|
| 4656 | - |
|
| 4657 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4658 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4659 | - return ''; |
|
| 4660 | - } |
|
| 4661 | - |
|
| 4662 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4663 | - if ($info == 'url') { |
|
| 4664 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4665 | - } |
|
| 4666 | - |
|
| 4667 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4668 | - $demande_titre = ($info === 'titre'); |
|
| 4669 | - $demande_introduction = ($info === 'introduction'); |
|
| 4670 | - |
|
| 4671 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4672 | - if ( |
|
| 4673 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4674 | - or |
|
| 4675 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4676 | - ) { |
|
| 4677 | - if (!$trouver_table) { |
|
| 4678 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4679 | - } |
|
| 4680 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4681 | - if (!$desc) { |
|
| 4682 | - return $objets[$type_objet] = false; |
|
| 4683 | - } |
|
| 4684 | - |
|
| 4685 | - // Si on demande le titre, on le gere en interne |
|
| 4686 | - $champ_titre = ''; |
|
| 4687 | - if ($demande_titre) { |
|
| 4688 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4689 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4690 | - } |
|
| 4691 | - include_spip('base/abstract_sql'); |
|
| 4692 | - include_spip('base/connect_sql'); |
|
| 4693 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4694 | - '*' . $champ_titre, |
|
| 4695 | - $desc['table_sql'], |
|
| 4696 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4697 | - ); |
|
| 4698 | - |
|
| 4699 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4700 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4701 | - } |
|
| 4702 | - |
|
| 4703 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4704 | - // ajouter la longueur au début des params supplémentaires |
|
| 4705 | - if ($demande_introduction) { |
|
| 4706 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4707 | - array_unshift($params, $introduction_longueur); |
|
| 4708 | - } |
|
| 4709 | - |
|
| 4710 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4711 | - if ( |
|
| 4712 | - $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true) |
|
| 4713 | - // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4714 | - or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true) |
|
| 4715 | - ) { |
|
| 4716 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4717 | - } |
|
| 4718 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4719 | - elseif ( |
|
| 4720 | - $generer = charger_fonction("generer_objet_{$info}", '', true) |
|
| 4721 | - // @deprecated 4.1 generer_TRUC_entite |
|
| 4722 | - or $generer = charger_fonction("generer_{$info}_entite", '', true) |
|
| 4723 | - ) { |
|
| 4724 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4725 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4726 | - else { |
|
| 4727 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4728 | - } |
|
| 4729 | - |
|
| 4730 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4731 | - if (!$etoile) { |
|
| 4732 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4733 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4734 | - $info_generee = appliquer_traitement_champ( |
|
| 4735 | - $info_generee, |
|
| 4736 | - $info, |
|
| 4737 | - table_objet($type_objet), |
|
| 4738 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4739 | - ); |
|
| 4740 | - } |
|
| 4741 | - |
|
| 4742 | - return $info_generee; |
|
| 4648 | + static $trouver_table = null; |
|
| 4649 | + static $objets; |
|
| 4650 | + |
|
| 4651 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4652 | + $id_objet = intval($id_objet); |
|
| 4653 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4654 | + return ''; |
|
| 4655 | + } |
|
| 4656 | + |
|
| 4657 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4658 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4659 | + return ''; |
|
| 4660 | + } |
|
| 4661 | + |
|
| 4662 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4663 | + if ($info == 'url') { |
|
| 4664 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4665 | + } |
|
| 4666 | + |
|
| 4667 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4668 | + $demande_titre = ($info === 'titre'); |
|
| 4669 | + $demande_introduction = ($info === 'introduction'); |
|
| 4670 | + |
|
| 4671 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4672 | + if ( |
|
| 4673 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4674 | + or |
|
| 4675 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4676 | + ) { |
|
| 4677 | + if (!$trouver_table) { |
|
| 4678 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4679 | + } |
|
| 4680 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4681 | + if (!$desc) { |
|
| 4682 | + return $objets[$type_objet] = false; |
|
| 4683 | + } |
|
| 4684 | + |
|
| 4685 | + // Si on demande le titre, on le gere en interne |
|
| 4686 | + $champ_titre = ''; |
|
| 4687 | + if ($demande_titre) { |
|
| 4688 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4689 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4690 | + } |
|
| 4691 | + include_spip('base/abstract_sql'); |
|
| 4692 | + include_spip('base/connect_sql'); |
|
| 4693 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4694 | + '*' . $champ_titre, |
|
| 4695 | + $desc['table_sql'], |
|
| 4696 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4697 | + ); |
|
| 4698 | + |
|
| 4699 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4700 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4701 | + } |
|
| 4702 | + |
|
| 4703 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4704 | + // ajouter la longueur au début des params supplémentaires |
|
| 4705 | + if ($demande_introduction) { |
|
| 4706 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4707 | + array_unshift($params, $introduction_longueur); |
|
| 4708 | + } |
|
| 4709 | + |
|
| 4710 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4711 | + if ( |
|
| 4712 | + $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true) |
|
| 4713 | + // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4714 | + or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true) |
|
| 4715 | + ) { |
|
| 4716 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4717 | + } |
|
| 4718 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4719 | + elseif ( |
|
| 4720 | + $generer = charger_fonction("generer_objet_{$info}", '', true) |
|
| 4721 | + // @deprecated 4.1 generer_TRUC_entite |
|
| 4722 | + or $generer = charger_fonction("generer_{$info}_entite", '', true) |
|
| 4723 | + ) { |
|
| 4724 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4725 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4726 | + else { |
|
| 4727 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4728 | + } |
|
| 4729 | + |
|
| 4730 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4731 | + if (!$etoile) { |
|
| 4732 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4733 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4734 | + $info_generee = appliquer_traitement_champ( |
|
| 4735 | + $info_generee, |
|
| 4736 | + $info, |
|
| 4737 | + table_objet($type_objet), |
|
| 4738 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4739 | + ); |
|
| 4740 | + } |
|
| 4741 | + |
|
| 4742 | + return $info_generee; |
|
| 4743 | 4743 | } |
| 4744 | 4744 | |
| 4745 | 4745 | /** |
@@ -4747,7 +4747,7 @@ discard block |
||
| 4747 | 4747 | * @see generer_objet_info |
| 4748 | 4748 | */ |
| 4749 | 4749 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4750 | - return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4750 | + return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4751 | 4751 | } |
| 4752 | 4752 | |
| 4753 | 4753 | /** |
@@ -4780,36 +4780,36 @@ discard block |
||
| 4780 | 4780 | */ |
| 4781 | 4781 | function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string { |
| 4782 | 4782 | |
| 4783 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4784 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4785 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4786 | - if (isset($ligne_sql['chapo'])) { |
|
| 4787 | - $chapo = $ligne_sql['chapo']; |
|
| 4788 | - $texte = strlen($descriptif) ? |
|
| 4789 | - '' : |
|
| 4790 | - "$chapo \n\n $texte"; |
|
| 4791 | - } |
|
| 4783 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4784 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4785 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4786 | + if (isset($ligne_sql['chapo'])) { |
|
| 4787 | + $chapo = $ligne_sql['chapo']; |
|
| 4788 | + $texte = strlen($descriptif) ? |
|
| 4789 | + '' : |
|
| 4790 | + "$chapo \n\n $texte"; |
|
| 4791 | + } |
|
| 4792 | 4792 | |
| 4793 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4794 | - if (!intval($longueur_ou_suite)) { |
|
| 4795 | - $longueur = intval($introduction_longueur ?: 600); |
|
| 4796 | - } else { |
|
| 4797 | - $longueur = intval($longueur_ou_suite); |
|
| 4798 | - } |
|
| 4793 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4794 | + if (!intval($longueur_ou_suite)) { |
|
| 4795 | + $longueur = intval($introduction_longueur ?: 600); |
|
| 4796 | + } else { |
|
| 4797 | + $longueur = intval($longueur_ou_suite); |
|
| 4798 | + } |
|
| 4799 | 4799 | |
| 4800 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4801 | - // Ex : #INTRODUCTION{...} |
|
| 4802 | - if ( |
|
| 4803 | - is_null($suite) |
|
| 4804 | - and !intval($longueur_ou_suite) |
|
| 4805 | - ) { |
|
| 4806 | - $suite = $longueur_ou_suite; |
|
| 4807 | - } |
|
| 4800 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4801 | + // Ex : #INTRODUCTION{...} |
|
| 4802 | + if ( |
|
| 4803 | + is_null($suite) |
|
| 4804 | + and !intval($longueur_ou_suite) |
|
| 4805 | + ) { |
|
| 4806 | + $suite = $longueur_ou_suite; |
|
| 4807 | + } |
|
| 4808 | 4808 | |
| 4809 | - $f = chercher_filtre('introduction'); |
|
| 4810 | - $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4809 | + $f = chercher_filtre('introduction'); |
|
| 4810 | + $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4811 | 4811 | |
| 4812 | - return $introduction; |
|
| 4812 | + return $introduction; |
|
| 4813 | 4813 | } |
| 4814 | 4814 | |
| 4815 | 4815 | /** |
@@ -4817,7 +4817,7 @@ discard block |
||
| 4817 | 4817 | * @see generer_objet_introduction |
| 4818 | 4818 | */ |
| 4819 | 4819 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') { |
| 4820 | - return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4820 | + return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4821 | 4821 | } |
| 4822 | 4822 | |
| 4823 | 4823 | /** |
@@ -4831,49 +4831,49 @@ discard block |
||
| 4831 | 4831 | * @return string |
| 4832 | 4832 | */ |
| 4833 | 4833 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4834 | - if (!$champ) { |
|
| 4835 | - return $texte; |
|
| 4836 | - } |
|
| 4834 | + if (!$champ) { |
|
| 4835 | + return $texte; |
|
| 4836 | + } |
|
| 4837 | 4837 | |
| 4838 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4839 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4840 | - include_fichiers_fonctions(); |
|
| 4838 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4839 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4840 | + include_fichiers_fonctions(); |
|
| 4841 | 4841 | |
| 4842 | - $champ = strtoupper($champ); |
|
| 4843 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4844 | - if (!$traitements or !is_array($traitements)) { |
|
| 4845 | - return $texte; |
|
| 4846 | - } |
|
| 4842 | + $champ = strtoupper($champ); |
|
| 4843 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4844 | + if (!$traitements or !is_array($traitements)) { |
|
| 4845 | + return $texte; |
|
| 4846 | + } |
|
| 4847 | 4847 | |
| 4848 | - $traitement = ''; |
|
| 4849 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4850 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4851 | - $table_objet = table_objet($table_objet); |
|
| 4852 | - if (isset($traitements[$table_objet])) { |
|
| 4853 | - $traitement = $traitements[$table_objet]; |
|
| 4854 | - } |
|
| 4855 | - } |
|
| 4856 | - if (!$traitement and isset($traitements[0])) { |
|
| 4857 | - $traitement = $traitements[0]; |
|
| 4858 | - } |
|
| 4859 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4848 | + $traitement = ''; |
|
| 4849 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4850 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4851 | + $table_objet = table_objet($table_objet); |
|
| 4852 | + if (isset($traitements[$table_objet])) { |
|
| 4853 | + $traitement = $traitements[$table_objet]; |
|
| 4854 | + } |
|
| 4855 | + } |
|
| 4856 | + if (!$traitement and isset($traitements[0])) { |
|
| 4857 | + $traitement = $traitements[0]; |
|
| 4858 | + } |
|
| 4859 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4860 | 4860 | |
| 4861 | - if (!$traitement) { |
|
| 4862 | - return $texte; |
|
| 4863 | - } |
|
| 4861 | + if (!$traitement) { |
|
| 4862 | + return $texte; |
|
| 4863 | + } |
|
| 4864 | 4864 | |
| 4865 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4865 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4866 | 4866 | |
| 4867 | - // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4868 | - if (test_espace_prive()) { |
|
| 4869 | - $env['espace_prive'] = 1; |
|
| 4870 | - } |
|
| 4867 | + // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4868 | + if (test_espace_prive()) { |
|
| 4869 | + $env['espace_prive'] = 1; |
|
| 4870 | + } |
|
| 4871 | 4871 | |
| 4872 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4873 | - $Pile = [0 => $env]; |
|
| 4874 | - eval("\$texte = $traitement;"); |
|
| 4872 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4873 | + $Pile = [0 => $env]; |
|
| 4874 | + eval("\$texte = $traitement;"); |
|
| 4875 | 4875 | |
| 4876 | - return $texte; |
|
| 4876 | + return $texte; |
|
| 4877 | 4877 | } |
| 4878 | 4878 | |
| 4879 | 4879 | |
@@ -4887,21 +4887,21 @@ discard block |
||
| 4887 | 4887 | * @return string |
| 4888 | 4888 | */ |
| 4889 | 4889 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4890 | - include_spip('inc/liens'); |
|
| 4891 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4892 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4893 | - // le raccourcis n'est plus valide |
|
| 4894 | - $titre = typo($titre['titre'] ?? ''); |
|
| 4895 | - // on essaye avec generer_info_entite ? |
|
| 4896 | - if (!strlen($titre) and !$connect) { |
|
| 4897 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4898 | - } |
|
| 4899 | - if (!strlen($titre)) { |
|
| 4900 | - $titre = _T('info_sans_titre'); |
|
| 4901 | - } |
|
| 4902 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4890 | + include_spip('inc/liens'); |
|
| 4891 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4892 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4893 | + // le raccourcis n'est plus valide |
|
| 4894 | + $titre = typo($titre['titre'] ?? ''); |
|
| 4895 | + // on essaye avec generer_info_entite ? |
|
| 4896 | + if (!strlen($titre) and !$connect) { |
|
| 4897 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4898 | + } |
|
| 4899 | + if (!strlen($titre)) { |
|
| 4900 | + $titre = _T('info_sans_titre'); |
|
| 4901 | + } |
|
| 4902 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4903 | 4903 | |
| 4904 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4904 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4905 | 4905 | } |
| 4906 | 4906 | |
| 4907 | 4907 | /** |
@@ -4909,7 +4909,7 @@ discard block |
||
| 4909 | 4909 | * @see generer_objet_lien |
| 4910 | 4910 | */ |
| 4911 | 4911 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 4912 | - return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 4912 | + return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 4913 | 4913 | } |
| 4914 | 4914 | |
| 4915 | 4915 | /** |
@@ -4925,15 +4925,15 @@ discard block |
||
| 4925 | 4925 | * @return string |
| 4926 | 4926 | */ |
| 4927 | 4927 | function wrap($texte, $wrap) { |
| 4928 | - $balises = extraire_balises($wrap); |
|
| 4929 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4930 | - $texte = $wrap . $texte; |
|
| 4931 | - $regs = array_reverse($regs[1]); |
|
| 4932 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4933 | - $texte = $texte . $wrap; |
|
| 4934 | - } |
|
| 4928 | + $balises = extraire_balises($wrap); |
|
| 4929 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4930 | + $texte = $wrap . $texte; |
|
| 4931 | + $regs = array_reverse($regs[1]); |
|
| 4932 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4933 | + $texte = $texte . $wrap; |
|
| 4934 | + } |
|
| 4935 | 4935 | |
| 4936 | - return $texte; |
|
| 4936 | + return $texte; |
|
| 4937 | 4937 | } |
| 4938 | 4938 | |
| 4939 | 4939 | |
@@ -4953,44 +4953,44 @@ discard block |
||
| 4953 | 4953 | * @return array|mixed|string |
| 4954 | 4954 | */ |
| 4955 | 4955 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 4956 | - if (is_string($u)) { |
|
| 4957 | - $u = typo($u); |
|
| 4956 | + if (is_string($u)) { |
|
| 4957 | + $u = typo($u); |
|
| 4958 | 4958 | |
| 4959 | - return $u; |
|
| 4960 | - } |
|
| 4959 | + return $u; |
|
| 4960 | + } |
|
| 4961 | 4961 | |
| 4962 | - // caster $u en array si besoin |
|
| 4963 | - if (is_object($u)) { |
|
| 4964 | - $u = (array)$u; |
|
| 4965 | - } |
|
| 4962 | + // caster $u en array si besoin |
|
| 4963 | + if (is_object($u)) { |
|
| 4964 | + $u = (array)$u; |
|
| 4965 | + } |
|
| 4966 | 4966 | |
| 4967 | - if (is_array($u)) { |
|
| 4968 | - $out = ''; |
|
| 4969 | - // toutes les cles sont numeriques ? |
|
| 4970 | - // et aucun enfant n'est un tableau |
|
| 4971 | - // liste simple separee par des virgules |
|
| 4972 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4973 | - $array_values = array_map('is_array', $u); |
|
| 4974 | - $object_values = array_map('is_object', $u); |
|
| 4975 | - if ( |
|
| 4976 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 4977 | - and !array_sum($array_values) |
|
| 4978 | - and !array_sum($object_values) |
|
| 4979 | - ) { |
|
| 4980 | - return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4981 | - } |
|
| 4967 | + if (is_array($u)) { |
|
| 4968 | + $out = ''; |
|
| 4969 | + // toutes les cles sont numeriques ? |
|
| 4970 | + // et aucun enfant n'est un tableau |
|
| 4971 | + // liste simple separee par des virgules |
|
| 4972 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4973 | + $array_values = array_map('is_array', $u); |
|
| 4974 | + $object_values = array_map('is_object', $u); |
|
| 4975 | + if ( |
|
| 4976 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 4977 | + and !array_sum($array_values) |
|
| 4978 | + and !array_sum($object_values) |
|
| 4979 | + ) { |
|
| 4980 | + return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4981 | + } |
|
| 4982 | 4982 | |
| 4983 | - // sinon on passe a la ligne et on indente |
|
| 4984 | - $i_str = str_pad('', $indent, ' '); |
|
| 4985 | - foreach ($u as $k => $v) { |
|
| 4986 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4987 | - } |
|
| 4983 | + // sinon on passe a la ligne et on indente |
|
| 4984 | + $i_str = str_pad('', $indent, ' '); |
|
| 4985 | + foreach ($u as $k => $v) { |
|
| 4986 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4987 | + } |
|
| 4988 | 4988 | |
| 4989 | - return $out; |
|
| 4990 | - } |
|
| 4989 | + return $out; |
|
| 4990 | + } |
|
| 4991 | 4991 | |
| 4992 | - // on sait pas quoi faire... |
|
| 4993 | - return $u; |
|
| 4992 | + // on sait pas quoi faire... |
|
| 4993 | + return $u; |
|
| 4994 | 4994 | } |
| 4995 | 4995 | |
| 4996 | 4996 | |
@@ -5003,10 +5003,10 @@ discard block |
||
| 5003 | 5003 | * @return string|array |
| 5004 | 5004 | */ |
| 5005 | 5005 | function objet_info($objet, $info) { |
| 5006 | - $table = table_objet_sql($objet); |
|
| 5007 | - $infos = lister_tables_objets_sql($table); |
|
| 5006 | + $table = table_objet_sql($objet); |
|
| 5007 | + $infos = lister_tables_objets_sql($table); |
|
| 5008 | 5008 | |
| 5009 | - return ($infos[$info] ?? ''); |
|
| 5009 | + return ($infos[$info] ?? ''); |
|
| 5010 | 5010 | } |
| 5011 | 5011 | |
| 5012 | 5012 | /** |
@@ -5021,11 +5021,11 @@ discard block |
||
| 5021 | 5021 | * Texte traduit du comptage, tel que '3 articles' |
| 5022 | 5022 | */ |
| 5023 | 5023 | function objet_afficher_nb($nb, $objet) { |
| 5024 | - if (!$nb) { |
|
| 5025 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5026 | - } else { |
|
| 5027 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5028 | - } |
|
| 5024 | + if (!$nb) { |
|
| 5025 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5026 | + } else { |
|
| 5027 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5028 | + } |
|
| 5029 | 5029 | } |
| 5030 | 5030 | |
| 5031 | 5031 | /** |
@@ -5037,11 +5037,11 @@ discard block |
||
| 5037 | 5037 | * @return string |
| 5038 | 5038 | */ |
| 5039 | 5039 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5040 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5041 | - $icone = chemin_image($icone); |
|
| 5042 | - $balise_img = charger_filtre('balise_img'); |
|
| 5040 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5041 | + $icone = chemin_image($icone); |
|
| 5042 | + $balise_img = charger_filtre('balise_img'); |
|
| 5043 | 5043 | |
| 5044 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5044 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5045 | 5045 | } |
| 5046 | 5046 | |
| 5047 | 5047 | /** |
@@ -5062,12 +5062,12 @@ discard block |
||
| 5062 | 5062 | * @return string |
| 5063 | 5063 | */ |
| 5064 | 5064 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5065 | - $chaine = explode(':', $chaine); |
|
| 5066 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5067 | - return $t; |
|
| 5068 | - } |
|
| 5069 | - $chaine = implode(':', $chaine); |
|
| 5070 | - return _T($chaine, $args, $options); |
|
| 5065 | + $chaine = explode(':', $chaine); |
|
| 5066 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5067 | + return $t; |
|
| 5068 | + } |
|
| 5069 | + $chaine = implode(':', $chaine); |
|
| 5070 | + return _T($chaine, $args, $options); |
|
| 5071 | 5071 | } |
| 5072 | 5072 | |
| 5073 | 5073 | /** |
@@ -5081,18 +5081,18 @@ discard block |
||
| 5081 | 5081 | * @return string Code HTML |
| 5082 | 5082 | */ |
| 5083 | 5083 | function insert_head_css_conditionnel($flux) { |
| 5084 | - if ( |
|
| 5085 | - strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5086 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5087 | - ) { |
|
| 5088 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5089 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5090 | - $p = $p1; |
|
| 5091 | - } |
|
| 5092 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5093 | - } |
|
| 5084 | + if ( |
|
| 5085 | + strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5086 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5087 | + ) { |
|
| 5088 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5089 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5090 | + $p = $p1; |
|
| 5091 | + } |
|
| 5092 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5093 | + } |
|
| 5094 | 5094 | |
| 5095 | - return $flux; |
|
| 5095 | + return $flux; |
|
| 5096 | 5096 | } |
| 5097 | 5097 | |
| 5098 | 5098 | /** |
@@ -5115,75 +5115,75 @@ discard block |
||
| 5115 | 5115 | * @return string |
| 5116 | 5116 | */ |
| 5117 | 5117 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 5118 | - if (isset($contexte['format'])) { |
|
| 5119 | - $extension = $contexte['format']; |
|
| 5120 | - unset($contexte['format']); |
|
| 5121 | - } else { |
|
| 5122 | - $extension = 'html'; |
|
| 5123 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5124 | - $extension = $m[1]; |
|
| 5125 | - } |
|
| 5126 | - } |
|
| 5127 | - // recuperer le contenu produit par le squelette |
|
| 5128 | - $options['raw'] = true; |
|
| 5129 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5130 | - |
|
| 5131 | - // calculer le nom de la css |
|
| 5132 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5133 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5134 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5135 | - |
|
| 5136 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5137 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5138 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5139 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5140 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5141 | - } |
|
| 5142 | - else { |
|
| 5143 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5144 | - ksort($contexte); |
|
| 5145 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5146 | - } |
|
| 5147 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5148 | - |
|
| 5149 | - // mettre a jour le fichier si il n'existe pas |
|
| 5150 | - // ou trop ancien |
|
| 5151 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5152 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5153 | - if ( |
|
| 5154 | - !file_exists($filename) |
|
| 5155 | - or !file_exists($filename . '.last') |
|
| 5156 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5157 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5158 | - ) { |
|
| 5159 | - $contenu = $cache['texte']; |
|
| 5160 | - // passer les urls en absolu si c'est une css |
|
| 5161 | - if ($extension == 'css') { |
|
| 5162 | - $contenu = urls_absolues_css( |
|
| 5163 | - $contenu, |
|
| 5164 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5165 | - ); |
|
| 5166 | - } |
|
| 5167 | - |
|
| 5168 | - $comment = ''; |
|
| 5169 | - // ne pas insérer de commentaire sur certains formats |
|
| 5170 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5171 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5172 | - foreach ($contexte as $k => $v) { |
|
| 5173 | - if (is_array($v)) { |
|
| 5174 | - $v = var_export($v, true); |
|
| 5175 | - } |
|
| 5176 | - $comment .= ",$k=$v"; |
|
| 5177 | - } |
|
| 5178 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5179 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5180 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5181 | - } |
|
| 5182 | - // et ecrire le fichier si il change |
|
| 5183 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5184 | - } |
|
| 5185 | - |
|
| 5186 | - return timestamp($filename); |
|
| 5118 | + if (isset($contexte['format'])) { |
|
| 5119 | + $extension = $contexte['format']; |
|
| 5120 | + unset($contexte['format']); |
|
| 5121 | + } else { |
|
| 5122 | + $extension = 'html'; |
|
| 5123 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5124 | + $extension = $m[1]; |
|
| 5125 | + } |
|
| 5126 | + } |
|
| 5127 | + // recuperer le contenu produit par le squelette |
|
| 5128 | + $options['raw'] = true; |
|
| 5129 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5130 | + |
|
| 5131 | + // calculer le nom de la css |
|
| 5132 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5133 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5134 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5135 | + |
|
| 5136 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5137 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5138 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5139 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5140 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5141 | + } |
|
| 5142 | + else { |
|
| 5143 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5144 | + ksort($contexte); |
|
| 5145 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5146 | + } |
|
| 5147 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5148 | + |
|
| 5149 | + // mettre a jour le fichier si il n'existe pas |
|
| 5150 | + // ou trop ancien |
|
| 5151 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5152 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5153 | + if ( |
|
| 5154 | + !file_exists($filename) |
|
| 5155 | + or !file_exists($filename . '.last') |
|
| 5156 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5157 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5158 | + ) { |
|
| 5159 | + $contenu = $cache['texte']; |
|
| 5160 | + // passer les urls en absolu si c'est une css |
|
| 5161 | + if ($extension == 'css') { |
|
| 5162 | + $contenu = urls_absolues_css( |
|
| 5163 | + $contenu, |
|
| 5164 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5165 | + ); |
|
| 5166 | + } |
|
| 5167 | + |
|
| 5168 | + $comment = ''; |
|
| 5169 | + // ne pas insérer de commentaire sur certains formats |
|
| 5170 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5171 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5172 | + foreach ($contexte as $k => $v) { |
|
| 5173 | + if (is_array($v)) { |
|
| 5174 | + $v = var_export($v, true); |
|
| 5175 | + } |
|
| 5176 | + $comment .= ",$k=$v"; |
|
| 5177 | + } |
|
| 5178 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5179 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5180 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5181 | + } |
|
| 5182 | + // et ecrire le fichier si il change |
|
| 5183 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5184 | + } |
|
| 5185 | + |
|
| 5186 | + return timestamp($filename); |
|
| 5187 | 5187 | } |
| 5188 | 5188 | |
| 5189 | 5189 | /** |
@@ -5196,15 +5196,15 @@ discard block |
||
| 5196 | 5196 | * $fichier auquel on a ajouté le timestamp |
| 5197 | 5197 | */ |
| 5198 | 5198 | function timestamp($fichier) { |
| 5199 | - if ( |
|
| 5200 | - !$fichier |
|
| 5201 | - or !file_exists($fichier) |
|
| 5202 | - or !$m = filemtime($fichier) |
|
| 5203 | - ) { |
|
| 5204 | - return $fichier; |
|
| 5205 | - } |
|
| 5199 | + if ( |
|
| 5200 | + !$fichier |
|
| 5201 | + or !file_exists($fichier) |
|
| 5202 | + or !$m = filemtime($fichier) |
|
| 5203 | + ) { |
|
| 5204 | + return $fichier; |
|
| 5205 | + } |
|
| 5206 | 5206 | |
| 5207 | - return "$fichier?$m"; |
|
| 5207 | + return "$fichier?$m"; |
|
| 5208 | 5208 | } |
| 5209 | 5209 | |
| 5210 | 5210 | /** |
@@ -5214,11 +5214,11 @@ discard block |
||
| 5214 | 5214 | * @return string |
| 5215 | 5215 | */ |
| 5216 | 5216 | function supprimer_timestamp($url) { |
| 5217 | - if (strpos($url, '?') === false) { |
|
| 5218 | - return $url; |
|
| 5219 | - } |
|
| 5217 | + if (strpos($url, '?') === false) { |
|
| 5218 | + return $url; |
|
| 5219 | + } |
|
| 5220 | 5220 | |
| 5221 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5221 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5222 | 5222 | } |
| 5223 | 5223 | |
| 5224 | 5224 | /** |
@@ -5233,15 +5233,15 @@ discard block |
||
| 5233 | 5233 | * @return string |
| 5234 | 5234 | */ |
| 5235 | 5235 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5236 | - include_spip('inc/envoyer_mail'); |
|
| 5236 | + include_spip('inc/envoyer_mail'); |
|
| 5237 | 5237 | |
| 5238 | - $titre = nettoyer_titre_email($titre); |
|
| 5239 | - // on est dans un squelette : securiser le retour |
|
| 5240 | - if (strpos($titre, '<') !== false) { |
|
| 5241 | - $titre = interdire_scripts($titre); |
|
| 5242 | - } |
|
| 5238 | + $titre = nettoyer_titre_email($titre); |
|
| 5239 | + // on est dans un squelette : securiser le retour |
|
| 5240 | + if (strpos($titre, '<') !== false) { |
|
| 5241 | + $titre = interdire_scripts($titre); |
|
| 5242 | + } |
|
| 5243 | 5243 | |
| 5244 | - return $titre; |
|
| 5244 | + return $titre; |
|
| 5245 | 5245 | } |
| 5246 | 5246 | |
| 5247 | 5247 | /** |
@@ -5263,27 +5263,27 @@ discard block |
||
| 5263 | 5263 | * @return string |
| 5264 | 5264 | */ |
| 5265 | 5265 | function filtre_chercher_rubrique_dist( |
| 5266 | - $titre, |
|
| 5267 | - $id_objet, |
|
| 5268 | - $id_parent, |
|
| 5269 | - $objet, |
|
| 5270 | - $id_secteur, |
|
| 5271 | - $restreint, |
|
| 5272 | - $actionable = false, |
|
| 5273 | - $retour_sans_cadre = false |
|
| 5266 | + $titre, |
|
| 5267 | + $id_objet, |
|
| 5268 | + $id_parent, |
|
| 5269 | + $objet, |
|
| 5270 | + $id_secteur, |
|
| 5271 | + $restreint, |
|
| 5272 | + $actionable = false, |
|
| 5273 | + $retour_sans_cadre = false |
|
| 5274 | 5274 | ) { |
| 5275 | - include_spip('inc/filtres_ecrire'); |
|
| 5275 | + include_spip('inc/filtres_ecrire'); |
|
| 5276 | 5276 | |
| 5277 | - return chercher_rubrique( |
|
| 5278 | - $titre, |
|
| 5279 | - $id_objet, |
|
| 5280 | - $id_parent, |
|
| 5281 | - $objet, |
|
| 5282 | - $id_secteur, |
|
| 5283 | - $restreint, |
|
| 5284 | - $actionable, |
|
| 5285 | - $retour_sans_cadre |
|
| 5286 | - ); |
|
| 5277 | + return chercher_rubrique( |
|
| 5278 | + $titre, |
|
| 5279 | + $id_objet, |
|
| 5280 | + $id_parent, |
|
| 5281 | + $objet, |
|
| 5282 | + $id_secteur, |
|
| 5283 | + $restreint, |
|
| 5284 | + $actionable, |
|
| 5285 | + $retour_sans_cadre |
|
| 5286 | + ); |
|
| 5287 | 5287 | } |
| 5288 | 5288 | |
| 5289 | 5289 | /** |
@@ -5312,56 +5312,56 @@ discard block |
||
| 5312 | 5312 | * Chaîne vide si l'accès est autorisé |
| 5313 | 5313 | */ |
| 5314 | 5314 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5315 | - if ($ok) { |
|
| 5316 | - return ''; |
|
| 5317 | - } |
|
| 5318 | - |
|
| 5319 | - // Vider tous les tampons |
|
| 5320 | - $level = @ob_get_level(); |
|
| 5321 | - while ($level--) { |
|
| 5322 | - @ob_end_clean(); |
|
| 5323 | - } |
|
| 5324 | - |
|
| 5325 | - include_spip('inc/headers'); |
|
| 5326 | - |
|
| 5327 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5328 | - if ($url) { |
|
| 5329 | - redirige_par_entete($url, '', $statut); |
|
| 5330 | - } |
|
| 5331 | - |
|
| 5332 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5333 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 5334 | - $message = $statut; |
|
| 5335 | - $statut = 0; |
|
| 5336 | - } |
|
| 5337 | - if (!$message) { |
|
| 5338 | - $message = ''; |
|
| 5339 | - } |
|
| 5340 | - $statut = intval($statut); |
|
| 5341 | - |
|
| 5342 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5343 | - if (test_espace_prive()) { |
|
| 5344 | - if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5345 | - $statut = 403; |
|
| 5346 | - } |
|
| 5347 | - http_response_code(403); |
|
| 5348 | - $echec = charger_fonction('403', 'exec'); |
|
| 5349 | - $echec($message); |
|
| 5350 | - } else { |
|
| 5351 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5352 | - if (!$statut) { |
|
| 5353 | - $statut = 404; |
|
| 5354 | - } |
|
| 5355 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5356 | - http_response_code($statut); |
|
| 5357 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5358 | - if ($statut >= 400) { |
|
| 5359 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5360 | - } |
|
| 5361 | - } |
|
| 5362 | - |
|
| 5363 | - |
|
| 5364 | - exit; |
|
| 5315 | + if ($ok) { |
|
| 5316 | + return ''; |
|
| 5317 | + } |
|
| 5318 | + |
|
| 5319 | + // Vider tous les tampons |
|
| 5320 | + $level = @ob_get_level(); |
|
| 5321 | + while ($level--) { |
|
| 5322 | + @ob_end_clean(); |
|
| 5323 | + } |
|
| 5324 | + |
|
| 5325 | + include_spip('inc/headers'); |
|
| 5326 | + |
|
| 5327 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5328 | + if ($url) { |
|
| 5329 | + redirige_par_entete($url, '', $statut); |
|
| 5330 | + } |
|
| 5331 | + |
|
| 5332 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5333 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 5334 | + $message = $statut; |
|
| 5335 | + $statut = 0; |
|
| 5336 | + } |
|
| 5337 | + if (!$message) { |
|
| 5338 | + $message = ''; |
|
| 5339 | + } |
|
| 5340 | + $statut = intval($statut); |
|
| 5341 | + |
|
| 5342 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5343 | + if (test_espace_prive()) { |
|
| 5344 | + if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5345 | + $statut = 403; |
|
| 5346 | + } |
|
| 5347 | + http_response_code(403); |
|
| 5348 | + $echec = charger_fonction('403', 'exec'); |
|
| 5349 | + $echec($message); |
|
| 5350 | + } else { |
|
| 5351 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5352 | + if (!$statut) { |
|
| 5353 | + $statut = 404; |
|
| 5354 | + } |
|
| 5355 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5356 | + http_response_code($statut); |
|
| 5357 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5358 | + if ($statut >= 400) { |
|
| 5359 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5360 | + } |
|
| 5361 | + } |
|
| 5362 | + |
|
| 5363 | + |
|
| 5364 | + exit; |
|
| 5365 | 5365 | } |
| 5366 | 5366 | |
| 5367 | 5367 | /** |
@@ -5372,11 +5372,11 @@ discard block |
||
| 5372 | 5372 | * @return string |
| 5373 | 5373 | */ |
| 5374 | 5374 | function filtre_compacte_dist($source, $format = null) { |
| 5375 | - if (function_exists('minifier')) { |
|
| 5376 | - return minifier($source, $format); |
|
| 5377 | - } |
|
| 5375 | + if (function_exists('minifier')) { |
|
| 5376 | + return minifier($source, $format); |
|
| 5377 | + } |
|
| 5378 | 5378 | |
| 5379 | - return $source; |
|
| 5379 | + return $source; |
|
| 5380 | 5380 | } |
| 5381 | 5381 | |
| 5382 | 5382 | |
@@ -5388,32 +5388,32 @@ discard block |
||
| 5388 | 5388 | * @return string |
| 5389 | 5389 | */ |
| 5390 | 5390 | function spip_affiche_mot_de_passe_masque(?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string { |
| 5391 | - $passe ??= ''; |
|
| 5392 | - $l = strlen($passe); |
|
| 5393 | - |
|
| 5394 | - if ($l <= 8 or !$afficher_partiellement) { |
|
| 5395 | - if (!$l) { |
|
| 5396 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5397 | - } |
|
| 5398 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5399 | - } |
|
| 5400 | - |
|
| 5401 | - if (is_null($portion_pourcent)) { |
|
| 5402 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5403 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5404 | - } |
|
| 5405 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5406 | - } |
|
| 5407 | - if ($portion_pourcent >= 100) { |
|
| 5408 | - return $passe; |
|
| 5409 | - } |
|
| 5410 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5411 | - $e = max($e, 0); |
|
| 5412 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5413 | - if ($e > 0 and strlen($mid) > 8) { |
|
| 5414 | - $mid = '***...***'; |
|
| 5415 | - } |
|
| 5416 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5391 | + $passe ??= ''; |
|
| 5392 | + $l = strlen($passe); |
|
| 5393 | + |
|
| 5394 | + if ($l <= 8 or !$afficher_partiellement) { |
|
| 5395 | + if (!$l) { |
|
| 5396 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5397 | + } |
|
| 5398 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5399 | + } |
|
| 5400 | + |
|
| 5401 | + if (is_null($portion_pourcent)) { |
|
| 5402 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5403 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5404 | + } |
|
| 5405 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5406 | + } |
|
| 5407 | + if ($portion_pourcent >= 100) { |
|
| 5408 | + return $passe; |
|
| 5409 | + } |
|
| 5410 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5411 | + $e = max($e, 0); |
|
| 5412 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5413 | + if ($e > 0 and strlen($mid) > 8) { |
|
| 5414 | + $mid = '***...***'; |
|
| 5415 | + } |
|
| 5416 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5417 | 5417 | } |
| 5418 | 5418 | |
| 5419 | 5419 | |
@@ -5434,64 +5434,64 @@ discard block |
||
| 5434 | 5434 | */ |
| 5435 | 5435 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5436 | 5436 | |
| 5437 | - $original = $texte; |
|
| 5438 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5439 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5440 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5437 | + $original = $texte; |
|
| 5438 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5439 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5440 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5441 | 5441 | |
| 5442 | - if (!function_exists('translitteration')) { |
|
| 5443 | - include_spip('inc/charsets'); |
|
| 5444 | - } |
|
| 5442 | + if (!function_exists('translitteration')) { |
|
| 5443 | + include_spip('inc/charsets'); |
|
| 5444 | + } |
|
| 5445 | 5445 | |
| 5446 | - // pas de balise html |
|
| 5447 | - if (strpos($texte, '<') !== false) { |
|
| 5448 | - $texte = strip_tags($texte); |
|
| 5449 | - } |
|
| 5450 | - if (strpos($texte, '&') !== false) { |
|
| 5451 | - $texte = unicode2charset($texte); |
|
| 5452 | - } |
|
| 5453 | - // On enlève les espaces indésirables |
|
| 5454 | - $texte = trim($texte); |
|
| 5446 | + // pas de balise html |
|
| 5447 | + if (strpos($texte, '<') !== false) { |
|
| 5448 | + $texte = strip_tags($texte); |
|
| 5449 | + } |
|
| 5450 | + if (strpos($texte, '&') !== false) { |
|
| 5451 | + $texte = unicode2charset($texte); |
|
| 5452 | + } |
|
| 5453 | + // On enlève les espaces indésirables |
|
| 5454 | + $texte = trim($texte); |
|
| 5455 | 5455 | |
| 5456 | - // On enlève les accents et cie |
|
| 5457 | - $texte = translitteration($texte); |
|
| 5456 | + // On enlève les accents et cie |
|
| 5457 | + $texte = translitteration($texte); |
|
| 5458 | 5458 | |
| 5459 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5460 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5459 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5460 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5461 | 5461 | |
| 5462 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5463 | - while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5464 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5465 | - } |
|
| 5462 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5463 | + while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5464 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5465 | + } |
|
| 5466 | 5466 | |
| 5467 | - // pas de separateur au debut ni a la fin |
|
| 5468 | - $texte = trim($texte, $separateur); |
|
| 5467 | + // pas de separateur au debut ni a la fin |
|
| 5468 | + $texte = trim($texte, $separateur); |
|
| 5469 | 5469 | |
| 5470 | - // en minuscules |
|
| 5471 | - $texte = strtolower($texte); |
|
| 5470 | + // en minuscules |
|
| 5471 | + $texte = strtolower($texte); |
|
| 5472 | 5472 | |
| 5473 | - switch ($type) { |
|
| 5474 | - case 'class': |
|
| 5475 | - case 'id': |
|
| 5476 | - case 'anchor': |
|
| 5477 | - if (preg_match(',^\d,', $texte)) { |
|
| 5478 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5479 | - } |
|
| 5480 | - } |
|
| 5473 | + switch ($type) { |
|
| 5474 | + case 'class': |
|
| 5475 | + case 'id': |
|
| 5476 | + case 'anchor': |
|
| 5477 | + if (preg_match(',^\d,', $texte)) { |
|
| 5478 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5479 | + } |
|
| 5480 | + } |
|
| 5481 | 5481 | |
| 5482 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5483 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5484 | - } |
|
| 5482 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5483 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5484 | + } |
|
| 5485 | 5485 | |
| 5486 | - if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5487 | - if (preg_match(',^\d,', $texte)) { |
|
| 5488 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5489 | - } |
|
| 5490 | - $texte .= $separateur . md5($original); |
|
| 5491 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5492 | - } |
|
| 5486 | + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5487 | + if (preg_match(',^\d,', $texte)) { |
|
| 5488 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5489 | + } |
|
| 5490 | + $texte .= $separateur . md5($original); |
|
| 5491 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5492 | + } |
|
| 5493 | 5493 | |
| 5494 | - return $texte; |
|
| 5494 | + return $texte; |
|
| 5495 | 5495 | } |
| 5496 | 5496 | |
| 5497 | 5497 | |
@@ -5512,11 +5512,11 @@ discard block |
||
| 5512 | 5512 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5513 | 5513 | */ |
| 5514 | 5514 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5515 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5516 | - if ($ucfirst) { |
|
| 5517 | - $label = spip_ucfirst($label); |
|
| 5518 | - } |
|
| 5519 | - return $label; |
|
| 5515 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5516 | + if ($ucfirst) { |
|
| 5517 | + $label = spip_ucfirst($label); |
|
| 5518 | + } |
|
| 5519 | + return $label; |
|
| 5520 | 5520 | } |
| 5521 | 5521 | |
| 5522 | 5522 | /** |
@@ -5529,8 +5529,8 @@ discard block |
||
| 5529 | 5529 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5530 | 5530 | */ |
| 5531 | 5531 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5532 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5533 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5532 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5533 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5534 | 5534 | } |
| 5535 | 5535 | |
| 5536 | 5536 | |
@@ -5543,19 +5543,19 @@ discard block |
||
| 5543 | 5543 | * @return array |
| 5544 | 5544 | */ |
| 5545 | 5545 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5546 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5547 | - return []; |
|
| 5548 | - } |
|
| 5546 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5547 | + return []; |
|
| 5548 | + } |
|
| 5549 | 5549 | |
| 5550 | - // compatibilite signature inversee |
|
| 5551 | - if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5552 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5553 | - } |
|
| 5550 | + // compatibilite signature inversee |
|
| 5551 | + if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5552 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5553 | + } |
|
| 5554 | 5554 | |
| 5555 | - if (!function_exists($fonction)) { |
|
| 5556 | - include_spip('base/objets'); |
|
| 5557 | - } |
|
| 5558 | - return $fonction($objet, $id_objet); |
|
| 5555 | + if (!function_exists($fonction)) { |
|
| 5556 | + include_spip('base/objets'); |
|
| 5557 | + } |
|
| 5558 | + return $fonction($objet, $id_objet); |
|
| 5559 | 5559 | } |
| 5560 | 5560 | |
| 5561 | 5561 | |
@@ -5570,7 +5570,7 @@ discard block |
||
| 5570 | 5570 | * @return array |
| 5571 | 5571 | */ |
| 5572 | 5572 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5573 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5573 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5574 | 5574 | } |
| 5575 | 5575 | |
| 5576 | 5576 | /** |
@@ -5584,7 +5584,7 @@ discard block |
||
| 5584 | 5584 | * @return array |
| 5585 | 5585 | */ |
| 5586 | 5586 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5587 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5587 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5588 | 5588 | } |
| 5589 | 5589 | |
| 5590 | 5590 | /** |
@@ -5598,7 +5598,7 @@ discard block |
||
| 5598 | 5598 | * @return array |
| 5599 | 5599 | */ |
| 5600 | 5600 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5601 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5601 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5602 | 5602 | } |
| 5603 | 5603 | |
| 5604 | 5604 | /** |
@@ -5612,5 +5612,5 @@ discard block |
||
| 5612 | 5612 | * @return array |
| 5613 | 5613 | */ |
| 5614 | 5614 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5615 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5615 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5616 | 5616 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | include_fichiers_fonctions(); |
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 99 | + foreach (['filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc] as $f) { |
|
| 100 | 100 | trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
| 101 | 101 | if (is_callable($f)) { |
| 102 | 102 | return $f; |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | // affichage "GIT [master: abcdef]" |
| 235 | 235 | $commit = $desc['commit_short'] ?? $desc['commit']; |
| 236 | 236 | if ($desc['branch']) { |
| 237 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 237 | + $commit = $desc['branch'].': '.$commit; |
|
| 238 | 238 | } |
| 239 | 239 | return "{$desc['vcs']} [$commit]"; |
| 240 | 240 | } |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // version installee par GIT |
| 256 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 256 | + if (lire_fichier($dir.'/.git/HEAD', $c)) { |
|
| 257 | 257 | $currentHead = trim(substr($c, 4)); |
| 258 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 258 | + if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) { |
|
| 259 | 259 | return [ |
| 260 | 260 | 'vcs' => 'GIT', |
| 261 | 261 | 'branch' => basename($currentHead), |
@@ -282,8 +282,8 @@ discard block |
||
| 282 | 282 | $dir = '.'; |
| 283 | 283 | } |
| 284 | 284 | // version installee par SVN |
| 285 | - if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 286 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 285 | + if (file_exists($dir.'/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 286 | + $db = new SQLite3($dir.'/.svn/wc.db'); |
|
| 287 | 287 | $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
| 288 | 288 | if ($result) { |
| 289 | 289 | $row = $result->fetchArray(); |
@@ -301,12 +301,12 @@ discard block |
||
| 301 | 301 | |
| 302 | 302 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
| 303 | 303 | // et laisser passer les fonctions personnelles baptisees image_... |
| 304 | -$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php'; |
|
| 305 | -$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php'; |
|
| 306 | -$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php'; |
|
| 307 | -$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php'; |
|
| 308 | -$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php'; |
|
| 309 | -$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true;//'inc/filtres_images_mini.php'; |
|
| 304 | +$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php'; |
|
| 305 | +$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php'; |
|
| 306 | +$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php'; |
|
| 307 | +$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php'; |
|
| 308 | +$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php'; |
|
| 309 | +$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true; //'inc/filtres_images_mini.php'; |
|
| 310 | 310 | |
| 311 | 311 | $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php'; |
| 312 | 312 | $GLOBALS['spip_matrice']['couleur_hex_to_hsl'] = 'inc/filtres_images_mini.php'; |
@@ -465,8 +465,8 @@ discard block |
||
| 465 | 465 | */ |
| 466 | 466 | function filtre_debug($val, $key = null) { |
| 467 | 467 | $debug = ( |
| 468 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 469 | - ) . var_export($val, true); |
|
| 468 | + is_null($key) ? '' : (var_export($key, true).' = ') |
|
| 469 | + ).var_export($val, true); |
|
| 470 | 470 | |
| 471 | 471 | include_spip('inc/autoriser'); |
| 472 | 472 | if (autoriser('webmestre')) { |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | $is_file = false; |
| 523 | 523 | } |
| 524 | 524 | if ($is_file) { |
| 525 | - $is_local_file = function ($path) { |
|
| 525 | + $is_local_file = function($path) { |
|
| 526 | 526 | if (strpos($path, '?') !== false) { |
| 527 | 527 | $path = supprimer_timestamp($path); |
| 528 | 528 | // remove ?24px added by find_in_theme on .svg files |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
| 572 | 572 | if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
| 573 | 573 | $srcover = $match[1]; |
| 574 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 574 | + $srcover_filter = $filtre("<img src='".$match[1]."' />", ...$args); |
|
| 575 | 575 | $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
| 576 | 576 | $reduit = str_replace($srcover, $srcover_filter, $reduit); |
| 577 | 577 | } |
@@ -973,7 +973,7 @@ discard block |
||
| 973 | 973 | // " -> " et tout ce genre de choses |
| 974 | 974 | $u = $GLOBALS['meta']['pcre_u']; |
| 975 | 975 | $texte = str_replace(' ', ' ', $texte); |
| 976 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 976 | + $texte = preg_replace('/\s{2,}/S'.$u, ' ', $texte); |
|
| 977 | 977 | // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
| 978 | 978 | $texte = entites_html($texte, false, false); |
| 979 | 979 | // mais bien echapper les double quotes ! |
@@ -1035,7 +1035,7 @@ discard block |
||
| 1035 | 1035 | return ''; |
| 1036 | 1036 | } |
| 1037 | 1037 | return preg_replace( |
| 1038 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1038 | + ',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S', |
|
| 1039 | 1039 | '', |
| 1040 | 1040 | $texte |
| 1041 | 1041 | ); |
@@ -1064,7 +1064,7 @@ discard block |
||
| 1064 | 1064 | if ( |
| 1065 | 1065 | $texte and |
| 1066 | 1066 | preg_match( |
| 1067 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1067 | + ',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S', |
|
| 1068 | 1068 | $texte, |
| 1069 | 1069 | $regs |
| 1070 | 1070 | ) |
@@ -1155,8 +1155,8 @@ discard block |
||
| 1155 | 1155 | **/ |
| 1156 | 1156 | function textebrut($texte) { |
| 1157 | 1157 | $u = $GLOBALS['meta']['pcre_u']; |
| 1158 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1159 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1158 | + $texte = preg_replace('/\s+/S'.$u, ' ', $texte); |
|
| 1159 | + $texte = preg_replace('/<(p|br)( [^>]*)?'.'>/iS', "\n\n", $texte); |
|
| 1160 | 1160 | $texte = preg_replace("/^\n+/", '', $texte); |
| 1161 | 1161 | $texte = preg_replace("/\n+$/", '', $texte); |
| 1162 | 1162 | $texte = preg_replace("/\n +/", "\n", $texte); |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | ) |
| 1191 | 1191 | ) { |
| 1192 | 1192 | foreach ($liens[0] as $a) { |
| 1193 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1193 | + $rel = 'noopener noreferrer '.extraire_attribut($a, 'rel'); |
|
| 1194 | 1194 | $ablank = inserer_attribut($a, 'rel', $rel); |
| 1195 | 1195 | $ablank = inserer_attribut($ablank, 'target', '_blank'); |
| 1196 | 1196 | $texte = str_replace($a, $ablank, $texte); |
@@ -1215,7 +1215,7 @@ discard block |
||
| 1215 | 1215 | foreach ($regs[0] as $a) { |
| 1216 | 1216 | $rel = extraire_attribut($a, 'rel') ?? ''; |
| 1217 | 1217 | if (strpos($rel, 'nofollow') === false) { |
| 1218 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1218 | + $rel = 'nofollow'.($rel ? " $rel" : ''); |
|
| 1219 | 1219 | $anofollow = inserer_attribut($a, 'rel', $rel); |
| 1220 | 1220 | $texte = str_replace($a, $anofollow, $texte); |
| 1221 | 1221 | } |
@@ -1244,7 +1244,7 @@ discard block |
||
| 1244 | 1244 | $u = $GLOBALS['meta']['pcre_u']; |
| 1245 | 1245 | $texte = preg_replace('@</p>@iS', "\n", $texte); |
| 1246 | 1246 | $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
| 1247 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1247 | + $texte = preg_replace('@^\s*<br />@S'.$u, '', $texte); |
|
| 1248 | 1248 | |
| 1249 | 1249 | return $texte; |
| 1250 | 1250 | } |
@@ -1275,7 +1275,7 @@ discard block |
||
| 1275 | 1275 | return $texte; |
| 1276 | 1276 | } |
| 1277 | 1277 | include_spip('inc/texte'); |
| 1278 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1278 | + $tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ? |
|
| 1279 | 1279 | 'div' : 'span'; |
| 1280 | 1280 | |
| 1281 | 1281 | return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
@@ -1387,7 +1387,7 @@ discard block |
||
| 1387 | 1387 | } |
| 1388 | 1388 | $u = $GLOBALS['meta']['pcre_u']; |
| 1389 | 1389 | if ($textebrut) { |
| 1390 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1390 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS'.$u], [' ', ''], textebrut($texte)); |
|
| 1391 | 1391 | } |
| 1392 | 1392 | $texte = texte_backend($texte); |
| 1393 | 1393 | $texte = str_replace(["'", '"'], [''', '"'], $texte); |
@@ -1422,7 +1422,7 @@ discard block |
||
| 1422 | 1422 | # un message pour abs_url |
| 1423 | 1423 | $GLOBALS['mode_abs_url'] = 'url'; |
| 1424 | 1424 | $url = trim($url); |
| 1425 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1425 | + $r = ',^(?:'._PROTOCOLES_STD.'):?/?/?$,iS'; |
|
| 1426 | 1426 | |
| 1427 | 1427 | return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
| 1428 | 1428 | } |
@@ -1629,7 +1629,7 @@ discard block |
||
| 1629 | 1629 | |
| 1630 | 1630 | $debut = ''; |
| 1631 | 1631 | $suite = $texte; |
| 1632 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1632 | + while ($t = strpos('-'.$suite, "\n", 1)) { |
|
| 1633 | 1633 | $debut .= substr($suite, 0, $t - 1); |
| 1634 | 1634 | $suite = substr($suite, $t); |
| 1635 | 1635 | $car = substr($suite, 0, 1); |
@@ -1647,7 +1647,7 @@ discard block |
||
| 1647 | 1647 | $suite = substr($suite, strlen($regs[0])); |
| 1648 | 1648 | } |
| 1649 | 1649 | } |
| 1650 | - $texte = $debut . $suite; |
|
| 1650 | + $texte = $debut.$suite; |
|
| 1651 | 1651 | |
| 1652 | 1652 | if ($collecteurModeles) { |
| 1653 | 1653 | $texte = $collecteurModeles->retablir($texte); |
@@ -1655,7 +1655,7 @@ discard block |
||
| 1655 | 1655 | |
| 1656 | 1656 | $texte = echappe_retour($texte); |
| 1657 | 1657 | |
| 1658 | - return $texte . $fin; |
|
| 1658 | + return $texte.$fin; |
|
| 1659 | 1659 | } |
| 1660 | 1660 | |
| 1661 | 1661 | |
@@ -1931,7 +1931,7 @@ discard block |
||
| 1931 | 1931 | if (is_array($balise)) { |
| 1932 | 1932 | array_walk( |
| 1933 | 1933 | $balise, |
| 1934 | - function (&$a, $key, $t) { |
|
| 1934 | + function(&$a, $key, $t) { |
|
| 1935 | 1935 | $a = extraire_attribut($a, $t); |
| 1936 | 1936 | }, |
| 1937 | 1937 | $attribut |
@@ -2029,14 +2029,14 @@ discard block |
||
| 2029 | 2029 | |
| 2030 | 2030 | if ($old !== null) { |
| 2031 | 2031 | // Remplacer l'ancien attribut du meme nom |
| 2032 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2032 | + $balise = $r[1].$insert.$r[5]; |
|
| 2033 | 2033 | } else { |
| 2034 | 2034 | // preferer une balise " />" (comme <img />) |
| 2035 | 2035 | if (preg_match(',/>,', $balise)) { |
| 2036 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2036 | + $balise = preg_replace(',\s?/>,S', $insert.' />', $balise, 1); |
|
| 2037 | 2037 | } // sinon une balise <a ...> ... </a> |
| 2038 | 2038 | else { |
| 2039 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2039 | + $balise = preg_replace(',\s?>,S', $insert.'>', $balise, 1); |
|
| 2040 | 2040 | } |
| 2041 | 2041 | } |
| 2042 | 2042 | |
@@ -2091,7 +2091,7 @@ discard block |
||
| 2091 | 2091 | if ( |
| 2092 | 2092 | $class_courante |
| 2093 | 2093 | and strpos($class_courante, (string) $c) !== false |
| 2094 | - and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2094 | + and preg_match('/(^|\s)'.preg_quote($c).'($|\s)/', $class_courante) |
|
| 2095 | 2095 | ) { |
| 2096 | 2096 | $is_class_presente = true; |
| 2097 | 2097 | } |
@@ -2099,12 +2099,12 @@ discard block |
||
| 2099 | 2099 | in_array($operation, ['ajouter', 'commuter']) |
| 2100 | 2100 | and !$is_class_presente |
| 2101 | 2101 | ) { |
| 2102 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2102 | + $class_new = ltrim(rtrim($class_new ?? '').' '.$c); |
|
| 2103 | 2103 | } elseif ( |
| 2104 | 2104 | in_array($operation, ['supprimer', 'commuter']) |
| 2105 | 2105 | and $is_class_presente |
| 2106 | 2106 | ) { |
| 2107 | - $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2107 | + $class_new = trim(preg_replace('/(^|\s)'.preg_quote($c).'($|\s)/', "\\1", $class_new)); |
|
| 2108 | 2108 | } |
| 2109 | 2109 | } |
| 2110 | 2110 | |
@@ -2167,7 +2167,7 @@ discard block |
||
| 2167 | 2167 | // Quelques fonctions de calcul arithmetique |
| 2168 | 2168 | // |
| 2169 | 2169 | function floatstr($a) { |
| 2170 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2170 | + return str_replace(',', '.', (string) floatval($a)); |
|
| 2171 | 2171 | } |
| 2172 | 2172 | function strize($f, $a, $b) { |
| 2173 | 2173 | return floatstr($f(floatstr($a), floatstr($b))); |
@@ -2303,13 +2303,13 @@ discard block |
||
| 2303 | 2303 | if (!defined('_TAGS_NOM_AUTEUR')) { |
| 2304 | 2304 | define('_TAGS_NOM_AUTEUR', ''); |
| 2305 | 2305 | } |
| 2306 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2306 | + $tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR)); |
|
| 2307 | 2307 | foreach ($tags_acceptes as $tag) { |
| 2308 | 2308 | if (strlen($tag)) { |
| 2309 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2310 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2311 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2312 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2309 | + $remp1[] = '<'.trim($tag).'>'; |
|
| 2310 | + $remp1[] = '</'.trim($tag).'>'; |
|
| 2311 | + $remp2[] = '\x60'.trim($tag).'\x61'; |
|
| 2312 | + $remp2[] = '\x60/'.trim($tag).'\x61'; |
|
| 2313 | 2313 | } |
| 2314 | 2314 | } |
| 2315 | 2315 | $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
@@ -2429,10 +2429,10 @@ discard block |
||
| 2429 | 2429 | $fichier = basename($url); |
| 2430 | 2430 | |
| 2431 | 2431 | return '<a rel="enclosure"' |
| 2432 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2433 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2434 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2435 | - . '>' . $fichier . '</a>'; |
|
| 2432 | + . ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2433 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2434 | + . ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '') |
|
| 2435 | + . '>'.$fichier.'</a>'; |
|
| 2436 | 2436 | } |
| 2437 | 2437 | |
| 2438 | 2438 | /** |
@@ -2460,9 +2460,9 @@ discard block |
||
| 2460 | 2460 | } # vieux data |
| 2461 | 2461 | $fichier = basename($url); |
| 2462 | 2462 | $enclosures[] = '<enclosure' |
| 2463 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2464 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2465 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2463 | + . ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2464 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2465 | + . ($length ? ' length="'.$length.'"' : '') |
|
| 2466 | 2466 | . ' />'; |
| 2467 | 2467 | } |
| 2468 | 2468 | } |
@@ -2488,7 +2488,7 @@ discard block |
||
| 2488 | 2488 | if (extraire_attribut($e, 'rel') == 'tag') { |
| 2489 | 2489 | $subjects .= '<dc:subject>' |
| 2490 | 2490 | . texte_backend(textebrut($e)) |
| 2491 | - . '</dc:subject>' . "\n"; |
|
| 2491 | + . '</dc:subject>'."\n"; |
|
| 2492 | 2492 | } |
| 2493 | 2493 | } |
| 2494 | 2494 | |
@@ -2524,7 +2524,7 @@ discard block |
||
| 2524 | 2524 | if (is_array($texte)) { |
| 2525 | 2525 | array_walk( |
| 2526 | 2526 | $texte, |
| 2527 | - function (&$a, $key, $t) { |
|
| 2527 | + function(&$a, $key, $t) { |
|
| 2528 | 2528 | $a = extraire_balise($a, $t); |
| 2529 | 2529 | }, |
| 2530 | 2530 | $tag |
@@ -2572,7 +2572,7 @@ discard block |
||
| 2572 | 2572 | if (is_array($texte)) { |
| 2573 | 2573 | array_walk( |
| 2574 | 2574 | $texte, |
| 2575 | - function (&$a, $key, $t) { |
|
| 2575 | + function(&$a, $key, $t) { |
|
| 2576 | 2576 | $a = extraire_balises($a, $t); |
| 2577 | 2577 | }, |
| 2578 | 2578 | $tag |
@@ -2705,7 +2705,7 @@ discard block |
||
| 2705 | 2705 | if ($fond != '404') { |
| 2706 | 2706 | $contexte = array_shift($p); |
| 2707 | 2707 | $contexte['page'] = $fond; |
| 2708 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2708 | + $action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2709 | 2709 | } |
| 2710 | 2710 | } |
| 2711 | 2711 | // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
@@ -2760,9 +2760,9 @@ discard block |
||
| 2760 | 2760 | . '"' |
| 2761 | 2761 | . (is_null($val) |
| 2762 | 2762 | ? '' |
| 2763 | - : ' value="' . entites_html($val) . '"' |
|
| 2763 | + : ' value="'.entites_html($val).'"' |
|
| 2764 | 2764 | ) |
| 2765 | - . ' type="hidden"' . "\n/>"; |
|
| 2765 | + . ' type="hidden"'."\n/>"; |
|
| 2766 | 2766 | } |
| 2767 | 2767 | |
| 2768 | 2768 | return join('', $hidden); |
@@ -2872,7 +2872,7 @@ discard block |
||
| 2872 | 2872 | |
| 2873 | 2873 | return preg_replace_callback( |
| 2874 | 2874 | ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
| 2875 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2875 | + fn($x) => "url('".suivre_lien($path, $x[1])."')", |
|
| 2876 | 2876 | $contenu |
| 2877 | 2877 | ); |
| 2878 | 2878 | } |
@@ -2933,14 +2933,14 @@ discard block |
||
| 2933 | 2933 | ) { |
| 2934 | 2934 | $distant = true; |
| 2935 | 2935 | $cssf = parse_url($css); |
| 2936 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2936 | + $cssf = $cssf['path'].($cssf['query'] ? '?'.$cssf['query'] : ''); |
|
| 2937 | 2937 | $cssf = preg_replace(',[?:&=],', '_', $cssf); |
| 2938 | 2938 | } else { |
| 2939 | 2939 | $distant = false; |
| 2940 | 2940 | $cssf = $css; |
| 2941 | 2941 | // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
| 2942 | 2942 | //propose (rien a faire dans ce cas) |
| 2943 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2943 | + $f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css); |
|
| 2944 | 2944 | if (@file_exists($f)) { |
| 2945 | 2945 | return $f; |
| 2946 | 2946 | } |
@@ -2950,7 +2950,7 @@ discard block |
||
| 2950 | 2950 | $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
| 2951 | 2951 | $f = $dir_var |
| 2952 | 2952 | . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
| 2953 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2953 | + . '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css'; |
|
| 2954 | 2954 | |
| 2955 | 2955 | // la css peut etre distante (url absolue !) |
| 2956 | 2956 | if ($distant) { |
@@ -2996,8 +2996,8 @@ discard block |
||
| 2996 | 2996 | } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
| 2997 | 2997 | elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
| 2998 | 2998 | $css_direction = substr($css_direction, strlen($dir_var)); |
| 2999 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3000 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2999 | + $src_faux_abs['/@@@@@@/'.$css_direction] = $css_direction; |
|
| 3000 | + $css_direction = '/@@@@@@/'.$css_direction; |
|
| 3001 | 3001 | } |
| 3002 | 3002 | $src[] = $regs[0][$k]; |
| 3003 | 3003 | $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
@@ -3046,7 +3046,7 @@ discard block |
||
| 3046 | 3046 | |
| 3047 | 3047 | $f = basename($css, '.css'); |
| 3048 | 3048 | $f = sous_repertoire(_DIR_VAR, 'cache-css') |
| 3049 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3049 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f) |
|
| 3050 | 3050 | . '.css'; |
| 3051 | 3051 | |
| 3052 | 3052 | if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
@@ -3056,7 +3056,7 @@ discard block |
||
| 3056 | 3056 | if ($url_absolue_css == $css) { |
| 3057 | 3057 | if ( |
| 3058 | 3058 | strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
| 3059 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3059 | + or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu) |
|
| 3060 | 3060 | ) { |
| 3061 | 3061 | include_spip('inc/distant'); |
| 3062 | 3062 | $contenu = recuperer_url($css); |
@@ -3168,7 +3168,7 @@ discard block |
||
| 3168 | 3168 | $expression = str_replace('\/', '/', $expression); |
| 3169 | 3169 | $expression = str_replace('/', '\/', $expression); |
| 3170 | 3170 | |
| 3171 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3171 | + if (preg_match('/'.$expression.'/'.$modif, $texte ?? '', $r)) { |
|
| 3172 | 3172 | if (isset($r[$capte])) { |
| 3173 | 3173 | return $r[$capte]; |
| 3174 | 3174 | } else { |
@@ -3206,7 +3206,7 @@ discard block |
||
| 3206 | 3206 | $expression = str_replace('\/', '/', $expression); |
| 3207 | 3207 | $expression = str_replace('/', '\/', $expression); |
| 3208 | 3208 | |
| 3209 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3209 | + return preg_replace('/'.$expression.'/'.$modif, $replace, $texte); |
|
| 3210 | 3210 | } |
| 3211 | 3211 | |
| 3212 | 3212 | |
@@ -3225,7 +3225,7 @@ discard block |
||
| 3225 | 3225 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3226 | 3226 | |
| 3227 | 3227 | // Verifier dans le texte & les notes (pas beau, helas) |
| 3228 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3228 | + $t = $letexte.$GLOBALS['les_notes']; |
|
| 3229 | 3229 | |
| 3230 | 3230 | if ( |
| 3231 | 3231 | strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
@@ -3239,7 +3239,7 @@ discard block |
||
| 3239 | 3239 | if (!isset($doublons['documents'])) { |
| 3240 | 3240 | $doublons['documents'] = ''; |
| 3241 | 3241 | } |
| 3242 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3242 | + $doublons['documents'] .= ','.join(',', $matches[1]); |
|
| 3243 | 3243 | } |
| 3244 | 3244 | |
| 3245 | 3245 | return $letexte; |
@@ -3296,7 +3296,7 @@ discard block |
||
| 3296 | 3296 | if ($env) { |
| 3297 | 3297 | foreach ($env as $i => $j) { |
| 3298 | 3298 | if (is_string($j) and !in_array($i, $ignore_params)) { |
| 3299 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3299 | + $texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />"; |
|
| 3300 | 3300 | } |
| 3301 | 3301 | } |
| 3302 | 3302 | } |
@@ -3335,7 +3335,7 @@ discard block |
||
| 3335 | 3335 | if ($env) { |
| 3336 | 3336 | foreach ($env as $i => $j) { |
| 3337 | 3337 | if (is_string($j) and !in_array($i, $ignore_params)) { |
| 3338 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3338 | + $texte .= attribut_html($i)."='".attribut_html($j)."' "; |
|
| 3339 | 3339 | } |
| 3340 | 3340 | } |
| 3341 | 3341 | } |
@@ -3409,10 +3409,10 @@ discard block |
||
| 3409 | 3409 | // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
| 3410 | 3410 | if ( |
| 3411 | 3411 | preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
| 3412 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3412 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])).'-xx.svg' |
|
| 3413 | 3413 | and file_exists($variante_svg_generique) |
| 3414 | 3414 | ) { |
| 3415 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3415 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].'.svg' and file_exists($variante_svg_size)) { |
|
| 3416 | 3416 | $img_file = $variante_svg_size; |
| 3417 | 3417 | } |
| 3418 | 3418 | else { |
@@ -3470,7 +3470,7 @@ discard block |
||
| 3470 | 3470 | return ''; |
| 3471 | 3471 | } |
| 3472 | 3472 | } |
| 3473 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3473 | + $atts .= " width='".$largeur."' height='".$hauteur."'"; |
|
| 3474 | 3474 | } |
| 3475 | 3475 | |
| 3476 | 3476 | if (file_exists($img_file)) { |
@@ -3480,14 +3480,14 @@ discard block |
||
| 3480 | 3480 | $alt = ''; |
| 3481 | 3481 | } |
| 3482 | 3482 | elseif ($alt or $alt === '') { |
| 3483 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3483 | + $alt = " alt='".attribut_html($alt)."'"; |
|
| 3484 | 3484 | } |
| 3485 | 3485 | else { |
| 3486 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3486 | + $alt = " alt='".attribut_html($title)."'"; |
|
| 3487 | 3487 | } |
| 3488 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3489 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3490 | - . ' ' . ltrim($atts) |
|
| 3488 | + return "<img src='".attribut_html($img_file)."'$alt" |
|
| 3489 | + . ($title ? ' title="'.attribut_html($title).'"' : '') |
|
| 3490 | + . ' '.ltrim($atts) |
|
| 3491 | 3491 | . ' />'; |
| 3492 | 3492 | } |
| 3493 | 3493 | |
@@ -3501,10 +3501,10 @@ discard block |
||
| 3501 | 3501 | */ |
| 3502 | 3502 | function http_style_background($img, $att = '', $size = null) { |
| 3503 | 3503 | if ($size and is_numeric($size)) { |
| 3504 | - $size = trim($size) . 'px'; |
|
| 3504 | + $size = trim($size).'px'; |
|
| 3505 | 3505 | } |
| 3506 | - return " style='background" . |
|
| 3507 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3506 | + return " style='background". |
|
| 3507 | + ($att ? '' : '-image').': url("'.chemin_image($img).'")'.($att ? (' '.$att) : '').';' |
|
| 3508 | 3508 | . ($size ? "background-size:{$size};" : '') |
| 3509 | 3509 | . "'"; |
| 3510 | 3510 | } |
@@ -3619,7 +3619,7 @@ discard block |
||
| 3619 | 3619 | $img = http_img_pack( |
| 3620 | 3620 | $img, |
| 3621 | 3621 | $alt, |
| 3622 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3622 | + $class ? " class='".attribut_html($class)."'" : '', |
|
| 3623 | 3623 | '', |
| 3624 | 3624 | ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
| 3625 | 3625 | ); |
@@ -3704,7 +3704,7 @@ discard block |
||
| 3704 | 3704 | $balise_svg_source = $balise_svg; |
| 3705 | 3705 | |
| 3706 | 3706 | // entete XML à supprimer |
| 3707 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3707 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?'.'>,', '', $svg); |
|
| 3708 | 3708 | |
| 3709 | 3709 | // IE est toujours mon ami |
| 3710 | 3710 | $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
@@ -3722,9 +3722,9 @@ discard block |
||
| 3722 | 3722 | // regler le alt |
| 3723 | 3723 | if ($alt) { |
| 3724 | 3724 | $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
| 3725 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3725 | + $id = 'img-svg-title-'.substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3726 | 3726 | $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
| 3727 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3727 | + $title = "<title id=\"$id\">".entites_html($alt)."</title>\n"; |
|
| 3728 | 3728 | $balise_svg .= $title; |
| 3729 | 3729 | } |
| 3730 | 3730 | else { |
@@ -3772,7 +3772,7 @@ discard block |
||
| 3772 | 3772 | if (is_array($tableau)) { |
| 3773 | 3773 | foreach ($tableau as $k => $v) { |
| 3774 | 3774 | $res = recuperer_fond( |
| 3775 | - 'modeles/' . $modele, |
|
| 3775 | + 'modeles/'.$modele, |
|
| 3776 | 3776 | array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
| 3777 | 3777 | ); |
| 3778 | 3778 | $texte .= $res; |
@@ -3957,7 +3957,7 @@ discard block |
||
| 3957 | 3957 | } |
| 3958 | 3958 | |
| 3959 | 3959 | $c = serialize($c); |
| 3960 | - $cle = calculer_cle_action($form . $c); |
|
| 3960 | + $cle = calculer_cle_action($form.$c); |
|
| 3961 | 3961 | $c = "$cle:$c"; |
| 3962 | 3962 | |
| 3963 | 3963 | // on ne stocke pas les contextes dans des fichiers en cache |
@@ -4015,15 +4015,15 @@ discard block |
||
| 4015 | 4015 | } |
| 4016 | 4016 | // toujours encoder l'url source dans le bloc ajax |
| 4017 | 4017 | $r = self(); |
| 4018 | - $r = ' data-origin="' . $r . '"'; |
|
| 4018 | + $r = ' data-origin="'.$r.'"'; |
|
| 4019 | 4019 | $class = 'ajaxbloc'; |
| 4020 | 4020 | if ($ajaxid and is_string($ajaxid)) { |
| 4021 | 4021 | // ajaxid est normalement conforme a un nom de classe css |
| 4022 | 4022 | // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
| 4023 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4023 | + $class .= ' ajax-id-'.entites_html($ajaxid); |
|
| 4024 | 4024 | } |
| 4025 | 4025 | |
| 4026 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4026 | + return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4027 | 4027 | } |
| 4028 | 4028 | |
| 4029 | 4029 | /** |
@@ -4067,7 +4067,7 @@ discard block |
||
| 4067 | 4067 | $cle = substr($c, 0, $p); |
| 4068 | 4068 | $c = substr($c, $p + 1); |
| 4069 | 4069 | |
| 4070 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4070 | + if ($cle == calculer_cle_action($form.$c)) { |
|
| 4071 | 4071 | $env = @unserialize($c); |
| 4072 | 4072 | return $env; |
| 4073 | 4073 | } |
@@ -4188,13 +4188,13 @@ discard block |
||
| 4188 | 4188 | } |
| 4189 | 4189 | } |
| 4190 | 4190 | } |
| 4191 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4191 | + $att .= 'class="'.($class ? attribut_html($class).' ' : '').(defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on').'"'; |
|
| 4192 | 4192 | } else { |
| 4193 | 4193 | $bal = 'a'; |
| 4194 | 4194 | $att = "href='$url'" |
| 4195 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4196 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4197 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4195 | + . ($title ? " title='".attribut_html($title)."'" : '') |
|
| 4196 | + . ($class ? " class='".attribut_html($class)."'" : '') |
|
| 4197 | + . ($rel ? " rel='".attribut_html($rel)."'" : '') |
|
| 4198 | 4198 | . $evt; |
| 4199 | 4199 | } |
| 4200 | 4200 | if ($libelle === null) { |
@@ -4333,7 +4333,7 @@ discard block |
||
| 4333 | 4333 | |
| 4334 | 4334 | // Icône |
| 4335 | 4335 | $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
| 4336 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4336 | + $icone = '<span class="icone-image'.($fonction ? " icone-fonction icone-fonction-$fonction" : '')."\">$icone</span>"; |
|
| 4337 | 4337 | |
| 4338 | 4338 | // Markup final |
| 4339 | 4339 | if ($type == 'lien') { |
@@ -4608,20 +4608,20 @@ discard block |
||
| 4608 | 4608 | $class_form = 'ajax'; |
| 4609 | 4609 | $class = str_replace('ajax', '', $class); |
| 4610 | 4610 | } |
| 4611 | - $class_btn = 'submit ' . trim($class); |
|
| 4611 | + $class_btn = 'submit '.trim($class); |
|
| 4612 | 4612 | |
| 4613 | 4613 | if ($confirm) { |
| 4614 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4614 | + $confirm = 'confirm("'.attribut_html($confirm).'")'; |
|
| 4615 | 4615 | if ($callback) { |
| 4616 | 4616 | $callback = "$confirm?($callback):false"; |
| 4617 | 4617 | } else { |
| 4618 | 4618 | $callback = $confirm; |
| 4619 | 4619 | } |
| 4620 | 4620 | } |
| 4621 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4621 | + $onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : ''; |
|
| 4622 | 4622 | $title = $title ? " title='$title'" : ''; |
| 4623 | 4623 | |
| 4624 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4624 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>".form_hidden($url) |
|
| 4625 | 4625 | . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
| 4626 | 4626 | } |
| 4627 | 4627 | |
@@ -4686,14 +4686,14 @@ discard block |
||
| 4686 | 4686 | $champ_titre = ''; |
| 4687 | 4687 | if ($demande_titre) { |
| 4688 | 4688 | // si pas de titre declare mais champ titre, il sera peuple par le select * |
| 4689 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4689 | + $champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : ''; |
|
| 4690 | 4690 | } |
| 4691 | 4691 | include_spip('base/abstract_sql'); |
| 4692 | 4692 | include_spip('base/connect_sql'); |
| 4693 | 4693 | $objets[$type_objet][$id_objet] = sql_fetsel( |
| 4694 | - '*' . $champ_titre, |
|
| 4694 | + '*'.$champ_titre, |
|
| 4695 | 4695 | $desc['table_sql'], |
| 4696 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4696 | + id_table_objet($type_objet).' = '.intval($id_objet) |
|
| 4697 | 4697 | ); |
| 4698 | 4698 | |
| 4699 | 4699 | // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
@@ -4786,8 +4786,7 @@ discard block |
||
| 4786 | 4786 | if (isset($ligne_sql['chapo'])) { |
| 4787 | 4787 | $chapo = $ligne_sql['chapo']; |
| 4788 | 4788 | $texte = strlen($descriptif) ? |
| 4789 | - '' : |
|
| 4790 | - "$chapo \n\n $texte"; |
|
| 4789 | + '' : "$chapo \n\n $texte"; |
|
| 4791 | 4790 | } |
| 4792 | 4791 | |
| 4793 | 4792 | // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
@@ -4862,7 +4861,7 @@ discard block |
||
| 4862 | 4861 | return $texte; |
| 4863 | 4862 | } |
| 4864 | 4863 | |
| 4865 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4864 | + $traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement); |
|
| 4866 | 4865 | |
| 4867 | 4866 | // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
| 4868 | 4867 | if (test_espace_prive()) { |
@@ -4901,7 +4900,7 @@ discard block |
||
| 4901 | 4900 | } |
| 4902 | 4901 | $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
| 4903 | 4902 | |
| 4904 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4903 | + return "<a href='$url' class='$objet'>".couper($titre, $longueur).'</a>'; |
|
| 4905 | 4904 | } |
| 4906 | 4905 | |
| 4907 | 4906 | /** |
@@ -4927,10 +4926,10 @@ discard block |
||
| 4927 | 4926 | function wrap($texte, $wrap) { |
| 4928 | 4927 | $balises = extraire_balises($wrap); |
| 4929 | 4928 | if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
| 4930 | - $texte = $wrap . $texte; |
|
| 4929 | + $texte = $wrap.$texte; |
|
| 4931 | 4930 | $regs = array_reverse($regs[1]); |
| 4932 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4933 | - $texte = $texte . $wrap; |
|
| 4931 | + $wrap = '</'.implode('></', $regs).'>'; |
|
| 4932 | + $texte = $texte.$wrap; |
|
| 4934 | 4933 | } |
| 4935 | 4934 | |
| 4936 | 4935 | return $texte; |
@@ -4961,7 +4960,7 @@ discard block |
||
| 4961 | 4960 | |
| 4962 | 4961 | // caster $u en array si besoin |
| 4963 | 4962 | if (is_object($u)) { |
| 4964 | - $u = (array)$u; |
|
| 4963 | + $u = (array) $u; |
|
| 4965 | 4964 | } |
| 4966 | 4965 | |
| 4967 | 4966 | if (is_array($u)) { |
@@ -4983,7 +4982,7 @@ discard block |
||
| 4983 | 4982 | // sinon on passe a la ligne et on indente |
| 4984 | 4983 | $i_str = str_pad('', $indent, ' '); |
| 4985 | 4984 | foreach ($u as $k => $v) { |
| 4986 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4985 | + $out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2); |
|
| 4987 | 4986 | } |
| 4988 | 4987 | |
| 4989 | 4988 | return $out; |
@@ -5037,7 +5036,7 @@ discard block |
||
| 5037 | 5036 | * @return string |
| 5038 | 5037 | */ |
| 5039 | 5038 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5040 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5039 | + $icone = objet_info($objet, 'icone_objet').'-'.$taille.'.png'; |
|
| 5041 | 5040 | $icone = chemin_image($icone); |
| 5042 | 5041 | $balise_img = charger_filtre('balise_img'); |
| 5043 | 5042 | |
@@ -5063,7 +5062,7 @@ discard block |
||
| 5063 | 5062 | */ |
| 5064 | 5063 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5065 | 5064 | $chaine = explode(':', $chaine); |
| 5066 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5065 | + if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5067 | 5066 | return $t; |
| 5068 | 5067 | } |
| 5069 | 5068 | $chaine = implode(':', $chaine); |
@@ -5129,7 +5128,7 @@ discard block |
||
| 5129 | 5128 | $cache = recuperer_fond($fond, $contexte, $options, $connect); |
| 5130 | 5129 | |
| 5131 | 5130 | // calculer le nom de la css |
| 5132 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5131 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension); |
|
| 5133 | 5132 | $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
| 5134 | 5133 | $contexte_implicite = calculer_contexte_implicite(); |
| 5135 | 5134 | |
@@ -5137,14 +5136,14 @@ discard block |
||
| 5137 | 5136 | // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
| 5138 | 5137 | // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
| 5139 | 5138 | if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
| 5140 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5139 | + $hash = md5($contexte_implicite['host'].'::'.$cache); |
|
| 5141 | 5140 | } |
| 5142 | 5141 | else { |
| 5143 | 5142 | unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
| 5144 | 5143 | ksort($contexte); |
| 5145 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5144 | + $hash = md5($fond.json_encode($contexte_implicite, JSON_THROW_ON_ERROR).json_encode($contexte, JSON_THROW_ON_ERROR).$connect); |
|
| 5146 | 5145 | } |
| 5147 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5146 | + $filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension"; |
|
| 5148 | 5147 | |
| 5149 | 5148 | // mettre a jour le fichier si il n'existe pas |
| 5150 | 5149 | // ou trop ancien |
@@ -5152,8 +5151,8 @@ discard block |
||
| 5152 | 5151 | // et recopie sur le fichier cible uniquement si il change |
| 5153 | 5152 | if ( |
| 5154 | 5153 | !file_exists($filename) |
| 5155 | - or !file_exists($filename . '.last') |
|
| 5156 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5154 | + or !file_exists($filename.'.last') |
|
| 5155 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.'.last') < $cache['lastmodified']) |
|
| 5157 | 5156 | or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
| 5158 | 5157 | ) { |
| 5159 | 5158 | $contenu = $cache['texte']; |
@@ -5177,10 +5176,10 @@ discard block |
||
| 5177 | 5176 | } |
| 5178 | 5177 | // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
| 5179 | 5178 | // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
| 5180 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5179 | + $comment .= "}\n md5:".md5($contenu)." */\n"; |
|
| 5181 | 5180 | } |
| 5182 | 5181 | // et ecrire le fichier si il change |
| 5183 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5182 | + ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true); |
|
| 5184 | 5183 | } |
| 5185 | 5184 | |
| 5186 | 5185 | return timestamp($filename); |
@@ -5413,7 +5412,7 @@ discard block |
||
| 5413 | 5412 | if ($e > 0 and strlen($mid) > 8) { |
| 5414 | 5413 | $mid = '***...***'; |
| 5415 | 5414 | } |
| 5416 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5415 | + return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : ''); |
|
| 5417 | 5416 | } |
| 5418 | 5417 | |
| 5419 | 5418 | |
@@ -5475,7 +5474,7 @@ discard block |
||
| 5475 | 5474 | case 'id': |
| 5476 | 5475 | case 'anchor': |
| 5477 | 5476 | if (preg_match(',^\d,', $texte)) { |
| 5478 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5477 | + $texte = substr($type, 0, 1).$texte; |
|
| 5479 | 5478 | } |
| 5480 | 5479 | } |
| 5481 | 5480 | |
@@ -5485,9 +5484,9 @@ discard block |
||
| 5485 | 5484 | |
| 5486 | 5485 | if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
| 5487 | 5486 | if (preg_match(',^\d,', $texte)) { |
| 5488 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5487 | + $texte = ($type ? substr($type, 0, 1) : 's').$texte; |
|
| 5489 | 5488 | } |
| 5490 | - $texte .= $separateur . md5($original); |
|
| 5489 | + $texte .= $separateur.md5($original); |
|
| 5491 | 5490 | $texte = substr($texte, 0, $longueur_mini); |
| 5492 | 5491 | } |
| 5493 | 5492 | |
@@ -14,171 +14,171 @@ |
||
| 14 | 14 | |
| 15 | 15 | /** Gestion des clés d’authentification / chiffrement de SPIP */ |
| 16 | 16 | final class SpipCles { |
| 17 | - private static array $instances = []; |
|
| 18 | - |
|
| 19 | - private string $file = _DIR_ETC . 'cles.php'; |
|
| 20 | - private Cles $cles; |
|
| 21 | - |
|
| 22 | - public static function instance(string $file = ''): self { |
|
| 23 | - if (empty(self::$instances[$file])) { |
|
| 24 | - self::$instances[$file] = new self($file); |
|
| 25 | - } |
|
| 26 | - return self::$instances[$file]; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Retourne le secret du site (shorthand) |
|
| 31 | - * @uses self::getSecretSite() |
|
| 32 | - */ |
|
| 33 | - public static function secret_du_site(): ?string { |
|
| 34 | - return (self::instance())->getSecretSite(); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - private function __construct(string $file = '') { |
|
| 38 | - if ($file) { |
|
| 39 | - $this->file = $file; |
|
| 40 | - } |
|
| 41 | - $this->cles = new Cles($this->read()); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Renvoyer le secret du site |
|
| 46 | - * |
|
| 47 | - * Le secret du site doit rester aussi secret que possible, et est eternel |
|
| 48 | - * On ne doit pas l'exporter |
|
| 49 | - * |
|
| 50 | - * Le secret est partagé entre une clé disque et une clé bdd |
|
| 51 | - * |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function getSecretSite(bool $autoInit = true): ?string { |
|
| 55 | - $key = $this->getKey('secret_du_site', $autoInit); |
|
| 56 | - $meta = $this->getMetaKey('secret_du_site', $autoInit); |
|
| 57 | - // conserve la même longeur. |
|
| 58 | - return $key ^ $meta; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** Renvoyer le secret des authentifications */ |
|
| 62 | - public function getSecretAuth(bool $autoInit = false): ?string { |
|
| 63 | - return $this->getKey('secret_des_auth', $autoInit); |
|
| 64 | - } |
|
| 65 | - public function save(): bool { |
|
| 66 | - return ecrire_fichier_securise($this->file, $this->cles->toJson()); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Fournir une sauvegarde chiffree des cles (a l'aide d'une autre clé, comme le pass d'un auteur) |
|
| 71 | - * |
|
| 72 | - * @param string $withKey Clé de chiffrage de la sauvegarde |
|
| 73 | - * @return string Contenu de la sauvegarde chiffrée générée |
|
| 74 | - */ |
|
| 75 | - public function backup( |
|
| 76 | - #[\SensitiveParameter] |
|
| 77 | - string $withKey |
|
| 78 | - ): string { |
|
| 79 | - if (count($this->cles)) { |
|
| 80 | - return Chiffrement::chiffrer($this->cles->toJson(), $withKey); |
|
| 81 | - } |
|
| 82 | - return ''; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Restaurer les cles manquantes depuis une sauvegarde chiffree des cles |
|
| 87 | - * (si la sauvegarde est bien valide) |
|
| 88 | - * |
|
| 89 | - * @param string $backup Sauvegarde chiffrée (générée par backup()) |
|
| 90 | - * @param int $id_auteur |
|
| 91 | - * @param string $pass |
|
| 92 | - * @return void |
|
| 93 | - */ |
|
| 94 | - public function restore( |
|
| 95 | - string $backup, |
|
| 96 | - #[\SensitiveParameter] |
|
| 97 | - string $password_clair, |
|
| 98 | - #[\SensitiveParameter] |
|
| 99 | - string $password_hash, |
|
| 100 | - int $id_auteur |
|
| 101 | - ): bool { |
|
| 102 | - if (empty($backup)) { |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $sauvegarde = Chiffrement::dechiffrer($backup, $password_clair); |
|
| 107 | - $json = json_decode($sauvegarde, true); |
|
| 108 | - if (!$json) { |
|
| 109 | - return false; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - // cela semble une sauvegarde valide |
|
| 113 | - $cles_potentielles = array_map('base64_decode', $json); |
|
| 114 | - |
|
| 115 | - // il faut faire une double verif sur secret_des_auth |
|
| 116 | - // pour s'assurer qu'elle permet bien de decrypter le pass de l'auteur qui fournit la sauvegarde |
|
| 117 | - // et par extension tous les passwords |
|
| 118 | - if (!empty($cles_potentielles['secret_des_auth'])) { |
|
| 119 | - if (!Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth'])) { |
|
| 120 | - spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 121 | - unset($cles_potentielles['secret_des_auth']); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - // on merge les cles pour recuperer les cles manquantes |
|
| 126 | - $restauration = false; |
|
| 127 | - foreach ($cles_potentielles as $name => $key) { |
|
| 128 | - if (!$this->cles->has($name)) { |
|
| 129 | - $this->cles->set($name, $key); |
|
| 130 | - spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 131 | - $restauration = true; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - return $restauration; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - private function getKey(string $name, bool $autoInit): ?string { |
|
| 138 | - if ($this->cles->has($name)) { |
|
| 139 | - return $this->cles->get($name); |
|
| 140 | - } |
|
| 141 | - if ($autoInit) { |
|
| 142 | - $this->cles->generate($name); |
|
| 143 | - // si l'ecriture de fichier a bien marche on peut utiliser la cle |
|
| 144 | - if ($this->save()) { |
|
| 145 | - return $this->cles->get($name); |
|
| 146 | - } |
|
| 147 | - // sinon loger et annule la cle generee car il ne faut pas l'utiliser |
|
| 148 | - spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR); |
|
| 149 | - $this->cles->delete($name); |
|
| 150 | - } |
|
| 151 | - return null; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - private function getMetaKey(string $name, bool $autoInit = true): ?string { |
|
| 155 | - if (!isset($GLOBALS['meta'][$name])) { |
|
| 156 | - include_spip('base/abstract_sql'); |
|
| 157 | - $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string')); |
|
| 158 | - } |
|
| 159 | - $key = base64_decode($GLOBALS['meta'][$name] ?? ''); |
|
| 160 | - if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 161 | - return $key; |
|
| 162 | - } |
|
| 163 | - if (!$autoInit) { |
|
| 164 | - return null; |
|
| 165 | - } |
|
| 166 | - $key = Chiffrement::keygen(); |
|
| 167 | - ecrire_meta($name, base64_encode($key), 'non'); |
|
| 168 | - lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
|
| 169 | - |
|
| 170 | - return $key; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - private function read(): array { |
|
| 174 | - lire_fichier_securise($this->file, $json); |
|
| 175 | - if ( |
|
| 176 | - $json |
|
| 177 | - and $json = \json_decode($json, true) |
|
| 178 | - and is_array($json) |
|
| 179 | - ) { |
|
| 180 | - return array_map('base64_decode', $json); |
|
| 181 | - } |
|
| 182 | - return []; |
|
| 183 | - } |
|
| 17 | + private static array $instances = []; |
|
| 18 | + |
|
| 19 | + private string $file = _DIR_ETC . 'cles.php'; |
|
| 20 | + private Cles $cles; |
|
| 21 | + |
|
| 22 | + public static function instance(string $file = ''): self { |
|
| 23 | + if (empty(self::$instances[$file])) { |
|
| 24 | + self::$instances[$file] = new self($file); |
|
| 25 | + } |
|
| 26 | + return self::$instances[$file]; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Retourne le secret du site (shorthand) |
|
| 31 | + * @uses self::getSecretSite() |
|
| 32 | + */ |
|
| 33 | + public static function secret_du_site(): ?string { |
|
| 34 | + return (self::instance())->getSecretSite(); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + private function __construct(string $file = '') { |
|
| 38 | + if ($file) { |
|
| 39 | + $this->file = $file; |
|
| 40 | + } |
|
| 41 | + $this->cles = new Cles($this->read()); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Renvoyer le secret du site |
|
| 46 | + * |
|
| 47 | + * Le secret du site doit rester aussi secret que possible, et est eternel |
|
| 48 | + * On ne doit pas l'exporter |
|
| 49 | + * |
|
| 50 | + * Le secret est partagé entre une clé disque et une clé bdd |
|
| 51 | + * |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function getSecretSite(bool $autoInit = true): ?string { |
|
| 55 | + $key = $this->getKey('secret_du_site', $autoInit); |
|
| 56 | + $meta = $this->getMetaKey('secret_du_site', $autoInit); |
|
| 57 | + // conserve la même longeur. |
|
| 58 | + return $key ^ $meta; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** Renvoyer le secret des authentifications */ |
|
| 62 | + public function getSecretAuth(bool $autoInit = false): ?string { |
|
| 63 | + return $this->getKey('secret_des_auth', $autoInit); |
|
| 64 | + } |
|
| 65 | + public function save(): bool { |
|
| 66 | + return ecrire_fichier_securise($this->file, $this->cles->toJson()); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Fournir une sauvegarde chiffree des cles (a l'aide d'une autre clé, comme le pass d'un auteur) |
|
| 71 | + * |
|
| 72 | + * @param string $withKey Clé de chiffrage de la sauvegarde |
|
| 73 | + * @return string Contenu de la sauvegarde chiffrée générée |
|
| 74 | + */ |
|
| 75 | + public function backup( |
|
| 76 | + #[\SensitiveParameter] |
|
| 77 | + string $withKey |
|
| 78 | + ): string { |
|
| 79 | + if (count($this->cles)) { |
|
| 80 | + return Chiffrement::chiffrer($this->cles->toJson(), $withKey); |
|
| 81 | + } |
|
| 82 | + return ''; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Restaurer les cles manquantes depuis une sauvegarde chiffree des cles |
|
| 87 | + * (si la sauvegarde est bien valide) |
|
| 88 | + * |
|
| 89 | + * @param string $backup Sauvegarde chiffrée (générée par backup()) |
|
| 90 | + * @param int $id_auteur |
|
| 91 | + * @param string $pass |
|
| 92 | + * @return void |
|
| 93 | + */ |
|
| 94 | + public function restore( |
|
| 95 | + string $backup, |
|
| 96 | + #[\SensitiveParameter] |
|
| 97 | + string $password_clair, |
|
| 98 | + #[\SensitiveParameter] |
|
| 99 | + string $password_hash, |
|
| 100 | + int $id_auteur |
|
| 101 | + ): bool { |
|
| 102 | + if (empty($backup)) { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $sauvegarde = Chiffrement::dechiffrer($backup, $password_clair); |
|
| 107 | + $json = json_decode($sauvegarde, true); |
|
| 108 | + if (!$json) { |
|
| 109 | + return false; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + // cela semble une sauvegarde valide |
|
| 113 | + $cles_potentielles = array_map('base64_decode', $json); |
|
| 114 | + |
|
| 115 | + // il faut faire une double verif sur secret_des_auth |
|
| 116 | + // pour s'assurer qu'elle permet bien de decrypter le pass de l'auteur qui fournit la sauvegarde |
|
| 117 | + // et par extension tous les passwords |
|
| 118 | + if (!empty($cles_potentielles['secret_des_auth'])) { |
|
| 119 | + if (!Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth'])) { |
|
| 120 | + spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 121 | + unset($cles_potentielles['secret_des_auth']); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + // on merge les cles pour recuperer les cles manquantes |
|
| 126 | + $restauration = false; |
|
| 127 | + foreach ($cles_potentielles as $name => $key) { |
|
| 128 | + if (!$this->cles->has($name)) { |
|
| 129 | + $this->cles->set($name, $key); |
|
| 130 | + spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 131 | + $restauration = true; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + return $restauration; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + private function getKey(string $name, bool $autoInit): ?string { |
|
| 138 | + if ($this->cles->has($name)) { |
|
| 139 | + return $this->cles->get($name); |
|
| 140 | + } |
|
| 141 | + if ($autoInit) { |
|
| 142 | + $this->cles->generate($name); |
|
| 143 | + // si l'ecriture de fichier a bien marche on peut utiliser la cle |
|
| 144 | + if ($this->save()) { |
|
| 145 | + return $this->cles->get($name); |
|
| 146 | + } |
|
| 147 | + // sinon loger et annule la cle generee car il ne faut pas l'utiliser |
|
| 148 | + spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR); |
|
| 149 | + $this->cles->delete($name); |
|
| 150 | + } |
|
| 151 | + return null; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + private function getMetaKey(string $name, bool $autoInit = true): ?string { |
|
| 155 | + if (!isset($GLOBALS['meta'][$name])) { |
|
| 156 | + include_spip('base/abstract_sql'); |
|
| 157 | + $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string')); |
|
| 158 | + } |
|
| 159 | + $key = base64_decode($GLOBALS['meta'][$name] ?? ''); |
|
| 160 | + if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 161 | + return $key; |
|
| 162 | + } |
|
| 163 | + if (!$autoInit) { |
|
| 164 | + return null; |
|
| 165 | + } |
|
| 166 | + $key = Chiffrement::keygen(); |
|
| 167 | + ecrire_meta($name, base64_encode($key), 'non'); |
|
| 168 | + lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
|
| 169 | + |
|
| 170 | + return $key; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + private function read(): array { |
|
| 174 | + lire_fichier_securise($this->file, $json); |
|
| 175 | + if ( |
|
| 176 | + $json |
|
| 177 | + and $json = \json_decode($json, true) |
|
| 178 | + and is_array($json) |
|
| 179 | + ) { |
|
| 180 | + return array_map('base64_decode', $json); |
|
| 181 | + } |
|
| 182 | + return []; |
|
| 183 | + } |
|
| 184 | 184 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | final class SpipCles { |
| 17 | 17 | private static array $instances = []; |
| 18 | 18 | |
| 19 | - private string $file = _DIR_ETC . 'cles.php'; |
|
| 19 | + private string $file = _DIR_ETC.'cles.php'; |
|
| 20 | 20 | private Cles $cles; |
| 21 | 21 | |
| 22 | 22 | public static function instance(string $file = ''): self { |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | // et par extension tous les passwords |
| 118 | 118 | if (!empty($cles_potentielles['secret_des_auth'])) { |
| 119 | 119 | if (!Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth'])) { |
| 120 | - spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 120 | + spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer'._LOG_INFO_IMPORTANTE); |
|
| 121 | 121 | unset($cles_potentielles['secret_des_auth']); |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | foreach ($cles_potentielles as $name => $key) { |
| 128 | 128 | if (!$this->cles->has($name)) { |
| 129 | 129 | $this->cles->set($name, $key); |
| 130 | - spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 130 | + spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer'._LOG_INFO_IMPORTANTE); |
|
| 131 | 131 | $restauration = true; |
| 132 | 132 | } |
| 133 | 133 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | return $this->cles->get($name); |
| 146 | 146 | } |
| 147 | 147 | // sinon loger et annule la cle generee car il ne faut pas l'utiliser |
| 148 | - spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR); |
|
| 148 | + spip_log('Echec ecriture du fichier cle '.$this->file." ; impossible de generer une cle $name", 'chiffrer'._LOG_ERREUR); |
|
| 149 | 149 | $this->cles->delete($name); |
| 150 | 150 | } |
| 151 | 151 | return null; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | private function getMetaKey(string $name, bool $autoInit = true): ?string { |
| 155 | 155 | if (!isset($GLOBALS['meta'][$name])) { |
| 156 | 156 | include_spip('base/abstract_sql'); |
| 157 | - $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string')); |
|
| 157 | + $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = '.sql_quote($name, '', 'string')); |
|
| 158 | 158 | } |
| 159 | 159 | $key = base64_decode($GLOBALS['meta'][$name] ?? ''); |
| 160 | 160 | if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
@@ -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 | /** |
@@ -39,28 +39,28 @@ discard block |
||
| 39 | 39 | * Tableau des champs et valeurs collectées |
| 40 | 40 | */ |
| 41 | 41 | function collecter_requests($include_list, $exclude_list = [], $set = null, $tous = false) { |
| 42 | - $c = $set; |
|
| 43 | - if (!$c) { |
|
| 44 | - $c = []; |
|
| 45 | - foreach ($include_list as $champ) { |
|
| 46 | - // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | - // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | - $val = _request($champ); |
|
| 49 | - if ($tous or $val !== null) { |
|
| 50 | - $c[$champ] = $val; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - // on ajoute toujours la lang en saisie possible |
|
| 54 | - // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | - if ($l = _request('changer_lang')) { |
|
| 56 | - $c['lang'] = $l; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - foreach ($exclude_list as $champ) { |
|
| 60 | - unset($c[$champ]); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - return $c; |
|
| 42 | + $c = $set; |
|
| 43 | + if (!$c) { |
|
| 44 | + $c = []; |
|
| 45 | + foreach ($include_list as $champ) { |
|
| 46 | + // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | + // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | + $val = _request($champ); |
|
| 49 | + if ($tous or $val !== null) { |
|
| 50 | + $c[$champ] = $val; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + // on ajoute toujours la lang en saisie possible |
|
| 54 | + // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | + if ($l = _request('changer_lang')) { |
|
| 56 | + $c['lang'] = $l; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + foreach ($exclude_list as $champ) { |
|
| 60 | + unset($c[$champ]); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + return $c; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -97,242 +97,242 @@ discard block |
||
| 97 | 97 | * - chaîne : Texte d'un message d'erreur |
| 98 | 98 | */ |
| 99 | 99 | function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') { |
| 100 | - if (!$id_objet = intval($id_objet)) { |
|
| 101 | - spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | - |
|
| 103 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/filtres'); |
|
| 107 | - |
|
| 108 | - $table_objet = table_objet($objet, $serveur); |
|
| 109 | - $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | - $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | - |
|
| 114 | - // Appels incomplets (sans $c) |
|
| 115 | - if (!is_array($c)) { |
|
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | - |
|
| 118 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | - // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | - // il faut passer par instituer_XX() |
|
| 124 | - // TODO: faut-il passer ces variables interdites |
|
| 125 | - // dans un fichier de description separe ? |
|
| 126 | - unset($c['statut']); |
|
| 127 | - unset($c['id_parent']); |
|
| 128 | - unset($c['id_rubrique']); |
|
| 129 | - unset($c['id_secteur']); |
|
| 130 | - |
|
| 131 | - // Gerer les champs non vides |
|
| 132 | - if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | - if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | - $c[$champ] = $sinon; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // N'accepter que les champs qui existent dans la table |
|
| 141 | - $champs = array_intersect_key($c, $desc['field']); |
|
| 142 | - // et dont la valeur n'est pas null |
|
| 143 | - $champs = array_filter($champs, static function ($var) { |
|
| 144 | - return $var !== null; |
|
| 145 | - }); |
|
| 146 | - // TODO: ici aussi on peut valider les contenus |
|
| 147 | - // en fonction du type |
|
| 148 | - |
|
| 149 | - // Nettoyer les valeurs |
|
| 150 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 151 | - |
|
| 152 | - // On récupère l'état avant toute modification |
|
| 153 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 154 | - |
|
| 155 | - // Envoyer aux plugins |
|
| 156 | - $champs = pipeline( |
|
| 157 | - 'pre_edition', |
|
| 158 | - [ |
|
| 159 | - 'args' => [ |
|
| 160 | - 'table' => $spip_table_objet, // compatibilite |
|
| 161 | - 'table_objet' => $table_objet, |
|
| 162 | - 'spip_table_objet' => $spip_table_objet, |
|
| 163 | - 'desc' => $desc, |
|
| 164 | - 'type' => $objet, |
|
| 165 | - 'id_objet' => $id_objet, |
|
| 166 | - 'data' => $options['data'] ?? null, |
|
| 167 | - 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 168 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 169 | - 'serveur' => $serveur, |
|
| 170 | - 'action' => $options['action'] ?? 'modifier' |
|
| 171 | - ], |
|
| 172 | - 'data' => $champs |
|
| 173 | - ] |
|
| 174 | - ); |
|
| 175 | - |
|
| 176 | - if (!$champs) { |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - // marquer le fait que l'objet est travaille par toto a telle date |
|
| 182 | - include_spip('inc/config'); |
|
| 183 | - if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 184 | - include_spip('inc/drapeau_edition'); |
|
| 185 | - signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 189 | - include_spip('inc/editer'); |
|
| 190 | - if (!isset($options['data']) or is_null($options['data'])) { |
|
| 191 | - $options['data'] = &$_POST; |
|
| 192 | - } |
|
| 193 | - $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 194 | - // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 195 | - // et gere l'interface |
|
| 196 | - // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 197 | - if ($conflits) { |
|
| 198 | - return _T('titre_conflit_edition'); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - if ($champs) { |
|
| 202 | - // cas particulier de la langue : passer par instituer_langue_objet |
|
| 203 | - if (isset($champs['lang'])) { |
|
| 204 | - if ($changer_lang = $champs['lang']) { |
|
| 205 | - $id_rubrique = 0; |
|
| 206 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 207 | - $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 208 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 209 | - } |
|
| 210 | - $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 211 | - $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 212 | - } |
|
| 213 | - // on laisse 'lang' dans $champs, |
|
| 214 | - // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 215 | - // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 216 | - // deja pris en compte |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // la modif peut avoir lieu |
|
| 220 | - |
|
| 221 | - // faut-il ajouter date_modif ? |
|
| 222 | - if ( |
|
| 223 | - !empty($options['date_modif']) |
|
| 224 | - and !isset($champs[$options['date_modif']]) |
|
| 225 | - ) { |
|
| 226 | - $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // allez on commit la modif |
|
| 230 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 231 | - |
|
| 232 | - // on verifie si elle est bien passee |
|
| 233 | - $moof = sql_fetsel( |
|
| 234 | - array_keys($champs), |
|
| 235 | - $spip_table_objet, |
|
| 236 | - "$id_table_objet=" . intval($id_objet), |
|
| 237 | - [], |
|
| 238 | - [], |
|
| 239 | - '', |
|
| 240 | - [], |
|
| 241 | - $serveur |
|
| 242 | - ); |
|
| 243 | - // si difference entre les champs, reperer les champs mal enregistres |
|
| 244 | - if ($moof != $champs) { |
|
| 245 | - $liste = []; |
|
| 246 | - foreach ($moof as $k => $v) { |
|
| 247 | - if ( |
|
| 248 | - $v !== $champs[$k] |
|
| 249 | - // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 250 | - and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 251 | - // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 252 | - and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 253 | - ) { |
|
| 254 | - $liste[] = $k; |
|
| 255 | - $conflits[$k]['post'] = $champs[$k]; |
|
| 256 | - $conflits[$k]['save'] = $v; |
|
| 257 | - |
|
| 258 | - // cas specifique MySQL+emoji : si l'un est la |
|
| 259 | - // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 260 | - if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 261 | - include_spip('inc/charsets'); |
|
| 262 | - if ($v == utf8_noplanes($champs[$k])) { |
|
| 263 | - array_pop($liste); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 269 | - // c'est un cas exceptionnel |
|
| 270 | - if (count($liste)) { |
|
| 271 | - spip_log( |
|
| 272 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 273 | - 'modifier.' . _LOG_CRITIQUE |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - return _T( |
|
| 277 | - 'erreur_technique_enregistrement_champs', |
|
| 278 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 279 | - ); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // Invalider les caches |
|
| 284 | - if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 285 | - include_spip('inc/invalideur'); |
|
| 286 | - if (is_array($options['invalideur'])) { |
|
| 287 | - array_map('suivre_invalideur', $options['invalideur']); |
|
| 288 | - } else { |
|
| 289 | - suivre_invalideur($options['invalideur']); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // Notifications, gestion des revisions... |
|
| 294 | - // en standard, appelle |nouvelle_revision ci-dessous |
|
| 295 | - pipeline( |
|
| 296 | - 'post_edition', |
|
| 297 | - [ |
|
| 298 | - 'args' => [ |
|
| 299 | - 'table' => $spip_table_objet, |
|
| 300 | - 'table_objet' => $table_objet, |
|
| 301 | - 'spip_table_objet' => $spip_table_objet, |
|
| 302 | - 'desc' => $desc, |
|
| 303 | - 'type' => $objet, |
|
| 304 | - 'id_objet' => $id_objet, |
|
| 305 | - 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 306 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 307 | - 'serveur' => $serveur, |
|
| 308 | - 'action' => $options['action'] ?? 'modifier' |
|
| 309 | - ], |
|
| 310 | - 'data' => $champs |
|
| 311 | - ] |
|
| 312 | - ); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - // journaliser l'affaire |
|
| 316 | - // message a affiner :-) |
|
| 317 | - include_spip('inc/filtres_mini'); |
|
| 318 | - $qui = ''; |
|
| 319 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 320 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 321 | - } |
|
| 322 | - if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 323 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 324 | - } |
|
| 325 | - if ($qui == '') { |
|
| 326 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 327 | - } |
|
| 328 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 329 | - '+', |
|
| 330 | - array_diff(array_keys($champs), ['date_modif']) |
|
| 331 | - ) . ')'), [ |
|
| 332 | - 'faire' => 'modifier', |
|
| 333 | - 'quoi' => $objet, |
|
| 334 | - 'id' => $id_objet |
|
| 335 | - ]); |
|
| 336 | - |
|
| 337 | - return ''; |
|
| 100 | + if (!$id_objet = intval($id_objet)) { |
|
| 101 | + spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | + |
|
| 103 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/filtres'); |
|
| 107 | + |
|
| 108 | + $table_objet = table_objet($objet, $serveur); |
|
| 109 | + $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | + $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | + |
|
| 114 | + // Appels incomplets (sans $c) |
|
| 115 | + if (!is_array($c)) { |
|
| 116 | + spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | + |
|
| 118 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | + // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | + // il faut passer par instituer_XX() |
|
| 124 | + // TODO: faut-il passer ces variables interdites |
|
| 125 | + // dans un fichier de description separe ? |
|
| 126 | + unset($c['statut']); |
|
| 127 | + unset($c['id_parent']); |
|
| 128 | + unset($c['id_rubrique']); |
|
| 129 | + unset($c['id_secteur']); |
|
| 130 | + |
|
| 131 | + // Gerer les champs non vides |
|
| 132 | + if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | + if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | + $c[$champ] = $sinon; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // N'accepter que les champs qui existent dans la table |
|
| 141 | + $champs = array_intersect_key($c, $desc['field']); |
|
| 142 | + // et dont la valeur n'est pas null |
|
| 143 | + $champs = array_filter($champs, static function ($var) { |
|
| 144 | + return $var !== null; |
|
| 145 | + }); |
|
| 146 | + // TODO: ici aussi on peut valider les contenus |
|
| 147 | + // en fonction du type |
|
| 148 | + |
|
| 149 | + // Nettoyer les valeurs |
|
| 150 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 151 | + |
|
| 152 | + // On récupère l'état avant toute modification |
|
| 153 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 154 | + |
|
| 155 | + // Envoyer aux plugins |
|
| 156 | + $champs = pipeline( |
|
| 157 | + 'pre_edition', |
|
| 158 | + [ |
|
| 159 | + 'args' => [ |
|
| 160 | + 'table' => $spip_table_objet, // compatibilite |
|
| 161 | + 'table_objet' => $table_objet, |
|
| 162 | + 'spip_table_objet' => $spip_table_objet, |
|
| 163 | + 'desc' => $desc, |
|
| 164 | + 'type' => $objet, |
|
| 165 | + 'id_objet' => $id_objet, |
|
| 166 | + 'data' => $options['data'] ?? null, |
|
| 167 | + 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 168 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 169 | + 'serveur' => $serveur, |
|
| 170 | + 'action' => $options['action'] ?? 'modifier' |
|
| 171 | + ], |
|
| 172 | + 'data' => $champs |
|
| 173 | + ] |
|
| 174 | + ); |
|
| 175 | + |
|
| 176 | + if (!$champs) { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + // marquer le fait que l'objet est travaille par toto a telle date |
|
| 182 | + include_spip('inc/config'); |
|
| 183 | + if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 184 | + include_spip('inc/drapeau_edition'); |
|
| 185 | + signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 189 | + include_spip('inc/editer'); |
|
| 190 | + if (!isset($options['data']) or is_null($options['data'])) { |
|
| 191 | + $options['data'] = &$_POST; |
|
| 192 | + } |
|
| 193 | + $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 194 | + // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 195 | + // et gere l'interface |
|
| 196 | + // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 197 | + if ($conflits) { |
|
| 198 | + return _T('titre_conflit_edition'); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + if ($champs) { |
|
| 202 | + // cas particulier de la langue : passer par instituer_langue_objet |
|
| 203 | + if (isset($champs['lang'])) { |
|
| 204 | + if ($changer_lang = $champs['lang']) { |
|
| 205 | + $id_rubrique = 0; |
|
| 206 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 207 | + $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 208 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 209 | + } |
|
| 210 | + $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 211 | + $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 212 | + } |
|
| 213 | + // on laisse 'lang' dans $champs, |
|
| 214 | + // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 215 | + // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 216 | + // deja pris en compte |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // la modif peut avoir lieu |
|
| 220 | + |
|
| 221 | + // faut-il ajouter date_modif ? |
|
| 222 | + if ( |
|
| 223 | + !empty($options['date_modif']) |
|
| 224 | + and !isset($champs[$options['date_modif']]) |
|
| 225 | + ) { |
|
| 226 | + $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // allez on commit la modif |
|
| 230 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 231 | + |
|
| 232 | + // on verifie si elle est bien passee |
|
| 233 | + $moof = sql_fetsel( |
|
| 234 | + array_keys($champs), |
|
| 235 | + $spip_table_objet, |
|
| 236 | + "$id_table_objet=" . intval($id_objet), |
|
| 237 | + [], |
|
| 238 | + [], |
|
| 239 | + '', |
|
| 240 | + [], |
|
| 241 | + $serveur |
|
| 242 | + ); |
|
| 243 | + // si difference entre les champs, reperer les champs mal enregistres |
|
| 244 | + if ($moof != $champs) { |
|
| 245 | + $liste = []; |
|
| 246 | + foreach ($moof as $k => $v) { |
|
| 247 | + if ( |
|
| 248 | + $v !== $champs[$k] |
|
| 249 | + // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 250 | + and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 251 | + // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 252 | + and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 253 | + ) { |
|
| 254 | + $liste[] = $k; |
|
| 255 | + $conflits[$k]['post'] = $champs[$k]; |
|
| 256 | + $conflits[$k]['save'] = $v; |
|
| 257 | + |
|
| 258 | + // cas specifique MySQL+emoji : si l'un est la |
|
| 259 | + // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 260 | + if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 261 | + include_spip('inc/charsets'); |
|
| 262 | + if ($v == utf8_noplanes($champs[$k])) { |
|
| 263 | + array_pop($liste); |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 269 | + // c'est un cas exceptionnel |
|
| 270 | + if (count($liste)) { |
|
| 271 | + spip_log( |
|
| 272 | + "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 273 | + 'modifier.' . _LOG_CRITIQUE |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + return _T( |
|
| 277 | + 'erreur_technique_enregistrement_champs', |
|
| 278 | + ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // Invalider les caches |
|
| 284 | + if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 285 | + include_spip('inc/invalideur'); |
|
| 286 | + if (is_array($options['invalideur'])) { |
|
| 287 | + array_map('suivre_invalideur', $options['invalideur']); |
|
| 288 | + } else { |
|
| 289 | + suivre_invalideur($options['invalideur']); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // Notifications, gestion des revisions... |
|
| 294 | + // en standard, appelle |nouvelle_revision ci-dessous |
|
| 295 | + pipeline( |
|
| 296 | + 'post_edition', |
|
| 297 | + [ |
|
| 298 | + 'args' => [ |
|
| 299 | + 'table' => $spip_table_objet, |
|
| 300 | + 'table_objet' => $table_objet, |
|
| 301 | + 'spip_table_objet' => $spip_table_objet, |
|
| 302 | + 'desc' => $desc, |
|
| 303 | + 'type' => $objet, |
|
| 304 | + 'id_objet' => $id_objet, |
|
| 305 | + 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 306 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 307 | + 'serveur' => $serveur, |
|
| 308 | + 'action' => $options['action'] ?? 'modifier' |
|
| 309 | + ], |
|
| 310 | + 'data' => $champs |
|
| 311 | + ] |
|
| 312 | + ); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + // journaliser l'affaire |
|
| 316 | + // message a affiner :-) |
|
| 317 | + include_spip('inc/filtres_mini'); |
|
| 318 | + $qui = ''; |
|
| 319 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 320 | + $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 321 | + } |
|
| 322 | + if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 323 | + $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 324 | + } |
|
| 325 | + if ($qui == '') { |
|
| 326 | + $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 327 | + } |
|
| 328 | + journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 329 | + '+', |
|
| 330 | + array_diff(array_keys($champs), ['date_modif']) |
|
| 331 | + ) . ')'), [ |
|
| 332 | + 'faire' => 'modifier', |
|
| 333 | + 'quoi' => $objet, |
|
| 334 | + 'id' => $id_objet |
|
| 335 | + ]); |
|
| 336 | + |
|
| 337 | + return ''; |
|
| 338 | 338 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | // Appels incomplets (sans $c) |
| 115 | 115 | if (!is_array($c)) { |
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 116 | + spip_log('erreur appel objet_modifier_champs('.$objet.'), manque $c'); |
|
| 117 | 117 | |
| 118 | 118 | return _T('erreur_technique_enregistrement_impossible'); |
| 119 | 119 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | // N'accepter que les champs qui existent dans la table |
| 141 | 141 | $champs = array_intersect_key($c, $desc['field']); |
| 142 | 142 | // et dont la valeur n'est pas null |
| 143 | - $champs = array_filter($champs, static function ($var) { |
|
| 143 | + $champs = array_filter($champs, static function($var) { |
|
| 144 | 144 | return $var !== null; |
| 145 | 145 | }); |
| 146 | 146 | // TODO: ici aussi on peut valider les contenus |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $champs = array_map('corriger_caracteres', $champs); |
| 151 | 151 | |
| 152 | 152 | // On récupère l'état avant toute modification |
| 153 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 153 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet.'='.$id_objet); |
|
| 154 | 154 | |
| 155 | 155 | // Envoyer aux plugins |
| 156 | 156 | $champs = pipeline( |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $id_rubrique = 0; |
| 206 | 206 | if (isset($desc['field']['id_rubrique'])) { |
| 207 | 207 | $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
| 208 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 208 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=".intval($id_objet)); |
|
| 209 | 209 | } |
| 210 | 210 | $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
| 211 | 211 | $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
@@ -227,13 +227,13 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | // allez on commit la modif |
| 230 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 230 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=".intval($id_objet), [], $serveur); |
|
| 231 | 231 | |
| 232 | 232 | // on verifie si elle est bien passee |
| 233 | 233 | $moof = sql_fetsel( |
| 234 | 234 | array_keys($champs), |
| 235 | 235 | $spip_table_objet, |
| 236 | - "$id_table_objet=" . intval($id_objet), |
|
| 236 | + "$id_table_objet=".intval($id_objet), |
|
| 237 | 237 | [], |
| 238 | 238 | [], |
| 239 | 239 | '', |
@@ -269,13 +269,13 @@ discard block |
||
| 269 | 269 | // c'est un cas exceptionnel |
| 270 | 270 | if (count($liste)) { |
| 271 | 271 | spip_log( |
| 272 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 273 | - 'modifier.' . _LOG_CRITIQUE |
|
| 272 | + "Erreur enregistrement en base $objet/$id_objet champs :".var_export($conflits, true), |
|
| 273 | + 'modifier.'._LOG_CRITIQUE |
|
| 274 | 274 | ); |
| 275 | 275 | |
| 276 | 276 | return _T( |
| 277 | 277 | 'erreur_technique_enregistrement_champs', |
| 278 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 278 | + ['champs' => "<i>'".implode("'</i>,<i>'", $liste)."'</i>"] |
|
| 279 | 279 | ); |
| 280 | 280 | } |
| 281 | 281 | } |
@@ -317,18 +317,18 @@ discard block |
||
| 317 | 317 | include_spip('inc/filtres_mini'); |
| 318 | 318 | $qui = ''; |
| 319 | 319 | if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
| 320 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 320 | + $qui .= ' #id_auteur:'.$GLOBALS['visiteur_session']['id_auteur'].'#'; |
|
| 321 | 321 | } |
| 322 | 322 | if (!empty($GLOBALS['visiteur_session']['nom'])) { |
| 323 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 323 | + $qui .= ' #nom:'.$GLOBALS['visiteur_session']['nom'].'#'; |
|
| 324 | 324 | } |
| 325 | 325 | if ($qui == '') { |
| 326 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 326 | + $qui = '#ip:'.$GLOBALS['ip'].'#'; |
|
| 327 | 327 | } |
| 328 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 328 | + journal(_L($qui.' a édité '.$objet.' '.$id_objet.' ('.join( |
|
| 329 | 329 | '+', |
| 330 | 330 | array_diff(array_keys($champs), ['date_modif']) |
| 331 | - ) . ')'), [ |
|
| 331 | + ).')'), [ |
|
| 332 | 332 | 'faire' => 'modifier', |
| 333 | 333 | 'quoi' => $objet, |
| 334 | 334 | 'id' => $id_objet |