@@ -11,73 +11,73 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | # Les information d'une rubrique selectionnee dans le mini navigateur |
| 18 | 18 | |
| 19 | 19 | function inc_informer_dist($id, $col, $exclus, $rac, $type, $do = 'aff') { |
| 20 | - include_spip('inc/texte'); |
|
| 21 | - $titre = $descriptif = ''; |
|
| 22 | - if ($type == 'rubrique') { |
|
| 23 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 24 | - if ($row) { |
|
| 25 | - $titre = typo($row['titre']); |
|
| 26 | - $descriptif = propre($row['descriptif']); |
|
| 27 | - } else { |
|
| 28 | - $titre = _T('info_racine_site'); |
|
| 29 | - } |
|
| 30 | - } |
|
| 20 | + include_spip('inc/texte'); |
|
| 21 | + $titre = $descriptif = ''; |
|
| 22 | + if ($type == 'rubrique') { |
|
| 23 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 24 | + if ($row) { |
|
| 25 | + $titre = typo($row['titre']); |
|
| 26 | + $descriptif = propre($row['descriptif']); |
|
| 27 | + } else { |
|
| 28 | + $titre = _T('info_racine_site'); |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $res = ''; |
|
| 33 | - if ($type == 'rubrique' and $GLOBALS['spip_display'] != 1 and isset($GLOBALS['meta']['image_process'])) { |
|
| 34 | - if ($GLOBALS['meta']['image_process'] != 'non') { |
|
| 35 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 36 | - if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 37 | - [$fid, $dir, $nom, $format] = $res; |
|
| 38 | - include_spip('inc/filtres_images_mini'); |
|
| 39 | - $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 40 | - if ($res) { |
|
| 41 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - } |
|
| 32 | + $res = ''; |
|
| 33 | + if ($type == 'rubrique' and $GLOBALS['spip_display'] != 1 and isset($GLOBALS['meta']['image_process'])) { |
|
| 34 | + if ($GLOBALS['meta']['image_process'] != 'non') { |
|
| 35 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 36 | + if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 37 | + [$fid, $dir, $nom, $format] = $res; |
|
| 38 | + include_spip('inc/filtres_images_mini'); |
|
| 39 | + $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 40 | + if ($res) { |
|
| 41 | + $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 48 | - $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 49 | - $id = intval($id); |
|
| 47 | + $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 48 | + $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 49 | + $id = intval($id); |
|
| 50 | 50 | |
| 51 | 51 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 52 | 52 | # et l'affichage de son titre dans le bandeau |
| 53 | - $titre = strtr( |
|
| 54 | - str_replace( |
|
| 55 | - "'", |
|
| 56 | - '’', |
|
| 57 | - str_replace('"', '"', textebrut($titre)) |
|
| 58 | - ), |
|
| 59 | - "\n\r", |
|
| 60 | - ' ' |
|
| 61 | - ); |
|
| 53 | + $titre = strtr( |
|
| 54 | + str_replace( |
|
| 55 | + "'", |
|
| 56 | + '’', |
|
| 57 | + str_replace('"', '"', textebrut($titre)) |
|
| 58 | + ), |
|
| 59 | + "\n\r", |
|
| 60 | + ' ' |
|
| 61 | + ); |
|
| 62 | 62 | |
| 63 | - $js_func = $do . '_selection_titre'; |
|
| 63 | + $js_func = $do . '_selection_titre'; |
|
| 64 | 64 | |
| 65 | - return "<div style='display: none;'>" |
|
| 66 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 67 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 68 | - . entites_html($titre) |
|
| 69 | - . '" />' |
|
| 70 | - . '</div>' |
|
| 71 | - . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 72 | - . '<div class="informer__item">' |
|
| 73 | - . (!$res ? '' : $res) |
|
| 74 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 75 | - . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 76 | - . '</div>' |
|
| 77 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 78 | - . "<input type='submit' class='fondo btn submit' value='" |
|
| 79 | - . _T('bouton_choisir') |
|
| 80 | - . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 81 | - . '</div>' |
|
| 82 | - . '</div>'; |
|
| 65 | + return "<div style='display: none;'>" |
|
| 66 | + . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 67 | + . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 68 | + . entites_html($titre) |
|
| 69 | + . '" />' |
|
| 70 | + . '</div>' |
|
| 71 | + . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 72 | + . '<div class="informer__item">' |
|
| 73 | + . (!$res ? '' : $res) |
|
| 74 | + . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 75 | + . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 76 | + . '</div>' |
|
| 77 | + . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 78 | + . "<input type='submit' class='fondo btn submit' value='" |
|
| 79 | + . _T('bouton_choisir') |
|
| 80 | + . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 81 | + . '</div>' |
|
| 82 | + . '</div>'; |
|
| 83 | 83 | } |
@@ -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 | |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | * @return void |
| 44 | 44 | **/ |
| 45 | 45 | function install_fichier_connexion($nom, $texte) { |
| 46 | - $texte = '<' . "?php\n" |
|
| 47 | - . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 48 | - . $texte |
|
| 49 | - . '?' . '>'; |
|
| 46 | + $texte = '<' . "?php\n" |
|
| 47 | + . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 48 | + . $texte |
|
| 49 | + . '?' . '>'; |
|
| 50 | 50 | |
| 51 | - ecrire_fichier($nom, $texte); |
|
| 51 | + ecrire_fichier($nom, $texte); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -77,20 +77,20 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | **/ |
| 79 | 79 | function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap = '', $charset = '') { |
| 80 | - $adr = addcslashes($adr, "'\\"); |
|
| 81 | - $port = addcslashes($port, "'\\"); |
|
| 82 | - $login = addcslashes($login, "'\\"); |
|
| 83 | - $pass = addcslashes($pass, "'\\"); |
|
| 84 | - $base = addcslashes($base, "'\\"); |
|
| 85 | - $type = addcslashes($type, "'\\"); |
|
| 86 | - $pref = addcslashes($pref, "'\\"); |
|
| 87 | - $ldap = addcslashes($ldap, "'\\"); |
|
| 88 | - $charset = addcslashes($charset, "'\\"); |
|
| 89 | - |
|
| 90 | - return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 91 | - . 'spip_connect_db(' |
|
| 92 | - . "'$adr','$port','$login','$pass','$base'" |
|
| 93 | - . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 80 | + $adr = addcslashes($adr, "'\\"); |
|
| 81 | + $port = addcslashes($port, "'\\"); |
|
| 82 | + $login = addcslashes($login, "'\\"); |
|
| 83 | + $pass = addcslashes($pass, "'\\"); |
|
| 84 | + $base = addcslashes($base, "'\\"); |
|
| 85 | + $type = addcslashes($type, "'\\"); |
|
| 86 | + $pref = addcslashes($pref, "'\\"); |
|
| 87 | + $ldap = addcslashes($ldap, "'\\"); |
|
| 88 | + $charset = addcslashes($charset, "'\\"); |
|
| 89 | + |
|
| 90 | + return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 91 | + . 'spip_connect_db(' |
|
| 92 | + . "'$adr','$port','$login','$pass','$base'" |
|
| 93 | + . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
@@ -106,26 +106,26 @@ discard block |
||
| 106 | 106 | * Tableau des informations sur la connexion |
| 107 | 107 | **/ |
| 108 | 108 | function analyse_fichier_connection($file) { |
| 109 | - $s = @join('', file($file)); |
|
| 110 | - if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 111 | - array_shift($regs); |
|
| 112 | - |
|
| 113 | - return $regs; |
|
| 114 | - } else { |
|
| 115 | - $ar = '\s*\'([^\']*)\''; |
|
| 116 | - $r = '\s*,' . $ar; |
|
| 117 | - $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 118 | - if (preg_match($r, $s, $regs)) { |
|
| 119 | - $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';'); |
|
| 120 | - array_shift($regs); |
|
| 121 | - array_shift($regs); |
|
| 122 | - |
|
| 123 | - return $regs; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - spip_log("$file n'est pas un fichier de connexion"); |
|
| 127 | - |
|
| 128 | - return []; |
|
| 109 | + $s = @join('', file($file)); |
|
| 110 | + if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 111 | + array_shift($regs); |
|
| 112 | + |
|
| 113 | + return $regs; |
|
| 114 | + } else { |
|
| 115 | + $ar = '\s*\'([^\']*)\''; |
|
| 116 | + $r = '\s*,' . $ar; |
|
| 117 | + $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 118 | + if (preg_match($r, $s, $regs)) { |
|
| 119 | + $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';'); |
|
| 120 | + array_shift($regs); |
|
| 121 | + array_shift($regs); |
|
| 122 | + |
|
| 123 | + return $regs; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + spip_log("$file n'est pas un fichier de connexion"); |
|
| 127 | + |
|
| 128 | + return []; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -142,73 +142,73 @@ discard block |
||
| 142 | 142 | * Liste des noms de connecteurs |
| 143 | 143 | **/ |
| 144 | 144 | function bases_referencees($exclu = '') { |
| 145 | - $tables = []; |
|
| 146 | - foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 147 | - if ($f != $exclu and analyse_fichier_connection($f)) { |
|
| 148 | - $tables[] = basename($f, '.php'); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $tables; |
|
| 145 | + $tables = []; |
|
| 146 | + foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 147 | + if ($f != $exclu and analyse_fichier_connection($f)) { |
|
| 148 | + $tables[] = basename($f, '.php'); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $tables; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
| 156 | 156 | function install_mode_appel($server_db, $tout = true) { |
| 157 | - return ($server_db != 'mysql') ? '' |
|
| 158 | - : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 159 | - . test_sql_mode_mysql($server_db)); |
|
| 157 | + return ($server_db != 'mysql') ? '' |
|
| 158 | + : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 159 | + . test_sql_mode_mysql($server_db)); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // |
| 163 | 163 | // Verifier que l'hebergement est compatible SPIP ... ou l'inverse :-) |
| 164 | 164 | // (sert a l'etape 1 de l'installation) |
| 165 | 165 | function tester_compatibilite_hebergement() { |
| 166 | - $err = []; |
|
| 167 | - |
|
| 168 | - $p = phpversion(); |
|
| 169 | - if (version_compare($p, _PHP_MIN, '<')) { |
|
| 170 | - $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 174 | - if ($err) { |
|
| 175 | - die("<div class='error'>" |
|
| 176 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 177 | - . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // Il faut une base de donnees tout de meme ... |
|
| 181 | - $serveurs = install_select_serveur(); |
|
| 182 | - if (!$serveurs) { |
|
| 183 | - $err[] = _T('install_extension_php_obligatoire') |
|
| 184 | - . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 185 | - . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>" |
|
| 186 | - . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // et il faut preg |
|
| 190 | - if (!function_exists('preg_match_all')) { |
|
| 191 | - $err[] = _T('install_extension_php_obligatoire') |
|
| 192 | - . " <a href='http://se.php.net/pcre'>PCRE</a>"; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - // et surtout pas ce mbstring.overload |
|
| 196 | - if ($a = @ini_get('mbstring.func_overload')) { |
|
| 197 | - $err[] = _T('install_extension_mbstring') |
|
| 198 | - . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - if ($err) { |
|
| 202 | - echo "<div class='error'>" |
|
| 203 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 204 | - foreach ($err as $e) { |
|
| 205 | - echo "<li><strong>$e</strong></li>\n"; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 209 | - # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 210 | - echo "</ul></div>\n"; |
|
| 211 | - } |
|
| 166 | + $err = []; |
|
| 167 | + |
|
| 168 | + $p = phpversion(); |
|
| 169 | + if (version_compare($p, _PHP_MIN, '<')) { |
|
| 170 | + $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 174 | + if ($err) { |
|
| 175 | + die("<div class='error'>" |
|
| 176 | + . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 177 | + . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // Il faut une base de donnees tout de meme ... |
|
| 181 | + $serveurs = install_select_serveur(); |
|
| 182 | + if (!$serveurs) { |
|
| 183 | + $err[] = _T('install_extension_php_obligatoire') |
|
| 184 | + . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 185 | + . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>" |
|
| 186 | + . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // et il faut preg |
|
| 190 | + if (!function_exists('preg_match_all')) { |
|
| 191 | + $err[] = _T('install_extension_php_obligatoire') |
|
| 192 | + . " <a href='http://se.php.net/pcre'>PCRE</a>"; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + // et surtout pas ce mbstring.overload |
|
| 196 | + if ($a = @ini_get('mbstring.func_overload')) { |
|
| 197 | + $err[] = _T('install_extension_mbstring') |
|
| 198 | + . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + if ($err) { |
|
| 202 | + echo "<div class='error'>" |
|
| 203 | + . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 204 | + foreach ($err as $e) { |
|
| 205 | + echo "<li><strong>$e</strong></li>\n"; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 209 | + # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 210 | + echo "</ul></div>\n"; |
|
| 211 | + } |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | |
@@ -218,23 +218,23 @@ discard block |
||
| 218 | 218 | * @note superflu ?? |
| 219 | 219 | */ |
| 220 | 220 | function login_hebergeur() { |
| 221 | - $base_hebergeur = 'localhost'; # par defaut |
|
| 221 | + $base_hebergeur = 'localhost'; # par defaut |
|
| 222 | 222 | |
| 223 | - // Free |
|
| 224 | - if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) { |
|
| 225 | - $base_hebergeur = 'sql.free.fr'; |
|
| 226 | - $login_hebergeur = $regs[1]; |
|
| 227 | - } else { |
|
| 228 | - $login_hebergeur = ''; |
|
| 229 | - } |
|
| 223 | + // Free |
|
| 224 | + if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) { |
|
| 225 | + $base_hebergeur = 'sql.free.fr'; |
|
| 226 | + $login_hebergeur = $regs[1]; |
|
| 227 | + } else { |
|
| 228 | + $login_hebergeur = ''; |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - return [$base_hebergeur, $login_hebergeur]; |
|
| 231 | + return [$base_hebergeur, $login_hebergeur]; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | |
| 235 | 235 | function info_etape($titre, $complement = '') { |
| 236 | - return '<h2>' . $titre . "</h2>\n" . |
|
| 237 | - ($complement ? '' . $complement . "\n" : ''); |
|
| 236 | + return '<h2>' . $titre . "</h2>\n" . |
|
| 237 | + ($complement ? '' . $complement . "\n" : ''); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -244,154 +244,154 @@ discard block |
||
| 244 | 244 | * @return string Code HTML du bouton |
| 245 | 245 | **/ |
| 246 | 246 | function bouton_suivant($code = '') { |
| 247 | - if ($code == '') { |
|
| 248 | - $code = _T('bouton_suivant'); |
|
| 249 | - } |
|
| 250 | - static $suivant = 0; |
|
| 251 | - $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 252 | - $suivant += 1; |
|
| 253 | - |
|
| 254 | - return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 255 | - $code . |
|
| 256 | - " >>\" /></p>\n"; |
|
| 247 | + if ($code == '') { |
|
| 248 | + $code = _T('bouton_suivant'); |
|
| 249 | + } |
|
| 250 | + static $suivant = 0; |
|
| 251 | + $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 252 | + $suivant += 1; |
|
| 253 | + |
|
| 254 | + return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 255 | + $code . |
|
| 256 | + " >>\" /></p>\n"; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | function info_progression_etape($en_cours, $phase, $dir, $erreur = false) { |
| 260 | - $intitule_etat = []; |
|
| 261 | - //$en_cours = _request('etape')?_request('etape'):""; |
|
| 262 | - $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 263 | - $debut = 1; |
|
| 264 | - $etat = 'ok'; |
|
| 265 | - $last = count($liste); |
|
| 260 | + $intitule_etat = []; |
|
| 261 | + //$en_cours = _request('etape')?_request('etape'):""; |
|
| 262 | + $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 263 | + $debut = 1; |
|
| 264 | + $etat = 'ok'; |
|
| 265 | + $last = count($liste); |
|
| 266 | 266 | // $texte_etat = array('ok'=>'OK','encours'=>_T('en_cours'),'todo'=>_T('todo')); |
| 267 | 267 | |
| 268 | - $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee')); |
|
| 269 | - $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 270 | - $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles')); |
|
| 271 | - $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape')); |
|
| 268 | + $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee')); |
|
| 269 | + $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 270 | + $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles')); |
|
| 271 | + $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape')); |
|
| 272 | 272 | |
| 273 | - $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap')); |
|
| 274 | - $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap')); |
|
| 275 | - $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1')); |
|
| 276 | - $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap')); |
|
| 277 | - $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok')); |
|
| 273 | + $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap')); |
|
| 274 | + $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap')); |
|
| 275 | + $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1')); |
|
| 276 | + $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap')); |
|
| 277 | + $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok')); |
|
| 278 | 278 | |
| 279 | 279 | // $aff_etapes = "<span id='etapes'>"; |
| 280 | 280 | |
| 281 | - $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 282 | - |
|
| 283 | - foreach ($liste as $etape => $fichier) { |
|
| 284 | - if ($debut < $last) { |
|
| 285 | - if ($debut == $en_cours && $erreur) { |
|
| 286 | - $class = 'on erreur'; |
|
| 287 | - } else { |
|
| 288 | - if ($debut == $en_cours) { |
|
| 289 | - $class = 'on'; |
|
| 290 | - } else { |
|
| 291 | - if ($debut > $en_cours) { |
|
| 292 | - $class = 'prochains'; |
|
| 293 | - } else { |
|
| 294 | - $class = 'valides'; |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 300 | - $aff_etapes .= ($debut == $en_cours) ? '<strong>' : ''; |
|
| 301 | - $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 302 | - $aff_etapes .= $intitule_etat["$phase"][$debut]; |
|
| 303 | - $aff_etapes .= ($debut == $en_cours) ? '</strong>' : ''; |
|
| 304 | - $aff_etapes .= '</div></li>'; |
|
| 305 | - } |
|
| 306 | - $debut++; |
|
| 307 | - } |
|
| 308 | - $aff_etapes .= '</ul>'; |
|
| 309 | - $aff_etapes .= "<br class='nettoyeur' />\n"; |
|
| 310 | - |
|
| 311 | - return $aff_etapes; |
|
| 281 | + $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 282 | + |
|
| 283 | + foreach ($liste as $etape => $fichier) { |
|
| 284 | + if ($debut < $last) { |
|
| 285 | + if ($debut == $en_cours && $erreur) { |
|
| 286 | + $class = 'on erreur'; |
|
| 287 | + } else { |
|
| 288 | + if ($debut == $en_cours) { |
|
| 289 | + $class = 'on'; |
|
| 290 | + } else { |
|
| 291 | + if ($debut > $en_cours) { |
|
| 292 | + $class = 'prochains'; |
|
| 293 | + } else { |
|
| 294 | + $class = 'valides'; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 300 | + $aff_etapes .= ($debut == $en_cours) ? '<strong>' : ''; |
|
| 301 | + $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 302 | + $aff_etapes .= $intitule_etat["$phase"][$debut]; |
|
| 303 | + $aff_etapes .= ($debut == $en_cours) ? '</strong>' : ''; |
|
| 304 | + $aff_etapes .= '</div></li>'; |
|
| 305 | + } |
|
| 306 | + $debut++; |
|
| 307 | + } |
|
| 308 | + $aff_etapes .= '</ul>'; |
|
| 309 | + $aff_etapes .= "<br class='nettoyeur' />\n"; |
|
| 310 | + |
|
| 311 | + return $aff_etapes; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | |
| 315 | 315 | function fieldset($legend, $champs = [], $apres = '', $avant = '') { |
| 316 | - return "<fieldset>\n" . |
|
| 317 | - $avant . |
|
| 318 | - ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 319 | - fieldset_champs($champs) . |
|
| 320 | - $apres . |
|
| 321 | - "</fieldset>\n"; |
|
| 316 | + return "<fieldset>\n" . |
|
| 317 | + $avant . |
|
| 318 | + ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 319 | + fieldset_champs($champs) . |
|
| 320 | + $apres . |
|
| 321 | + "</fieldset>\n"; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | function fieldset_champs($champs = []) { |
| 325 | - $fieldset = ''; |
|
| 326 | - foreach ($champs as $nom => $contenu) { |
|
| 327 | - $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
|
| 328 | - $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 329 | - if (isset($contenu['alternatives'])) { |
|
| 330 | - $fieldset .= $contenu['label'] . "\n"; |
|
| 331 | - foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 332 | - $fieldset .= "<input type='radio' name='" . $nom . |
|
| 333 | - "' id='$nom-$valeur' value='$valeur'" |
|
| 334 | - . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 335 | - . "/>\n"; |
|
| 336 | - $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 337 | - } |
|
| 338 | - $fieldset .= "<br />\n"; |
|
| 339 | - } else { |
|
| 340 | - $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 341 | - $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 342 | - . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
|
| 343 | - . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '') |
|
| 344 | - . " />\n"; |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - return $fieldset; |
|
| 325 | + $fieldset = ''; |
|
| 326 | + foreach ($champs as $nom => $contenu) { |
|
| 327 | + $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
|
| 328 | + $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 329 | + if (isset($contenu['alternatives'])) { |
|
| 330 | + $fieldset .= $contenu['label'] . "\n"; |
|
| 331 | + foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 332 | + $fieldset .= "<input type='radio' name='" . $nom . |
|
| 333 | + "' id='$nom-$valeur' value='$valeur'" |
|
| 334 | + . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 335 | + . "/>\n"; |
|
| 336 | + $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 337 | + } |
|
| 338 | + $fieldset .= "<br />\n"; |
|
| 339 | + } else { |
|
| 340 | + $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 341 | + $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 342 | + . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
|
| 343 | + . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '') |
|
| 344 | + . " />\n"; |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + return $fieldset; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | function install_select_serveur() { |
| 352 | - $options = []; |
|
| 353 | - $dir = _DIR_RESTREINT . 'req/'; |
|
| 354 | - $d = opendir($dir); |
|
| 355 | - if (!$d) { |
|
| 356 | - return []; |
|
| 357 | - } |
|
| 358 | - while (($f = readdir($d)) !== false) { |
|
| 359 | - if ( |
|
| 360 | - (preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 361 | - and is_readable($f = $dir . $f) |
|
| 362 | - ) { |
|
| 363 | - require_once($f); |
|
| 364 | - $s = $s[1]; |
|
| 365 | - $v = 'spip_versions_' . $s; |
|
| 366 | - if (function_exists($v) and $v()) { |
|
| 367 | - $titre = _T("install_select_type_$s"); |
|
| 368 | - // proposer mysql par defaut si dispo |
|
| 369 | - $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
|
| 370 | - $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 371 | - . "<label for='$s'>" . ($titre ?: $s) . '</label></li>'; |
|
| 372 | - } else { |
|
| 373 | - spip_log("$s: portage indisponible"); |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - sort($options); |
|
| 378 | - |
|
| 379 | - return $options; |
|
| 352 | + $options = []; |
|
| 353 | + $dir = _DIR_RESTREINT . 'req/'; |
|
| 354 | + $d = opendir($dir); |
|
| 355 | + if (!$d) { |
|
| 356 | + return []; |
|
| 357 | + } |
|
| 358 | + while (($f = readdir($d)) !== false) { |
|
| 359 | + if ( |
|
| 360 | + (preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 361 | + and is_readable($f = $dir . $f) |
|
| 362 | + ) { |
|
| 363 | + require_once($f); |
|
| 364 | + $s = $s[1]; |
|
| 365 | + $v = 'spip_versions_' . $s; |
|
| 366 | + if (function_exists($v) and $v()) { |
|
| 367 | + $titre = _T("install_select_type_$s"); |
|
| 368 | + // proposer mysql par defaut si dispo |
|
| 369 | + $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
|
| 370 | + $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 371 | + . "<label for='$s'>" . ($titre ?: $s) . '</label></li>'; |
|
| 372 | + } else { |
|
| 373 | + spip_log("$s: portage indisponible"); |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + sort($options); |
|
| 378 | + |
|
| 379 | + return $options; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery = true) { |
| 383 | - $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 384 | - |
|
| 385 | - return generer_form_ecrire('install', ( |
|
| 386 | - "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 387 | - . $hidden |
|
| 388 | - . (_request('echec') ? |
|
| 389 | - ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 390 | - '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 391 | - : '') |
|
| 392 | - |
|
| 393 | - . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 394 | - . http_script(' |
|
| 383 | + $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 384 | + |
|
| 385 | + return generer_form_ecrire('install', ( |
|
| 386 | + "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 387 | + . $hidden |
|
| 388 | + . (_request('echec') ? |
|
| 389 | + ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 390 | + '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 391 | + : '') |
|
| 392 | + |
|
| 393 | + . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 394 | + . http_script(' |
|
| 395 | 395 | jQuery(function($) { |
| 396 | 396 | $details_db = $("#install_adresse_base_hebergeur,#install_login_base_hebergeur,#install_pass_base_hebergeur"); |
| 397 | 397 | $("input[type=hidden][name=server_db]").each(function(){ |
@@ -424,145 +424,145 @@ discard block |
||
| 424 | 424 | }); |
| 425 | 425 | });') |
| 426 | 426 | |
| 427 | - . ($server_db |
|
| 428 | - ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 429 | - . (($predef[0]) |
|
| 430 | - ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 431 | - : '') |
|
| 432 | - : ('<fieldset><legend>' |
|
| 433 | - . _T('install_select_type_db') |
|
| 434 | - . '</legend>' |
|
| 435 | - . '<p class="explication">' |
|
| 436 | - . _T('install_types_db_connus') |
|
| 437 | - // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 438 | - // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 439 | - . '</p>' |
|
| 440 | - . "\n<div class='p'>\n<ul>\n" |
|
| 441 | - . join("\n", install_select_serveur()) |
|
| 442 | - . "\n</ul>\n</div></fieldset>") |
|
| 443 | - ) |
|
| 444 | - . '<div id="install_adresse_base_hebergeur">' |
|
| 445 | - . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 446 | - . ($predef[1] |
|
| 447 | - ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 448 | - : fieldset( |
|
| 449 | - _T('entree_base_donnee_1'), |
|
| 450 | - [ |
|
| 451 | - 'adresse_db' => [ |
|
| 452 | - 'label' => $db[1], |
|
| 453 | - 'valeur' => $db[0] |
|
| 454 | - ], |
|
| 455 | - ] |
|
| 456 | - ) |
|
| 457 | - ) |
|
| 458 | - . '</div>' |
|
| 459 | - |
|
| 460 | - . '<div id="install_login_base_hebergeur">' |
|
| 461 | - . ($predef[2] |
|
| 462 | - ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 463 | - : fieldset( |
|
| 464 | - _T('entree_login_connexion_1'), |
|
| 465 | - [ |
|
| 466 | - 'login_db' => [ |
|
| 467 | - 'label' => $login[1], |
|
| 468 | - 'valeur' => $login[0] |
|
| 469 | - ], |
|
| 470 | - ] |
|
| 471 | - ) |
|
| 472 | - ) |
|
| 473 | - . '</div>' |
|
| 474 | - |
|
| 475 | - . '<div id="install_pass_base_hebergeur">' |
|
| 476 | - . ($predef[3] |
|
| 477 | - ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 478 | - : fieldset( |
|
| 479 | - _T('entree_mot_passe_1'), |
|
| 480 | - [ |
|
| 481 | - 'pass_db' => [ |
|
| 482 | - 'label' => $pass[1], |
|
| 483 | - 'valeur' => $pass[0] |
|
| 484 | - ], |
|
| 485 | - ] |
|
| 486 | - ) |
|
| 487 | - ) |
|
| 488 | - . '</div>' |
|
| 489 | - |
|
| 490 | - . bouton_suivant())); |
|
| 427 | + . ($server_db |
|
| 428 | + ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 429 | + . (($predef[0]) |
|
| 430 | + ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 431 | + : '') |
|
| 432 | + : ('<fieldset><legend>' |
|
| 433 | + . _T('install_select_type_db') |
|
| 434 | + . '</legend>' |
|
| 435 | + . '<p class="explication">' |
|
| 436 | + . _T('install_types_db_connus') |
|
| 437 | + // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 438 | + // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 439 | + . '</p>' |
|
| 440 | + . "\n<div class='p'>\n<ul>\n" |
|
| 441 | + . join("\n", install_select_serveur()) |
|
| 442 | + . "\n</ul>\n</div></fieldset>") |
|
| 443 | + ) |
|
| 444 | + . '<div id="install_adresse_base_hebergeur">' |
|
| 445 | + . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 446 | + . ($predef[1] |
|
| 447 | + ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 448 | + : fieldset( |
|
| 449 | + _T('entree_base_donnee_1'), |
|
| 450 | + [ |
|
| 451 | + 'adresse_db' => [ |
|
| 452 | + 'label' => $db[1], |
|
| 453 | + 'valeur' => $db[0] |
|
| 454 | + ], |
|
| 455 | + ] |
|
| 456 | + ) |
|
| 457 | + ) |
|
| 458 | + . '</div>' |
|
| 459 | + |
|
| 460 | + . '<div id="install_login_base_hebergeur">' |
|
| 461 | + . ($predef[2] |
|
| 462 | + ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 463 | + : fieldset( |
|
| 464 | + _T('entree_login_connexion_1'), |
|
| 465 | + [ |
|
| 466 | + 'login_db' => [ |
|
| 467 | + 'label' => $login[1], |
|
| 468 | + 'valeur' => $login[0] |
|
| 469 | + ], |
|
| 470 | + ] |
|
| 471 | + ) |
|
| 472 | + ) |
|
| 473 | + . '</div>' |
|
| 474 | + |
|
| 475 | + . '<div id="install_pass_base_hebergeur">' |
|
| 476 | + . ($predef[3] |
|
| 477 | + ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 478 | + : fieldset( |
|
| 479 | + _T('entree_mot_passe_1'), |
|
| 480 | + [ |
|
| 481 | + 'pass_db' => [ |
|
| 482 | + 'label' => $pass[1], |
|
| 483 | + 'valeur' => $pass[0] |
|
| 484 | + ], |
|
| 485 | + ] |
|
| 486 | + ) |
|
| 487 | + ) |
|
| 488 | + . '</div>' |
|
| 489 | + |
|
| 490 | + . bouton_suivant())); |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | // 4 valeurs qu'on reconduit d'un script a l'autre |
| 494 | 494 | // sauf s'ils sont predefinis. |
| 495 | 495 | |
| 496 | 496 | function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) { |
| 497 | - return ((defined('_INSTALL_HOST_DB')) |
|
| 498 | - ? '' |
|
| 499 | - : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 500 | - ) |
|
| 501 | - . ((defined('_INSTALL_USER_DB')) |
|
| 502 | - ? '' |
|
| 503 | - : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 504 | - ) |
|
| 505 | - . ((defined('_INSTALL_PASS_DB')) |
|
| 506 | - ? '' |
|
| 507 | - : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 508 | - ) |
|
| 509 | - |
|
| 510 | - . ((defined('_INSTALL_SERVER_DB')) |
|
| 511 | - ? '' |
|
| 512 | - : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 513 | - ); |
|
| 497 | + return ((defined('_INSTALL_HOST_DB')) |
|
| 498 | + ? '' |
|
| 499 | + : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 500 | + ) |
|
| 501 | + . ((defined('_INSTALL_USER_DB')) |
|
| 502 | + ? '' |
|
| 503 | + : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 504 | + ) |
|
| 505 | + . ((defined('_INSTALL_PASS_DB')) |
|
| 506 | + ? '' |
|
| 507 | + : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 508 | + ) |
|
| 509 | + |
|
| 510 | + . ((defined('_INSTALL_SERVER_DB')) |
|
| 511 | + ? '' |
|
| 512 | + : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 513 | + ); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | // presentation des bases existantes |
| 517 | 517 | |
| 518 | 518 | function install_etape_liste_bases($server_db, $login_db, $disabled = []) { |
| 519 | - $bases = $checked = []; |
|
| 520 | - $noms = sql_listdbs($server_db); |
|
| 521 | - if (!$noms) { |
|
| 522 | - return ''; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - foreach ($noms as $nom) { |
|
| 526 | - $id = spip_htmlspecialchars($nom); |
|
| 527 | - $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 528 | - $base = ' name="choix_db" value="' |
|
| 529 | - . $nom |
|
| 530 | - . '"' |
|
| 531 | - . $dis |
|
| 532 | - . " type='radio' id='$id'"; |
|
| 533 | - $label = "<label for='$id'>" |
|
| 534 | - . ($dis ? "<i>$nom</i>" : $nom) |
|
| 535 | - . '</label>'; |
|
| 536 | - |
|
| 537 | - if ( |
|
| 538 | - !$checked and !$dis and |
|
| 539 | - (($nom == $login_db) or |
|
| 540 | - ($GLOBALS['table_prefix'] == $nom)) |
|
| 541 | - ) { |
|
| 542 | - $checked = "<input$base checked='checked' />\n$label"; |
|
| 543 | - } else { |
|
| 544 | - $bases[] = "<input$base />\n$label"; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - if (!$bases && !$checked) { |
|
| 549 | - return false; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - if ($checked) { |
|
| 553 | - array_unshift($bases, $checked); |
|
| 554 | - $checked = true; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - return [$checked, $bases]; |
|
| 519 | + $bases = $checked = []; |
|
| 520 | + $noms = sql_listdbs($server_db); |
|
| 521 | + if (!$noms) { |
|
| 522 | + return ''; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + foreach ($noms as $nom) { |
|
| 526 | + $id = spip_htmlspecialchars($nom); |
|
| 527 | + $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 528 | + $base = ' name="choix_db" value="' |
|
| 529 | + . $nom |
|
| 530 | + . '"' |
|
| 531 | + . $dis |
|
| 532 | + . " type='radio' id='$id'"; |
|
| 533 | + $label = "<label for='$id'>" |
|
| 534 | + . ($dis ? "<i>$nom</i>" : $nom) |
|
| 535 | + . '</label>'; |
|
| 536 | + |
|
| 537 | + if ( |
|
| 538 | + !$checked and !$dis and |
|
| 539 | + (($nom == $login_db) or |
|
| 540 | + ($GLOBALS['table_prefix'] == $nom)) |
|
| 541 | + ) { |
|
| 542 | + $checked = "<input$base checked='checked' />\n$label"; |
|
| 543 | + } else { |
|
| 544 | + $bases[] = "<input$base />\n$label"; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + if (!$bases && !$checked) { |
|
| 549 | + return false; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + if ($checked) { |
|
| 553 | + array_unshift($bases, $checked); |
|
| 554 | + $checked = true; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + return [$checked, $bases]; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | function install_propager($hidden) { |
| 561 | - $res = ''; |
|
| 562 | - foreach ($hidden as $k) { |
|
| 563 | - $v = spip_htmlentities(_request($k)); |
|
| 564 | - $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 565 | - } |
|
| 561 | + $res = ''; |
|
| 562 | + foreach ($hidden as $k) { |
|
| 563 | + $v = spip_htmlentities(_request($k)); |
|
| 564 | + $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 565 | + } |
|
| 566 | 566 | |
| 567 | - return $res; |
|
| 567 | + return $res; |
|
| 568 | 568 | } |
@@ -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('base/abstract_sql'); |
@@ -23,16 +23,16 @@ discard block |
||
| 23 | 23 | // |
| 24 | 24 | |
| 25 | 25 | function inc_lien_dist( |
| 26 | - $lien, |
|
| 27 | - $texte = '', |
|
| 28 | - $class = '', |
|
| 29 | - $title = '', |
|
| 30 | - $hlang = '', |
|
| 31 | - $rel = '', |
|
| 32 | - string $connect = '', |
|
| 33 | - $env = [] |
|
| 26 | + $lien, |
|
| 27 | + $texte = '', |
|
| 28 | + $class = '', |
|
| 29 | + $title = '', |
|
| 30 | + $hlang = '', |
|
| 31 | + $rel = '', |
|
| 32 | + string $connect = '', |
|
| 33 | + $env = [] |
|
| 34 | 34 | ) { |
| 35 | - return $lien; |
|
| 35 | + return $lien; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip |
@@ -43,28 +43,28 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | function expanser_liens($t, string $connect = '', $env = []) { |
| 45 | 45 | |
| 46 | - $t = pipeline('pre_liens', $t); |
|
| 46 | + $t = pipeline('pre_liens', $t); |
|
| 47 | 47 | |
| 48 | - // on passe a traiter_modeles la liste des liens reperes pour lui permettre |
|
| 49 | - // de remettre le texte d'origine dans les parametres du modele |
|
| 50 | - $t = traiter_modeles($t, false, false, $connect); |
|
| 48 | + // on passe a traiter_modeles la liste des liens reperes pour lui permettre |
|
| 49 | + // de remettre le texte d'origine dans les parametres du modele |
|
| 50 | + $t = traiter_modeles($t, false, false, $connect); |
|
| 51 | 51 | |
| 52 | - return $t; |
|
| 52 | + return $t; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // Meme analyse mais pour eliminer les liens |
| 56 | 56 | // et ne laisser que leur titre, a expliciter si ce n'est fait |
| 57 | 57 | function nettoyer_raccourcis_typo($texte, string $connect = '') { |
| 58 | - return $texte; |
|
| 58 | + return $texte; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // Repere dans la partie texte d'un raccourci [texte->...] |
| 62 | 62 | // la langue et la bulle eventuelles |
| 63 | 63 | function traiter_raccourci_lien_atts($texte) { |
| 64 | - $bulle = ''; |
|
| 65 | - $hlang = ''; |
|
| 64 | + $bulle = ''; |
|
| 65 | + $hlang = ''; |
|
| 66 | 66 | |
| 67 | - return [trim($texte), $bulle, $hlang]; |
|
| 67 | + return [trim($texte), $bulle, $hlang]; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | define('_RACCOURCI_CHAPO', '/^(\W*)(\W*)(\w*\d+([?#].*)?)$/'); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @return string |
| 81 | 81 | */ |
| 82 | 82 | function virtuel_redirige($virtuel, $url = false) { |
| 83 | - return $virtuel; |
|
| 83 | + return $virtuel; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // Cherche un lien du type [->raccourci 123] |
@@ -93,121 +93,121 @@ discard block |
||
| 93 | 93 | // 'url': seulement U (i.e. generer_url_RACCOURCI) |
| 94 | 94 | |
| 95 | 95 | function calculer_url($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
| 96 | - $r = traiter_lien_implicite($ref, $texte, $pour, $connect); |
|
| 96 | + $r = traiter_lien_implicite($ref, $texte, $pour, $connect); |
|
| 97 | 97 | |
| 98 | - return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 98 | + return $r ?: traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS'); |
| 102 | 102 | |
| 103 | 103 | function traiter_lien_explicite($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
| 104 | - if (preg_match(_EXTRAIRE_LIEN, $ref)) { |
|
| 105 | - return ($pour != 'tout') ? '' : ['', '', '', '']; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $lien = entites_html(trim($ref)); |
|
| 109 | - |
|
| 110 | - // Liens explicites |
|
| 111 | - if (!$texte) { |
|
| 112 | - $texte = str_replace('"', '', $lien); |
|
| 113 | - // evite l'affichage de trops longues urls. |
|
| 114 | - $lien_court = charger_fonction('lien_court', 'inc'); |
|
| 115 | - $texte = $lien_court($texte); |
|
| 116 | - if ($echappe_typo) { |
|
| 117 | - $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // petites corrections d'URL |
|
| 122 | - if (preg_match('/^www\.[^@]+$/S', $lien)) { |
|
| 123 | - $lien = 'http://' . $lien; |
|
| 124 | - } else { |
|
| 125 | - if (strpos($lien, '@') && email_valide($lien)) { |
|
| 126 | - if (!$texte) { |
|
| 127 | - $texte = $lien; |
|
| 128 | - } |
|
| 129 | - $lien = 'mailto:' . $lien; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - if ($pour == 'url') { |
|
| 134 | - return $lien; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - if ($pour == 'titre') { |
|
| 138 | - return $texte; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return ['url' => $lien, 'titre' => $texte]; |
|
| 104 | + if (preg_match(_EXTRAIRE_LIEN, $ref)) { |
|
| 105 | + return ($pour != 'tout') ? '' : ['', '', '', '']; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $lien = entites_html(trim($ref)); |
|
| 109 | + |
|
| 110 | + // Liens explicites |
|
| 111 | + if (!$texte) { |
|
| 112 | + $texte = str_replace('"', '', $lien); |
|
| 113 | + // evite l'affichage de trops longues urls. |
|
| 114 | + $lien_court = charger_fonction('lien_court', 'inc'); |
|
| 115 | + $texte = $lien_court($texte); |
|
| 116 | + if ($echappe_typo) { |
|
| 117 | + $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // petites corrections d'URL |
|
| 122 | + if (preg_match('/^www\.[^@]+$/S', $lien)) { |
|
| 123 | + $lien = 'http://' . $lien; |
|
| 124 | + } else { |
|
| 125 | + if (strpos($lien, '@') && email_valide($lien)) { |
|
| 126 | + if (!$texte) { |
|
| 127 | + $texte = $lien; |
|
| 128 | + } |
|
| 129 | + $lien = 'mailto:' . $lien; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + if ($pour == 'url') { |
|
| 134 | + return $lien; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + if ($pour == 'titre') { |
|
| 138 | + return $texte; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return ['url' => $lien, 'titre' => $texte]; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, string $connect = '') { |
| 145 | - if (function_exists($f = 'glossaire_' . $ancre)) { |
|
| 146 | - $url = $f($texte, $id); |
|
| 147 | - } else { |
|
| 148 | - $url = glossaire_std($texte); |
|
| 149 | - } |
|
| 145 | + if (function_exists($f = 'glossaire_' . $ancre)) { |
|
| 146 | + $url = $f($texte, $id); |
|
| 147 | + } else { |
|
| 148 | + $url = glossaire_std($texte); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - return $url; |
|
| 151 | + return $url; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | function traiter_lien_implicite($ref, $texte = '', $pour = 'url', string $connect = '') { |
| 155 | - $url = null; |
|
| 156 | - if (!($match = typer_raccourci($ref))) { |
|
| 157 | - return false; |
|
| 158 | - } |
|
| 159 | - [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null); |
|
| 160 | - // attention dans le cas des sites le lien doit pointer non pas sur |
|
| 161 | - // la page locale du site, mais directement sur le site lui-meme |
|
| 162 | - if ($f = charger_fonction("implicite_$type", 'liens', true)) { |
|
| 163 | - $url = $f($texte, $id, $type, $args, $ancre, $connect); |
|
| 164 | - } |
|
| 165 | - if (!$url) { |
|
| 166 | - $url = generer_url_entite($id, $type, $args, $ancre, $connect ?: null); |
|
| 167 | - } |
|
| 168 | - if (!$url) { |
|
| 169 | - return false; |
|
| 170 | - } |
|
| 171 | - if (is_array($url)) { |
|
| 172 | - [$type, $id] = array_pad($url, 2, null); |
|
| 173 | - $url = generer_url_entite($id, $type, $args, $ancre, $connect ?: null); |
|
| 174 | - } |
|
| 175 | - if ($pour === 'url') { |
|
| 176 | - return $url; |
|
| 177 | - } |
|
| 178 | - $r = traiter_raccourci_titre($id, $type, $connect); |
|
| 179 | - if ($r) { |
|
| 180 | - $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in'; |
|
| 181 | - } |
|
| 182 | - if ($texte = trim($texte)) { |
|
| 183 | - $r['titre'] = $texte; |
|
| 184 | - } |
|
| 185 | - if (!@$r['titre']) { |
|
| 186 | - $r['titre'] = _T($type) . " $id"; |
|
| 187 | - } |
|
| 188 | - if ($pour == 'titre') { |
|
| 189 | - return $r['titre']; |
|
| 190 | - } |
|
| 191 | - $r['url'] = $url; |
|
| 192 | - |
|
| 193 | - // dans le cas d'un lien vers un doc, ajouter le type='mime/type' |
|
| 194 | - if ( |
|
| 195 | - $type == 'document' |
|
| 196 | - and $mime = sql_getfetsel( |
|
| 197 | - 'mime_type', |
|
| 198 | - 'spip_types_documents', |
|
| 199 | - 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 200 | - '', |
|
| 201 | - '', |
|
| 202 | - '', |
|
| 203 | - '', |
|
| 204 | - $connect |
|
| 205 | - ) |
|
| 206 | - ) { |
|
| 207 | - $r['mime'] = $mime; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - return $r; |
|
| 155 | + $url = null; |
|
| 156 | + if (!($match = typer_raccourci($ref))) { |
|
| 157 | + return false; |
|
| 158 | + } |
|
| 159 | + [$type, , $id, , $args, , $ancre] = array_pad($match, 7, null); |
|
| 160 | + // attention dans le cas des sites le lien doit pointer non pas sur |
|
| 161 | + // la page locale du site, mais directement sur le site lui-meme |
|
| 162 | + if ($f = charger_fonction("implicite_$type", 'liens', true)) { |
|
| 163 | + $url = $f($texte, $id, $type, $args, $ancre, $connect); |
|
| 164 | + } |
|
| 165 | + if (!$url) { |
|
| 166 | + $url = generer_url_entite($id, $type, $args, $ancre, $connect ?: null); |
|
| 167 | + } |
|
| 168 | + if (!$url) { |
|
| 169 | + return false; |
|
| 170 | + } |
|
| 171 | + if (is_array($url)) { |
|
| 172 | + [$type, $id] = array_pad($url, 2, null); |
|
| 173 | + $url = generer_url_entite($id, $type, $args, $ancre, $connect ?: null); |
|
| 174 | + } |
|
| 175 | + if ($pour === 'url') { |
|
| 176 | + return $url; |
|
| 177 | + } |
|
| 178 | + $r = traiter_raccourci_titre($id, $type, $connect); |
|
| 179 | + if ($r) { |
|
| 180 | + $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in'; |
|
| 181 | + } |
|
| 182 | + if ($texte = trim($texte)) { |
|
| 183 | + $r['titre'] = $texte; |
|
| 184 | + } |
|
| 185 | + if (!@$r['titre']) { |
|
| 186 | + $r['titre'] = _T($type) . " $id"; |
|
| 187 | + } |
|
| 188 | + if ($pour == 'titre') { |
|
| 189 | + return $r['titre']; |
|
| 190 | + } |
|
| 191 | + $r['url'] = $url; |
|
| 192 | + |
|
| 193 | + // dans le cas d'un lien vers un doc, ajouter le type='mime/type' |
|
| 194 | + if ( |
|
| 195 | + $type == 'document' |
|
| 196 | + and $mime = sql_getfetsel( |
|
| 197 | + 'mime_type', |
|
| 198 | + 'spip_types_documents', |
|
| 199 | + 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 200 | + '', |
|
| 201 | + '', |
|
| 202 | + '', |
|
| 203 | + '', |
|
| 204 | + $connect |
|
| 205 | + ) |
|
| 206 | + ) { |
|
| 207 | + $r['mime'] = $mime; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + return $r; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | // analyse des raccourcis issus de [TITRE->RACCOURCInnn] et connexes |
@@ -215,41 +215,41 @@ discard block |
||
| 215 | 215 | define('_RACCOURCI_URL', '/^\s*(\w*?)\s*(\d+)(\?(.*?))?(#([^\s]*))?\s*$/S'); |
| 216 | 216 | |
| 217 | 217 | function typer_raccourci($lien) { |
| 218 | - if (!preg_match(_RACCOURCI_URL, $lien, $match)) { |
|
| 219 | - return []; |
|
| 220 | - } |
|
| 221 | - $f = $match[1]; |
|
| 222 | - // valeur par defaut et alias historiques |
|
| 223 | - if (!$f) { |
|
| 224 | - $f = 'article'; |
|
| 225 | - } else { |
|
| 226 | - if ($f == 'art') { |
|
| 227 | - $f = 'article'; |
|
| 228 | - } else { |
|
| 229 | - if ($f == 'br') { |
|
| 230 | - $f = 'breve'; |
|
| 231 | - } else { |
|
| 232 | - if ($f == 'rub') { |
|
| 233 | - $f = 'rubrique'; |
|
| 234 | - } else { |
|
| 235 | - if ($f == 'aut') { |
|
| 236 | - $f = 'auteur'; |
|
| 237 | - } else { |
|
| 238 | - if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') { |
|
| 239 | - $f = 'document'; |
|
| 240 | - } else { |
|
| 241 | - if (preg_match('/^br..?ve$/S', $f)) { |
|
| 242 | - $f = 'breve'; |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - } # accents :( |
|
| 250 | - $match[0] = $f; |
|
| 251 | - |
|
| 252 | - return $match; |
|
| 218 | + if (!preg_match(_RACCOURCI_URL, $lien, $match)) { |
|
| 219 | + return []; |
|
| 220 | + } |
|
| 221 | + $f = $match[1]; |
|
| 222 | + // valeur par defaut et alias historiques |
|
| 223 | + if (!$f) { |
|
| 224 | + $f = 'article'; |
|
| 225 | + } else { |
|
| 226 | + if ($f == 'art') { |
|
| 227 | + $f = 'article'; |
|
| 228 | + } else { |
|
| 229 | + if ($f == 'br') { |
|
| 230 | + $f = 'breve'; |
|
| 231 | + } else { |
|
| 232 | + if ($f == 'rub') { |
|
| 233 | + $f = 'rubrique'; |
|
| 234 | + } else { |
|
| 235 | + if ($f == 'aut') { |
|
| 236 | + $f = 'auteur'; |
|
| 237 | + } else { |
|
| 238 | + if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') { |
|
| 239 | + $f = 'document'; |
|
| 240 | + } else { |
|
| 241 | + if (preg_match('/^br..?ve$/S', $f)) { |
|
| 242 | + $f = 'breve'; |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + } # accents :( |
|
| 250 | + $match[0] = $f; |
|
| 251 | + |
|
| 252 | + return $match; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -264,25 +264,25 @@ discard block |
||
| 264 | 264 | * } |
| 265 | 265 | **/ |
| 266 | 266 | function traiter_raccourci_titre($id, $type, $connect = null) { |
| 267 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 268 | - $desc = $trouver_table(table_objet($type)); |
|
| 269 | - if (!($desc and $s = $desc['titre'])) { |
|
| 270 | - return []; |
|
| 271 | - } |
|
| 272 | - $_id = $desc['key']['PRIMARY KEY']; |
|
| 273 | - $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect); |
|
| 274 | - if (!$r) { |
|
| 275 | - return []; |
|
| 276 | - } |
|
| 277 | - $r['titre'] = supprimer_numero($r['titre']); |
|
| 278 | - if (!$r['titre'] and !empty($r['surnom'])) { |
|
| 279 | - $r['titre'] = $r['surnom']; |
|
| 280 | - } |
|
| 281 | - if (!isset($r['lang'])) { |
|
| 282 | - $r['lang'] = ''; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $r; |
|
| 267 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 268 | + $desc = $trouver_table(table_objet($type)); |
|
| 269 | + if (!($desc and $s = $desc['titre'])) { |
|
| 270 | + return []; |
|
| 271 | + } |
|
| 272 | + $_id = $desc['key']['PRIMARY KEY']; |
|
| 273 | + $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect); |
|
| 274 | + if (!$r) { |
|
| 275 | + return []; |
|
| 276 | + } |
|
| 277 | + $r['titre'] = supprimer_numero($r['titre']); |
|
| 278 | + if (!$r['titre'] and !empty($r['surnom'])) { |
|
| 279 | + $r['titre'] = $r['surnom']; |
|
| 280 | + } |
|
| 281 | + if (!isset($r['lang'])) { |
|
| 282 | + $r['lang'] = ''; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $r; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // traite les modeles (dans la fonction typo), en remplacant |
@@ -293,136 +293,136 @@ discard block |
||
| 293 | 293 | // mais on renvoie les params (pour l'indexation par le moteur de recherche) |
| 294 | 294 | |
| 295 | 295 | define( |
| 296 | - '_RACCOURCI_MODELE', |
|
| 297 | - '(<([a-z_-]{3,})' # <modele |
|
| 298 | - . '\s*([0-9]*)\s*' # id |
|
| 299 | - . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 300 | - . '\s*/?' . '>)' # fin du modele > |
|
| 301 | - . '\s*(<\/a>)?' # eventuel </a> |
|
| 296 | + '_RACCOURCI_MODELE', |
|
| 297 | + '(<([a-z_-]{3,})' # <modele |
|
| 298 | + . '\s*([0-9]*)\s*' # id |
|
| 299 | + . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 300 | + . '\s*/?' . '>)' # fin du modele > |
|
| 301 | + . '\s*(<\/a>)?' # eventuel </a> |
|
| 302 | 302 | ); |
| 303 | 303 | |
| 304 | 304 | define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS'); |
| 305 | 305 | |
| 306 | 306 | function traiter_modeles($texte, $doublons = false, $echap = '', string $connect = '', $liens = null, $env = []) { |
| 307 | - // preserver la compatibilite : true = recherche des documents |
|
| 308 | - if ($doublons === true) { |
|
| 309 | - $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 310 | - } |
|
| 311 | - // detecter les modeles (rapide) |
|
| 312 | - if ( |
|
| 313 | - strpos($texte, '<') !== false and |
|
| 314 | - preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER) |
|
| 315 | - ) { |
|
| 316 | - include_spip('public/assembler'); |
|
| 317 | - $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 318 | - foreach ($matches as $match) { |
|
| 319 | - // Recuperer l'appel complet (y compris un eventuel lien) |
|
| 320 | - |
|
| 321 | - $a = strpos($texte, (string) $match[0]); |
|
| 322 | - preg_match( |
|
| 323 | - _RACCOURCI_MODELE_DEBUT, |
|
| 324 | - substr($texte, $a), |
|
| 325 | - $regs |
|
| 326 | - ); |
|
| 327 | - $regs[] = ''; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide |
|
| 328 | - [, $mod, $type, $id, $params, $fin] = $regs; |
|
| 329 | - if ( |
|
| 330 | - $fin and |
|
| 331 | - preg_match( |
|
| 332 | - '/<a\s[^<>]*>\s*$/i', |
|
| 333 | - substr($texte, 0, $a), |
|
| 334 | - $r |
|
| 335 | - ) |
|
| 336 | - ) { |
|
| 337 | - $lien = [ |
|
| 338 | - 'href' => extraire_attribut($r[0], 'href'), |
|
| 339 | - 'class' => extraire_attribut($r[0], 'class'), |
|
| 340 | - 'mime' => extraire_attribut($r[0], 'type'), |
|
| 341 | - 'title' => extraire_attribut($r[0], 'title'), |
|
| 342 | - 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 343 | - ]; |
|
| 344 | - $n = strlen($r[0]); |
|
| 345 | - $a -= $n; |
|
| 346 | - $cherche = $n + strlen($regs[0]); |
|
| 347 | - } else { |
|
| 348 | - $lien = false; |
|
| 349 | - $cherche = strlen($mod); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - // calculer le modele |
|
| 353 | - # hack indexation |
|
| 354 | - if ($doublons) { |
|
| 355 | - $texte .= preg_replace(',[|][^|=]*,s', ' ', $params); |
|
| 356 | - } # version normale |
|
| 357 | - else { |
|
| 358 | - // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 359 | - // dans les parametres, plutot que les liens echappes |
|
| 360 | - if (!is_null($liens)) { |
|
| 361 | - $params = str_replace($liens[0], $liens[1], $params); |
|
| 362 | - } |
|
| 363 | - $modele = inclure_modele($type, $id, $params, $lien, $connect, $env); |
|
| 364 | - // en cas d'echec, |
|
| 365 | - // si l'objet demande a une url, |
|
| 366 | - // creer un petit encadre vers elle |
|
| 367 | - if ($modele === false) { |
|
| 368 | - if (!$lien) { |
|
| 369 | - $lien = traiter_lien_implicite("$type$id", '', 'tout', $connect); |
|
| 370 | - } |
|
| 371 | - if ($lien) { |
|
| 372 | - $modele = '<a href="' |
|
| 373 | - . $lien['url'] |
|
| 374 | - . '" class="spip_modele' |
|
| 375 | - . '">' |
|
| 376 | - . sinon($lien['titre'], _T('ecrire:info_sans_titre')) |
|
| 377 | - . '</a>'; |
|
| 378 | - } else { |
|
| 379 | - $modele = ''; |
|
| 380 | - if (test_espace_prive()) { |
|
| 381 | - $modele = entites_html(substr($texte, $a, $cherche)); |
|
| 382 | - if (!is_null($liens)) { |
|
| 383 | - $modele = '<pre>' . str_replace($liens[0], $liens[1], $modele) . '</pre>'; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - // le remplacer dans le texte |
|
| 389 | - if ($modele !== false) { |
|
| 390 | - $modele = protege_js_modeles($modele); |
|
| 391 | - if ($wrap_embed_html) { |
|
| 392 | - $modele = $wrap_embed_html($mod, $modele); |
|
| 393 | - } |
|
| 394 | - $rempl = code_echappement($modele, $echap); |
|
| 395 | - $texte = substr($texte, 0, $a) |
|
| 396 | - . $rempl |
|
| 397 | - . substr($texte, $a + $cherche); |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - // hack pour tout l'espace prive |
|
| 402 | - if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) { |
|
| 403 | - foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $modeles) { |
|
| 404 | - if (in_array($type, $modeles)) { |
|
| 405 | - $GLOBALS["doublons_{$quoi}_inclus"][] = $id; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - return $texte; |
|
| 307 | + // preserver la compatibilite : true = recherche des documents |
|
| 308 | + if ($doublons === true) { |
|
| 309 | + $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 310 | + } |
|
| 311 | + // detecter les modeles (rapide) |
|
| 312 | + if ( |
|
| 313 | + strpos($texte, '<') !== false and |
|
| 314 | + preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER) |
|
| 315 | + ) { |
|
| 316 | + include_spip('public/assembler'); |
|
| 317 | + $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 318 | + foreach ($matches as $match) { |
|
| 319 | + // Recuperer l'appel complet (y compris un eventuel lien) |
|
| 320 | + |
|
| 321 | + $a = strpos($texte, (string) $match[0]); |
|
| 322 | + preg_match( |
|
| 323 | + _RACCOURCI_MODELE_DEBUT, |
|
| 324 | + substr($texte, $a), |
|
| 325 | + $regs |
|
| 326 | + ); |
|
| 327 | + $regs[] = ''; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide |
|
| 328 | + [, $mod, $type, $id, $params, $fin] = $regs; |
|
| 329 | + if ( |
|
| 330 | + $fin and |
|
| 331 | + preg_match( |
|
| 332 | + '/<a\s[^<>]*>\s*$/i', |
|
| 333 | + substr($texte, 0, $a), |
|
| 334 | + $r |
|
| 335 | + ) |
|
| 336 | + ) { |
|
| 337 | + $lien = [ |
|
| 338 | + 'href' => extraire_attribut($r[0], 'href'), |
|
| 339 | + 'class' => extraire_attribut($r[0], 'class'), |
|
| 340 | + 'mime' => extraire_attribut($r[0], 'type'), |
|
| 341 | + 'title' => extraire_attribut($r[0], 'title'), |
|
| 342 | + 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 343 | + ]; |
|
| 344 | + $n = strlen($r[0]); |
|
| 345 | + $a -= $n; |
|
| 346 | + $cherche = $n + strlen($regs[0]); |
|
| 347 | + } else { |
|
| 348 | + $lien = false; |
|
| 349 | + $cherche = strlen($mod); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + // calculer le modele |
|
| 353 | + # hack indexation |
|
| 354 | + if ($doublons) { |
|
| 355 | + $texte .= preg_replace(',[|][^|=]*,s', ' ', $params); |
|
| 356 | + } # version normale |
|
| 357 | + else { |
|
| 358 | + // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 359 | + // dans les parametres, plutot que les liens echappes |
|
| 360 | + if (!is_null($liens)) { |
|
| 361 | + $params = str_replace($liens[0], $liens[1], $params); |
|
| 362 | + } |
|
| 363 | + $modele = inclure_modele($type, $id, $params, $lien, $connect, $env); |
|
| 364 | + // en cas d'echec, |
|
| 365 | + // si l'objet demande a une url, |
|
| 366 | + // creer un petit encadre vers elle |
|
| 367 | + if ($modele === false) { |
|
| 368 | + if (!$lien) { |
|
| 369 | + $lien = traiter_lien_implicite("$type$id", '', 'tout', $connect); |
|
| 370 | + } |
|
| 371 | + if ($lien) { |
|
| 372 | + $modele = '<a href="' |
|
| 373 | + . $lien['url'] |
|
| 374 | + . '" class="spip_modele' |
|
| 375 | + . '">' |
|
| 376 | + . sinon($lien['titre'], _T('ecrire:info_sans_titre')) |
|
| 377 | + . '</a>'; |
|
| 378 | + } else { |
|
| 379 | + $modele = ''; |
|
| 380 | + if (test_espace_prive()) { |
|
| 381 | + $modele = entites_html(substr($texte, $a, $cherche)); |
|
| 382 | + if (!is_null($liens)) { |
|
| 383 | + $modele = '<pre>' . str_replace($liens[0], $liens[1], $modele) . '</pre>'; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + // le remplacer dans le texte |
|
| 389 | + if ($modele !== false) { |
|
| 390 | + $modele = protege_js_modeles($modele); |
|
| 391 | + if ($wrap_embed_html) { |
|
| 392 | + $modele = $wrap_embed_html($mod, $modele); |
|
| 393 | + } |
|
| 394 | + $rempl = code_echappement($modele, $echap); |
|
| 395 | + $texte = substr($texte, 0, $a) |
|
| 396 | + . $rempl |
|
| 397 | + . substr($texte, $a + $cherche); |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + // hack pour tout l'espace prive |
|
| 402 | + if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) { |
|
| 403 | + foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $modeles) { |
|
| 404 | + if (in_array($type, $modeles)) { |
|
| 405 | + $GLOBALS["doublons_{$quoi}_inclus"][] = $id; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + return $texte; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | // |
| 416 | 416 | // Raccourcis ancre [#ancre<-] |
| 417 | 417 | // |
| 418 | 418 | function traiter_raccourci_ancre($letexte) { |
| 419 | - return $letexte; |
|
| 419 | + return $letexte; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | function traiter_raccourci_glossaire($texte) { |
| 423 | - return $texte; |
|
| 423 | + return $texte; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | function glossaire_std($terme) { |
| 427 | - return $terme; |
|
| 427 | + return $terme; |
|
| 428 | 428 | } |
@@ -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 | include_spip('inc/filtres'); |
| 23 | 23 | include_spip('inc/lang'); |
@@ -39,21 +39,21 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function definir_puce() { |
| 41 | 41 | |
| 42 | - // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | - // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | - // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | - $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 42 | + // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | + // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | + // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | + $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 46 | 46 | |
| 47 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | - if ($dir == 'rtl') { |
|
| 49 | - $p .= '_rtl'; |
|
| 50 | - } |
|
| 47 | + $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | + if ($dir == 'rtl') { |
|
| 49 | + $p .= '_rtl'; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - if (!isset($GLOBALS[$p])) { |
|
| 53 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 54 | - } |
|
| 52 | + if (!isset($GLOBALS[$p])) { |
|
| 53 | + $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $GLOBALS[$p]; |
|
| 56 | + return $GLOBALS[$p]; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 62 | 62 | |
| 63 | 63 | if (!defined('_BALISES_BLOCS')) { |
| 64 | - define( |
|
| 65 | - '_BALISES_BLOCS', |
|
| 66 | - 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 67 | - ); |
|
| 64 | + define( |
|
| 65 | + '_BALISES_BLOCS', |
|
| 66 | + 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 67 | + ); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 71 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 71 | + define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // |
@@ -79,106 +79,106 @@ discard block |
||
| 79 | 79 | // une $source differente ; le script detecte automagiquement si ce qu'on |
| 80 | 80 | // echappe est un div ou un span |
| 81 | 81 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 82 | - if (!strlen($rempl)) { |
|
| 83 | - return ''; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Tester si on echappe en span ou en div |
|
| 87 | - if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 88 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 92 | - $taille = 30000; |
|
| 93 | - $return = ''; |
|
| 94 | - for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 95 | - // Convertir en base64 et cacher dans un attribut |
|
| 96 | - // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 97 | - $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 98 | - $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $return; |
|
| 82 | + if (!strlen($rempl)) { |
|
| 83 | + return ''; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Tester si on echappe en span ou en div |
|
| 87 | + if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 88 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 92 | + $taille = 30000; |
|
| 93 | + $return = ''; |
|
| 94 | + for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 95 | + // Convertir en base64 et cacher dans un attribut |
|
| 96 | + // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 97 | + $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 98 | + $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $return; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
| 105 | 105 | // Echapper les <html>...</ html> |
| 106 | 106 | function traiter_echap_html_dist($regs) { |
| 107 | - return $regs[3]; |
|
| 107 | + return $regs[3]; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Echapper les <pre>...</ pre> |
| 111 | 111 | function traiter_echap_pre_dist($regs) { |
| 112 | - // echapper les <code> dans <pre> |
|
| 113 | - $pre = $regs[3]; |
|
| 114 | - |
|
| 115 | - // echapper les < dans <code> |
|
| 116 | - // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 117 | - if ( |
|
| 118 | - strpos($pre, '<') !== false |
|
| 119 | - and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 120 | - ) { |
|
| 121 | - foreach ($matches as $m) { |
|
| 122 | - if ($m[1] === 'code') { |
|
| 123 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 124 | - $pre = str_replace($m[0], $code, $pre); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - return "<pre>$pre</pre>"; |
|
| 112 | + // echapper les <code> dans <pre> |
|
| 113 | + $pre = $regs[3]; |
|
| 114 | + |
|
| 115 | + // echapper les < dans <code> |
|
| 116 | + // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 117 | + if ( |
|
| 118 | + strpos($pre, '<') !== false |
|
| 119 | + and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 120 | + ) { |
|
| 121 | + foreach ($matches as $m) { |
|
| 122 | + if ($m[1] === 'code') { |
|
| 123 | + $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 124 | + $pre = str_replace($m[0], $code, $pre); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + return "<pre>$pre</pre>"; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Echapper les <code>...</ code> |
| 132 | 132 | function traiter_echap_code_dist($regs) { |
| 133 | - [, , $att, $corps] = $regs; |
|
| 134 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 135 | - |
|
| 136 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 137 | - if (is_int(strpos($echap, "\n"))) { |
|
| 138 | - // supprimer les sauts de ligne debut/fin |
|
| 139 | - // (mais pas les espaces => ascii art). |
|
| 140 | - $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap); |
|
| 141 | - $echap = nl2br($echap); |
|
| 142 | - $echap = "<div style='text-align: left;' " |
|
| 143 | - . "class='spip_code' dir='ltr'><code$att>" |
|
| 144 | - . $echap . '</code></div>'; |
|
| 145 | - } else { |
|
| 146 | - $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>'; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $echap = str_replace("\t", ' ', $echap); |
|
| 150 | - $echap = str_replace(' ', ' ', $echap); |
|
| 151 | - |
|
| 152 | - return $echap; |
|
| 133 | + [, , $att, $corps] = $regs; |
|
| 134 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 135 | + |
|
| 136 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 137 | + if (is_int(strpos($echap, "\n"))) { |
|
| 138 | + // supprimer les sauts de ligne debut/fin |
|
| 139 | + // (mais pas les espaces => ascii art). |
|
| 140 | + $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap); |
|
| 141 | + $echap = nl2br($echap); |
|
| 142 | + $echap = "<div style='text-align: left;' " |
|
| 143 | + . "class='spip_code' dir='ltr'><code$att>" |
|
| 144 | + . $echap . '</code></div>'; |
|
| 145 | + } else { |
|
| 146 | + $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>'; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $echap = str_replace("\t", ' ', $echap); |
|
| 150 | + $echap = str_replace(' ', ' ', $echap); |
|
| 151 | + |
|
| 152 | + return $echap; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 156 | 156 | function traiter_echap_cadre_dist($regs) { |
| 157 | - $echap = trim(entites_html($regs[3])); |
|
| 158 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 159 | - $lignes = explode("\n", trim($echap)); |
|
| 160 | - $n = 0; |
|
| 161 | - foreach ($lignes as $l) { |
|
| 162 | - $n += floor(strlen($l) / 60) + 1; |
|
| 163 | - } |
|
| 164 | - $n = max($n, 2); |
|
| 165 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 166 | - |
|
| 167 | - return $echap; |
|
| 157 | + $echap = trim(entites_html($regs[3])); |
|
| 158 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 159 | + $lignes = explode("\n", trim($echap)); |
|
| 160 | + $n = 0; |
|
| 161 | + foreach ($lignes as $l) { |
|
| 162 | + $n += floor(strlen($l) / 60) + 1; |
|
| 163 | + } |
|
| 164 | + $n = max($n, 2); |
|
| 165 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 166 | + |
|
| 167 | + return $echap; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | function traiter_echap_frame_dist($regs) { |
| 171 | - return traiter_echap_cadre_dist($regs); |
|
| 171 | + return traiter_echap_cadre_dist($regs); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | function traiter_echap_script_dist($regs) { |
| 175 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 176 | - if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 177 | - return highlight_string($regs[0], true); |
|
| 178 | - } |
|
| 175 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 176 | + if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 177 | + return highlight_string($regs[0], true); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - // Cas normal : le script passe tel quel |
|
| 181 | - return $regs[0]; |
|
| 180 | + // Cas normal : le script passe tel quel |
|
| 181 | + return $regs[0]; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\s[^>]*)?>(.*)</\1>,UimsS'); |
@@ -196,79 +196,79 @@ discard block |
||
| 196 | 196 | * @return string|string[] |
| 197 | 197 | */ |
| 198 | 198 | function echappe_html( |
| 199 | - $letexte, |
|
| 200 | - $source = '', |
|
| 201 | - $no_transform = false, |
|
| 202 | - $preg = '', |
|
| 203 | - $callback_prefix = '' |
|
| 199 | + $letexte, |
|
| 200 | + $source = '', |
|
| 201 | + $no_transform = false, |
|
| 202 | + $preg = '', |
|
| 203 | + $callback_prefix = '' |
|
| 204 | 204 | ) { |
| 205 | - if (!is_string($letexte) or !strlen($letexte)) { |
|
| 206 | - return $letexte; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // si le texte recu est long PCRE risque d'exploser, on |
|
| 210 | - // fait donc un mic-mac pour augmenter pcre.backtrack_limit |
|
| 211 | - if (($len = strlen($letexte)) > 100000) { |
|
| 212 | - if (!$old = @ini_get('pcre.backtrack_limit')) { |
|
| 213 | - $old = 100000; |
|
| 214 | - } |
|
| 215 | - if ($len > $old) { |
|
| 216 | - $a = @ini_set('pcre.backtrack_limit', $len); |
|
| 217 | - spip_log("ini_set pcre.backtrack_limit=$len ($old)"); |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - if ( |
|
| 222 | - ($preg or strpos($letexte, '<') !== false) |
|
| 223 | - and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 224 | - ) { |
|
| 225 | - foreach ($matches as $regs) { |
|
| 226 | - // echappements tels quels ? |
|
| 227 | - if ($no_transform) { |
|
| 228 | - $echap = $regs[0]; |
|
| 229 | - } // sinon les traiter selon le cas |
|
| 230 | - else { |
|
| 231 | - if ( |
|
| 232 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 233 | - or function_exists($f = $f . '_dist') |
|
| 234 | - ) { |
|
| 235 | - $echap = $f($regs); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - $p = strpos($letexte, (string) $regs[0]); |
|
| 240 | - $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - if ($no_transform) { |
|
| 245 | - return $letexte; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 249 | - // seulement si on a echappe les <script> |
|
| 250 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 251 | - // dans une callback autonommee |
|
| 252 | - if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 253 | - if ( |
|
| 254 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 255 | - ',<[?].*($|[?]>),UisS', |
|
| 256 | - $letexte, |
|
| 257 | - $matches, |
|
| 258 | - PREG_SET_ORDER |
|
| 259 | - ) |
|
| 260 | - ) { |
|
| 261 | - foreach ($matches as $regs) { |
|
| 262 | - $letexte = str_replace( |
|
| 263 | - $regs[0], |
|
| 264 | - code_echappement(highlight_string($regs[0], true), $source), |
|
| 265 | - $letexte |
|
| 266 | - ); |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - return $letexte; |
|
| 205 | + if (!is_string($letexte) or !strlen($letexte)) { |
|
| 206 | + return $letexte; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // si le texte recu est long PCRE risque d'exploser, on |
|
| 210 | + // fait donc un mic-mac pour augmenter pcre.backtrack_limit |
|
| 211 | + if (($len = strlen($letexte)) > 100000) { |
|
| 212 | + if (!$old = @ini_get('pcre.backtrack_limit')) { |
|
| 213 | + $old = 100000; |
|
| 214 | + } |
|
| 215 | + if ($len > $old) { |
|
| 216 | + $a = @ini_set('pcre.backtrack_limit', $len); |
|
| 217 | + spip_log("ini_set pcre.backtrack_limit=$len ($old)"); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + if ( |
|
| 222 | + ($preg or strpos($letexte, '<') !== false) |
|
| 223 | + and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 224 | + ) { |
|
| 225 | + foreach ($matches as $regs) { |
|
| 226 | + // echappements tels quels ? |
|
| 227 | + if ($no_transform) { |
|
| 228 | + $echap = $regs[0]; |
|
| 229 | + } // sinon les traiter selon le cas |
|
| 230 | + else { |
|
| 231 | + if ( |
|
| 232 | + function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 233 | + or function_exists($f = $f . '_dist') |
|
| 234 | + ) { |
|
| 235 | + $echap = $f($regs); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + $p = strpos($letexte, (string) $regs[0]); |
|
| 240 | + $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + if ($no_transform) { |
|
| 245 | + return $letexte; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 249 | + // seulement si on a echappe les <script> |
|
| 250 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 251 | + // dans une callback autonommee |
|
| 252 | + if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 253 | + if ( |
|
| 254 | + strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 255 | + ',<[?].*($|[?]>),UisS', |
|
| 256 | + $letexte, |
|
| 257 | + $matches, |
|
| 258 | + PREG_SET_ORDER |
|
| 259 | + ) |
|
| 260 | + ) { |
|
| 261 | + foreach ($matches as $regs) { |
|
| 262 | + $letexte = str_replace( |
|
| 263 | + $regs[0], |
|
| 264 | + code_echappement(highlight_string($regs[0], true), $source), |
|
| 265 | + $letexte |
|
| 266 | + ); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + return $letexte; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // |
@@ -276,57 +276,57 @@ discard block |
||
| 276 | 276 | // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes |
| 277 | 277 | // par propre() : exemple dans multi et dans typo() |
| 278 | 278 | function echappe_retour($letexte, $source = '', $filtre = '') { |
| 279 | - if (strpos($letexte, (string) "base64$source")) { |
|
| 280 | - # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 281 | - $max_prof = 5; |
|
| 282 | - while ( |
|
| 283 | - strpos($letexte, '<') !== false |
|
| 284 | - and |
|
| 285 | - preg_match_all( |
|
| 286 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 287 | - $letexte, |
|
| 288 | - $regs, |
|
| 289 | - PREG_SET_ORDER |
|
| 290 | - ) |
|
| 291 | - and $max_prof-- |
|
| 292 | - ) { |
|
| 293 | - foreach ($regs as $reg) { |
|
| 294 | - $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 295 | - // recherche d'attributs supplementaires |
|
| 296 | - $at = []; |
|
| 297 | - foreach (['lang', 'dir'] as $attr) { |
|
| 298 | - if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 299 | - $at[$attr] = $a; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - if ($at) { |
|
| 303 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 304 | - foreach ($at as $attr => $a) { |
|
| 305 | - $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - if ($filtre) { |
|
| 309 | - $rempl = $filtre($rempl); |
|
| 310 | - } |
|
| 311 | - $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - return $letexte; |
|
| 279 | + if (strpos($letexte, (string) "base64$source")) { |
|
| 280 | + # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 281 | + $max_prof = 5; |
|
| 282 | + while ( |
|
| 283 | + strpos($letexte, '<') !== false |
|
| 284 | + and |
|
| 285 | + preg_match_all( |
|
| 286 | + ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 287 | + $letexte, |
|
| 288 | + $regs, |
|
| 289 | + PREG_SET_ORDER |
|
| 290 | + ) |
|
| 291 | + and $max_prof-- |
|
| 292 | + ) { |
|
| 293 | + foreach ($regs as $reg) { |
|
| 294 | + $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 295 | + // recherche d'attributs supplementaires |
|
| 296 | + $at = []; |
|
| 297 | + foreach (['lang', 'dir'] as $attr) { |
|
| 298 | + if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 299 | + $at[$attr] = $a; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + if ($at) { |
|
| 303 | + $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 304 | + foreach ($at as $attr => $a) { |
|
| 305 | + $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + if ($filtre) { |
|
| 309 | + $rempl = $filtre($rempl); |
|
| 310 | + } |
|
| 311 | + $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + return $letexte; |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | // Reinserer le javascript de confiance (venant des modeles) |
| 320 | 320 | |
| 321 | 321 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 322 | - $letexte = echappe_retour($letexte); |
|
| 322 | + $letexte = echappe_retour($letexte); |
|
| 323 | 323 | |
| 324 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 325 | - if ($interdire_scripts) { |
|
| 326 | - $letexte = interdire_scripts($letexte); |
|
| 327 | - } |
|
| 324 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 325 | + if ($interdire_scripts) { |
|
| 326 | + $letexte = interdire_scripts($letexte); |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - return trim($letexte); |
|
| 329 | + return trim($letexte); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | |
@@ -354,131 +354,131 @@ discard block |
||
| 354 | 354 | * Texte coupé |
| 355 | 355 | **/ |
| 356 | 356 | function couper($texte, $taille = 50, $suite = null) { |
| 357 | - if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 358 | - return ''; |
|
| 359 | - } |
|
| 360 | - $offset = 400 + 2 * $taille; |
|
| 361 | - while ( |
|
| 362 | - $offset < $length |
|
| 363 | - and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 364 | - ) { |
|
| 365 | - $offset = 2 * $offset; |
|
| 366 | - } |
|
| 367 | - if ( |
|
| 368 | - $offset < $length |
|
| 369 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 370 | - ) { |
|
| 371 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 372 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 373 | - $offset = $p_tag_fermant + 1; |
|
| 374 | - } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 375 | - } |
|
| 376 | - $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 377 | - |
|
| 378 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 379 | - include_spip('inc/lien'); |
|
| 380 | - } |
|
| 381 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 382 | - |
|
| 383 | - // balises de sauts de ligne et paragraphe |
|
| 384 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 385 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 386 | - |
|
| 387 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 388 | - $texte = str_replace("\n\n", "\r", $texte); |
|
| 389 | - |
|
| 390 | - // supprimer les tags |
|
| 391 | - $texte = supprimer_tags($texte); |
|
| 392 | - $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 393 | - $texte .= "\n"; // marquer la fin |
|
| 394 | - |
|
| 395 | - // corriger la longueur de coupe |
|
| 396 | - // en fonction de la presence de caracteres utf |
|
| 397 | - if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 398 | - $long = charset2unicode($texte); |
|
| 399 | - $long = spip_substr($long, 0, max($taille, 1)); |
|
| 400 | - $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 401 | - $taille += $nbcharutf; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - // couper au mot precedent |
|
| 406 | - $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 407 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 408 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 409 | - if (is_null($suite)) { |
|
| 410 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 411 | - } |
|
| 412 | - $points = $suite; |
|
| 413 | - |
|
| 414 | - // trop court ? ne pas faire de (...) |
|
| 415 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 416 | - $points = ''; |
|
| 417 | - $long = spip_substr($texte, 0, $taille); |
|
| 418 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 419 | - // encore trop court ? couper au caractere |
|
| 420 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 421 | - $texte = $long; |
|
| 422 | - } |
|
| 423 | - } else { |
|
| 424 | - $texte = $court; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 428 | - $points = ''; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - // remettre les paragraphes |
|
| 432 | - $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 433 | - |
|
| 434 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 435 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 436 | - |
|
| 437 | - return quote_amp(trim($texte)) . $points; |
|
| 357 | + if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 358 | + return ''; |
|
| 359 | + } |
|
| 360 | + $offset = 400 + 2 * $taille; |
|
| 361 | + while ( |
|
| 362 | + $offset < $length |
|
| 363 | + and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 364 | + ) { |
|
| 365 | + $offset = 2 * $offset; |
|
| 366 | + } |
|
| 367 | + if ( |
|
| 368 | + $offset < $length |
|
| 369 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 370 | + ) { |
|
| 371 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 372 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 373 | + $offset = $p_tag_fermant + 1; |
|
| 374 | + } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 375 | + } |
|
| 376 | + $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 377 | + |
|
| 378 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 379 | + include_spip('inc/lien'); |
|
| 380 | + } |
|
| 381 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 382 | + |
|
| 383 | + // balises de sauts de ligne et paragraphe |
|
| 384 | + $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 385 | + $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 386 | + |
|
| 387 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 388 | + $texte = str_replace("\n\n", "\r", $texte); |
|
| 389 | + |
|
| 390 | + // supprimer les tags |
|
| 391 | + $texte = supprimer_tags($texte); |
|
| 392 | + $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 393 | + $texte .= "\n"; // marquer la fin |
|
| 394 | + |
|
| 395 | + // corriger la longueur de coupe |
|
| 396 | + // en fonction de la presence de caracteres utf |
|
| 397 | + if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 398 | + $long = charset2unicode($texte); |
|
| 399 | + $long = spip_substr($long, 0, max($taille, 1)); |
|
| 400 | + $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 401 | + $taille += $nbcharutf; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + // couper au mot precedent |
|
| 406 | + $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 407 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 408 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 409 | + if (is_null($suite)) { |
|
| 410 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 411 | + } |
|
| 412 | + $points = $suite; |
|
| 413 | + |
|
| 414 | + // trop court ? ne pas faire de (...) |
|
| 415 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 416 | + $points = ''; |
|
| 417 | + $long = spip_substr($texte, 0, $taille); |
|
| 418 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 419 | + // encore trop court ? couper au caractere |
|
| 420 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 421 | + $texte = $long; |
|
| 422 | + } |
|
| 423 | + } else { |
|
| 424 | + $texte = $court; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 428 | + $points = ''; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + // remettre les paragraphes |
|
| 432 | + $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 433 | + |
|
| 434 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 435 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 436 | + |
|
| 437 | + return quote_amp(trim($texte)) . $points; |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | |
| 441 | 441 | function protege_js_modeles($t) { |
| 442 | - if (isset($GLOBALS['visiteur_session'])) { |
|
| 443 | - if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 444 | - if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 445 | - include_spip('inc/acces'); |
|
| 446 | - define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 447 | - } |
|
| 448 | - foreach ($r as $regs) { |
|
| 449 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 453 | - if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 454 | - include_spip('inc/acces'); |
|
| 455 | - define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 456 | - } |
|
| 457 | - foreach ($r as $regs) { |
|
| 458 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - return $t; |
|
| 442 | + if (isset($GLOBALS['visiteur_session'])) { |
|
| 443 | + if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 444 | + if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 445 | + include_spip('inc/acces'); |
|
| 446 | + define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 447 | + } |
|
| 448 | + foreach ($r as $regs) { |
|
| 449 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 453 | + if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 454 | + include_spip('inc/acces'); |
|
| 455 | + define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 456 | + } |
|
| 457 | + foreach ($r as $regs) { |
|
| 458 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + return $t; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
| 467 | 467 | function echapper_faux_tags($letexte) { |
| 468 | - if (strpos($letexte, '<') === false) { |
|
| 469 | - return $letexte; |
|
| 470 | - } |
|
| 471 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 472 | - |
|
| 473 | - $letexte = ''; |
|
| 474 | - while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 475 | - // un texte a echapper |
|
| 476 | - $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 477 | - // un tag html qui a servit a faite le split |
|
| 478 | - $letexte .= array_shift($textMatches); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - return $letexte; |
|
| 468 | + if (strpos($letexte, '<') === false) { |
|
| 469 | + return $letexte; |
|
| 470 | + } |
|
| 471 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 472 | + |
|
| 473 | + $letexte = ''; |
|
| 474 | + while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 475 | + // un texte a echapper |
|
| 476 | + $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 477 | + // un tag html qui a servit a faite le split |
|
| 478 | + $letexte .= array_shift($textMatches); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + return $letexte; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | /** |
@@ -491,47 +491,47 @@ discard block |
||
| 491 | 491 | * @return string |
| 492 | 492 | */ |
| 493 | 493 | function echapper_html_suspect($texte, $strict = true) { |
| 494 | - static $echapper_html_suspect; |
|
| 495 | - if (!$texte or !is_string($texte)) { |
|
| 496 | - return $texte; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - if (!isset($echapper_html_suspect)) { |
|
| 500 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 501 | - } |
|
| 502 | - // si fonction personalisee, on delegue |
|
| 503 | - if ($echapper_html_suspect) { |
|
| 504 | - return $echapper_html_suspect($texte, $strict); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - if ( |
|
| 508 | - strpos($texte, '<') === false |
|
| 509 | - or strpos($texte, '=') === false |
|
| 510 | - ) { |
|
| 511 | - return $texte; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 515 | - // car sinon on declenche sur les modeles ou ressources |
|
| 516 | - if ( |
|
| 517 | - !$strict and |
|
| 518 | - (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 519 | - ) { |
|
| 520 | - return $texte; |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 524 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 525 | - // donc un test d'egalite est trop strict |
|
| 526 | - if (strlen(safehtml($texte)) !== strlen($texte)) { |
|
| 527 | - $texte = str_replace('<', '<', $texte); |
|
| 528 | - if (!function_exists('attribut_html')) { |
|
| 529 | - include_spip('inc/filtres'); |
|
| 530 | - } |
|
| 531 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - return $texte; |
|
| 494 | + static $echapper_html_suspect; |
|
| 495 | + if (!$texte or !is_string($texte)) { |
|
| 496 | + return $texte; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + if (!isset($echapper_html_suspect)) { |
|
| 500 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 501 | + } |
|
| 502 | + // si fonction personalisee, on delegue |
|
| 503 | + if ($echapper_html_suspect) { |
|
| 504 | + return $echapper_html_suspect($texte, $strict); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + if ( |
|
| 508 | + strpos($texte, '<') === false |
|
| 509 | + or strpos($texte, '=') === false |
|
| 510 | + ) { |
|
| 511 | + return $texte; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 515 | + // car sinon on declenche sur les modeles ou ressources |
|
| 516 | + if ( |
|
| 517 | + !$strict and |
|
| 518 | + (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 519 | + ) { |
|
| 520 | + return $texte; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 524 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 525 | + // donc un test d'egalite est trop strict |
|
| 526 | + if (strlen(safehtml($texte)) !== strlen($texte)) { |
|
| 527 | + $texte = str_replace('<', '<', $texte); |
|
| 528 | + if (!function_exists('attribut_html')) { |
|
| 529 | + include_spip('inc/filtres'); |
|
| 530 | + } |
|
| 531 | + $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + return $texte; |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | |
@@ -552,30 +552,30 @@ discard block |
||
| 552 | 552 | * Texte sécurisé |
| 553 | 553 | **/ |
| 554 | 554 | function safehtml($t) { |
| 555 | - static $safehtml; |
|
| 556 | - |
|
| 557 | - if (!$t or !is_string($t)) { |
|
| 558 | - return $t; |
|
| 559 | - } |
|
| 560 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 561 | - if (strpos($t, '<') === false) { |
|
| 562 | - return str_replace("\x00", '', $t); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - if (!function_exists('interdire_scripts')) { |
|
| 566 | - include_spip('inc/texte'); |
|
| 567 | - } |
|
| 568 | - $t = interdire_scripts($t); // jolifier le php |
|
| 569 | - $t = echappe_js($t); |
|
| 570 | - |
|
| 571 | - if (!isset($safehtml)) { |
|
| 572 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 573 | - } |
|
| 574 | - if ($safehtml) { |
|
| 575 | - $t = $safehtml($t); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 555 | + static $safehtml; |
|
| 556 | + |
|
| 557 | + if (!$t or !is_string($t)) { |
|
| 558 | + return $t; |
|
| 559 | + } |
|
| 560 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 561 | + if (strpos($t, '<') === false) { |
|
| 562 | + return str_replace("\x00", '', $t); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + if (!function_exists('interdire_scripts')) { |
|
| 566 | + include_spip('inc/texte'); |
|
| 567 | + } |
|
| 568 | + $t = interdire_scripts($t); // jolifier le php |
|
| 569 | + $t = echappe_js($t); |
|
| 570 | + |
|
| 571 | + if (!isset($safehtml)) { |
|
| 572 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 573 | + } |
|
| 574 | + if ($safehtml) { |
|
| 575 | + $t = $safehtml($t); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | |
@@ -597,13 +597,13 @@ discard block |
||
| 597 | 597 | * Texte sans les modèles d'image |
| 598 | 598 | **/ |
| 599 | 599 | function supprime_img($letexte, $message = null) { |
| 600 | - if ($message === null) { |
|
| 601 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - return preg_replace( |
|
| 605 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 606 | - $message, |
|
| 607 | - $letexte |
|
| 608 | - ); |
|
| 600 | + if ($message === null) { |
|
| 601 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + return preg_replace( |
|
| 605 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 606 | + $message, |
|
| 607 | + $letexte |
|
| 608 | + ); |
|
| 609 | 609 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Langue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -39,36 +39,36 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function changer_langue($lang, $liste_langues = null) { |
| 41 | 41 | |
| 42 | - if (is_null($liste_langues)) { |
|
| 43 | - $liste_langues = @$GLOBALS['meta']['langues_proposees'] . ',' . @$GLOBALS['meta']['langues_multilingue']; |
|
| 44 | - } |
|
| 45 | - else { |
|
| 46 | - if (is_array($liste_langues)) { |
|
| 47 | - $liste_langues = implode(',', $liste_langues); |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 51 | - |
|
| 52 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 53 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 54 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 55 | - if (!$lang) { |
|
| 56 | - return false; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - if ( |
|
| 60 | - strpos($liste_langues, (string) ",$lang,") !== false |
|
| 61 | - or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 62 | - and strpos($liste_langues, (string) ",$lang,") !== false) |
|
| 63 | - ) { |
|
| 64 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 65 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 66 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 67 | - |
|
| 68 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 69 | - } else { |
|
| 70 | - return false; |
|
| 71 | - } |
|
| 42 | + if (is_null($liste_langues)) { |
|
| 43 | + $liste_langues = @$GLOBALS['meta']['langues_proposees'] . ',' . @$GLOBALS['meta']['langues_multilingue']; |
|
| 44 | + } |
|
| 45 | + else { |
|
| 46 | + if (is_array($liste_langues)) { |
|
| 47 | + $liste_langues = implode(',', $liste_langues); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 51 | + |
|
| 52 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 53 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 54 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 55 | + if (!$lang) { |
|
| 56 | + return false; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + if ( |
|
| 60 | + strpos($liste_langues, (string) ",$lang,") !== false |
|
| 61 | + or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 62 | + and strpos($liste_langues, (string) ",$lang,") !== false) |
|
| 63 | + ) { |
|
| 64 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 65 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 66 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 67 | + |
|
| 68 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 69 | + } else { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 82 | 82 | |
| 83 | 83 | function choisir_traduction($trads, $lang = '') { |
| 84 | - $k = approcher_langue($trads, $lang); |
|
| 84 | + $k = approcher_langue($trads, $lang); |
|
| 85 | 85 | |
| 86 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 86 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // retourne son 2e argument si c'est un index du premier |
@@ -91,21 +91,21 @@ discard block |
||
| 91 | 91 | // la langue X etant consideree comme une approche de X_Y |
| 92 | 92 | function approcher_langue($trads, $lang = '') { |
| 93 | 93 | |
| 94 | - if (!$lang) { |
|
| 95 | - $lang = $GLOBALS['spip_lang']; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - if (isset($trads[$lang])) { |
|
| 99 | - return $lang; |
|
| 100 | - } // cas des langues xx_yy |
|
| 101 | - else { |
|
| 102 | - $r = explode('_', $lang); |
|
| 103 | - if (isset($trads[$r[0]])) { |
|
| 104 | - return $r[0]; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - return ''; |
|
| 94 | + if (!$lang) { |
|
| 95 | + $lang = $GLOBALS['spip_lang']; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + if (isset($trads[$lang])) { |
|
| 99 | + return $lang; |
|
| 100 | + } // cas des langues xx_yy |
|
| 101 | + else { |
|
| 102 | + $r = explode('_', $lang); |
|
| 103 | + if (isset($trads[$r[0]])) { |
|
| 104 | + return $r[0]; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + return ''; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | * Nom de la langue, sinon son code. |
| 121 | 121 | **/ |
| 122 | 122 | function traduire_nom_langue($lang) { |
| 123 | - include_spip('inc/lang_liste'); |
|
| 124 | - include_spip('inc/charsets'); |
|
| 123 | + include_spip('inc/lang_liste'); |
|
| 124 | + include_spip('inc/charsets'); |
|
| 125 | 125 | |
| 126 | - return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 126 | + return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // |
@@ -136,10 +136,10 @@ discard block |
||
| 136 | 136 | // hebreu a priori), 'droitier' sinon. |
| 137 | 137 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 138 | 138 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 139 | - static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 139 | + static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 140 | 140 | |
| 141 | - return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 142 | - $gaucher : $droitier; |
|
| 141 | + return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 142 | + $gaucher : $droitier; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | // typo francaise ou anglaise ? |
@@ -148,29 +148,29 @@ discard block |
||
| 148 | 148 | // sinon determiner la typo en fonction de la langue courante |
| 149 | 149 | |
| 150 | 150 | function lang_typo($lang = '') { |
| 151 | - if (!$lang) { |
|
| 152 | - $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 153 | - } |
|
| 154 | - if ( |
|
| 155 | - $lang == 'eo' |
|
| 156 | - or $lang == 'fr' |
|
| 157 | - or strncmp($lang, 'fr_', 3) == 0 |
|
| 158 | - or $lang == 'cpf' |
|
| 159 | - ) { |
|
| 160 | - return 'fr'; |
|
| 161 | - } else { |
|
| 162 | - return 'en'; |
|
| 163 | - } |
|
| 151 | + if (!$lang) { |
|
| 152 | + $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 153 | + } |
|
| 154 | + if ( |
|
| 155 | + $lang == 'eo' |
|
| 156 | + or $lang == 'fr' |
|
| 157 | + or strncmp($lang, 'fr_', 3) == 0 |
|
| 158 | + or $lang == 'cpf' |
|
| 159 | + ) { |
|
| 160 | + return 'fr'; |
|
| 161 | + } else { |
|
| 162 | + return 'en'; |
|
| 163 | + } |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 167 | 167 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 168 | 168 | function changer_typo($lang = '') { |
| 169 | - if ($lang) { |
|
| 170 | - $GLOBALS['lang_objet'] = $lang; |
|
| 171 | - } else { |
|
| 172 | - unset($GLOBALS['lang_objet']); |
|
| 173 | - } |
|
| 169 | + if ($lang) { |
|
| 170 | + $GLOBALS['lang_objet'] = $lang; |
|
| 171 | + } else { |
|
| 172 | + unset($GLOBALS['lang_objet']); |
|
| 173 | + } |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | // |
@@ -180,58 +180,58 @@ discard block |
||
| 180 | 180 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 181 | 181 | // |
| 182 | 182 | function menu_langues($nom_select, $default = '') { |
| 183 | - include_spip('inc/actions'); |
|
| 184 | - |
|
| 185 | - $langues = liste_options_langues($nom_select); |
|
| 186 | - $ret = ''; |
|
| 187 | - if (!count($langues)) { |
|
| 188 | - return ''; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - if (!$default) { |
|
| 192 | - $default = $GLOBALS['spip_lang']; |
|
| 193 | - } |
|
| 194 | - foreach ($langues as $l) { |
|
| 195 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 196 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - if (!test_espace_prive()) { |
|
| 200 | - $cible = self(); |
|
| 201 | - $base = ''; |
|
| 202 | - } else { |
|
| 203 | - $cible = self(); |
|
| 204 | - $base = spip_connect() ? 'base' : ''; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 208 | - |
|
| 209 | - return generer_action_auteur( |
|
| 210 | - 'converser', |
|
| 211 | - $base, |
|
| 212 | - $cible, |
|
| 213 | - (select_langues($nom_select, $change, $ret) |
|
| 214 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 215 | - " method='post'" |
|
| 216 | - ); |
|
| 183 | + include_spip('inc/actions'); |
|
| 184 | + |
|
| 185 | + $langues = liste_options_langues($nom_select); |
|
| 186 | + $ret = ''; |
|
| 187 | + if (!count($langues)) { |
|
| 188 | + return ''; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if (!$default) { |
|
| 192 | + $default = $GLOBALS['spip_lang']; |
|
| 193 | + } |
|
| 194 | + foreach ($langues as $l) { |
|
| 195 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 196 | + $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + if (!test_espace_prive()) { |
|
| 200 | + $cible = self(); |
|
| 201 | + $base = ''; |
|
| 202 | + } else { |
|
| 203 | + $cible = self(); |
|
| 204 | + $base = spip_connect() ? 'base' : ''; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 208 | + |
|
| 209 | + return generer_action_auteur( |
|
| 210 | + 'converser', |
|
| 211 | + $base, |
|
| 212 | + $cible, |
|
| 213 | + (select_langues($nom_select, $change, $ret) |
|
| 214 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 215 | + " method='post'" |
|
| 216 | + ); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | function select_langues($nom_select, $change, $options, $label = '') { |
| 220 | - static $cpt = 0; |
|
| 221 | - $id = 'menu_langues' . $cpt++; |
|
| 222 | - |
|
| 223 | - return |
|
| 224 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 225 | - "<select name='$nom_select' id='$id' " |
|
| 226 | - . ((!test_espace_prive()) ? |
|
| 227 | - ("class='forml menu_langues'") : |
|
| 228 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 229 | - ("class='lang_ecrire'") : |
|
| 230 | - "class='fondl'")) |
|
| 231 | - . $change |
|
| 232 | - . ">\n" |
|
| 233 | - . $options |
|
| 234 | - . '</select>'; |
|
| 220 | + static $cpt = 0; |
|
| 221 | + $id = 'menu_langues' . $cpt++; |
|
| 222 | + |
|
| 223 | + return |
|
| 224 | + "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 225 | + "<select name='$nom_select' id='$id' " |
|
| 226 | + . ((!test_espace_prive()) ? |
|
| 227 | + ("class='forml menu_langues'") : |
|
| 228 | + (($nom_select == 'var_lang_ecrire') ? |
|
| 229 | + ("class='lang_ecrire'") : |
|
| 230 | + "class='fondl'")) |
|
| 231 | + . $change |
|
| 232 | + . ">\n" |
|
| 233 | + . $options |
|
| 234 | + . '</select>'; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -253,34 +253,34 @@ discard block |
||
| 253 | 253 | */ |
| 254 | 254 | function liste_options_langues($nom_select) { |
| 255 | 255 | |
| 256 | - switch ($nom_select) { |
|
| 257 | - # #MENU_LANG |
|
| 258 | - case 'var_lang': |
|
| 259 | - # menu de changement de la langue d'un article |
|
| 260 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 261 | - case 'changer_lang': |
|
| 262 | - $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 263 | - break; |
|
| 264 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 265 | - # les langues presentes sous forme de fichiers de langue |
|
| 266 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 267 | - case 'var_lang_ecrire': |
|
| 268 | - default: |
|
| 269 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 270 | - init_langues(); |
|
| 271 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 272 | - break; |
|
| 256 | + switch ($nom_select) { |
|
| 257 | + # #MENU_LANG |
|
| 258 | + case 'var_lang': |
|
| 259 | + # menu de changement de la langue d'un article |
|
| 260 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 261 | + case 'changer_lang': |
|
| 262 | + $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 263 | + break; |
|
| 264 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 265 | + # les langues presentes sous forme de fichiers de langue |
|
| 266 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 267 | + case 'var_lang_ecrire': |
|
| 268 | + default: |
|
| 269 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 270 | + init_langues(); |
|
| 271 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 272 | + break; |
|
| 273 | 273 | |
| 274 | 274 | # dernier choix possible : toutes les langues = langues_proposees |
| 275 | 275 | # + langues_multilingues ; mais, ne sert pas |
| 276 | 276 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 277 | - } |
|
| 278 | - if (count($langues) <= 1) { |
|
| 279 | - return []; |
|
| 280 | - } |
|
| 281 | - sort($langues); |
|
| 277 | + } |
|
| 278 | + if (count($langues) <= 1) { |
|
| 279 | + return []; |
|
| 280 | + } |
|
| 281 | + sort($langues); |
|
| 282 | 282 | |
| 283 | - return $langues; |
|
| 283 | + return $langues; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -295,39 +295,39 @@ discard block |
||
| 295 | 295 | **/ |
| 296 | 296 | function verifier_lang_url() { |
| 297 | 297 | |
| 298 | - // quelle langue est demandee ? |
|
| 299 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 300 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 301 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 302 | - } |
|
| 303 | - if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 304 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 305 | - } |
|
| 306 | - if (isset($_GET['lang'])) { |
|
| 307 | - $lang_demandee = $_GET['lang']; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 311 | - if ( |
|
| 312 | - $GLOBALS['spip_lang'] != $lang_demandee |
|
| 313 | - and changer_langue($lang_demandee) |
|
| 314 | - and $lang_demandee != @$_GET['lang'] |
|
| 315 | - ) { |
|
| 316 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 317 | - // ici on a besoin des var_truc |
|
| 318 | - foreach ($_GET as $var => $val) { |
|
| 319 | - if (!strncmp('var_', $var, 4)) { |
|
| 320 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - include_spip('inc/headers'); |
|
| 324 | - redirige_par_entete($destination); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 328 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 329 | - // (pour criteres {lang}). |
|
| 330 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 298 | + // quelle langue est demandee ? |
|
| 299 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 300 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 301 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 302 | + } |
|
| 303 | + if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 304 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 305 | + } |
|
| 306 | + if (isset($_GET['lang'])) { |
|
| 307 | + $lang_demandee = $_GET['lang']; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 311 | + if ( |
|
| 312 | + $GLOBALS['spip_lang'] != $lang_demandee |
|
| 313 | + and changer_langue($lang_demandee) |
|
| 314 | + and $lang_demandee != @$_GET['lang'] |
|
| 315 | + ) { |
|
| 316 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 317 | + // ici on a besoin des var_truc |
|
| 318 | + foreach ($_GET as $var => $val) { |
|
| 319 | + if (!strncmp('var_', $var, 4)) { |
|
| 320 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + include_spip('inc/headers'); |
|
| 324 | + redirige_par_entete($destination); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 328 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 329 | + // (pour criteres {lang}). |
|
| 330 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | |
@@ -345,22 +345,22 @@ discard block |
||
| 345 | 345 | * La langue sélectionnée |
| 346 | 346 | **/ |
| 347 | 347 | function utiliser_langue_site($liste_langues = null) { |
| 348 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 349 | - if ( |
|
| 350 | - isset($GLOBALS['meta']['langue_site']) |
|
| 351 | - // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 352 | - // ou qu'elle n'est pas identique à la langue du site |
|
| 353 | - and (!isset($GLOBALS['spip_lang']) |
|
| 354 | - or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 355 | - ) { |
|
| 356 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 357 | - } |
|
| 358 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 359 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 360 | - spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - return $GLOBALS['spip_lang']; |
|
| 348 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 349 | + if ( |
|
| 350 | + isset($GLOBALS['meta']['langue_site']) |
|
| 351 | + // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 352 | + // ou qu'elle n'est pas identique à la langue du site |
|
| 353 | + and (!isset($GLOBALS['spip_lang']) |
|
| 354 | + or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 355 | + ) { |
|
| 356 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 357 | + } |
|
| 358 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 359 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 360 | + spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + return $GLOBALS['spip_lang']; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | /** |
@@ -379,30 +379,30 @@ discard block |
||
| 379 | 379 | **/ |
| 380 | 380 | function utiliser_langue_visiteur($liste_langues = null) { |
| 381 | 381 | |
| 382 | - $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 383 | - if (isset($_COOKIE[$l])) { |
|
| 384 | - if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 385 | - return $l; |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 390 | - if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 391 | - return $l; |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 396 | - foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 397 | - if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 398 | - if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 399 | - return $l; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return utiliser_langue_site($liste_langues); |
|
| 382 | + $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 383 | + if (isset($_COOKIE[$l])) { |
|
| 384 | + if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 385 | + return $l; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 390 | + if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 391 | + return $l; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 396 | + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 397 | + if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 398 | + if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 399 | + return $l; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return utiliser_langue_site($liste_langues); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | * @return int |
| 413 | 413 | */ |
| 414 | 414 | function match_langue($chaine) { |
| 415 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 415 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
@@ -430,36 +430,36 @@ discard block |
||
| 430 | 430 | **/ |
| 431 | 431 | function init_langues() { |
| 432 | 432 | |
| 433 | - // liste des langues dans les meta, sauf a l'install |
|
| 434 | - $all_langs = @$GLOBALS['meta']['langues_proposees']; |
|
| 435 | - |
|
| 436 | - $tout = []; |
|
| 437 | - if (!$all_langs) { |
|
| 438 | - // trouver tous les modules lang/spip_xx.php |
|
| 439 | - $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 440 | - foreach ($modules as $name => $path) { |
|
| 441 | - if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 442 | - if (match_langue($regs[1])) { |
|
| 443 | - $tout[] = $regs[1]; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - sort($tout); |
|
| 448 | - $tout = join(',', $tout); |
|
| 449 | - // Si les langues n'ont pas change, ne rien faire |
|
| 450 | - if ($tout != $all_langs) { |
|
| 451 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 452 | - include_spip('inc/meta'); |
|
| 453 | - ecrire_meta('langues_proposees', $tout); |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 457 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 458 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 459 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 460 | - ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 461 | - ecrire_meta('langue_site', $tout); |
|
| 462 | - } |
|
| 433 | + // liste des langues dans les meta, sauf a l'install |
|
| 434 | + $all_langs = @$GLOBALS['meta']['langues_proposees']; |
|
| 435 | + |
|
| 436 | + $tout = []; |
|
| 437 | + if (!$all_langs) { |
|
| 438 | + // trouver tous les modules lang/spip_xx.php |
|
| 439 | + $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 440 | + foreach ($modules as $name => $path) { |
|
| 441 | + if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 442 | + if (match_langue($regs[1])) { |
|
| 443 | + $tout[] = $regs[1]; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + sort($tout); |
|
| 448 | + $tout = join(',', $tout); |
|
| 449 | + // Si les langues n'ont pas change, ne rien faire |
|
| 450 | + if ($tout != $all_langs) { |
|
| 451 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 452 | + include_spip('inc/meta'); |
|
| 453 | + ecrire_meta('langues_proposees', $tout); |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 457 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 458 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 459 | + (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 460 | + ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 461 | + ecrire_meta('langue_site', $tout); |
|
| 462 | + } |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | /** |
@@ -473,10 +473,10 @@ discard block |
||
| 473 | 473 | * Code html de la balise <html> |
| 474 | 474 | **/ |
| 475 | 475 | function html_lang_attributes() { |
| 476 | - $lang = $GLOBALS['spip_lang']; |
|
| 477 | - $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 476 | + $lang = $GLOBALS['spip_lang']; |
|
| 477 | + $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 478 | 478 | |
| 479 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 479 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | * @return string |
| 491 | 491 | */ |
| 492 | 492 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 493 | - return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 493 | + return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | |
@@ -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 | |
@@ -47,24 +47,24 @@ discard block |
||
| 47 | 47 | * - false si l'arbre xml ne peut être créé ou est vide |
| 48 | 48 | **/ |
| 49 | 49 | function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1_048_576, $datas = '', $profondeur = -1) { |
| 50 | - $contenu = ''; |
|
| 51 | - if (tester_url_absolue($fichier)) { |
|
| 52 | - include_spip('inc/distant'); |
|
| 53 | - $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 54 | - $contenu = $contenu['page'] ?? ''; |
|
| 55 | - } else { |
|
| 56 | - lire_fichier($fichier, $contenu); |
|
| 57 | - } |
|
| 58 | - $arbre = []; |
|
| 59 | - if ($contenu) { |
|
| 60 | - $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 61 | - } |
|
| 50 | + $contenu = ''; |
|
| 51 | + if (tester_url_absolue($fichier)) { |
|
| 52 | + include_spip('inc/distant'); |
|
| 53 | + $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 54 | + $contenu = $contenu['page'] ?? ''; |
|
| 55 | + } else { |
|
| 56 | + lire_fichier($fichier, $contenu); |
|
| 57 | + } |
|
| 58 | + $arbre = []; |
|
| 59 | + if ($contenu) { |
|
| 60 | + $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return count($arbre) ? $arbre : false; |
|
| 63 | + return count($arbre) ? $arbre : false; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | if (!defined('_SPIP_XML_TAG_SPLIT')) { |
| 67 | - define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS'); |
|
| 67 | + define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS'); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -83,150 +83,150 @@ discard block |
||
| 83 | 83 | * - false si l'arbre xml ne peut être créé ou est vide |
| 84 | 84 | **/ |
| 85 | 85 | function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) { |
| 86 | - $out = []; |
|
| 87 | - // enlever les commentaires |
|
| 88 | - $charset = 'AUTO'; |
|
| 89 | - if ($clean === true) { |
|
| 90 | - if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 91 | - $charset = $regs[2]; |
|
| 92 | - } |
|
| 93 | - $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 94 | - $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 95 | - include_spip('inc/charsets'); |
|
| 96 | - $clean = $charset; |
|
| 97 | - //$texte = importer_charset($texte,$charset); |
|
| 98 | - } |
|
| 99 | - if (is_string($clean)) { |
|
| 100 | - $charset = $clean; |
|
| 101 | - } |
|
| 102 | - $txt = $texte; |
|
| 86 | + $out = []; |
|
| 87 | + // enlever les commentaires |
|
| 88 | + $charset = 'AUTO'; |
|
| 89 | + if ($clean === true) { |
|
| 90 | + if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 91 | + $charset = $regs[2]; |
|
| 92 | + } |
|
| 93 | + $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 94 | + $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 95 | + include_spip('inc/charsets'); |
|
| 96 | + $clean = $charset; |
|
| 97 | + //$texte = importer_charset($texte,$charset); |
|
| 98 | + } |
|
| 99 | + if (is_string($clean)) { |
|
| 100 | + $charset = $clean; |
|
| 101 | + } |
|
| 102 | + $txt = $texte; |
|
| 103 | 103 | |
| 104 | - // tant qu'il y a des tags |
|
| 105 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 106 | - while ((is_countable($chars) ? count($chars) : 0) >= 2) { |
|
| 107 | - // tag ouvrant |
|
| 108 | - //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 104 | + // tant qu'il y a des tags |
|
| 105 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 106 | + while ((is_countable($chars) ? count($chars) : 0) >= 2) { |
|
| 107 | + // tag ouvrant |
|
| 108 | + //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 109 | 109 | |
| 110 | - // $before doit etre vide ou des espaces uniquements! |
|
| 111 | - $before = trim($chars[0]); |
|
| 110 | + // $before doit etre vide ou des espaces uniquements! |
|
| 111 | + $before = trim($chars[0]); |
|
| 112 | 112 | |
| 113 | - if (strlen($before) > 0) { |
|
| 114 | - return importer_charset($texte, $charset); |
|
| 115 | - }//$texte; // before non vide, donc on est dans du texte |
|
| 113 | + if (strlen($before) > 0) { |
|
| 114 | + return importer_charset($texte, $charset); |
|
| 115 | + }//$texte; // before non vide, donc on est dans du texte |
|
| 116 | 116 | |
| 117 | - $tag = rtrim($chars[1]); |
|
| 118 | - $txt = $chars[2]; |
|
| 117 | + $tag = rtrim($chars[1]); |
|
| 118 | + $txt = $chars[2]; |
|
| 119 | 119 | |
| 120 | - if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 121 | - return importer_charset($texte, $charset); |
|
| 122 | - }//$texte; |
|
| 123 | - if (substr($tag, -1) == '/') { // self closing tag |
|
| 124 | - $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 125 | - $out[$tag][] = ''; |
|
| 126 | - } else { |
|
| 127 | - $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 128 | - $closing_tag = reset($closing_tag); |
|
| 129 | - // tag fermant |
|
| 130 | - $ncclos = strlen("</$closing_tag>"); |
|
| 131 | - $p = strpos($txt, (string) "</$closing_tag>"); |
|
| 132 | - if ($p !== false and (strpos($txt, '<') < $p)) { |
|
| 133 | - $nclose = 0; |
|
| 134 | - $nopen = 0; |
|
| 135 | - $d = 0; |
|
| 136 | - while ( |
|
| 137 | - $p !== false |
|
| 138 | - and ($morceau = substr($txt, $d, $p - $d)) |
|
| 139 | - and (($nopen += preg_match_all( |
|
| 140 | - '{<' . preg_quote($closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 141 | - $morceau, |
|
| 142 | - $matches, |
|
| 143 | - PREG_SET_ORDER |
|
| 144 | - )) > $nclose) |
|
| 145 | - ) { |
|
| 146 | - $nclose++; |
|
| 147 | - $d = $p + $ncclos; |
|
| 148 | - $p = strpos($txt, (string) "</$closing_tag>", $d); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - if ($p === false) { |
|
| 152 | - if ($strict) { |
|
| 153 | - $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 120 | + if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 121 | + return importer_charset($texte, $charset); |
|
| 122 | + }//$texte; |
|
| 123 | + if (substr($tag, -1) == '/') { // self closing tag |
|
| 124 | + $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 125 | + $out[$tag][] = ''; |
|
| 126 | + } else { |
|
| 127 | + $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 128 | + $closing_tag = reset($closing_tag); |
|
| 129 | + // tag fermant |
|
| 130 | + $ncclos = strlen("</$closing_tag>"); |
|
| 131 | + $p = strpos($txt, (string) "</$closing_tag>"); |
|
| 132 | + if ($p !== false and (strpos($txt, '<') < $p)) { |
|
| 133 | + $nclose = 0; |
|
| 134 | + $nopen = 0; |
|
| 135 | + $d = 0; |
|
| 136 | + while ( |
|
| 137 | + $p !== false |
|
| 138 | + and ($morceau = substr($txt, $d, $p - $d)) |
|
| 139 | + and (($nopen += preg_match_all( |
|
| 140 | + '{<' . preg_quote($closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 141 | + $morceau, |
|
| 142 | + $matches, |
|
| 143 | + PREG_SET_ORDER |
|
| 144 | + )) > $nclose) |
|
| 145 | + ) { |
|
| 146 | + $nclose++; |
|
| 147 | + $d = $p + $ncclos; |
|
| 148 | + $p = strpos($txt, (string) "</$closing_tag>", $d); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + if ($p === false) { |
|
| 152 | + if ($strict) { |
|
| 153 | + $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 154 | 154 | |
| 155 | - return $out; |
|
| 156 | - } else { |
|
| 157 | - return importer_charset($texte, $charset); |
|
| 158 | - }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 159 | - } |
|
| 160 | - $content = substr($txt, 0, $p); |
|
| 161 | - $txt = substr($txt, $p + $ncclos); |
|
| 162 | - if ($profondeur == 0 or strpos($content, '<') === false) { // eviter une recursion si pas utile |
|
| 163 | - $out[$tag][] = importer_charset($content, $charset); |
|
| 164 | - }//$content; |
|
| 165 | - else { |
|
| 166 | - $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 170 | - } |
|
| 171 | - if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 172 | - return $out; |
|
| 173 | - } else { |
|
| 174 | - return importer_charset($texte, $charset); |
|
| 175 | - }//$texte; |
|
| 155 | + return $out; |
|
| 156 | + } else { |
|
| 157 | + return importer_charset($texte, $charset); |
|
| 158 | + }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 159 | + } |
|
| 160 | + $content = substr($txt, 0, $p); |
|
| 161 | + $txt = substr($txt, $p + $ncclos); |
|
| 162 | + if ($profondeur == 0 or strpos($content, '<') === false) { // eviter une recursion si pas utile |
|
| 163 | + $out[$tag][] = importer_charset($content, $charset); |
|
| 164 | + }//$content; |
|
| 165 | + else { |
|
| 166 | + $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 170 | + } |
|
| 171 | + if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 172 | + return $out; |
|
| 173 | + } else { |
|
| 174 | + return importer_charset($texte, $charset); |
|
| 175 | + }//$texte; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | function spip_xml_aplatit($arbre, $separateur = ' ') { |
| 179 | - $s = ''; |
|
| 180 | - if (is_array($arbre)) { |
|
| 181 | - foreach ($arbre as $tag => $feuille) { |
|
| 182 | - if (is_array($feuille)) { |
|
| 183 | - if ($tag !== intval($tag)) { |
|
| 184 | - $f = spip_xml_aplatit($feuille, $separateur); |
|
| 185 | - if (strlen($f)) { |
|
| 186 | - $tagf = explode(' ', $tag); |
|
| 187 | - $tagf = $tagf[0]; |
|
| 188 | - $s .= "<$tag>$f</$tagf>"; |
|
| 189 | - } else { |
|
| 190 | - $s .= "<$tag />"; |
|
| 191 | - } |
|
| 192 | - } else { |
|
| 193 | - $s .= spip_xml_aplatit($feuille); |
|
| 194 | - } |
|
| 195 | - $s .= $separateur; |
|
| 196 | - } else { |
|
| 197 | - $s .= "$feuille$separateur"; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 179 | + $s = ''; |
|
| 180 | + if (is_array($arbre)) { |
|
| 181 | + foreach ($arbre as $tag => $feuille) { |
|
| 182 | + if (is_array($feuille)) { |
|
| 183 | + if ($tag !== intval($tag)) { |
|
| 184 | + $f = spip_xml_aplatit($feuille, $separateur); |
|
| 185 | + if (strlen($f)) { |
|
| 186 | + $tagf = explode(' ', $tag); |
|
| 187 | + $tagf = $tagf[0]; |
|
| 188 | + $s .= "<$tag>$f</$tagf>"; |
|
| 189 | + } else { |
|
| 190 | + $s .= "<$tag />"; |
|
| 191 | + } |
|
| 192 | + } else { |
|
| 193 | + $s .= spip_xml_aplatit($feuille); |
|
| 194 | + } |
|
| 195 | + $s .= $separateur; |
|
| 196 | + } else { |
|
| 197 | + $s .= "$feuille$separateur"; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 202 | + return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | function spip_xml_tagname($tag) { |
| 206 | - if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 207 | - return $reg[1]; |
|
| 208 | - } |
|
| 206 | + if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 207 | + return $reg[1]; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - return ''; |
|
| 210 | + return ''; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | function spip_xml_decompose_tag($tag) { |
| 214 | - $tagname = spip_xml_tagname($tag); |
|
| 215 | - $liste = []; |
|
| 216 | - $tag = ltrim(strpbrk($tag, " \n\t")); |
|
| 217 | - $p = strpos($tag, '='); |
|
| 218 | - while ($p !== false) { |
|
| 219 | - $attr = trim(substr($tag, 0, $p)); |
|
| 220 | - $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | - $quote = $tag[0]; |
|
| 222 | - $p = strpos($tag, $quote, 1); |
|
| 223 | - $cont = substr($tag, 1, $p - 1); |
|
| 224 | - $liste[$attr] = $cont; |
|
| 225 | - $tag = substr($tag, $p + 1); |
|
| 226 | - $p = strpos($tag, '='); |
|
| 227 | - } |
|
| 214 | + $tagname = spip_xml_tagname($tag); |
|
| 215 | + $liste = []; |
|
| 216 | + $tag = ltrim(strpbrk($tag, " \n\t")); |
|
| 217 | + $p = strpos($tag, '='); |
|
| 218 | + while ($p !== false) { |
|
| 219 | + $attr = trim(substr($tag, 0, $p)); |
|
| 220 | + $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | + $quote = $tag[0]; |
|
| 222 | + $p = strpos($tag, $quote, 1); |
|
| 223 | + $cont = substr($tag, 1, $p - 1); |
|
| 224 | + $liste[$attr] = $cont; |
|
| 225 | + $tag = substr($tag, $p + 1); |
|
| 226 | + $p = strpos($tag, '='); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - return [$tagname, $liste]; |
|
| 229 | + return [$tagname, $liste]; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 250 | 250 | **/ |
| 251 | 251 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
| 252 | - if ($init) { |
|
| 253 | - $matches = []; |
|
| 254 | - } |
|
| 255 | - if (is_array($arbre) && count($arbre)) { |
|
| 256 | - foreach (array_keys($arbre) as $tag) { |
|
| 257 | - if (preg_match($regexp, $tag)) { |
|
| 258 | - $matches[$tag] = &$arbre[$tag]; |
|
| 259 | - } |
|
| 260 | - if (is_array($arbre[$tag])) { |
|
| 261 | - foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | - spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 252 | + if ($init) { |
|
| 253 | + $matches = []; |
|
| 254 | + } |
|
| 255 | + if (is_array($arbre) && count($arbre)) { |
|
| 256 | + foreach (array_keys($arbre) as $tag) { |
|
| 257 | + if (preg_match($regexp, $tag)) { |
|
| 258 | + $matches[$tag] = &$arbre[$tag]; |
|
| 259 | + } |
|
| 260 | + if (is_array($arbre[$tag])) { |
|
| 261 | + foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | + spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - return (is_countable($matches) ? count($matches) : 0); |
|
| 268 | + return (is_countable($matches) ? count($matches) : 0); |
|
| 269 | 269 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('base/serial'); |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * en droit de l'éliminer |
| 28 | 28 | */ |
| 29 | 29 | if (!defined('_AGE_CACHE_ATIME')) { |
| 30 | - define('_AGE_CACHE_ATIME', 3600); |
|
| 30 | + define('_AGE_CACHE_ATIME', 3600); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -40,31 +40,31 @@ discard block |
||
| 40 | 40 | * @return int Taille approximative en octets |
| 41 | 41 | **/ |
| 42 | 42 | function taille_du_cache() { |
| 43 | - # check dirs until we reach > 500 files |
|
| 44 | - $t = 0; |
|
| 45 | - $n = 0; |
|
| 46 | - $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
|
| 47 | - for ($i = 0; $i < 256; $i++) { |
|
| 48 | - $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 49 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 50 | - while (($f = readdir($d)) !== false) { |
|
| 51 | - if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
|
| 52 | - $n++; |
|
| 53 | - if ($a['mtime'] >= $time) { |
|
| 54 | - if ($a['blocks'] > 0) { |
|
| 55 | - $t += 512 * $a['blocks']; |
|
| 56 | - } else { |
|
| 57 | - $t += $a['size']; |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - if ($n > 500) { |
|
| 64 | - return intval(256 * $t / (1 + $i)); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - return $t; |
|
| 43 | + # check dirs until we reach > 500 files |
|
| 44 | + $t = 0; |
|
| 45 | + $n = 0; |
|
| 46 | + $time = $GLOBALS['meta']['cache_mark'] ?? 0; |
|
| 47 | + for ($i = 0; $i < 256; $i++) { |
|
| 48 | + $dir = _DIR_CACHE . sprintf('%02s', dechex($i)); |
|
| 49 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 50 | + while (($f = readdir($d)) !== false) { |
|
| 51 | + if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
|
| 52 | + $n++; |
|
| 53 | + if ($a['mtime'] >= $time) { |
|
| 54 | + if ($a['blocks'] > 0) { |
|
| 55 | + $t += 512 * $a['blocks']; |
|
| 56 | + } else { |
|
| 57 | + $t += $a['size']; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + if ($n > 500) { |
|
| 64 | + return intval(256 * $t / (1 + $i)); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + return $t; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
@@ -91,30 +91,30 @@ discard block |
||
| 91 | 91 | * Inutilisé |
| 92 | 92 | **/ |
| 93 | 93 | function inc_suivre_invalideur_dist($cond, $modif = true) { |
| 94 | - if (!$modif) { |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // determiner l'objet modifie : forum, article, etc |
|
| 99 | - if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 100 | - $objet = objet_type($r[1]); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 104 | - if (isset($objet)) { |
|
| 105 | - ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 109 | - // n'affecter la meta que si un de ces objets est modifie |
|
| 110 | - if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 111 | - if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 112 | - ecrire_meta('derniere_modif', time()); |
|
| 113 | - } |
|
| 114 | - } // sinon, cas standard, toujours affecter la meta |
|
| 115 | - else { |
|
| 116 | - ecrire_meta('derniere_modif', time()); |
|
| 117 | - } |
|
| 94 | + if (!$modif) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // determiner l'objet modifie : forum, article, etc |
|
| 99 | + if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 100 | + $objet = objet_type($r[1]); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 104 | + if (isset($objet)) { |
|
| 105 | + ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 109 | + // n'affecter la meta que si un de ces objets est modifie |
|
| 110 | + if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 111 | + if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 112 | + ecrire_meta('derniere_modif', time()); |
|
| 113 | + } |
|
| 114 | + } // sinon, cas standard, toujours affecter la meta |
|
| 115 | + else { |
|
| 116 | + ecrire_meta('derniere_modif', time()); |
|
| 117 | + } |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -139,57 +139,57 @@ discard block |
||
| 139 | 139 | * Nombre de fichiers supprimés |
| 140 | 140 | **/ |
| 141 | 141 | function purger_repertoire($dir, $options = []) { |
| 142 | - if (!is_dir($dir) or !is_readable($dir)) { |
|
| 143 | - return 0; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
|
| 147 | - // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
|
| 148 | - if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 149 | - return 0; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $handle = opendir($dir); |
|
| 153 | - if (!$handle) { |
|
| 154 | - return 0; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $total = 0; |
|
| 158 | - |
|
| 159 | - while (($fichier = @readdir($handle)) !== false) { |
|
| 160 | - // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 161 | - if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') { |
|
| 162 | - continue; |
|
| 163 | - } |
|
| 164 | - $chemin = "$dir/$fichier"; |
|
| 165 | - if (is_file($chemin)) { |
|
| 166 | - if ( |
|
| 167 | - (!isset($options['atime']) or (@fileatime($chemin) < $options['atime'])) |
|
| 168 | - and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime'])) |
|
| 169 | - ) { |
|
| 170 | - supprimer_fichier($chemin); |
|
| 171 | - $total++; |
|
| 172 | - } |
|
| 173 | - } else { |
|
| 174 | - if (is_dir($chemin)) { |
|
| 175 | - $opts = $options; |
|
| 176 | - if (isset($options['limit'])) { |
|
| 177 | - $opts['limit'] = $options['limit'] - $total; |
|
| 178 | - } |
|
| 179 | - $total += purger_repertoire($chemin, $opts); |
|
| 180 | - if (isset($options['subdir']) && $options['subdir']) { |
|
| 181 | - spip_unlink($chemin); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - if (isset($options['limit']) and $total >= $options['limit']) { |
|
| 187 | - break; |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - closedir($handle); |
|
| 191 | - |
|
| 192 | - return $total; |
|
| 142 | + if (!is_dir($dir) or !is_readable($dir)) { |
|
| 143 | + return 0; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + // sur certains sites on veut absolument garder certains caches référencés dans un CDN |
|
| 147 | + // on peut donc inhiber la purge de ces répertoires pour eviter tout probleme |
|
| 148 | + if (file_exists(rtrim($dir, '/') . '/inhib_purger_repertoire.txt')) { |
|
| 149 | + return 0; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $handle = opendir($dir); |
|
| 153 | + if (!$handle) { |
|
| 154 | + return 0; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $total = 0; |
|
| 158 | + |
|
| 159 | + while (($fichier = @readdir($handle)) !== false) { |
|
| 160 | + // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 161 | + if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') { |
|
| 162 | + continue; |
|
| 163 | + } |
|
| 164 | + $chemin = "$dir/$fichier"; |
|
| 165 | + if (is_file($chemin)) { |
|
| 166 | + if ( |
|
| 167 | + (!isset($options['atime']) or (@fileatime($chemin) < $options['atime'])) |
|
| 168 | + and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime'])) |
|
| 169 | + ) { |
|
| 170 | + supprimer_fichier($chemin); |
|
| 171 | + $total++; |
|
| 172 | + } |
|
| 173 | + } else { |
|
| 174 | + if (is_dir($chemin)) { |
|
| 175 | + $opts = $options; |
|
| 176 | + if (isset($options['limit'])) { |
|
| 177 | + $opts['limit'] = $options['limit'] - $total; |
|
| 178 | + } |
|
| 179 | + $total += purger_repertoire($chemin, $opts); |
|
| 180 | + if (isset($options['subdir']) && $options['subdir']) { |
|
| 181 | + spip_unlink($chemin); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + if (isset($options['limit']) and $total >= $options['limit']) { |
|
| 187 | + break; |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + closedir($handle); |
|
| 191 | + |
|
| 192 | + return $total; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -200,26 +200,26 @@ discard block |
||
| 200 | 200 | // Securite : est sur que c'est un cache |
| 201 | 201 | function retire_cache($cache) { |
| 202 | 202 | |
| 203 | - if ( |
|
| 204 | - preg_match( |
|
| 205 | - ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 206 | - $cache |
|
| 207 | - ) |
|
| 208 | - ) { |
|
| 209 | - // supprimer le fichier (de facon propre) |
|
| 210 | - supprimer_fichier(_DIR_CACHE . $cache); |
|
| 211 | - } else { |
|
| 212 | - spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 213 | - } |
|
| 203 | + if ( |
|
| 204 | + preg_match( |
|
| 205 | + ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 206 | + $cache |
|
| 207 | + ) |
|
| 208 | + ) { |
|
| 209 | + // supprimer le fichier (de facon propre) |
|
| 210 | + supprimer_fichier(_DIR_CACHE . $cache); |
|
| 211 | + } else { |
|
| 212 | + spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 213 | + } |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | // Supprimer les caches marques "x" |
| 217 | 217 | // A priori dans cette version la fonction ne sera pas appelee, car |
| 218 | 218 | // la meta est toujours false ; mais evitons un bug si elle est appellee |
| 219 | 219 | function inc_retire_caches_dist($chemin = '') { |
| 220 | - if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 221 | - effacer_meta('invalider_caches'); |
|
| 222 | - } # concurrence |
|
| 220 | + if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 221 | + effacer_meta('invalider_caches'); |
|
| 222 | + } # concurrence |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | ####################################################################### |
@@ -230,9 +230,9 @@ discard block |
||
| 230 | 230 | ## |
| 231 | 231 | |
| 232 | 232 | function retire_caches($chemin = '') { |
| 233 | - if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 234 | - return $retire_caches($chemin); |
|
| 235 | - } |
|
| 233 | + if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 234 | + return $retire_caches($chemin); |
|
| 235 | + } |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -240,10 +240,10 @@ discard block |
||
| 240 | 240 | // (note: si absente, n'est pas appellee) |
| 241 | 241 | |
| 242 | 242 | function calcul_invalideurs($corps, $primary, &$boucles, $id_boucle) { |
| 243 | - if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 244 | - return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 245 | - } |
|
| 246 | - return $corps; |
|
| 243 | + if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 244 | + return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 245 | + } |
|
| 246 | + return $corps; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -252,41 +252,41 @@ discard block |
||
| 252 | 252 | // invoquee quand on vide tout le cache en bloc (action/purger) |
| 253 | 253 | // |
| 254 | 254 | function supprime_invalideurs() { |
| 255 | - if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 256 | - return $supprime_invalideurs(); |
|
| 257 | - } |
|
| 255 | + if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 256 | + return $supprime_invalideurs(); |
|
| 257 | + } |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
| 261 | 261 | // Calcul des pages : noter dans la base les liens d'invalidation |
| 262 | 262 | function maj_invalideurs($fichier, &$page) { |
| 263 | - if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 264 | - return $maj_invalideurs($fichier, $page); |
|
| 265 | - } |
|
| 263 | + if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 264 | + return $maj_invalideurs($fichier, $page); |
|
| 265 | + } |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | |
| 269 | 269 | // les invalideurs sont de la forme "objet/id_objet" |
| 270 | 270 | function insere_invalideur($inval, $fichier) { |
| 271 | - if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 272 | - return $insere_invalideur($inval, $fichier); |
|
| 273 | - } |
|
| 271 | + if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 272 | + return $insere_invalideur($inval, $fichier); |
|
| 273 | + } |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // |
| 277 | 277 | // Marquer les fichiers caches invalides comme etant a supprimer |
| 278 | 278 | // |
| 279 | 279 | function applique_invalideur($depart) { |
| 280 | - if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 281 | - return $applique_invalideur($depart); |
|
| 282 | - } |
|
| 280 | + if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 281 | + return $applique_invalideur($depart); |
|
| 282 | + } |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | // |
| 286 | 286 | // Invalider les caches liés à telle condition |
| 287 | 287 | // |
| 288 | 288 | function suivre_invalideur($cond, $modif = true) { |
| 289 | - if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 290 | - return $suivre_invalideur($cond, $modif); |
|
| 291 | - } |
|
| 289 | + if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 290 | + return $suivre_invalideur($cond, $modif); |
|
| 291 | + } |
|
| 292 | 292 | } |
@@ -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/charsets'); |
@@ -24,222 +24,222 @@ discard block |
||
| 24 | 24 | * @return string |
| 25 | 25 | */ |
| 26 | 26 | function xml_entites_html($texte) { |
| 27 | - if ( |
|
| 28 | - !is_string($texte) or !$texte |
|
| 29 | - or strpbrk($texte, "&\"'<>") == false |
|
| 30 | - ) { |
|
| 31 | - return $texte; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - if (!function_exists('spip_htmlspecialchars')) { |
|
| 35 | - include_spip('inc/filtres_mini'); |
|
| 36 | - } |
|
| 37 | - $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 38 | - |
|
| 39 | - return $texte; |
|
| 27 | + if ( |
|
| 28 | + !is_string($texte) or !$texte |
|
| 29 | + or strpbrk($texte, "&\"'<>") == false |
|
| 30 | + ) { |
|
| 31 | + return $texte; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + if (!function_exists('spip_htmlspecialchars')) { |
|
| 35 | + include_spip('inc/filtres_mini'); |
|
| 36 | + } |
|
| 37 | + $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 38 | + |
|
| 39 | + return $texte; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | function xml_debutElement($phraseur, $name, $attrs) { |
| 43 | - $depth = $phraseur->depth; |
|
| 44 | - |
|
| 45 | - $t = $phraseur->ouvrant[$depth] ?? ' '; |
|
| 46 | - // espace initial signifie: deja integree au resultat |
|
| 47 | - if ($t[0] != ' ') { |
|
| 48 | - $phraseur->res .= '<' . $t . '>'; |
|
| 49 | - $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 50 | - } |
|
| 51 | - $t = $phraseur->contenu[$depth]; |
|
| 52 | - // n'indenter que s'il y a un separateur avant |
|
| 53 | - $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t); |
|
| 54 | - $phraseur->contenu[$depth] = ''; |
|
| 55 | - $att = ''; |
|
| 56 | - $sep = ' '; |
|
| 57 | - foreach ($attrs as $k => $v) { |
|
| 58 | - $delim = strpos($v, "'") === false ? "'" : '"'; |
|
| 59 | - $val = xml_entites_html($v); |
|
| 60 | - $att .= $sep . $k . '=' . $delim |
|
| 61 | - . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
|
| 62 | - . $delim; |
|
| 63 | - $sep = "\n $depth"; |
|
| 64 | - } |
|
| 65 | - $phraseur->depth .= ' '; |
|
| 66 | - $phraseur->contenu[$phraseur->depth] = ''; |
|
| 67 | - $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 68 | - $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
|
| 43 | + $depth = $phraseur->depth; |
|
| 44 | + |
|
| 45 | + $t = $phraseur->ouvrant[$depth] ?? ' '; |
|
| 46 | + // espace initial signifie: deja integree au resultat |
|
| 47 | + if ($t[0] != ' ') { |
|
| 48 | + $phraseur->res .= '<' . $t . '>'; |
|
| 49 | + $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 50 | + } |
|
| 51 | + $t = $phraseur->contenu[$depth]; |
|
| 52 | + // n'indenter que s'il y a un separateur avant |
|
| 53 | + $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t); |
|
| 54 | + $phraseur->contenu[$depth] = ''; |
|
| 55 | + $att = ''; |
|
| 56 | + $sep = ' '; |
|
| 57 | + foreach ($attrs as $k => $v) { |
|
| 58 | + $delim = strpos($v, "'") === false ? "'" : '"'; |
|
| 59 | + $val = xml_entites_html($v); |
|
| 60 | + $att .= $sep . $k . '=' . $delim |
|
| 61 | + . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
|
| 62 | + . $delim; |
|
| 63 | + $sep = "\n $depth"; |
|
| 64 | + } |
|
| 65 | + $phraseur->depth .= ' '; |
|
| 66 | + $phraseur->contenu[$phraseur->depth] = ''; |
|
| 67 | + $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 68 | + $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function xml_finElement($phraseur, $name, $fusion_bal = false) { |
| 72 | - $ouv = $phraseur->ouvrant[$phraseur->depth]; |
|
| 73 | - |
|
| 74 | - if ($ouv[0] != ' ') { |
|
| 75 | - $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 76 | - } else { |
|
| 77 | - $ouv = ''; |
|
| 78 | - } |
|
| 79 | - $t = $phraseur->contenu[$phraseur->depth]; |
|
| 80 | - $phraseur->depth = substr($phraseur->depth, 2); |
|
| 81 | - $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 82 | - |
|
| 83 | - // fusion <balise></balise> en <balise />. |
|
| 84 | - // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
|
| 85 | - // en particulier pour les balises Script et A. |
|
| 86 | - // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
|
| 87 | - // (param fusion_bal) |
|
| 88 | - |
|
| 89 | - if ($t || (($ouv != $name) and !$fusion_bal)) { |
|
| 90 | - $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>'; |
|
| 91 | - } else { |
|
| 92 | - $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>')); |
|
| 93 | - } |
|
| 72 | + $ouv = $phraseur->ouvrant[$phraseur->depth]; |
|
| 73 | + |
|
| 74 | + if ($ouv[0] != ' ') { |
|
| 75 | + $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 76 | + } else { |
|
| 77 | + $ouv = ''; |
|
| 78 | + } |
|
| 79 | + $t = $phraseur->contenu[$phraseur->depth]; |
|
| 80 | + $phraseur->depth = substr($phraseur->depth, 2); |
|
| 81 | + $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 82 | + |
|
| 83 | + // fusion <balise></balise> en <balise />. |
|
| 84 | + // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
|
| 85 | + // en particulier pour les balises Script et A. |
|
| 86 | + // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
|
| 87 | + // (param fusion_bal) |
|
| 88 | + |
|
| 89 | + if ($t || (($ouv != $name) and !$fusion_bal)) { |
|
| 90 | + $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>'; |
|
| 91 | + } else { |
|
| 92 | + $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>')); |
|
| 93 | + } |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function xml_textElement($phraseur, $data) { |
| 97 | - $depth = $phraseur->depth; |
|
| 98 | - $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth]) |
|
| 99 | - ? $data |
|
| 100 | - : xml_entites_html($data); |
|
| 97 | + $depth = $phraseur->depth; |
|
| 98 | + $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth]) |
|
| 99 | + ? $data |
|
| 100 | + : xml_entites_html($data); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | function xml_piElement($phraseur, $target, $data) { |
| 104 | - $depth = $phraseur->depth; |
|
| 105 | - |
|
| 106 | - if (strtolower($target) != 'php') { |
|
| 107 | - $phraseur->contenu[$depth] .= $data; |
|
| 108 | - } else { |
|
| 109 | - ob_start(); |
|
| 110 | - eval($data); |
|
| 111 | - $data = ob_get_contents(); |
|
| 112 | - ob_end_clean(); |
|
| 113 | - $phraseur->contenu[$depth] .= $data; |
|
| 114 | - } |
|
| 104 | + $depth = $phraseur->depth; |
|
| 105 | + |
|
| 106 | + if (strtolower($target) != 'php') { |
|
| 107 | + $phraseur->contenu[$depth] .= $data; |
|
| 108 | + } else { |
|
| 109 | + ob_start(); |
|
| 110 | + eval($data); |
|
| 111 | + $data = ob_get_contents(); |
|
| 112 | + ob_end_clean(); |
|
| 113 | + $phraseur->contenu[$depth] .= $data; |
|
| 114 | + } |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | function xml_defaultElement($phraseur, $data) { |
| 119 | - $depth = $phraseur->depth; |
|
| 119 | + $depth = $phraseur->depth; |
|
| 120 | 120 | |
| 121 | - if (!isset($phraseur->contenu[$depth])) { |
|
| 122 | - $phraseur->contenu[$depth] = ''; |
|
| 123 | - } |
|
| 124 | - $phraseur->contenu[$depth] .= $data; |
|
| 121 | + if (!isset($phraseur->contenu[$depth])) { |
|
| 122 | + $phraseur->contenu[$depth] = ''; |
|
| 123 | + } |
|
| 124 | + $phraseur->contenu[$depth] .= $data; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | function xml_parsestring($phraseur, $data) { |
| 128 | - $phraseur->contenu[$phraseur->depth] = ''; |
|
| 129 | - |
|
| 130 | - if (!xml_parse($phraseur->sax, $data, true)) { |
|
| 131 | - coordonnees_erreur( |
|
| 132 | - $phraseur, |
|
| 133 | - xml_error_string(xml_get_error_code($phraseur->sax)) |
|
| 134 | - . "<br />\n" . |
|
| 135 | - (!$phraseur->depth ? '' : |
|
| 136 | - ('(' . |
|
| 137 | - _T('erreur_balise_non_fermee') . |
|
| 138 | - ' <tt>' . |
|
| 139 | - $phraseur->ouvrant[$phraseur->depth] . |
|
| 140 | - '</tt> ' . |
|
| 141 | - _T('ligne') . |
|
| 142 | - ' ' . |
|
| 143 | - $phraseur->reperes[$phraseur->depth] . |
|
| 144 | - ") <br />\n")) |
|
| 145 | - ); |
|
| 146 | - } |
|
| 128 | + $phraseur->contenu[$phraseur->depth] = ''; |
|
| 129 | + |
|
| 130 | + if (!xml_parse($phraseur->sax, $data, true)) { |
|
| 131 | + coordonnees_erreur( |
|
| 132 | + $phraseur, |
|
| 133 | + xml_error_string(xml_get_error_code($phraseur->sax)) |
|
| 134 | + . "<br />\n" . |
|
| 135 | + (!$phraseur->depth ? '' : |
|
| 136 | + ('(' . |
|
| 137 | + _T('erreur_balise_non_fermee') . |
|
| 138 | + ' <tt>' . |
|
| 139 | + $phraseur->ouvrant[$phraseur->depth] . |
|
| 140 | + '</tt> ' . |
|
| 141 | + _T('ligne') . |
|
| 142 | + ' ' . |
|
| 143 | + $phraseur->reperes[$phraseur->depth] . |
|
| 144 | + ") <br />\n")) |
|
| 145 | + ); |
|
| 146 | + } |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | function coordonnees_erreur($phraseur, $msg) { |
| 150 | - $entete_length = substr_count($phraseur->entete, "\n"); |
|
| 151 | - $phraseur->err[] = [ |
|
| 152 | - $msg, |
|
| 153 | - xml_get_current_line_number($phraseur->sax) + $entete_length, |
|
| 154 | - xml_get_current_column_number($phraseur->sax) |
|
| 155 | - ]; |
|
| 150 | + $entete_length = substr_count($phraseur->entete, "\n"); |
|
| 151 | + $phraseur->err[] = [ |
|
| 152 | + $msg, |
|
| 153 | + xml_get_current_line_number($phraseur->sax) + $entete_length, |
|
| 154 | + xml_get_current_column_number($phraseur->sax) |
|
| 155 | + ]; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | function xml_sax_dist($page, $apply = false, $phraseur = null, $doctype = '', $charset = null) { |
| 159 | - if (is_null($charset)) { |
|
| 160 | - $charset = $GLOBALS['meta']['charset']; |
|
| 161 | - } |
|
| 162 | - if ($apply) { |
|
| 163 | - ob_start(); |
|
| 164 | - if (is_array($apply)) { |
|
| 165 | - $r = call_user_func_array($page, $apply); |
|
| 166 | - } else { |
|
| 167 | - $r = $page(); |
|
| 168 | - } |
|
| 169 | - $page = ob_get_contents(); |
|
| 170 | - ob_end_clean(); |
|
| 171 | - // fonction sans aucun "echo", ca doit etre le resultat |
|
| 172 | - if (!$page) { |
|
| 173 | - $page = $r; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - if (!$page) { |
|
| 178 | - return ''; |
|
| 179 | - } |
|
| 180 | - // charger la DTD et transcoder les entites, |
|
| 181 | - // et escamoter le doctype que sax mange en php5 mais pas en php4 |
|
| 182 | - if (!$doctype) { |
|
| 183 | - if (!$r = analyser_doctype($page)) { |
|
| 184 | - $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 185 | - . preg_replace(_REGEXP_DOCTYPE, '', $page); |
|
| 186 | - $r = analyser_doctype($page); |
|
| 187 | - } |
|
| 188 | - [$entete, $avail, $grammaire, $rotlvl] = array_pad($r, 4, null); |
|
| 189 | - $page = substr($page, strlen($entete)); |
|
| 190 | - } else { |
|
| 191 | - $avail = 'SYSTEM'; |
|
| 192 | - $grammaire = $doctype; |
|
| 193 | - $rotlvl = basename($grammaire); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - include_spip('xml/analyser_dtd'); |
|
| 197 | - $dtc = charger_dtd($grammaire, $avail, $rotlvl); |
|
| 198 | - $page = sax_bug($page, $dtc, $charset); |
|
| 199 | - |
|
| 200 | - // compatibilite Tidy espace public |
|
| 201 | - if (!$phraseur) { |
|
| 202 | - $indenter_xml = charger_fonction('indenter', 'xml'); |
|
| 203 | - |
|
| 204 | - return $indenter_xml($page, $apply); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $xml_parser = xml_parser_create($charset); |
|
| 208 | - |
|
| 209 | - xml_set_element_handler( |
|
| 210 | - $xml_parser, |
|
| 211 | - [$phraseur, 'debutElement'], |
|
| 212 | - [$phraseur, 'finElement'] |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - xml_set_character_data_handler( |
|
| 216 | - $xml_parser, |
|
| 217 | - [$phraseur, 'textElement'] |
|
| 218 | - ); |
|
| 219 | - |
|
| 220 | - xml_set_processing_instruction_handler( |
|
| 221 | - $xml_parser, |
|
| 222 | - [$phraseur, 'piElement'] |
|
| 223 | - ); |
|
| 224 | - |
|
| 225 | - xml_set_default_handler( |
|
| 226 | - $xml_parser, |
|
| 227 | - [$phraseur, 'defaultElement'] |
|
| 228 | - ); |
|
| 229 | - |
|
| 230 | - xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 231 | - |
|
| 232 | - $phraseur->sax = $xml_parser; |
|
| 233 | - if (isset($entete)) { |
|
| 234 | - $phraseur->entete = $entete; |
|
| 235 | - } |
|
| 236 | - $phraseur->page = $page; |
|
| 237 | - $phraseur->dtc = $dtc; |
|
| 238 | - $phraseur->phraserTout($xml_parser, $page); |
|
| 239 | - xml_parser_free($xml_parser); |
|
| 240 | - $phraseur->sax = ''; |
|
| 241 | - |
|
| 242 | - return $phraseur; |
|
| 159 | + if (is_null($charset)) { |
|
| 160 | + $charset = $GLOBALS['meta']['charset']; |
|
| 161 | + } |
|
| 162 | + if ($apply) { |
|
| 163 | + ob_start(); |
|
| 164 | + if (is_array($apply)) { |
|
| 165 | + $r = call_user_func_array($page, $apply); |
|
| 166 | + } else { |
|
| 167 | + $r = $page(); |
|
| 168 | + } |
|
| 169 | + $page = ob_get_contents(); |
|
| 170 | + ob_end_clean(); |
|
| 171 | + // fonction sans aucun "echo", ca doit etre le resultat |
|
| 172 | + if (!$page) { |
|
| 173 | + $page = $r; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + if (!$page) { |
|
| 178 | + return ''; |
|
| 179 | + } |
|
| 180 | + // charger la DTD et transcoder les entites, |
|
| 181 | + // et escamoter le doctype que sax mange en php5 mais pas en php4 |
|
| 182 | + if (!$doctype) { |
|
| 183 | + if (!$r = analyser_doctype($page)) { |
|
| 184 | + $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 185 | + . preg_replace(_REGEXP_DOCTYPE, '', $page); |
|
| 186 | + $r = analyser_doctype($page); |
|
| 187 | + } |
|
| 188 | + [$entete, $avail, $grammaire, $rotlvl] = array_pad($r, 4, null); |
|
| 189 | + $page = substr($page, strlen($entete)); |
|
| 190 | + } else { |
|
| 191 | + $avail = 'SYSTEM'; |
|
| 192 | + $grammaire = $doctype; |
|
| 193 | + $rotlvl = basename($grammaire); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + include_spip('xml/analyser_dtd'); |
|
| 197 | + $dtc = charger_dtd($grammaire, $avail, $rotlvl); |
|
| 198 | + $page = sax_bug($page, $dtc, $charset); |
|
| 199 | + |
|
| 200 | + // compatibilite Tidy espace public |
|
| 201 | + if (!$phraseur) { |
|
| 202 | + $indenter_xml = charger_fonction('indenter', 'xml'); |
|
| 203 | + |
|
| 204 | + return $indenter_xml($page, $apply); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $xml_parser = xml_parser_create($charset); |
|
| 208 | + |
|
| 209 | + xml_set_element_handler( |
|
| 210 | + $xml_parser, |
|
| 211 | + [$phraseur, 'debutElement'], |
|
| 212 | + [$phraseur, 'finElement'] |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + xml_set_character_data_handler( |
|
| 216 | + $xml_parser, |
|
| 217 | + [$phraseur, 'textElement'] |
|
| 218 | + ); |
|
| 219 | + |
|
| 220 | + xml_set_processing_instruction_handler( |
|
| 221 | + $xml_parser, |
|
| 222 | + [$phraseur, 'piElement'] |
|
| 223 | + ); |
|
| 224 | + |
|
| 225 | + xml_set_default_handler( |
|
| 226 | + $xml_parser, |
|
| 227 | + [$phraseur, 'defaultElement'] |
|
| 228 | + ); |
|
| 229 | + |
|
| 230 | + xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 231 | + |
|
| 232 | + $phraseur->sax = $xml_parser; |
|
| 233 | + if (isset($entete)) { |
|
| 234 | + $phraseur->entete = $entete; |
|
| 235 | + } |
|
| 236 | + $phraseur->page = $page; |
|
| 237 | + $phraseur->dtc = $dtc; |
|
| 238 | + $phraseur->phraserTout($xml_parser, $page); |
|
| 239 | + xml_parser_free($xml_parser); |
|
| 240 | + $phraseur->sax = ''; |
|
| 241 | + |
|
| 242 | + return $phraseur; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // SAX ne dit pas si une Entite est dans un attribut ou non. |
@@ -250,24 +250,24 @@ discard block |
||
| 250 | 250 | // sinon on se rabat sur ce qu'en connait SPIP en standard. |
| 251 | 251 | |
| 252 | 252 | function sax_bug($data, $dtc, $charset = null) { |
| 253 | - if (is_null($charset)) { |
|
| 254 | - $charset = $GLOBALS['meta']['charset']; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if ($dtc) { |
|
| 258 | - $trans = []; |
|
| 259 | - |
|
| 260 | - foreach ($dtc->entites as $k => $v) { |
|
| 261 | - if (!strpos(' amp lt gt quot ', (string) $k)) { |
|
| 262 | - $trans["&$k;"] = $v; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - $data = strtr($data, $trans); |
|
| 266 | - } else { |
|
| 267 | - $data = html2unicode($data, true); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - return unicode2charset($data, $charset); |
|
| 253 | + if (is_null($charset)) { |
|
| 254 | + $charset = $GLOBALS['meta']['charset']; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if ($dtc) { |
|
| 258 | + $trans = []; |
|
| 259 | + |
|
| 260 | + foreach ($dtc->entites as $k => $v) { |
|
| 261 | + if (!strpos(' amp lt gt quot ', (string) $k)) { |
|
| 262 | + $trans["&$k;"] = $v; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + $data = strtr($data, $trans); |
|
| 266 | + } else { |
|
| 267 | + $data = html2unicode($data, true); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + return unicode2charset($data, $charset); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // Retirer < ? xml... ? > et autre PI, ainsi que les commentaires en debut |
@@ -277,52 +277,52 @@ discard block |
||
| 277 | 277 | // les autres formats RSS n'ont pas de DTD, |
| 278 | 278 | // mais un XML Schema que SPIP ne fait pas encore lire. |
| 279 | 279 | function analyser_doctype($data) { |
| 280 | - if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
|
| 281 | - if (preg_match(_REGEXP_XML, $data, $page)) { |
|
| 282 | - [, $entete, $topelement] = $page; |
|
| 283 | - if ($topelement == 'rss') { |
|
| 284 | - return [ |
|
| 285 | - $entete, |
|
| 286 | - 'PUBLIC', |
|
| 287 | - _DOCTYPE_RSS, |
|
| 288 | - 'rss-0.91.dtd' |
|
| 289 | - ]; |
|
| 290 | - } else { |
|
| 291 | - $dtd = $topelement . '.dtd'; |
|
| 292 | - $f = find_in_path($dtd); |
|
| 293 | - if (file_exists($f)) { |
|
| 294 | - return [$entete, 'SYSTEM', $f, $dtd]; |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - spip_log('Dtd pas vu pour ' . substr($data, 0, 100)); |
|
| 299 | - |
|
| 300 | - return []; |
|
| 301 | - } |
|
| 302 | - [$entete, , $topelement, $avail, $suite] = $page; |
|
| 303 | - |
|
| 304 | - if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
|
| 305 | - if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
|
| 306 | - return []; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - [, $rotlvl, $suite] = $r; |
|
| 310 | - |
|
| 311 | - if (!$suite) { |
|
| 312 | - if ($avail != 'SYSTEM') { |
|
| 313 | - return []; |
|
| 314 | - } |
|
| 315 | - $grammaire = $rotlvl; |
|
| 316 | - $rotlvl = ''; |
|
| 317 | - } else { |
|
| 318 | - if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) { |
|
| 319 | - if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) { |
|
| 320 | - return []; |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - $grammaire = $r[1]; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - return [$entete, $avail, $grammaire, $rotlvl]; |
|
| 280 | + if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
|
| 281 | + if (preg_match(_REGEXP_XML, $data, $page)) { |
|
| 282 | + [, $entete, $topelement] = $page; |
|
| 283 | + if ($topelement == 'rss') { |
|
| 284 | + return [ |
|
| 285 | + $entete, |
|
| 286 | + 'PUBLIC', |
|
| 287 | + _DOCTYPE_RSS, |
|
| 288 | + 'rss-0.91.dtd' |
|
| 289 | + ]; |
|
| 290 | + } else { |
|
| 291 | + $dtd = $topelement . '.dtd'; |
|
| 292 | + $f = find_in_path($dtd); |
|
| 293 | + if (file_exists($f)) { |
|
| 294 | + return [$entete, 'SYSTEM', $f, $dtd]; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + spip_log('Dtd pas vu pour ' . substr($data, 0, 100)); |
|
| 299 | + |
|
| 300 | + return []; |
|
| 301 | + } |
|
| 302 | + [$entete, , $topelement, $avail, $suite] = $page; |
|
| 303 | + |
|
| 304 | + if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
|
| 305 | + if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
|
| 306 | + return []; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + [, $rotlvl, $suite] = $r; |
|
| 310 | + |
|
| 311 | + if (!$suite) { |
|
| 312 | + if ($avail != 'SYSTEM') { |
|
| 313 | + return []; |
|
| 314 | + } |
|
| 315 | + $grammaire = $rotlvl; |
|
| 316 | + $rotlvl = ''; |
|
| 317 | + } else { |
|
| 318 | + if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) { |
|
| 319 | + if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) { |
|
| 320 | + return []; |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + $grammaire = $r[1]; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + return [$entete, $avail, $grammaire, $rotlvl]; |
|
| 328 | 328 | } |
@@ -11,55 +11,55 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | class IndenteurXML { |
| 18 | 18 | |
| 19 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 20 | - xml_debutElement($this, $name, $attrs); |
|
| 21 | - } |
|
| 19 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 20 | + xml_debutElement($this, $name, $attrs); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function finElement($phraseur, $name) { |
|
| 24 | - xml_finElement($this, $name); |
|
| 25 | - } |
|
| 23 | + public function finElement($phraseur, $name) { |
|
| 24 | + xml_finElement($this, $name); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function textElement($phraseur, $data) { |
|
| 28 | - xml_textElement($this, $data); |
|
| 29 | - } |
|
| 27 | + public function textElement($phraseur, $data) { |
|
| 28 | + xml_textElement($this, $data); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function piElement($phraseur, $target, $data) { |
|
| 32 | - xml_PiElement($this, $target, $data); |
|
| 33 | - } |
|
| 31 | + public function piElement($phraseur, $target, $data) { |
|
| 32 | + xml_PiElement($this, $target, $data); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function defaultElement($phraseur, $data) { |
|
| 36 | - xml_defaultElement($this, $data); |
|
| 37 | - } |
|
| 35 | + public function defaultElement($phraseur, $data) { |
|
| 36 | + xml_defaultElement($this, $data); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function phraserTout($phraseur, $data) { |
|
| 40 | - xml_parsestring($this, $data); |
|
| 41 | - } |
|
| 39 | + public function phraserTout($phraseur, $data) { |
|
| 40 | + xml_parsestring($this, $data); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public $depth = ''; |
|
| 44 | - public $res = ''; |
|
| 45 | - public $err = []; |
|
| 46 | - public $contenu = []; |
|
| 47 | - public $ouvrant = []; |
|
| 48 | - public $reperes = []; |
|
| 49 | - public $entete = ''; |
|
| 50 | - public $page = ''; |
|
| 51 | - public $dtc = null; |
|
| 52 | - public $sax = null; |
|
| 43 | + public $depth = ''; |
|
| 44 | + public $res = ''; |
|
| 45 | + public $err = []; |
|
| 46 | + public $contenu = []; |
|
| 47 | + public $ouvrant = []; |
|
| 48 | + public $reperes = []; |
|
| 49 | + public $entete = ''; |
|
| 50 | + public $page = ''; |
|
| 51 | + public $dtc = null; |
|
| 52 | + public $sax = null; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | function xml_indenter_dist($page, $apply = false) { |
| 56 | - $sax = charger_fonction('sax', 'xml'); |
|
| 57 | - $f = new IndenteurXML(); |
|
| 58 | - $sax($page, $apply, $f); |
|
| 59 | - if (!$f->err) { |
|
| 60 | - return $f->entete . $f->res; |
|
| 61 | - } |
|
| 62 | - spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 56 | + $sax = charger_fonction('sax', 'xml'); |
|
| 57 | + $f = new IndenteurXML(); |
|
| 58 | + $sax($page, $apply, $f); |
|
| 59 | + if (!$f->err) { |
|
| 60 | + return $f->entete . $f->res; |
|
| 61 | + } |
|
| 62 | + spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 63 | 63 | |
| 64 | - return $f->entete . $f->page; |
|
| 64 | + return $f->entete . $f->page; |
|
| 65 | 65 | } |