@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | if (is_null($p)) { |
| 50 | - $arbre = array('erreur' => array(_T('erreur_plugin_tag_plugin_absent') . " : $plug")); |
|
| 50 | + $arbre = array('erreur' => array(_T('erreur_plugin_tag_plugin_absent')." : $plug")); |
|
| 51 | 51 | $silence = true; |
| 52 | 52 | } else { |
| 53 | 53 | $arbre = $p; |
@@ -82,15 +82,15 @@ discard block |
||
| 82 | 82 | if (isset($arbre['etat'])) { |
| 83 | 83 | $etat = trim(end($arbre['etat'])); |
| 84 | 84 | if (!in_array($etat, $etats)) { |
| 85 | - $arbre['erreur'][] = _T('erreur_plugin_etat_inconnu') . " : '$etat'"; |
|
| 85 | + $arbre['erreur'][] = _T('erreur_plugin_etat_inconnu')." : '$etat'"; |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | if (isset($arbre['options'])) { |
| 89 | 89 | foreach ($arbre['options'] as $optfile) { |
| 90 | 90 | $optfile = trim($optfile); |
| 91 | - if (!@is_readable($dir_plugins . "$plug/$optfile")) { |
|
| 91 | + if (!@is_readable($dir_plugins."$plug/$optfile")) { |
|
| 92 | 92 | if (!$silence) { |
| 93 | - $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile"; |
|
| 93 | + $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile"; |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -98,9 +98,9 @@ discard block |
||
| 98 | 98 | if (isset($arbre['fonctions'])) { |
| 99 | 99 | foreach ($arbre['fonctions'] as $optfile) { |
| 100 | 100 | $optfile = trim($optfile); |
| 101 | - if (!@is_readable($dir_plugins . "$plug/$optfile")) { |
|
| 101 | + if (!@is_readable($dir_plugins."$plug/$optfile")) { |
|
| 102 | 102 | if (!$silence) { |
| 103 | - $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile"; |
|
| 103 | + $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile"; |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | // verif que la methode a un nom autorise |
| 135 | 135 | if (in_array(strtolower($action), $liste_methodes_reservees)) { |
| 136 | 136 | if (!$silence) { |
| 137 | - $arbre['erreur'][] = _T("erreur_plugin_nom_fonction_interdit") . " : $action"; |
|
| 137 | + $arbre['erreur'][] = _T("erreur_plugin_nom_fonction_interdit")." : $action"; |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | if (isset($pipe['inclure'])) { |
| 141 | - $inclure = $dir_plugins . "$plug/" . $pipe['inclure']; |
|
| 141 | + $inclure = $dir_plugins."$plug/".$pipe['inclure']; |
|
| 142 | 142 | if (!@is_readable($inclure)) { |
| 143 | 143 | if (!$silence) { |
| 144 | - $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $inclure"; |
|
| 144 | + $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $inclure"; |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -207,9 +207,9 @@ discard block |
||
| 207 | 207 | foreach ($arbre['noisette'] as $k => $nut) { |
| 208 | 208 | $nut = preg_replace(',[.]html$,uims', '', trim($nut)); |
| 209 | 209 | $arbre['noisette'][$k] = $nut; |
| 210 | - if (!@is_readable($dir_plugins . "$plug/$nut.html")) { |
|
| 210 | + if (!@is_readable($dir_plugins."$plug/$nut.html")) { |
|
| 211 | 211 | if (!$silence) { |
| 212 | - $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $nut"; |
|
| 212 | + $arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $nut"; |
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/xml'); |
@@ -19,208 +19,208 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | // https://code.spip.net/@plugin_verifie_conformite |
| 21 | 21 | function plugins_verifie_conformite_dist($plug, &$arbre, $dir_plugins = _DIR_PLUGINS) { |
| 22 | - static $etats = array('dev', 'experimental', 'test', 'stable'); |
|
| 22 | + static $etats = array('dev', 'experimental', 'test', 'stable'); |
|
| 23 | 23 | |
| 24 | - $matches = array(); |
|
| 25 | - $silence = false; |
|
| 26 | - $p = null; |
|
| 27 | - // chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP |
|
| 28 | - if ($n = spip_xml_match_nodes(",^plugin(\s|$),", $arbre, $matches)) { |
|
| 29 | - // version de SPIP |
|
| 30 | - $vspip = $GLOBALS['spip_version_branche']; |
|
| 31 | - foreach ($matches as $tag => $sous) { |
|
| 32 | - list($tagname, $atts) = spip_xml_decompose_tag($tag); |
|
| 33 | - if ($tagname == 'plugin' and is_array($sous)) { |
|
| 34 | - // On rajoute la condition sur $n : |
|
| 35 | - // -- en effet si $n==1 on a pas plus a choisir la balise que l'on ait |
|
| 36 | - // un attribut spip ou pas. Cela permet de traiter tous les cas mono-balise |
|
| 37 | - // de la meme facon. |
|
| 38 | - if (!isset($atts['spip']) |
|
| 39 | - or $n == 1 |
|
| 40 | - or plugin_version_compatible($atts['spip'], $vspip, 'spip') |
|
| 41 | - ) { |
|
| 42 | - // on prend la derniere declaration avec ce nom |
|
| 43 | - $p = end($sous); |
|
| 44 | - $compat_spip = isset($atts['spip']) ? $atts['spip'] : ''; |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - if (is_null($p)) { |
|
| 50 | - $arbre = array('erreur' => array(_T('erreur_plugin_tag_plugin_absent') . " : $plug")); |
|
| 51 | - $silence = true; |
|
| 52 | - } else { |
|
| 53 | - $arbre = $p; |
|
| 54 | - } |
|
| 55 | - if (!is_array($arbre)) { |
|
| 56 | - $arbre = array(); |
|
| 57 | - } |
|
| 58 | - // verification de la conformite du plugin avec quelques |
|
| 59 | - // precautions elementaires |
|
| 60 | - if (!isset($arbre['nom'])) { |
|
| 61 | - if (!$silence) { |
|
| 62 | - $arbre['erreur'][] = _T('erreur_plugin_nom_manquant'); |
|
| 63 | - } |
|
| 64 | - $arbre['nom'] = array(""); |
|
| 65 | - } |
|
| 66 | - if (!isset($arbre['version'])) { |
|
| 67 | - if (!$silence) { |
|
| 68 | - $arbre['erreur'][] = _T('erreur_plugin_version_manquant'); |
|
| 69 | - } |
|
| 70 | - $arbre['version'] = array(""); |
|
| 71 | - } |
|
| 72 | - if (!isset($arbre['prefix'])) { |
|
| 73 | - if (!$silence) { |
|
| 74 | - $arbre['erreur'][] = _T('erreur_plugin_prefix_manquant'); |
|
| 75 | - } |
|
| 76 | - $arbre['prefix'] = array(""); |
|
| 77 | - } else { |
|
| 78 | - $prefix = trim(end($arbre['prefix'])); |
|
| 79 | - if (strtoupper($prefix) == 'SPIP' and $plug != "./") { |
|
| 80 | - $arbre['erreur'][] = _T('erreur_plugin_prefix_interdit'); |
|
| 81 | - } |
|
| 82 | - if (isset($arbre['etat'])) { |
|
| 83 | - $etat = trim(end($arbre['etat'])); |
|
| 84 | - if (!in_array($etat, $etats)) { |
|
| 85 | - $arbre['erreur'][] = _T('erreur_plugin_etat_inconnu') . " : '$etat'"; |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - if (isset($arbre['options'])) { |
|
| 89 | - foreach ($arbre['options'] as $optfile) { |
|
| 90 | - $optfile = trim($optfile); |
|
| 91 | - if (!@is_readable($dir_plugins . "$plug/$optfile")) { |
|
| 92 | - if (!$silence) { |
|
| 93 | - $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile"; |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - if (isset($arbre['fonctions'])) { |
|
| 99 | - foreach ($arbre['fonctions'] as $optfile) { |
|
| 100 | - $optfile = trim($optfile); |
|
| 101 | - if (!@is_readable($dir_plugins . "$plug/$optfile")) { |
|
| 102 | - if (!$silence) { |
|
| 103 | - $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile"; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - $fonctions = array(); |
|
| 109 | - if (isset($arbre['fonctions'])) { |
|
| 110 | - $fonctions = $arbre['fonctions']; |
|
| 111 | - } |
|
| 112 | - $liste_methodes_reservees = array( |
|
| 113 | - '__construct', |
|
| 114 | - '__destruct', |
|
| 115 | - 'plugin', |
|
| 116 | - 'install', |
|
| 117 | - 'uninstall', |
|
| 118 | - strtolower($prefix) |
|
| 119 | - ); |
|
| 24 | + $matches = array(); |
|
| 25 | + $silence = false; |
|
| 26 | + $p = null; |
|
| 27 | + // chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP |
|
| 28 | + if ($n = spip_xml_match_nodes(",^plugin(\s|$),", $arbre, $matches)) { |
|
| 29 | + // version de SPIP |
|
| 30 | + $vspip = $GLOBALS['spip_version_branche']; |
|
| 31 | + foreach ($matches as $tag => $sous) { |
|
| 32 | + list($tagname, $atts) = spip_xml_decompose_tag($tag); |
|
| 33 | + if ($tagname == 'plugin' and is_array($sous)) { |
|
| 34 | + // On rajoute la condition sur $n : |
|
| 35 | + // -- en effet si $n==1 on a pas plus a choisir la balise que l'on ait |
|
| 36 | + // un attribut spip ou pas. Cela permet de traiter tous les cas mono-balise |
|
| 37 | + // de la meme facon. |
|
| 38 | + if (!isset($atts['spip']) |
|
| 39 | + or $n == 1 |
|
| 40 | + or plugin_version_compatible($atts['spip'], $vspip, 'spip') |
|
| 41 | + ) { |
|
| 42 | + // on prend la derniere declaration avec ce nom |
|
| 43 | + $p = end($sous); |
|
| 44 | + $compat_spip = isset($atts['spip']) ? $atts['spip'] : ''; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + if (is_null($p)) { |
|
| 50 | + $arbre = array('erreur' => array(_T('erreur_plugin_tag_plugin_absent') . " : $plug")); |
|
| 51 | + $silence = true; |
|
| 52 | + } else { |
|
| 53 | + $arbre = $p; |
|
| 54 | + } |
|
| 55 | + if (!is_array($arbre)) { |
|
| 56 | + $arbre = array(); |
|
| 57 | + } |
|
| 58 | + // verification de la conformite du plugin avec quelques |
|
| 59 | + // precautions elementaires |
|
| 60 | + if (!isset($arbre['nom'])) { |
|
| 61 | + if (!$silence) { |
|
| 62 | + $arbre['erreur'][] = _T('erreur_plugin_nom_manquant'); |
|
| 63 | + } |
|
| 64 | + $arbre['nom'] = array(""); |
|
| 65 | + } |
|
| 66 | + if (!isset($arbre['version'])) { |
|
| 67 | + if (!$silence) { |
|
| 68 | + $arbre['erreur'][] = _T('erreur_plugin_version_manquant'); |
|
| 69 | + } |
|
| 70 | + $arbre['version'] = array(""); |
|
| 71 | + } |
|
| 72 | + if (!isset($arbre['prefix'])) { |
|
| 73 | + if (!$silence) { |
|
| 74 | + $arbre['erreur'][] = _T('erreur_plugin_prefix_manquant'); |
|
| 75 | + } |
|
| 76 | + $arbre['prefix'] = array(""); |
|
| 77 | + } else { |
|
| 78 | + $prefix = trim(end($arbre['prefix'])); |
|
| 79 | + if (strtoupper($prefix) == 'SPIP' and $plug != "./") { |
|
| 80 | + $arbre['erreur'][] = _T('erreur_plugin_prefix_interdit'); |
|
| 81 | + } |
|
| 82 | + if (isset($arbre['etat'])) { |
|
| 83 | + $etat = trim(end($arbre['etat'])); |
|
| 84 | + if (!in_array($etat, $etats)) { |
|
| 85 | + $arbre['erreur'][] = _T('erreur_plugin_etat_inconnu') . " : '$etat'"; |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + if (isset($arbre['options'])) { |
|
| 89 | + foreach ($arbre['options'] as $optfile) { |
|
| 90 | + $optfile = trim($optfile); |
|
| 91 | + if (!@is_readable($dir_plugins . "$plug/$optfile")) { |
|
| 92 | + if (!$silence) { |
|
| 93 | + $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile"; |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + if (isset($arbre['fonctions'])) { |
|
| 99 | + foreach ($arbre['fonctions'] as $optfile) { |
|
| 100 | + $optfile = trim($optfile); |
|
| 101 | + if (!@is_readable($dir_plugins . "$plug/$optfile")) { |
|
| 102 | + if (!$silence) { |
|
| 103 | + $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $optfile"; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + $fonctions = array(); |
|
| 109 | + if (isset($arbre['fonctions'])) { |
|
| 110 | + $fonctions = $arbre['fonctions']; |
|
| 111 | + } |
|
| 112 | + $liste_methodes_reservees = array( |
|
| 113 | + '__construct', |
|
| 114 | + '__destruct', |
|
| 115 | + 'plugin', |
|
| 116 | + 'install', |
|
| 117 | + 'uninstall', |
|
| 118 | + strtolower($prefix) |
|
| 119 | + ); |
|
| 120 | 120 | |
| 121 | - $extraire_pipelines = charger_fonction("extraire_pipelines", "plugins"); |
|
| 122 | - $arbre['pipeline'] = $extraire_pipelines($arbre); |
|
| 123 | - foreach ($arbre['pipeline'] as $pipe) { |
|
| 124 | - if (!isset($pipe['nom'])) { |
|
| 125 | - if (!$silence) { |
|
| 126 | - $arbre['erreur'][] = _T("erreur_plugin_nom_pipeline_non_defini"); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - if (isset($pipe['action'])) { |
|
| 130 | - $action = $pipe['action']; |
|
| 131 | - } else { |
|
| 132 | - $action = $pipe['nom']; |
|
| 133 | - } |
|
| 134 | - // verif que la methode a un nom autorise |
|
| 135 | - if (in_array(strtolower($action), $liste_methodes_reservees)) { |
|
| 136 | - if (!$silence) { |
|
| 137 | - $arbre['erreur'][] = _T("erreur_plugin_nom_fonction_interdit") . " : $action"; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - if (isset($pipe['inclure'])) { |
|
| 141 | - $inclure = $dir_plugins . "$plug/" . $pipe['inclure']; |
|
| 142 | - if (!@is_readable($inclure)) { |
|
| 143 | - if (!$silence) { |
|
| 144 | - $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $inclure"; |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - $necessite = array(); |
|
| 150 | - $spip_trouve = false; |
|
| 151 | - if (spip_xml_match_nodes(',^necessite,', $arbre, $needs)) { |
|
| 152 | - foreach (array_keys($needs) as $tag) { |
|
| 153 | - list($tag, $att) = spip_xml_decompose_tag($tag); |
|
| 154 | - if (!isset($att['id'])) { |
|
| 155 | - if (!$silence) { |
|
| 156 | - $arbre['erreur'][] = _T('erreur_plugin_attribut_balise_manquant', |
|
| 157 | - array('attribut' => 'id', 'balise' => $att)); |
|
| 158 | - } |
|
| 159 | - } else { |
|
| 160 | - $necessite[] = $att; |
|
| 161 | - } |
|
| 162 | - if (strtolower($att['id']) == 'spip') { |
|
| 163 | - $spip_trouve = true; |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - if ($compat_spip and !$spip_trouve) { |
|
| 168 | - $necessite[] = array('id' => 'spip', 'version' => $compat_spip); |
|
| 169 | - } |
|
| 170 | - $arbre['necessite'] = $necessite; |
|
| 171 | - $utilise = array(); |
|
| 172 | - if (spip_xml_match_nodes(',^utilise,', $arbre, $uses)) { |
|
| 173 | - foreach (array_keys($uses) as $tag) { |
|
| 174 | - list($tag, $att) = spip_xml_decompose_tag($tag); |
|
| 175 | - if (!isset($att['id'])) { |
|
| 176 | - if (!$silence) { |
|
| 177 | - $arbre['erreur'][] = _T('erreur_plugin_attribut_balise_manquant', |
|
| 178 | - array('attribut' => 'id', 'balise' => $att)); |
|
| 179 | - } |
|
| 180 | - } else { |
|
| 181 | - $utilise[] = $att; |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - $arbre['utilise'] = $utilise; |
|
| 186 | - $procure = array(); |
|
| 187 | - if (spip_xml_match_nodes(',^procure,', $arbre, $uses)) { |
|
| 188 | - foreach (array_keys($uses) as $tag) { |
|
| 189 | - list($tag, $att) = spip_xml_decompose_tag($tag); |
|
| 190 | - $procure[] = $att; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - $arbre['procure'] = $procure; |
|
| 194 | - $path = array(); |
|
| 195 | - if (spip_xml_match_nodes(',^chemin,', $arbre, $paths)) { |
|
| 196 | - foreach (array_keys($paths) as $tag) { |
|
| 197 | - list($tag, $att) = spip_xml_decompose_tag($tag); |
|
| 198 | - $att['path'] = $att['dir']; // ancienne syntaxe |
|
| 199 | - $path[] = $att; |
|
| 200 | - } |
|
| 201 | - } else { |
|
| 202 | - $path = array(array('dir' => '')); |
|
| 203 | - } // initialiser par defaut |
|
| 204 | - $arbre['path'] = $path; |
|
| 205 | - // exposer les noisettes |
|
| 206 | - if (isset($arbre['noisette'])) { |
|
| 207 | - foreach ($arbre['noisette'] as $k => $nut) { |
|
| 208 | - $nut = preg_replace(',[.]html$,uims', '', trim($nut)); |
|
| 209 | - $arbre['noisette'][$k] = $nut; |
|
| 210 | - if (!@is_readable($dir_plugins . "$plug/$nut.html")) { |
|
| 211 | - if (!$silence) { |
|
| 212 | - $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $nut"; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - $traduire = array(); |
|
| 218 | - if (spip_xml_match_nodes(',^traduire,', $arbre, $trads)) { |
|
| 219 | - foreach (array_keys($trads) as $tag) { |
|
| 220 | - list($tag, $att) = spip_xml_decompose_tag($tag); |
|
| 221 | - $traduire[] = $att; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - $arbre['traduire'] = $traduire; |
|
| 225 | - } |
|
| 121 | + $extraire_pipelines = charger_fonction("extraire_pipelines", "plugins"); |
|
| 122 | + $arbre['pipeline'] = $extraire_pipelines($arbre); |
|
| 123 | + foreach ($arbre['pipeline'] as $pipe) { |
|
| 124 | + if (!isset($pipe['nom'])) { |
|
| 125 | + if (!$silence) { |
|
| 126 | + $arbre['erreur'][] = _T("erreur_plugin_nom_pipeline_non_defini"); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + if (isset($pipe['action'])) { |
|
| 130 | + $action = $pipe['action']; |
|
| 131 | + } else { |
|
| 132 | + $action = $pipe['nom']; |
|
| 133 | + } |
|
| 134 | + // verif que la methode a un nom autorise |
|
| 135 | + if (in_array(strtolower($action), $liste_methodes_reservees)) { |
|
| 136 | + if (!$silence) { |
|
| 137 | + $arbre['erreur'][] = _T("erreur_plugin_nom_fonction_interdit") . " : $action"; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + if (isset($pipe['inclure'])) { |
|
| 141 | + $inclure = $dir_plugins . "$plug/" . $pipe['inclure']; |
|
| 142 | + if (!@is_readable($inclure)) { |
|
| 143 | + if (!$silence) { |
|
| 144 | + $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $inclure"; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + $necessite = array(); |
|
| 150 | + $spip_trouve = false; |
|
| 151 | + if (spip_xml_match_nodes(',^necessite,', $arbre, $needs)) { |
|
| 152 | + foreach (array_keys($needs) as $tag) { |
|
| 153 | + list($tag, $att) = spip_xml_decompose_tag($tag); |
|
| 154 | + if (!isset($att['id'])) { |
|
| 155 | + if (!$silence) { |
|
| 156 | + $arbre['erreur'][] = _T('erreur_plugin_attribut_balise_manquant', |
|
| 157 | + array('attribut' => 'id', 'balise' => $att)); |
|
| 158 | + } |
|
| 159 | + } else { |
|
| 160 | + $necessite[] = $att; |
|
| 161 | + } |
|
| 162 | + if (strtolower($att['id']) == 'spip') { |
|
| 163 | + $spip_trouve = true; |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + if ($compat_spip and !$spip_trouve) { |
|
| 168 | + $necessite[] = array('id' => 'spip', 'version' => $compat_spip); |
|
| 169 | + } |
|
| 170 | + $arbre['necessite'] = $necessite; |
|
| 171 | + $utilise = array(); |
|
| 172 | + if (spip_xml_match_nodes(',^utilise,', $arbre, $uses)) { |
|
| 173 | + foreach (array_keys($uses) as $tag) { |
|
| 174 | + list($tag, $att) = spip_xml_decompose_tag($tag); |
|
| 175 | + if (!isset($att['id'])) { |
|
| 176 | + if (!$silence) { |
|
| 177 | + $arbre['erreur'][] = _T('erreur_plugin_attribut_balise_manquant', |
|
| 178 | + array('attribut' => 'id', 'balise' => $att)); |
|
| 179 | + } |
|
| 180 | + } else { |
|
| 181 | + $utilise[] = $att; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + $arbre['utilise'] = $utilise; |
|
| 186 | + $procure = array(); |
|
| 187 | + if (spip_xml_match_nodes(',^procure,', $arbre, $uses)) { |
|
| 188 | + foreach (array_keys($uses) as $tag) { |
|
| 189 | + list($tag, $att) = spip_xml_decompose_tag($tag); |
|
| 190 | + $procure[] = $att; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + $arbre['procure'] = $procure; |
|
| 194 | + $path = array(); |
|
| 195 | + if (spip_xml_match_nodes(',^chemin,', $arbre, $paths)) { |
|
| 196 | + foreach (array_keys($paths) as $tag) { |
|
| 197 | + list($tag, $att) = spip_xml_decompose_tag($tag); |
|
| 198 | + $att['path'] = $att['dir']; // ancienne syntaxe |
|
| 199 | + $path[] = $att; |
|
| 200 | + } |
|
| 201 | + } else { |
|
| 202 | + $path = array(array('dir' => '')); |
|
| 203 | + } // initialiser par defaut |
|
| 204 | + $arbre['path'] = $path; |
|
| 205 | + // exposer les noisettes |
|
| 206 | + if (isset($arbre['noisette'])) { |
|
| 207 | + foreach ($arbre['noisette'] as $k => $nut) { |
|
| 208 | + $nut = preg_replace(',[.]html$,uims', '', trim($nut)); |
|
| 209 | + $arbre['noisette'][$k] = $nut; |
|
| 210 | + if (!@is_readable($dir_plugins . "$plug/$nut.html")) { |
|
| 211 | + if (!$silence) { |
|
| 212 | + $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : $nut"; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + $traduire = array(); |
|
| 218 | + if (spip_xml_match_nodes(',^traduire,', $arbre, $trads)) { |
|
| 219 | + foreach (array_keys($trads) as $tag) { |
|
| 220 | + list($tag, $att) = spip_xml_decompose_tag($tag); |
|
| 221 | + $traduire[] = $att; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + $arbre['traduire'] = $traduire; |
|
| 225 | + } |
|
| 226 | 226 | } |
@@ -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 | /** |
@@ -21,30 +21,30 @@ discard block |
||
| 21 | 21 | * @return <type> |
| 22 | 22 | */ |
| 23 | 23 | function plugins_extraire_boutons_dist($arbre) { |
| 24 | - $ret = array('bouton' => array(), 'onglet' => array()); |
|
| 25 | - // recuperer les boutons et onglets si necessaire |
|
| 26 | - spip_xml_match_nodes(",^(bouton|onglet)\s,", $arbre, $les_boutons); |
|
| 27 | - if (is_array($les_boutons) && count($les_boutons)) { |
|
| 28 | - $ret['bouton'] = array(); |
|
| 29 | - $ret['onglet'] = array(); |
|
| 30 | - foreach ($les_boutons as $bouton => $val) { |
|
| 31 | - $bouton = spip_xml_decompose_tag($bouton); |
|
| 32 | - $type = reset($bouton); |
|
| 33 | - $bouton = end($bouton); |
|
| 34 | - if (isset($bouton['id'])) { |
|
| 35 | - $id = $bouton['id']; |
|
| 36 | - $val = reset($val); |
|
| 37 | - if (is_array($val)) { |
|
| 38 | - $ret[$type][$id]['parent'] = isset($bouton['parent']) ? $bouton['parent'] : ''; |
|
| 39 | - $ret[$type][$id]['position'] = isset($bouton['position']) ? $bouton['position'] : ''; |
|
| 40 | - $ret[$type][$id]['titre'] = isset($val['titre']) ? trim(spip_xml_aplatit($val['titre'])) : ''; |
|
| 41 | - $ret[$type][$id]['icone'] = isset($val['icone']) ? trim(end($val['icone'])) : ''; |
|
| 42 | - $ret[$type][$id]['action'] = isset($val['url']) ? trim(end($val['url'])) : ''; |
|
| 43 | - $ret[$type][$id]['parametres'] = isset($val['args']) ? trim(end($val['args'])) : ''; |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 24 | + $ret = array('bouton' => array(), 'onglet' => array()); |
|
| 25 | + // recuperer les boutons et onglets si necessaire |
|
| 26 | + spip_xml_match_nodes(",^(bouton|onglet)\s,", $arbre, $les_boutons); |
|
| 27 | + if (is_array($les_boutons) && count($les_boutons)) { |
|
| 28 | + $ret['bouton'] = array(); |
|
| 29 | + $ret['onglet'] = array(); |
|
| 30 | + foreach ($les_boutons as $bouton => $val) { |
|
| 31 | + $bouton = spip_xml_decompose_tag($bouton); |
|
| 32 | + $type = reset($bouton); |
|
| 33 | + $bouton = end($bouton); |
|
| 34 | + if (isset($bouton['id'])) { |
|
| 35 | + $id = $bouton['id']; |
|
| 36 | + $val = reset($val); |
|
| 37 | + if (is_array($val)) { |
|
| 38 | + $ret[$type][$id]['parent'] = isset($bouton['parent']) ? $bouton['parent'] : ''; |
|
| 39 | + $ret[$type][$id]['position'] = isset($bouton['position']) ? $bouton['position'] : ''; |
|
| 40 | + $ret[$type][$id]['titre'] = isset($val['titre']) ? trim(spip_xml_aplatit($val['titre'])) : ''; |
|
| 41 | + $ret[$type][$id]['icone'] = isset($val['icone']) ? trim(end($val['icone'])) : ''; |
|
| 42 | + $ret[$type][$id]['action'] = isset($val['url']) ? trim(end($val['url'])) : ''; |
|
| 43 | + $ret[$type][$id]['parametres'] = isset($val['args']) ? trim(end($val['args'])) : ''; |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return $ret; |
|
| 49 | + return $ret; |
|
| 50 | 50 | } |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | $plug = $liste_plugins[$key]; |
| 59 | 59 | $actif = @isset($fast_liste_plugins_actifs[$plug]); |
| 60 | 60 | $id = substr(md5($plug), 0, 16); |
| 61 | - $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | - 'menu-entree') . "\n"; |
|
| 61 | + $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE.$plug), $actif, |
|
| 62 | + 'menu-entree')."\n"; |
|
| 63 | 63 | unset($liste_plugins[$key]); |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -101,12 +101,12 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | $chemin = ""; |
| 103 | 103 | if (count($tcom)) { |
| 104 | - $chemin .= implode("/", $tcom) . "/"; |
|
| 104 | + $chemin .= implode("/", $tcom)."/"; |
|
| 105 | 105 | } |
| 106 | 106 | // ouvrir les repertoires jusqu'a la cible |
| 107 | 107 | while ($open = array_shift($ttarg)) { |
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . "/"; |
|
| 108 | + $visible = @isset($deplie[$chemin.$open]); |
|
| 109 | + $chemin .= $open."/"; |
|
| 110 | 110 | $output .= "<li>"; |
| 111 | 111 | $output .= bouton_block_depliable($chemin, $visible); |
| 112 | 112 | $output .= debut_block_depliable($visible); |
@@ -75,11 +75,19 @@ |
||
| 75 | 75 | // vraiment n'importe quoi la gestion des chemins des plugins |
| 76 | 76 | // une fonction pour aider... |
| 77 | 77 | // https://code.spip.net/@chemin_plug |
| 78 | +/** |
|
| 79 | + * @param string $racine |
|
| 80 | + * |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 78 | 83 | function chemin_plug($racine, $plug) { |
| 79 | 84 | return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
| 80 | 85 | } |
| 81 | 86 | |
| 82 | 87 | // https://code.spip.net/@tree_open_close_dir |
| 88 | +/** |
|
| 89 | + * @param string $target |
|
| 90 | + */ |
|
| 83 | 91 | function tree_open_close_dir(&$current, $target, $deplie = array()) { |
| 84 | 92 | if ($current == $target) { |
| 85 | 93 | return ""; |
@@ -11,64 +11,64 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // https://code.spip.net/@affiche_arbre_plugins |
| 18 | 18 | function plugins_afficher_repertoires_dist($url_page, $liste_plugins, $liste_plugins_actifs) { |
| 19 | - $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 20 | - $racine = basename(_DIR_PLUGINS); |
|
| 21 | - $init_dir = $current_dir = ""; |
|
| 22 | - // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 23 | - // des qu'un path est deja note deplie on s'arrete |
|
| 24 | - $deplie = array($racine => true); |
|
| 25 | - $fast_liste_plugins_actifs = array(); |
|
| 26 | - foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 27 | - $chemin_plug = chemin_plug($racine, $plug); |
|
| 28 | - $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 29 | - $dir = dirname($chemin_plug); |
|
| 30 | - $maxiter = 100; |
|
| 31 | - while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) { |
|
| 32 | - $deplie[$dir] = true; |
|
| 33 | - $dir = dirname($dir); |
|
| 34 | - } |
|
| 35 | - } |
|
| 19 | + $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 20 | + $racine = basename(_DIR_PLUGINS); |
|
| 21 | + $init_dir = $current_dir = ""; |
|
| 22 | + // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 23 | + // des qu'un path est deja note deplie on s'arrete |
|
| 24 | + $deplie = array($racine => true); |
|
| 25 | + $fast_liste_plugins_actifs = array(); |
|
| 26 | + foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 27 | + $chemin_plug = chemin_plug($racine, $plug); |
|
| 28 | + $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 29 | + $dir = dirname($chemin_plug); |
|
| 30 | + $maxiter = 100; |
|
| 31 | + while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) { |
|
| 32 | + $deplie[$dir] = true; |
|
| 33 | + $dir = dirname($dir); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - // index repertoires --> plugin |
|
| 38 | - $dir_index = array(); |
|
| 39 | - foreach ($liste_plugins as $key => $plug) { |
|
| 40 | - $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 41 | - $dir_index[dirname($liste_plugins[$key])][] = $key; |
|
| 42 | - } |
|
| 37 | + // index repertoires --> plugin |
|
| 38 | + $dir_index = array(); |
|
| 39 | + foreach ($liste_plugins as $key => $plug) { |
|
| 40 | + $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 41 | + $dir_index[dirname($liste_plugins[$key])][] = $key; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $visible = @isset($deplie[$current_dir]); |
|
| 45 | - $maxiter = 1000; |
|
| 44 | + $visible = @isset($deplie[$current_dir]); |
|
| 45 | + $maxiter = 1000; |
|
| 46 | 46 | |
| 47 | - $res = ''; |
|
| 48 | - while (count($liste_plugins) && $maxiter--) { |
|
| 49 | - // le rep suivant |
|
| 50 | - $dir = dirname(reset($liste_plugins)); |
|
| 51 | - if ($dir != $current_dir) { |
|
| 52 | - $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 53 | - } |
|
| 47 | + $res = ''; |
|
| 48 | + while (count($liste_plugins) && $maxiter--) { |
|
| 49 | + // le rep suivant |
|
| 50 | + $dir = dirname(reset($liste_plugins)); |
|
| 51 | + if ($dir != $current_dir) { |
|
| 52 | + $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - // d'abord tous les plugins du rep courant |
|
| 56 | - if (isset($dir_index[$current_dir])) { |
|
| 57 | - foreach ($dir_index[$current_dir] as $key) { |
|
| 58 | - $plug = $liste_plugins[$key]; |
|
| 59 | - $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 60 | - $id = substr(md5($plug), 0, 16); |
|
| 61 | - $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | - 'menu-entree') . "\n"; |
|
| 63 | - unset($liste_plugins[$key]); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 55 | + // d'abord tous les plugins du rep courant |
|
| 56 | + if (isset($dir_index[$current_dir])) { |
|
| 57 | + foreach ($dir_index[$current_dir] as $key) { |
|
| 58 | + $plug = $liste_plugins[$key]; |
|
| 59 | + $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 60 | + $id = substr(md5($plug), 0, 16); |
|
| 61 | + $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | + 'menu-entree') . "\n"; |
|
| 63 | + unset($liste_plugins[$key]); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 68 | 68 | |
| 69 | - return "<ul class='menu-liste plugins'>" |
|
| 70 | - . $res |
|
| 71 | - . "</ul>"; |
|
| 69 | + return "<ul class='menu-liste plugins'>" |
|
| 70 | + . $res |
|
| 71 | + . "</ul>"; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
@@ -76,44 +76,44 @@ discard block |
||
| 76 | 76 | // une fonction pour aider... |
| 77 | 77 | // https://code.spip.net/@chemin_plug |
| 78 | 78 | function chemin_plug($racine, $plug) { |
| 79 | - return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 79 | + return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // https://code.spip.net/@tree_open_close_dir |
| 83 | 83 | function tree_open_close_dir(&$current, $target, $deplie = array()) { |
| 84 | - if ($current == $target) { |
|
| 85 | - return ""; |
|
| 86 | - } |
|
| 87 | - $tcur = explode("/", $current); |
|
| 88 | - $ttarg = explode("/", $target); |
|
| 89 | - $tcom = array(); |
|
| 90 | - $output = ""; |
|
| 91 | - // la partie commune |
|
| 92 | - while (reset($tcur) == reset($ttarg)) { |
|
| 93 | - $tcom[] = array_shift($tcur); |
|
| 94 | - array_shift($ttarg); |
|
| 95 | - } |
|
| 96 | - // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | - while ($close = array_pop($tcur)) { |
|
| 98 | - $output .= "</ul>\n"; |
|
| 99 | - $output .= fin_block(); |
|
| 100 | - $output .= "</li>\n"; |
|
| 101 | - } |
|
| 102 | - $chemin = ""; |
|
| 103 | - if (count($tcom)) { |
|
| 104 | - $chemin .= implode("/", $tcom) . "/"; |
|
| 105 | - } |
|
| 106 | - // ouvrir les repertoires jusqu'a la cible |
|
| 107 | - while ($open = array_shift($ttarg)) { |
|
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . "/"; |
|
| 110 | - $output .= "<li>"; |
|
| 111 | - $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | - $output .= debut_block_depliable($visible); |
|
| 84 | + if ($current == $target) { |
|
| 85 | + return ""; |
|
| 86 | + } |
|
| 87 | + $tcur = explode("/", $current); |
|
| 88 | + $ttarg = explode("/", $target); |
|
| 89 | + $tcom = array(); |
|
| 90 | + $output = ""; |
|
| 91 | + // la partie commune |
|
| 92 | + while (reset($tcur) == reset($ttarg)) { |
|
| 93 | + $tcom[] = array_shift($tcur); |
|
| 94 | + array_shift($ttarg); |
|
| 95 | + } |
|
| 96 | + // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | + while ($close = array_pop($tcur)) { |
|
| 98 | + $output .= "</ul>\n"; |
|
| 99 | + $output .= fin_block(); |
|
| 100 | + $output .= "</li>\n"; |
|
| 101 | + } |
|
| 102 | + $chemin = ""; |
|
| 103 | + if (count($tcom)) { |
|
| 104 | + $chemin .= implode("/", $tcom) . "/"; |
|
| 105 | + } |
|
| 106 | + // ouvrir les repertoires jusqu'a la cible |
|
| 107 | + while ($open = array_shift($ttarg)) { |
|
| 108 | + $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | + $chemin .= $open . "/"; |
|
| 110 | + $output .= "<li>"; |
|
| 111 | + $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | + $output .= debut_block_depliable($visible); |
|
| 113 | 113 | |
| 114 | - $output .= "<ul>\n"; |
|
| 115 | - } |
|
| 116 | - $current = $target; |
|
| 114 | + $output .= "<ul>\n"; |
|
| 115 | + } |
|
| 116 | + $current = $target; |
|
| 117 | 117 | |
| 118 | - return $output; |
|
| 118 | + return $output; |
|
| 119 | 119 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | asort($liste_plugins); |
| 65 | 65 | $exposed = urldecode(_request('plugin')); |
| 66 | 66 | |
| 67 | - $block_par_lettre = false;//count($liste_plugins)>10; |
|
| 67 | + $block_par_lettre = false; //count($liste_plugins)>10; |
|
| 68 | 68 | $fast_liste_plugins_actifs = array(); |
| 69 | 69 | $fast_liste_plugins_checked = array(); |
| 70 | 70 | if (is_array($liste_plugins_actifs)) { |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | $actif = isset($fast_liste_plugins_actifs[$plug]); |
| 90 | 90 | $checked = isset($fast_liste_plugins_checked[$plug]); |
| 91 | 91 | $block_actif = $block_actif | $actif; |
| 92 | - $expose = ($exposed and ($exposed == $plug or $exposed == $dir_plugins . $plug or $exposed == substr($dir_plugins, |
|
| 93 | - strlen(_DIR_RACINE)) . $plug)); |
|
| 94 | - $block .= $ligne_plug($url_page, $plug, $checked, $actif, $expose, "item", $dir_plugins) . "\n"; |
|
| 92 | + $expose = ($exposed and ($exposed == $plug or $exposed == $dir_plugins.$plug or $exposed == substr($dir_plugins, |
|
| 93 | + strlen(_DIR_RACINE)).$plug)); |
|
| 94 | + $block .= $ligne_plug($url_page, $plug, $checked, $actif, $expose, "item", $dir_plugins)."\n"; |
|
| 95 | 95 | } |
| 96 | 96 | $res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block; |
| 97 | 97 | $class = basename($dir_plugins); |
@@ -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 | include_spip('inc/charsets'); |
| 17 | 17 | |
@@ -28,88 +28,88 @@ discard block |
||
| 28 | 28 | * @return string |
| 29 | 29 | */ |
| 30 | 30 | function plugins_afficher_liste_dist( |
| 31 | - $url_page, |
|
| 32 | - $liste_plugins, |
|
| 33 | - $liste_plugins_checked, |
|
| 34 | - $liste_plugins_actifs, |
|
| 35 | - $dir_plugins = _DIR_PLUGINS, |
|
| 36 | - $afficher_un = 'afficher_plugin' |
|
| 31 | + $url_page, |
|
| 32 | + $liste_plugins, |
|
| 33 | + $liste_plugins_checked, |
|
| 34 | + $liste_plugins_actifs, |
|
| 35 | + $dir_plugins = _DIR_PLUGINS, |
|
| 36 | + $afficher_un = 'afficher_plugin' |
|
| 37 | 37 | ) { |
| 38 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 39 | - $ligne_plug = charger_fonction($afficher_un, 'plugins'); |
|
| 38 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 39 | + $ligne_plug = charger_fonction($afficher_un, 'plugins'); |
|
| 40 | 40 | |
| 41 | - $all_infos = $get_infos($liste_plugins, false, $dir_plugins); |
|
| 41 | + $all_infos = $get_infos($liste_plugins, false, $dir_plugins); |
|
| 42 | 42 | |
| 43 | - $all_infos = pipeline('filtrer_liste_plugins', |
|
| 44 | - array( |
|
| 45 | - 'args' => array( |
|
| 46 | - 'liste_plugins' => $liste_plugins, |
|
| 47 | - 'liste_plugins_checked' => $liste_plugins_checked, |
|
| 48 | - 'liste_plugins_actifs' => $liste_plugins_actifs, |
|
| 49 | - 'dir_plugins' => $dir_plugins |
|
| 50 | - ), |
|
| 51 | - 'data' => $all_infos |
|
| 52 | - ) |
|
| 53 | - ); |
|
| 43 | + $all_infos = pipeline('filtrer_liste_plugins', |
|
| 44 | + array( |
|
| 45 | + 'args' => array( |
|
| 46 | + 'liste_plugins' => $liste_plugins, |
|
| 47 | + 'liste_plugins_checked' => $liste_plugins_checked, |
|
| 48 | + 'liste_plugins_actifs' => $liste_plugins_actifs, |
|
| 49 | + 'dir_plugins' => $dir_plugins |
|
| 50 | + ), |
|
| 51 | + 'data' => $all_infos |
|
| 52 | + ) |
|
| 53 | + ); |
|
| 54 | 54 | |
| 55 | - $liste_plugins = array_flip($liste_plugins); |
|
| 56 | - foreach ($liste_plugins as $chemin => $v) { |
|
| 57 | - // des plugins ont pu etre enleves de la liste par le pipeline. On en tient compte. |
|
| 58 | - if (isset($all_infos[$chemin])) { |
|
| 59 | - $liste_plugins[$chemin] = strtoupper(trim(typo(translitteration(unicode2charset(html2unicode($all_infos[$chemin]['nom'])))))); |
|
| 60 | - } else { |
|
| 61 | - unset($liste_plugins[$chemin]); |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - asort($liste_plugins); |
|
| 65 | - $exposed = urldecode(_request('plugin')); |
|
| 55 | + $liste_plugins = array_flip($liste_plugins); |
|
| 56 | + foreach ($liste_plugins as $chemin => $v) { |
|
| 57 | + // des plugins ont pu etre enleves de la liste par le pipeline. On en tient compte. |
|
| 58 | + if (isset($all_infos[$chemin])) { |
|
| 59 | + $liste_plugins[$chemin] = strtoupper(trim(typo(translitteration(unicode2charset(html2unicode($all_infos[$chemin]['nom'])))))); |
|
| 60 | + } else { |
|
| 61 | + unset($liste_plugins[$chemin]); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + asort($liste_plugins); |
|
| 65 | + $exposed = urldecode(_request('plugin')); |
|
| 66 | 66 | |
| 67 | - $block_par_lettre = false;//count($liste_plugins)>10; |
|
| 68 | - $fast_liste_plugins_actifs = array(); |
|
| 69 | - $fast_liste_plugins_checked = array(); |
|
| 70 | - if (is_array($liste_plugins_actifs)) { |
|
| 71 | - $fast_liste_plugins_actifs = array_flip($liste_plugins_actifs); |
|
| 72 | - } |
|
| 73 | - if (is_array($liste_plugins_checked)) { |
|
| 74 | - $fast_liste_plugins_checked = array_flip($liste_plugins_checked); |
|
| 75 | - } |
|
| 67 | + $block_par_lettre = false;//count($liste_plugins)>10; |
|
| 68 | + $fast_liste_plugins_actifs = array(); |
|
| 69 | + $fast_liste_plugins_checked = array(); |
|
| 70 | + if (is_array($liste_plugins_actifs)) { |
|
| 71 | + $fast_liste_plugins_actifs = array_flip($liste_plugins_actifs); |
|
| 72 | + } |
|
| 73 | + if (is_array($liste_plugins_checked)) { |
|
| 74 | + $fast_liste_plugins_checked = array_flip($liste_plugins_checked); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - $res = ''; |
|
| 78 | - $block = ''; |
|
| 79 | - $initiale = ''; |
|
| 80 | - $block_actif = false; |
|
| 81 | - foreach ($liste_plugins as $plug => $nom) { |
|
| 82 | - if (($i = substr($nom, 0, 1)) !== $initiale) { |
|
| 83 | - $res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block; |
|
| 84 | - $initiale = $i; |
|
| 85 | - $block = ''; |
|
| 86 | - $block_actif = false; |
|
| 87 | - } |
|
| 88 | - // le rep suivant |
|
| 89 | - $actif = isset($fast_liste_plugins_actifs[$plug]); |
|
| 90 | - $checked = isset($fast_liste_plugins_checked[$plug]); |
|
| 91 | - $block_actif = $block_actif | $actif; |
|
| 92 | - $expose = ($exposed and ($exposed == $plug or $exposed == $dir_plugins . $plug or $exposed == substr($dir_plugins, |
|
| 93 | - strlen(_DIR_RACINE)) . $plug)); |
|
| 94 | - $block .= $ligne_plug($url_page, $plug, $checked, $actif, $expose, "item", $dir_plugins) . "\n"; |
|
| 95 | - } |
|
| 96 | - $res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block; |
|
| 97 | - $class = basename($dir_plugins); |
|
| 77 | + $res = ''; |
|
| 78 | + $block = ''; |
|
| 79 | + $initiale = ''; |
|
| 80 | + $block_actif = false; |
|
| 81 | + foreach ($liste_plugins as $plug => $nom) { |
|
| 82 | + if (($i = substr($nom, 0, 1)) !== $initiale) { |
|
| 83 | + $res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block; |
|
| 84 | + $initiale = $i; |
|
| 85 | + $block = ''; |
|
| 86 | + $block_actif = false; |
|
| 87 | + } |
|
| 88 | + // le rep suivant |
|
| 89 | + $actif = isset($fast_liste_plugins_actifs[$plug]); |
|
| 90 | + $checked = isset($fast_liste_plugins_checked[$plug]); |
|
| 91 | + $block_actif = $block_actif | $actif; |
|
| 92 | + $expose = ($exposed and ($exposed == $plug or $exposed == $dir_plugins . $plug or $exposed == substr($dir_plugins, |
|
| 93 | + strlen(_DIR_RACINE)) . $plug)); |
|
| 94 | + $block .= $ligne_plug($url_page, $plug, $checked, $actif, $expose, "item", $dir_plugins) . "\n"; |
|
| 95 | + } |
|
| 96 | + $res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block; |
|
| 97 | + $class = basename($dir_plugins); |
|
| 98 | 98 | |
| 99 | - return $res ? "<ul class='liste-items plugins $class'>$res</ul>" : ""; |
|
| 99 | + return $res ? "<ul class='liste-items plugins $class'>$res</ul>" : ""; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | 103 | // https://code.spip.net/@affiche_block_initiale |
| 104 | 104 | function affiche_block_initiale($initiale, $block, $block_actif) { |
| 105 | - if (strlen($block)) { |
|
| 106 | - return "<li class='item'>" |
|
| 107 | - . bouton_block_depliable($initiale, $block_actif ? true : false) |
|
| 108 | - . debut_block_depliable($block_actif) |
|
| 109 | - . "<ul>$block</ul>" |
|
| 110 | - . fin_block() |
|
| 111 | - . "</li>"; |
|
| 112 | - } |
|
| 105 | + if (strlen($block)) { |
|
| 106 | + return "<li class='item'>" |
|
| 107 | + . bouton_block_depliable($initiale, $block_actif ? true : false) |
|
| 108 | + . debut_block_depliable($block_actif) |
|
| 109 | + . "<ul>$block</ul>" |
|
| 110 | + . fin_block() |
|
| 111 | + . "</li>"; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - return ""; |
|
| 114 | + return ""; |
|
| 115 | 115 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | # attention toutefois seuls '' et '=' figurent dans les modes de compatibilite |
| 24 | 24 | define('_separateur_urls_page', ''); |
| 25 | 25 | # on peut indiquer '' si on a installe le .htaccess |
| 26 | -define('_debut_urls_page', get_spip_script('./') . '?'); |
|
| 26 | +define('_debut_urls_page', get_spip_script('./').'?'); |
|
| 27 | 27 | ####### |
| 28 | 28 | |
| 29 | 29 | |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - $url = _debut_urls_page . $type . _separateur_urls_page |
|
| 41 | - . $id . _terminaison_urls_page; |
|
| 40 | + $url = _debut_urls_page.$type._separateur_urls_page |
|
| 41 | + . $id._terminaison_urls_page; |
|
| 42 | 42 | |
| 43 | 43 | if ($args) { |
| 44 | 44 | $args = strpos($url, '?') ? "&$args" : "?$args"; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : ''); |
|
| 47 | + return _DIR_RACINE.$url.$args.($ancre ? "#$ancre" : ''); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // retrouve le fond et les parametres d'une URL abregee |
@@ -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 | define('URLS_PAGE_EXEMPLE', 'spip.php?article12'); |
@@ -30,74 +30,74 @@ discard block |
||
| 30 | 30 | // https://code.spip.net/@_generer_url_page |
| 31 | 31 | function _generer_url_page($type, $id, $args = '', $ancre = '') { |
| 32 | 32 | |
| 33 | - if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls', true)) { |
|
| 34 | - $url = $generer_url_externe($id, $args, $ancre); |
|
| 35 | - if (null != $url) { |
|
| 36 | - return $url; |
|
| 37 | - } |
|
| 38 | - } |
|
| 33 | + if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls', true)) { |
|
| 34 | + $url = $generer_url_externe($id, $args, $ancre); |
|
| 35 | + if (null != $url) { |
|
| 36 | + return $url; |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - $url = _debut_urls_page . $type . _separateur_urls_page |
|
| 41 | - . $id . _terminaison_urls_page; |
|
| 40 | + $url = _debut_urls_page . $type . _separateur_urls_page |
|
| 41 | + . $id . _terminaison_urls_page; |
|
| 42 | 42 | |
| 43 | - if ($args) { |
|
| 44 | - $args = strpos($url, '?') ? "&$args" : "?$args"; |
|
| 45 | - } |
|
| 43 | + if ($args) { |
|
| 44 | + $args = strpos($url, '?') ? "&$args" : "?$args"; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : ''); |
|
| 47 | + return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : ''); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // retrouve le fond et les parametres d'une URL abregee |
| 51 | 51 | // le contexte deja existant est fourni dans args sous forme de tableau ou query string |
| 52 | 52 | // https://code.spip.net/@urls_page_dist |
| 53 | 53 | function urls_page_dist($i, &$entite, $args = '', $ancre = '') { |
| 54 | - if (is_numeric($i)) { |
|
| 55 | - return _generer_url_page($entite, $i, $args, $ancre); |
|
| 56 | - } |
|
| 54 | + if (is_numeric($i)) { |
|
| 55 | + return _generer_url_page($entite, $i, $args, $ancre); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23 |
|
| 59 | - if ($GLOBALS['profondeur_url'] > 0 and $entite == 'sommaire') { |
|
| 60 | - return array(array(), '404'); |
|
| 61 | - } |
|
| 58 | + // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23 |
|
| 59 | + if ($GLOBALS['profondeur_url'] > 0 and $entite == 'sommaire') { |
|
| 60 | + return array(array(), '404'); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - // voir s'il faut recuperer le id_* implicite et les &debut_xx; |
|
| 64 | - if (is_array($args)) { |
|
| 65 | - $contexte = $args; |
|
| 66 | - } else { |
|
| 67 | - parse_str($args, $contexte); |
|
| 68 | - } |
|
| 69 | - include_spip('inc/urls'); |
|
| 70 | - $r = nettoyer_url_page($i, $contexte); |
|
| 71 | - if ($r) { |
|
| 72 | - array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici |
|
| 73 | - return $r; |
|
| 74 | - } |
|
| 63 | + // voir s'il faut recuperer le id_* implicite et les &debut_xx; |
|
| 64 | + if (is_array($args)) { |
|
| 65 | + $contexte = $args; |
|
| 66 | + } else { |
|
| 67 | + parse_str($args, $contexte); |
|
| 68 | + } |
|
| 69 | + include_spip('inc/urls'); |
|
| 70 | + $r = nettoyer_url_page($i, $contexte); |
|
| 71 | + if ($r) { |
|
| 72 | + array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici |
|
| 73 | + return $r; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /* |
|
| 76 | + /* |
|
| 77 | 77 | * Le bloc qui suit sert a faciliter les transitions depuis |
| 78 | 78 | * le mode 'urls-propres' vers les modes 'urls-standard' et 'url-html' |
| 79 | 79 | * Il est inutile de le recopier si vous personnalisez vos URLs |
| 80 | 80 | * et votre .htaccess |
| 81 | 81 | */ |
| 82 | - // Si on est revenu en mode html, mais c'est une ancienne url_propre |
|
| 83 | - // on ne redirige pas, on assume le nouveau contexte (si possible) |
|
| 84 | - $url = $i; |
|
| 85 | - $url_propre = isset($url) |
|
| 86 | - ? $url |
|
| 87 | - : (isset($_SERVER['REDIRECT_url_propre']) |
|
| 88 | - ? $_SERVER['REDIRECT_url_propre'] |
|
| 89 | - : (isset($_ENV['url_propre']) |
|
| 90 | - ? $_ENV['url_propre'] |
|
| 91 | - : '' |
|
| 92 | - )); |
|
| 93 | - if ($url_propre) { |
|
| 94 | - if ($GLOBALS['profondeur_url'] <= 0) { |
|
| 95 | - $urls_anciennes = charger_fonction('propres', 'urls', true); |
|
| 96 | - } else { |
|
| 97 | - $urls_anciennes = charger_fonction('arbo', 'urls', true); |
|
| 98 | - } |
|
| 82 | + // Si on est revenu en mode html, mais c'est une ancienne url_propre |
|
| 83 | + // on ne redirige pas, on assume le nouveau contexte (si possible) |
|
| 84 | + $url = $i; |
|
| 85 | + $url_propre = isset($url) |
|
| 86 | + ? $url |
|
| 87 | + : (isset($_SERVER['REDIRECT_url_propre']) |
|
| 88 | + ? $_SERVER['REDIRECT_url_propre'] |
|
| 89 | + : (isset($_ENV['url_propre']) |
|
| 90 | + ? $_ENV['url_propre'] |
|
| 91 | + : '' |
|
| 92 | + )); |
|
| 93 | + if ($url_propre) { |
|
| 94 | + if ($GLOBALS['profondeur_url'] <= 0) { |
|
| 95 | + $urls_anciennes = charger_fonction('propres', 'urls', true); |
|
| 96 | + } else { |
|
| 97 | + $urls_anciennes = charger_fonction('arbo', 'urls', true); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - return $urls_anciennes ? $urls_anciennes($url_propre, $entite, $contexte) : ''; |
|
| 101 | - } |
|
| 102 | - /* Fin du bloc compatibilite url-propres */ |
|
| 100 | + return $urls_anciennes ? $urls_anciennes($url_propre, $entite, $contexte) : ''; |
|
| 101 | + } |
|
| 102 | + /* Fin du bloc compatibilite url-propres */ |
|
| 103 | 103 | } |
@@ -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 | define('_REGEXP_DOCTYPE', |
@@ -33,14 +33,14 @@ discard block |
||
| 33 | 33 | define('_REGEXP_ENTITY_DEF', '/^%(' . _SUB_REGEXP_SYMBOL . '+);/'); |
| 34 | 34 | define('_REGEXP_TYPE_XML', 'PUBLIC|SYSTEM|INCLUDE|IGNORE|CDATA'); |
| 35 | 35 | define('_REGEXP_ENTITY_DECL', '/^<!ENTITY\s+(%?)\s*(' . |
| 36 | - _SUB_REGEXP_SYMBOL . |
|
| 37 | - '+;?)\s+(' . |
|
| 38 | - _REGEXP_TYPE_XML . |
|
| 39 | - ')?\s*(' . |
|
| 40 | - "('([^']*)')" . |
|
| 41 | - '|("([^"]*)")' . |
|
| 42 | - '|\s*(%' . _SUB_REGEXP_SYMBOL . '+;)\s*' . |
|
| 43 | - ')\s*(--.*?--)?("([^"]*)")?\s*>\s*(.*)$/s'); |
|
| 36 | + _SUB_REGEXP_SYMBOL . |
|
| 37 | + '+;?)\s+(' . |
|
| 38 | + _REGEXP_TYPE_XML . |
|
| 39 | + ')?\s*(' . |
|
| 40 | + "('([^']*)')" . |
|
| 41 | + '|("([^"]*)")' . |
|
| 42 | + '|\s*(%' . _SUB_REGEXP_SYMBOL . '+;)\s*' . |
|
| 43 | + ')\s*(--.*?--)?("([^"]*)")?\s*>\s*(.*)$/s'); |
|
| 44 | 44 | |
| 45 | 45 | define('_REGEXP_INCLUDE_USE', '/^<!\[\s*%\s*([^;]*);\s*\[\s*(.*)$/s'); |
| 46 | 46 | |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | * Document Type Compilation |
| 51 | 51 | **/ |
| 52 | 52 | class DTC { |
| 53 | - public $macros = array(); |
|
| 54 | - public $elements = array(); |
|
| 55 | - public $peres = array(); |
|
| 56 | - public $attributs = array(); |
|
| 57 | - public $entites = array(); |
|
| 58 | - public $regles = array(); |
|
| 59 | - public $pcdata = array(); |
|
| 53 | + public $macros = array(); |
|
| 54 | + public $elements = array(); |
|
| 55 | + public $peres = array(); |
|
| 56 | + public $attributs = array(); |
|
| 57 | + public $entites = array(); |
|
| 58 | + public $regles = array(); |
|
| 59 | + public $pcdata = array(); |
|
| 60 | 60 | } |
@@ -23,23 +23,23 @@ |
||
| 23 | 23 | |
| 24 | 24 | define('_SUB_REGEXP_SYMBOL', '[\w_:.-]'); |
| 25 | 25 | |
| 26 | -define('_REGEXP_NMTOKEN', '/^' . _SUB_REGEXP_SYMBOL . '+$/'); |
|
| 26 | +define('_REGEXP_NMTOKEN', '/^'._SUB_REGEXP_SYMBOL.'+$/'); |
|
| 27 | 27 | |
| 28 | -define('_REGEXP_NMTOKENS', '/^(' . _SUB_REGEXP_SYMBOL . '+\s*)*$/'); |
|
| 28 | +define('_REGEXP_NMTOKENS', '/^('._SUB_REGEXP_SYMBOL.'+\s*)*$/'); |
|
| 29 | 29 | |
| 30 | -define('_REGEXP_ID', '/^[A-Za-z_:]' . _SUB_REGEXP_SYMBOL . '*$/'); |
|
| 30 | +define('_REGEXP_ID', '/^[A-Za-z_:]'._SUB_REGEXP_SYMBOL.'*$/'); |
|
| 31 | 31 | |
| 32 | -define('_REGEXP_ENTITY_USE', '/%(' . _SUB_REGEXP_SYMBOL . '+);/'); |
|
| 33 | -define('_REGEXP_ENTITY_DEF', '/^%(' . _SUB_REGEXP_SYMBOL . '+);/'); |
|
| 32 | +define('_REGEXP_ENTITY_USE', '/%('._SUB_REGEXP_SYMBOL.'+);/'); |
|
| 33 | +define('_REGEXP_ENTITY_DEF', '/^%('._SUB_REGEXP_SYMBOL.'+);/'); |
|
| 34 | 34 | define('_REGEXP_TYPE_XML', 'PUBLIC|SYSTEM|INCLUDE|IGNORE|CDATA'); |
| 35 | -define('_REGEXP_ENTITY_DECL', '/^<!ENTITY\s+(%?)\s*(' . |
|
| 36 | - _SUB_REGEXP_SYMBOL . |
|
| 37 | - '+;?)\s+(' . |
|
| 38 | - _REGEXP_TYPE_XML . |
|
| 39 | - ')?\s*(' . |
|
| 40 | - "('([^']*)')" . |
|
| 41 | - '|("([^"]*)")' . |
|
| 42 | - '|\s*(%' . _SUB_REGEXP_SYMBOL . '+;)\s*' . |
|
| 35 | +define('_REGEXP_ENTITY_DECL', '/^<!ENTITY\s+(%?)\s*('. |
|
| 36 | + _SUB_REGEXP_SYMBOL. |
|
| 37 | + '+;?)\s+('. |
|
| 38 | + _REGEXP_TYPE_XML. |
|
| 39 | + ')?\s*('. |
|
| 40 | + "('([^']*)')". |
|
| 41 | + '|("([^"]*)")'. |
|
| 42 | + '|\s*(%'._SUB_REGEXP_SYMBOL.'+;)\s*'. |
|
| 43 | 43 | ')\s*(--.*?--)?("([^"]*)")?\s*>\s*(.*)$/s'); |
| 44 | 44 | |
| 45 | 45 | define('_REGEXP_INCLUDE_USE', '/^<!\[\s*%\s*([^;]*);\s*\[\s*(.*)$/s'); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | $grammaire = find_in_path($grammaire); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 31 | + $file = _DIR_CACHE_XML.preg_replace('/[^\w.]/', '_', $rotlvl).'.gz'; |
|
| 32 | 32 | |
| 33 | 33 | if (lire_fichier($file, $r)) { |
| 34 | 34 | if (!$grammaire) { |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $dtc->peres[$k] = $v; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ") " . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . " entites"); |
|
| 58 | + spip_log("Analyser DTD $avail $grammaire (".spip_timer('dtd').") ".count($dtc->macros).' macros, '.count($dtc->elements).' elements, '.count($dtc->attributs)." listes d'attributs, ".count($dtc->entites)." entites"); |
|
| 59 | 59 | # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
| 60 | 60 | ecrire_fichier($file, serialize($dtc), true); |
| 61 | 61 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | if (!is_string($r)) { |
| 159 | - spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . "....."); |
|
| 159 | + spip_log("erreur $r dans la DTD ".substr($dtd, 0, 80)."....."); |
|
| 160 | 160 | |
| 161 | 161 | return false; |
| 162 | 162 | } |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | if (($n[0] == 'PUBLIC') |
| 204 | 204 | and !tester_url_absolue($n[1]) |
| 205 | 205 | ) { |
| 206 | - $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 206 | + $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1).$n[1]; |
|
| 207 | 207 | } |
| 208 | 208 | analyser_dtd($n[1], $n[0], $dtc); |
| 209 | 209 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | if ($dtc->macros[$m[1]] == 'INCLUDE') { |
| 230 | - $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 230 | + $retour = $r[1].substr($m[2], strlen($r[0])); |
|
| 231 | 231 | } else { |
| 232 | 232 | $retour = substr($m[2], strlen($r[0])); |
| 233 | 233 | } |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | spip_log("redefinition de l'entite $nom"); |
| 261 | 261 | } |
| 262 | 262 | if ($k6) { |
| 263 | - return $k6 . $dtd; |
|
| 263 | + return $k6.$dtd; |
|
| 264 | 264 | } // cas du synonyme complet |
| 265 | 265 | $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
| 266 | 266 | |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
| 367 | 367 | foreach ($r2 as $m2) { |
| 368 | 368 | $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
| 369 | - : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 369 | + : ('/^'.preg_replace('/\s+/', '', $m2[2]).'$/'); |
|
| 370 | 370 | $m21 = expanserEntite($m2[1], $dtc->macros); |
| 371 | 371 | $m25 = expanserEntite($m2[5], $dtc->macros); |
| 372 | 372 | $dtc->attributs[$nom][$m21] = array($v, $m25); |
@@ -167,6 +167,9 @@ discard block |
||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // https://code.spip.net/@analyser_dtd_comment |
| 170 | +/** |
|
| 171 | + * @param string $dtd |
|
| 172 | + */ |
|
| 170 | 173 | function analyser_dtd_comment($dtd, &$dtc, $grammaire) { |
| 171 | 174 | // ejecter les commentaires, surtout quand ils contiennent du code. |
| 172 | 175 | // Option /s car sur plusieurs lignes parfois |
@@ -179,6 +182,9 @@ discard block |
||
| 179 | 182 | } |
| 180 | 183 | |
| 181 | 184 | // https://code.spip.net/@analyser_dtd_pi |
| 185 | +/** |
|
| 186 | + * @param string $dtd |
|
| 187 | + */ |
|
| 182 | 188 | function analyser_dtd_pi($dtd, &$dtc, $grammaire) { |
| 183 | 189 | if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
| 184 | 190 | return -10; |
@@ -188,6 +194,9 @@ discard block |
||
| 188 | 194 | } |
| 189 | 195 | |
| 190 | 196 | // https://code.spip.net/@analyser_dtd_lexeme |
| 197 | +/** |
|
| 198 | + * @param string $dtd |
|
| 199 | + */ |
|
| 191 | 200 | function analyser_dtd_lexeme($dtd, &$dtc, $grammaire) { |
| 192 | 201 | |
| 193 | 202 | if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
@@ -215,6 +224,9 @@ discard block |
||
| 215 | 224 | // ca ne depasse pas 3 ici. |
| 216 | 225 | |
| 217 | 226 | // https://code.spip.net/@analyser_dtd_data |
| 227 | +/** |
|
| 228 | + * @param string $dtd |
|
| 229 | + */ |
|
| 218 | 230 | function analyser_dtd_data($dtd, &$dtc, $grammaire) { |
| 219 | 231 | |
| 220 | 232 | if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
@@ -236,6 +248,9 @@ discard block |
||
| 236 | 248 | } |
| 237 | 249 | |
| 238 | 250 | // https://code.spip.net/@analyser_dtd_notation |
| 251 | +/** |
|
| 252 | + * @param string $dtd |
|
| 253 | + */ |
|
| 239 | 254 | function analyser_dtd_notation($dtd, &$dtc, $grammaire) { |
| 240 | 255 | if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
| 241 | 256 | return -8; |
@@ -246,6 +261,9 @@ discard block |
||
| 246 | 261 | } |
| 247 | 262 | |
| 248 | 263 | // https://code.spip.net/@analyser_dtd_entity |
| 264 | +/** |
|
| 265 | + * @param string $dtd |
|
| 266 | + */ |
|
| 249 | 267 | function analyser_dtd_entity($dtd, &$dtc, $grammaire) { |
| 250 | 268 | if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
| 251 | 269 | return -2; |
@@ -303,6 +321,9 @@ discard block |
||
| 303 | 321 | // Fin du controle en finElement |
| 304 | 322 | |
| 305 | 323 | // https://code.spip.net/@analyser_dtd_element |
| 324 | +/** |
|
| 325 | + * @param string $dtd |
|
| 326 | + */ |
|
| 306 | 327 | function analyser_dtd_element($dtd, &$dtc, $grammaire) { |
| 307 | 328 | if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
| 308 | 329 | return -3; |
@@ -351,6 +372,9 @@ discard block |
||
| 351 | 372 | |
| 352 | 373 | |
| 353 | 374 | // https://code.spip.net/@analyser_dtd_attlist |
| 375 | +/** |
|
| 376 | + * @param string $dtd |
|
| 377 | + */ |
|
| 354 | 378 | function analyser_dtd_attlist($dtd, &$dtc, $grammaire) { |
| 355 | 379 | if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
| 356 | 380 | return -5; |
@@ -11,59 +11,59 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('xml/interfaces'); |
| 18 | 18 | |
| 19 | 19 | // https://code.spip.net/@charger_dtd |
| 20 | 20 | function charger_dtd($grammaire, $avail, $rotlvl) { |
| 21 | - static $dtd = array(); # cache bien utile pour le validateur en boucle |
|
| 22 | - |
|
| 23 | - if (isset($dtd[$grammaire])) { |
|
| 24 | - return $dtd[$grammaire]; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - if ($avail == 'SYSTEM') { |
|
| 28 | - $grammaire = find_in_path($grammaire); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | - |
|
| 33 | - if (lire_fichier($file, $r)) { |
|
| 34 | - if (!$grammaire) { |
|
| 35 | - return array(); |
|
| 36 | - } |
|
| 37 | - if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) { |
|
| 38 | - $r = false; |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - if ($r) { |
|
| 43 | - $dtc = unserialize($r); |
|
| 44 | - } else { |
|
| 45 | - spip_timer('dtd'); |
|
| 46 | - $dtc = new DTC; |
|
| 47 | - // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 48 | - // Retourner vide en cas d'echec |
|
| 49 | - if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 50 | - $dtc = array(); |
|
| 51 | - } else { |
|
| 52 | - // tri final pour presenter les suggestions de corrections |
|
| 53 | - foreach ($dtc->peres as $k => $v) { |
|
| 54 | - asort($v); |
|
| 55 | - $dtc->peres[$k] = $v; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ") " . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . " entites"); |
|
| 59 | - # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 60 | - ecrire_fichier($file, serialize($dtc), true); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - } |
|
| 64 | - $dtd[$grammaire] = $dtc; |
|
| 65 | - |
|
| 66 | - return $dtc; |
|
| 21 | + static $dtd = array(); # cache bien utile pour le validateur en boucle |
|
| 22 | + |
|
| 23 | + if (isset($dtd[$grammaire])) { |
|
| 24 | + return $dtd[$grammaire]; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + if ($avail == 'SYSTEM') { |
|
| 28 | + $grammaire = find_in_path($grammaire); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | + |
|
| 33 | + if (lire_fichier($file, $r)) { |
|
| 34 | + if (!$grammaire) { |
|
| 35 | + return array(); |
|
| 36 | + } |
|
| 37 | + if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) { |
|
| 38 | + $r = false; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + if ($r) { |
|
| 43 | + $dtc = unserialize($r); |
|
| 44 | + } else { |
|
| 45 | + spip_timer('dtd'); |
|
| 46 | + $dtc = new DTC; |
|
| 47 | + // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 48 | + // Retourner vide en cas d'echec |
|
| 49 | + if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 50 | + $dtc = array(); |
|
| 51 | + } else { |
|
| 52 | + // tri final pour presenter les suggestions de corrections |
|
| 53 | + foreach ($dtc->peres as $k => $v) { |
|
| 54 | + asort($v); |
|
| 55 | + $dtc->peres[$k] = $v; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ") " . count($dtc->macros) . ' macros, ' . count($dtc->elements) . ' elements, ' . count($dtc->attributs) . " listes d'attributs, " . count($dtc->entites) . " entites"); |
|
| 59 | + # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 60 | + ecrire_fichier($file, serialize($dtc), true); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + } |
|
| 64 | + $dtd[$grammaire] = $dtc; |
|
| 65 | + |
|
| 66 | + return $dtc; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | // Compiler une regle de production en une Regexp qu'on appliquera sur la |
@@ -76,139 +76,139 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | // https://code.spip.net/@compilerRegle |
| 78 | 78 | function compilerRegle($val) { |
| 79 | - $x = str_replace('()', '', |
|
| 80 | - preg_replace('/\s*,\s*/', '', |
|
| 81 | - preg_replace('/(\w+)\s*/', '(?:\1 )', |
|
| 82 | - preg_replace('/\s*\)/', ')', |
|
| 83 | - preg_replace('/\s*([(+*|?])\s*/', '\1', |
|
| 84 | - preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val)))))); |
|
| 85 | - |
|
| 86 | - return $x; |
|
| 79 | + $x = str_replace('()', '', |
|
| 80 | + preg_replace('/\s*,\s*/', '', |
|
| 81 | + preg_replace('/(\w+)\s*/', '(?:\1 )', |
|
| 82 | + preg_replace('/\s*\)/', ')', |
|
| 83 | + preg_replace('/\s*([(+*|?])\s*/', '\1', |
|
| 84 | + preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val)))))); |
|
| 85 | + |
|
| 86 | + return $x; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
| 90 | 90 | // https://code.spip.net/@analyser_dtd |
| 91 | 91 | function analyser_dtd($loc, $avail, &$dtc) { |
| 92 | - // creer le repertoire de cache si ce n'est fait |
|
| 93 | - // (utile aussi pour le resultat de la compil) |
|
| 94 | - $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 95 | - // si DTD locale, ignorer ce repertoire pour le moment |
|
| 96 | - if ($avail == 'SYSTEM') { |
|
| 97 | - $file = $loc; |
|
| 98 | - if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 99 | - $file = substr($file, strlen(_DIR_RACINE)); |
|
| 100 | - } |
|
| 101 | - $file = find_in_path($file); |
|
| 102 | - } else { |
|
| 103 | - $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $dtd = ''; |
|
| 107 | - if (@is_readable($file)) { |
|
| 108 | - lire_fichier($file, $dtd); |
|
| 109 | - } else { |
|
| 110 | - if ($avail == 'PUBLIC') { |
|
| 111 | - include_spip('inc/distant'); |
|
| 112 | - if ($dtd = trim(recuperer_page($loc))) { |
|
| 113 | - ecrire_fichier($file, $dtd, true); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $dtd = ltrim($dtd); |
|
| 119 | - if (!$dtd) { |
|
| 120 | - spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 121 | - |
|
| 122 | - return false; |
|
| 123 | - } else { |
|
| 124 | - spip_log("analyse de la DTD $loc "); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - while ($dtd) { |
|
| 128 | - if ($dtd[0] != '<') { |
|
| 129 | - $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 130 | - } elseif ($dtd[1] != '!') { |
|
| 131 | - $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 132 | - } elseif ($dtd[2] == '[') { |
|
| 133 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 134 | - } else { |
|
| 135 | - switch ($dtd[3]) { |
|
| 136 | - case '%' : |
|
| 137 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 138 | - break; |
|
| 139 | - case 'T' : |
|
| 140 | - $r = analyser_dtd_attlist($dtd, $dtc, $loc); |
|
| 141 | - break; |
|
| 142 | - case 'L' : |
|
| 143 | - $r = analyser_dtd_element($dtd, $dtc, $loc); |
|
| 144 | - break; |
|
| 145 | - case 'N' : |
|
| 146 | - $r = analyser_dtd_entity($dtd, $dtc, $loc); |
|
| 147 | - break; |
|
| 148 | - case 'O' : |
|
| 149 | - $r = analyser_dtd_notation($dtd, $dtc, $loc); |
|
| 150 | - break; |
|
| 151 | - case '-' : |
|
| 152 | - $r = analyser_dtd_comment($dtd, $dtc, $loc); |
|
| 153 | - break; |
|
| 154 | - default: |
|
| 155 | - $r = -1; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - if (!is_string($r)) { |
|
| 159 | - spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . "....."); |
|
| 160 | - |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - $dtd = $r; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - return true; |
|
| 92 | + // creer le repertoire de cache si ce n'est fait |
|
| 93 | + // (utile aussi pour le resultat de la compil) |
|
| 94 | + $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 95 | + // si DTD locale, ignorer ce repertoire pour le moment |
|
| 96 | + if ($avail == 'SYSTEM') { |
|
| 97 | + $file = $loc; |
|
| 98 | + if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 99 | + $file = substr($file, strlen(_DIR_RACINE)); |
|
| 100 | + } |
|
| 101 | + $file = find_in_path($file); |
|
| 102 | + } else { |
|
| 103 | + $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $dtd = ''; |
|
| 107 | + if (@is_readable($file)) { |
|
| 108 | + lire_fichier($file, $dtd); |
|
| 109 | + } else { |
|
| 110 | + if ($avail == 'PUBLIC') { |
|
| 111 | + include_spip('inc/distant'); |
|
| 112 | + if ($dtd = trim(recuperer_page($loc))) { |
|
| 113 | + ecrire_fichier($file, $dtd, true); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $dtd = ltrim($dtd); |
|
| 119 | + if (!$dtd) { |
|
| 120 | + spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 121 | + |
|
| 122 | + return false; |
|
| 123 | + } else { |
|
| 124 | + spip_log("analyse de la DTD $loc "); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + while ($dtd) { |
|
| 128 | + if ($dtd[0] != '<') { |
|
| 129 | + $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 130 | + } elseif ($dtd[1] != '!') { |
|
| 131 | + $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 132 | + } elseif ($dtd[2] == '[') { |
|
| 133 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 134 | + } else { |
|
| 135 | + switch ($dtd[3]) { |
|
| 136 | + case '%' : |
|
| 137 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 138 | + break; |
|
| 139 | + case 'T' : |
|
| 140 | + $r = analyser_dtd_attlist($dtd, $dtc, $loc); |
|
| 141 | + break; |
|
| 142 | + case 'L' : |
|
| 143 | + $r = analyser_dtd_element($dtd, $dtc, $loc); |
|
| 144 | + break; |
|
| 145 | + case 'N' : |
|
| 146 | + $r = analyser_dtd_entity($dtd, $dtc, $loc); |
|
| 147 | + break; |
|
| 148 | + case 'O' : |
|
| 149 | + $r = analyser_dtd_notation($dtd, $dtc, $loc); |
|
| 150 | + break; |
|
| 151 | + case '-' : |
|
| 152 | + $r = analyser_dtd_comment($dtd, $dtc, $loc); |
|
| 153 | + break; |
|
| 154 | + default: |
|
| 155 | + $r = -1; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + if (!is_string($r)) { |
|
| 159 | + spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . "....."); |
|
| 160 | + |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + $dtd = $r; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + return true; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // https://code.spip.net/@analyser_dtd_comment |
| 170 | 170 | function analyser_dtd_comment($dtd, &$dtc, $grammaire) { |
| 171 | - // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 172 | - // Option /s car sur plusieurs lignes parfois |
|
| 171 | + // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 172 | + // Option /s car sur plusieurs lignes parfois |
|
| 173 | 173 | |
| 174 | - if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 175 | - return -6; |
|
| 176 | - } |
|
| 174 | + if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 175 | + return -6; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - return $m[1]; |
|
| 178 | + return $m[1]; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | // https://code.spip.net/@analyser_dtd_pi |
| 182 | 182 | function analyser_dtd_pi($dtd, &$dtc, $grammaire) { |
| 183 | - if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 184 | - return -10; |
|
| 185 | - } |
|
| 183 | + if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 184 | + return -10; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - return $m[1]; |
|
| 187 | + return $m[1]; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | // https://code.spip.net/@analyser_dtd_lexeme |
| 191 | 191 | function analyser_dtd_lexeme($dtd, &$dtc, $grammaire) { |
| 192 | 192 | |
| 193 | - if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 194 | - return -9; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - list(, $s) = $m; |
|
| 198 | - $n = $dtc->macros[$s]; |
|
| 199 | - |
|
| 200 | - if (is_array($n)) { |
|
| 201 | - // en cas d'inclusion, l'espace de nom est le meme |
|
| 202 | - // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 203 | - if (($n[0] == 'PUBLIC') |
|
| 204 | - and !tester_url_absolue($n[1]) |
|
| 205 | - ) { |
|
| 206 | - $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 207 | - } |
|
| 208 | - analyser_dtd($n[1], $n[0], $dtc); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return ltrim(substr($dtd, strlen($m[0]))); |
|
| 193 | + if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 194 | + return -9; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + list(, $s) = $m; |
|
| 198 | + $n = $dtc->macros[$s]; |
|
| 199 | + |
|
| 200 | + if (is_array($n)) { |
|
| 201 | + // en cas d'inclusion, l'espace de nom est le meme |
|
| 202 | + // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 203 | + if (($n[0] == 'PUBLIC') |
|
| 204 | + and !tester_url_absolue($n[1]) |
|
| 205 | + ) { |
|
| 206 | + $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 207 | + } |
|
| 208 | + analyser_dtd($n[1], $n[0], $dtc); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return ltrim(substr($dtd, strlen($m[0]))); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | // il faudrait gerer plus proprement les niveaux d'inclusion: |
@@ -217,80 +217,80 @@ discard block |
||
| 217 | 217 | // https://code.spip.net/@analyser_dtd_data |
| 218 | 218 | function analyser_dtd_data($dtd, &$dtc, $grammaire) { |
| 219 | 219 | |
| 220 | - if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 221 | - return -11; |
|
| 222 | - } |
|
| 223 | - if (!preg_match('/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', $m[2], |
|
| 224 | - $r) |
|
| 225 | - ) { |
|
| 226 | - return -12; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - if ($dtc->macros[$m[1]] == 'INCLUDE') { |
|
| 230 | - $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 231 | - } else { |
|
| 232 | - $retour = substr($m[2], strlen($r[0])); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return $retour; |
|
| 220 | + if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 221 | + return -11; |
|
| 222 | + } |
|
| 223 | + if (!preg_match('/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', $m[2], |
|
| 224 | + $r) |
|
| 225 | + ) { |
|
| 226 | + return -12; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if ($dtc->macros[$m[1]] == 'INCLUDE') { |
|
| 230 | + $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 231 | + } else { |
|
| 232 | + $retour = substr($m[2], strlen($r[0])); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return $retour; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // https://code.spip.net/@analyser_dtd_notation |
| 239 | 239 | function analyser_dtd_notation($dtd, &$dtc, $grammaire) { |
| 240 | - if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 241 | - return -8; |
|
| 242 | - } |
|
| 243 | - spip_log("analyser_dtd_notation a ecrire"); |
|
| 240 | + if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 241 | + return -8; |
|
| 242 | + } |
|
| 243 | + spip_log("analyser_dtd_notation a ecrire"); |
|
| 244 | 244 | |
| 245 | - return $m[1]; |
|
| 245 | + return $m[1]; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // https://code.spip.net/@analyser_dtd_entity |
| 249 | 249 | function analyser_dtd_entity($dtd, &$dtc, $grammaire) { |
| 250 | - if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 251 | - return -2; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - list($t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd) = $m; |
|
| 255 | - |
|
| 256 | - if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) { |
|
| 257 | - return $dtd; |
|
| 258 | - } |
|
| 259 | - if (isset($dtc->entites[$nom])) { |
|
| 260 | - spip_log("redefinition de l'entite $nom"); |
|
| 261 | - } |
|
| 262 | - if ($k6) { |
|
| 263 | - return $k6 . $dtd; |
|
| 264 | - } // cas du synonyme complet |
|
| 265 | - $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 266 | - |
|
| 267 | - // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 268 | - if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 269 | - list($t, $type, $val, $q, $alt) = $r; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - if (!$term) { |
|
| 273 | - $dtc->entites[$nom] = $val; |
|
| 274 | - } elseif (!$type) { |
|
| 275 | - $dtc->macros[$nom] = $val; |
|
| 276 | - } else { |
|
| 277 | - if (($type == 'SYSTEM') and !$alt) { |
|
| 278 | - $alt = $val; |
|
| 279 | - } |
|
| 280 | - if (!$alt) { |
|
| 281 | - $dtc->macros[$nom] = $val; |
|
| 282 | - } else { |
|
| 283 | - if (($type == 'PUBLIC') |
|
| 284 | - and (strpos($alt, '/') === false) |
|
| 285 | - ) { |
|
| 286 | - $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 287 | - . $alt; |
|
| 288 | - } |
|
| 289 | - $dtc->macros[$nom] = array($type, $alt); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - return $dtd; |
|
| 250 | + if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 251 | + return -2; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + list($t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd) = $m; |
|
| 255 | + |
|
| 256 | + if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) { |
|
| 257 | + return $dtd; |
|
| 258 | + } |
|
| 259 | + if (isset($dtc->entites[$nom])) { |
|
| 260 | + spip_log("redefinition de l'entite $nom"); |
|
| 261 | + } |
|
| 262 | + if ($k6) { |
|
| 263 | + return $k6 . $dtd; |
|
| 264 | + } // cas du synonyme complet |
|
| 265 | + $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 266 | + |
|
| 267 | + // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 268 | + if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 269 | + list($t, $type, $val, $q, $alt) = $r; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + if (!$term) { |
|
| 273 | + $dtc->entites[$nom] = $val; |
|
| 274 | + } elseif (!$type) { |
|
| 275 | + $dtc->macros[$nom] = $val; |
|
| 276 | + } else { |
|
| 277 | + if (($type == 'SYSTEM') and !$alt) { |
|
| 278 | + $alt = $val; |
|
| 279 | + } |
|
| 280 | + if (!$alt) { |
|
| 281 | + $dtc->macros[$nom] = $val; |
|
| 282 | + } else { |
|
| 283 | + if (($type == 'PUBLIC') |
|
| 284 | + and (strpos($alt, '/') === false) |
|
| 285 | + ) { |
|
| 286 | + $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 287 | + . $alt; |
|
| 288 | + } |
|
| 289 | + $dtc->macros[$nom] = array($type, $alt); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + return $dtd; |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | // Dresser le tableau des filles potentielles de l'element |
@@ -304,76 +304,76 @@ discard block |
||
| 304 | 304 | |
| 305 | 305 | // https://code.spip.net/@analyser_dtd_element |
| 306 | 306 | function analyser_dtd_element($dtd, &$dtc, $grammaire) { |
| 307 | - if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 308 | - return -3; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - list(, $nom, $contenu, $dtd) = $m; |
|
| 312 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 313 | - |
|
| 314 | - if (isset($dtc->elements[$nom])) { |
|
| 315 | - spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 316 | - |
|
| 317 | - return -4; |
|
| 318 | - } |
|
| 319 | - $filles = array(); |
|
| 320 | - $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 321 | - $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 322 | - if ($val == '(?:EMPTY )') { |
|
| 323 | - $dtc->regles[$nom] = 'EMPTY'; |
|
| 324 | - } elseif ($val == '(?:ANY )') { |
|
| 325 | - $dtc->regles[$nom] = 'ANY'; |
|
| 326 | - } else { |
|
| 327 | - $last = substr($val, -1); |
|
| 328 | - if (preg_match('/ \w/', $val) |
|
| 329 | - or (!empty($last) and strpos('*+?', $last) === false) |
|
| 330 | - ) { |
|
| 331 | - $dtc->regles[$nom] = "/^$val$/"; |
|
| 332 | - } else { |
|
| 333 | - $dtc->regles[$nom] = $last; |
|
| 334 | - } |
|
| 335 | - $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 336 | - |
|
| 337 | - foreach ($filles as $k) { |
|
| 338 | - if (!isset($dtc->peres[$k])) { |
|
| 339 | - $dtc->peres[$k] = array(); |
|
| 340 | - } |
|
| 341 | - if (!in_array($nom, $dtc->peres[$k])) { |
|
| 342 | - $dtc->peres[$k][] = $nom; |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false); |
|
| 347 | - $dtc->elements[$nom] = $filles; |
|
| 348 | - |
|
| 349 | - return $dtd; |
|
| 307 | + if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 308 | + return -3; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + list(, $nom, $contenu, $dtd) = $m; |
|
| 312 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 313 | + |
|
| 314 | + if (isset($dtc->elements[$nom])) { |
|
| 315 | + spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 316 | + |
|
| 317 | + return -4; |
|
| 318 | + } |
|
| 319 | + $filles = array(); |
|
| 320 | + $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 321 | + $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 322 | + if ($val == '(?:EMPTY )') { |
|
| 323 | + $dtc->regles[$nom] = 'EMPTY'; |
|
| 324 | + } elseif ($val == '(?:ANY )') { |
|
| 325 | + $dtc->regles[$nom] = 'ANY'; |
|
| 326 | + } else { |
|
| 327 | + $last = substr($val, -1); |
|
| 328 | + if (preg_match('/ \w/', $val) |
|
| 329 | + or (!empty($last) and strpos('*+?', $last) === false) |
|
| 330 | + ) { |
|
| 331 | + $dtc->regles[$nom] = "/^$val$/"; |
|
| 332 | + } else { |
|
| 333 | + $dtc->regles[$nom] = $last; |
|
| 334 | + } |
|
| 335 | + $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 336 | + |
|
| 337 | + foreach ($filles as $k) { |
|
| 338 | + if (!isset($dtc->peres[$k])) { |
|
| 339 | + $dtc->peres[$k] = array(); |
|
| 340 | + } |
|
| 341 | + if (!in_array($nom, $dtc->peres[$k])) { |
|
| 342 | + $dtc->peres[$k][] = $nom; |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false); |
|
| 347 | + $dtc->elements[$nom] = $filles; |
|
| 348 | + |
|
| 349 | + return $dtd; |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | |
| 353 | 353 | // https://code.spip.net/@analyser_dtd_attlist |
| 354 | 354 | function analyser_dtd_attlist($dtd, &$dtc, $grammaire) { |
| 355 | - if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 356 | - return -5; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - list(, $nom, $val, $dtd) = $m; |
|
| 360 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 361 | - $val = expanserEntite($val, $dtc->macros); |
|
| 362 | - if (!isset($dtc->attributs[$nom])) { |
|
| 363 | - $dtc->attributs[$nom] = array(); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 367 | - foreach ($r2 as $m2) { |
|
| 368 | - $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 369 | - : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 370 | - $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 371 | - $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 372 | - $dtc->attributs[$nom][$m21] = array($v, $m25); |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - return $dtd; |
|
| 355 | + if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 356 | + return -5; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + list(, $nom, $val, $dtd) = $m; |
|
| 360 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 361 | + $val = expanserEntite($val, $dtc->macros); |
|
| 362 | + if (!isset($dtc->attributs[$nom])) { |
|
| 363 | + $dtc->attributs[$nom] = array(); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 367 | + foreach ($r2 as $m2) { |
|
| 368 | + $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 369 | + : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 370 | + $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 371 | + $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 372 | + $dtc->attributs[$nom][$m21] = array($v, $m25); |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + return $dtd; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | |
@@ -389,26 +389,26 @@ discard block |
||
| 389 | 389 | * @return string|array |
| 390 | 390 | **/ |
| 391 | 391 | function expanserEntite($val, $macros = array()) { |
| 392 | - static $vu = array(); |
|
| 393 | - if (!is_string($val)) { |
|
| 394 | - return $vu; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 398 | - foreach ($r as $m) { |
|
| 399 | - $ent = $m[1]; |
|
| 400 | - // il peut valoir "" |
|
| 401 | - if (!isset($macros[$ent])) { |
|
| 402 | - spip_log("Entite $ent inconnu"); |
|
| 403 | - } else { |
|
| 404 | - if (!isset($vu[$ent])) { |
|
| 405 | - $vu[$ent] = 0; |
|
| 406 | - } |
|
| 407 | - ++$vu[$ent]; |
|
| 408 | - $val = str_replace($m[0], $macros[$ent], $val); |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 392 | + static $vu = array(); |
|
| 393 | + if (!is_string($val)) { |
|
| 394 | + return $vu; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 398 | + foreach ($r as $m) { |
|
| 399 | + $ent = $m[1]; |
|
| 400 | + // il peut valoir "" |
|
| 401 | + if (!isset($macros[$ent])) { |
|
| 402 | + spip_log("Entite $ent inconnu"); |
|
| 403 | + } else { |
|
| 404 | + if (!isset($vu[$ent])) { |
|
| 405 | + $vu[$ent] = 0; |
|
| 406 | + } |
|
| 407 | + ++$vu[$ent]; |
|
| 408 | + $val = str_replace($m[0], $macros[$ent], $val); |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 414 | 414 | } |
@@ -63,9 +63,9 @@ |
||
| 63 | 63 | $f = new IndenteurXML(); |
| 64 | 64 | $sax($page, $apply, $f); |
| 65 | 65 | if (!$f->err) { |
| 66 | - return $f->entete . $f->res; |
|
| 66 | + return $f->entete.$f->res; |
|
| 67 | 67 | } |
| 68 | - spip_log("indentation impossible " . count($f->err) . " erreurs de validation"); |
|
| 68 | + spip_log("indentation impossible ".count($f->err)." erreurs de validation"); |
|
| 69 | 69 | |
| 70 | - return $f->entete . $f->page; |
|
| 70 | + return $f->entete.$f->page; |
|
| 71 | 71 | } |
@@ -11,61 +11,61 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | class IndenteurXML { |
| 18 | 18 | |
| 19 | - // https://code.spip.net/@debutElement |
|
| 20 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 21 | - xml_debutElement($this, $name, $attrs); |
|
| 22 | - } |
|
| 19 | + // https://code.spip.net/@debutElement |
|
| 20 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 21 | + xml_debutElement($this, $name, $attrs); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - // https://code.spip.net/@finElement |
|
| 25 | - public function finElement($phraseur, $name) { |
|
| 26 | - xml_finElement($this, $name); |
|
| 27 | - } |
|
| 24 | + // https://code.spip.net/@finElement |
|
| 25 | + public function finElement($phraseur, $name) { |
|
| 26 | + xml_finElement($this, $name); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - // https://code.spip.net/@textElement |
|
| 30 | - public function textElement($phraseur, $data) { |
|
| 31 | - xml_textElement($this, $data); |
|
| 32 | - } |
|
| 29 | + // https://code.spip.net/@textElement |
|
| 30 | + public function textElement($phraseur, $data) { |
|
| 31 | + xml_textElement($this, $data); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public function piElement($phraseur, $target, $data) { |
|
| 35 | - xml_PiElement($this, $target, $data); |
|
| 36 | - } |
|
| 34 | + public function piElement($phraseur, $target, $data) { |
|
| 35 | + xml_PiElement($this, $target, $data); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - // https://code.spip.net/@defautElement |
|
| 39 | - public function defaultElement($phraseur, $data) { |
|
| 40 | - xml_defaultElement($this, $data); |
|
| 41 | - } |
|
| 38 | + // https://code.spip.net/@defautElement |
|
| 39 | + public function defaultElement($phraseur, $data) { |
|
| 40 | + xml_defaultElement($this, $data); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - // https://code.spip.net/@phraserTout |
|
| 44 | - public function phraserTout($phraseur, $data) { |
|
| 45 | - xml_parsestring($this, $data); |
|
| 46 | - } |
|
| 43 | + // https://code.spip.net/@phraserTout |
|
| 44 | + public function phraserTout($phraseur, $data) { |
|
| 45 | + xml_parsestring($this, $data); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public $depth = ""; |
|
| 49 | - public $res = ""; |
|
| 50 | - public $err = array(); |
|
| 51 | - public $contenu = array(); |
|
| 52 | - public $ouvrant = array(); |
|
| 53 | - public $reperes = array(); |
|
| 54 | - public $entete = ''; |
|
| 55 | - public $page = ''; |
|
| 56 | - public $dtc = null; |
|
| 57 | - public $sax = null; |
|
| 48 | + public $depth = ""; |
|
| 49 | + public $res = ""; |
|
| 50 | + public $err = array(); |
|
| 51 | + public $contenu = array(); |
|
| 52 | + public $ouvrant = array(); |
|
| 53 | + public $reperes = array(); |
|
| 54 | + public $entete = ''; |
|
| 55 | + public $page = ''; |
|
| 56 | + public $dtc = null; |
|
| 57 | + public $sax = null; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | // https://code.spip.net/@xml_indenter_dist |
| 61 | 61 | function xml_indenter_dist($page, $apply = false) { |
| 62 | - $sax = charger_fonction('sax', 'xml'); |
|
| 63 | - $f = new IndenteurXML(); |
|
| 64 | - $sax($page, $apply, $f); |
|
| 65 | - if (!$f->err) { |
|
| 66 | - return $f->entete . $f->res; |
|
| 67 | - } |
|
| 68 | - spip_log("indentation impossible " . count($f->err) . " erreurs de validation"); |
|
| 62 | + $sax = charger_fonction('sax', 'xml'); |
|
| 63 | + $f = new IndenteurXML(); |
|
| 64 | + $sax($page, $apply, $f); |
|
| 65 | + if (!$f->err) { |
|
| 66 | + return $f->entete . $f->res; |
|
| 67 | + } |
|
| 68 | + spip_log("indentation impossible " . count($f->err) . " erreurs de validation"); |
|
| 69 | 69 | |
| 70 | - return $f->entete . $f->page; |
|
| 70 | + return $f->entete . $f->page; |
|
| 71 | 71 | } |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | $t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' '; |
| 46 | 46 | // espace initial signifie: deja integree au resultat |
| 47 | 47 | if ($t[0] != ' ') { |
| 48 | - $phraseur->res .= '<' . $t . '>'; |
|
| 49 | - $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 48 | + $phraseur->res .= '<'.$t.'>'; |
|
| 49 | + $phraseur->ouvrant[$depth] = ' '.$t; |
|
| 50 | 50 | } |
| 51 | 51 | $t = $phraseur->contenu[$depth]; |
| 52 | 52 | // n'indenter que s'il y a un separateur avant |
@@ -57,14 +57,14 @@ discard block |
||
| 57 | 57 | foreach ($attrs as $k => $v) { |
| 58 | 58 | $delim = strpos($v, "'") === false ? "'" : '"'; |
| 59 | 59 | $val = xml_entites_html($v); |
| 60 | - $att .= $sep . $k . "=" . $delim |
|
| 60 | + $att .= $sep.$k."=".$delim |
|
| 61 | 61 | . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
| 62 | 62 | . $delim; |
| 63 | 63 | $sep = "\n $depth"; |
| 64 | 64 | } |
| 65 | 65 | $phraseur->depth .= ' '; |
| 66 | 66 | $phraseur->contenu[$phraseur->depth] = ""; |
| 67 | - $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 67 | + $phraseur->ouvrant[$phraseur->depth] = $name.$att; |
|
| 68 | 68 | $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | $ouv = $phraseur->ouvrant[$phraseur->depth]; |
| 74 | 74 | |
| 75 | 75 | if ($ouv[0] != ' ') { |
| 76 | - $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 76 | + $phraseur->ouvrant[$phraseur->depth] = ' '.$ouv; |
|
| 77 | 77 | } else { |
| 78 | 78 | $ouv = ""; |
| 79 | 79 | } |
| 80 | 80 | $t = $phraseur->contenu[$phraseur->depth]; |
| 81 | 81 | $phraseur->depth = substr($phraseur->depth, 2); |
| 82 | - $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 82 | + $t = preg_replace("/[\n\t ]+$/", "\n".$phraseur->depth, $t); |
|
| 83 | 83 | |
| 84 | 84 | // fusion <balise></balise> en <balise />. |
| 85 | 85 | // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
@@ -88,9 +88,9 @@ discard block |
||
| 88 | 88 | // (param fusion_bal) |
| 89 | 89 | |
| 90 | 90 | if ($t || (($ouv != $name) and !$fusion_bal)) { |
| 91 | - $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . "</" . $name . ">"; |
|
| 91 | + $phraseur->res .= ($ouv ? ('<'.$ouv.'>') : '').$t."</".$name.">"; |
|
| 92 | 92 | } else { |
| 93 | - $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ("</" . $name . ">")); |
|
| 93 | + $phraseur->res .= ($ouv ? ('<'.$ouv.' />') : ("</".$name.">")); |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
@@ -134,16 +134,15 @@ discard block |
||
| 134 | 134 | if (!xml_parse($phraseur->sax, $data, true)) { |
| 135 | 135 | coordonnees_erreur($phraseur, |
| 136 | 136 | xml_error_string(xml_get_error_code($phraseur->sax)) |
| 137 | - . "<br />\n" . |
|
| 138 | - (!$phraseur->depth ? '' : |
|
| 139 | - ('(' . |
|
| 140 | - _T('erreur_balise_non_fermee') . |
|
| 141 | - " <tt>" . |
|
| 142 | - $phraseur->ouvrant[$phraseur->depth] . |
|
| 143 | - "</tt> " . |
|
| 144 | - _T('ligne') . |
|
| 145 | - " " . |
|
| 146 | - $phraseur->reperes[$phraseur->depth] . |
|
| 137 | + . "<br />\n". |
|
| 138 | + (!$phraseur->depth ? '' : ('('. |
|
| 139 | + _T('erreur_balise_non_fermee'). |
|
| 140 | + " <tt>". |
|
| 141 | + $phraseur->ouvrant[$phraseur->depth]. |
|
| 142 | + "</tt> ". |
|
| 143 | + _T('ligne'). |
|
| 144 | + " ". |
|
| 145 | + $phraseur->reperes[$phraseur->depth]. |
|
| 147 | 146 | ") <br />\n"))); |
| 148 | 147 | } |
| 149 | 148 | } |
@@ -185,7 +184,7 @@ discard block |
||
| 185 | 184 | // et escamoter le doctype que sax mange en php5 mais pas en php4 |
| 186 | 185 | if (!$doctype) { |
| 187 | 186 | if (!$r = analyser_doctype($page)) { |
| 188 | - $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 187 | + $page = _MESSAGE_DOCTYPE._DOCTYPE_ECRIRE |
|
| 189 | 188 | . preg_replace(_REGEXP_DOCTYPE, '', $page); |
| 190 | 189 | $r = analyser_doctype($page); |
| 191 | 190 | } |
@@ -286,18 +285,18 @@ discard block |
||
| 286 | 285 | 'rss-0.91.dtd' |
| 287 | 286 | ); |
| 288 | 287 | } else { |
| 289 | - $dtd = $topelement . '.dtd'; |
|
| 288 | + $dtd = $topelement.'.dtd'; |
|
| 290 | 289 | $f = find_in_path($dtd); |
| 291 | 290 | if (file_exists($f)) { |
| 292 | 291 | return array($entete, 'SYSTEM', $f, $dtd); |
| 293 | 292 | } |
| 294 | 293 | } |
| 295 | 294 | } |
| 296 | - spip_log("Dtd pas vu pour " . substr($data, 0, 100)); |
|
| 295 | + spip_log("Dtd pas vu pour ".substr($data, 0, 100)); |
|
| 297 | 296 | |
| 298 | 297 | return array(); |
| 299 | 298 | } |
| 300 | - list($entete, , $topelement, $avail, $suite) = $page; |
|
| 299 | + list($entete,, $topelement, $avail, $suite) = $page; |
|
| 301 | 300 | |
| 302 | 301 | if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
| 303 | 302 | if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
@@ -102,6 +102,9 @@ discard block |
||
| 102 | 102 | : xml_entites_html($data); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | +/** |
|
| 106 | + * @param IndenteurXML $phraseur |
|
| 107 | + */ |
|
| 105 | 108 | function xml_piElement($phraseur, $target, $data) { |
| 106 | 109 | $depth = $phraseur->depth; |
| 107 | 110 | |
@@ -118,6 +121,9 @@ discard block |
||
| 118 | 121 | |
| 119 | 122 | |
| 120 | 123 | // https://code.spip.net/@xml_defautElement |
| 124 | +/** |
|
| 125 | + * @param IndenteurXML $phraseur |
|
| 126 | + */ |
|
| 121 | 127 | function xml_defaultElement($phraseur, $data) { |
| 122 | 128 | $depth = $phraseur->depth; |
| 123 | 129 | |
@@ -149,6 +155,9 @@ discard block |
||
| 149 | 155 | } |
| 150 | 156 | |
| 151 | 157 | // https://code.spip.net/@coordonnees_erreur |
| 158 | +/** |
|
| 159 | + * @param string $msg |
|
| 160 | + */ |
|
| 152 | 161 | function coordonnees_erreur($phraseur, $msg) { |
| 153 | 162 | $entete_length = substr_count($phraseur->entete, "\n"); |
| 154 | 163 | $phraseur->err[] = array( |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/charsets'); |
@@ -24,218 +24,218 @@ discard block |
||
| 24 | 24 | * @return string |
| 25 | 25 | */ |
| 26 | 26 | function xml_entites_html($texte) { |
| 27 | - if (!is_string($texte) or !$texte |
|
| 28 | - or strpbrk($texte, "&\"'<>") == false |
|
| 29 | - ) { |
|
| 30 | - return $texte; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - if (!function_exists('spip_htmlspecialchars')) { |
|
| 34 | - include_spip("inc/filtres_mini"); |
|
| 35 | - } |
|
| 36 | - $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 37 | - |
|
| 38 | - return $texte; |
|
| 27 | + if (!is_string($texte) or !$texte |
|
| 28 | + or strpbrk($texte, "&\"'<>") == false |
|
| 29 | + ) { |
|
| 30 | + return $texte; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + if (!function_exists('spip_htmlspecialchars')) { |
|
| 34 | + include_spip("inc/filtres_mini"); |
|
| 35 | + } |
|
| 36 | + $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 37 | + |
|
| 38 | + return $texte; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // https://code.spip.net/@xml_debutElement |
| 42 | 42 | function xml_debutElement($phraseur, $name, $attrs) { |
| 43 | - $depth = $phraseur->depth; |
|
| 44 | - |
|
| 45 | - $t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' '; |
|
| 46 | - // espace initial signifie: deja integree au resultat |
|
| 47 | - if ($t[0] != ' ') { |
|
| 48 | - $phraseur->res .= '<' . $t . '>'; |
|
| 49 | - $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 50 | - } |
|
| 51 | - $t = $phraseur->contenu[$depth]; |
|
| 52 | - // n'indenter que s'il y a un separateur avant |
|
| 53 | - $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t); |
|
| 54 | - $phraseur->contenu[$depth] = ""; |
|
| 55 | - $att = ''; |
|
| 56 | - $sep = ' '; |
|
| 57 | - foreach ($attrs as $k => $v) { |
|
| 58 | - $delim = strpos($v, "'") === false ? "'" : '"'; |
|
| 59 | - $val = xml_entites_html($v); |
|
| 60 | - $att .= $sep . $k . "=" . $delim |
|
| 61 | - . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
|
| 62 | - . $delim; |
|
| 63 | - $sep = "\n $depth"; |
|
| 64 | - } |
|
| 65 | - $phraseur->depth .= ' '; |
|
| 66 | - $phraseur->contenu[$phraseur->depth] = ""; |
|
| 67 | - $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 68 | - $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
|
| 43 | + $depth = $phraseur->depth; |
|
| 44 | + |
|
| 45 | + $t = isset($phraseur->ouvrant[$depth]) ? $phraseur->ouvrant[$depth] : ' '; |
|
| 46 | + // espace initial signifie: deja integree au resultat |
|
| 47 | + if ($t[0] != ' ') { |
|
| 48 | + $phraseur->res .= '<' . $t . '>'; |
|
| 49 | + $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 50 | + } |
|
| 51 | + $t = $phraseur->contenu[$depth]; |
|
| 52 | + // n'indenter que s'il y a un separateur avant |
|
| 53 | + $phraseur->res .= preg_replace("/[\n\t ]+$/", "\n$depth", $t); |
|
| 54 | + $phraseur->contenu[$depth] = ""; |
|
| 55 | + $att = ''; |
|
| 56 | + $sep = ' '; |
|
| 57 | + foreach ($attrs as $k => $v) { |
|
| 58 | + $delim = strpos($v, "'") === false ? "'" : '"'; |
|
| 59 | + $val = xml_entites_html($v); |
|
| 60 | + $att .= $sep . $k . "=" . $delim |
|
| 61 | + . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
|
| 62 | + . $delim; |
|
| 63 | + $sep = "\n $depth"; |
|
| 64 | + } |
|
| 65 | + $phraseur->depth .= ' '; |
|
| 66 | + $phraseur->contenu[$phraseur->depth] = ""; |
|
| 67 | + $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 68 | + $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // https://code.spip.net/@xml_finElement |
| 72 | 72 | function xml_finElement($phraseur, $name, $fusion_bal = false) { |
| 73 | - $ouv = $phraseur->ouvrant[$phraseur->depth]; |
|
| 74 | - |
|
| 75 | - if ($ouv[0] != ' ') { |
|
| 76 | - $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 77 | - } else { |
|
| 78 | - $ouv = ""; |
|
| 79 | - } |
|
| 80 | - $t = $phraseur->contenu[$phraseur->depth]; |
|
| 81 | - $phraseur->depth = substr($phraseur->depth, 2); |
|
| 82 | - $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 83 | - |
|
| 84 | - // fusion <balise></balise> en <balise />. |
|
| 85 | - // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
|
| 86 | - // en particulier pour les balises Script et A. |
|
| 87 | - // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
|
| 88 | - // (param fusion_bal) |
|
| 89 | - |
|
| 90 | - if ($t || (($ouv != $name) and !$fusion_bal)) { |
|
| 91 | - $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . "</" . $name . ">"; |
|
| 92 | - } else { |
|
| 93 | - $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ("</" . $name . ">")); |
|
| 94 | - } |
|
| 73 | + $ouv = $phraseur->ouvrant[$phraseur->depth]; |
|
| 74 | + |
|
| 75 | + if ($ouv[0] != ' ') { |
|
| 76 | + $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 77 | + } else { |
|
| 78 | + $ouv = ""; |
|
| 79 | + } |
|
| 80 | + $t = $phraseur->contenu[$phraseur->depth]; |
|
| 81 | + $phraseur->depth = substr($phraseur->depth, 2); |
|
| 82 | + $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 83 | + |
|
| 84 | + // fusion <balise></balise> en <balise />. |
|
| 85 | + // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
|
| 86 | + // en particulier pour les balises Script et A. |
|
| 87 | + // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
|
| 88 | + // (param fusion_bal) |
|
| 89 | + |
|
| 90 | + if ($t || (($ouv != $name) and !$fusion_bal)) { |
|
| 91 | + $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . "</" . $name . ">"; |
|
| 92 | + } else { |
|
| 93 | + $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ("</" . $name . ">")); |
|
| 94 | + } |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | // https://code.spip.net/@xml_textElement |
| 98 | 98 | function xml_textElement($phraseur, $data) { |
| 99 | - $depth = $phraseur->depth; |
|
| 100 | - $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth]) |
|
| 101 | - ? $data |
|
| 102 | - : xml_entites_html($data); |
|
| 99 | + $depth = $phraseur->depth; |
|
| 100 | + $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth]) |
|
| 101 | + ? $data |
|
| 102 | + : xml_entites_html($data); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | function xml_piElement($phraseur, $target, $data) { |
| 106 | - $depth = $phraseur->depth; |
|
| 107 | - |
|
| 108 | - if (strtolower($target) != "php") { |
|
| 109 | - $phraseur->contenu[$depth] .= $data; |
|
| 110 | - } else { |
|
| 111 | - ob_start(); |
|
| 112 | - eval($data); |
|
| 113 | - $data = ob_get_contents(); |
|
| 114 | - ob_end_clean(); |
|
| 115 | - $phraseur->contenu[$depth] .= $data; |
|
| 116 | - } |
|
| 106 | + $depth = $phraseur->depth; |
|
| 107 | + |
|
| 108 | + if (strtolower($target) != "php") { |
|
| 109 | + $phraseur->contenu[$depth] .= $data; |
|
| 110 | + } else { |
|
| 111 | + ob_start(); |
|
| 112 | + eval($data); |
|
| 113 | + $data = ob_get_contents(); |
|
| 114 | + ob_end_clean(); |
|
| 115 | + $phraseur->contenu[$depth] .= $data; |
|
| 116 | + } |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | |
| 120 | 120 | // https://code.spip.net/@xml_defautElement |
| 121 | 121 | function xml_defaultElement($phraseur, $data) { |
| 122 | - $depth = $phraseur->depth; |
|
| 122 | + $depth = $phraseur->depth; |
|
| 123 | 123 | |
| 124 | - if (!isset($phraseur->contenu[$depth])) { |
|
| 125 | - $phraseur->contenu[$depth] = ''; |
|
| 126 | - } |
|
| 127 | - $phraseur->contenu[$depth] .= $data; |
|
| 124 | + if (!isset($phraseur->contenu[$depth])) { |
|
| 125 | + $phraseur->contenu[$depth] = ''; |
|
| 126 | + } |
|
| 127 | + $phraseur->contenu[$depth] .= $data; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // https://code.spip.net/@xml_parsestring |
| 131 | 131 | function xml_parsestring($phraseur, $data) { |
| 132 | - $phraseur->contenu[$phraseur->depth] = ''; |
|
| 133 | - |
|
| 134 | - if (!xml_parse($phraseur->sax, $data, true)) { |
|
| 135 | - coordonnees_erreur($phraseur, |
|
| 136 | - xml_error_string(xml_get_error_code($phraseur->sax)) |
|
| 137 | - . "<br />\n" . |
|
| 138 | - (!$phraseur->depth ? '' : |
|
| 139 | - ('(' . |
|
| 140 | - _T('erreur_balise_non_fermee') . |
|
| 141 | - " <tt>" . |
|
| 142 | - $phraseur->ouvrant[$phraseur->depth] . |
|
| 143 | - "</tt> " . |
|
| 144 | - _T('ligne') . |
|
| 145 | - " " . |
|
| 146 | - $phraseur->reperes[$phraseur->depth] . |
|
| 147 | - ") <br />\n"))); |
|
| 148 | - } |
|
| 132 | + $phraseur->contenu[$phraseur->depth] = ''; |
|
| 133 | + |
|
| 134 | + if (!xml_parse($phraseur->sax, $data, true)) { |
|
| 135 | + coordonnees_erreur($phraseur, |
|
| 136 | + xml_error_string(xml_get_error_code($phraseur->sax)) |
|
| 137 | + . "<br />\n" . |
|
| 138 | + (!$phraseur->depth ? '' : |
|
| 139 | + ('(' . |
|
| 140 | + _T('erreur_balise_non_fermee') . |
|
| 141 | + " <tt>" . |
|
| 142 | + $phraseur->ouvrant[$phraseur->depth] . |
|
| 143 | + "</tt> " . |
|
| 144 | + _T('ligne') . |
|
| 145 | + " " . |
|
| 146 | + $phraseur->reperes[$phraseur->depth] . |
|
| 147 | + ") <br />\n"))); |
|
| 148 | + } |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // https://code.spip.net/@coordonnees_erreur |
| 152 | 152 | function coordonnees_erreur($phraseur, $msg) { |
| 153 | - $entete_length = substr_count($phraseur->entete, "\n"); |
|
| 154 | - $phraseur->err[] = array( |
|
| 155 | - $msg, |
|
| 156 | - xml_get_current_line_number($phraseur->sax) + $entete_length, |
|
| 157 | - xml_get_current_column_number($phraseur->sax) |
|
| 158 | - ); |
|
| 153 | + $entete_length = substr_count($phraseur->entete, "\n"); |
|
| 154 | + $phraseur->err[] = array( |
|
| 155 | + $msg, |
|
| 156 | + xml_get_current_line_number($phraseur->sax) + $entete_length, |
|
| 157 | + xml_get_current_column_number($phraseur->sax) |
|
| 158 | + ); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | // https://code.spip.net/@xml_sax_dist |
| 162 | 162 | function xml_sax_dist($page, $apply = false, $phraseur = null, $doctype = '', $charset = null) { |
| 163 | - if (is_null($charset)) { |
|
| 164 | - $charset = $GLOBALS['meta']['charset']; |
|
| 165 | - } |
|
| 166 | - if ($apply) { |
|
| 167 | - ob_start(); |
|
| 168 | - if (is_array($apply)) { |
|
| 169 | - $r = call_user_func_array($page, $apply); |
|
| 170 | - } else { |
|
| 171 | - $r = $page(); |
|
| 172 | - } |
|
| 173 | - $page = ob_get_contents(); |
|
| 174 | - ob_end_clean(); |
|
| 175 | - // fonction sans aucun "echo", ca doit etre le resultat |
|
| 176 | - if (!$page) { |
|
| 177 | - $page = $r; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if (!$page) { |
|
| 182 | - return ''; |
|
| 183 | - } |
|
| 184 | - // charger la DTD et transcoder les entites, |
|
| 185 | - // et escamoter le doctype que sax mange en php5 mais pas en php4 |
|
| 186 | - if (!$doctype) { |
|
| 187 | - if (!$r = analyser_doctype($page)) { |
|
| 188 | - $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 189 | - . preg_replace(_REGEXP_DOCTYPE, '', $page); |
|
| 190 | - $r = analyser_doctype($page); |
|
| 191 | - } |
|
| 192 | - list($entete, $avail, $grammaire, $rotlvl) = array_pad($r, 4, null); |
|
| 193 | - $page = substr($page, strlen($entete)); |
|
| 194 | - } else { |
|
| 195 | - $avail = 'SYSTEM'; |
|
| 196 | - $grammaire = $doctype; |
|
| 197 | - $rotlvl = basename($grammaire); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - include_spip('xml/analyser_dtd'); |
|
| 201 | - $dtc = charger_dtd($grammaire, $avail, $rotlvl); |
|
| 202 | - $page = sax_bug($page, $dtc, $charset); |
|
| 203 | - |
|
| 204 | - // compatibilite Tidy espace public |
|
| 205 | - if (!$phraseur) { |
|
| 206 | - $indenter_xml = charger_fonction('indenter', 'xml'); |
|
| 207 | - |
|
| 208 | - return $indenter_xml($page, $apply); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - $xml_parser = xml_parser_create($charset); |
|
| 212 | - |
|
| 213 | - xml_set_element_handler($xml_parser, |
|
| 214 | - array($phraseur, "debutElement"), |
|
| 215 | - array($phraseur, "finElement")); |
|
| 216 | - |
|
| 217 | - xml_set_character_data_handler($xml_parser, |
|
| 218 | - array($phraseur, "textElement")); |
|
| 219 | - |
|
| 220 | - xml_set_processing_instruction_handler($xml_parser, |
|
| 221 | - array($phraseur, 'piElement')); |
|
| 222 | - |
|
| 223 | - xml_set_default_handler($xml_parser, |
|
| 224 | - array($phraseur, "defaultElement")); |
|
| 225 | - |
|
| 226 | - xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 227 | - |
|
| 228 | - $phraseur->sax = $xml_parser; |
|
| 229 | - if (isset($entete)) { |
|
| 230 | - $phraseur->entete = $entete; |
|
| 231 | - } |
|
| 232 | - $phraseur->page = $page; |
|
| 233 | - $phraseur->dtc = $dtc; |
|
| 234 | - $phraseur->phraserTout($xml_parser, $page); |
|
| 235 | - xml_parser_free($xml_parser); |
|
| 236 | - $phraseur->sax = ''; |
|
| 237 | - |
|
| 238 | - return $phraseur; |
|
| 163 | + if (is_null($charset)) { |
|
| 164 | + $charset = $GLOBALS['meta']['charset']; |
|
| 165 | + } |
|
| 166 | + if ($apply) { |
|
| 167 | + ob_start(); |
|
| 168 | + if (is_array($apply)) { |
|
| 169 | + $r = call_user_func_array($page, $apply); |
|
| 170 | + } else { |
|
| 171 | + $r = $page(); |
|
| 172 | + } |
|
| 173 | + $page = ob_get_contents(); |
|
| 174 | + ob_end_clean(); |
|
| 175 | + // fonction sans aucun "echo", ca doit etre le resultat |
|
| 176 | + if (!$page) { |
|
| 177 | + $page = $r; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if (!$page) { |
|
| 182 | + return ''; |
|
| 183 | + } |
|
| 184 | + // charger la DTD et transcoder les entites, |
|
| 185 | + // et escamoter le doctype que sax mange en php5 mais pas en php4 |
|
| 186 | + if (!$doctype) { |
|
| 187 | + if (!$r = analyser_doctype($page)) { |
|
| 188 | + $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 189 | + . preg_replace(_REGEXP_DOCTYPE, '', $page); |
|
| 190 | + $r = analyser_doctype($page); |
|
| 191 | + } |
|
| 192 | + list($entete, $avail, $grammaire, $rotlvl) = array_pad($r, 4, null); |
|
| 193 | + $page = substr($page, strlen($entete)); |
|
| 194 | + } else { |
|
| 195 | + $avail = 'SYSTEM'; |
|
| 196 | + $grammaire = $doctype; |
|
| 197 | + $rotlvl = basename($grammaire); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + include_spip('xml/analyser_dtd'); |
|
| 201 | + $dtc = charger_dtd($grammaire, $avail, $rotlvl); |
|
| 202 | + $page = sax_bug($page, $dtc, $charset); |
|
| 203 | + |
|
| 204 | + // compatibilite Tidy espace public |
|
| 205 | + if (!$phraseur) { |
|
| 206 | + $indenter_xml = charger_fonction('indenter', 'xml'); |
|
| 207 | + |
|
| 208 | + return $indenter_xml($page, $apply); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + $xml_parser = xml_parser_create($charset); |
|
| 212 | + |
|
| 213 | + xml_set_element_handler($xml_parser, |
|
| 214 | + array($phraseur, "debutElement"), |
|
| 215 | + array($phraseur, "finElement")); |
|
| 216 | + |
|
| 217 | + xml_set_character_data_handler($xml_parser, |
|
| 218 | + array($phraseur, "textElement")); |
|
| 219 | + |
|
| 220 | + xml_set_processing_instruction_handler($xml_parser, |
|
| 221 | + array($phraseur, 'piElement')); |
|
| 222 | + |
|
| 223 | + xml_set_default_handler($xml_parser, |
|
| 224 | + array($phraseur, "defaultElement")); |
|
| 225 | + |
|
| 226 | + xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 227 | + |
|
| 228 | + $phraseur->sax = $xml_parser; |
|
| 229 | + if (isset($entete)) { |
|
| 230 | + $phraseur->entete = $entete; |
|
| 231 | + } |
|
| 232 | + $phraseur->page = $page; |
|
| 233 | + $phraseur->dtc = $dtc; |
|
| 234 | + $phraseur->phraserTout($xml_parser, $page); |
|
| 235 | + xml_parser_free($xml_parser); |
|
| 236 | + $phraseur->sax = ''; |
|
| 237 | + |
|
| 238 | + return $phraseur; |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | // SAX ne dit pas si une Entite est dans un attribut ou non. |
@@ -247,24 +247,24 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | // https://code.spip.net/@sax_bug |
| 249 | 249 | function sax_bug($data, $dtc, $charset = null) { |
| 250 | - if (is_null($charset)) { |
|
| 251 | - $charset = $GLOBALS['meta']['charset']; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - if ($dtc) { |
|
| 255 | - $trans = array(); |
|
| 256 | - |
|
| 257 | - foreach ($dtc->entites as $k => $v) { |
|
| 258 | - if (!strpos(" amp lt gt quot ", $k)) { |
|
| 259 | - $trans["&$k;"] = $v; |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - $data = strtr($data, $trans); |
|
| 263 | - } else { |
|
| 264 | - $data = html2unicode($data, true); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return unicode2charset($data, $charset); |
|
| 250 | + if (is_null($charset)) { |
|
| 251 | + $charset = $GLOBALS['meta']['charset']; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + if ($dtc) { |
|
| 255 | + $trans = array(); |
|
| 256 | + |
|
| 257 | + foreach ($dtc->entites as $k => $v) { |
|
| 258 | + if (!strpos(" amp lt gt quot ", $k)) { |
|
| 259 | + $trans["&$k;"] = $v; |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + $data = strtr($data, $trans); |
|
| 263 | + } else { |
|
| 264 | + $data = html2unicode($data, true); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return unicode2charset($data, $charset); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // Retirer < ? xml... ? > et autre PI, ainsi que les commentaires en debut |
@@ -275,52 +275,52 @@ discard block |
||
| 275 | 275 | // mais un XML Schema que SPIP ne fait pas encore lire. |
| 276 | 276 | // https://code.spip.net/@analyser_doctype |
| 277 | 277 | function analyser_doctype($data) { |
| 278 | - if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
|
| 279 | - if (preg_match(_REGEXP_XML, $data, $page)) { |
|
| 280 | - list(, $entete, $topelement) = $page; |
|
| 281 | - if ($topelement == 'rss') { |
|
| 282 | - return array( |
|
| 283 | - $entete, |
|
| 284 | - 'PUBLIC', |
|
| 285 | - _DOCTYPE_RSS, |
|
| 286 | - 'rss-0.91.dtd' |
|
| 287 | - ); |
|
| 288 | - } else { |
|
| 289 | - $dtd = $topelement . '.dtd'; |
|
| 290 | - $f = find_in_path($dtd); |
|
| 291 | - if (file_exists($f)) { |
|
| 292 | - return array($entete, 'SYSTEM', $f, $dtd); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - spip_log("Dtd pas vu pour " . substr($data, 0, 100)); |
|
| 297 | - |
|
| 298 | - return array(); |
|
| 299 | - } |
|
| 300 | - list($entete, , $topelement, $avail, $suite) = $page; |
|
| 301 | - |
|
| 302 | - if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
|
| 303 | - if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
|
| 304 | - return array(); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - list(, $rotlvl, $suite) = $r; |
|
| 308 | - |
|
| 309 | - if (!$suite) { |
|
| 310 | - if ($avail != 'SYSTEM') { |
|
| 311 | - return array(); |
|
| 312 | - } |
|
| 313 | - $grammaire = $rotlvl; |
|
| 314 | - $rotlvl = ''; |
|
| 315 | - } else { |
|
| 316 | - if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) { |
|
| 317 | - if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) { |
|
| 318 | - return array(); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - $grammaire = $r[1]; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - return array($entete, $avail, $grammaire, $rotlvl); |
|
| 278 | + if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
|
| 279 | + if (preg_match(_REGEXP_XML, $data, $page)) { |
|
| 280 | + list(, $entete, $topelement) = $page; |
|
| 281 | + if ($topelement == 'rss') { |
|
| 282 | + return array( |
|
| 283 | + $entete, |
|
| 284 | + 'PUBLIC', |
|
| 285 | + _DOCTYPE_RSS, |
|
| 286 | + 'rss-0.91.dtd' |
|
| 287 | + ); |
|
| 288 | + } else { |
|
| 289 | + $dtd = $topelement . '.dtd'; |
|
| 290 | + $f = find_in_path($dtd); |
|
| 291 | + if (file_exists($f)) { |
|
| 292 | + return array($entete, 'SYSTEM', $f, $dtd); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + spip_log("Dtd pas vu pour " . substr($data, 0, 100)); |
|
| 297 | + |
|
| 298 | + return array(); |
|
| 299 | + } |
|
| 300 | + list($entete, , $topelement, $avail, $suite) = $page; |
|
| 301 | + |
|
| 302 | + if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
|
| 303 | + if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
|
| 304 | + return array(); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + list(, $rotlvl, $suite) = $r; |
|
| 308 | + |
|
| 309 | + if (!$suite) { |
|
| 310 | + if ($avail != 'SYSTEM') { |
|
| 311 | + return array(); |
|
| 312 | + } |
|
| 313 | + $grammaire = $rotlvl; |
|
| 314 | + $rotlvl = ''; |
|
| 315 | + } else { |
|
| 316 | + if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) { |
|
| 317 | + if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) { |
|
| 318 | + return array(); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + $grammaire = $r[1]; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + return array($entete, $avail, $grammaire, $rotlvl); |
|
| 326 | 326 | } |