@@ -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 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('inc/filtres'); |
| 23 | 23 | include_spip('inc/lang'); |
@@ -39,21 +39,21 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function definir_puce() { |
| 41 | 41 | |
| 42 | - // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | - // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | - // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | - $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 42 | + // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | + // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | + // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | + $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 46 | 46 | |
| 47 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | - if ($dir == 'rtl') { |
|
| 49 | - $p .= '_rtl'; |
|
| 50 | - } |
|
| 47 | + $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | + if ($dir == 'rtl') { |
|
| 49 | + $p .= '_rtl'; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - if (!isset($GLOBALS[$p])) { |
|
| 53 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 54 | - } |
|
| 52 | + if (!isset($GLOBALS[$p])) { |
|
| 53 | + $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $GLOBALS[$p]; |
|
| 56 | + return $GLOBALS[$p]; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 62 | 62 | |
| 63 | 63 | if (!defined('_BALISES_BLOCS')) { |
| 64 | - define( |
|
| 65 | - '_BALISES_BLOCS', |
|
| 66 | - 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 67 | - ); |
|
| 64 | + define( |
|
| 65 | + '_BALISES_BLOCS', |
|
| 66 | + 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 67 | + ); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 71 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 71 | + define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // |
@@ -79,106 +79,106 @@ discard block |
||
| 79 | 79 | // une $source differente ; le script detecte automagiquement si ce qu'on |
| 80 | 80 | // echappe est un div ou un span |
| 81 | 81 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 82 | - if (!strlen($rempl)) { |
|
| 83 | - return ''; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Tester si on echappe en span ou en div |
|
| 87 | - if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 88 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 92 | - $taille = 30000; |
|
| 93 | - $return = ''; |
|
| 94 | - for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 95 | - // Convertir en base64 et cacher dans un attribut |
|
| 96 | - // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 97 | - $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 98 | - $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $return; |
|
| 82 | + if (!strlen($rempl)) { |
|
| 83 | + return ''; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Tester si on echappe en span ou en div |
|
| 87 | + if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 88 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 92 | + $taille = 30000; |
|
| 93 | + $return = ''; |
|
| 94 | + for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 95 | + // Convertir en base64 et cacher dans un attribut |
|
| 96 | + // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 97 | + $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 98 | + $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $return; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
| 105 | 105 | // Echapper les <html>...</ html> |
| 106 | 106 | function traiter_echap_html_dist($regs, $options = []) { |
| 107 | - return $regs[3]; |
|
| 107 | + return $regs[3]; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Echapper les <pre>...</ pre> |
| 111 | 111 | function traiter_echap_pre_dist($regs, $options = []) { |
| 112 | - // echapper les <code> dans <pre> |
|
| 113 | - $pre = $regs[3]; |
|
| 114 | - |
|
| 115 | - // echapper les < dans <code> |
|
| 116 | - // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 117 | - if ( |
|
| 118 | - strpos($pre, '<') !== false |
|
| 119 | - and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 120 | - ) { |
|
| 121 | - foreach ($matches as $m) { |
|
| 122 | - if ($m[1] === 'code') { |
|
| 123 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 124 | - $pre = str_replace($m[0], $code, $pre); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - return "<pre>$pre</pre>"; |
|
| 112 | + // echapper les <code> dans <pre> |
|
| 113 | + $pre = $regs[3]; |
|
| 114 | + |
|
| 115 | + // echapper les < dans <code> |
|
| 116 | + // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 117 | + if ( |
|
| 118 | + strpos($pre, '<') !== false |
|
| 119 | + and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 120 | + ) { |
|
| 121 | + foreach ($matches as $m) { |
|
| 122 | + if ($m[1] === 'code') { |
|
| 123 | + $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 124 | + $pre = str_replace($m[0], $code, $pre); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + return "<pre>$pre</pre>"; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Echapper les <code>...</ code> |
| 132 | 132 | function traiter_echap_code_dist($regs, $options = []) { |
| 133 | - [, , $att, $corps] = $regs; |
|
| 134 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 135 | - |
|
| 136 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 137 | - if (is_int(strpos($echap, "\n"))) { |
|
| 138 | - // supprimer les sauts de ligne debut/fin |
|
| 139 | - // (mais pas les espaces => ascii art). |
|
| 140 | - $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap); |
|
| 141 | - $echap = nl2br($echap); |
|
| 142 | - $echap = "<div style='text-align: left;' " |
|
| 143 | - . "class='spip_code' dir='ltr'><code$att>" |
|
| 144 | - . $echap . '</code></div>'; |
|
| 145 | - } else { |
|
| 146 | - $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>'; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $echap = str_replace("\t", ' ', $echap); |
|
| 150 | - $echap = str_replace(' ', ' ', $echap); |
|
| 151 | - |
|
| 152 | - return $echap; |
|
| 133 | + [, , $att, $corps] = $regs; |
|
| 134 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 135 | + |
|
| 136 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 137 | + if (is_int(strpos($echap, "\n"))) { |
|
| 138 | + // supprimer les sauts de ligne debut/fin |
|
| 139 | + // (mais pas les espaces => ascii art). |
|
| 140 | + $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap); |
|
| 141 | + $echap = nl2br($echap); |
|
| 142 | + $echap = "<div style='text-align: left;' " |
|
| 143 | + . "class='spip_code' dir='ltr'><code$att>" |
|
| 144 | + . $echap . '</code></div>'; |
|
| 145 | + } else { |
|
| 146 | + $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>'; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $echap = str_replace("\t", ' ', $echap); |
|
| 150 | + $echap = str_replace(' ', ' ', $echap); |
|
| 151 | + |
|
| 152 | + return $echap; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 156 | 156 | function traiter_echap_cadre_dist($regs, $options = []) { |
| 157 | - $echap = trim(entites_html($regs[3])); |
|
| 158 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 159 | - $lignes = explode("\n", trim($echap)); |
|
| 160 | - $n = 0; |
|
| 161 | - foreach ($lignes as $l) { |
|
| 162 | - $n += floor(strlen($l) / 60) + 1; |
|
| 163 | - } |
|
| 164 | - $n = max($n, 2); |
|
| 165 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 166 | - |
|
| 167 | - return $echap; |
|
| 157 | + $echap = trim(entites_html($regs[3])); |
|
| 158 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 159 | + $lignes = explode("\n", trim($echap)); |
|
| 160 | + $n = 0; |
|
| 161 | + foreach ($lignes as $l) { |
|
| 162 | + $n += floor(strlen($l) / 60) + 1; |
|
| 163 | + } |
|
| 164 | + $n = max($n, 2); |
|
| 165 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 166 | + |
|
| 167 | + return $echap; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | function traiter_echap_frame_dist($regs, $options = []) { |
| 171 | - return traiter_echap_cadre_dist($regs); |
|
| 171 | + return traiter_echap_cadre_dist($regs); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | function traiter_echap_script_dist($regs, $options = []) { |
| 175 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 176 | - if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 177 | - return highlight_string($regs[0], true); |
|
| 178 | - } |
|
| 175 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 176 | + if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 177 | + return highlight_string($regs[0], true); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - // Cas normal : le script passe tel quel |
|
| 181 | - return $regs[0]; |
|
| 180 | + // Cas normal : le script passe tel quel |
|
| 181 | + return $regs[0]; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\b[^>]*)?>(.*)</\1>,UimsS'); |
@@ -197,73 +197,73 @@ discard block |
||
| 197 | 197 | * @return string|string[] |
| 198 | 198 | */ |
| 199 | 199 | function echappe_html( |
| 200 | - $letexte, |
|
| 201 | - $source = '', |
|
| 202 | - $no_transform = false, |
|
| 203 | - $preg = '', |
|
| 204 | - $callback_prefix = '', |
|
| 205 | - $callback_options = [] |
|
| 200 | + $letexte, |
|
| 201 | + $source = '', |
|
| 202 | + $no_transform = false, |
|
| 203 | + $preg = '', |
|
| 204 | + $callback_prefix = '', |
|
| 205 | + $callback_options = [] |
|
| 206 | 206 | ) { |
| 207 | - if (!is_string($letexte) or !strlen($letexte)) { |
|
| 208 | - return $letexte; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if ( |
|
| 212 | - ($preg or strpos($letexte, '<') !== false) |
|
| 213 | - and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 214 | - ) { |
|
| 215 | - foreach ($matches as $regs) { |
|
| 216 | - // echappements tels quels ? |
|
| 217 | - if ($no_transform) { |
|
| 218 | - $echap = $regs[0]; |
|
| 219 | - } // sinon les traiter selon le cas |
|
| 220 | - else { |
|
| 221 | - $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 222 | - if ( |
|
| 223 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 224 | - or function_exists($f = $f . '_dist') |
|
| 225 | - or ($callback_secure_prefix and ( |
|
| 226 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 227 | - or function_exists($f = $f . '_dist') |
|
| 228 | - )) |
|
| 229 | - ) { |
|
| 230 | - $echap = $f($regs, $callback_options); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $p = strpos($letexte, (string) $regs[0]); |
|
| 235 | - $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - if ($no_transform) { |
|
| 240 | - return $letexte; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 244 | - // seulement si on a echappe les <script> |
|
| 245 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 246 | - // dans une callback autonommee |
|
| 247 | - if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 248 | - if ( |
|
| 249 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 250 | - ',<[?].*($|[?]>),UisS', |
|
| 251 | - $letexte, |
|
| 252 | - $matches, |
|
| 253 | - PREG_SET_ORDER |
|
| 254 | - ) |
|
| 255 | - ) { |
|
| 256 | - foreach ($matches as $regs) { |
|
| 257 | - $letexte = str_replace( |
|
| 258 | - $regs[0], |
|
| 259 | - code_echappement(highlight_string($regs[0], true), $source), |
|
| 260 | - $letexte |
|
| 261 | - ); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return $letexte; |
|
| 207 | + if (!is_string($letexte) or !strlen($letexte)) { |
|
| 208 | + return $letexte; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if ( |
|
| 212 | + ($preg or strpos($letexte, '<') !== false) |
|
| 213 | + and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 214 | + ) { |
|
| 215 | + foreach ($matches as $regs) { |
|
| 216 | + // echappements tels quels ? |
|
| 217 | + if ($no_transform) { |
|
| 218 | + $echap = $regs[0]; |
|
| 219 | + } // sinon les traiter selon le cas |
|
| 220 | + else { |
|
| 221 | + $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 222 | + if ( |
|
| 223 | + function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 224 | + or function_exists($f = $f . '_dist') |
|
| 225 | + or ($callback_secure_prefix and ( |
|
| 226 | + function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 227 | + or function_exists($f = $f . '_dist') |
|
| 228 | + )) |
|
| 229 | + ) { |
|
| 230 | + $echap = $f($regs, $callback_options); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $p = strpos($letexte, (string) $regs[0]); |
|
| 235 | + $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + if ($no_transform) { |
|
| 240 | + return $letexte; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 244 | + // seulement si on a echappe les <script> |
|
| 245 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 246 | + // dans une callback autonommee |
|
| 247 | + if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 248 | + if ( |
|
| 249 | + strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 250 | + ',<[?].*($|[?]>),UisS', |
|
| 251 | + $letexte, |
|
| 252 | + $matches, |
|
| 253 | + PREG_SET_ORDER |
|
| 254 | + ) |
|
| 255 | + ) { |
|
| 256 | + foreach ($matches as $regs) { |
|
| 257 | + $letexte = str_replace( |
|
| 258 | + $regs[0], |
|
| 259 | + code_echappement(highlight_string($regs[0], true), $source), |
|
| 260 | + $letexte |
|
| 261 | + ); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return $letexte; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // |
@@ -271,57 +271,57 @@ discard block |
||
| 271 | 271 | // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes |
| 272 | 272 | // par propre() : exemple dans multi et dans typo() |
| 273 | 273 | function echappe_retour($letexte, $source = '', $filtre = '') { |
| 274 | - if (strpos($letexte, (string) "base64$source")) { |
|
| 275 | - # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 276 | - $max_prof = 5; |
|
| 277 | - while ( |
|
| 278 | - strpos($letexte, '<') !== false |
|
| 279 | - and |
|
| 280 | - preg_match_all( |
|
| 281 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 282 | - $letexte, |
|
| 283 | - $regs, |
|
| 284 | - PREG_SET_ORDER |
|
| 285 | - ) |
|
| 286 | - and $max_prof-- |
|
| 287 | - ) { |
|
| 288 | - foreach ($regs as $reg) { |
|
| 289 | - $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 290 | - // recherche d'attributs supplementaires |
|
| 291 | - $at = []; |
|
| 292 | - foreach (['lang', 'dir'] as $attr) { |
|
| 293 | - if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 294 | - $at[$attr] = $a; |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - if ($at) { |
|
| 298 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 299 | - foreach ($at as $attr => $a) { |
|
| 300 | - $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - if ($filtre) { |
|
| 304 | - $rempl = $filtre($rempl); |
|
| 305 | - } |
|
| 306 | - $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - return $letexte; |
|
| 274 | + if (strpos($letexte, (string) "base64$source")) { |
|
| 275 | + # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 276 | + $max_prof = 5; |
|
| 277 | + while ( |
|
| 278 | + strpos($letexte, '<') !== false |
|
| 279 | + and |
|
| 280 | + preg_match_all( |
|
| 281 | + ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 282 | + $letexte, |
|
| 283 | + $regs, |
|
| 284 | + PREG_SET_ORDER |
|
| 285 | + ) |
|
| 286 | + and $max_prof-- |
|
| 287 | + ) { |
|
| 288 | + foreach ($regs as $reg) { |
|
| 289 | + $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 290 | + // recherche d'attributs supplementaires |
|
| 291 | + $at = []; |
|
| 292 | + foreach (['lang', 'dir'] as $attr) { |
|
| 293 | + if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 294 | + $at[$attr] = $a; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + if ($at) { |
|
| 298 | + $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 299 | + foreach ($at as $attr => $a) { |
|
| 300 | + $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + if ($filtre) { |
|
| 304 | + $rempl = $filtre($rempl); |
|
| 305 | + } |
|
| 306 | + $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + return $letexte; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | // Reinserer le javascript de confiance (venant des modeles) |
| 315 | 315 | |
| 316 | 316 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 317 | - $letexte = echappe_retour($letexte); |
|
| 317 | + $letexte = echappe_retour($letexte); |
|
| 318 | 318 | |
| 319 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 320 | - if ($interdire_scripts) { |
|
| 321 | - $letexte = interdire_scripts($letexte); |
|
| 322 | - } |
|
| 319 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 320 | + if ($interdire_scripts) { |
|
| 321 | + $letexte = interdire_scripts($letexte); |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - return trim($letexte); |
|
| 324 | + return trim($letexte); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -349,131 +349,131 @@ discard block |
||
| 349 | 349 | * Texte coupé |
| 350 | 350 | **/ |
| 351 | 351 | function couper($texte, $taille = 50, $suite = null) { |
| 352 | - if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 353 | - return ''; |
|
| 354 | - } |
|
| 355 | - $offset = 400 + 2 * $taille; |
|
| 356 | - while ( |
|
| 357 | - $offset < $length |
|
| 358 | - and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 359 | - ) { |
|
| 360 | - $offset = 2 * $offset; |
|
| 361 | - } |
|
| 362 | - if ( |
|
| 363 | - $offset < $length |
|
| 364 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 365 | - ) { |
|
| 366 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 367 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 368 | - $offset = $p_tag_fermant + 1; |
|
| 369 | - } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 370 | - } |
|
| 371 | - $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 372 | - |
|
| 373 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 374 | - include_spip('inc/lien'); |
|
| 375 | - } |
|
| 376 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 377 | - |
|
| 378 | - // balises de sauts de ligne et paragraphe |
|
| 379 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 380 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 381 | - |
|
| 382 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 383 | - $texte = str_replace("\n\n", "\r", $texte); |
|
| 384 | - |
|
| 385 | - // supprimer les tags |
|
| 386 | - $texte = supprimer_tags($texte); |
|
| 387 | - $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 388 | - $texte .= "\n"; // marquer la fin |
|
| 389 | - |
|
| 390 | - // corriger la longueur de coupe |
|
| 391 | - // en fonction de la presence de caracteres utf |
|
| 392 | - if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 393 | - $long = charset2unicode($texte); |
|
| 394 | - $long = spip_substr($long, 0, max($taille, 1)); |
|
| 395 | - $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 396 | - $taille += $nbcharutf; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - // couper au mot precedent |
|
| 401 | - $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 402 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 403 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 404 | - if (is_null($suite)) { |
|
| 405 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 406 | - } |
|
| 407 | - $points = $suite; |
|
| 408 | - |
|
| 409 | - // trop court ? ne pas faire de (...) |
|
| 410 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 411 | - $points = ''; |
|
| 412 | - $long = spip_substr($texte, 0, $taille); |
|
| 413 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 414 | - // encore trop court ? couper au caractere |
|
| 415 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 416 | - $texte = $long; |
|
| 417 | - } |
|
| 418 | - } else { |
|
| 419 | - $texte = $court; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 423 | - $points = ''; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - // remettre les paragraphes |
|
| 427 | - $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 428 | - |
|
| 429 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 430 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 431 | - |
|
| 432 | - return quote_amp(trim($texte)) . $points; |
|
| 352 | + if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 353 | + return ''; |
|
| 354 | + } |
|
| 355 | + $offset = 400 + 2 * $taille; |
|
| 356 | + while ( |
|
| 357 | + $offset < $length |
|
| 358 | + and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 359 | + ) { |
|
| 360 | + $offset = 2 * $offset; |
|
| 361 | + } |
|
| 362 | + if ( |
|
| 363 | + $offset < $length |
|
| 364 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 365 | + ) { |
|
| 366 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 367 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 368 | + $offset = $p_tag_fermant + 1; |
|
| 369 | + } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 370 | + } |
|
| 371 | + $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 372 | + |
|
| 373 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 374 | + include_spip('inc/lien'); |
|
| 375 | + } |
|
| 376 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 377 | + |
|
| 378 | + // balises de sauts de ligne et paragraphe |
|
| 379 | + $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 380 | + $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 381 | + |
|
| 382 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 383 | + $texte = str_replace("\n\n", "\r", $texte); |
|
| 384 | + |
|
| 385 | + // supprimer les tags |
|
| 386 | + $texte = supprimer_tags($texte); |
|
| 387 | + $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 388 | + $texte .= "\n"; // marquer la fin |
|
| 389 | + |
|
| 390 | + // corriger la longueur de coupe |
|
| 391 | + // en fonction de la presence de caracteres utf |
|
| 392 | + if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 393 | + $long = charset2unicode($texte); |
|
| 394 | + $long = spip_substr($long, 0, max($taille, 1)); |
|
| 395 | + $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 396 | + $taille += $nbcharutf; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + // couper au mot precedent |
|
| 401 | + $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 402 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 403 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 404 | + if (is_null($suite)) { |
|
| 405 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 406 | + } |
|
| 407 | + $points = $suite; |
|
| 408 | + |
|
| 409 | + // trop court ? ne pas faire de (...) |
|
| 410 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 411 | + $points = ''; |
|
| 412 | + $long = spip_substr($texte, 0, $taille); |
|
| 413 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 414 | + // encore trop court ? couper au caractere |
|
| 415 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 416 | + $texte = $long; |
|
| 417 | + } |
|
| 418 | + } else { |
|
| 419 | + $texte = $court; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 423 | + $points = ''; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + // remettre les paragraphes |
|
| 427 | + $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 428 | + |
|
| 429 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 430 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 431 | + |
|
| 432 | + return quote_amp(trim($texte)) . $points; |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | |
| 436 | 436 | function protege_js_modeles($t) { |
| 437 | - if (isset($GLOBALS['visiteur_session'])) { |
|
| 438 | - if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 439 | - if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 440 | - include_spip('inc/acces'); |
|
| 441 | - define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 442 | - } |
|
| 443 | - foreach ($r as $regs) { |
|
| 444 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 448 | - if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 449 | - include_spip('inc/acces'); |
|
| 450 | - define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 451 | - } |
|
| 452 | - foreach ($r as $regs) { |
|
| 453 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - return $t; |
|
| 437 | + if (isset($GLOBALS['visiteur_session'])) { |
|
| 438 | + if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 439 | + if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 440 | + include_spip('inc/acces'); |
|
| 441 | + define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 442 | + } |
|
| 443 | + foreach ($r as $regs) { |
|
| 444 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 448 | + if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 449 | + include_spip('inc/acces'); |
|
| 450 | + define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 451 | + } |
|
| 452 | + foreach ($r as $regs) { |
|
| 453 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + return $t; |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | |
| 462 | 462 | function echapper_faux_tags($letexte) { |
| 463 | - if (strpos($letexte, '<') === false) { |
|
| 464 | - return $letexte; |
|
| 465 | - } |
|
| 466 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 467 | - |
|
| 468 | - $letexte = ''; |
|
| 469 | - while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 470 | - // un texte a echapper |
|
| 471 | - $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 472 | - // un tag html qui a servit a faite le split |
|
| 473 | - $letexte .= array_shift($textMatches); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - return $letexte; |
|
| 463 | + if (strpos($letexte, '<') === false) { |
|
| 464 | + return $letexte; |
|
| 465 | + } |
|
| 466 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 467 | + |
|
| 468 | + $letexte = ''; |
|
| 469 | + while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 470 | + // un texte a echapper |
|
| 471 | + $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 472 | + // un tag html qui a servit a faite le split |
|
| 473 | + $letexte .= array_shift($textMatches); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + return $letexte; |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
@@ -493,115 +493,115 @@ discard block |
||
| 493 | 493 | * @return string |
| 494 | 494 | */ |
| 495 | 495 | function echapper_html_suspect($texte, $options = [], $connect = null, $env = []) { |
| 496 | - static $echapper_html_suspect; |
|
| 497 | - if (!$texte or !is_string($texte)) { |
|
| 498 | - return $texte; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - if (!isset($echapper_html_suspect)) { |
|
| 502 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 503 | - } |
|
| 504 | - // si fonction personalisee, on delegue |
|
| 505 | - if ($echapper_html_suspect) { |
|
| 506 | - // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 507 | - $args = [$texte, $options]; |
|
| 508 | - if ($connect or !empty($env)) { |
|
| 509 | - $args[] = $connect; |
|
| 510 | - } |
|
| 511 | - if (!empty($env)) { |
|
| 512 | - $args[] = $env; |
|
| 513 | - } |
|
| 514 | - return $echapper_html_suspect(...$args); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - if (is_bool($options)) { |
|
| 518 | - $options = ['strict' => $options]; |
|
| 519 | - } |
|
| 520 | - $strict = $options['strict'] ?? true; |
|
| 521 | - |
|
| 522 | - // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 523 | - if ( |
|
| 524 | - strpos($texte, '<') === false |
|
| 525 | - or strpos($texte, '=') === false |
|
| 526 | - ) { |
|
| 527 | - return $texte; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 531 | - if (!isset($env['espace_prive'])) { |
|
| 532 | - // conserver le comportement historique en cas d'appel court sans env |
|
| 533 | - $env['espace_prive'] = test_espace_prive(); |
|
| 534 | - } |
|
| 535 | - if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) { |
|
| 536 | - |
|
| 537 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 538 | - // car sinon on declenche sur les modeles ou ressources |
|
| 539 | - if ( |
|
| 540 | - !$strict and |
|
| 541 | - (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 542 | - ) { |
|
| 543 | - return $texte; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 547 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 548 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 549 | - $texte = $collecteurModeles->echapper($texte); |
|
| 550 | - $texte = echappe_js($texte); |
|
| 551 | - |
|
| 552 | - $texte_to_check = $texte; |
|
| 553 | - // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 554 | - // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 555 | - // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 556 | - if (!empty($options['expanser_liens'])) { |
|
| 557 | - $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 558 | - } |
|
| 559 | - if (!is_html_safe($texte_to_check)) { |
|
| 560 | - $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 561 | - $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 562 | - $texte = str_replace('<', '<', $texte); |
|
| 563 | - $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 564 | - $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 565 | - if (!function_exists('attribut_html')) { |
|
| 566 | - include_spip('inc/filtres'); |
|
| 567 | - } |
|
| 568 | - if (!empty($options['wrap_suspect'])) { |
|
| 569 | - $texte = wrap($texte, $options['wrap_suspect']); |
|
| 570 | - } |
|
| 571 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - $texte = $collecteurModeles->retablir($texte); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - // si on est là dans le public c'est le mode parano |
|
| 578 | - // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 579 | - else { |
|
| 580 | - $collecteurLiens = $collecteurModeles = null; |
|
| 581 | - if (!empty($options['expanser_liens'])) { |
|
| 582 | - $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 583 | - } |
|
| 584 | - else { |
|
| 585 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 586 | - include_spip("src/Texte/Collecteur/Liens"); |
|
| 587 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 588 | - |
|
| 589 | - $collecteurLiens = new Spip\Texte\Collecteur\Liens(); |
|
| 590 | - $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 591 | - |
|
| 592 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 593 | - $texte = $collecteurModeles->echapper($texte); |
|
| 594 | - } |
|
| 595 | - $texte = safehtml($texte); |
|
| 596 | - if ($collecteurModeles) { |
|
| 597 | - $texte = $collecteurModeles->retablir($texte); |
|
| 598 | - } |
|
| 599 | - if ($collecteurLiens) { |
|
| 600 | - $texte = $collecteurLiens->retablir($texte); |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - return $texte; |
|
| 496 | + static $echapper_html_suspect; |
|
| 497 | + if (!$texte or !is_string($texte)) { |
|
| 498 | + return $texte; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + if (!isset($echapper_html_suspect)) { |
|
| 502 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 503 | + } |
|
| 504 | + // si fonction personalisee, on delegue |
|
| 505 | + if ($echapper_html_suspect) { |
|
| 506 | + // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 507 | + $args = [$texte, $options]; |
|
| 508 | + if ($connect or !empty($env)) { |
|
| 509 | + $args[] = $connect; |
|
| 510 | + } |
|
| 511 | + if (!empty($env)) { |
|
| 512 | + $args[] = $env; |
|
| 513 | + } |
|
| 514 | + return $echapper_html_suspect(...$args); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + if (is_bool($options)) { |
|
| 518 | + $options = ['strict' => $options]; |
|
| 519 | + } |
|
| 520 | + $strict = $options['strict'] ?? true; |
|
| 521 | + |
|
| 522 | + // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 523 | + if ( |
|
| 524 | + strpos($texte, '<') === false |
|
| 525 | + or strpos($texte, '=') === false |
|
| 526 | + ) { |
|
| 527 | + return $texte; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 531 | + if (!isset($env['espace_prive'])) { |
|
| 532 | + // conserver le comportement historique en cas d'appel court sans env |
|
| 533 | + $env['espace_prive'] = test_espace_prive(); |
|
| 534 | + } |
|
| 535 | + if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) { |
|
| 536 | + |
|
| 537 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 538 | + // car sinon on declenche sur les modeles ou ressources |
|
| 539 | + if ( |
|
| 540 | + !$strict and |
|
| 541 | + (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 542 | + ) { |
|
| 543 | + return $texte; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 547 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 548 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 549 | + $texte = $collecteurModeles->echapper($texte); |
|
| 550 | + $texte = echappe_js($texte); |
|
| 551 | + |
|
| 552 | + $texte_to_check = $texte; |
|
| 553 | + // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 554 | + // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 555 | + // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 556 | + if (!empty($options['expanser_liens'])) { |
|
| 557 | + $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 558 | + } |
|
| 559 | + if (!is_html_safe($texte_to_check)) { |
|
| 560 | + $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 561 | + $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 562 | + $texte = str_replace('<', '<', $texte); |
|
| 563 | + $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 564 | + $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 565 | + if (!function_exists('attribut_html')) { |
|
| 566 | + include_spip('inc/filtres'); |
|
| 567 | + } |
|
| 568 | + if (!empty($options['wrap_suspect'])) { |
|
| 569 | + $texte = wrap($texte, $options['wrap_suspect']); |
|
| 570 | + } |
|
| 571 | + $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + $texte = $collecteurModeles->retablir($texte); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + // si on est là dans le public c'est le mode parano |
|
| 578 | + // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 579 | + else { |
|
| 580 | + $collecteurLiens = $collecteurModeles = null; |
|
| 581 | + if (!empty($options['expanser_liens'])) { |
|
| 582 | + $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 583 | + } |
|
| 584 | + else { |
|
| 585 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 586 | + include_spip("src/Texte/Collecteur/Liens"); |
|
| 587 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 588 | + |
|
| 589 | + $collecteurLiens = new Spip\Texte\Collecteur\Liens(); |
|
| 590 | + $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 591 | + |
|
| 592 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 593 | + $texte = $collecteurModeles->echapper($texte); |
|
| 594 | + } |
|
| 595 | + $texte = safehtml($texte); |
|
| 596 | + if ($collecteurModeles) { |
|
| 597 | + $texte = $collecteurModeles->retablir($texte); |
|
| 598 | + } |
|
| 599 | + if ($collecteurLiens) { |
|
| 600 | + $texte = $collecteurLiens->retablir($texte); |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + return $texte; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | |
@@ -622,52 +622,52 @@ discard block |
||
| 622 | 622 | * Texte sécurisé |
| 623 | 623 | **/ |
| 624 | 624 | function safehtml($t) { |
| 625 | - static $safehtml; |
|
| 626 | - |
|
| 627 | - if (!$t or !is_string($t)) { |
|
| 628 | - return $t; |
|
| 629 | - } |
|
| 630 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 631 | - if (strpos($t, '<') === false) { |
|
| 632 | - return str_replace("\x00", '', $t); |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - $collecteurIdiomes = null; |
|
| 636 | - if (stripos($t, '<:') !== false) { |
|
| 637 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 638 | - include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 639 | - $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 640 | - $t = $collecteurIdiomes->echapper($t); |
|
| 641 | - } |
|
| 642 | - $collecteurMultis = null; |
|
| 643 | - if (stripos($t, '<multi') !== false) { |
|
| 644 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 645 | - include_spip("src/Texte/Collecteur/Multis"); |
|
| 646 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 647 | - $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - if (!function_exists('interdire_scripts')) { |
|
| 651 | - include_spip('inc/texte'); |
|
| 652 | - } |
|
| 653 | - $t = interdire_scripts($t); // jolifier le php |
|
| 654 | - $t = echappe_js($t); |
|
| 655 | - |
|
| 656 | - if (!isset($safehtml)) { |
|
| 657 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 658 | - } |
|
| 659 | - if ($safehtml) { |
|
| 660 | - $t = $safehtml($t); |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - if ($collecteurMultis) { |
|
| 664 | - $t = $collecteurMultis->retablir($t); |
|
| 665 | - } |
|
| 666 | - if ($collecteurIdiomes) { |
|
| 667 | - $t = $collecteurIdiomes->retablir($t); |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 625 | + static $safehtml; |
|
| 626 | + |
|
| 627 | + if (!$t or !is_string($t)) { |
|
| 628 | + return $t; |
|
| 629 | + } |
|
| 630 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 631 | + if (strpos($t, '<') === false) { |
|
| 632 | + return str_replace("\x00", '', $t); |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + $collecteurIdiomes = null; |
|
| 636 | + if (stripos($t, '<:') !== false) { |
|
| 637 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 638 | + include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 639 | + $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 640 | + $t = $collecteurIdiomes->echapper($t); |
|
| 641 | + } |
|
| 642 | + $collecteurMultis = null; |
|
| 643 | + if (stripos($t, '<multi') !== false) { |
|
| 644 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 645 | + include_spip("src/Texte/Collecteur/Multis"); |
|
| 646 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 647 | + $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + if (!function_exists('interdire_scripts')) { |
|
| 651 | + include_spip('inc/texte'); |
|
| 652 | + } |
|
| 653 | + $t = interdire_scripts($t); // jolifier le php |
|
| 654 | + $t = echappe_js($t); |
|
| 655 | + |
|
| 656 | + if (!isset($safehtml)) { |
|
| 657 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 658 | + } |
|
| 659 | + if ($safehtml) { |
|
| 660 | + $t = $safehtml($t); |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + if ($collecteurMultis) { |
|
| 664 | + $t = $collecteurMultis->retablir($t); |
|
| 665 | + } |
|
| 666 | + if ($collecteurIdiomes) { |
|
| 667 | + $t = $collecteurIdiomes->retablir($t); |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | |
@@ -675,25 +675,25 @@ discard block |
||
| 675 | 675 | * Detecter si un texte est "safe" ie non modifie significativement par safehtml() |
| 676 | 676 | */ |
| 677 | 677 | function is_html_safe(string $texte): bool { |
| 678 | - if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 679 | - return $is_html_safe($texte); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 683 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 684 | - // safehtml reduit aussi potentiellement les |
|
| 685 | - $texte = str_replace(" ", " ", $texte); |
|
| 686 | - // safehtml remplace les entités numériques |
|
| 687 | - if (strpos($texte, '&#') !== false) { |
|
| 688 | - $texte = unicode2charset($texte); |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - $texte_safe = safehtml($texte); |
|
| 692 | - |
|
| 693 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 694 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 695 | - // donc un test d'egalite est trop strict |
|
| 696 | - return strlen($texte_safe) === strlen($texte); |
|
| 678 | + if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 679 | + return $is_html_safe($texte); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 683 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 684 | + // safehtml reduit aussi potentiellement les |
|
| 685 | + $texte = str_replace(" ", " ", $texte); |
|
| 686 | + // safehtml remplace les entités numériques |
|
| 687 | + if (strpos($texte, '&#') !== false) { |
|
| 688 | + $texte = unicode2charset($texte); |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + $texte_safe = safehtml($texte); |
|
| 692 | + |
|
| 693 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 694 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 695 | + // donc un test d'egalite est trop strict |
|
| 696 | + return strlen($texte_safe) === strlen($texte); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | /** |
@@ -714,13 +714,13 @@ discard block |
||
| 714 | 714 | * Texte sans les modèles d'image |
| 715 | 715 | **/ |
| 716 | 716 | function supprime_img($letexte, $message = null) { |
| 717 | - if ($message === null) { |
|
| 718 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - return preg_replace( |
|
| 722 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 723 | - $message, |
|
| 724 | - $letexte |
|
| 725 | - ); |
|
| 717 | + if ($message === null) { |
|
| 718 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + return preg_replace( |
|
| 722 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 723 | + $message, |
|
| 724 | + $letexte |
|
| 725 | + ); |
|
| 726 | 726 | } |
@@ -11,5 +11,5 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @return string Fonction PHP correspondante du filtre |
| 43 | 43 | */ |
| 44 | 44 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 45 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | - return chercher_filtre($fonc, $default); |
|
| 45 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | + return chercher_filtre($fonc, $default); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return string Texte |
| 54 | 54 | **/ |
| 55 | 55 | function filtre_identite_dist($texte) { |
| 56 | - return $texte; |
|
| 56 | + return $texte; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -77,33 +77,33 @@ discard block |
||
| 77 | 77 | * Fonction PHP correspondante du filtre demandé |
| 78 | 78 | */ |
| 79 | 79 | function chercher_filtre($fonc, $default = null) { |
| 80 | - if (!$fonc) { |
|
| 81 | - return $default; |
|
| 82 | - } |
|
| 83 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | - // Foo::Bar |
|
| 85 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | - $f = chercher_filtre($nom); |
|
| 89 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | - if (!$f and $nom !== $fonc) { |
|
| 92 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $f; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - include_fichiers_fonctions(); |
|
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | - if (is_callable($f)) { |
|
| 102 | - return $f; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $default; |
|
| 80 | + if (!$fonc) { |
|
| 81 | + return $default; |
|
| 82 | + } |
|
| 83 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | + // Foo::Bar |
|
| 85 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | + $f = chercher_filtre($nom); |
|
| 89 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | + if (!$f and $nom !== $fonc) { |
|
| 92 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $f; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + include_fichiers_fonctions(); |
|
| 99 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | + if (is_callable($f)) { |
|
| 102 | + return $f; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $default; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -147,8 +147,8 @@ discard block |
||
| 147 | 147 | * Chaîne vide sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function appliquer_filtre($arg, $filtre) { |
| 150 | - $args = func_get_args(); |
|
| 151 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 150 | + $args = func_get_args(); |
|
| 151 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * Texte d'origine sinon |
| 174 | 174 | **/ |
| 175 | 175 | function appliquer_si_filtre($arg, $filtre) { |
| 176 | - $args = func_get_args(); |
|
| 177 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 176 | + $args = func_get_args(); |
|
| 177 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -190,12 +190,12 @@ discard block |
||
| 190 | 190 | * Version de SPIP |
| 191 | 191 | **/ |
| 192 | 192 | function spip_version() { |
| 193 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 194 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 195 | - $version .= " $vcs_version"; |
|
| 196 | - } |
|
| 193 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 194 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 195 | + $version .= " $vcs_version"; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - return $version; |
|
| 198 | + return $version; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -207,11 +207,11 @@ discard block |
||
| 207 | 207 | * @return string |
| 208 | 208 | */ |
| 209 | 209 | function header_silencieux($version): string { |
| 210 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 211 | - $version = ''; |
|
| 212 | - } |
|
| 210 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 211 | + $version = ''; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - return (string) $version; |
|
| 214 | + return (string) $version; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -224,19 +224,19 @@ discard block |
||
| 224 | 224 | * - string|null si $raw = false |
| 225 | 225 | */ |
| 226 | 226 | function version_vcs_courante($dir, $raw = false) { |
| 227 | - $desc = decrire_version_git($dir); |
|
| 228 | - if ($desc === null) { |
|
| 229 | - $desc = decrire_version_svn($dir); |
|
| 230 | - } |
|
| 231 | - if ($desc === null or $raw) { |
|
| 232 | - return $desc; |
|
| 233 | - } |
|
| 234 | - // affichage "GIT [master: abcdef]" |
|
| 235 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 236 | - if ($desc['branch']) { |
|
| 237 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 238 | - } |
|
| 239 | - return "{$desc['vcs']} [$commit]"; |
|
| 227 | + $desc = decrire_version_git($dir); |
|
| 228 | + if ($desc === null) { |
|
| 229 | + $desc = decrire_version_svn($dir); |
|
| 230 | + } |
|
| 231 | + if ($desc === null or $raw) { |
|
| 232 | + return $desc; |
|
| 233 | + } |
|
| 234 | + // affichage "GIT [master: abcdef]" |
|
| 235 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 236 | + if ($desc['branch']) { |
|
| 237 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 238 | + } |
|
| 239 | + return "{$desc['vcs']} [$commit]"; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -248,24 +248,24 @@ discard block |
||
| 248 | 248 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 249 | 249 | **/ |
| 250 | 250 | function decrire_version_git($dir) { |
| 251 | - if (!$dir) { |
|
| 252 | - $dir = '.'; |
|
| 253 | - } |
|
| 251 | + if (!$dir) { |
|
| 252 | + $dir = '.'; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - // version installee par GIT |
|
| 256 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 257 | - $currentHead = trim(substr($c, 4)); |
|
| 258 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 259 | - return [ |
|
| 260 | - 'vcs' => 'GIT', |
|
| 261 | - 'branch' => basename($currentHead), |
|
| 262 | - 'commit' => trim($hash), |
|
| 263 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 264 | - ]; |
|
| 265 | - } |
|
| 266 | - } |
|
| 255 | + // version installee par GIT |
|
| 256 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 257 | + $currentHead = trim(substr($c, 4)); |
|
| 258 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 259 | + return [ |
|
| 260 | + 'vcs' => 'GIT', |
|
| 261 | + 'branch' => basename($currentHead), |
|
| 262 | + 'commit' => trim($hash), |
|
| 263 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 264 | + ]; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - return null; |
|
| 268 | + return null; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | |
@@ -278,25 +278,25 @@ discard block |
||
| 278 | 278 | * array ['commit' => yy, 'date' => xx, 'author' => xx] sinon. |
| 279 | 279 | **/ |
| 280 | 280 | function decrire_version_svn($dir) { |
| 281 | - if (!$dir) { |
|
| 282 | - $dir = '.'; |
|
| 283 | - } |
|
| 284 | - // version installee par SVN |
|
| 285 | - if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 286 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 287 | - $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 288 | - if ($result) { |
|
| 289 | - $row = $result->fetchArray(); |
|
| 290 | - if ($row['changed_revision'] != '') { |
|
| 291 | - return [ |
|
| 292 | - 'vcs' => 'SVN', |
|
| 293 | - 'branch' => '', |
|
| 294 | - 'commit' => $row['changed_revision'], |
|
| 295 | - ]; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - return null; |
|
| 281 | + if (!$dir) { |
|
| 282 | + $dir = '.'; |
|
| 283 | + } |
|
| 284 | + // version installee par SVN |
|
| 285 | + if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 286 | + $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 287 | + $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 288 | + if ($result) { |
|
| 289 | + $row = $result->fetchArray(); |
|
| 290 | + if ($row['changed_revision'] != '') { |
|
| 291 | + return [ |
|
| 292 | + 'vcs' => 'SVN', |
|
| 293 | + 'branch' => '', |
|
| 294 | + 'commit' => $row['changed_revision'], |
|
| 295 | + ]; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + return null; |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -343,18 +343,18 @@ discard block |
||
| 343 | 343 | * Code HTML retourné par le filtre |
| 344 | 344 | **/ |
| 345 | 345 | function filtrer($filtre) { |
| 346 | - $tous = func_get_args(); |
|
| 347 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 348 | - return image_filtrer($tous); |
|
| 349 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 350 | - array_shift($tous); |
|
| 351 | - return $f(...$tous); |
|
| 352 | - } else { |
|
| 353 | - // le filtre n'existe pas, on provoque une erreur |
|
| 354 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 355 | - erreur_squelette($msg); |
|
| 356 | - return ''; |
|
| 357 | - } |
|
| 346 | + $tous = func_get_args(); |
|
| 347 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 348 | + return image_filtrer($tous); |
|
| 349 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 350 | + array_shift($tous); |
|
| 351 | + return $f(...$tous); |
|
| 352 | + } else { |
|
| 353 | + // le filtre n'existe pas, on provoque une erreur |
|
| 354 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 355 | + erreur_squelette($msg); |
|
| 356 | + return ''; |
|
| 357 | + } |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -371,11 +371,11 @@ discard block |
||
| 371 | 371 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 372 | 372 | */ |
| 373 | 373 | function trouver_filtre_matrice($filtre) { |
| 374 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 375 | - find_in_path($f, '', true); |
|
| 376 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 377 | - } |
|
| 378 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 374 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 375 | + find_in_path($f, '', true); |
|
| 376 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 377 | + } |
|
| 378 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | |
@@ -403,8 +403,8 @@ discard block |
||
| 403 | 403 | * @return mixed |
| 404 | 404 | */ |
| 405 | 405 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 406 | - $Pile['vars'][$key] = $val; |
|
| 407 | - return $continue ? $val : ''; |
|
| 406 | + $Pile['vars'][$key] = $val; |
|
| 407 | + return $continue ? $val : ''; |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -430,8 +430,8 @@ discard block |
||
| 430 | 430 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 431 | 431 | */ |
| 432 | 432 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 433 | - $Pile[0][$key] = $val; |
|
| 434 | - return $continue ? $val : ''; |
|
| 433 | + $Pile[0][$key] = $val; |
|
| 434 | + return $continue ? $val : ''; |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -440,8 +440,8 @@ discard block |
||
| 440 | 440 | * @return string |
| 441 | 441 | */ |
| 442 | 442 | function filtre_sanitize_env(&$Pile, $keys) { |
| 443 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 444 | - return ''; |
|
| 443 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 444 | + return ''; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | |
@@ -464,18 +464,18 @@ discard block |
||
| 464 | 464 | * @return mixed Retourne la valeur (sans la modifier). |
| 465 | 465 | */ |
| 466 | 466 | function filtre_debug($val, $key = null) { |
| 467 | - $debug = ( |
|
| 468 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 469 | - ) . var_export($val, true); |
|
| 467 | + $debug = ( |
|
| 468 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 469 | + ) . var_export($val, true); |
|
| 470 | 470 | |
| 471 | - include_spip('inc/autoriser'); |
|
| 472 | - if (autoriser('webmestre')) { |
|
| 473 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 474 | - } |
|
| 471 | + include_spip('inc/autoriser'); |
|
| 472 | + if (autoriser('webmestre')) { |
|
| 473 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 474 | + } |
|
| 475 | 475 | |
| 476 | - spip_log($debug, 'debug'); |
|
| 476 | + spip_log($debug, 'debug'); |
|
| 477 | 477 | |
| 478 | - return $val; |
|
| 478 | + return $val; |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | |
@@ -505,84 +505,84 @@ discard block |
||
| 505 | 505 | * Texte qui a reçu les filtres |
| 506 | 506 | **/ |
| 507 | 507 | function image_filtrer($args) { |
| 508 | - $filtre = array_shift($args); # enlever $filtre |
|
| 509 | - $texte = array_shift($args); |
|
| 510 | - if ($texte === null || !strlen($texte)) { |
|
| 511 | - return ''; |
|
| 512 | - } |
|
| 513 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 514 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 515 | - // Cas du nom de fichier local |
|
| 516 | - $is_file = trim($texte); |
|
| 517 | - if ( |
|
| 518 | - strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 519 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 520 | - or strpos($is_file, '/') === 0 |
|
| 521 | - ) { |
|
| 522 | - $is_file = false; |
|
| 523 | - } |
|
| 524 | - if ($is_file) { |
|
| 525 | - $is_local_file = function ($path) { |
|
| 526 | - if (strpos($path, '?') !== false) { |
|
| 527 | - $path = supprimer_timestamp($path); |
|
| 528 | - // remove ?24px added by find_in_theme on .svg files |
|
| 529 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 530 | - } |
|
| 531 | - return file_exists($path); |
|
| 532 | - }; |
|
| 533 | - if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 534 | - $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 535 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 536 | - return $res; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 541 | - if ( |
|
| 542 | - preg_match_all( |
|
| 543 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 544 | - $texte, |
|
| 545 | - $tags, |
|
| 546 | - PREG_SET_ORDER |
|
| 547 | - ) |
|
| 548 | - ) { |
|
| 549 | - foreach ($tags as $tag) { |
|
| 550 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 551 | - if ( |
|
| 552 | - !$class or |
|
| 553 | - (strpos($class, 'filtre_inactif') === false |
|
| 554 | - // compat historique a virer en 3.2 |
|
| 555 | - and strpos($class, 'no_image_filtrer') === false) |
|
| 556 | - ) { |
|
| 557 | - if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 558 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 559 | - if ($tag[1]) { |
|
| 560 | - $w = extraire_attribut($reduit, 'width'); |
|
| 561 | - if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 562 | - $w = $regs[1]; |
|
| 563 | - } |
|
| 564 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 565 | - $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 566 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 567 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - // traiter aussi un eventuel mouseover |
|
| 571 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 572 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 573 | - $srcover = $match[1]; |
|
| 574 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 575 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 576 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 585 | - return $texte; |
|
| 508 | + $filtre = array_shift($args); # enlever $filtre |
|
| 509 | + $texte = array_shift($args); |
|
| 510 | + if ($texte === null || !strlen($texte)) { |
|
| 511 | + return ''; |
|
| 512 | + } |
|
| 513 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 514 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 515 | + // Cas du nom de fichier local |
|
| 516 | + $is_file = trim($texte); |
|
| 517 | + if ( |
|
| 518 | + strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 519 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 520 | + or strpos($is_file, '/') === 0 |
|
| 521 | + ) { |
|
| 522 | + $is_file = false; |
|
| 523 | + } |
|
| 524 | + if ($is_file) { |
|
| 525 | + $is_local_file = function ($path) { |
|
| 526 | + if (strpos($path, '?') !== false) { |
|
| 527 | + $path = supprimer_timestamp($path); |
|
| 528 | + // remove ?24px added by find_in_theme on .svg files |
|
| 529 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 530 | + } |
|
| 531 | + return file_exists($path); |
|
| 532 | + }; |
|
| 533 | + if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 534 | + $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 535 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 536 | + return $res; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 541 | + if ( |
|
| 542 | + preg_match_all( |
|
| 543 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 544 | + $texte, |
|
| 545 | + $tags, |
|
| 546 | + PREG_SET_ORDER |
|
| 547 | + ) |
|
| 548 | + ) { |
|
| 549 | + foreach ($tags as $tag) { |
|
| 550 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 551 | + if ( |
|
| 552 | + !$class or |
|
| 553 | + (strpos($class, 'filtre_inactif') === false |
|
| 554 | + // compat historique a virer en 3.2 |
|
| 555 | + and strpos($class, 'no_image_filtrer') === false) |
|
| 556 | + ) { |
|
| 557 | + if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 558 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 559 | + if ($tag[1]) { |
|
| 560 | + $w = extraire_attribut($reduit, 'width'); |
|
| 561 | + if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 562 | + $w = $regs[1]; |
|
| 563 | + } |
|
| 564 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 565 | + $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 566 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 567 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + // traiter aussi un eventuel mouseover |
|
| 571 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 572 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 573 | + $srcover = $match[1]; |
|
| 574 | + $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 575 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 576 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 585 | + return $texte; |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | /** |
@@ -599,91 +599,91 @@ discard block |
||
| 599 | 599 | **/ |
| 600 | 600 | function infos_image($img, $force_refresh = false) { |
| 601 | 601 | |
| 602 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 603 | - $srcWidth = 0; |
|
| 604 | - $srcHeight = 0; |
|
| 605 | - $srcSize = null; |
|
| 606 | - |
|
| 607 | - $src = extraire_attribut($img, 'src'); |
|
| 608 | - |
|
| 609 | - if (!$src) { |
|
| 610 | - $src = $img; |
|
| 611 | - } else { |
|
| 612 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 613 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 617 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 618 | - if (tester_url_absolue($src)) { |
|
| 619 | - include_spip('inc/distant'); |
|
| 620 | - $fichier = copie_locale($src); |
|
| 621 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 622 | - } |
|
| 623 | - if (($p = strpos($src, '?')) !== false) { |
|
| 624 | - $src = substr($src, 0, $p); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - $imagesize = false; |
|
| 628 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 629 | - $srcWidth = $largeur_img[$src]; |
|
| 630 | - } |
|
| 631 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 632 | - $srcHeight = $hauteur_img[$src]; |
|
| 633 | - } |
|
| 634 | - if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 635 | - $srcSize = $poids_img[$src]; |
|
| 636 | - } |
|
| 637 | - if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 638 | - if ( |
|
| 639 | - file_exists($src) |
|
| 640 | - and $imagesize = spip_getimagesize($src) |
|
| 641 | - ) { |
|
| 642 | - if (!$srcWidth) { |
|
| 643 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 644 | - } |
|
| 645 | - if (!$srcHeight) { |
|
| 646 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 647 | - } |
|
| 648 | - if (!$srcSize) { |
|
| 649 | - $poids_img[$src] = filesize($src); |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - elseif (strpos($src, '<svg') !== false) { |
|
| 653 | - include_spip('inc/svg'); |
|
| 654 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 655 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 656 | - if (!$srcWidth) { |
|
| 657 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 658 | - } |
|
| 659 | - if (!$srcHeight) { |
|
| 660 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 661 | - } |
|
| 662 | - if (!$srcSize) { |
|
| 663 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 664 | - } |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 668 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 669 | - elseif ( |
|
| 670 | - @file_exists($f = "$src.src") |
|
| 671 | - and lire_fichier($f, $valeurs) |
|
| 672 | - and $valeurs = unserialize($valeurs) |
|
| 673 | - ) { |
|
| 674 | - if (!$srcWidth) { |
|
| 675 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 676 | - } |
|
| 677 | - if (!$srcHeight) { |
|
| 678 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 679 | - } |
|
| 680 | - if (!$srcSize) { |
|
| 681 | - $poids_img[$src] = $srcSize = 0; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 602 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 603 | + $srcWidth = 0; |
|
| 604 | + $srcHeight = 0; |
|
| 605 | + $srcSize = null; |
|
| 606 | + |
|
| 607 | + $src = extraire_attribut($img, 'src'); |
|
| 608 | + |
|
| 609 | + if (!$src) { |
|
| 610 | + $src = $img; |
|
| 611 | + } else { |
|
| 612 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 613 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 617 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 618 | + if (tester_url_absolue($src)) { |
|
| 619 | + include_spip('inc/distant'); |
|
| 620 | + $fichier = copie_locale($src); |
|
| 621 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 622 | + } |
|
| 623 | + if (($p = strpos($src, '?')) !== false) { |
|
| 624 | + $src = substr($src, 0, $p); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + $imagesize = false; |
|
| 628 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 629 | + $srcWidth = $largeur_img[$src]; |
|
| 630 | + } |
|
| 631 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 632 | + $srcHeight = $hauteur_img[$src]; |
|
| 633 | + } |
|
| 634 | + if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 635 | + $srcSize = $poids_img[$src]; |
|
| 636 | + } |
|
| 637 | + if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 638 | + if ( |
|
| 639 | + file_exists($src) |
|
| 640 | + and $imagesize = spip_getimagesize($src) |
|
| 641 | + ) { |
|
| 642 | + if (!$srcWidth) { |
|
| 643 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 644 | + } |
|
| 645 | + if (!$srcHeight) { |
|
| 646 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 647 | + } |
|
| 648 | + if (!$srcSize) { |
|
| 649 | + $poids_img[$src] = filesize($src); |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + elseif (strpos($src, '<svg') !== false) { |
|
| 653 | + include_spip('inc/svg'); |
|
| 654 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 655 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 656 | + if (!$srcWidth) { |
|
| 657 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 658 | + } |
|
| 659 | + if (!$srcHeight) { |
|
| 660 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 661 | + } |
|
| 662 | + if (!$srcSize) { |
|
| 663 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 664 | + } |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 668 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 669 | + elseif ( |
|
| 670 | + @file_exists($f = "$src.src") |
|
| 671 | + and lire_fichier($f, $valeurs) |
|
| 672 | + and $valeurs = unserialize($valeurs) |
|
| 673 | + ) { |
|
| 674 | + if (!$srcWidth) { |
|
| 675 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 676 | + } |
|
| 677 | + if (!$srcHeight) { |
|
| 678 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 679 | + } |
|
| 680 | + if (!$srcSize) { |
|
| 681 | + $poids_img[$src] = $srcSize = 0; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | /** |
@@ -699,13 +699,13 @@ discard block |
||
| 699 | 699 | * poids |
| 700 | 700 | **/ |
| 701 | 701 | function poids_image($img, $force_refresh = false) { |
| 702 | - $infos = infos_image($img, $force_refresh); |
|
| 703 | - return $infos['poids']; |
|
| 702 | + $infos = infos_image($img, $force_refresh); |
|
| 703 | + return $infos['poids']; |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | function taille_image($img, $force_refresh = false) { |
| 707 | - $infos = infos_image($img, $force_refresh); |
|
| 708 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 707 | + $infos = infos_image($img, $force_refresh); |
|
| 708 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -722,12 +722,12 @@ discard block |
||
| 722 | 722 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 723 | 723 | **/ |
| 724 | 724 | function largeur($img) { |
| 725 | - if (!$img) { |
|
| 726 | - return; |
|
| 727 | - } |
|
| 728 | - [$h, $l] = taille_image($img); |
|
| 725 | + if (!$img) { |
|
| 726 | + return; |
|
| 727 | + } |
|
| 728 | + [$h, $l] = taille_image($img); |
|
| 729 | 729 | |
| 730 | - return $l; |
|
| 730 | + return $l; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -744,12 +744,12 @@ discard block |
||
| 744 | 744 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 745 | 745 | **/ |
| 746 | 746 | function hauteur($img) { |
| 747 | - if (!$img) { |
|
| 748 | - return; |
|
| 749 | - } |
|
| 750 | - [$h, $l] = taille_image($img); |
|
| 747 | + if (!$img) { |
|
| 748 | + return; |
|
| 749 | + } |
|
| 750 | + [$h, $l] = taille_image($img); |
|
| 751 | 751 | |
| 752 | - return $h; |
|
| 752 | + return $h; |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | |
@@ -769,11 +769,11 @@ discard block |
||
| 769 | 769 | * @return string |
| 770 | 770 | **/ |
| 771 | 771 | function corriger_entites_html($texte) { |
| 772 | - if (strpos($texte, '&') === false) { |
|
| 773 | - return $texte; |
|
| 774 | - } |
|
| 772 | + if (strpos($texte, '&') === false) { |
|
| 773 | + return $texte; |
|
| 774 | + } |
|
| 775 | 775 | |
| 776 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 776 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | /** |
@@ -788,11 +788,11 @@ discard block |
||
| 788 | 788 | * @return string |
| 789 | 789 | **/ |
| 790 | 790 | function corriger_toutes_entites_html($texte) { |
| 791 | - if (strpos($texte, '&') === false) { |
|
| 792 | - return $texte; |
|
| 793 | - } |
|
| 791 | + if (strpos($texte, '&') === false) { |
|
| 792 | + return $texte; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 795 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | * @return string |
| 803 | 803 | **/ |
| 804 | 804 | function proteger_amp($texte) { |
| 805 | - return str_replace('&', '&', $texte); |
|
| 805 | + return str_replace('&', '&', $texte); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | |
@@ -833,21 +833,21 @@ discard block |
||
| 833 | 833 | * @return mixed|string |
| 834 | 834 | */ |
| 835 | 835 | function entites_html($texte, $tout = false, $quote = true) { |
| 836 | - if ( |
|
| 837 | - !is_string($texte) or !$texte |
|
| 838 | - or strpbrk($texte, "&\"'<>") == false |
|
| 839 | - ) { |
|
| 840 | - return $texte; |
|
| 841 | - } |
|
| 842 | - include_spip('inc/texte'); |
|
| 843 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 844 | - $flags |= ENT_HTML401; |
|
| 845 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 846 | - if ($tout) { |
|
| 847 | - return corriger_toutes_entites_html($texte); |
|
| 848 | - } else { |
|
| 849 | - return corriger_entites_html($texte); |
|
| 850 | - } |
|
| 836 | + if ( |
|
| 837 | + !is_string($texte) or !$texte |
|
| 838 | + or strpbrk($texte, "&\"'<>") == false |
|
| 839 | + ) { |
|
| 840 | + return $texte; |
|
| 841 | + } |
|
| 842 | + include_spip('inc/texte'); |
|
| 843 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 844 | + $flags |= ENT_HTML401; |
|
| 845 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 846 | + if ($tout) { |
|
| 847 | + return corriger_toutes_entites_html($texte); |
|
| 848 | + } else { |
|
| 849 | + return corriger_entites_html($texte); |
|
| 850 | + } |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | /** |
@@ -866,38 +866,38 @@ discard block |
||
| 866 | 866 | * Texte converti |
| 867 | 867 | **/ |
| 868 | 868 | function filtrer_entites(?string $texte): string { |
| 869 | - $texte ??= ''; |
|
| 870 | - if (strpos($texte, '&') === false) { |
|
| 871 | - return $texte; |
|
| 872 | - } |
|
| 873 | - // filtrer |
|
| 874 | - $texte = html2unicode($texte); |
|
| 875 | - // remettre le tout dans le charset cible |
|
| 876 | - $texte = unicode2charset($texte); |
|
| 877 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 878 | - // (on le faisait deja avec un ") |
|
| 879 | - if (strpos($texte, '&#') !== false) { |
|
| 880 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 881 | - } |
|
| 869 | + $texte ??= ''; |
|
| 870 | + if (strpos($texte, '&') === false) { |
|
| 871 | + return $texte; |
|
| 872 | + } |
|
| 873 | + // filtrer |
|
| 874 | + $texte = html2unicode($texte); |
|
| 875 | + // remettre le tout dans le charset cible |
|
| 876 | + $texte = unicode2charset($texte); |
|
| 877 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 878 | + // (on le faisait deja avec un ") |
|
| 879 | + if (strpos($texte, '&#') !== false) { |
|
| 880 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 881 | + } |
|
| 882 | 882 | |
| 883 | - return $texte; |
|
| 883 | + return $texte; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | |
| 887 | 887 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 888 | - /** |
|
| 889 | - * Version sécurisée de filtrer_entites |
|
| 890 | - * |
|
| 891 | - * @uses interdire_scripts() |
|
| 892 | - * @uses filtrer_entites() |
|
| 893 | - * |
|
| 894 | - * @param string $t |
|
| 895 | - * @return string |
|
| 896 | - */ |
|
| 897 | - function filtre_filtrer_entites_dist($t) { |
|
| 898 | - include_spip('inc/texte'); |
|
| 899 | - return interdire_scripts(filtrer_entites($t)); |
|
| 900 | - } |
|
| 888 | + /** |
|
| 889 | + * Version sécurisée de filtrer_entites |
|
| 890 | + * |
|
| 891 | + * @uses interdire_scripts() |
|
| 892 | + * @uses filtrer_entites() |
|
| 893 | + * |
|
| 894 | + * @param string $t |
|
| 895 | + * @return string |
|
| 896 | + */ |
|
| 897 | + function filtre_filtrer_entites_dist($t) { |
|
| 898 | + include_spip('inc/texte'); |
|
| 899 | + return interdire_scripts(filtrer_entites($t)); |
|
| 900 | + } |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | |
@@ -912,18 +912,18 @@ discard block |
||
| 912 | 912 | * @return string|array |
| 913 | 913 | **/ |
| 914 | 914 | function supprimer_caracteres_illegaux($texte) { |
| 915 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 916 | - static $to = null; |
|
| 915 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 916 | + static $to = null; |
|
| 917 | 917 | |
| 918 | - if (is_array($texte)) { |
|
| 919 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 920 | - } |
|
| 918 | + if (is_array($texte)) { |
|
| 919 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 920 | + } |
|
| 921 | 921 | |
| 922 | - if (!$to) { |
|
| 923 | - $to = str_repeat('-', strlen($from)); |
|
| 924 | - } |
|
| 922 | + if (!$to) { |
|
| 923 | + $to = str_repeat('-', strlen($from)); |
|
| 924 | + } |
|
| 925 | 925 | |
| 926 | - return strtr($texte, $from, $to); |
|
| 926 | + return strtr($texte, $from, $to); |
|
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | /** |
@@ -935,10 +935,10 @@ discard block |
||
| 935 | 935 | * @return string|array |
| 936 | 936 | **/ |
| 937 | 937 | function corriger_caracteres($texte) { |
| 938 | - $texte = corriger_caracteres_windows($texte); |
|
| 939 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 938 | + $texte = corriger_caracteres_windows($texte); |
|
| 939 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 940 | 940 | |
| 941 | - return $texte; |
|
| 941 | + return $texte; |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | /** |
@@ -955,44 +955,44 @@ discard block |
||
| 955 | 955 | * Texte encodé pour XML |
| 956 | 956 | */ |
| 957 | 957 | function texte_backend(string $texte): string { |
| 958 | - if ($texte === '') { |
|
| 959 | - return ''; |
|
| 960 | - } |
|
| 958 | + if ($texte === '') { |
|
| 959 | + return ''; |
|
| 960 | + } |
|
| 961 | 961 | |
| 962 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 962 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 963 | 963 | |
| 964 | - // si on a des liens ou des images, les passer en absolu |
|
| 965 | - $texte = liens_absolus($texte); |
|
| 964 | + // si on a des liens ou des images, les passer en absolu |
|
| 965 | + $texte = liens_absolus($texte); |
|
| 966 | 966 | |
| 967 | - // echapper les tags > < |
|
| 968 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 967 | + // echapper les tags > < |
|
| 968 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 969 | 969 | |
| 970 | - // importer les é |
|
| 971 | - $texte = filtrer_entites($texte); |
|
| 970 | + // importer les é |
|
| 971 | + $texte = filtrer_entites($texte); |
|
| 972 | 972 | |
| 973 | - // " -> " et tout ce genre de choses |
|
| 974 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 975 | - $texte = str_replace(' ', ' ', $texte); |
|
| 976 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 977 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 978 | - $texte = entites_html($texte, false, false); |
|
| 979 | - // mais bien echapper les double quotes ! |
|
| 980 | - $texte = str_replace('"', '"', $texte); |
|
| 973 | + // " -> " et tout ce genre de choses |
|
| 974 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 975 | + $texte = str_replace(' ', ' ', $texte); |
|
| 976 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 977 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 978 | + $texte = entites_html($texte, false, false); |
|
| 979 | + // mais bien echapper les double quotes ! |
|
| 980 | + $texte = str_replace('"', '"', $texte); |
|
| 981 | 981 | |
| 982 | - // verifier le charset |
|
| 983 | - $texte = charset2unicode($texte); |
|
| 982 | + // verifier le charset |
|
| 983 | + $texte = charset2unicode($texte); |
|
| 984 | 984 | |
| 985 | - // Caracteres problematiques en iso-latin 1 |
|
| 986 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 987 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 988 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 989 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 990 | - } |
|
| 985 | + // Caracteres problematiques en iso-latin 1 |
|
| 986 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 987 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 988 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 989 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 990 | + } |
|
| 991 | 991 | |
| 992 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 993 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 994 | - // ==> on les remplace par l'entite HTML |
|
| 995 | - return str_replace($apostrophe, "'", $texte); |
|
| 992 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 993 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 994 | + // ==> on les remplace par l'entite HTML |
|
| 995 | + return str_replace($apostrophe, "'", $texte); |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | /** |
@@ -1009,7 +1009,7 @@ discard block |
||
| 1009 | 1009 | * Texte encodé et quote pour XML |
| 1010 | 1010 | */ |
| 1011 | 1011 | function texte_backendq(string $texte): string { |
| 1012 | - return addslashes(texte_backend($texte)); |
|
| 1012 | + return addslashes(texte_backend($texte)); |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | |
@@ -1032,11 +1032,11 @@ discard block |
||
| 1032 | 1032 | * Numéro de titre, sinon chaîne vide |
| 1033 | 1033 | **/ |
| 1034 | 1034 | function supprimer_numero($texte) { |
| 1035 | - return preg_replace( |
|
| 1036 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1037 | - '', |
|
| 1038 | - $texte |
|
| 1039 | - ); |
|
| 1035 | + return preg_replace( |
|
| 1036 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1037 | + '', |
|
| 1038 | + $texte |
|
| 1039 | + ); |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | /** |
@@ -1059,18 +1059,18 @@ discard block |
||
| 1059 | 1059 | * Numéro de titre, sinon chaîne vide |
| 1060 | 1060 | **/ |
| 1061 | 1061 | function recuperer_numero($texte) { |
| 1062 | - if ( |
|
| 1063 | - $texte and |
|
| 1064 | - preg_match( |
|
| 1065 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1066 | - $texte, |
|
| 1067 | - $regs |
|
| 1068 | - ) |
|
| 1069 | - ) { |
|
| 1070 | - return strval($regs[1]); |
|
| 1071 | - } else { |
|
| 1072 | - return ''; |
|
| 1073 | - } |
|
| 1062 | + if ( |
|
| 1063 | + $texte and |
|
| 1064 | + preg_match( |
|
| 1065 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1066 | + $texte, |
|
| 1067 | + $regs |
|
| 1068 | + ) |
|
| 1069 | + ) { |
|
| 1070 | + return strval($regs[1]); |
|
| 1071 | + } else { |
|
| 1072 | + return ''; |
|
| 1073 | + } |
|
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | 1076 | /** |
@@ -1097,16 +1097,16 @@ discard block |
||
| 1097 | 1097 | * Texte ou tableau de textes converti |
| 1098 | 1098 | **/ |
| 1099 | 1099 | function supprimer_tags($texte, $rempl = '') { |
| 1100 | - if ($texte === null) { |
|
| 1101 | - return ''; |
|
| 1102 | - } |
|
| 1103 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1104 | - // ne pas oublier un < final non ferme car coupe |
|
| 1105 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1106 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1107 | - $texte = str_replace('<', '<', $texte); |
|
| 1100 | + if ($texte === null) { |
|
| 1101 | + return ''; |
|
| 1102 | + } |
|
| 1103 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1104 | + // ne pas oublier un < final non ferme car coupe |
|
| 1105 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1106 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1107 | + $texte = str_replace('<', '<', $texte); |
|
| 1108 | 1108 | |
| 1109 | - return $texte; |
|
| 1109 | + return $texte; |
|
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | 1112 | /** |
@@ -1129,9 +1129,9 @@ discard block |
||
| 1129 | 1129 | * Texte converti |
| 1130 | 1130 | **/ |
| 1131 | 1131 | function echapper_tags($texte, $rempl = '') { |
| 1132 | - $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1132 | + $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1133 | 1133 | |
| 1134 | - return $texte; |
|
| 1134 | + return $texte; |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | /** |
@@ -1152,18 +1152,18 @@ discard block |
||
| 1152 | 1152 | * Texte converti |
| 1153 | 1153 | **/ |
| 1154 | 1154 | function textebrut($texte) { |
| 1155 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1156 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1157 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1158 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1159 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1160 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1161 | - $texte = supprimer_tags($texte); |
|
| 1162 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1163 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1164 | - $texte = str_replace('’', "'", $texte); |
|
| 1155 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1156 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1157 | + $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1158 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1159 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1160 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1161 | + $texte = supprimer_tags($texte); |
|
| 1162 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1163 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1164 | + $texte = str_replace('’', "'", $texte); |
|
| 1165 | 1165 | |
| 1166 | - return $texte; |
|
| 1166 | + return $texte; |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | |
@@ -1179,23 +1179,23 @@ discard block |
||
| 1179 | 1179 | * Texte avec liens ouvrants |
| 1180 | 1180 | **/ |
| 1181 | 1181 | function liens_ouvrants($texte) { |
| 1182 | - if ( |
|
| 1183 | - preg_match_all( |
|
| 1184 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1185 | - $texte, |
|
| 1186 | - $liens, |
|
| 1187 | - PREG_PATTERN_ORDER |
|
| 1188 | - ) |
|
| 1189 | - ) { |
|
| 1190 | - foreach ($liens[0] as $a) { |
|
| 1191 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1192 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1193 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1194 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1195 | - } |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - return $texte; |
|
| 1182 | + if ( |
|
| 1183 | + preg_match_all( |
|
| 1184 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1185 | + $texte, |
|
| 1186 | + $liens, |
|
| 1187 | + PREG_PATTERN_ORDER |
|
| 1188 | + ) |
|
| 1189 | + ) { |
|
| 1190 | + foreach ($liens[0] as $a) { |
|
| 1191 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1192 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1193 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1194 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1195 | + } |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + return $texte; |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | /** |
@@ -1205,22 +1205,22 @@ discard block |
||
| 1205 | 1205 | * @return string |
| 1206 | 1206 | */ |
| 1207 | 1207 | function liens_nofollow($texte) { |
| 1208 | - if (stripos($texte, '<a') === false) { |
|
| 1209 | - return $texte; |
|
| 1210 | - } |
|
| 1208 | + if (stripos($texte, '<a') === false) { |
|
| 1209 | + return $texte; |
|
| 1210 | + } |
|
| 1211 | 1211 | |
| 1212 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1213 | - foreach ($regs[0] as $a) { |
|
| 1214 | - $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1215 | - if (strpos($rel, 'nofollow') === false) { |
|
| 1216 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1217 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1218 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1219 | - } |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1212 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1213 | + foreach ($regs[0] as $a) { |
|
| 1214 | + $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1215 | + if (strpos($rel, 'nofollow') === false) { |
|
| 1216 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1217 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1218 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1219 | + } |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | 1222 | |
| 1223 | - return $texte; |
|
| 1223 | + return $texte; |
|
| 1224 | 1224 | } |
| 1225 | 1225 | |
| 1226 | 1226 | /** |
@@ -1239,12 +1239,12 @@ discard block |
||
| 1239 | 1239 | * Texte sans paraghaphes |
| 1240 | 1240 | **/ |
| 1241 | 1241 | function PtoBR($texte) { |
| 1242 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1243 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1244 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1245 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1242 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1243 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1244 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1245 | + $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1246 | 1246 | |
| 1247 | - return $texte; |
|
| 1247 | + return $texte; |
|
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | 1250 | |
@@ -1269,14 +1269,14 @@ discard block |
||
| 1269 | 1269 | * @return string Texte encadré du style CSS |
| 1270 | 1270 | */ |
| 1271 | 1271 | function lignes_longues($texte) { |
| 1272 | - if (!strlen(trim($texte))) { |
|
| 1273 | - return $texte; |
|
| 1274 | - } |
|
| 1275 | - include_spip('inc/texte'); |
|
| 1276 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1277 | - 'div' : 'span'; |
|
| 1272 | + if (!strlen(trim($texte))) { |
|
| 1273 | + return $texte; |
|
| 1274 | + } |
|
| 1275 | + include_spip('inc/texte'); |
|
| 1276 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1277 | + 'div' : 'span'; |
|
| 1278 | 1278 | |
| 1279 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1279 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | /** |
@@ -1295,30 +1295,30 @@ discard block |
||
| 1295 | 1295 | * @return string Texte en majuscule |
| 1296 | 1296 | */ |
| 1297 | 1297 | function majuscules($texte) { |
| 1298 | - if (!strlen($texte)) { |
|
| 1299 | - return ''; |
|
| 1300 | - } |
|
| 1298 | + if (!strlen($texte)) { |
|
| 1299 | + return ''; |
|
| 1300 | + } |
|
| 1301 | 1301 | |
| 1302 | - // Cas du turc |
|
| 1303 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1304 | - # remplacer hors des tags et des entites |
|
| 1305 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1306 | - foreach ($regs as $n => $match) { |
|
| 1307 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1308 | - } |
|
| 1309 | - } |
|
| 1302 | + // Cas du turc |
|
| 1303 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1304 | + # remplacer hors des tags et des entites |
|
| 1305 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1306 | + foreach ($regs as $n => $match) { |
|
| 1307 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1308 | + } |
|
| 1309 | + } |
|
| 1310 | 1310 | |
| 1311 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1311 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1312 | 1312 | |
| 1313 | - if ($regs) { |
|
| 1314 | - foreach ($regs as $n => $match) { |
|
| 1315 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1316 | - } |
|
| 1317 | - } |
|
| 1318 | - } |
|
| 1313 | + if ($regs) { |
|
| 1314 | + foreach ($regs as $n => $match) { |
|
| 1315 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1316 | + } |
|
| 1317 | + } |
|
| 1318 | + } |
|
| 1319 | 1319 | |
| 1320 | - // Cas general |
|
| 1321 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1320 | + // Cas general |
|
| 1321 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | 1324 | /** |
@@ -1336,29 +1336,29 @@ discard block |
||
| 1336 | 1336 | * @return string |
| 1337 | 1337 | **/ |
| 1338 | 1338 | function taille_en_octets($taille) { |
| 1339 | - if (!defined('_KILOBYTE')) { |
|
| 1340 | - /** |
|
| 1341 | - * Définit le nombre d'octets dans un Kilobyte |
|
| 1342 | - * |
|
| 1343 | - * @var int |
|
| 1344 | - **/ |
|
| 1345 | - define('_KILOBYTE', 1024); |
|
| 1346 | - } |
|
| 1339 | + if (!defined('_KILOBYTE')) { |
|
| 1340 | + /** |
|
| 1341 | + * Définit le nombre d'octets dans un Kilobyte |
|
| 1342 | + * |
|
| 1343 | + * @var int |
|
| 1344 | + **/ |
|
| 1345 | + define('_KILOBYTE', 1024); |
|
| 1346 | + } |
|
| 1347 | 1347 | |
| 1348 | - if ($taille < 1) { |
|
| 1349 | - return ''; |
|
| 1350 | - } |
|
| 1351 | - if ($taille < _KILOBYTE) { |
|
| 1352 | - $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1353 | - } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1354 | - $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1355 | - } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1356 | - $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1357 | - } else { |
|
| 1358 | - $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1359 | - } |
|
| 1348 | + if ($taille < 1) { |
|
| 1349 | + return ''; |
|
| 1350 | + } |
|
| 1351 | + if ($taille < _KILOBYTE) { |
|
| 1352 | + $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1353 | + } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1354 | + $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1355 | + } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1356 | + $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1357 | + } else { |
|
| 1358 | + $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1359 | + } |
|
| 1360 | 1360 | |
| 1361 | - return $taille; |
|
| 1361 | + return $taille; |
|
| 1362 | 1362 | } |
| 1363 | 1363 | |
| 1364 | 1364 | |
@@ -1380,21 +1380,21 @@ discard block |
||
| 1380 | 1380 | * Texte prêt pour être utilisé en attribut HTML |
| 1381 | 1381 | **/ |
| 1382 | 1382 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1383 | - if ($texte === null) { |
|
| 1384 | - return ''; |
|
| 1385 | - } |
|
| 1386 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1387 | - if ($textebrut) { |
|
| 1388 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1389 | - } |
|
| 1390 | - $texte = texte_backend($texte); |
|
| 1391 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1383 | + if ($texte === null) { |
|
| 1384 | + return ''; |
|
| 1385 | + } |
|
| 1386 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1387 | + if ($textebrut) { |
|
| 1388 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1389 | + } |
|
| 1390 | + $texte = texte_backend($texte); |
|
| 1391 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1392 | 1392 | |
| 1393 | - return preg_replace( |
|
| 1394 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1395 | - ['&', '&'], |
|
| 1396 | - $texte |
|
| 1397 | - ); |
|
| 1393 | + return preg_replace( |
|
| 1394 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1395 | + ['&', '&'], |
|
| 1396 | + $texte |
|
| 1397 | + ); |
|
| 1398 | 1398 | } |
| 1399 | 1399 | |
| 1400 | 1400 | |
@@ -1414,15 +1414,15 @@ discard block |
||
| 1414 | 1414 | * URL ou chaîne vide |
| 1415 | 1415 | **/ |
| 1416 | 1416 | function vider_url(?string $url, $entites = true): string { |
| 1417 | - if ($url === null) { |
|
| 1418 | - return ''; |
|
| 1419 | - } |
|
| 1420 | - # un message pour abs_url |
|
| 1421 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1422 | - $url = trim($url); |
|
| 1423 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1417 | + if ($url === null) { |
|
| 1418 | + return ''; |
|
| 1419 | + } |
|
| 1420 | + # un message pour abs_url |
|
| 1421 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1422 | + $url = trim($url); |
|
| 1423 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1424 | 1424 | |
| 1425 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1425 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | 1428 | |
@@ -1437,10 +1437,10 @@ discard block |
||
| 1437 | 1437 | * @return string Adresse email maquillée |
| 1438 | 1438 | **/ |
| 1439 | 1439 | function antispam($texte) { |
| 1440 | - include_spip('inc/acces'); |
|
| 1441 | - $masque = creer_pass_aleatoire(3); |
|
| 1440 | + include_spip('inc/acces'); |
|
| 1441 | + $masque = creer_pass_aleatoire(3); |
|
| 1442 | 1442 | |
| 1443 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1443 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | 1446 | /** |
@@ -1472,8 +1472,8 @@ discard block |
||
| 1472 | 1472 | * True si on a le droit d'accès, false sinon. |
| 1473 | 1473 | **/ |
| 1474 | 1474 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1475 | - include_spip('inc/acces'); |
|
| 1476 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1475 | + include_spip('inc/acces'); |
|
| 1476 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1477 | 1477 | } |
| 1478 | 1478 | |
| 1479 | 1479 | /** |
@@ -1498,13 +1498,13 @@ discard block |
||
| 1498 | 1498 | * Retourne $texte, sinon $sinon. |
| 1499 | 1499 | **/ |
| 1500 | 1500 | function sinon($texte, $sinon = '') { |
| 1501 | - if ($texte) { |
|
| 1502 | - return $texte; |
|
| 1503 | - } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1504 | - return $texte; |
|
| 1505 | - } else { |
|
| 1506 | - return $sinon; |
|
| 1507 | - } |
|
| 1501 | + if ($texte) { |
|
| 1502 | + return $texte; |
|
| 1503 | + } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1504 | + return $texte; |
|
| 1505 | + } else { |
|
| 1506 | + return $sinon; |
|
| 1507 | + } |
|
| 1508 | 1508 | } |
| 1509 | 1509 | |
| 1510 | 1510 | /** |
@@ -1528,7 +1528,7 @@ discard block |
||
| 1528 | 1528 | * @return mixed |
| 1529 | 1529 | **/ |
| 1530 | 1530 | function choixsivide($a, $vide, $pasvide) { |
| 1531 | - return $a ? $pasvide : $vide; |
|
| 1531 | + return $a ? $pasvide : $vide; |
|
| 1532 | 1532 | } |
| 1533 | 1533 | |
| 1534 | 1534 | /** |
@@ -1552,7 +1552,7 @@ discard block |
||
| 1552 | 1552 | * @return mixed |
| 1553 | 1553 | **/ |
| 1554 | 1554 | function choixsiegal($a1, $a2, $v, $f) { |
| 1555 | - return ($a1 == $a2) ? $v : $f; |
|
| 1555 | + return ($a1 == $a2) ? $v : $f; |
|
| 1556 | 1556 | } |
| 1557 | 1557 | |
| 1558 | 1558 | // |
@@ -1571,13 +1571,13 @@ discard block |
||
| 1571 | 1571 | * @return string |
| 1572 | 1572 | **/ |
| 1573 | 1573 | function filtrer_ical($texte) { |
| 1574 | - #include_spip('inc/charsets'); |
|
| 1575 | - $texte = html2unicode($texte); |
|
| 1576 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1577 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1578 | - $texte = preg_replace('/,/', '\,', $texte); |
|
| 1574 | + #include_spip('inc/charsets'); |
|
| 1575 | + $texte = html2unicode($texte); |
|
| 1576 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1577 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1578 | + $texte = preg_replace('/,/', '\,', $texte); |
|
| 1579 | 1579 | |
| 1580 | - return $texte; |
|
| 1580 | + return $texte; |
|
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | 1583 | |
@@ -1602,58 +1602,58 @@ discard block |
||
| 1602 | 1602 | * @return string |
| 1603 | 1603 | **/ |
| 1604 | 1604 | function post_autobr($texte, $delim = "\n_ ") { |
| 1605 | - if (!function_exists('echappe_html')) { |
|
| 1606 | - include_spip('inc/texte_mini'); |
|
| 1607 | - } |
|
| 1608 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1609 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1610 | - |
|
| 1611 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1612 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1613 | - } else { |
|
| 1614 | - $fin = ''; |
|
| 1615 | - } |
|
| 1616 | - |
|
| 1617 | - $texte = echappe_html($texte, '', true); |
|
| 1618 | - |
|
| 1619 | - // echapper les modeles |
|
| 1620 | - $collecteurModeles = null; |
|
| 1621 | - if (strpos($texte, '<') !== false) { |
|
| 1622 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1623 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 1624 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1625 | - $texte = $collecteurModeles->echapper($texte); |
|
| 1626 | - } |
|
| 1627 | - |
|
| 1628 | - $debut = ''; |
|
| 1629 | - $suite = $texte; |
|
| 1630 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1631 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1632 | - $suite = substr($suite, $t); |
|
| 1633 | - $car = substr($suite, 0, 1); |
|
| 1634 | - if ( |
|
| 1635 | - ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1636 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1637 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1638 | - ) { |
|
| 1639 | - $debut .= $delim; |
|
| 1640 | - } else { |
|
| 1641 | - $debut .= "\n"; |
|
| 1642 | - } |
|
| 1643 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1644 | - $debut .= $regs[0]; |
|
| 1645 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1646 | - } |
|
| 1647 | - } |
|
| 1648 | - $texte = $debut . $suite; |
|
| 1649 | - |
|
| 1650 | - if ($collecteurModeles) { |
|
| 1651 | - $texte = $collecteurModeles->retablir($texte); |
|
| 1652 | - } |
|
| 1653 | - |
|
| 1654 | - $texte = echappe_retour($texte); |
|
| 1655 | - |
|
| 1656 | - return $texte . $fin; |
|
| 1605 | + if (!function_exists('echappe_html')) { |
|
| 1606 | + include_spip('inc/texte_mini'); |
|
| 1607 | + } |
|
| 1608 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1609 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1610 | + |
|
| 1611 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1612 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1613 | + } else { |
|
| 1614 | + $fin = ''; |
|
| 1615 | + } |
|
| 1616 | + |
|
| 1617 | + $texte = echappe_html($texte, '', true); |
|
| 1618 | + |
|
| 1619 | + // echapper les modeles |
|
| 1620 | + $collecteurModeles = null; |
|
| 1621 | + if (strpos($texte, '<') !== false) { |
|
| 1622 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1623 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 1624 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1625 | + $texte = $collecteurModeles->echapper($texte); |
|
| 1626 | + } |
|
| 1627 | + |
|
| 1628 | + $debut = ''; |
|
| 1629 | + $suite = $texte; |
|
| 1630 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1631 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1632 | + $suite = substr($suite, $t); |
|
| 1633 | + $car = substr($suite, 0, 1); |
|
| 1634 | + if ( |
|
| 1635 | + ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1636 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1637 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1638 | + ) { |
|
| 1639 | + $debut .= $delim; |
|
| 1640 | + } else { |
|
| 1641 | + $debut .= "\n"; |
|
| 1642 | + } |
|
| 1643 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1644 | + $debut .= $regs[0]; |
|
| 1645 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1646 | + } |
|
| 1647 | + } |
|
| 1648 | + $texte = $debut . $suite; |
|
| 1649 | + |
|
| 1650 | + if ($collecteurModeles) { |
|
| 1651 | + $texte = $collecteurModeles->retablir($texte); |
|
| 1652 | + } |
|
| 1653 | + |
|
| 1654 | + $texte = echappe_retour($texte); |
|
| 1655 | + |
|
| 1656 | + return $texte . $fin; |
|
| 1657 | 1657 | } |
| 1658 | 1658 | |
| 1659 | 1659 | |
@@ -1688,30 +1688,30 @@ discard block |
||
| 1688 | 1688 | **/ |
| 1689 | 1689 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1690 | 1690 | |
| 1691 | - if ( |
|
| 1692 | - $letexte |
|
| 1693 | - and strpos($letexte, '<:') !== false |
|
| 1694 | - ) { |
|
| 1695 | - if (!$lang) { |
|
| 1696 | - $lang = $GLOBALS['spip_lang']; |
|
| 1697 | - } |
|
| 1698 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1699 | - if (is_bool($options)) { |
|
| 1700 | - $options = ['echappe_span' => $options]; |
|
| 1701 | - } |
|
| 1702 | - if (!isset($options['echappe_span'])) { |
|
| 1703 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1704 | - } |
|
| 1705 | - $options['lang'] = $lang; |
|
| 1691 | + if ( |
|
| 1692 | + $letexte |
|
| 1693 | + and strpos($letexte, '<:') !== false |
|
| 1694 | + ) { |
|
| 1695 | + if (!$lang) { |
|
| 1696 | + $lang = $GLOBALS['spip_lang']; |
|
| 1697 | + } |
|
| 1698 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1699 | + if (is_bool($options)) { |
|
| 1700 | + $options = ['echappe_span' => $options]; |
|
| 1701 | + } |
|
| 1702 | + if (!isset($options['echappe_span'])) { |
|
| 1703 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1704 | + } |
|
| 1705 | + $options['lang'] = $lang; |
|
| 1706 | 1706 | |
| 1707 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1708 | - include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 1709 | - $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1707 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1708 | + include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 1709 | + $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1710 | 1710 | |
| 1711 | - $letexte = $CollecteurIdiomes->traiter($letexte, $options); |
|
| 1711 | + $letexte = $CollecteurIdiomes->traiter($letexte, $options); |
|
| 1712 | 1712 | |
| 1713 | - } |
|
| 1714 | - return $letexte; |
|
| 1713 | + } |
|
| 1714 | + return $letexte; |
|
| 1715 | 1715 | } |
| 1716 | 1716 | |
| 1717 | 1717 | /** |
@@ -1749,34 +1749,34 @@ discard block |
||
| 1749 | 1749 | **/ |
| 1750 | 1750 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1751 | 1751 | |
| 1752 | - if ( |
|
| 1753 | - $letexte |
|
| 1754 | - and stripos($letexte, '<multi') !== false |
|
| 1755 | - ) { |
|
| 1756 | - if (!$lang) { |
|
| 1757 | - $lang = $GLOBALS['spip_lang']; |
|
| 1758 | - } |
|
| 1752 | + if ( |
|
| 1753 | + $letexte |
|
| 1754 | + and stripos($letexte, '<multi') !== false |
|
| 1755 | + ) { |
|
| 1756 | + if (!$lang) { |
|
| 1757 | + $lang = $GLOBALS['spip_lang']; |
|
| 1758 | + } |
|
| 1759 | 1759 | |
| 1760 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1761 | - if (is_bool($options)) { |
|
| 1762 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1763 | - } |
|
| 1764 | - if (!isset($options['echappe_span'])) { |
|
| 1765 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1766 | - } |
|
| 1767 | - if (!isset($options['lang_defaut'])) { |
|
| 1768 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1769 | - } |
|
| 1770 | - $options['lang'] = $lang; |
|
| 1760 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1761 | + if (is_bool($options)) { |
|
| 1762 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1763 | + } |
|
| 1764 | + if (!isset($options['echappe_span'])) { |
|
| 1765 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1766 | + } |
|
| 1767 | + if (!isset($options['lang_defaut'])) { |
|
| 1768 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1769 | + } |
|
| 1770 | + $options['lang'] = $lang; |
|
| 1771 | 1771 | |
| 1772 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1773 | - include_spip("src/Texte/Collecteur/Multis"); |
|
| 1774 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1772 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1773 | + include_spip("src/Texte/Collecteur/Multis"); |
|
| 1774 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1775 | 1775 | |
| 1776 | - $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1777 | - } |
|
| 1776 | + $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1777 | + } |
|
| 1778 | 1778 | |
| 1779 | - return $letexte; |
|
| 1779 | + return $letexte; |
|
| 1780 | 1780 | } |
| 1781 | 1781 | |
| 1782 | 1782 | /** |
@@ -1786,7 +1786,7 @@ discard block |
||
| 1786 | 1786 | * @return string L'initiale en majuscule |
| 1787 | 1787 | */ |
| 1788 | 1788 | function filtre_initiale($nom) { |
| 1789 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1789 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1790 | 1790 | } |
| 1791 | 1791 | |
| 1792 | 1792 | |
@@ -1831,33 +1831,33 @@ discard block |
||
| 1831 | 1831 | * - null (interne) : si on empile |
| 1832 | 1832 | **/ |
| 1833 | 1833 | function unique($donnee, $famille = '', $cpt = false) { |
| 1834 | - static $mem = []; |
|
| 1835 | - // permettre de vider la pile et de la restaurer |
|
| 1836 | - // pour le calcul de introduction... |
|
| 1837 | - if ($famille == '_spip_raz_') { |
|
| 1838 | - $tmp = $mem; |
|
| 1839 | - $mem = []; |
|
| 1840 | - |
|
| 1841 | - return $tmp; |
|
| 1842 | - } elseif ($famille == '_spip_set_') { |
|
| 1843 | - $mem = $donnee; |
|
| 1844 | - |
|
| 1845 | - return; |
|
| 1846 | - } |
|
| 1847 | - // eviter une notice |
|
| 1848 | - if (!isset($mem[$famille])) { |
|
| 1849 | - $mem[$famille] = []; |
|
| 1850 | - } |
|
| 1851 | - if ($cpt) { |
|
| 1852 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1853 | - } |
|
| 1854 | - // eviter une notice |
|
| 1855 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1856 | - $mem[$famille][$donnee] = 0; |
|
| 1857 | - } |
|
| 1858 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1859 | - return $donnee; |
|
| 1860 | - } |
|
| 1834 | + static $mem = []; |
|
| 1835 | + // permettre de vider la pile et de la restaurer |
|
| 1836 | + // pour le calcul de introduction... |
|
| 1837 | + if ($famille == '_spip_raz_') { |
|
| 1838 | + $tmp = $mem; |
|
| 1839 | + $mem = []; |
|
| 1840 | + |
|
| 1841 | + return $tmp; |
|
| 1842 | + } elseif ($famille == '_spip_set_') { |
|
| 1843 | + $mem = $donnee; |
|
| 1844 | + |
|
| 1845 | + return; |
|
| 1846 | + } |
|
| 1847 | + // eviter une notice |
|
| 1848 | + if (!isset($mem[$famille])) { |
|
| 1849 | + $mem[$famille] = []; |
|
| 1850 | + } |
|
| 1851 | + if ($cpt) { |
|
| 1852 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1853 | + } |
|
| 1854 | + // eviter une notice |
|
| 1855 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1856 | + $mem[$famille][$donnee] = 0; |
|
| 1857 | + } |
|
| 1858 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1859 | + return $donnee; |
|
| 1860 | + } |
|
| 1861 | 1861 | } |
| 1862 | 1862 | |
| 1863 | 1863 | |
@@ -1887,20 +1887,20 @@ discard block |
||
| 1887 | 1887 | * Une des valeurs en fonction du compteur. |
| 1888 | 1888 | **/ |
| 1889 | 1889 | function alterner($i, ...$args) { |
| 1890 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1891 | - $num = count($args); |
|
| 1890 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1891 | + $num = count($args); |
|
| 1892 | 1892 | |
| 1893 | - if ($num === 1 && is_array($args[0])) { |
|
| 1894 | - // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1895 | - $args = array_values($args[0]); |
|
| 1896 | - $num = count($args); |
|
| 1897 | - } |
|
| 1893 | + if ($num === 1 && is_array($args[0])) { |
|
| 1894 | + // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1895 | + $args = array_values($args[0]); |
|
| 1896 | + $num = count($args); |
|
| 1897 | + } |
|
| 1898 | 1898 | |
| 1899 | - // un index compris entre 0 et num exclus |
|
| 1900 | - $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 1901 | - $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1902 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1903 | - return $args[$i]; |
|
| 1899 | + // un index compris entre 0 et num exclus |
|
| 1900 | + $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 1901 | + $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1902 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1903 | + return $args[$i]; |
|
| 1904 | 1904 | } |
| 1905 | 1905 | |
| 1906 | 1906 | |
@@ -1926,52 +1926,52 @@ discard block |
||
| 1926 | 1926 | * - null lorsque l’attribut n’existe pas. |
| 1927 | 1927 | **/ |
| 1928 | 1928 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1929 | - if (is_array($balise)) { |
|
| 1930 | - array_walk( |
|
| 1931 | - $balise, |
|
| 1932 | - function (&$a, $key, $t) { |
|
| 1933 | - $a = extraire_attribut($a, $t); |
|
| 1934 | - }, |
|
| 1935 | - $attribut |
|
| 1936 | - ); |
|
| 1937 | - |
|
| 1938 | - return $balise; |
|
| 1939 | - } |
|
| 1940 | - if ( |
|
| 1941 | - $balise |
|
| 1942 | - && stripos($balise, $attribut) !== false |
|
| 1943 | - && preg_match( |
|
| 1944 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1945 | - . $attribut |
|
| 1946 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1947 | - $balise, |
|
| 1948 | - $r |
|
| 1949 | - ) |
|
| 1950 | - ) { |
|
| 1951 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1952 | - $r[4] = substr($r[3], 1, -1); |
|
| 1953 | - $r[3] = $r[3][0]; |
|
| 1954 | - } elseif ($r[3] !== '') { |
|
| 1955 | - $r[4] = $r[3]; |
|
| 1956 | - $r[3] = ''; |
|
| 1957 | - } else { |
|
| 1958 | - $r[4] = trim($r[2]); |
|
| 1959 | - } |
|
| 1960 | - $att = $r[4]; |
|
| 1961 | - if (strpos($att, '&#') !== false) { |
|
| 1962 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1963 | - } |
|
| 1964 | - $att = filtrer_entites($att); |
|
| 1965 | - } else { |
|
| 1966 | - $att = null; |
|
| 1967 | - $r = []; |
|
| 1968 | - } |
|
| 1969 | - |
|
| 1970 | - if ($complet) { |
|
| 1971 | - return [$att, $r]; |
|
| 1972 | - } else { |
|
| 1973 | - return $att; |
|
| 1974 | - } |
|
| 1929 | + if (is_array($balise)) { |
|
| 1930 | + array_walk( |
|
| 1931 | + $balise, |
|
| 1932 | + function (&$a, $key, $t) { |
|
| 1933 | + $a = extraire_attribut($a, $t); |
|
| 1934 | + }, |
|
| 1935 | + $attribut |
|
| 1936 | + ); |
|
| 1937 | + |
|
| 1938 | + return $balise; |
|
| 1939 | + } |
|
| 1940 | + if ( |
|
| 1941 | + $balise |
|
| 1942 | + && stripos($balise, $attribut) !== false |
|
| 1943 | + && preg_match( |
|
| 1944 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1945 | + . $attribut |
|
| 1946 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1947 | + $balise, |
|
| 1948 | + $r |
|
| 1949 | + ) |
|
| 1950 | + ) { |
|
| 1951 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1952 | + $r[4] = substr($r[3], 1, -1); |
|
| 1953 | + $r[3] = $r[3][0]; |
|
| 1954 | + } elseif ($r[3] !== '') { |
|
| 1955 | + $r[4] = $r[3]; |
|
| 1956 | + $r[3] = ''; |
|
| 1957 | + } else { |
|
| 1958 | + $r[4] = trim($r[2]); |
|
| 1959 | + } |
|
| 1960 | + $att = $r[4]; |
|
| 1961 | + if (strpos($att, '&#') !== false) { |
|
| 1962 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1963 | + } |
|
| 1964 | + $att = filtrer_entites($att); |
|
| 1965 | + } else { |
|
| 1966 | + $att = null; |
|
| 1967 | + $r = []; |
|
| 1968 | + } |
|
| 1969 | + |
|
| 1970 | + if ($complet) { |
|
| 1971 | + return [$att, $r]; |
|
| 1972 | + } else { |
|
| 1973 | + return $att; |
|
| 1974 | + } |
|
| 1975 | 1975 | } |
| 1976 | 1976 | |
| 1977 | 1977 | /** |
@@ -2004,41 +2004,41 @@ discard block |
||
| 2004 | 2004 | **/ |
| 2005 | 2005 | function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string { |
| 2006 | 2006 | |
| 2007 | - if ($balise === null or $balise === '') { |
|
| 2008 | - return ''; |
|
| 2009 | - } |
|
| 2007 | + if ($balise === null or $balise === '') { |
|
| 2008 | + return ''; |
|
| 2009 | + } |
|
| 2010 | 2010 | |
| 2011 | - // preparer l'attribut |
|
| 2012 | - // supprimer les etc mais pas les balises html |
|
| 2013 | - // qui ont un sens dans un attribut value d'un input |
|
| 2014 | - if ($proteger) { |
|
| 2015 | - $val = attribut_html($val, false); |
|
| 2016 | - } |
|
| 2011 | + // preparer l'attribut |
|
| 2012 | + // supprimer les etc mais pas les balises html |
|
| 2013 | + // qui ont un sens dans un attribut value d'un input |
|
| 2014 | + if ($proteger) { |
|
| 2015 | + $val = attribut_html($val, false); |
|
| 2016 | + } |
|
| 2017 | 2017 | |
| 2018 | - // echapper les ' pour eviter tout bug |
|
| 2019 | - $val = str_replace("'", ''', $val); |
|
| 2020 | - if ($vider and strlen($val) === 0) { |
|
| 2021 | - $insert = ''; |
|
| 2022 | - } else { |
|
| 2023 | - $insert = " $attribut='$val'"; |
|
| 2024 | - } |
|
| 2018 | + // echapper les ' pour eviter tout bug |
|
| 2019 | + $val = str_replace("'", ''', $val); |
|
| 2020 | + if ($vider and strlen($val) === 0) { |
|
| 2021 | + $insert = ''; |
|
| 2022 | + } else { |
|
| 2023 | + $insert = " $attribut='$val'"; |
|
| 2024 | + } |
|
| 2025 | 2025 | |
| 2026 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2026 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2027 | 2027 | |
| 2028 | - if ($old !== null) { |
|
| 2029 | - // Remplacer l'ancien attribut du meme nom |
|
| 2030 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2031 | - } else { |
|
| 2032 | - // preferer une balise " />" (comme <img />) |
|
| 2033 | - if (preg_match(',/>,', $balise)) { |
|
| 2034 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2035 | - } // sinon une balise <a ...> ... </a> |
|
| 2036 | - else { |
|
| 2037 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2038 | - } |
|
| 2039 | - } |
|
| 2028 | + if ($old !== null) { |
|
| 2029 | + // Remplacer l'ancien attribut du meme nom |
|
| 2030 | + $balise = $r[1] . $insert . $r[5]; |
|
| 2031 | + } else { |
|
| 2032 | + // preferer une balise " />" (comme <img />) |
|
| 2033 | + if (preg_match(',/>,', $balise)) { |
|
| 2034 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2035 | + } // sinon une balise <a ...> ... </a> |
|
| 2036 | + else { |
|
| 2037 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2038 | + } |
|
| 2039 | + } |
|
| 2040 | 2040 | |
| 2041 | - return $balise; |
|
| 2041 | + return $balise; |
|
| 2042 | 2042 | } |
| 2043 | 2043 | |
| 2044 | 2044 | /** |
@@ -2056,7 +2056,7 @@ discard block |
||
| 2056 | 2056 | * @return string Code HTML sans l'attribut |
| 2057 | 2057 | **/ |
| 2058 | 2058 | function vider_attribut(?string $balise, string $attribut): string { |
| 2059 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2059 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2060 | 2060 | } |
| 2061 | 2061 | |
| 2062 | 2062 | /** |
@@ -2068,53 +2068,53 @@ discard block |
||
| 2068 | 2068 | * @return string |
| 2069 | 2069 | */ |
| 2070 | 2070 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2071 | - if (is_string($class)) { |
|
| 2072 | - $class = explode(' ', trim($class)); |
|
| 2073 | - } |
|
| 2074 | - $class = array_filter($class); |
|
| 2075 | - $class = array_unique($class); |
|
| 2076 | - if (!$class) { |
|
| 2077 | - return $balise; |
|
| 2078 | - } |
|
| 2079 | - |
|
| 2080 | - // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2081 | - if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2082 | - return $balise; |
|
| 2083 | - } |
|
| 2084 | - |
|
| 2085 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2086 | - $class_new = $class_courante; |
|
| 2087 | - foreach ($class as $c) { |
|
| 2088 | - $is_class_presente = false; |
|
| 2089 | - if ( |
|
| 2090 | - $class_courante |
|
| 2091 | - and strpos($class_courante, (string) $c) !== false |
|
| 2092 | - and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2093 | - ) { |
|
| 2094 | - $is_class_presente = true; |
|
| 2095 | - } |
|
| 2096 | - if ( |
|
| 2097 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2098 | - and !$is_class_presente |
|
| 2099 | - ) { |
|
| 2100 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2101 | - } elseif ( |
|
| 2102 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2103 | - and $is_class_presente |
|
| 2104 | - ) { |
|
| 2105 | - $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2106 | - } |
|
| 2107 | - } |
|
| 2108 | - |
|
| 2109 | - if ($class_new !== $class_courante) { |
|
| 2110 | - if (strlen($class_new)) { |
|
| 2111 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2112 | - } elseif ($class_courante) { |
|
| 2113 | - $balise = vider_attribut($balise, 'class'); |
|
| 2114 | - } |
|
| 2115 | - } |
|
| 2116 | - |
|
| 2117 | - return $balise; |
|
| 2071 | + if (is_string($class)) { |
|
| 2072 | + $class = explode(' ', trim($class)); |
|
| 2073 | + } |
|
| 2074 | + $class = array_filter($class); |
|
| 2075 | + $class = array_unique($class); |
|
| 2076 | + if (!$class) { |
|
| 2077 | + return $balise; |
|
| 2078 | + } |
|
| 2079 | + |
|
| 2080 | + // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2081 | + if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2082 | + return $balise; |
|
| 2083 | + } |
|
| 2084 | + |
|
| 2085 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2086 | + $class_new = $class_courante; |
|
| 2087 | + foreach ($class as $c) { |
|
| 2088 | + $is_class_presente = false; |
|
| 2089 | + if ( |
|
| 2090 | + $class_courante |
|
| 2091 | + and strpos($class_courante, (string) $c) !== false |
|
| 2092 | + and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2093 | + ) { |
|
| 2094 | + $is_class_presente = true; |
|
| 2095 | + } |
|
| 2096 | + if ( |
|
| 2097 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2098 | + and !$is_class_presente |
|
| 2099 | + ) { |
|
| 2100 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2101 | + } elseif ( |
|
| 2102 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2103 | + and $is_class_presente |
|
| 2104 | + ) { |
|
| 2105 | + $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2106 | + } |
|
| 2107 | + } |
|
| 2108 | + |
|
| 2109 | + if ($class_new !== $class_courante) { |
|
| 2110 | + if (strlen($class_new)) { |
|
| 2111 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2112 | + } elseif ($class_courante) { |
|
| 2113 | + $balise = vider_attribut($balise, 'class'); |
|
| 2114 | + } |
|
| 2115 | + } |
|
| 2116 | + |
|
| 2117 | + return $balise; |
|
| 2118 | 2118 | } |
| 2119 | 2119 | |
| 2120 | 2120 | /** |
@@ -2124,7 +2124,7 @@ discard block |
||
| 2124 | 2124 | * @return string |
| 2125 | 2125 | */ |
| 2126 | 2126 | function ajouter_class($balise, $class) { |
| 2127 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2127 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2128 | 2128 | } |
| 2129 | 2129 | |
| 2130 | 2130 | /** |
@@ -2134,7 +2134,7 @@ discard block |
||
| 2134 | 2134 | * @return string |
| 2135 | 2135 | */ |
| 2136 | 2136 | function supprimer_class($balise, $class) { |
| 2137 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2137 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2138 | 2138 | } |
| 2139 | 2139 | |
| 2140 | 2140 | /** |
@@ -2145,7 +2145,7 @@ discard block |
||
| 2145 | 2145 | * @return string |
| 2146 | 2146 | */ |
| 2147 | 2147 | function commuter_class($balise, $class) { |
| 2148 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2148 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2149 | 2149 | } |
| 2150 | 2150 | |
| 2151 | 2151 | /** |
@@ -2156,19 +2156,19 @@ discard block |
||
| 2156 | 2156 | * @return string |
| 2157 | 2157 | */ |
| 2158 | 2158 | function tester_config($id, $mode = '') { |
| 2159 | - include_spip('action/inscrire_auteur'); |
|
| 2159 | + include_spip('action/inscrire_auteur'); |
|
| 2160 | 2160 | |
| 2161 | - return tester_statut_inscription($mode, $id); |
|
| 2161 | + return tester_statut_inscription($mode, $id); |
|
| 2162 | 2162 | } |
| 2163 | 2163 | |
| 2164 | 2164 | // |
| 2165 | 2165 | // Quelques fonctions de calcul arithmetique |
| 2166 | 2166 | // |
| 2167 | 2167 | function floatstr($a) { |
| 2168 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2168 | + return str_replace(',', '.', (string)floatval($a)); |
|
| 2169 | 2169 | } |
| 2170 | 2170 | function strize($f, $a, $b) { |
| 2171 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2171 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2172 | 2172 | } |
| 2173 | 2173 | |
| 2174 | 2174 | /** |
@@ -2187,7 +2187,7 @@ discard block |
||
| 2187 | 2187 | * @return int $a+$b |
| 2188 | 2188 | **/ |
| 2189 | 2189 | function plus($a, $b) { |
| 2190 | - return $a + $b; |
|
| 2190 | + return $a + $b; |
|
| 2191 | 2191 | } |
| 2192 | 2192 | function strplus($a, $b) { |
| 2193 | 2193 | return strize('plus', $a, $b); |
@@ -2208,7 +2208,7 @@ discard block |
||
| 2208 | 2208 | * @return int $a-$b |
| 2209 | 2209 | **/ |
| 2210 | 2210 | function moins($a, $b) { |
| 2211 | - return $a - $b; |
|
| 2211 | + return $a - $b; |
|
| 2212 | 2212 | } |
| 2213 | 2213 | function strmoins($a, $b) { |
| 2214 | 2214 | return strize('moins', $a, $b); |
@@ -2231,7 +2231,7 @@ discard block |
||
| 2231 | 2231 | * @return int $a*$b |
| 2232 | 2232 | **/ |
| 2233 | 2233 | function mult($a, $b) { |
| 2234 | - return $a * $b; |
|
| 2234 | + return $a * $b; |
|
| 2235 | 2235 | } |
| 2236 | 2236 | function strmult($a, $b) { |
| 2237 | 2237 | return strize('mult', $a, $b); |
@@ -2254,7 +2254,7 @@ discard block |
||
| 2254 | 2254 | * @return int $a/$b (ou 0 si $b est nul) |
| 2255 | 2255 | **/ |
| 2256 | 2256 | function div($a, $b) { |
| 2257 | - return $b ? $a / $b : 0; |
|
| 2257 | + return $b ? $a / $b : 0; |
|
| 2258 | 2258 | } |
| 2259 | 2259 | function strdiv($a, $b) { |
| 2260 | 2260 | return strize('div', $a, $b); |
@@ -2278,7 +2278,7 @@ discard block |
||
| 2278 | 2278 | * @return int ($nb % $mod) + $add |
| 2279 | 2279 | **/ |
| 2280 | 2280 | function modulo($nb, $mod, $add = 0) { |
| 2281 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2281 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2282 | 2282 | } |
| 2283 | 2283 | |
| 2284 | 2284 | |
@@ -2293,26 +2293,26 @@ discard block |
||
| 2293 | 2293 | * - true sinon |
| 2294 | 2294 | **/ |
| 2295 | 2295 | function nom_acceptable($nom) { |
| 2296 | - $remp2 = []; |
|
| 2297 | - $remp1 = []; |
|
| 2298 | - if (!is_string($nom)) { |
|
| 2299 | - return false; |
|
| 2300 | - } |
|
| 2301 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2302 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2303 | - } |
|
| 2304 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2305 | - foreach ($tags_acceptes as $tag) { |
|
| 2306 | - if (strlen($tag)) { |
|
| 2307 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2308 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2309 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2310 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2311 | - } |
|
| 2312 | - } |
|
| 2313 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2314 | - |
|
| 2315 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2296 | + $remp2 = []; |
|
| 2297 | + $remp1 = []; |
|
| 2298 | + if (!is_string($nom)) { |
|
| 2299 | + return false; |
|
| 2300 | + } |
|
| 2301 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2302 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2303 | + } |
|
| 2304 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2305 | + foreach ($tags_acceptes as $tag) { |
|
| 2306 | + if (strlen($tag)) { |
|
| 2307 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2308 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2309 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2310 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2311 | + } |
|
| 2312 | + } |
|
| 2313 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2314 | + |
|
| 2315 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2316 | 2316 | } |
| 2317 | 2317 | |
| 2318 | 2318 | |
@@ -2328,14 +2328,14 @@ discard block |
||
| 2328 | 2328 | * - renvoie un tableau si l'entree est un tableau |
| 2329 | 2329 | **/ |
| 2330 | 2330 | function email_valide($adresses) { |
| 2331 | - if (is_array($adresses)) { |
|
| 2332 | - $adresses = array_map('email_valide', $adresses); |
|
| 2333 | - $adresses = array_filter($adresses); |
|
| 2334 | - return $adresses; |
|
| 2335 | - } |
|
| 2331 | + if (is_array($adresses)) { |
|
| 2332 | + $adresses = array_map('email_valide', $adresses); |
|
| 2333 | + $adresses = array_filter($adresses); |
|
| 2334 | + return $adresses; |
|
| 2335 | + } |
|
| 2336 | 2336 | |
| 2337 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2338 | - return $email_valide($adresses); |
|
| 2337 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2338 | + return $email_valide($adresses); |
|
| 2339 | 2339 | } |
| 2340 | 2340 | |
| 2341 | 2341 | /** |
@@ -2349,29 +2349,29 @@ discard block |
||
| 2349 | 2349 | * @return string Texte |
| 2350 | 2350 | **/ |
| 2351 | 2351 | function afficher_enclosures($tags) { |
| 2352 | - $s = []; |
|
| 2353 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2354 | - if ( |
|
| 2355 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2356 | - and $t = extraire_attribut($tag, 'href') |
|
| 2357 | - ) { |
|
| 2358 | - $s[] = preg_replace( |
|
| 2359 | - ',>[^<]+</a>,S', |
|
| 2360 | - '>' |
|
| 2361 | - . http_img_pack( |
|
| 2362 | - 'attachment-16.png', |
|
| 2363 | - $t, |
|
| 2364 | - '', |
|
| 2365 | - $t, |
|
| 2366 | - ['utiliser_suffixe_size' => true] |
|
| 2367 | - ) |
|
| 2368 | - . '</a>', |
|
| 2369 | - $tag |
|
| 2370 | - ); |
|
| 2371 | - } |
|
| 2372 | - } |
|
| 2373 | - |
|
| 2374 | - return join(' ', $s); |
|
| 2352 | + $s = []; |
|
| 2353 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2354 | + if ( |
|
| 2355 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2356 | + and $t = extraire_attribut($tag, 'href') |
|
| 2357 | + ) { |
|
| 2358 | + $s[] = preg_replace( |
|
| 2359 | + ',>[^<]+</a>,S', |
|
| 2360 | + '>' |
|
| 2361 | + . http_img_pack( |
|
| 2362 | + 'attachment-16.png', |
|
| 2363 | + $t, |
|
| 2364 | + '', |
|
| 2365 | + $t, |
|
| 2366 | + ['utiliser_suffixe_size' => true] |
|
| 2367 | + ) |
|
| 2368 | + . '</a>', |
|
| 2369 | + $tag |
|
| 2370 | + ); |
|
| 2371 | + } |
|
| 2372 | + } |
|
| 2373 | + |
|
| 2374 | + return join(' ', $s); |
|
| 2375 | 2375 | } |
| 2376 | 2376 | |
| 2377 | 2377 | /** |
@@ -2386,15 +2386,15 @@ discard block |
||
| 2386 | 2386 | * @return string Liens trouvés |
| 2387 | 2387 | **/ |
| 2388 | 2388 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2389 | - $s = []; |
|
| 2390 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2391 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2392 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2393 | - $s[] = $tag; |
|
| 2394 | - } |
|
| 2395 | - } |
|
| 2389 | + $s = []; |
|
| 2390 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2391 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2392 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2393 | + $s[] = $tag; |
|
| 2394 | + } |
|
| 2395 | + } |
|
| 2396 | 2396 | |
| 2397 | - return join(', ', $s); |
|
| 2397 | + return join(', ', $s); |
|
| 2398 | 2398 | } |
| 2399 | 2399 | |
| 2400 | 2400 | |
@@ -2416,21 +2416,21 @@ discard block |
||
| 2416 | 2416 | * @return string Tag HTML `<a>` avec microformat. |
| 2417 | 2417 | **/ |
| 2418 | 2418 | function enclosure2microformat($e) { |
| 2419 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2420 | - $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2421 | - } |
|
| 2422 | - $type = extraire_attribut($e, 'type'); |
|
| 2423 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2424 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2425 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2426 | - } |
|
| 2427 | - $fichier = basename($url); |
|
| 2419 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2420 | + $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2421 | + } |
|
| 2422 | + $type = extraire_attribut($e, 'type'); |
|
| 2423 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2424 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2425 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2426 | + } |
|
| 2427 | + $fichier = basename($url); |
|
| 2428 | 2428 | |
| 2429 | - return '<a rel="enclosure"' |
|
| 2430 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2431 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2432 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2433 | - . '>' . $fichier . '</a>'; |
|
| 2429 | + return '<a rel="enclosure"' |
|
| 2430 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2431 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2432 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2433 | + . '>' . $fichier . '</a>'; |
|
| 2434 | 2434 | } |
| 2435 | 2435 | |
| 2436 | 2436 | /** |
@@ -2448,24 +2448,24 @@ discard block |
||
| 2448 | 2448 | * @return string Tags RSS `<enclosure>`. |
| 2449 | 2449 | **/ |
| 2450 | 2450 | function microformat2enclosure($tags) { |
| 2451 | - $enclosures = []; |
|
| 2452 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2453 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2454 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2455 | - $type = extraire_attribut($e, 'type'); |
|
| 2456 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2457 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2458 | - } # vieux data |
|
| 2459 | - $fichier = basename($url); |
|
| 2460 | - $enclosures[] = '<enclosure' |
|
| 2461 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2462 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2463 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2464 | - . ' />'; |
|
| 2465 | - } |
|
| 2466 | - } |
|
| 2451 | + $enclosures = []; |
|
| 2452 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2453 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2454 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2455 | + $type = extraire_attribut($e, 'type'); |
|
| 2456 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2457 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2458 | + } # vieux data |
|
| 2459 | + $fichier = basename($url); |
|
| 2460 | + $enclosures[] = '<enclosure' |
|
| 2461 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2462 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2463 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2464 | + . ' />'; |
|
| 2465 | + } |
|
| 2466 | + } |
|
| 2467 | 2467 | |
| 2468 | - return join("\n", $enclosures); |
|
| 2468 | + return join("\n", $enclosures); |
|
| 2469 | 2469 | } |
| 2470 | 2470 | |
| 2471 | 2471 | |
@@ -2481,16 +2481,16 @@ discard block |
||
| 2481 | 2481 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2482 | 2482 | **/ |
| 2483 | 2483 | function tags2dcsubject($tags) { |
| 2484 | - $subjects = ''; |
|
| 2485 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2486 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2487 | - $subjects .= '<dc:subject>' |
|
| 2488 | - . texte_backend(textebrut($e)) |
|
| 2489 | - . '</dc:subject>' . "\n"; |
|
| 2490 | - } |
|
| 2491 | - } |
|
| 2484 | + $subjects = ''; |
|
| 2485 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2486 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2487 | + $subjects .= '<dc:subject>' |
|
| 2488 | + . texte_backend(textebrut($e)) |
|
| 2489 | + . '</dc:subject>' . "\n"; |
|
| 2490 | + } |
|
| 2491 | + } |
|
| 2492 | 2492 | |
| 2493 | - return $subjects; |
|
| 2493 | + return $subjects; |
|
| 2494 | 2494 | } |
| 2495 | 2495 | |
| 2496 | 2496 | /** |
@@ -2519,27 +2519,27 @@ discard block |
||
| 2519 | 2519 | * - Tableau de résultats, si tableau en entrée. |
| 2520 | 2520 | **/ |
| 2521 | 2521 | function extraire_balise($texte, $tag = 'a') { |
| 2522 | - if (is_array($texte)) { |
|
| 2523 | - array_walk( |
|
| 2524 | - $texte, |
|
| 2525 | - function (&$a, $key, $t) { |
|
| 2526 | - $a = extraire_balise($a, $t); |
|
| 2527 | - }, |
|
| 2528 | - $tag |
|
| 2529 | - ); |
|
| 2530 | - |
|
| 2531 | - return $texte; |
|
| 2532 | - } |
|
| 2533 | - |
|
| 2534 | - if ( |
|
| 2535 | - preg_match( |
|
| 2536 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2537 | - $texte, |
|
| 2538 | - $regs |
|
| 2539 | - ) |
|
| 2540 | - ) { |
|
| 2541 | - return $regs[0]; |
|
| 2542 | - } |
|
| 2522 | + if (is_array($texte)) { |
|
| 2523 | + array_walk( |
|
| 2524 | + $texte, |
|
| 2525 | + function (&$a, $key, $t) { |
|
| 2526 | + $a = extraire_balise($a, $t); |
|
| 2527 | + }, |
|
| 2528 | + $tag |
|
| 2529 | + ); |
|
| 2530 | + |
|
| 2531 | + return $texte; |
|
| 2532 | + } |
|
| 2533 | + |
|
| 2534 | + if ( |
|
| 2535 | + preg_match( |
|
| 2536 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2537 | + $texte, |
|
| 2538 | + $regs |
|
| 2539 | + ) |
|
| 2540 | + ) { |
|
| 2541 | + return $regs[0]; |
|
| 2542 | + } |
|
| 2543 | 2543 | } |
| 2544 | 2544 | |
| 2545 | 2545 | /** |
@@ -2567,30 +2567,30 @@ discard block |
||
| 2567 | 2567 | * - Tableau de résultats, si tableau en entrée. |
| 2568 | 2568 | **/ |
| 2569 | 2569 | function extraire_balises($texte, $tag = 'a') { |
| 2570 | - if (is_array($texte)) { |
|
| 2571 | - array_walk( |
|
| 2572 | - $texte, |
|
| 2573 | - function (&$a, $key, $t) { |
|
| 2574 | - $a = extraire_balises($a, $t); |
|
| 2575 | - }, |
|
| 2576 | - $tag |
|
| 2577 | - ); |
|
| 2578 | - |
|
| 2579 | - return $texte; |
|
| 2580 | - } |
|
| 2581 | - |
|
| 2582 | - if ( |
|
| 2583 | - preg_match_all( |
|
| 2584 | - ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2585 | - $texte, |
|
| 2586 | - $regs, |
|
| 2587 | - PREG_PATTERN_ORDER |
|
| 2588 | - ) |
|
| 2589 | - ) { |
|
| 2590 | - return $regs[0]; |
|
| 2591 | - } else { |
|
| 2592 | - return []; |
|
| 2593 | - } |
|
| 2570 | + if (is_array($texte)) { |
|
| 2571 | + array_walk( |
|
| 2572 | + $texte, |
|
| 2573 | + function (&$a, $key, $t) { |
|
| 2574 | + $a = extraire_balises($a, $t); |
|
| 2575 | + }, |
|
| 2576 | + $tag |
|
| 2577 | + ); |
|
| 2578 | + |
|
| 2579 | + return $texte; |
|
| 2580 | + } |
|
| 2581 | + |
|
| 2582 | + if ( |
|
| 2583 | + preg_match_all( |
|
| 2584 | + ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2585 | + $texte, |
|
| 2586 | + $regs, |
|
| 2587 | + PREG_PATTERN_ORDER |
|
| 2588 | + ) |
|
| 2589 | + ) { |
|
| 2590 | + return $regs[0]; |
|
| 2591 | + } else { |
|
| 2592 | + return []; |
|
| 2593 | + } |
|
| 2594 | 2594 | } |
| 2595 | 2595 | |
| 2596 | 2596 | /** |
@@ -2619,11 +2619,11 @@ discard block |
||
| 2619 | 2619 | * - `$def` si on n'a pas transmis de tableau |
| 2620 | 2620 | **/ |
| 2621 | 2621 | function in_any($val, $vals, $def = '') { |
| 2622 | - if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2623 | - $vals = $v; |
|
| 2624 | - } |
|
| 2622 | + if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2623 | + $vals = $v; |
|
| 2624 | + } |
|
| 2625 | 2625 | |
| 2626 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2626 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2627 | 2627 | } |
| 2628 | 2628 | |
| 2629 | 2629 | |
@@ -2644,12 +2644,12 @@ discard block |
||
| 2644 | 2644 | * Résultat du calcul |
| 2645 | 2645 | **/ |
| 2646 | 2646 | function valeur_numerique($expr) { |
| 2647 | - $a = 0; |
|
| 2648 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2649 | - eval("\$a = $expr;"); |
|
| 2650 | - } |
|
| 2647 | + $a = 0; |
|
| 2648 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2649 | + eval("\$a = $expr;"); |
|
| 2650 | + } |
|
| 2651 | 2651 | |
| 2652 | - return intval($a); |
|
| 2652 | + return intval($a); |
|
| 2653 | 2653 | } |
| 2654 | 2654 | |
| 2655 | 2655 | /** |
@@ -2668,7 +2668,7 @@ discard block |
||
| 2668 | 2668 | * Retourne `$a*$b/$c` |
| 2669 | 2669 | **/ |
| 2670 | 2670 | function regledetrois($a, $b, $c) { |
| 2671 | - return round($a * $b / $c); |
|
| 2671 | + return round($a * $b / $c); |
|
| 2672 | 2672 | } |
| 2673 | 2673 | |
| 2674 | 2674 | |
@@ -2691,79 +2691,79 @@ discard block |
||
| 2691 | 2691 | * @return string Suite de champs input hidden |
| 2692 | 2692 | **/ |
| 2693 | 2693 | function form_hidden(?string $action = ''): string { |
| 2694 | - $action ??= ''; |
|
| 2695 | - |
|
| 2696 | - $contexte = []; |
|
| 2697 | - include_spip('inc/urls'); |
|
| 2698 | - if ( |
|
| 2699 | - $p = urls_decoder_url($action, '') |
|
| 2700 | - and reset($p) |
|
| 2701 | - ) { |
|
| 2702 | - $fond = array_shift($p); |
|
| 2703 | - if ($fond != '404') { |
|
| 2704 | - $contexte = array_shift($p); |
|
| 2705 | - $contexte['page'] = $fond; |
|
| 2706 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2707 | - } |
|
| 2708 | - } |
|
| 2709 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2710 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2711 | - unset($contexte['type']); |
|
| 2712 | - } |
|
| 2713 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2714 | - unset($contexte['type-page']); |
|
| 2715 | - } |
|
| 2716 | - |
|
| 2717 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2718 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2719 | - $values = []; |
|
| 2720 | - |
|
| 2721 | - // d'abord avec celles de l'url |
|
| 2722 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2723 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2724 | - $c = explode('=', $c, 2); |
|
| 2725 | - $var = array_shift($c); |
|
| 2726 | - $val = array_shift($c) ?? ''; |
|
| 2727 | - if ($var) { |
|
| 2728 | - $val = rawurldecode($val); |
|
| 2729 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2730 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2731 | - $values[] = [$var, $val]; |
|
| 2732 | - } else { |
|
| 2733 | - if (!isset($values[$var])) { |
|
| 2734 | - $values[$var] = [$var, $val]; |
|
| 2735 | - } |
|
| 2736 | - } |
|
| 2737 | - } |
|
| 2738 | - } |
|
| 2739 | - } |
|
| 2740 | - |
|
| 2741 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2742 | - foreach ($contexte as $var => $val) { |
|
| 2743 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2744 | - $values[] = [$var, $val]; |
|
| 2745 | - } else { |
|
| 2746 | - if (!isset($values[$var])) { |
|
| 2747 | - $values[$var] = [$var, $val]; |
|
| 2748 | - } |
|
| 2749 | - } |
|
| 2750 | - } |
|
| 2751 | - |
|
| 2752 | - // puis on rassemble le tout |
|
| 2753 | - $hidden = []; |
|
| 2754 | - foreach ($values as $value) { |
|
| 2755 | - [$var, $val] = $value; |
|
| 2756 | - $hidden[] = '<input name="' |
|
| 2757 | - . entites_html($var) |
|
| 2758 | - . '"' |
|
| 2759 | - . (is_null($val) |
|
| 2760 | - ? '' |
|
| 2761 | - : ' value="' . entites_html($val) . '"' |
|
| 2762 | - ) |
|
| 2763 | - . ' type="hidden"' . "\n/>"; |
|
| 2764 | - } |
|
| 2765 | - |
|
| 2766 | - return join('', $hidden); |
|
| 2694 | + $action ??= ''; |
|
| 2695 | + |
|
| 2696 | + $contexte = []; |
|
| 2697 | + include_spip('inc/urls'); |
|
| 2698 | + if ( |
|
| 2699 | + $p = urls_decoder_url($action, '') |
|
| 2700 | + and reset($p) |
|
| 2701 | + ) { |
|
| 2702 | + $fond = array_shift($p); |
|
| 2703 | + if ($fond != '404') { |
|
| 2704 | + $contexte = array_shift($p); |
|
| 2705 | + $contexte['page'] = $fond; |
|
| 2706 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2707 | + } |
|
| 2708 | + } |
|
| 2709 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2710 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2711 | + unset($contexte['type']); |
|
| 2712 | + } |
|
| 2713 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2714 | + unset($contexte['type-page']); |
|
| 2715 | + } |
|
| 2716 | + |
|
| 2717 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2718 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2719 | + $values = []; |
|
| 2720 | + |
|
| 2721 | + // d'abord avec celles de l'url |
|
| 2722 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2723 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2724 | + $c = explode('=', $c, 2); |
|
| 2725 | + $var = array_shift($c); |
|
| 2726 | + $val = array_shift($c) ?? ''; |
|
| 2727 | + if ($var) { |
|
| 2728 | + $val = rawurldecode($val); |
|
| 2729 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2730 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2731 | + $values[] = [$var, $val]; |
|
| 2732 | + } else { |
|
| 2733 | + if (!isset($values[$var])) { |
|
| 2734 | + $values[$var] = [$var, $val]; |
|
| 2735 | + } |
|
| 2736 | + } |
|
| 2737 | + } |
|
| 2738 | + } |
|
| 2739 | + } |
|
| 2740 | + |
|
| 2741 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2742 | + foreach ($contexte as $var => $val) { |
|
| 2743 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2744 | + $values[] = [$var, $val]; |
|
| 2745 | + } else { |
|
| 2746 | + if (!isset($values[$var])) { |
|
| 2747 | + $values[$var] = [$var, $val]; |
|
| 2748 | + } |
|
| 2749 | + } |
|
| 2750 | + } |
|
| 2751 | + |
|
| 2752 | + // puis on rassemble le tout |
|
| 2753 | + $hidden = []; |
|
| 2754 | + foreach ($values as $value) { |
|
| 2755 | + [$var, $val] = $value; |
|
| 2756 | + $hidden[] = '<input name="' |
|
| 2757 | + . entites_html($var) |
|
| 2758 | + . '"' |
|
| 2759 | + . (is_null($val) |
|
| 2760 | + ? '' |
|
| 2761 | + : ' value="' . entites_html($val) . '"' |
|
| 2762 | + ) |
|
| 2763 | + . ' type="hidden"' . "\n/>"; |
|
| 2764 | + } |
|
| 2765 | + |
|
| 2766 | + return join('', $hidden); |
|
| 2767 | 2767 | } |
| 2768 | 2768 | |
| 2769 | 2769 | |
@@ -2785,7 +2785,7 @@ discard block |
||
| 2785 | 2785 | * - la première valeur du tableau sinon. |
| 2786 | 2786 | **/ |
| 2787 | 2787 | function filtre_reset($array) { |
| 2788 | - return !is_array($array) ? null : reset($array); |
|
| 2788 | + return !is_array($array) ? null : reset($array); |
|
| 2789 | 2789 | } |
| 2790 | 2790 | |
| 2791 | 2791 | /** |
@@ -2806,7 +2806,7 @@ discard block |
||
| 2806 | 2806 | * - la dernière valeur du tableau sinon. |
| 2807 | 2807 | **/ |
| 2808 | 2808 | function filtre_end($array) { |
| 2809 | - return !is_array($array) ? null : end($array); |
|
| 2809 | + return !is_array($array) ? null : end($array); |
|
| 2810 | 2810 | } |
| 2811 | 2811 | |
| 2812 | 2812 | /** |
@@ -2826,11 +2826,11 @@ discard block |
||
| 2826 | 2826 | * |
| 2827 | 2827 | **/ |
| 2828 | 2828 | function filtre_push($array, $val) { |
| 2829 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2830 | - return ''; |
|
| 2831 | - } |
|
| 2829 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2830 | + return ''; |
|
| 2831 | + } |
|
| 2832 | 2832 | |
| 2833 | - return $array; |
|
| 2833 | + return $array; |
|
| 2834 | 2834 | } |
| 2835 | 2835 | |
| 2836 | 2836 | /** |
@@ -2849,7 +2849,7 @@ discard block |
||
| 2849 | 2849 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2850 | 2850 | **/ |
| 2851 | 2851 | function filtre_find($array, $val) { |
| 2852 | - return (is_array($array) and in_array($val, $array)); |
|
| 2852 | + return (is_array($array) and in_array($val, $array)); |
|
| 2853 | 2853 | } |
| 2854 | 2854 | |
| 2855 | 2855 | |
@@ -2866,13 +2866,13 @@ discard block |
||
| 2866 | 2866 | * Contenu avec urls en absolus |
| 2867 | 2867 | **/ |
| 2868 | 2868 | function urls_absolues_css($contenu, $source) { |
| 2869 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2869 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2870 | 2870 | |
| 2871 | - return preg_replace_callback( |
|
| 2872 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2873 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2874 | - $contenu |
|
| 2875 | - ); |
|
| 2871 | + return preg_replace_callback( |
|
| 2872 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2873 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2874 | + $contenu |
|
| 2875 | + ); |
|
| 2876 | 2876 | } |
| 2877 | 2877 | |
| 2878 | 2878 | |
@@ -2901,119 +2901,119 @@ discard block |
||
| 2901 | 2901 | * Chemin du fichier CSS inversé |
| 2902 | 2902 | **/ |
| 2903 | 2903 | function direction_css($css, $voulue = '') { |
| 2904 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2905 | - return $css; |
|
| 2906 | - } |
|
| 2907 | - include_spip('inc/lang'); |
|
| 2908 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2909 | - if ($voulue = strtolower($voulue)) { |
|
| 2910 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2911 | - $voulue = lang_dir($voulue); |
|
| 2912 | - } |
|
| 2913 | - } else { |
|
| 2914 | - $voulue = lang_dir(); |
|
| 2915 | - } |
|
| 2916 | - |
|
| 2917 | - $r = count($r) > 1; |
|
| 2918 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2919 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2920 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2921 | - |
|
| 2922 | - if ($voulue == $dir) { |
|
| 2923 | - return $css; |
|
| 2924 | - } |
|
| 2925 | - |
|
| 2926 | - if ( |
|
| 2927 | - // url absolue |
|
| 2928 | - preg_match(',^https?:,i', $css) |
|
| 2929 | - // ou qui contient un ? |
|
| 2930 | - or (($p = strpos($css, '?')) !== false) |
|
| 2931 | - ) { |
|
| 2932 | - $distant = true; |
|
| 2933 | - $cssf = parse_url($css); |
|
| 2934 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2935 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2936 | - } else { |
|
| 2937 | - $distant = false; |
|
| 2938 | - $cssf = $css; |
|
| 2939 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2940 | - //propose (rien a faire dans ce cas) |
|
| 2941 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2942 | - if (@file_exists($f)) { |
|
| 2943 | - return $f; |
|
| 2944 | - } |
|
| 2945 | - } |
|
| 2946 | - |
|
| 2947 | - // 2. |
|
| 2948 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2949 | - $f = $dir_var |
|
| 2950 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2951 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2952 | - |
|
| 2953 | - // la css peut etre distante (url absolue !) |
|
| 2954 | - if ($distant) { |
|
| 2955 | - include_spip('inc/distant'); |
|
| 2956 | - $res = recuperer_url($css); |
|
| 2957 | - if (!$res or !$contenu = $res['page']) { |
|
| 2958 | - return $css; |
|
| 2959 | - } |
|
| 2960 | - } else { |
|
| 2961 | - if ( |
|
| 2962 | - (@filemtime($f) > @filemtime($css)) |
|
| 2963 | - and (_VAR_MODE != 'recalcul') |
|
| 2964 | - ) { |
|
| 2965 | - return $f; |
|
| 2966 | - } |
|
| 2967 | - if (!lire_fichier($css, $contenu)) { |
|
| 2968 | - return $css; |
|
| 2969 | - } |
|
| 2970 | - } |
|
| 2971 | - |
|
| 2972 | - |
|
| 2973 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2974 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 2975 | - $parser = new csstidy(); |
|
| 2976 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 2977 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 2978 | - $parser->parse($contenu); |
|
| 2979 | - |
|
| 2980 | - $contenu = $parser->print->plain(); |
|
| 2981 | - |
|
| 2982 | - |
|
| 2983 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 2984 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2985 | - $src = []; |
|
| 2986 | - $src_direction_css = []; |
|
| 2987 | - $src_faux_abs = []; |
|
| 2988 | - $d = dirname($css); |
|
| 2989 | - foreach ($regs[1] as $k => $import_css) { |
|
| 2990 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2991 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2992 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2993 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2994 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2995 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2996 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2997 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2998 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2999 | - } |
|
| 3000 | - $src[] = $regs[0][$k]; |
|
| 3001 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3002 | - } |
|
| 3003 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3004 | - |
|
| 3005 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3006 | - |
|
| 3007 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 3008 | - if (count($src_faux_abs)) { |
|
| 3009 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3010 | - } |
|
| 3011 | - |
|
| 3012 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3013 | - return $css; |
|
| 3014 | - } |
|
| 3015 | - |
|
| 3016 | - return $f; |
|
| 2904 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2905 | + return $css; |
|
| 2906 | + } |
|
| 2907 | + include_spip('inc/lang'); |
|
| 2908 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2909 | + if ($voulue = strtolower($voulue)) { |
|
| 2910 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2911 | + $voulue = lang_dir($voulue); |
|
| 2912 | + } |
|
| 2913 | + } else { |
|
| 2914 | + $voulue = lang_dir(); |
|
| 2915 | + } |
|
| 2916 | + |
|
| 2917 | + $r = count($r) > 1; |
|
| 2918 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2919 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2920 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2921 | + |
|
| 2922 | + if ($voulue == $dir) { |
|
| 2923 | + return $css; |
|
| 2924 | + } |
|
| 2925 | + |
|
| 2926 | + if ( |
|
| 2927 | + // url absolue |
|
| 2928 | + preg_match(',^https?:,i', $css) |
|
| 2929 | + // ou qui contient un ? |
|
| 2930 | + or (($p = strpos($css, '?')) !== false) |
|
| 2931 | + ) { |
|
| 2932 | + $distant = true; |
|
| 2933 | + $cssf = parse_url($css); |
|
| 2934 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2935 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2936 | + } else { |
|
| 2937 | + $distant = false; |
|
| 2938 | + $cssf = $css; |
|
| 2939 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2940 | + //propose (rien a faire dans ce cas) |
|
| 2941 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2942 | + if (@file_exists($f)) { |
|
| 2943 | + return $f; |
|
| 2944 | + } |
|
| 2945 | + } |
|
| 2946 | + |
|
| 2947 | + // 2. |
|
| 2948 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2949 | + $f = $dir_var |
|
| 2950 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2951 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2952 | + |
|
| 2953 | + // la css peut etre distante (url absolue !) |
|
| 2954 | + if ($distant) { |
|
| 2955 | + include_spip('inc/distant'); |
|
| 2956 | + $res = recuperer_url($css); |
|
| 2957 | + if (!$res or !$contenu = $res['page']) { |
|
| 2958 | + return $css; |
|
| 2959 | + } |
|
| 2960 | + } else { |
|
| 2961 | + if ( |
|
| 2962 | + (@filemtime($f) > @filemtime($css)) |
|
| 2963 | + and (_VAR_MODE != 'recalcul') |
|
| 2964 | + ) { |
|
| 2965 | + return $f; |
|
| 2966 | + } |
|
| 2967 | + if (!lire_fichier($css, $contenu)) { |
|
| 2968 | + return $css; |
|
| 2969 | + } |
|
| 2970 | + } |
|
| 2971 | + |
|
| 2972 | + |
|
| 2973 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2974 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 2975 | + $parser = new csstidy(); |
|
| 2976 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 2977 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 2978 | + $parser->parse($contenu); |
|
| 2979 | + |
|
| 2980 | + $contenu = $parser->print->plain(); |
|
| 2981 | + |
|
| 2982 | + |
|
| 2983 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 2984 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2985 | + $src = []; |
|
| 2986 | + $src_direction_css = []; |
|
| 2987 | + $src_faux_abs = []; |
|
| 2988 | + $d = dirname($css); |
|
| 2989 | + foreach ($regs[1] as $k => $import_css) { |
|
| 2990 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2991 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2992 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2993 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2994 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2995 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2996 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2997 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2998 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2999 | + } |
|
| 3000 | + $src[] = $regs[0][$k]; |
|
| 3001 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3002 | + } |
|
| 3003 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3004 | + |
|
| 3005 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3006 | + |
|
| 3007 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 3008 | + if (count($src_faux_abs)) { |
|
| 3009 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3010 | + } |
|
| 3011 | + |
|
| 3012 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3013 | + return $css; |
|
| 3014 | + } |
|
| 3015 | + |
|
| 3016 | + return $f; |
|
| 3017 | 3017 | } |
| 3018 | 3018 | |
| 3019 | 3019 | |
@@ -3036,46 +3036,46 @@ discard block |
||
| 3036 | 3036 | * - Chemin ou URL du fichier CSS source sinon. |
| 3037 | 3037 | **/ |
| 3038 | 3038 | function url_absolue_css($css) { |
| 3039 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3040 | - return $css; |
|
| 3041 | - } |
|
| 3039 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3040 | + return $css; |
|
| 3041 | + } |
|
| 3042 | 3042 | |
| 3043 | - $url_absolue_css = url_absolue($css); |
|
| 3043 | + $url_absolue_css = url_absolue($css); |
|
| 3044 | 3044 | |
| 3045 | - $f = basename($css, '.css'); |
|
| 3046 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3047 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3048 | - . '.css'; |
|
| 3045 | + $f = basename($css, '.css'); |
|
| 3046 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3047 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3048 | + . '.css'; |
|
| 3049 | 3049 | |
| 3050 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3051 | - return $f; |
|
| 3052 | - } |
|
| 3050 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3051 | + return $f; |
|
| 3052 | + } |
|
| 3053 | 3053 | |
| 3054 | - if ($url_absolue_css == $css) { |
|
| 3055 | - if ( |
|
| 3056 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3057 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3058 | - ) { |
|
| 3059 | - include_spip('inc/distant'); |
|
| 3060 | - $contenu = recuperer_url($css); |
|
| 3061 | - $contenu = $contenu['page'] ?? ''; |
|
| 3062 | - if (!$contenu) { |
|
| 3063 | - return $css; |
|
| 3064 | - } |
|
| 3065 | - } |
|
| 3066 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3067 | - return $css; |
|
| 3068 | - } |
|
| 3054 | + if ($url_absolue_css == $css) { |
|
| 3055 | + if ( |
|
| 3056 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3057 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3058 | + ) { |
|
| 3059 | + include_spip('inc/distant'); |
|
| 3060 | + $contenu = recuperer_url($css); |
|
| 3061 | + $contenu = $contenu['page'] ?? ''; |
|
| 3062 | + if (!$contenu) { |
|
| 3063 | + return $css; |
|
| 3064 | + } |
|
| 3065 | + } |
|
| 3066 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3067 | + return $css; |
|
| 3068 | + } |
|
| 3069 | 3069 | |
| 3070 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3071 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3070 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3071 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3072 | 3072 | |
| 3073 | - // ecrire la css |
|
| 3074 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3075 | - return $css; |
|
| 3076 | - } |
|
| 3073 | + // ecrire la css |
|
| 3074 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3075 | + return $css; |
|
| 3076 | + } |
|
| 3077 | 3077 | |
| 3078 | - return $f; |
|
| 3078 | + return $f; |
|
| 3079 | 3079 | } |
| 3080 | 3080 | |
| 3081 | 3081 | |
@@ -3109,24 +3109,24 @@ discard block |
||
| 3109 | 3109 | * Valeur trouvée ou valeur par défaut. |
| 3110 | 3110 | **/ |
| 3111 | 3111 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3112 | - foreach (explode('/', $cle) as $k) { |
|
| 3113 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3112 | + foreach (explode('/', $cle) as $k) { |
|
| 3113 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3114 | 3114 | |
| 3115 | - if (is_object($table)) { |
|
| 3116 | - $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3117 | - } elseif (is_array($table)) { |
|
| 3118 | - if ($conserver_null) { |
|
| 3119 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3120 | - } else { |
|
| 3121 | - $table = ($table[$k] ?? $defaut); |
|
| 3122 | - } |
|
| 3123 | - } else { |
|
| 3124 | - $table = $defaut; |
|
| 3125 | - break; |
|
| 3126 | - } |
|
| 3127 | - } |
|
| 3115 | + if (is_object($table)) { |
|
| 3116 | + $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3117 | + } elseif (is_array($table)) { |
|
| 3118 | + if ($conserver_null) { |
|
| 3119 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3120 | + } else { |
|
| 3121 | + $table = ($table[$k] ?? $defaut); |
|
| 3122 | + } |
|
| 3123 | + } else { |
|
| 3124 | + $table = $defaut; |
|
| 3125 | + break; |
|
| 3126 | + } |
|
| 3127 | + } |
|
| 3128 | 3128 | |
| 3129 | - return $table; |
|
| 3129 | + return $table; |
|
| 3130 | 3130 | } |
| 3131 | 3131 | |
| 3132 | 3132 | /** |
@@ -3159,22 +3159,22 @@ discard block |
||
| 3159 | 3159 | * - string : expression trouvée. |
| 3160 | 3160 | **/ |
| 3161 | 3161 | function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) { |
| 3162 | - if (intval($modif) and $capte == 0) { |
|
| 3163 | - $capte = $modif; |
|
| 3164 | - $modif = 'UuimsS'; |
|
| 3165 | - } |
|
| 3166 | - $expression = str_replace('\/', '/', $expression); |
|
| 3167 | - $expression = str_replace('/', '\/', $expression); |
|
| 3162 | + if (intval($modif) and $capte == 0) { |
|
| 3163 | + $capte = $modif; |
|
| 3164 | + $modif = 'UuimsS'; |
|
| 3165 | + } |
|
| 3166 | + $expression = str_replace('\/', '/', $expression); |
|
| 3167 | + $expression = str_replace('/', '\/', $expression); |
|
| 3168 | 3168 | |
| 3169 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3170 | - if (isset($r[$capte])) { |
|
| 3171 | - return $r[$capte]; |
|
| 3172 | - } else { |
|
| 3173 | - return true; |
|
| 3174 | - } |
|
| 3175 | - } |
|
| 3169 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3170 | + if (isset($r[$capte])) { |
|
| 3171 | + return $r[$capte]; |
|
| 3172 | + } else { |
|
| 3173 | + return true; |
|
| 3174 | + } |
|
| 3175 | + } |
|
| 3176 | 3176 | |
| 3177 | - return false; |
|
| 3177 | + return false; |
|
| 3178 | 3178 | } |
| 3179 | 3179 | |
| 3180 | 3180 | |
@@ -3201,10 +3201,10 @@ discard block |
||
| 3201 | 3201 | * Texte |
| 3202 | 3202 | **/ |
| 3203 | 3203 | function replace($texte, $expression, $replace = '', $modif = 'UimsS') { |
| 3204 | - $expression = str_replace('\/', '/', $expression); |
|
| 3205 | - $expression = str_replace('/', '\/', $expression); |
|
| 3204 | + $expression = str_replace('\/', '/', $expression); |
|
| 3205 | + $expression = str_replace('/', '\/', $expression); |
|
| 3206 | 3206 | |
| 3207 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3207 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3208 | 3208 | } |
| 3209 | 3209 | |
| 3210 | 3210 | |
@@ -3222,25 +3222,25 @@ discard block |
||
| 3222 | 3222 | **/ |
| 3223 | 3223 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3224 | 3224 | |
| 3225 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3226 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3225 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3226 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3227 | 3227 | |
| 3228 | - if ( |
|
| 3229 | - strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3230 | - and preg_match_all( |
|
| 3231 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3232 | - $t, |
|
| 3233 | - $matches, |
|
| 3234 | - PREG_PATTERN_ORDER |
|
| 3235 | - ) |
|
| 3236 | - ) { |
|
| 3237 | - if (!isset($doublons['documents'])) { |
|
| 3238 | - $doublons['documents'] = ''; |
|
| 3239 | - } |
|
| 3240 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3241 | - } |
|
| 3228 | + if ( |
|
| 3229 | + strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3230 | + and preg_match_all( |
|
| 3231 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3232 | + $t, |
|
| 3233 | + $matches, |
|
| 3234 | + PREG_PATTERN_ORDER |
|
| 3235 | + ) |
|
| 3236 | + ) { |
|
| 3237 | + if (!isset($doublons['documents'])) { |
|
| 3238 | + $doublons['documents'] = ''; |
|
| 3239 | + } |
|
| 3240 | + $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3241 | + } |
|
| 3242 | 3242 | |
| 3243 | - return $letexte; |
|
| 3243 | + return $letexte; |
|
| 3244 | 3244 | } |
| 3245 | 3245 | |
| 3246 | 3246 | /** |
@@ -3254,7 +3254,7 @@ discard block |
||
| 3254 | 3254 | * @return string Chaîne vide |
| 3255 | 3255 | **/ |
| 3256 | 3256 | function vide($texte) { |
| 3257 | - return ''; |
|
| 3257 | + return ''; |
|
| 3258 | 3258 | } |
| 3259 | 3259 | |
| 3260 | 3260 | // |
@@ -3283,23 +3283,23 @@ discard block |
||
| 3283 | 3283 | * Code HTML résultant |
| 3284 | 3284 | **/ |
| 3285 | 3285 | function env_to_params($env, $ignore_params = []) { |
| 3286 | - $ignore_params = array_merge( |
|
| 3287 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3288 | - $ignore_params |
|
| 3289 | - ); |
|
| 3290 | - if (!is_array($env)) { |
|
| 3291 | - $env = unserialize($env); |
|
| 3292 | - } |
|
| 3293 | - $texte = ''; |
|
| 3294 | - if ($env) { |
|
| 3295 | - foreach ($env as $i => $j) { |
|
| 3296 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3297 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3298 | - } |
|
| 3299 | - } |
|
| 3300 | - } |
|
| 3301 | - |
|
| 3302 | - return $texte; |
|
| 3286 | + $ignore_params = array_merge( |
|
| 3287 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3288 | + $ignore_params |
|
| 3289 | + ); |
|
| 3290 | + if (!is_array($env)) { |
|
| 3291 | + $env = unserialize($env); |
|
| 3292 | + } |
|
| 3293 | + $texte = ''; |
|
| 3294 | + if ($env) { |
|
| 3295 | + foreach ($env as $i => $j) { |
|
| 3296 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3297 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3298 | + } |
|
| 3299 | + } |
|
| 3300 | + } |
|
| 3301 | + |
|
| 3302 | + return $texte; |
|
| 3303 | 3303 | } |
| 3304 | 3304 | |
| 3305 | 3305 | /** |
@@ -3322,23 +3322,23 @@ discard block |
||
| 3322 | 3322 | * Code HTML résultant |
| 3323 | 3323 | **/ |
| 3324 | 3324 | function env_to_attributs($env, $ignore_params = []) { |
| 3325 | - $ignore_params = array_merge( |
|
| 3326 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3327 | - $ignore_params |
|
| 3328 | - ); |
|
| 3329 | - if (!is_array($env)) { |
|
| 3330 | - $env = unserialize($env); |
|
| 3331 | - } |
|
| 3332 | - $texte = ''; |
|
| 3333 | - if ($env) { |
|
| 3334 | - foreach ($env as $i => $j) { |
|
| 3335 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3336 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3337 | - } |
|
| 3338 | - } |
|
| 3339 | - } |
|
| 3325 | + $ignore_params = array_merge( |
|
| 3326 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3327 | + $ignore_params |
|
| 3328 | + ); |
|
| 3329 | + if (!is_array($env)) { |
|
| 3330 | + $env = unserialize($env); |
|
| 3331 | + } |
|
| 3332 | + $texte = ''; |
|
| 3333 | + if ($env) { |
|
| 3334 | + foreach ($env as $i => $j) { |
|
| 3335 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3336 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3337 | + } |
|
| 3338 | + } |
|
| 3339 | + } |
|
| 3340 | 3340 | |
| 3341 | - return $texte; |
|
| 3341 | + return $texte; |
|
| 3342 | 3342 | } |
| 3343 | 3343 | |
| 3344 | 3344 | |
@@ -3356,7 +3356,7 @@ discard block |
||
| 3356 | 3356 | * @return string Chaînes concaténés |
| 3357 | 3357 | **/ |
| 3358 | 3358 | function concat(...$args): string { |
| 3359 | - return join('', $args); |
|
| 3359 | + return join('', $args); |
|
| 3360 | 3360 | } |
| 3361 | 3361 | |
| 3362 | 3362 | |
@@ -3376,23 +3376,23 @@ discard block |
||
| 3376 | 3376 | * Contenu du ou des fichiers, concaténé |
| 3377 | 3377 | **/ |
| 3378 | 3378 | function charge_scripts($files, $script = true) { |
| 3379 | - $flux = ''; |
|
| 3380 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3381 | - if (!is_string($file)) { |
|
| 3382 | - continue; |
|
| 3383 | - } |
|
| 3384 | - if ($script) { |
|
| 3385 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3386 | - } |
|
| 3387 | - if ($file) { |
|
| 3388 | - $path = find_in_path($file); |
|
| 3389 | - if ($path) { |
|
| 3390 | - $flux .= spip_file_get_contents($path); |
|
| 3391 | - } |
|
| 3392 | - } |
|
| 3393 | - } |
|
| 3394 | - |
|
| 3395 | - return $flux; |
|
| 3379 | + $flux = ''; |
|
| 3380 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3381 | + if (!is_string($file)) { |
|
| 3382 | + continue; |
|
| 3383 | + } |
|
| 3384 | + if ($script) { |
|
| 3385 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3386 | + } |
|
| 3387 | + if ($file) { |
|
| 3388 | + $path = find_in_path($file); |
|
| 3389 | + if ($path) { |
|
| 3390 | + $flux .= spip_file_get_contents($path); |
|
| 3391 | + } |
|
| 3392 | + } |
|
| 3393 | + } |
|
| 3394 | + |
|
| 3395 | + return $flux; |
|
| 3396 | 3396 | } |
| 3397 | 3397 | |
| 3398 | 3398 | /** |
@@ -3403,22 +3403,22 @@ discard block |
||
| 3403 | 3403 | * @return string |
| 3404 | 3404 | */ |
| 3405 | 3405 | function http_img_variante_svg_si_possible($img_file) { |
| 3406 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3407 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3408 | - if ( |
|
| 3409 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3410 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3411 | - and file_exists($variante_svg_generique) |
|
| 3412 | - ) { |
|
| 3413 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3414 | - $img_file = $variante_svg_size; |
|
| 3415 | - } |
|
| 3416 | - else { |
|
| 3417 | - $img_file = $variante_svg_generique; |
|
| 3418 | - } |
|
| 3419 | - } |
|
| 3406 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3407 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3408 | + if ( |
|
| 3409 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3410 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3411 | + and file_exists($variante_svg_generique) |
|
| 3412 | + ) { |
|
| 3413 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3414 | + $img_file = $variante_svg_size; |
|
| 3415 | + } |
|
| 3416 | + else { |
|
| 3417 | + $img_file = $variante_svg_generique; |
|
| 3418 | + } |
|
| 3419 | + } |
|
| 3420 | 3420 | |
| 3421 | - return $img_file; |
|
| 3421 | + return $img_file; |
|
| 3422 | 3422 | } |
| 3423 | 3423 | |
| 3424 | 3424 | /** |
@@ -3439,54 +3439,54 @@ discard block |
||
| 3439 | 3439 | */ |
| 3440 | 3440 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3441 | 3441 | |
| 3442 | - $img_file = $img; |
|
| 3443 | - if ($p = strpos($img_file, '?')) { |
|
| 3444 | - $img_file = substr($img_file, 0, $p); |
|
| 3445 | - } |
|
| 3446 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3447 | - $img_file = chemin_image($img); |
|
| 3448 | - } |
|
| 3449 | - else { |
|
| 3450 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3451 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3452 | - } |
|
| 3453 | - } |
|
| 3454 | - if (stripos($atts, 'width') === false) { |
|
| 3455 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3456 | - if ( |
|
| 3457 | - (!isset($options['utiliser_suffixe_size']) |
|
| 3458 | - or $options['utiliser_suffixe_size'] == true |
|
| 3459 | - or strpos($img_file, '-xx.svg') !== false) |
|
| 3460 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3461 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3462 | - ) { |
|
| 3463 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3464 | - } else { |
|
| 3465 | - $taille = taille_image($img_file); |
|
| 3466 | - [$hauteur, $largeur] = $taille; |
|
| 3467 | - if (!$hauteur or !$largeur) { |
|
| 3468 | - return ''; |
|
| 3469 | - } |
|
| 3470 | - } |
|
| 3471 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3472 | - } |
|
| 3473 | - |
|
| 3474 | - if (file_exists($img_file)) { |
|
| 3475 | - $img_file = timestamp($img_file); |
|
| 3476 | - } |
|
| 3477 | - if ($alt === false) { |
|
| 3478 | - $alt = ''; |
|
| 3479 | - } |
|
| 3480 | - elseif ($alt or $alt === '') { |
|
| 3481 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3482 | - } |
|
| 3483 | - else { |
|
| 3484 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3485 | - } |
|
| 3486 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3487 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3488 | - . ' ' . ltrim($atts) |
|
| 3489 | - . ' />'; |
|
| 3442 | + $img_file = $img; |
|
| 3443 | + if ($p = strpos($img_file, '?')) { |
|
| 3444 | + $img_file = substr($img_file, 0, $p); |
|
| 3445 | + } |
|
| 3446 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3447 | + $img_file = chemin_image($img); |
|
| 3448 | + } |
|
| 3449 | + else { |
|
| 3450 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3451 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3452 | + } |
|
| 3453 | + } |
|
| 3454 | + if (stripos($atts, 'width') === false) { |
|
| 3455 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3456 | + if ( |
|
| 3457 | + (!isset($options['utiliser_suffixe_size']) |
|
| 3458 | + or $options['utiliser_suffixe_size'] == true |
|
| 3459 | + or strpos($img_file, '-xx.svg') !== false) |
|
| 3460 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3461 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3462 | + ) { |
|
| 3463 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3464 | + } else { |
|
| 3465 | + $taille = taille_image($img_file); |
|
| 3466 | + [$hauteur, $largeur] = $taille; |
|
| 3467 | + if (!$hauteur or !$largeur) { |
|
| 3468 | + return ''; |
|
| 3469 | + } |
|
| 3470 | + } |
|
| 3471 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3472 | + } |
|
| 3473 | + |
|
| 3474 | + if (file_exists($img_file)) { |
|
| 3475 | + $img_file = timestamp($img_file); |
|
| 3476 | + } |
|
| 3477 | + if ($alt === false) { |
|
| 3478 | + $alt = ''; |
|
| 3479 | + } |
|
| 3480 | + elseif ($alt or $alt === '') { |
|
| 3481 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3482 | + } |
|
| 3483 | + else { |
|
| 3484 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3485 | + } |
|
| 3486 | + return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3487 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3488 | + . ' ' . ltrim($atts) |
|
| 3489 | + . ' />'; |
|
| 3490 | 3490 | } |
| 3491 | 3491 | |
| 3492 | 3492 | /** |
@@ -3498,70 +3498,70 @@ discard block |
||
| 3498 | 3498 | * @return string |
| 3499 | 3499 | */ |
| 3500 | 3500 | function http_style_background($img, $att = '', $size = null) { |
| 3501 | - if ($size and is_numeric($size)) { |
|
| 3502 | - $size = trim($size) . 'px'; |
|
| 3503 | - } |
|
| 3504 | - return " style='background" . |
|
| 3505 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3506 | - . ($size ? "background-size:{$size};" : '') |
|
| 3507 | - . "'"; |
|
| 3501 | + if ($size and is_numeric($size)) { |
|
| 3502 | + $size = trim($size) . 'px'; |
|
| 3503 | + } |
|
| 3504 | + return " style='background" . |
|
| 3505 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3506 | + . ($size ? "background-size:{$size};" : '') |
|
| 3507 | + . "'"; |
|
| 3508 | 3508 | } |
| 3509 | 3509 | |
| 3510 | 3510 | |
| 3511 | 3511 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3512 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3513 | - while (is_null(end($args)) and count($args)) { |
|
| 3514 | - array_pop($args); |
|
| 3515 | - } |
|
| 3516 | - if (!count($args)) { |
|
| 3517 | - return [null, null, null]; |
|
| 3518 | - } |
|
| 3519 | - if (count($args) < 3) { |
|
| 3520 | - $maybe_size = array_pop($args); |
|
| 3521 | - // @2x |
|
| 3522 | - // @1.5x |
|
| 3523 | - // 512 |
|
| 3524 | - // 512x* |
|
| 3525 | - // 512x300 |
|
| 3526 | - if ( |
|
| 3527 | - !strlen($maybe_size) |
|
| 3528 | - or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3529 | - ) { |
|
| 3530 | - $args[] = $maybe_size; |
|
| 3531 | - $maybe_size = null; |
|
| 3532 | - } |
|
| 3533 | - while (count($args) < 2) { |
|
| 3534 | - $args[] = null; // default alt or class |
|
| 3535 | - } |
|
| 3536 | - $args[] = $maybe_size; |
|
| 3537 | - } |
|
| 3538 | - return $args; |
|
| 3512 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3513 | + while (is_null(end($args)) and count($args)) { |
|
| 3514 | + array_pop($args); |
|
| 3515 | + } |
|
| 3516 | + if (!count($args)) { |
|
| 3517 | + return [null, null, null]; |
|
| 3518 | + } |
|
| 3519 | + if (count($args) < 3) { |
|
| 3520 | + $maybe_size = array_pop($args); |
|
| 3521 | + // @2x |
|
| 3522 | + // @1.5x |
|
| 3523 | + // 512 |
|
| 3524 | + // 512x* |
|
| 3525 | + // 512x300 |
|
| 3526 | + if ( |
|
| 3527 | + !strlen($maybe_size) |
|
| 3528 | + or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3529 | + ) { |
|
| 3530 | + $args[] = $maybe_size; |
|
| 3531 | + $maybe_size = null; |
|
| 3532 | + } |
|
| 3533 | + while (count($args) < 2) { |
|
| 3534 | + $args[] = null; // default alt or class |
|
| 3535 | + } |
|
| 3536 | + $args[] = $maybe_size; |
|
| 3537 | + } |
|
| 3538 | + return $args; |
|
| 3539 | 3539 | } |
| 3540 | 3540 | |
| 3541 | 3541 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3542 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3543 | - if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3544 | - $coef = floatval(substr($size, 1, -1)); |
|
| 3545 | - [$h, $w] = taille_image($img); |
|
| 3546 | - $height = intval(round($h / $coef)); |
|
| 3547 | - $width = intval(round($w / $coef)); |
|
| 3548 | - } |
|
| 3549 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3550 | - else { |
|
| 3551 | - $size = explode('x', $size, 2); |
|
| 3552 | - $size = array_map('trim', $size); |
|
| 3553 | - $height = $width = intval(array_shift($size)); |
|
| 3554 | - |
|
| 3555 | - if (count($size) and reset($size)) { |
|
| 3556 | - $height = array_shift($size); |
|
| 3557 | - if ($height === '*') { |
|
| 3558 | - [$h, $w] = taille_image($img); |
|
| 3559 | - $height = intval(round($h * $width / $w)); |
|
| 3560 | - } |
|
| 3561 | - } |
|
| 3562 | - } |
|
| 3563 | - |
|
| 3564 | - return [$width, $height]; |
|
| 3542 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3543 | + if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3544 | + $coef = floatval(substr($size, 1, -1)); |
|
| 3545 | + [$h, $w] = taille_image($img); |
|
| 3546 | + $height = intval(round($h / $coef)); |
|
| 3547 | + $width = intval(round($w / $coef)); |
|
| 3548 | + } |
|
| 3549 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3550 | + else { |
|
| 3551 | + $size = explode('x', $size, 2); |
|
| 3552 | + $size = array_map('trim', $size); |
|
| 3553 | + $height = $width = intval(array_shift($size)); |
|
| 3554 | + |
|
| 3555 | + if (count($size) and reset($size)) { |
|
| 3556 | + $height = array_shift($size); |
|
| 3557 | + if ($height === '*') { |
|
| 3558 | + [$h, $w] = taille_image($img); |
|
| 3559 | + $height = intval(round($h * $width / $w)); |
|
| 3560 | + } |
|
| 3561 | + } |
|
| 3562 | + } |
|
| 3563 | + |
|
| 3564 | + return [$width, $height]; |
|
| 3565 | 3565 | } |
| 3566 | 3566 | |
| 3567 | 3567 | /** |
@@ -3597,43 +3597,43 @@ discard block |
||
| 3597 | 3597 | */ |
| 3598 | 3598 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3599 | 3599 | |
| 3600 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3601 | - |
|
| 3602 | - $img = trim((string) $img); |
|
| 3603 | - if (strpos($img, '<img') === 0) { |
|
| 3604 | - if (!is_null($alt)) { |
|
| 3605 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3606 | - } |
|
| 3607 | - if (!is_null($class)) { |
|
| 3608 | - if (strlen($class)) { |
|
| 3609 | - $img = inserer_attribut($img, 'class', $class); |
|
| 3610 | - } |
|
| 3611 | - else { |
|
| 3612 | - $img = vider_attribut($img, 'class'); |
|
| 3613 | - } |
|
| 3614 | - } |
|
| 3615 | - } |
|
| 3616 | - else { |
|
| 3617 | - $img = http_img_pack( |
|
| 3618 | - $img, |
|
| 3619 | - $alt, |
|
| 3620 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3621 | - '', |
|
| 3622 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3623 | - ); |
|
| 3624 | - if (is_null($alt)) { |
|
| 3625 | - $img = vider_attribut($img, 'alt'); |
|
| 3626 | - } |
|
| 3627 | - } |
|
| 3628 | - |
|
| 3629 | - if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3630 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3631 | - |
|
| 3632 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3633 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3634 | - } |
|
| 3635 | - |
|
| 3636 | - return $img; |
|
| 3600 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3601 | + |
|
| 3602 | + $img = trim((string) $img); |
|
| 3603 | + if (strpos($img, '<img') === 0) { |
|
| 3604 | + if (!is_null($alt)) { |
|
| 3605 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3606 | + } |
|
| 3607 | + if (!is_null($class)) { |
|
| 3608 | + if (strlen($class)) { |
|
| 3609 | + $img = inserer_attribut($img, 'class', $class); |
|
| 3610 | + } |
|
| 3611 | + else { |
|
| 3612 | + $img = vider_attribut($img, 'class'); |
|
| 3613 | + } |
|
| 3614 | + } |
|
| 3615 | + } |
|
| 3616 | + else { |
|
| 3617 | + $img = http_img_pack( |
|
| 3618 | + $img, |
|
| 3619 | + $alt, |
|
| 3620 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3621 | + '', |
|
| 3622 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3623 | + ); |
|
| 3624 | + if (is_null($alt)) { |
|
| 3625 | + $img = vider_attribut($img, 'alt'); |
|
| 3626 | + } |
|
| 3627 | + } |
|
| 3628 | + |
|
| 3629 | + if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3630 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3631 | + |
|
| 3632 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3633 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3634 | + } |
|
| 3635 | + |
|
| 3636 | + return $img; |
|
| 3637 | 3637 | } |
| 3638 | 3638 | |
| 3639 | 3639 | |
@@ -3667,80 +3667,80 @@ discard block |
||
| 3667 | 3667 | */ |
| 3668 | 3668 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3669 | 3669 | |
| 3670 | - $svg = null; |
|
| 3671 | - $img = trim($img); |
|
| 3672 | - $img_file = $img; |
|
| 3673 | - if (strpos($img, '<svg') === false) { |
|
| 3674 | - if ($p = strpos($img_file, '?')) { |
|
| 3675 | - $img_file = substr($img_file, 0, $p); |
|
| 3676 | - } |
|
| 3677 | - |
|
| 3678 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3679 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3680 | - if (tester_url_absolue($img_file)) { |
|
| 3681 | - include_spip('inc/distant'); |
|
| 3682 | - $fichier = copie_locale($img_file); |
|
| 3683 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3684 | - } |
|
| 3685 | - |
|
| 3686 | - if ( |
|
| 3687 | - !$img_file |
|
| 3688 | - or !file_exists($img_file) |
|
| 3689 | - or !$svg = file_get_contents($img_file) |
|
| 3690 | - ) { |
|
| 3691 | - return ''; |
|
| 3692 | - } |
|
| 3693 | - } |
|
| 3694 | - |
|
| 3695 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3696 | - return ''; |
|
| 3697 | - } |
|
| 3698 | - |
|
| 3699 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3700 | - |
|
| 3701 | - $balise_svg = $match[0]; |
|
| 3702 | - $balise_svg_source = $balise_svg; |
|
| 3703 | - |
|
| 3704 | - // entete XML à supprimer |
|
| 3705 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3706 | - |
|
| 3707 | - // IE est toujours mon ami |
|
| 3708 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3709 | - |
|
| 3710 | - // regler la classe |
|
| 3711 | - if (!is_null($class)) { |
|
| 3712 | - if (strlen($class)) { |
|
| 3713 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3714 | - } |
|
| 3715 | - else { |
|
| 3716 | - $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3717 | - } |
|
| 3718 | - } |
|
| 3719 | - |
|
| 3720 | - // regler le alt |
|
| 3721 | - if ($alt) { |
|
| 3722 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3723 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3724 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3725 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3726 | - $balise_svg .= $title; |
|
| 3727 | - } |
|
| 3728 | - else { |
|
| 3729 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3730 | - } |
|
| 3731 | - |
|
| 3732 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3733 | - |
|
| 3734 | - if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3735 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3736 | - |
|
| 3737 | - if (!function_exists('svg_redimensionner')) { |
|
| 3738 | - include_spip('inc/svg'); |
|
| 3739 | - } |
|
| 3740 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3741 | - } |
|
| 3742 | - |
|
| 3743 | - return $svg; |
|
| 3670 | + $svg = null; |
|
| 3671 | + $img = trim($img); |
|
| 3672 | + $img_file = $img; |
|
| 3673 | + if (strpos($img, '<svg') === false) { |
|
| 3674 | + if ($p = strpos($img_file, '?')) { |
|
| 3675 | + $img_file = substr($img_file, 0, $p); |
|
| 3676 | + } |
|
| 3677 | + |
|
| 3678 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3679 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3680 | + if (tester_url_absolue($img_file)) { |
|
| 3681 | + include_spip('inc/distant'); |
|
| 3682 | + $fichier = copie_locale($img_file); |
|
| 3683 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3684 | + } |
|
| 3685 | + |
|
| 3686 | + if ( |
|
| 3687 | + !$img_file |
|
| 3688 | + or !file_exists($img_file) |
|
| 3689 | + or !$svg = file_get_contents($img_file) |
|
| 3690 | + ) { |
|
| 3691 | + return ''; |
|
| 3692 | + } |
|
| 3693 | + } |
|
| 3694 | + |
|
| 3695 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3696 | + return ''; |
|
| 3697 | + } |
|
| 3698 | + |
|
| 3699 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3700 | + |
|
| 3701 | + $balise_svg = $match[0]; |
|
| 3702 | + $balise_svg_source = $balise_svg; |
|
| 3703 | + |
|
| 3704 | + // entete XML à supprimer |
|
| 3705 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3706 | + |
|
| 3707 | + // IE est toujours mon ami |
|
| 3708 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3709 | + |
|
| 3710 | + // regler la classe |
|
| 3711 | + if (!is_null($class)) { |
|
| 3712 | + if (strlen($class)) { |
|
| 3713 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3714 | + } |
|
| 3715 | + else { |
|
| 3716 | + $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3717 | + } |
|
| 3718 | + } |
|
| 3719 | + |
|
| 3720 | + // regler le alt |
|
| 3721 | + if ($alt) { |
|
| 3722 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3723 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3724 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3725 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3726 | + $balise_svg .= $title; |
|
| 3727 | + } |
|
| 3728 | + else { |
|
| 3729 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3730 | + } |
|
| 3731 | + |
|
| 3732 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3733 | + |
|
| 3734 | + if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3735 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3736 | + |
|
| 3737 | + if (!function_exists('svg_redimensionner')) { |
|
| 3738 | + include_spip('inc/svg'); |
|
| 3739 | + } |
|
| 3740 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3741 | + } |
|
| 3742 | + |
|
| 3743 | + return $svg; |
|
| 3744 | 3744 | } |
| 3745 | 3745 | |
| 3746 | 3746 | |
@@ -3766,18 +3766,18 @@ discard block |
||
| 3766 | 3766 | * Code HTML résultant |
| 3767 | 3767 | **/ |
| 3768 | 3768 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3769 | - $texte = ''; |
|
| 3770 | - if (is_array($tableau)) { |
|
| 3771 | - foreach ($tableau as $k => $v) { |
|
| 3772 | - $res = recuperer_fond( |
|
| 3773 | - 'modeles/' . $modele, |
|
| 3774 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3775 | - ); |
|
| 3776 | - $texte .= $res; |
|
| 3777 | - } |
|
| 3778 | - } |
|
| 3769 | + $texte = ''; |
|
| 3770 | + if (is_array($tableau)) { |
|
| 3771 | + foreach ($tableau as $k => $v) { |
|
| 3772 | + $res = recuperer_fond( |
|
| 3773 | + 'modeles/' . $modele, |
|
| 3774 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3775 | + ); |
|
| 3776 | + $texte .= $res; |
|
| 3777 | + } |
|
| 3778 | + } |
|
| 3779 | 3779 | |
| 3780 | - return $texte; |
|
| 3780 | + return $texte; |
|
| 3781 | 3781 | } |
| 3782 | 3782 | |
| 3783 | 3783 | |
@@ -3802,37 +3802,37 @@ discard block |
||
| 3802 | 3802 | * - tout : retourne toutes les informations du plugin actif |
| 3803 | 3803 | **/ |
| 3804 | 3804 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3805 | - include_spip('inc/plugin'); |
|
| 3806 | - $plugin = strtoupper($plugin); |
|
| 3807 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3808 | - |
|
| 3809 | - if (!$plugin) { |
|
| 3810 | - return serialize(array_keys($plugins_actifs)); |
|
| 3811 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3812 | - return ''; |
|
| 3813 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3814 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3815 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3816 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3817 | - } else { |
|
| 3818 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3819 | - // On prend en compte les extensions |
|
| 3820 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3821 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3822 | - } else { |
|
| 3823 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3824 | - } |
|
| 3825 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3826 | - return ''; |
|
| 3827 | - } |
|
| 3828 | - if ($type_info == 'tout') { |
|
| 3829 | - return $infos; |
|
| 3830 | - } elseif ($type_info == 'est_actif') { |
|
| 3831 | - return $infos ? 1 : 0; |
|
| 3832 | - } else { |
|
| 3833 | - return strval($infos[$type_info]); |
|
| 3834 | - } |
|
| 3835 | - } |
|
| 3805 | + include_spip('inc/plugin'); |
|
| 3806 | + $plugin = strtoupper($plugin); |
|
| 3807 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3808 | + |
|
| 3809 | + if (!$plugin) { |
|
| 3810 | + return serialize(array_keys($plugins_actifs)); |
|
| 3811 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3812 | + return ''; |
|
| 3813 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3814 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3815 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3816 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3817 | + } else { |
|
| 3818 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3819 | + // On prend en compte les extensions |
|
| 3820 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3821 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3822 | + } else { |
|
| 3823 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3824 | + } |
|
| 3825 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3826 | + return ''; |
|
| 3827 | + } |
|
| 3828 | + if ($type_info == 'tout') { |
|
| 3829 | + return $infos; |
|
| 3830 | + } elseif ($type_info == 'est_actif') { |
|
| 3831 | + return $infos ? 1 : 0; |
|
| 3832 | + } else { |
|
| 3833 | + return strval($infos[$type_info]); |
|
| 3834 | + } |
|
| 3835 | + } |
|
| 3836 | 3836 | } |
| 3837 | 3837 | |
| 3838 | 3838 | |
@@ -3859,9 +3859,9 @@ discard block |
||
| 3859 | 3859 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3860 | 3860 | */ |
| 3861 | 3861 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3862 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3862 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3863 | 3863 | |
| 3864 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3864 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3865 | 3865 | } |
| 3866 | 3866 | |
| 3867 | 3867 | |
@@ -3891,19 +3891,19 @@ discard block |
||
| 3891 | 3891 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3892 | 3892 | */ |
| 3893 | 3893 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3894 | - static $puce_statut = null; |
|
| 3895 | - if (!$puce_statut) { |
|
| 3896 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3897 | - } |
|
| 3894 | + static $puce_statut = null; |
|
| 3895 | + if (!$puce_statut) { |
|
| 3896 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3897 | + } |
|
| 3898 | 3898 | |
| 3899 | - return $puce_statut( |
|
| 3900 | - $id_objet, |
|
| 3901 | - $statut, |
|
| 3902 | - $id_parent, |
|
| 3903 | - $objet, |
|
| 3904 | - false, |
|
| 3905 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3906 | - ); |
|
| 3899 | + return $puce_statut( |
|
| 3900 | + $id_objet, |
|
| 3901 | + $statut, |
|
| 3902 | + $id_parent, |
|
| 3903 | + $objet, |
|
| 3904 | + false, |
|
| 3905 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3906 | + ); |
|
| 3907 | 3907 | } |
| 3908 | 3908 | |
| 3909 | 3909 | |
@@ -3930,98 +3930,98 @@ discard block |
||
| 3930 | 3930 | * hash du contexte |
| 3931 | 3931 | */ |
| 3932 | 3932 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3933 | - $env = null; |
|
| 3934 | - if ( |
|
| 3935 | - is_string($c) |
|
| 3936 | - and @unserialize($c) !== false |
|
| 3937 | - ) { |
|
| 3938 | - $c = unserialize($c); |
|
| 3939 | - } |
|
| 3940 | - |
|
| 3941 | - // supprimer les parametres debut_x |
|
| 3942 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3943 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3944 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3945 | - if (is_array($c)) { |
|
| 3946 | - foreach ($c as $k => $v) { |
|
| 3947 | - if (strpos($k, 'debut_') === 0) { |
|
| 3948 | - unset($c[$k]); |
|
| 3949 | - } |
|
| 3950 | - } |
|
| 3951 | - } |
|
| 3952 | - |
|
| 3953 | - if (!function_exists('calculer_cle_action')) { |
|
| 3954 | - include_spip('inc/securiser_action'); |
|
| 3955 | - } |
|
| 3956 | - |
|
| 3957 | - $c = serialize($c); |
|
| 3958 | - $cle = calculer_cle_action($form . $c); |
|
| 3959 | - $c = "$cle:$c"; |
|
| 3960 | - |
|
| 3961 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3962 | - // par defaut, sauf si cette configuration a été forcée |
|
| 3963 | - // OU que la longueur de l’argument géneré est plus long |
|
| 3964 | - // que ce qui est toléré. |
|
| 3965 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3966 | - if (!$cache_contextes_ajax) { |
|
| 3967 | - $env = $c; |
|
| 3968 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3969 | - $env = gzdeflate($env); |
|
| 3970 | - } |
|
| 3971 | - $env = _xor($env); |
|
| 3972 | - $env = base64_encode($env); |
|
| 3973 | - $len = strlen($env); |
|
| 3974 | - // Si l’url est trop longue pour le navigateur |
|
| 3975 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3976 | - if ($len > $max_len) { |
|
| 3977 | - $cache_contextes_ajax = true; |
|
| 3978 | - spip_log( |
|
| 3979 | - 'Contextes AJAX forces en fichiers !' |
|
| 3980 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3981 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3982 | - _LOG_AVERTISSEMENT |
|
| 3983 | - ); |
|
| 3984 | - } |
|
| 3985 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3986 | - elseif ( |
|
| 3987 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3988 | - and $max_len < $len |
|
| 3989 | - ) { |
|
| 3990 | - $cache_contextes_ajax = true; |
|
| 3991 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 3992 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3993 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3994 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3995 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3996 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3997 | - } |
|
| 3998 | - } |
|
| 3999 | - |
|
| 4000 | - if ($cache_contextes_ajax) { |
|
| 4001 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4002 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4003 | - $md5 = md5($c); |
|
| 4004 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 4005 | - $env = $md5; |
|
| 4006 | - } |
|
| 4007 | - |
|
| 4008 | - if ($emboite === null) { |
|
| 4009 | - return $env; |
|
| 4010 | - } |
|
| 4011 | - if (!trim($emboite)) { |
|
| 4012 | - return ''; |
|
| 4013 | - } |
|
| 4014 | - // toujours encoder l'url source dans le bloc ajax |
|
| 4015 | - $r = self(); |
|
| 4016 | - $r = ' data-origin="' . $r . '"'; |
|
| 4017 | - $class = 'ajaxbloc'; |
|
| 4018 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 4019 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 4020 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4021 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4022 | - } |
|
| 4023 | - |
|
| 4024 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3933 | + $env = null; |
|
| 3934 | + if ( |
|
| 3935 | + is_string($c) |
|
| 3936 | + and @unserialize($c) !== false |
|
| 3937 | + ) { |
|
| 3938 | + $c = unserialize($c); |
|
| 3939 | + } |
|
| 3940 | + |
|
| 3941 | + // supprimer les parametres debut_x |
|
| 3942 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3943 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3944 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3945 | + if (is_array($c)) { |
|
| 3946 | + foreach ($c as $k => $v) { |
|
| 3947 | + if (strpos($k, 'debut_') === 0) { |
|
| 3948 | + unset($c[$k]); |
|
| 3949 | + } |
|
| 3950 | + } |
|
| 3951 | + } |
|
| 3952 | + |
|
| 3953 | + if (!function_exists('calculer_cle_action')) { |
|
| 3954 | + include_spip('inc/securiser_action'); |
|
| 3955 | + } |
|
| 3956 | + |
|
| 3957 | + $c = serialize($c); |
|
| 3958 | + $cle = calculer_cle_action($form . $c); |
|
| 3959 | + $c = "$cle:$c"; |
|
| 3960 | + |
|
| 3961 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3962 | + // par defaut, sauf si cette configuration a été forcée |
|
| 3963 | + // OU que la longueur de l’argument géneré est plus long |
|
| 3964 | + // que ce qui est toléré. |
|
| 3965 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3966 | + if (!$cache_contextes_ajax) { |
|
| 3967 | + $env = $c; |
|
| 3968 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3969 | + $env = gzdeflate($env); |
|
| 3970 | + } |
|
| 3971 | + $env = _xor($env); |
|
| 3972 | + $env = base64_encode($env); |
|
| 3973 | + $len = strlen($env); |
|
| 3974 | + // Si l’url est trop longue pour le navigateur |
|
| 3975 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3976 | + if ($len > $max_len) { |
|
| 3977 | + $cache_contextes_ajax = true; |
|
| 3978 | + spip_log( |
|
| 3979 | + 'Contextes AJAX forces en fichiers !' |
|
| 3980 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3981 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3982 | + _LOG_AVERTISSEMENT |
|
| 3983 | + ); |
|
| 3984 | + } |
|
| 3985 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3986 | + elseif ( |
|
| 3987 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3988 | + and $max_len < $len |
|
| 3989 | + ) { |
|
| 3990 | + $cache_contextes_ajax = true; |
|
| 3991 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 3992 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3993 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3994 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3995 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3996 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3997 | + } |
|
| 3998 | + } |
|
| 3999 | + |
|
| 4000 | + if ($cache_contextes_ajax) { |
|
| 4001 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4002 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4003 | + $md5 = md5($c); |
|
| 4004 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 4005 | + $env = $md5; |
|
| 4006 | + } |
|
| 4007 | + |
|
| 4008 | + if ($emboite === null) { |
|
| 4009 | + return $env; |
|
| 4010 | + } |
|
| 4011 | + if (!trim($emboite)) { |
|
| 4012 | + return ''; |
|
| 4013 | + } |
|
| 4014 | + // toujours encoder l'url source dans le bloc ajax |
|
| 4015 | + $r = self(); |
|
| 4016 | + $r = ' data-origin="' . $r . '"'; |
|
| 4017 | + $class = 'ajaxbloc'; |
|
| 4018 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 4019 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 4020 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4021 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4022 | + } |
|
| 4023 | + |
|
| 4024 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4025 | 4025 | } |
| 4026 | 4026 | |
| 4027 | 4027 | /** |
@@ -4041,37 +4041,37 @@ discard block |
||
| 4041 | 4041 | * - false : erreur de décodage |
| 4042 | 4042 | */ |
| 4043 | 4043 | function decoder_contexte_ajax($c, $form = '') { |
| 4044 | - if (!function_exists('calculer_cle_action')) { |
|
| 4045 | - include_spip('inc/securiser_action'); |
|
| 4046 | - } |
|
| 4047 | - if ( |
|
| 4048 | - ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4049 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4050 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 4051 | - ) { |
|
| 4052 | - $c = $contexte; |
|
| 4053 | - } else { |
|
| 4054 | - $c = @base64_decode($c); |
|
| 4055 | - $c = _xor($c); |
|
| 4056 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4057 | - $c = @gzinflate($c); |
|
| 4058 | - } |
|
| 4059 | - } |
|
| 4060 | - |
|
| 4061 | - // extraire la signature en debut de contexte |
|
| 4062 | - // et la verifier avant de deserializer |
|
| 4063 | - // format : signature:donneesserializees |
|
| 4064 | - if ($p = strpos($c, ':')) { |
|
| 4065 | - $cle = substr($c, 0, $p); |
|
| 4066 | - $c = substr($c, $p + 1); |
|
| 4067 | - |
|
| 4068 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4069 | - $env = @unserialize($c); |
|
| 4070 | - return $env; |
|
| 4071 | - } |
|
| 4072 | - } |
|
| 4073 | - |
|
| 4074 | - return false; |
|
| 4044 | + if (!function_exists('calculer_cle_action')) { |
|
| 4045 | + include_spip('inc/securiser_action'); |
|
| 4046 | + } |
|
| 4047 | + if ( |
|
| 4048 | + ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4049 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4050 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 4051 | + ) { |
|
| 4052 | + $c = $contexte; |
|
| 4053 | + } else { |
|
| 4054 | + $c = @base64_decode($c); |
|
| 4055 | + $c = _xor($c); |
|
| 4056 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4057 | + $c = @gzinflate($c); |
|
| 4058 | + } |
|
| 4059 | + } |
|
| 4060 | + |
|
| 4061 | + // extraire la signature en debut de contexte |
|
| 4062 | + // et la verifier avant de deserializer |
|
| 4063 | + // format : signature:donneesserializees |
|
| 4064 | + if ($p = strpos($c, ':')) { |
|
| 4065 | + $cle = substr($c, 0, $p); |
|
| 4066 | + $c = substr($c, $p + 1); |
|
| 4067 | + |
|
| 4068 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4069 | + $env = @unserialize($c); |
|
| 4070 | + return $env; |
|
| 4071 | + } |
|
| 4072 | + } |
|
| 4073 | + |
|
| 4074 | + return false; |
|
| 4075 | 4075 | } |
| 4076 | 4076 | |
| 4077 | 4077 | |
@@ -4089,20 +4089,20 @@ discard block |
||
| 4089 | 4089 | * Message décrypté ou encrypté |
| 4090 | 4090 | **/ |
| 4091 | 4091 | function _xor($message, $key = null) { |
| 4092 | - if (is_null($key)) { |
|
| 4093 | - if (!function_exists('calculer_cle_action')) { |
|
| 4094 | - include_spip('inc/securiser_action'); |
|
| 4095 | - } |
|
| 4096 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4097 | - } |
|
| 4092 | + if (is_null($key)) { |
|
| 4093 | + if (!function_exists('calculer_cle_action')) { |
|
| 4094 | + include_spip('inc/securiser_action'); |
|
| 4095 | + } |
|
| 4096 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4097 | + } |
|
| 4098 | 4098 | |
| 4099 | - $keylen = strlen($key); |
|
| 4100 | - $messagelen = strlen($message); |
|
| 4101 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4102 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4103 | - } |
|
| 4099 | + $keylen = strlen($key); |
|
| 4100 | + $messagelen = strlen($message); |
|
| 4101 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4102 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4103 | + } |
|
| 4104 | 4104 | |
| 4105 | - return $message; |
|
| 4105 | + return $message; |
|
| 4106 | 4106 | } |
| 4107 | 4107 | |
| 4108 | 4108 | /** |
@@ -4116,7 +4116,7 @@ discard block |
||
| 4116 | 4116 | * @return string |
| 4117 | 4117 | */ |
| 4118 | 4118 | function url_reponse_forum($texte) { |
| 4119 | - return $texte; |
|
| 4119 | + return $texte; |
|
| 4120 | 4120 | } |
| 4121 | 4121 | |
| 4122 | 4122 | /** |
@@ -4130,7 +4130,7 @@ discard block |
||
| 4130 | 4130 | * @return string |
| 4131 | 4131 | */ |
| 4132 | 4132 | function url_rss_forum($texte) { |
| 4133 | - return $texte; |
|
| 4133 | + return $texte; |
|
| 4134 | 4134 | } |
| 4135 | 4135 | |
| 4136 | 4136 | |
@@ -4169,37 +4169,37 @@ discard block |
||
| 4169 | 4169 | * Code HTML |
| 4170 | 4170 | */ |
| 4171 | 4171 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4172 | - if ($on) { |
|
| 4173 | - $bal = 'strong'; |
|
| 4174 | - $class = ''; |
|
| 4175 | - $att = ''; |
|
| 4176 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4177 | - // a.active span.selected.active etc.... |
|
| 4178 | - if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4179 | - $on = explode('.', $on); |
|
| 4180 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4181 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4182 | - $bal = array_shift($on); |
|
| 4183 | - $class = implode(' ', $on); |
|
| 4184 | - if ($bal == 'a') { |
|
| 4185 | - $att = 'href="#" '; |
|
| 4186 | - } |
|
| 4187 | - } |
|
| 4188 | - } |
|
| 4189 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4190 | - } else { |
|
| 4191 | - $bal = 'a'; |
|
| 4192 | - $att = "href='$url'" |
|
| 4193 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4194 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4195 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4196 | - . $evt; |
|
| 4197 | - } |
|
| 4198 | - if ($libelle === null) { |
|
| 4199 | - $libelle = $url; |
|
| 4200 | - } |
|
| 4201 | - |
|
| 4202 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4172 | + if ($on) { |
|
| 4173 | + $bal = 'strong'; |
|
| 4174 | + $class = ''; |
|
| 4175 | + $att = ''; |
|
| 4176 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4177 | + // a.active span.selected.active etc.... |
|
| 4178 | + if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4179 | + $on = explode('.', $on); |
|
| 4180 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4181 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4182 | + $bal = array_shift($on); |
|
| 4183 | + $class = implode(' ', $on); |
|
| 4184 | + if ($bal == 'a') { |
|
| 4185 | + $att = 'href="#" '; |
|
| 4186 | + } |
|
| 4187 | + } |
|
| 4188 | + } |
|
| 4189 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4190 | + } else { |
|
| 4191 | + $bal = 'a'; |
|
| 4192 | + $att = "href='$url'" |
|
| 4193 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4194 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4195 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4196 | + . $evt; |
|
| 4197 | + } |
|
| 4198 | + if ($libelle === null) { |
|
| 4199 | + $libelle = $url; |
|
| 4200 | + } |
|
| 4201 | + |
|
| 4202 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4203 | 4203 | } |
| 4204 | 4204 | |
| 4205 | 4205 | |
@@ -4216,39 +4216,39 @@ discard block |
||
| 4216 | 4216 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4217 | 4217 | */ |
| 4218 | 4218 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4219 | - static $local_singulier_ou_pluriel = []; |
|
| 4220 | - |
|
| 4221 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4222 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 4223 | - return ''; |
|
| 4224 | - } |
|
| 4225 | - if (!is_array($vars)) { |
|
| 4226 | - return ''; |
|
| 4227 | - } |
|
| 4228 | - |
|
| 4229 | - $langue = $GLOBALS['spip_lang']; |
|
| 4230 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4231 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4232 | - if ( |
|
| 4233 | - $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true) |
|
| 4234 | - or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4235 | - ) { |
|
| 4236 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4237 | - } |
|
| 4238 | - } |
|
| 4239 | - |
|
| 4240 | - // si on a une surcharge on l'utilise |
|
| 4241 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4242 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4243 | - } |
|
| 4244 | - |
|
| 4245 | - // sinon traitement par defaut |
|
| 4246 | - $vars[$var] = $nb; |
|
| 4247 | - if ($nb >= 2) { |
|
| 4248 | - return _T($chaine_plusieurs, $vars); |
|
| 4249 | - } else { |
|
| 4250 | - return _T($chaine_un, $vars); |
|
| 4251 | - } |
|
| 4219 | + static $local_singulier_ou_pluriel = []; |
|
| 4220 | + |
|
| 4221 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4222 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 4223 | + return ''; |
|
| 4224 | + } |
|
| 4225 | + if (!is_array($vars)) { |
|
| 4226 | + return ''; |
|
| 4227 | + } |
|
| 4228 | + |
|
| 4229 | + $langue = $GLOBALS['spip_lang']; |
|
| 4230 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4231 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4232 | + if ( |
|
| 4233 | + $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true) |
|
| 4234 | + or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4235 | + ) { |
|
| 4236 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4237 | + } |
|
| 4238 | + } |
|
| 4239 | + |
|
| 4240 | + // si on a une surcharge on l'utilise |
|
| 4241 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4242 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4243 | + } |
|
| 4244 | + |
|
| 4245 | + // sinon traitement par defaut |
|
| 4246 | + $vars[$var] = $nb; |
|
| 4247 | + if ($nb >= 2) { |
|
| 4248 | + return _T($chaine_plusieurs, $vars); |
|
| 4249 | + } else { |
|
| 4250 | + return _T($chaine_un, $vars); |
|
| 4251 | + } |
|
| 4252 | 4252 | } |
| 4253 | 4253 | |
| 4254 | 4254 | |
@@ -4276,73 +4276,73 @@ discard block |
||
| 4276 | 4276 | */ |
| 4277 | 4277 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4278 | 4278 | |
| 4279 | - $class_lien = $class_bouton = $class; |
|
| 4280 | - |
|
| 4281 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4282 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4283 | - $class_lien .= ' danger'; |
|
| 4284 | - $class_bouton .= ' btn_danger'; |
|
| 4285 | - } elseif ($fonction == 'rien.gif') { |
|
| 4286 | - $fonction = ''; |
|
| 4287 | - } elseif ($fonction == 'delsafe') { |
|
| 4288 | - $fonction = 'del'; |
|
| 4289 | - } |
|
| 4290 | - |
|
| 4291 | - $fond_origine = $fond; |
|
| 4292 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4293 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4294 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4295 | - } |
|
| 4296 | - |
|
| 4297 | - // Ajouter le type d'objet dans la classe |
|
| 4298 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4299 | - $class_lien .= " $objet_type"; |
|
| 4300 | - $class_bouton .= " $objet_type"; |
|
| 4301 | - |
|
| 4302 | - // Texte |
|
| 4303 | - $alt = attribut_html($texte); |
|
| 4304 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4305 | - |
|
| 4306 | - // Liens : préparer les classes ajax |
|
| 4307 | - $ajax = ''; |
|
| 4308 | - if ($type === 'lien') { |
|
| 4309 | - if (strpos($class_lien, 'ajax') !== false) { |
|
| 4310 | - $ajax = 'ajax'; |
|
| 4311 | - if (strpos($class_lien, 'preload') !== false) { |
|
| 4312 | - $ajax .= ' preload'; |
|
| 4313 | - } |
|
| 4314 | - if (strpos($class_lien, 'nocache') !== false) { |
|
| 4315 | - $ajax .= ' nocache'; |
|
| 4316 | - } |
|
| 4317 | - $ajax = " class='$ajax'"; |
|
| 4318 | - } |
|
| 4319 | - } |
|
| 4320 | - |
|
| 4321 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4322 | - $size = 24; |
|
| 4323 | - if ( |
|
| 4324 | - preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4325 | - or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4326 | - ) { |
|
| 4327 | - $size = $match[1]; |
|
| 4328 | - } |
|
| 4329 | - $class_lien .= " s$size"; |
|
| 4330 | - $class_bouton .= " s$size"; |
|
| 4331 | - |
|
| 4332 | - // Icône |
|
| 4333 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4334 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4335 | - |
|
| 4336 | - // Markup final |
|
| 4337 | - if ($type == 'lien') { |
|
| 4338 | - return "<span class='icone $class_lien'>" |
|
| 4339 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4340 | - . $icone |
|
| 4341 | - . "<b>$texte</b>" |
|
| 4342 | - . "</a></span>\n"; |
|
| 4343 | - } else { |
|
| 4344 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4345 | - } |
|
| 4279 | + $class_lien = $class_bouton = $class; |
|
| 4280 | + |
|
| 4281 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4282 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4283 | + $class_lien .= ' danger'; |
|
| 4284 | + $class_bouton .= ' btn_danger'; |
|
| 4285 | + } elseif ($fonction == 'rien.gif') { |
|
| 4286 | + $fonction = ''; |
|
| 4287 | + } elseif ($fonction == 'delsafe') { |
|
| 4288 | + $fonction = 'del'; |
|
| 4289 | + } |
|
| 4290 | + |
|
| 4291 | + $fond_origine = $fond; |
|
| 4292 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4293 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4294 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4295 | + } |
|
| 4296 | + |
|
| 4297 | + // Ajouter le type d'objet dans la classe |
|
| 4298 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4299 | + $class_lien .= " $objet_type"; |
|
| 4300 | + $class_bouton .= " $objet_type"; |
|
| 4301 | + |
|
| 4302 | + // Texte |
|
| 4303 | + $alt = attribut_html($texte); |
|
| 4304 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4305 | + |
|
| 4306 | + // Liens : préparer les classes ajax |
|
| 4307 | + $ajax = ''; |
|
| 4308 | + if ($type === 'lien') { |
|
| 4309 | + if (strpos($class_lien, 'ajax') !== false) { |
|
| 4310 | + $ajax = 'ajax'; |
|
| 4311 | + if (strpos($class_lien, 'preload') !== false) { |
|
| 4312 | + $ajax .= ' preload'; |
|
| 4313 | + } |
|
| 4314 | + if (strpos($class_lien, 'nocache') !== false) { |
|
| 4315 | + $ajax .= ' nocache'; |
|
| 4316 | + } |
|
| 4317 | + $ajax = " class='$ajax'"; |
|
| 4318 | + } |
|
| 4319 | + } |
|
| 4320 | + |
|
| 4321 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4322 | + $size = 24; |
|
| 4323 | + if ( |
|
| 4324 | + preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4325 | + or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4326 | + ) { |
|
| 4327 | + $size = $match[1]; |
|
| 4328 | + } |
|
| 4329 | + $class_lien .= " s$size"; |
|
| 4330 | + $class_bouton .= " s$size"; |
|
| 4331 | + |
|
| 4332 | + // Icône |
|
| 4333 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4334 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4335 | + |
|
| 4336 | + // Markup final |
|
| 4337 | + if ($type == 'lien') { |
|
| 4338 | + return "<span class='icone $class_lien'>" |
|
| 4339 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4340 | + . $icone |
|
| 4341 | + . "<b>$texte</b>" |
|
| 4342 | + . "</a></span>\n"; |
|
| 4343 | + } else { |
|
| 4344 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4345 | + } |
|
| 4346 | 4346 | } |
| 4347 | 4347 | |
| 4348 | 4348 | /** |
@@ -4366,7 +4366,7 @@ discard block |
||
| 4366 | 4366 | * Code HTML du lien |
| 4367 | 4367 | **/ |
| 4368 | 4368 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4369 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4369 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4370 | 4370 | } |
| 4371 | 4371 | |
| 4372 | 4372 | /** |
@@ -4401,7 +4401,7 @@ discard block |
||
| 4401 | 4401 | * Code HTML du lien |
| 4402 | 4402 | **/ |
| 4403 | 4403 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4404 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4404 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4405 | 4405 | } |
| 4406 | 4406 | |
| 4407 | 4407 | /** |
@@ -4446,7 +4446,7 @@ discard block |
||
| 4446 | 4446 | * Code HTML du lien |
| 4447 | 4447 | **/ |
| 4448 | 4448 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4449 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4449 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4450 | 4450 | } |
| 4451 | 4451 | |
| 4452 | 4452 | /** |
@@ -4477,7 +4477,7 @@ discard block |
||
| 4477 | 4477 | * Code HTML du lien |
| 4478 | 4478 | **/ |
| 4479 | 4479 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4480 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4480 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4481 | 4481 | } |
| 4482 | 4482 | |
| 4483 | 4483 | /** |
@@ -4508,7 +4508,7 @@ discard block |
||
| 4508 | 4508 | * Code HTML du lien |
| 4509 | 4509 | */ |
| 4510 | 4510 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4511 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4511 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4512 | 4512 | } |
| 4513 | 4513 | |
| 4514 | 4514 | |
@@ -4530,7 +4530,7 @@ discard block |
||
| 4530 | 4530 | * @return array Liste des éléments |
| 4531 | 4531 | */ |
| 4532 | 4532 | function filtre_explode_dist($a, $b) { |
| 4533 | - return explode($b, (string) $a); |
|
| 4533 | + return explode($b, (string) $a); |
|
| 4534 | 4534 | } |
| 4535 | 4535 | |
| 4536 | 4536 | /** |
@@ -4551,7 +4551,7 @@ discard block |
||
| 4551 | 4551 | * @return string Texte |
| 4552 | 4552 | */ |
| 4553 | 4553 | function filtre_implode_dist($a, $b) { |
| 4554 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4554 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4555 | 4555 | } |
| 4556 | 4556 | |
| 4557 | 4557 | /** |
@@ -4560,22 +4560,22 @@ discard block |
||
| 4560 | 4560 | * @return string Code CSS |
| 4561 | 4561 | */ |
| 4562 | 4562 | function bando_images_background() { |
| 4563 | - include_spip('inc/bandeau'); |
|
| 4564 | - // recuperer tous les boutons et leurs images |
|
| 4565 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4563 | + include_spip('inc/bandeau'); |
|
| 4564 | + // recuperer tous les boutons et leurs images |
|
| 4565 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4566 | 4566 | |
| 4567 | - $res = ''; |
|
| 4568 | - foreach ($boutons as $page => $detail) { |
|
| 4569 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4570 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4571 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4572 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4573 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4574 | - } |
|
| 4575 | - } |
|
| 4576 | - } |
|
| 4567 | + $res = ''; |
|
| 4568 | + foreach ($boutons as $page => $detail) { |
|
| 4569 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4570 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4571 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4572 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4573 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4574 | + } |
|
| 4575 | + } |
|
| 4576 | + } |
|
| 4577 | 4577 | |
| 4578 | - return $res; |
|
| 4578 | + return $res; |
|
| 4579 | 4579 | } |
| 4580 | 4580 | |
| 4581 | 4581 | /** |
@@ -4600,27 +4600,27 @@ discard block |
||
| 4600 | 4600 | */ |
| 4601 | 4601 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4602 | 4602 | |
| 4603 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4604 | - $class_form = ''; |
|
| 4605 | - if (strpos($class, 'ajax') !== false) { |
|
| 4606 | - $class_form = 'ajax'; |
|
| 4607 | - $class = str_replace('ajax', '', $class); |
|
| 4608 | - } |
|
| 4609 | - $class_btn = 'submit ' . trim($class); |
|
| 4603 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4604 | + $class_form = ''; |
|
| 4605 | + if (strpos($class, 'ajax') !== false) { |
|
| 4606 | + $class_form = 'ajax'; |
|
| 4607 | + $class = str_replace('ajax', '', $class); |
|
| 4608 | + } |
|
| 4609 | + $class_btn = 'submit ' . trim($class); |
|
| 4610 | 4610 | |
| 4611 | - if ($confirm) { |
|
| 4612 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4613 | - if ($callback) { |
|
| 4614 | - $callback = "$confirm?($callback):false"; |
|
| 4615 | - } else { |
|
| 4616 | - $callback = $confirm; |
|
| 4617 | - } |
|
| 4618 | - } |
|
| 4619 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4620 | - $title = $title ? " title='$title'" : ''; |
|
| 4611 | + if ($confirm) { |
|
| 4612 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4613 | + if ($callback) { |
|
| 4614 | + $callback = "$confirm?($callback):false"; |
|
| 4615 | + } else { |
|
| 4616 | + $callback = $confirm; |
|
| 4617 | + } |
|
| 4618 | + } |
|
| 4619 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4620 | + $title = $title ? " title='$title'" : ''; |
|
| 4621 | 4621 | |
| 4622 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4623 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4622 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4623 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4624 | 4624 | } |
| 4625 | 4625 | |
| 4626 | 4626 | /** |
@@ -4643,101 +4643,101 @@ discard block |
||
| 4643 | 4643 | * @return string |
| 4644 | 4644 | */ |
| 4645 | 4645 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4646 | - static $trouver_table = null; |
|
| 4647 | - static $objets; |
|
| 4648 | - |
|
| 4649 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4650 | - $id_objet = intval($id_objet); |
|
| 4651 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4652 | - return ''; |
|
| 4653 | - } |
|
| 4654 | - |
|
| 4655 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4656 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4657 | - return ''; |
|
| 4658 | - } |
|
| 4659 | - |
|
| 4660 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4661 | - if ($info == 'url') { |
|
| 4662 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4663 | - } |
|
| 4664 | - |
|
| 4665 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4666 | - $demande_titre = ($info === 'titre'); |
|
| 4667 | - $demande_introduction = ($info === 'introduction'); |
|
| 4668 | - |
|
| 4669 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4670 | - if ( |
|
| 4671 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4672 | - or |
|
| 4673 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4674 | - ) { |
|
| 4675 | - if (!$trouver_table) { |
|
| 4676 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4677 | - } |
|
| 4678 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4679 | - if (!$desc) { |
|
| 4680 | - return $objets[$type_objet] = false; |
|
| 4681 | - } |
|
| 4682 | - |
|
| 4683 | - // Si on demande le titre, on le gere en interne |
|
| 4684 | - $champ_titre = ''; |
|
| 4685 | - if ($demande_titre) { |
|
| 4686 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4687 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4688 | - } |
|
| 4689 | - include_spip('base/abstract_sql'); |
|
| 4690 | - include_spip('base/connect_sql'); |
|
| 4691 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4692 | - '*' . $champ_titre, |
|
| 4693 | - $desc['table_sql'], |
|
| 4694 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4695 | - ); |
|
| 4696 | - |
|
| 4697 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4698 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4699 | - } |
|
| 4700 | - |
|
| 4701 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4702 | - // ajouter la longueur au début des params supplémentaires |
|
| 4703 | - if ($demande_introduction) { |
|
| 4704 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4705 | - array_unshift($params, $introduction_longueur); |
|
| 4706 | - } |
|
| 4707 | - |
|
| 4708 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4709 | - if ( |
|
| 4710 | - $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true) |
|
| 4711 | - // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4712 | - or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true) |
|
| 4713 | - ) { |
|
| 4714 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4715 | - } |
|
| 4716 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4717 | - elseif ( |
|
| 4718 | - $generer = charger_fonction("generer_objet_{$info}", '', true) |
|
| 4719 | - // @deprecated 4.1 generer_TRUC_entite |
|
| 4720 | - or $generer = charger_fonction("generer_{$info}_entite", '', true) |
|
| 4721 | - ) { |
|
| 4722 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4723 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4724 | - else { |
|
| 4725 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4726 | - } |
|
| 4727 | - |
|
| 4728 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4729 | - if (!$etoile) { |
|
| 4730 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4731 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4732 | - $info_generee = appliquer_traitement_champ( |
|
| 4733 | - $info_generee, |
|
| 4734 | - $info, |
|
| 4735 | - table_objet($type_objet), |
|
| 4736 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4737 | - ); |
|
| 4738 | - } |
|
| 4739 | - |
|
| 4740 | - return $info_generee; |
|
| 4646 | + static $trouver_table = null; |
|
| 4647 | + static $objets; |
|
| 4648 | + |
|
| 4649 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4650 | + $id_objet = intval($id_objet); |
|
| 4651 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4652 | + return ''; |
|
| 4653 | + } |
|
| 4654 | + |
|
| 4655 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4656 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4657 | + return ''; |
|
| 4658 | + } |
|
| 4659 | + |
|
| 4660 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4661 | + if ($info == 'url') { |
|
| 4662 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4663 | + } |
|
| 4664 | + |
|
| 4665 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4666 | + $demande_titre = ($info === 'titre'); |
|
| 4667 | + $demande_introduction = ($info === 'introduction'); |
|
| 4668 | + |
|
| 4669 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4670 | + if ( |
|
| 4671 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4672 | + or |
|
| 4673 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4674 | + ) { |
|
| 4675 | + if (!$trouver_table) { |
|
| 4676 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4677 | + } |
|
| 4678 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4679 | + if (!$desc) { |
|
| 4680 | + return $objets[$type_objet] = false; |
|
| 4681 | + } |
|
| 4682 | + |
|
| 4683 | + // Si on demande le titre, on le gere en interne |
|
| 4684 | + $champ_titre = ''; |
|
| 4685 | + if ($demande_titre) { |
|
| 4686 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4687 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4688 | + } |
|
| 4689 | + include_spip('base/abstract_sql'); |
|
| 4690 | + include_spip('base/connect_sql'); |
|
| 4691 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4692 | + '*' . $champ_titre, |
|
| 4693 | + $desc['table_sql'], |
|
| 4694 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4695 | + ); |
|
| 4696 | + |
|
| 4697 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4698 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4699 | + } |
|
| 4700 | + |
|
| 4701 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4702 | + // ajouter la longueur au début des params supplémentaires |
|
| 4703 | + if ($demande_introduction) { |
|
| 4704 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4705 | + array_unshift($params, $introduction_longueur); |
|
| 4706 | + } |
|
| 4707 | + |
|
| 4708 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4709 | + if ( |
|
| 4710 | + $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true) |
|
| 4711 | + // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4712 | + or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true) |
|
| 4713 | + ) { |
|
| 4714 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4715 | + } |
|
| 4716 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4717 | + elseif ( |
|
| 4718 | + $generer = charger_fonction("generer_objet_{$info}", '', true) |
|
| 4719 | + // @deprecated 4.1 generer_TRUC_entite |
|
| 4720 | + or $generer = charger_fonction("generer_{$info}_entite", '', true) |
|
| 4721 | + ) { |
|
| 4722 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4723 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4724 | + else { |
|
| 4725 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4726 | + } |
|
| 4727 | + |
|
| 4728 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4729 | + if (!$etoile) { |
|
| 4730 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4731 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4732 | + $info_generee = appliquer_traitement_champ( |
|
| 4733 | + $info_generee, |
|
| 4734 | + $info, |
|
| 4735 | + table_objet($type_objet), |
|
| 4736 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4737 | + ); |
|
| 4738 | + } |
|
| 4739 | + |
|
| 4740 | + return $info_generee; |
|
| 4741 | 4741 | } |
| 4742 | 4742 | |
| 4743 | 4743 | /** |
@@ -4745,7 +4745,7 @@ discard block |
||
| 4745 | 4745 | * @see generer_objet_info |
| 4746 | 4746 | */ |
| 4747 | 4747 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4748 | - return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4748 | + return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4749 | 4749 | } |
| 4750 | 4750 | |
| 4751 | 4751 | /** |
@@ -4778,36 +4778,36 @@ discard block |
||
| 4778 | 4778 | */ |
| 4779 | 4779 | function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string { |
| 4780 | 4780 | |
| 4781 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4782 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4783 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4784 | - if (isset($ligne_sql['chapo'])) { |
|
| 4785 | - $chapo = $ligne_sql['chapo']; |
|
| 4786 | - $texte = strlen($descriptif) ? |
|
| 4787 | - '' : |
|
| 4788 | - "$chapo \n\n $texte"; |
|
| 4789 | - } |
|
| 4781 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4782 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4783 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4784 | + if (isset($ligne_sql['chapo'])) { |
|
| 4785 | + $chapo = $ligne_sql['chapo']; |
|
| 4786 | + $texte = strlen($descriptif) ? |
|
| 4787 | + '' : |
|
| 4788 | + "$chapo \n\n $texte"; |
|
| 4789 | + } |
|
| 4790 | 4790 | |
| 4791 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4792 | - if (!intval($longueur_ou_suite)) { |
|
| 4793 | - $longueur = intval($introduction_longueur ?: 600); |
|
| 4794 | - } else { |
|
| 4795 | - $longueur = intval($longueur_ou_suite); |
|
| 4796 | - } |
|
| 4791 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4792 | + if (!intval($longueur_ou_suite)) { |
|
| 4793 | + $longueur = intval($introduction_longueur ?: 600); |
|
| 4794 | + } else { |
|
| 4795 | + $longueur = intval($longueur_ou_suite); |
|
| 4796 | + } |
|
| 4797 | 4797 | |
| 4798 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4799 | - // Ex : #INTRODUCTION{...} |
|
| 4800 | - if ( |
|
| 4801 | - is_null($suite) |
|
| 4802 | - and !intval($longueur_ou_suite) |
|
| 4803 | - ) { |
|
| 4804 | - $suite = $longueur_ou_suite; |
|
| 4805 | - } |
|
| 4798 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4799 | + // Ex : #INTRODUCTION{...} |
|
| 4800 | + if ( |
|
| 4801 | + is_null($suite) |
|
| 4802 | + and !intval($longueur_ou_suite) |
|
| 4803 | + ) { |
|
| 4804 | + $suite = $longueur_ou_suite; |
|
| 4805 | + } |
|
| 4806 | 4806 | |
| 4807 | - $f = chercher_filtre('introduction'); |
|
| 4808 | - $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4807 | + $f = chercher_filtre('introduction'); |
|
| 4808 | + $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4809 | 4809 | |
| 4810 | - return $introduction; |
|
| 4810 | + return $introduction; |
|
| 4811 | 4811 | } |
| 4812 | 4812 | |
| 4813 | 4813 | /** |
@@ -4815,7 +4815,7 @@ discard block |
||
| 4815 | 4815 | * @see generer_objet_introduction |
| 4816 | 4816 | */ |
| 4817 | 4817 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') { |
| 4818 | - return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4818 | + return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4819 | 4819 | } |
| 4820 | 4820 | |
| 4821 | 4821 | /** |
@@ -4829,49 +4829,49 @@ discard block |
||
| 4829 | 4829 | * @return string |
| 4830 | 4830 | */ |
| 4831 | 4831 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4832 | - if (!$champ) { |
|
| 4833 | - return $texte; |
|
| 4834 | - } |
|
| 4832 | + if (!$champ) { |
|
| 4833 | + return $texte; |
|
| 4834 | + } |
|
| 4835 | 4835 | |
| 4836 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4837 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4838 | - include_fichiers_fonctions(); |
|
| 4836 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4837 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4838 | + include_fichiers_fonctions(); |
|
| 4839 | 4839 | |
| 4840 | - $champ = strtoupper($champ); |
|
| 4841 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4842 | - if (!$traitements or !is_array($traitements)) { |
|
| 4843 | - return $texte; |
|
| 4844 | - } |
|
| 4840 | + $champ = strtoupper($champ); |
|
| 4841 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4842 | + if (!$traitements or !is_array($traitements)) { |
|
| 4843 | + return $texte; |
|
| 4844 | + } |
|
| 4845 | 4845 | |
| 4846 | - $traitement = ''; |
|
| 4847 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4848 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4849 | - $table_objet = table_objet($table_objet); |
|
| 4850 | - if (isset($traitements[$table_objet])) { |
|
| 4851 | - $traitement = $traitements[$table_objet]; |
|
| 4852 | - } |
|
| 4853 | - } |
|
| 4854 | - if (!$traitement and isset($traitements[0])) { |
|
| 4855 | - $traitement = $traitements[0]; |
|
| 4856 | - } |
|
| 4857 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4846 | + $traitement = ''; |
|
| 4847 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4848 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4849 | + $table_objet = table_objet($table_objet); |
|
| 4850 | + if (isset($traitements[$table_objet])) { |
|
| 4851 | + $traitement = $traitements[$table_objet]; |
|
| 4852 | + } |
|
| 4853 | + } |
|
| 4854 | + if (!$traitement and isset($traitements[0])) { |
|
| 4855 | + $traitement = $traitements[0]; |
|
| 4856 | + } |
|
| 4857 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4858 | 4858 | |
| 4859 | - if (!$traitement) { |
|
| 4860 | - return $texte; |
|
| 4861 | - } |
|
| 4859 | + if (!$traitement) { |
|
| 4860 | + return $texte; |
|
| 4861 | + } |
|
| 4862 | 4862 | |
| 4863 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4863 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4864 | 4864 | |
| 4865 | - // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4866 | - if (test_espace_prive()) { |
|
| 4867 | - $env['espace_prive'] = 1; |
|
| 4868 | - } |
|
| 4865 | + // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4866 | + if (test_espace_prive()) { |
|
| 4867 | + $env['espace_prive'] = 1; |
|
| 4868 | + } |
|
| 4869 | 4869 | |
| 4870 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4871 | - $Pile = [0 => $env]; |
|
| 4872 | - eval("\$texte = $traitement;"); |
|
| 4870 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4871 | + $Pile = [0 => $env]; |
|
| 4872 | + eval("\$texte = $traitement;"); |
|
| 4873 | 4873 | |
| 4874 | - return $texte; |
|
| 4874 | + return $texte; |
|
| 4875 | 4875 | } |
| 4876 | 4876 | |
| 4877 | 4877 | |
@@ -4885,21 +4885,21 @@ discard block |
||
| 4885 | 4885 | * @return string |
| 4886 | 4886 | */ |
| 4887 | 4887 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4888 | - include_spip('inc/liens'); |
|
| 4889 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4890 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4891 | - // le raccourcis n'est plus valide |
|
| 4892 | - $titre = typo($titre['titre'] ?? ''); |
|
| 4893 | - // on essaye avec generer_info_entite ? |
|
| 4894 | - if (!strlen($titre) and !$connect) { |
|
| 4895 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4896 | - } |
|
| 4897 | - if (!strlen($titre)) { |
|
| 4898 | - $titre = _T('info_sans_titre'); |
|
| 4899 | - } |
|
| 4900 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4888 | + include_spip('inc/liens'); |
|
| 4889 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4890 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4891 | + // le raccourcis n'est plus valide |
|
| 4892 | + $titre = typo($titre['titre'] ?? ''); |
|
| 4893 | + // on essaye avec generer_info_entite ? |
|
| 4894 | + if (!strlen($titre) and !$connect) { |
|
| 4895 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4896 | + } |
|
| 4897 | + if (!strlen($titre)) { |
|
| 4898 | + $titre = _T('info_sans_titre'); |
|
| 4899 | + } |
|
| 4900 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4901 | 4901 | |
| 4902 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4902 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4903 | 4903 | } |
| 4904 | 4904 | |
| 4905 | 4905 | /** |
@@ -4907,7 +4907,7 @@ discard block |
||
| 4907 | 4907 | * @see generer_objet_lien |
| 4908 | 4908 | */ |
| 4909 | 4909 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 4910 | - return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 4910 | + return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 4911 | 4911 | } |
| 4912 | 4912 | |
| 4913 | 4913 | /** |
@@ -4923,15 +4923,15 @@ discard block |
||
| 4923 | 4923 | * @return string |
| 4924 | 4924 | */ |
| 4925 | 4925 | function wrap($texte, $wrap) { |
| 4926 | - $balises = extraire_balises($wrap); |
|
| 4927 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4928 | - $texte = $wrap . $texte; |
|
| 4929 | - $regs = array_reverse($regs[1]); |
|
| 4930 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4931 | - $texte = $texte . $wrap; |
|
| 4932 | - } |
|
| 4926 | + $balises = extraire_balises($wrap); |
|
| 4927 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4928 | + $texte = $wrap . $texte; |
|
| 4929 | + $regs = array_reverse($regs[1]); |
|
| 4930 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4931 | + $texte = $texte . $wrap; |
|
| 4932 | + } |
|
| 4933 | 4933 | |
| 4934 | - return $texte; |
|
| 4934 | + return $texte; |
|
| 4935 | 4935 | } |
| 4936 | 4936 | |
| 4937 | 4937 | |
@@ -4951,44 +4951,44 @@ discard block |
||
| 4951 | 4951 | * @return array|mixed|string |
| 4952 | 4952 | */ |
| 4953 | 4953 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 4954 | - if (is_string($u)) { |
|
| 4955 | - $u = typo($u); |
|
| 4954 | + if (is_string($u)) { |
|
| 4955 | + $u = typo($u); |
|
| 4956 | 4956 | |
| 4957 | - return $u; |
|
| 4958 | - } |
|
| 4957 | + return $u; |
|
| 4958 | + } |
|
| 4959 | 4959 | |
| 4960 | - // caster $u en array si besoin |
|
| 4961 | - if (is_object($u)) { |
|
| 4962 | - $u = (array)$u; |
|
| 4963 | - } |
|
| 4960 | + // caster $u en array si besoin |
|
| 4961 | + if (is_object($u)) { |
|
| 4962 | + $u = (array)$u; |
|
| 4963 | + } |
|
| 4964 | 4964 | |
| 4965 | - if (is_array($u)) { |
|
| 4966 | - $out = ''; |
|
| 4967 | - // toutes les cles sont numeriques ? |
|
| 4968 | - // et aucun enfant n'est un tableau |
|
| 4969 | - // liste simple separee par des virgules |
|
| 4970 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4971 | - $array_values = array_map('is_array', $u); |
|
| 4972 | - $object_values = array_map('is_object', $u); |
|
| 4973 | - if ( |
|
| 4974 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 4975 | - and !array_sum($array_values) |
|
| 4976 | - and !array_sum($object_values) |
|
| 4977 | - ) { |
|
| 4978 | - return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4979 | - } |
|
| 4965 | + if (is_array($u)) { |
|
| 4966 | + $out = ''; |
|
| 4967 | + // toutes les cles sont numeriques ? |
|
| 4968 | + // et aucun enfant n'est un tableau |
|
| 4969 | + // liste simple separee par des virgules |
|
| 4970 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4971 | + $array_values = array_map('is_array', $u); |
|
| 4972 | + $object_values = array_map('is_object', $u); |
|
| 4973 | + if ( |
|
| 4974 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 4975 | + and !array_sum($array_values) |
|
| 4976 | + and !array_sum($object_values) |
|
| 4977 | + ) { |
|
| 4978 | + return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4979 | + } |
|
| 4980 | 4980 | |
| 4981 | - // sinon on passe a la ligne et on indente |
|
| 4982 | - $i_str = str_pad('', $indent, ' '); |
|
| 4983 | - foreach ($u as $k => $v) { |
|
| 4984 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4985 | - } |
|
| 4981 | + // sinon on passe a la ligne et on indente |
|
| 4982 | + $i_str = str_pad('', $indent, ' '); |
|
| 4983 | + foreach ($u as $k => $v) { |
|
| 4984 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4985 | + } |
|
| 4986 | 4986 | |
| 4987 | - return $out; |
|
| 4988 | - } |
|
| 4987 | + return $out; |
|
| 4988 | + } |
|
| 4989 | 4989 | |
| 4990 | - // on sait pas quoi faire... |
|
| 4991 | - return $u; |
|
| 4990 | + // on sait pas quoi faire... |
|
| 4991 | + return $u; |
|
| 4992 | 4992 | } |
| 4993 | 4993 | |
| 4994 | 4994 | |
@@ -5001,10 +5001,10 @@ discard block |
||
| 5001 | 5001 | * @return string|array |
| 5002 | 5002 | */ |
| 5003 | 5003 | function objet_info($objet, $info) { |
| 5004 | - $table = table_objet_sql($objet); |
|
| 5005 | - $infos = lister_tables_objets_sql($table); |
|
| 5004 | + $table = table_objet_sql($objet); |
|
| 5005 | + $infos = lister_tables_objets_sql($table); |
|
| 5006 | 5006 | |
| 5007 | - return ($infos[$info] ?? ''); |
|
| 5007 | + return ($infos[$info] ?? ''); |
|
| 5008 | 5008 | } |
| 5009 | 5009 | |
| 5010 | 5010 | /** |
@@ -5019,11 +5019,11 @@ discard block |
||
| 5019 | 5019 | * Texte traduit du comptage, tel que '3 articles' |
| 5020 | 5020 | */ |
| 5021 | 5021 | function objet_afficher_nb($nb, $objet) { |
| 5022 | - if (!$nb) { |
|
| 5023 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5024 | - } else { |
|
| 5025 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5026 | - } |
|
| 5022 | + if (!$nb) { |
|
| 5023 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5024 | + } else { |
|
| 5025 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5026 | + } |
|
| 5027 | 5027 | } |
| 5028 | 5028 | |
| 5029 | 5029 | /** |
@@ -5035,11 +5035,11 @@ discard block |
||
| 5035 | 5035 | * @return string |
| 5036 | 5036 | */ |
| 5037 | 5037 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5038 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5039 | - $icone = chemin_image($icone); |
|
| 5040 | - $balise_img = charger_filtre('balise_img'); |
|
| 5038 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5039 | + $icone = chemin_image($icone); |
|
| 5040 | + $balise_img = charger_filtre('balise_img'); |
|
| 5041 | 5041 | |
| 5042 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5042 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5043 | 5043 | } |
| 5044 | 5044 | |
| 5045 | 5045 | /** |
@@ -5060,12 +5060,12 @@ discard block |
||
| 5060 | 5060 | * @return string |
| 5061 | 5061 | */ |
| 5062 | 5062 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5063 | - $chaine = explode(':', $chaine); |
|
| 5064 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5065 | - return $t; |
|
| 5066 | - } |
|
| 5067 | - $chaine = implode(':', $chaine); |
|
| 5068 | - return _T($chaine, $args, $options); |
|
| 5063 | + $chaine = explode(':', $chaine); |
|
| 5064 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5065 | + return $t; |
|
| 5066 | + } |
|
| 5067 | + $chaine = implode(':', $chaine); |
|
| 5068 | + return _T($chaine, $args, $options); |
|
| 5069 | 5069 | } |
| 5070 | 5070 | |
| 5071 | 5071 | /** |
@@ -5079,18 +5079,18 @@ discard block |
||
| 5079 | 5079 | * @return string Code HTML |
| 5080 | 5080 | */ |
| 5081 | 5081 | function insert_head_css_conditionnel($flux) { |
| 5082 | - if ( |
|
| 5083 | - strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5084 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5085 | - ) { |
|
| 5086 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5087 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5088 | - $p = $p1; |
|
| 5089 | - } |
|
| 5090 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5091 | - } |
|
| 5082 | + if ( |
|
| 5083 | + strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5084 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5085 | + ) { |
|
| 5086 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5087 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5088 | + $p = $p1; |
|
| 5089 | + } |
|
| 5090 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5091 | + } |
|
| 5092 | 5092 | |
| 5093 | - return $flux; |
|
| 5093 | + return $flux; |
|
| 5094 | 5094 | } |
| 5095 | 5095 | |
| 5096 | 5096 | /** |
@@ -5113,75 +5113,75 @@ discard block |
||
| 5113 | 5113 | * @return string |
| 5114 | 5114 | */ |
| 5115 | 5115 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 5116 | - if (isset($contexte['format'])) { |
|
| 5117 | - $extension = $contexte['format']; |
|
| 5118 | - unset($contexte['format']); |
|
| 5119 | - } else { |
|
| 5120 | - $extension = 'html'; |
|
| 5121 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5122 | - $extension = $m[1]; |
|
| 5123 | - } |
|
| 5124 | - } |
|
| 5125 | - // recuperer le contenu produit par le squelette |
|
| 5126 | - $options['raw'] = true; |
|
| 5127 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5128 | - |
|
| 5129 | - // calculer le nom de la css |
|
| 5130 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5131 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5132 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5133 | - |
|
| 5134 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5135 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5136 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5137 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5138 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5139 | - } |
|
| 5140 | - else { |
|
| 5141 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5142 | - ksort($contexte); |
|
| 5143 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5144 | - } |
|
| 5145 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5146 | - |
|
| 5147 | - // mettre a jour le fichier si il n'existe pas |
|
| 5148 | - // ou trop ancien |
|
| 5149 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5150 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5151 | - if ( |
|
| 5152 | - !file_exists($filename) |
|
| 5153 | - or !file_exists($filename . '.last') |
|
| 5154 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5155 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5156 | - ) { |
|
| 5157 | - $contenu = $cache['texte']; |
|
| 5158 | - // passer les urls en absolu si c'est une css |
|
| 5159 | - if ($extension == 'css') { |
|
| 5160 | - $contenu = urls_absolues_css( |
|
| 5161 | - $contenu, |
|
| 5162 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5163 | - ); |
|
| 5164 | - } |
|
| 5165 | - |
|
| 5166 | - $comment = ''; |
|
| 5167 | - // ne pas insérer de commentaire sur certains formats |
|
| 5168 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5169 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5170 | - foreach ($contexte as $k => $v) { |
|
| 5171 | - if (is_array($v)) { |
|
| 5172 | - $v = var_export($v, true); |
|
| 5173 | - } |
|
| 5174 | - $comment .= ",$k=$v"; |
|
| 5175 | - } |
|
| 5176 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5177 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5178 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5179 | - } |
|
| 5180 | - // et ecrire le fichier si il change |
|
| 5181 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5182 | - } |
|
| 5183 | - |
|
| 5184 | - return timestamp($filename); |
|
| 5116 | + if (isset($contexte['format'])) { |
|
| 5117 | + $extension = $contexte['format']; |
|
| 5118 | + unset($contexte['format']); |
|
| 5119 | + } else { |
|
| 5120 | + $extension = 'html'; |
|
| 5121 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5122 | + $extension = $m[1]; |
|
| 5123 | + } |
|
| 5124 | + } |
|
| 5125 | + // recuperer le contenu produit par le squelette |
|
| 5126 | + $options['raw'] = true; |
|
| 5127 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5128 | + |
|
| 5129 | + // calculer le nom de la css |
|
| 5130 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5131 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5132 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5133 | + |
|
| 5134 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5135 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5136 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5137 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5138 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5139 | + } |
|
| 5140 | + else { |
|
| 5141 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5142 | + ksort($contexte); |
|
| 5143 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5144 | + } |
|
| 5145 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5146 | + |
|
| 5147 | + // mettre a jour le fichier si il n'existe pas |
|
| 5148 | + // ou trop ancien |
|
| 5149 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5150 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5151 | + if ( |
|
| 5152 | + !file_exists($filename) |
|
| 5153 | + or !file_exists($filename . '.last') |
|
| 5154 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5155 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5156 | + ) { |
|
| 5157 | + $contenu = $cache['texte']; |
|
| 5158 | + // passer les urls en absolu si c'est une css |
|
| 5159 | + if ($extension == 'css') { |
|
| 5160 | + $contenu = urls_absolues_css( |
|
| 5161 | + $contenu, |
|
| 5162 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5163 | + ); |
|
| 5164 | + } |
|
| 5165 | + |
|
| 5166 | + $comment = ''; |
|
| 5167 | + // ne pas insérer de commentaire sur certains formats |
|
| 5168 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5169 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5170 | + foreach ($contexte as $k => $v) { |
|
| 5171 | + if (is_array($v)) { |
|
| 5172 | + $v = var_export($v, true); |
|
| 5173 | + } |
|
| 5174 | + $comment .= ",$k=$v"; |
|
| 5175 | + } |
|
| 5176 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5177 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5178 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5179 | + } |
|
| 5180 | + // et ecrire le fichier si il change |
|
| 5181 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5182 | + } |
|
| 5183 | + |
|
| 5184 | + return timestamp($filename); |
|
| 5185 | 5185 | } |
| 5186 | 5186 | |
| 5187 | 5187 | /** |
@@ -5194,15 +5194,15 @@ discard block |
||
| 5194 | 5194 | * $fichier auquel on a ajouté le timestamp |
| 5195 | 5195 | */ |
| 5196 | 5196 | function timestamp($fichier) { |
| 5197 | - if ( |
|
| 5198 | - !$fichier |
|
| 5199 | - or !file_exists($fichier) |
|
| 5200 | - or !$m = filemtime($fichier) |
|
| 5201 | - ) { |
|
| 5202 | - return $fichier; |
|
| 5203 | - } |
|
| 5197 | + if ( |
|
| 5198 | + !$fichier |
|
| 5199 | + or !file_exists($fichier) |
|
| 5200 | + or !$m = filemtime($fichier) |
|
| 5201 | + ) { |
|
| 5202 | + return $fichier; |
|
| 5203 | + } |
|
| 5204 | 5204 | |
| 5205 | - return "$fichier?$m"; |
|
| 5205 | + return "$fichier?$m"; |
|
| 5206 | 5206 | } |
| 5207 | 5207 | |
| 5208 | 5208 | /** |
@@ -5212,11 +5212,11 @@ discard block |
||
| 5212 | 5212 | * @return string |
| 5213 | 5213 | */ |
| 5214 | 5214 | function supprimer_timestamp($url) { |
| 5215 | - if (strpos($url, '?') === false) { |
|
| 5216 | - return $url; |
|
| 5217 | - } |
|
| 5215 | + if (strpos($url, '?') === false) { |
|
| 5216 | + return $url; |
|
| 5217 | + } |
|
| 5218 | 5218 | |
| 5219 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5219 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5220 | 5220 | } |
| 5221 | 5221 | |
| 5222 | 5222 | /** |
@@ -5231,15 +5231,15 @@ discard block |
||
| 5231 | 5231 | * @return string |
| 5232 | 5232 | */ |
| 5233 | 5233 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5234 | - include_spip('inc/envoyer_mail'); |
|
| 5234 | + include_spip('inc/envoyer_mail'); |
|
| 5235 | 5235 | |
| 5236 | - $titre = nettoyer_titre_email($titre); |
|
| 5237 | - // on est dans un squelette : securiser le retour |
|
| 5238 | - if (strpos($titre, '<') !== false) { |
|
| 5239 | - $titre = interdire_scripts($titre); |
|
| 5240 | - } |
|
| 5236 | + $titre = nettoyer_titre_email($titre); |
|
| 5237 | + // on est dans un squelette : securiser le retour |
|
| 5238 | + if (strpos($titre, '<') !== false) { |
|
| 5239 | + $titre = interdire_scripts($titre); |
|
| 5240 | + } |
|
| 5241 | 5241 | |
| 5242 | - return $titre; |
|
| 5242 | + return $titre; |
|
| 5243 | 5243 | } |
| 5244 | 5244 | |
| 5245 | 5245 | /** |
@@ -5261,27 +5261,27 @@ discard block |
||
| 5261 | 5261 | * @return string |
| 5262 | 5262 | */ |
| 5263 | 5263 | function filtre_chercher_rubrique_dist( |
| 5264 | - $titre, |
|
| 5265 | - $id_objet, |
|
| 5266 | - $id_parent, |
|
| 5267 | - $objet, |
|
| 5268 | - $id_secteur, |
|
| 5269 | - $restreint, |
|
| 5270 | - $actionable = false, |
|
| 5271 | - $retour_sans_cadre = false |
|
| 5264 | + $titre, |
|
| 5265 | + $id_objet, |
|
| 5266 | + $id_parent, |
|
| 5267 | + $objet, |
|
| 5268 | + $id_secteur, |
|
| 5269 | + $restreint, |
|
| 5270 | + $actionable = false, |
|
| 5271 | + $retour_sans_cadre = false |
|
| 5272 | 5272 | ) { |
| 5273 | - include_spip('inc/filtres_ecrire'); |
|
| 5273 | + include_spip('inc/filtres_ecrire'); |
|
| 5274 | 5274 | |
| 5275 | - return chercher_rubrique( |
|
| 5276 | - $titre, |
|
| 5277 | - $id_objet, |
|
| 5278 | - $id_parent, |
|
| 5279 | - $objet, |
|
| 5280 | - $id_secteur, |
|
| 5281 | - $restreint, |
|
| 5282 | - $actionable, |
|
| 5283 | - $retour_sans_cadre |
|
| 5284 | - ); |
|
| 5275 | + return chercher_rubrique( |
|
| 5276 | + $titre, |
|
| 5277 | + $id_objet, |
|
| 5278 | + $id_parent, |
|
| 5279 | + $objet, |
|
| 5280 | + $id_secteur, |
|
| 5281 | + $restreint, |
|
| 5282 | + $actionable, |
|
| 5283 | + $retour_sans_cadre |
|
| 5284 | + ); |
|
| 5285 | 5285 | } |
| 5286 | 5286 | |
| 5287 | 5287 | /** |
@@ -5310,56 +5310,56 @@ discard block |
||
| 5310 | 5310 | * Chaîne vide si l'accès est autorisé |
| 5311 | 5311 | */ |
| 5312 | 5312 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5313 | - if ($ok) { |
|
| 5314 | - return ''; |
|
| 5315 | - } |
|
| 5316 | - |
|
| 5317 | - // Vider tous les tampons |
|
| 5318 | - $level = @ob_get_level(); |
|
| 5319 | - while ($level--) { |
|
| 5320 | - @ob_end_clean(); |
|
| 5321 | - } |
|
| 5322 | - |
|
| 5323 | - include_spip('inc/headers'); |
|
| 5324 | - |
|
| 5325 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5326 | - if ($url) { |
|
| 5327 | - redirige_par_entete($url, '', $statut); |
|
| 5328 | - } |
|
| 5329 | - |
|
| 5330 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5331 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 5332 | - $message = $statut; |
|
| 5333 | - $statut = 0; |
|
| 5334 | - } |
|
| 5335 | - if (!$message) { |
|
| 5336 | - $message = ''; |
|
| 5337 | - } |
|
| 5338 | - $statut = intval($statut); |
|
| 5339 | - |
|
| 5340 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5341 | - if (test_espace_prive()) { |
|
| 5342 | - if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5343 | - $statut = 403; |
|
| 5344 | - } |
|
| 5345 | - http_response_code(403); |
|
| 5346 | - $echec = charger_fonction('403', 'exec'); |
|
| 5347 | - $echec($message); |
|
| 5348 | - } else { |
|
| 5349 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5350 | - if (!$statut) { |
|
| 5351 | - $statut = 404; |
|
| 5352 | - } |
|
| 5353 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5354 | - http_response_code($statut); |
|
| 5355 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5356 | - if ($statut >= 400) { |
|
| 5357 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5358 | - } |
|
| 5359 | - } |
|
| 5360 | - |
|
| 5361 | - |
|
| 5362 | - exit; |
|
| 5313 | + if ($ok) { |
|
| 5314 | + return ''; |
|
| 5315 | + } |
|
| 5316 | + |
|
| 5317 | + // Vider tous les tampons |
|
| 5318 | + $level = @ob_get_level(); |
|
| 5319 | + while ($level--) { |
|
| 5320 | + @ob_end_clean(); |
|
| 5321 | + } |
|
| 5322 | + |
|
| 5323 | + include_spip('inc/headers'); |
|
| 5324 | + |
|
| 5325 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5326 | + if ($url) { |
|
| 5327 | + redirige_par_entete($url, '', $statut); |
|
| 5328 | + } |
|
| 5329 | + |
|
| 5330 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5331 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 5332 | + $message = $statut; |
|
| 5333 | + $statut = 0; |
|
| 5334 | + } |
|
| 5335 | + if (!$message) { |
|
| 5336 | + $message = ''; |
|
| 5337 | + } |
|
| 5338 | + $statut = intval($statut); |
|
| 5339 | + |
|
| 5340 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5341 | + if (test_espace_prive()) { |
|
| 5342 | + if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5343 | + $statut = 403; |
|
| 5344 | + } |
|
| 5345 | + http_response_code(403); |
|
| 5346 | + $echec = charger_fonction('403', 'exec'); |
|
| 5347 | + $echec($message); |
|
| 5348 | + } else { |
|
| 5349 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5350 | + if (!$statut) { |
|
| 5351 | + $statut = 404; |
|
| 5352 | + } |
|
| 5353 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5354 | + http_response_code($statut); |
|
| 5355 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5356 | + if ($statut >= 400) { |
|
| 5357 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5358 | + } |
|
| 5359 | + } |
|
| 5360 | + |
|
| 5361 | + |
|
| 5362 | + exit; |
|
| 5363 | 5363 | } |
| 5364 | 5364 | |
| 5365 | 5365 | /** |
@@ -5370,11 +5370,11 @@ discard block |
||
| 5370 | 5370 | * @return string |
| 5371 | 5371 | */ |
| 5372 | 5372 | function filtre_compacte_dist($source, $format = null) { |
| 5373 | - if (function_exists('minifier')) { |
|
| 5374 | - return minifier($source, $format); |
|
| 5375 | - } |
|
| 5373 | + if (function_exists('minifier')) { |
|
| 5374 | + return minifier($source, $format); |
|
| 5375 | + } |
|
| 5376 | 5376 | |
| 5377 | - return $source; |
|
| 5377 | + return $source; |
|
| 5378 | 5378 | } |
| 5379 | 5379 | |
| 5380 | 5380 | |
@@ -5386,32 +5386,32 @@ discard block |
||
| 5386 | 5386 | * @return string |
| 5387 | 5387 | */ |
| 5388 | 5388 | function spip_affiche_mot_de_passe_masque(?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string { |
| 5389 | - $passe ??= ''; |
|
| 5390 | - $l = strlen($passe); |
|
| 5391 | - |
|
| 5392 | - if ($l <= 8 or !$afficher_partiellement) { |
|
| 5393 | - if (!$l) { |
|
| 5394 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5395 | - } |
|
| 5396 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5397 | - } |
|
| 5398 | - |
|
| 5399 | - if (is_null($portion_pourcent)) { |
|
| 5400 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5401 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5402 | - } |
|
| 5403 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5404 | - } |
|
| 5405 | - if ($portion_pourcent >= 100) { |
|
| 5406 | - return $passe; |
|
| 5407 | - } |
|
| 5408 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5409 | - $e = max($e, 0); |
|
| 5410 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5411 | - if ($e > 0 and strlen($mid) > 8) { |
|
| 5412 | - $mid = '***...***'; |
|
| 5413 | - } |
|
| 5414 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5389 | + $passe ??= ''; |
|
| 5390 | + $l = strlen($passe); |
|
| 5391 | + |
|
| 5392 | + if ($l <= 8 or !$afficher_partiellement) { |
|
| 5393 | + if (!$l) { |
|
| 5394 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5395 | + } |
|
| 5396 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5397 | + } |
|
| 5398 | + |
|
| 5399 | + if (is_null($portion_pourcent)) { |
|
| 5400 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5401 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5402 | + } |
|
| 5403 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5404 | + } |
|
| 5405 | + if ($portion_pourcent >= 100) { |
|
| 5406 | + return $passe; |
|
| 5407 | + } |
|
| 5408 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5409 | + $e = max($e, 0); |
|
| 5410 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5411 | + if ($e > 0 and strlen($mid) > 8) { |
|
| 5412 | + $mid = '***...***'; |
|
| 5413 | + } |
|
| 5414 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5415 | 5415 | } |
| 5416 | 5416 | |
| 5417 | 5417 | |
@@ -5432,64 +5432,64 @@ discard block |
||
| 5432 | 5432 | */ |
| 5433 | 5433 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5434 | 5434 | |
| 5435 | - $original = $texte; |
|
| 5436 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5437 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5438 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5435 | + $original = $texte; |
|
| 5436 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5437 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5438 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5439 | 5439 | |
| 5440 | - if (!function_exists('translitteration')) { |
|
| 5441 | - include_spip('inc/charsets'); |
|
| 5442 | - } |
|
| 5440 | + if (!function_exists('translitteration')) { |
|
| 5441 | + include_spip('inc/charsets'); |
|
| 5442 | + } |
|
| 5443 | 5443 | |
| 5444 | - // pas de balise html |
|
| 5445 | - if (strpos($texte, '<') !== false) { |
|
| 5446 | - $texte = strip_tags($texte); |
|
| 5447 | - } |
|
| 5448 | - if (strpos($texte, '&') !== false) { |
|
| 5449 | - $texte = unicode2charset($texte); |
|
| 5450 | - } |
|
| 5451 | - // On enlève les espaces indésirables |
|
| 5452 | - $texte = trim($texte); |
|
| 5444 | + // pas de balise html |
|
| 5445 | + if (strpos($texte, '<') !== false) { |
|
| 5446 | + $texte = strip_tags($texte); |
|
| 5447 | + } |
|
| 5448 | + if (strpos($texte, '&') !== false) { |
|
| 5449 | + $texte = unicode2charset($texte); |
|
| 5450 | + } |
|
| 5451 | + // On enlève les espaces indésirables |
|
| 5452 | + $texte = trim($texte); |
|
| 5453 | 5453 | |
| 5454 | - // On enlève les accents et cie |
|
| 5455 | - $texte = translitteration($texte); |
|
| 5454 | + // On enlève les accents et cie |
|
| 5455 | + $texte = translitteration($texte); |
|
| 5456 | 5456 | |
| 5457 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5458 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5457 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5458 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5459 | 5459 | |
| 5460 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5461 | - while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5462 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5463 | - } |
|
| 5460 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5461 | + while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5462 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5463 | + } |
|
| 5464 | 5464 | |
| 5465 | - // pas de separateur au debut ni a la fin |
|
| 5466 | - $texte = trim($texte, $separateur); |
|
| 5465 | + // pas de separateur au debut ni a la fin |
|
| 5466 | + $texte = trim($texte, $separateur); |
|
| 5467 | 5467 | |
| 5468 | - // en minuscules |
|
| 5469 | - $texte = strtolower($texte); |
|
| 5468 | + // en minuscules |
|
| 5469 | + $texte = strtolower($texte); |
|
| 5470 | 5470 | |
| 5471 | - switch ($type) { |
|
| 5472 | - case 'class': |
|
| 5473 | - case 'id': |
|
| 5474 | - case 'anchor': |
|
| 5475 | - if (preg_match(',^\d,', $texte)) { |
|
| 5476 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5477 | - } |
|
| 5478 | - } |
|
| 5471 | + switch ($type) { |
|
| 5472 | + case 'class': |
|
| 5473 | + case 'id': |
|
| 5474 | + case 'anchor': |
|
| 5475 | + if (preg_match(',^\d,', $texte)) { |
|
| 5476 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5477 | + } |
|
| 5478 | + } |
|
| 5479 | 5479 | |
| 5480 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5481 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5482 | - } |
|
| 5480 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5481 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5482 | + } |
|
| 5483 | 5483 | |
| 5484 | - if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5485 | - if (preg_match(',^\d,', $texte)) { |
|
| 5486 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5487 | - } |
|
| 5488 | - $texte .= $separateur . md5($original); |
|
| 5489 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5490 | - } |
|
| 5484 | + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5485 | + if (preg_match(',^\d,', $texte)) { |
|
| 5486 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5487 | + } |
|
| 5488 | + $texte .= $separateur . md5($original); |
|
| 5489 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5490 | + } |
|
| 5491 | 5491 | |
| 5492 | - return $texte; |
|
| 5492 | + return $texte; |
|
| 5493 | 5493 | } |
| 5494 | 5494 | |
| 5495 | 5495 | |
@@ -5510,11 +5510,11 @@ discard block |
||
| 5510 | 5510 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5511 | 5511 | */ |
| 5512 | 5512 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5513 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5514 | - if ($ucfirst) { |
|
| 5515 | - $label = spip_ucfirst($label); |
|
| 5516 | - } |
|
| 5517 | - return $label; |
|
| 5513 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5514 | + if ($ucfirst) { |
|
| 5515 | + $label = spip_ucfirst($label); |
|
| 5516 | + } |
|
| 5517 | + return $label; |
|
| 5518 | 5518 | } |
| 5519 | 5519 | |
| 5520 | 5520 | /** |
@@ -5527,8 +5527,8 @@ discard block |
||
| 5527 | 5527 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5528 | 5528 | */ |
| 5529 | 5529 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5530 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5531 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5530 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5531 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5532 | 5532 | } |
| 5533 | 5533 | |
| 5534 | 5534 | |
@@ -5541,19 +5541,19 @@ discard block |
||
| 5541 | 5541 | * @return array |
| 5542 | 5542 | */ |
| 5543 | 5543 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5544 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5545 | - return []; |
|
| 5546 | - } |
|
| 5544 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5545 | + return []; |
|
| 5546 | + } |
|
| 5547 | 5547 | |
| 5548 | - // compatibilite signature inversee |
|
| 5549 | - if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5550 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5551 | - } |
|
| 5548 | + // compatibilite signature inversee |
|
| 5549 | + if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5550 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5551 | + } |
|
| 5552 | 5552 | |
| 5553 | - if (!function_exists($fonction)) { |
|
| 5554 | - include_spip('base/objets'); |
|
| 5555 | - } |
|
| 5556 | - return $fonction($objet, $id_objet); |
|
| 5553 | + if (!function_exists($fonction)) { |
|
| 5554 | + include_spip('base/objets'); |
|
| 5555 | + } |
|
| 5556 | + return $fonction($objet, $id_objet); |
|
| 5557 | 5557 | } |
| 5558 | 5558 | |
| 5559 | 5559 | |
@@ -5568,7 +5568,7 @@ discard block |
||
| 5568 | 5568 | * @return array |
| 5569 | 5569 | */ |
| 5570 | 5570 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5571 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5571 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5572 | 5572 | } |
| 5573 | 5573 | |
| 5574 | 5574 | /** |
@@ -5582,7 +5582,7 @@ discard block |
||
| 5582 | 5582 | * @return array |
| 5583 | 5583 | */ |
| 5584 | 5584 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5585 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5585 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5586 | 5586 | } |
| 5587 | 5587 | |
| 5588 | 5588 | /** |
@@ -5596,7 +5596,7 @@ discard block |
||
| 5596 | 5596 | * @return array |
| 5597 | 5597 | */ |
| 5598 | 5598 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5599 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5599 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5600 | 5600 | } |
| 5601 | 5601 | |
| 5602 | 5602 | /** |
@@ -5610,5 +5610,5 @@ discard block |
||
| 5610 | 5610 | * @return array |
| 5611 | 5611 | */ |
| 5612 | 5612 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5613 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5613 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5614 | 5614 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** Repérer un code ne calculant rien, meme avec commentaire */ |
@@ -58,92 +58,92 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | function argumenter_inclure( |
| 61 | - $params, |
|
| 62 | - $rejet_filtres, |
|
| 63 | - $p, |
|
| 64 | - &$boucles, |
|
| 65 | - $id_boucle, |
|
| 66 | - $echap = true, |
|
| 67 | - $lang = '', |
|
| 68 | - $fond1 = false |
|
| 61 | + $params, |
|
| 62 | + $rejet_filtres, |
|
| 63 | + $p, |
|
| 64 | + &$boucles, |
|
| 65 | + $id_boucle, |
|
| 66 | + $echap = true, |
|
| 67 | + $lang = '', |
|
| 68 | + $fond1 = false |
|
| 69 | 69 | ) { |
| 70 | - $l = []; |
|
| 71 | - $erreur_p_i_i = ''; |
|
| 72 | - if (!is_array($params)) { |
|
| 73 | - return $l; |
|
| 74 | - } |
|
| 75 | - foreach ($params as $k => $couple) { |
|
| 76 | - // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 77 | - $filtre = array_shift($couple); |
|
| 78 | - if ($filtre) { |
|
| 79 | - break; |
|
| 80 | - } |
|
| 81 | - foreach ($couple as $n => $val) { |
|
| 82 | - $var = $val[0]; |
|
| 83 | - if ($var->type != 'texte') { |
|
| 84 | - if ($n or $k or $fond1) { |
|
| 85 | - $erreur_p_i_i = [ |
|
| 86 | - 'zbug_parametres_inclus_incorrects', |
|
| 87 | - ['param' => $var->nom_champ] |
|
| 88 | - ]; |
|
| 89 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 90 | - break; |
|
| 91 | - } else { |
|
| 92 | - $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 93 | - } |
|
| 94 | - } else { |
|
| 95 | - preg_match(',^([^=]*)(=?)(.*)$,m', $var->texte, $m); |
|
| 96 | - $m = array_pad($m, 3, null); |
|
| 97 | - $var = $m[1]; |
|
| 98 | - $auto = false; |
|
| 70 | + $l = []; |
|
| 71 | + $erreur_p_i_i = ''; |
|
| 72 | + if (!is_array($params)) { |
|
| 73 | + return $l; |
|
| 74 | + } |
|
| 75 | + foreach ($params as $k => $couple) { |
|
| 76 | + // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 77 | + $filtre = array_shift($couple); |
|
| 78 | + if ($filtre) { |
|
| 79 | + break; |
|
| 80 | + } |
|
| 81 | + foreach ($couple as $n => $val) { |
|
| 82 | + $var = $val[0]; |
|
| 83 | + if ($var->type != 'texte') { |
|
| 84 | + if ($n or $k or $fond1) { |
|
| 85 | + $erreur_p_i_i = [ |
|
| 86 | + 'zbug_parametres_inclus_incorrects', |
|
| 87 | + ['param' => $var->nom_champ] |
|
| 88 | + ]; |
|
| 89 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 90 | + break; |
|
| 91 | + } else { |
|
| 92 | + $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 93 | + } |
|
| 94 | + } else { |
|
| 95 | + preg_match(',^([^=]*)(=?)(.*)$,m', $var->texte, $m); |
|
| 96 | + $m = array_pad($m, 3, null); |
|
| 97 | + $var = $m[1]; |
|
| 98 | + $auto = false; |
|
| 99 | 99 | ; |
| 100 | - if ($m[2]) { |
|
| 101 | - $v = $m[3]; |
|
| 102 | - if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 103 | - $v = $m[1]; |
|
| 104 | - } |
|
| 105 | - $val[0] = new Texte(); |
|
| 106 | - $val[0]->texte = $v; |
|
| 107 | - } elseif ($k or $n or $fond1) { |
|
| 108 | - $auto = true; |
|
| 109 | - } else { |
|
| 110 | - $var = 1; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if ($var == 'lang') { |
|
| 114 | - $lang = !$auto |
|
| 115 | - ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 116 | - : '$GLOBALS["spip_lang"]'; |
|
| 117 | - } else { |
|
| 118 | - $val = $auto |
|
| 119 | - ? index_pile($id_boucle, $var, $boucles) |
|
| 120 | - : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 121 | - if ($var !== 1) { |
|
| 122 | - $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 123 | - . $val . ($echap ? ") . '" : ' '); |
|
| 124 | - } else { |
|
| 125 | - $val = $echap ? "'.$val.'" : $val; |
|
| 126 | - } |
|
| 127 | - $l[$var] = $val; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - if ($erreur_p_i_i) { |
|
| 133 | - return false; |
|
| 134 | - } |
|
| 135 | - // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 136 | - // la passe, sinon on passe la langue courante au moment du calcul |
|
| 137 | - // sauf si on n'en veut pas |
|
| 138 | - if ($lang === false) { |
|
| 139 | - return $l; |
|
| 140 | - } |
|
| 141 | - if (!$lang) { |
|
| 142 | - $lang = '$GLOBALS["spip_lang"]'; |
|
| 143 | - } |
|
| 144 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 145 | - |
|
| 146 | - return $l; |
|
| 100 | + if ($m[2]) { |
|
| 101 | + $v = $m[3]; |
|
| 102 | + if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 103 | + $v = $m[1]; |
|
| 104 | + } |
|
| 105 | + $val[0] = new Texte(); |
|
| 106 | + $val[0]->texte = $v; |
|
| 107 | + } elseif ($k or $n or $fond1) { |
|
| 108 | + $auto = true; |
|
| 109 | + } else { |
|
| 110 | + $var = 1; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if ($var == 'lang') { |
|
| 114 | + $lang = !$auto |
|
| 115 | + ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 116 | + : '$GLOBALS["spip_lang"]'; |
|
| 117 | + } else { |
|
| 118 | + $val = $auto |
|
| 119 | + ? index_pile($id_boucle, $var, $boucles) |
|
| 120 | + : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 121 | + if ($var !== 1) { |
|
| 122 | + $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 123 | + . $val . ($echap ? ") . '" : ' '); |
|
| 124 | + } else { |
|
| 125 | + $val = $echap ? "'.$val.'" : $val; |
|
| 126 | + } |
|
| 127 | + $l[$var] = $val; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + if ($erreur_p_i_i) { |
|
| 133 | + return false; |
|
| 134 | + } |
|
| 135 | + // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 136 | + // la passe, sinon on passe la langue courante au moment du calcul |
|
| 137 | + // sauf si on n'en veut pas |
|
| 138 | + if ($lang === false) { |
|
| 139 | + return $l; |
|
| 140 | + } |
|
| 141 | + if (!$lang) { |
|
| 142 | + $lang = '$GLOBALS["spip_lang"]'; |
|
| 143 | + } |
|
| 144 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 145 | + |
|
| 146 | + return $l; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -167,84 +167,84 @@ discard block |
||
| 167 | 167 | **/ |
| 168 | 168 | function calculer_inclure($p, &$boucles, $id_boucle) { |
| 169 | 169 | |
| 170 | - $_options = []; |
|
| 171 | - $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | - if (is_string($p->texte)) { |
|
| 173 | - $fichier = $p->texte; |
|
| 174 | - $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 175 | - } else { |
|
| 176 | - $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 177 | - if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 178 | - $fichier = $r[1]; |
|
| 179 | - } else { |
|
| 180 | - $fichier = ''; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - if (!$code or $code === '""' or $code === "''") { |
|
| 184 | - $trace = $p->fonctions; |
|
| 185 | - while ( |
|
| 186 | - is_array($trace) |
|
| 187 | - and $trace = array_filter($trace) |
|
| 188 | - and count($trace) == 1 |
|
| 189 | - ) { |
|
| 190 | - $trace = reset($trace); |
|
| 191 | - } |
|
| 192 | - $erreur_p_i_i = [ |
|
| 193 | - 'zbug_parametres_inclus_incorrects', |
|
| 194 | - ['param' => print_r($trace, true)] |
|
| 195 | - ]; |
|
| 196 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 197 | - |
|
| 198 | - return "''"; |
|
| 199 | - } |
|
| 200 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 201 | - |
|
| 202 | - if (is_array($_contexte)) { |
|
| 203 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 204 | - if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 205 | - unset($_contexte['env']); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // noter les doublons dans l'appel a public.php |
|
| 209 | - if (isset($_contexte['doublons'])) { |
|
| 210 | - $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if ($ajax = isset($_contexte['ajax'])) { |
|
| 214 | - $ajax = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 215 | - unset($_contexte['ajax']); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $_contexte = join(",\n\t", $_contexte); |
|
| 219 | - } else { |
|
| 220 | - return false; |
|
| 221 | - } // j'aurais voulu toucher le fond ... |
|
| 222 | - |
|
| 223 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 224 | - |
|
| 225 | - if ($env) { |
|
| 226 | - $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // s'il y a une extension .php, ce n'est pas un squelette |
|
| 230 | - if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 231 | - $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 232 | - } else { |
|
| 233 | - $_options[] = "\"compil\"=>array($compil)"; |
|
| 234 | - if ($ajax) { |
|
| 235 | - $_options[] = $ajax; |
|
| 236 | - } |
|
| 237 | - $code = " ' . argumenter_squelette($code) . '"; |
|
| 238 | - $code = 'echo ' . sprintf( |
|
| 239 | - CODE_RECUPERER_FOND, |
|
| 240 | - $code, |
|
| 241 | - $contexte, |
|
| 242 | - implode(',', $_options), |
|
| 243 | - "_request(\\'connect\\') ?? \\'\\'" |
|
| 244 | - ) . ';'; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 170 | + $_options = []; |
|
| 171 | + $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | + if (is_string($p->texte)) { |
|
| 173 | + $fichier = $p->texte; |
|
| 174 | + $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 175 | + } else { |
|
| 176 | + $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 177 | + if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 178 | + $fichier = $r[1]; |
|
| 179 | + } else { |
|
| 180 | + $fichier = ''; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + if (!$code or $code === '""' or $code === "''") { |
|
| 184 | + $trace = $p->fonctions; |
|
| 185 | + while ( |
|
| 186 | + is_array($trace) |
|
| 187 | + and $trace = array_filter($trace) |
|
| 188 | + and count($trace) == 1 |
|
| 189 | + ) { |
|
| 190 | + $trace = reset($trace); |
|
| 191 | + } |
|
| 192 | + $erreur_p_i_i = [ |
|
| 193 | + 'zbug_parametres_inclus_incorrects', |
|
| 194 | + ['param' => print_r($trace, true)] |
|
| 195 | + ]; |
|
| 196 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 197 | + |
|
| 198 | + return "''"; |
|
| 199 | + } |
|
| 200 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 201 | + |
|
| 202 | + if (is_array($_contexte)) { |
|
| 203 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 204 | + if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 205 | + unset($_contexte['env']); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // noter les doublons dans l'appel a public.php |
|
| 209 | + if (isset($_contexte['doublons'])) { |
|
| 210 | + $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if ($ajax = isset($_contexte['ajax'])) { |
|
| 214 | + $ajax = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 215 | + unset($_contexte['ajax']); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $_contexte = join(",\n\t", $_contexte); |
|
| 219 | + } else { |
|
| 220 | + return false; |
|
| 221 | + } // j'aurais voulu toucher le fond ... |
|
| 222 | + |
|
| 223 | + $contexte = 'array(' . $_contexte . ')'; |
|
| 224 | + |
|
| 225 | + if ($env) { |
|
| 226 | + $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // s'il y a une extension .php, ce n'est pas un squelette |
|
| 230 | + if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 231 | + $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 232 | + } else { |
|
| 233 | + $_options[] = "\"compil\"=>array($compil)"; |
|
| 234 | + if ($ajax) { |
|
| 235 | + $_options[] = $ajax; |
|
| 236 | + } |
|
| 237 | + $code = " ' . argumenter_squelette($code) . '"; |
|
| 238 | + $code = 'echo ' . sprintf( |
|
| 239 | + CODE_RECUPERER_FOND, |
|
| 240 | + $code, |
|
| 241 | + $contexte, |
|
| 242 | + implode(',', $_options), |
|
| 243 | + "_request(\\'connect\\') ?? \\'\\'" |
|
| 244 | + ) . ';'; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 263 | 263 | */ |
| 264 | 264 | function instituer_boucle(&$boucle, $echapper = true, $ignore_previsu = false) { |
| 265 | - /* |
|
| 265 | + /* |
|
| 266 | 266 | $show['statut'][] = array( |
| 267 | 267 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
| 268 | 268 | 'publie'=>'publie', // valeur ou liste de valeurs, qui definissent l'objet comme publie. |
@@ -286,74 +286,74 @@ discard block |
||
| 286 | 286 | champstatut est alors le champ statut sur la tablen |
| 287 | 287 | dans les jointures, clen peut etre un tableau pour une jointure complexe : array('id_objet','id_article','objet','article') |
| 288 | 288 | */ |
| 289 | - $id_table = $boucle->id_table; |
|
| 290 | - $show = $boucle->show; |
|
| 291 | - if (isset($show['statut']) and $show['statut']) { |
|
| 292 | - foreach ($show['statut'] as $k => $s) { |
|
| 293 | - // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 294 | - $filtrer = true; |
|
| 295 | - if (isset($s['exception'])) { |
|
| 296 | - foreach (is_array($s['exception']) ? $s['exception'] : [$s['exception']] as $m) { |
|
| 297 | - if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 298 | - $filtrer = false; |
|
| 299 | - break; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if ($filtrer) { |
|
| 305 | - if (is_array($s['champ'])) { |
|
| 306 | - $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 307 | - $jointures = []; |
|
| 308 | - // indiquer la description de chaque table dans le tableau de jointures, |
|
| 309 | - // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 310 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 311 | - foreach ($s['champ'] as $j) { |
|
| 312 | - $id = reset($j); |
|
| 313 | - $def = $trouver_table($id); |
|
| 314 | - $jointures[] = ['', [$id, $def], end($j)]; |
|
| 315 | - } |
|
| 316 | - $jointures[0][0] = $id_table; |
|
| 317 | - if (!array_search($id, $boucle->from)) { |
|
| 318 | - include_spip('public/jointures'); |
|
| 319 | - fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 320 | - } |
|
| 321 | - // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 322 | - $id = array_search($id, $boucle->from); |
|
| 323 | - } else { |
|
| 324 | - $id = $id_table; |
|
| 325 | - $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 326 | - } |
|
| 327 | - $mstatut = $id . '.' . $statut; |
|
| 328 | - |
|
| 329 | - $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
|
| 330 | - include_spip('public/quete'); |
|
| 331 | - if ( |
|
| 332 | - isset($s['post_date']) and $s['post_date'] |
|
| 333 | - and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 334 | - ) { |
|
| 335 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | - array_unshift( |
|
| 337 | - $boucle->where, |
|
| 338 | - $echapper ? |
|
| 339 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 340 | - : |
|
| 341 | - quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 342 | - ); |
|
| 343 | - } |
|
| 344 | - array_unshift( |
|
| 345 | - $boucle->where, |
|
| 346 | - $echapper ? |
|
| 347 | - "\nquete_condition_statut('$mstatut'," |
|
| 348 | - . _q($s['previsu']) . ',' |
|
| 349 | - . _q($s['publie']) . ',' |
|
| 350 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 351 | - : |
|
| 352 | - quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 353 | - ); |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - } |
|
| 289 | + $id_table = $boucle->id_table; |
|
| 290 | + $show = $boucle->show; |
|
| 291 | + if (isset($show['statut']) and $show['statut']) { |
|
| 292 | + foreach ($show['statut'] as $k => $s) { |
|
| 293 | + // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 294 | + $filtrer = true; |
|
| 295 | + if (isset($s['exception'])) { |
|
| 296 | + foreach (is_array($s['exception']) ? $s['exception'] : [$s['exception']] as $m) { |
|
| 297 | + if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 298 | + $filtrer = false; |
|
| 299 | + break; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ($filtrer) { |
|
| 305 | + if (is_array($s['champ'])) { |
|
| 306 | + $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 307 | + $jointures = []; |
|
| 308 | + // indiquer la description de chaque table dans le tableau de jointures, |
|
| 309 | + // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 310 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 311 | + foreach ($s['champ'] as $j) { |
|
| 312 | + $id = reset($j); |
|
| 313 | + $def = $trouver_table($id); |
|
| 314 | + $jointures[] = ['', [$id, $def], end($j)]; |
|
| 315 | + } |
|
| 316 | + $jointures[0][0] = $id_table; |
|
| 317 | + if (!array_search($id, $boucle->from)) { |
|
| 318 | + include_spip('public/jointures'); |
|
| 319 | + fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 320 | + } |
|
| 321 | + // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 322 | + $id = array_search($id, $boucle->from); |
|
| 323 | + } else { |
|
| 324 | + $id = $id_table; |
|
| 325 | + $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 326 | + } |
|
| 327 | + $mstatut = $id . '.' . $statut; |
|
| 328 | + |
|
| 329 | + $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
|
| 330 | + include_spip('public/quete'); |
|
| 331 | + if ( |
|
| 332 | + isset($s['post_date']) and $s['post_date'] |
|
| 333 | + and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 334 | + ) { |
|
| 335 | + $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | + array_unshift( |
|
| 337 | + $boucle->where, |
|
| 338 | + $echapper ? |
|
| 339 | + "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 340 | + : |
|
| 341 | + quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 342 | + ); |
|
| 343 | + } |
|
| 344 | + array_unshift( |
|
| 345 | + $boucle->where, |
|
| 346 | + $echapper ? |
|
| 347 | + "\nquete_condition_statut('$mstatut'," |
|
| 348 | + . _q($s['previsu']) . ',' |
|
| 349 | + . _q($s['publie']) . ',' |
|
| 350 | + . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 351 | + : |
|
| 352 | + quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 353 | + ); |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -372,29 +372,29 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | function calculer_boucle($id_boucle, &$boucles) { |
| 374 | 374 | |
| 375 | - $boucle = &$boucles[$id_boucle]; |
|
| 376 | - instituer_boucle($boucle); |
|
| 377 | - $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 378 | - |
|
| 379 | - // en mode debug memoriser les premiers passages dans la boucle, |
|
| 380 | - // mais pas tous, sinon ca pete. |
|
| 381 | - if (_request('var_mode_affiche') != 'resultat') { |
|
| 382 | - $trace = ''; |
|
| 383 | - } else { |
|
| 384 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 385 | - $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 386 | - $trace = " |
|
| 375 | + $boucle = &$boucles[$id_boucle]; |
|
| 376 | + instituer_boucle($boucle); |
|
| 377 | + $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 378 | + |
|
| 379 | + // en mode debug memoriser les premiers passages dans la boucle, |
|
| 380 | + // mais pas tous, sinon ca pete. |
|
| 381 | + if (_request('var_mode_affiche') != 'resultat') { |
|
| 382 | + $trace = ''; |
|
| 383 | + } else { |
|
| 384 | + $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 385 | + $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 386 | + $trace = " |
|
| 387 | 387 | if (empty($_trace)) { |
| 388 | 388 | $_trace = []; |
| 389 | 389 | } |
| 390 | 390 | if (count($_trace) < 3) { |
| 391 | 391 | $_trace" . '[] = $t0; |
| 392 | 392 | }'; |
| 393 | - } |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 396 | - ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 397 | - : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 395 | + return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 396 | + ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 397 | + : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | |
@@ -417,15 +417,15 @@ discard block |
||
| 417 | 417 | * Code PHP compilé de la boucle récursive |
| 418 | 418 | **/ |
| 419 | 419 | function calculer_boucle_rec($id_boucle, &$boucles, $trace) { |
| 420 | - $nom = $boucles[$id_boucle]->param[0]; |
|
| 421 | - |
|
| 422 | - return |
|
| 423 | - // Numrows[$nom] peut ne pas être encore defini |
|
| 424 | - "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 425 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 426 | - . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 427 | - . $trace |
|
| 428 | - . "\n\treturn \$t0;"; |
|
| 420 | + $nom = $boucles[$id_boucle]->param[0]; |
|
| 421 | + |
|
| 422 | + return |
|
| 423 | + // Numrows[$nom] peut ne pas être encore defini |
|
| 424 | + "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 425 | + . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 426 | + . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 427 | + . $trace |
|
| 428 | + . "\n\treturn \$t0;"; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -478,174 +478,174 @@ discard block |
||
| 478 | 478 | **/ |
| 479 | 479 | function calculer_boucle_nonrec($id_boucle, &$boucles, $trace) { |
| 480 | 480 | |
| 481 | - $code_sep = null; |
|
| 482 | - $boucle = &$boucles[$id_boucle]; |
|
| 483 | - $return = $boucle->return; |
|
| 484 | - $type_boucle = $boucle->type_requete; |
|
| 485 | - $primary = $boucle->primary; |
|
| 486 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 487 | - $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 488 | - $corps = ''; |
|
| 489 | - |
|
| 490 | - // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 491 | - // et puis faire un [] plutot qu'un "','." |
|
| 492 | - if ($boucle->doublons) { |
|
| 493 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 494 | - index_pile($id_boucle, $primary, $boucles) |
|
| 495 | - . "; // doublons\n"; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - // La boucle doit-elle selectionner la langue ? |
|
| 499 | - // - par defaut, les boucles suivantes le font |
|
| 500 | - // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 501 | - // - a moins d'une demande explicite via {!lang_select} |
|
| 502 | - if ( |
|
| 503 | - !$constant && $boucle->lang_select != 'non' && |
|
| 504 | - (($boucle->lang_select == 'oui') || |
|
| 505 | - in_array($type_boucle, [ |
|
| 506 | - 'articles', |
|
| 507 | - 'rubriques', |
|
| 508 | - 'hierarchie', |
|
| 509 | - 'breves' |
|
| 510 | - ])) |
|
| 511 | - ) { |
|
| 512 | - // Memoriser la langue avant la boucle et la restituer apres |
|
| 513 | - // afin que le corps de boucle affecte la globale directement |
|
| 514 | - $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 515 | - $fin_lang = "lang_select();\n\t"; |
|
| 516 | - $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 517 | - |
|
| 518 | - $corps .= |
|
| 519 | - "\n\t\tlang_select_public(" |
|
| 520 | - . index_pile($id_boucle, 'lang', $boucles) |
|
| 521 | - . ", '" . $boucle->lang_select . "'" |
|
| 522 | - . (in_array($type_boucle, [ |
|
| 523 | - 'articles', |
|
| 524 | - 'rubriques', |
|
| 525 | - 'hierarchie', |
|
| 526 | - 'breves' |
|
| 527 | - ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 528 | - . ');'; |
|
| 529 | - } else { |
|
| 530 | - $init_lang = ''; |
|
| 531 | - $fin_lang = ''; |
|
| 532 | - $fin_lang_select_public = ''; |
|
| 533 | - // sortir les appels au traducteur (invariants de boucle) |
|
| 534 | - if ( |
|
| 535 | - strpos($return, '?php') === false |
|
| 536 | - and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 537 | - ) { |
|
| 538 | - $i = 1; |
|
| 539 | - foreach ($r[1] as $t) { |
|
| 540 | - $init_lang .= "\n\t\$l$i = $t;"; |
|
| 541 | - $return = str_replace($t, "\$l$i", $return); |
|
| 542 | - $i++; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // gestion optimale des separateurs et des boucles constantes |
|
| 548 | - if (is_countable($boucle->separateur) ? count($boucle->separateur) : 0) { |
|
| 549 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - $corps .= |
|
| 553 | - ((!$boucle->separateur) ? |
|
| 554 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 555 | - (($return === "''") ? '' : |
|
| 556 | - ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 557 | - ("\n\t\t\$t1 " . |
|
| 558 | - ((strpos($return, '$t1.') === 0) ? |
|
| 559 | - ('.=' . substr($return, 4)) : |
|
| 560 | - ('= ' . $return)) . |
|
| 561 | - ";\n\t\t" . |
|
| 562 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 563 | - |
|
| 564 | - // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 565 | - // souhaite invalider ces elements |
|
| 566 | - if (!$constant and $primary) { |
|
| 567 | - include_spip('inc/invalideur'); |
|
| 568 | - $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - // gerer le compteur de boucle |
|
| 572 | - // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 573 | - |
|
| 574 | - if ($boucle->partie or $boucle->cptrows) { |
|
| 575 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 576 | - . $boucle->partie |
|
| 577 | - . $corps; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - // depiler la lang de la boucle si besoin |
|
| 581 | - $corps .= $fin_lang_select_public; |
|
| 582 | - |
|
| 583 | - // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 584 | - |
|
| 585 | - if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 586 | - if (!isset($r[2]) or (!$r[2])) { |
|
| 587 | - if (!$boucle->numrows) { |
|
| 588 | - return "\n\t\$t0 = '';"; |
|
| 589 | - } else { |
|
| 590 | - $corps = ''; |
|
| 591 | - } |
|
| 592 | - } else { |
|
| 593 | - $boucle->numrows = true; |
|
| 594 | - $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 595 | - } |
|
| 596 | - } else { |
|
| 597 | - $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - $count = ''; |
|
| 601 | - if (!$boucle->select) { |
|
| 602 | - if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 603 | - $count = '1'; |
|
| 604 | - } else { |
|
| 605 | - $count = 'count(*)'; |
|
| 606 | - } |
|
| 607 | - $boucles[$id_boucle]->select[] = $count; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - if ($flag_cpt) { |
|
| 611 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 612 | - . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 613 | - } else { |
|
| 614 | - $nums = ''; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - if ($boucle->numrows or $boucle->mode_partie) { |
|
| 618 | - $nums .= "\$Numrows['$id_boucle']['command'] = \$command;\n\t" |
|
| 619 | - . "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 620 | - . $boucle->mode_partie |
|
| 621 | - . "\n\t"; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - // Ne calculer la requete que maintenant |
|
| 625 | - // car ce qui precede appelle index_pile qui influe dessus |
|
| 626 | - |
|
| 627 | - $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 628 | - ? ("\n\t$init = array();") : '') |
|
| 629 | - . calculer_requete_sql($boucles[$id_boucle]); |
|
| 630 | - |
|
| 631 | - $contexte = memoriser_contexte_compil($boucle); |
|
| 632 | - |
|
| 633 | - $a = sprintf( |
|
| 634 | - CODE_CORPS_BOUCLE, |
|
| 635 | - $init, |
|
| 636 | - $boucle->iterateur, |
|
| 637 | - '$command', |
|
| 638 | - $contexte, |
|
| 639 | - $nums, |
|
| 640 | - $init_lang, |
|
| 641 | - $corps, |
|
| 642 | - $fin_lang, |
|
| 643 | - $trace, |
|
| 644 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 645 | - ); |
|
| 481 | + $code_sep = null; |
|
| 482 | + $boucle = &$boucles[$id_boucle]; |
|
| 483 | + $return = $boucle->return; |
|
| 484 | + $type_boucle = $boucle->type_requete; |
|
| 485 | + $primary = $boucle->primary; |
|
| 486 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 487 | + $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 488 | + $corps = ''; |
|
| 489 | + |
|
| 490 | + // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 491 | + // et puis faire un [] plutot qu'un "','." |
|
| 492 | + if ($boucle->doublons) { |
|
| 493 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 494 | + index_pile($id_boucle, $primary, $boucles) |
|
| 495 | + . "; // doublons\n"; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + // La boucle doit-elle selectionner la langue ? |
|
| 499 | + // - par defaut, les boucles suivantes le font |
|
| 500 | + // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 501 | + // - a moins d'une demande explicite via {!lang_select} |
|
| 502 | + if ( |
|
| 503 | + !$constant && $boucle->lang_select != 'non' && |
|
| 504 | + (($boucle->lang_select == 'oui') || |
|
| 505 | + in_array($type_boucle, [ |
|
| 506 | + 'articles', |
|
| 507 | + 'rubriques', |
|
| 508 | + 'hierarchie', |
|
| 509 | + 'breves' |
|
| 510 | + ])) |
|
| 511 | + ) { |
|
| 512 | + // Memoriser la langue avant la boucle et la restituer apres |
|
| 513 | + // afin que le corps de boucle affecte la globale directement |
|
| 514 | + $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 515 | + $fin_lang = "lang_select();\n\t"; |
|
| 516 | + $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 517 | + |
|
| 518 | + $corps .= |
|
| 519 | + "\n\t\tlang_select_public(" |
|
| 520 | + . index_pile($id_boucle, 'lang', $boucles) |
|
| 521 | + . ", '" . $boucle->lang_select . "'" |
|
| 522 | + . (in_array($type_boucle, [ |
|
| 523 | + 'articles', |
|
| 524 | + 'rubriques', |
|
| 525 | + 'hierarchie', |
|
| 526 | + 'breves' |
|
| 527 | + ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 528 | + . ');'; |
|
| 529 | + } else { |
|
| 530 | + $init_lang = ''; |
|
| 531 | + $fin_lang = ''; |
|
| 532 | + $fin_lang_select_public = ''; |
|
| 533 | + // sortir les appels au traducteur (invariants de boucle) |
|
| 534 | + if ( |
|
| 535 | + strpos($return, '?php') === false |
|
| 536 | + and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 537 | + ) { |
|
| 538 | + $i = 1; |
|
| 539 | + foreach ($r[1] as $t) { |
|
| 540 | + $init_lang .= "\n\t\$l$i = $t;"; |
|
| 541 | + $return = str_replace($t, "\$l$i", $return); |
|
| 542 | + $i++; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // gestion optimale des separateurs et des boucles constantes |
|
| 548 | + if (is_countable($boucle->separateur) ? count($boucle->separateur) : 0) { |
|
| 549 | + $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + $corps .= |
|
| 553 | + ((!$boucle->separateur) ? |
|
| 554 | + (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 555 | + (($return === "''") ? '' : |
|
| 556 | + ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 557 | + ("\n\t\t\$t1 " . |
|
| 558 | + ((strpos($return, '$t1.') === 0) ? |
|
| 559 | + ('.=' . substr($return, 4)) : |
|
| 560 | + ('= ' . $return)) . |
|
| 561 | + ";\n\t\t" . |
|
| 562 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 563 | + |
|
| 564 | + // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 565 | + // souhaite invalider ces elements |
|
| 566 | + if (!$constant and $primary) { |
|
| 567 | + include_spip('inc/invalideur'); |
|
| 568 | + $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + // gerer le compteur de boucle |
|
| 572 | + // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 573 | + |
|
| 574 | + if ($boucle->partie or $boucle->cptrows) { |
|
| 575 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 576 | + . $boucle->partie |
|
| 577 | + . $corps; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + // depiler la lang de la boucle si besoin |
|
| 581 | + $corps .= $fin_lang_select_public; |
|
| 582 | + |
|
| 583 | + // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 584 | + |
|
| 585 | + if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 586 | + if (!isset($r[2]) or (!$r[2])) { |
|
| 587 | + if (!$boucle->numrows) { |
|
| 588 | + return "\n\t\$t0 = '';"; |
|
| 589 | + } else { |
|
| 590 | + $corps = ''; |
|
| 591 | + } |
|
| 592 | + } else { |
|
| 593 | + $boucle->numrows = true; |
|
| 594 | + $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 595 | + } |
|
| 596 | + } else { |
|
| 597 | + $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + $count = ''; |
|
| 601 | + if (!$boucle->select) { |
|
| 602 | + if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 603 | + $count = '1'; |
|
| 604 | + } else { |
|
| 605 | + $count = 'count(*)'; |
|
| 606 | + } |
|
| 607 | + $boucles[$id_boucle]->select[] = $count; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + if ($flag_cpt) { |
|
| 611 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 612 | + . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 613 | + } else { |
|
| 614 | + $nums = ''; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + if ($boucle->numrows or $boucle->mode_partie) { |
|
| 618 | + $nums .= "\$Numrows['$id_boucle']['command'] = \$command;\n\t" |
|
| 619 | + . "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 620 | + . $boucle->mode_partie |
|
| 621 | + . "\n\t"; |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + // Ne calculer la requete que maintenant |
|
| 625 | + // car ce qui precede appelle index_pile qui influe dessus |
|
| 626 | + |
|
| 627 | + $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 628 | + ? ("\n\t$init = array();") : '') |
|
| 629 | + . calculer_requete_sql($boucles[$id_boucle]); |
|
| 630 | + |
|
| 631 | + $contexte = memoriser_contexte_compil($boucle); |
|
| 632 | + |
|
| 633 | + $a = sprintf( |
|
| 634 | + CODE_CORPS_BOUCLE, |
|
| 635 | + $init, |
|
| 636 | + $boucle->iterateur, |
|
| 637 | + '$command', |
|
| 638 | + $contexte, |
|
| 639 | + $nums, |
|
| 640 | + $init_lang, |
|
| 641 | + $corps, |
|
| 642 | + $fin_lang, |
|
| 643 | + $trace, |
|
| 644 | + 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 645 | + ); |
|
| 646 | 646 | |
| 647 | 647 | # var_dump($a);exit; |
| 648 | - return $a; |
|
| 648 | + return $a; |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | |
@@ -661,48 +661,48 @@ discard block |
||
| 661 | 661 | * Code PHP compilé définissant les informations de requête |
| 662 | 662 | **/ |
| 663 | 663 | function calculer_requete_sql($boucle) { |
| 664 | - $init = []; |
|
| 665 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 666 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 667 | - # En absence de champ c'est un decompte : |
|
| 668 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 669 | - $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 670 | - $init[] = calculer_dec( |
|
| 671 | - 'groupby', |
|
| 672 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 673 | - ); |
|
| 674 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 675 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 676 | - $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 677 | - $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 678 | - $init[] = calculer_dec( |
|
| 679 | - 'limit', |
|
| 680 | - ( |
|
| 681 | - strpos($boucle->limit, 'intval') === false ? |
|
| 682 | - "'" . ($boucle->limit) . "'" : |
|
| 683 | - $boucle->limit |
|
| 684 | - ) |
|
| 685 | - ); |
|
| 686 | - $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 687 | - $s = $d = ''; |
|
| 688 | - // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 689 | - // ou recalculée à chaque passage (vide) |
|
| 690 | - foreach ($init as $i) { |
|
| 691 | - if (reset($i)) { |
|
| 692 | - $s .= "\n\t\t" . end($i); |
|
| 693 | - } # statique |
|
| 694 | - else { |
|
| 695 | - $d .= "\n\t" . end($i); |
|
| 696 | - } # dynamique |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 700 | - . $boucle->in |
|
| 701 | - . $boucle->hash |
|
| 702 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 703 | - . $s |
|
| 704 | - . "\n\t}" |
|
| 705 | - . $d; |
|
| 664 | + $init = []; |
|
| 665 | + $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 666 | + $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 667 | + # En absence de champ c'est un decompte : |
|
| 668 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 669 | + $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 670 | + $init[] = calculer_dec( |
|
| 671 | + 'groupby', |
|
| 672 | + 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 673 | + ); |
|
| 674 | + $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 675 | + $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 676 | + $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 677 | + $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 678 | + $init[] = calculer_dec( |
|
| 679 | + 'limit', |
|
| 680 | + ( |
|
| 681 | + strpos($boucle->limit, 'intval') === false ? |
|
| 682 | + "'" . ($boucle->limit) . "'" : |
|
| 683 | + $boucle->limit |
|
| 684 | + ) |
|
| 685 | + ); |
|
| 686 | + $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 687 | + $s = $d = ''; |
|
| 688 | + // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 689 | + // ou recalculée à chaque passage (vide) |
|
| 690 | + foreach ($init as $i) { |
|
| 691 | + if (reset($i)) { |
|
| 692 | + $s .= "\n\t\t" . end($i); |
|
| 693 | + } # statique |
|
| 694 | + else { |
|
| 695 | + $d .= "\n\t" . end($i); |
|
| 696 | + } # dynamique |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 700 | + . $boucle->in |
|
| 701 | + . $boucle->hash |
|
| 702 | + . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 703 | + . $s |
|
| 704 | + . "\n\t}" |
|
| 705 | + . $d; |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | /** |
@@ -720,13 +720,13 @@ discard block |
||
| 720 | 720 | * qui peut être utilisé pour la production d'un tableau array() |
| 721 | 721 | **/ |
| 722 | 722 | function memoriser_contexte_compil($p) { |
| 723 | - return join(',', [ |
|
| 724 | - _q($p->descr['sourcefile'] ?? ''), |
|
| 725 | - _q($p->descr['nom'] ?? ''), |
|
| 726 | - _q($p->id_boucle ?? ''), |
|
| 727 | - intval($p->ligne), |
|
| 728 | - '$GLOBALS[\'spip_lang\']' |
|
| 729 | - ]); |
|
| 723 | + return join(',', [ |
|
| 724 | + _q($p->descr['sourcefile'] ?? ''), |
|
| 725 | + _q($p->descr['nom'] ?? ''), |
|
| 726 | + _q($p->id_boucle ?? ''), |
|
| 727 | + intval($p->ligne), |
|
| 728 | + '$GLOBALS[\'spip_lang\']' |
|
| 729 | + ]); |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /** |
@@ -744,20 +744,20 @@ discard block |
||
| 744 | 744 | * Objet Contexte |
| 745 | 745 | **/ |
| 746 | 746 | function reconstruire_contexte_compil($context_compil) { |
| 747 | - if (!is_array($context_compil)) { |
|
| 748 | - return $context_compil; |
|
| 749 | - } |
|
| 750 | - $p = new Contexte(); |
|
| 751 | - $p->descr = [ |
|
| 752 | - 'sourcefile' => $context_compil[0] ?? '', |
|
| 753 | - 'nom' => $context_compil[1] ?? '', |
|
| 754 | - ]; |
|
| 755 | - |
|
| 756 | - $p->id_boucle = $context_compil[2] ?? ''; |
|
| 757 | - $p->ligne = (int)($context_compil[3] ?? 0); |
|
| 758 | - $p->lang = $context_compil[4] ?? ''; |
|
| 759 | - |
|
| 760 | - return $p; |
|
| 747 | + if (!is_array($context_compil)) { |
|
| 748 | + return $context_compil; |
|
| 749 | + } |
|
| 750 | + $p = new Contexte(); |
|
| 751 | + $p->descr = [ |
|
| 752 | + 'sourcefile' => $context_compil[0] ?? '', |
|
| 753 | + 'nom' => $context_compil[1] ?? '', |
|
| 754 | + ]; |
|
| 755 | + |
|
| 756 | + $p->id_boucle = $context_compil[2] ?? ''; |
|
| 757 | + $p->ligne = (int)($context_compil[3] ?? 0); |
|
| 758 | + $p->lang = $context_compil[4] ?? ''; |
|
| 759 | + |
|
| 760 | + return $p; |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -783,12 +783,12 @@ discard block |
||
| 783 | 783 | * - index 1 : Code de l'affectation |
| 784 | 784 | **/ |
| 785 | 785 | function calculer_dec($nom, $val) { |
| 786 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 787 | - // si une variable apparait dans le calcul de la clause |
|
| 788 | - // il faut la re-evaluer a chaque passage |
|
| 789 | - if ( |
|
| 790 | - strpos($val, '$') !== false |
|
| 791 | - /* |
|
| 786 | + $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 787 | + // si une variable apparait dans le calcul de la clause |
|
| 788 | + // il faut la re-evaluer a chaque passage |
|
| 789 | + if ( |
|
| 790 | + strpos($val, '$') !== false |
|
| 791 | + /* |
|
| 792 | 792 | OR strpos($val, 'sql_') !== false |
| 793 | 793 | OR ( |
| 794 | 794 | $test = str_replace(array("array(",'\"',"\'"),array("","",""),$val) // supprimer les array( et les echappements de guillemets |
@@ -796,11 +796,11 @@ discard block |
||
| 796 | 796 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 797 | 797 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 798 | 798 | )*/ |
| 799 | - ) { |
|
| 800 | - $static = ''; |
|
| 801 | - } |
|
| 799 | + ) { |
|
| 800 | + $static = ''; |
|
| 801 | + } |
|
| 802 | 802 | |
| 803 | - return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 803 | + return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /** |
@@ -820,32 +820,32 @@ discard block |
||
| 820 | 820 | * Expression PHP décrivant un texte ou un tableau |
| 821 | 821 | **/ |
| 822 | 822 | function calculer_dump_array($a) { |
| 823 | - if (!is_array($a)) { |
|
| 824 | - return $a; |
|
| 825 | - } |
|
| 826 | - $res = ''; |
|
| 827 | - if ($a and $a[0] == "'?'") { |
|
| 828 | - return ('(' . calculer_dump_array($a[1]) . |
|
| 829 | - ' ? ' . calculer_dump_array($a[2]) . |
|
| 830 | - ' : ' . calculer_dump_array($a[3]) . |
|
| 831 | - ')'); |
|
| 832 | - } else { |
|
| 833 | - foreach ($a as $k => $v) { |
|
| 834 | - $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 835 | - $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 839 | - } |
|
| 823 | + if (!is_array($a)) { |
|
| 824 | + return $a; |
|
| 825 | + } |
|
| 826 | + $res = ''; |
|
| 827 | + if ($a and $a[0] == "'?'") { |
|
| 828 | + return ('(' . calculer_dump_array($a[1]) . |
|
| 829 | + ' ? ' . calculer_dump_array($a[2]) . |
|
| 830 | + ' : ' . calculer_dump_array($a[3]) . |
|
| 831 | + ')'); |
|
| 832 | + } else { |
|
| 833 | + foreach ($a as $k => $v) { |
|
| 834 | + $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 835 | + $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 839 | + } |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | function calculer_dump_join($a) { |
| 843 | - $res = ''; |
|
| 844 | - foreach ($a as $k => $v) { |
|
| 845 | - $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 846 | - } |
|
| 843 | + $res = ''; |
|
| 844 | + foreach ($a as $k => $v) { |
|
| 845 | + $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 846 | + } |
|
| 847 | 847 | |
| 848 | - return 'array(' . substr($res, 2) . ')'; |
|
| 848 | + return 'array(' . substr($res, 2) . ')'; |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | /** |
@@ -857,12 +857,12 @@ discard block |
||
| 857 | 857 | * Code PHP construisant un tableau des alias et noms des tables du FROM |
| 858 | 858 | **/ |
| 859 | 859 | function calculer_from(&$boucle) { |
| 860 | - $res = ''; |
|
| 861 | - foreach ($boucle->from as $k => $v) { |
|
| 862 | - $res .= ",'$k' => '$v'"; |
|
| 863 | - } |
|
| 860 | + $res = ''; |
|
| 861 | + foreach ($boucle->from as $k => $v) { |
|
| 862 | + $res .= ",'$k' => '$v'"; |
|
| 863 | + } |
|
| 864 | 864 | |
| 865 | - return 'array(' . substr($res, 1) . ')'; |
|
| 865 | + return 'array(' . substr($res, 1) . ')'; |
|
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | /** |
@@ -875,30 +875,30 @@ discard block |
||
| 875 | 875 | * Code PHP construisant un tableau des alias et type de jointure du FROM |
| 876 | 876 | **/ |
| 877 | 877 | function calculer_from_type(&$boucle) { |
| 878 | - $res = ''; |
|
| 879 | - foreach ($boucle->from_type as $k => $v) { |
|
| 880 | - $res .= ",'$k' => '$v'"; |
|
| 881 | - } |
|
| 878 | + $res = ''; |
|
| 879 | + foreach ($boucle->from_type as $k => $v) { |
|
| 880 | + $res .= ",'$k' => '$v'"; |
|
| 881 | + } |
|
| 882 | 882 | |
| 883 | - return 'array(' . substr($res, 1) . ')'; |
|
| 883 | + return 'array(' . substr($res, 1) . ')'; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | function calculer_order(&$boucle) { |
| 887 | - if ( |
|
| 888 | - !$order = $boucle->order |
|
| 889 | - and !$order = $boucle->default_order |
|
| 890 | - ) { |
|
| 891 | - $order = []; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - /*if (isset($boucle->modificateur['collate'])){ |
|
| 887 | + if ( |
|
| 888 | + !$order = $boucle->order |
|
| 889 | + and !$order = $boucle->default_order |
|
| 890 | + ) { |
|
| 891 | + $order = []; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + /*if (isset($boucle->modificateur['collate'])){ |
|
| 895 | 895 | $col = "." . $boucle->modificateur['collate']; |
| 896 | 896 | foreach($order as $k=>$o) |
| 897 | 897 | if (strpos($order[$k],'COLLATE')===false) |
| 898 | 898 | $order[$k].= $col; |
| 899 | 899 | }*/ |
| 900 | 900 | |
| 901 | - return join(', ', $order); |
|
| 901 | + return join(', ', $order); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | // Production du code PHP a partir de la sequence livree par le phraseur |
@@ -907,62 +907,62 @@ discard block |
||
| 907 | 907 | // (qui sera argument d'un Return ou la partie droite d'une affectation). |
| 908 | 908 | |
| 909 | 909 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle = '') { |
| 910 | - if (!$tableau) { |
|
| 911 | - return "''"; |
|
| 912 | - } |
|
| 913 | - if (is_string($descr)) { |
|
| 914 | - if (isset($boucles[$descr])) { |
|
| 915 | - $idb = $descr; |
|
| 916 | - $descr = []; |
|
| 917 | - if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 918 | - $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 919 | - } |
|
| 920 | - if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 921 | - $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 922 | - } |
|
| 923 | - } |
|
| 924 | - else { |
|
| 925 | - $descr = []; |
|
| 926 | - } |
|
| 927 | - } |
|
| 928 | - if (!isset($descr['niv'])) { |
|
| 929 | - $descr['niv'] = 0; |
|
| 930 | - } |
|
| 931 | - $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 932 | - if ($codes === false) { |
|
| 933 | - return false; |
|
| 934 | - } |
|
| 935 | - $n = is_countable($codes) ? count($codes) : 0; |
|
| 936 | - if (!$n) { |
|
| 937 | - return "''"; |
|
| 938 | - } |
|
| 939 | - $tab = str_repeat("\t", $descr['niv']); |
|
| 940 | - if (_request('var_mode_affiche') != 'validation') { |
|
| 941 | - if ($n == 1) { |
|
| 942 | - return $codes[0]; |
|
| 943 | - } else { |
|
| 944 | - $res = ''; |
|
| 945 | - foreach ($codes as $code) { |
|
| 946 | - if ( |
|
| 947 | - !preg_match("/^'[^']*'$/", $code) |
|
| 948 | - or substr($res, -1, 1) !== "'" |
|
| 949 | - ) { |
|
| 950 | - $res .= " .\n$tab$code"; |
|
| 951 | - } else { |
|
| 952 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 953 | - } |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 957 | - } |
|
| 958 | - } else { |
|
| 959 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ?: ''); |
|
| 960 | - |
|
| 961 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 962 | - " ,\n$tab", |
|
| 963 | - $codes |
|
| 964 | - ) . ')))'; |
|
| 965 | - } |
|
| 910 | + if (!$tableau) { |
|
| 911 | + return "''"; |
|
| 912 | + } |
|
| 913 | + if (is_string($descr)) { |
|
| 914 | + if (isset($boucles[$descr])) { |
|
| 915 | + $idb = $descr; |
|
| 916 | + $descr = []; |
|
| 917 | + if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 918 | + $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 919 | + } |
|
| 920 | + if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 921 | + $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 922 | + } |
|
| 923 | + } |
|
| 924 | + else { |
|
| 925 | + $descr = []; |
|
| 926 | + } |
|
| 927 | + } |
|
| 928 | + if (!isset($descr['niv'])) { |
|
| 929 | + $descr['niv'] = 0; |
|
| 930 | + } |
|
| 931 | + $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 932 | + if ($codes === false) { |
|
| 933 | + return false; |
|
| 934 | + } |
|
| 935 | + $n = is_countable($codes) ? count($codes) : 0; |
|
| 936 | + if (!$n) { |
|
| 937 | + return "''"; |
|
| 938 | + } |
|
| 939 | + $tab = str_repeat("\t", $descr['niv']); |
|
| 940 | + if (_request('var_mode_affiche') != 'validation') { |
|
| 941 | + if ($n == 1) { |
|
| 942 | + return $codes[0]; |
|
| 943 | + } else { |
|
| 944 | + $res = ''; |
|
| 945 | + foreach ($codes as $code) { |
|
| 946 | + if ( |
|
| 947 | + !preg_match("/^'[^']*'$/", $code) |
|
| 948 | + or substr($res, -1, 1) !== "'" |
|
| 949 | + ) { |
|
| 950 | + $res .= " .\n$tab$code"; |
|
| 951 | + } else { |
|
| 952 | + $res = substr($res, 0, -1) . substr($code, 1); |
|
| 953 | + } |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 957 | + } |
|
| 958 | + } else { |
|
| 959 | + $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ?: ''); |
|
| 960 | + |
|
| 961 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 962 | + " ,\n$tab", |
|
| 963 | + $codes |
|
| 964 | + ) . ')))'; |
|
| 965 | + } |
|
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | |
@@ -981,213 +981,213 @@ discard block |
||
| 981 | 981 | */ |
| 982 | 982 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 983 | 983 | |
| 984 | - $codes = []; |
|
| 985 | - // cas de la boucle recursive |
|
| 986 | - if (is_array($id_boucle)) { |
|
| 987 | - $id_boucle = $id_boucle[0]; |
|
| 988 | - } |
|
| 989 | - $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 990 | - $tab = str_repeat("\t", ++$descr['niv']); |
|
| 991 | - $mode = _request('var_mode_affiche'); |
|
| 992 | - $err_e_c = ''; |
|
| 993 | - // chaque commentaire introduit dans le code doit commencer |
|
| 994 | - // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 995 | - foreach ($tableau as $p) { |
|
| 996 | - switch ($p->type) { |
|
| 997 | - // texte seul |
|
| 998 | - case 'texte': |
|
| 999 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 1000 | - $commentaire = strlen($p->texte) . ' signes'; |
|
| 1001 | - $avant = ''; |
|
| 1002 | - $apres = ''; |
|
| 1003 | - $altern = "''"; |
|
| 1004 | - break; |
|
| 1005 | - |
|
| 1006 | - case 'polyglotte': |
|
| 1007 | - $code = ''; |
|
| 1008 | - foreach ($p->traductions as $k => $v) { |
|
| 1009 | - $code .= ",'" . |
|
| 1010 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1011 | - "' => '" . |
|
| 1012 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 1013 | - "'"; |
|
| 1014 | - } |
|
| 1015 | - $code = 'choisir_traduction(array(' . |
|
| 1016 | - substr($code, 1) . |
|
| 1017 | - '))'; |
|
| 1018 | - $commentaire = '&'; |
|
| 1019 | - $avant = ''; |
|
| 1020 | - $apres = ''; |
|
| 1021 | - $altern = "''"; |
|
| 1022 | - break; |
|
| 1023 | - |
|
| 1024 | - // inclure |
|
| 1025 | - case 'include': |
|
| 1026 | - $p->descr = $descr; |
|
| 1027 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 1028 | - if ($code === false) { |
|
| 1029 | - $err_e_c = true; |
|
| 1030 | - $code = "''"; |
|
| 1031 | - } else { |
|
| 1032 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1033 | - $avant = ''; |
|
| 1034 | - $apres = ''; |
|
| 1035 | - $altern = "''"; |
|
| 1036 | - } |
|
| 1037 | - break; |
|
| 1038 | - |
|
| 1039 | - // boucle |
|
| 1040 | - case TYPE_RECURSIF: |
|
| 1041 | - $nom = $p->id_boucle; |
|
| 1042 | - $newdescr = $descr; |
|
| 1043 | - $newdescr['id_mere'] = $nom; |
|
| 1044 | - $newdescr['niv']++; |
|
| 1045 | - $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1046 | - $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1047 | - $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1048 | - $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1049 | - $newdescr['niv']--; |
|
| 1050 | - $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1051 | - if ( |
|
| 1052 | - $preaff === false |
|
| 1053 | - or $avant === false |
|
| 1054 | - or $apres === false |
|
| 1055 | - or $altern === false |
|
| 1056 | - or $postaff === false |
|
| 1057 | - ) { |
|
| 1058 | - $err_e_c = true; |
|
| 1059 | - $code = "''"; |
|
| 1060 | - } else { |
|
| 1061 | - $code = 'BOUCLE' . |
|
| 1062 | - str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1063 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1064 | - $commentaire = "?$nom"; |
|
| 1065 | - if ( |
|
| 1066 | - !$boucles[$nom]->milieu |
|
| 1067 | - and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1068 | - ) { |
|
| 1069 | - if ($preaff != "''") { |
|
| 1070 | - $code .= "\n. $preaff"; |
|
| 1071 | - } |
|
| 1072 | - if ($altern != "''") { |
|
| 1073 | - $code .= "\n. $altern"; |
|
| 1074 | - } |
|
| 1075 | - if ($postaff != "''") { |
|
| 1076 | - $code .= "\n. $postaff"; |
|
| 1077 | - } |
|
| 1078 | - if ($avant <> "''" or $apres <> "''") { |
|
| 1079 | - spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1080 | - } |
|
| 1081 | - $avant = $apres = $altern = "''"; |
|
| 1082 | - } else { |
|
| 1083 | - if ($preaff != "''") { |
|
| 1084 | - $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1085 | - $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1086 | - } |
|
| 1087 | - if ($postaff != "''") { |
|
| 1088 | - $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1089 | - $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1090 | - } |
|
| 1091 | - if ($altern != "''") { |
|
| 1092 | - $altern = "($altern)"; |
|
| 1093 | - } |
|
| 1094 | - } |
|
| 1095 | - } |
|
| 1096 | - break; |
|
| 1097 | - |
|
| 1098 | - case 'idiome': |
|
| 1099 | - $l = []; |
|
| 1100 | - $code = ''; |
|
| 1101 | - foreach ($p->arg as $k => $v) { |
|
| 1102 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1103 | - if ($k) { |
|
| 1104 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1105 | - } else { |
|
| 1106 | - $code = $_v; |
|
| 1107 | - } |
|
| 1108 | - } |
|
| 1109 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1110 | - if ($p->module) { |
|
| 1111 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1112 | - } elseif ($p->nom_champ) { |
|
| 1113 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1114 | - } else { |
|
| 1115 | - $m = ''; |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - $code = (!$code ? "'$m'" : |
|
| 1119 | - ($m ? "'$m' . $code" : |
|
| 1120 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1121 | - . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1122 | - $code = "_T($code)"; |
|
| 1123 | - if ($p->param) { |
|
| 1124 | - $p->id_boucle = $id_boucle; |
|
| 1125 | - $p->boucles = &$boucles; |
|
| 1126 | - $code = compose_filtres($p, $code); |
|
| 1127 | - } |
|
| 1128 | - $commentaire = ':'; |
|
| 1129 | - $avant = ''; |
|
| 1130 | - $apres = ''; |
|
| 1131 | - $altern = "''"; |
|
| 1132 | - break; |
|
| 1133 | - |
|
| 1134 | - case 'champ': |
|
| 1135 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1136 | - $p->id_boucle = $id_boucle; |
|
| 1137 | - $p->boucles = &$boucles; |
|
| 1138 | - $p->descr = $descr; |
|
| 1139 | - #$p->interdire_scripts = true; |
|
| 1140 | - $p->type_requete = $type; |
|
| 1141 | - |
|
| 1142 | - $code = calculer_champ($p); |
|
| 1143 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1144 | - $avant = calculer_liste( |
|
| 1145 | - $p->avant, |
|
| 1146 | - $descr, |
|
| 1147 | - $boucles, |
|
| 1148 | - $id_boucle |
|
| 1149 | - ); |
|
| 1150 | - $apres = calculer_liste( |
|
| 1151 | - $p->apres, |
|
| 1152 | - $descr, |
|
| 1153 | - $boucles, |
|
| 1154 | - $id_boucle |
|
| 1155 | - ); |
|
| 1156 | - $altern = "''"; |
|
| 1157 | - // Si la valeur est destinee a une comparaison a '' |
|
| 1158 | - // forcer la conversion en une chaine par strval |
|
| 1159 | - // si ca peut etre autre chose qu'une chaine |
|
| 1160 | - if ( |
|
| 1161 | - ($avant != "''" or $apres != "''") |
|
| 1162 | - and $code[0] != "'" |
|
| 984 | + $codes = []; |
|
| 985 | + // cas de la boucle recursive |
|
| 986 | + if (is_array($id_boucle)) { |
|
| 987 | + $id_boucle = $id_boucle[0]; |
|
| 988 | + } |
|
| 989 | + $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 990 | + $tab = str_repeat("\t", ++$descr['niv']); |
|
| 991 | + $mode = _request('var_mode_affiche'); |
|
| 992 | + $err_e_c = ''; |
|
| 993 | + // chaque commentaire introduit dans le code doit commencer |
|
| 994 | + // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 995 | + foreach ($tableau as $p) { |
|
| 996 | + switch ($p->type) { |
|
| 997 | + // texte seul |
|
| 998 | + case 'texte': |
|
| 999 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 1000 | + $commentaire = strlen($p->texte) . ' signes'; |
|
| 1001 | + $avant = ''; |
|
| 1002 | + $apres = ''; |
|
| 1003 | + $altern = "''"; |
|
| 1004 | + break; |
|
| 1005 | + |
|
| 1006 | + case 'polyglotte': |
|
| 1007 | + $code = ''; |
|
| 1008 | + foreach ($p->traductions as $k => $v) { |
|
| 1009 | + $code .= ",'" . |
|
| 1010 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1011 | + "' => '" . |
|
| 1012 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 1013 | + "'"; |
|
| 1014 | + } |
|
| 1015 | + $code = 'choisir_traduction(array(' . |
|
| 1016 | + substr($code, 1) . |
|
| 1017 | + '))'; |
|
| 1018 | + $commentaire = '&'; |
|
| 1019 | + $avant = ''; |
|
| 1020 | + $apres = ''; |
|
| 1021 | + $altern = "''"; |
|
| 1022 | + break; |
|
| 1023 | + |
|
| 1024 | + // inclure |
|
| 1025 | + case 'include': |
|
| 1026 | + $p->descr = $descr; |
|
| 1027 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 1028 | + if ($code === false) { |
|
| 1029 | + $err_e_c = true; |
|
| 1030 | + $code = "''"; |
|
| 1031 | + } else { |
|
| 1032 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1033 | + $avant = ''; |
|
| 1034 | + $apres = ''; |
|
| 1035 | + $altern = "''"; |
|
| 1036 | + } |
|
| 1037 | + break; |
|
| 1038 | + |
|
| 1039 | + // boucle |
|
| 1040 | + case TYPE_RECURSIF: |
|
| 1041 | + $nom = $p->id_boucle; |
|
| 1042 | + $newdescr = $descr; |
|
| 1043 | + $newdescr['id_mere'] = $nom; |
|
| 1044 | + $newdescr['niv']++; |
|
| 1045 | + $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1046 | + $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1047 | + $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1048 | + $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1049 | + $newdescr['niv']--; |
|
| 1050 | + $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1051 | + if ( |
|
| 1052 | + $preaff === false |
|
| 1053 | + or $avant === false |
|
| 1054 | + or $apres === false |
|
| 1055 | + or $altern === false |
|
| 1056 | + or $postaff === false |
|
| 1057 | + ) { |
|
| 1058 | + $err_e_c = true; |
|
| 1059 | + $code = "''"; |
|
| 1060 | + } else { |
|
| 1061 | + $code = 'BOUCLE' . |
|
| 1062 | + str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1063 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1064 | + $commentaire = "?$nom"; |
|
| 1065 | + if ( |
|
| 1066 | + !$boucles[$nom]->milieu |
|
| 1067 | + and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1068 | + ) { |
|
| 1069 | + if ($preaff != "''") { |
|
| 1070 | + $code .= "\n. $preaff"; |
|
| 1071 | + } |
|
| 1072 | + if ($altern != "''") { |
|
| 1073 | + $code .= "\n. $altern"; |
|
| 1074 | + } |
|
| 1075 | + if ($postaff != "''") { |
|
| 1076 | + $code .= "\n. $postaff"; |
|
| 1077 | + } |
|
| 1078 | + if ($avant <> "''" or $apres <> "''") { |
|
| 1079 | + spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1080 | + } |
|
| 1081 | + $avant = $apres = $altern = "''"; |
|
| 1082 | + } else { |
|
| 1083 | + if ($preaff != "''") { |
|
| 1084 | + $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1085 | + $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1086 | + } |
|
| 1087 | + if ($postaff != "''") { |
|
| 1088 | + $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1089 | + $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1090 | + } |
|
| 1091 | + if ($altern != "''") { |
|
| 1092 | + $altern = "($altern)"; |
|
| 1093 | + } |
|
| 1094 | + } |
|
| 1095 | + } |
|
| 1096 | + break; |
|
| 1097 | + |
|
| 1098 | + case 'idiome': |
|
| 1099 | + $l = []; |
|
| 1100 | + $code = ''; |
|
| 1101 | + foreach ($p->arg as $k => $v) { |
|
| 1102 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1103 | + if ($k) { |
|
| 1104 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 1105 | + } else { |
|
| 1106 | + $code = $_v; |
|
| 1107 | + } |
|
| 1108 | + } |
|
| 1109 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1110 | + if ($p->module) { |
|
| 1111 | + $m = $p->module . ':' . $p->nom_champ; |
|
| 1112 | + } elseif ($p->nom_champ) { |
|
| 1113 | + $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1114 | + } else { |
|
| 1115 | + $m = ''; |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + $code = (!$code ? "'$m'" : |
|
| 1119 | + ($m ? "'$m' . $code" : |
|
| 1120 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1121 | + . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1122 | + $code = "_T($code)"; |
|
| 1123 | + if ($p->param) { |
|
| 1124 | + $p->id_boucle = $id_boucle; |
|
| 1125 | + $p->boucles = &$boucles; |
|
| 1126 | + $code = compose_filtres($p, $code); |
|
| 1127 | + } |
|
| 1128 | + $commentaire = ':'; |
|
| 1129 | + $avant = ''; |
|
| 1130 | + $apres = ''; |
|
| 1131 | + $altern = "''"; |
|
| 1132 | + break; |
|
| 1133 | + |
|
| 1134 | + case 'champ': |
|
| 1135 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1136 | + $p->id_boucle = $id_boucle; |
|
| 1137 | + $p->boucles = &$boucles; |
|
| 1138 | + $p->descr = $descr; |
|
| 1139 | + #$p->interdire_scripts = true; |
|
| 1140 | + $p->type_requete = $type; |
|
| 1141 | + |
|
| 1142 | + $code = calculer_champ($p); |
|
| 1143 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1144 | + $avant = calculer_liste( |
|
| 1145 | + $p->avant, |
|
| 1146 | + $descr, |
|
| 1147 | + $boucles, |
|
| 1148 | + $id_boucle |
|
| 1149 | + ); |
|
| 1150 | + $apres = calculer_liste( |
|
| 1151 | + $p->apres, |
|
| 1152 | + $descr, |
|
| 1153 | + $boucles, |
|
| 1154 | + $id_boucle |
|
| 1155 | + ); |
|
| 1156 | + $altern = "''"; |
|
| 1157 | + // Si la valeur est destinee a une comparaison a '' |
|
| 1158 | + // forcer la conversion en une chaine par strval |
|
| 1159 | + // si ca peut etre autre chose qu'une chaine |
|
| 1160 | + if ( |
|
| 1161 | + ($avant != "''" or $apres != "''") |
|
| 1162 | + and $code[0] != "'" |
|
| 1163 | 1163 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 1164 | - and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1165 | - and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1166 | - and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1167 | - ) { |
|
| 1168 | - $code = "strval($code)"; |
|
| 1169 | - } |
|
| 1170 | - break; |
|
| 1171 | - |
|
| 1172 | - default: |
|
| 1173 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1174 | - $code = "''"; |
|
| 1175 | - $p->descr = $descr; |
|
| 1176 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1177 | - erreur_squelette($err_e_c, $p); |
|
| 1178 | - } // switch |
|
| 1179 | - |
|
| 1180 | - if ($code != "''") { |
|
| 1181 | - $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1182 | - $codes[] = (($mode == 'validation') ? |
|
| 1183 | - "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1184 | - : (($mode == 'code') ? |
|
| 1185 | - "\n// $commentaire\n$code" : |
|
| 1186 | - $code)); |
|
| 1187 | - } |
|
| 1188 | - } // foreach |
|
| 1189 | - |
|
| 1190 | - return $err_e_c ? false : $codes; |
|
| 1164 | + and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1165 | + and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1166 | + and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1167 | + ) { |
|
| 1168 | + $code = "strval($code)"; |
|
| 1169 | + } |
|
| 1170 | + break; |
|
| 1171 | + |
|
| 1172 | + default: |
|
| 1173 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1174 | + $code = "''"; |
|
| 1175 | + $p->descr = $descr; |
|
| 1176 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1177 | + erreur_squelette($err_e_c, $p); |
|
| 1178 | + } // switch |
|
| 1179 | + |
|
| 1180 | + if ($code != "''") { |
|
| 1181 | + $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1182 | + $codes[] = (($mode == 'validation') ? |
|
| 1183 | + "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1184 | + : (($mode == 'code') ? |
|
| 1185 | + "\n// $commentaire\n$code" : |
|
| 1186 | + $code)); |
|
| 1187 | + } |
|
| 1188 | + } // foreach |
|
| 1189 | + |
|
| 1190 | + return $err_e_c ? false : $codes; |
|
| 1191 | 1191 | } |
| 1192 | 1192 | |
| 1193 | 1193 | /** |
@@ -1197,13 +1197,13 @@ discard block |
||
| 1197 | 1197 | * @return string |
| 1198 | 1198 | */ |
| 1199 | 1199 | function compile_concatene_parties_codes($partie1, $partie2) { |
| 1200 | - if ($partie1 === "''") { |
|
| 1201 | - return $partie2; |
|
| 1202 | - } |
|
| 1203 | - if ($partie2 === "''") { |
|
| 1204 | - return $partie1; |
|
| 1205 | - } |
|
| 1206 | - return "$partie1\n. $partie2"; |
|
| 1200 | + if ($partie1 === "''") { |
|
| 1201 | + return $partie2; |
|
| 1202 | + } |
|
| 1203 | + if ($partie2 === "''") { |
|
| 1204 | + return $partie1; |
|
| 1205 | + } |
|
| 1206 | + return "$partie1\n. $partie2"; |
|
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | 1209 | |
@@ -1227,56 +1227,56 @@ discard block |
||
| 1227 | 1227 | * @return mixed|string |
| 1228 | 1228 | */ |
| 1229 | 1229 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) { |
| 1230 | - if ($avant === "''") { |
|
| 1231 | - $avant = ''; |
|
| 1232 | - } |
|
| 1233 | - if ($apres === "''") { |
|
| 1234 | - $apres = ''; |
|
| 1235 | - } |
|
| 1236 | - if ($avant or $apres or ($altern !== "''")) { |
|
| 1237 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1238 | - $t = $code; |
|
| 1239 | - $cond = ''; |
|
| 1240 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1241 | - $t = $r[2]; |
|
| 1242 | - $cond = '!' . $r[1]; |
|
| 1243 | - } else { |
|
| 1244 | - if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1245 | - $t = $r[2]; |
|
| 1246 | - $cond = $r[1]; |
|
| 1247 | - } else { |
|
| 1248 | - $t = '$t' . $n; |
|
| 1249 | - $cond = "($t = $code)!==''"; |
|
| 1250 | - } |
|
| 1251 | - } |
|
| 1252 | - |
|
| 1253 | - $res = (!$avant ? '' : "$avant . ") . |
|
| 1254 | - $t . |
|
| 1255 | - (!$apres ? '' : " . $apres"); |
|
| 1256 | - |
|
| 1257 | - if ($res !== $t) { |
|
| 1258 | - $res = "($res)"; |
|
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1262 | - } |
|
| 1263 | - |
|
| 1264 | - return $code; |
|
| 1230 | + if ($avant === "''") { |
|
| 1231 | + $avant = ''; |
|
| 1232 | + } |
|
| 1233 | + if ($apres === "''") { |
|
| 1234 | + $apres = ''; |
|
| 1235 | + } |
|
| 1236 | + if ($avant or $apres or ($altern !== "''")) { |
|
| 1237 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1238 | + $t = $code; |
|
| 1239 | + $cond = ''; |
|
| 1240 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1241 | + $t = $r[2]; |
|
| 1242 | + $cond = '!' . $r[1]; |
|
| 1243 | + } else { |
|
| 1244 | + if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1245 | + $t = $r[2]; |
|
| 1246 | + $cond = $r[1]; |
|
| 1247 | + } else { |
|
| 1248 | + $t = '$t' . $n; |
|
| 1249 | + $cond = "($t = $code)!==''"; |
|
| 1250 | + } |
|
| 1251 | + } |
|
| 1252 | + |
|
| 1253 | + $res = (!$avant ? '' : "$avant . ") . |
|
| 1254 | + $t . |
|
| 1255 | + (!$apres ? '' : " . $apres"); |
|
| 1256 | + |
|
| 1257 | + if ($res !== $t) { |
|
| 1258 | + $res = "($res)"; |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1262 | + } |
|
| 1263 | + |
|
| 1264 | + return $code; |
|
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | 1267 | |
| 1268 | 1268 | function compile_inclure_doublons($lexemes) { |
| 1269 | - foreach ($lexemes as $v) { |
|
| 1270 | - if ($v->type === 'include' and $v->param) { |
|
| 1271 | - foreach ($v->param as $r) { |
|
| 1272 | - if (trim($r[0]) === 'doublons') { |
|
| 1273 | - return true; |
|
| 1274 | - } |
|
| 1275 | - } |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - return false; |
|
| 1269 | + foreach ($lexemes as $v) { |
|
| 1270 | + if ($v->type === 'include' and $v->param) { |
|
| 1271 | + foreach ($v->param as $r) { |
|
| 1272 | + if (trim($r[0]) === 'doublons') { |
|
| 1273 | + return true; |
|
| 1274 | + } |
|
| 1275 | + } |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + return false; |
|
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | // Prend en argument le texte d'un squelette, le nom de son fichier d'origine, |
@@ -1295,354 +1295,354 @@ discard block |
||
| 1295 | 1295 | // En cas d'erreur, elle retournera un tableau des 2 premiers elements seulement |
| 1296 | 1296 | |
| 1297 | 1297 | function public_compiler_dist($squelette, $nom, $gram, $sourcefile, string $connect = '') { |
| 1298 | - // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1299 | - // Bonus : supprime le BOM |
|
| 1300 | - include_spip('inc/charsets'); |
|
| 1301 | - $squelette = transcoder_page($squelette); |
|
| 1302 | - |
|
| 1303 | - // rendre inertes les echappements de #[](){}<> |
|
| 1304 | - $i = 0; |
|
| 1305 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1306 | - $i++; |
|
| 1307 | - } |
|
| 1308 | - $squelette = preg_replace_callback( |
|
| 1309 | - ',\\\\([#[()\]{}<>]),', |
|
| 1310 | - fn($a) => "$inerte-" . ord($a[1]) . '-', |
|
| 1311 | - $squelette, |
|
| 1312 | - -1, |
|
| 1313 | - $esc |
|
| 1314 | - ); |
|
| 1315 | - |
|
| 1316 | - $descr = [ |
|
| 1317 | - 'nom' => $nom, |
|
| 1318 | - 'gram' => $gram, |
|
| 1319 | - 'sourcefile' => $sourcefile, |
|
| 1320 | - 'squelette' => $squelette |
|
| 1321 | - ]; |
|
| 1322 | - |
|
| 1323 | - // Phraser le squelette, selon sa grammaire |
|
| 1324 | - |
|
| 1325 | - $boucles = []; |
|
| 1326 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1327 | - |
|
| 1328 | - $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1329 | - |
|
| 1330 | - $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1331 | - |
|
| 1332 | - // restituer les echappements |
|
| 1333 | - if ($esc) { |
|
| 1334 | - foreach ($boucles as $i => $boucle) { |
|
| 1335 | - $boucles[$i]->return = preg_replace_callback( |
|
| 1336 | - ",$inerte-(\d+)-,", |
|
| 1337 | - fn($a) => chr($a[1]), |
|
| 1338 | - $boucle->return |
|
| 1339 | - ); |
|
| 1340 | - $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1341 | - ",$inerte-(\d+)-,", |
|
| 1342 | - fn($a) => '\\\\' . chr($a[1]), |
|
| 1343 | - $boucle->descr['squelette'] |
|
| 1344 | - ); |
|
| 1345 | - } |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1349 | - if ($debug) { |
|
| 1350 | - include_spip('public/decompiler'); |
|
| 1351 | - foreach ($boucles as $id => $boucle) { |
|
| 1352 | - if ($id) { |
|
| 1353 | - $decomp = "\n/* BOUCLE " . |
|
| 1354 | - $boucle->type_requete . |
|
| 1355 | - ' ' . |
|
| 1356 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1357 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1358 | - " */\n"; |
|
| 1359 | - } else { |
|
| 1360 | - $decomp = ("\n/*\n" . |
|
| 1361 | - str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1362 | - . "\n*/"); |
|
| 1363 | - } |
|
| 1364 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1365 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1366 | - } |
|
| 1367 | - } |
|
| 1368 | - |
|
| 1369 | - return $boucles; |
|
| 1298 | + // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1299 | + // Bonus : supprime le BOM |
|
| 1300 | + include_spip('inc/charsets'); |
|
| 1301 | + $squelette = transcoder_page($squelette); |
|
| 1302 | + |
|
| 1303 | + // rendre inertes les echappements de #[](){}<> |
|
| 1304 | + $i = 0; |
|
| 1305 | + while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1306 | + $i++; |
|
| 1307 | + } |
|
| 1308 | + $squelette = preg_replace_callback( |
|
| 1309 | + ',\\\\([#[()\]{}<>]),', |
|
| 1310 | + fn($a) => "$inerte-" . ord($a[1]) . '-', |
|
| 1311 | + $squelette, |
|
| 1312 | + -1, |
|
| 1313 | + $esc |
|
| 1314 | + ); |
|
| 1315 | + |
|
| 1316 | + $descr = [ |
|
| 1317 | + 'nom' => $nom, |
|
| 1318 | + 'gram' => $gram, |
|
| 1319 | + 'sourcefile' => $sourcefile, |
|
| 1320 | + 'squelette' => $squelette |
|
| 1321 | + ]; |
|
| 1322 | + |
|
| 1323 | + // Phraser le squelette, selon sa grammaire |
|
| 1324 | + |
|
| 1325 | + $boucles = []; |
|
| 1326 | + $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1327 | + |
|
| 1328 | + $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1329 | + |
|
| 1330 | + $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1331 | + |
|
| 1332 | + // restituer les echappements |
|
| 1333 | + if ($esc) { |
|
| 1334 | + foreach ($boucles as $i => $boucle) { |
|
| 1335 | + $boucles[$i]->return = preg_replace_callback( |
|
| 1336 | + ",$inerte-(\d+)-,", |
|
| 1337 | + fn($a) => chr($a[1]), |
|
| 1338 | + $boucle->return |
|
| 1339 | + ); |
|
| 1340 | + $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1341 | + ",$inerte-(\d+)-,", |
|
| 1342 | + fn($a) => '\\\\' . chr($a[1]), |
|
| 1343 | + $boucle->descr['squelette'] |
|
| 1344 | + ); |
|
| 1345 | + } |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1349 | + if ($debug) { |
|
| 1350 | + include_spip('public/decompiler'); |
|
| 1351 | + foreach ($boucles as $id => $boucle) { |
|
| 1352 | + if ($id) { |
|
| 1353 | + $decomp = "\n/* BOUCLE " . |
|
| 1354 | + $boucle->type_requete . |
|
| 1355 | + ' ' . |
|
| 1356 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1357 | + ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1358 | + " */\n"; |
|
| 1359 | + } else { |
|
| 1360 | + $decomp = ("\n/*\n" . |
|
| 1361 | + str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1362 | + . "\n*/"); |
|
| 1363 | + } |
|
| 1364 | + $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1365 | + $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1366 | + } |
|
| 1367 | + } |
|
| 1368 | + |
|
| 1369 | + return $boucles; |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1373 | 1373 | // Autres specifications comme ci-dessus |
| 1374 | 1374 | |
| 1375 | 1375 | function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, string $connect = '') { |
| 1376 | - static $trouver_table; |
|
| 1377 | - spip_timer('calcul_skel'); |
|
| 1378 | - |
|
| 1379 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1380 | - $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1381 | - $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1382 | - |
|
| 1383 | - if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1384 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1385 | - } |
|
| 1386 | - } |
|
| 1387 | - foreach ($boucles as $id => $boucle) { |
|
| 1388 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1389 | - } |
|
| 1390 | - $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1391 | - |
|
| 1392 | - // Demander la description des tables une fois pour toutes |
|
| 1393 | - if (!$trouver_table) { |
|
| 1394 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1395 | - } |
|
| 1396 | - |
|
| 1397 | - // reperer si les doublons sont demandes |
|
| 1398 | - // pour un inclure ou une boucle document |
|
| 1399 | - // c'est utile a la fonction champs_traitements |
|
| 1400 | - foreach ($boucles as $id => $boucle) { |
|
| 1401 | - if (!($type = $boucle->type_requete)) { |
|
| 1402 | - continue; |
|
| 1403 | - } |
|
| 1404 | - if ( |
|
| 1405 | - !$descr['documents'] and ( |
|
| 1406 | - (($type == 'documents') and $boucle->doublons) or |
|
| 1407 | - compile_inclure_doublons($boucle->avant) or |
|
| 1408 | - compile_inclure_doublons($boucle->apres) or |
|
| 1409 | - compile_inclure_doublons($boucle->milieu) or |
|
| 1410 | - compile_inclure_doublons($boucle->altern)) |
|
| 1411 | - ) { |
|
| 1412 | - $descr['documents'] = true; |
|
| 1413 | - } |
|
| 1414 | - if ($type != TYPE_RECURSIF) { |
|
| 1415 | - if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1416 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1420 | - if ( |
|
| 1421 | - $g = charger_fonction( |
|
| 1422 | - preg_replace('/\W/', '_', $boucle->type_requete), |
|
| 1423 | - 'iterateur', |
|
| 1424 | - true |
|
| 1425 | - ) |
|
| 1426 | - ) { |
|
| 1427 | - $boucles[$id] = $g($boucle); |
|
| 1428 | - |
|
| 1429 | - // sinon, en cas de requeteur d'un type predefini, |
|
| 1430 | - // utiliser les informations donnees par le requeteur |
|
| 1431 | - // cas "php:xx" et "data:xx". |
|
| 1432 | - } else { |
|
| 1433 | - if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1434 | - $requeteur($boucles, $boucle, $id); |
|
| 1435 | - |
|
| 1436 | - // utiliser la description des champs transmis |
|
| 1437 | - } else { |
|
| 1438 | - $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1439 | - // si la table n'existe pas avec le connecteur par defaut, |
|
| 1440 | - // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1441 | - // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1442 | - if ( |
|
| 1443 | - !$show |
|
| 1444 | - and $show = $trouver_table($type, strtolower($type)) |
|
| 1445 | - ) { |
|
| 1446 | - $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1447 | - } |
|
| 1448 | - if ($show) { |
|
| 1449 | - $boucles[$id]->show = $show; |
|
| 1450 | - // recopie les infos les plus importantes |
|
| 1451 | - $boucles[$id]->primary = $show['key']['PRIMARY KEY'] ?? ''; |
|
| 1452 | - $boucles[$id]->id_table = $x = preg_replace(',^spip_,', '', $show['id_table']); |
|
| 1453 | - $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1454 | - $boucles[$id]->iterateur = 'SQL'; |
|
| 1455 | - |
|
| 1456 | - if (empty($boucles[$id]->descr)) { |
|
| 1457 | - $boucles[$id]->descr = &$descr; |
|
| 1458 | - } |
|
| 1459 | - if ( |
|
| 1460 | - (!$boucles[$id]->jointures) |
|
| 1461 | - and is_array($show['tables_jointures']) |
|
| 1462 | - and count($x = $show['tables_jointures']) |
|
| 1463 | - ) { |
|
| 1464 | - $boucles[$id]->jointures = $x; |
|
| 1465 | - } |
|
| 1466 | - if ($boucles[$id]->jointures_explicites) { |
|
| 1467 | - $jointures = preg_split('/\s+/', $boucles[$id]->jointures_explicites); |
|
| 1468 | - while ($j = array_pop($jointures)) { |
|
| 1469 | - array_unshift($boucles[$id]->jointures, $j); |
|
| 1470 | - } |
|
| 1471 | - } |
|
| 1472 | - } else { |
|
| 1473 | - // Pas une erreur si la table est optionnelle |
|
| 1474 | - if ($boucles[$id]->table_optionnelle) { |
|
| 1475 | - $boucles[$id]->type_requete = ''; |
|
| 1476 | - } else { |
|
| 1477 | - $boucles[$id]->type_requete = false; |
|
| 1478 | - $boucle = $boucles[$id]; |
|
| 1479 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1480 | - ($boucle->sql_serveur . ':')) . |
|
| 1481 | - $type; |
|
| 1482 | - $msg = [ |
|
| 1483 | - 'zbug_table_inconnue', |
|
| 1484 | - ['table' => $x] |
|
| 1485 | - ]; |
|
| 1486 | - erreur_squelette($msg, $boucle); |
|
| 1487 | - } |
|
| 1488 | - } |
|
| 1489 | - } |
|
| 1490 | - } |
|
| 1491 | - } |
|
| 1492 | - } |
|
| 1493 | - |
|
| 1494 | - // Commencer par reperer les boucles appelees explicitement |
|
| 1495 | - // car elles indexent les arguments de maniere derogatoire |
|
| 1496 | - foreach ($boucles as $id => $boucle) { |
|
| 1497 | - if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1498 | - $boucles[$id]->descr = &$descr; |
|
| 1499 | - $rec = &$boucles[$boucle->param[0]]; |
|
| 1500 | - if (!$rec) { |
|
| 1501 | - $msg = [ |
|
| 1502 | - 'zbug_boucle_recursive_undef', |
|
| 1503 | - ['nom' => $boucle->param[0]] |
|
| 1504 | - ]; |
|
| 1505 | - erreur_squelette($msg, $boucle); |
|
| 1506 | - $boucles[$id]->type_requete = false; |
|
| 1507 | - } else { |
|
| 1508 | - $rec->externe = $id; |
|
| 1509 | - $descr['id_mere'] = $id; |
|
| 1510 | - $boucles[$id]->return = |
|
| 1511 | - calculer_liste( |
|
| 1512 | - [$rec], |
|
| 1513 | - $descr, |
|
| 1514 | - $boucles, |
|
| 1515 | - $boucle->param |
|
| 1516 | - ); |
|
| 1517 | - } |
|
| 1518 | - } |
|
| 1519 | - } |
|
| 1520 | - foreach ($boucles as $id => $boucle) { |
|
| 1521 | - $id = strval($id); // attention au type dans index_pile |
|
| 1522 | - $type = $boucle->type_requete; |
|
| 1523 | - if ($type and $type != TYPE_RECURSIF) { |
|
| 1524 | - $res = ''; |
|
| 1525 | - if ($boucle->param) { |
|
| 1526 | - // retourne un tableau en cas d'erreur |
|
| 1527 | - $res = calculer_criteres($id, $boucles); |
|
| 1528 | - } |
|
| 1529 | - $descr['id_mere'] = $id; |
|
| 1530 | - $boucles[$id]->return = |
|
| 1531 | - calculer_liste( |
|
| 1532 | - $boucle->milieu, |
|
| 1533 | - $descr, |
|
| 1534 | - $boucles, |
|
| 1535 | - $id |
|
| 1536 | - ); |
|
| 1537 | - // Si les criteres se sont mal compiles |
|
| 1538 | - // ne pas tenter d'assembler le code final |
|
| 1539 | - // (mais compiler le corps pour detection d'erreurs) |
|
| 1540 | - if (is_array($res)) { |
|
| 1541 | - $boucles[$id]->type_requete = false; |
|
| 1542 | - } |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - |
|
| 1546 | - // idem pour la racine |
|
| 1547 | - $descr['id_mere'] = ''; |
|
| 1548 | - $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1549 | - |
|
| 1550 | - |
|
| 1551 | - // Calcul du corps de toutes les fonctions PHP, |
|
| 1552 | - // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1553 | - // de'terminables seulement maintenant |
|
| 1554 | - |
|
| 1555 | - foreach ($boucles as $id => $boucle) { |
|
| 1556 | - $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1557 | - if ($boucle->return === false) { |
|
| 1558 | - $corps = false; |
|
| 1559 | - continue; |
|
| 1560 | - } |
|
| 1561 | - // appeler la fonction de definition de la boucle |
|
| 1562 | - |
|
| 1563 | - if ($req = $boucle->type_requete) { |
|
| 1564 | - // boucle personnalisée ? |
|
| 1565 | - $table = strtoupper($boucle->type_requete); |
|
| 1566 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1567 | - if ( |
|
| 1568 | - // fonction de boucle avec serveur & table |
|
| 1569 | - (!$serveur or |
|
| 1570 | - ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1571 | - and (!function_exists($f = $f . '_dist')) |
|
| 1572 | - ) |
|
| 1573 | - ) |
|
| 1574 | - // fonction de boucle avec table |
|
| 1575 | - and (!function_exists($f = 'boucle_' . $table)) |
|
| 1576 | - and (!function_exists($f = $f . '_dist')) |
|
| 1577 | - ) { |
|
| 1578 | - // fonction de boucle standard |
|
| 1579 | - if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1580 | - $f = 'boucle_DEFAUT_dist'; |
|
| 1581 | - } |
|
| 1582 | - } |
|
| 1583 | - |
|
| 1584 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1585 | - "static \$connect;\n\t" . |
|
| 1586 | - "\$command['connect'] = \$connect = " . |
|
| 1587 | - _q($boucle->sql_serveur) . |
|
| 1588 | - ';' . |
|
| 1589 | - $f($id, $boucles); |
|
| 1590 | - } else { |
|
| 1591 | - $req = ("\n\treturn '';"); |
|
| 1592 | - } |
|
| 1593 | - |
|
| 1594 | - $boucles[$id]->return = |
|
| 1595 | - "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1596 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1597 | - $req . |
|
| 1598 | - "\n}\n"; |
|
| 1599 | - } |
|
| 1600 | - |
|
| 1601 | - // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1602 | - // retourner False, sinon inserer leur decompilation |
|
| 1603 | - if (is_bool($corps)) { |
|
| 1604 | - return false; |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1376 | + static $trouver_table; |
|
| 1377 | + spip_timer('calcul_skel'); |
|
| 1378 | + |
|
| 1379 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1380 | + $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1381 | + $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1382 | + |
|
| 1383 | + if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1384 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1385 | + } |
|
| 1386 | + } |
|
| 1387 | + foreach ($boucles as $id => $boucle) { |
|
| 1388 | + $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1389 | + } |
|
| 1390 | + $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1391 | + |
|
| 1392 | + // Demander la description des tables une fois pour toutes |
|
| 1393 | + if (!$trouver_table) { |
|
| 1394 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + // reperer si les doublons sont demandes |
|
| 1398 | + // pour un inclure ou une boucle document |
|
| 1399 | + // c'est utile a la fonction champs_traitements |
|
| 1400 | + foreach ($boucles as $id => $boucle) { |
|
| 1401 | + if (!($type = $boucle->type_requete)) { |
|
| 1402 | + continue; |
|
| 1403 | + } |
|
| 1404 | + if ( |
|
| 1405 | + !$descr['documents'] and ( |
|
| 1406 | + (($type == 'documents') and $boucle->doublons) or |
|
| 1407 | + compile_inclure_doublons($boucle->avant) or |
|
| 1408 | + compile_inclure_doublons($boucle->apres) or |
|
| 1409 | + compile_inclure_doublons($boucle->milieu) or |
|
| 1410 | + compile_inclure_doublons($boucle->altern)) |
|
| 1411 | + ) { |
|
| 1412 | + $descr['documents'] = true; |
|
| 1413 | + } |
|
| 1414 | + if ($type != TYPE_RECURSIF) { |
|
| 1415 | + if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1416 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1420 | + if ( |
|
| 1421 | + $g = charger_fonction( |
|
| 1422 | + preg_replace('/\W/', '_', $boucle->type_requete), |
|
| 1423 | + 'iterateur', |
|
| 1424 | + true |
|
| 1425 | + ) |
|
| 1426 | + ) { |
|
| 1427 | + $boucles[$id] = $g($boucle); |
|
| 1428 | + |
|
| 1429 | + // sinon, en cas de requeteur d'un type predefini, |
|
| 1430 | + // utiliser les informations donnees par le requeteur |
|
| 1431 | + // cas "php:xx" et "data:xx". |
|
| 1432 | + } else { |
|
| 1433 | + if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1434 | + $requeteur($boucles, $boucle, $id); |
|
| 1435 | + |
|
| 1436 | + // utiliser la description des champs transmis |
|
| 1437 | + } else { |
|
| 1438 | + $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1439 | + // si la table n'existe pas avec le connecteur par defaut, |
|
| 1440 | + // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1441 | + // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1442 | + if ( |
|
| 1443 | + !$show |
|
| 1444 | + and $show = $trouver_table($type, strtolower($type)) |
|
| 1445 | + ) { |
|
| 1446 | + $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1447 | + } |
|
| 1448 | + if ($show) { |
|
| 1449 | + $boucles[$id]->show = $show; |
|
| 1450 | + // recopie les infos les plus importantes |
|
| 1451 | + $boucles[$id]->primary = $show['key']['PRIMARY KEY'] ?? ''; |
|
| 1452 | + $boucles[$id]->id_table = $x = preg_replace(',^spip_,', '', $show['id_table']); |
|
| 1453 | + $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1454 | + $boucles[$id]->iterateur = 'SQL'; |
|
| 1455 | + |
|
| 1456 | + if (empty($boucles[$id]->descr)) { |
|
| 1457 | + $boucles[$id]->descr = &$descr; |
|
| 1458 | + } |
|
| 1459 | + if ( |
|
| 1460 | + (!$boucles[$id]->jointures) |
|
| 1461 | + and is_array($show['tables_jointures']) |
|
| 1462 | + and count($x = $show['tables_jointures']) |
|
| 1463 | + ) { |
|
| 1464 | + $boucles[$id]->jointures = $x; |
|
| 1465 | + } |
|
| 1466 | + if ($boucles[$id]->jointures_explicites) { |
|
| 1467 | + $jointures = preg_split('/\s+/', $boucles[$id]->jointures_explicites); |
|
| 1468 | + while ($j = array_pop($jointures)) { |
|
| 1469 | + array_unshift($boucles[$id]->jointures, $j); |
|
| 1470 | + } |
|
| 1471 | + } |
|
| 1472 | + } else { |
|
| 1473 | + // Pas une erreur si la table est optionnelle |
|
| 1474 | + if ($boucles[$id]->table_optionnelle) { |
|
| 1475 | + $boucles[$id]->type_requete = ''; |
|
| 1476 | + } else { |
|
| 1477 | + $boucles[$id]->type_requete = false; |
|
| 1478 | + $boucle = $boucles[$id]; |
|
| 1479 | + $x = (!$boucle->sql_serveur ? '' : |
|
| 1480 | + ($boucle->sql_serveur . ':')) . |
|
| 1481 | + $type; |
|
| 1482 | + $msg = [ |
|
| 1483 | + 'zbug_table_inconnue', |
|
| 1484 | + ['table' => $x] |
|
| 1485 | + ]; |
|
| 1486 | + erreur_squelette($msg, $boucle); |
|
| 1487 | + } |
|
| 1488 | + } |
|
| 1489 | + } |
|
| 1490 | + } |
|
| 1491 | + } |
|
| 1492 | + } |
|
| 1493 | + |
|
| 1494 | + // Commencer par reperer les boucles appelees explicitement |
|
| 1495 | + // car elles indexent les arguments de maniere derogatoire |
|
| 1496 | + foreach ($boucles as $id => $boucle) { |
|
| 1497 | + if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1498 | + $boucles[$id]->descr = &$descr; |
|
| 1499 | + $rec = &$boucles[$boucle->param[0]]; |
|
| 1500 | + if (!$rec) { |
|
| 1501 | + $msg = [ |
|
| 1502 | + 'zbug_boucle_recursive_undef', |
|
| 1503 | + ['nom' => $boucle->param[0]] |
|
| 1504 | + ]; |
|
| 1505 | + erreur_squelette($msg, $boucle); |
|
| 1506 | + $boucles[$id]->type_requete = false; |
|
| 1507 | + } else { |
|
| 1508 | + $rec->externe = $id; |
|
| 1509 | + $descr['id_mere'] = $id; |
|
| 1510 | + $boucles[$id]->return = |
|
| 1511 | + calculer_liste( |
|
| 1512 | + [$rec], |
|
| 1513 | + $descr, |
|
| 1514 | + $boucles, |
|
| 1515 | + $boucle->param |
|
| 1516 | + ); |
|
| 1517 | + } |
|
| 1518 | + } |
|
| 1519 | + } |
|
| 1520 | + foreach ($boucles as $id => $boucle) { |
|
| 1521 | + $id = strval($id); // attention au type dans index_pile |
|
| 1522 | + $type = $boucle->type_requete; |
|
| 1523 | + if ($type and $type != TYPE_RECURSIF) { |
|
| 1524 | + $res = ''; |
|
| 1525 | + if ($boucle->param) { |
|
| 1526 | + // retourne un tableau en cas d'erreur |
|
| 1527 | + $res = calculer_criteres($id, $boucles); |
|
| 1528 | + } |
|
| 1529 | + $descr['id_mere'] = $id; |
|
| 1530 | + $boucles[$id]->return = |
|
| 1531 | + calculer_liste( |
|
| 1532 | + $boucle->milieu, |
|
| 1533 | + $descr, |
|
| 1534 | + $boucles, |
|
| 1535 | + $id |
|
| 1536 | + ); |
|
| 1537 | + // Si les criteres se sont mal compiles |
|
| 1538 | + // ne pas tenter d'assembler le code final |
|
| 1539 | + // (mais compiler le corps pour detection d'erreurs) |
|
| 1540 | + if (is_array($res)) { |
|
| 1541 | + $boucles[$id]->type_requete = false; |
|
| 1542 | + } |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + // idem pour la racine |
|
| 1547 | + $descr['id_mere'] = ''; |
|
| 1548 | + $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1549 | + |
|
| 1550 | + |
|
| 1551 | + // Calcul du corps de toutes les fonctions PHP, |
|
| 1552 | + // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1553 | + // de'terminables seulement maintenant |
|
| 1554 | + |
|
| 1555 | + foreach ($boucles as $id => $boucle) { |
|
| 1556 | + $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1557 | + if ($boucle->return === false) { |
|
| 1558 | + $corps = false; |
|
| 1559 | + continue; |
|
| 1560 | + } |
|
| 1561 | + // appeler la fonction de definition de la boucle |
|
| 1562 | + |
|
| 1563 | + if ($req = $boucle->type_requete) { |
|
| 1564 | + // boucle personnalisée ? |
|
| 1565 | + $table = strtoupper($boucle->type_requete); |
|
| 1566 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1567 | + if ( |
|
| 1568 | + // fonction de boucle avec serveur & table |
|
| 1569 | + (!$serveur or |
|
| 1570 | + ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1571 | + and (!function_exists($f = $f . '_dist')) |
|
| 1572 | + ) |
|
| 1573 | + ) |
|
| 1574 | + // fonction de boucle avec table |
|
| 1575 | + and (!function_exists($f = 'boucle_' . $table)) |
|
| 1576 | + and (!function_exists($f = $f . '_dist')) |
|
| 1577 | + ) { |
|
| 1578 | + // fonction de boucle standard |
|
| 1579 | + if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1580 | + $f = 'boucle_DEFAUT_dist'; |
|
| 1581 | + } |
|
| 1582 | + } |
|
| 1583 | + |
|
| 1584 | + $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1585 | + "static \$connect;\n\t" . |
|
| 1586 | + "\$command['connect'] = \$connect = " . |
|
| 1587 | + _q($boucle->sql_serveur) . |
|
| 1588 | + ';' . |
|
| 1589 | + $f($id, $boucles); |
|
| 1590 | + } else { |
|
| 1591 | + $req = ("\n\treturn '';"); |
|
| 1592 | + } |
|
| 1593 | + |
|
| 1594 | + $boucles[$id]->return = |
|
| 1595 | + "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1596 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1597 | + $req . |
|
| 1598 | + "\n}\n"; |
|
| 1599 | + } |
|
| 1600 | + |
|
| 1601 | + // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1602 | + // retourner False, sinon inserer leur decompilation |
|
| 1603 | + if (is_bool($corps)) { |
|
| 1604 | + return false; |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1608 | 1608 | ' |
| 1609 | - // reporter de maniere securisee les doublons inclus |
|
| 1610 | - . ' |
|
| 1609 | + // reporter de maniere securisee les doublons inclus |
|
| 1610 | + . ' |
|
| 1611 | 1611 | if (isset($Pile[0]["doublons"]) AND is_array($Pile[0]["doublons"])) |
| 1612 | 1612 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1613 | 1613 | |
| 1614 | 1614 | $connect = ' . |
| 1615 | - _q($connect) . '; |
|
| 1615 | + _q($connect) . '; |
|
| 1616 | 1616 | $page = ' . |
| 1617 | - // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1618 | - // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1619 | - // avant de referencer $Cache |
|
| 1620 | - $corps . '; |
|
| 1617 | + // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1618 | + // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1619 | + // avant de referencer $Cache |
|
| 1620 | + $corps . '; |
|
| 1621 | 1621 | |
| 1622 | 1622 | return analyse_resultat_skel(' . var_export($nom, true) |
| 1623 | - . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1623 | + . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1624 | 1624 | }'; |
| 1625 | 1625 | |
| 1626 | - $secondes = spip_timer('calcul_skel'); |
|
| 1627 | - spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1628 | - // $connect n'est pas sûr : on nettoie |
|
| 1629 | - $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1626 | + $secondes = spip_timer('calcul_skel'); |
|
| 1627 | + spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1628 | + // $connect n'est pas sûr : on nettoie |
|
| 1629 | + $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1630 | 1630 | |
| 1631 | - // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1632 | - $code = new Boucle(); |
|
| 1633 | - $code->descr = $descr; |
|
| 1634 | - $code->return = ' |
|
| 1631 | + // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1632 | + $code = new Boucle(); |
|
| 1633 | + $code->descr = $descr; |
|
| 1634 | + $code->return = ' |
|
| 1635 | 1635 | // |
| 1636 | 1636 | // Fonction principale du squelette ' . |
| 1637 | - $sourcefile . |
|
| 1638 | - ($connect ? " pour $connect" : '') . |
|
| 1639 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1640 | - "\n//\n" . |
|
| 1641 | - $principal; |
|
| 1637 | + $sourcefile . |
|
| 1638 | + ($connect ? " pour $connect" : '') . |
|
| 1639 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1640 | + "\n//\n" . |
|
| 1641 | + $principal; |
|
| 1642 | 1642 | |
| 1643 | - $boucles[''] = $code; |
|
| 1643 | + $boucles[''] = $code; |
|
| 1644 | 1644 | |
| 1645 | - return $boucles; |
|
| 1645 | + return $boucles; |
|
| 1646 | 1646 | } |
| 1647 | 1647 | |
| 1648 | 1648 | |
@@ -1659,18 +1659,18 @@ discard block |
||
| 1659 | 1659 | * |
| 1660 | 1660 | **/ |
| 1661 | 1661 | function requeteur_php_dist(&$boucles, &$boucle, &$id) { |
| 1662 | - if (class_exists($boucle->type_requete)) { |
|
| 1663 | - $g = charger_fonction('php', 'iterateur'); |
|
| 1664 | - $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1665 | - } else { |
|
| 1666 | - $x = $boucle->type_requete; |
|
| 1667 | - $boucle->type_requete = false; |
|
| 1668 | - $msg = [ |
|
| 1669 | - 'zbug_iterateur_inconnu', |
|
| 1670 | - ['iterateur' => $x] |
|
| 1671 | - ]; |
|
| 1672 | - erreur_squelette($msg, $boucle); |
|
| 1673 | - } |
|
| 1662 | + if (class_exists($boucle->type_requete)) { |
|
| 1663 | + $g = charger_fonction('php', 'iterateur'); |
|
| 1664 | + $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1665 | + } else { |
|
| 1666 | + $x = $boucle->type_requete; |
|
| 1667 | + $boucle->type_requete = false; |
|
| 1668 | + $msg = [ |
|
| 1669 | + 'zbug_iterateur_inconnu', |
|
| 1670 | + ['iterateur' => $x] |
|
| 1671 | + ]; |
|
| 1672 | + erreur_squelette($msg, $boucle); |
|
| 1673 | + } |
|
| 1674 | 1674 | } |
| 1675 | 1675 | |
| 1676 | 1676 | |
@@ -1688,22 +1688,22 @@ discard block |
||
| 1688 | 1688 | * |
| 1689 | 1689 | **/ |
| 1690 | 1690 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1691 | - include_spip('iterateur/data'); |
|
| 1692 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1693 | - $g = charger_fonction('data', 'iterateur'); |
|
| 1694 | - $boucles[$id] = $g($boucle); |
|
| 1695 | - // from[0] stocke le type de data (rss, yql, ...) |
|
| 1696 | - $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1697 | - } else { |
|
| 1698 | - $x = $boucle->type_requete; |
|
| 1699 | - $boucle->type_requete = false; |
|
| 1700 | - $msg = [ |
|
| 1701 | - 'zbug_requeteur_inconnu', |
|
| 1702 | - [ |
|
| 1703 | - 'requeteur' => 'data', |
|
| 1704 | - 'type' => $x |
|
| 1705 | - ] |
|
| 1706 | - ]; |
|
| 1707 | - erreur_squelette($msg, $boucle); |
|
| 1708 | - } |
|
| 1691 | + include_spip('iterateur/data'); |
|
| 1692 | + if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1693 | + $g = charger_fonction('data', 'iterateur'); |
|
| 1694 | + $boucles[$id] = $g($boucle); |
|
| 1695 | + // from[0] stocke le type de data (rss, yql, ...) |
|
| 1696 | + $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1697 | + } else { |
|
| 1698 | + $x = $boucle->type_requete; |
|
| 1699 | + $boucle->type_requete = false; |
|
| 1700 | + $msg = [ |
|
| 1701 | + 'zbug_requeteur_inconnu', |
|
| 1702 | + [ |
|
| 1703 | + 'requeteur' => 'data', |
|
| 1704 | + 'type' => $x |
|
| 1705 | + ] |
|
| 1706 | + ]; |
|
| 1707 | + erreur_squelette($msg, $boucle); |
|
| 1708 | + } |
|
| 1709 | 1709 | } |
@@ -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 | } |