@@ -17,92 +17,92 @@ |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | function action_api_transmettre_dist($arg = null) { |
| 25 | 25 | |
| 26 | - // Obtenir l'argument 'id_auteur/cle/format/fond' |
|
| 27 | - if (is_null($arg)) { |
|
| 28 | - $arg = _request('arg'); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $args = explode('/', $arg); |
|
| 32 | - |
|
| 33 | - if (count($args) !== 4) { |
|
| 34 | - action_api_transmettre_fail($arg); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - [$id_auteur, $cle, $format, $fond] = $args; |
|
| 38 | - $id_auteur = intval($id_auteur); |
|
| 39 | - |
|
| 40 | - if (preg_match(',[^\w\\.-],', $format)) { |
|
| 41 | - action_api_transmettre_fail("format $format ??"); |
|
| 42 | - } |
|
| 43 | - if (preg_match(',[^\w\\.-],', $fond)) { |
|
| 44 | - action_api_transmettre_fail("fond $fond ??"); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // verifier la cle |
|
| 48 | - //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 49 | - //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 50 | - |
|
| 51 | - $qs = $_SERVER['QUERY_STRING']; |
|
| 52 | - // retirer action et arg de la qs |
|
| 53 | - $contexte = []; |
|
| 54 | - parse_str($qs, $contexte); |
|
| 55 | - foreach ($contexte as $k => $v) { |
|
| 56 | - if (in_array($k, ['action', 'arg', 'var_mode'])) { |
|
| 57 | - unset($contexte[$k]); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - $qs = http_build_query($contexte); |
|
| 61 | - include_spip('inc/acces'); |
|
| 62 | - if (!securiser_acces_low_sec(intval($id_auteur), $cle, "transmettre/$format", $fond, $qs)) { |
|
| 63 | - // si le autoriser low_sec n'est pas bon, on peut valider l'appel si l'auteur est identifie |
|
| 64 | - include_spip('inc/autoriser'); |
|
| 65 | - $autoriser_type = preg_replace(',\W+,', '', "_{$format}{$fond}"); |
|
| 66 | - if ( |
|
| 67 | - !$id_auteur |
|
| 68 | - or empty($GLOBALS['visiteur_session']['id_auteur']) |
|
| 69 | - or $GLOBALS['visiteur_session']['id_auteur'] != $id_auteur |
|
| 70 | - or !autoriser('transmettre', $autoriser_type, $id_auteur) |
|
| 71 | - ) { |
|
| 72 | - action_api_transmettre_fail("auth QS $qs ??"); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - $contexte['id_auteur'] = $id_auteur; |
|
| 77 | - |
|
| 78 | - $fond = "transmettre/$format/$fond"; |
|
| 79 | - |
|
| 80 | - if (!trouver_fond($fond)) { |
|
| 81 | - $fond = "prive/$fond"; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - if (!trouver_fond($fond)) { |
|
| 85 | - action_api_transmettre_fail("fond $fond ??"); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $res = recuperer_fond($fond, $contexte, ['raw' => true]); |
|
| 89 | - if (!empty($res['entetes'])) { |
|
| 90 | - foreach ($res['entetes'] as $h => $v) { |
|
| 91 | - header("$h: $v"); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $res = ltrim($res['texte']); |
|
| 96 | - if (empty($res)) { |
|
| 97 | - spip_log("$arg $qs resultat vide", 'transmettre' . _LOG_INFO_IMPORTANTE); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - echo $res; |
|
| 101 | - exit(); |
|
| 26 | + // Obtenir l'argument 'id_auteur/cle/format/fond' |
|
| 27 | + if (is_null($arg)) { |
|
| 28 | + $arg = _request('arg'); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $args = explode('/', $arg); |
|
| 32 | + |
|
| 33 | + if (count($args) !== 4) { |
|
| 34 | + action_api_transmettre_fail($arg); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + [$id_auteur, $cle, $format, $fond] = $args; |
|
| 38 | + $id_auteur = intval($id_auteur); |
|
| 39 | + |
|
| 40 | + if (preg_match(',[^\w\\.-],', $format)) { |
|
| 41 | + action_api_transmettre_fail("format $format ??"); |
|
| 42 | + } |
|
| 43 | + if (preg_match(',[^\w\\.-],', $fond)) { |
|
| 44 | + action_api_transmettre_fail("fond $fond ??"); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // verifier la cle |
|
| 48 | + //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 49 | + //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 50 | + |
|
| 51 | + $qs = $_SERVER['QUERY_STRING']; |
|
| 52 | + // retirer action et arg de la qs |
|
| 53 | + $contexte = []; |
|
| 54 | + parse_str($qs, $contexte); |
|
| 55 | + foreach ($contexte as $k => $v) { |
|
| 56 | + if (in_array($k, ['action', 'arg', 'var_mode'])) { |
|
| 57 | + unset($contexte[$k]); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + $qs = http_build_query($contexte); |
|
| 61 | + include_spip('inc/acces'); |
|
| 62 | + if (!securiser_acces_low_sec(intval($id_auteur), $cle, "transmettre/$format", $fond, $qs)) { |
|
| 63 | + // si le autoriser low_sec n'est pas bon, on peut valider l'appel si l'auteur est identifie |
|
| 64 | + include_spip('inc/autoriser'); |
|
| 65 | + $autoriser_type = preg_replace(',\W+,', '', "_{$format}{$fond}"); |
|
| 66 | + if ( |
|
| 67 | + !$id_auteur |
|
| 68 | + or empty($GLOBALS['visiteur_session']['id_auteur']) |
|
| 69 | + or $GLOBALS['visiteur_session']['id_auteur'] != $id_auteur |
|
| 70 | + or !autoriser('transmettre', $autoriser_type, $id_auteur) |
|
| 71 | + ) { |
|
| 72 | + action_api_transmettre_fail("auth QS $qs ??"); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + $contexte['id_auteur'] = $id_auteur; |
|
| 77 | + |
|
| 78 | + $fond = "transmettre/$format/$fond"; |
|
| 79 | + |
|
| 80 | + if (!trouver_fond($fond)) { |
|
| 81 | + $fond = "prive/$fond"; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + if (!trouver_fond($fond)) { |
|
| 85 | + action_api_transmettre_fail("fond $fond ??"); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $res = recuperer_fond($fond, $contexte, ['raw' => true]); |
|
| 89 | + if (!empty($res['entetes'])) { |
|
| 90 | + foreach ($res['entetes'] as $h => $v) { |
|
| 91 | + header("$h: $v"); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $res = ltrim($res['texte']); |
|
| 96 | + if (empty($res)) { |
|
| 97 | + spip_log("$arg $qs resultat vide", 'transmettre' . _LOG_INFO_IMPORTANTE); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + echo $res; |
|
| 101 | + exit(); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | function action_api_transmettre_fail($arg) { |
| 105 | - include_spip('inc/minipres'); |
|
| 106 | - echo minipres(_T('info_acces_interdit'), $arg); |
|
| 107 | - exit; |
|
| 105 | + include_spip('inc/minipres'); |
|
| 106 | + echo minipres(_T('info_acces_interdit'), $arg); |
|
| 107 | + exit; |
|
| 108 | 108 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -43,90 +43,90 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | function _sqlite_init_functions(&$sqlite) { |
| 45 | 45 | |
| 46 | - if (!$sqlite) { |
|
| 47 | - return false; |
|
| 48 | - } |
|
| 46 | + if (!$sqlite) { |
|
| 47 | + return false; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - $fonctions = [ |
|
| 52 | - // A |
|
| 53 | - 'ACOS' => ['acos', 1], |
|
| 54 | - 'ASIN' => ['asin', 1], |
|
| 55 | - 'ATAN' => ['atan', 1], // mysql accepte 2 params comme atan2… hum ? |
|
| 56 | - 'ATAN2' => ['atan2', 2], |
|
| 51 | + $fonctions = [ |
|
| 52 | + // A |
|
| 53 | + 'ACOS' => ['acos', 1], |
|
| 54 | + 'ASIN' => ['asin', 1], |
|
| 55 | + 'ATAN' => ['atan', 1], // mysql accepte 2 params comme atan2… hum ? |
|
| 56 | + 'ATAN2' => ['atan2', 2], |
|
| 57 | 57 | |
| 58 | - // C |
|
| 59 | - 'CEIL' => ['_sqlite_func_ceil', 1], |
|
| 60 | - 'CONCAT' => ['_sqlite_func_concat', -1], |
|
| 61 | - 'COS' => ['cos', 1], |
|
| 58 | + // C |
|
| 59 | + 'CEIL' => ['_sqlite_func_ceil', 1], |
|
| 60 | + 'CONCAT' => ['_sqlite_func_concat', -1], |
|
| 61 | + 'COS' => ['cos', 1], |
|
| 62 | 62 | |
| 63 | - // D |
|
| 64 | - 'DATE_FORMAT' => ['_sqlite_func_date_format', 2], // équivalent a strftime avec args inversés |
|
| 65 | - 'DAYOFMONTH' => ['_sqlite_func_dayofmonth', 1], |
|
| 66 | - 'DEGREES' => ['rad2deg', 1], |
|
| 63 | + // D |
|
| 64 | + 'DATE_FORMAT' => ['_sqlite_func_date_format', 2], // équivalent a strftime avec args inversés |
|
| 65 | + 'DAYOFMONTH' => ['_sqlite_func_dayofmonth', 1], |
|
| 66 | + 'DEGREES' => ['rad2deg', 1], |
|
| 67 | 67 | |
| 68 | - // E |
|
| 69 | - 'EXTRAIRE_MULTI' => ['_sqlite_func_extraire_multi', 2], // specifique a SPIP/sql_multi() |
|
| 70 | - 'EXP' => ['exp', 1], |
|
| 68 | + // E |
|
| 69 | + 'EXTRAIRE_MULTI' => ['_sqlite_func_extraire_multi', 2], // specifique a SPIP/sql_multi() |
|
| 70 | + 'EXP' => ['exp', 1], |
|
| 71 | 71 | |
| 72 | - // F |
|
| 73 | - 'FIND_IN_SET' => ['_sqlite_func_find_in_set', 2], |
|
| 74 | - 'FLOOR' => ['_sqlite_func_floor', 1], |
|
| 72 | + // F |
|
| 73 | + 'FIND_IN_SET' => ['_sqlite_func_find_in_set', 2], |
|
| 74 | + 'FLOOR' => ['_sqlite_func_floor', 1], |
|
| 75 | 75 | |
| 76 | - // G |
|
| 77 | - 'GREATEST' => ['_sqlite_func_greatest', -1], |
|
| 76 | + // G |
|
| 77 | + 'GREATEST' => ['_sqlite_func_greatest', -1], |
|
| 78 | 78 | |
| 79 | - // I |
|
| 80 | - 'IF' => ['_sqlite_func_if', 3], |
|
| 81 | - 'INSERT' => ['_sqlite_func_insert', 4], |
|
| 82 | - 'INSTR' => ['_sqlite_func_instr', 2], |
|
| 79 | + // I |
|
| 80 | + 'IF' => ['_sqlite_func_if', 3], |
|
| 81 | + 'INSERT' => ['_sqlite_func_insert', 4], |
|
| 82 | + 'INSTR' => ['_sqlite_func_instr', 2], |
|
| 83 | 83 | |
| 84 | - // L |
|
| 85 | - 'LEAST' => ['_sqlite_func_least', -1], |
|
| 86 | - '_LEFT' => ['_sqlite_func_left', 2], |
|
| 84 | + // L |
|
| 85 | + 'LEAST' => ['_sqlite_func_least', -1], |
|
| 86 | + '_LEFT' => ['_sqlite_func_left', 2], |
|
| 87 | 87 | |
| 88 | - // N |
|
| 89 | - 'NOW' => ['_sqlite_func_now', 0], |
|
| 88 | + // N |
|
| 89 | + 'NOW' => ['_sqlite_func_now', 0], |
|
| 90 | 90 | |
| 91 | - // M |
|
| 92 | - 'MD5' => ['md5', 1], |
|
| 93 | - 'MONTH' => ['_sqlite_func_month', 1], |
|
| 91 | + // M |
|
| 92 | + 'MD5' => ['md5', 1], |
|
| 93 | + 'MONTH' => ['_sqlite_func_month', 1], |
|
| 94 | 94 | |
| 95 | - // P |
|
| 96 | - 'PREG_REPLACE' => ['_sqlite_func_preg_replace', 3], |
|
| 95 | + // P |
|
| 96 | + 'PREG_REPLACE' => ['_sqlite_func_preg_replace', 3], |
|
| 97 | 97 | |
| 98 | - // R |
|
| 99 | - 'RADIANS' => ['deg2rad', 1], |
|
| 100 | - 'RAND' => ['_sqlite_func_rand', 0], // sinon random() v2.4 |
|
| 101 | - 'REGEXP' => ['_sqlite_func_regexp_match', 2], // critere REGEXP supporte a partir de v3.3.2 |
|
| 102 | - 'RIGHT' => ['_sqlite_func_right', 2], |
|
| 98 | + // R |
|
| 99 | + 'RADIANS' => ['deg2rad', 1], |
|
| 100 | + 'RAND' => ['_sqlite_func_rand', 0], // sinon random() v2.4 |
|
| 101 | + 'REGEXP' => ['_sqlite_func_regexp_match', 2], // critere REGEXP supporte a partir de v3.3.2 |
|
| 102 | + 'RIGHT' => ['_sqlite_func_right', 2], |
|
| 103 | 103 | |
| 104 | - // S |
|
| 105 | - 'SETTYPE' => ['settype', 2], // CAST present en v3.2.3 |
|
| 106 | - 'SIN' => ['sin', 1], |
|
| 107 | - 'SQRT' => ['sqrt', 1], |
|
| 108 | - 'SUBSTRING' => ['_sqlite_func_substring' /*, 3*/], // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0 |
|
| 104 | + // S |
|
| 105 | + 'SETTYPE' => ['settype', 2], // CAST present en v3.2.3 |
|
| 106 | + 'SIN' => ['sin', 1], |
|
| 107 | + 'SQRT' => ['sqrt', 1], |
|
| 108 | + 'SUBSTRING' => ['_sqlite_func_substring' /*, 3*/], // peut etre appelee avec 2 ou 3 arguments, index base 1 et non 0 |
|
| 109 | 109 | |
| 110 | - // T |
|
| 111 | - 'TAN' => ['tan', 1], |
|
| 112 | - 'TIMESTAMPDIFF' => ['_sqlite_timestampdiff' /*, 3*/], |
|
| 113 | - 'TO_DAYS' => ['_sqlite_func_to_days', 1], |
|
| 110 | + // T |
|
| 111 | + 'TAN' => ['tan', 1], |
|
| 112 | + 'TIMESTAMPDIFF' => ['_sqlite_timestampdiff' /*, 3*/], |
|
| 113 | + 'TO_DAYS' => ['_sqlite_func_to_days', 1], |
|
| 114 | 114 | |
| 115 | - // U |
|
| 116 | - 'UNIX_TIMESTAMP' => ['_sqlite_func_unix_timestamp', 1], |
|
| 115 | + // U |
|
| 116 | + 'UNIX_TIMESTAMP' => ['_sqlite_func_unix_timestamp', 1], |
|
| 117 | 117 | |
| 118 | - // V |
|
| 119 | - 'VIDE' => ['_sqlite_func_vide', 0], // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide() |
|
| 118 | + // V |
|
| 119 | + 'VIDE' => ['_sqlite_func_vide', 0], // du vide pour SELECT 0 as x ... ORDER BY x -> ORDER BY vide() |
|
| 120 | 120 | |
| 121 | - // Y |
|
| 122 | - 'YEAR' => ['_sqlite_func_year', 1] |
|
| 123 | - ]; |
|
| 121 | + // Y |
|
| 122 | + 'YEAR' => ['_sqlite_func_year', 1] |
|
| 123 | + ]; |
|
| 124 | 124 | |
| 125 | - foreach ($fonctions as $f => $r) { |
|
| 126 | - _sqlite_add_function($sqlite, $f, $r); |
|
| 127 | - } |
|
| 125 | + foreach ($fonctions as $f => $r) { |
|
| 126 | + _sqlite_add_function($sqlite, $f, $r); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - #spip_log('functions sqlite chargees ','sqlite.'._LOG_DEBUG); |
|
| 129 | + #spip_log('functions sqlite chargees ','sqlite.'._LOG_DEBUG); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | **/ |
| 149 | 149 | function _sqlite_add_function(&$sqlite, &$f, &$r) { |
| 150 | - isset($r[1]) |
|
| 151 | - ? $sqlite->sqliteCreateFunction($f, $r[0], $r[1]) |
|
| 152 | - : $sqlite->sqliteCreateFunction($f, $r[0]); |
|
| 150 | + isset($r[1]) |
|
| 151 | + ? $sqlite->sqliteCreateFunction($f, $r[0], $r[1]) |
|
| 152 | + : $sqlite->sqliteCreateFunction($f, $r[0]); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @return int |
| 160 | 160 | */ |
| 161 | 161 | function _sqlite_func_ceil($a) { |
| 162 | - return ceil($a); |
|
| 162 | + return ceil($a); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * @return string |
| 170 | 170 | */ |
| 171 | 171 | function _sqlite_func_concat(...$args) { |
| 172 | - return join('', $args); |
|
| 172 | + return join('', $args); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @return string |
| 183 | 183 | */ |
| 184 | 184 | function _sqlite_func_dayofmonth($d) { |
| 185 | - return _sqlite_func_date('d', $d); |
|
| 185 | + return _sqlite_func_date('d', $d); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | |
@@ -194,15 +194,15 @@ discard block |
||
| 194 | 194 | * @return int |
| 195 | 195 | */ |
| 196 | 196 | function _sqlite_func_find_in_set($num, $set) { |
| 197 | - $rank = 0; |
|
| 198 | - foreach (explode(',', $set) as $v) { |
|
| 199 | - if ($v == $num) { |
|
| 200 | - return (++$rank); |
|
| 201 | - } |
|
| 202 | - $rank++; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return 0; |
|
| 197 | + $rank = 0; |
|
| 198 | + foreach (explode(',', $set) as $v) { |
|
| 199 | + if ($v == $num) { |
|
| 200 | + return (++$rank); |
|
| 201 | + } |
|
| 202 | + $rank++; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return 0; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * @return int |
| 213 | 213 | */ |
| 214 | 214 | function _sqlite_func_floor($a) { |
| 215 | - return floor($a); |
|
| 215 | + return floor($a); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @return mixed |
| 226 | 226 | */ |
| 227 | 227 | function _sqlite_func_if($bool, $oui, $non) { |
| 228 | - return ($bool) ? $oui : $non; |
|
| 228 | + return ($bool) ? $oui : $non; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | |
@@ -242,10 +242,10 @@ discard block |
||
| 242 | 242 | * @return string |
| 243 | 243 | */ |
| 244 | 244 | function _sqlite_func_insert($s, $index, $longueur, $chaine) { |
| 245 | - return |
|
| 246 | - substr($s, 0, $index) |
|
| 247 | - . $chaine |
|
| 248 | - . substr(substr($s, $index), $longueur); |
|
| 245 | + return |
|
| 246 | + substr($s, 0, $index) |
|
| 247 | + . $chaine |
|
| 248 | + . substr(substr($s, $index), $longueur); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @return int |
| 258 | 258 | */ |
| 259 | 259 | function _sqlite_func_instr($s, $search) { |
| 260 | - return strpos($s, $search); |
|
| 260 | + return strpos($s, $search); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * @return int |
| 269 | 269 | */ |
| 270 | 270 | function _sqlite_func_least(...$args) { |
| 271 | - return min($args); |
|
| 271 | + return min($args); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * @return int |
| 280 | 280 | */ |
| 281 | 281 | function _sqlite_func_greatest(...$args) { |
| 282 | - return max($args); |
|
| 282 | + return max($args); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * @return string |
| 292 | 292 | */ |
| 293 | 293 | function _sqlite_func_left($s, $lenght) { |
| 294 | - return substr($s, $lenght); |
|
| 294 | + return substr($s, $lenght); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -301,13 +301,13 @@ discard block |
||
| 301 | 301 | * @return string |
| 302 | 302 | */ |
| 303 | 303 | function _sqlite_func_now($force_refresh = false) { |
| 304 | - static $now = null; |
|
| 305 | - if (is_null($now) or $force_refresh) { |
|
| 306 | - $now = date('Y-m-d H:i:s'); |
|
| 307 | - } |
|
| 304 | + static $now = null; |
|
| 305 | + if (is_null($now) or $force_refresh) { |
|
| 306 | + $now = date('Y-m-d H:i:s'); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - #spip_log("Passage avec NOW : $now | ".time(),'sqlite.'._LOG_DEBUG); |
|
| 310 | - return $now; |
|
| 309 | + #spip_log("Passage avec NOW : $now | ".time(),'sqlite.'._LOG_DEBUG); |
|
| 310 | + return $now; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | * @return string |
| 321 | 321 | */ |
| 322 | 322 | function _sqlite_func_month($d) { |
| 323 | - return _sqlite_func_date('m', $d); |
|
| 323 | + return _sqlite_func_date('m', $d); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | |
@@ -333,10 +333,10 @@ discard block |
||
| 333 | 333 | * @return string |
| 334 | 334 | */ |
| 335 | 335 | function _sqlite_func_preg_replace($quoi, $cherche, $remplace) { |
| 336 | - $return = preg_replace('%' . $cherche . '%', $remplace, $quoi); |
|
| 336 | + $return = preg_replace('%' . $cherche . '%', $remplace, $quoi); |
|
| 337 | 337 | |
| 338 | - #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 339 | - return $return; |
|
| 338 | + #spip_log("preg_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 339 | + return $return; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -349,13 +349,13 @@ discard block |
||
| 349 | 349 | * @return string, l'extrait trouve. |
| 350 | 350 | **/ |
| 351 | 351 | function _sqlite_func_extraire_multi($quoi, $lang) { |
| 352 | - if (strpos($quoi, '<')) { |
|
| 353 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 354 | - include_spip("src/Texte/Collecteur/Multis"); |
|
| 355 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 356 | - $quoi = $collecteurMultis->traiter($quoi, ['lang' => $lang, 'appliquer_typo' => false]); |
|
| 357 | - } |
|
| 358 | - return $quoi; |
|
| 352 | + if (strpos($quoi, '<')) { |
|
| 353 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 354 | + include_spip("src/Texte/Collecteur/Multis"); |
|
| 355 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 356 | + $quoi = $collecteurMultis->traiter($quoi, ['lang' => $lang, 'appliquer_typo' => false]); |
|
| 357 | + } |
|
| 358 | + return $quoi; |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | * @return float |
| 366 | 366 | */ |
| 367 | 367 | function _sqlite_func_rand() { |
| 368 | - return random_int(0, mt_getrandmax()); |
|
| 368 | + return random_int(0, mt_getrandmax()); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | * @return string |
| 378 | 378 | */ |
| 379 | 379 | function _sqlite_func_right($s, $length) { |
| 380 | - return substr($s, 0 - $length); |
|
| 380 | + return substr($s, 0 - $length); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | |
@@ -389,17 +389,17 @@ discard block |
||
| 389 | 389 | * @return bool |
| 390 | 390 | */ |
| 391 | 391 | function _sqlite_func_regexp_match($cherche, $quoi) { |
| 392 | - // optimiser un cas tres courant avec les requetes en base |
|
| 393 | - if (!$quoi and !strlen($quoi)) { |
|
| 394 | - return false; |
|
| 395 | - } |
|
| 396 | - // il faut enlever un niveau d'echappement pour être homogène à mysql |
|
| 397 | - $cherche = str_replace('\\\\', '\\', $cherche); |
|
| 398 | - $u = $GLOBALS['meta']['pcre_u'] ?? 'u'; |
|
| 399 | - $return = preg_match('%' . $cherche . '%imsS' . $u, $quoi); |
|
| 400 | - |
|
| 401 | - #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 402 | - return $return; |
|
| 392 | + // optimiser un cas tres courant avec les requetes en base |
|
| 393 | + if (!$quoi and !strlen($quoi)) { |
|
| 394 | + return false; |
|
| 395 | + } |
|
| 396 | + // il faut enlever un niveau d'echappement pour être homogène à mysql |
|
| 397 | + $cherche = str_replace('\\\\', '\\', $cherche); |
|
| 398 | + $u = $GLOBALS['meta']['pcre_u'] ?? 'u'; |
|
| 399 | + $return = preg_match('%' . $cherche . '%imsS' . $u, $quoi); |
|
| 400 | + |
|
| 401 | + #spip_log("regexp_replace : $quoi, $cherche, $remplace, $return",'sqlite.'._LOG_DEBUG); |
|
| 402 | + return $return; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
@@ -414,8 +414,8 @@ discard block |
||
| 414 | 414 | * @return string |
| 415 | 415 | */ |
| 416 | 416 | function _sqlite_func_date_format($date, $conv) { |
| 417 | - $conv = _sqlite_func_strftime_format_converter($conv); |
|
| 418 | - return strftime($conv, is_int($date) ? $date : strtotime($date)); |
|
| 417 | + $conv = _sqlite_func_strftime_format_converter($conv); |
|
| 418 | + return strftime($conv, is_int($date) ? $date : strtotime($date)); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | /** |
@@ -431,28 +431,28 @@ discard block |
||
| 431 | 431 | * @return void |
| 432 | 432 | */ |
| 433 | 433 | function _sqlite_func_strftime_format_converter(string $conv): string { |
| 434 | - // ok : %a %b %d %e %H %I %l %j %k %m %p %r %S %T %w %y %Y |
|
| 435 | - // on ne sait pas en gérer certains... |
|
| 436 | - static $mysql_to_strftime_not_ok = ['%c', '%D', '%f', '%U', '%V', '%W', '%X']; |
|
| 437 | - static $mysql_to_strftime = [ |
|
| 438 | - '%h' => '%I', |
|
| 439 | - '%i' => '%M', |
|
| 440 | - '%M' => '%B', |
|
| 441 | - '%s' => '%S', |
|
| 442 | - '%u' => '%U', |
|
| 443 | - '%v' => '%V', |
|
| 444 | - '%x' => '%G', |
|
| 445 | - ]; |
|
| 446 | - static $to_strftime = []; |
|
| 447 | - if (!isset($to_strftime[$conv])) { |
|
| 448 | - $count = 0; |
|
| 449 | - str_replace($mysql_to_strftime_not_ok, '', $conv, $count); |
|
| 450 | - if ($count > 0) { |
|
| 451 | - spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR); |
|
| 452 | - } |
|
| 453 | - $to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv); |
|
| 454 | - } |
|
| 455 | - return $to_strftime[$conv]; |
|
| 434 | + // ok : %a %b %d %e %H %I %l %j %k %m %p %r %S %T %w %y %Y |
|
| 435 | + // on ne sait pas en gérer certains... |
|
| 436 | + static $mysql_to_strftime_not_ok = ['%c', '%D', '%f', '%U', '%V', '%W', '%X']; |
|
| 437 | + static $mysql_to_strftime = [ |
|
| 438 | + '%h' => '%I', |
|
| 439 | + '%i' => '%M', |
|
| 440 | + '%M' => '%B', |
|
| 441 | + '%s' => '%S', |
|
| 442 | + '%u' => '%U', |
|
| 443 | + '%v' => '%V', |
|
| 444 | + '%x' => '%G', |
|
| 445 | + ]; |
|
| 446 | + static $to_strftime = []; |
|
| 447 | + if (!isset($to_strftime[$conv])) { |
|
| 448 | + $count = 0; |
|
| 449 | + str_replace($mysql_to_strftime_not_ok, '', $conv, $count); |
|
| 450 | + if ($count > 0) { |
|
| 451 | + spip_log("DATE_FORMAT : At least one parameter can't be parsed by strftime with format '$conv'", 'sqlite.' . _LOG_ERREUR); |
|
| 452 | + } |
|
| 453 | + $to_strftime[$conv] = str_replace(array_keys($mysql_to_strftime), $mysql_to_strftime, $conv); |
|
| 454 | + } |
|
| 455 | + return $to_strftime[$conv]; |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | /** |
@@ -466,11 +466,11 @@ discard block |
||
| 466 | 466 | * @return int |
| 467 | 467 | */ |
| 468 | 468 | function _sqlite_func_to_days($d) { |
| 469 | - static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
|
| 470 | - $result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 469 | + static $offset = 719528; // nb de jour entre 0000-00-00 et timestamp 0=1970-01-01 |
|
| 470 | + $result = $offset + (int)ceil(_sqlite_func_unix_timestamp($d) / (24 * 3600)); |
|
| 471 | 471 | |
| 472 | - #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
|
| 473 | - return $result; |
|
| 472 | + #spip_log("Passage avec TO_DAYS : $d, $result",'sqlite.'._LOG_DEBUG); |
|
| 473 | + return $result; |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | /** |
@@ -482,13 +482,13 @@ discard block |
||
| 482 | 482 | * @return string |
| 483 | 483 | */ |
| 484 | 484 | function _sqlite_func_substring($string, $start, $len = null) { |
| 485 | - // SQL compte a partir de 1, php a partir de 0 |
|
| 486 | - $start = ($start > 0) ? $start - 1 : $start; |
|
| 487 | - if (is_null($len)) { |
|
| 488 | - return substr($string, $start); |
|
| 489 | - } else { |
|
| 490 | - return substr($string, $start, $len); |
|
| 491 | - } |
|
| 485 | + // SQL compte a partir de 1, php a partir de 0 |
|
| 486 | + $start = ($start > 0) ? $start - 1 : $start; |
|
| 487 | + if (is_null($len)) { |
|
| 488 | + return substr($string, $start); |
|
| 489 | + } else { |
|
| 490 | + return substr($string, $start, $len); |
|
| 491 | + } |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | /** |
@@ -504,33 +504,33 @@ discard block |
||
| 504 | 504 | * @return int |
| 505 | 505 | */ |
| 506 | 506 | function _sqlite_timestampdiff($unit, $date1, $date2) { |
| 507 | - $d1 = date_create($date1); |
|
| 508 | - $d2 = date_create($date2); |
|
| 509 | - $diff = date_diff($d1, $d2); |
|
| 510 | - $inv = $diff->invert ? -1 : 1; |
|
| 511 | - switch ($unit) { |
|
| 512 | - case 'YEAR': |
|
| 513 | - return $inv * $diff->y; |
|
| 514 | - case 'QUARTER': |
|
| 515 | - return $inv * (4 * $diff->y + intval(floor($diff->m / 3))); |
|
| 516 | - case 'MONTH': |
|
| 517 | - return $inv * (12 * $diff->y + $diff->m); |
|
| 518 | - case 'WEEK': |
|
| 519 | - return $inv * intval(floor($diff->days / 7)); |
|
| 520 | - case 'DAY': |
|
| 521 | - #var_dump($inv*$diff->days); |
|
| 522 | - return $inv * $diff->days; |
|
| 523 | - case 'HOUR': |
|
| 524 | - return $inv * (24 * $diff->days + $diff->h); |
|
| 525 | - case 'MINUTE': |
|
| 526 | - return $inv * ((24 * $diff->days + $diff->h) * 60 + $diff->i); |
|
| 527 | - case 'SECOND': |
|
| 528 | - return $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s); |
|
| 529 | - case 'MICROSECOND': |
|
| 530 | - return $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s) * 1_000_000; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - return 0; |
|
| 507 | + $d1 = date_create($date1); |
|
| 508 | + $d2 = date_create($date2); |
|
| 509 | + $diff = date_diff($d1, $d2); |
|
| 510 | + $inv = $diff->invert ? -1 : 1; |
|
| 511 | + switch ($unit) { |
|
| 512 | + case 'YEAR': |
|
| 513 | + return $inv * $diff->y; |
|
| 514 | + case 'QUARTER': |
|
| 515 | + return $inv * (4 * $diff->y + intval(floor($diff->m / 3))); |
|
| 516 | + case 'MONTH': |
|
| 517 | + return $inv * (12 * $diff->y + $diff->m); |
|
| 518 | + case 'WEEK': |
|
| 519 | + return $inv * intval(floor($diff->days / 7)); |
|
| 520 | + case 'DAY': |
|
| 521 | + #var_dump($inv*$diff->days); |
|
| 522 | + return $inv * $diff->days; |
|
| 523 | + case 'HOUR': |
|
| 524 | + return $inv * (24 * $diff->days + $diff->h); |
|
| 525 | + case 'MINUTE': |
|
| 526 | + return $inv * ((24 * $diff->days + $diff->h) * 60 + $diff->i); |
|
| 527 | + case 'SECOND': |
|
| 528 | + return $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s); |
|
| 529 | + case 'MICROSECOND': |
|
| 530 | + return $inv * (((24 * $diff->days + $diff->h) * 60 + $diff->i) * 60 + $diff->s) * 1_000_000; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + return 0; |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** |
@@ -540,24 +540,24 @@ discard block |
||
| 540 | 540 | * @return int |
| 541 | 541 | */ |
| 542 | 542 | function _sqlite_func_unix_timestamp($d) { |
| 543 | - static $mem = []; |
|
| 544 | - static $n = 0; |
|
| 545 | - if (isset($mem[$d])) { |
|
| 546 | - return $mem[$d]; |
|
| 547 | - } |
|
| 548 | - if ($n++ > 100) { |
|
| 549 | - $mem = []; |
|
| 550 | - $n = 0; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - //2005-12-02 20:53:53 |
|
| 554 | - #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG); |
|
| 555 | - if (!$d) { |
|
| 556 | - return $mem[$d] = time(); |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - // une pile plus grosse n'accelere pas le calcul |
|
| 560 | - return $mem[$d] = strtotime($d); |
|
| 543 | + static $mem = []; |
|
| 544 | + static $n = 0; |
|
| 545 | + if (isset($mem[$d])) { |
|
| 546 | + return $mem[$d]; |
|
| 547 | + } |
|
| 548 | + if ($n++ > 100) { |
|
| 549 | + $mem = []; |
|
| 550 | + $n = 0; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + //2005-12-02 20:53:53 |
|
| 554 | + #spip_log("Passage avec UNIX_TIMESTAMP : $d",'sqlite.'._LOG_DEBUG); |
|
| 555 | + if (!$d) { |
|
| 556 | + return $mem[$d] = time(); |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + // une pile plus grosse n'accelere pas le calcul |
|
| 560 | + return $mem[$d] = strtotime($d); |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | * @return string |
| 571 | 571 | */ |
| 572 | 572 | function _sqlite_func_year($d) { |
| 573 | - return _sqlite_func_date('Y', $d); |
|
| 573 | + return _sqlite_func_date('Y', $d); |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -583,20 +583,20 @@ discard block |
||
| 583 | 583 | * @return string |
| 584 | 584 | */ |
| 585 | 585 | function _sqlite_func_date($quoi, $d) { |
| 586 | - static $mem = []; |
|
| 587 | - static $n = 0; |
|
| 588 | - if (isset($mem[$d])) { |
|
| 589 | - return $mem[$d][$quoi]; |
|
| 590 | - } |
|
| 591 | - if ($n++ > 100) { |
|
| 592 | - $mem = []; |
|
| 593 | - $n = 0; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - $dec = date('Y-m-d', _sqlite_func_unix_timestamp($d)); |
|
| 597 | - $mem[$d] = ['Y' => substr($dec, 0, 4), 'm' => substr($dec, 5, 2), 'd' => substr($dec, 8, 2)]; |
|
| 598 | - |
|
| 599 | - return $mem[$d][$quoi]; |
|
| 586 | + static $mem = []; |
|
| 587 | + static $n = 0; |
|
| 588 | + if (isset($mem[$d])) { |
|
| 589 | + return $mem[$d][$quoi]; |
|
| 590 | + } |
|
| 591 | + if ($n++ > 100) { |
|
| 592 | + $mem = []; |
|
| 593 | + $n = 0; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + $dec = date('Y-m-d', _sqlite_func_unix_timestamp($d)); |
|
| 597 | + $mem[$d] = ['Y' => substr($dec, 0, 4), 'm' => substr($dec, 5, 2), 'd' => substr($dec, 8, 2)]; |
|
| 598 | + |
|
| 599 | + return $mem[$d][$quoi]; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | /** |
@@ -605,5 +605,5 @@ discard block |
||
| 605 | 605 | * @return void |
| 606 | 606 | */ |
| 607 | 607 | function _sqlite_func_vide() { |
| 608 | - return; |
|
| 608 | + return; |
|
| 609 | 609 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('public/decompiler'); |
@@ -68,133 +68,133 @@ discard block |
||
| 68 | 68 | * - true si $opt 'erreurs' = 'reset' |
| 69 | 69 | **/ |
| 70 | 70 | function public_debusquer_dist($message = '', $lieu = '', $opt = []) { |
| 71 | - static $should_log; |
|
| 72 | - static $tableau_des_erreurs = []; |
|
| 73 | - |
|
| 74 | - // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 75 | - if (isset($opt['erreurs'])) { |
|
| 76 | - if ($opt['erreurs'] == 'get') { |
|
| 77 | - return $tableau_des_erreurs; |
|
| 78 | - } |
|
| 79 | - if ($opt['erreurs'] == 'reset') { |
|
| 80 | - $tableau_des_erreurs = []; |
|
| 81 | - |
|
| 82 | - return true; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if (is_null($should_log)) { |
|
| 87 | - $should_log = (empty($GLOBALS['visiteur_session']) || !include_spip('inc/autoriser') || !autoriser('debug')); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - // Erreur ou appel final ? |
|
| 91 | - if ($message) { |
|
| 92 | - $message = debusquer_compose_message($message); |
|
| 93 | - $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 94 | - set_request('var_mode', 'debug'); |
|
| 95 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 96 | - // Permettre a la compil de continuer |
|
| 97 | - if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 98 | - $lieu->code = "''"; |
|
| 99 | - } |
|
| 100 | - // loger si personne ne verra l'erreur |
|
| 101 | - if ($should_log) { |
|
| 102 | - debusquer_loger_erreur($message, $lieu); |
|
| 103 | - } |
|
| 104 | - // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 105 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and (is_countable($tableau_des_erreurs) ? count($tableau_des_erreurs) : 0) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 106 | - if (!$urgence) { |
|
| 107 | - return; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 111 | - // espace public ? |
|
| 112 | - if (isset($GLOBALS['fond'])) { |
|
| 113 | - $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - include_spip('inc/autoriser'); |
|
| 118 | - if (!autoriser('debug')) { |
|
| 119 | - return; |
|
| 120 | - } |
|
| 121 | - include_spip('inc/headers'); |
|
| 122 | - include_spip('inc/filtres'); |
|
| 123 | - |
|
| 124 | - lang_select($GLOBALS['visiteur_session']['lang'] ?? null); |
|
| 125 | - $fonc = preg_replace(',\W,', '_', _request('var_mode_objet') ?? ''); |
|
| 126 | - $mode = preg_replace(',\W,', '_', _request('var_mode_affiche') ?? ''); |
|
| 127 | - |
|
| 128 | - $self = str_replace("\\'", ''', self()); |
|
| 129 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 130 | - |
|
| 131 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 132 | - . '<br />' |
|
| 133 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 134 | - |
|
| 135 | - if (!_DIR_RESTREINT or headers_sent()) { |
|
| 136 | - return $res; |
|
| 137 | - } |
|
| 138 | - if ($tableau_des_erreurs) { |
|
| 139 | - http_response_code(503); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - http_no_cache(); |
|
| 143 | - if (isset($_GET['var_profile'])) { |
|
| 144 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 145 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 146 | - } else { |
|
| 147 | - if (!$fonc) { |
|
| 148 | - $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 149 | - } |
|
| 150 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 151 | - } |
|
| 152 | - if ($message === false) { |
|
| 153 | - lang_select(); |
|
| 154 | - |
|
| 155 | - return debusquer_entete($titre, $res); |
|
| 156 | - } else { |
|
| 157 | - echo debusquer_entete($titre, $res); |
|
| 158 | - } |
|
| 159 | - exit; |
|
| 71 | + static $should_log; |
|
| 72 | + static $tableau_des_erreurs = []; |
|
| 73 | + |
|
| 74 | + // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 75 | + if (isset($opt['erreurs'])) { |
|
| 76 | + if ($opt['erreurs'] == 'get') { |
|
| 77 | + return $tableau_des_erreurs; |
|
| 78 | + } |
|
| 79 | + if ($opt['erreurs'] == 'reset') { |
|
| 80 | + $tableau_des_erreurs = []; |
|
| 81 | + |
|
| 82 | + return true; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if (is_null($should_log)) { |
|
| 87 | + $should_log = (empty($GLOBALS['visiteur_session']) || !include_spip('inc/autoriser') || !autoriser('debug')); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + // Erreur ou appel final ? |
|
| 91 | + if ($message) { |
|
| 92 | + $message = debusquer_compose_message($message); |
|
| 93 | + $tableau_des_erreurs[] = [$message, $lieu]; |
|
| 94 | + set_request('var_mode', 'debug'); |
|
| 95 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 96 | + // Permettre a la compil de continuer |
|
| 97 | + if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 98 | + $lieu->code = "''"; |
|
| 99 | + } |
|
| 100 | + // loger si personne ne verra l'erreur |
|
| 101 | + if ($should_log) { |
|
| 102 | + debusquer_loger_erreur($message, $lieu); |
|
| 103 | + } |
|
| 104 | + // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 105 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and (is_countable($tableau_des_erreurs) ? count($tableau_des_erreurs) : 0) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 106 | + if (!$urgence) { |
|
| 107 | + return; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 111 | + // espace public ? |
|
| 112 | + if (isset($GLOBALS['fond'])) { |
|
| 113 | + $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + include_spip('inc/autoriser'); |
|
| 118 | + if (!autoriser('debug')) { |
|
| 119 | + return; |
|
| 120 | + } |
|
| 121 | + include_spip('inc/headers'); |
|
| 122 | + include_spip('inc/filtres'); |
|
| 123 | + |
|
| 124 | + lang_select($GLOBALS['visiteur_session']['lang'] ?? null); |
|
| 125 | + $fonc = preg_replace(',\W,', '_', _request('var_mode_objet') ?? ''); |
|
| 126 | + $mode = preg_replace(',\W,', '_', _request('var_mode_affiche') ?? ''); |
|
| 127 | + |
|
| 128 | + $self = str_replace("\\'", ''', self()); |
|
| 129 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 130 | + |
|
| 131 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 132 | + . '<br />' |
|
| 133 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 134 | + |
|
| 135 | + if (!_DIR_RESTREINT or headers_sent()) { |
|
| 136 | + return $res; |
|
| 137 | + } |
|
| 138 | + if ($tableau_des_erreurs) { |
|
| 139 | + http_response_code(503); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + http_no_cache(); |
|
| 143 | + if (isset($_GET['var_profile'])) { |
|
| 144 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 145 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 146 | + } else { |
|
| 147 | + if (!$fonc) { |
|
| 148 | + $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 149 | + } |
|
| 150 | + $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? ' ' . $GLOBALS['debug_objets']['sourcefile'][$fonc] : '')); |
|
| 151 | + } |
|
| 152 | + if ($message === false) { |
|
| 153 | + lang_select(); |
|
| 154 | + |
|
| 155 | + return debusquer_entete($titre, $res); |
|
| 156 | + } else { |
|
| 157 | + echo debusquer_entete($titre, $res); |
|
| 158 | + } |
|
| 159 | + exit; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | function debusquer_compose_message($msg) { |
| 163 | - if (is_array($msg)) { |
|
| 164 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 165 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 166 | - if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 167 | - // message avec argument: instancier |
|
| 168 | - $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 169 | - } else { |
|
| 170 | - // message SQL: interpreter |
|
| 171 | - $msg = debusquer_requete($msg); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 175 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 176 | - $fond = $GLOBALS['fond'] ?? ''; |
|
| 177 | - // une erreur critique sort $message en array |
|
| 178 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 179 | - spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 180 | - |
|
| 181 | - return $msg; |
|
| 163 | + if (is_array($msg)) { |
|
| 164 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 165 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 166 | + if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 167 | + // message avec argument: instancier |
|
| 168 | + $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 169 | + } else { |
|
| 170 | + // message SQL: interpreter |
|
| 171 | + $msg = debusquer_requete($msg); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 175 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 176 | + $fond = $GLOBALS['fond'] ?? ''; |
|
| 177 | + // une erreur critique sort $message en array |
|
| 178 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 179 | + spip_log('Debug: ' . $debug . ' (' . $fond . ')'); |
|
| 180 | + |
|
| 181 | + return $msg; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function debusquer_bandeau($erreurs) { |
| 185 | 185 | |
| 186 | - if (!empty($erreurs)) { |
|
| 187 | - $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 186 | + if (!empty($erreurs)) { |
|
| 187 | + $n = [(is_countable($erreurs) ? count($erreurs) : 0) . ' ' . _T('zbug_erreur_squelette')]; |
|
| 188 | 188 | |
| 189 | - return debusquer_navigation($erreurs, $n); |
|
| 190 | - } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 191 | - include_spip('public/tracer'); |
|
| 192 | - [$temps, $nav] = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 189 | + return debusquer_navigation($erreurs, $n); |
|
| 190 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 191 | + include_spip('public/tracer'); |
|
| 192 | + [$temps, $nav] = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 193 | 193 | |
| 194 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 195 | - } else { |
|
| 196 | - return ''; |
|
| 197 | - } |
|
| 194 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 195 | + } else { |
|
| 196 | + return ''; |
|
| 197 | + } |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -204,63 +204,63 @@ discard block |
||
| 204 | 204 | * @return string Code HTML |
| 205 | 205 | **/ |
| 206 | 206 | function debusquer_contexte($env) { |
| 207 | - if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 208 | - $env = $env_tab; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if (!$env) { |
|
| 212 | - return ''; |
|
| 213 | - } |
|
| 214 | - $res = ''; |
|
| 215 | - foreach ($env as $nom => $valeur) { |
|
| 216 | - if (is_array($valeur)) { |
|
| 217 | - $valeur_simple = []; |
|
| 218 | - foreach ($valeur as $v) { |
|
| 219 | - if (is_array($v)) { |
|
| 220 | - $valeur_simple[] = 'array:' . count($v); |
|
| 221 | - } elseif (is_object($v)) { |
|
| 222 | - $valeur_simple[] = get_class($v); |
|
| 223 | - } elseif (is_string($v)) { |
|
| 224 | - $valeur_simple[] = "'" . $v . "'"; |
|
| 225 | - } else { |
|
| 226 | - $valeur_simple[] = $v; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - $n = count($valeur); |
|
| 230 | - $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 231 | - $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 232 | - } elseif (is_object($valeur)) { |
|
| 233 | - $valeur = get_class($valeur); |
|
| 234 | - } elseif (is_string($valeur)) { |
|
| 235 | - $valeur = "'" . $valeur . "'"; |
|
| 236 | - } |
|
| 237 | - $res .= "\n<tr><td><strong>" . nl2br((string) entites_html($nom)) |
|
| 238 | - . '</strong></td><td>: ' . nl2br((string) entites_html($valeur)) |
|
| 239 | - . "</td></tr>\n"; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 207 | + if (is_string($env) and is_array($env_tab = @unserialize($env))) { |
|
| 208 | + $env = $env_tab; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if (!$env) { |
|
| 212 | + return ''; |
|
| 213 | + } |
|
| 214 | + $res = ''; |
|
| 215 | + foreach ($env as $nom => $valeur) { |
|
| 216 | + if (is_array($valeur)) { |
|
| 217 | + $valeur_simple = []; |
|
| 218 | + foreach ($valeur as $v) { |
|
| 219 | + if (is_array($v)) { |
|
| 220 | + $valeur_simple[] = 'array:' . count($v); |
|
| 221 | + } elseif (is_object($v)) { |
|
| 222 | + $valeur_simple[] = get_class($v); |
|
| 223 | + } elseif (is_string($v)) { |
|
| 224 | + $valeur_simple[] = "'" . $v . "'"; |
|
| 225 | + } else { |
|
| 226 | + $valeur_simple[] = $v; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + $n = count($valeur); |
|
| 230 | + $valeur = (($n > 3) ? 'array:' . $n . ' ' : ''); |
|
| 231 | + $valeur .= '[' . join(', ', $valeur_simple) . ']'; |
|
| 232 | + } elseif (is_object($valeur)) { |
|
| 233 | + $valeur = get_class($valeur); |
|
| 234 | + } elseif (is_string($valeur)) { |
|
| 235 | + $valeur = "'" . $valeur . "'"; |
|
| 236 | + } |
|
| 237 | + $res .= "\n<tr><td><strong>" . nl2br((string) entites_html($nom)) |
|
| 238 | + . '</strong></td><td>: ' . nl2br((string) entites_html($valeur)) |
|
| 239 | + . "</td></tr>\n"; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + return "<div class='spip-env'><fieldset><legend onclick=\"this.parentElement.classList.toggle('expanded');\">#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | |
| 246 | 246 | function debusquer_loger_erreur($msg, $lieu) { |
| 247 | - $boucle = $ligne = $skel = ''; |
|
| 248 | - if (is_object($lieu)) { |
|
| 249 | - $ligne = ($lieu->ligne ?? ''); |
|
| 250 | - $boucle = ($lieu->id_boucle ?? ''); |
|
| 251 | - $skel = ($lieu->descr['sourcefile'] ?? ''); |
|
| 252 | - } |
|
| 253 | - $msg = (is_array($msg) ? implode('', $msg) : $msg); |
|
| 254 | - if ($skel) { |
|
| 255 | - $msg .= " Squelette $skel"; |
|
| 256 | - } |
|
| 257 | - if ($boucle) { |
|
| 258 | - $msg .= " Boucle $boucle"; |
|
| 259 | - } |
|
| 260 | - if ($ligne) { |
|
| 261 | - $msg .= " L$ligne"; |
|
| 262 | - } |
|
| 263 | - spip_log($msg, "debusquer" . _LOG_ERREUR); |
|
| 247 | + $boucle = $ligne = $skel = ''; |
|
| 248 | + if (is_object($lieu)) { |
|
| 249 | + $ligne = ($lieu->ligne ?? ''); |
|
| 250 | + $boucle = ($lieu->id_boucle ?? ''); |
|
| 251 | + $skel = ($lieu->descr['sourcefile'] ?? ''); |
|
| 252 | + } |
|
| 253 | + $msg = (is_array($msg) ? implode('', $msg) : $msg); |
|
| 254 | + if ($skel) { |
|
| 255 | + $msg .= " Squelette $skel"; |
|
| 256 | + } |
|
| 257 | + if ($boucle) { |
|
| 258 | + $msg .= " Boucle $boucle"; |
|
| 259 | + } |
|
| 260 | + if ($ligne) { |
|
| 261 | + $msg .= " L$ligne"; |
|
| 262 | + } |
|
| 263 | + spip_log($msg, "debusquer" . _LOG_ERREUR); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | |
@@ -269,66 +269,66 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | function debusquer_navigation($tableau, $caption = [], $id = 'debug-nav') { |
| 271 | 271 | |
| 272 | - if (_request('exec') == 'valider_xml') { |
|
| 273 | - return ''; |
|
| 274 | - } |
|
| 275 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 276 | - $res = ''; |
|
| 277 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 278 | - foreach ($tableau as $i => $err) { |
|
| 279 | - $boucle = $ligne = $skel = ''; |
|
| 280 | - [$msg, $lieu] = $err; |
|
| 281 | - if (is_object($lieu)) { |
|
| 282 | - $ligne = $lieu->ligne; |
|
| 283 | - $boucle = !empty($lieu->id_boucle) ? $lieu->id_boucle : ''; |
|
| 284 | - if (isset($lieu->descr['nom'])) { |
|
| 285 | - $nom_code = $lieu->descr['nom']; |
|
| 286 | - $skel = $lieu->descr['sourcefile']; |
|
| 287 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 288 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 289 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 290 | - if ($boucle) { |
|
| 291 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 292 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - $j = ($i + 1); |
|
| 298 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 299 | - . $j |
|
| 300 | - . " </td><td style='text-align: left'>" |
|
| 301 | - . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 302 | - . "</td><td style='text-align: left'>" |
|
| 303 | - . ($skel ?: ' / ') |
|
| 304 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 305 | - . ($boucle ?: ' / ') |
|
| 306 | - . "</td><td style='text-align: right'>" |
|
| 307 | - . $ligne |
|
| 308 | - . "</td></tr>\n"; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - return "\n<table id='$id'>" |
|
| 312 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 313 | - . $caption[0] |
|
| 272 | + if (_request('exec') == 'valider_xml') { |
|
| 273 | + return ''; |
|
| 274 | + } |
|
| 275 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 276 | + $res = ''; |
|
| 277 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 278 | + foreach ($tableau as $i => $err) { |
|
| 279 | + $boucle = $ligne = $skel = ''; |
|
| 280 | + [$msg, $lieu] = $err; |
|
| 281 | + if (is_object($lieu)) { |
|
| 282 | + $ligne = $lieu->ligne; |
|
| 283 | + $boucle = !empty($lieu->id_boucle) ? $lieu->id_boucle : ''; |
|
| 284 | + if (isset($lieu->descr['nom'])) { |
|
| 285 | + $nom_code = $lieu->descr['nom']; |
|
| 286 | + $skel = $lieu->descr['sourcefile']; |
|
| 287 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 288 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 289 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 290 | + if ($boucle) { |
|
| 291 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 292 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + $j = ($i + 1); |
|
| 298 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 299 | + . $j |
|
| 300 | + . " </td><td style='text-align: left'>" |
|
| 301 | + . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 302 | + . "</td><td style='text-align: left'>" |
|
| 303 | + . ($skel ?: ' / ') |
|
| 304 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 305 | + . ($boucle ?: ' / ') |
|
| 306 | + . "</td><td style='text-align: right'>" |
|
| 307 | + . $ligne |
|
| 308 | + . "</td></tr>\n"; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + return "\n<table id='$id'>" |
|
| 312 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 313 | + . $caption[0] |
|
| 314 | 314 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 315 | 315 | # aider('erreur_compilation'), |
| 316 | - . '</caption>' |
|
| 317 | - // fausse caption du chrono (mais vraie nav) |
|
| 318 | - . (!empty($caption[1]) ? $caption[1] : '') |
|
| 319 | - . '<tr><th>' |
|
| 320 | - . _T('numero') |
|
| 321 | - . '</th><th>' |
|
| 322 | - . _T('public:message') |
|
| 323 | - . '</th><th>' |
|
| 324 | - . _T('squelette') |
|
| 325 | - . '</th><th>' |
|
| 326 | - . _T('zbug_boucle') |
|
| 327 | - . '</th><th>' |
|
| 328 | - . _T('ligne') |
|
| 329 | - . '</th></tr>' |
|
| 330 | - . $res |
|
| 331 | - . '</table>'; |
|
| 316 | + . '</caption>' |
|
| 317 | + // fausse caption du chrono (mais vraie nav) |
|
| 318 | + . (!empty($caption[1]) ? $caption[1] : '') |
|
| 319 | + . '<tr><th>' |
|
| 320 | + . _T('numero') |
|
| 321 | + . '</th><th>' |
|
| 322 | + . _T('public:message') |
|
| 323 | + . '</th><th>' |
|
| 324 | + . _T('squelette') |
|
| 325 | + . '</th><th>' |
|
| 326 | + . _T('zbug_boucle') |
|
| 327 | + . '</th><th>' |
|
| 328 | + . _T('ligne') |
|
| 329 | + . '</th></tr>' |
|
| 330 | + . $res |
|
| 331 | + . '</table>'; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | |
@@ -348,514 +348,514 @@ discard block |
||
| 348 | 348 | * ou un tableau si l'erreur est critique |
| 349 | 349 | **/ |
| 350 | 350 | function debusquer_requete($message) { |
| 351 | - [$errno, $msg, $query] = $message; |
|
| 352 | - |
|
| 353 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 354 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 355 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 356 | - $errno = $regs[2]; |
|
| 357 | - } elseif ( |
|
| 358 | - is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 359 | - and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 360 | - ) { |
|
| 361 | - $errno = $regs[1]; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - // Erreur systeme |
|
| 365 | - if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 366 | - $retour = '<tt><br /><br /><blink>' |
|
| 367 | - . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 368 | - . "</blink><br />\n<b>" |
|
| 369 | - . _T( |
|
| 370 | - 'info_erreur_systeme2', |
|
| 371 | - ['script' => generer_url_ecrire('base_repair')] |
|
| 372 | - ) |
|
| 373 | - . '</b><br />'; |
|
| 374 | - spip_log("Erreur systeme $errno"); |
|
| 375 | - |
|
| 376 | - return [$retour, '']; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - // Requete erronee |
|
| 380 | - $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 381 | - . spip_htmlspecialchars($msg) |
|
| 382 | - . "\n<br /><span style='color: red'><b>" |
|
| 383 | - . spip_htmlspecialchars($query) |
|
| 384 | - . '</b></span></tt><br />'; |
|
| 385 | - |
|
| 386 | - //. aider('erreur_mysql'); |
|
| 387 | - |
|
| 388 | - return $err; |
|
| 351 | + [$errno, $msg, $query] = $message; |
|
| 352 | + |
|
| 353 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 354 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 355 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 356 | + $errno = $regs[2]; |
|
| 357 | + } elseif ( |
|
| 358 | + is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 359 | + and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 360 | + ) { |
|
| 361 | + $errno = $regs[1]; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + // Erreur systeme |
|
| 365 | + if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 366 | + $retour = '<tt><br /><br /><blink>' |
|
| 367 | + . _T('info_erreur_systeme', ['errsys' => $errno]) |
|
| 368 | + . "</blink><br />\n<b>" |
|
| 369 | + . _T( |
|
| 370 | + 'info_erreur_systeme2', |
|
| 371 | + ['script' => generer_url_ecrire('base_repair')] |
|
| 372 | + ) |
|
| 373 | + . '</b><br />'; |
|
| 374 | + spip_log("Erreur systeme $errno"); |
|
| 375 | + |
|
| 376 | + return [$retour, '']; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + // Requete erronee |
|
| 380 | + $err = '<b>' . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 381 | + . spip_htmlspecialchars($msg) |
|
| 382 | + . "\n<br /><span style='color: red'><b>" |
|
| 383 | + . spip_htmlspecialchars($query) |
|
| 384 | + . '</b></span></tt><br />'; |
|
| 385 | + |
|
| 386 | + //. aider('erreur_mysql'); |
|
| 387 | + |
|
| 388 | + return $err; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | |
| 392 | 392 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = '') { |
| 393 | 393 | |
| 394 | - $id = $nom . $boucle; |
|
| 395 | - if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 396 | - foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 397 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 398 | - $y = substr_count($v[0], "\n"); |
|
| 399 | - } else { |
|
| 400 | - if ($v[1][0] == '#') { // balise dynamique |
|
| 401 | - $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 402 | - } else // inclusion |
|
| 403 | - { |
|
| 404 | - $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 405 | - } |
|
| 406 | - $y = substr_count($incl, "\n") |
|
| 407 | - + substr_count($r[1], "\n") |
|
| 408 | - + substr_count($r[3], "\n"); |
|
| 409 | - } |
|
| 410 | - if ($n <= ($y + $debut)) { |
|
| 411 | - if ($v[1][0] == '?') { |
|
| 412 | - return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 413 | - } elseif ($v[1][0] == '!') { |
|
| 414 | - if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 415 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 420 | - } |
|
| 421 | - $debut += $y; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - return [$nom, $boucle, $n - $debut]; |
|
| 394 | + $id = $nom . $boucle; |
|
| 395 | + if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 396 | + foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 397 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 398 | + $y = substr_count($v[0], "\n"); |
|
| 399 | + } else { |
|
| 400 | + if ($v[1][0] == '#') { // balise dynamique |
|
| 401 | + $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 402 | + } else // inclusion |
|
| 403 | + { |
|
| 404 | + $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 405 | + } |
|
| 406 | + $y = substr_count($incl, "\n") |
|
| 407 | + + substr_count($r[1], "\n") |
|
| 408 | + + substr_count($r[3], "\n"); |
|
| 409 | + } |
|
| 410 | + if ($n <= ($y + $debut)) { |
|
| 411 | + if ($v[1][0] == '?') { |
|
| 412 | + return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 413 | + } elseif ($v[1][0] == '!') { |
|
| 414 | + if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 415 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + return [$nom, $boucle, $v[2] - 1 + $n - $debut]; |
|
| 420 | + } |
|
| 421 | + $debut += $y; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + return [$nom, $boucle, $n - $debut]; |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | function trouve_squelette_inclus($script) { |
| 429 | 429 | |
| 430 | - preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 431 | - // si le script X.php n'est pas ecrire/public.php |
|
| 432 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 433 | - if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 434 | - if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page' |
|
| 435 | - if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 436 | - $reg[1] = 'inconnu'; |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 441 | - |
|
| 442 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 443 | - if (preg_match($incl, $v)) { |
|
| 444 | - return $k; |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - return ''; |
|
| 430 | + preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 431 | + // si le script X.php n'est pas ecrire/public.php |
|
| 432 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 433 | + if ($reg[1] == 'ecrire/public') { // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 434 | + if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) { // a defaut on cherche le param 'page' |
|
| 435 | + if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 436 | + $reg[1] = 'inconnu'; |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 441 | + |
|
| 442 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 443 | + if (preg_match($incl, $v)) { |
|
| 444 | + return $k; |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + return ''; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | function reference_boucle_debug($n, $nom, $self) { |
| 452 | - [$skel, $boucle, $ligne] = trouve_boucle_debug($n, $nom); |
|
| 453 | - |
|
| 454 | - if (!$boucle) { |
|
| 455 | - return !$ligne ? '' : |
|
| 456 | - (' (' . |
|
| 457 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 458 | - _T('squelette_ligne')) . |
|
| 459 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 460 | - } else { |
|
| 461 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 462 | - |
|
| 463 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 464 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 465 | - } |
|
| 452 | + [$skel, $boucle, $ligne] = trouve_boucle_debug($n, $nom); |
|
| 453 | + |
|
| 454 | + if (!$boucle) { |
|
| 455 | + return !$ligne ? '' : |
|
| 456 | + (' (' . |
|
| 457 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 458 | + _T('squelette_ligne')) . |
|
| 459 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 460 | + } else { |
|
| 461 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 462 | + |
|
| 463 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 464 | + " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 465 | + } |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | // affiche un texte avec numero de ligne et ancre. |
| 469 | 469 | |
| 470 | 470 | function ancre_texte($texte, $fautifs = [], $nocpt = false) { |
| 471 | 471 | |
| 472 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 473 | - if ($var_mode_ligne) { |
|
| 474 | - $fautifs[] = [$var_mode_ligne]; |
|
| 475 | - } |
|
| 476 | - $res = ''; |
|
| 477 | - |
|
| 478 | - $s = highlight_string($texte, true); |
|
| 479 | - if (substr($s, 0, 6) == '<code>') { |
|
| 480 | - $s = substr($s, 6); |
|
| 481 | - $res = '<code>'; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - $s = preg_replace( |
|
| 485 | - ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 486 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 487 | - $s |
|
| 488 | - ); |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - $tableau = explode('<br />', $s); |
|
| 492 | - |
|
| 493 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 494 | - |
|
| 495 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 496 | - $formaterr = 'color: red;'; |
|
| 497 | - $i = 1; |
|
| 498 | - $flignes = []; |
|
| 499 | - $loc = [0, 0]; |
|
| 500 | - foreach ($fautifs as $lc) { |
|
| 501 | - if (is_array($lc)) { |
|
| 502 | - $l = array_shift($lc); |
|
| 503 | - $flignes[$l] = $lc; |
|
| 504 | - } else { |
|
| 505 | - $flignes[$lc] = $loc; |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - $ancre = md5($texte); |
|
| 510 | - foreach ($tableau as $ligne) { |
|
| 511 | - if (isset($flignes[$i])) { |
|
| 512 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 513 | - $indexmesg = $flignes[$i][1]; |
|
| 514 | - $err = textebrut($flignes[$i][2]); |
|
| 515 | - // tentative de pointer sur la colonne fautive; |
|
| 516 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 517 | - // $m = $flignes[$i][0]; |
|
| 518 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 519 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 520 | - $bg = $formaterr; |
|
| 521 | - } else { |
|
| 522 | - $indexmesg = $ancre; |
|
| 523 | - $err = $bg = ''; |
|
| 524 | - } |
|
| 525 | - $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 526 | - $i++; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - return "<div id='T$ancre'>" |
|
| 530 | - . '<div onclick="' |
|
| 531 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 532 | - . '" title="' |
|
| 533 | - . _T('masquer_colonne') |
|
| 534 | - . '" style="cursor: pointer;">' |
|
| 535 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 536 | - . '</div> |
|
| 472 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 473 | + if ($var_mode_ligne) { |
|
| 474 | + $fautifs[] = [$var_mode_ligne]; |
|
| 475 | + } |
|
| 476 | + $res = ''; |
|
| 477 | + |
|
| 478 | + $s = highlight_string($texte, true); |
|
| 479 | + if (substr($s, 0, 6) == '<code>') { |
|
| 480 | + $s = substr($s, 6); |
|
| 481 | + $res = '<code>'; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + $s = preg_replace( |
|
| 485 | + ',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 486 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 487 | + $s |
|
| 488 | + ); |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + $tableau = explode('<br />', $s); |
|
| 492 | + |
|
| 493 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 494 | + |
|
| 495 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 496 | + $formaterr = 'color: red;'; |
|
| 497 | + $i = 1; |
|
| 498 | + $flignes = []; |
|
| 499 | + $loc = [0, 0]; |
|
| 500 | + foreach ($fautifs as $lc) { |
|
| 501 | + if (is_array($lc)) { |
|
| 502 | + $l = array_shift($lc); |
|
| 503 | + $flignes[$l] = $lc; |
|
| 504 | + } else { |
|
| 505 | + $flignes[$lc] = $loc; |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + $ancre = md5($texte); |
|
| 510 | + foreach ($tableau as $ligne) { |
|
| 511 | + if (isset($flignes[$i])) { |
|
| 512 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 513 | + $indexmesg = $flignes[$i][1]; |
|
| 514 | + $err = textebrut($flignes[$i][2]); |
|
| 515 | + // tentative de pointer sur la colonne fautive; |
|
| 516 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 517 | + // $m = $flignes[$i][0]; |
|
| 518 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 519 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 520 | + $bg = $formaterr; |
|
| 521 | + } else { |
|
| 522 | + $indexmesg = $ancre; |
|
| 523 | + $err = $bg = ''; |
|
| 524 | + } |
|
| 525 | + $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 526 | + $i++; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + return "<div id='T$ancre'>" |
|
| 530 | + . '<div onclick="' |
|
| 531 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 532 | + . '" title="' |
|
| 533 | + . _T('masquer_colonne') |
|
| 534 | + . '" style="cursor: pointer;">' |
|
| 535 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 536 | + . '</div> |
|
| 537 | 537 | ' . $res . "</div>\n"; |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | // l'environnement graphique du debuggueur |
| 541 | 541 | |
| 542 | 542 | function debusquer_squelette($fonc, $mode, $self) { |
| 543 | - $legend = null; |
|
| 544 | - $texte = ''; |
|
| 545 | - |
|
| 546 | - if ($mode !== 'validation') { |
|
| 547 | - if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 548 | - $res = "<div id='spip-boucles'>\n" |
|
| 549 | - . debusquer_navigation_squelettes($self) |
|
| 550 | - . '</div>'; |
|
| 551 | - } else { |
|
| 552 | - $res = ''; |
|
| 553 | - } |
|
| 554 | - if ($fonc) { |
|
| 555 | - $id = " id='$fonc'"; |
|
| 556 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 557 | - [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
|
| 558 | - $texte .= $res2; |
|
| 559 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 560 | - $legend = _T('zbug_' . $mode); |
|
| 561 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 562 | - $texte = ancre_texte($texte, ['', '']); |
|
| 563 | - } |
|
| 564 | - } else { |
|
| 565 | - if (strlen(trim($res))) { |
|
| 566 | - return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 567 | - } else { |
|
| 568 | - // cas de l'appel sur erreur: montre la page |
|
| 569 | - return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - } else { |
|
| 573 | - $valider = charger_fonction('valider', 'xml'); |
|
| 574 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 575 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 576 | - $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 577 | - [$texte, $err] = emboite_texte($val, $fonc, $self); |
|
| 578 | - if ($err === false) { |
|
| 579 | - $err = _T('impossible'); |
|
| 580 | - } elseif ($err === true) { |
|
| 581 | - $err = _T('correcte'); |
|
| 582 | - } else { |
|
| 583 | - $err = ": $err"; |
|
| 584 | - } |
|
| 585 | - $legend = _T('validation') . ' ' . $err; |
|
| 586 | - $res = $id = ''; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return !trim($texte) ? '' : ( |
|
| 590 | - "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 591 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 592 | - . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 593 | - . ($legend ?: $mode) |
|
| 594 | - . '</a></legend>' |
|
| 595 | - . $texte |
|
| 596 | - . '</fieldset></div>' |
|
| 597 | - . '</div>'); |
|
| 543 | + $legend = null; |
|
| 544 | + $texte = ''; |
|
| 545 | + |
|
| 546 | + if ($mode !== 'validation') { |
|
| 547 | + if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 548 | + $res = "<div id='spip-boucles'>\n" |
|
| 549 | + . debusquer_navigation_squelettes($self) |
|
| 550 | + . '</div>'; |
|
| 551 | + } else { |
|
| 552 | + $res = ''; |
|
| 553 | + } |
|
| 554 | + if ($fonc) { |
|
| 555 | + $id = " id='$fonc'"; |
|
| 556 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 557 | + [$legend, $texte, $res2] = debusquer_source($fonc, $mode); |
|
| 558 | + $texte .= $res2; |
|
| 559 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 560 | + $legend = _T('zbug_' . $mode); |
|
| 561 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 562 | + $texte = ancre_texte($texte, ['', '']); |
|
| 563 | + } |
|
| 564 | + } else { |
|
| 565 | + if (strlen(trim($res))) { |
|
| 566 | + return "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>"; |
|
| 567 | + } else { |
|
| 568 | + // cas de l'appel sur erreur: montre la page |
|
| 569 | + return $GLOBALS['debug_objets']['resultat']['tout'] ?? ''; |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + } else { |
|
| 573 | + $valider = charger_fonction('valider', 'xml'); |
|
| 574 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 575 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 576 | + $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 577 | + [$texte, $err] = emboite_texte($val, $fonc, $self); |
|
| 578 | + if ($err === false) { |
|
| 579 | + $err = _T('impossible'); |
|
| 580 | + } elseif ($err === true) { |
|
| 581 | + $err = _T('correcte'); |
|
| 582 | + } else { |
|
| 583 | + $err = ": $err"; |
|
| 584 | + } |
|
| 585 | + $legend = _T('validation') . ' ' . $err; |
|
| 586 | + $res = $id = ''; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return !trim($texte) ? '' : ( |
|
| 590 | + "<img src='" . chemin_image('debug-xx.svg') . "' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 591 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 592 | + . "<a href='" . $self . '#f_' . substr($fonc, 0, 37) . "'> ↑ " |
|
| 593 | + . ($legend ?: $mode) |
|
| 594 | + . '</a></legend>' |
|
| 595 | + . $texte |
|
| 596 | + . '</fieldset></div>' |
|
| 597 | + . '</div>'); |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | |
| 601 | 601 | function emboite_texte($res, $fonc = '', $self = '') { |
| 602 | - $errs = $res->err; |
|
| 603 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 604 | - |
|
| 605 | - if (!$texte and !$errs) { |
|
| 606 | - return [ancre_texte('', ['', '']), false]; |
|
| 607 | - } |
|
| 608 | - if (!$errs) { |
|
| 609 | - return [ancre_texte($texte, ['', '']), true]; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - if (!isset($GLOBALS['debug_objets'])) { |
|
| 613 | - $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 614 | - $encore = count_occ($errs); |
|
| 615 | - $encore2 = []; |
|
| 616 | - $fautifs = []; |
|
| 617 | - |
|
| 618 | - $err = '<tr><th>' |
|
| 619 | - . _T('numero') |
|
| 620 | - . '</th><th>' |
|
| 621 | - . _T('occurence') |
|
| 622 | - . '</th><th>' |
|
| 623 | - . _T('ligne') |
|
| 624 | - . '</th><th>' |
|
| 625 | - . _T('colonne') |
|
| 626 | - . '</th><th>' |
|
| 627 | - . _T('erreur') |
|
| 628 | - . '</th></tr>'; |
|
| 629 | - |
|
| 630 | - $i = 0; |
|
| 631 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 632 | - foreach ($errs as $r) { |
|
| 633 | - $i++; |
|
| 634 | - [$msg, $ligne, $col] = $r; |
|
| 635 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 636 | - if (isset($encore2[$msg])) { |
|
| 637 | - $ref = ++$encore2[$msg]; |
|
| 638 | - } else { |
|
| 639 | - $encore2[$msg] = $ref = 1; |
|
| 640 | - } |
|
| 641 | - $err .= "<tr style='background-color: " |
|
| 642 | - . $colors[$i % 2] |
|
| 643 | - . "'><td $style><a href='#debut_err'>" |
|
| 644 | - . $i |
|
| 645 | - . "</a></td><td $style>" |
|
| 646 | - . "$ref/$encore[$msg]</td>" |
|
| 647 | - . "<td $style><a href='#L" |
|
| 648 | - . $ligne |
|
| 649 | - . "' id='T$i'>" |
|
| 650 | - . $ligne |
|
| 651 | - . "</a></td><td $style>" |
|
| 652 | - . $col |
|
| 653 | - . "</td><td>$msg</td></tr>\n"; |
|
| 654 | - $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 655 | - } |
|
| 656 | - $err = "<h2 style='text-align: center'>" |
|
| 657 | - . $i |
|
| 658 | - . "<a href='#fin_err'>" |
|
| 659 | - . ' ' . _T('erreur_texte') |
|
| 660 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 661 | - . $err |
|
| 662 | - . " </table><a id='fin_err'></a>"; |
|
| 663 | - |
|
| 664 | - return [ancre_texte($texte, $fautifs), $err]; |
|
| 665 | - } else { |
|
| 666 | - [$msg, $fermant, $ouvrant] = $errs[0]; |
|
| 667 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 668 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 669 | - $err = $msg . |
|
| 670 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 671 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 672 | - |
|
| 673 | - return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 674 | - } |
|
| 602 | + $errs = $res->err; |
|
| 603 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 604 | + |
|
| 605 | + if (!$texte and !$errs) { |
|
| 606 | + return [ancre_texte('', ['', '']), false]; |
|
| 607 | + } |
|
| 608 | + if (!$errs) { |
|
| 609 | + return [ancre_texte($texte, ['', '']), true]; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 613 | + $colors = ['#e0e0f0', '#f8f8ff']; |
|
| 614 | + $encore = count_occ($errs); |
|
| 615 | + $encore2 = []; |
|
| 616 | + $fautifs = []; |
|
| 617 | + |
|
| 618 | + $err = '<tr><th>' |
|
| 619 | + . _T('numero') |
|
| 620 | + . '</th><th>' |
|
| 621 | + . _T('occurence') |
|
| 622 | + . '</th><th>' |
|
| 623 | + . _T('ligne') |
|
| 624 | + . '</th><th>' |
|
| 625 | + . _T('colonne') |
|
| 626 | + . '</th><th>' |
|
| 627 | + . _T('erreur') |
|
| 628 | + . '</th></tr>'; |
|
| 629 | + |
|
| 630 | + $i = 0; |
|
| 631 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 632 | + foreach ($errs as $r) { |
|
| 633 | + $i++; |
|
| 634 | + [$msg, $ligne, $col] = $r; |
|
| 635 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 636 | + if (isset($encore2[$msg])) { |
|
| 637 | + $ref = ++$encore2[$msg]; |
|
| 638 | + } else { |
|
| 639 | + $encore2[$msg] = $ref = 1; |
|
| 640 | + } |
|
| 641 | + $err .= "<tr style='background-color: " |
|
| 642 | + . $colors[$i % 2] |
|
| 643 | + . "'><td $style><a href='#debut_err'>" |
|
| 644 | + . $i |
|
| 645 | + . "</a></td><td $style>" |
|
| 646 | + . "$ref/$encore[$msg]</td>" |
|
| 647 | + . "<td $style><a href='#L" |
|
| 648 | + . $ligne |
|
| 649 | + . "' id='T$i'>" |
|
| 650 | + . $ligne |
|
| 651 | + . "</a></td><td $style>" |
|
| 652 | + . $col |
|
| 653 | + . "</td><td>$msg</td></tr>\n"; |
|
| 654 | + $fautifs[] = [$ligne, $col, $i, $msg]; |
|
| 655 | + } |
|
| 656 | + $err = "<h2 style='text-align: center'>" |
|
| 657 | + . $i |
|
| 658 | + . "<a href='#fin_err'>" |
|
| 659 | + . ' ' . _T('erreur_texte') |
|
| 660 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 661 | + . $err |
|
| 662 | + . " </table><a id='fin_err'></a>"; |
|
| 663 | + |
|
| 664 | + return [ancre_texte($texte, $fautifs), $err]; |
|
| 665 | + } else { |
|
| 666 | + [$msg, $fermant, $ouvrant] = $errs[0]; |
|
| 667 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 668 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 669 | + $err = $msg . |
|
| 670 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 671 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 672 | + |
|
| 673 | + return [ancre_texte($texte, [[$ouvrant], [$fermant]]), $err]; |
|
| 674 | + } |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | function count_occ($regs) { |
| 678 | - $encore = []; |
|
| 679 | - foreach ($regs as $r) { |
|
| 680 | - if (isset($encore[$r[0]])) { |
|
| 681 | - $encore[$r[0]]++; |
|
| 682 | - } else { |
|
| 683 | - $encore[$r[0]] = 1; |
|
| 684 | - } |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - return $encore; |
|
| 678 | + $encore = []; |
|
| 679 | + foreach ($regs as $r) { |
|
| 680 | + if (isset($encore[$r[0]])) { |
|
| 681 | + $encore[$r[0]]++; |
|
| 682 | + } else { |
|
| 683 | + $encore[$r[0]] = 1; |
|
| 684 | + } |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + return $encore; |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | function debusquer_navigation_squelettes($self) { |
| 691 | 691 | |
| 692 | - $res = ''; |
|
| 693 | - $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 694 | - $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 695 | - $t_skel = _T('squelette'); |
|
| 696 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 697 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 698 | - $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 699 | - $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T( |
|
| 700 | - 'zbug_profile', |
|
| 701 | - ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 702 | - ); |
|
| 703 | - |
|
| 704 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 705 | - . $t_skel |
|
| 706 | - . ' ' |
|
| 707 | - . $sourcefile |
|
| 708 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 709 | - . $t_skel |
|
| 710 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 711 | - . _T('zbug_resultat') |
|
| 712 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 713 | - . _T('zbug_code') |
|
| 714 | - . "</a>\n<a href='" |
|
| 715 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 716 | - . "'>" |
|
| 717 | - . _T('zbug_calcul') |
|
| 718 | - . '</a></legend>' |
|
| 719 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 720 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 721 | - . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 722 | - . "</fieldset>\n"; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - return $res; |
|
| 692 | + $res = ''; |
|
| 693 | + $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 694 | + $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 695 | + $t_skel = _T('squelette'); |
|
| 696 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 697 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 698 | + $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 699 | + $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T( |
|
| 700 | + 'zbug_profile', |
|
| 701 | + ['time' => $GLOBALS['debug_objets']['profile'][$sourcefile]] |
|
| 702 | + ); |
|
| 703 | + |
|
| 704 | + $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 705 | + . $t_skel |
|
| 706 | + . ' ' |
|
| 707 | + . $sourcefile |
|
| 708 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 709 | + . $t_skel |
|
| 710 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 711 | + . _T('zbug_resultat') |
|
| 712 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 713 | + . _T('zbug_code') |
|
| 714 | + . "</a>\n<a href='" |
|
| 715 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 716 | + . "'>" |
|
| 717 | + . _T('zbug_calcul') |
|
| 718 | + . '</a></legend>' |
|
| 719 | + . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 720 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 721 | + . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 722 | + . "</fieldset>\n"; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + return $res; |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
| 729 | - $i = 0; |
|
| 730 | - $res = ''; |
|
| 731 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 732 | - $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 733 | - |
|
| 734 | - foreach ($boucles as $objet => $boucle) { |
|
| 735 | - if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 736 | - $i++; |
|
| 737 | - $nom = $boucle->id_boucle; |
|
| 738 | - $req = $boucle->type_requete; |
|
| 739 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 740 | - $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 741 | - |
|
| 742 | - $res .= "\n<tr style='background-color: " . |
|
| 743 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 744 | - "'><td align='right'>$i</td><td>\n" . |
|
| 745 | - "<a class='debug_link_boucle' href='" . |
|
| 746 | - $self2 . |
|
| 747 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 748 | - _T('zbug_boucle') . |
|
| 749 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 750 | - $self2 . |
|
| 751 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 752 | - _T('zbug_resultat') . |
|
| 753 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 754 | - $self2 . |
|
| 755 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 756 | - _T('zbug_code') . |
|
| 757 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 758 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 759 | - "'>" . |
|
| 760 | - _T('zbug_calcul') . |
|
| 761 | - "</a></td><td>\n" . |
|
| 762 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 763 | - "</td><td>\n" . |
|
| 764 | - $req . |
|
| 765 | - "</td><td>\n" . |
|
| 766 | - spip_htmlspecialchars($crit) . |
|
| 767 | - '</td></tr>'; |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - return $res; |
|
| 729 | + $i = 0; |
|
| 730 | + $res = ''; |
|
| 731 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 732 | + $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 733 | + |
|
| 734 | + foreach ($boucles as $objet => $boucle) { |
|
| 735 | + if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 736 | + $i++; |
|
| 737 | + $nom = $boucle->id_boucle; |
|
| 738 | + $req = $boucle->type_requete; |
|
| 739 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 740 | + $self2 = $self . '&var_mode_objet=' . $objet; |
|
| 741 | + |
|
| 742 | + $res .= "\n<tr style='background-color: " . |
|
| 743 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 744 | + "'><td align='right'>$i</td><td>\n" . |
|
| 745 | + "<a class='debug_link_boucle' href='" . |
|
| 746 | + $self2 . |
|
| 747 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 748 | + _T('zbug_boucle') . |
|
| 749 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 750 | + $self2 . |
|
| 751 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 752 | + _T('zbug_resultat') . |
|
| 753 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 754 | + $self2 . |
|
| 755 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 756 | + _T('zbug_code') . |
|
| 757 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 758 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 759 | + "'>" . |
|
| 760 | + _T('zbug_calcul') . |
|
| 761 | + "</a></td><td>\n" . |
|
| 762 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 763 | + "</td><td>\n" . |
|
| 764 | + $req . |
|
| 765 | + "</td><td>\n" . |
|
| 766 | + spip_htmlspecialchars($crit) . |
|
| 767 | + '</td></tr>'; |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + return $res; |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | function debusquer_source($objet, $affiche) { |
| 775 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 776 | - if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 777 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 778 | - } else { |
|
| 779 | - $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 780 | - } |
|
| 781 | - $res2 = ''; |
|
| 782 | - |
|
| 783 | - if ($affiche == 'resultat') { |
|
| 784 | - $legend = $nom; |
|
| 785 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 786 | - if (function_exists('_mysql_traite_query')) { |
|
| 787 | - $c = strtolower(_request('connect') ?? ''); |
|
| 788 | - $c = $GLOBALS['connexions'][$c ?: 0]['prefixe']; |
|
| 789 | - $req = _mysql_traite_query($req, '', $c); |
|
| 790 | - } |
|
| 791 | - // permettre le copier/coller facile |
|
| 792 | - // $res = ancre_texte($req, array(), true); |
|
| 793 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 794 | - // formatage et affichage des resultats bruts de la requete |
|
| 795 | - $ress_req = spip_query($req); |
|
| 796 | - $brut_sql = ''; |
|
| 797 | - $num = 1; |
|
| 798 | - // eviter l'affichage de milliers de lignes |
|
| 799 | - // personnalisation possible dans mes_options |
|
| 800 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 801 | - while ($retours_sql = sql_fetch($ress_req)) { |
|
| 802 | - if ($num <= $max_aff) { |
|
| 803 | - $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 804 | - $brut_sql .= '<p>'; |
|
| 805 | - foreach ($retours_sql as $key => $val) { |
|
| 806 | - $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 807 | - } |
|
| 808 | - $brut_sql .= '</p>'; |
|
| 809 | - } |
|
| 810 | - $num++; |
|
| 811 | - } |
|
| 812 | - $res2 = interdire_scripts($brut_sql); |
|
| 813 | - foreach ($quoi as $view) { |
|
| 814 | - // ne pas afficher les $contexte_inclus |
|
| 815 | - $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
|
| 816 | - if ($view) { |
|
| 817 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - } elseif ($affiche == 'code') { |
|
| 821 | - $legend = $nom; |
|
| 822 | - $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 823 | - } elseif ($affiche == 'boucle') { |
|
| 824 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 825 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 826 | - $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 827 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 828 | - } elseif ($affiche == 'squelette') { |
|
| 829 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 830 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - return [$legend, $res, $res2]; |
|
| 775 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 776 | + if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 777 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 778 | + } else { |
|
| 779 | + $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 780 | + } |
|
| 781 | + $res2 = ''; |
|
| 782 | + |
|
| 783 | + if ($affiche == 'resultat') { |
|
| 784 | + $legend = $nom; |
|
| 785 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 786 | + if (function_exists('_mysql_traite_query')) { |
|
| 787 | + $c = strtolower(_request('connect') ?? ''); |
|
| 788 | + $c = $GLOBALS['connexions'][$c ?: 0]['prefixe']; |
|
| 789 | + $req = _mysql_traite_query($req, '', $c); |
|
| 790 | + } |
|
| 791 | + // permettre le copier/coller facile |
|
| 792 | + // $res = ancre_texte($req, array(), true); |
|
| 793 | + $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 794 | + // formatage et affichage des resultats bruts de la requete |
|
| 795 | + $ress_req = spip_query($req); |
|
| 796 | + $brut_sql = ''; |
|
| 797 | + $num = 1; |
|
| 798 | + // eviter l'affichage de milliers de lignes |
|
| 799 | + // personnalisation possible dans mes_options |
|
| 800 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 801 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 802 | + if ($num <= $max_aff) { |
|
| 803 | + $brut_sql .= '<h3>' . ($num == 1 ? $num . ' sur ' . sql_count($ress_req) : $num) . '</h3>'; |
|
| 804 | + $brut_sql .= '<p>'; |
|
| 805 | + foreach ($retours_sql as $key => $val) { |
|
| 806 | + $brut_sql .= '<strong>' . $key . '</strong> => ' . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 807 | + } |
|
| 808 | + $brut_sql .= '</p>'; |
|
| 809 | + } |
|
| 810 | + $num++; |
|
| 811 | + } |
|
| 812 | + $res2 = interdire_scripts($brut_sql); |
|
| 813 | + foreach ($quoi as $view) { |
|
| 814 | + // ne pas afficher les $contexte_inclus |
|
| 815 | + $view = preg_replace(',<\?php.+\?[>],Uims', '', $view); |
|
| 816 | + if ($view) { |
|
| 817 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . '</fieldset>'; |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + } elseif ($affiche == 'code') { |
|
| 821 | + $legend = $nom; |
|
| 822 | + $res = ancre_texte('<' . "?php\n" . $quoi . "\n?" . '>'); |
|
| 823 | + } elseif ($affiche == 'boucle') { |
|
| 824 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 825 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 826 | + $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 827 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 828 | + } elseif ($affiche == 'squelette') { |
|
| 829 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 830 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + return [$legend, $res, $res2]; |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | function debusquer_entete($titre, $corps) { |
| 837 | 837 | |
| 838 | - include_spip('balise/formulaire_admin'); |
|
| 839 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 840 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 841 | - |
|
| 842 | - return _DOCTYPE_ECRIRE . |
|
| 843 | - html_lang_attributes() . |
|
| 844 | - "<head>\n<title>" . |
|
| 845 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 846 | - _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 847 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 848 | - ")</title>\n" . |
|
| 849 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 850 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 851 | - "' />\n" . |
|
| 852 | - http_script('', 'jquery.js') |
|
| 853 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 854 | - . "' type='text/css' />" . |
|
| 855 | - "</head>\n" . |
|
| 856 | - "<body style='margin:0 10px;'>\n" . |
|
| 857 | - "<div id='spip-debug-header'>" . |
|
| 858 | - $corps . |
|
| 859 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 860 | - '</div></body></html>'; |
|
| 838 | + include_spip('balise/formulaire_admin'); |
|
| 839 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 840 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 841 | + |
|
| 842 | + return _DOCTYPE_ECRIRE . |
|
| 843 | + html_lang_attributes() . |
|
| 844 | + "<head>\n<title>" . |
|
| 845 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 846 | + _T('admin_debug') . ' ' . spip_htmlspecialchars($titre) . ' (' . |
|
| 847 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 848 | + ")</title>\n" . |
|
| 849 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 850 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 851 | + "' />\n" . |
|
| 852 | + http_script('', 'jquery.js') |
|
| 853 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 854 | + . "' type='text/css' />" . |
|
| 855 | + "</head>\n" . |
|
| 856 | + "<body style='margin:0 10px;'>\n" . |
|
| 857 | + "<div id='spip-debug-header'>" . |
|
| 858 | + $corps . |
|
| 859 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 860 | + '</div></body></html>'; |
|
| 861 | 861 | } |