@@ -19,21 +19,21 @@ discard block |
||
| 19 | 19 | * @package SPIP\Core\SQL\Upgrade |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][2021_02_18_00] = [ |
| 26 | - ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | - ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 26 | + ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | + ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 28 | 28 | ]; |
| 29 | 29 | |
| 30 | 30 | $GLOBALS['maj'][2022_02_23_02] = [ |
| 31 | - ['sql_alter', "TABLE spip_auteurs ADD backup_cles mediumtext DEFAULT '' NOT NULL" ], |
|
| 32 | - ['sql_delete', 'spip_meta', "nom='secret_du_site'" ], |
|
| 31 | + ['sql_alter', "TABLE spip_auteurs ADD backup_cles mediumtext DEFAULT '' NOT NULL" ], |
|
| 32 | + ['sql_delete', 'spip_meta', "nom='secret_du_site'" ], |
|
| 33 | 33 | ]; |
| 34 | 34 | |
| 35 | 35 | $GLOBALS['maj'][2022_02_23_03] = [ |
| 36 | - ['maj2021_supprimer_toutes_sessions_si_aucun_backup_cles'], |
|
| 36 | + ['maj2021_supprimer_toutes_sessions_si_aucun_backup_cles'], |
|
| 37 | 37 | ]; |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -44,15 +44,15 @@ discard block |
||
| 44 | 44 | * - les autres auteurs vont tous regénérer un mot de passe plus sécure au premier login |
| 45 | 45 | **/ |
| 46 | 46 | function maj2021_supprimer_toutes_sessions_si_aucun_backup_cles() { |
| 47 | - if (!sql_countsel('spip_auteurs', "webmestre='oui' AND backup_cles!=''")) { |
|
| 48 | - spip_log('supprimer sessions auteur', 'maj'); |
|
| 49 | - if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 50 | - while (($f = readdir($dir)) !== false) { |
|
| 51 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 52 | - if (time() >= _TIME_OUT) { |
|
| 53 | - return; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 47 | + if (!sql_countsel('spip_auteurs', "webmestre='oui' AND backup_cles!=''")) { |
|
| 48 | + spip_log('supprimer sessions auteur', 'maj'); |
|
| 49 | + if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 50 | + while (($f = readdir($dir)) !== false) { |
|
| 51 | + spip_unlink(_DIR_SESSIONS . $f); |
|
| 52 | + if (time() >= _TIME_OUT) { |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -23,13 +23,13 @@ discard block |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][2021_02_18_00] = [ |
| 26 | - ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | - ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 26 | + ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL"], |
|
| 27 | + ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL"], |
|
| 28 | 28 | ]; |
| 29 | 29 | |
| 30 | 30 | $GLOBALS['maj'][2022_02_23_02] = [ |
| 31 | - ['sql_alter', "TABLE spip_auteurs ADD backup_cles mediumtext DEFAULT '' NOT NULL" ], |
|
| 32 | - ['sql_delete', 'spip_meta', "nom='secret_du_site'" ], |
|
| 31 | + ['sql_alter', "TABLE spip_auteurs ADD backup_cles mediumtext DEFAULT '' NOT NULL"], |
|
| 32 | + ['sql_delete', 'spip_meta', "nom='secret_du_site'"], |
|
| 33 | 33 | ]; |
| 34 | 34 | |
| 35 | 35 | $GLOBALS['maj'][2022_02_23_03] = [ |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | spip_log('supprimer sessions auteur', 'maj'); |
| 49 | 49 | if ($dir = opendir(_DIR_SESSIONS)) { |
| 50 | 50 | while (($f = readdir($dir)) !== false) { |
| 51 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 51 | + spip_unlink(_DIR_SESSIONS.$f); |
|
| 52 | 52 | if (time() >= _TIME_OUT) { |
| 53 | 53 | return; |
| 54 | 54 | } |
@@ -14,154 +14,154 @@ |
||
| 14 | 14 | |
| 15 | 15 | abstract class AbstractCollecteur { |
| 16 | 16 | |
| 17 | - protected static string $markPrefix = 'COLLECT'; |
|
| 18 | - protected string $markId; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Collecteur générique des occurences d'une preg dans un texte avec leurs positions et longueur |
|
| 22 | - * @param string $texte |
|
| 23 | - * texte à analyser pour la collecte |
|
| 24 | - * @param string $if_chars |
|
| 25 | - * caractere(s) à tester avant de tenter la preg |
|
| 26 | - * @param string $start_with |
|
| 27 | - * caractere(s) par lesquels commencent l'expression recherchée (permet de démarrer la preg à la prochaine occurence de cette chaine) |
|
| 28 | - * @param string $preg |
|
| 29 | - * preg utilisée pour la collecte |
|
| 30 | - * @param int $max_items |
|
| 31 | - * pour limiter le nombre de preg collectée (pour la detection simple de présence par exemple) |
|
| 32 | - * @return array |
|
| 33 | - */ |
|
| 34 | - protected static function collecteur(string $texte, string $if_chars, string $start_with, string $preg, int $max_items = 0): array { |
|
| 35 | - |
|
| 36 | - $collection = []; |
|
| 37 | - $pos = 0; |
|
| 38 | - while ( |
|
| 39 | - (!$if_chars || strpos($texte, $if_chars, $pos) !== false) |
|
| 40 | - and ($next = ($start_with ? strpos($texte, $start_with, $pos) : $pos)) !== false |
|
| 41 | - and preg_match($preg, $texte, $r, PREG_OFFSET_CAPTURE, $next)) { |
|
| 42 | - |
|
| 43 | - $found_pos = $r[0][1]; |
|
| 44 | - $found_length = strlen($r[0][0]); |
|
| 45 | - $match = [ |
|
| 46 | - 'raw' => $r[0][0], |
|
| 47 | - 'match' => array_column($r, 0), |
|
| 48 | - 'pos' => $found_pos, |
|
| 49 | - 'length' => $found_length |
|
| 50 | - ]; |
|
| 51 | - |
|
| 52 | - $collection[] = $match; |
|
| 53 | - |
|
| 54 | - if ($max_items and count($collection) === $max_items) { |
|
| 55 | - break; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - $pos = $match['pos'] + $match['length']; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return $collection; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Sanitizer une collection d'occurences |
|
| 66 | - * |
|
| 67 | - * @param array $collection |
|
| 68 | - * @param string $sanitize_callback |
|
| 69 | - * @return array |
|
| 70 | - */ |
|
| 71 | - protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 72 | - foreach ($collection as &$c) { |
|
| 73 | - $c['raw'] = $sanitize_callback($c['raw']); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - return $collection; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param string $texte |
|
| 81 | - * @param array $options |
|
| 82 | - * @return array |
|
| 83 | - */ |
|
| 84 | - public function collecter(string $texte, array $options = []): array { |
|
| 85 | - $collection = []; |
|
| 86 | - return $collection; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function detecter($texte): bool { |
|
| 90 | - if (!empty($this->markId) and strpos($texte, $this->markId) !== false) { |
|
| 91 | - return true; |
|
| 92 | - } |
|
| 93 | - return !empty($this->collecter($texte, ['detecter_presence' => true])); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Echapper les occurences de la collecte par un texte neutre du point de vue HTML |
|
| 98 | - * |
|
| 99 | - * @see retablir() |
|
| 100 | - * @param string $texte |
|
| 101 | - * @param array $options |
|
| 102 | - * string $sanitize_callback |
|
| 103 | - * @return array |
|
| 104 | - * texte, marqueur utilise pour echapper les modeles |
|
| 105 | - */ |
|
| 106 | - public function echapper(string $texte, array $options = []): string { |
|
| 107 | - if (!function_exists('creer_uniqid')) { |
|
| 108 | - include_spip('inc/acces'); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $collection = $this->collecter($texte, $options); |
|
| 112 | - if (!empty($options['sanitize_callback']) and is_callable($options['sanitize_callback'])) { |
|
| 113 | - $collection = $this->sanitizer_collection($collection, $options['sanitize_callback']); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - if (!empty($collection)) { |
|
| 117 | - if (empty($this->markId)) { |
|
| 118 | - // generer un marqueur qui n'existe pas dans le texte |
|
| 119 | - do { |
|
| 120 | - $this->markId = substr(md5(uniqid(static::class, 1)), 0, 7); |
|
| 121 | - $this->markId = "@|".static::$markPrefix . $this->markId . "|"; |
|
| 122 | - } while (strpos($texte, $this->markId) !== false); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $offset_pos = 0; |
|
| 126 | - foreach ($collection as $c) { |
|
| 127 | - $rempl = $this->markId . base64_encode($c['raw']) . '|@'; |
|
| 128 | - $texte = substr_replace($texte, $rempl, $c['pos'] + $offset_pos, $c['length']); |
|
| 129 | - $offset_pos += strlen($rempl) - $c['length']; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - return $texte; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Retablir les occurences échappées précédemment |
|
| 139 | - * |
|
| 140 | - * @see echapper() |
|
| 141 | - * @param string $texte |
|
| 142 | - * @return string |
|
| 143 | - */ |
|
| 144 | - function retablir(string $texte): string { |
|
| 145 | - |
|
| 146 | - if (!empty($this->markId)) { |
|
| 147 | - $lm = strlen($this->markId); |
|
| 148 | - $pos = 0; |
|
| 149 | - while ( |
|
| 150 | - ($p = strpos($texte, $this->markId, $pos)) !== false |
|
| 151 | - and $end = strpos($texte, '|@', $p + $lm) |
|
| 152 | - ) { |
|
| 153 | - $base64 = substr($texte, $p + $lm, $end - ($p + $lm)); |
|
| 154 | - if ($c = base64_decode($base64, true)) { |
|
| 155 | - $texte = substr_replace($texte, $c, $p, $end + 2 - $p); |
|
| 156 | - $pos = $p + strlen($c); |
|
| 157 | - } |
|
| 158 | - else { |
|
| 159 | - $pos = $end; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $texte; |
|
| 165 | - } |
|
| 17 | + protected static string $markPrefix = 'COLLECT'; |
|
| 18 | + protected string $markId; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Collecteur générique des occurences d'une preg dans un texte avec leurs positions et longueur |
|
| 22 | + * @param string $texte |
|
| 23 | + * texte à analyser pour la collecte |
|
| 24 | + * @param string $if_chars |
|
| 25 | + * caractere(s) à tester avant de tenter la preg |
|
| 26 | + * @param string $start_with |
|
| 27 | + * caractere(s) par lesquels commencent l'expression recherchée (permet de démarrer la preg à la prochaine occurence de cette chaine) |
|
| 28 | + * @param string $preg |
|
| 29 | + * preg utilisée pour la collecte |
|
| 30 | + * @param int $max_items |
|
| 31 | + * pour limiter le nombre de preg collectée (pour la detection simple de présence par exemple) |
|
| 32 | + * @return array |
|
| 33 | + */ |
|
| 34 | + protected static function collecteur(string $texte, string $if_chars, string $start_with, string $preg, int $max_items = 0): array { |
|
| 35 | + |
|
| 36 | + $collection = []; |
|
| 37 | + $pos = 0; |
|
| 38 | + while ( |
|
| 39 | + (!$if_chars || strpos($texte, $if_chars, $pos) !== false) |
|
| 40 | + and ($next = ($start_with ? strpos($texte, $start_with, $pos) : $pos)) !== false |
|
| 41 | + and preg_match($preg, $texte, $r, PREG_OFFSET_CAPTURE, $next)) { |
|
| 42 | + |
|
| 43 | + $found_pos = $r[0][1]; |
|
| 44 | + $found_length = strlen($r[0][0]); |
|
| 45 | + $match = [ |
|
| 46 | + 'raw' => $r[0][0], |
|
| 47 | + 'match' => array_column($r, 0), |
|
| 48 | + 'pos' => $found_pos, |
|
| 49 | + 'length' => $found_length |
|
| 50 | + ]; |
|
| 51 | + |
|
| 52 | + $collection[] = $match; |
|
| 53 | + |
|
| 54 | + if ($max_items and count($collection) === $max_items) { |
|
| 55 | + break; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + $pos = $match['pos'] + $match['length']; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + return $collection; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Sanitizer une collection d'occurences |
|
| 66 | + * |
|
| 67 | + * @param array $collection |
|
| 68 | + * @param string $sanitize_callback |
|
| 69 | + * @return array |
|
| 70 | + */ |
|
| 71 | + protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 72 | + foreach ($collection as &$c) { |
|
| 73 | + $c['raw'] = $sanitize_callback($c['raw']); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + return $collection; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param string $texte |
|
| 81 | + * @param array $options |
|
| 82 | + * @return array |
|
| 83 | + */ |
|
| 84 | + public function collecter(string $texte, array $options = []): array { |
|
| 85 | + $collection = []; |
|
| 86 | + return $collection; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function detecter($texte): bool { |
|
| 90 | + if (!empty($this->markId) and strpos($texte, $this->markId) !== false) { |
|
| 91 | + return true; |
|
| 92 | + } |
|
| 93 | + return !empty($this->collecter($texte, ['detecter_presence' => true])); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Echapper les occurences de la collecte par un texte neutre du point de vue HTML |
|
| 98 | + * |
|
| 99 | + * @see retablir() |
|
| 100 | + * @param string $texte |
|
| 101 | + * @param array $options |
|
| 102 | + * string $sanitize_callback |
|
| 103 | + * @return array |
|
| 104 | + * texte, marqueur utilise pour echapper les modeles |
|
| 105 | + */ |
|
| 106 | + public function echapper(string $texte, array $options = []): string { |
|
| 107 | + if (!function_exists('creer_uniqid')) { |
|
| 108 | + include_spip('inc/acces'); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $collection = $this->collecter($texte, $options); |
|
| 112 | + if (!empty($options['sanitize_callback']) and is_callable($options['sanitize_callback'])) { |
|
| 113 | + $collection = $this->sanitizer_collection($collection, $options['sanitize_callback']); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + if (!empty($collection)) { |
|
| 117 | + if (empty($this->markId)) { |
|
| 118 | + // generer un marqueur qui n'existe pas dans le texte |
|
| 119 | + do { |
|
| 120 | + $this->markId = substr(md5(uniqid(static::class, 1)), 0, 7); |
|
| 121 | + $this->markId = "@|".static::$markPrefix . $this->markId . "|"; |
|
| 122 | + } while (strpos($texte, $this->markId) !== false); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $offset_pos = 0; |
|
| 126 | + foreach ($collection as $c) { |
|
| 127 | + $rempl = $this->markId . base64_encode($c['raw']) . '|@'; |
|
| 128 | + $texte = substr_replace($texte, $rempl, $c['pos'] + $offset_pos, $c['length']); |
|
| 129 | + $offset_pos += strlen($rempl) - $c['length']; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + return $texte; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Retablir les occurences échappées précédemment |
|
| 139 | + * |
|
| 140 | + * @see echapper() |
|
| 141 | + * @param string $texte |
|
| 142 | + * @return string |
|
| 143 | + */ |
|
| 144 | + function retablir(string $texte): string { |
|
| 145 | + |
|
| 146 | + if (!empty($this->markId)) { |
|
| 147 | + $lm = strlen($this->markId); |
|
| 148 | + $pos = 0; |
|
| 149 | + while ( |
|
| 150 | + ($p = strpos($texte, $this->markId, $pos)) !== false |
|
| 151 | + and $end = strpos($texte, '|@', $p + $lm) |
|
| 152 | + ) { |
|
| 153 | + $base64 = substr($texte, $p + $lm, $end - ($p + $lm)); |
|
| 154 | + if ($c = base64_decode($base64, true)) { |
|
| 155 | + $texte = substr_replace($texte, $c, $p, $end + 2 - $p); |
|
| 156 | + $pos = $p + strlen($c); |
|
| 157 | + } |
|
| 158 | + else { |
|
| 159 | + $pos = $end; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $texte; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | 167 | } |
@@ -118,13 +118,13 @@ |
||
| 118 | 118 | // generer un marqueur qui n'existe pas dans le texte |
| 119 | 119 | do { |
| 120 | 120 | $this->markId = substr(md5(uniqid(static::class, 1)), 0, 7); |
| 121 | - $this->markId = "@|".static::$markPrefix . $this->markId . "|"; |
|
| 121 | + $this->markId = "@|".static::$markPrefix.$this->markId."|"; |
|
| 122 | 122 | } while (strpos($texte, $this->markId) !== false); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $offset_pos = 0; |
| 126 | 126 | foreach ($collection as $c) { |
| 127 | - $rempl = $this->markId . base64_encode($c['raw']) . '|@'; |
|
| 127 | + $rempl = $this->markId.base64_encode($c['raw']).'|@'; |
|
| 128 | 128 | $texte = substr_replace($texte, $rempl, $c['pos'] + $offset_pos, $c['length']); |
| 129 | 129 | $offset_pos += strlen($rempl) - $c['length']; |
| 130 | 130 | } |
@@ -154,8 +154,7 @@ |
||
| 154 | 154 | if ($c = base64_decode($base64, true)) { |
| 155 | 155 | $texte = substr_replace($texte, $c, $p, $end + 2 - $p); |
| 156 | 156 | $pos = $p + strlen($c); |
| 157 | - } |
|
| 158 | - else { |
|
| 157 | + } else { |
|
| 159 | 158 | $pos = $end; |
| 160 | 159 | } |
| 161 | 160 | } |
@@ -23,115 +23,115 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class Idiomes extends AbstractCollecteur { |
| 25 | 25 | |
| 26 | - protected static string $markPrefix = 'IDIOME'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * La preg pour découper et collecter les modèles |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 32 | - protected string $preg_idiome; |
|
| 33 | - |
|
| 34 | - public function __construct(?string $preg = null) { |
|
| 35 | - |
|
| 36 | - $this->preg_idiome = ($preg ?: '@<:(?:([a-z0-9_]+):)?([a-z0-9_]+):>@isS'); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Sanitizer une collection d'occurences d'idiomes : on ne fait rien |
|
| 41 | - * |
|
| 42 | - * @param array $collection |
|
| 43 | - * @param string $sanitize_callback |
|
| 44 | - * @return array |
|
| 45 | - */ |
|
| 46 | - protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 47 | - |
|
| 48 | - return $collection; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param string $texte |
|
| 54 | - * @param array $options |
|
| 55 | - * bool $collecter_liens |
|
| 56 | - * @return array |
|
| 57 | - */ |
|
| 58 | - public function collecter(string $texte, array $options = []): array { |
|
| 59 | - if (!$texte) { |
|
| 60 | - return []; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // collecter les matchs de la preg |
|
| 64 | - $idiomes = $this->collecteur($texte, '', '<:', $this->preg_idiome, empty($options['detecter_presence']) ? 0 : 1); |
|
| 65 | - |
|
| 66 | - // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 67 | - if (empty($options['detecter_presence'])) { |
|
| 68 | - |
|
| 69 | - $pos_prev = 0; |
|
| 70 | - foreach ($idiomes as $k => &$idiome) { |
|
| 71 | - |
|
| 72 | - $idiome['module'] = $idiome['match'][1]; |
|
| 73 | - $idiome['chaine'] = $idiome['match'][2]; |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - return $idiomes; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Traiter les idiomes d'un texte |
|
| 82 | - * |
|
| 83 | - * @uses inc_traduire_dist() |
|
| 84 | - * @uses code_echappement() |
|
| 85 | - * @uses echappe_retour() |
|
| 86 | - * |
|
| 87 | - * @param string $texte |
|
| 88 | - * @param array $options |
|
| 89 | - * ?string $lang |
|
| 90 | - * ?bool echappe_span |
|
| 91 | - * @return string |
|
| 92 | - */ |
|
| 93 | - public function traiter(string $texte, array $options) { |
|
| 94 | - static $traduire; |
|
| 95 | - if ($texte) { |
|
| 96 | - |
|
| 97 | - $idiomes = $this->collecter($texte); |
|
| 98 | - if (!empty($idiomes)) { |
|
| 99 | - $lang = $options['lang'] ?? $GLOBALS['spip_lang']; |
|
| 100 | - $echappe_span = $options['echappe_span'] ?? false; |
|
| 101 | - |
|
| 102 | - if (is_null($traduire)) { |
|
| 103 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 104 | - include_spip('inc/lang'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $offset_pos = 0; |
|
| 108 | - foreach ($idiomes as $idiome) { |
|
| 109 | - |
|
| 110 | - $cle = ($idiome['module'] ? $idiome['module'] . ':' : '') . $idiome['chaine']; |
|
| 111 | - $desc = $traduire($cle, $lang, true); |
|
| 112 | - $l = $desc->langue; |
|
| 113 | - |
|
| 114 | - // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 115 | - if (strlen($desc->texte ?? '')) { |
|
| 116 | - $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 117 | - if ($l !== $lang) { |
|
| 118 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 119 | - } |
|
| 120 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 121 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 122 | - } |
|
| 123 | - if (!$echappe_span) { |
|
| 124 | - $trad = echappe_retour($trad, 'idiome'); |
|
| 125 | - } |
|
| 126 | - $texte = substr_replace($texte, $trad, $idiome['pos'] + $offset_pos, $idiome['length']); |
|
| 127 | - $offset_pos += strlen($trad) - $idiome['length']; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return $texte; |
|
| 135 | - } |
|
| 26 | + protected static string $markPrefix = 'IDIOME'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * La preg pour découper et collecter les modèles |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | + protected string $preg_idiome; |
|
| 33 | + |
|
| 34 | + public function __construct(?string $preg = null) { |
|
| 35 | + |
|
| 36 | + $this->preg_idiome = ($preg ?: '@<:(?:([a-z0-9_]+):)?([a-z0-9_]+):>@isS'); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Sanitizer une collection d'occurences d'idiomes : on ne fait rien |
|
| 41 | + * |
|
| 42 | + * @param array $collection |
|
| 43 | + * @param string $sanitize_callback |
|
| 44 | + * @return array |
|
| 45 | + */ |
|
| 46 | + protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 47 | + |
|
| 48 | + return $collection; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param string $texte |
|
| 54 | + * @param array $options |
|
| 55 | + * bool $collecter_liens |
|
| 56 | + * @return array |
|
| 57 | + */ |
|
| 58 | + public function collecter(string $texte, array $options = []): array { |
|
| 59 | + if (!$texte) { |
|
| 60 | + return []; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // collecter les matchs de la preg |
|
| 64 | + $idiomes = $this->collecteur($texte, '', '<:', $this->preg_idiome, empty($options['detecter_presence']) ? 0 : 1); |
|
| 65 | + |
|
| 66 | + // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 67 | + if (empty($options['detecter_presence'])) { |
|
| 68 | + |
|
| 69 | + $pos_prev = 0; |
|
| 70 | + foreach ($idiomes as $k => &$idiome) { |
|
| 71 | + |
|
| 72 | + $idiome['module'] = $idiome['match'][1]; |
|
| 73 | + $idiome['chaine'] = $idiome['match'][2]; |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + return $idiomes; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Traiter les idiomes d'un texte |
|
| 82 | + * |
|
| 83 | + * @uses inc_traduire_dist() |
|
| 84 | + * @uses code_echappement() |
|
| 85 | + * @uses echappe_retour() |
|
| 86 | + * |
|
| 87 | + * @param string $texte |
|
| 88 | + * @param array $options |
|
| 89 | + * ?string $lang |
|
| 90 | + * ?bool echappe_span |
|
| 91 | + * @return string |
|
| 92 | + */ |
|
| 93 | + public function traiter(string $texte, array $options) { |
|
| 94 | + static $traduire; |
|
| 95 | + if ($texte) { |
|
| 96 | + |
|
| 97 | + $idiomes = $this->collecter($texte); |
|
| 98 | + if (!empty($idiomes)) { |
|
| 99 | + $lang = $options['lang'] ?? $GLOBALS['spip_lang']; |
|
| 100 | + $echappe_span = $options['echappe_span'] ?? false; |
|
| 101 | + |
|
| 102 | + if (is_null($traduire)) { |
|
| 103 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 104 | + include_spip('inc/lang'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $offset_pos = 0; |
|
| 108 | + foreach ($idiomes as $idiome) { |
|
| 109 | + |
|
| 110 | + $cle = ($idiome['module'] ? $idiome['module'] . ':' : '') . $idiome['chaine']; |
|
| 111 | + $desc = $traduire($cle, $lang, true); |
|
| 112 | + $l = $desc->langue; |
|
| 113 | + |
|
| 114 | + // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 115 | + if (strlen($desc->texte ?? '')) { |
|
| 116 | + $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 117 | + if ($l !== $lang) { |
|
| 118 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 119 | + } |
|
| 120 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 121 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 122 | + } |
|
| 123 | + if (!$echappe_span) { |
|
| 124 | + $trad = echappe_retour($trad, 'idiome'); |
|
| 125 | + } |
|
| 126 | + $texte = substr_replace($texte, $trad, $idiome['pos'] + $offset_pos, $idiome['length']); |
|
| 127 | + $offset_pos += strlen($trad) - $idiome['length']; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return $texte; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | 137 | } |
@@ -107,7 +107,7 @@ |
||
| 107 | 107 | $offset_pos = 0; |
| 108 | 108 | foreach ($idiomes as $idiome) { |
| 109 | 109 | |
| 110 | - $cle = ($idiome['module'] ? $idiome['module'] . ':' : '') . $idiome['chaine']; |
|
| 110 | + $cle = ($idiome['module'] ? $idiome['module'].':' : '').$idiome['chaine']; |
|
| 111 | 111 | $desc = $traduire($cle, $lang, true); |
| 112 | 112 | $l = $desc->langue; |
| 113 | 113 | |
@@ -22,202 +22,202 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class Modeles extends AbstractCollecteur { |
| 24 | 24 | |
| 25 | - protected static string $markPrefix = 'MODELE'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * La preg pour découper et collecter les modèles |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - protected string $preg_modele; |
|
| 32 | - |
|
| 33 | - public function __construct(?string $preg = null) { |
|
| 34 | - |
|
| 35 | - $this->preg_modele = ($preg ?: |
|
| 36 | - '@<([a-z_-]{3,})' # <modele |
|
| 37 | - . '\s*([0-9]*)\s*' # id |
|
| 38 | - . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 39 | - . '\s*/?' . '>@isS' # fin du modele > |
|
| 40 | - ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Sanitizer une collection d'occurences de modèle : on ne fait rien |
|
| 45 | - * |
|
| 46 | - * @param array $collection |
|
| 47 | - * @param string $sanitize_callback |
|
| 48 | - * @return array |
|
| 49 | - */ |
|
| 50 | - protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 51 | - |
|
| 52 | - return $collection; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param string $texte |
|
| 57 | - * @param array $options |
|
| 58 | - * bool $collecter_liens |
|
| 59 | - * @return array |
|
| 60 | - */ |
|
| 61 | - public function collecter(string $texte, array $options = []): array { |
|
| 62 | - if (!$texte) { |
|
| 63 | - return []; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // collecter les matchs de la preg |
|
| 67 | - $modeles = $this->collecteur($texte, '', '<', $this->preg_modele); |
|
| 68 | - |
|
| 69 | - $pos_prev = 0; |
|
| 70 | - foreach ($modeles as $k => &$modele) { |
|
| 71 | - $pos = $modele['pos']; |
|
| 72 | - $modele['type'] = $modele['match'][1]; |
|
| 73 | - $modele['id'] = $modele['match'][2] ?? ''; |
|
| 74 | - $modele['params'] = $modele['match'][3] ?? ''; |
|
| 75 | - |
|
| 76 | - $longueur = $modele['length']; |
|
| 77 | - $end = $pos + $longueur; |
|
| 78 | - |
|
| 79 | - // il faut avoir un id ou des params commençant par un | sinon c'est une simple balise html |
|
| 80 | - if (empty($modele['id']) and empty($modele['params'])) { |
|
| 81 | - unset($modeles[$k]); |
|
| 82 | - continue; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 86 | - if (!empty($options['detecter_presence'])) { |
|
| 87 | - break; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $modele['lien'] = false; |
|
| 91 | - if (!empty($options['collecter_liens']) |
|
| 92 | - and $pos_fermeture_lien = stripos($texte, '</a>', $end) |
|
| 93 | - and !strlen(trim(substr($texte, $end, $pos_fermeture_lien - $end)))) { |
|
| 94 | - |
|
| 95 | - $pos_lien_ouvrant = stripos($texte, '<a', $pos_prev); |
|
| 96 | - if ($pos_lien_ouvrant !== false |
|
| 97 | - and $pos_lien_ouvrant < $pos |
|
| 98 | - and preg_match('/<a\s[^<>]*>\s*$/i', substr($texte, $pos_prev, $pos - $pos_prev), $r) |
|
| 99 | - ) { |
|
| 100 | - $modele['lien'] = [ |
|
| 101 | - 'href' => extraire_attribut($r[0], 'href'), |
|
| 102 | - 'class' => extraire_attribut($r[0], 'class'), |
|
| 103 | - 'mime' => extraire_attribut($r[0], 'type'), |
|
| 104 | - 'title' => extraire_attribut($r[0], 'title'), |
|
| 105 | - 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 106 | - ]; |
|
| 107 | - $n = strlen($r[0]); |
|
| 108 | - $pos -= $n; |
|
| 109 | - $longueur = $pos_fermeture_lien - $pos + 4; |
|
| 110 | - $end = $pos + $longueur; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - $modele['pos'] = $pos; |
|
| 116 | - $modele['length'] = $longueur; |
|
| 117 | - $pos_prev = $end; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $modeles; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Traiter les modeles d'un texte |
|
| 125 | - * @param string $texte |
|
| 126 | - * @param array $options |
|
| 127 | - * bool|array $doublons |
|
| 128 | - * string $echap |
|
| 129 | - * ?Spip\Texte\CollecteurLiens $collecteurLiens |
|
| 130 | - * ?array $env |
|
| 131 | - * ?string $connect |
|
| 132 | - * @return string |
|
| 133 | - */ |
|
| 134 | - public function traiter(string $texte, array $options) { |
|
| 135 | - if ($texte) { |
|
| 136 | - $doublons = $options['doublons'] ?? false; |
|
| 137 | - $echap = $options['echap'] ?? ''; |
|
| 138 | - $collecteurLiens = $options['collecteurLiens'] ?? null; |
|
| 139 | - $env = $options['env'] ?? []; |
|
| 140 | - $connect = $options['connect'] ?? ''; |
|
| 141 | - |
|
| 142 | - // preserver la compatibilite : true = recherche des documents |
|
| 143 | - if ($doublons === true) { |
|
| 144 | - $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $modeles = $this->collecter($texte, ['collecter_liens' => true]); |
|
| 148 | - if (!empty($modeles)) { |
|
| 149 | - include_spip('public/assembler'); |
|
| 150 | - $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 151 | - |
|
| 152 | - $offset_pos = 0; |
|
| 153 | - foreach ($modeles as $m) { |
|
| 154 | - // calculer le modele |
|
| 155 | - # hack indexation |
|
| 156 | - if ($doublons) { |
|
| 157 | - $texte .= preg_replace(',[|][^|=]*,s', ' ', $m['params']); |
|
| 158 | - } # version normale |
|
| 159 | - else { |
|
| 160 | - // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 161 | - // dans les parametres, plutot que les liens echappes |
|
| 162 | - $params = $m['params']; |
|
| 163 | - if (!is_null($collecteurLiens)) { |
|
| 164 | - $params = $collecteurLiens->retablir($params); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - $modele = inclure_modele($m['type'], $m['id'], $params, $m['lien'], $connect ?? '', $env); |
|
| 168 | - |
|
| 169 | - // en cas d'echec, |
|
| 170 | - // si l'objet demande a une url, |
|
| 171 | - // creer un petit encadre vers elle |
|
| 172 | - if ($modele === false) { |
|
| 173 | - $modele = $m['raw']; |
|
| 174 | - |
|
| 175 | - if (!is_null($collecteurLiens)) { |
|
| 176 | - $modele = $collecteurLiens->retablir($modele); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $contexte = array_merge($env, ['id' => $m['id'], 'type' => $m['type'], 'modele' => $modele]); |
|
| 180 | - |
|
| 181 | - if (!empty($m['lien'])) { |
|
| 182 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 183 | - $contexte['lien'] = str_replace('"', '"', $m['lien']['href']); |
|
| 184 | - $contexte['lien_class'] = $m['lien']['class']; |
|
| 185 | - $contexte['lien_mime'] = $m['lien']['mime']; |
|
| 186 | - $contexte['lien_title'] = $m['lien']['title']; |
|
| 187 | - $contexte['lien_hreflang'] = $m['lien']['hreflang']; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $modele = recuperer_fond('modeles/dist', $contexte, [], $connect ?? ''); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // le remplacer dans le texte |
|
| 194 | - if ($modele !== false) { |
|
| 195 | - $modele = protege_js_modeles($modele); |
|
| 196 | - |
|
| 197 | - if ($wrap_embed_html) { |
|
| 198 | - $modele = $wrap_embed_html($m['raw'], $modele); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - $rempl = code_echappement($modele, $echap); |
|
| 202 | - $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
|
| 203 | - $offset_pos += strlen($rempl) - $m['length']; |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - // hack pour tout l'espace prive |
|
| 208 | - if ((test_espace_prive() or ($doublons)) and !empty($m['id'])) { |
|
| 209 | - $type = strtolower($m['type']); |
|
| 210 | - foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $type_modeles) { |
|
| 211 | - if (in_array($type, $type_modeles)) { |
|
| 212 | - $GLOBALS["doublons_{$quoi}_inclus"][] = $m['id']; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return $texte; |
|
| 221 | - } |
|
| 25 | + protected static string $markPrefix = 'MODELE'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * La preg pour découper et collecter les modèles |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + protected string $preg_modele; |
|
| 32 | + |
|
| 33 | + public function __construct(?string $preg = null) { |
|
| 34 | + |
|
| 35 | + $this->preg_modele = ($preg ?: |
|
| 36 | + '@<([a-z_-]{3,})' # <modele |
|
| 37 | + . '\s*([0-9]*)\s*' # id |
|
| 38 | + . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 39 | + . '\s*/?' . '>@isS' # fin du modele > |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Sanitizer une collection d'occurences de modèle : on ne fait rien |
|
| 45 | + * |
|
| 46 | + * @param array $collection |
|
| 47 | + * @param string $sanitize_callback |
|
| 48 | + * @return array |
|
| 49 | + */ |
|
| 50 | + protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 51 | + |
|
| 52 | + return $collection; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param string $texte |
|
| 57 | + * @param array $options |
|
| 58 | + * bool $collecter_liens |
|
| 59 | + * @return array |
|
| 60 | + */ |
|
| 61 | + public function collecter(string $texte, array $options = []): array { |
|
| 62 | + if (!$texte) { |
|
| 63 | + return []; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // collecter les matchs de la preg |
|
| 67 | + $modeles = $this->collecteur($texte, '', '<', $this->preg_modele); |
|
| 68 | + |
|
| 69 | + $pos_prev = 0; |
|
| 70 | + foreach ($modeles as $k => &$modele) { |
|
| 71 | + $pos = $modele['pos']; |
|
| 72 | + $modele['type'] = $modele['match'][1]; |
|
| 73 | + $modele['id'] = $modele['match'][2] ?? ''; |
|
| 74 | + $modele['params'] = $modele['match'][3] ?? ''; |
|
| 75 | + |
|
| 76 | + $longueur = $modele['length']; |
|
| 77 | + $end = $pos + $longueur; |
|
| 78 | + |
|
| 79 | + // il faut avoir un id ou des params commençant par un | sinon c'est une simple balise html |
|
| 80 | + if (empty($modele['id']) and empty($modele['params'])) { |
|
| 81 | + unset($modeles[$k]); |
|
| 82 | + continue; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 86 | + if (!empty($options['detecter_presence'])) { |
|
| 87 | + break; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $modele['lien'] = false; |
|
| 91 | + if (!empty($options['collecter_liens']) |
|
| 92 | + and $pos_fermeture_lien = stripos($texte, '</a>', $end) |
|
| 93 | + and !strlen(trim(substr($texte, $end, $pos_fermeture_lien - $end)))) { |
|
| 94 | + |
|
| 95 | + $pos_lien_ouvrant = stripos($texte, '<a', $pos_prev); |
|
| 96 | + if ($pos_lien_ouvrant !== false |
|
| 97 | + and $pos_lien_ouvrant < $pos |
|
| 98 | + and preg_match('/<a\s[^<>]*>\s*$/i', substr($texte, $pos_prev, $pos - $pos_prev), $r) |
|
| 99 | + ) { |
|
| 100 | + $modele['lien'] = [ |
|
| 101 | + 'href' => extraire_attribut($r[0], 'href'), |
|
| 102 | + 'class' => extraire_attribut($r[0], 'class'), |
|
| 103 | + 'mime' => extraire_attribut($r[0], 'type'), |
|
| 104 | + 'title' => extraire_attribut($r[0], 'title'), |
|
| 105 | + 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 106 | + ]; |
|
| 107 | + $n = strlen($r[0]); |
|
| 108 | + $pos -= $n; |
|
| 109 | + $longueur = $pos_fermeture_lien - $pos + 4; |
|
| 110 | + $end = $pos + $longueur; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + $modele['pos'] = $pos; |
|
| 116 | + $modele['length'] = $longueur; |
|
| 117 | + $pos_prev = $end; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $modeles; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Traiter les modeles d'un texte |
|
| 125 | + * @param string $texte |
|
| 126 | + * @param array $options |
|
| 127 | + * bool|array $doublons |
|
| 128 | + * string $echap |
|
| 129 | + * ?Spip\Texte\CollecteurLiens $collecteurLiens |
|
| 130 | + * ?array $env |
|
| 131 | + * ?string $connect |
|
| 132 | + * @return string |
|
| 133 | + */ |
|
| 134 | + public function traiter(string $texte, array $options) { |
|
| 135 | + if ($texte) { |
|
| 136 | + $doublons = $options['doublons'] ?? false; |
|
| 137 | + $echap = $options['echap'] ?? ''; |
|
| 138 | + $collecteurLiens = $options['collecteurLiens'] ?? null; |
|
| 139 | + $env = $options['env'] ?? []; |
|
| 140 | + $connect = $options['connect'] ?? ''; |
|
| 141 | + |
|
| 142 | + // preserver la compatibilite : true = recherche des documents |
|
| 143 | + if ($doublons === true) { |
|
| 144 | + $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $modeles = $this->collecter($texte, ['collecter_liens' => true]); |
|
| 148 | + if (!empty($modeles)) { |
|
| 149 | + include_spip('public/assembler'); |
|
| 150 | + $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 151 | + |
|
| 152 | + $offset_pos = 0; |
|
| 153 | + foreach ($modeles as $m) { |
|
| 154 | + // calculer le modele |
|
| 155 | + # hack indexation |
|
| 156 | + if ($doublons) { |
|
| 157 | + $texte .= preg_replace(',[|][^|=]*,s', ' ', $m['params']); |
|
| 158 | + } # version normale |
|
| 159 | + else { |
|
| 160 | + // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 161 | + // dans les parametres, plutot que les liens echappes |
|
| 162 | + $params = $m['params']; |
|
| 163 | + if (!is_null($collecteurLiens)) { |
|
| 164 | + $params = $collecteurLiens->retablir($params); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + $modele = inclure_modele($m['type'], $m['id'], $params, $m['lien'], $connect ?? '', $env); |
|
| 168 | + |
|
| 169 | + // en cas d'echec, |
|
| 170 | + // si l'objet demande a une url, |
|
| 171 | + // creer un petit encadre vers elle |
|
| 172 | + if ($modele === false) { |
|
| 173 | + $modele = $m['raw']; |
|
| 174 | + |
|
| 175 | + if (!is_null($collecteurLiens)) { |
|
| 176 | + $modele = $collecteurLiens->retablir($modele); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $contexte = array_merge($env, ['id' => $m['id'], 'type' => $m['type'], 'modele' => $modele]); |
|
| 180 | + |
|
| 181 | + if (!empty($m['lien'])) { |
|
| 182 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 183 | + $contexte['lien'] = str_replace('"', '"', $m['lien']['href']); |
|
| 184 | + $contexte['lien_class'] = $m['lien']['class']; |
|
| 185 | + $contexte['lien_mime'] = $m['lien']['mime']; |
|
| 186 | + $contexte['lien_title'] = $m['lien']['title']; |
|
| 187 | + $contexte['lien_hreflang'] = $m['lien']['hreflang']; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $modele = recuperer_fond('modeles/dist', $contexte, [], $connect ?? ''); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // le remplacer dans le texte |
|
| 194 | + if ($modele !== false) { |
|
| 195 | + $modele = protege_js_modeles($modele); |
|
| 196 | + |
|
| 197 | + if ($wrap_embed_html) { |
|
| 198 | + $modele = $wrap_embed_html($m['raw'], $modele); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + $rempl = code_echappement($modele, $echap); |
|
| 202 | + $texte = substr_replace($texte, $rempl, $m['pos'] + $offset_pos, $m['length']); |
|
| 203 | + $offset_pos += strlen($rempl) - $m['length']; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + // hack pour tout l'espace prive |
|
| 208 | + if ((test_espace_prive() or ($doublons)) and !empty($m['id'])) { |
|
| 209 | + $type = strtolower($m['type']); |
|
| 210 | + foreach ($doublons ?: ['documents' => ['doc', 'emb', 'img']] as $quoi => $type_modeles) { |
|
| 211 | + if (in_array($type, $type_modeles)) { |
|
| 212 | + $GLOBALS["doublons_{$quoi}_inclus"][] = $m['id']; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return $texte; |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | 223 | } |
@@ -32,11 +32,10 @@ |
||
| 32 | 32 | |
| 33 | 33 | public function __construct(?string $preg = null) { |
| 34 | 34 | |
| 35 | - $this->preg_modele = ($preg ?: |
|
| 36 | - '@<([a-z_-]{3,})' # <modele |
|
| 35 | + $this->preg_modele = ($preg ?: '@<([a-z_-]{3,})' # <modele |
|
| 37 | 36 | . '\s*([0-9]*)\s*' # id |
| 38 | 37 | . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
| 39 | - . '\s*/?' . '>@isS' # fin du modele > |
|
| 38 | + . '\s*/?'.'>@isS' # fin du modele > |
|
| 40 | 39 | ); |
| 41 | 40 | } |
| 42 | 41 | |
@@ -17,103 +17,103 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Liens extends AbstractCollecteur { |
| 19 | 19 | |
| 20 | - protected static string $markPrefix = 'LIEN'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * La preg pour découper et collecter les modèles |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - protected string $preg_lien; |
|
| 27 | - |
|
| 28 | - public function __construct(?string $preg = null) { |
|
| 29 | - |
|
| 30 | - // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip |
|
| 31 | - // Laisser passer des paires de crochets pour la balise multi |
|
| 32 | - // mais refuser plus d'imbrications ou de mauvaises imbrications |
|
| 33 | - // sinon les crochets ne peuvent plus servir qu'a ce type de raccourci |
|
| 34 | - $this->preg_lien = ($preg ?: '/\[([^][]*?([[][^]>-]*[]][^][]*)*)->(>?)([^]]*)\]/msS'); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Sanitizer une collection d'occurences de liens : il faut sanitizer le href et le texte uniquement |
|
| 40 | - * |
|
| 41 | - * @param array $collection |
|
| 42 | - * @param string $sanitize_callback |
|
| 43 | - * @return array |
|
| 44 | - */ |
|
| 45 | - protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 46 | - foreach ($collection as &$lien) { |
|
| 47 | - $t = $sanitize_callback($lien['texte']); |
|
| 48 | - if ($t !== $lien['texte']) { |
|
| 49 | - $lien['raw'] = str_replace($lien['texte'], $t, $lien['raw']); |
|
| 50 | - $lien['texte'] = $t; |
|
| 51 | - } |
|
| 52 | - $href = $sanitize_callback($lien['href']); |
|
| 53 | - if ($href !== $lien['href']) { |
|
| 54 | - $lien['raw'] = str_replace($lien['href'], $href, $lien['raw']); |
|
| 55 | - $lien['href'] = $href; |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - return $collection; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param string $texte |
|
| 64 | - * @param array $options |
|
| 65 | - * bool $collecter_liens |
|
| 66 | - * @return array |
|
| 67 | - */ |
|
| 68 | - public function collecter(string $texte, array $options = []): array { |
|
| 69 | - if (!$texte) { |
|
| 70 | - return []; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $liens = []; |
|
| 74 | - if (strpos($texte, '->') !== false) { |
|
| 75 | - |
|
| 76 | - $desechappe_crochets = false; |
|
| 77 | - // si il y a un crochet ouvrant échappé ou un crochet fermant échappé, les substituer pour les ignorer |
|
| 78 | - if (strpos($texte, '\[') !== false or strpos($texte, '\]') !== false) { |
|
| 79 | - $texte = str_replace(['\[', '\]'], ["\x1\x5", "\x1\x6"], $texte); |
|
| 80 | - $desechappe_crochets = true; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // collecter les matchs de la preg |
|
| 84 | - $liens = $this->collecteur($texte, '->', '[', $this->preg_lien, empty($options['detecter_presence']) ? 0 : 1); |
|
| 85 | - |
|
| 86 | - // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 87 | - if (empty($options['detecter_presence'])) { |
|
| 88 | - |
|
| 89 | - foreach ($liens as $k => &$lien) { |
|
| 90 | - |
|
| 91 | - $lien['href'] = end($lien['match']); |
|
| 92 | - $lien['texte'] = $lien['match'][1]; |
|
| 93 | - $lien['ouvrant'] = $lien['match'][3] ?? ''; |
|
| 94 | - |
|
| 95 | - // la mise en lien automatique est passee par la a tort ! |
|
| 96 | - // corrigeons pour eviter d'avoir un <a...> dans un href... |
|
| 97 | - if (strncmp($lien['href'], '<a', 2) == 0) { |
|
| 98 | - $href = extraire_attribut($lien['href'], 'href'); |
|
| 99 | - // remplacons dans la source qui peut etre reinjectee dans les arguments |
|
| 100 | - // d'un modele |
|
| 101 | - $lien['raw'] = str_replace($lien['href'], $href, $lien['raw']); |
|
| 102 | - // et prenons le href comme la vraie url a linker |
|
| 103 | - $lien['href'] = $href; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($desechappe_crochets and strpos($lien['raw'], "\x1") !== false) { |
|
| 107 | - $lien['raw'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $lien['raw']); |
|
| 108 | - $lien['texte'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $lien['texte']); |
|
| 109 | - $lien['href'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $lien['href']); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return $liens; |
|
| 117 | - } |
|
| 20 | + protected static string $markPrefix = 'LIEN'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * La preg pour découper et collecter les modèles |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + protected string $preg_lien; |
|
| 27 | + |
|
| 28 | + public function __construct(?string $preg = null) { |
|
| 29 | + |
|
| 30 | + // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip |
|
| 31 | + // Laisser passer des paires de crochets pour la balise multi |
|
| 32 | + // mais refuser plus d'imbrications ou de mauvaises imbrications |
|
| 33 | + // sinon les crochets ne peuvent plus servir qu'a ce type de raccourci |
|
| 34 | + $this->preg_lien = ($preg ?: '/\[([^][]*?([[][^]>-]*[]][^][]*)*)->(>?)([^]]*)\]/msS'); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Sanitizer une collection d'occurences de liens : il faut sanitizer le href et le texte uniquement |
|
| 40 | + * |
|
| 41 | + * @param array $collection |
|
| 42 | + * @param string $sanitize_callback |
|
| 43 | + * @return array |
|
| 44 | + */ |
|
| 45 | + protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 46 | + foreach ($collection as &$lien) { |
|
| 47 | + $t = $sanitize_callback($lien['texte']); |
|
| 48 | + if ($t !== $lien['texte']) { |
|
| 49 | + $lien['raw'] = str_replace($lien['texte'], $t, $lien['raw']); |
|
| 50 | + $lien['texte'] = $t; |
|
| 51 | + } |
|
| 52 | + $href = $sanitize_callback($lien['href']); |
|
| 53 | + if ($href !== $lien['href']) { |
|
| 54 | + $lien['raw'] = str_replace($lien['href'], $href, $lien['raw']); |
|
| 55 | + $lien['href'] = $href; |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + return $collection; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param string $texte |
|
| 64 | + * @param array $options |
|
| 65 | + * bool $collecter_liens |
|
| 66 | + * @return array |
|
| 67 | + */ |
|
| 68 | + public function collecter(string $texte, array $options = []): array { |
|
| 69 | + if (!$texte) { |
|
| 70 | + return []; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $liens = []; |
|
| 74 | + if (strpos($texte, '->') !== false) { |
|
| 75 | + |
|
| 76 | + $desechappe_crochets = false; |
|
| 77 | + // si il y a un crochet ouvrant échappé ou un crochet fermant échappé, les substituer pour les ignorer |
|
| 78 | + if (strpos($texte, '\[') !== false or strpos($texte, '\]') !== false) { |
|
| 79 | + $texte = str_replace(['\[', '\]'], ["\x1\x5", "\x1\x6"], $texte); |
|
| 80 | + $desechappe_crochets = true; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // collecter les matchs de la preg |
|
| 84 | + $liens = $this->collecteur($texte, '->', '[', $this->preg_lien, empty($options['detecter_presence']) ? 0 : 1); |
|
| 85 | + |
|
| 86 | + // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 87 | + if (empty($options['detecter_presence'])) { |
|
| 88 | + |
|
| 89 | + foreach ($liens as $k => &$lien) { |
|
| 90 | + |
|
| 91 | + $lien['href'] = end($lien['match']); |
|
| 92 | + $lien['texte'] = $lien['match'][1]; |
|
| 93 | + $lien['ouvrant'] = $lien['match'][3] ?? ''; |
|
| 94 | + |
|
| 95 | + // la mise en lien automatique est passee par la a tort ! |
|
| 96 | + // corrigeons pour eviter d'avoir un <a...> dans un href... |
|
| 97 | + if (strncmp($lien['href'], '<a', 2) == 0) { |
|
| 98 | + $href = extraire_attribut($lien['href'], 'href'); |
|
| 99 | + // remplacons dans la source qui peut etre reinjectee dans les arguments |
|
| 100 | + // d'un modele |
|
| 101 | + $lien['raw'] = str_replace($lien['href'], $href, $lien['raw']); |
|
| 102 | + // et prenons le href comme la vraie url a linker |
|
| 103 | + $lien['href'] = $href; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($desechappe_crochets and strpos($lien['raw'], "\x1") !== false) { |
|
| 107 | + $lien['raw'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $lien['raw']); |
|
| 108 | + $lien['texte'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $lien['texte']); |
|
| 109 | + $lien['href'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $lien['href']); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return $liens; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | } |
@@ -209,9 +209,9 @@ |
||
| 209 | 209 | // il ne faut pas echapper en div si propre produit un seul paragraphe |
| 210 | 210 | include_spip('inc/texte'); |
| 211 | 211 | $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
| 212 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 212 | + $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 213 | 213 | if ($mode === 'div') { |
| 214 | - $trad = rtrim($trad) . "\n\n"; |
|
| 214 | + $trad = rtrim($trad)."\n\n"; |
|
| 215 | 215 | } |
| 216 | 216 | $trad = code_echappement($trad, 'multi', false, $mode); |
| 217 | 217 | $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
@@ -29,210 +29,210 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class Multis extends AbstractCollecteur { |
| 31 | 31 | |
| 32 | - protected static string $markPrefix = 'MULTI'; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * La preg pour découper et collecter les modèles |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - protected string $preg_multi; |
|
| 39 | - |
|
| 40 | - public function __construct(?string $preg = null) { |
|
| 41 | - |
|
| 42 | - $this->preg_multi = ($preg ?: '@<multi>(.*?)</multi>@sS'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Sanitizer une collection d'occurences de multi : on sanitize chaque texte de langue séparemment |
|
| 47 | - * |
|
| 48 | - * @param array $collection |
|
| 49 | - * @param string $sanitize_callback |
|
| 50 | - * @return array |
|
| 51 | - */ |
|
| 52 | - protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 53 | - |
|
| 54 | - foreach ($collection as &$multi) { |
|
| 55 | - $changed = false; |
|
| 56 | - foreach ($multi['trads'] as $lang => $trad) { |
|
| 57 | - $t = $sanitize_callback($trad); |
|
| 58 | - if ($t !== $trad) { |
|
| 59 | - $changed = true; |
|
| 60 | - $multi['trads'][$lang] = $t; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - if ($changed) { |
|
| 64 | - $texte = $this->agglomerer_trads($multi['trads']); |
|
| 65 | - $multi['raw'] = str_replace($multi['texte'], $texte, $multi['raw']); |
|
| 66 | - $multi['texte'] = $texte; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - return $collection; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Convertit le contenu d'une balise `<multi>` en un tableau |
|
| 75 | - * |
|
| 76 | - * Exemple de blocs. |
|
| 77 | - * - `texte par défaut [fr] en français [en] en anglais` |
|
| 78 | - * - `[fr] en français [en] en anglais` |
|
| 79 | - * |
|
| 80 | - * @param string $bloc |
|
| 81 | - * Le contenu intérieur d'un bloc multi |
|
| 82 | - * @return array [code de langue => texte] |
|
| 83 | - * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
|
| 84 | - **/ |
|
| 85 | - protected function extraire_trads($bloc) { |
|
| 86 | - $trads = []; |
|
| 87 | - |
|
| 88 | - if (strlen($bloc)) { |
|
| 89 | - $langs = $this->collecteur($bloc, ']', '[', '@[\[]([a-z]{2,3}(_[a-z]{2,3})?(_[a-z]{2,3})?)[\]]@siS'); |
|
| 90 | - $lang = ''; |
|
| 91 | - $pos_prev = 0; |
|
| 92 | - foreach ($langs as $l) { |
|
| 93 | - $pos = $l['pos']; |
|
| 94 | - if ($lang or $pos > $pos_prev) { |
|
| 95 | - $trads[$lang] = substr($bloc, $pos_prev, $pos - $pos_prev); |
|
| 96 | - } |
|
| 97 | - $lang = $l['match'][1]; |
|
| 98 | - $pos_prev = $pos + $l['length']; |
|
| 99 | - } |
|
| 100 | - $trads[$lang] = substr($bloc, $pos_prev); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - return $trads; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Recoller ensemble les trads pour reconstituer le texte dans la balise <multi>...</multi> |
|
| 108 | - * @param $trads |
|
| 109 | - * @return string |
|
| 110 | - */ |
|
| 111 | - protected function agglomerer_trads($trads) { |
|
| 112 | - $texte = ''; |
|
| 113 | - foreach ($trads as $lang => $trad) { |
|
| 114 | - if ($texte or $lang) { |
|
| 115 | - $texte .= "[$lang]"; |
|
| 116 | - } |
|
| 117 | - $texte .= $trad; |
|
| 118 | - } |
|
| 119 | - return $texte; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @param string $texte |
|
| 124 | - * @param array $options |
|
| 125 | - * bool $collecter_liens |
|
| 126 | - * @return array |
|
| 127 | - */ |
|
| 128 | - public function collecter(string $texte, array $options = []): array { |
|
| 129 | - if (!$texte) { |
|
| 130 | - return []; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // collecter les matchs de la preg |
|
| 134 | - $multis = $this->collecteur($texte, '', '<multi', $this->preg_multi, empty($options['detecter_presence']) ? 0 : 1); |
|
| 135 | - |
|
| 136 | - // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 137 | - if (empty($options['detecter_presence'])) { |
|
| 138 | - foreach ($multis as $k => &$multi) { |
|
| 139 | - $multi['texte'] = $multi['match'][1]; |
|
| 140 | - // extraire les trads du texte |
|
| 141 | - $multi['trads'] = $this->extraire_trads($multi['texte']); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return $multis; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Traiter les multis d'un texte |
|
| 150 | - * |
|
| 151 | - * @uses approcher_langue() |
|
| 152 | - * @uses lang_typo() |
|
| 153 | - * @uses code_echappement() |
|
| 154 | - * @uses echappe_retour() |
|
| 155 | - * |
|
| 156 | - * @param string $texte |
|
| 157 | - * @param array $options |
|
| 158 | - * ?string $lang |
|
| 159 | - * ?string $lang_defaut |
|
| 160 | - * ?bool echappe_span |
|
| 161 | - * ?bool appliquer_typo |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function traiter(string $texte, array $options) { |
|
| 165 | - if ($texte) { |
|
| 166 | - |
|
| 167 | - $multis = $this->collecter($texte); |
|
| 168 | - if (!empty($multis)) { |
|
| 169 | - $lang = $options['lang'] ?? $GLOBALS['spip_lang']; |
|
| 170 | - $lang_defaut = $options['lang_defaut'] ?? _LANGUE_PAR_DEFAUT; |
|
| 171 | - $echappe_span = $options['echappe_span'] ?? false; |
|
| 172 | - $appliquer_typo = $options['appliquer_typo'] ?? true; |
|
| 173 | - |
|
| 174 | - if (!function_exists('approcher_langue')) { |
|
| 175 | - include_spip('inc/lang'); |
|
| 176 | - } |
|
| 177 | - if (!function_exists('code_echappement')) { |
|
| 178 | - include_spip('inc/texte_mini'); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $offset_pos = 0; |
|
| 182 | - foreach ($multis as $m) { |
|
| 183 | - |
|
| 184 | - // chercher la version de la langue courante |
|
| 185 | - $trads = $m['trads']; |
|
| 186 | - if (empty($trads)) { |
|
| 187 | - $trad = ''; |
|
| 188 | - } |
|
| 189 | - elseif ($l = approcher_langue($trads, $lang)) { |
|
| 190 | - $trad = $trads[$l]; |
|
| 191 | - } else { |
|
| 192 | - if ($lang_defaut == 'aucune') { |
|
| 193 | - $trad = ''; |
|
| 194 | - } else { |
|
| 195 | - // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 196 | - // ou la premiere dispo |
|
| 197 | - if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 198 | - $l = array_keys($trads); |
|
| 199 | - $l = reset($l); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // mais typographier le texte selon les regles de celle-ci |
|
| 203 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 204 | - if ($appliquer_typo) { |
|
| 205 | - $trad = $trads[$l]; |
|
| 206 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 207 | - $trad = $typographie($trad); |
|
| 208 | - |
|
| 209 | - // Tester si on echappe en span ou en div |
|
| 210 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 211 | - include_spip('inc/texte'); |
|
| 212 | - $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 213 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 214 | - if ($mode === 'div') { |
|
| 215 | - $trad = rtrim($trad) . "\n\n"; |
|
| 216 | - } |
|
| 217 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 218 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 219 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 220 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 221 | - } |
|
| 222 | - if (!$echappe_span) { |
|
| 223 | - $trad = echappe_retour($trad, 'multi'); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $texte = substr_replace($texte, $trad, $m['pos'] + $offset_pos, $m['length']); |
|
| 230 | - $offset_pos += strlen($trad) - $m['length']; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return $texte; |
|
| 236 | - } |
|
| 32 | + protected static string $markPrefix = 'MULTI'; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * La preg pour découper et collecter les modèles |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + protected string $preg_multi; |
|
| 39 | + |
|
| 40 | + public function __construct(?string $preg = null) { |
|
| 41 | + |
|
| 42 | + $this->preg_multi = ($preg ?: '@<multi>(.*?)</multi>@sS'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Sanitizer une collection d'occurences de multi : on sanitize chaque texte de langue séparemment |
|
| 47 | + * |
|
| 48 | + * @param array $collection |
|
| 49 | + * @param string $sanitize_callback |
|
| 50 | + * @return array |
|
| 51 | + */ |
|
| 52 | + protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 53 | + |
|
| 54 | + foreach ($collection as &$multi) { |
|
| 55 | + $changed = false; |
|
| 56 | + foreach ($multi['trads'] as $lang => $trad) { |
|
| 57 | + $t = $sanitize_callback($trad); |
|
| 58 | + if ($t !== $trad) { |
|
| 59 | + $changed = true; |
|
| 60 | + $multi['trads'][$lang] = $t; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + if ($changed) { |
|
| 64 | + $texte = $this->agglomerer_trads($multi['trads']); |
|
| 65 | + $multi['raw'] = str_replace($multi['texte'], $texte, $multi['raw']); |
|
| 66 | + $multi['texte'] = $texte; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + return $collection; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Convertit le contenu d'une balise `<multi>` en un tableau |
|
| 75 | + * |
|
| 76 | + * Exemple de blocs. |
|
| 77 | + * - `texte par défaut [fr] en français [en] en anglais` |
|
| 78 | + * - `[fr] en français [en] en anglais` |
|
| 79 | + * |
|
| 80 | + * @param string $bloc |
|
| 81 | + * Le contenu intérieur d'un bloc multi |
|
| 82 | + * @return array [code de langue => texte] |
|
| 83 | + * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
|
| 84 | + **/ |
|
| 85 | + protected function extraire_trads($bloc) { |
|
| 86 | + $trads = []; |
|
| 87 | + |
|
| 88 | + if (strlen($bloc)) { |
|
| 89 | + $langs = $this->collecteur($bloc, ']', '[', '@[\[]([a-z]{2,3}(_[a-z]{2,3})?(_[a-z]{2,3})?)[\]]@siS'); |
|
| 90 | + $lang = ''; |
|
| 91 | + $pos_prev = 0; |
|
| 92 | + foreach ($langs as $l) { |
|
| 93 | + $pos = $l['pos']; |
|
| 94 | + if ($lang or $pos > $pos_prev) { |
|
| 95 | + $trads[$lang] = substr($bloc, $pos_prev, $pos - $pos_prev); |
|
| 96 | + } |
|
| 97 | + $lang = $l['match'][1]; |
|
| 98 | + $pos_prev = $pos + $l['length']; |
|
| 99 | + } |
|
| 100 | + $trads[$lang] = substr($bloc, $pos_prev); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + return $trads; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Recoller ensemble les trads pour reconstituer le texte dans la balise <multi>...</multi> |
|
| 108 | + * @param $trads |
|
| 109 | + * @return string |
|
| 110 | + */ |
|
| 111 | + protected function agglomerer_trads($trads) { |
|
| 112 | + $texte = ''; |
|
| 113 | + foreach ($trads as $lang => $trad) { |
|
| 114 | + if ($texte or $lang) { |
|
| 115 | + $texte .= "[$lang]"; |
|
| 116 | + } |
|
| 117 | + $texte .= $trad; |
|
| 118 | + } |
|
| 119 | + return $texte; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @param string $texte |
|
| 124 | + * @param array $options |
|
| 125 | + * bool $collecter_liens |
|
| 126 | + * @return array |
|
| 127 | + */ |
|
| 128 | + public function collecter(string $texte, array $options = []): array { |
|
| 129 | + if (!$texte) { |
|
| 130 | + return []; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // collecter les matchs de la preg |
|
| 134 | + $multis = $this->collecteur($texte, '', '<multi', $this->preg_multi, empty($options['detecter_presence']) ? 0 : 1); |
|
| 135 | + |
|
| 136 | + // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 137 | + if (empty($options['detecter_presence'])) { |
|
| 138 | + foreach ($multis as $k => &$multi) { |
|
| 139 | + $multi['texte'] = $multi['match'][1]; |
|
| 140 | + // extraire les trads du texte |
|
| 141 | + $multi['trads'] = $this->extraire_trads($multi['texte']); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return $multis; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Traiter les multis d'un texte |
|
| 150 | + * |
|
| 151 | + * @uses approcher_langue() |
|
| 152 | + * @uses lang_typo() |
|
| 153 | + * @uses code_echappement() |
|
| 154 | + * @uses echappe_retour() |
|
| 155 | + * |
|
| 156 | + * @param string $texte |
|
| 157 | + * @param array $options |
|
| 158 | + * ?string $lang |
|
| 159 | + * ?string $lang_defaut |
|
| 160 | + * ?bool echappe_span |
|
| 161 | + * ?bool appliquer_typo |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | + public function traiter(string $texte, array $options) { |
|
| 165 | + if ($texte) { |
|
| 166 | + |
|
| 167 | + $multis = $this->collecter($texte); |
|
| 168 | + if (!empty($multis)) { |
|
| 169 | + $lang = $options['lang'] ?? $GLOBALS['spip_lang']; |
|
| 170 | + $lang_defaut = $options['lang_defaut'] ?? _LANGUE_PAR_DEFAUT; |
|
| 171 | + $echappe_span = $options['echappe_span'] ?? false; |
|
| 172 | + $appliquer_typo = $options['appliquer_typo'] ?? true; |
|
| 173 | + |
|
| 174 | + if (!function_exists('approcher_langue')) { |
|
| 175 | + include_spip('inc/lang'); |
|
| 176 | + } |
|
| 177 | + if (!function_exists('code_echappement')) { |
|
| 178 | + include_spip('inc/texte_mini'); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $offset_pos = 0; |
|
| 182 | + foreach ($multis as $m) { |
|
| 183 | + |
|
| 184 | + // chercher la version de la langue courante |
|
| 185 | + $trads = $m['trads']; |
|
| 186 | + if (empty($trads)) { |
|
| 187 | + $trad = ''; |
|
| 188 | + } |
|
| 189 | + elseif ($l = approcher_langue($trads, $lang)) { |
|
| 190 | + $trad = $trads[$l]; |
|
| 191 | + } else { |
|
| 192 | + if ($lang_defaut == 'aucune') { |
|
| 193 | + $trad = ''; |
|
| 194 | + } else { |
|
| 195 | + // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 196 | + // ou la premiere dispo |
|
| 197 | + if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 198 | + $l = array_keys($trads); |
|
| 199 | + $l = reset($l); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // mais typographier le texte selon les regles de celle-ci |
|
| 203 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 204 | + if ($appliquer_typo) { |
|
| 205 | + $trad = $trads[$l]; |
|
| 206 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 207 | + $trad = $typographie($trad); |
|
| 208 | + |
|
| 209 | + // Tester si on echappe en span ou en div |
|
| 210 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 211 | + include_spip('inc/texte'); |
|
| 212 | + $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 213 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 214 | + if ($mode === 'div') { |
|
| 215 | + $trad = rtrim($trad) . "\n\n"; |
|
| 216 | + } |
|
| 217 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 218 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 219 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 220 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 221 | + } |
|
| 222 | + if (!$echappe_span) { |
|
| 223 | + $trad = echappe_retour($trad, 'multi'); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $texte = substr_replace($texte, $trad, $m['pos'] + $offset_pos, $m['length']); |
|
| 230 | + $offset_pos += strlen($trad) - $m['length']; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return $texte; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | 238 | } |
@@ -185,8 +185,7 @@ |
||
| 185 | 185 | $trads = $m['trads']; |
| 186 | 186 | if (empty($trads)) { |
| 187 | 187 | $trad = ''; |
| 188 | - } |
|
| 189 | - elseif ($l = approcher_langue($trads, $lang)) { |
|
| 188 | + } elseif ($l = approcher_langue($trads, $lang)) { |
|
| 190 | 189 | $trad = $trads[$l]; |
| 191 | 190 | } else { |
| 192 | 191 | if ($lang_defaut == 'aucune') { |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function traiter_modeles($texte, $doublons = false, $echap = '', string $connect = '', ?Spip\Texte\Collecteur\Liens $collecteurLiens = null, $env = []) { |
| 28 | 28 | |
| 29 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 30 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 31 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 29 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 30 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 31 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 32 | 32 | |
| 33 | - $options = [ |
|
| 34 | - 'doublons' => $doublons, |
|
| 35 | - 'echap' => $echap, |
|
| 36 | - 'connect' => $connect, |
|
| 37 | - 'collecteurLiens' => $collecteurLiens, |
|
| 38 | - 'env' => $env |
|
| 39 | - ]; |
|
| 40 | - return $collecteurModeles->traiter($texte ?? '', $options); |
|
| 33 | + $options = [ |
|
| 34 | + 'doublons' => $doublons, |
|
| 35 | + 'echap' => $echap, |
|
| 36 | + 'connect' => $connect, |
|
| 37 | + 'collecteurLiens' => $collecteurLiens, |
|
| 38 | + 'env' => $env |
|
| 39 | + ]; |
|
| 40 | + return $collecteurModeles->traiter($texte ?? '', $options); |
|
| 41 | 41 | } |
@@ -11,5 +11,5 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
@@ -83,8 +83,7 @@ discard block |
||
| 83 | 83 | . '</code>' |
| 84 | 84 | . '</pre>' |
| 85 | 85 | . '</div>'; |
| 86 | - } |
|
| 87 | - else { |
|
| 86 | + } else { |
|
| 88 | 87 | $echap = str_replace("\t", " ", $echap); |
| 89 | 88 | $echap = str_replace(" ", " ", $echap); |
| 90 | 89 | $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
@@ -611,8 +610,7 @@ discard block |
||
| 611 | 610 | $collecteurLiens = $collecteurModeles = null; |
| 612 | 611 | if (!empty($options['expanser_liens'])) { |
| 613 | 612 | $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
| 614 | - } |
|
| 615 | - else { |
|
| 613 | + } else { |
|
| 616 | 614 | include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
| 617 | 615 | include_spip("src/Texte/Collecteur/Liens"); |
| 618 | 616 | include_spip("src/Texte/Collecteur/Modeles"); |
@@ -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 | /** |
@@ -67,31 +67,31 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = '') { |
| 69 | 69 | |
| 70 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 71 | - $class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 72 | - if ($attributs) { |
|
| 73 | - $attributs = " " . trim($attributs); |
|
| 74 | - } |
|
| 75 | - if ($langage) { |
|
| 76 | - $class .= " language-$langage"; |
|
| 77 | - $attributs .= ' data-language="'. $langage .'"'; |
|
| 78 | - } |
|
| 79 | - if ($bloc) { |
|
| 80 | - $html = "<div class=\"precode\">" |
|
| 81 | - . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>" |
|
| 82 | - . "<code>" |
|
| 83 | - . $echap |
|
| 84 | - . '</code>' |
|
| 85 | - . '</pre>' |
|
| 86 | - . '</div>'; |
|
| 87 | - } |
|
| 88 | - else { |
|
| 89 | - $echap = str_replace("\t", " ", $echap); |
|
| 90 | - $echap = str_replace(" ", " ", $echap); |
|
| 91 | - $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $html; |
|
| 70 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 71 | + $class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 72 | + if ($attributs) { |
|
| 73 | + $attributs = " " . trim($attributs); |
|
| 74 | + } |
|
| 75 | + if ($langage) { |
|
| 76 | + $class .= " language-$langage"; |
|
| 77 | + $attributs .= ' data-language="'. $langage .'"'; |
|
| 78 | + } |
|
| 79 | + if ($bloc) { |
|
| 80 | + $html = "<div class=\"precode\">" |
|
| 81 | + . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>" |
|
| 82 | + . "<code>" |
|
| 83 | + . $echap |
|
| 84 | + . '</code>' |
|
| 85 | + . '</pre>' |
|
| 86 | + . '</div>'; |
|
| 87 | + } |
|
| 88 | + else { |
|
| 89 | + $echap = str_replace("\t", " ", $echap); |
|
| 90 | + $echap = str_replace(" ", " ", $echap); |
|
| 91 | + $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $html; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -99,14 +99,14 @@ discard block |
||
| 99 | 99 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 100 | 100 | |
| 101 | 101 | if (!defined('_BALISES_BLOCS')) { |
| 102 | - define( |
|
| 103 | - '_BALISES_BLOCS', |
|
| 104 | - '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' |
|
| 105 | - ); |
|
| 102 | + define( |
|
| 103 | + '_BALISES_BLOCS', |
|
| 104 | + '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' |
|
| 105 | + ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 109 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 109 | + define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // |
@@ -117,100 +117,100 @@ discard block |
||
| 117 | 117 | // une $source differente ; le script detecte automagiquement si ce qu'on |
| 118 | 118 | // echappe est un div ou un span |
| 119 | 119 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 120 | - if (!strlen($rempl)) { |
|
| 121 | - return ''; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // Tester si on echappe en span ou en div |
|
| 125 | - if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 126 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 130 | - $taille = 30000; |
|
| 131 | - $return = ''; |
|
| 132 | - for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 133 | - // Convertir en base64 et cacher dans un attribut |
|
| 134 | - // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 135 | - $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 136 | - $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $return; |
|
| 120 | + if (!strlen($rempl)) { |
|
| 121 | + return ''; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // Tester si on echappe en span ou en div |
|
| 125 | + if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 126 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 130 | + $taille = 30000; |
|
| 131 | + $return = ''; |
|
| 132 | + for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 133 | + // Convertir en base64 et cacher dans un attribut |
|
| 134 | + // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 135 | + $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 136 | + $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $return; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | |
| 143 | 143 | // Echapper les <html>...</ html> |
| 144 | 144 | function traiter_echap_html_dist($regs, $options = []) { |
| 145 | - return $regs[3]; |
|
| 145 | + return $regs[3]; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Echapper les <pre>...</ pre> |
| 149 | 149 | function traiter_echap_pre_dist($regs, $options = []) { |
| 150 | - // echapper les <code> dans <pre> |
|
| 151 | - $pre = $regs[3]; |
|
| 152 | - |
|
| 153 | - // echapper les < dans <code> |
|
| 154 | - // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 155 | - if ( |
|
| 156 | - strpos($pre, '<') !== false |
|
| 157 | - and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 158 | - ) { |
|
| 159 | - foreach ($matches as $m) { |
|
| 160 | - if ($m[1] === 'code') { |
|
| 161 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 162 | - $pre = str_replace($m[0], $code, $pre); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - return "<pre>$pre</pre>"; |
|
| 150 | + // echapper les <code> dans <pre> |
|
| 151 | + $pre = $regs[3]; |
|
| 152 | + |
|
| 153 | + // echapper les < dans <code> |
|
| 154 | + // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 155 | + if ( |
|
| 156 | + strpos($pre, '<') !== false |
|
| 157 | + and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 158 | + ) { |
|
| 159 | + foreach ($matches as $m) { |
|
| 160 | + if ($m[1] === 'code') { |
|
| 161 | + $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 162 | + $pre = str_replace($m[0], $code, $pre); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + return "<pre>$pre</pre>"; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // Echapper les <code>...</ code> |
| 170 | 170 | function traiter_echap_code_dist($regs, $options = []) { |
| 171 | - [, , $att, $corps] = $regs; |
|
| 171 | + [, , $att, $corps] = $regs; |
|
| 172 | 172 | |
| 173 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 174 | - if (strpos($corps, "\n") !== false) { |
|
| 175 | - // supprimer les sauts de ligne debut/fin |
|
| 176 | - // (mais pas les espaces => ascii art). |
|
| 177 | - $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps); |
|
| 173 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 174 | + if (strpos($corps, "\n") !== false) { |
|
| 175 | + // supprimer les sauts de ligne debut/fin |
|
| 176 | + // (mais pas les espaces => ascii art). |
|
| 177 | + $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps); |
|
| 178 | 178 | |
| 179 | - $echap = spip_balisage_code($corps, true, $att); |
|
| 180 | - } else { |
|
| 181 | - $echap = spip_balisage_code($corps, false, $att); |
|
| 182 | - } |
|
| 179 | + $echap = spip_balisage_code($corps, true, $att); |
|
| 180 | + } else { |
|
| 181 | + $echap = spip_balisage_code($corps, false, $att); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - return $echap; |
|
| 184 | + return $echap; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 188 | 188 | function traiter_echap_cadre_dist($regs, $options = []) { |
| 189 | - $echap = trim(entites_html($regs[3])); |
|
| 190 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 191 | - $lignes = explode("\n", trim($echap)); |
|
| 192 | - $n = 0; |
|
| 193 | - foreach ($lignes as $l) { |
|
| 194 | - $n += floor(strlen($l) / 60) + 1; |
|
| 195 | - } |
|
| 196 | - $n = max($n, 2); |
|
| 197 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>"; |
|
| 198 | - |
|
| 199 | - return $echap; |
|
| 189 | + $echap = trim(entites_html($regs[3])); |
|
| 190 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 191 | + $lignes = explode("\n", trim($echap)); |
|
| 192 | + $n = 0; |
|
| 193 | + foreach ($lignes as $l) { |
|
| 194 | + $n += floor(strlen($l) / 60) + 1; |
|
| 195 | + } |
|
| 196 | + $n = max($n, 2); |
|
| 197 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>"; |
|
| 198 | + |
|
| 199 | + return $echap; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | function traiter_echap_frame_dist($regs, $options = []) { |
| 203 | - return traiter_echap_cadre_dist($regs); |
|
| 203 | + return traiter_echap_cadre_dist($regs); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | function traiter_echap_script_dist($regs, $options = []) { |
| 207 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 208 | - if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 209 | - return highlight_string($regs[0], true); |
|
| 210 | - } |
|
| 207 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 208 | + if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 209 | + return highlight_string($regs[0], true); |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - // Cas normal : le script passe tel quel |
|
| 213 | - return $regs[0]; |
|
| 212 | + // Cas normal : le script passe tel quel |
|
| 213 | + return $regs[0]; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\b[^>]*)?>(.*)</\1>,UimsS'); |
@@ -229,73 +229,73 @@ discard block |
||
| 229 | 229 | * @return string|string[] |
| 230 | 230 | */ |
| 231 | 231 | function echappe_html( |
| 232 | - $letexte, |
|
| 233 | - $source = '', |
|
| 234 | - $no_transform = false, |
|
| 235 | - $preg = '', |
|
| 236 | - $callback_prefix = '', |
|
| 237 | - $callback_options = [] |
|
| 232 | + $letexte, |
|
| 233 | + $source = '', |
|
| 234 | + $no_transform = false, |
|
| 235 | + $preg = '', |
|
| 236 | + $callback_prefix = '', |
|
| 237 | + $callback_options = [] |
|
| 238 | 238 | ) { |
| 239 | - if (!is_string($letexte) or !strlen($letexte)) { |
|
| 240 | - return $letexte; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - if ( |
|
| 244 | - ($preg or str_contains($letexte, '<')) |
|
| 245 | - and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 246 | - ) { |
|
| 247 | - foreach ($matches as $regs) { |
|
| 248 | - // echappements tels quels ? |
|
| 249 | - if ($no_transform) { |
|
| 250 | - $echap = $regs[0]; |
|
| 251 | - } // sinon les traiter selon le cas |
|
| 252 | - else { |
|
| 253 | - $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 254 | - if ( |
|
| 255 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 256 | - or function_exists($f = $f . '_dist') |
|
| 257 | - or ($callback_secure_prefix and ( |
|
| 258 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 259 | - or function_exists($f = $f . '_dist') |
|
| 260 | - )) |
|
| 261 | - ) { |
|
| 262 | - $echap = $f($regs, $callback_options); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - $p = strpos($letexte, (string) $regs[0]); |
|
| 267 | - $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - if ($no_transform) { |
|
| 272 | - return $letexte; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 276 | - // seulement si on a echappe les <script> |
|
| 277 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 278 | - // dans une callback autonommee |
|
| 279 | - if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 280 | - if ( |
|
| 281 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 282 | - ',<[?].*($|[?]>),UisS', |
|
| 283 | - $letexte, |
|
| 284 | - $matches, |
|
| 285 | - PREG_SET_ORDER |
|
| 286 | - ) |
|
| 287 | - ) { |
|
| 288 | - foreach ($matches as $regs) { |
|
| 289 | - $letexte = str_replace( |
|
| 290 | - $regs[0], |
|
| 291 | - code_echappement(highlight_string($regs[0], true), $source), |
|
| 292 | - $letexte |
|
| 293 | - ); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - return $letexte; |
|
| 239 | + if (!is_string($letexte) or !strlen($letexte)) { |
|
| 240 | + return $letexte; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + if ( |
|
| 244 | + ($preg or str_contains($letexte, '<')) |
|
| 245 | + and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 246 | + ) { |
|
| 247 | + foreach ($matches as $regs) { |
|
| 248 | + // echappements tels quels ? |
|
| 249 | + if ($no_transform) { |
|
| 250 | + $echap = $regs[0]; |
|
| 251 | + } // sinon les traiter selon le cas |
|
| 252 | + else { |
|
| 253 | + $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 254 | + if ( |
|
| 255 | + function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 256 | + or function_exists($f = $f . '_dist') |
|
| 257 | + or ($callback_secure_prefix and ( |
|
| 258 | + function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 259 | + or function_exists($f = $f . '_dist') |
|
| 260 | + )) |
|
| 261 | + ) { |
|
| 262 | + $echap = $f($regs, $callback_options); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + $p = strpos($letexte, (string) $regs[0]); |
|
| 267 | + $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + if ($no_transform) { |
|
| 272 | + return $letexte; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 276 | + // seulement si on a echappe les <script> |
|
| 277 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 278 | + // dans une callback autonommee |
|
| 279 | + if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 280 | + if ( |
|
| 281 | + strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 282 | + ',<[?].*($|[?]>),UisS', |
|
| 283 | + $letexte, |
|
| 284 | + $matches, |
|
| 285 | + PREG_SET_ORDER |
|
| 286 | + ) |
|
| 287 | + ) { |
|
| 288 | + foreach ($matches as $regs) { |
|
| 289 | + $letexte = str_replace( |
|
| 290 | + $regs[0], |
|
| 291 | + code_echappement(highlight_string($regs[0], true), $source), |
|
| 292 | + $letexte |
|
| 293 | + ); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + return $letexte; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | // |
@@ -303,57 +303,57 @@ discard block |
||
| 303 | 303 | // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes |
| 304 | 304 | // par propre() : exemple dans multi et dans typo() |
| 305 | 305 | function echappe_retour($letexte, $source = '', $filtre = '') { |
| 306 | - if (strpos($letexte, (string) "base64$source")) { |
|
| 307 | - # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 308 | - $max_prof = 5; |
|
| 309 | - while ( |
|
| 310 | - strpos($letexte, '<') !== false |
|
| 311 | - and |
|
| 312 | - preg_match_all( |
|
| 313 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 314 | - $letexte, |
|
| 315 | - $regs, |
|
| 316 | - PREG_SET_ORDER |
|
| 317 | - ) |
|
| 318 | - and $max_prof-- |
|
| 319 | - ) { |
|
| 320 | - foreach ($regs as $reg) { |
|
| 321 | - $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 322 | - // recherche d'attributs supplementaires |
|
| 323 | - $at = []; |
|
| 324 | - foreach (['lang', 'dir'] as $attr) { |
|
| 325 | - if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 326 | - $at[$attr] = $a; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - if ($at) { |
|
| 330 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 331 | - foreach ($at as $attr => $a) { |
|
| 332 | - $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - if ($filtre) { |
|
| 336 | - $rempl = $filtre($rempl); |
|
| 337 | - } |
|
| 338 | - $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return $letexte; |
|
| 306 | + if (strpos($letexte, (string) "base64$source")) { |
|
| 307 | + # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 308 | + $max_prof = 5; |
|
| 309 | + while ( |
|
| 310 | + strpos($letexte, '<') !== false |
|
| 311 | + and |
|
| 312 | + preg_match_all( |
|
| 313 | + ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 314 | + $letexte, |
|
| 315 | + $regs, |
|
| 316 | + PREG_SET_ORDER |
|
| 317 | + ) |
|
| 318 | + and $max_prof-- |
|
| 319 | + ) { |
|
| 320 | + foreach ($regs as $reg) { |
|
| 321 | + $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 322 | + // recherche d'attributs supplementaires |
|
| 323 | + $at = []; |
|
| 324 | + foreach (['lang', 'dir'] as $attr) { |
|
| 325 | + if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 326 | + $at[$attr] = $a; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + if ($at) { |
|
| 330 | + $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 331 | + foreach ($at as $attr => $a) { |
|
| 332 | + $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + if ($filtre) { |
|
| 336 | + $rempl = $filtre($rempl); |
|
| 337 | + } |
|
| 338 | + $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return $letexte; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | // Reinserer le javascript de confiance (venant des modeles) |
| 347 | 347 | |
| 348 | 348 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 349 | - $letexte = echappe_retour($letexte); |
|
| 349 | + $letexte = echappe_retour($letexte); |
|
| 350 | 350 | |
| 351 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 352 | - if ($interdire_scripts) { |
|
| 353 | - $letexte = interdire_scripts($letexte); |
|
| 354 | - } |
|
| 351 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 352 | + if ($interdire_scripts) { |
|
| 353 | + $letexte = interdire_scripts($letexte); |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - return trim($letexte); |
|
| 356 | + return trim($letexte); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | |
@@ -381,131 +381,131 @@ discard block |
||
| 381 | 381 | * texte coupé |
| 382 | 382 | **/ |
| 383 | 383 | function couper($texte, $taille = 50, $suite = null) { |
| 384 | - if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 385 | - return ''; |
|
| 386 | - } |
|
| 387 | - $offset = 400 + 2 * $taille; |
|
| 388 | - while ( |
|
| 389 | - $offset < $length |
|
| 390 | - and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 391 | - ) { |
|
| 392 | - $offset = 2 * $offset; |
|
| 393 | - } |
|
| 394 | - if ( |
|
| 395 | - $offset < $length |
|
| 396 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 397 | - ) { |
|
| 398 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 399 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 400 | - $offset = $p_tag_fermant + 1; |
|
| 401 | - } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 402 | - } |
|
| 403 | - $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 404 | - |
|
| 405 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 406 | - include_spip('inc/lien'); |
|
| 407 | - } |
|
| 408 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 409 | - |
|
| 410 | - // balises de sauts de ligne et paragraphe |
|
| 411 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 412 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 413 | - |
|
| 414 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 415 | - $texte = str_replace("\n\n", "\r", $texte); |
|
| 416 | - |
|
| 417 | - // supprimer les tags |
|
| 418 | - $texte = supprimer_tags($texte); |
|
| 419 | - $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 420 | - $texte .= "\n"; // marquer la fin |
|
| 421 | - |
|
| 422 | - // corriger la longueur de coupe |
|
| 423 | - // en fonction de la presence de caracteres utf |
|
| 424 | - if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 425 | - $long = charset2unicode($texte); |
|
| 426 | - $long = spip_substr($long, 0, max($taille, 1)); |
|
| 427 | - $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 428 | - $taille += $nbcharutf; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - // couper au mot precedent |
|
| 433 | - $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 434 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 435 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 436 | - if (is_null($suite)) { |
|
| 437 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 438 | - } |
|
| 439 | - $points = $suite; |
|
| 440 | - |
|
| 441 | - // trop court ? ne pas faire de (...) |
|
| 442 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 443 | - $points = ''; |
|
| 444 | - $long = spip_substr($texte, 0, $taille); |
|
| 445 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 446 | - // encore trop court ? couper au caractere |
|
| 447 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 448 | - $texte = $long; |
|
| 449 | - } |
|
| 450 | - } else { |
|
| 451 | - $texte = $court; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 455 | - $points = ''; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - // remettre les paragraphes |
|
| 459 | - $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 460 | - |
|
| 461 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 462 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 463 | - |
|
| 464 | - return quote_amp(trim($texte)) . $points; |
|
| 384 | + if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 385 | + return ''; |
|
| 386 | + } |
|
| 387 | + $offset = 400 + 2 * $taille; |
|
| 388 | + while ( |
|
| 389 | + $offset < $length |
|
| 390 | + and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 391 | + ) { |
|
| 392 | + $offset = 2 * $offset; |
|
| 393 | + } |
|
| 394 | + if ( |
|
| 395 | + $offset < $length |
|
| 396 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 397 | + ) { |
|
| 398 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 399 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 400 | + $offset = $p_tag_fermant + 1; |
|
| 401 | + } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 402 | + } |
|
| 403 | + $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 404 | + |
|
| 405 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 406 | + include_spip('inc/lien'); |
|
| 407 | + } |
|
| 408 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 409 | + |
|
| 410 | + // balises de sauts de ligne et paragraphe |
|
| 411 | + $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 412 | + $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 413 | + |
|
| 414 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 415 | + $texte = str_replace("\n\n", "\r", $texte); |
|
| 416 | + |
|
| 417 | + // supprimer les tags |
|
| 418 | + $texte = supprimer_tags($texte); |
|
| 419 | + $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 420 | + $texte .= "\n"; // marquer la fin |
|
| 421 | + |
|
| 422 | + // corriger la longueur de coupe |
|
| 423 | + // en fonction de la presence de caracteres utf |
|
| 424 | + if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 425 | + $long = charset2unicode($texte); |
|
| 426 | + $long = spip_substr($long, 0, max($taille, 1)); |
|
| 427 | + $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 428 | + $taille += $nbcharutf; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + // couper au mot precedent |
|
| 433 | + $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 434 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 435 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 436 | + if (is_null($suite)) { |
|
| 437 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 438 | + } |
|
| 439 | + $points = $suite; |
|
| 440 | + |
|
| 441 | + // trop court ? ne pas faire de (...) |
|
| 442 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 443 | + $points = ''; |
|
| 444 | + $long = spip_substr($texte, 0, $taille); |
|
| 445 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 446 | + // encore trop court ? couper au caractere |
|
| 447 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 448 | + $texte = $long; |
|
| 449 | + } |
|
| 450 | + } else { |
|
| 451 | + $texte = $court; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 455 | + $points = ''; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + // remettre les paragraphes |
|
| 459 | + $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 460 | + |
|
| 461 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 462 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 463 | + |
|
| 464 | + return quote_amp(trim($texte)) . $points; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | |
| 468 | 468 | function protege_js_modeles($t) { |
| 469 | - if (isset($GLOBALS['visiteur_session'])) { |
|
| 470 | - if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 471 | - if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 472 | - include_spip('inc/acces'); |
|
| 473 | - define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 474 | - } |
|
| 475 | - foreach ($r as $regs) { |
|
| 476 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 480 | - if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 481 | - include_spip('inc/acces'); |
|
| 482 | - define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 483 | - } |
|
| 484 | - foreach ($r as $regs) { |
|
| 485 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - return $t; |
|
| 469 | + if (isset($GLOBALS['visiteur_session'])) { |
|
| 470 | + if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 471 | + if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 472 | + include_spip('inc/acces'); |
|
| 473 | + define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 474 | + } |
|
| 475 | + foreach ($r as $regs) { |
|
| 476 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 480 | + if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 481 | + include_spip('inc/acces'); |
|
| 482 | + define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 483 | + } |
|
| 484 | + foreach ($r as $regs) { |
|
| 485 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + return $t; |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | |
| 494 | 494 | function echapper_faux_tags($letexte) { |
| 495 | - if (strpos($letexte, '<') === false) { |
|
| 496 | - return $letexte; |
|
| 497 | - } |
|
| 498 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 499 | - |
|
| 500 | - $letexte = ''; |
|
| 501 | - while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 502 | - // un texte a echapper |
|
| 503 | - $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 504 | - // un tag html qui a servit a faite le split |
|
| 505 | - $letexte .= array_shift($textMatches); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - return $letexte; |
|
| 495 | + if (strpos($letexte, '<') === false) { |
|
| 496 | + return $letexte; |
|
| 497 | + } |
|
| 498 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 499 | + |
|
| 500 | + $letexte = ''; |
|
| 501 | + while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 502 | + // un texte a echapper |
|
| 503 | + $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 504 | + // un tag html qui a servit a faite le split |
|
| 505 | + $letexte .= array_shift($textMatches); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + return $letexte; |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | /** |
@@ -525,115 +525,115 @@ discard block |
||
| 525 | 525 | * @return string |
| 526 | 526 | */ |
| 527 | 527 | function echapper_html_suspect($texte, $options = [], $connect = null, $env = []) { |
| 528 | - static $echapper_html_suspect; |
|
| 529 | - if (!$texte or !is_string($texte)) { |
|
| 530 | - return $texte; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - if (!isset($echapper_html_suspect)) { |
|
| 534 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 535 | - } |
|
| 536 | - // si fonction personalisee, on delegue |
|
| 537 | - if ($echapper_html_suspect) { |
|
| 538 | - // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 539 | - $args = [$texte, $options]; |
|
| 540 | - if ($connect or !empty($env)) { |
|
| 541 | - $args[] = $connect; |
|
| 542 | - } |
|
| 543 | - if (!empty($env)) { |
|
| 544 | - $args[] = $env; |
|
| 545 | - } |
|
| 546 | - return $echapper_html_suspect(...$args); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - if (is_bool($options)) { |
|
| 550 | - $options = ['strict' => $options]; |
|
| 551 | - } |
|
| 552 | - $strict = $options['strict'] ?? true; |
|
| 553 | - |
|
| 554 | - // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 555 | - if ( |
|
| 556 | - strpos($texte, '<') === false |
|
| 557 | - or !str_contains($texte, '=') |
|
| 558 | - ) { |
|
| 559 | - return $texte; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 563 | - if (!isset($env['espace_prive'])) { |
|
| 564 | - // conserver le comportement historique en cas d'appel court sans env |
|
| 565 | - $env['espace_prive'] = test_espace_prive(); |
|
| 566 | - } |
|
| 567 | - if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) { |
|
| 568 | - |
|
| 569 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 570 | - // car sinon on declenche sur les modeles ou ressources |
|
| 571 | - if ( |
|
| 572 | - !$strict and |
|
| 573 | - (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 574 | - ) { |
|
| 575 | - return $texte; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 579 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 580 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 581 | - $texte = $collecteurModeles->echapper($texte); |
|
| 582 | - $texte = echappe_js($texte); |
|
| 583 | - |
|
| 584 | - $texte_to_check = $texte; |
|
| 585 | - // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 586 | - // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 587 | - // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 588 | - if (!empty($options['expanser_liens'])) { |
|
| 589 | - $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 590 | - } |
|
| 591 | - if (!is_html_safe($texte_to_check)) { |
|
| 592 | - $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 593 | - $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 594 | - $texte = str_replace('<', '<', $texte); |
|
| 595 | - $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 596 | - $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 597 | - if (!function_exists('attribut_html')) { |
|
| 598 | - include_spip('inc/filtres'); |
|
| 599 | - } |
|
| 600 | - if (!empty($options['wrap_suspect'])) { |
|
| 601 | - $texte = wrap($texte, $options['wrap_suspect']); |
|
| 602 | - } |
|
| 603 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - $texte = $collecteurModeles->retablir($texte); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - // si on est là dans le public c'est le mode parano |
|
| 610 | - // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 611 | - else { |
|
| 612 | - $collecteurLiens = $collecteurModeles = null; |
|
| 613 | - if (!empty($options['expanser_liens'])) { |
|
| 614 | - $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 615 | - } |
|
| 616 | - else { |
|
| 617 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 618 | - include_spip("src/Texte/Collecteur/Liens"); |
|
| 619 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 620 | - |
|
| 621 | - $collecteurLiens = new Spip\Texte\Collecteur\Liens(); |
|
| 622 | - $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 623 | - |
|
| 624 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 625 | - $texte = $collecteurModeles->echapper($texte); |
|
| 626 | - } |
|
| 627 | - $texte = safehtml($texte); |
|
| 628 | - if ($collecteurModeles) { |
|
| 629 | - $texte = $collecteurModeles->retablir($texte); |
|
| 630 | - } |
|
| 631 | - if ($collecteurLiens) { |
|
| 632 | - $texte = $collecteurLiens->retablir($texte); |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - return $texte; |
|
| 528 | + static $echapper_html_suspect; |
|
| 529 | + if (!$texte or !is_string($texte)) { |
|
| 530 | + return $texte; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + if (!isset($echapper_html_suspect)) { |
|
| 534 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 535 | + } |
|
| 536 | + // si fonction personalisee, on delegue |
|
| 537 | + if ($echapper_html_suspect) { |
|
| 538 | + // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 539 | + $args = [$texte, $options]; |
|
| 540 | + if ($connect or !empty($env)) { |
|
| 541 | + $args[] = $connect; |
|
| 542 | + } |
|
| 543 | + if (!empty($env)) { |
|
| 544 | + $args[] = $env; |
|
| 545 | + } |
|
| 546 | + return $echapper_html_suspect(...$args); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + if (is_bool($options)) { |
|
| 550 | + $options = ['strict' => $options]; |
|
| 551 | + } |
|
| 552 | + $strict = $options['strict'] ?? true; |
|
| 553 | + |
|
| 554 | + // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 555 | + if ( |
|
| 556 | + strpos($texte, '<') === false |
|
| 557 | + or !str_contains($texte, '=') |
|
| 558 | + ) { |
|
| 559 | + return $texte; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 563 | + if (!isset($env['espace_prive'])) { |
|
| 564 | + // conserver le comportement historique en cas d'appel court sans env |
|
| 565 | + $env['espace_prive'] = test_espace_prive(); |
|
| 566 | + } |
|
| 567 | + if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) { |
|
| 568 | + |
|
| 569 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 570 | + // car sinon on declenche sur les modeles ou ressources |
|
| 571 | + if ( |
|
| 572 | + !$strict and |
|
| 573 | + (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 574 | + ) { |
|
| 575 | + return $texte; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 579 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 580 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 581 | + $texte = $collecteurModeles->echapper($texte); |
|
| 582 | + $texte = echappe_js($texte); |
|
| 583 | + |
|
| 584 | + $texte_to_check = $texte; |
|
| 585 | + // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 586 | + // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 587 | + // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 588 | + if (!empty($options['expanser_liens'])) { |
|
| 589 | + $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 590 | + } |
|
| 591 | + if (!is_html_safe($texte_to_check)) { |
|
| 592 | + $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 593 | + $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 594 | + $texte = str_replace('<', '<', $texte); |
|
| 595 | + $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 596 | + $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 597 | + if (!function_exists('attribut_html')) { |
|
| 598 | + include_spip('inc/filtres'); |
|
| 599 | + } |
|
| 600 | + if (!empty($options['wrap_suspect'])) { |
|
| 601 | + $texte = wrap($texte, $options['wrap_suspect']); |
|
| 602 | + } |
|
| 603 | + $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + $texte = $collecteurModeles->retablir($texte); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + // si on est là dans le public c'est le mode parano |
|
| 610 | + // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 611 | + else { |
|
| 612 | + $collecteurLiens = $collecteurModeles = null; |
|
| 613 | + if (!empty($options['expanser_liens'])) { |
|
| 614 | + $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 615 | + } |
|
| 616 | + else { |
|
| 617 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 618 | + include_spip("src/Texte/Collecteur/Liens"); |
|
| 619 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 620 | + |
|
| 621 | + $collecteurLiens = new Spip\Texte\Collecteur\Liens(); |
|
| 622 | + $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 623 | + |
|
| 624 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 625 | + $texte = $collecteurModeles->echapper($texte); |
|
| 626 | + } |
|
| 627 | + $texte = safehtml($texte); |
|
| 628 | + if ($collecteurModeles) { |
|
| 629 | + $texte = $collecteurModeles->retablir($texte); |
|
| 630 | + } |
|
| 631 | + if ($collecteurLiens) { |
|
| 632 | + $texte = $collecteurLiens->retablir($texte); |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + return $texte; |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | |
@@ -654,52 +654,52 @@ discard block |
||
| 654 | 654 | * texte sécurisé |
| 655 | 655 | **/ |
| 656 | 656 | function safehtml($t) { |
| 657 | - static $safehtml; |
|
| 658 | - |
|
| 659 | - if (!$t or !is_string($t)) { |
|
| 660 | - return $t; |
|
| 661 | - } |
|
| 662 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 663 | - if (strpos($t, '<') === false) { |
|
| 664 | - return str_replace("\x00", '', $t); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - $collecteurIdiomes = null; |
|
| 668 | - if (stripos($t, '<:') !== false) { |
|
| 669 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 670 | - include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 671 | - $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 672 | - $t = $collecteurIdiomes->echapper($t); |
|
| 673 | - } |
|
| 674 | - $collecteurMultis = null; |
|
| 675 | - if (stripos($t, '<multi') !== false) { |
|
| 676 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 677 | - include_spip("src/Texte/Collecteur/Multis"); |
|
| 678 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 679 | - $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - if (!function_exists('interdire_scripts')) { |
|
| 683 | - include_spip('inc/texte'); |
|
| 684 | - } |
|
| 685 | - $t = interdire_scripts($t); // jolifier le php |
|
| 686 | - $t = echappe_js($t); |
|
| 687 | - |
|
| 688 | - if (!isset($safehtml)) { |
|
| 689 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 690 | - } |
|
| 691 | - if ($safehtml) { |
|
| 692 | - $t = $safehtml($t); |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - if ($collecteurMultis) { |
|
| 696 | - $t = $collecteurMultis->retablir($t); |
|
| 697 | - } |
|
| 698 | - if ($collecteurIdiomes) { |
|
| 699 | - $t = $collecteurIdiomes->retablir($t); |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 657 | + static $safehtml; |
|
| 658 | + |
|
| 659 | + if (!$t or !is_string($t)) { |
|
| 660 | + return $t; |
|
| 661 | + } |
|
| 662 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 663 | + if (strpos($t, '<') === false) { |
|
| 664 | + return str_replace("\x00", '', $t); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + $collecteurIdiomes = null; |
|
| 668 | + if (stripos($t, '<:') !== false) { |
|
| 669 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 670 | + include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 671 | + $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 672 | + $t = $collecteurIdiomes->echapper($t); |
|
| 673 | + } |
|
| 674 | + $collecteurMultis = null; |
|
| 675 | + if (stripos($t, '<multi') !== false) { |
|
| 676 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 677 | + include_spip("src/Texte/Collecteur/Multis"); |
|
| 678 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 679 | + $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + if (!function_exists('interdire_scripts')) { |
|
| 683 | + include_spip('inc/texte'); |
|
| 684 | + } |
|
| 685 | + $t = interdire_scripts($t); // jolifier le php |
|
| 686 | + $t = echappe_js($t); |
|
| 687 | + |
|
| 688 | + if (!isset($safehtml)) { |
|
| 689 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 690 | + } |
|
| 691 | + if ($safehtml) { |
|
| 692 | + $t = $safehtml($t); |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + if ($collecteurMultis) { |
|
| 696 | + $t = $collecteurMultis->retablir($t); |
|
| 697 | + } |
|
| 698 | + if ($collecteurIdiomes) { |
|
| 699 | + $t = $collecteurIdiomes->retablir($t); |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | |
@@ -707,25 +707,25 @@ discard block |
||
| 707 | 707 | * Detecter si un texte est "safe" ie non modifie significativement par safehtml() |
| 708 | 708 | */ |
| 709 | 709 | function is_html_safe(string $texte): bool { |
| 710 | - if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 711 | - return $is_html_safe($texte); |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 715 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 716 | - // safehtml reduit aussi potentiellement les |
|
| 717 | - $texte = str_replace(" ", " ", $texte); |
|
| 718 | - // safehtml remplace les entités numériques |
|
| 719 | - if (strpos($texte, '&#') !== false) { |
|
| 720 | - $texte = unicode2charset($texte); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - $texte_safe = safehtml($texte); |
|
| 724 | - |
|
| 725 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 726 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 727 | - // donc un test d'egalite est trop strict |
|
| 728 | - return strlen($texte_safe) === strlen($texte); |
|
| 710 | + if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 711 | + return $is_html_safe($texte); |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 715 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 716 | + // safehtml reduit aussi potentiellement les |
|
| 717 | + $texte = str_replace(" ", " ", $texte); |
|
| 718 | + // safehtml remplace les entités numériques |
|
| 719 | + if (strpos($texte, '&#') !== false) { |
|
| 720 | + $texte = unicode2charset($texte); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + $texte_safe = safehtml($texte); |
|
| 724 | + |
|
| 725 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 726 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 727 | + // donc un test d'egalite est trop strict |
|
| 728 | + return strlen($texte_safe) === strlen($texte); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | /** |
@@ -746,13 +746,13 @@ discard block |
||
| 746 | 746 | * texte sans les modèles d'image |
| 747 | 747 | **/ |
| 748 | 748 | function supprime_img($letexte, $message = null) { |
| 749 | - if ($message === null) { |
|
| 750 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - return preg_replace( |
|
| 754 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 755 | - $message, |
|
| 756 | - $letexte |
|
| 757 | - ); |
|
| 749 | + if ($message === null) { |
|
| 750 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + return preg_replace( |
|
| 754 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 755 | + $message, |
|
| 756 | + $letexte |
|
| 757 | + ); |
|
| 758 | 758 | } |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | // celle du texte) et public (spip_lang est la langue du texte) |
| 45 | 45 | $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
| 46 | 46 | |
| 47 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 47 | + $p = 'puce'.(test_espace_prive() ? '_prive' : ''); |
|
| 48 | 48 | if ($dir == 'rtl') { |
| 49 | 49 | $p .= '_rtl'; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | if (!isset($GLOBALS[$p])) { |
| 53 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 53 | + $GLOBALS[$p] = '<span class="spip-puce '.$dir.'"><b>–</b></span>'; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | return $GLOBALS[$p]; |
@@ -68,13 +68,13 @@ discard block |
||
| 68 | 68 | function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = '') { |
| 69 | 69 | |
| 70 | 70 | $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
| 71 | - $class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 71 | + $class = "spip_code ".($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 72 | 72 | if ($attributs) { |
| 73 | - $attributs = " " . trim($attributs); |
|
| 73 | + $attributs = " ".trim($attributs); |
|
| 74 | 74 | } |
| 75 | 75 | if ($langage) { |
| 76 | 76 | $class .= " language-$langage"; |
| 77 | - $attributs .= ' data-language="'. $langage .'"'; |
|
| 77 | + $attributs .= ' data-language="'.$langage.'"'; |
|
| 78 | 78 | } |
| 79 | 79 | if ($bloc) { |
| 80 | 80 | $html = "<div class=\"precode\">" |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | else { |
| 89 | 89 | $echap = str_replace("\t", " ", $echap); |
| 90 | 90 | $echap = str_replace(" ", " ", $echap); |
| 91 | - $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 91 | + $html = "<code class=\"$class\" dir=\"ltr\"$attributs>".$echap.'</code>'; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | return $html; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 109 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 109 | + define('_BALISES_BLOCS_REGEXP', ',</?('._BALISES_BLOCS.')[>[:space:]],iS'); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | // Tester si on echappe en span ou en div |
| 125 | 125 | if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
| 126 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 126 | + $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | ) { |
| 159 | 159 | foreach ($matches as $m) { |
| 160 | 160 | if ($m[1] === 'code') { |
| 161 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 161 | + $code = '<code'.$m[2].'>'.spip_htmlspecialchars($m[3]).'</code>'; |
|
| 162 | 162 | $pre = str_replace($m[0], $code, $pre); |
| 163 | 163 | } |
| 164 | 164 | } |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | // Echapper les <code>...</ code> |
| 170 | 170 | function traiter_echap_code_dist($regs, $options = []) { |
| 171 | - [, , $att, $corps] = $regs; |
|
| 171 | + [,, $att, $corps] = $regs; |
|
| 172 | 172 | |
| 173 | 173 | // ne pas mettre le <div...> s'il n'y a qu'une ligne |
| 174 | 174 | if (strpos($corps, "\n") !== false) { |
@@ -252,11 +252,11 @@ discard block |
||
| 252 | 252 | else { |
| 253 | 253 | $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
| 254 | 254 | if ( |
| 255 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 256 | - or function_exists($f = $f . '_dist') |
|
| 255 | + function_exists($f = $callback_prefix.$callback_secure_prefix.'traiter_echap_'.strtolower($regs[1])) |
|
| 256 | + or function_exists($f = $f.'_dist') |
|
| 257 | 257 | or ($callback_secure_prefix and ( |
| 258 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 259 | - or function_exists($f = $f . '_dist') |
|
| 258 | + function_exists($f = $callback_prefix.'traiter_echap_'.strtolower($regs[1])) |
|
| 259 | + or function_exists($f = $f.'_dist') |
|
| 260 | 260 | )) |
| 261 | 261 | ) { |
| 262 | 262 | $echap = $f($regs, $callback_options); |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | // dans une callback autonommee |
| 279 | 279 | if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
| 280 | 280 | if ( |
| 281 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 281 | + strpos($letexte, '<'.'?') !== false and preg_match_all( |
|
| 282 | 282 | ',<[?].*($|[?]>),UisS', |
| 283 | 283 | $letexte, |
| 284 | 284 | $matches, |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | strpos($letexte, '<') !== false |
| 311 | 311 | and |
| 312 | 312 | preg_match_all( |
| 313 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 313 | + ',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 314 | 314 | $letexte, |
| 315 | 315 | $regs, |
| 316 | 316 | PREG_SET_ORDER |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | if ($at) { |
| 330 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 330 | + $rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>'; |
|
| 331 | 331 | foreach ($at as $attr => $a) { |
| 332 | 332 | $rempl = inserer_attribut($rempl, $attr, $a); |
| 333 | 333 | } |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | $texte = nettoyer_raccourcis_typo($texte); |
| 409 | 409 | |
| 410 | 410 | // balises de sauts de ligne et paragraphe |
| 411 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 412 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 411 | + $texte = preg_replace('/<p( [^>]*)?'.'>/', "\r", $texte); |
|
| 412 | + $texte = preg_replace('/<br( [^>]*)?'.'>/', "\n", $texte); |
|
| 413 | 413 | |
| 414 | 414 | // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
| 415 | 415 | $texte = str_replace("\n\n", "\r", $texte); |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | // supprimer les tags |
| 418 | 418 | $texte = supprimer_tags($texte); |
| 419 | 419 | $texte = trim(str_replace("\n", ' ', $texte)); |
| 420 | - $texte .= "\n"; // marquer la fin |
|
| 420 | + $texte .= "\n"; // marquer la fin |
|
| 421 | 421 | |
| 422 | 422 | // corriger la longueur de coupe |
| 423 | 423 | // en fonction de la presence de caracteres utf |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | // couper au mot precedent |
| 433 | 433 | $long = spip_substr($texte, 0, max($taille - 4, 1)); |
| 434 | 434 | $u = $GLOBALS['meta']['pcre_u']; |
| 435 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 435 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long); |
|
| 436 | 436 | if (is_null($suite)) { |
| 437 | 437 | $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
| 438 | 438 | } |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
| 443 | 443 | $points = ''; |
| 444 | 444 | $long = spip_substr($texte, 0, $taille); |
| 445 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 445 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/".$u, "\\1", $long); |
|
| 446 | 446 | // encore trop court ? couper au caractere |
| 447 | 447 | if (spip_strlen($texte) < 0.75 * $taille) { |
| 448 | 448 | $texte = $long; |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | // supprimer l'eventuelle entite finale mal coupee |
| 462 | 462 | $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
| 463 | 463 | |
| 464 | - return quote_amp(trim($texte)) . $points; |
|
| 464 | + return quote_amp(trim($texte)).$points; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | |
@@ -473,16 +473,16 @@ discard block |
||
| 473 | 473 | define('_PROTEGE_JS_MODELES', creer_uniqid()); |
| 474 | 474 | } |
| 475 | 475 | foreach ($r as $regs) { |
| 476 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 476 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript'._PROTEGE_JS_MODELES), $t); |
|
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 479 | + if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 480 | 480 | if (!defined('_PROTEGE_PHP_MODELES')) { |
| 481 | 481 | include_spip('inc/acces'); |
| 482 | 482 | define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
| 483 | 483 | } |
| 484 | 484 | foreach ($r as $regs) { |
| 485 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 485 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php'._PROTEGE_PHP_MODELES), $t); |
|
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | 488 | } |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | if (!empty($options['wrap_suspect'])) { |
| 601 | 601 | $texte = wrap($texte, $options['wrap_suspect']); |
| 602 | 602 | } |
| 603 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 603 | + $texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte; |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | $texte = $collecteurModeles->retablir($texte); |
@@ -747,11 +747,11 @@ discard block |
||
| 747 | 747 | **/ |
| 748 | 748 | function supprime_img($letexte, $message = null) { |
| 749 | 749 | if ($message === null) { |
| 750 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 750 | + $message = '('._T('img_indisponible').')'; |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | return preg_replace( |
| 754 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 754 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i', |
|
| 755 | 755 | $message, |
| 756 | 756 | $letexte |
| 757 | 757 | ); |