@@ -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 | /** |
@@ -30,155 +30,155 @@ discard block |
||
| 30 | 30 | * redirige sur l'image ainsi créée (sinon sur une image d'echec). |
| 31 | 31 | **/ |
| 32 | 32 | function action_tester_dist() { |
| 33 | - $arg = _request('arg'); |
|
| 34 | - |
|
| 35 | - $gd_formats = []; |
|
| 36 | - $gd_formats_read_gif = ''; |
|
| 37 | - // verifier les formats acceptes par GD |
|
| 38 | - if ($arg == 'gd1') { |
|
| 39 | - // Si GD est installe et php >= 4.0.2 |
|
| 40 | - if (function_exists('imagetypes')) { |
|
| 41 | - if (imagetypes() & IMG_GIF) { |
|
| 42 | - $gd_formats[] = 'gif'; |
|
| 43 | - } else { |
|
| 44 | - # Attention GD sait lire le gif mais pas forcement l'ecrire |
|
| 45 | - if (function_exists('ImageCreateFromGIF')) { |
|
| 46 | - $srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . 'test.gif'); |
|
| 47 | - if ($srcImage) { |
|
| 48 | - $gd_formats_read_gif = ',gif'; |
|
| 49 | - ImageDestroy($srcImage); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if (imagetypes() & IMG_JPG) { |
|
| 55 | - $gd_formats[] = 'jpg'; |
|
| 56 | - } |
|
| 57 | - if (imagetypes() & IMG_PNG) { |
|
| 58 | - $gd_formats[] = 'png'; |
|
| 59 | - } |
|
| 60 | - if (imagetypes() & IMG_WEBP) { |
|
| 61 | - $gd_formats[] = 'webp'; |
|
| 62 | - } |
|
| 63 | - } else { |
|
| 64 | - # ancienne methode de detection des formats, qui en plus |
|
| 65 | - # est bugguee car elle teste les formats en lecture |
|
| 66 | - # alors que la valeur deduite sert a identifier |
|
| 67 | - # les formats disponibles en ecriture... (cf. inc_logos) |
|
| 68 | - |
|
| 69 | - if (function_exists('ImageCreateFromJPEG')) { |
|
| 70 | - $srcImage = @ImageCreateFromJPEG(_ROOT_IMG_PACK . 'test.jpg'); |
|
| 71 | - if ($srcImage) { |
|
| 72 | - $gd_formats[] = 'jpg'; |
|
| 73 | - ImageDestroy($srcImage); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - if (function_exists('ImageCreateFromGIF')) { |
|
| 77 | - $srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . 'test.gif'); |
|
| 78 | - if ($srcImage) { |
|
| 79 | - $gd_formats[] = 'gif'; |
|
| 80 | - ImageDestroy($srcImage); |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - if (function_exists('ImageCreateFromPNG')) { |
|
| 84 | - $srcImage = @ImageCreateFromPNG(_ROOT_IMG_PACK . 'test.png'); |
|
| 85 | - if ($srcImage) { |
|
| 86 | - $gd_formats[] = 'png'; |
|
| 87 | - ImageDestroy($srcImage); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - if (function_exists('ImageCreateFromWEBP')) { |
|
| 91 | - $srcImage = @ImageCreateFromWEBP(_ROOT_IMG_PACK . 'test.webp'); |
|
| 92 | - if ($srcImage) { |
|
| 93 | - $gd_formats[] = 'webp'; |
|
| 94 | - ImageDestroy($srcImage); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - if (! empty($gd_formats)) { |
|
| 100 | - $gd_formats = join(',', $gd_formats); |
|
| 101 | - } |
|
| 102 | - ecrire_meta('gd_formats_read', $gd_formats . $gd_formats_read_gif); |
|
| 103 | - ecrire_meta('gd_formats', $gd_formats); |
|
| 104 | - } // verifier les formats netpbm |
|
| 105 | - else { |
|
| 106 | - if ($arg == 'netpbm') { |
|
| 107 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 108 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 109 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 110 | - if (_PNMSCALE_COMMAND == '') { |
|
| 111 | - return; |
|
| 112 | - } |
|
| 113 | - $netpbm_formats = []; |
|
| 114 | - |
|
| 115 | - $jpegtopnm_command = str_replace( |
|
| 116 | - 'pnmscale', |
|
| 117 | - 'jpegtopnm', |
|
| 118 | - _PNMSCALE_COMMAND |
|
| 119 | - ); |
|
| 120 | - $pnmtojpeg_command = str_replace( |
|
| 121 | - 'pnmscale', |
|
| 122 | - 'pnmtojpeg', |
|
| 123 | - _PNMSCALE_COMMAND |
|
| 124 | - ); |
|
| 125 | - |
|
| 126 | - $vignette = _ROOT_IMG_PACK . 'test.jpg'; |
|
| 127 | - $dest = _DIR_VAR . 'test-jpg.jpg'; |
|
| 128 | - $commande = "$jpegtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest"; |
|
| 129 | - spip_log($commande); |
|
| 130 | - exec($commande); |
|
| 131 | - if ($taille = @getimagesize($dest)) { |
|
| 132 | - if ($taille[1] == 10) { |
|
| 133 | - $netpbm_formats[] = 'jpg'; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 137 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 138 | - $vignette = _ROOT_IMG_PACK . 'test.gif'; |
|
| 139 | - $dest = _DIR_VAR . 'test-gif.jpg'; |
|
| 140 | - $commande = "$giftopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest"; |
|
| 141 | - spip_log($commande); |
|
| 142 | - exec($commande); |
|
| 143 | - if ($taille = @getimagesize($dest)) { |
|
| 144 | - if ($taille[1] == 10) { |
|
| 145 | - $netpbm_formats[] = 'gif'; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 150 | - $vignette = _ROOT_IMG_PACK . 'test.png'; |
|
| 151 | - $dest = _DIR_VAR . 'test-gif.jpg'; |
|
| 152 | - $commande = "$pngtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest"; |
|
| 153 | - spip_log($commande); |
|
| 154 | - exec($commande); |
|
| 155 | - if ($taille = @getimagesize($dest)) { |
|
| 156 | - if ($taille[1] == 10) { |
|
| 157 | - $netpbm_formats[] = 'png'; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - ecrire_meta('netpbm_formats', join(',', $netpbm_formats ?: [])); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // et maintenant envoyer la vignette de tests |
|
| 166 | - if (in_array($arg, ['gd1', 'gd2', 'imagick', 'convert', 'netpbm'])) { |
|
| 167 | - include_spip('inc/filtres'); |
|
| 168 | - include_spip('inc/filtres_images_mini'); |
|
| 169 | - $taille_preview = 150; |
|
| 170 | - $image = _image_valeurs_trans(_DIR_IMG_PACK . 'test_image.jpg', "reduire-$taille_preview-$taille_preview", 'jpg'); |
|
| 171 | - |
|
| 172 | - $image['fichier_dest'] = _DIR_VAR . "test_$arg"; |
|
| 173 | - |
|
| 174 | - if ( |
|
| 175 | - $preview = _image_creer_vignette($image, $taille_preview, $taille_preview, $arg, true) |
|
| 176 | - and ($preview['width'] * $preview['height'] > 0) |
|
| 177 | - ) { |
|
| 178 | - redirige_par_entete($preview['fichier']); |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - # image echec |
|
| 183 | - redirige_par_entete(chemin_image('echec-reducteur-xx.svg')); |
|
| 33 | + $arg = _request('arg'); |
|
| 34 | + |
|
| 35 | + $gd_formats = []; |
|
| 36 | + $gd_formats_read_gif = ''; |
|
| 37 | + // verifier les formats acceptes par GD |
|
| 38 | + if ($arg == 'gd1') { |
|
| 39 | + // Si GD est installe et php >= 4.0.2 |
|
| 40 | + if (function_exists('imagetypes')) { |
|
| 41 | + if (imagetypes() & IMG_GIF) { |
|
| 42 | + $gd_formats[] = 'gif'; |
|
| 43 | + } else { |
|
| 44 | + # Attention GD sait lire le gif mais pas forcement l'ecrire |
|
| 45 | + if (function_exists('ImageCreateFromGIF')) { |
|
| 46 | + $srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . 'test.gif'); |
|
| 47 | + if ($srcImage) { |
|
| 48 | + $gd_formats_read_gif = ',gif'; |
|
| 49 | + ImageDestroy($srcImage); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if (imagetypes() & IMG_JPG) { |
|
| 55 | + $gd_formats[] = 'jpg'; |
|
| 56 | + } |
|
| 57 | + if (imagetypes() & IMG_PNG) { |
|
| 58 | + $gd_formats[] = 'png'; |
|
| 59 | + } |
|
| 60 | + if (imagetypes() & IMG_WEBP) { |
|
| 61 | + $gd_formats[] = 'webp'; |
|
| 62 | + } |
|
| 63 | + } else { |
|
| 64 | + # ancienne methode de detection des formats, qui en plus |
|
| 65 | + # est bugguee car elle teste les formats en lecture |
|
| 66 | + # alors que la valeur deduite sert a identifier |
|
| 67 | + # les formats disponibles en ecriture... (cf. inc_logos) |
|
| 68 | + |
|
| 69 | + if (function_exists('ImageCreateFromJPEG')) { |
|
| 70 | + $srcImage = @ImageCreateFromJPEG(_ROOT_IMG_PACK . 'test.jpg'); |
|
| 71 | + if ($srcImage) { |
|
| 72 | + $gd_formats[] = 'jpg'; |
|
| 73 | + ImageDestroy($srcImage); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + if (function_exists('ImageCreateFromGIF')) { |
|
| 77 | + $srcImage = @ImageCreateFromGIF(_ROOT_IMG_PACK . 'test.gif'); |
|
| 78 | + if ($srcImage) { |
|
| 79 | + $gd_formats[] = 'gif'; |
|
| 80 | + ImageDestroy($srcImage); |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + if (function_exists('ImageCreateFromPNG')) { |
|
| 84 | + $srcImage = @ImageCreateFromPNG(_ROOT_IMG_PACK . 'test.png'); |
|
| 85 | + if ($srcImage) { |
|
| 86 | + $gd_formats[] = 'png'; |
|
| 87 | + ImageDestroy($srcImage); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + if (function_exists('ImageCreateFromWEBP')) { |
|
| 91 | + $srcImage = @ImageCreateFromWEBP(_ROOT_IMG_PACK . 'test.webp'); |
|
| 92 | + if ($srcImage) { |
|
| 93 | + $gd_formats[] = 'webp'; |
|
| 94 | + ImageDestroy($srcImage); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + if (! empty($gd_formats)) { |
|
| 100 | + $gd_formats = join(',', $gd_formats); |
|
| 101 | + } |
|
| 102 | + ecrire_meta('gd_formats_read', $gd_formats . $gd_formats_read_gif); |
|
| 103 | + ecrire_meta('gd_formats', $gd_formats); |
|
| 104 | + } // verifier les formats netpbm |
|
| 105 | + else { |
|
| 106 | + if ($arg == 'netpbm') { |
|
| 107 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 108 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 109 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 110 | + if (_PNMSCALE_COMMAND == '') { |
|
| 111 | + return; |
|
| 112 | + } |
|
| 113 | + $netpbm_formats = []; |
|
| 114 | + |
|
| 115 | + $jpegtopnm_command = str_replace( |
|
| 116 | + 'pnmscale', |
|
| 117 | + 'jpegtopnm', |
|
| 118 | + _PNMSCALE_COMMAND |
|
| 119 | + ); |
|
| 120 | + $pnmtojpeg_command = str_replace( |
|
| 121 | + 'pnmscale', |
|
| 122 | + 'pnmtojpeg', |
|
| 123 | + _PNMSCALE_COMMAND |
|
| 124 | + ); |
|
| 125 | + |
|
| 126 | + $vignette = _ROOT_IMG_PACK . 'test.jpg'; |
|
| 127 | + $dest = _DIR_VAR . 'test-jpg.jpg'; |
|
| 128 | + $commande = "$jpegtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest"; |
|
| 129 | + spip_log($commande); |
|
| 130 | + exec($commande); |
|
| 131 | + if ($taille = @getimagesize($dest)) { |
|
| 132 | + if ($taille[1] == 10) { |
|
| 133 | + $netpbm_formats[] = 'jpg'; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 137 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 138 | + $vignette = _ROOT_IMG_PACK . 'test.gif'; |
|
| 139 | + $dest = _DIR_VAR . 'test-gif.jpg'; |
|
| 140 | + $commande = "$giftopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest"; |
|
| 141 | + spip_log($commande); |
|
| 142 | + exec($commande); |
|
| 143 | + if ($taille = @getimagesize($dest)) { |
|
| 144 | + if ($taille[1] == 10) { |
|
| 145 | + $netpbm_formats[] = 'gif'; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 150 | + $vignette = _ROOT_IMG_PACK . 'test.png'; |
|
| 151 | + $dest = _DIR_VAR . 'test-gif.jpg'; |
|
| 152 | + $commande = "$pngtopnm_command $vignette | " . _PNMSCALE_COMMAND . " -width 10 | $pnmtojpeg_command > $dest"; |
|
| 153 | + spip_log($commande); |
|
| 154 | + exec($commande); |
|
| 155 | + if ($taille = @getimagesize($dest)) { |
|
| 156 | + if ($taille[1] == 10) { |
|
| 157 | + $netpbm_formats[] = 'png'; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + ecrire_meta('netpbm_formats', join(',', $netpbm_formats ?: [])); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // et maintenant envoyer la vignette de tests |
|
| 166 | + if (in_array($arg, ['gd1', 'gd2', 'imagick', 'convert', 'netpbm'])) { |
|
| 167 | + include_spip('inc/filtres'); |
|
| 168 | + include_spip('inc/filtres_images_mini'); |
|
| 169 | + $taille_preview = 150; |
|
| 170 | + $image = _image_valeurs_trans(_DIR_IMG_PACK . 'test_image.jpg', "reduire-$taille_preview-$taille_preview", 'jpg'); |
|
| 171 | + |
|
| 172 | + $image['fichier_dest'] = _DIR_VAR . "test_$arg"; |
|
| 173 | + |
|
| 174 | + if ( |
|
| 175 | + $preview = _image_creer_vignette($image, $taille_preview, $taille_preview, $arg, true) |
|
| 176 | + and ($preview['width'] * $preview['height'] > 0) |
|
| 177 | + ) { |
|
| 178 | + redirige_par_entete($preview['fichier']); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + # image echec |
|
| 183 | + redirige_par_entete(chemin_image('echec-reducteur-xx.svg')); |
|
| 184 | 184 | } |
@@ -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 | /** |
@@ -32,28 +32,28 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function action_desinstaller_plugin_dist() { |
| 34 | 34 | |
| 35 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 36 | - $arg = $securiser_action(); |
|
| 37 | - [$dir_plugins, $plugin] = explode('::', $arg); |
|
| 38 | - $dir_type = '_DIR_PLUGINS'; |
|
| 39 | - if (defined('_DIR_PLUGINS_SUPPL') and $dir_plugins == _DIR_PLUGINS_SUPPL) { |
|
| 40 | - $dir_type = '_DIR_PLUGINS_SUPPL'; |
|
| 41 | - } |
|
| 42 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 43 | - $infos = $installer_plugins($plugin, 'uninstall', $dir_type); |
|
| 44 | - if ($infos and !$infos['install_test'][0]) { |
|
| 45 | - include_spip('inc/plugin'); |
|
| 46 | - ecrire_plugin_actifs([$plugin], false, 'enleve'); |
|
| 47 | - $erreur = ''; |
|
| 48 | - } else { |
|
| 49 | - $erreur = 'erreur_plugin_desinstalation_echouee'; |
|
| 50 | - } |
|
| 51 | - if ($redirect = _request('redirect')) { |
|
| 52 | - include_spip('inc/headers'); |
|
| 53 | - if ($erreur) { |
|
| 54 | - $redirect = parametre_url($redirect, 'erreur', $erreur); |
|
| 55 | - } |
|
| 56 | - $redirect = str_replace('&', '&', $redirect); |
|
| 57 | - redirige_par_entete($redirect); |
|
| 58 | - } |
|
| 35 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 36 | + $arg = $securiser_action(); |
|
| 37 | + [$dir_plugins, $plugin] = explode('::', $arg); |
|
| 38 | + $dir_type = '_DIR_PLUGINS'; |
|
| 39 | + if (defined('_DIR_PLUGINS_SUPPL') and $dir_plugins == _DIR_PLUGINS_SUPPL) { |
|
| 40 | + $dir_type = '_DIR_PLUGINS_SUPPL'; |
|
| 41 | + } |
|
| 42 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 43 | + $infos = $installer_plugins($plugin, 'uninstall', $dir_type); |
|
| 44 | + if ($infos and !$infos['install_test'][0]) { |
|
| 45 | + include_spip('inc/plugin'); |
|
| 46 | + ecrire_plugin_actifs([$plugin], false, 'enleve'); |
|
| 47 | + $erreur = ''; |
|
| 48 | + } else { |
|
| 49 | + $erreur = 'erreur_plugin_desinstalation_echouee'; |
|
| 50 | + } |
|
| 51 | + if ($redirect = _request('redirect')) { |
|
| 52 | + include_spip('inc/headers'); |
|
| 53 | + if ($erreur) { |
|
| 54 | + $redirect = parametre_url($redirect, 'erreur', $erreur); |
|
| 55 | + } |
|
| 56 | + $redirect = str_replace('&', '&', $redirect); |
|
| 57 | + redirige_par_entete($redirect); |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -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 | |
@@ -54,84 +54,84 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function balise_LOGO__dist($p) { |
| 56 | 56 | |
| 57 | - preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 58 | - $type = strtolower($regs[1]); |
|
| 59 | - $suite_logo = $regs[2]; |
|
| 60 | - |
|
| 61 | - // cas de #LOGO_SITE_SPIP |
|
| 62 | - if ($type == 'site_spip') { |
|
| 63 | - $type = 'site'; |
|
| 64 | - $_id_objet = "\"'0'\""; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - $id_objet = id_table_objet($type); |
|
| 68 | - if (!isset($_id_objet)) { |
|
| 69 | - $_id_objet = champ_sql($id_objet, $p); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $fichier = ($p->etoile === '**') ? -1 : 0; |
|
| 73 | - $coord = []; |
|
| 74 | - $align = $lien = ''; |
|
| 75 | - $mode_logo = ''; |
|
| 76 | - |
|
| 77 | - if ($p->param and !$p->param[0][0]) { |
|
| 78 | - $params = $p->param[0]; |
|
| 79 | - array_shift($params); |
|
| 80 | - foreach ($params as $a) { |
|
| 81 | - if ($a[0]->type === 'texte') { |
|
| 82 | - $n = $a[0]->texte; |
|
| 83 | - if (is_numeric($n)) { |
|
| 84 | - $coord[] = $n; |
|
| 85 | - } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) { |
|
| 86 | - $align = $n; |
|
| 87 | - } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) { |
|
| 88 | - $mode_logo = $n; |
|
| 89 | - } |
|
| 90 | - } else { |
|
| 91 | - $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $coord_x = !$coord ? 0 : intval(array_shift($coord)); |
|
| 97 | - $coord_y = !$coord ? 0 : intval(array_shift($coord)); |
|
| 98 | - |
|
| 99 | - if ($p->etoile === '*') { |
|
| 100 | - include_spip('balise/url_'); |
|
| 101 | - $lien = generer_generer_url_arg($type, $p, $_id_objet); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 105 | - if ($type == 'document') { |
|
| 106 | - $qconnect = _q($connect); |
|
| 107 | - $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 108 | - if ($fichier) { |
|
| 109 | - $code = "quete_logo_file($doc, $qconnect)"; |
|
| 110 | - } else { |
|
| 111 | - $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 112 | - } |
|
| 113 | - // (x=non-faux ? y : '') pour affecter x en retournant y |
|
| 114 | - if ($p->descr['documents']) { |
|
| 115 | - $code = '(($doublons["documents"] .= ",". ' |
|
| 116 | - . $_id_objet |
|
| 117 | - . ") ? $code : '')"; |
|
| 118 | - } |
|
| 119 | - } elseif ($connect) { |
|
| 120 | - $code = "''"; |
|
| 121 | - spip_log('Les logos distants ne sont pas prevus'); |
|
| 122 | - } else { |
|
| 123 | - $code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
|
| 127 | - if ($coord_x or $coord_y) { |
|
| 128 | - $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $p->code = $code; |
|
| 132 | - $p->interdire_scripts = false; |
|
| 133 | - |
|
| 134 | - return $p; |
|
| 57 | + preg_match(',^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 58 | + $type = strtolower($regs[1]); |
|
| 59 | + $suite_logo = $regs[2]; |
|
| 60 | + |
|
| 61 | + // cas de #LOGO_SITE_SPIP |
|
| 62 | + if ($type == 'site_spip') { |
|
| 63 | + $type = 'site'; |
|
| 64 | + $_id_objet = "\"'0'\""; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + $id_objet = id_table_objet($type); |
|
| 68 | + if (!isset($_id_objet)) { |
|
| 69 | + $_id_objet = champ_sql($id_objet, $p); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $fichier = ($p->etoile === '**') ? -1 : 0; |
|
| 73 | + $coord = []; |
|
| 74 | + $align = $lien = ''; |
|
| 75 | + $mode_logo = ''; |
|
| 76 | + |
|
| 77 | + if ($p->param and !$p->param[0][0]) { |
|
| 78 | + $params = $p->param[0]; |
|
| 79 | + array_shift($params); |
|
| 80 | + foreach ($params as $a) { |
|
| 81 | + if ($a[0]->type === 'texte') { |
|
| 82 | + $n = $a[0]->texte; |
|
| 83 | + if (is_numeric($n)) { |
|
| 84 | + $coord[] = $n; |
|
| 85 | + } elseif (in_array($n, ['top', 'left', 'right', 'center', 'bottom'])) { |
|
| 86 | + $align = $n; |
|
| 87 | + } elseif (in_array($n, ['auto', 'icone', 'apercu', 'vignette'])) { |
|
| 88 | + $mode_logo = $n; |
|
| 89 | + } |
|
| 90 | + } else { |
|
| 91 | + $lien = calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $coord_x = !$coord ? 0 : intval(array_shift($coord)); |
|
| 97 | + $coord_y = !$coord ? 0 : intval(array_shift($coord)); |
|
| 98 | + |
|
| 99 | + if ($p->etoile === '*') { |
|
| 100 | + include_spip('balise/url_'); |
|
| 101 | + $lien = generer_generer_url_arg($type, $p, $_id_objet); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 105 | + if ($type == 'document') { |
|
| 106 | + $qconnect = _q($connect); |
|
| 107 | + $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 108 | + if ($fichier) { |
|
| 109 | + $code = "quete_logo_file($doc, $qconnect)"; |
|
| 110 | + } else { |
|
| 111 | + $code = "quete_logo_document($doc, " . ($lien ?: "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)"; |
|
| 112 | + } |
|
| 113 | + // (x=non-faux ? y : '') pour affecter x en retournant y |
|
| 114 | + if ($p->descr['documents']) { |
|
| 115 | + $code = '(($doublons["documents"] .= ",". ' |
|
| 116 | + . $_id_objet |
|
| 117 | + . ") ? $code : '')"; |
|
| 118 | + } |
|
| 119 | + } elseif ($connect) { |
|
| 120 | + $code = "''"; |
|
| 121 | + spip_log('Les logos distants ne sont pas prevus'); |
|
| 122 | + } else { |
|
| 123 | + $code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0} |
|
| 127 | + if ($coord_x or $coord_y) { |
|
| 128 | + $code = "filtrer('image_graver',filtrer('image_reduire'," . $code . ", '$coord_x', '$coord_y'))"; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $p->code = $code; |
|
| 132 | + $p->interdire_scripts = false; |
|
| 133 | + |
|
| 134 | + return $p; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -158,20 +158,20 @@ discard block |
||
| 158 | 158 | * Code compilé retournant le chemin du logo ou le code HTML du logo. |
| 159 | 159 | **/ |
| 160 | 160 | function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $_lien, $p, $suite) { |
| 161 | - $code = "quete_logo('$id_objet', '" . |
|
| 162 | - (($suite == '_SURVOL') ? 'off' : |
|
| 163 | - (($suite == '_NORMAL') ? 'on' : 'ON')) . |
|
| 164 | - "', $_id_objet," . |
|
| 165 | - (($suite == '_RUBRIQUE') ? |
|
| 166 | - champ_sql('id_rubrique', $p) : |
|
| 167 | - (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) . |
|
| 168 | - ', ' . intval($fichier) . ')'; |
|
| 169 | - |
|
| 170 | - if ($fichier) { |
|
| 171 | - return $code; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $align = preg_replace(',\W,', '', $align); |
|
| 175 | - |
|
| 176 | - return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 161 | + $code = "quete_logo('$id_objet', '" . |
|
| 162 | + (($suite == '_SURVOL') ? 'off' : |
|
| 163 | + (($suite == '_NORMAL') ? 'on' : 'ON')) . |
|
| 164 | + "', $_id_objet," . |
|
| 165 | + (($suite == '_RUBRIQUE') ? |
|
| 166 | + champ_sql('id_rubrique', $p) : |
|
| 167 | + (($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) . |
|
| 168 | + ', ' . intval($fichier) . ')'; |
|
| 169 | + |
|
| 170 | + if ($fichier) { |
|
| 171 | + return $code; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $align = preg_replace(',\W,', '', $align); |
|
| 175 | + |
|
| 176 | + return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 177 | 177 | } |
@@ -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 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * Pile complétée du code compilé |
| 37 | 37 | **/ |
| 38 | 38 | function balise_URL_LOGOUT($p) { |
| 39 | - return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 39 | + return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * Liste (url) des arguments collectés. |
| 53 | 53 | */ |
| 54 | 54 | function balise_URL_LOGOUT_stat($args, $context_compil) { |
| 55 | - $url = $args[0] ?? ''; |
|
| 55 | + $url = $args[0] ?? ''; |
|
| 56 | 56 | |
| 57 | - return [$url]; |
|
| 57 | + return [$url]; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function balise_URL_LOGOUT_dyn($cible) { |
| 71 | 71 | |
| 72 | - if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 73 | - return ''; |
|
| 74 | - } |
|
| 72 | + if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 73 | + return ''; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 76 | + return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 77 | 77 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('base/abstract_sql'); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * Pile complétée du code compilé |
| 44 | 44 | **/ |
| 45 | 45 | function balise_FORMULAIRE_INSCRIPTION($p) { |
| 46 | - return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []); |
|
| 46 | + return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | * - chaîne vide sinon. |
| 73 | 73 | */ |
| 74 | 74 | function balise_FORMULAIRE_INSCRIPTION_stat($args, $context_compil) { |
| 75 | - [$mode, $id, $retour] = array_pad($args, 3, null); |
|
| 76 | - include_spip('action/inscrire_auteur'); |
|
| 77 | - $mode = tester_statut_inscription($mode, $id ?? 0); |
|
| 75 | + [$mode, $id, $retour] = array_pad($args, 3, null); |
|
| 76 | + include_spip('action/inscrire_auteur'); |
|
| 77 | + $mode = tester_statut_inscription($mode, $id ?? 0); |
|
| 78 | 78 | |
| 79 | - return $mode ? [$mode, $id, $retour] : ''; |
|
| 79 | + return $mode ? [$mode, $id, $retour] : ''; |
|
| 80 | 80 | } |
@@ -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 | |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * Chaine sinon : le nom du champ (non décomposable donc) |
| 34 | 34 | */ |
| 35 | 35 | function decompose_champ_id_objet($champ) { |
| 36 | - if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | - return ['id_objet', 'objet', objet_type($champ)]; |
|
| 38 | - } |
|
| 36 | + if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | + return ['id_objet', 'objet', objet_type($champ)]; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - return $champ; |
|
| 40 | + return $champ; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -56,21 +56,21 @@ discard block |
||
| 56 | 56 | * - array(id_objet, objet), si le champ n'existe pas mais qu'on peut décomposer |
| 57 | 57 | */ |
| 58 | 58 | function trouver_champs_decomposes($champ, $desc) { |
| 59 | - if ( |
|
| 60 | - !is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 61 | - or array_key_exists($champ, $desc['field']) |
|
| 62 | - ) { |
|
| 63 | - return [$champ]; |
|
| 64 | - } |
|
| 65 | - // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 66 | - if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 67 | - array_pop($decompose); |
|
| 68 | - if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 69 | - return $decompose; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return [$champ]; |
|
| 59 | + if ( |
|
| 60 | + !is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 61 | + or array_key_exists($champ, $desc['field']) |
|
| 62 | + ) { |
|
| 63 | + return [$champ]; |
|
| 64 | + } |
|
| 65 | + // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 66 | + if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 67 | + array_pop($decompose); |
|
| 68 | + if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 69 | + return $decompose; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return [$champ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | |
@@ -100,23 +100,23 @@ discard block |
||
| 100 | 100 | * Alias de la table de jointure (Lx) |
| 101 | 101 | */ |
| 102 | 102 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) { |
| 103 | - // les jointures minimales sont optimales : |
|
| 104 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 105 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 106 | - $max = 1; |
|
| 107 | - $res = false; |
|
| 108 | - $milieu_exclus = ($col ?: []); |
|
| 109 | - while ($max <= $max_liens and !$res) { |
|
| 110 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 111 | - $max++; |
|
| 112 | - } |
|
| 113 | - if (!$res) { |
|
| 114 | - return ''; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - [$nom, $desc] = $depart; |
|
| 118 | - |
|
| 119 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 103 | + // les jointures minimales sont optimales : |
|
| 104 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 105 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 106 | + $max = 1; |
|
| 107 | + $res = false; |
|
| 108 | + $milieu_exclus = ($col ?: []); |
|
| 109 | + while ($max <= $max_liens and !$res) { |
|
| 110 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 111 | + $max++; |
|
| 112 | + } |
|
| 113 | + if (!$res) { |
|
| 114 | + return ''; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + [$nom, $desc] = $depart; |
|
| 118 | + |
|
| 119 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -155,82 +155,82 @@ discard block |
||
| 155 | 155 | * Alias de la table de jointure (Lx) |
| 156 | 156 | */ |
| 157 | 157 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = [], $nom = '', $col = '', $echap = true) { |
| 158 | - $a = []; |
|
| 159 | - $j = null; |
|
| 160 | - $n = null; |
|
| 161 | - static $num = []; |
|
| 162 | - $id_table = ''; |
|
| 163 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 164 | - foreach ($res as $cle => $r) { |
|
| 165 | - [$d, $a, $j] = $r; |
|
| 166 | - if (!$id_table) { |
|
| 167 | - $id_table = $d; |
|
| 168 | - } |
|
| 169 | - $n = ++$cpt; |
|
| 170 | - if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 171 | - [$j1, $j2, $obj, $type] = $j; |
|
| 172 | - // trouver de quel cote est (id_objet,objet) |
|
| 173 | - if ($j1 == "id_$obj") { |
|
| 174 | - $obj = "$id_table.$obj"; |
|
| 175 | - } else { |
|
| 176 | - $obj = "L$n.$obj"; |
|
| 177 | - } |
|
| 178 | - // le where complementaire est envoye dans la jointure et dans le where |
|
| 179 | - // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 180 | - // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 181 | - $boucle->where["JOIN-L$n"] = |
|
| 182 | - $echap ? |
|
| 183 | - ["'='","'$obj'","sql_quote('$type')"] |
|
| 184 | - : |
|
| 185 | - ['=',"$obj",sql_quote($type)]; |
|
| 186 | - $boucle->join["L$n"] = |
|
| 187 | - $echap ? |
|
| 188 | - ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 189 | - : |
|
| 190 | - [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 191 | - } else { |
|
| 192 | - $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 193 | - } |
|
| 194 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - // pas besoin de group by |
|
| 199 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 200 | - // si une seule jointure et sur une table avec primary key formee |
|
| 201 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 202 | - // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 203 | - |
|
| 204 | - if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 205 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // pas de group by |
|
| 209 | - // si une seule jointure |
|
| 210 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 211 | - if ( |
|
| 212 | - !$pk |
|
| 213 | - and (count($boucle->from) == 2) |
|
| 214 | - and isset($a[1]['key']['PRIMARY KEY']) |
|
| 215 | - and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 216 | - ) { |
|
| 217 | - $pk = true; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 221 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 222 | - if (!$pk) { |
|
| 223 | - foreach ($groups as $id_prim) { |
|
| 224 | - $id_field = $nom . '.' . $id_prim; |
|
| 225 | - if (!in_array($id_field, $boucle->group)) { |
|
| 226 | - $boucle->group[] = $id_field; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $boucle->modificateur['lien'] = true; |
|
| 232 | - |
|
| 233 | - return "L$n"; |
|
| 158 | + $a = []; |
|
| 159 | + $j = null; |
|
| 160 | + $n = null; |
|
| 161 | + static $num = []; |
|
| 162 | + $id_table = ''; |
|
| 163 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 164 | + foreach ($res as $cle => $r) { |
|
| 165 | + [$d, $a, $j] = $r; |
|
| 166 | + if (!$id_table) { |
|
| 167 | + $id_table = $d; |
|
| 168 | + } |
|
| 169 | + $n = ++$cpt; |
|
| 170 | + if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 171 | + [$j1, $j2, $obj, $type] = $j; |
|
| 172 | + // trouver de quel cote est (id_objet,objet) |
|
| 173 | + if ($j1 == "id_$obj") { |
|
| 174 | + $obj = "$id_table.$obj"; |
|
| 175 | + } else { |
|
| 176 | + $obj = "L$n.$obj"; |
|
| 177 | + } |
|
| 178 | + // le where complementaire est envoye dans la jointure et dans le where |
|
| 179 | + // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 180 | + // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 181 | + $boucle->where["JOIN-L$n"] = |
|
| 182 | + $echap ? |
|
| 183 | + ["'='","'$obj'","sql_quote('$type')"] |
|
| 184 | + : |
|
| 185 | + ['=',"$obj",sql_quote($type)]; |
|
| 186 | + $boucle->join["L$n"] = |
|
| 187 | + $echap ? |
|
| 188 | + ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 189 | + : |
|
| 190 | + [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 191 | + } else { |
|
| 192 | + $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 193 | + } |
|
| 194 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + // pas besoin de group by |
|
| 199 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 200 | + // si une seule jointure et sur une table avec primary key formee |
|
| 201 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 202 | + // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 203 | + |
|
| 204 | + if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 205 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // pas de group by |
|
| 209 | + // si une seule jointure |
|
| 210 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 211 | + if ( |
|
| 212 | + !$pk |
|
| 213 | + and (count($boucle->from) == 2) |
|
| 214 | + and isset($a[1]['key']['PRIMARY KEY']) |
|
| 215 | + and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 216 | + ) { |
|
| 217 | + $pk = true; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 221 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 222 | + if (!$pk) { |
|
| 223 | + foreach ($groups as $id_prim) { |
|
| 224 | + $id_field = $nom . '.' . $id_prim; |
|
| 225 | + if (!in_array($id_field, $boucle->group)) { |
|
| 226 | + $boucle->group[] = $id_field; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $boucle->modificateur['lien'] = true; |
|
| 232 | + |
|
| 233 | + return "L$n"; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -245,19 +245,19 @@ discard block |
||
| 245 | 245 | * @return bool |
| 246 | 246 | */ |
| 247 | 247 | function nogroupby_if($depart, $arrivee, $col) { |
| 248 | - if ( |
|
| 249 | - empty($arrivee['key']['PRIMARY KEY']) |
|
| 250 | - or !($pk = $arrivee['key']['PRIMARY KEY']) |
|
| 251 | - or empty($depart['key']['PRIMARY KEY']) |
|
| 252 | - ) { |
|
| 253 | - return false; |
|
| 254 | - } |
|
| 255 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 256 | - if (is_array($col)) { |
|
| 257 | - $col = implode(', *', $col); |
|
| 258 | - } // cas id_objet, objet |
|
| 259 | - return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 260 | - preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 248 | + if ( |
|
| 249 | + empty($arrivee['key']['PRIMARY KEY']) |
|
| 250 | + or !($pk = $arrivee['key']['PRIMARY KEY']) |
|
| 251 | + or empty($depart['key']['PRIMARY KEY']) |
|
| 252 | + ) { |
|
| 253 | + return false; |
|
| 254 | + } |
|
| 255 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 256 | + if (is_array($col)) { |
|
| 257 | + $col = implode(', *', $col); |
|
| 258 | + } // cas id_objet, objet |
|
| 259 | + return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 260 | + preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -275,46 +275,46 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | function liste_champs_jointures($nom, $desc, $primary = false) { |
| 277 | 277 | |
| 278 | - static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 278 | + static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 279 | 279 | |
| 280 | - // si cle primaire demandee, la privilegier |
|
| 281 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 282 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 283 | - } |
|
| 280 | + // si cle primaire demandee, la privilegier |
|
| 281 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 282 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - // les champs declares explicitement pour les jointures |
|
| 286 | - if (isset($desc['join'])) { |
|
| 287 | - return $desc['join']; |
|
| 288 | - } |
|
| 289 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 285 | + // les champs declares explicitement pour les jointures |
|
| 286 | + if (isset($desc['join'])) { |
|
| 287 | + return $desc['join']; |
|
| 288 | + } |
|
| 289 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 290 | 290 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 291 | 291 | |
| 292 | - // si pas de cle, c'est fichu |
|
| 293 | - if (!isset($desc['key'])) { |
|
| 294 | - return []; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // si cle primaire |
|
| 298 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 299 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - // ici on se rabat sur les cles secondaires, |
|
| 303 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 304 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 305 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 306 | - |
|
| 307 | - $join = []; |
|
| 308 | - foreach ($desc['key'] as $v) { |
|
| 309 | - $join = split_key($v, $join); |
|
| 310 | - } |
|
| 311 | - foreach ($join as $k) { |
|
| 312 | - if (in_array($k, $nojoin)) { |
|
| 313 | - unset($join[$k]); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - return $join; |
|
| 292 | + // si pas de cle, c'est fichu |
|
| 293 | + if (!isset($desc['key'])) { |
|
| 294 | + return []; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // si cle primaire |
|
| 298 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 299 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + // ici on se rabat sur les cles secondaires, |
|
| 303 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 304 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 305 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 306 | + |
|
| 307 | + $join = []; |
|
| 308 | + foreach ($desc['key'] as $v) { |
|
| 309 | + $join = split_key($v, $join); |
|
| 310 | + } |
|
| 311 | + foreach ($join as $k) { |
|
| 312 | + if (in_array($k, $nojoin)) { |
|
| 313 | + unset($join[$k]); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + return $join; |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -325,14 +325,14 @@ discard block |
||
| 325 | 325 | * @return array |
| 326 | 326 | */ |
| 327 | 327 | function split_key($v, $join = []) { |
| 328 | - foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 329 | - if (strpos($k, '(') !== false) { |
|
| 330 | - $k = explode('(', $k); |
|
| 331 | - $k = trim(reset($k)); |
|
| 332 | - } |
|
| 333 | - $join[$k] = $k; |
|
| 334 | - } |
|
| 335 | - return $join; |
|
| 328 | + foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 329 | + if (strpos($k, '(') !== false) { |
|
| 330 | + $k = explode('(', $k); |
|
| 331 | + $k = trim(reset($k)); |
|
| 332 | + } |
|
| 333 | + $join[$k] = $k; |
|
| 334 | + } |
|
| 335 | + return $join; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /** |
@@ -355,135 +355,135 @@ discard block |
||
| 355 | 355 | * @return array |
| 356 | 356 | */ |
| 357 | 357 | function calculer_chaine_jointures( |
| 358 | - &$boucle, |
|
| 359 | - $depart, |
|
| 360 | - $arrivee, |
|
| 361 | - $vu = [], |
|
| 362 | - $milieu_exclus = [], |
|
| 363 | - $max_liens = 5 |
|
| 358 | + &$boucle, |
|
| 359 | + $depart, |
|
| 360 | + $arrivee, |
|
| 361 | + $vu = [], |
|
| 362 | + $milieu_exclus = [], |
|
| 363 | + $max_liens = 5 |
|
| 364 | 364 | ) { |
| 365 | - static $trouver_table; |
|
| 366 | - if (!$trouver_table) { |
|
| 367 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - if (is_string($milieu_exclus)) { |
|
| 371 | - $milieu_exclus = [$milieu_exclus]; |
|
| 372 | - } |
|
| 373 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 374 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 375 | - if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 376 | - $milieu_exclus[] = 'objet'; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - [$dnom, $ddesc] = $depart; |
|
| 380 | - [$anom, $adesc] = $arrivee; |
|
| 381 | - if (!count($vu)) { |
|
| 382 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 383 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - $akeys = []; |
|
| 387 | - foreach ($adesc['key'] as $k) { |
|
| 388 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 389 | - $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 393 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 394 | - |
|
| 395 | - // cles candidates au depart |
|
| 396 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 397 | - // enlever les cles dde depart exclues par l'appel |
|
| 398 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 399 | - |
|
| 400 | - $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 401 | - |
|
| 402 | - if ($v) { |
|
| 403 | - return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 407 | - if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 408 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 409 | - // id_objet,objet |
|
| 410 | - // si oui on la prend |
|
| 411 | - foreach ($akeys as $key) { |
|
| 412 | - $v = decompose_champ_id_objet($key); |
|
| 413 | - if (is_array($v)) { |
|
| 414 | - $objet = array_shift($v); // objet,'article' |
|
| 415 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 416 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 417 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } else { |
|
| 421 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 422 | - // id_objet,objet a l'arrivee |
|
| 423 | - // si oui on la prend |
|
| 424 | - foreach ($keys as $key) { |
|
| 425 | - if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 426 | - if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 427 | - $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 428 | - array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 429 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 435 | - if ($max_liens <= 1) { |
|
| 436 | - return []; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // sinon essayer de passer par une autre table |
|
| 440 | - $new = $vu; |
|
| 441 | - foreach ($boucle->jointures as $v) { |
|
| 442 | - if ( |
|
| 443 | - $v |
|
| 444 | - and !in_array($v, $vu) |
|
| 445 | - and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 446 | - and !in_array($def['table_sql'], $vu) |
|
| 447 | - ) { |
|
| 448 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 449 | - // ie la cle de la jointure precedente |
|
| 450 | - $test_cles = $milieu_exclus; |
|
| 451 | - $new[] = $v; |
|
| 452 | - $max_iter = 50; // securite |
|
| 453 | - while ( |
|
| 454 | - count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 455 | - $boucle, |
|
| 456 | - $depart, |
|
| 457 | - [$v, $def], |
|
| 458 | - $vu, |
|
| 459 | - $test_cles, |
|
| 460 | - 1 |
|
| 461 | - )) |
|
| 462 | - and $max_iter-- |
|
| 463 | - ) { |
|
| 464 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 465 | - $milieu = end($jointure_directe_possible); |
|
| 466 | - $exclure_fin = $milieu_exclus; |
|
| 467 | - if (is_string($milieu)) { |
|
| 468 | - $exclure_fin[] = $milieu; |
|
| 469 | - $test_cles[] = $milieu; |
|
| 470 | - } else { |
|
| 471 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 472 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 473 | - } |
|
| 474 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 475 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 476 | - $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 477 | - if ($r) { |
|
| 478 | - array_unshift($r, $jointure_directe_possible); |
|
| 479 | - |
|
| 480 | - return $r; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return []; |
|
| 365 | + static $trouver_table; |
|
| 366 | + if (!$trouver_table) { |
|
| 367 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + if (is_string($milieu_exclus)) { |
|
| 371 | + $milieu_exclus = [$milieu_exclus]; |
|
| 372 | + } |
|
| 373 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 374 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 375 | + if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 376 | + $milieu_exclus[] = 'objet'; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + [$dnom, $ddesc] = $depart; |
|
| 380 | + [$anom, $adesc] = $arrivee; |
|
| 381 | + if (!count($vu)) { |
|
| 382 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 383 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + $akeys = []; |
|
| 387 | + foreach ($adesc['key'] as $k) { |
|
| 388 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 389 | + $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 393 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 394 | + |
|
| 395 | + // cles candidates au depart |
|
| 396 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 397 | + // enlever les cles dde depart exclues par l'appel |
|
| 398 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 399 | + |
|
| 400 | + $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 401 | + |
|
| 402 | + if ($v) { |
|
| 403 | + return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 407 | + if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 408 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 409 | + // id_objet,objet |
|
| 410 | + // si oui on la prend |
|
| 411 | + foreach ($akeys as $key) { |
|
| 412 | + $v = decompose_champ_id_objet($key); |
|
| 413 | + if (is_array($v)) { |
|
| 414 | + $objet = array_shift($v); // objet,'article' |
|
| 415 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 416 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 417 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } else { |
|
| 421 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 422 | + // id_objet,objet a l'arrivee |
|
| 423 | + // si oui on la prend |
|
| 424 | + foreach ($keys as $key) { |
|
| 425 | + if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 426 | + if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 427 | + $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 428 | + array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 429 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 435 | + if ($max_liens <= 1) { |
|
| 436 | + return []; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // sinon essayer de passer par une autre table |
|
| 440 | + $new = $vu; |
|
| 441 | + foreach ($boucle->jointures as $v) { |
|
| 442 | + if ( |
|
| 443 | + $v |
|
| 444 | + and !in_array($v, $vu) |
|
| 445 | + and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 446 | + and !in_array($def['table_sql'], $vu) |
|
| 447 | + ) { |
|
| 448 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 449 | + // ie la cle de la jointure precedente |
|
| 450 | + $test_cles = $milieu_exclus; |
|
| 451 | + $new[] = $v; |
|
| 452 | + $max_iter = 50; // securite |
|
| 453 | + while ( |
|
| 454 | + count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 455 | + $boucle, |
|
| 456 | + $depart, |
|
| 457 | + [$v, $def], |
|
| 458 | + $vu, |
|
| 459 | + $test_cles, |
|
| 460 | + 1 |
|
| 461 | + )) |
|
| 462 | + and $max_iter-- |
|
| 463 | + ) { |
|
| 464 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 465 | + $milieu = end($jointure_directe_possible); |
|
| 466 | + $exclure_fin = $milieu_exclus; |
|
| 467 | + if (is_string($milieu)) { |
|
| 468 | + $exclure_fin[] = $milieu; |
|
| 469 | + $test_cles[] = $milieu; |
|
| 470 | + } else { |
|
| 471 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 472 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 473 | + } |
|
| 474 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 475 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 476 | + $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 477 | + if ($r) { |
|
| 478 | + array_unshift($r, $jointure_directe_possible); |
|
| 479 | + |
|
| 480 | + return $r; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return []; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -494,18 +494,18 @@ discard block |
||
| 494 | 494 | * @return array |
| 495 | 495 | */ |
| 496 | 496 | function trouver_cles_table($keys) { |
| 497 | - $res = []; |
|
| 498 | - foreach ($keys as $v) { |
|
| 499 | - if (!strpos($v, ',')) { |
|
| 500 | - $res[$v] = 1; |
|
| 501 | - } else { |
|
| 502 | - foreach (preg_split('/\s*,\s*/', $v) as $k) { |
|
| 503 | - $res[$k] = 1; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - return array_keys($res); |
|
| 497 | + $res = []; |
|
| 498 | + foreach ($keys as $v) { |
|
| 499 | + if (!strpos($v, ',')) { |
|
| 500 | + $res[$v] = 1; |
|
| 501 | + } else { |
|
| 502 | + foreach (preg_split('/\s*,\s*/', $v) as $k) { |
|
| 503 | + $res[$k] = 1; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + return array_keys($res); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | |
@@ -532,34 +532,34 @@ discard block |
||
| 532 | 532 | * - 'alias' : alias utilisé pour la table (si pertinent. ie: avec `$boucle->from` transmis par exemple) |
| 533 | 533 | */ |
| 534 | 534 | function chercher_champ_dans_tables($cle, $tables, $connect, $checkarrivee = false) { |
| 535 | - static $trouver_table = ''; |
|
| 536 | - if (!$trouver_table) { |
|
| 537 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - if (!is_array($cle)) { |
|
| 541 | - $cle = [$cle]; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - foreach ($tables as $k => $table) { |
|
| 545 | - if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 546 | - if ( |
|
| 547 | - isset($desc['field']) |
|
| 548 | - // verifier que toutes les cles cherchees sont la |
|
| 549 | - and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 550 | - // si on sait ou on veut arriver, il faut que ca colle |
|
| 551 | - and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 552 | - ) { |
|
| 553 | - return [ |
|
| 554 | - 'desc' => $desc, |
|
| 555 | - 'table' => $desc['table'], |
|
| 556 | - 'alias' => $k, |
|
| 557 | - ]; |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return false; |
|
| 535 | + static $trouver_table = ''; |
|
| 536 | + if (!$trouver_table) { |
|
| 537 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + if (!is_array($cle)) { |
|
| 541 | + $cle = [$cle]; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + foreach ($tables as $k => $table) { |
|
| 545 | + if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 546 | + if ( |
|
| 547 | + isset($desc['field']) |
|
| 548 | + // verifier que toutes les cles cherchees sont la |
|
| 549 | + and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 550 | + // si on sait ou on veut arriver, il faut que ca colle |
|
| 551 | + and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 552 | + ) { |
|
| 553 | + return [ |
|
| 554 | + 'desc' => $desc, |
|
| 555 | + 'table' => $desc['table'], |
|
| 556 | + 'alias' => $k, |
|
| 557 | + ]; |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return false; |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | /** |
@@ -585,52 +585,52 @@ discard block |
||
| 585 | 585 | */ |
| 586 | 586 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) { |
| 587 | 587 | |
| 588 | - // support de la recherche multi champ : |
|
| 589 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 590 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 591 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 592 | - if (!is_array($cle)) { |
|
| 593 | - $cle = [$cle]; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 597 | - return [$infos['table'], $infos['desc'], $cle]; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - // au premier coup, on essaye de decomposer, si possible |
|
| 601 | - if ( |
|
| 602 | - count($cle) == 1 |
|
| 603 | - and $c = reset($cle) |
|
| 604 | - and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 605 | - ) { |
|
| 606 | - $desc = $boucle->show; |
|
| 607 | - |
|
| 608 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 609 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 610 | - if (isset($desc['field'][$c])) { |
|
| 611 | - $cle = []; |
|
| 612 | - $cle[] = array_shift($decompose); // id_objet |
|
| 613 | - $cle[] = array_shift($decompose); // objet |
|
| 614 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 615 | - } |
|
| 616 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 617 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 618 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 619 | - else { |
|
| 620 | - $depart = liste_champs_jointures(($desc['table'] ?? ''), $desc); |
|
| 621 | - foreach ($depart as $d) { |
|
| 622 | - $cle = []; |
|
| 623 | - $cle[] = array_shift($decompose); // id_objet |
|
| 624 | - $cle[] = array_shift($decompose); // objet |
|
| 625 | - $cle[] = $d; |
|
| 626 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 627 | - return $ext; |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - } |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - return ''; |
|
| 588 | + // support de la recherche multi champ : |
|
| 589 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 590 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 591 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 592 | + if (!is_array($cle)) { |
|
| 593 | + $cle = [$cle]; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 597 | + return [$infos['table'], $infos['desc'], $cle]; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + // au premier coup, on essaye de decomposer, si possible |
|
| 601 | + if ( |
|
| 602 | + count($cle) == 1 |
|
| 603 | + and $c = reset($cle) |
|
| 604 | + and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 605 | + ) { |
|
| 606 | + $desc = $boucle->show; |
|
| 607 | + |
|
| 608 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 609 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 610 | + if (isset($desc['field'][$c])) { |
|
| 611 | + $cle = []; |
|
| 612 | + $cle[] = array_shift($decompose); // id_objet |
|
| 613 | + $cle[] = array_shift($decompose); // objet |
|
| 614 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 615 | + } |
|
| 616 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 617 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 618 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 619 | + else { |
|
| 620 | + $depart = liste_champs_jointures(($desc['table'] ?? ''), $desc); |
|
| 621 | + foreach ($depart as $d) { |
|
| 622 | + $cle = []; |
|
| 623 | + $cle[] = array_shift($decompose); // id_objet |
|
| 624 | + $cle[] = array_shift($decompose); // objet |
|
| 625 | + $cle[] = $d; |
|
| 626 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 627 | + return $ext; |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + } |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + return ''; |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | /** |
@@ -662,21 +662,21 @@ discard block |
||
| 662 | 662 | * @return string |
| 663 | 663 | */ |
| 664 | 664 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false, $checkarrivee = false) { |
| 665 | - if ($jointures === false) { |
|
| 666 | - $jointures = $boucle->jointures; |
|
| 667 | - } |
|
| 668 | - // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 669 | - // mais pas poour construire la jointure ensuite |
|
| 670 | - $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 671 | - if ($arrivee) { |
|
| 672 | - $desc = $boucle->show; |
|
| 673 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 674 | - $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 675 | - if ($cle) { |
|
| 676 | - return $cle; |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 680 | - |
|
| 681 | - return ''; |
|
| 665 | + if ($jointures === false) { |
|
| 666 | + $jointures = $boucle->jointures; |
|
| 667 | + } |
|
| 668 | + // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 669 | + // mais pas poour construire la jointure ensuite |
|
| 670 | + $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 671 | + if ($arrivee) { |
|
| 672 | + $desc = $boucle->show; |
|
| 673 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 674 | + $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 675 | + if ($cle) { |
|
| 676 | + return $cle; |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 680 | + |
|
| 681 | + return ''; |
|
| 682 | 682 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Ce fichier doit imperativement definir la fonction ci-dessous: |
@@ -39,59 +39,59 @@ discard block |
||
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | 41 | function public_styliser_dist($fond, $contexte, $lang = '', string $connect = '') { |
| 42 | - static $styliser_par_z; |
|
| 43 | - |
|
| 44 | - // s'assurer que le fond est licite |
|
| 45 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | - if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | - $fond = '404'; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | - $modele = substr($fond, 8); |
|
| 52 | - $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | - $fond = "modeles/$modele"; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | - $id_rubrique = 0; |
|
| 58 | - // Chercher le fond qui va servir de squelette |
|
| 59 | - if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | - [$id_rubrique, $lang] = $r; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // trouver un squelette du nom demande |
|
| 64 | - // ne rien dire si on ne trouve pas, |
|
| 65 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | - $squelette = trouver_fond($fond, '', true); |
|
| 68 | - $ext = $squelette['extension']; |
|
| 69 | - |
|
| 70 | - $flux = [ |
|
| 71 | - 'args' => [ |
|
| 72 | - 'id_rubrique' => $id_rubrique, |
|
| 73 | - 'ext' => $ext, |
|
| 74 | - 'fond' => $fond, |
|
| 75 | - 'lang' => $lang, |
|
| 76 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | - 'connect' => $connect |
|
| 78 | - ], |
|
| 79 | - 'data' => $squelette['fond'], |
|
| 80 | - ]; |
|
| 81 | - |
|
| 82 | - if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | - if (!$styliser_par_z) { |
|
| 84 | - $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | - } |
|
| 86 | - $flux = $styliser_par_z($flux); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $flux = styliser_par_objets($flux); |
|
| 90 | - |
|
| 91 | - // pipeline styliser |
|
| 92 | - $squelette = pipeline('styliser', $flux); |
|
| 93 | - |
|
| 94 | - return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 42 | + static $styliser_par_z; |
|
| 43 | + |
|
| 44 | + // s'assurer que le fond est licite |
|
| 45 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | + if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | + $fond = '404'; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | + $modele = substr($fond, 8); |
|
| 52 | + $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | + $fond = "modeles/$modele"; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | + $id_rubrique = 0; |
|
| 58 | + // Chercher le fond qui va servir de squelette |
|
| 59 | + if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | + [$id_rubrique, $lang] = $r; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // trouver un squelette du nom demande |
|
| 64 | + // ne rien dire si on ne trouve pas, |
|
| 65 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | + $squelette = trouver_fond($fond, '', true); |
|
| 68 | + $ext = $squelette['extension']; |
|
| 69 | + |
|
| 70 | + $flux = [ |
|
| 71 | + 'args' => [ |
|
| 72 | + 'id_rubrique' => $id_rubrique, |
|
| 73 | + 'ext' => $ext, |
|
| 74 | + 'fond' => $fond, |
|
| 75 | + 'lang' => $lang, |
|
| 76 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | + 'connect' => $connect |
|
| 78 | + ], |
|
| 79 | + 'data' => $squelette['fond'], |
|
| 80 | + ]; |
|
| 81 | + |
|
| 82 | + if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | + if (!$styliser_par_z) { |
|
| 84 | + $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | + } |
|
| 86 | + $flux = $styliser_par_z($flux); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $flux = styliser_par_objets($flux); |
|
| 90 | + |
|
| 91 | + // pipeline styliser |
|
| 92 | + $squelette = pipeline('styliser', $flux); |
|
| 93 | + |
|
| 94 | + return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -110,32 +110,32 @@ discard block |
||
| 110 | 110 | * Données du pipeline styliser |
| 111 | 111 | **/ |
| 112 | 112 | function styliser_par_objets($flux) { |
| 113 | - if ( |
|
| 114 | - test_espace_prive() |
|
| 115 | - and !$squelette = $flux['data'] |
|
| 116 | - and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | - and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | - ) { |
|
| 119 | - if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | - $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | - $table_sql = table_objet_sql($table); |
|
| 122 | - $objets = lister_tables_objets_sql(); |
|
| 123 | - if (isset($objets[$table_sql])) { |
|
| 124 | - $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | - $type = substr($flux['args']['fond'], 21); |
|
| 129 | - $table = table_objet($type); |
|
| 130 | - $table_sql = table_objet_sql($table); |
|
| 131 | - $objets = lister_tables_objets_sql(); |
|
| 132 | - if (isset($objets[$table_sql])) { |
|
| 133 | - $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $flux; |
|
| 113 | + if ( |
|
| 114 | + test_espace_prive() |
|
| 115 | + and !$squelette = $flux['data'] |
|
| 116 | + and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | + and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | + ) { |
|
| 119 | + if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | + $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | + $table_sql = table_objet_sql($table); |
|
| 122 | + $objets = lister_tables_objets_sql(); |
|
| 123 | + if (isset($objets[$table_sql])) { |
|
| 124 | + $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | + $type = substr($flux['args']['fond'], 21); |
|
| 129 | + $table = table_objet($type); |
|
| 130 | + $table_sql = table_objet_sql($table); |
|
| 131 | + $objets = lister_tables_objets_sql(); |
|
| 132 | + if (isset($objets[$table_sql])) { |
|
| 133 | + $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $flux; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,50 +151,50 @@ discard block |
||
| 151 | 151 | * @return array |
| 152 | 152 | */ |
| 153 | 153 | function quete_rubrique_fond($contexte) { |
| 154 | - static $liste_objets = null; |
|
| 155 | - static $quete = []; |
|
| 156 | - if (is_null($liste_objets)) { |
|
| 157 | - $liste_objets = []; |
|
| 158 | - include_spip('inc/urls'); |
|
| 159 | - include_spip('public/quete'); |
|
| 160 | - $l = urls_liste_objets(false); |
|
| 161 | - // placer la rubrique en tete des objets |
|
| 162 | - $l = array_diff($l, ['rubrique']); |
|
| 163 | - array_unshift($l, 'rubrique'); |
|
| 164 | - foreach ($l as $objet) { |
|
| 165 | - $id = id_table_objet($objet); |
|
| 166 | - if (!isset($liste_objets[$id])) { |
|
| 167 | - $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | - if (!count($c)) { |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $c = array_map('intval', $c); |
|
| 177 | - $s = serialize($c); |
|
| 178 | - if (isset($quete[$s])) { |
|
| 179 | - return $quete[$s]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | - unset($c['id_rubrique']); |
|
| 184 | - $c = ['id_rubrique' => $r] + $c; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - foreach ($c as $_id => $id) { |
|
| 188 | - if ( |
|
| 189 | - $id |
|
| 190 | - and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | - ) { |
|
| 192 | - $lang = $row['lang'] ?? ''; |
|
| 193 | - if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | - return $quete[$s] = [$id, $lang]; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $quete[$s] = false; |
|
| 154 | + static $liste_objets = null; |
|
| 155 | + static $quete = []; |
|
| 156 | + if (is_null($liste_objets)) { |
|
| 157 | + $liste_objets = []; |
|
| 158 | + include_spip('inc/urls'); |
|
| 159 | + include_spip('public/quete'); |
|
| 160 | + $l = urls_liste_objets(false); |
|
| 161 | + // placer la rubrique en tete des objets |
|
| 162 | + $l = array_diff($l, ['rubrique']); |
|
| 163 | + array_unshift($l, 'rubrique'); |
|
| 164 | + foreach ($l as $objet) { |
|
| 165 | + $id = id_table_objet($objet); |
|
| 166 | + if (!isset($liste_objets[$id])) { |
|
| 167 | + $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | + if (!count($c)) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $c = array_map('intval', $c); |
|
| 177 | + $s = serialize($c); |
|
| 178 | + if (isset($quete[$s])) { |
|
| 179 | + return $quete[$s]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | + unset($c['id_rubrique']); |
|
| 184 | + $c = ['id_rubrique' => $r] + $c; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + foreach ($c as $_id => $id) { |
|
| 188 | + if ( |
|
| 189 | + $id |
|
| 190 | + and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | + ) { |
|
| 192 | + $lang = $row['lang'] ?? ''; |
|
| 193 | + if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | + return $quete[$s] = [$id, $lang]; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $quete[$s] = false; |
|
| 200 | 200 | } |
@@ -11,127 +11,127 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) { |
| 18 | - $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 19 | - $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 20 | - $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 21 | - $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 22 | - $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 23 | - if (!$corps) { |
|
| 24 | - $corps = ' />'; |
|
| 25 | - } else { |
|
| 26 | - $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 18 | + $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 19 | + $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 20 | + $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 21 | + $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 22 | + $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 23 | + if (!$corps) { |
|
| 24 | + $corps = ' />'; |
|
| 25 | + } else { |
|
| 26 | + $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function format_inclure_html($file, $args, $prof) { |
| 33 | - if (strpos($file, '#') === false) { |
|
| 34 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 35 | - } else { |
|
| 36 | - $t = '{fond=' . $file . '}'; |
|
| 37 | - } |
|
| 38 | - $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 39 | - |
|
| 40 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 33 | + if (strpos($file, '#') === false) { |
|
| 34 | + $t = $file ? ('(' . $file . ')') : ''; |
|
| 35 | + } else { |
|
| 36 | + $t = '{fond=' . $file . '}'; |
|
| 37 | + } |
|
| 38 | + $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 39 | + |
|
| 40 | + return ('<INCLURE' . $t . $args . '>'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function format_polyglotte_html($args, $prof) { |
| 44 | - $contenu = []; |
|
| 45 | - foreach ($args as $l => $t) { |
|
| 46 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | - } |
|
| 44 | + $contenu = []; |
|
| 45 | + foreach ($args as $l => $t) { |
|
| 46 | + $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 49 | + return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 53 | - foreach ($args as $k => $v) { |
|
| 54 | - $args[$k] = "$k=$v"; |
|
| 55 | - } |
|
| 56 | - $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 53 | + foreach ($args as $k => $v) { |
|
| 54 | + $args[$k] = "$k=$v"; |
|
| 55 | + } |
|
| 56 | + $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 57 | 57 | |
| 58 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 58 | + return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 62 | - $nom = '#' |
|
| 63 | - . ($boucle ? ($boucle . ':') : '') |
|
| 64 | - . $nom |
|
| 65 | - . $etoile |
|
| 66 | - . $args |
|
| 67 | - . $filtres; |
|
| 62 | + $nom = '#' |
|
| 63 | + . ($boucle ? ($boucle . ':') : '') |
|
| 64 | + . $nom |
|
| 65 | + . $etoile |
|
| 66 | + . $args |
|
| 67 | + . $filtres; |
|
| 68 | 68 | |
| 69 | - // Determiner si c'est un champ etendu, |
|
| 69 | + // Determiner si c'est un champ etendu, |
|
| 70 | 70 | |
| 71 | - $s = ($avant or $apres or $filtres |
|
| 72 | - or (strpos($args, '(#') !== false)); |
|
| 71 | + $s = ($avant or $apres or $filtres |
|
| 72 | + or (strpos($args, '(#') !== false)); |
|
| 73 | 73 | |
| 74 | - return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 74 | + return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function format_critere_html($critere) { |
| 78 | - foreach ($critere as $k => $crit) { |
|
| 79 | - $crit_s = ''; |
|
| 80 | - foreach ($crit as $operande) { |
|
| 81 | - [$type, $valeur] = $operande; |
|
| 82 | - if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | - $valeur = substr($valeur, 1, -1); |
|
| 84 | - if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | - $valeur = substr($valeur, 1, -1); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - $crit_s .= $valeur; |
|
| 89 | - } |
|
| 90 | - $critere[$k] = $crit_s; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 78 | + foreach ($critere as $k => $crit) { |
|
| 79 | + $crit_s = ''; |
|
| 80 | + foreach ($crit as $operande) { |
|
| 81 | + [$type, $valeur] = $operande; |
|
| 82 | + if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | + $valeur = substr($valeur, 1, -1); |
|
| 84 | + if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | + $valeur = substr($valeur, 1, -1); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + $crit_s .= $valeur; |
|
| 89 | + } |
|
| 90 | + $critere[$k] = $crit_s; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function format_liste_html($fonc, $args, $prof) { |
| 97 | - return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | - . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 97 | + return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | + . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
| 102 | 102 | function format_suite_html($args) { |
| 103 | - for ($i = 0; $i < (is_countable($args) ? count($args) : 0) - 1; $i++) { |
|
| 104 | - [$texte, $type] = $args[$i]; |
|
| 105 | - [$texte2, $type2] = $args[$i + 1]; |
|
| 106 | - if (!$texte or !$texte2) { |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 109 | - $c1 = substr($texte, -1); |
|
| 110 | - if ($type2 !== 'texte') { |
|
| 111 | - // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | - // ou assimiles, forcer la notation pleine |
|
| 113 | - if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | - } |
|
| 116 | - } else { |
|
| 117 | - if ($type == 'texte') { |
|
| 118 | - continue; |
|
| 119 | - } |
|
| 120 | - // si un champ ou assimiles est suivi d'un texte |
|
| 121 | - // et si celui-ci commence par un caractere de champ |
|
| 122 | - // forcer la notation pleine |
|
| 123 | - if ( |
|
| 124 | - ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 125 | - or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 126 | - ) { |
|
| 127 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return join('', array_map(fn($arg) => reset($arg), $args)); |
|
| 103 | + for ($i = 0; $i < (is_countable($args) ? count($args) : 0) - 1; $i++) { |
|
| 104 | + [$texte, $type] = $args[$i]; |
|
| 105 | + [$texte2, $type2] = $args[$i + 1]; |
|
| 106 | + if (!$texte or !$texte2) { |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 109 | + $c1 = substr($texte, -1); |
|
| 110 | + if ($type2 !== 'texte') { |
|
| 111 | + // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | + // ou assimiles, forcer la notation pleine |
|
| 113 | + if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | + $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | + } |
|
| 116 | + } else { |
|
| 117 | + if ($type == 'texte') { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 120 | + // si un champ ou assimiles est suivi d'un texte |
|
| 121 | + // et si celui-ci commence par un caractere de champ |
|
| 122 | + // forcer la notation pleine |
|
| 123 | + if ( |
|
| 124 | + ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 125 | + or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 126 | + ) { |
|
| 127 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return join('', array_map(fn($arg) => reset($arg), $args)); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | function format_texte_html($texte) { |
| 136 | - return $texte; |
|
| 136 | + return $texte; |
|
| 137 | 137 | } |
@@ -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 | // Les fonctions de ce fichier sont appelees en certains points |
@@ -25,193 +25,193 @@ discard block |
||
| 25 | 25 | // -> https://www.spip.net/fr_article901.html |
| 26 | 26 | |
| 27 | 27 | function phraser_vieux_logos(&$p) { |
| 28 | - if ($p->param[0][0]) { |
|
| 29 | - $args = ['']; |
|
| 30 | - } else { |
|
| 31 | - $args = array_shift($p->param); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - foreach ($p->param as $couple) { |
|
| 35 | - $nom = trim($couple[0]); |
|
| 36 | - if ($nom == '') { |
|
| 37 | - array_shift($p->param); |
|
| 38 | - break; |
|
| 39 | - } |
|
| 40 | - $r = phraser_logo_faux_filtres($nom); |
|
| 41 | - if ($r === 0) { |
|
| 42 | - $c = new Texte(); |
|
| 43 | - $c->texte = $nom; |
|
| 44 | - $args[] = [$c]; |
|
| 45 | - array_shift($p->param); |
|
| 46 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | - } elseif ($r === 2) { |
|
| 48 | - $p->etoile = '**'; |
|
| 49 | - array_shift($p->param); |
|
| 50 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | - } elseif ($r === 1) { |
|
| 52 | - array_shift($p->param); |
|
| 53 | - $p->etoile = '*'; |
|
| 54 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | - } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | - $champ = new Champ(); |
|
| 57 | - $champ->nom_boucle = $m[2]; |
|
| 58 | - $champ->nom_champ = $m[3]; |
|
| 59 | - $champ->etoile = $m[5]; |
|
| 60 | - $champ = [$champ]; |
|
| 61 | - if ($m[6]) { |
|
| 62 | - $r = new Texte(); |
|
| 63 | - $r->texte = $m[6]; |
|
| 64 | - $champ[] = $r; |
|
| 65 | - } |
|
| 66 | - $args[] = $champ; |
|
| 67 | - array_shift($p->param); |
|
| 68 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 69 | - } // le cas else est la seule incompatibilite |
|
| 70 | - } |
|
| 71 | - array_unshift($p->param, $args); |
|
| 28 | + if ($p->param[0][0]) { |
|
| 29 | + $args = ['']; |
|
| 30 | + } else { |
|
| 31 | + $args = array_shift($p->param); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + foreach ($p->param as $couple) { |
|
| 35 | + $nom = trim($couple[0]); |
|
| 36 | + if ($nom == '') { |
|
| 37 | + array_shift($p->param); |
|
| 38 | + break; |
|
| 39 | + } |
|
| 40 | + $r = phraser_logo_faux_filtres($nom); |
|
| 41 | + if ($r === 0) { |
|
| 42 | + $c = new Texte(); |
|
| 43 | + $c->texte = $nom; |
|
| 44 | + $args[] = [$c]; |
|
| 45 | + array_shift($p->param); |
|
| 46 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | + } elseif ($r === 2) { |
|
| 48 | + $p->etoile = '**'; |
|
| 49 | + array_shift($p->param); |
|
| 50 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | + } elseif ($r === 1) { |
|
| 52 | + array_shift($p->param); |
|
| 53 | + $p->etoile = '*'; |
|
| 54 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | + } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | + $champ = new Champ(); |
|
| 57 | + $champ->nom_boucle = $m[2]; |
|
| 58 | + $champ->nom_champ = $m[3]; |
|
| 59 | + $champ->etoile = $m[5]; |
|
| 60 | + $champ = [$champ]; |
|
| 61 | + if ($m[6]) { |
|
| 62 | + $r = new Texte(); |
|
| 63 | + $r->texte = $m[6]; |
|
| 64 | + $champ[] = $r; |
|
| 65 | + } |
|
| 66 | + $args[] = $champ; |
|
| 67 | + array_shift($p->param); |
|
| 68 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 69 | + } // le cas else est la seule incompatibilite |
|
| 70 | + } |
|
| 71 | + array_unshift($p->param, $args); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | function phraser_logo_faux_filtres($nom) { |
| 76 | - switch ($nom) { |
|
| 77 | - case 'top': |
|
| 78 | - case 'left': |
|
| 79 | - case 'right': |
|
| 80 | - case 'center': |
|
| 81 | - case 'bottom': |
|
| 82 | - return 0; |
|
| 83 | - case 'lien': |
|
| 84 | - return 1; |
|
| 85 | - case 'fichier': |
|
| 86 | - return 2; |
|
| 87 | - default: |
|
| 88 | - return $nom; |
|
| 89 | - } |
|
| 76 | + switch ($nom) { |
|
| 77 | + case 'top': |
|
| 78 | + case 'left': |
|
| 79 | + case 'right': |
|
| 80 | + case 'center': |
|
| 81 | + case 'bottom': |
|
| 82 | + return 0; |
|
| 83 | + case 'lien': |
|
| 84 | + return 1; |
|
| 85 | + case 'fichier': |
|
| 86 | + return 2; |
|
| 87 | + default: |
|
| 88 | + return $nom; |
|
| 89 | + } |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
| 93 | 93 | // La balise embed_document est a present le modele emb |
| 94 | 94 | |
| 95 | 95 | function phraser_vieux_emb(&$p) { |
| 96 | - if (!is_array($p->param)) { |
|
| 97 | - $p->param = []; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // Produire le premier argument {emb} |
|
| 101 | - $texte = new Texte(); |
|
| 102 | - $texte->texte = 'emb'; |
|
| 103 | - $param = ['', [$texte]]; |
|
| 104 | - |
|
| 105 | - // Transformer les filtres en arguments |
|
| 106 | - for ($i = 0; $i < (is_countable($p->param) ? count($p->param) : 0); $i++) { |
|
| 107 | - if ($p->param[$i][0]) { |
|
| 108 | - if (!strstr($p->param[$i][0], '=')) { |
|
| 109 | - break; |
|
| 110 | - }# on a rencontre un vrai filtre, c'est fini |
|
| 111 | - $texte = new Texte(); |
|
| 112 | - $texte->texte = $p->param[$i][0]; |
|
| 113 | - $param[] = [$texte]; |
|
| 114 | - } |
|
| 115 | - array_shift($p->param); |
|
| 116 | - } |
|
| 117 | - array_unshift($p->param, $param); |
|
| 118 | - spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 119 | - $p->nom_champ = 'MODELE'; |
|
| 96 | + if (!is_array($p->param)) { |
|
| 97 | + $p->param = []; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // Produire le premier argument {emb} |
|
| 101 | + $texte = new Texte(); |
|
| 102 | + $texte->texte = 'emb'; |
|
| 103 | + $param = ['', [$texte]]; |
|
| 104 | + |
|
| 105 | + // Transformer les filtres en arguments |
|
| 106 | + for ($i = 0; $i < (is_countable($p->param) ? count($p->param) : 0); $i++) { |
|
| 107 | + if ($p->param[$i][0]) { |
|
| 108 | + if (!strstr($p->param[$i][0], '=')) { |
|
| 109 | + break; |
|
| 110 | + }# on a rencontre un vrai filtre, c'est fini |
|
| 111 | + $texte = new Texte(); |
|
| 112 | + $texte->texte = $p->param[$i][0]; |
|
| 113 | + $param[] = [$texte]; |
|
| 114 | + } |
|
| 115 | + array_shift($p->param); |
|
| 116 | + } |
|
| 117 | + array_unshift($p->param, $param); |
|
| 118 | + spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 119 | + $p->nom_champ = 'MODELE'; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Vieux formulaire de recherch |
| 123 | 123 | |
| 124 | 124 | function phraser_vieux_recherche($p) { |
| 125 | - if ($p->param[0][0]) { |
|
| 126 | - $c = new Texte(); |
|
| 127 | - $c->texte = $p->param[0][0]; |
|
| 128 | - $p->param[0][1] = [$c]; |
|
| 129 | - $p->param[0][0] = ''; |
|
| 130 | - $p->fonctions = []; |
|
| 131 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 132 | - } |
|
| 125 | + if ($p->param[0][0]) { |
|
| 126 | + $c = new Texte(); |
|
| 127 | + $c->texte = $p->param[0][0]; |
|
| 128 | + $p->param[0][1] = [$c]; |
|
| 129 | + $p->param[0][0] = ''; |
|
| 130 | + $p->fonctions = []; |
|
| 131 | + spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 132 | + } |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Gerer la notation [(#EXPOSER|on,off)] |
| 136 | 136 | function phraser_vieux_exposer($p) { |
| 137 | - if ($a = $p->fonctions) { |
|
| 138 | - preg_match('#([^,]*)(,(.*))?#', $a[0][0], $regs); |
|
| 139 | - $args = []; |
|
| 140 | - if ($regs[1]) { |
|
| 141 | - $a = new Texte(); |
|
| 142 | - $a->texte = $regs[1]; |
|
| 143 | - $args = ['', [$a]]; |
|
| 144 | - if ($regs[3]) { |
|
| 145 | - $a = new Texte(); |
|
| 146 | - $a->texte = $regs[3]; |
|
| 147 | - $args[] = [$a]; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - $p->param[0] = $args; |
|
| 151 | - $p->fonctions = []; |
|
| 152 | - $p->nom_champ = 'EXPOSE'; |
|
| 153 | - } |
|
| 137 | + if ($a = $p->fonctions) { |
|
| 138 | + preg_match('#([^,]*)(,(.*))?#', $a[0][0], $regs); |
|
| 139 | + $args = []; |
|
| 140 | + if ($regs[1]) { |
|
| 141 | + $a = new Texte(); |
|
| 142 | + $a->texte = $regs[1]; |
|
| 143 | + $args = ['', [$a]]; |
|
| 144 | + if ($regs[3]) { |
|
| 145 | + $a = new Texte(); |
|
| 146 | + $a->texte = $regs[3]; |
|
| 147 | + $args[] = [$a]; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + $p->param[0] = $args; |
|
| 151 | + $p->fonctions = []; |
|
| 152 | + $p->nom_champ = 'EXPOSE'; |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | function phraser_vieux_modele($p) { |
| 157 | - normaliser_args_inclumodel($p); |
|
| 157 | + normaliser_args_inclumodel($p); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | function phraser_vieux_inclu($p) { |
| 161 | - normaliser_args_inclumodel($p); |
|
| 161 | + normaliser_args_inclumodel($p); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | function normaliser_args_inclumodel($p) { |
| 165 | - $params = $p->param; |
|
| 166 | - if (!$params) { |
|
| 167 | - return; |
|
| 168 | - } |
|
| 169 | - $args = $params[0]; |
|
| 170 | - if ($args[0]) { |
|
| 171 | - return; |
|
| 172 | - } // filtre immediat |
|
| 173 | - array_shift($p->param); |
|
| 174 | - foreach ($p->param as $l) { |
|
| 175 | - if (!array_shift($l)) { |
|
| 176 | - $args = array_merge($args, $l); |
|
| 177 | - array_shift($p->param); |
|
| 178 | - } else { |
|
| 179 | - break; |
|
| 180 | - } // filtre |
|
| 181 | - } |
|
| 182 | - array_unshift($p->param, $args); |
|
| 165 | + $params = $p->param; |
|
| 166 | + if (!$params) { |
|
| 167 | + return; |
|
| 168 | + } |
|
| 169 | + $args = $params[0]; |
|
| 170 | + if ($args[0]) { |
|
| 171 | + return; |
|
| 172 | + } // filtre immediat |
|
| 173 | + array_shift($p->param); |
|
| 174 | + foreach ($p->param as $l) { |
|
| 175 | + if (!array_shift($l)) { |
|
| 176 | + $args = array_merge($args, $l); |
|
| 177 | + array_shift($p->param); |
|
| 178 | + } else { |
|
| 179 | + break; |
|
| 180 | + } // filtre |
|
| 181 | + } |
|
| 182 | + array_unshift($p->param, $args); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | function normaliser_inclure($champ) { |
| 186 | - normaliser_args_inclumodel($champ); |
|
| 187 | - $l = $champ->param[0]; |
|
| 188 | - if (is_array($l) and !$l[0]) { |
|
| 189 | - foreach ($l as $k => $p) { |
|
| 190 | - if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 191 | - $p[0]->texte = trim($p[0]->texte); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - foreach ($l as $k => $p) { |
|
| 195 | - if ( |
|
| 196 | - !$p or $p[0]->type != 'texte' or |
|
| 197 | - !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 198 | - ) { |
|
| 199 | - continue; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ($r[1]) { |
|
| 203 | - $p[0]->texte = $r[1]; |
|
| 204 | - } else { |
|
| 205 | - unset($p[0]); |
|
| 206 | - } |
|
| 207 | - $champ->texte = $p; |
|
| 208 | - unset($champ->param[0][$k]); |
|
| 209 | - if ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) { |
|
| 210 | - array_shift($champ->param); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - return; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - spip_log('inclure sans fond ni fichier'); |
|
| 186 | + normaliser_args_inclumodel($champ); |
|
| 187 | + $l = $champ->param[0]; |
|
| 188 | + if (is_array($l) and !$l[0]) { |
|
| 189 | + foreach ($l as $k => $p) { |
|
| 190 | + if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 191 | + $p[0]->texte = trim($p[0]->texte); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + foreach ($l as $k => $p) { |
|
| 195 | + if ( |
|
| 196 | + !$p or $p[0]->type != 'texte' or |
|
| 197 | + !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 198 | + ) { |
|
| 199 | + continue; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ($r[1]) { |
|
| 203 | + $p[0]->texte = $r[1]; |
|
| 204 | + } else { |
|
| 205 | + unset($p[0]); |
|
| 206 | + } |
|
| 207 | + $champ->texte = $p; |
|
| 208 | + unset($champ->param[0][$k]); |
|
| 209 | + if ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) { |
|
| 210 | + array_shift($champ->param); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + return; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + spip_log('inclure sans fond ni fichier'); |
|
| 217 | 217 | } |