@@ -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 | } |
@@ -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 | } |
@@ -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 | /** |
@@ -23,333 +23,333 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | class ValidateurXML { |
| 25 | 25 | |
| 26 | - // https://code.spip.net/@validerElement |
|
| 27 | - public function validerElement($phraseur, $name, $attrs) { |
|
| 28 | - if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 29 | - if ($p = strpos($name, ':')) { |
|
| 30 | - $name = substr($name, $p + 1); |
|
| 31 | - $p = isset($this->dtc->elements[$name]); |
|
| 32 | - } |
|
| 33 | - if (!$p) { |
|
| 34 | - coordonnees_erreur($this, " <b>$name</b> : " |
|
| 35 | - . _T('zxml_inconnu_balise')); |
|
| 36 | - |
|
| 37 | - return; |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - // controler les filles illegitimes, ca suffit |
|
| 41 | - $depth = $this->depth; |
|
| 42 | - $ouvrant = $this->ouvrant; |
|
| 43 | - #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 44 | - if (isset($ouvrant[$depth])) { |
|
| 45 | - if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 46 | - $pere = $r[1]; |
|
| 47 | - #spip_log("pere $pere"); |
|
| 48 | - if (isset($this->dtc->elements[$pere])) { |
|
| 49 | - $fils = $this->dtc->elements[$pere]; |
|
| 50 | - #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 51 | - if (!($p = @in_array($name, $fils))) { |
|
| 52 | - if ($p = strpos($name, ':')) { |
|
| 53 | - $p = substr($name, $p + 1); |
|
| 54 | - $p = @in_array($p, $fils); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - if (!$p) { |
|
| 58 | - $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 59 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 60 | - . _T('zxml_non_fils') |
|
| 61 | - . ' <b>' |
|
| 62 | - . $pere |
|
| 63 | - . '</b>' |
|
| 64 | - . (!$bons_peres ? '' |
|
| 65 | - : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 66 | - } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 67 | - $frat = substr($depth, 2); |
|
| 68 | - if (!isset($this->fratrie[$frat])) { |
|
| 69 | - $this->fratrie[$frat] = ''; |
|
| 70 | - } |
|
| 71 | - $this->fratrie[$frat] .= "$name "; |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - // Init de la suite des balises a memoriser si regle difficile |
|
| 77 | - if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 78 | - $this->fratrie[$depth] = ''; |
|
| 79 | - } |
|
| 80 | - if (isset($this->dtc->attributs[$name])) { |
|
| 81 | - foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 82 | - if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 83 | - coordonnees_erreur($this, " <b>$n</b>" |
|
| 84 | - . ' : ' |
|
| 85 | - . _T('zxml_obligatoire_attribut') |
|
| 86 | - . " <b>$name</b>"); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // https://code.spip.net/@validerAttribut |
|
| 93 | - public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 94 | - // Si la balise est inconnue, eviter d'insister |
|
| 95 | - if (!isset($this->dtc->attributs[$bal])) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $a = $this->dtc->attributs[$bal]; |
|
| 100 | - if (!isset($a[$name])) { |
|
| 101 | - $bons = join(', ', array_keys($a)); |
|
| 102 | - if ($bons) { |
|
| 103 | - $bons = " title=' " . |
|
| 104 | - _T('zxml_connus_attributs') . |
|
| 105 | - ' : ' . |
|
| 106 | - $bons . |
|
| 107 | - "'"; |
|
| 108 | - } |
|
| 109 | - $bons .= " style='font-weight: bold'"; |
|
| 110 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 111 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 112 | - . " <a$bons>$bal</a> (" |
|
| 113 | - . _T('zxml_survoler') |
|
| 114 | - . ")"); |
|
| 115 | - } else { |
|
| 116 | - $type = $a[$name][0]; |
|
| 117 | - if (!preg_match('/^\w+$/', $type)) { |
|
| 118 | - $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 119 | - } else { |
|
| 120 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 121 | - $this->$f($phraseur, $name, $val, $bal); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - # else spip_log("$type type d'attribut inconnu"); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 129 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 133 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // https://code.spip.net/@validerAttribut_ID |
|
| 137 | - public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 138 | - if (isset($this->ids[$val])) { |
|
| 139 | - list($l, $c) = $this->ids[$val]; |
|
| 140 | - coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 141 | - . _T('zxml_valeur_attribut') |
|
| 142 | - . " <b>$name</b> " |
|
| 143 | - . _T('zxml_de') |
|
| 144 | - . " <b>$bal</b> " |
|
| 145 | - . _T('zxml_vu') |
|
| 146 | - . " (L$l,C$c)"); |
|
| 147 | - } else { |
|
| 148 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 149 | - $this->ids[$val] = array(xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // https://code.spip.net/@validerAttribut_IDREF |
|
| 154 | - public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 155 | - $this->idrefs[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // https://code.spip.net/@validerAttribut_IDREFS |
|
| 159 | - public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 160 | - $this->idrefss[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // https://code.spip.net/@valider_motif |
|
| 164 | - public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 165 | - if (!preg_match($motif, $val)) { |
|
| 166 | - coordonnees_erreur($this, "<b>$val</b> " |
|
| 167 | - . _T('zxml_valeur_attribut') |
|
| 168 | - . " <b>$name</b> " |
|
| 169 | - . _T('zxml_de') |
|
| 170 | - . " <b>$bal</b> " |
|
| 171 | - . _T('zxml_non_conforme') |
|
| 172 | - . "</p><p>" |
|
| 173 | - . "<b>" . $motif . "</b>"); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - // https://code.spip.net/@valider_idref |
|
| 178 | - public function valider_idref($nom, $ligne, $col) { |
|
| 179 | - if (!isset($this->ids[$nom])) { |
|
| 180 | - $this->err[] = array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // https://code.spip.net/@valider_passe2 |
|
| 185 | - public function valider_passe2() { |
|
| 186 | - if (!$this->err) { |
|
| 187 | - foreach ($this->idrefs as $idref) { |
|
| 188 | - list($nom, $ligne, $col) = $idref; |
|
| 189 | - $this->valider_idref($nom, $ligne, $col); |
|
| 190 | - } |
|
| 191 | - foreach ($this->idrefss as $idref) { |
|
| 192 | - list($noms, $ligne, $col) = $idref; |
|
| 193 | - foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 194 | - $this->valider_idref($nom, $ligne, $col); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // https://code.spip.net/@debutElement |
|
| 201 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 202 | - if ($this->dtc->elements) { |
|
| 203 | - $this->validerElement($phraseur, $name, $attrs); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($f = $this->process['debut']) { |
|
| 207 | - $f($this, $name, $attrs); |
|
| 208 | - } |
|
| 209 | - $depth = $this->depth; |
|
| 210 | - $this->debuts[$depth] = strlen($this->res); |
|
| 211 | - foreach ($attrs as $k => $v) { |
|
| 212 | - $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // https://code.spip.net/@finElement |
|
| 217 | - public function finElement($phraseur, $name) { |
|
| 218 | - $depth = $this->depth; |
|
| 219 | - $contenu = $this->contenu; |
|
| 220 | - |
|
| 221 | - $n = strlen($this->res); |
|
| 222 | - $c = strlen(trim($contenu[$depth])); |
|
| 223 | - $k = $this->debuts[$depth]; |
|
| 224 | - |
|
| 225 | - $regle = isset($this->dtc->regles[$name]) ? $this->dtc->regles[$name] : false; |
|
| 226 | - $vide = ($regle == 'EMPTY'); |
|
| 227 | - // controler que les balises devant etre vides le sont |
|
| 228 | - if ($vide) { |
|
| 229 | - if ($n <> ($k + $c)) { |
|
| 230 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 231 | - } |
|
| 232 | - // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 233 | - } elseif ($regle and ($regle != '*')) { |
|
| 234 | - if ($regle == '+') { |
|
| 235 | - // iteration de disjonction non vide: 1 balise au - |
|
| 236 | - if ($n == $k) { |
|
| 237 | - coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 238 | - . _T('zxml_vide_balise')); |
|
| 239 | - } |
|
| 240 | - } else { |
|
| 241 | - $f = isset($this->fratrie[substr($depth, 2)]) ? $this->fratrie[substr($depth, 2)] : null; |
|
| 242 | - if (is_null($f) or !preg_match($regle, $f)) { |
|
| 243 | - coordonnees_erreur($this, |
|
| 244 | - " <p>\n<b>$name</b> " |
|
| 245 | - . _T('zxml_succession_fils_incorrecte') |
|
| 246 | - . ' : <b>' |
|
| 247 | - . $f |
|
| 248 | - . '</b>'); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - } |
|
| 253 | - if ($f = $this->process['fin']) { |
|
| 254 | - $f($this, $name, $vide); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - // https://code.spip.net/@textElement |
|
| 259 | - public function textElement($phraseur, $data) { |
|
| 260 | - if (trim($data)) { |
|
| 261 | - $d = $this->depth; |
|
| 262 | - $d = $this->ouvrant[$d]; |
|
| 263 | - preg_match('/^\s*(\S+)/', $d, $m); |
|
| 264 | - if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 265 | - coordonnees_erreur($this, " <p><b>" . $m[1] . "</b> " |
|
| 266 | - . _T('zxml_nonvide_balise') // message a affiner |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - if ($f = $this->process['text']) { |
|
| 271 | - $f($this, $data); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - public function piElement($phraseur, $target, $data) { |
|
| 276 | - if ($f = $this->process['pi']) { |
|
| 277 | - $f($this, $target, $data); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - // Denonciation des entitees XML inconnues |
|
| 282 | - // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 283 | - // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 284 | - // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 285 | - // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 286 | - // le source de la page laisse legitimement supposer. |
|
| 287 | - |
|
| 288 | - // https://code.spip.net/@defautElement |
|
| 289 | - public function defaultElement($phraseur, $data) { |
|
| 290 | - if (!preg_match('/^<!--/', $data) |
|
| 291 | - and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 292 | - ) { |
|
| 293 | - foreach ($r as $m) { |
|
| 294 | - list($t, $e) = $m; |
|
| 295 | - if (!isset($this->dtc->entites[$e])) { |
|
| 296 | - coordonnees_erreur($this, " <b>$e</b> " |
|
| 297 | - . _T('zxml_inconnu_entite') |
|
| 298 | - . ' ' |
|
| 299 | - ); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 304 | - $f($this, $data); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - // https://code.spip.net/@phraserTout |
|
| 309 | - public function phraserTout($phraseur, $data) { |
|
| 310 | - xml_parsestring($this, $data); |
|
| 311 | - |
|
| 312 | - if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 313 | - $this->err[] = array('DOCTYPE ?', 0, 0); |
|
| 314 | - } else { |
|
| 315 | - $this->valider_passe2($this); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Constructeur |
|
| 321 | - * |
|
| 322 | - * @param array $process ? |
|
| 323 | - **/ |
|
| 324 | - public function __construct($process = array()) { |
|
| 325 | - if (is_array($process)) { |
|
| 326 | - $this->process = $process; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - public $ids = array(); |
|
| 331 | - public $idrefs = array(); |
|
| 332 | - public $idrefss = array(); |
|
| 333 | - public $debuts = array(); |
|
| 334 | - public $fratrie = array(); |
|
| 335 | - |
|
| 336 | - public $dtc = null; |
|
| 337 | - public $sax = null; |
|
| 338 | - public $depth = ""; |
|
| 339 | - public $entete = ''; |
|
| 340 | - public $page = ''; |
|
| 341 | - public $res = ""; |
|
| 342 | - public $err = array(); |
|
| 343 | - public $contenu = array(); |
|
| 344 | - public $ouvrant = array(); |
|
| 345 | - public $reperes = array(); |
|
| 346 | - public $process = array( |
|
| 347 | - 'debut' => 'xml_debutElement', |
|
| 348 | - 'fin' => 'xml_finElement', |
|
| 349 | - 'text' => 'xml_textElement', |
|
| 350 | - 'pi' => 'xml_piElement', |
|
| 351 | - 'default' => 'xml_defaultElement' |
|
| 352 | - ); |
|
| 26 | + // https://code.spip.net/@validerElement |
|
| 27 | + public function validerElement($phraseur, $name, $attrs) { |
|
| 28 | + if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 29 | + if ($p = strpos($name, ':')) { |
|
| 30 | + $name = substr($name, $p + 1); |
|
| 31 | + $p = isset($this->dtc->elements[$name]); |
|
| 32 | + } |
|
| 33 | + if (!$p) { |
|
| 34 | + coordonnees_erreur($this, " <b>$name</b> : " |
|
| 35 | + . _T('zxml_inconnu_balise')); |
|
| 36 | + |
|
| 37 | + return; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + // controler les filles illegitimes, ca suffit |
|
| 41 | + $depth = $this->depth; |
|
| 42 | + $ouvrant = $this->ouvrant; |
|
| 43 | + #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 44 | + if (isset($ouvrant[$depth])) { |
|
| 45 | + if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 46 | + $pere = $r[1]; |
|
| 47 | + #spip_log("pere $pere"); |
|
| 48 | + if (isset($this->dtc->elements[$pere])) { |
|
| 49 | + $fils = $this->dtc->elements[$pere]; |
|
| 50 | + #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 51 | + if (!($p = @in_array($name, $fils))) { |
|
| 52 | + if ($p = strpos($name, ':')) { |
|
| 53 | + $p = substr($name, $p + 1); |
|
| 54 | + $p = @in_array($p, $fils); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + if (!$p) { |
|
| 58 | + $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 59 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 60 | + . _T('zxml_non_fils') |
|
| 61 | + . ' <b>' |
|
| 62 | + . $pere |
|
| 63 | + . '</b>' |
|
| 64 | + . (!$bons_peres ? '' |
|
| 65 | + : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 66 | + } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 67 | + $frat = substr($depth, 2); |
|
| 68 | + if (!isset($this->fratrie[$frat])) { |
|
| 69 | + $this->fratrie[$frat] = ''; |
|
| 70 | + } |
|
| 71 | + $this->fratrie[$frat] .= "$name "; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + // Init de la suite des balises a memoriser si regle difficile |
|
| 77 | + if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 78 | + $this->fratrie[$depth] = ''; |
|
| 79 | + } |
|
| 80 | + if (isset($this->dtc->attributs[$name])) { |
|
| 81 | + foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 82 | + if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 83 | + coordonnees_erreur($this, " <b>$n</b>" |
|
| 84 | + . ' : ' |
|
| 85 | + . _T('zxml_obligatoire_attribut') |
|
| 86 | + . " <b>$name</b>"); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // https://code.spip.net/@validerAttribut |
|
| 93 | + public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 94 | + // Si la balise est inconnue, eviter d'insister |
|
| 95 | + if (!isset($this->dtc->attributs[$bal])) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $a = $this->dtc->attributs[$bal]; |
|
| 100 | + if (!isset($a[$name])) { |
|
| 101 | + $bons = join(', ', array_keys($a)); |
|
| 102 | + if ($bons) { |
|
| 103 | + $bons = " title=' " . |
|
| 104 | + _T('zxml_connus_attributs') . |
|
| 105 | + ' : ' . |
|
| 106 | + $bons . |
|
| 107 | + "'"; |
|
| 108 | + } |
|
| 109 | + $bons .= " style='font-weight: bold'"; |
|
| 110 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 111 | + . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 112 | + . " <a$bons>$bal</a> (" |
|
| 113 | + . _T('zxml_survoler') |
|
| 114 | + . ")"); |
|
| 115 | + } else { |
|
| 116 | + $type = $a[$name][0]; |
|
| 117 | + if (!preg_match('/^\w+$/', $type)) { |
|
| 118 | + $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 119 | + } else { |
|
| 120 | + if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 121 | + $this->$f($phraseur, $name, $val, $bal); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + # else spip_log("$type type d'attribut inconnu"); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 129 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 133 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // https://code.spip.net/@validerAttribut_ID |
|
| 137 | + public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 138 | + if (isset($this->ids[$val])) { |
|
| 139 | + list($l, $c) = $this->ids[$val]; |
|
| 140 | + coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 141 | + . _T('zxml_valeur_attribut') |
|
| 142 | + . " <b>$name</b> " |
|
| 143 | + . _T('zxml_de') |
|
| 144 | + . " <b>$bal</b> " |
|
| 145 | + . _T('zxml_vu') |
|
| 146 | + . " (L$l,C$c)"); |
|
| 147 | + } else { |
|
| 148 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 149 | + $this->ids[$val] = array(xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // https://code.spip.net/@validerAttribut_IDREF |
|
| 154 | + public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 155 | + $this->idrefs[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // https://code.spip.net/@validerAttribut_IDREFS |
|
| 159 | + public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 160 | + $this->idrefss[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // https://code.spip.net/@valider_motif |
|
| 164 | + public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 165 | + if (!preg_match($motif, $val)) { |
|
| 166 | + coordonnees_erreur($this, "<b>$val</b> " |
|
| 167 | + . _T('zxml_valeur_attribut') |
|
| 168 | + . " <b>$name</b> " |
|
| 169 | + . _T('zxml_de') |
|
| 170 | + . " <b>$bal</b> " |
|
| 171 | + . _T('zxml_non_conforme') |
|
| 172 | + . "</p><p>" |
|
| 173 | + . "<b>" . $motif . "</b>"); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + // https://code.spip.net/@valider_idref |
|
| 178 | + public function valider_idref($nom, $ligne, $col) { |
|
| 179 | + if (!isset($this->ids[$nom])) { |
|
| 180 | + $this->err[] = array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // https://code.spip.net/@valider_passe2 |
|
| 185 | + public function valider_passe2() { |
|
| 186 | + if (!$this->err) { |
|
| 187 | + foreach ($this->idrefs as $idref) { |
|
| 188 | + list($nom, $ligne, $col) = $idref; |
|
| 189 | + $this->valider_idref($nom, $ligne, $col); |
|
| 190 | + } |
|
| 191 | + foreach ($this->idrefss as $idref) { |
|
| 192 | + list($noms, $ligne, $col) = $idref; |
|
| 193 | + foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 194 | + $this->valider_idref($nom, $ligne, $col); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // https://code.spip.net/@debutElement |
|
| 201 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 202 | + if ($this->dtc->elements) { |
|
| 203 | + $this->validerElement($phraseur, $name, $attrs); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($f = $this->process['debut']) { |
|
| 207 | + $f($this, $name, $attrs); |
|
| 208 | + } |
|
| 209 | + $depth = $this->depth; |
|
| 210 | + $this->debuts[$depth] = strlen($this->res); |
|
| 211 | + foreach ($attrs as $k => $v) { |
|
| 212 | + $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // https://code.spip.net/@finElement |
|
| 217 | + public function finElement($phraseur, $name) { |
|
| 218 | + $depth = $this->depth; |
|
| 219 | + $contenu = $this->contenu; |
|
| 220 | + |
|
| 221 | + $n = strlen($this->res); |
|
| 222 | + $c = strlen(trim($contenu[$depth])); |
|
| 223 | + $k = $this->debuts[$depth]; |
|
| 224 | + |
|
| 225 | + $regle = isset($this->dtc->regles[$name]) ? $this->dtc->regles[$name] : false; |
|
| 226 | + $vide = ($regle == 'EMPTY'); |
|
| 227 | + // controler que les balises devant etre vides le sont |
|
| 228 | + if ($vide) { |
|
| 229 | + if ($n <> ($k + $c)) { |
|
| 230 | + coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 231 | + } |
|
| 232 | + // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 233 | + } elseif ($regle and ($regle != '*')) { |
|
| 234 | + if ($regle == '+') { |
|
| 235 | + // iteration de disjonction non vide: 1 balise au - |
|
| 236 | + if ($n == $k) { |
|
| 237 | + coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 238 | + . _T('zxml_vide_balise')); |
|
| 239 | + } |
|
| 240 | + } else { |
|
| 241 | + $f = isset($this->fratrie[substr($depth, 2)]) ? $this->fratrie[substr($depth, 2)] : null; |
|
| 242 | + if (is_null($f) or !preg_match($regle, $f)) { |
|
| 243 | + coordonnees_erreur($this, |
|
| 244 | + " <p>\n<b>$name</b> " |
|
| 245 | + . _T('zxml_succession_fils_incorrecte') |
|
| 246 | + . ' : <b>' |
|
| 247 | + . $f |
|
| 248 | + . '</b>'); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + } |
|
| 253 | + if ($f = $this->process['fin']) { |
|
| 254 | + $f($this, $name, $vide); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + // https://code.spip.net/@textElement |
|
| 259 | + public function textElement($phraseur, $data) { |
|
| 260 | + if (trim($data)) { |
|
| 261 | + $d = $this->depth; |
|
| 262 | + $d = $this->ouvrant[$d]; |
|
| 263 | + preg_match('/^\s*(\S+)/', $d, $m); |
|
| 264 | + if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 265 | + coordonnees_erreur($this, " <p><b>" . $m[1] . "</b> " |
|
| 266 | + . _T('zxml_nonvide_balise') // message a affiner |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + if ($f = $this->process['text']) { |
|
| 271 | + $f($this, $data); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + public function piElement($phraseur, $target, $data) { |
|
| 276 | + if ($f = $this->process['pi']) { |
|
| 277 | + $f($this, $target, $data); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + // Denonciation des entitees XML inconnues |
|
| 282 | + // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 283 | + // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 284 | + // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 285 | + // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 286 | + // le source de la page laisse legitimement supposer. |
|
| 287 | + |
|
| 288 | + // https://code.spip.net/@defautElement |
|
| 289 | + public function defaultElement($phraseur, $data) { |
|
| 290 | + if (!preg_match('/^<!--/', $data) |
|
| 291 | + and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 292 | + ) { |
|
| 293 | + foreach ($r as $m) { |
|
| 294 | + list($t, $e) = $m; |
|
| 295 | + if (!isset($this->dtc->entites[$e])) { |
|
| 296 | + coordonnees_erreur($this, " <b>$e</b> " |
|
| 297 | + . _T('zxml_inconnu_entite') |
|
| 298 | + . ' ' |
|
| 299 | + ); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 304 | + $f($this, $data); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + // https://code.spip.net/@phraserTout |
|
| 309 | + public function phraserTout($phraseur, $data) { |
|
| 310 | + xml_parsestring($this, $data); |
|
| 311 | + |
|
| 312 | + if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 313 | + $this->err[] = array('DOCTYPE ?', 0, 0); |
|
| 314 | + } else { |
|
| 315 | + $this->valider_passe2($this); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Constructeur |
|
| 321 | + * |
|
| 322 | + * @param array $process ? |
|
| 323 | + **/ |
|
| 324 | + public function __construct($process = array()) { |
|
| 325 | + if (is_array($process)) { |
|
| 326 | + $this->process = $process; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + public $ids = array(); |
|
| 331 | + public $idrefs = array(); |
|
| 332 | + public $idrefss = array(); |
|
| 333 | + public $debuts = array(); |
|
| 334 | + public $fratrie = array(); |
|
| 335 | + |
|
| 336 | + public $dtc = null; |
|
| 337 | + public $sax = null; |
|
| 338 | + public $depth = ""; |
|
| 339 | + public $entete = ''; |
|
| 340 | + public $page = ''; |
|
| 341 | + public $res = ""; |
|
| 342 | + public $err = array(); |
|
| 343 | + public $contenu = array(); |
|
| 344 | + public $ouvrant = array(); |
|
| 345 | + public $reperes = array(); |
|
| 346 | + public $process = array( |
|
| 347 | + 'debut' => 'xml_debutElement', |
|
| 348 | + 'fin' => 'xml_finElement', |
|
| 349 | + 'text' => 'xml_textElement', |
|
| 350 | + 'pi' => 'xml_piElement', |
|
| 351 | + 'default' => 'xml_defaultElement' |
|
| 352 | + ); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | |
@@ -359,8 +359,8 @@ discard block |
||
| 359 | 359 | * |
| 360 | 360 | **/ |
| 361 | 361 | function xml_valider_dist($page, $apply = false, $process = false, $doctype = '', $charset = null) { |
| 362 | - $f = new ValidateurXML($process); |
|
| 363 | - $sax = charger_fonction('sax', 'xml'); |
|
| 362 | + $f = new ValidateurXML($process); |
|
| 363 | + $sax = charger_fonction('sax', 'xml'); |
|
| 364 | 364 | |
| 365 | - return $sax($page, $apply, $f, $doctype, $charset); |
|
| 365 | + return $sax($page, $apply, $f, $doctype, $charset); |
|
| 366 | 366 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Les fonctions de ce fichier sont appelees en certains points |
@@ -25,135 +25,135 @@ discard block |
||
| 25 | 25 | // -> https://www.spip.net/fr_article901.html |
| 26 | 26 | |
| 27 | 27 | function phraser_vieux_logos(&$p) { |
| 28 | - if ($p->param[0][0]) { |
|
| 29 | - $args = array(''); |
|
| 30 | - } else { |
|
| 31 | - $args = array_shift($p->param); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - foreach ($p->param as $couple) { |
|
| 35 | - $nom = trim($couple[0]); |
|
| 36 | - if ($nom == '') { |
|
| 37 | - array_shift($p->param); |
|
| 38 | - break; |
|
| 39 | - } |
|
| 40 | - $r = phraser_logo_faux_filtres($nom); |
|
| 41 | - if ($r === 0) { |
|
| 42 | - $c = new Texte; |
|
| 43 | - $c->texte = $nom; |
|
| 44 | - $args[] = array($c); |
|
| 45 | - array_shift($p->param); |
|
| 46 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | - } elseif ($r === 2) { |
|
| 48 | - $p->etoile = '**'; |
|
| 49 | - array_shift($p->param); |
|
| 50 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | - } elseif ($r === 1) { |
|
| 52 | - array_shift($p->param); |
|
| 53 | - $p->etoile = '*'; |
|
| 54 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | - |
|
| 56 | - } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 57 | - $champ = new Champ(); |
|
| 58 | - $champ->nom_boucle = $m[2]; |
|
| 59 | - $champ->nom_champ = $m[3]; |
|
| 60 | - $champ->etoile = $m[5]; |
|
| 61 | - $champ = array($champ); |
|
| 62 | - if ($m[6]) { |
|
| 63 | - $r = new Texte; |
|
| 64 | - $r->texte = $m[6]; |
|
| 65 | - $champ[] = $r; |
|
| 66 | - } |
|
| 67 | - $args[] = $champ; |
|
| 68 | - array_shift($p->param); |
|
| 69 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 70 | - |
|
| 71 | - } // le cas else est la seule incompatibilite |
|
| 72 | - |
|
| 73 | - } |
|
| 74 | - array_unshift($p->param, $args); |
|
| 28 | + if ($p->param[0][0]) { |
|
| 29 | + $args = array(''); |
|
| 30 | + } else { |
|
| 31 | + $args = array_shift($p->param); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + foreach ($p->param as $couple) { |
|
| 35 | + $nom = trim($couple[0]); |
|
| 36 | + if ($nom == '') { |
|
| 37 | + array_shift($p->param); |
|
| 38 | + break; |
|
| 39 | + } |
|
| 40 | + $r = phraser_logo_faux_filtres($nom); |
|
| 41 | + if ($r === 0) { |
|
| 42 | + $c = new Texte; |
|
| 43 | + $c->texte = $nom; |
|
| 44 | + $args[] = array($c); |
|
| 45 | + array_shift($p->param); |
|
| 46 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | + } elseif ($r === 2) { |
|
| 48 | + $p->etoile = '**'; |
|
| 49 | + array_shift($p->param); |
|
| 50 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | + } elseif ($r === 1) { |
|
| 52 | + array_shift($p->param); |
|
| 53 | + $p->etoile = '*'; |
|
| 54 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | + |
|
| 56 | + } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 57 | + $champ = new Champ(); |
|
| 58 | + $champ->nom_boucle = $m[2]; |
|
| 59 | + $champ->nom_champ = $m[3]; |
|
| 60 | + $champ->etoile = $m[5]; |
|
| 61 | + $champ = array($champ); |
|
| 62 | + if ($m[6]) { |
|
| 63 | + $r = new Texte; |
|
| 64 | + $r->texte = $m[6]; |
|
| 65 | + $champ[] = $r; |
|
| 66 | + } |
|
| 67 | + $args[] = $champ; |
|
| 68 | + array_shift($p->param); |
|
| 69 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 70 | + |
|
| 71 | + } // le cas else est la seule incompatibilite |
|
| 72 | + |
|
| 73 | + } |
|
| 74 | + array_unshift($p->param, $args); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | function phraser_logo_faux_filtres($nom) { |
| 79 | - switch ($nom) { |
|
| 80 | - case 'top': |
|
| 81 | - case 'left': |
|
| 82 | - case 'right': |
|
| 83 | - case 'center': |
|
| 84 | - case 'bottom': |
|
| 85 | - return 0; |
|
| 86 | - case 'lien': |
|
| 87 | - return 1; |
|
| 88 | - case 'fichier': |
|
| 89 | - return 2; |
|
| 90 | - default: |
|
| 91 | - return $nom; |
|
| 92 | - } |
|
| 79 | + switch ($nom) { |
|
| 80 | + case 'top': |
|
| 81 | + case 'left': |
|
| 82 | + case 'right': |
|
| 83 | + case 'center': |
|
| 84 | + case 'bottom': |
|
| 85 | + return 0; |
|
| 86 | + case 'lien': |
|
| 87 | + return 1; |
|
| 88 | + case 'fichier': |
|
| 89 | + return 2; |
|
| 90 | + default: |
|
| 91 | + return $nom; |
|
| 92 | + } |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
| 96 | 96 | // La balise embed_document est a present le modele emb |
| 97 | 97 | |
| 98 | 98 | function phraser_vieux_emb(&$p) { |
| 99 | - if (!is_array($p->param)) { |
|
| 100 | - $p->param = array(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // Produire le premier argument {emb} |
|
| 104 | - $texte = new Texte; |
|
| 105 | - $texte->texte = 'emb'; |
|
| 106 | - $param = array('', array($texte)); |
|
| 107 | - |
|
| 108 | - // Transformer les filtres en arguments |
|
| 109 | - for ($i = 0; $i < count($p->param); $i++) { |
|
| 110 | - if ($p->param[$i][0]) { |
|
| 111 | - if (!strstr($p->param[$i][0], '=')) { |
|
| 112 | - break; |
|
| 113 | - }# on a rencontre un vrai filtre, c'est fini |
|
| 114 | - $texte = new Texte; |
|
| 115 | - $texte->texte = $p->param[$i][0]; |
|
| 116 | - $param[] = array($texte); |
|
| 117 | - } |
|
| 118 | - array_shift($p->param); |
|
| 119 | - } |
|
| 120 | - array_unshift($p->param, $param); |
|
| 121 | - spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 122 | - $p->nom_champ = 'MODELE'; |
|
| 99 | + if (!is_array($p->param)) { |
|
| 100 | + $p->param = array(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // Produire le premier argument {emb} |
|
| 104 | + $texte = new Texte; |
|
| 105 | + $texte->texte = 'emb'; |
|
| 106 | + $param = array('', array($texte)); |
|
| 107 | + |
|
| 108 | + // Transformer les filtres en arguments |
|
| 109 | + for ($i = 0; $i < count($p->param); $i++) { |
|
| 110 | + if ($p->param[$i][0]) { |
|
| 111 | + if (!strstr($p->param[$i][0], '=')) { |
|
| 112 | + break; |
|
| 113 | + }# on a rencontre un vrai filtre, c'est fini |
|
| 114 | + $texte = new Texte; |
|
| 115 | + $texte->texte = $p->param[$i][0]; |
|
| 116 | + $param[] = array($texte); |
|
| 117 | + } |
|
| 118 | + array_shift($p->param); |
|
| 119 | + } |
|
| 120 | + array_unshift($p->param, $param); |
|
| 121 | + spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 122 | + $p->nom_champ = 'MODELE'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // Vieux formulaire de recherch |
| 126 | 126 | |
| 127 | 127 | function phraser_vieux_recherche($p) { |
| 128 | - if ($p->param[0][0]) { |
|
| 129 | - $c = new Texte; |
|
| 130 | - $c->texte = $p->param[0][0]; |
|
| 131 | - $p->param[0][1] = array($c); |
|
| 132 | - $p->param[0][0] = ''; |
|
| 133 | - $p->fonctions = array(); |
|
| 134 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 135 | - } |
|
| 128 | + if ($p->param[0][0]) { |
|
| 129 | + $c = new Texte; |
|
| 130 | + $c->texte = $p->param[0][0]; |
|
| 131 | + $p->param[0][1] = array($c); |
|
| 132 | + $p->param[0][0] = ''; |
|
| 133 | + $p->fonctions = array(); |
|
| 134 | + spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 135 | + } |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Gerer la notation [(#EXPOSER|on,off)] |
| 139 | 139 | function phraser_vieux_exposer($p) { |
| 140 | - if ($a = $p->fonctions) { |
|
| 141 | - preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs); |
|
| 142 | - $args = array(); |
|
| 143 | - if ($regs[1]) { |
|
| 144 | - $a = new Texte; |
|
| 145 | - $a->texte = $regs[1]; |
|
| 146 | - $args = array('', array($a)); |
|
| 147 | - if ($regs[3]) { |
|
| 148 | - $a = new Texte; |
|
| 149 | - $a->texte = $regs[3]; |
|
| 150 | - $args[] = array($a); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - $p->param[0] = $args; |
|
| 154 | - $p->fonctions = array(); |
|
| 155 | - $p->nom_champ = 'EXPOSE'; |
|
| 156 | - } |
|
| 140 | + if ($a = $p->fonctions) { |
|
| 141 | + preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs); |
|
| 142 | + $args = array(); |
|
| 143 | + if ($regs[1]) { |
|
| 144 | + $a = new Texte; |
|
| 145 | + $a->texte = $regs[1]; |
|
| 146 | + $args = array('', array($a)); |
|
| 147 | + if ($regs[3]) { |
|
| 148 | + $a = new Texte; |
|
| 149 | + $a->texte = $regs[3]; |
|
| 150 | + $args[] = array($a); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + $p->param[0] = $args; |
|
| 154 | + $p->fonctions = array(); |
|
| 155 | + $p->nom_champ = 'EXPOSE'; |
|
| 156 | + } |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | function phraser_vieux_modele($p) { normaliser_args_inclumodel($p); } |
@@ -161,55 +161,55 @@ discard block |
||
| 161 | 161 | function phraser_vieux_inclu($p) { normaliser_args_inclumodel($p); } |
| 162 | 162 | |
| 163 | 163 | function normaliser_args_inclumodel($p) { |
| 164 | - $params = $p->param; |
|
| 165 | - if (!$params) { |
|
| 166 | - return; |
|
| 167 | - } |
|
| 168 | - $args = $params[0]; |
|
| 169 | - if ($args[0]) { |
|
| 170 | - return; |
|
| 171 | - } // filtre immediat |
|
| 172 | - array_shift($p->param); |
|
| 173 | - foreach ($p->param as $l) { |
|
| 174 | - if (!array_shift($l)) { |
|
| 175 | - $args = array_merge($args, $l); |
|
| 176 | - array_shift($p->param); |
|
| 177 | - } else { |
|
| 178 | - break; |
|
| 179 | - } // filtre |
|
| 180 | - } |
|
| 181 | - array_unshift($p->param, $args); |
|
| 164 | + $params = $p->param; |
|
| 165 | + if (!$params) { |
|
| 166 | + return; |
|
| 167 | + } |
|
| 168 | + $args = $params[0]; |
|
| 169 | + if ($args[0]) { |
|
| 170 | + return; |
|
| 171 | + } // filtre immediat |
|
| 172 | + array_shift($p->param); |
|
| 173 | + foreach ($p->param as $l) { |
|
| 174 | + if (!array_shift($l)) { |
|
| 175 | + $args = array_merge($args, $l); |
|
| 176 | + array_shift($p->param); |
|
| 177 | + } else { |
|
| 178 | + break; |
|
| 179 | + } // filtre |
|
| 180 | + } |
|
| 181 | + array_unshift($p->param, $args); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function normaliser_inclure($champ) { |
| 185 | - normaliser_args_inclumodel($champ); |
|
| 186 | - $l = $champ->param[0]; |
|
| 187 | - if (is_array($l) and !$l[0]) { |
|
| 188 | - foreach ($l as $k => $p) { |
|
| 189 | - if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 190 | - $p[0]->texte = trim($p[0]->texte); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - foreach ($l as $k => $p) { |
|
| 194 | - if (!$p or $p[0]->type != 'texte' or |
|
| 195 | - !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 196 | - ) { |
|
| 197 | - continue; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($r[1]) { |
|
| 201 | - $p[0]->texte = $r[1]; |
|
| 202 | - } else { |
|
| 203 | - unset($p[0]); |
|
| 204 | - } |
|
| 205 | - $champ->texte = $p; |
|
| 206 | - unset($champ->param[0][$k]); |
|
| 207 | - if (count($champ->param[0]) == 1) { |
|
| 208 | - array_shift($champ->param); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - spip_log("inclure sans fond ni fichier"); |
|
| 185 | + normaliser_args_inclumodel($champ); |
|
| 186 | + $l = $champ->param[0]; |
|
| 187 | + if (is_array($l) and !$l[0]) { |
|
| 188 | + foreach ($l as $k => $p) { |
|
| 189 | + if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 190 | + $p[0]->texte = trim($p[0]->texte); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + foreach ($l as $k => $p) { |
|
| 194 | + if (!$p or $p[0]->type != 'texte' or |
|
| 195 | + !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 196 | + ) { |
|
| 197 | + continue; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($r[1]) { |
|
| 201 | + $p[0]->texte = $r[1]; |
|
| 202 | + } else { |
|
| 203 | + unset($p[0]); |
|
| 204 | + } |
|
| 205 | + $champ->texte = $p; |
|
| 206 | + unset($champ->param[0][$k]); |
|
| 207 | + if (count($champ->param[0]) == 1) { |
|
| 208 | + array_shift($champ->param); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + spip_log("inclure sans fond ni fichier"); |
|
| 215 | 215 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | // Les parametres generaux du site sont dans une table SQL; |
@@ -28,47 +28,47 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | // https://code.spip.net/@inc_meta_dist |
| 30 | 30 | function inc_meta_dist($table = 'meta') { |
| 31 | - // Lire les meta, en cache si present, valide et lisible |
|
| 32 | - // en cas d'install ne pas faire confiance au meta_cache eventuel |
|
| 33 | - $cache = cache_meta($table); |
|
| 31 | + // Lire les meta, en cache si present, valide et lisible |
|
| 32 | + // en cas d'install ne pas faire confiance au meta_cache eventuel |
|
| 33 | + $cache = cache_meta($table); |
|
| 34 | 34 | |
| 35 | - if ((!$exec = _request('exec') or !autoriser_sans_cookie($exec)) |
|
| 36 | - and $new = jeune_fichier($cache, _META_CACHE_TIME) |
|
| 37 | - and lire_fichier_securise($cache, $meta) |
|
| 38 | - and $meta = @unserialize($meta) |
|
| 39 | - ) { |
|
| 40 | - $GLOBALS[$table] = $meta; |
|
| 41 | - } |
|
| 35 | + if ((!$exec = _request('exec') or !autoriser_sans_cookie($exec)) |
|
| 36 | + and $new = jeune_fichier($cache, _META_CACHE_TIME) |
|
| 37 | + and lire_fichier_securise($cache, $meta) |
|
| 38 | + and $meta = @unserialize($meta) |
|
| 39 | + ) { |
|
| 40 | + $GLOBALS[$table] = $meta; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - if (isset($GLOBALS[$table]['touch']) |
|
| 44 | - and ($GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME) |
|
| 45 | - ) { |
|
| 46 | - $GLOBALS[$table] = array(); |
|
| 47 | - } |
|
| 48 | - // sinon lire en base |
|
| 49 | - if (!$GLOBALS[$table]) { |
|
| 50 | - $new = !lire_metas($table); |
|
| 51 | - } |
|
| 43 | + if (isset($GLOBALS[$table]['touch']) |
|
| 44 | + and ($GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME) |
|
| 45 | + ) { |
|
| 46 | + $GLOBALS[$table] = array(); |
|
| 47 | + } |
|
| 48 | + // sinon lire en base |
|
| 49 | + if (!$GLOBALS[$table]) { |
|
| 50 | + $new = !lire_metas($table); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // renouveller l'alea general si trop vieux ou sur demande explicite |
|
| 54 | - if ((test_espace_prive() || isset($_GET['renouvelle_alea'])) |
|
| 55 | - and $GLOBALS[$table] |
|
| 56 | - and (time() > _RENOUVELLE_ALEA + (isset($GLOBALS['meta']['alea_ephemere_date']) ? $GLOBALS['meta']['alea_ephemere_date'] : 0)) |
|
| 57 | - ) { |
|
| 58 | - // si on n'a pas l'acces en ecriture sur le cache, |
|
| 59 | - // ne pas renouveller l'alea sinon le cache devient faux |
|
| 60 | - if (supprimer_fichier($cache)) { |
|
| 61 | - include_spip('inc/acces'); |
|
| 62 | - renouvelle_alea(); |
|
| 63 | - $new = false; |
|
| 64 | - } else { |
|
| 65 | - spip_log("impossible d'ecrire dans " . $cache); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - // et refaire le cache si on a du lire en base |
|
| 69 | - if (!$new) { |
|
| 70 | - touch_meta(false, $table); |
|
| 71 | - } |
|
| 53 | + // renouveller l'alea general si trop vieux ou sur demande explicite |
|
| 54 | + if ((test_espace_prive() || isset($_GET['renouvelle_alea'])) |
|
| 55 | + and $GLOBALS[$table] |
|
| 56 | + and (time() > _RENOUVELLE_ALEA + (isset($GLOBALS['meta']['alea_ephemere_date']) ? $GLOBALS['meta']['alea_ephemere_date'] : 0)) |
|
| 57 | + ) { |
|
| 58 | + // si on n'a pas l'acces en ecriture sur le cache, |
|
| 59 | + // ne pas renouveller l'alea sinon le cache devient faux |
|
| 60 | + if (supprimer_fichier($cache)) { |
|
| 61 | + include_spip('inc/acces'); |
|
| 62 | + renouvelle_alea(); |
|
| 63 | + $new = false; |
|
| 64 | + } else { |
|
| 65 | + spip_log("impossible d'ecrire dans " . $cache); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + // et refaire le cache si on a du lire en base |
|
| 69 | + if (!$new) { |
|
| 70 | + touch_meta(false, $table); |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // fonctions aussi appelees a l'install ==> spip_query en premiere requete |
@@ -77,38 +77,38 @@ discard block |
||
| 77 | 77 | // https://code.spip.net/@lire_metas |
| 78 | 78 | function lire_metas($table = 'meta') { |
| 79 | 79 | |
| 80 | - if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) { |
|
| 81 | - include_spip('base/abstract_sql'); |
|
| 82 | - $GLOBALS[$table] = array(); |
|
| 83 | - while ($row = sql_fetch($result)) { |
|
| 84 | - $GLOBALS[$table][$row['nom']] = $row['valeur']; |
|
| 85 | - } |
|
| 86 | - sql_free($result); |
|
| 80 | + if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) { |
|
| 81 | + include_spip('base/abstract_sql'); |
|
| 82 | + $GLOBALS[$table] = array(); |
|
| 83 | + while ($row = sql_fetch($result)) { |
|
| 84 | + $GLOBALS[$table][$row['nom']] = $row['valeur']; |
|
| 85 | + } |
|
| 86 | + sql_free($result); |
|
| 87 | 87 | |
| 88 | - if (!isset($GLOBALS[$table]['charset']) |
|
| 89 | - or !$GLOBALS[$table]['charset'] |
|
| 90 | - or $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install |
|
| 91 | - ) { |
|
| 92 | - ecrire_meta('charset', _DEFAULT_CHARSET, null, $table); |
|
| 93 | - } |
|
| 88 | + if (!isset($GLOBALS[$table]['charset']) |
|
| 89 | + or !$GLOBALS[$table]['charset'] |
|
| 90 | + or $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install |
|
| 91 | + ) { |
|
| 92 | + ecrire_meta('charset', _DEFAULT_CHARSET, null, $table); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - // noter cette table de configuration dans les meta de SPIP |
|
| 96 | - if ($table !== 'meta') { |
|
| 97 | - $liste = array(); |
|
| 98 | - if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 99 | - $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 100 | - } |
|
| 101 | - if (!$liste) { |
|
| 102 | - $liste = array(); |
|
| 103 | - } |
|
| 104 | - if (!in_array($table, $liste)) { |
|
| 105 | - $liste[] = $table; |
|
| 106 | - ecrire_meta('tables_config', serialize($liste)); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 95 | + // noter cette table de configuration dans les meta de SPIP |
|
| 96 | + if ($table !== 'meta') { |
|
| 97 | + $liste = array(); |
|
| 98 | + if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 99 | + $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 100 | + } |
|
| 101 | + if (!$liste) { |
|
| 102 | + $liste = array(); |
|
| 103 | + } |
|
| 104 | + if (!in_array($table, $liste)) { |
|
| 105 | + $liste[] = $table; |
|
| 106 | + ecrire_meta('tables_config', serialize($liste)); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - return isset($GLOBALS[$table]) ? $GLOBALS[$table] : null; |
|
| 111 | + return isset($GLOBALS[$table]) ? $GLOBALS[$table] : null; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | |
@@ -122,22 +122,22 @@ discard block |
||
| 122 | 122 | * Table SQL d'enregistrement des meta. |
| 123 | 123 | **/ |
| 124 | 124 | function touch_meta($antidate = false, $table = 'meta') { |
| 125 | - $file = cache_meta($table); |
|
| 126 | - if (!$antidate or !@touch($file, $antidate)) { |
|
| 127 | - $r = isset($GLOBALS[$table]) ? $GLOBALS[$table] : array(); |
|
| 128 | - if ($table == 'meta') { |
|
| 129 | - unset($r['alea_ephemere']); |
|
| 130 | - unset($r['alea_ephemere_ancien']); |
|
| 131 | - // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables |
|
| 132 | - // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique |
|
| 133 | - // meme si son squelette est en cache |
|
| 134 | - //unset($r['secret_du_site']); |
|
| 135 | - if ($antidate) { |
|
| 136 | - $r['touch'] = $antidate; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - ecrire_fichier_securise($file, serialize($r)); |
|
| 140 | - } |
|
| 125 | + $file = cache_meta($table); |
|
| 126 | + if (!$antidate or !@touch($file, $antidate)) { |
|
| 127 | + $r = isset($GLOBALS[$table]) ? $GLOBALS[$table] : array(); |
|
| 128 | + if ($table == 'meta') { |
|
| 129 | + unset($r['alea_ephemere']); |
|
| 130 | + unset($r['alea_ephemere_ancien']); |
|
| 131 | + // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables |
|
| 132 | + // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique |
|
| 133 | + // meme si son squelette est en cache |
|
| 134 | + //unset($r['secret_du_site']); |
|
| 135 | + if ($antidate) { |
|
| 136 | + $r['touch'] = $antidate; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + ecrire_fichier_securise($file, serialize($r)); |
|
| 140 | + } |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -153,21 +153,21 @@ discard block |
||
| 153 | 153 | * Table SQL d'enregistrement de la meta. |
| 154 | 154 | **/ |
| 155 | 155 | function effacer_meta($nom, $table = 'meta') { |
| 156 | - // section critique sur le cache: |
|
| 157 | - // l'invalider avant et apres la MAJ de la BD |
|
| 158 | - // c'est un peu moins bien qu'un vrai verrou mais ca suffira |
|
| 159 | - // et utiliser une statique pour eviter des acces disques a repetition |
|
| 160 | - static $touch = array(); |
|
| 161 | - $antidate = time() - (_META_CACHE_TIME << 4); |
|
| 162 | - if (!isset($touch[$table])) { |
|
| 163 | - touch_meta($antidate, $table); |
|
| 164 | - } |
|
| 165 | - sql_delete('spip_' . $table, "nom='$nom'", '', 'continue'); |
|
| 166 | - unset($GLOBALS[$table][$nom]); |
|
| 167 | - if (!isset($touch[$table])) { |
|
| 168 | - touch_meta($antidate, $table); |
|
| 169 | - $touch[$table] = false; |
|
| 170 | - } |
|
| 156 | + // section critique sur le cache: |
|
| 157 | + // l'invalider avant et apres la MAJ de la BD |
|
| 158 | + // c'est un peu moins bien qu'un vrai verrou mais ca suffira |
|
| 159 | + // et utiliser une statique pour eviter des acces disques a repetition |
|
| 160 | + static $touch = array(); |
|
| 161 | + $antidate = time() - (_META_CACHE_TIME << 4); |
|
| 162 | + if (!isset($touch[$table])) { |
|
| 163 | + touch_meta($antidate, $table); |
|
| 164 | + } |
|
| 165 | + sql_delete('spip_' . $table, "nom='$nom'", '', 'continue'); |
|
| 166 | + unset($GLOBALS[$table][$nom]); |
|
| 167 | + if (!isset($touch[$table])) { |
|
| 168 | + touch_meta($antidate, $table); |
|
| 169 | + $touch[$table] = false; |
|
| 170 | + } |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -188,52 +188,52 @@ discard block |
||
| 188 | 188 | **/ |
| 189 | 189 | function ecrire_meta($nom, $valeur, $importable = null, $table = 'meta') { |
| 190 | 190 | |
| 191 | - static $touch = array(); |
|
| 192 | - if (!$nom) { |
|
| 193 | - return; |
|
| 194 | - } |
|
| 195 | - include_spip('base/abstract_sql'); |
|
| 196 | - $res = sql_select("*", 'spip_' . $table, "nom=" . sql_quote($nom), '', '', '', '', '', 'continue'); |
|
| 197 | - // table pas encore installee, travailler en php seulement |
|
| 198 | - if (!$res) { |
|
| 199 | - $GLOBALS[$table][$nom] = $valeur; |
|
| 191 | + static $touch = array(); |
|
| 192 | + if (!$nom) { |
|
| 193 | + return; |
|
| 194 | + } |
|
| 195 | + include_spip('base/abstract_sql'); |
|
| 196 | + $res = sql_select("*", 'spip_' . $table, "nom=" . sql_quote($nom), '', '', '', '', '', 'continue'); |
|
| 197 | + // table pas encore installee, travailler en php seulement |
|
| 198 | + if (!$res) { |
|
| 199 | + $GLOBALS[$table][$nom] = $valeur; |
|
| 200 | 200 | |
| 201 | - return; |
|
| 202 | - } |
|
| 203 | - $row = sql_fetch($res); |
|
| 204 | - sql_free($res); |
|
| 201 | + return; |
|
| 202 | + } |
|
| 203 | + $row = sql_fetch($res); |
|
| 204 | + sql_free($res); |
|
| 205 | 205 | |
| 206 | - // ne pas invalider le cache si affectation a l'identique |
|
| 207 | - // (tant pis si impt aurait du changer) |
|
| 208 | - if ($row and $valeur == $row['valeur'] |
|
| 209 | - and isset($GLOBALS[$table][$nom]) |
|
| 210 | - and $GLOBALS[$table][$nom] == $valeur |
|
| 211 | - ) { |
|
| 212 | - return; |
|
| 213 | - } |
|
| 206 | + // ne pas invalider le cache si affectation a l'identique |
|
| 207 | + // (tant pis si impt aurait du changer) |
|
| 208 | + if ($row and $valeur == $row['valeur'] |
|
| 209 | + and isset($GLOBALS[$table][$nom]) |
|
| 210 | + and $GLOBALS[$table][$nom] == $valeur |
|
| 211 | + ) { |
|
| 212 | + return; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - $GLOBALS[$table][$nom] = $valeur; |
|
| 216 | - // cf effacer pour comprendre le double touch |
|
| 217 | - $antidate = time() - (_META_CACHE_TIME << 1); |
|
| 218 | - if (!isset($touch[$table])) { |
|
| 219 | - touch_meta($antidate, $table); |
|
| 220 | - } |
|
| 221 | - $r = array('nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')); |
|
| 222 | - // Gaffe aux tables sans impt (vieilles versions de SPIP notamment) |
|
| 223 | - // ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot |
|
| 224 | - // de lecture des descriptions des tables |
|
| 225 | - if ($importable and isset($row['impt'])) { |
|
| 226 | - $r['impt'] = sql_quote($importable, '', 'text'); |
|
| 227 | - } |
|
| 228 | - if ($row) { |
|
| 229 | - sql_update('spip_' . $table, $r, "nom=" . sql_quote($nom)); |
|
| 230 | - } else { |
|
| 231 | - sql_insert('spip_' . $table, "(" . join(',', array_keys($r)) . ")", "(" . join(',', array_values($r)) . ")"); |
|
| 232 | - } |
|
| 233 | - if (!isset($touch[$table])) { |
|
| 234 | - touch_meta($antidate, $table); |
|
| 235 | - $touch[$table] = false; |
|
| 236 | - } |
|
| 215 | + $GLOBALS[$table][$nom] = $valeur; |
|
| 216 | + // cf effacer pour comprendre le double touch |
|
| 217 | + $antidate = time() - (_META_CACHE_TIME << 1); |
|
| 218 | + if (!isset($touch[$table])) { |
|
| 219 | + touch_meta($antidate, $table); |
|
| 220 | + } |
|
| 221 | + $r = array('nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')); |
|
| 222 | + // Gaffe aux tables sans impt (vieilles versions de SPIP notamment) |
|
| 223 | + // ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot |
|
| 224 | + // de lecture des descriptions des tables |
|
| 225 | + if ($importable and isset($row['impt'])) { |
|
| 226 | + $r['impt'] = sql_quote($importable, '', 'text'); |
|
| 227 | + } |
|
| 228 | + if ($row) { |
|
| 229 | + sql_update('spip_' . $table, $r, "nom=" . sql_quote($nom)); |
|
| 230 | + } else { |
|
| 231 | + sql_insert('spip_' . $table, "(" . join(',', array_keys($r)) . ")", "(" . join(',', array_values($r)) . ")"); |
|
| 232 | + } |
|
| 233 | + if (!isset($touch[$table])) { |
|
| 234 | + touch_meta($antidate, $table); |
|
| 235 | + $touch[$table] = false; |
|
| 236 | + } |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * Nom du fichier cache |
| 246 | 246 | **/ |
| 247 | 247 | function cache_meta($table = 'meta') { |
| 248 | - return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 248 | + return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -254,14 +254,14 @@ discard block |
||
| 254 | 254 | * @param string $table |
| 255 | 255 | */ |
| 256 | 256 | function installer_table_meta($table) { |
| 257 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 258 | - if (!$trouver_table("spip_$table")) { |
|
| 259 | - include_spip('base/auxiliaires'); |
|
| 260 | - include_spip('base/create'); |
|
| 261 | - creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false); |
|
| 262 | - $trouver_table(''); |
|
| 263 | - } |
|
| 264 | - lire_metas($table); |
|
| 257 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 258 | + if (!$trouver_table("spip_$table")) { |
|
| 259 | + include_spip('base/auxiliaires'); |
|
| 260 | + include_spip('base/create'); |
|
| 261 | + creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false); |
|
| 262 | + $trouver_table(''); |
|
| 263 | + } |
|
| 264 | + lire_metas($table); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -273,47 +273,47 @@ discard block |
||
| 273 | 273 | * @param bool $force |
| 274 | 274 | */ |
| 275 | 275 | function supprimer_table_meta($table, $force = false) { |
| 276 | - if ($table !== 'meta') { |
|
| 277 | - // Vérifier le contenu restant de la table |
|
| 278 | - $nb_variables = sql_countsel("spip_$table"); |
|
| 276 | + if ($table !== 'meta') { |
|
| 277 | + // Vérifier le contenu restant de la table |
|
| 278 | + $nb_variables = sql_countsel("spip_$table"); |
|
| 279 | 279 | |
| 280 | - // Supprimer si : |
|
| 281 | - // - la table est vide |
|
| 282 | - // - ou limitée à la variable charset |
|
| 283 | - // - ou qu'on force la suppression |
|
| 284 | - if ( |
|
| 285 | - $force |
|
| 286 | - or !$nb_variables |
|
| 287 | - or ( |
|
| 288 | - ($nb_variables == 1) |
|
| 289 | - and isset($GLOBALS[$table]['charset']) |
|
| 290 | - ) |
|
| 291 | - ) { |
|
| 292 | - // Supprimer la table des globaleset de la base |
|
| 293 | - unset($GLOBALS[$table]); |
|
| 294 | - sql_drop_table("spip_$table"); |
|
| 295 | - // Supprimer le fichier cache |
|
| 296 | - include_spip('inc/flock'); |
|
| 297 | - $cache = cache_meta($table); |
|
| 298 | - supprimer_fichier($cache); |
|
| 280 | + // Supprimer si : |
|
| 281 | + // - la table est vide |
|
| 282 | + // - ou limitée à la variable charset |
|
| 283 | + // - ou qu'on force la suppression |
|
| 284 | + if ( |
|
| 285 | + $force |
|
| 286 | + or !$nb_variables |
|
| 287 | + or ( |
|
| 288 | + ($nb_variables == 1) |
|
| 289 | + and isset($GLOBALS[$table]['charset']) |
|
| 290 | + ) |
|
| 291 | + ) { |
|
| 292 | + // Supprimer la table des globaleset de la base |
|
| 293 | + unset($GLOBALS[$table]); |
|
| 294 | + sql_drop_table("spip_$table"); |
|
| 295 | + // Supprimer le fichier cache |
|
| 296 | + include_spip('inc/flock'); |
|
| 297 | + $cache = cache_meta($table); |
|
| 298 | + supprimer_fichier($cache); |
|
| 299 | 299 | |
| 300 | - // vider le cache des tables |
|
| 301 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 302 | - $trouver_table(''); |
|
| 300 | + // vider le cache des tables |
|
| 301 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 302 | + $trouver_table(''); |
|
| 303 | 303 | |
| 304 | - // Supprimer la table de la liste des tables de configuration autres que spip_meta |
|
| 305 | - if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 306 | - $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 307 | - $cle = array_search($table, $liste); |
|
| 308 | - if ($cle !== false) { |
|
| 309 | - unset($liste[$cle]); |
|
| 310 | - if ($liste ) { |
|
| 311 | - ecrire_meta('tables_config', serialize($liste)); |
|
| 312 | - } else { |
|
| 313 | - effacer_meta('tables_config'); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - } |
|
| 304 | + // Supprimer la table de la liste des tables de configuration autres que spip_meta |
|
| 305 | + if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 306 | + $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 307 | + $cle = array_search($table, $liste); |
|
| 308 | + if ($cle !== false) { |
|
| 309 | + unset($liste[$cle]); |
|
| 310 | + if ($liste ) { |
|
| 311 | + ecrire_meta('tables_config', serialize($liste)); |
|
| 312 | + } else { |
|
| 313 | + effacer_meta('tables_config'); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | 319 | } |
@@ -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('base/abstract_sql'); |
@@ -23,16 +23,16 @@ discard block |
||
| 23 | 23 | // |
| 24 | 24 | |
| 25 | 25 | function inc_lien_dist( |
| 26 | - $lien, |
|
| 27 | - $texte = '', |
|
| 28 | - $class = '', |
|
| 29 | - $title = '', |
|
| 30 | - $hlang = '', |
|
| 31 | - $rel = '', |
|
| 32 | - $connect = '', |
|
| 33 | - $env = array() |
|
| 26 | + $lien, |
|
| 27 | + $texte = '', |
|
| 28 | + $class = '', |
|
| 29 | + $title = '', |
|
| 30 | + $hlang = '', |
|
| 31 | + $rel = '', |
|
| 32 | + $connect = '', |
|
| 33 | + $env = array() |
|
| 34 | 34 | ) { |
| 35 | - return $lien; |
|
| 35 | + return $lien; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip |
@@ -44,30 +44,30 @@ discard block |
||
| 44 | 44 | // https://code.spip.net/@expanser_liens |
| 45 | 45 | function expanser_liens($t, $connect = '', $env = array()) { |
| 46 | 46 | |
| 47 | - $t = pipeline('pre_liens', $t); |
|
| 47 | + $t = pipeline('pre_liens', $t); |
|
| 48 | 48 | |
| 49 | - // on passe a traiter_modeles la liste des liens reperes pour lui permettre |
|
| 50 | - // de remettre le texte d'origine dans les parametres du modele |
|
| 51 | - $t = traiter_modeles($t, false, false, $connect); |
|
| 49 | + // on passe a traiter_modeles la liste des liens reperes pour lui permettre |
|
| 50 | + // de remettre le texte d'origine dans les parametres du modele |
|
| 51 | + $t = traiter_modeles($t, false, false, $connect); |
|
| 52 | 52 | |
| 53 | - return $t; |
|
| 53 | + return $t; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // Meme analyse mais pour eliminer les liens |
| 57 | 57 | // et ne laisser que leur titre, a expliciter si ce n'est fait |
| 58 | 58 | // https://code.spip.net/@nettoyer_raccourcis_typo |
| 59 | 59 | function nettoyer_raccourcis_typo($texte, $connect = '') { |
| 60 | - return $texte; |
|
| 60 | + return $texte; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Repere dans la partie texte d'un raccourci [texte->...] |
| 64 | 64 | // la langue et la bulle eventuelles |
| 65 | 65 | // https://code.spip.net/@traiter_raccourci_lien_atts |
| 66 | 66 | function traiter_raccourci_lien_atts($texte) { |
| 67 | - $bulle = ''; |
|
| 68 | - $hlang = ''; |
|
| 67 | + $bulle = ''; |
|
| 68 | + $hlang = ''; |
|
| 69 | 69 | |
| 70 | - return array(trim($texte), $bulle, $hlang); |
|
| 70 | + return array(trim($texte), $bulle, $hlang); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | define('_RACCOURCI_CHAPO', '/^(\W*)(\W*)(\w*\d+([?#].*)?)$/'); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @return string |
| 84 | 84 | */ |
| 85 | 85 | function virtuel_redirige($virtuel, $url = false) { |
| 86 | - return $virtuel; |
|
| 86 | + return $virtuel; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // Cherche un lien du type [->raccourci 123] |
@@ -97,114 +97,114 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | // https://code.spip.net/@calculer_url |
| 99 | 99 | function calculer_url($ref, $texte = '', $pour = 'url', $connect = '', $echappe_typo = true) { |
| 100 | - $r = traiter_lien_implicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 100 | + $r = traiter_lien_implicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 101 | 101 | |
| 102 | - return $r ? $r : traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 102 | + return $r ? $r : traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS'); |
| 106 | 106 | |
| 107 | 107 | // https://code.spip.net/@traiter_lien_explicite |
| 108 | 108 | function traiter_lien_explicite($ref, $texte = '', $pour = 'url', $connect = '', $echappe_typo = true) { |
| 109 | - if (preg_match(_EXTRAIRE_LIEN, $ref)) { |
|
| 110 | - return ($pour != 'tout') ? '' : array('', '', '', ''); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $lien = entites_html(trim($ref)); |
|
| 114 | - |
|
| 115 | - // Liens explicites |
|
| 116 | - if (!$texte) { |
|
| 117 | - $texte = str_replace('"', '', $lien); |
|
| 118 | - // evite l'affichage de trops longues urls. |
|
| 119 | - $lien_court = charger_fonction('lien_court', 'inc'); |
|
| 120 | - $texte = $lien_court($texte); |
|
| 121 | - if ($echappe_typo) { |
|
| 122 | - $texte = "<html>" . quote_amp($texte) . "</html>"; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // petites corrections d'URL |
|
| 127 | - if (preg_match('/^www\.[^@]+$/S', $lien)) { |
|
| 128 | - $lien = "http://" . $lien; |
|
| 129 | - } else { |
|
| 130 | - if (strpos($lien, "@") && email_valide($lien)) { |
|
| 131 | - if (!$texte) { |
|
| 132 | - $texte = $lien; |
|
| 133 | - } |
|
| 134 | - $lien = "mailto:" . $lien; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - if ($pour == 'url') { |
|
| 139 | - return $lien; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - if ($pour == 'titre') { |
|
| 143 | - return $texte; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return array('url' => $lien, 'titre' => $texte); |
|
| 109 | + if (preg_match(_EXTRAIRE_LIEN, $ref)) { |
|
| 110 | + return ($pour != 'tout') ? '' : array('', '', '', ''); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $lien = entites_html(trim($ref)); |
|
| 114 | + |
|
| 115 | + // Liens explicites |
|
| 116 | + if (!$texte) { |
|
| 117 | + $texte = str_replace('"', '', $lien); |
|
| 118 | + // evite l'affichage de trops longues urls. |
|
| 119 | + $lien_court = charger_fonction('lien_court', 'inc'); |
|
| 120 | + $texte = $lien_court($texte); |
|
| 121 | + if ($echappe_typo) { |
|
| 122 | + $texte = "<html>" . quote_amp($texte) . "</html>"; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // petites corrections d'URL |
|
| 127 | + if (preg_match('/^www\.[^@]+$/S', $lien)) { |
|
| 128 | + $lien = "http://" . $lien; |
|
| 129 | + } else { |
|
| 130 | + if (strpos($lien, "@") && email_valide($lien)) { |
|
| 131 | + if (!$texte) { |
|
| 132 | + $texte = $lien; |
|
| 133 | + } |
|
| 134 | + $lien = "mailto:" . $lien; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + if ($pour == 'url') { |
|
| 139 | + return $lien; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + if ($pour == 'titre') { |
|
| 143 | + return $texte; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return array('url' => $lien, 'titre' => $texte); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, $connect = '') { |
| 150 | - if (function_exists($f = 'glossaire_' . $ancre)) { |
|
| 151 | - $url = $f($texte, $id); |
|
| 152 | - } else { |
|
| 153 | - $url = glossaire_std($texte); |
|
| 154 | - } |
|
| 150 | + if (function_exists($f = 'glossaire_' . $ancre)) { |
|
| 151 | + $url = $f($texte, $id); |
|
| 152 | + } else { |
|
| 153 | + $url = glossaire_std($texte); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - return $url; |
|
| 156 | + return $url; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // https://code.spip.net/@traiter_lien_implicite |
| 160 | 160 | function traiter_lien_implicite($ref, $texte = '', $pour = 'url', $connect = '') { |
| 161 | - if (!($match = typer_raccourci($ref))) { |
|
| 162 | - return false; |
|
| 163 | - } |
|
| 164 | - @list($type, , $id, , $args, , $ancre) = $match; |
|
| 165 | - // attention dans le cas des sites le lien doit pointer non pas sur |
|
| 166 | - // la page locale du site, mais directement sur le site lui-meme |
|
| 167 | - if ($f = charger_fonction("implicite_$type", "liens", true)) { |
|
| 168 | - $url = $f($texte, $id, $type, $args, $ancre, $connect); |
|
| 169 | - } |
|
| 170 | - if (!$url) { |
|
| 171 | - $url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : null); |
|
| 172 | - } |
|
| 173 | - if (!$url) { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - if (is_array($url)) { |
|
| 177 | - @list($type, $id) = $url; |
|
| 178 | - $url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : null); |
|
| 179 | - } |
|
| 180 | - if ($pour === 'url') { |
|
| 181 | - return $url; |
|
| 182 | - } |
|
| 183 | - $r = traiter_raccourci_titre($id, $type, $connect); |
|
| 184 | - if ($r) { |
|
| 185 | - $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in'; |
|
| 186 | - } |
|
| 187 | - if ($texte = trim($texte)) { |
|
| 188 | - $r['titre'] = $texte; |
|
| 189 | - } |
|
| 190 | - if (!@$r['titre']) { |
|
| 191 | - $r['titre'] = _T($type) . " $id"; |
|
| 192 | - } |
|
| 193 | - if ($pour == 'titre') { |
|
| 194 | - return $r['titre']; |
|
| 195 | - } |
|
| 196 | - $r['url'] = $url; |
|
| 197 | - |
|
| 198 | - // dans le cas d'un lien vers un doc, ajouter le type='mime/type' |
|
| 199 | - if ($type == 'document' |
|
| 200 | - and $mime = sql_getfetsel('mime_type', 'spip_types_documents', |
|
| 201 | - "extension IN (" . sql_get_select("extension", "spip_documents", "id_document=" . sql_quote($id)) . ")", |
|
| 202 | - '', '', '', '', $connect) |
|
| 203 | - ) { |
|
| 204 | - $r['mime'] = $mime; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - return $r; |
|
| 161 | + if (!($match = typer_raccourci($ref))) { |
|
| 162 | + return false; |
|
| 163 | + } |
|
| 164 | + @list($type, , $id, , $args, , $ancre) = $match; |
|
| 165 | + // attention dans le cas des sites le lien doit pointer non pas sur |
|
| 166 | + // la page locale du site, mais directement sur le site lui-meme |
|
| 167 | + if ($f = charger_fonction("implicite_$type", "liens", true)) { |
|
| 168 | + $url = $f($texte, $id, $type, $args, $ancre, $connect); |
|
| 169 | + } |
|
| 170 | + if (!$url) { |
|
| 171 | + $url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : null); |
|
| 172 | + } |
|
| 173 | + if (!$url) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + if (is_array($url)) { |
|
| 177 | + @list($type, $id) = $url; |
|
| 178 | + $url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : null); |
|
| 179 | + } |
|
| 180 | + if ($pour === 'url') { |
|
| 181 | + return $url; |
|
| 182 | + } |
|
| 183 | + $r = traiter_raccourci_titre($id, $type, $connect); |
|
| 184 | + if ($r) { |
|
| 185 | + $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in'; |
|
| 186 | + } |
|
| 187 | + if ($texte = trim($texte)) { |
|
| 188 | + $r['titre'] = $texte; |
|
| 189 | + } |
|
| 190 | + if (!@$r['titre']) { |
|
| 191 | + $r['titre'] = _T($type) . " $id"; |
|
| 192 | + } |
|
| 193 | + if ($pour == 'titre') { |
|
| 194 | + return $r['titre']; |
|
| 195 | + } |
|
| 196 | + $r['url'] = $url; |
|
| 197 | + |
|
| 198 | + // dans le cas d'un lien vers un doc, ajouter le type='mime/type' |
|
| 199 | + if ($type == 'document' |
|
| 200 | + and $mime = sql_getfetsel('mime_type', 'spip_types_documents', |
|
| 201 | + "extension IN (" . sql_get_select("extension", "spip_documents", "id_document=" . sql_quote($id)) . ")", |
|
| 202 | + '', '', '', '', $connect) |
|
| 203 | + ) { |
|
| 204 | + $r['mime'] = $mime; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + return $r; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // analyse des raccourcis issus de [TITRE->RACCOURCInnn] et connexes |
@@ -213,41 +213,41 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | // https://code.spip.net/@typer_raccourci |
| 215 | 215 | function typer_raccourci($lien) { |
| 216 | - if (!preg_match(_RACCOURCI_URL, $lien, $match)) { |
|
| 217 | - return array(); |
|
| 218 | - } |
|
| 219 | - $f = $match[1]; |
|
| 220 | - // valeur par defaut et alias historiques |
|
| 221 | - if (!$f) { |
|
| 222 | - $f = 'article'; |
|
| 223 | - } else { |
|
| 224 | - if ($f == 'art') { |
|
| 225 | - $f = 'article'; |
|
| 226 | - } else { |
|
| 227 | - if ($f == 'br') { |
|
| 228 | - $f = 'breve'; |
|
| 229 | - } else { |
|
| 230 | - if ($f == 'rub') { |
|
| 231 | - $f = 'rubrique'; |
|
| 232 | - } else { |
|
| 233 | - if ($f == 'aut') { |
|
| 234 | - $f = 'auteur'; |
|
| 235 | - } else { |
|
| 236 | - if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') { |
|
| 237 | - $f = 'document'; |
|
| 238 | - } else { |
|
| 239 | - if (preg_match('/^br..?ve$/S', $f)) { |
|
| 240 | - $f = 'breve'; |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } # accents :( |
|
| 248 | - $match[0] = $f; |
|
| 249 | - |
|
| 250 | - return $match; |
|
| 216 | + if (!preg_match(_RACCOURCI_URL, $lien, $match)) { |
|
| 217 | + return array(); |
|
| 218 | + } |
|
| 219 | + $f = $match[1]; |
|
| 220 | + // valeur par defaut et alias historiques |
|
| 221 | + if (!$f) { |
|
| 222 | + $f = 'article'; |
|
| 223 | + } else { |
|
| 224 | + if ($f == 'art') { |
|
| 225 | + $f = 'article'; |
|
| 226 | + } else { |
|
| 227 | + if ($f == 'br') { |
|
| 228 | + $f = 'breve'; |
|
| 229 | + } else { |
|
| 230 | + if ($f == 'rub') { |
|
| 231 | + $f = 'rubrique'; |
|
| 232 | + } else { |
|
| 233 | + if ($f == 'aut') { |
|
| 234 | + $f = 'auteur'; |
|
| 235 | + } else { |
|
| 236 | + if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') { |
|
| 237 | + $f = 'document'; |
|
| 238 | + } else { |
|
| 239 | + if (preg_match('/^br..?ve$/S', $f)) { |
|
| 240 | + $f = 'breve'; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } # accents :( |
|
| 248 | + $match[0] = $f; |
|
| 249 | + |
|
| 250 | + return $match; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -262,25 +262,25 @@ discard block |
||
| 262 | 262 | * } |
| 263 | 263 | **/ |
| 264 | 264 | function traiter_raccourci_titre($id, $type, $connect = null) { |
| 265 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 266 | - $desc = $trouver_table(table_objet($type)); |
|
| 267 | - if (!($desc and $s = $desc['titre'])) { |
|
| 268 | - return array(); |
|
| 269 | - } |
|
| 270 | - $_id = $desc['key']['PRIMARY KEY']; |
|
| 271 | - $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect); |
|
| 272 | - if (!$r) { |
|
| 273 | - return array(); |
|
| 274 | - } |
|
| 275 | - $r['titre'] = supprimer_numero($r['titre']); |
|
| 276 | - if (!$r['titre'] and !empty($r['surnom'])) { |
|
| 277 | - $r['titre'] = $r['surnom']; |
|
| 278 | - } |
|
| 279 | - if (!isset($r['lang'])) { |
|
| 280 | - $r['lang'] = ''; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - return $r; |
|
| 265 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 266 | + $desc = $trouver_table(table_objet($type)); |
|
| 267 | + if (!($desc and $s = $desc['titre'])) { |
|
| 268 | + return array(); |
|
| 269 | + } |
|
| 270 | + $_id = $desc['key']['PRIMARY KEY']; |
|
| 271 | + $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect); |
|
| 272 | + if (!$r) { |
|
| 273 | + return array(); |
|
| 274 | + } |
|
| 275 | + $r['titre'] = supprimer_numero($r['titre']); |
|
| 276 | + if (!$r['titre'] and !empty($r['surnom'])) { |
|
| 277 | + $r['titre'] = $r['surnom']; |
|
| 278 | + } |
|
| 279 | + if (!isset($r['lang'])) { |
|
| 280 | + $r['lang'] = ''; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + return $r; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // traite les modeles (dans la fonction typo), en remplacant |
@@ -292,115 +292,115 @@ discard block |
||
| 292 | 292 | // https://code.spip.net/@traiter_modeles |
| 293 | 293 | |
| 294 | 294 | define('_RACCOURCI_MODELE', |
| 295 | - '(<([a-z_-]{3,})' # <modele |
|
| 296 | - . '\s*([0-9]*)\s*' # id |
|
| 297 | - . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 298 | - . '\s*/?' . '>)' # fin du modele > |
|
| 299 | - . '\s*(<\/a>)?' # eventuel </a> |
|
| 295 | + '(<([a-z_-]{3,})' # <modele |
|
| 296 | + . '\s*([0-9]*)\s*' # id |
|
| 297 | + . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 298 | + . '\s*/?' . '>)' # fin du modele > |
|
| 299 | + . '\s*(<\/a>)?' # eventuel </a> |
|
| 300 | 300 | ); |
| 301 | 301 | |
| 302 | 302 | define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS'); |
| 303 | 303 | |
| 304 | 304 | // https://code.spip.net/@traiter_modeles |
| 305 | 305 | function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '', $liens = null, $env = array()) { |
| 306 | - // preserver la compatibilite : true = recherche des documents |
|
| 307 | - if ($doublons === true) { |
|
| 308 | - $doublons = array('documents' => array('doc', 'emb', 'img')); |
|
| 309 | - } |
|
| 310 | - // detecter les modeles (rapide) |
|
| 311 | - if (strpos($texte, "<") !== false and |
|
| 312 | - preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER) |
|
| 313 | - ) { |
|
| 314 | - include_spip('public/assembler'); |
|
| 315 | - $wrap_embed_html = charger_fonction("wrap_embed_html", "inc", true); |
|
| 316 | - foreach ($matches as $match) { |
|
| 317 | - // Recuperer l'appel complet (y compris un eventuel lien) |
|
| 318 | - |
|
| 319 | - $a = strpos($texte, $match[0]); |
|
| 320 | - preg_match(_RACCOURCI_MODELE_DEBUT, |
|
| 321 | - substr($texte, $a), $regs); |
|
| 322 | - $regs[] = ""; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide |
|
| 323 | - list(, $mod, $type, $id, $params, $fin) = $regs; |
|
| 324 | - if ($fin and |
|
| 325 | - preg_match('/<a\s[^<>]*>\s*$/i', |
|
| 326 | - substr($texte, 0, $a), $r) |
|
| 327 | - ) { |
|
| 328 | - $lien = array( |
|
| 329 | - 'href' => extraire_attribut($r[0], 'href'), |
|
| 330 | - 'class' => extraire_attribut($r[0], 'class'), |
|
| 331 | - 'mime' => extraire_attribut($r[0], 'type'), |
|
| 332 | - 'title' => extraire_attribut($r[0], 'title'), |
|
| 333 | - 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 334 | - ); |
|
| 335 | - $n = strlen($r[0]); |
|
| 336 | - $a -= $n; |
|
| 337 | - $cherche = $n + strlen($regs[0]); |
|
| 338 | - } else { |
|
| 339 | - $lien = false; |
|
| 340 | - $cherche = strlen($mod); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - // calculer le modele |
|
| 344 | - # hack indexation |
|
| 345 | - if ($doublons) { |
|
| 346 | - $texte .= preg_replace(',[|][^|=]*,s', ' ', $params); |
|
| 347 | - } # version normale |
|
| 348 | - else { |
|
| 349 | - // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 350 | - // dans les parametres, plutot que les liens echappes |
|
| 351 | - if (!is_null($liens)) { |
|
| 352 | - $params = str_replace($liens[0], $liens[1], $params); |
|
| 353 | - } |
|
| 354 | - $modele = inclure_modele($type, $id, $params, $lien, $connect, $env); |
|
| 355 | - // en cas d'echec, |
|
| 356 | - // si l'objet demande a une url, |
|
| 357 | - // creer un petit encadre vers elle |
|
| 358 | - if ($modele === false) { |
|
| 359 | - if (!$lien) { |
|
| 360 | - $lien = traiter_lien_implicite("$type$id", '', 'tout', $connect); |
|
| 361 | - } |
|
| 362 | - if ($lien) { |
|
| 363 | - $modele = '<a href="' |
|
| 364 | - . $lien['url'] |
|
| 365 | - . '" class="spip_modele' |
|
| 366 | - . '">' |
|
| 367 | - . sinon($lien['titre'], _T('ecrire:info_sans_titre')) |
|
| 368 | - . "</a>"; |
|
| 369 | - } else { |
|
| 370 | - $modele = ""; |
|
| 371 | - if (test_espace_prive()) { |
|
| 372 | - $modele = entites_html(substr($texte, $a, $cherche)); |
|
| 373 | - if (!is_null($liens)) { |
|
| 374 | - $modele = "<pre>" . str_replace($liens[0], $liens[1], $modele) . "</pre>"; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - // le remplacer dans le texte |
|
| 380 | - if ($modele !== false) { |
|
| 381 | - $modele = protege_js_modeles($modele); |
|
| 382 | - if ($wrap_embed_html) { |
|
| 383 | - $modele = $wrap_embed_html($mod, $modele); |
|
| 384 | - } |
|
| 385 | - $rempl = code_echappement($modele, $echap); |
|
| 386 | - $texte = substr($texte, 0, $a) |
|
| 387 | - . $rempl |
|
| 388 | - . substr($texte, $a + $cherche); |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - // hack pour tout l'espace prive |
|
| 393 | - if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) { |
|
| 394 | - foreach ($doublons ? $doublons : array('documents' => array('doc', 'emb', 'img')) as $quoi => $modeles) { |
|
| 395 | - if (in_array($type, $modeles)) { |
|
| 396 | - $GLOBALS["doublons_{$quoi}_inclus"][] = $id; |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - return $texte; |
|
| 306 | + // preserver la compatibilite : true = recherche des documents |
|
| 307 | + if ($doublons === true) { |
|
| 308 | + $doublons = array('documents' => array('doc', 'emb', 'img')); |
|
| 309 | + } |
|
| 310 | + // detecter les modeles (rapide) |
|
| 311 | + if (strpos($texte, "<") !== false and |
|
| 312 | + preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER) |
|
| 313 | + ) { |
|
| 314 | + include_spip('public/assembler'); |
|
| 315 | + $wrap_embed_html = charger_fonction("wrap_embed_html", "inc", true); |
|
| 316 | + foreach ($matches as $match) { |
|
| 317 | + // Recuperer l'appel complet (y compris un eventuel lien) |
|
| 318 | + |
|
| 319 | + $a = strpos($texte, $match[0]); |
|
| 320 | + preg_match(_RACCOURCI_MODELE_DEBUT, |
|
| 321 | + substr($texte, $a), $regs); |
|
| 322 | + $regs[] = ""; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide |
|
| 323 | + list(, $mod, $type, $id, $params, $fin) = $regs; |
|
| 324 | + if ($fin and |
|
| 325 | + preg_match('/<a\s[^<>]*>\s*$/i', |
|
| 326 | + substr($texte, 0, $a), $r) |
|
| 327 | + ) { |
|
| 328 | + $lien = array( |
|
| 329 | + 'href' => extraire_attribut($r[0], 'href'), |
|
| 330 | + 'class' => extraire_attribut($r[0], 'class'), |
|
| 331 | + 'mime' => extraire_attribut($r[0], 'type'), |
|
| 332 | + 'title' => extraire_attribut($r[0], 'title'), |
|
| 333 | + 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 334 | + ); |
|
| 335 | + $n = strlen($r[0]); |
|
| 336 | + $a -= $n; |
|
| 337 | + $cherche = $n + strlen($regs[0]); |
|
| 338 | + } else { |
|
| 339 | + $lien = false; |
|
| 340 | + $cherche = strlen($mod); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + // calculer le modele |
|
| 344 | + # hack indexation |
|
| 345 | + if ($doublons) { |
|
| 346 | + $texte .= preg_replace(',[|][^|=]*,s', ' ', $params); |
|
| 347 | + } # version normale |
|
| 348 | + else { |
|
| 349 | + // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 350 | + // dans les parametres, plutot que les liens echappes |
|
| 351 | + if (!is_null($liens)) { |
|
| 352 | + $params = str_replace($liens[0], $liens[1], $params); |
|
| 353 | + } |
|
| 354 | + $modele = inclure_modele($type, $id, $params, $lien, $connect, $env); |
|
| 355 | + // en cas d'echec, |
|
| 356 | + // si l'objet demande a une url, |
|
| 357 | + // creer un petit encadre vers elle |
|
| 358 | + if ($modele === false) { |
|
| 359 | + if (!$lien) { |
|
| 360 | + $lien = traiter_lien_implicite("$type$id", '', 'tout', $connect); |
|
| 361 | + } |
|
| 362 | + if ($lien) { |
|
| 363 | + $modele = '<a href="' |
|
| 364 | + . $lien['url'] |
|
| 365 | + . '" class="spip_modele' |
|
| 366 | + . '">' |
|
| 367 | + . sinon($lien['titre'], _T('ecrire:info_sans_titre')) |
|
| 368 | + . "</a>"; |
|
| 369 | + } else { |
|
| 370 | + $modele = ""; |
|
| 371 | + if (test_espace_prive()) { |
|
| 372 | + $modele = entites_html(substr($texte, $a, $cherche)); |
|
| 373 | + if (!is_null($liens)) { |
|
| 374 | + $modele = "<pre>" . str_replace($liens[0], $liens[1], $modele) . "</pre>"; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + // le remplacer dans le texte |
|
| 380 | + if ($modele !== false) { |
|
| 381 | + $modele = protege_js_modeles($modele); |
|
| 382 | + if ($wrap_embed_html) { |
|
| 383 | + $modele = $wrap_embed_html($mod, $modele); |
|
| 384 | + } |
|
| 385 | + $rempl = code_echappement($modele, $echap); |
|
| 386 | + $texte = substr($texte, 0, $a) |
|
| 387 | + . $rempl |
|
| 388 | + . substr($texte, $a + $cherche); |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + // hack pour tout l'espace prive |
|
| 393 | + if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) { |
|
| 394 | + foreach ($doublons ? $doublons : array('documents' => array('doc', 'emb', 'img')) as $quoi => $modeles) { |
|
| 395 | + if (in_array($type, $modeles)) { |
|
| 396 | + $GLOBALS["doublons_{$quoi}_inclus"][] = $id; |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + return $texte; |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | // |
@@ -408,15 +408,15 @@ discard block |
||
| 408 | 408 | // |
| 409 | 409 | // https://code.spip.net/@traiter_raccourci_ancre |
| 410 | 410 | function traiter_raccourci_ancre($letexte) { |
| 411 | - return $letexte; |
|
| 411 | + return $letexte; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | // https://code.spip.net/@traiter_raccourci_glossaire |
| 415 | 415 | function traiter_raccourci_glossaire($texte) { |
| 416 | - return $texte; |
|
| 416 | + return $texte; |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | // https://code.spip.net/@glossaire_std |
| 420 | 420 | function glossaire_std($terme) { |
| 421 | - return $terme; |
|
| 421 | + return $terme; |
|
| 422 | 422 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Affichage |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @return string Code HTML |
| 46 | 46 | */ |
| 47 | 47 | function debut_gauche() { |
| 48 | - return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 48 | + return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -61,13 +61,13 @@ discard block |
||
| 61 | 61 | * @return string Code HTML |
| 62 | 62 | */ |
| 63 | 63 | function creer_colonne_droite() { |
| 64 | - static $deja_colonne_droite; |
|
| 65 | - if ($deja_colonne_droite) { |
|
| 66 | - return ''; |
|
| 67 | - } |
|
| 68 | - $deja_colonne_droite = true; |
|
| 64 | + static $deja_colonne_droite; |
|
| 65 | + if ($deja_colonne_droite) { |
|
| 66 | + return ''; |
|
| 67 | + } |
|
| 68 | + $deja_colonne_droite = true; |
|
| 69 | 69 | |
| 70 | - return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 70 | + return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | * @return string Code HTML |
| 77 | 77 | */ |
| 78 | 78 | function debut_droite() { |
| 79 | - return liste_objets_bloques(_request('exec')) |
|
| 80 | - . creer_colonne_droite() |
|
| 81 | - . "</div>" |
|
| 82 | - . "\n<div id='contenu'>"; |
|
| 79 | + return liste_objets_bloques(_request('exec')) |
|
| 80 | + . creer_colonne_droite() |
|
| 81 | + . "</div>" |
|
| 82 | + . "\n<div id='contenu'>"; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -101,30 +101,30 @@ discard block |
||
| 101 | 101 | * Code HTML |
| 102 | 102 | **/ |
| 103 | 103 | function liste_objets_bloques($exec, $contexte = array(), $auteur = null) { |
| 104 | - $res = ''; |
|
| 105 | - if ($GLOBALS['meta']["articles_modif"] != "non") { |
|
| 106 | - include_spip('inc/drapeau_edition'); |
|
| 107 | - if (is_null($auteur)) { |
|
| 108 | - $auteur = $GLOBALS['visiteur_session']; |
|
| 109 | - } |
|
| 110 | - if ($en_cours = trouver_objet_exec($exec) |
|
| 111 | - and $en_cours['edition'] |
|
| 112 | - and $type = $en_cours['type'] |
|
| 113 | - and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']]) |
|
| 114 | - or $id = _request($en_cours['id_table_objet'])) |
|
| 115 | - ) { |
|
| 116 | - // marquer le fait que l'objet est ouvert en edition par toto |
|
| 117 | - // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 118 | - signale_edition($id, $auteur, $type); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 122 | - if (count($objets_ouverts)) { |
|
| 123 | - $res .= recuperer_fond('prive/objets/liste/objets-en-edition', array(), array('ajax' => true)); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return $res; |
|
| 104 | + $res = ''; |
|
| 105 | + if ($GLOBALS['meta']["articles_modif"] != "non") { |
|
| 106 | + include_spip('inc/drapeau_edition'); |
|
| 107 | + if (is_null($auteur)) { |
|
| 108 | + $auteur = $GLOBALS['visiteur_session']; |
|
| 109 | + } |
|
| 110 | + if ($en_cours = trouver_objet_exec($exec) |
|
| 111 | + and $en_cours['edition'] |
|
| 112 | + and $type = $en_cours['type'] |
|
| 113 | + and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']]) |
|
| 114 | + or $id = _request($en_cours['id_table_objet'])) |
|
| 115 | + ) { |
|
| 116 | + // marquer le fait que l'objet est ouvert en edition par toto |
|
| 117 | + // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 118 | + signale_edition($id, $auteur, $type); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 122 | + if (count($objets_ouverts)) { |
|
| 123 | + $res .= recuperer_fond('prive/objets/liste/objets-en-edition', array(), array('ajax' => true)); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return $res; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
@@ -138,20 +138,20 @@ discard block |
||
| 138 | 138 | * @return string Code HTML |
| 139 | 139 | **/ |
| 140 | 140 | function fin_page() { |
| 141 | - include_spip('inc/pipelines'); |
|
| 142 | - // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 143 | - $debug = ((_request('exec') !== 'valider_xml') |
|
| 144 | - and ((_request('var_mode') == 'debug') |
|
| 145 | - or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps']) |
|
| 146 | - and isset($_COOKIE['spip_admin']))); |
|
| 147 | - $t = '</div><div id="pied"><div class="largeur">' |
|
| 148 | - . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 149 | - . "</div>" |
|
| 150 | - . "</div></div>" // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 151 | - . ($debug ? erreur_squelette() : '') |
|
| 152 | - . "</body></html>\n"; |
|
| 153 | - |
|
| 154 | - return f_queue($t); |
|
| 141 | + include_spip('inc/pipelines'); |
|
| 142 | + // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 143 | + $debug = ((_request('exec') !== 'valider_xml') |
|
| 144 | + and ((_request('var_mode') == 'debug') |
|
| 145 | + or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps']) |
|
| 146 | + and isset($_COOKIE['spip_admin']))); |
|
| 147 | + $t = '</div><div id="pied"><div class="largeur">' |
|
| 148 | + . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 149 | + . "</div>" |
|
| 150 | + . "</div></div>" // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 151 | + . ($debug ? erreur_squelette() : '') |
|
| 152 | + . "</body></html>\n"; |
|
| 153 | + |
|
| 154 | + return f_queue($t); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -166,20 +166,20 @@ discard block |
||
| 166 | 166 | * @return string Code HTML |
| 167 | 167 | **/ |
| 168 | 168 | function html_tests_js() { |
| 169 | - if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) { |
|
| 170 | - // pour le pied de page (deja defini si on est validation XML) |
|
| 171 | - define('_TESTER_NOSCRIPT', |
|
| 172 | - "<noscript>\n<div style='display:none;'><img src='" |
|
| 173 | - . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 174 | - . "' width='1' height='1' alt='' /></div></noscript>\n"); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $rejouer = ''; |
|
| 178 | - if (defined('_SESSION_REJOUER')) { |
|
| 179 | - $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 169 | + if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) { |
|
| 170 | + // pour le pied de page (deja defini si on est validation XML) |
|
| 171 | + define('_TESTER_NOSCRIPT', |
|
| 172 | + "<noscript>\n<div style='display:none;'><img src='" |
|
| 173 | + . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 174 | + . "' width='1' height='1' alt='' /></div></noscript>\n"); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $rejouer = ''; |
|
| 178 | + if (defined('_SESSION_REJOUER')) { |
|
| 179 | + $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -189,25 +189,25 @@ discard block |
||
| 189 | 189 | **/ |
| 190 | 190 | function info_maj_spip() { |
| 191 | 191 | |
| 192 | - $maj = isset($GLOBALS['meta']['info_maj_spip']) ? $GLOBALS['meta']['info_maj_spip'] : null; |
|
| 193 | - if (!$maj) { |
|
| 194 | - return ""; |
|
| 195 | - } |
|
| 192 | + $maj = isset($GLOBALS['meta']['info_maj_spip']) ? $GLOBALS['meta']['info_maj_spip'] : null; |
|
| 193 | + if (!$maj) { |
|
| 194 | + return ""; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - $maj = explode('|', $maj); |
|
| 198 | - // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 199 | - if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 200 | - return ""; |
|
| 201 | - } |
|
| 197 | + $maj = explode('|', $maj); |
|
| 198 | + // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 199 | + if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 200 | + return ""; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - if (!autoriser('webmestre')) { |
|
| 204 | - return ""; |
|
| 205 | - } |
|
| 203 | + if (!autoriser('webmestre')) { |
|
| 204 | + return ""; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - array_shift($maj); |
|
| 208 | - $maj = implode('|', $maj); |
|
| 207 | + array_shift($maj); |
|
| 208 | + $maj = implode('|', $maj); |
|
| 209 | 209 | |
| 210 | - return "$maj<br />"; |
|
| 210 | + return "$maj<br />"; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -218,43 +218,43 @@ discard block |
||
| 218 | 218 | **/ |
| 219 | 219 | function info_copyright() { |
| 220 | 220 | |
| 221 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 222 | - |
|
| 223 | - // |
|
| 224 | - // Mention, le cas echeant, de la revision SVN courante |
|
| 225 | - // |
|
| 226 | - if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 227 | - if ($vcs['vcs'] === 'GIT') { |
|
| 228 | - $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 229 | - } elseif ($vcs['vcs'] === 'SVN') { |
|
| 230 | - $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 231 | - } else { |
|
| 232 | - $url = ''; |
|
| 233 | - } |
|
| 234 | - // affichage "GIT [master: abcdef]" |
|
| 235 | - $commit = isset($vcs['commit_short']) ? $vcs['commit_short'] : $vcs['commit']; |
|
| 236 | - if ($url) { |
|
| 237 | - $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 238 | - } |
|
| 239 | - if ($vcs['branch']) { |
|
| 240 | - $commit = $vcs['branch'] . ': ' . $commit; |
|
| 241 | - } |
|
| 242 | - $version .= " {$vcs['vcs']} [$commit]"; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - // et la version de l'ecran de securite |
|
| 246 | - $secu = defined('_ECRAN_SECURITE') |
|
| 247 | - ? "<br />" . _T('ecran_securite', array('version' => _ECRAN_SECURITE)) |
|
| 248 | - : ''; |
|
| 249 | - |
|
| 250 | - return _T('info_copyright', |
|
| 251 | - array( |
|
| 252 | - 'spip' => "<b>SPIP $version</b> ", |
|
| 253 | - 'lien_gpl' => |
|
| 254 | - "<a href='" . generer_url_ecrire("aide", |
|
| 255 | - "aide=licence&var_lang=" . $GLOBALS['spip_lang']) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . "</a>" |
|
| 256 | - )) |
|
| 257 | - . $secu; |
|
| 221 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 222 | + |
|
| 223 | + // |
|
| 224 | + // Mention, le cas echeant, de la revision SVN courante |
|
| 225 | + // |
|
| 226 | + if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 227 | + if ($vcs['vcs'] === 'GIT') { |
|
| 228 | + $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 229 | + } elseif ($vcs['vcs'] === 'SVN') { |
|
| 230 | + $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 231 | + } else { |
|
| 232 | + $url = ''; |
|
| 233 | + } |
|
| 234 | + // affichage "GIT [master: abcdef]" |
|
| 235 | + $commit = isset($vcs['commit_short']) ? $vcs['commit_short'] : $vcs['commit']; |
|
| 236 | + if ($url) { |
|
| 237 | + $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 238 | + } |
|
| 239 | + if ($vcs['branch']) { |
|
| 240 | + $commit = $vcs['branch'] . ': ' . $commit; |
|
| 241 | + } |
|
| 242 | + $version .= " {$vcs['vcs']} [$commit]"; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + // et la version de l'ecran de securite |
|
| 246 | + $secu = defined('_ECRAN_SECURITE') |
|
| 247 | + ? "<br />" . _T('ecran_securite', array('version' => _ECRAN_SECURITE)) |
|
| 248 | + : ''; |
|
| 249 | + |
|
| 250 | + return _T('info_copyright', |
|
| 251 | + array( |
|
| 252 | + 'spip' => "<b>SPIP $version</b> ", |
|
| 253 | + 'lien_gpl' => |
|
| 254 | + "<a href='" . generer_url_ecrire("aide", |
|
| 255 | + "aide=licence&var_lang=" . $GLOBALS['spip_lang']) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . "</a>" |
|
| 256 | + )) |
|
| 257 | + . $secu; |
|
| 258 | 258 | |
| 259 | 259 | } |
| 260 | 260 | |
@@ -270,17 +270,17 @@ discard block |
||
| 270 | 270 | * @return string Code HTML |
| 271 | 271 | **/ |
| 272 | 272 | function formulaire_recherche($page, $complement = "") { |
| 273 | - $recherche = _request('recherche'); |
|
| 274 | - $recherche_aff = entites_html($recherche); |
|
| 275 | - if (!strlen($recherche)) { |
|
| 276 | - $recherche_aff = _T('info_rechercher'); |
|
| 277 | - $onfocus = " onfocus=\"this.value='';\""; |
|
| 278 | - } else { |
|
| 279 | - $onfocus = ''; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 283 | - $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 284 | - |
|
| 285 | - return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . "</div>"; |
|
| 273 | + $recherche = _request('recherche'); |
|
| 274 | + $recherche_aff = entites_html($recherche); |
|
| 275 | + if (!strlen($recherche)) { |
|
| 276 | + $recherche_aff = _T('info_rechercher'); |
|
| 277 | + $onfocus = " onfocus=\"this.value='';\""; |
|
| 278 | + } else { |
|
| 279 | + $onfocus = ''; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 283 | + $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 284 | + |
|
| 285 | + return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . "</div>"; |
|
| 286 | 286 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Les fonctions de toggg pour faire du JSON |
@@ -26,64 +26,64 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | // https://code.spip.net/@var2js |
| 28 | 28 | function var2js($var) { |
| 29 | - $asso = false; |
|
| 30 | - switch (true) { |
|
| 31 | - case is_null($var): |
|
| 32 | - return 'null'; |
|
| 33 | - case is_string($var): |
|
| 34 | - return '"' . addcslashes($var, "\"\\\n\r/") . '"'; |
|
| 35 | - case is_bool($var): |
|
| 36 | - return $var ? 'true' : 'false'; |
|
| 37 | - case is_scalar($var): |
|
| 38 | - return (string)$var; |
|
| 39 | - case is_object($var):// blam |
|
| 40 | - $var = get_object_vars($var); |
|
| 41 | - $asso = true; |
|
| 42 | - // $var devient un array, on continue |
|
| 43 | - case is_array($var): |
|
| 44 | - $keys = array_keys($var); |
|
| 45 | - $ikey = count($keys); |
|
| 46 | - while (!$asso && $ikey--) { |
|
| 47 | - $asso = $ikey !== $keys[$ikey]; |
|
| 48 | - } |
|
| 49 | - $sep = ''; |
|
| 50 | - if ($asso) { |
|
| 51 | - $ret = '{'; |
|
| 52 | - foreach ($var as $key => $elt) { |
|
| 53 | - $ret .= $sep . '"' . $key . '":' . var2js($elt); |
|
| 54 | - $sep = ','; |
|
| 55 | - } |
|
| 29 | + $asso = false; |
|
| 30 | + switch (true) { |
|
| 31 | + case is_null($var): |
|
| 32 | + return 'null'; |
|
| 33 | + case is_string($var): |
|
| 34 | + return '"' . addcslashes($var, "\"\\\n\r/") . '"'; |
|
| 35 | + case is_bool($var): |
|
| 36 | + return $var ? 'true' : 'false'; |
|
| 37 | + case is_scalar($var): |
|
| 38 | + return (string)$var; |
|
| 39 | + case is_object($var):// blam |
|
| 40 | + $var = get_object_vars($var); |
|
| 41 | + $asso = true; |
|
| 42 | + // $var devient un array, on continue |
|
| 43 | + case is_array($var): |
|
| 44 | + $keys = array_keys($var); |
|
| 45 | + $ikey = count($keys); |
|
| 46 | + while (!$asso && $ikey--) { |
|
| 47 | + $asso = $ikey !== $keys[$ikey]; |
|
| 48 | + } |
|
| 49 | + $sep = ''; |
|
| 50 | + if ($asso) { |
|
| 51 | + $ret = '{'; |
|
| 52 | + foreach ($var as $key => $elt) { |
|
| 53 | + $ret .= $sep . '"' . $key . '":' . var2js($elt); |
|
| 54 | + $sep = ','; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - return $ret . '}'; |
|
| 58 | - } else { |
|
| 59 | - $ret = '['; |
|
| 60 | - foreach ($var as $elt) { |
|
| 61 | - $ret .= $sep . var2js($elt); |
|
| 62 | - $sep = ','; |
|
| 63 | - } |
|
| 57 | + return $ret . '}'; |
|
| 58 | + } else { |
|
| 59 | + $ret = '['; |
|
| 60 | + foreach ($var as $elt) { |
|
| 61 | + $ret .= $sep . var2js($elt); |
|
| 62 | + $sep = ','; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return $ret . ']'; |
|
| 66 | - } |
|
| 67 | - } |
|
| 65 | + return $ret . ']'; |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - return false; |
|
| 69 | + return false; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | if (!function_exists('json_encode')) { |
| 73 | - function json_encode($v) { |
|
| 74 | - return var2js($v); |
|
| 75 | - } |
|
| 73 | + function json_encode($v) { |
|
| 74 | + return var2js($v); |
|
| 75 | + } |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // https://code.spip.net/@json_export |
| 79 | 79 | function json_export($var) { |
| 80 | - $var = json_encode($var); |
|
| 80 | + $var = json_encode($var); |
|
| 81 | 81 | |
| 82 | - // flag indiquant qu'on est en iframe et qu'il faut proteger nos |
|
| 83 | - // donnees dans un <textarea> ; attention $_FILES a ete vide par array_pop |
|
| 84 | - if (defined('FILE_UPLOAD')) { |
|
| 85 | - return '<textarea>' . spip_htmlspecialchars($var) . '</textarea>'; |
|
| 86 | - } else { |
|
| 87 | - return $var; |
|
| 88 | - } |
|
| 82 | + // flag indiquant qu'on est en iframe et qu'il faut proteger nos |
|
| 83 | + // donnees dans un <textarea> ; attention $_FILES a ete vide par array_pop |
|
| 84 | + if (defined('FILE_UPLOAD')) { |
|
| 85 | + return '<textarea>' . spip_htmlspecialchars($var) . '</textarea>'; |
|
| 86 | + } else { |
|
| 87 | + return $var; |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -26,41 +26,41 @@ discard block |
||
| 26 | 26 | * @return string Code HTML du cadre dépliable |
| 27 | 27 | **/ |
| 28 | 28 | function cadre_depliable($icone, $titre, $deplie, $contenu, $ids = '', $style_cadre = 'r') { |
| 29 | - $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 30 | - |
|
| 31 | - return |
|
| 32 | - debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 33 | - . debut_block_depliable($deplie, $ids) |
|
| 34 | - . "<div class='cadre_padding'>\n" |
|
| 35 | - . $contenu |
|
| 36 | - . "</div>\n" |
|
| 37 | - . fin_block() |
|
| 38 | - . fin_cadre(); |
|
| 29 | + $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 30 | + |
|
| 31 | + return |
|
| 32 | + debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 33 | + . debut_block_depliable($deplie, $ids) |
|
| 34 | + . "<div class='cadre_padding'>\n" |
|
| 35 | + . $contenu |
|
| 36 | + . "</div>\n" |
|
| 37 | + . fin_block() |
|
| 38 | + . fin_cadre(); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // https://code.spip.net/@block_parfois_visible |
| 42 | 42 | function block_parfois_visible($nom, $invite, $masque, $style = '', $visible = false) { |
| 43 | - return "\n" |
|
| 44 | - . bouton_block_depliable($invite, $visible, $nom) |
|
| 45 | - . debut_block_depliable($visible, $nom) |
|
| 46 | - . $masque |
|
| 47 | - . fin_block(); |
|
| 43 | + return "\n" |
|
| 44 | + . bouton_block_depliable($invite, $visible, $nom) |
|
| 45 | + . debut_block_depliable($visible, $nom) |
|
| 46 | + . $masque |
|
| 47 | + . fin_block(); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // https://code.spip.net/@debut_block_depliable |
| 51 | 51 | function debut_block_depliable($deplie, $id = "") { |
| 52 | - $class = ' blocdeplie'; |
|
| 53 | - // si on n'accepte pas js, ne pas fermer |
|
| 54 | - if (!$deplie) { |
|
| 55 | - $class = " blocreplie"; |
|
| 56 | - } |
|
| 52 | + $class = ' blocdeplie'; |
|
| 53 | + // si on n'accepte pas js, ne pas fermer |
|
| 54 | + if (!$deplie) { |
|
| 55 | + $class = " blocreplie"; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - return "<div " . ($id ? "id='$id' " : "") . "class='bloc_depliable$class'>"; |
|
| 58 | + return "<div " . ($id ? "id='$id' " : "") . "class='bloc_depliable$class'>"; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // https://code.spip.net/@fin_block |
| 62 | 62 | function fin_block() { |
| 63 | - return "<div class='nettoyeur'></div>\n</div>"; |
|
| 63 | + return "<div class='nettoyeur'></div>\n</div>"; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // $texte : texte du bouton |
@@ -68,32 +68,32 @@ discard block |
||
| 68 | 68 | // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit) |
| 69 | 69 | // https://code.spip.net/@bouton_block_depliable |
| 70 | 70 | function bouton_block_depliable($texte, $deplie, $ids = "") { |
| 71 | - $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 72 | - |
|
| 73 | - $class = ($deplie === true) ? " deplie" : (($deplie == -1) ? " impliable" : " replie"); |
|
| 74 | - if (strlen($ids)) { |
|
| 75 | - $cible = explode(',', $ids); |
|
| 76 | - $cible = '#' . implode(",#", $cible); |
|
| 77 | - } else { |
|
| 78 | - $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $b = (strpos($texte, "<h") === false ? 'h3' : 'div'); |
|
| 82 | - |
|
| 83 | - return "<$b " |
|
| 84 | - . ($bouton_id ? "id='$bouton_id' " : "") |
|
| 85 | - . "class='titrem$class'" |
|
| 86 | - . (($deplie === -1) |
|
| 87 | - ? "" |
|
| 88 | - : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 89 | - ) |
|
| 90 | - . ">" |
|
| 91 | - // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 92 | - . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 93 | - . "$texte</$b>" |
|
| 94 | - . http_script(($deplie === 'incertain') |
|
| 95 | - ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 96 | - : ''); |
|
| 71 | + $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 72 | + |
|
| 73 | + $class = ($deplie === true) ? " deplie" : (($deplie == -1) ? " impliable" : " replie"); |
|
| 74 | + if (strlen($ids)) { |
|
| 75 | + $cible = explode(',', $ids); |
|
| 76 | + $cible = '#' . implode(",#", $cible); |
|
| 77 | + } else { |
|
| 78 | + $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $b = (strpos($texte, "<h") === false ? 'h3' : 'div'); |
|
| 82 | + |
|
| 83 | + return "<$b " |
|
| 84 | + . ($bouton_id ? "id='$bouton_id' " : "") |
|
| 85 | + . "class='titrem$class'" |
|
| 86 | + . (($deplie === -1) |
|
| 87 | + ? "" |
|
| 88 | + : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 89 | + ) |
|
| 90 | + . ">" |
|
| 91 | + // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 92 | + . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 93 | + . "$texte</$b>" |
|
| 94 | + . http_script(($deplie === 'incertain') |
|
| 95 | + ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 96 | + : ''); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // |
@@ -102,62 +102,62 @@ discard block |
||
| 102 | 102 | // https://code.spip.net/@verif_butineur |
| 103 | 103 | function verif_butineur() { |
| 104 | 104 | |
| 105 | - preg_match(",^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,", $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 106 | - $GLOBALS['browser_name'] = $match[1]; |
|
| 107 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 108 | - $GLOBALS['browser_description'] = $match[3]; |
|
| 109 | - $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 110 | - $GLOBALS['browser_barre'] = ''; |
|
| 111 | - |
|
| 112 | - if (!preg_match(",opera,i", $GLOBALS['browser_description']) && preg_match(",opera,i", $GLOBALS['browser_name'])) { |
|
| 113 | - $GLOBALS['browser_name'] = "Opera"; |
|
| 114 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 115 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 116 | - } else { |
|
| 117 | - if (preg_match(",opera,i", $GLOBALS['browser_description'])) { |
|
| 118 | - preg_match(",Opera ([^\ ]*),i", $GLOBALS['browser_description'], $match); |
|
| 119 | - $GLOBALS['browser_name'] = "Opera"; |
|
| 120 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 121 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 122 | - } else { |
|
| 123 | - if (preg_match(",msie,i", $GLOBALS['browser_description'])) { |
|
| 124 | - preg_match(",MSIE ([^;]*),i", $GLOBALS['browser_description'], $match); |
|
| 125 | - $GLOBALS['browser_name'] = "MSIE"; |
|
| 126 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 127 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 128 | - } else { |
|
| 129 | - if (preg_match(",KHTML,i", $GLOBALS['browser_description']) && |
|
| 130 | - preg_match(",Safari/([^;]*),", $GLOBALS['browser_description'], $match) |
|
| 131 | - ) { |
|
| 132 | - $GLOBALS['browser_name'] = "Safari"; |
|
| 133 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 134 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 135 | - } else { |
|
| 136 | - if (preg_match(",mozilla,i", $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) { |
|
| 137 | - // Numero de version pour Mozilla "authentique" |
|
| 138 | - if (preg_match(",rv:([0-9]+\.[0-9]+),", $GLOBALS['browser_description'], $match)) { |
|
| 139 | - $GLOBALS['browser_rev'] = doubleval($match[1]); |
|
| 140 | - } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 141 | - else { |
|
| 142 | - if (strpos($GLOBALS['browser_description'], "Gecko") and !strpos($GLOBALS['browser_description'], |
|
| 143 | - "KHTML") |
|
| 144 | - ) { |
|
| 145 | - $GLOBALS['browser_rev'] = 1.4; |
|
| 146 | - } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 147 | - else { |
|
| 148 | - $GLOBALS['browser_rev'] = 1.0; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if (!$GLOBALS['browser_name']) { |
|
| 159 | - $GLOBALS['browser_name'] = "Mozilla"; |
|
| 160 | - } |
|
| 105 | + preg_match(",^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,", $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 106 | + $GLOBALS['browser_name'] = $match[1]; |
|
| 107 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 108 | + $GLOBALS['browser_description'] = $match[3]; |
|
| 109 | + $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 110 | + $GLOBALS['browser_barre'] = ''; |
|
| 111 | + |
|
| 112 | + if (!preg_match(",opera,i", $GLOBALS['browser_description']) && preg_match(",opera,i", $GLOBALS['browser_name'])) { |
|
| 113 | + $GLOBALS['browser_name'] = "Opera"; |
|
| 114 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 115 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 116 | + } else { |
|
| 117 | + if (preg_match(",opera,i", $GLOBALS['browser_description'])) { |
|
| 118 | + preg_match(",Opera ([^\ ]*),i", $GLOBALS['browser_description'], $match); |
|
| 119 | + $GLOBALS['browser_name'] = "Opera"; |
|
| 120 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 121 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 122 | + } else { |
|
| 123 | + if (preg_match(",msie,i", $GLOBALS['browser_description'])) { |
|
| 124 | + preg_match(",MSIE ([^;]*),i", $GLOBALS['browser_description'], $match); |
|
| 125 | + $GLOBALS['browser_name'] = "MSIE"; |
|
| 126 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 127 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 128 | + } else { |
|
| 129 | + if (preg_match(",KHTML,i", $GLOBALS['browser_description']) && |
|
| 130 | + preg_match(",Safari/([^;]*),", $GLOBALS['browser_description'], $match) |
|
| 131 | + ) { |
|
| 132 | + $GLOBALS['browser_name'] = "Safari"; |
|
| 133 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 134 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 135 | + } else { |
|
| 136 | + if (preg_match(",mozilla,i", $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) { |
|
| 137 | + // Numero de version pour Mozilla "authentique" |
|
| 138 | + if (preg_match(",rv:([0-9]+\.[0-9]+),", $GLOBALS['browser_description'], $match)) { |
|
| 139 | + $GLOBALS['browser_rev'] = doubleval($match[1]); |
|
| 140 | + } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 141 | + else { |
|
| 142 | + if (strpos($GLOBALS['browser_description'], "Gecko") and !strpos($GLOBALS['browser_description'], |
|
| 143 | + "KHTML") |
|
| 144 | + ) { |
|
| 145 | + $GLOBALS['browser_rev'] = 1.4; |
|
| 146 | + } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 147 | + else { |
|
| 148 | + $GLOBALS['browser_rev'] = 1.0; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if (!$GLOBALS['browser_name']) { |
|
| 159 | + $GLOBALS['browser_name'] = "Mozilla"; |
|
| 160 | + } |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | verif_butineur(); |