@@ -63,9 +63,9 @@ |
||
| 63 | 63 | $f = new IndenteurXML(); |
| 64 | 64 | $sax($page, $apply, $f); |
| 65 | 65 | if (!$f->err) { |
| 66 | - return $f->entete . $f->res; |
|
| 66 | + return $f->entete.$f->res; |
|
| 67 | 67 | } |
| 68 | - spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 68 | + spip_log('indentation impossible '.(is_countable($f->err) ? count($f->err) : 0).' erreurs de validation'); |
|
| 69 | 69 | |
| 70 | - return $f->entete . $f->page; |
|
| 70 | + return $f->entete.$f->page; |
|
| 71 | 71 | } |
@@ -11,55 +11,55 @@ |
||
| 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 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 20 | - xml_debutElement($this, $name, $attrs); |
|
| 21 | - } |
|
| 19 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 20 | + xml_debutElement($this, $name, $attrs); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function finElement($phraseur, $name) { |
|
| 24 | - xml_finElement($this, $name); |
|
| 25 | - } |
|
| 23 | + public function finElement($phraseur, $name) { |
|
| 24 | + xml_finElement($this, $name); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function textElement($phraseur, $data) { |
|
| 28 | - xml_textElement($this, $data); |
|
| 29 | - } |
|
| 27 | + public function textElement($phraseur, $data) { |
|
| 28 | + xml_textElement($this, $data); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function piElement($phraseur, $target, $data) { |
|
| 32 | - xml_PiElement($this, $target, $data); |
|
| 33 | - } |
|
| 31 | + public function piElement($phraseur, $target, $data) { |
|
| 32 | + xml_PiElement($this, $target, $data); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function defaultElement($phraseur, $data) { |
|
| 36 | - xml_defaultElement($this, $data); |
|
| 37 | - } |
|
| 35 | + public function defaultElement($phraseur, $data) { |
|
| 36 | + xml_defaultElement($this, $data); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function phraserTout($phraseur, $data) { |
|
| 40 | - xml_parsestring($this, $data); |
|
| 41 | - } |
|
| 39 | + public function phraserTout($phraseur, $data) { |
|
| 40 | + xml_parsestring($this, $data); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public $depth = ''; |
|
| 44 | - public $res = ''; |
|
| 45 | - public $err = []; |
|
| 46 | - public $contenu = []; |
|
| 47 | - public $ouvrant = []; |
|
| 48 | - public $reperes = []; |
|
| 49 | - public $entete = ''; |
|
| 50 | - public $page = ''; |
|
| 51 | - public $dtc = null; |
|
| 52 | - public $sax = null; |
|
| 43 | + public $depth = ''; |
|
| 44 | + public $res = ''; |
|
| 45 | + public $err = []; |
|
| 46 | + public $contenu = []; |
|
| 47 | + public $ouvrant = []; |
|
| 48 | + public $reperes = []; |
|
| 49 | + public $entete = ''; |
|
| 50 | + public $page = ''; |
|
| 51 | + public $dtc = null; |
|
| 52 | + public $sax = null; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | function xml_indenter_dist($page, $apply = false) { |
| 56 | - $sax = charger_fonction('sax', 'xml'); |
|
| 57 | - $f = new IndenteurXML(); |
|
| 58 | - $sax($page, $apply, $f); |
|
| 59 | - if (!$f->err) { |
|
| 60 | - return $f->entete . $f->res; |
|
| 61 | - } |
|
| 62 | - spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 56 | + $sax = charger_fonction('sax', 'xml'); |
|
| 57 | + $f = new IndenteurXML(); |
|
| 58 | + $sax($page, $apply, $f); |
|
| 59 | + if (!$f->err) { |
|
| 60 | + return $f->entete . $f->res; |
|
| 61 | + } |
|
| 62 | + spip_log('indentation impossible ' . (is_countable($f->err) ? count($f->err) : 0) . ' erreurs de validation'); |
|
| 63 | 63 | |
| 64 | - return $f->entete . $f->page; |
|
| 64 | + return $f->entete . $f->page; |
|
| 65 | 65 | } |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | $t = $phraseur->ouvrant[$depth] ?? ' '; |
| 47 | 47 | // espace initial signifie: deja integree au resultat |
| 48 | 48 | if ($t[0] != ' ') { |
| 49 | - $phraseur->res .= '<' . $t . '>'; |
|
| 50 | - $phraseur->ouvrant[$depth] = ' ' . $t; |
|
| 49 | + $phraseur->res .= '<'.$t.'>'; |
|
| 50 | + $phraseur->ouvrant[$depth] = ' '.$t; |
|
| 51 | 51 | } |
| 52 | 52 | $t = $phraseur->contenu[$depth]; |
| 53 | 53 | // n'indenter que s'il y a un separateur avant |
@@ -58,14 +58,14 @@ discard block |
||
| 58 | 58 | foreach ($attrs as $k => $v) { |
| 59 | 59 | $delim = strpos($v, "'") === false ? "'" : '"'; |
| 60 | 60 | $val = xml_entites_html($v); |
| 61 | - $att .= $sep . $k . '=' . $delim |
|
| 61 | + $att .= $sep.$k.'='.$delim |
|
| 62 | 62 | . ($delim !== '"' ? str_replace('"', '"', $val) : $val) |
| 63 | 63 | . $delim; |
| 64 | 64 | $sep = "\n $depth"; |
| 65 | 65 | } |
| 66 | 66 | $phraseur->depth .= ' '; |
| 67 | 67 | $phraseur->contenu[$phraseur->depth] = ''; |
| 68 | - $phraseur->ouvrant[$phraseur->depth] = $name . $att; |
|
| 68 | + $phraseur->ouvrant[$phraseur->depth] = $name.$att; |
|
| 69 | 69 | $phraseur->reperes[$phraseur->depth] = xml_get_current_line_number($phraseur->sax); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | $ouv = $phraseur->ouvrant[$phraseur->depth]; |
| 75 | 75 | |
| 76 | 76 | if ($ouv[0] != ' ') { |
| 77 | - $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 77 | + $phraseur->ouvrant[$phraseur->depth] = ' '.$ouv; |
|
| 78 | 78 | } else { |
| 79 | 79 | $ouv = ''; |
| 80 | 80 | } |
| 81 | 81 | $t = $phraseur->contenu[$phraseur->depth]; |
| 82 | 82 | $phraseur->depth = substr($phraseur->depth, 2); |
| 83 | - $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 83 | + $t = preg_replace("/[\n\t ]+$/", "\n".$phraseur->depth, $t); |
|
| 84 | 84 | |
| 85 | 85 | // fusion <balise></balise> en <balise />. |
| 86 | 86 | // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | // (param fusion_bal) |
| 90 | 90 | |
| 91 | 91 | if ($t || (($ouv != $name) and !$fusion_bal)) { |
| 92 | - $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>'; |
|
| 92 | + $phraseur->res .= ($ouv ? ('<'.$ouv.'>') : '').$t.'</'.$name.'>'; |
|
| 93 | 93 | } else { |
| 94 | - $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>')); |
|
| 94 | + $phraseur->res .= ($ouv ? ('<'.$ouv.' />') : ('</'.$name.'>')); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
@@ -136,16 +136,15 @@ discard block |
||
| 136 | 136 | coordonnees_erreur( |
| 137 | 137 | $phraseur, |
| 138 | 138 | xml_error_string(xml_get_error_code($phraseur->sax)) |
| 139 | - . "<br />\n" . |
|
| 140 | - (!$phraseur->depth ? '' : |
|
| 141 | - ('(' . |
|
| 142 | - _T('erreur_balise_non_fermee') . |
|
| 143 | - ' <tt>' . |
|
| 144 | - $phraseur->ouvrant[$phraseur->depth] . |
|
| 145 | - '</tt> ' . |
|
| 146 | - _T('ligne') . |
|
| 147 | - ' ' . |
|
| 148 | - $phraseur->reperes[$phraseur->depth] . |
|
| 139 | + . "<br />\n". |
|
| 140 | + (!$phraseur->depth ? '' : ('('. |
|
| 141 | + _T('erreur_balise_non_fermee'). |
|
| 142 | + ' <tt>'. |
|
| 143 | + $phraseur->ouvrant[$phraseur->depth]. |
|
| 144 | + '</tt> '. |
|
| 145 | + _T('ligne'). |
|
| 146 | + ' '. |
|
| 147 | + $phraseur->reperes[$phraseur->depth]. |
|
| 149 | 148 | ") <br />\n")) |
| 150 | 149 | ); |
| 151 | 150 | } |
@@ -188,7 +187,7 @@ discard block |
||
| 188 | 187 | // et escamoter le doctype que sax mange en php5 mais pas en php4 |
| 189 | 188 | if (!$doctype) { |
| 190 | 189 | if (!$r = analyser_doctype($page)) { |
| 191 | - $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 190 | + $page = _MESSAGE_DOCTYPE._DOCTYPE_ECRIRE |
|
| 192 | 191 | . preg_replace(_REGEXP_DOCTYPE, '', $page); |
| 193 | 192 | $r = analyser_doctype($page); |
| 194 | 193 | } |
@@ -297,18 +296,18 @@ discard block |
||
| 297 | 296 | 'rss-0.91.dtd' |
| 298 | 297 | ]; |
| 299 | 298 | } else { |
| 300 | - $dtd = $topelement . '.dtd'; |
|
| 299 | + $dtd = $topelement.'.dtd'; |
|
| 301 | 300 | $f = find_in_path($dtd); |
| 302 | 301 | if (file_exists($f)) { |
| 303 | 302 | return [$entete, 'SYSTEM', $f, $dtd]; |
| 304 | 303 | } |
| 305 | 304 | } |
| 306 | 305 | } |
| 307 | - spip_log('Dtd pas vu pour ' . substr($data, 0, 100)); |
|
| 306 | + spip_log('Dtd pas vu pour '.substr($data, 0, 100)); |
|
| 308 | 307 | |
| 309 | 308 | return []; |
| 310 | 309 | } |
| 311 | - [$entete, , $topelement, $avail, $suite] = $page; |
|
| 310 | + [$entete,, $topelement, $avail, $suite] = $page; |
|
| 312 | 311 | |
| 313 | 312 | if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
| 314 | 313 | if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
@@ -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,222 +24,222 @@ discard block |
||
| 24 | 24 | * @return string |
| 25 | 25 | */ |
| 26 | 26 | function xml_entites_html($texte) { |
| 27 | - if ( |
|
| 28 | - !is_string($texte) or !$texte |
|
| 29 | - or strpbrk($texte, "&\"'<>") == false |
|
| 30 | - ) { |
|
| 31 | - return $texte; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - if (!function_exists('spip_htmlspecialchars')) { |
|
| 35 | - include_spip('inc/filtres_mini'); |
|
| 36 | - } |
|
| 37 | - $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 38 | - |
|
| 39 | - return $texte; |
|
| 27 | + if ( |
|
| 28 | + !is_string($texte) or !$texte |
|
| 29 | + or strpbrk($texte, "&\"'<>") == false |
|
| 30 | + ) { |
|
| 31 | + return $texte; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + if (!function_exists('spip_htmlspecialchars')) { |
|
| 35 | + include_spip('inc/filtres_mini'); |
|
| 36 | + } |
|
| 37 | + $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 38 | + |
|
| 39 | + return $texte; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | function xml_debutElement($phraseur, $name, $attrs) { |
| 43 | - $depth = $phraseur->depth; |
|
| 44 | - |
|
| 45 | - $t = $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 = $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 | function xml_finElement($phraseur, $name, $fusion_bal = false) { |
| 72 | - $ouv = $phraseur->ouvrant[$phraseur->depth]; |
|
| 73 | - |
|
| 74 | - if ($ouv[0] != ' ') { |
|
| 75 | - $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 76 | - } else { |
|
| 77 | - $ouv = ''; |
|
| 78 | - } |
|
| 79 | - $t = $phraseur->contenu[$phraseur->depth]; |
|
| 80 | - $phraseur->depth = substr($phraseur->depth, 2); |
|
| 81 | - $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 82 | - |
|
| 83 | - // fusion <balise></balise> en <balise />. |
|
| 84 | - // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
|
| 85 | - // en particulier pour les balises Script et A. |
|
| 86 | - // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
|
| 87 | - // (param fusion_bal) |
|
| 88 | - |
|
| 89 | - if ($t || (($ouv != $name) and !$fusion_bal)) { |
|
| 90 | - $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>'; |
|
| 91 | - } else { |
|
| 92 | - $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>')); |
|
| 93 | - } |
|
| 72 | + $ouv = $phraseur->ouvrant[$phraseur->depth]; |
|
| 73 | + |
|
| 74 | + if ($ouv[0] != ' ') { |
|
| 75 | + $phraseur->ouvrant[$phraseur->depth] = ' ' . $ouv; |
|
| 76 | + } else { |
|
| 77 | + $ouv = ''; |
|
| 78 | + } |
|
| 79 | + $t = $phraseur->contenu[$phraseur->depth]; |
|
| 80 | + $phraseur->depth = substr($phraseur->depth, 2); |
|
| 81 | + $t = preg_replace("/[\n\t ]+$/", "\n" . $phraseur->depth, $t); |
|
| 82 | + |
|
| 83 | + // fusion <balise></balise> en <balise />. |
|
| 84 | + // ATTENTION, certains clients http croient que fusion ==> pas d'atttributs |
|
| 85 | + // en particulier pour les balises Script et A. |
|
| 86 | + // en presence d'attributs ne le faire que si la DTD est dispo et d'accord |
|
| 87 | + // (param fusion_bal) |
|
| 88 | + |
|
| 89 | + if ($t || (($ouv != $name) and !$fusion_bal)) { |
|
| 90 | + $phraseur->res .= ($ouv ? ('<' . $ouv . '>') : '') . $t . '</' . $name . '>'; |
|
| 91 | + } else { |
|
| 92 | + $phraseur->res .= ($ouv ? ('<' . $ouv . ' />') : ('</' . $name . '>')); |
|
| 93 | + } |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function xml_textElement($phraseur, $data) { |
| 97 | - $depth = $phraseur->depth; |
|
| 98 | - $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth]) |
|
| 99 | - ? $data |
|
| 100 | - : xml_entites_html($data); |
|
| 97 | + $depth = $phraseur->depth; |
|
| 98 | + $phraseur->contenu[$depth] .= preg_match('/^script/', $phraseur->ouvrant[$depth]) |
|
| 99 | + ? $data |
|
| 100 | + : xml_entites_html($data); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | function xml_piElement($phraseur, $target, $data) { |
| 104 | - $depth = $phraseur->depth; |
|
| 105 | - |
|
| 106 | - if (strtolower($target) != 'php') { |
|
| 107 | - $phraseur->contenu[$depth] .= $data; |
|
| 108 | - } else { |
|
| 109 | - ob_start(); |
|
| 110 | - eval($data); |
|
| 111 | - $data = ob_get_contents(); |
|
| 112 | - ob_end_clean(); |
|
| 113 | - $phraseur->contenu[$depth] .= $data; |
|
| 114 | - } |
|
| 104 | + $depth = $phraseur->depth; |
|
| 105 | + |
|
| 106 | + if (strtolower($target) != 'php') { |
|
| 107 | + $phraseur->contenu[$depth] .= $data; |
|
| 108 | + } else { |
|
| 109 | + ob_start(); |
|
| 110 | + eval($data); |
|
| 111 | + $data = ob_get_contents(); |
|
| 112 | + ob_end_clean(); |
|
| 113 | + $phraseur->contenu[$depth] .= $data; |
|
| 114 | + } |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | function xml_defaultElement($phraseur, $data) { |
| 119 | - $depth = $phraseur->depth; |
|
| 119 | + $depth = $phraseur->depth; |
|
| 120 | 120 | |
| 121 | - if (!isset($phraseur->contenu[$depth])) { |
|
| 122 | - $phraseur->contenu[$depth] = ''; |
|
| 123 | - } |
|
| 124 | - $phraseur->contenu[$depth] .= $data; |
|
| 121 | + if (!isset($phraseur->contenu[$depth])) { |
|
| 122 | + $phraseur->contenu[$depth] = ''; |
|
| 123 | + } |
|
| 124 | + $phraseur->contenu[$depth] .= $data; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | function xml_parsestring($phraseur, $data) { |
| 128 | - $phraseur->contenu[$phraseur->depth] = ''; |
|
| 129 | - |
|
| 130 | - if (!xml_parse($phraseur->sax, $data, true)) { |
|
| 131 | - coordonnees_erreur( |
|
| 132 | - $phraseur, |
|
| 133 | - xml_error_string(xml_get_error_code($phraseur->sax)) |
|
| 134 | - . "<br />\n" . |
|
| 135 | - (!$phraseur->depth ? '' : |
|
| 136 | - ('(' . |
|
| 137 | - _T('erreur_balise_non_fermee') . |
|
| 138 | - ' <tt>' . |
|
| 139 | - $phraseur->ouvrant[$phraseur->depth] . |
|
| 140 | - '</tt> ' . |
|
| 141 | - _T('ligne') . |
|
| 142 | - ' ' . |
|
| 143 | - $phraseur->reperes[$phraseur->depth] . |
|
| 144 | - ") <br />\n")) |
|
| 145 | - ); |
|
| 146 | - } |
|
| 128 | + $phraseur->contenu[$phraseur->depth] = ''; |
|
| 129 | + |
|
| 130 | + if (!xml_parse($phraseur->sax, $data, true)) { |
|
| 131 | + coordonnees_erreur( |
|
| 132 | + $phraseur, |
|
| 133 | + xml_error_string(xml_get_error_code($phraseur->sax)) |
|
| 134 | + . "<br />\n" . |
|
| 135 | + (!$phraseur->depth ? '' : |
|
| 136 | + ('(' . |
|
| 137 | + _T('erreur_balise_non_fermee') . |
|
| 138 | + ' <tt>' . |
|
| 139 | + $phraseur->ouvrant[$phraseur->depth] . |
|
| 140 | + '</tt> ' . |
|
| 141 | + _T('ligne') . |
|
| 142 | + ' ' . |
|
| 143 | + $phraseur->reperes[$phraseur->depth] . |
|
| 144 | + ") <br />\n")) |
|
| 145 | + ); |
|
| 146 | + } |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | function coordonnees_erreur($phraseur, $msg) { |
| 150 | - $entete_length = substr_count($phraseur->entete, "\n"); |
|
| 151 | - $phraseur->err[] = [ |
|
| 152 | - $msg, |
|
| 153 | - xml_get_current_line_number($phraseur->sax) + $entete_length, |
|
| 154 | - xml_get_current_column_number($phraseur->sax) |
|
| 155 | - ]; |
|
| 150 | + $entete_length = substr_count($phraseur->entete, "\n"); |
|
| 151 | + $phraseur->err[] = [ |
|
| 152 | + $msg, |
|
| 153 | + xml_get_current_line_number($phraseur->sax) + $entete_length, |
|
| 154 | + xml_get_current_column_number($phraseur->sax) |
|
| 155 | + ]; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | function xml_sax_dist($page, $apply = false, $phraseur = null, $doctype = '', $charset = null) { |
| 159 | - if (is_null($charset)) { |
|
| 160 | - $charset = $GLOBALS['meta']['charset']; |
|
| 161 | - } |
|
| 162 | - if ($apply) { |
|
| 163 | - ob_start(); |
|
| 164 | - if (is_array($apply)) { |
|
| 165 | - $r = $page(...$apply); |
|
| 166 | - } else { |
|
| 167 | - $r = $page(); |
|
| 168 | - } |
|
| 169 | - $page = ob_get_contents(); |
|
| 170 | - ob_end_clean(); |
|
| 171 | - // fonction sans aucun "echo", ca doit etre le resultat |
|
| 172 | - if (!$page) { |
|
| 173 | - $page = $r; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - if (!$page) { |
|
| 178 | - return ''; |
|
| 179 | - } |
|
| 180 | - // charger la DTD et transcoder les entites, |
|
| 181 | - // et escamoter le doctype que sax mange en php5 mais pas en php4 |
|
| 182 | - if (!$doctype) { |
|
| 183 | - if (!$r = analyser_doctype($page)) { |
|
| 184 | - $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 185 | - . preg_replace(_REGEXP_DOCTYPE, '', $page); |
|
| 186 | - $r = analyser_doctype($page); |
|
| 187 | - } |
|
| 188 | - [$entete, $avail, $grammaire, $rotlvl] = array_pad($r, 4, null); |
|
| 189 | - $page = substr($page, strlen($entete)); |
|
| 190 | - } else { |
|
| 191 | - $avail = 'SYSTEM'; |
|
| 192 | - $grammaire = $doctype; |
|
| 193 | - $rotlvl = basename($grammaire); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - include_spip('xml/analyser_dtd'); |
|
| 197 | - $dtc = charger_dtd($grammaire, $avail, $rotlvl); |
|
| 198 | - $page = sax_bug($page, $dtc, $charset); |
|
| 199 | - |
|
| 200 | - // compatibilite Tidy espace public |
|
| 201 | - if (!$phraseur) { |
|
| 202 | - $indenter_xml = charger_fonction('indenter', 'xml'); |
|
| 203 | - |
|
| 204 | - return $indenter_xml($page, $apply); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $xml_parser = xml_parser_create($charset); |
|
| 208 | - |
|
| 209 | - xml_set_element_handler( |
|
| 210 | - $xml_parser, |
|
| 211 | - [$phraseur, 'debutElement'], |
|
| 212 | - [$phraseur, 'finElement'] |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - xml_set_character_data_handler( |
|
| 216 | - $xml_parser, |
|
| 217 | - [$phraseur, 'textElement'] |
|
| 218 | - ); |
|
| 219 | - |
|
| 220 | - xml_set_processing_instruction_handler( |
|
| 221 | - $xml_parser, |
|
| 222 | - [$phraseur, 'piElement'] |
|
| 223 | - ); |
|
| 224 | - |
|
| 225 | - xml_set_default_handler( |
|
| 226 | - $xml_parser, |
|
| 227 | - [$phraseur, 'defaultElement'] |
|
| 228 | - ); |
|
| 229 | - |
|
| 230 | - xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 231 | - |
|
| 232 | - $phraseur->sax = $xml_parser; |
|
| 233 | - if (isset($entete)) { |
|
| 234 | - $phraseur->entete = $entete; |
|
| 235 | - } |
|
| 236 | - $phraseur->page = $page; |
|
| 237 | - $phraseur->dtc = $dtc; |
|
| 238 | - $phraseur->phraserTout($xml_parser, $page); |
|
| 239 | - xml_parser_free($xml_parser); |
|
| 240 | - $phraseur->sax = ''; |
|
| 241 | - |
|
| 242 | - return $phraseur; |
|
| 159 | + if (is_null($charset)) { |
|
| 160 | + $charset = $GLOBALS['meta']['charset']; |
|
| 161 | + } |
|
| 162 | + if ($apply) { |
|
| 163 | + ob_start(); |
|
| 164 | + if (is_array($apply)) { |
|
| 165 | + $r = $page(...$apply); |
|
| 166 | + } else { |
|
| 167 | + $r = $page(); |
|
| 168 | + } |
|
| 169 | + $page = ob_get_contents(); |
|
| 170 | + ob_end_clean(); |
|
| 171 | + // fonction sans aucun "echo", ca doit etre le resultat |
|
| 172 | + if (!$page) { |
|
| 173 | + $page = $r; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + if (!$page) { |
|
| 178 | + return ''; |
|
| 179 | + } |
|
| 180 | + // charger la DTD et transcoder les entites, |
|
| 181 | + // et escamoter le doctype que sax mange en php5 mais pas en php4 |
|
| 182 | + if (!$doctype) { |
|
| 183 | + if (!$r = analyser_doctype($page)) { |
|
| 184 | + $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE |
|
| 185 | + . preg_replace(_REGEXP_DOCTYPE, '', $page); |
|
| 186 | + $r = analyser_doctype($page); |
|
| 187 | + } |
|
| 188 | + [$entete, $avail, $grammaire, $rotlvl] = array_pad($r, 4, null); |
|
| 189 | + $page = substr($page, strlen($entete)); |
|
| 190 | + } else { |
|
| 191 | + $avail = 'SYSTEM'; |
|
| 192 | + $grammaire = $doctype; |
|
| 193 | + $rotlvl = basename($grammaire); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + include_spip('xml/analyser_dtd'); |
|
| 197 | + $dtc = charger_dtd($grammaire, $avail, $rotlvl); |
|
| 198 | + $page = sax_bug($page, $dtc, $charset); |
|
| 199 | + |
|
| 200 | + // compatibilite Tidy espace public |
|
| 201 | + if (!$phraseur) { |
|
| 202 | + $indenter_xml = charger_fonction('indenter', 'xml'); |
|
| 203 | + |
|
| 204 | + return $indenter_xml($page, $apply); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $xml_parser = xml_parser_create($charset); |
|
| 208 | + |
|
| 209 | + xml_set_element_handler( |
|
| 210 | + $xml_parser, |
|
| 211 | + [$phraseur, 'debutElement'], |
|
| 212 | + [$phraseur, 'finElement'] |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + xml_set_character_data_handler( |
|
| 216 | + $xml_parser, |
|
| 217 | + [$phraseur, 'textElement'] |
|
| 218 | + ); |
|
| 219 | + |
|
| 220 | + xml_set_processing_instruction_handler( |
|
| 221 | + $xml_parser, |
|
| 222 | + [$phraseur, 'piElement'] |
|
| 223 | + ); |
|
| 224 | + |
|
| 225 | + xml_set_default_handler( |
|
| 226 | + $xml_parser, |
|
| 227 | + [$phraseur, 'defaultElement'] |
|
| 228 | + ); |
|
| 229 | + |
|
| 230 | + xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 231 | + |
|
| 232 | + $phraseur->sax = $xml_parser; |
|
| 233 | + if (isset($entete)) { |
|
| 234 | + $phraseur->entete = $entete; |
|
| 235 | + } |
|
| 236 | + $phraseur->page = $page; |
|
| 237 | + $phraseur->dtc = $dtc; |
|
| 238 | + $phraseur->phraserTout($xml_parser, $page); |
|
| 239 | + xml_parser_free($xml_parser); |
|
| 240 | + $phraseur->sax = ''; |
|
| 241 | + |
|
| 242 | + return $phraseur; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // SAX ne dit pas si une Entite est dans un attribut ou non. |
@@ -250,24 +250,24 @@ discard block |
||
| 250 | 250 | // sinon on se rabat sur ce qu'en connait SPIP en standard. |
| 251 | 251 | |
| 252 | 252 | function sax_bug($data, $dtc, $charset = null) { |
| 253 | - if (is_null($charset)) { |
|
| 254 | - $charset = $GLOBALS['meta']['charset']; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if ($dtc) { |
|
| 258 | - $trans = []; |
|
| 259 | - |
|
| 260 | - foreach ($dtc->entites as $k => $v) { |
|
| 261 | - if (!strpos(' amp lt gt quot ', (string) $k)) { |
|
| 262 | - $trans["&$k;"] = $v; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - $data = strtr($data, $trans); |
|
| 266 | - } else { |
|
| 267 | - $data = html2unicode($data, true); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - return unicode2charset($data, $charset); |
|
| 253 | + if (is_null($charset)) { |
|
| 254 | + $charset = $GLOBALS['meta']['charset']; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if ($dtc) { |
|
| 258 | + $trans = []; |
|
| 259 | + |
|
| 260 | + foreach ($dtc->entites as $k => $v) { |
|
| 261 | + if (!strpos(' amp lt gt quot ', (string) $k)) { |
|
| 262 | + $trans["&$k;"] = $v; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + $data = strtr($data, $trans); |
|
| 266 | + } else { |
|
| 267 | + $data = html2unicode($data, true); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + return unicode2charset($data, $charset); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // Retirer < ? xml... ? > et autre PI, ainsi que les commentaires en debut |
@@ -277,52 +277,52 @@ discard block |
||
| 277 | 277 | // les autres formats RSS n'ont pas de DTD, |
| 278 | 278 | // mais un XML Schema que SPIP ne fait pas encore lire. |
| 279 | 279 | function analyser_doctype($data) { |
| 280 | - if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
|
| 281 | - if (preg_match(_REGEXP_XML, $data, $page)) { |
|
| 282 | - [, $entete, $topelement] = $page; |
|
| 283 | - if ($topelement == 'rss') { |
|
| 284 | - return [ |
|
| 285 | - $entete, |
|
| 286 | - 'PUBLIC', |
|
| 287 | - _DOCTYPE_RSS, |
|
| 288 | - 'rss-0.91.dtd' |
|
| 289 | - ]; |
|
| 290 | - } else { |
|
| 291 | - $dtd = $topelement . '.dtd'; |
|
| 292 | - $f = find_in_path($dtd); |
|
| 293 | - if (file_exists($f)) { |
|
| 294 | - return [$entete, 'SYSTEM', $f, $dtd]; |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - spip_log('Dtd pas vu pour ' . substr($data, 0, 100)); |
|
| 299 | - |
|
| 300 | - return []; |
|
| 301 | - } |
|
| 302 | - [$entete, , $topelement, $avail, $suite] = $page; |
|
| 303 | - |
|
| 304 | - if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
|
| 305 | - if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
|
| 306 | - return []; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - [, $rotlvl, $suite] = $r; |
|
| 310 | - |
|
| 311 | - if (!$suite) { |
|
| 312 | - if ($avail != 'SYSTEM') { |
|
| 313 | - return []; |
|
| 314 | - } |
|
| 315 | - $grammaire = $rotlvl; |
|
| 316 | - $rotlvl = ''; |
|
| 317 | - } else { |
|
| 318 | - if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) { |
|
| 319 | - if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) { |
|
| 320 | - return []; |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - $grammaire = $r[1]; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - return [$entete, $avail, $grammaire, $rotlvl]; |
|
| 280 | + if (!preg_match(_REGEXP_DOCTYPE, $data, $page)) { |
|
| 281 | + if (preg_match(_REGEXP_XML, $data, $page)) { |
|
| 282 | + [, $entete, $topelement] = $page; |
|
| 283 | + if ($topelement == 'rss') { |
|
| 284 | + return [ |
|
| 285 | + $entete, |
|
| 286 | + 'PUBLIC', |
|
| 287 | + _DOCTYPE_RSS, |
|
| 288 | + 'rss-0.91.dtd' |
|
| 289 | + ]; |
|
| 290 | + } else { |
|
| 291 | + $dtd = $topelement . '.dtd'; |
|
| 292 | + $f = find_in_path($dtd); |
|
| 293 | + if (file_exists($f)) { |
|
| 294 | + return [$entete, 'SYSTEM', $f, $dtd]; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + spip_log('Dtd pas vu pour ' . substr($data, 0, 100)); |
|
| 299 | + |
|
| 300 | + return []; |
|
| 301 | + } |
|
| 302 | + [$entete, , $topelement, $avail, $suite] = $page; |
|
| 303 | + |
|
| 304 | + if (!preg_match('/^"([^"]*)"\s*(.*)$/', $suite, $r)) { |
|
| 305 | + if (!preg_match("/^'([^']*)'\s*(.*)$/", $suite, $r)) { |
|
| 306 | + return []; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + [, $rotlvl, $suite] = $r; |
|
| 310 | + |
|
| 311 | + if (!$suite) { |
|
| 312 | + if ($avail != 'SYSTEM') { |
|
| 313 | + return []; |
|
| 314 | + } |
|
| 315 | + $grammaire = $rotlvl; |
|
| 316 | + $rotlvl = ''; |
|
| 317 | + } else { |
|
| 318 | + if (!preg_match('/^"([^"]*)"\s*$/', $suite, $r)) { |
|
| 319 | + if (!preg_match("/^'([^']*)'\s*$/", $suite, $r)) { |
|
| 320 | + return []; |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + $grammaire = $r[1]; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + return [$entete, $avail, $grammaire, $rotlvl]; |
|
| 328 | 328 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $grammaire = find_in_path($grammaire); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | + $file = _DIR_CACHE_XML.preg_replace('/[^\w.]/', '_', $rotlvl).'.gz'; |
|
| 33 | 33 | |
| 34 | 34 | if (lire_fichier($file, $r)) { |
| 35 | 35 | if (!$grammaire) { |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $dtc->peres[$k] = $v; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . (is_countable($dtc->macros) ? count($dtc->macros) : 0) . ' macros, ' . (is_countable($dtc->elements) ? count($dtc->elements) : 0) . ' elements, ' . (is_countable($dtc->attributs) ? count($dtc->attributs) : 0) . " listes d'attributs, " . (is_countable($dtc->entites) ? count($dtc->entites) : 0) . ' entites'); |
|
| 59 | + spip_log("Analyser DTD $avail $grammaire (".spip_timer('dtd').') '.(is_countable($dtc->macros) ? count($dtc->macros) : 0).' macros, '.(is_countable($dtc->elements) ? count($dtc->elements) : 0).' elements, '.(is_countable($dtc->attributs) ? count($dtc->attributs) : 0)." listes d'attributs, ".(is_countable($dtc->entites) ? count($dtc->entites) : 0).' entites'); |
|
| 60 | 60 | # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
| 61 | 61 | ecrire_fichier($file, serialize($dtc), true); |
| 62 | 62 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | if (!is_string($r)) { |
| 176 | - spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 176 | + spip_log("erreur $r dans la DTD ".substr($dtd, 0, 80).'.....'); |
|
| 177 | 177 | |
| 178 | 178 | return false; |
| 179 | 179 | } |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | ($n[0] == 'PUBLIC') |
| 222 | 222 | and !tester_url_absolue($n[1]) |
| 223 | 223 | ) { |
| 224 | - $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 224 | + $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1).$n[1]; |
|
| 225 | 225 | } |
| 226 | 226 | analyser_dtd($n[1], $n[0], $dtc); |
| 227 | 227 | } |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | if ($dtc->macros[$m[1]] == 'INCLUDE') { |
| 252 | - $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 252 | + $retour = $r[1].substr($m[2], strlen($r[0])); |
|
| 253 | 253 | } else { |
| 254 | 254 | $retour = substr($m[2], strlen($r[0])); |
| 255 | 255 | } |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | spip_log("redefinition de l'entite $nom"); |
| 283 | 283 | } |
| 284 | 284 | if ($k6) { |
| 285 | - return $k6 . $dtd; |
|
| 285 | + return $k6.$dtd; |
|
| 286 | 286 | } // cas du synonyme complet |
| 287 | 287 | $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
| 288 | 288 | |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
| 391 | 391 | foreach ($r2 as $m2) { |
| 392 | 392 | $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
| 393 | - : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 393 | + : ('/^'.preg_replace('/\s+/', '', $m2[2]).'$/'); |
|
| 394 | 394 | $m21 = expanserEntite($m2[1], $dtc->macros); |
| 395 | 395 | $m25 = expanserEntite($m2[5], $dtc->macros); |
| 396 | 396 | $dtc->attributs[$nom][$m21] = [$v, $m25]; |
@@ -11,58 +11,58 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('xml/interfaces'); |
| 18 | 18 | |
| 19 | 19 | function charger_dtd($grammaire, $avail, $rotlvl) { |
| 20 | - $r = null; |
|
| 21 | - static $dtd = []; # cache bien utile pour le validateur en boucle |
|
| 22 | - |
|
| 23 | - if (isset($dtd[$grammaire])) { |
|
| 24 | - return $dtd[$grammaire]; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - if ($avail == 'SYSTEM') { |
|
| 28 | - $grammaire = find_in_path($grammaire); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | - |
|
| 33 | - if (lire_fichier($file, $r)) { |
|
| 34 | - if (!$grammaire) { |
|
| 35 | - return []; |
|
| 36 | - } |
|
| 37 | - if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) { |
|
| 38 | - $r = false; |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - if ($r) { |
|
| 43 | - $dtc = unserialize($r); |
|
| 44 | - } else { |
|
| 45 | - spip_timer('dtd'); |
|
| 46 | - $dtc = new DTC(); |
|
| 47 | - // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 48 | - // Retourner vide en cas d'echec |
|
| 49 | - if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 50 | - $dtc = []; |
|
| 51 | - } else { |
|
| 52 | - // tri final pour presenter les suggestions de corrections |
|
| 53 | - foreach ($dtc->peres as $k => $v) { |
|
| 54 | - asort($v); |
|
| 55 | - $dtc->peres[$k] = $v; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . (is_countable($dtc->macros) ? count($dtc->macros) : 0) . ' macros, ' . (is_countable($dtc->elements) ? count($dtc->elements) : 0) . ' elements, ' . (is_countable($dtc->attributs) ? count($dtc->attributs) : 0) . " listes d'attributs, " . (is_countable($dtc->entites) ? count($dtc->entites) : 0) . ' entites'); |
|
| 59 | - # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 60 | - ecrire_fichier($file, serialize($dtc), true); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - $dtd[$grammaire] = $dtc; |
|
| 64 | - |
|
| 65 | - return $dtc; |
|
| 20 | + $r = null; |
|
| 21 | + static $dtd = []; # cache bien utile pour le validateur en boucle |
|
| 22 | + |
|
| 23 | + if (isset($dtd[$grammaire])) { |
|
| 24 | + return $dtd[$grammaire]; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + if ($avail == 'SYSTEM') { |
|
| 28 | + $grammaire = find_in_path($grammaire); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $file = _DIR_CACHE_XML . preg_replace('/[^\w.]/', '_', $rotlvl) . '.gz'; |
|
| 32 | + |
|
| 33 | + if (lire_fichier($file, $r)) { |
|
| 34 | + if (!$grammaire) { |
|
| 35 | + return []; |
|
| 36 | + } |
|
| 37 | + if (($avail == 'SYSTEM') and filemtime($file) < filemtime($grammaire)) { |
|
| 38 | + $r = false; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + if ($r) { |
|
| 43 | + $dtc = unserialize($r); |
|
| 44 | + } else { |
|
| 45 | + spip_timer('dtd'); |
|
| 46 | + $dtc = new DTC(); |
|
| 47 | + // L'analyseur retourne un booleen de reussite et modifie $dtc. |
|
| 48 | + // Retourner vide en cas d'echec |
|
| 49 | + if (!analyser_dtd($grammaire, $avail, $dtc)) { |
|
| 50 | + $dtc = []; |
|
| 51 | + } else { |
|
| 52 | + // tri final pour presenter les suggestions de corrections |
|
| 53 | + foreach ($dtc->peres as $k => $v) { |
|
| 54 | + asort($v); |
|
| 55 | + $dtc->peres[$k] = $v; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + spip_log("Analyser DTD $avail $grammaire (" . spip_timer('dtd') . ') ' . (is_countable($dtc->macros) ? count($dtc->macros) : 0) . ' macros, ' . (is_countable($dtc->elements) ? count($dtc->elements) : 0) . ' elements, ' . (is_countable($dtc->attributs) ? count($dtc->attributs) : 0) . " listes d'attributs, " . (is_countable($dtc->entites) ? count($dtc->entites) : 0) . ' entites'); |
|
| 59 | + # $r = $dtc->regles; ksort($r);foreach($r as $l => $v) {$t=array_keys($dtc->attributs[$l]);echo "<b>$l</b> '$v' ", count($t), " attributs: ", join (', ',$t);$t=$dtc->peres[$l];echo "<br />",count($t), " peres: ", @join (', ',$t), "<br />\n";}exit; |
|
| 60 | + ecrire_fichier($file, serialize($dtc), true); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + $dtd[$grammaire] = $dtc; |
|
| 64 | + |
|
| 65 | + return $dtc; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Compiler une regle de production en une Regexp qu'on appliquera sur la |
@@ -74,153 +74,153 @@ discard block |
||
| 74 | 74 | // et parentheser le tout pour que | + * ? s'applique dessus. |
| 75 | 75 | |
| 76 | 76 | function compilerRegle($val) { |
| 77 | - $x = str_replace( |
|
| 78 | - '()', |
|
| 79 | - '', |
|
| 80 | - preg_replace( |
|
| 81 | - '/\s*,\s*/', |
|
| 82 | - '', |
|
| 83 | - preg_replace( |
|
| 84 | - '/(\w+)\s*/', |
|
| 85 | - '(?:\1 )', |
|
| 86 | - preg_replace( |
|
| 87 | - '/\s*\)/', |
|
| 88 | - ')', |
|
| 89 | - preg_replace( |
|
| 90 | - '/\s*([(+*|?])\s*/', |
|
| 91 | - '\1', |
|
| 92 | - preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val) |
|
| 93 | - ) |
|
| 94 | - ) |
|
| 95 | - ) |
|
| 96 | - ) |
|
| 97 | - ); |
|
| 98 | - |
|
| 99 | - return $x; |
|
| 77 | + $x = str_replace( |
|
| 78 | + '()', |
|
| 79 | + '', |
|
| 80 | + preg_replace( |
|
| 81 | + '/\s*,\s*/', |
|
| 82 | + '', |
|
| 83 | + preg_replace( |
|
| 84 | + '/(\w+)\s*/', |
|
| 85 | + '(?:\1 )', |
|
| 86 | + preg_replace( |
|
| 87 | + '/\s*\)/', |
|
| 88 | + ')', |
|
| 89 | + preg_replace( |
|
| 90 | + '/\s*([(+*|?])\s*/', |
|
| 91 | + '\1', |
|
| 92 | + preg_replace('/\s*#\w+\s*[,|]?\s*/', '', $val) |
|
| 93 | + ) |
|
| 94 | + ) |
|
| 95 | + ) |
|
| 96 | + ) |
|
| 97 | + ); |
|
| 98 | + |
|
| 99 | + return $x; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | 103 | function analyser_dtd($loc, $avail, &$dtc) { |
| 104 | - // creer le repertoire de cache si ce n'est fait |
|
| 105 | - // (utile aussi pour le resultat de la compil) |
|
| 106 | - $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 107 | - // si DTD locale, ignorer ce repertoire pour le moment |
|
| 108 | - if ($avail == 'SYSTEM') { |
|
| 109 | - $file = $loc; |
|
| 110 | - if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 111 | - $file = substr($file, strlen(_DIR_RACINE)); |
|
| 112 | - } |
|
| 113 | - $file = find_in_path($file); |
|
| 114 | - } else { |
|
| 115 | - $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $dtd = ''; |
|
| 119 | - if (@is_readable($file)) { |
|
| 120 | - lire_fichier($file, $dtd); |
|
| 121 | - } else { |
|
| 122 | - if ($avail == 'PUBLIC') { |
|
| 123 | - include_spip('inc/distant'); |
|
| 124 | - $dtd = recuperer_url($loc); |
|
| 125 | - $dtd = trim($dtd['page'] ?? ''); |
|
| 126 | - if ($dtd) { |
|
| 127 | - ecrire_fichier($file, $dtd, true); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $dtd = ltrim($dtd); |
|
| 133 | - if (!$dtd) { |
|
| 134 | - spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 135 | - |
|
| 136 | - return false; |
|
| 137 | - } else { |
|
| 138 | - spip_log("analyse de la DTD $loc "); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - while ($dtd) { |
|
| 142 | - if ($dtd[0] != '<') { |
|
| 143 | - $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 144 | - } elseif ($dtd[1] != '!') { |
|
| 145 | - $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 146 | - } elseif ($dtd[2] == '[') { |
|
| 147 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 148 | - } else { |
|
| 149 | - switch ($dtd[3]) { |
|
| 150 | - case '%': |
|
| 151 | - $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 152 | - break; |
|
| 153 | - case 'T': |
|
| 154 | - $r = analyser_dtd_attlist($dtd, $dtc, $loc); |
|
| 155 | - break; |
|
| 156 | - case 'L': |
|
| 157 | - $r = analyser_dtd_element($dtd, $dtc, $loc); |
|
| 158 | - break; |
|
| 159 | - case 'N': |
|
| 160 | - $r = analyser_dtd_entity($dtd, $dtc, $loc); |
|
| 161 | - break; |
|
| 162 | - case 'O': |
|
| 163 | - $r = analyser_dtd_notation($dtd, $dtc, $loc); |
|
| 164 | - break; |
|
| 165 | - case '-': |
|
| 166 | - $r = analyser_dtd_comment($dtd, $dtc, $loc); |
|
| 167 | - break; |
|
| 168 | - default: |
|
| 169 | - $r = -1; |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - if (!is_string($r)) { |
|
| 173 | - spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 174 | - |
|
| 175 | - return false; |
|
| 176 | - } |
|
| 177 | - $dtd = $r; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return true; |
|
| 104 | + // creer le repertoire de cache si ce n'est fait |
|
| 105 | + // (utile aussi pour le resultat de la compil) |
|
| 106 | + $file = sous_repertoire(_DIR_CACHE_XML); |
|
| 107 | + // si DTD locale, ignorer ce repertoire pour le moment |
|
| 108 | + if ($avail == 'SYSTEM') { |
|
| 109 | + $file = $loc; |
|
| 110 | + if (_DIR_RACINE and strncmp($file, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 111 | + $file = substr($file, strlen(_DIR_RACINE)); |
|
| 112 | + } |
|
| 113 | + $file = find_in_path($file); |
|
| 114 | + } else { |
|
| 115 | + $file .= preg_replace('/[^\w.]/', '_', $loc); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $dtd = ''; |
|
| 119 | + if (@is_readable($file)) { |
|
| 120 | + lire_fichier($file, $dtd); |
|
| 121 | + } else { |
|
| 122 | + if ($avail == 'PUBLIC') { |
|
| 123 | + include_spip('inc/distant'); |
|
| 124 | + $dtd = recuperer_url($loc); |
|
| 125 | + $dtd = trim($dtd['page'] ?? ''); |
|
| 126 | + if ($dtd) { |
|
| 127 | + ecrire_fichier($file, $dtd, true); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $dtd = ltrim($dtd); |
|
| 133 | + if (!$dtd) { |
|
| 134 | + spip_log("DTD '$loc' ($file) inaccessible"); |
|
| 135 | + |
|
| 136 | + return false; |
|
| 137 | + } else { |
|
| 138 | + spip_log("analyse de la DTD $loc "); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + while ($dtd) { |
|
| 142 | + if ($dtd[0] != '<') { |
|
| 143 | + $r = analyser_dtd_lexeme($dtd, $dtc, $loc); |
|
| 144 | + } elseif ($dtd[1] != '!') { |
|
| 145 | + $r = analyser_dtd_pi($dtd, $dtc, $loc); |
|
| 146 | + } elseif ($dtd[2] == '[') { |
|
| 147 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 148 | + } else { |
|
| 149 | + switch ($dtd[3]) { |
|
| 150 | + case '%': |
|
| 151 | + $r = analyser_dtd_data($dtd, $dtc, $loc); |
|
| 152 | + break; |
|
| 153 | + case 'T': |
|
| 154 | + $r = analyser_dtd_attlist($dtd, $dtc, $loc); |
|
| 155 | + break; |
|
| 156 | + case 'L': |
|
| 157 | + $r = analyser_dtd_element($dtd, $dtc, $loc); |
|
| 158 | + break; |
|
| 159 | + case 'N': |
|
| 160 | + $r = analyser_dtd_entity($dtd, $dtc, $loc); |
|
| 161 | + break; |
|
| 162 | + case 'O': |
|
| 163 | + $r = analyser_dtd_notation($dtd, $dtc, $loc); |
|
| 164 | + break; |
|
| 165 | + case '-': |
|
| 166 | + $r = analyser_dtd_comment($dtd, $dtc, $loc); |
|
| 167 | + break; |
|
| 168 | + default: |
|
| 169 | + $r = -1; |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + if (!is_string($r)) { |
|
| 173 | + spip_log("erreur $r dans la DTD " . substr($dtd, 0, 80) . '.....'); |
|
| 174 | + |
|
| 175 | + return false; |
|
| 176 | + } |
|
| 177 | + $dtd = $r; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return true; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | function analyser_dtd_comment($dtd, &$dtc, $grammaire) { |
| 184 | - // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 185 | - // Option /s car sur plusieurs lignes parfois |
|
| 184 | + // ejecter les commentaires, surtout quand ils contiennent du code. |
|
| 185 | + // Option /s car sur plusieurs lignes parfois |
|
| 186 | 186 | |
| 187 | - if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 188 | - return -6; |
|
| 189 | - } |
|
| 187 | + if (!preg_match('/^<!--.*?-->\s*(.*)$/s', $dtd, $m)) { |
|
| 188 | + return -6; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - return $m[1]; |
|
| 191 | + return $m[1]; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | function analyser_dtd_pi($dtd, &$dtc, $grammaire) { |
| 195 | - if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 196 | - return -10; |
|
| 197 | - } |
|
| 195 | + if (!preg_match('/^<\?.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 196 | + return -10; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return $m[1]; |
|
| 199 | + return $m[1]; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | function analyser_dtd_lexeme($dtd, &$dtc, $grammaire) { |
| 203 | 203 | |
| 204 | - if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 205 | - return -9; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - [, $s] = $m; |
|
| 209 | - $n = $dtc->macros[$s]; |
|
| 210 | - |
|
| 211 | - if (is_array($n)) { |
|
| 212 | - // en cas d'inclusion, l'espace de nom est le meme |
|
| 213 | - // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 214 | - if ( |
|
| 215 | - ($n[0] == 'PUBLIC') |
|
| 216 | - and !tester_url_absolue($n[1]) |
|
| 217 | - ) { |
|
| 218 | - $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 219 | - } |
|
| 220 | - analyser_dtd($n[1], $n[0], $dtc); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return ltrim(substr($dtd, strlen($m[0]))); |
|
| 204 | + if (!preg_match(_REGEXP_ENTITY_DEF, $dtd, $m)) { |
|
| 205 | + return -9; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + [, $s] = $m; |
|
| 209 | + $n = $dtc->macros[$s]; |
|
| 210 | + |
|
| 211 | + if (is_array($n)) { |
|
| 212 | + // en cas d'inclusion, l'espace de nom est le meme |
|
| 213 | + // mais gaffe aux DTD dont l'URL est relative a l'engloblante |
|
| 214 | + if ( |
|
| 215 | + ($n[0] == 'PUBLIC') |
|
| 216 | + and !tester_url_absolue($n[1]) |
|
| 217 | + ) { |
|
| 218 | + $n[1] = substr($grammaire, 0, strrpos($grammaire, '/') + 1) . $n[1]; |
|
| 219 | + } |
|
| 220 | + analyser_dtd($n[1], $n[0], $dtc); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return ltrim(substr($dtd, strlen($m[0]))); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // il faudrait gerer plus proprement les niveaux d'inclusion: |
@@ -228,83 +228,83 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | function analyser_dtd_data($dtd, &$dtc, $grammaire) { |
| 230 | 230 | |
| 231 | - if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 232 | - return -11; |
|
| 233 | - } |
|
| 234 | - if ( |
|
| 235 | - !preg_match( |
|
| 236 | - '/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', |
|
| 237 | - $m[2], |
|
| 238 | - $r |
|
| 239 | - ) |
|
| 240 | - ) { |
|
| 241 | - return -12; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - if ($dtc->macros[$m[1]] == 'INCLUDE') { |
|
| 245 | - $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 246 | - } else { |
|
| 247 | - $retour = substr($m[2], strlen($r[0])); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - return $retour; |
|
| 231 | + if (!preg_match(_REGEXP_INCLUDE_USE, $dtd, $m)) { |
|
| 232 | + return -11; |
|
| 233 | + } |
|
| 234 | + if ( |
|
| 235 | + !preg_match( |
|
| 236 | + '/^((\s*<!(\[\s*%\s*[^;]*;\s*\[([^]<]*<[^>]*>)*[^]<]*\]\]>)|([^]>]*>))*[^]<]*)\]\]>\s*/s', |
|
| 237 | + $m[2], |
|
| 238 | + $r |
|
| 239 | + ) |
|
| 240 | + ) { |
|
| 241 | + return -12; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + if ($dtc->macros[$m[1]] == 'INCLUDE') { |
|
| 245 | + $retour = $r[1] . substr($m[2], strlen($r[0])); |
|
| 246 | + } else { |
|
| 247 | + $retour = substr($m[2], strlen($r[0])); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return $retour; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | function analyser_dtd_notation($dtd, &$dtc, $grammaire) { |
| 254 | - if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 255 | - return -8; |
|
| 256 | - } |
|
| 257 | - spip_log('analyser_dtd_notation a ecrire'); |
|
| 254 | + if (!preg_match('/^<!NOTATION.*?>\s*(.*)$/s', $dtd, $m)) { |
|
| 255 | + return -8; |
|
| 256 | + } |
|
| 257 | + spip_log('analyser_dtd_notation a ecrire'); |
|
| 258 | 258 | |
| 259 | - return $m[1]; |
|
| 259 | + return $m[1]; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | function analyser_dtd_entity($dtd, &$dtc, $grammaire) { |
| 263 | - if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 264 | - return -2; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - [$t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd] = $m; |
|
| 268 | - |
|
| 269 | - if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) { |
|
| 270 | - return $dtd; |
|
| 271 | - } |
|
| 272 | - if (isset($dtc->entites[$nom])) { |
|
| 273 | - spip_log("redefinition de l'entite $nom"); |
|
| 274 | - } |
|
| 275 | - if ($k6) { |
|
| 276 | - return $k6 . $dtd; |
|
| 277 | - } // cas du synonyme complet |
|
| 278 | - $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 279 | - |
|
| 280 | - // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 281 | - if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 282 | - [$t, $type, $val, $q, $alt] = $r; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - if (!$term) { |
|
| 286 | - $dtc->entites[$nom] = $val; |
|
| 287 | - } elseif (!$type) { |
|
| 288 | - $dtc->macros[$nom] = $val; |
|
| 289 | - } else { |
|
| 290 | - if (($type == 'SYSTEM') and !$alt) { |
|
| 291 | - $alt = $val; |
|
| 292 | - } |
|
| 293 | - if (!$alt) { |
|
| 294 | - $dtc->macros[$nom] = $val; |
|
| 295 | - } else { |
|
| 296 | - if ( |
|
| 297 | - ($type == 'PUBLIC') |
|
| 298 | - and (strpos($alt, '/') === false) |
|
| 299 | - ) { |
|
| 300 | - $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 301 | - . $alt; |
|
| 302 | - } |
|
| 303 | - $dtc->macros[$nom] = [$type, $alt]; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - return $dtd; |
|
| 263 | + if (!preg_match(_REGEXP_ENTITY_DECL, $dtd, $m)) { |
|
| 264 | + return -2; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + [$t, $term, $nom, $type, $k1, $k2, $k3, $k4, $k5, $k6, $c, $q, $alt, $dtd] = $m; |
|
| 268 | + |
|
| 269 | + if (isset($dtc->macros[$nom]) and $dtc->macros[$nom]) { |
|
| 270 | + return $dtd; |
|
| 271 | + } |
|
| 272 | + if (isset($dtc->entites[$nom])) { |
|
| 273 | + spip_log("redefinition de l'entite $nom"); |
|
| 274 | + } |
|
| 275 | + if ($k6) { |
|
| 276 | + return $k6 . $dtd; |
|
| 277 | + } // cas du synonyme complet |
|
| 278 | + $val = expanserEntite(($k2 ? $k3 : ($k4 ? $k5 : $k6)), $dtc->macros); |
|
| 279 | + |
|
| 280 | + // cas particulier double evaluation: 'PUBLIC "..." "...."' |
|
| 281 | + if (preg_match('/(PUBLIC|SYSTEM)\s+"([^"]*)"\s*("([^"]*)")?\s*$/s', $val, $r)) { |
|
| 282 | + [$t, $type, $val, $q, $alt] = $r; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + if (!$term) { |
|
| 286 | + $dtc->entites[$nom] = $val; |
|
| 287 | + } elseif (!$type) { |
|
| 288 | + $dtc->macros[$nom] = $val; |
|
| 289 | + } else { |
|
| 290 | + if (($type == 'SYSTEM') and !$alt) { |
|
| 291 | + $alt = $val; |
|
| 292 | + } |
|
| 293 | + if (!$alt) { |
|
| 294 | + $dtc->macros[$nom] = $val; |
|
| 295 | + } else { |
|
| 296 | + if ( |
|
| 297 | + ($type == 'PUBLIC') |
|
| 298 | + and (strpos($alt, '/') === false) |
|
| 299 | + ) { |
|
| 300 | + $alt = preg_replace(',/[^/]+$,', '/', $grammaire) |
|
| 301 | + . $alt; |
|
| 302 | + } |
|
| 303 | + $dtc->macros[$nom] = [$type, $alt]; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + return $dtd; |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | // Dresser le tableau des filles potentielles de l'element |
@@ -317,76 +317,76 @@ discard block |
||
| 317 | 317 | // Fin du controle en finElement |
| 318 | 318 | |
| 319 | 319 | function analyser_dtd_element($dtd, &$dtc, $grammaire) { |
| 320 | - if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 321 | - return -3; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - [, $nom, $contenu, $dtd] = $m; |
|
| 325 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 326 | - |
|
| 327 | - if (isset($dtc->elements[$nom])) { |
|
| 328 | - spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 329 | - |
|
| 330 | - return -4; |
|
| 331 | - } |
|
| 332 | - $filles = []; |
|
| 333 | - $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 334 | - $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 335 | - if ($val == '(?:EMPTY )') { |
|
| 336 | - $dtc->regles[$nom] = 'EMPTY'; |
|
| 337 | - } elseif ($val == '(?:ANY )') { |
|
| 338 | - $dtc->regles[$nom] = 'ANY'; |
|
| 339 | - } else { |
|
| 340 | - $last = substr($val, -1); |
|
| 341 | - if ( |
|
| 342 | - preg_match('/ \w/', $val) |
|
| 343 | - or (!empty($last) and strpos('*+?', $last) === false) |
|
| 344 | - ) { |
|
| 345 | - $dtc->regles[$nom] = "/^$val$/"; |
|
| 346 | - } else { |
|
| 347 | - $dtc->regles[$nom] = $last; |
|
| 348 | - } |
|
| 349 | - $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 350 | - |
|
| 351 | - foreach ($filles as $k) { |
|
| 352 | - if (!isset($dtc->peres[$k])) { |
|
| 353 | - $dtc->peres[$k] = []; |
|
| 354 | - } |
|
| 355 | - if (!in_array($nom, $dtc->peres[$k])) { |
|
| 356 | - $dtc->peres[$k][] = $nom; |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false); |
|
| 361 | - $dtc->elements[$nom] = $filles; |
|
| 362 | - |
|
| 363 | - return $dtd; |
|
| 320 | + if (!preg_match('/^<!ELEMENT\s+([^>\s]+)([^>]*)>\s*(.*)$/s', $dtd, $m)) { |
|
| 321 | + return -3; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + [, $nom, $contenu, $dtd] = $m; |
|
| 325 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 326 | + |
|
| 327 | + if (isset($dtc->elements[$nom])) { |
|
| 328 | + spip_log("redefinition de l'element $nom dans la DTD"); |
|
| 329 | + |
|
| 330 | + return -4; |
|
| 331 | + } |
|
| 332 | + $filles = []; |
|
| 333 | + $contenu = expanserEntite($contenu, $dtc->macros); |
|
| 334 | + $val = $contenu ? compilerRegle($contenu) : '(?:EMPTY )'; |
|
| 335 | + if ($val == '(?:EMPTY )') { |
|
| 336 | + $dtc->regles[$nom] = 'EMPTY'; |
|
| 337 | + } elseif ($val == '(?:ANY )') { |
|
| 338 | + $dtc->regles[$nom] = 'ANY'; |
|
| 339 | + } else { |
|
| 340 | + $last = substr($val, -1); |
|
| 341 | + if ( |
|
| 342 | + preg_match('/ \w/', $val) |
|
| 343 | + or (!empty($last) and strpos('*+?', $last) === false) |
|
| 344 | + ) { |
|
| 345 | + $dtc->regles[$nom] = "/^$val$/"; |
|
| 346 | + } else { |
|
| 347 | + $dtc->regles[$nom] = $last; |
|
| 348 | + } |
|
| 349 | + $filles = array_values(preg_split('/\W+/', $val, -1, PREG_SPLIT_NO_EMPTY)); |
|
| 350 | + |
|
| 351 | + foreach ($filles as $k) { |
|
| 352 | + if (!isset($dtc->peres[$k])) { |
|
| 353 | + $dtc->peres[$k] = []; |
|
| 354 | + } |
|
| 355 | + if (!in_array($nom, $dtc->peres[$k])) { |
|
| 356 | + $dtc->peres[$k][] = $nom; |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + $dtc->pcdata[$nom] = (strpos($contenu, '#PCDATA') === false); |
|
| 361 | + $dtc->elements[$nom] = $filles; |
|
| 362 | + |
|
| 363 | + return $dtd; |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
| 367 | 367 | function analyser_dtd_attlist($dtd, &$dtc, $grammaire) { |
| 368 | - if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 369 | - return -5; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - [, $nom, $val, $dtd] = $m; |
|
| 373 | - $nom = expanserEntite($nom, $dtc->macros); |
|
| 374 | - $val = expanserEntite($val, $dtc->macros); |
|
| 375 | - if (!isset($dtc->attributs[$nom])) { |
|
| 376 | - $dtc->attributs[$nom] = []; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 380 | - foreach ($r2 as $m2) { |
|
| 381 | - $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 382 | - : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 383 | - $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 384 | - $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 385 | - $dtc->attributs[$nom][$m21] = [$v, $m25]; |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - return $dtd; |
|
| 368 | + if (!preg_match('/^<!ATTLIST\s+(\S+)\s+([^>]*)>\s*(.*)/s', $dtd, $m)) { |
|
| 369 | + return -5; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + [, $nom, $val, $dtd] = $m; |
|
| 373 | + $nom = expanserEntite($nom, $dtc->macros); |
|
| 374 | + $val = expanserEntite($val, $dtc->macros); |
|
| 375 | + if (!isset($dtc->attributs[$nom])) { |
|
| 376 | + $dtc->attributs[$nom] = []; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + if (preg_match_all("/\s*(\S+)\s+(([(][^)]*[)])|(\S+))\s+([^\s']*)(\s*'[^']*')?/", $val, $r2, PREG_SET_ORDER)) { |
|
| 380 | + foreach ($r2 as $m2) { |
|
| 381 | + $v = preg_match('/^\w+$/', $m2[2]) ? $m2[2] |
|
| 382 | + : ('/^' . preg_replace('/\s+/', '', $m2[2]) . '$/'); |
|
| 383 | + $m21 = expanserEntite($m2[1], $dtc->macros); |
|
| 384 | + $m25 = expanserEntite($m2[5], $dtc->macros); |
|
| 385 | + $dtc->attributs[$nom][$m21] = [$v, $m25]; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + return $dtd; |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | |
@@ -402,26 +402,26 @@ discard block |
||
| 402 | 402 | * @return string|array |
| 403 | 403 | **/ |
| 404 | 404 | function expanserEntite($val, $macros = []) { |
| 405 | - static $vu = []; |
|
| 406 | - if (!is_string($val)) { |
|
| 407 | - return $vu; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 411 | - foreach ($r as $m) { |
|
| 412 | - $ent = $m[1]; |
|
| 413 | - // il peut valoir "" |
|
| 414 | - if (!isset($macros[$ent])) { |
|
| 415 | - spip_log("Entite $ent inconnu"); |
|
| 416 | - } else { |
|
| 417 | - if (!isset($vu[$ent])) { |
|
| 418 | - $vu[$ent] = 0; |
|
| 419 | - } |
|
| 420 | - ++$vu[$ent]; |
|
| 421 | - $val = str_replace($m[0], $macros[$ent], $val); |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 405 | + static $vu = []; |
|
| 406 | + if (!is_string($val)) { |
|
| 407 | + return $vu; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + if (preg_match_all(_REGEXP_ENTITY_USE, $val, $r, PREG_SET_ORDER)) { |
|
| 411 | + foreach ($r as $m) { |
|
| 412 | + $ent = $m[1]; |
|
| 413 | + // il peut valoir "" |
|
| 414 | + if (!isset($macros[$ent])) { |
|
| 415 | + spip_log("Entite $ent inconnu"); |
|
| 416 | + } else { |
|
| 417 | + if (!isset($vu[$ent])) { |
|
| 418 | + $vu[$ent] = 0; |
|
| 419 | + } |
|
| 420 | + ++$vu[$ent]; |
|
| 421 | + $val = str_replace($m[0], $macros[$ent], $val); |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + return trim(preg_replace('/\s+/', ' ', $val)); |
|
| 427 | 427 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/editer'); |
@@ -32,17 +32,17 @@ discard block |
||
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | 34 | function lister_statuts_proposes($desc, $publiable = true) { |
| 35 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 36 | - return false; |
|
| 37 | - } |
|
| 35 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 36 | + return false; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - $l = $desc['statut_textes_instituer']; |
|
| 40 | - if (!$publiable) { |
|
| 41 | - unset($l['publie']); |
|
| 42 | - unset($l['refuse']); |
|
| 43 | - } |
|
| 39 | + $l = $desc['statut_textes_instituer']; |
|
| 40 | + if (!$publiable) { |
|
| 41 | + unset($l['publie']); |
|
| 42 | + unset($l['refuse']); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - return $l; |
|
| 45 | + return $l; |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -64,54 +64,54 @@ discard block |
||
| 64 | 64 | * Environnement du formulaire ou false si aucun affichage à faire. |
| 65 | 65 | */ |
| 66 | 66 | function formulaires_instituer_objet_charger_dist($objet, $id_objet, $retour = '', $editable = true) { |
| 67 | - $editable = ($editable ? true : false); |
|
| 68 | - |
|
| 69 | - $table = table_objet_sql($objet); |
|
| 70 | - $desc = lister_tables_objets_sql($table); |
|
| 71 | - |
|
| 72 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 73 | - return false; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (!autoriser('modifier', $objet, $id_objet)) { |
|
| 77 | - $editable = false; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // charger le contenu de l'objet |
|
| 81 | - // dont son champ statut |
|
| 82 | - $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', ''); |
|
| 83 | - |
|
| 84 | - $publiable = true; |
|
| 85 | - $statuts = lister_statuts_proposes($desc); |
|
| 86 | - // tester si on a le droit de publier, si un statut publie existe |
|
| 87 | - if (isset($statuts['publie'])) { |
|
| 88 | - if (!autoriser('instituer', $objet, $id_objet, null, ['statut' => 'publie'])) { |
|
| 89 | - if ($v['statut'] == 'publie') { |
|
| 90 | - $editable = false; |
|
| 91 | - } else { |
|
| 92 | - $publiable = false; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - $statuts = lister_statuts_proposes($desc, $editable ? $publiable : true); |
|
| 97 | - if (count($statuts) == 1 and isset($statuts[$v['statut']])) { |
|
| 98 | - $editable = false; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $valeurs = [ |
|
| 102 | - 'editable' => $editable, |
|
| 103 | - 'statut' => $v['statut'], |
|
| 104 | - '_objet' => $objet, |
|
| 105 | - '_id_objet' => $id_objet, |
|
| 106 | - '_statuts' => $statuts, |
|
| 107 | - '_publiable' => $publiable, |
|
| 108 | - '_label' => $desc['texte_changer_statut'] ?? 'texte_article_statut', |
|
| 109 | - '_aide' => $desc['aide_changer_statut'] ?? '', |
|
| 110 | - '_hidden' => "<input type='hidden' name='statut_old' value='" . $v['statut'] . "' />", |
|
| 111 | - ]; |
|
| 112 | - |
|
| 113 | - #if (!count($valeurs['statuts'])) |
|
| 114 | - return $valeurs; |
|
| 67 | + $editable = ($editable ? true : false); |
|
| 68 | + |
|
| 69 | + $table = table_objet_sql($objet); |
|
| 70 | + $desc = lister_tables_objets_sql($table); |
|
| 71 | + |
|
| 72 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 73 | + return false; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (!autoriser('modifier', $objet, $id_objet)) { |
|
| 77 | + $editable = false; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // charger le contenu de l'objet |
|
| 81 | + // dont son champ statut |
|
| 82 | + $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', ''); |
|
| 83 | + |
|
| 84 | + $publiable = true; |
|
| 85 | + $statuts = lister_statuts_proposes($desc); |
|
| 86 | + // tester si on a le droit de publier, si un statut publie existe |
|
| 87 | + if (isset($statuts['publie'])) { |
|
| 88 | + if (!autoriser('instituer', $objet, $id_objet, null, ['statut' => 'publie'])) { |
|
| 89 | + if ($v['statut'] == 'publie') { |
|
| 90 | + $editable = false; |
|
| 91 | + } else { |
|
| 92 | + $publiable = false; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + $statuts = lister_statuts_proposes($desc, $editable ? $publiable : true); |
|
| 97 | + if (count($statuts) == 1 and isset($statuts[$v['statut']])) { |
|
| 98 | + $editable = false; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $valeurs = [ |
|
| 102 | + 'editable' => $editable, |
|
| 103 | + 'statut' => $v['statut'], |
|
| 104 | + '_objet' => $objet, |
|
| 105 | + '_id_objet' => $id_objet, |
|
| 106 | + '_statuts' => $statuts, |
|
| 107 | + '_publiable' => $publiable, |
|
| 108 | + '_label' => $desc['texte_changer_statut'] ?? 'texte_article_statut', |
|
| 109 | + '_aide' => $desc['aide_changer_statut'] ?? '', |
|
| 110 | + '_hidden' => "<input type='hidden' name='statut_old' value='" . $v['statut'] . "' />", |
|
| 111 | + ]; |
|
| 112 | + |
|
| 113 | + #if (!count($valeurs['statuts'])) |
|
| 114 | + return $valeurs; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -131,35 +131,35 @@ discard block |
||
| 131 | 131 | * Tableau des erreurs |
| 132 | 132 | */ |
| 133 | 133 | function formulaires_instituer_objet_verifier_dist($objet, $id_objet, $retour = '', $editable = true) { |
| 134 | - $erreurs = []; |
|
| 135 | - // charger le contenu de l'objet |
|
| 136 | - // dont son champ statut |
|
| 137 | - $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', ''); |
|
| 138 | - |
|
| 139 | - if ($v['statut'] !== _request('statut_old')) { |
|
| 140 | - $erreurs['statut'] = _T('instituer_erreur_statut_a_change'); |
|
| 141 | - } else { |
|
| 142 | - $table = table_objet_sql($objet); |
|
| 143 | - $desc = lister_tables_objets_sql($table); |
|
| 144 | - |
|
| 145 | - $publiable = true; |
|
| 146 | - if ( |
|
| 147 | - isset($v['id_rubrique']) |
|
| 148 | - and !autoriser('publierdans', 'rubrique', $v['id_rubrique']) |
|
| 149 | - ) { |
|
| 150 | - $publiable = false; |
|
| 151 | - } |
|
| 152 | - $l = lister_statuts_proposes($desc, $publiable); |
|
| 153 | - $statut = _request('statut'); |
|
| 154 | - if ( |
|
| 155 | - !isset($l[$statut]) |
|
| 156 | - or !autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 157 | - ) { |
|
| 158 | - $erreurs['statut'] = _T('instituer_erreur_statut_non_autorise'); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - return $erreurs; |
|
| 134 | + $erreurs = []; |
|
| 135 | + // charger le contenu de l'objet |
|
| 136 | + // dont son champ statut |
|
| 137 | + $v = formulaires_editer_objet_charger($objet, $id_objet, 0, 0, '', ''); |
|
| 138 | + |
|
| 139 | + if ($v['statut'] !== _request('statut_old')) { |
|
| 140 | + $erreurs['statut'] = _T('instituer_erreur_statut_a_change'); |
|
| 141 | + } else { |
|
| 142 | + $table = table_objet_sql($objet); |
|
| 143 | + $desc = lister_tables_objets_sql($table); |
|
| 144 | + |
|
| 145 | + $publiable = true; |
|
| 146 | + if ( |
|
| 147 | + isset($v['id_rubrique']) |
|
| 148 | + and !autoriser('publierdans', 'rubrique', $v['id_rubrique']) |
|
| 149 | + ) { |
|
| 150 | + $publiable = false; |
|
| 151 | + } |
|
| 152 | + $l = lister_statuts_proposes($desc, $publiable); |
|
| 153 | + $statut = _request('statut'); |
|
| 154 | + if ( |
|
| 155 | + !isset($l[$statut]) |
|
| 156 | + or !autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 157 | + ) { |
|
| 158 | + $erreurs['statut'] = _T('instituer_erreur_statut_non_autorise'); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return $erreurs; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -178,25 +178,25 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | function formulaires_instituer_objet_traiter_dist($objet, $id_objet, $retour = '', $editable = true) { |
| 180 | 180 | |
| 181 | - $c = ['statut' => _request('statut')]; |
|
| 182 | - // si on a envoye une 'date_posterieure', l'enregistrer |
|
| 183 | - // todo dans le HTML |
|
| 184 | - if ($d = _request('date_posterieure')) { |
|
| 185 | - $c['date'] = $d; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - include_spip('action/editer_objet'); |
|
| 190 | - if ($err = objet_instituer($objet, $id_objet, $c)) { |
|
| 191 | - $res = ['message_erreur' => $err]; |
|
| 192 | - } else { |
|
| 193 | - $res = ['message_ok' => _T('info_modification_enregistree')]; |
|
| 194 | - if ($retour) { |
|
| 195 | - $res['redirect'] = $retour; |
|
| 196 | - } |
|
| 197 | - set_request('statut'); |
|
| 198 | - set_request('date_posterieure'); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $res; |
|
| 181 | + $c = ['statut' => _request('statut')]; |
|
| 182 | + // si on a envoye une 'date_posterieure', l'enregistrer |
|
| 183 | + // todo dans le HTML |
|
| 184 | + if ($d = _request('date_posterieure')) { |
|
| 185 | + $c['date'] = $d; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + include_spip('action/editer_objet'); |
|
| 190 | + if ($err = objet_instituer($objet, $id_objet, $c)) { |
|
| 191 | + $res = ['message_erreur' => $err]; |
|
| 192 | + } else { |
|
| 193 | + $res = ['message_ok' => _T('info_modification_enregistree')]; |
|
| 194 | + if ($retour) { |
|
| 195 | + $res['redirect'] = $retour; |
|
| 196 | + } |
|
| 197 | + set_request('statut'); |
|
| 198 | + set_request('date_posterieure'); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $res; |
|
| 202 | 202 | } |
@@ -107,7 +107,7 @@ |
||
| 107 | 107 | '_publiable' => $publiable, |
| 108 | 108 | '_label' => $desc['texte_changer_statut'] ?? 'texte_article_statut', |
| 109 | 109 | '_aide' => $desc['aide_changer_statut'] ?? '', |
| 110 | - '_hidden' => "<input type='hidden' name='statut_old' value='" . $v['statut'] . "' />", |
|
| 110 | + '_hidden' => "<input type='hidden' name='statut_old' value='".$v['statut']."' />", |
|
| 111 | 111 | ]; |
| 112 | 112 | |
| 113 | 113 | #if (!count($valeurs['statuts'])) |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Formulaires |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -36,25 +36,25 @@ discard block |
||
| 36 | 36 | * ($table_source,$objet,$id_objet,$objet_lien) |
| 37 | 37 | */ |
| 38 | 38 | function determine_source_lien_objet($a, $b, $c) { |
| 39 | - $table_source = $objet_lien = $objet = $id_objet = null; |
|
| 40 | - // auteurs, article, 23 : |
|
| 41 | - // associer des auteurs à l'article 23, sur la table pivot spip_auteurs_liens |
|
| 42 | - if (is_numeric($c) and !is_numeric($b)) { |
|
| 43 | - $table_source = table_objet($a); |
|
| 44 | - $objet_lien = objet_type($a); |
|
| 45 | - $objet = objet_type($b); |
|
| 46 | - $id_objet = $c; |
|
| 47 | - } |
|
| 48 | - // article, 23, auteurs |
|
| 49 | - // associer des auteurs à l'article 23, sur la table pivot spip_articles_liens |
|
| 50 | - if (is_numeric($b) and !is_numeric($c)) { |
|
| 51 | - $table_source = table_objet($c); |
|
| 52 | - $objet_lien = objet_type($a); |
|
| 53 | - $objet = objet_type($a); |
|
| 54 | - $id_objet = $b; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - return [$table_source, $objet, $id_objet, $objet_lien]; |
|
| 39 | + $table_source = $objet_lien = $objet = $id_objet = null; |
|
| 40 | + // auteurs, article, 23 : |
|
| 41 | + // associer des auteurs à l'article 23, sur la table pivot spip_auteurs_liens |
|
| 42 | + if (is_numeric($c) and !is_numeric($b)) { |
|
| 43 | + $table_source = table_objet($a); |
|
| 44 | + $objet_lien = objet_type($a); |
|
| 45 | + $objet = objet_type($b); |
|
| 46 | + $id_objet = $c; |
|
| 47 | + } |
|
| 48 | + // article, 23, auteurs |
|
| 49 | + // associer des auteurs à l'article 23, sur la table pivot spip_articles_liens |
|
| 50 | + if (is_numeric($b) and !is_numeric($c)) { |
|
| 51 | + $table_source = table_objet($c); |
|
| 52 | + $objet_lien = objet_type($a); |
|
| 53 | + $objet = objet_type($a); |
|
| 54 | + $id_objet = $b; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + return [$table_source, $objet, $id_objet, $objet_lien]; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -80,93 +80,93 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function formulaires_editer_liens_charger_dist($a, $b, $c, $options = []) { |
| 82 | 82 | |
| 83 | - // compat avec ancienne signature ou le 4eme argument est $editable |
|
| 84 | - if (!is_array($options)) { |
|
| 85 | - $options = ['editable' => $options]; |
|
| 86 | - } elseif (!isset($options['editable'])) { |
|
| 87 | - $options['editable'] = true; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $editable = $options['editable']; |
|
| 91 | - |
|
| 92 | - [$table_source, $objet, $id_objet, $objet_lien] = determine_source_lien_objet($a, $b, $c); |
|
| 93 | - if (!$table_source or !$objet or !$objet_lien or !$id_objet) { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $objet_source = objet_type($table_source); |
|
| 98 | - $table_sql_source = table_objet_sql($objet_source); |
|
| 99 | - |
|
| 100 | - // verifier existence de la table xxx_liens |
|
| 101 | - include_spip('action/editer_liens'); |
|
| 102 | - if (!objet_associable($objet_lien)) { |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // L'éditabilité :) est définie par un test permanent (par exemple "associermots") ET le 4ème argument |
|
| 107 | - include_spip('inc/autoriser'); |
|
| 108 | - $editable = ($editable and autoriser('associer' . $table_source, $objet, $id_objet) |
|
| 109 | - and autoriser('modifier', $objet, $id_objet)); |
|
| 110 | - |
|
| 111 | - if ( |
|
| 112 | - !$editable and !count(objet_trouver_liens( |
|
| 113 | - [$objet_lien => '*'], |
|
| 114 | - [($objet_lien == $objet_source ? $objet : $objet_source) => $id_objet] |
|
| 115 | - )) |
|
| 116 | - ) { |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // squelettes de vue et de d'association |
|
| 121 | - // ils sont différents si des rôles sont définis. |
|
| 122 | - $skel_vue = $table_source . '_lies'; |
|
| 123 | - $skel_ajout = $table_source . '_associer'; |
|
| 124 | - |
|
| 125 | - // description des roles |
|
| 126 | - include_spip('inc/roles'); |
|
| 127 | - if ($roles = roles_presents($objet_source, $objet)) { |
|
| 128 | - // on demande de nouveaux squelettes en conséquence |
|
| 129 | - $skel_vue = $table_source . '_roles_lies'; |
|
| 130 | - $skel_ajout = $table_source . '_roles_associer'; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $oups = _request('_oups') ?? ''; |
|
| 134 | - if ($oups) { |
|
| 135 | - if (unserialize(base64_decode($oups))) { |
|
| 136 | - // on est bon, rien a faire |
|
| 137 | - } elseif (unserialize($oups)) { |
|
| 138 | - // il faut encoder |
|
| 139 | - $oups = base64_encode($oups); |
|
| 140 | - } else { |
|
| 141 | - $oups = ''; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - $valeurs = [ |
|
| 145 | - 'id' => "$table_source-$objet-$id_objet-$objet_lien", // identifiant unique pour les id du form |
|
| 146 | - '_vue_liee' => $skel_vue, |
|
| 147 | - '_vue_ajout' => $skel_ajout, |
|
| 148 | - '_objet_lien' => $objet_lien, |
|
| 149 | - 'id_lien_ajoute' => _request('id_lien_ajoute'), |
|
| 150 | - 'objet' => $objet, |
|
| 151 | - 'id_objet' => $id_objet, |
|
| 152 | - 'objet_source' => $objet_source, |
|
| 153 | - 'table_source' => $table_source, |
|
| 154 | - 'recherche' => '', |
|
| 155 | - 'visible' => 0, |
|
| 156 | - 'ajouter_lien' => '', |
|
| 157 | - 'supprimer_lien' => '', |
|
| 158 | - 'qualifier_lien' => '', |
|
| 159 | - 'ordonner_lien' => '', |
|
| 160 | - 'desordonner_liens' => '', |
|
| 161 | - '_roles' => $roles, # description des roles |
|
| 162 | - '_oups' => $oups, |
|
| 163 | - 'editable' => $editable, |
|
| 164 | - ]; |
|
| 165 | - |
|
| 166 | - // les options non definies dans $valeurs sont passees telles quelles au formulaire html |
|
| 167 | - $valeurs = array_merge($options, $valeurs); |
|
| 168 | - |
|
| 169 | - return $valeurs; |
|
| 83 | + // compat avec ancienne signature ou le 4eme argument est $editable |
|
| 84 | + if (!is_array($options)) { |
|
| 85 | + $options = ['editable' => $options]; |
|
| 86 | + } elseif (!isset($options['editable'])) { |
|
| 87 | + $options['editable'] = true; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $editable = $options['editable']; |
|
| 91 | + |
|
| 92 | + [$table_source, $objet, $id_objet, $objet_lien] = determine_source_lien_objet($a, $b, $c); |
|
| 93 | + if (!$table_source or !$objet or !$objet_lien or !$id_objet) { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $objet_source = objet_type($table_source); |
|
| 98 | + $table_sql_source = table_objet_sql($objet_source); |
|
| 99 | + |
|
| 100 | + // verifier existence de la table xxx_liens |
|
| 101 | + include_spip('action/editer_liens'); |
|
| 102 | + if (!objet_associable($objet_lien)) { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // L'éditabilité :) est définie par un test permanent (par exemple "associermots") ET le 4ème argument |
|
| 107 | + include_spip('inc/autoriser'); |
|
| 108 | + $editable = ($editable and autoriser('associer' . $table_source, $objet, $id_objet) |
|
| 109 | + and autoriser('modifier', $objet, $id_objet)); |
|
| 110 | + |
|
| 111 | + if ( |
|
| 112 | + !$editable and !count(objet_trouver_liens( |
|
| 113 | + [$objet_lien => '*'], |
|
| 114 | + [($objet_lien == $objet_source ? $objet : $objet_source) => $id_objet] |
|
| 115 | + )) |
|
| 116 | + ) { |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // squelettes de vue et de d'association |
|
| 121 | + // ils sont différents si des rôles sont définis. |
|
| 122 | + $skel_vue = $table_source . '_lies'; |
|
| 123 | + $skel_ajout = $table_source . '_associer'; |
|
| 124 | + |
|
| 125 | + // description des roles |
|
| 126 | + include_spip('inc/roles'); |
|
| 127 | + if ($roles = roles_presents($objet_source, $objet)) { |
|
| 128 | + // on demande de nouveaux squelettes en conséquence |
|
| 129 | + $skel_vue = $table_source . '_roles_lies'; |
|
| 130 | + $skel_ajout = $table_source . '_roles_associer'; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $oups = _request('_oups') ?? ''; |
|
| 134 | + if ($oups) { |
|
| 135 | + if (unserialize(base64_decode($oups))) { |
|
| 136 | + // on est bon, rien a faire |
|
| 137 | + } elseif (unserialize($oups)) { |
|
| 138 | + // il faut encoder |
|
| 139 | + $oups = base64_encode($oups); |
|
| 140 | + } else { |
|
| 141 | + $oups = ''; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + $valeurs = [ |
|
| 145 | + 'id' => "$table_source-$objet-$id_objet-$objet_lien", // identifiant unique pour les id du form |
|
| 146 | + '_vue_liee' => $skel_vue, |
|
| 147 | + '_vue_ajout' => $skel_ajout, |
|
| 148 | + '_objet_lien' => $objet_lien, |
|
| 149 | + 'id_lien_ajoute' => _request('id_lien_ajoute'), |
|
| 150 | + 'objet' => $objet, |
|
| 151 | + 'id_objet' => $id_objet, |
|
| 152 | + 'objet_source' => $objet_source, |
|
| 153 | + 'table_source' => $table_source, |
|
| 154 | + 'recherche' => '', |
|
| 155 | + 'visible' => 0, |
|
| 156 | + 'ajouter_lien' => '', |
|
| 157 | + 'supprimer_lien' => '', |
|
| 158 | + 'qualifier_lien' => '', |
|
| 159 | + 'ordonner_lien' => '', |
|
| 160 | + 'desordonner_liens' => '', |
|
| 161 | + '_roles' => $roles, # description des roles |
|
| 162 | + '_oups' => $oups, |
|
| 163 | + 'editable' => $editable, |
|
| 164 | + ]; |
|
| 165 | + |
|
| 166 | + // les options non definies dans $valeurs sont passees telles quelles au formulaire html |
|
| 167 | + $valeurs = array_merge($options, $valeurs); |
|
| 168 | + |
|
| 169 | + return $valeurs; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -210,165 +210,165 @@ discard block |
||
| 210 | 210 | * @return array |
| 211 | 211 | */ |
| 212 | 212 | function formulaires_editer_liens_traiter_dist($a, $b, $c, $options = []) { |
| 213 | - // compat avec ancienne signature ou le 4eme argument est $editable |
|
| 214 | - if (!is_array($options)) { |
|
| 215 | - $options = ['editable' => $options]; |
|
| 216 | - } elseif (!isset($options['editable'])) { |
|
| 217 | - $options['editable'] = true; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - $editable = $options['editable']; |
|
| 221 | - |
|
| 222 | - $res = ['editable' => $editable ? true : false]; |
|
| 223 | - [$table_source, $objet, $id_objet, $objet_lien] = determine_source_lien_objet($a, $b, $c); |
|
| 224 | - if (!$table_source or !$objet or !$objet_lien) { |
|
| 225 | - return $res; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - if (_request('tout_voir')) { |
|
| 230 | - set_request('recherche', ''); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - include_spip('inc/autoriser'); |
|
| 234 | - if (autoriser('modifier', $objet, $id_objet)) { |
|
| 235 | - // annuler les suppressions du coup d'avant ! |
|
| 236 | - if ( |
|
| 237 | - _request('annuler_oups') |
|
| 238 | - and $oups = _request('_oups') |
|
| 239 | - and $oups = base64_decode($oups) |
|
| 240 | - and $oups = unserialize($oups) |
|
| 241 | - ) { |
|
| 242 | - if ($oups_objets = charger_fonction("editer_liens_oups_{$table_source}_{$objet}_{$objet_lien}", 'action', true)) { |
|
| 243 | - $oups_objets($oups); |
|
| 244 | - } else { |
|
| 245 | - $objet_source = objet_type($table_source); |
|
| 246 | - include_spip('action/editer_liens'); |
|
| 247 | - foreach ($oups as $oup) { |
|
| 248 | - if ($objet_lien == $objet_source) { |
|
| 249 | - objet_associer([$objet_source => $oup[$objet_source]], [$objet => $oup[$objet]], $oup); |
|
| 250 | - } else { |
|
| 251 | - objet_associer([$objet => $oup[$objet]], [$objet_source => $oup[$objet_source]], $oup); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - # oups ne persiste que pour la derniere action, si suppression |
|
| 256 | - set_request('_oups'); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $supprimer = _request('supprimer_lien'); |
|
| 260 | - $ajouter = _request('ajouter_lien'); |
|
| 261 | - $ordonner = _request('ordonner_lien'); |
|
| 262 | - |
|
| 263 | - if (_request('desordonner_liens')) { |
|
| 264 | - include_spip('action/editer_liens'); |
|
| 265 | - objet_qualifier_liens([$objet_lien => '*'], [$objet => $id_objet], ['rang_lien' => 0]); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - // il est possible de preciser dans une seule variable un remplacement : |
|
| 269 | - // remplacer_lien[old][new] |
|
| 270 | - if ($remplacer = _request('remplacer_lien')) { |
|
| 271 | - foreach ($remplacer as $k => $v) { |
|
| 272 | - if ($old = lien_verifier_action($k, '')) { |
|
| 273 | - foreach (is_array($v) ? $v : [$v] as $kn => $vn) { |
|
| 274 | - if ($new = lien_verifier_action($kn, $vn)) { |
|
| 275 | - $supprimer[$old] = 'x'; |
|
| 276 | - $ajouter[$new] = '+'; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - if ($supprimer) { |
|
| 284 | - if ( |
|
| 285 | - $supprimer_objets = charger_fonction( |
|
| 286 | - "editer_liens_supprimer_{$table_source}_{$objet}_{$objet_lien}", |
|
| 287 | - 'action', |
|
| 288 | - true |
|
| 289 | - ) |
|
| 290 | - ) { |
|
| 291 | - $oups = $supprimer_objets($supprimer); |
|
| 292 | - } else { |
|
| 293 | - include_spip('action/editer_liens'); |
|
| 294 | - $oups = []; |
|
| 295 | - |
|
| 296 | - foreach ($supprimer as $k => $v) { |
|
| 297 | - if ($lien = lien_verifier_action($k, $v)) { |
|
| 298 | - $lien = explode('-', $lien); |
|
| 299 | - [$objet_source, $ids, $objet_lie, $idl, $role] = array_pad($lien, 5, null); |
|
| 300 | - // appliquer une condition sur le rôle si défini ('*' pour tous les roles) |
|
| 301 | - $cond = (!is_null($role) ? ['role' => $role] : []); |
|
| 302 | - if ($objet_lien == $objet_source) { |
|
| 303 | - $oups = array_merge( |
|
| 304 | - $oups, |
|
| 305 | - objet_trouver_liens([$objet_source => $ids], [$objet_lie => $idl], $cond) |
|
| 306 | - ); |
|
| 307 | - objet_dissocier([$objet_source => $ids], [$objet_lie => $idl], $cond); |
|
| 308 | - } else { |
|
| 309 | - $oups = array_merge( |
|
| 310 | - $oups, |
|
| 311 | - objet_trouver_liens([$objet_lie => $idl], [$objet_source => $ids], $cond) |
|
| 312 | - ); |
|
| 313 | - objet_dissocier([$objet_lie => $idl], [$objet_source => $ids], $cond); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - set_request('_oups', $oups ? base64_encode(serialize($oups)) : null); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - if ($ajouter) { |
|
| 322 | - if ( |
|
| 323 | - $ajouter_objets = charger_fonction("editer_liens_ajouter_{$table_source}_{$objet}_{$objet_lien}", 'action', true) |
|
| 324 | - ) { |
|
| 325 | - $ajout_ok = $ajouter_objets($ajouter); |
|
| 326 | - } else { |
|
| 327 | - $ajout_ok = false; |
|
| 328 | - include_spip('action/editer_liens'); |
|
| 329 | - foreach ($ajouter as $k => $v) { |
|
| 330 | - if ($lien = lien_verifier_action($k, $v)) { |
|
| 331 | - $ajout_ok = true; |
|
| 332 | - [$objet1, $ids, $objet2, $idl] = explode('-', $lien); |
|
| 333 | - $qualifs = lien_retrouver_qualif($objet_lien, $lien); |
|
| 334 | - if ($objet_lien == $objet1) { |
|
| 335 | - lien_ajouter_liaisons($objet1, $ids, $objet2, $idl, $qualifs); |
|
| 336 | - } else { |
|
| 337 | - lien_ajouter_liaisons($objet2, $idl, $objet1, $ids, $qualifs); |
|
| 338 | - } |
|
| 339 | - set_request('id_lien_ajoute', $ids); |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - # oups ne persiste que pour la derniere action, si suppression |
|
| 344 | - # une suppression suivie d'un ajout dans le meme hit est un remplacement |
|
| 345 | - # non annulable ! |
|
| 346 | - if ($ajout_ok) { |
|
| 347 | - set_request('_oups'); |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - if ($ordonner) { |
|
| 352 | - include_spip('action/editer_liens'); |
|
| 353 | - foreach ($ordonner as $k => $rang_lien) { |
|
| 354 | - if ($lien = lien_verifier_action($k, '')) { |
|
| 355 | - [$objet1, $ids, $objet2, $idl] = explode('-', $lien); |
|
| 356 | - $qualif = ['rang_lien' => $rang_lien]; |
|
| 357 | - |
|
| 358 | - if ($objet_lien == $objet1) { |
|
| 359 | - objet_qualifier_liens([$objet1 => $ids], [$objet2 => $idl], $qualif); |
|
| 360 | - } else { |
|
| 361 | - objet_qualifier_liens([$objet2 => $idl], [$objet1 => $ids], $qualif); |
|
| 362 | - } |
|
| 363 | - set_request('id_lien_ajoute', $ids); |
|
| 364 | - set_request('_oups'); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - return $res; |
|
| 213 | + // compat avec ancienne signature ou le 4eme argument est $editable |
|
| 214 | + if (!is_array($options)) { |
|
| 215 | + $options = ['editable' => $options]; |
|
| 216 | + } elseif (!isset($options['editable'])) { |
|
| 217 | + $options['editable'] = true; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + $editable = $options['editable']; |
|
| 221 | + |
|
| 222 | + $res = ['editable' => $editable ? true : false]; |
|
| 223 | + [$table_source, $objet, $id_objet, $objet_lien] = determine_source_lien_objet($a, $b, $c); |
|
| 224 | + if (!$table_source or !$objet or !$objet_lien) { |
|
| 225 | + return $res; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + if (_request('tout_voir')) { |
|
| 230 | + set_request('recherche', ''); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + include_spip('inc/autoriser'); |
|
| 234 | + if (autoriser('modifier', $objet, $id_objet)) { |
|
| 235 | + // annuler les suppressions du coup d'avant ! |
|
| 236 | + if ( |
|
| 237 | + _request('annuler_oups') |
|
| 238 | + and $oups = _request('_oups') |
|
| 239 | + and $oups = base64_decode($oups) |
|
| 240 | + and $oups = unserialize($oups) |
|
| 241 | + ) { |
|
| 242 | + if ($oups_objets = charger_fonction("editer_liens_oups_{$table_source}_{$objet}_{$objet_lien}", 'action', true)) { |
|
| 243 | + $oups_objets($oups); |
|
| 244 | + } else { |
|
| 245 | + $objet_source = objet_type($table_source); |
|
| 246 | + include_spip('action/editer_liens'); |
|
| 247 | + foreach ($oups as $oup) { |
|
| 248 | + if ($objet_lien == $objet_source) { |
|
| 249 | + objet_associer([$objet_source => $oup[$objet_source]], [$objet => $oup[$objet]], $oup); |
|
| 250 | + } else { |
|
| 251 | + objet_associer([$objet => $oup[$objet]], [$objet_source => $oup[$objet_source]], $oup); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + # oups ne persiste que pour la derniere action, si suppression |
|
| 256 | + set_request('_oups'); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $supprimer = _request('supprimer_lien'); |
|
| 260 | + $ajouter = _request('ajouter_lien'); |
|
| 261 | + $ordonner = _request('ordonner_lien'); |
|
| 262 | + |
|
| 263 | + if (_request('desordonner_liens')) { |
|
| 264 | + include_spip('action/editer_liens'); |
|
| 265 | + objet_qualifier_liens([$objet_lien => '*'], [$objet => $id_objet], ['rang_lien' => 0]); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + // il est possible de preciser dans une seule variable un remplacement : |
|
| 269 | + // remplacer_lien[old][new] |
|
| 270 | + if ($remplacer = _request('remplacer_lien')) { |
|
| 271 | + foreach ($remplacer as $k => $v) { |
|
| 272 | + if ($old = lien_verifier_action($k, '')) { |
|
| 273 | + foreach (is_array($v) ? $v : [$v] as $kn => $vn) { |
|
| 274 | + if ($new = lien_verifier_action($kn, $vn)) { |
|
| 275 | + $supprimer[$old] = 'x'; |
|
| 276 | + $ajouter[$new] = '+'; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + if ($supprimer) { |
|
| 284 | + if ( |
|
| 285 | + $supprimer_objets = charger_fonction( |
|
| 286 | + "editer_liens_supprimer_{$table_source}_{$objet}_{$objet_lien}", |
|
| 287 | + 'action', |
|
| 288 | + true |
|
| 289 | + ) |
|
| 290 | + ) { |
|
| 291 | + $oups = $supprimer_objets($supprimer); |
|
| 292 | + } else { |
|
| 293 | + include_spip('action/editer_liens'); |
|
| 294 | + $oups = []; |
|
| 295 | + |
|
| 296 | + foreach ($supprimer as $k => $v) { |
|
| 297 | + if ($lien = lien_verifier_action($k, $v)) { |
|
| 298 | + $lien = explode('-', $lien); |
|
| 299 | + [$objet_source, $ids, $objet_lie, $idl, $role] = array_pad($lien, 5, null); |
|
| 300 | + // appliquer une condition sur le rôle si défini ('*' pour tous les roles) |
|
| 301 | + $cond = (!is_null($role) ? ['role' => $role] : []); |
|
| 302 | + if ($objet_lien == $objet_source) { |
|
| 303 | + $oups = array_merge( |
|
| 304 | + $oups, |
|
| 305 | + objet_trouver_liens([$objet_source => $ids], [$objet_lie => $idl], $cond) |
|
| 306 | + ); |
|
| 307 | + objet_dissocier([$objet_source => $ids], [$objet_lie => $idl], $cond); |
|
| 308 | + } else { |
|
| 309 | + $oups = array_merge( |
|
| 310 | + $oups, |
|
| 311 | + objet_trouver_liens([$objet_lie => $idl], [$objet_source => $ids], $cond) |
|
| 312 | + ); |
|
| 313 | + objet_dissocier([$objet_lie => $idl], [$objet_source => $ids], $cond); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + set_request('_oups', $oups ? base64_encode(serialize($oups)) : null); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + if ($ajouter) { |
|
| 322 | + if ( |
|
| 323 | + $ajouter_objets = charger_fonction("editer_liens_ajouter_{$table_source}_{$objet}_{$objet_lien}", 'action', true) |
|
| 324 | + ) { |
|
| 325 | + $ajout_ok = $ajouter_objets($ajouter); |
|
| 326 | + } else { |
|
| 327 | + $ajout_ok = false; |
|
| 328 | + include_spip('action/editer_liens'); |
|
| 329 | + foreach ($ajouter as $k => $v) { |
|
| 330 | + if ($lien = lien_verifier_action($k, $v)) { |
|
| 331 | + $ajout_ok = true; |
|
| 332 | + [$objet1, $ids, $objet2, $idl] = explode('-', $lien); |
|
| 333 | + $qualifs = lien_retrouver_qualif($objet_lien, $lien); |
|
| 334 | + if ($objet_lien == $objet1) { |
|
| 335 | + lien_ajouter_liaisons($objet1, $ids, $objet2, $idl, $qualifs); |
|
| 336 | + } else { |
|
| 337 | + lien_ajouter_liaisons($objet2, $idl, $objet1, $ids, $qualifs); |
|
| 338 | + } |
|
| 339 | + set_request('id_lien_ajoute', $ids); |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + # oups ne persiste que pour la derniere action, si suppression |
|
| 344 | + # une suppression suivie d'un ajout dans le meme hit est un remplacement |
|
| 345 | + # non annulable ! |
|
| 346 | + if ($ajout_ok) { |
|
| 347 | + set_request('_oups'); |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + if ($ordonner) { |
|
| 352 | + include_spip('action/editer_liens'); |
|
| 353 | + foreach ($ordonner as $k => $rang_lien) { |
|
| 354 | + if ($lien = lien_verifier_action($k, '')) { |
|
| 355 | + [$objet1, $ids, $objet2, $idl] = explode('-', $lien); |
|
| 356 | + $qualif = ['rang_lien' => $rang_lien]; |
|
| 357 | + |
|
| 358 | + if ($objet_lien == $objet1) { |
|
| 359 | + objet_qualifier_liens([$objet1 => $ids], [$objet2 => $idl], $qualif); |
|
| 360 | + } else { |
|
| 361 | + objet_qualifier_liens([$objet2 => $idl], [$objet1 => $ids], $qualif); |
|
| 362 | + } |
|
| 363 | + set_request('id_lien_ajoute', $ids); |
|
| 364 | + set_request('_oups'); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + return $res; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | |
@@ -391,24 +391,24 @@ discard block |
||
| 391 | 391 | * @return string Action demandée si trouvée, sinon '' |
| 392 | 392 | */ |
| 393 | 393 | function lien_verifier_action($k, $v) { |
| 394 | - $action = ''; |
|
| 395 | - if (preg_match(',^\w+-[\w*]+-[\w*]+-[\w*]+(-[\w*])?,', $k)) { |
|
| 396 | - $action = $k; |
|
| 397 | - } |
|
| 398 | - if (preg_match(',^\w+-[\w*]+-[\w*]+-[\w*]+(-[\w*])?,', $v)) { |
|
| 399 | - if (is_numeric($k)) { |
|
| 400 | - $action = $v; |
|
| 401 | - } |
|
| 402 | - if (_request($k)) { |
|
| 403 | - $action = $v; |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - // ajout un role null fictif (plus pratique) si pas défini |
|
| 407 | - if ($action and count(explode('-', $action)) == 4) { |
|
| 408 | - $action .= '-'; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - return $action; |
|
| 394 | + $action = ''; |
|
| 395 | + if (preg_match(',^\w+-[\w*]+-[\w*]+-[\w*]+(-[\w*])?,', $k)) { |
|
| 396 | + $action = $k; |
|
| 397 | + } |
|
| 398 | + if (preg_match(',^\w+-[\w*]+-[\w*]+-[\w*]+(-[\w*])?,', $v)) { |
|
| 399 | + if (is_numeric($k)) { |
|
| 400 | + $action = $v; |
|
| 401 | + } |
|
| 402 | + if (_request($k)) { |
|
| 403 | + $action = $v; |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + // ajout un role null fictif (plus pratique) si pas défini |
|
| 407 | + if ($action and count(explode('-', $action)) == 4) { |
|
| 408 | + $action .= '-'; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + return $action; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
@@ -424,66 +424,66 @@ discard block |
||
| 424 | 424 | * Liste des qualifs pour chaque lien. Tableau vide s'il n'y en a pas. |
| 425 | 425 | **/ |
| 426 | 426 | function lien_retrouver_qualif($objet_lien, $lien) { |
| 427 | - // un role est défini dans la liaison |
|
| 428 | - $defs = explode('-', $lien); |
|
| 429 | - [$objet1, , $objet2, , $role] = array_pad($defs, 5, null); |
|
| 430 | - if ($objet_lien == $objet1) { |
|
| 431 | - $colonne_role = roles_colonne($objet1, $objet2); |
|
| 432 | - } else { |
|
| 433 | - $colonne_role = roles_colonne($objet2, $objet1); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - // cas ou le role est defini en 5e argument de l'action sur le lien (suppression, ajout rapide sans autre attribut) |
|
| 437 | - if ($role) { |
|
| 438 | - return [ |
|
| 439 | - // un seul lien avec ce role |
|
| 440 | - [$colonne_role => $role] |
|
| 441 | - ]; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - // retrouver les rôles postés pour cette liaison, s'il y en a. |
|
| 445 | - $qualifier_lien = _request('qualifier_lien'); |
|
| 446 | - if (!$qualifier_lien or !is_array($qualifier_lien)) { |
|
| 447 | - return []; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - // pas avec l'action complete (incluant le role) |
|
| 451 | - $qualif = []; |
|
| 452 | - if ( |
|
| 453 | - (!isset($qualifier_lien[$lien]) or !$qualif = $qualifier_lien[$lien]) |
|
| 454 | - and count($defs) == 5 |
|
| 455 | - ) { |
|
| 456 | - // on tente avec l'action sans le role |
|
| 457 | - array_pop($defs); |
|
| 458 | - $lien = implode('-', $defs); |
|
| 459 | - if (!isset($qualifier_lien[$lien]) or !$qualif = $qualifier_lien[$lien]) { |
|
| 460 | - $qualif = []; |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - // $qualif de la forme array(role=>array(...),valeur=>array(...),....) |
|
| 465 | - // on le reforme en array(array(role=>..,valeur=>..,..),array(role=>..,valeur=>..,..),...) |
|
| 466 | - $qualifs = []; |
|
| 467 | - while (is_countable($qualif) ? count($qualif) : 0) { |
|
| 468 | - $q = []; |
|
| 469 | - foreach ($qualif as $att => $values) { |
|
| 470 | - if (is_array($values)) { |
|
| 471 | - $q[$att] = array_shift($qualif[$att]); |
|
| 472 | - if (!(is_countable($qualif[$att]) ? count($qualif[$att]) : 0)) { |
|
| 473 | - unset($qualif[$att]); |
|
| 474 | - } |
|
| 475 | - } else { |
|
| 476 | - $q[$att] = $values; |
|
| 477 | - unset($qualif[$att]); |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - // pas de rôle vide |
|
| 481 | - if (!$colonne_role or !isset($q[$colonne_role]) or $q[$colonne_role]) { |
|
| 482 | - $qualifs[] = $q; |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return $qualifs; |
|
| 427 | + // un role est défini dans la liaison |
|
| 428 | + $defs = explode('-', $lien); |
|
| 429 | + [$objet1, , $objet2, , $role] = array_pad($defs, 5, null); |
|
| 430 | + if ($objet_lien == $objet1) { |
|
| 431 | + $colonne_role = roles_colonne($objet1, $objet2); |
|
| 432 | + } else { |
|
| 433 | + $colonne_role = roles_colonne($objet2, $objet1); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + // cas ou le role est defini en 5e argument de l'action sur le lien (suppression, ajout rapide sans autre attribut) |
|
| 437 | + if ($role) { |
|
| 438 | + return [ |
|
| 439 | + // un seul lien avec ce role |
|
| 440 | + [$colonne_role => $role] |
|
| 441 | + ]; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + // retrouver les rôles postés pour cette liaison, s'il y en a. |
|
| 445 | + $qualifier_lien = _request('qualifier_lien'); |
|
| 446 | + if (!$qualifier_lien or !is_array($qualifier_lien)) { |
|
| 447 | + return []; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + // pas avec l'action complete (incluant le role) |
|
| 451 | + $qualif = []; |
|
| 452 | + if ( |
|
| 453 | + (!isset($qualifier_lien[$lien]) or !$qualif = $qualifier_lien[$lien]) |
|
| 454 | + and count($defs) == 5 |
|
| 455 | + ) { |
|
| 456 | + // on tente avec l'action sans le role |
|
| 457 | + array_pop($defs); |
|
| 458 | + $lien = implode('-', $defs); |
|
| 459 | + if (!isset($qualifier_lien[$lien]) or !$qualif = $qualifier_lien[$lien]) { |
|
| 460 | + $qualif = []; |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + // $qualif de la forme array(role=>array(...),valeur=>array(...),....) |
|
| 465 | + // on le reforme en array(array(role=>..,valeur=>..,..),array(role=>..,valeur=>..,..),...) |
|
| 466 | + $qualifs = []; |
|
| 467 | + while (is_countable($qualif) ? count($qualif) : 0) { |
|
| 468 | + $q = []; |
|
| 469 | + foreach ($qualif as $att => $values) { |
|
| 470 | + if (is_array($values)) { |
|
| 471 | + $q[$att] = array_shift($qualif[$att]); |
|
| 472 | + if (!(is_countable($qualif[$att]) ? count($qualif[$att]) : 0)) { |
|
| 473 | + unset($qualif[$att]); |
|
| 474 | + } |
|
| 475 | + } else { |
|
| 476 | + $q[$att] = $values; |
|
| 477 | + unset($qualif[$att]); |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + // pas de rôle vide |
|
| 481 | + if (!$colonne_role or !isset($q[$colonne_role]) or $q[$colonne_role]) { |
|
| 482 | + $qualifs[] = $q; |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return $qualifs; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -502,12 +502,12 @@ discard block |
||
| 502 | 502 | **/ |
| 503 | 503 | function lien_ajouter_liaisons($objet_source, $ids, $objet_lien, $idl, $qualifs) { |
| 504 | 504 | |
| 505 | - // retrouver la colonne de roles s'il y en a a lier |
|
| 506 | - if (is_array($qualifs) and count($qualifs)) { |
|
| 507 | - foreach ($qualifs as $qualif) { |
|
| 508 | - objet_associer([$objet_source => $ids], [$objet_lien => $idl], $qualif); |
|
| 509 | - } |
|
| 510 | - } else { |
|
| 511 | - objet_associer([$objet_source => $ids], [$objet_lien => $idl]); |
|
| 512 | - } |
|
| 505 | + // retrouver la colonne de roles s'il y en a a lier |
|
| 506 | + if (is_array($qualifs) and count($qualifs)) { |
|
| 507 | + foreach ($qualifs as $qualif) { |
|
| 508 | + objet_associer([$objet_source => $ids], [$objet_lien => $idl], $qualif); |
|
| 509 | + } |
|
| 510 | + } else { |
|
| 511 | + objet_associer([$objet_source => $ids], [$objet_lien => $idl]); |
|
| 512 | + } |
|
| 513 | 513 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | // L'éditabilité :) est définie par un test permanent (par exemple "associermots") ET le 4ème argument |
| 107 | 107 | include_spip('inc/autoriser'); |
| 108 | - $editable = ($editable and autoriser('associer' . $table_source, $objet, $id_objet) |
|
| 108 | + $editable = ($editable and autoriser('associer'.$table_source, $objet, $id_objet) |
|
| 109 | 109 | and autoriser('modifier', $objet, $id_objet)); |
| 110 | 110 | |
| 111 | 111 | if ( |
@@ -119,15 +119,15 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | // squelettes de vue et de d'association |
| 121 | 121 | // ils sont différents si des rôles sont définis. |
| 122 | - $skel_vue = $table_source . '_lies'; |
|
| 123 | - $skel_ajout = $table_source . '_associer'; |
|
| 122 | + $skel_vue = $table_source.'_lies'; |
|
| 123 | + $skel_ajout = $table_source.'_associer'; |
|
| 124 | 124 | |
| 125 | 125 | // description des roles |
| 126 | 126 | include_spip('inc/roles'); |
| 127 | 127 | if ($roles = roles_presents($objet_source, $objet)) { |
| 128 | 128 | // on demande de nouveaux squelettes en conséquence |
| 129 | - $skel_vue = $table_source . '_roles_lies'; |
|
| 130 | - $skel_ajout = $table_source . '_roles_associer'; |
|
| 129 | + $skel_vue = $table_source.'_roles_lies'; |
|
| 130 | + $skel_ajout = $table_source.'_roles_associer'; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | $oups = _request('_oups') ?? ''; |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | function lien_retrouver_qualif($objet_lien, $lien) { |
| 427 | 427 | // un role est défini dans la liaison |
| 428 | 428 | $defs = explode('-', $lien); |
| 429 | - [$objet1, , $objet2, , $role] = array_pad($defs, 5, null); |
|
| 429 | + [$objet1,, $objet2,, $role] = array_pad($defs, 5, null); |
|
| 430 | 430 | if ($objet_lien == $objet1) { |
| 431 | 431 | $colonne_role = roles_colonne($objet1, $objet2); |
| 432 | 432 | } else { |
@@ -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 | |
@@ -45,136 +45,136 @@ discard block |
||
| 45 | 45 | **/ |
| 46 | 46 | function formulaires_dater_charger_dist($objet, $id_objet, $retour = '', $options = []) { |
| 47 | 47 | |
| 48 | - $jour = null; |
|
| 49 | - $mois = null; |
|
| 50 | - $annee = null; |
|
| 51 | - $heure = null; |
|
| 52 | - $minute = null; |
|
| 53 | - $objet = objet_type($objet); |
|
| 54 | - if (!$objet or !intval($id_objet)) { |
|
| 55 | - return false; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if (!is_array($options)) { |
|
| 59 | - $options = unserialize($options); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - $_id_objet = id_table_objet($objet); |
|
| 63 | - $table = table_objet($objet); |
|
| 64 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | - $desc = $trouver_table($table); |
|
| 66 | - |
|
| 67 | - if (!$desc) { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $champ_date = $desc['date'] ?: 'date'; |
|
| 72 | - if (isset($options['champ_date']) and $options['champ_date']) { |
|
| 73 | - $champ_date = $options['champ_date']; |
|
| 74 | - } |
|
| 75 | - if (!isset($desc['field'][$champ_date])) { |
|
| 76 | - return false; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - $valeurs = [ |
|
| 80 | - 'objet' => $objet, |
|
| 81 | - 'id_objet' => $id_objet, |
|
| 82 | - 'id' => $id_objet, |
|
| 83 | - ]; |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - $select = "$champ_date as date"; |
|
| 87 | - $champ_date_redac = 'date_redac'; |
|
| 88 | - if (isset($options['champ_date_redac']) and $options['champ_date_redac']) { |
|
| 89 | - $champ_date_redac = $options['champ_date_redac']; |
|
| 90 | - } |
|
| 91 | - if (isset($desc['field'][$champ_date_redac])) { |
|
| 92 | - $select .= ",$champ_date_redac as date_redac"; |
|
| 93 | - } |
|
| 94 | - if (isset($desc['field']['statut'])) { |
|
| 95 | - $select .= ',statut'; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - $row = sql_fetsel($select, $desc['table'], "$_id_objet=" . intval($id_objet)); |
|
| 100 | - $statut = $row['statut'] ?? 'publie'; // pas de statut => publie |
|
| 101 | - |
|
| 102 | - $valeurs['editable'] = autoriser('dater', $objet, $id_objet, null, ['statut' => $statut]); |
|
| 103 | - |
|
| 104 | - $possedeDateRedac = false; |
|
| 105 | - |
|
| 106 | - if ( |
|
| 107 | - isset($row['date_redac']) and |
|
| 108 | - $regs = recup_date($row['date_redac'], false) |
|
| 109 | - ) { |
|
| 110 | - $annee_redac = $regs[0]; |
|
| 111 | - $mois_redac = $regs[1]; |
|
| 112 | - $jour_redac = $regs[2]; |
|
| 113 | - $heure_redac = $regs[3]; |
|
| 114 | - $minute_redac = $regs[4]; |
|
| 115 | - $possedeDateRedac = true; |
|
| 116 | - // attention : les vrai dates de l'annee 1 sont stockee avec +9000 => 9001 |
|
| 117 | - // mais reviennent ici en annee 1 par recup_date |
|
| 118 | - // on verifie donc que le intval($row['date_redac']) qui ressort l'annee |
|
| 119 | - // est bien lui aussi <=1 : dans ce cas c'est une date sql 'nulle' ou presque, selon |
|
| 120 | - // le gestionnnaire sql utilise (0001-01-01 pour PG par exemple) |
|
| 121 | - if (intval($row['date_redac']) <= 1 and ($annee_redac <= 1) and ($mois_redac <= 1) and ($jour_redac <= 1)) { |
|
| 122 | - $possedeDateRedac = false; |
|
| 123 | - } |
|
| 124 | - } else { |
|
| 125 | - $annee_redac = $mois_redac = $jour_redac = $heure_redac = $minute_redac = 0; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if ($regs = recup_date($row['date'], false)) { |
|
| 129 | - $annee = $regs[0]; |
|
| 130 | - $mois = $regs[1]; |
|
| 131 | - $jour = $regs[2]; |
|
| 132 | - $heure = $regs[3]; |
|
| 133 | - $minute = $regs[4]; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // attention, si la variable s'appelle date ou date_redac, le compilo va |
|
| 137 | - // la normaliser, ce qu'on ne veut pas ici. |
|
| 138 | - $valeurs['afficher_date_redac'] = ($possedeDateRedac ? $row['date_redac'] : ''); |
|
| 139 | - $valeurs['date_redac_jour'] = dater_formater_saisie_jour($jour_redac, $mois_redac, $annee_redac); |
|
| 140 | - $valeurs['date_redac_heure'] = "$heure_redac:$minute_redac"; |
|
| 141 | - |
|
| 142 | - $valeurs['afficher_date'] = $row['date']; |
|
| 143 | - $valeurs['date_jour'] = dater_formater_saisie_jour($jour, $mois, $annee); |
|
| 144 | - $valeurs['date_heure'] = "$heure:$minute"; |
|
| 145 | - |
|
| 146 | - $valeurs['sans_redac'] = !$possedeDateRedac; |
|
| 147 | - |
|
| 148 | - if (isset($options['date_redac'])) { |
|
| 149 | - $valeurs['_editer_date_anterieure'] = $options['date_redac']; |
|
| 150 | - } else { |
|
| 151 | - $valeurs['_editer_date_anterieure'] = ($objet == 'article' and ($GLOBALS['meta']['articles_redac'] != 'non' or $possedeDateRedac)); |
|
| 152 | - } |
|
| 153 | - $valeurs['_label_date'] = (($statut == 'publie') ? |
|
| 154 | - _T('texte_date_publication_objet') : _T('texte_date_creation_objet')); |
|
| 155 | - if (isset($options['label_date']) and $options['label_date']) { |
|
| 156 | - $valeurs['_label_date'] = $options['label_date']; |
|
| 157 | - } |
|
| 158 | - if (isset($options['label_date_redac']) and $options['label_date_redac']) { |
|
| 159 | - $valeurs['_label_date_redac'] = $options['label_date_redac']; |
|
| 160 | - } |
|
| 161 | - if (isset($options['texte_sans_date_redac']) and $options['texte_sans_date_redac']) { |
|
| 162 | - $valeurs['_texte_sans_date_redac'] = $options['texte_sans_date_redac']; |
|
| 163 | - } |
|
| 164 | - if (isset($options['class']) and $options['class']) { |
|
| 165 | - $valeurs['_class'] = $options['class']; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - $valeurs['_saisie_en_cours'] = (_request('_saisie_en_cours') !== null or _request('date_jour') !== null); |
|
| 169 | - |
|
| 170 | - // cas ou l'on ne peut pas dater mais on peut modifier la date de redac anterieure |
|
| 171 | - // https://core.spip.net/issues/3494 |
|
| 172 | - $valeurs['_editer_date'] = $valeurs['editable']; |
|
| 173 | - if ($valeurs['_editer_date_anterieure'] and !$valeurs['editable']) { |
|
| 174 | - $valeurs['editable'] = autoriser('modifier', $objet, $id_objet); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $valeurs; |
|
| 48 | + $jour = null; |
|
| 49 | + $mois = null; |
|
| 50 | + $annee = null; |
|
| 51 | + $heure = null; |
|
| 52 | + $minute = null; |
|
| 53 | + $objet = objet_type($objet); |
|
| 54 | + if (!$objet or !intval($id_objet)) { |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if (!is_array($options)) { |
|
| 59 | + $options = unserialize($options); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + $_id_objet = id_table_objet($objet); |
|
| 63 | + $table = table_objet($objet); |
|
| 64 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | + $desc = $trouver_table($table); |
|
| 66 | + |
|
| 67 | + if (!$desc) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $champ_date = $desc['date'] ?: 'date'; |
|
| 72 | + if (isset($options['champ_date']) and $options['champ_date']) { |
|
| 73 | + $champ_date = $options['champ_date']; |
|
| 74 | + } |
|
| 75 | + if (!isset($desc['field'][$champ_date])) { |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + $valeurs = [ |
|
| 80 | + 'objet' => $objet, |
|
| 81 | + 'id_objet' => $id_objet, |
|
| 82 | + 'id' => $id_objet, |
|
| 83 | + ]; |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + $select = "$champ_date as date"; |
|
| 87 | + $champ_date_redac = 'date_redac'; |
|
| 88 | + if (isset($options['champ_date_redac']) and $options['champ_date_redac']) { |
|
| 89 | + $champ_date_redac = $options['champ_date_redac']; |
|
| 90 | + } |
|
| 91 | + if (isset($desc['field'][$champ_date_redac])) { |
|
| 92 | + $select .= ",$champ_date_redac as date_redac"; |
|
| 93 | + } |
|
| 94 | + if (isset($desc['field']['statut'])) { |
|
| 95 | + $select .= ',statut'; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + $row = sql_fetsel($select, $desc['table'], "$_id_objet=" . intval($id_objet)); |
|
| 100 | + $statut = $row['statut'] ?? 'publie'; // pas de statut => publie |
|
| 101 | + |
|
| 102 | + $valeurs['editable'] = autoriser('dater', $objet, $id_objet, null, ['statut' => $statut]); |
|
| 103 | + |
|
| 104 | + $possedeDateRedac = false; |
|
| 105 | + |
|
| 106 | + if ( |
|
| 107 | + isset($row['date_redac']) and |
|
| 108 | + $regs = recup_date($row['date_redac'], false) |
|
| 109 | + ) { |
|
| 110 | + $annee_redac = $regs[0]; |
|
| 111 | + $mois_redac = $regs[1]; |
|
| 112 | + $jour_redac = $regs[2]; |
|
| 113 | + $heure_redac = $regs[3]; |
|
| 114 | + $minute_redac = $regs[4]; |
|
| 115 | + $possedeDateRedac = true; |
|
| 116 | + // attention : les vrai dates de l'annee 1 sont stockee avec +9000 => 9001 |
|
| 117 | + // mais reviennent ici en annee 1 par recup_date |
|
| 118 | + // on verifie donc que le intval($row['date_redac']) qui ressort l'annee |
|
| 119 | + // est bien lui aussi <=1 : dans ce cas c'est une date sql 'nulle' ou presque, selon |
|
| 120 | + // le gestionnnaire sql utilise (0001-01-01 pour PG par exemple) |
|
| 121 | + if (intval($row['date_redac']) <= 1 and ($annee_redac <= 1) and ($mois_redac <= 1) and ($jour_redac <= 1)) { |
|
| 122 | + $possedeDateRedac = false; |
|
| 123 | + } |
|
| 124 | + } else { |
|
| 125 | + $annee_redac = $mois_redac = $jour_redac = $heure_redac = $minute_redac = 0; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if ($regs = recup_date($row['date'], false)) { |
|
| 129 | + $annee = $regs[0]; |
|
| 130 | + $mois = $regs[1]; |
|
| 131 | + $jour = $regs[2]; |
|
| 132 | + $heure = $regs[3]; |
|
| 133 | + $minute = $regs[4]; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // attention, si la variable s'appelle date ou date_redac, le compilo va |
|
| 137 | + // la normaliser, ce qu'on ne veut pas ici. |
|
| 138 | + $valeurs['afficher_date_redac'] = ($possedeDateRedac ? $row['date_redac'] : ''); |
|
| 139 | + $valeurs['date_redac_jour'] = dater_formater_saisie_jour($jour_redac, $mois_redac, $annee_redac); |
|
| 140 | + $valeurs['date_redac_heure'] = "$heure_redac:$minute_redac"; |
|
| 141 | + |
|
| 142 | + $valeurs['afficher_date'] = $row['date']; |
|
| 143 | + $valeurs['date_jour'] = dater_formater_saisie_jour($jour, $mois, $annee); |
|
| 144 | + $valeurs['date_heure'] = "$heure:$minute"; |
|
| 145 | + |
|
| 146 | + $valeurs['sans_redac'] = !$possedeDateRedac; |
|
| 147 | + |
|
| 148 | + if (isset($options['date_redac'])) { |
|
| 149 | + $valeurs['_editer_date_anterieure'] = $options['date_redac']; |
|
| 150 | + } else { |
|
| 151 | + $valeurs['_editer_date_anterieure'] = ($objet == 'article' and ($GLOBALS['meta']['articles_redac'] != 'non' or $possedeDateRedac)); |
|
| 152 | + } |
|
| 153 | + $valeurs['_label_date'] = (($statut == 'publie') ? |
|
| 154 | + _T('texte_date_publication_objet') : _T('texte_date_creation_objet')); |
|
| 155 | + if (isset($options['label_date']) and $options['label_date']) { |
|
| 156 | + $valeurs['_label_date'] = $options['label_date']; |
|
| 157 | + } |
|
| 158 | + if (isset($options['label_date_redac']) and $options['label_date_redac']) { |
|
| 159 | + $valeurs['_label_date_redac'] = $options['label_date_redac']; |
|
| 160 | + } |
|
| 161 | + if (isset($options['texte_sans_date_redac']) and $options['texte_sans_date_redac']) { |
|
| 162 | + $valeurs['_texte_sans_date_redac'] = $options['texte_sans_date_redac']; |
|
| 163 | + } |
|
| 164 | + if (isset($options['class']) and $options['class']) { |
|
| 165 | + $valeurs['_class'] = $options['class']; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + $valeurs['_saisie_en_cours'] = (_request('_saisie_en_cours') !== null or _request('date_jour') !== null); |
|
| 169 | + |
|
| 170 | + // cas ou l'on ne peut pas dater mais on peut modifier la date de redac anterieure |
|
| 171 | + // https://core.spip.net/issues/3494 |
|
| 172 | + $valeurs['_editer_date'] = $valeurs['editable']; |
|
| 173 | + if ($valeurs['_editer_date_anterieure'] and !$valeurs['editable']) { |
|
| 174 | + $valeurs['editable'] = autoriser('modifier', $objet, $id_objet); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $valeurs; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -192,20 +192,20 @@ discard block |
||
| 192 | 192 | * Date formatée tel que `02/10/2012` |
| 193 | 193 | **/ |
| 194 | 194 | function dater_formater_saisie_jour($jour, $mois, $annee, $sep = '/') { |
| 195 | - $annee = str_pad($annee, 4, '0', STR_PAD_LEFT); |
|
| 196 | - if (intval($jour)) { |
|
| 197 | - $jour = str_pad($jour, 2, '0', STR_PAD_LEFT); |
|
| 198 | - $mois = str_pad($mois, 2, '0', STR_PAD_LEFT); |
|
| 195 | + $annee = str_pad($annee, 4, '0', STR_PAD_LEFT); |
|
| 196 | + if (intval($jour)) { |
|
| 197 | + $jour = str_pad($jour, 2, '0', STR_PAD_LEFT); |
|
| 198 | + $mois = str_pad($mois, 2, '0', STR_PAD_LEFT); |
|
| 199 | 199 | |
| 200 | - return "$jour$sep$mois$sep$annee"; |
|
| 201 | - } |
|
| 202 | - if (intval($mois)) { |
|
| 203 | - $mois = str_pad($mois, 2, '0', STR_PAD_LEFT); |
|
| 200 | + return "$jour$sep$mois$sep$annee"; |
|
| 201 | + } |
|
| 202 | + if (intval($mois)) { |
|
| 203 | + $mois = str_pad($mois, 2, '0', STR_PAD_LEFT); |
|
| 204 | 204 | |
| 205 | - return "$mois$sep$annee"; |
|
| 206 | - } |
|
| 205 | + return "$mois$sep$annee"; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - return $annee; |
|
| 208 | + return $annee; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * Hash du formulaire |
| 225 | 225 | **/ |
| 226 | 226 | function formulaires_dater_identifier_dist($objet, $id_objet, $retour = '', $options = []) { |
| 227 | - return serialize([$objet, $id_objet]); |
|
| 227 | + return serialize([$objet, $id_objet]); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -242,30 +242,30 @@ discard block |
||
| 242 | 242 | * Tableau des erreurs |
| 243 | 243 | */ |
| 244 | 244 | function formulaires_dater_verifier_dist($objet, $id_objet, $retour = '', $options = []) { |
| 245 | - $erreurs = []; |
|
| 246 | - |
|
| 247 | - // ouvrir le formulaire en edition ? |
|
| 248 | - if (_request('_saisie_en_cours')) { |
|
| 249 | - $erreurs['message_erreur'] = ''; |
|
| 250 | - |
|
| 251 | - return $erreurs; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - if (_request('changer')) { |
|
| 255 | - foreach (['date', 'date_redac'] as $k) { |
|
| 256 | - if ($v = _request($k . '_jour') and !dater_recuperer_date_saisie($v, $k)) { |
|
| 257 | - $erreurs[$k] = _T('format_date_incorrecte'); |
|
| 258 | - } elseif ($v = _request($k . '_heure') and !dater_recuperer_heure_saisie($v)) { |
|
| 259 | - $erreurs[$k] = _T('format_heure_incorrecte'); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if (!_request('date_jour')) { |
|
| 264 | - $erreurs['date'] = _T('info_obligatoire'); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - return $erreurs; |
|
| 245 | + $erreurs = []; |
|
| 246 | + |
|
| 247 | + // ouvrir le formulaire en edition ? |
|
| 248 | + if (_request('_saisie_en_cours')) { |
|
| 249 | + $erreurs['message_erreur'] = ''; |
|
| 250 | + |
|
| 251 | + return $erreurs; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + if (_request('changer')) { |
|
| 255 | + foreach (['date', 'date_redac'] as $k) { |
|
| 256 | + if ($v = _request($k . '_jour') and !dater_recuperer_date_saisie($v, $k)) { |
|
| 257 | + $erreurs[$k] = _T('format_date_incorrecte'); |
|
| 258 | + } elseif ($v = _request($k . '_heure') and !dater_recuperer_heure_saisie($v)) { |
|
| 259 | + $erreurs[$k] = _T('format_heure_incorrecte'); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if (!_request('date_jour')) { |
|
| 264 | + $erreurs['date'] = _T('info_obligatoire'); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + return $erreurs; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -283,79 +283,79 @@ discard block |
||
| 283 | 283 | * Retours des traitements |
| 284 | 284 | */ |
| 285 | 285 | function formulaires_dater_traiter_dist($objet, $id_objet, $retour = '', $options = []) { |
| 286 | - $res = ['editable' => ' ']; |
|
| 287 | - |
|
| 288 | - if (_request('changer')) { |
|
| 289 | - $table = table_objet($objet); |
|
| 290 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 291 | - $desc = $trouver_table($table); |
|
| 292 | - |
|
| 293 | - if (!$desc) { |
|
| 294 | - return ['message_erreur' => _L('erreur')]; |
|
| 295 | - } #impossible en principe |
|
| 296 | - |
|
| 297 | - $champ_date = $desc['date'] ?: 'date'; |
|
| 298 | - if (isset($options['champ_date']) and $options['champ_date']) { |
|
| 299 | - $champ_date = $options['champ_date']; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $set = []; |
|
| 303 | - |
|
| 304 | - $charger = charger_fonction('charger', 'formulaires/dater/'); |
|
| 305 | - $v = $charger($objet, $id_objet, $retour, $options); |
|
| 306 | - |
|
| 307 | - if ($v['_editer_date']) { |
|
| 308 | - if (!$d = dater_recuperer_date_saisie(_request('date_jour'))) { |
|
| 309 | - $d = [date('Y'), date('m'), date('d')]; |
|
| 310 | - } |
|
| 311 | - if (!$h = dater_recuperer_heure_saisie(_request('date_heure'))) { |
|
| 312 | - $h = [0, 0]; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $set[$champ_date] = sql_format_date($d[0], $d[1], $d[2], $h[0], $h[1]); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $champ_date_redac = 'date_redac'; |
|
| 319 | - if (isset($options['champ_date_redac']) and $options['champ_date_redac']) { |
|
| 320 | - $champ_date_redac = $options['champ_date_redac']; |
|
| 321 | - } |
|
| 322 | - if (isset($desc['field'][$champ_date_redac]) and $v['_editer_date_anterieure']) { |
|
| 323 | - if (!_request('date_redac_jour') or _request('sans_redac')) { |
|
| 324 | - $set[$champ_date_redac] = sql_format_date(0, 0, 0, 0, 0, 0); |
|
| 325 | - } else { |
|
| 326 | - if (!$d = dater_recuperer_date_saisie(_request('date_redac_jour'), 'date_redac')) { |
|
| 327 | - $d = [date('Y'), date('m'), date('d')]; |
|
| 328 | - } |
|
| 329 | - if (!$h = dater_recuperer_heure_saisie(_request('date_redac_heure'))) { |
|
| 330 | - $h = [0, 0]; |
|
| 331 | - } |
|
| 332 | - $set[$champ_date_redac] = sql_format_date($d[0], $d[1], $d[2], $h[0], $h[1]); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - if (count($set)) { |
|
| 337 | - $publie_avant = objet_test_si_publie($objet, $id_objet); |
|
| 338 | - include_spip('action/editer_objet'); |
|
| 339 | - objet_modifier($objet, $id_objet, $set); |
|
| 340 | - $publie_apres = objet_test_si_publie($objet, $id_objet); |
|
| 341 | - if ($publie_avant !== $publie_apres) { |
|
| 342 | - // on refuse ajax pour forcer le rechargement de la page ici |
|
| 343 | - // on refera traiter une 2eme fois, mais c'est sans consequence |
|
| 344 | - refuser_traiter_formulaire_ajax(); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if ($retour) { |
|
| 350 | - $res['redirect'] = $retour; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - set_request('date_jour'); |
|
| 354 | - set_request('date_redac_jour'); |
|
| 355 | - set_request('date_heure'); |
|
| 356 | - set_request('date_redac_heure'); |
|
| 357 | - |
|
| 358 | - return $res; |
|
| 286 | + $res = ['editable' => ' ']; |
|
| 287 | + |
|
| 288 | + if (_request('changer')) { |
|
| 289 | + $table = table_objet($objet); |
|
| 290 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 291 | + $desc = $trouver_table($table); |
|
| 292 | + |
|
| 293 | + if (!$desc) { |
|
| 294 | + return ['message_erreur' => _L('erreur')]; |
|
| 295 | + } #impossible en principe |
|
| 296 | + |
|
| 297 | + $champ_date = $desc['date'] ?: 'date'; |
|
| 298 | + if (isset($options['champ_date']) and $options['champ_date']) { |
|
| 299 | + $champ_date = $options['champ_date']; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $set = []; |
|
| 303 | + |
|
| 304 | + $charger = charger_fonction('charger', 'formulaires/dater/'); |
|
| 305 | + $v = $charger($objet, $id_objet, $retour, $options); |
|
| 306 | + |
|
| 307 | + if ($v['_editer_date']) { |
|
| 308 | + if (!$d = dater_recuperer_date_saisie(_request('date_jour'))) { |
|
| 309 | + $d = [date('Y'), date('m'), date('d')]; |
|
| 310 | + } |
|
| 311 | + if (!$h = dater_recuperer_heure_saisie(_request('date_heure'))) { |
|
| 312 | + $h = [0, 0]; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $set[$champ_date] = sql_format_date($d[0], $d[1], $d[2], $h[0], $h[1]); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $champ_date_redac = 'date_redac'; |
|
| 319 | + if (isset($options['champ_date_redac']) and $options['champ_date_redac']) { |
|
| 320 | + $champ_date_redac = $options['champ_date_redac']; |
|
| 321 | + } |
|
| 322 | + if (isset($desc['field'][$champ_date_redac]) and $v['_editer_date_anterieure']) { |
|
| 323 | + if (!_request('date_redac_jour') or _request('sans_redac')) { |
|
| 324 | + $set[$champ_date_redac] = sql_format_date(0, 0, 0, 0, 0, 0); |
|
| 325 | + } else { |
|
| 326 | + if (!$d = dater_recuperer_date_saisie(_request('date_redac_jour'), 'date_redac')) { |
|
| 327 | + $d = [date('Y'), date('m'), date('d')]; |
|
| 328 | + } |
|
| 329 | + if (!$h = dater_recuperer_heure_saisie(_request('date_redac_heure'))) { |
|
| 330 | + $h = [0, 0]; |
|
| 331 | + } |
|
| 332 | + $set[$champ_date_redac] = sql_format_date($d[0], $d[1], $d[2], $h[0], $h[1]); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + if (count($set)) { |
|
| 337 | + $publie_avant = objet_test_si_publie($objet, $id_objet); |
|
| 338 | + include_spip('action/editer_objet'); |
|
| 339 | + objet_modifier($objet, $id_objet, $set); |
|
| 340 | + $publie_apres = objet_test_si_publie($objet, $id_objet); |
|
| 341 | + if ($publie_avant !== $publie_apres) { |
|
| 342 | + // on refuse ajax pour forcer le rechargement de la page ici |
|
| 343 | + // on refera traiter une 2eme fois, mais c'est sans consequence |
|
| 344 | + refuser_traiter_formulaire_ajax(); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if ($retour) { |
|
| 350 | + $res['redirect'] = $retour; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + set_request('date_jour'); |
|
| 354 | + set_request('date_redac_jour'); |
|
| 355 | + set_request('date_heure'); |
|
| 356 | + set_request('date_redac_heure'); |
|
| 357 | + |
|
| 358 | + return $res; |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
@@ -366,24 +366,24 @@ discard block |
||
| 366 | 366 | * @return array|string Chaîne vide si date invalide, tableau (année, mois, jour) sinon. |
| 367 | 367 | */ |
| 368 | 368 | function dater_recuperer_date_saisie($post, $quoi = 'date') { |
| 369 | - if (!preg_match('#^(?:(?:([0-9]{1,2})[/-])?([0-9]{1,2})[/-])?([0-9]{4}|[0-9]{1,2})#', $post, $regs)) { |
|
| 370 | - return ''; |
|
| 371 | - } |
|
| 372 | - if ($quoi == 'date_redac') { |
|
| 373 | - if ($regs[3] <> '' and $regs[3] < 1001) { |
|
| 374 | - $regs[3] += 9000; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - return [$regs[3], $regs[2], $regs[1]]; |
|
| 378 | - } else { |
|
| 379 | - if ( |
|
| 380 | - checkdate(intval($regs[2]), intval($regs[1]), intval($regs[3])) |
|
| 381 | - and $t = mktime(0, 0, 0, $regs[2], $regs[1], $regs[3]) |
|
| 382 | - ) { |
|
| 383 | - return [date('Y', $t), date('m', $t), date('d', $t)]; |
|
| 384 | - } |
|
| 385 | - return ''; |
|
| 386 | - } |
|
| 369 | + if (!preg_match('#^(?:(?:([0-9]{1,2})[/-])?([0-9]{1,2})[/-])?([0-9]{4}|[0-9]{1,2})#', $post, $regs)) { |
|
| 370 | + return ''; |
|
| 371 | + } |
|
| 372 | + if ($quoi == 'date_redac') { |
|
| 373 | + if ($regs[3] <> '' and $regs[3] < 1001) { |
|
| 374 | + $regs[3] += 9000; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + return [$regs[3], $regs[2], $regs[1]]; |
|
| 378 | + } else { |
|
| 379 | + if ( |
|
| 380 | + checkdate(intval($regs[2]), intval($regs[1]), intval($regs[3])) |
|
| 381 | + and $t = mktime(0, 0, 0, $regs[2], $regs[1], $regs[3]) |
|
| 382 | + ) { |
|
| 383 | + return [date('Y', $t), date('m', $t), date('d', $t)]; |
|
| 384 | + } |
|
| 385 | + return ''; |
|
| 386 | + } |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -393,12 +393,12 @@ discard block |
||
| 393 | 393 | * @return array |
| 394 | 394 | */ |
| 395 | 395 | function dater_recuperer_heure_saisie($post) { |
| 396 | - if (!preg_match('#([0-9]{1,2})(?:[h:](?:([0-9]{1,2}))?)?#', $post, $regs)) { |
|
| 397 | - return ''; |
|
| 398 | - } |
|
| 399 | - if ($regs[1] > 23 or $regs[2] > 59) { |
|
| 400 | - return ''; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - return [$regs[1], $regs[2]]; |
|
| 396 | + if (!preg_match('#([0-9]{1,2})(?:[h:](?:([0-9]{1,2}))?)?#', $post, $regs)) { |
|
| 397 | + return ''; |
|
| 398 | + } |
|
| 399 | + if ($regs[1] > 23 or $regs[2] > 59) { |
|
| 400 | + return ''; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + return [$regs[1], $regs[2]]; |
|
| 404 | 404 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
| 99 | - $row = sql_fetsel($select, $desc['table'], "$_id_objet=" . intval($id_objet)); |
|
| 99 | + $row = sql_fetsel($select, $desc['table'], "$_id_objet=".intval($id_objet)); |
|
| 100 | 100 | $statut = $row['statut'] ?? 'publie'; // pas de statut => publie |
| 101 | 101 | |
| 102 | 102 | $valeurs['editable'] = autoriser('dater', $objet, $id_objet, null, ['statut' => $statut]); |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | if (_request('changer')) { |
| 255 | 255 | foreach (['date', 'date_redac'] as $k) { |
| 256 | - if ($v = _request($k . '_jour') and !dater_recuperer_date_saisie($v, $k)) { |
|
| 256 | + if ($v = _request($k.'_jour') and !dater_recuperer_date_saisie($v, $k)) { |
|
| 257 | 257 | $erreurs[$k] = _T('format_date_incorrecte'); |
| 258 | - } elseif ($v = _request($k . '_heure') and !dater_recuperer_heure_saisie($v)) { |
|
| 258 | + } elseif ($v = _request($k.'_heure') and !dater_recuperer_heure_saisie($v)) { |
|
| 259 | 259 | $erreurs[$k] = _T('format_heure_incorrecte'); |
| 260 | 260 | } |
| 261 | 261 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | // si id numerique et un seul objet possible, pas d'ambiguite |
| 160 | 160 | if (is_numeric($ref) and count($objets) === 1) { |
| 161 | - $ref = reset($objets) . $ref; |
|
| 161 | + $ref = reset($objets).$ref; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // Si la référence ne correspond à rien, c'est fini |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | return json_export(false); |
| 167 | 167 | } |
| 168 | 168 | // Sinon on récupère les infos utiles |
| 169 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 169 | + [$type,, $id,,,,] = array_pad($match, 7, null); |
|
| 170 | 170 | |
| 171 | 171 | // On regarde si le type trouvé fait partie des objets sélectionnables |
| 172 | 172 | if (!in_array(table_objet($type), $objets)) { |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | $types = (is_array($types) ? array_filter($types) : []); |
| 212 | 212 | |
| 213 | 213 | // recuperer tous les freres et soeurs de la rubrique visee |
| 214 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 215 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . intval($id_parent)); |
|
| 214 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique)); |
|
| 215 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent='.intval($id_parent)); |
|
| 216 | 216 | $fratrie = array_column($fratrie, 'id_rubrique'); |
| 217 | 217 | $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
| 218 | 218 | $has = array_column($has, 'id_parent'); |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | **/ |
| 8 | 8 | |
| 9 | 9 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 10 | - return; |
|
| 10 | + return; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -28,51 +28,51 @@ discard block |
||
| 28 | 28 | * - afficher : tableau des objets à afficher (mais pas forcément sélectionnables) |
| 29 | 29 | */ |
| 30 | 30 | function selecteur_lister_objets($includelist = [], $excludelist = []) { |
| 31 | - static $liste_selecteurs, $liste_parents; |
|
| 32 | - |
|
| 33 | - if (!$liste_selecteurs) { |
|
| 34 | - $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | - } |
|
| 36 | - $objets_selectionner = []; |
|
| 37 | - foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | - $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', $fichier); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | - if (!empty($includelist)) { |
|
| 43 | - $includelist = array_map('table_objet', $includelist); |
|
| 44 | - $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | - } |
|
| 46 | - // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | - $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | - // On enlève toujours la racine |
|
| 49 | - $excludelist[] = 'racine'; |
|
| 50 | - $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | - |
|
| 52 | - // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | - $objets_afficher = $objets_selectionner; |
|
| 54 | - |
|
| 55 | - // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | - // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | - if (!$liste_parents) { |
|
| 58 | - $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | - } |
|
| 60 | - foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | - preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', $fichier, $captures); |
|
| 62 | - $parent = $captures[1]; |
|
| 63 | - $type = $captures[2]; |
|
| 64 | - // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | - if (in_array($type, $objets_afficher)) { |
|
| 66 | - $objets_afficher[] = $parent; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $objets = [ |
|
| 71 | - 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | - 'afficher' => array_unique($objets_afficher), |
|
| 73 | - ]; |
|
| 74 | - |
|
| 75 | - return $objets; |
|
| 31 | + static $liste_selecteurs, $liste_parents; |
|
| 32 | + |
|
| 33 | + if (!$liste_selecteurs) { |
|
| 34 | + $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | + } |
|
| 36 | + $objets_selectionner = []; |
|
| 37 | + foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | + $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', $fichier); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | + if (!empty($includelist)) { |
|
| 43 | + $includelist = array_map('table_objet', $includelist); |
|
| 44 | + $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | + } |
|
| 46 | + // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | + $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | + // On enlève toujours la racine |
|
| 49 | + $excludelist[] = 'racine'; |
|
| 50 | + $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | + |
|
| 52 | + // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | + $objets_afficher = $objets_selectionner; |
|
| 54 | + |
|
| 55 | + // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | + // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | + if (!$liste_parents) { |
|
| 58 | + $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | + } |
|
| 60 | + foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | + preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', $fichier, $captures); |
|
| 62 | + $parent = $captures[1]; |
|
| 63 | + $type = $captures[2]; |
|
| 64 | + // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | + if (in_array($type, $objets_afficher)) { |
|
| 66 | + $objets_afficher[] = $parent; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $objets = [ |
|
| 71 | + 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | + 'afficher' => array_unique($objets_afficher), |
|
| 73 | + ]; |
|
| 74 | + |
|
| 75 | + return $objets; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -99,31 +99,31 @@ discard block |
||
| 99 | 99 | * liste des couples (objets => id_objet) ou liste des identifiants d'un type d'objet. |
| 100 | 100 | **/ |
| 101 | 101 | function picker_selected($selected, $type = '') { |
| 102 | - $select = []; |
|
| 103 | - $type = preg_replace(',\W,', '', $type); |
|
| 104 | - |
|
| 105 | - if ($selected and !is_array($selected)) { |
|
| 106 | - $selected = explode(',', $selected); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if (is_array($selected)) { |
|
| 110 | - foreach ($selected as $value) { |
|
| 111 | - // Si c'est le bon format déjà |
|
| 112 | - if (preg_match('/^([\w]+)[|]([0-9]+)$/', $value, $captures)) { |
|
| 113 | - $objet = $captures[1]; |
|
| 114 | - $id_objet = intval($captures[2]); |
|
| 115 | - |
|
| 116 | - // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 117 | - if (is_string($type) and $type == $objet and ($id_objet or in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | - $select[] = $id_objet; |
|
| 119 | - } elseif (!$type and ($id_objet or in_array($objet, ['racine', 'rubrique']))) { |
|
| 120 | - $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return $select; |
|
| 102 | + $select = []; |
|
| 103 | + $type = preg_replace(',\W,', '', $type); |
|
| 104 | + |
|
| 105 | + if ($selected and !is_array($selected)) { |
|
| 106 | + $selected = explode(',', $selected); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if (is_array($selected)) { |
|
| 110 | + foreach ($selected as $value) { |
|
| 111 | + // Si c'est le bon format déjà |
|
| 112 | + if (preg_match('/^([\w]+)[|]([0-9]+)$/', $value, $captures)) { |
|
| 113 | + $objet = $captures[1]; |
|
| 114 | + $id_objet = intval($captures[2]); |
|
| 115 | + |
|
| 116 | + // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 117 | + if (is_string($type) and $type == $objet and ($id_objet or in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | + $select[] = $id_objet; |
|
| 119 | + } elseif (!$type and ($id_objet or in_array($objet, ['racine', 'rubrique']))) { |
|
| 120 | + $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return $select; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -140,49 +140,49 @@ discard block |
||
| 140 | 140 | * Booléen indiquant si les articles sont sélectionnables |
| 141 | 141 | */ |
| 142 | 142 | function picker_identifie_id_rapide($ref, $rubriques_ou_objets = false, $articles = false) { |
| 143 | - include_spip('inc/json'); |
|
| 144 | - include_spip('inc/lien'); |
|
| 145 | - |
|
| 146 | - // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 147 | - $objets = []; |
|
| 148 | - if ($rubriques_ou_objets and is_array($rubriques_ou_objets)) { |
|
| 149 | - $objets = $rubriques_ou_objets; |
|
| 150 | - } else { |
|
| 151 | - if ($rubriques_ou_objets) { |
|
| 152 | - $objets[] = 'rubriques'; |
|
| 153 | - } |
|
| 154 | - if ($articles) { |
|
| 155 | - $objets[] = 'articles'; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 160 | - if (is_numeric($ref) and count($objets) === 1) { |
|
| 161 | - $ref = reset($objets) . $ref; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - // Si la référence ne correspond à rien, c'est fini |
|
| 165 | - if (!($match = typer_raccourci($ref))) { |
|
| 166 | - return json_export(false); |
|
| 167 | - } |
|
| 168 | - // Sinon on récupère les infos utiles |
|
| 169 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 170 | - |
|
| 171 | - // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 172 | - if (!in_array(table_objet($type), $objets)) { |
|
| 173 | - return json_export(false); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 177 | - include_spip('inc/filtres'); |
|
| 178 | - if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 179 | - return json_export(false); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - // On simplifie le texte |
|
| 183 | - $titre = attribut_html($titre); |
|
| 184 | - |
|
| 185 | - return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 143 | + include_spip('inc/json'); |
|
| 144 | + include_spip('inc/lien'); |
|
| 145 | + |
|
| 146 | + // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 147 | + $objets = []; |
|
| 148 | + if ($rubriques_ou_objets and is_array($rubriques_ou_objets)) { |
|
| 149 | + $objets = $rubriques_ou_objets; |
|
| 150 | + } else { |
|
| 151 | + if ($rubriques_ou_objets) { |
|
| 152 | + $objets[] = 'rubriques'; |
|
| 153 | + } |
|
| 154 | + if ($articles) { |
|
| 155 | + $objets[] = 'articles'; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 160 | + if (is_numeric($ref) and count($objets) === 1) { |
|
| 161 | + $ref = reset($objets) . $ref; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + // Si la référence ne correspond à rien, c'est fini |
|
| 165 | + if (!($match = typer_raccourci($ref))) { |
|
| 166 | + return json_export(false); |
|
| 167 | + } |
|
| 168 | + // Sinon on récupère les infos utiles |
|
| 169 | + [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 170 | + |
|
| 171 | + // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 172 | + if (!in_array(table_objet($type), $objets)) { |
|
| 173 | + return json_export(false); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 177 | + include_spip('inc/filtres'); |
|
| 178 | + if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 179 | + return json_export(false); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + // On simplifie le texte |
|
| 183 | + $titre = attribut_html($titre); |
|
| 184 | + |
|
| 185 | + return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -205,34 +205,34 @@ discard block |
||
| 205 | 205 | * Comme le filtre `oui` : espace (` `) si rubrique à afficher, chaîne vide sinon. |
| 206 | 206 | */ |
| 207 | 207 | function test_enfants_rubrique($id_rubrique, $types = []) { |
| 208 | - static $has_child = []; |
|
| 209 | - |
|
| 210 | - if (!isset($has_child[$id_rubrique])) { |
|
| 211 | - $types = (is_array($types) ? array_filter($types) : []); |
|
| 212 | - |
|
| 213 | - // recuperer tous les freres et soeurs de la rubrique visee |
|
| 214 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 215 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . intval($id_parent)); |
|
| 216 | - $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 217 | - $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 218 | - $has = array_column($has, 'id_parent'); |
|
| 219 | - $fratrie = array_diff($fratrie, $has); |
|
| 220 | - |
|
| 221 | - while (count($fratrie) and is_array($types) and count($types)) { |
|
| 222 | - $type = array_shift($types); |
|
| 223 | - $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 224 | - $h = array_column($h, 'id_rubrique'); |
|
| 225 | - $has = array_merge($has, $h); |
|
| 226 | - $fratrie = array_diff($fratrie, $h); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - if (count($has)) { |
|
| 230 | - $has_child = $has_child + array_combine($has, array_pad([], count($has), true)); |
|
| 231 | - } |
|
| 232 | - if (count($fratrie)) { |
|
| 233 | - $has_child = $has_child + array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 208 | + static $has_child = []; |
|
| 209 | + |
|
| 210 | + if (!isset($has_child[$id_rubrique])) { |
|
| 211 | + $types = (is_array($types) ? array_filter($types) : []); |
|
| 212 | + |
|
| 213 | + // recuperer tous les freres et soeurs de la rubrique visee |
|
| 214 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 215 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . intval($id_parent)); |
|
| 216 | + $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 217 | + $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 218 | + $has = array_column($has, 'id_parent'); |
|
| 219 | + $fratrie = array_diff($fratrie, $has); |
|
| 220 | + |
|
| 221 | + while (count($fratrie) and is_array($types) and count($types)) { |
|
| 222 | + $type = array_shift($types); |
|
| 223 | + $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 224 | + $h = array_column($h, 'id_rubrique'); |
|
| 225 | + $has = array_merge($has, $h); |
|
| 226 | + $fratrie = array_diff($fratrie, $h); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if (count($has)) { |
|
| 230 | + $has_child = $has_child + array_combine($has, array_pad([], count($has), true)); |
|
| 231 | + } |
|
| 232 | + if (count($fratrie)) { |
|
| 233 | + $has_child = $has_child + array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 238 | 238 | } |
@@ -11,53 +11,53 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Fonction appelee par divers pipelines |
| 18 | 18 | function notifications_instituerarticle_dist($quoi, $id_article, $options) { |
| 19 | 19 | |
| 20 | - // ne devrait jamais se produire |
|
| 21 | - if ($options['statut'] == $options['statut_ancien']) { |
|
| 22 | - spip_log('statut inchange', 'notifications'); |
|
| 23 | - |
|
| 24 | - return; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - include_spip('inc/texte'); |
|
| 28 | - |
|
| 29 | - $modele = ''; |
|
| 30 | - if ($options['statut'] == 'publie') { |
|
| 31 | - if ( |
|
| 32 | - $GLOBALS['meta']['post_dates'] == 'non' |
|
| 33 | - and strtotime($options['date']) > time() |
|
| 34 | - ) { |
|
| 35 | - $modele = 'notifications/article_valide'; |
|
| 36 | - } else { |
|
| 37 | - $modele = 'notifications/article_publie'; |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - if ($options['statut'] == 'prop' and $options['statut_ancien'] != 'publie') { |
|
| 42 | - $modele = 'notifications/article_propose'; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if ($modele) { |
|
| 46 | - $destinataires = []; |
|
| 47 | - if ($GLOBALS['meta']['suivi_edito'] == 'oui') { |
|
| 48 | - $destinataires = explode(',', $GLOBALS['meta']['adresse_suivi']); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - $destinataires = pipeline( |
|
| 53 | - 'notifications_destinataires', |
|
| 54 | - [ |
|
| 55 | - 'args' => ['quoi' => $quoi, 'id' => $id_article, 'options' => $options], |
|
| 56 | - 'data' => $destinataires |
|
| 57 | - ] |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - $texte = email_notification_article($id_article, $modele); |
|
| 61 | - notifications_envoyer_mails($destinataires, $texte); |
|
| 62 | - } |
|
| 20 | + // ne devrait jamais se produire |
|
| 21 | + if ($options['statut'] == $options['statut_ancien']) { |
|
| 22 | + spip_log('statut inchange', 'notifications'); |
|
| 23 | + |
|
| 24 | + return; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + include_spip('inc/texte'); |
|
| 28 | + |
|
| 29 | + $modele = ''; |
|
| 30 | + if ($options['statut'] == 'publie') { |
|
| 31 | + if ( |
|
| 32 | + $GLOBALS['meta']['post_dates'] == 'non' |
|
| 33 | + and strtotime($options['date']) > time() |
|
| 34 | + ) { |
|
| 35 | + $modele = 'notifications/article_valide'; |
|
| 36 | + } else { |
|
| 37 | + $modele = 'notifications/article_publie'; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + if ($options['statut'] == 'prop' and $options['statut_ancien'] != 'publie') { |
|
| 42 | + $modele = 'notifications/article_propose'; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if ($modele) { |
|
| 46 | + $destinataires = []; |
|
| 47 | + if ($GLOBALS['meta']['suivi_edito'] == 'oui') { |
|
| 48 | + $destinataires = explode(',', $GLOBALS['meta']['adresse_suivi']); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + $destinataires = pipeline( |
|
| 53 | + 'notifications_destinataires', |
|
| 54 | + [ |
|
| 55 | + 'args' => ['quoi' => $quoi, 'id' => $id_article, 'options' => $options], |
|
| 56 | + 'data' => $destinataires |
|
| 57 | + ] |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + $texte = email_notification_article($id_article, $modele); |
|
| 61 | + notifications_envoyer_mails($destinataires, $texte); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
@@ -21,18 +21,18 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | function req_sqlite3_dist($addr, $port, $login, $pass, $db = '', $prefixe = '') { |
| 24 | - return req_sqlite_dist($addr, $port, $login, $pass, $db, $prefixe, $sqlite_version = 3); |
|
| 24 | + return req_sqlite_dist($addr, $port, $login, $pass, $db, $prefixe, $sqlite_version = 3); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | function spip_sqlite3_constantes() { |
| 29 | - if (!defined('SPIP_SQLITE3_ASSOC')) { |
|
| 30 | - define('SPIP_SQLITE3_ASSOC', PDO::FETCH_ASSOC); |
|
| 31 | - define('SPIP_SQLITE3_NUM', PDO::FETCH_NUM); |
|
| 32 | - define('SPIP_SQLITE3_BOTH', PDO::FETCH_BOTH); |
|
| 33 | - } |
|
| 29 | + if (!defined('SPIP_SQLITE3_ASSOC')) { |
|
| 30 | + define('SPIP_SQLITE3_ASSOC', PDO::FETCH_ASSOC); |
|
| 31 | + define('SPIP_SQLITE3_NUM', PDO::FETCH_NUM); |
|
| 32 | + define('SPIP_SQLITE3_BOTH', PDO::FETCH_BOTH); |
|
| 33 | + } |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | function spip_versions_sqlite3() { |
| 37 | - return _sqlite_charger_version(3) ? 3 : false; |
|
| 37 | + return _sqlite_charger_version(3) ? 3 : false; |
|
| 38 | 38 | } |